# X is some random variable and f is a continuous function. Is f[E(X)] = E[f(X)]?

I am curious about at what conditions the expectation and a mapping could exchange their operation.

Say, X is some random variable, and $f:R\rightarrow R$ is a continuous function. Does $$f[E(X)] = E[f(X)]$$ hold? What if X is absolutely continuous (i.e., the density function g(x) of X exists)? Does it make any difference?

I'm just feel it's interesting. Thanks for discussion!:)

No it doesn't. In fact, if $f$ is strictly convex (e.g. $f(x)=x^2$), and $X$ is not a constant with probability 1, then Jensen's inequality tells us that $$E[f(X)] > f(E(X))$$

One important class of functions where equality does hold is linear functions (e.g. $f(x)=ax+b$)

For example, if the equality holds when $f(x)=x^2$, then by the equality case in Cauchy-Schwarz inequality we would get that $X$ is constant.

Hence the equality $\mathbb E[f(X)]=f\left(\mathbb E[X]\right)$ has no reason to hold in general.

As per other answers, this is in general false.

If $f(X)$ is not only continuous but differentiable, and if the moments of higher order are finite, the equality can be "approximately true" in the following sense: letting $Y=f(X)$ you can do a Taylor expansion around $\mu_X=E(X)$:

$$Y \approx f(\mu_X) + f'(\mu_X) (X-\mu_X) + \frac{1}{2!}f''(\mu_X) (X-\mu_X)^2 +\cdots$$

and taking expectations on both sides, the linear term vanishes and:

$$\mu_Y \approx f(\mu_X) + \frac{1}{2!} f^{''}(\mu_X) m_2 + \frac{1}{3!} f^{[3]}(\mu_X) m_3 + \cdots$$

where $m_k = E[(X-\mu_X)^k]$.