# Numerical computation of $\log \int_a ^b f(x) \mathrm{d}x$ from $\log f(x)$?

I want a numerical method to evaluate:

$$\log \int_a ^b f(x) \mathrm{d}x$$

when what I have is a numerical routine to evaluate $\log f(x)$. The problem is that if $f(x)$ takes very large or very small values, direct evaluation of $f(x)$ will lead to overflows/underflows. I am wondering if anyone has approached this numerical integration problem in general?

Note that even though $f(x)$ can be very small in some regions and very large in other regions, you can't just approximate the small values to zero, because if the region where $f(x)$ is very small is large enough, it may contribute significantly to the integral.

• If $f$ does not vary too much, you can try to normalize it by just one (or a couple) of its values: pick a point $x_1$ and compute $\log f(x_1) + \log\int e^{\log f(x)-\log f(x_1)}\,dx$. That might be enough avoid over-/underflows in the exponentials, depending on how the function behaves. – Kirill Apr 28 '15 at 21:34

You say that $f(x)$ has both very large and very small (positive) values. Then the integral you have is "large", and the small values of $f(x)$ don't matter very much: in those areas where $f(x)$ would produce an underflow, you might as well add zeros because the contributions of this to the overall integral do not matter.
So what matters are those areas where $f(x)$ is so large that you get overflows. This must happen because you have some kind of singularity at these locations. If so, it would be worth splitting $f(x)$ into its singular and non-singular parts and integrating the singular parts analytically if possible, and the remainder term with quadrature.
• I did not say that $f(x)$ takes both very large and very small values. I said it takes very small values or very large values. These are two separate situations. – becko Apr 28 '15 at 17:05
• Ah, I read the statement that for different values of $x$, $f(x)$ may be large or small. Are you saying that it is always large, or always small? – Wolfgang Bangerth Apr 28 '15 at 17:29
• In that case, can't you just normalize $f(x)$ by dividing it by a "typical size"? – Wolfgang Bangerth Apr 29 '15 at 3:02
• Yes. We can go on forever with this, though. It would be more productive if you state what you know about $f(x)$ in the question. – Wolfgang Bangerth Apr 29 '15 at 21:14