I am trying to find a good way to numerically integrate $$\int_0^\infty \frac{e^{ -x^2/(2 a^2)} }{a \sqrt{2 \pi}} \frac{2 \log( a^2 ) }{\pi^2 (a^2-1)} da$$ for $x \in (-\infty, \infty)$. I believe there is no closed form analytical solution for this integral. In the end I want to plot this integral as a function of x.
My main issue with using some simple (adaptive) quadrature procedures is the singularities at 0 (due to the $\log a^2$ term) and at 1 (due to the $1/(a^2-1)$ term) - plus the integral being to $\infty$. I would assume that one could find some good substitution that might remove both singularities and turn this into an integral on finite intervals, but I lack the experience or intuition about what a good substitution would be in this case.
I thought of $u=\cos(a)$ or $u = \log a^2$, but these do not do the job. Or perhaps I could split the integral into e.g. 0 to 0.5, 0.5 to 2 and 2 to $\infty$. For the first of these $u=\log a^2$ does remove the singularity. Then I need some transformation that removes the signularity in the second integral and one that turns the final interval into a finite one. Are there obvious ones I should consider.
Or is there some more obvious or simple way to do this numerical integration (particularly, with a method that is implemented in some R package)?
Let $F(x)=\int_0^\infty \frac{e^{-x^2/(2a^2)}}{a}\,\frac{\log(a^2)}{a^2-1}\,da$. We remark that $F(0)$ fails to exist.
Next, we can write for $x\ne 0$
$$\begin{align} F(x)&=\int_0^\infty \frac{e^{-x^2/(2a^2)}}{a}\,\frac{\log(a^2)}{a^2-1}\,da\\\\ &=\int_0^1 \frac{e^{-x^2/(2a^2)}}{a}\,\frac{\log(a^2)}{a^2-1}\,da+\int_1^\infty \frac{e^{-x^2/(2a^2)}}{a}\,\frac{\log(a^2)}{a^2-1}\,da\\\\ &=\int_0^1 \frac{e^{-x^2/(2a^2)}}{a}\,\frac{\log(a^2)}{a^2-1}\,da+\int_0^1 \frac{e^{-x^2a^2/2}}{1/a}\frac{\log(1/a^2)}{1/a^2-1}\frac{1}{a^2}\,da\\\\ &=\int_0^1 \frac{e^{-x^2/(2a^2)}}{a}\,\frac{\log(a^2)}{a^2-1}\,da+\int_0^1 ae^{-x^2a^2/2}\frac{\log(a^2)}{a^2-1}\,da \tag 1 \end{align}$$
Note that $\frac{\log(a^2)}{a^2-1}=\frac{2}{a+1}\frac{\log(a)}{a-1}$ is well-behaved near $a=1$ since $\log(a)=(a-1)+O(a-1)^2$ for $a$ near $1$. Hence, both integrals on the right-hand side of $(1)$ are well-behaved near $a=1$
The second integral on the right-hand side of $(1)$ is also well-behaved near $a=0$ since $\lim_{a\to 0}a\log(a)=0$.
Finally, we see that for fixed $x\ne 0$, $\lim_{a\to 0} \frac{e^{-x^2/(2a^2)}}{a}\,\log(a^2)=0$ and hence the integral on the right-hand side of $(1)$ is also well-behaved near $a=0$.
Hence, for numerical evaluation, we need only redefine the integrand as to account for the removable discontinuities.
All of that said, there is still a potentially challenging issue left to resolve. For $x=0$, the first integral on the right-hand side of $(1)$ diverges. We can handle this issue as follows.
To facilitate numerical analysis, we proceed by integrating by parts with $u=\frac{a^2\log(a^2)}{a^2-1}$ and $dv=\frac{e^{-x^2/(2a^2)}}{a^3}$. Then, we find that
$$\begin{align} \int_0^1 \frac{e^{-x^2/(2a^2)}}{a}\,\frac{\log(a^2)}{a^2-1}\,da&=\frac{e^{-x^2/2}}{x^2}-\frac{1}{x^2}\int_0^1 e^{-x^2/(2a^2)}\left(\frac{2a\log(a^2)}{a^2-1}-\frac{2a^3\log(a^2)}{(a^2-1)^2}+\frac{2a}{a^2-1} \right)\,da \tag 2 \end{align}$$
The integral on the right-hand side of $(2)$ is well-behaved for $x=0$. In fact, at $x=0$ the integral is equal to $1$.
Finally, we write
$$\begin{align} F(x)&=\frac{e^{-x^2/2}}{x^2}-\frac{1}{x^2}\int_0^1 e^{-x^2/(2a^2)}\left(\frac{2a\log(a^2)}{a^2-1}-\frac{2a^3\log(a^2)}{(a^2-1)^2}+\frac{2a}{a^2-1} \right)\,da\\\\ &+\int_0^1 ae^{-x^2a^2/2}\frac{\log(a^2)}{a^2-1}\,da \tag 3 \end{align}$$
where all of the integrals in $(3)$ have removable discontinuities.