I am solving a problem involving the following integral: $$ \int_{\ln\left(\frac{(b-c)d-a}{1+b-c}\right)}^\infty \ln(a+\exp(x)-b\left|\exp(x)-d\right|-c(\exp(x)-d)) \frac{1}{\sqrt{2\pi}\sigma}\exp\left({-\frac{(x-\mu)^2}{2\sigma^2}}\right) \ dx $$ with \begin{aligned} a\geq0, \\ 0\leq c<b<1, \\ b+c<1, \\ d>0. \end{aligned} The lower bound ensures that the argument of the logarithm is positive, so the logarithm is well defined. The integral can be interpreted as the expected value of the following function of a random variable $X$, $$ \ln(a+\exp(X)-b\left|\exp(X)-d\right|-c(\exp(X)-d)), $$ where $X\sim \text{truncated}\ N(\mu,\sigma^2)$ where the left tail of the Normal distribution is truncated at $\ln\left(\frac{(b-c)d-a}{1+b-c}\right)$.
I have mostly forgotten the little calculus that I once knew, so I resorted to some online solvers such as
www.integral-calculator.com
and www.Desmos.com
. They said Antiderivative or integral could not be found and Undefined, respectively. I then turned to Sage Math but did not manage to make it work either (this is most likely my own fault; I am just a beginner at Sage Math).
However, I think the integral should be doable and its value should be finite.
- As $x\downarrow-\infty$, the logarithm asymptotes along $\ln(a)$.
As $x\uparrow\infty$, the logarithm asymptotes along $(1-B-C)x$.
Thus the function behaves at most as a linear function of $x$. - The (truncated) normal distribution has finite first moment (and many more moments than that).
- Therefore, the integral should be finite.
What surprised me even more was that the solvers failed to calculate a finite value of the integral even when concrete values of $a,\ b,\ c,\ d,\ \mu,\ \sigma$ were supplied, at least for some sets of such values (e.g. when $d$ is relatively large).
I would appreciate any help getting this integral done. I have plotted all the functions involved in the integral using Desmos here. You can check it out and adjust with the parameters very easily to see how the functions behave. Perhaps that will be helpful in helping me. A screenshot is presented below:
The dashed blue line is the argument of $\ln(\cdot)$.
The violet line is $\ln(a+\exp(x)-b\left|\exp(x)-d\right|-c(\exp(x)-d))$.
The green line is the density of the random variable w.r.t. which I am integrating.
The red line is the integrand (the product of the logarithm and the density).
The black line is the lower bound of the definite integral.
Update: As suggested in the comments, finding a closed-form expression for the integral may be impossible. However, I think I found an explanation for why the integral failed numerically for concrete values of $a,\ b,\ c,\ d$. Though the integrand is asymptotically linear for $x\rightarrow+\infty$, its calculation requires exponentiation (followed by a logarithm). When executed naively, exponent of a large number quickly exceeds the limits of standard software, so numerical integration fails. A (probably) naive workaround is to introduce an upper bound $ub$ such that conditions A and B are satisfied.
- Condition A: the density $\frac{1}{\sqrt{2\pi}\sigma}\exp\left({-\frac{(x-\mu)^2}{2\sigma^2}}\right)$ is numerically equal to zero.
- Condition B: the exponent $\exp(x)$ is small enough so that software can handle it without returning infinity or error or the like.
This seems be working OK for me in R software using the function integrate
.