Solution (source code)

= Solution

For real <random variables> with finite <second moments>, the <Cauchy-Schwarz inequality> is
$$
\boxed{|\mathbb E[Y_1Y_2]|^2\leq\mathbb E[Y_1^2],\mathbb E[Y_2^2].}
$$
The product is integrable because $2|Y_1Y_2|\leq Y_1^2+Y_2^2$. If $\mathbb E[Y_2^2]=0$, then $Y_2=0$ almost surely and the result is immediate. Otherwise the nonnegative <expectation> of a square gives, for every real $t$,
$$
0\leq\mathbb E[(Y_1-tY_2)^2]=\mathbb E[Y_1^2]-2t\mathbb E[Y_1Y_2]+t^2\mathbb E[Y_2^2].
$$
Choose $t=\mathbb E[Y_1Y_2]/\mathbb E[Y_2^2]$. The resulting inequality is exactly the claimed <Cauchy-Schwarz inequality>. Equality holds precisely when $Y_1$ is a constant multiple of $Y_2$ almost surely in this nondegenerate case.