Solution (source code)

= Solution
{c}

Assume $X$ is <square-integrable>. Since $X$ and $Y$ have the same <probability distribution>, $Y$ is also <square-integrable> and $\mathbb E[Y^2]=\mathbb E[X^2]$. The product $XY$ is <integrable> by the <Cauchy-Schwarz inequality>.

We use the defining test-function identity for <conditional expectation>: for bounded $\mathcal G$-<measurable> $H$, $\mathbb E[XH]=\mathbb E[YH]$. Take $H=Y\mathbf1_{\{|Y|\leq m\}}$ and let $m\to\infty$. The <dominated convergence theorem>, with bounds $|XY|$ and $Y^2$, gives
$$
\mathbb E[XY]=\mathbb E[Y^2].
$$
This is the extension of the <conditional expectation> pull-out identity to this <square-integrable> multiplier. Consequently
$$
\mathbb E[(X-Y)^2]
=\mathbb E[X^2]-2\mathbb E[XY]+\mathbb E[Y^2]
=\mathbb E[X^2]-\mathbb E[Y^2]=0.
$$
A nonnegative <random variable> with zero <expectation> is zero <almost surely>. Hence
$$
\boxed{X=Y\quad\text{almost surely}.}
$$
Geometrically, this is the equality case in the <L2 space> <orthogonal projection> interpretation of <conditional expectation>.