Variance of an operator In statistics, given a probability distribution, the variance of a quantity $X$ is obtained by averaging $(X - \langle X\rangle)^2$ over the distribution. Here $\langle X\rangle$ is the average value of $X$. We can also write the variance as $\langle X^2\rangle - \langle X\rangle^2$. It can easily be verified that the two definitions are equivalent.
In quantum mechanics, given the wave function, we may define the variance of an operator $O$. One choice would be to evaluate the expectation value of $(O - A)^2$. Here $A$ is the expectation value of $O$. The other choice would be to take $O^2 - A^2$.
Unfortunately these two choices are not equivalent in QM. That is because the operator $O$ will (in general) not only act on the wave function, but also on $A$ since it need not be a constant but can be a function of space or momentum coordinates.
My question is: what is the preferred definition of the variance in QM ?
 A: The two choices are equivalent in QM as well. Take a wavefunction $\psi$. Take an operator $Q$ with expectation value $\langle Q \rangle$ in state $\psi$.
$$(Q-\langle Q \rangle)^2=(Q-\langle Q \rangle)(Q-\langle Q \rangle)=Q^2-2\langle Q \rangle Q+\langle Q \rangle^2$$
Thus,
$$\langle \psi|(Q-\langle Q \rangle)^2|\psi \rangle=\langle\psi|Q^2|\psi\rangle-2\langle Q\rangle \langle \psi|Q|\psi \rangle+\langle Q \rangle^2$$
since $\langle Q \rangle$ is a constant. The above expression, as you can see is simply: $\langle Q^2 \rangle-\langle Q \rangle^2$
Where is the discrepancy? $\langle Q \rangle$ is a fixed number that does not depend on anything but time, in which case the operator Q will still not care about it since most quantum operators are time independent.
A: Hint: use carets like $\hat X$ to denote operators.
Then $x:=\langle \hat X\rangle$ is a number since average values are numbers, not operators.  Using this:
\begin{align}
\langle (\hat X-x)^2\rangle 
=\langle 
\hat X^2 - 2x\hat X + x^2\rangle
&=  \langle \hat X^2\rangle - 2x \langle \hat X\rangle + x^2 
 \, ,
\tag{1}\\
&= \langle \hat X^2\rangle - x^2 = \langle \hat X^2\rangle - \langle \hat X\rangle ^2
\end{align}
where $\langle \hat X\rangle=x$ and $\langle x\rangle=x\, , \langle x^2\rangle = x^2$ (since $x$ is a number) have been used.
Thus the two definitions are identical.
