# Trying to approximate $E[f(X)]$ - Woflram Alpha gives $E[f(X)] \approx \frac{1}{\sqrt{3}}$ but I get $E[f(X)] \approx 0$?

Let $$X \sim \mathcal{N}(\mu_X,\sigma_X^2) = \mathcal{N}(0,1)$$. Let $$f(x) = e^{-x^2}$$. I want to approximate $$E[f(X)]$$.

Wolfram Alpha gives \begin{align} E[f(X)] \approx \frac{1}{\sqrt{3}}. \end{align}

Using a Taylor expansion approach, and noting that $$f''(0) = -2$$, I get \begin{align} E[f(X)] &\approx f(\mu_X) + \frac{f''(\mu_X)}{2} \sigma_X^2 \\ & = f(0) + \frac{f''(0)}{2} \\ & = 1 + \frac{-2}{2} \\ & = 0. \end{align}

Why does my approximation fail to match the Wolfram Alpha result? What can be done to fix it?

• Ok, we need $\sigma_X^2$ to be small, then it works. Then smaller the better. Makes sense. – Bertus101 Nov 4 '20 at 14:07
• $e^{-x^2}$ looks like an upside down parabola near zero, but it is strictly positive everywhere (and so the expected value must also be strictly positive), whereas the parabola will eventually turn negative. The more probability mass you have far from zero, the more you are landing in the region where it is a very bad approximation. – Chris Haug Nov 4 '20 at 14:18
• Shouldn't you use a univariate transformation? i.e: define Y as $e^{-x^2}$, and then calculate $F(a) = P(Y < a) = P(e^{-x^2} < a) = P(X > \sqrt{-ln(a)}) = 1 - P(X < \sqrt{-ln(a)})$ and then differentiate wrt a to get f(a), where F is the cdf and f the pdf. Then, calculate the expected value $E(Y) = \int f(y) \times y$. Wolfram alpha is giving you the exact result, it's only approximating $\frac{1}{\sqrt{3}}$, my guess is that it's using the univariate transformation I mentioned above. – Caio C. Nov 4 '20 at 14:26
• @CaioC. You can do it a lot easier than that by noting that the form of $f$ is such that it combines with the normal density into a standard Gaussian integral. – Chris Haug Nov 4 '20 at 14:34
• @ChrisHaug you're right, that's a lot easier. – Caio C. Nov 4 '20 at 14:48

You does not need an approximation here. Use properties of moment generating functions, $$X$$ is standard normal so $$X^2$$ is chisquared with one df, with moment generating function $$M_{X^2}(t)=\frac1{\sqrt{1-2t}}$$ (for $$t<1/2$$.) Then note that $$\DeclareMathOperator{\E}{\mathbb{E}}M_X(t)=\E e^{t X}$$ is the definition, so that $$\E e^{-X^2}=M_{X²}(-1)=\frac1{\sqrt{1-2\cdot (-1)}}=\frac1{\sqrt{3}}$$ We can check that in R with a fast simulation (always a good idea to do a simulation check):

 mean( exp(-rnorm(1E6)^2) )
[1] 0.5774847
1/sqrt(3)
[1] 0.5773503


What about if 𝑋 was not standard normal but normal with mean $$𝜇_𝑋$$ and variance $$𝜎^2_𝑋$$. Can your approach still be used or is it specific to the case of a standard normal distribution?
It can still be used. I will not give full details. First, the easy case $$X \sim \mathcal{N}(0,\sigma^2)$$. Then $$X=(\sigma Z)^2$$ with $$Z$$ standard normal, so in the above argument you get the argument $$-\sigma^2$$ in place of $$-1$$ for the mgf (moment generating function.) For the fully general case, see for instance Moment-generating function (MGF) of non-central chi-squared distribution and work from there.
• What about if $X$ was not standard normal but normal with mean $\mu_X$ and variance $\sigma_X^2$. Can your approach still be used or is it specific to the case of a standard normal distribution? – Bertus101 Nov 4 '20 at 16:00
There's no need to "approximate" when you can derive the exact value of $$\mathbb{E}[f(X)]$$ . Let us apply the Law of the Unconscious Statistician (LoTUS) to obtain : \begin{align*} \mathbb{E}[f(X)] &= \int_{-\infty}^{+\infty} e^{-x^2} \cdot \frac{1}{\sqrt{2\pi}} \exp\left(-\frac{x^2}{2}\right)~dx\\ &= 2\int_0^{+\infty} \frac{1}{\sqrt{2\pi}} \exp\left(-\frac{3x^2}{2}\right)~dx\\ &= 2\int_0^{+\infty} \frac{1}{\sqrt{2\pi}} \cdot\frac{1}{\sqrt{6z}} e^{-z}~dz\\ &= \frac{2}{2\sqrt{3\pi}} \int_0^{+\infty} e^{-z} z^{\frac{1}{2} -1} ~dz\\ &=\frac{1}{\sqrt{3\pi}}\cdot \Gamma\left(\frac{1}{2}\right)\\ &= \frac{1}{\sqrt{3\pi}}\cdot \sqrt{\pi}\\ &= \frac{1}{\sqrt{3}} \end{align*}