Express random variable $V(X)$ given function $V(x)$

expected valueprobabilityrandom variablesvariance

I have come across a question which reads as follows:
For a random variable $X$ with mean $\mu$ and variance $\sigma^2 < \infty$, define the function $V (x) = E((X −x)^2)$ where $'E'$ denotes expectation. Express the random variable V (X) in terms of $\mu, \sigma^2$:

What I have so far: I am able to calculate $V(x)=\sigma^2+\mu2-2x\mu+x^2$
. The answer is $V(X)=\sigma^2+\mu2-2X\mu+X^2$.

My question is why we can't substitute $X$ directly into the expression for $V$ to ge $E((X-X)^2)=0$?

Best Answer

We actually have:$$V(x)=\int \left(X (\omega)-x\right)^2P(d\omega)$$

Now if I substitute $x=X(\omega)$ then this $\omega$ becomes a free variable on LHS but a bound variable (ranging over $\Omega$) on RHS.

This is not allowed.


The situation is up to a certain level comparable with the following:

It is true in $\mathbb R$ that $\forall x\exists y\;[ x<y]$.

Nevertheless something that is not true arises if we substitute $x=y+1$.

This because the free variable $y$ is placed on a spot where it is bound by quantifier $\exists y$.