Solution (source code)

= Solution

Because $\widehat X-i\lambda\widehat Y$ is the adjoint of $\widehat X+i\lambda\widehat Y$,
$$
f(\lambda)=\|(\widehat X+i\lambda\widehat Y)\psi\|^2\geq0.
$$
Expanding gives the real quadratic
$$
f(\lambda)
=\langle\widehat X^2\rangle
+i\lambda\langle[\widehat X,\widehat Y]\rangle
+\lambda^2\langle\widehat Y^2\rangle.
$$
Its discriminant must be nonpositive. Since the expectation of a commutator of Hermitian operators is purely imaginary,
$$
4\langle\widehat X^2\rangle\langle\widehat Y^2\rangle
\geq\left|\langle[\widehat X,\widehat Y]\rangle\right|^2.
$$
Taking $\widehat X=\widehat A-\langle\widehat A\rangle$ and $\widehat Y=\widehat B-\langle\widehat B\rangle$ and then taking square roots gives the stated uncertainty relation. This is the <quadratic-norm proof of the Heisenberg uncertainty relation>.