# Show that $X = Y$ almost surely

I am trying to solve this problem:

Let $X,Y$ be random variables on $(\Omega, \mathcal{F}, P)$ such that $E(Y|\mathcal{G}) = X$ and $E(Y^2|\mathcal{G}) = X^2$, where $\mathcal{G} \subset \mathcal{F}$ is a sigma-algebra. Prove that $X = Y$ almost surely.

What I have until now:

From the given property, it's easy to see that $\int_{G}XdP = \int_{G} YdP$, for any $G \in \mathcal{G}$. Also, $X$ is $\mathcal{G}$-measurable.

I know that if the integrals of two random variables, on the same probability space, over any element of the sigma-algebra in discussion agree, then they are equal almost surely. So, if I could prove that $Y$ is also $\mathcal{G}$-measurable I could apply this result. Or, in te other hand, if I could find a similar equality as above for any element $F \in \mathcal{F}$, then I think the problem is solved too. But I can't do it.

Also, I can't see how the information the $X^2$ can be helpful here. Any ideas? Thanks in advance for the support.

• Hint: What is the variance of $Y$ over $\mathcal G$? $\mathsf{Var}(Y\mid\mathcal G) = \ldots$ – Graham Kemp May 8 '17 at 23:37
• @GrahamKemp Oh yeah, I think I see it now. The conditional variance is going to be zero. That's cool, thanks! But, sorry, does that imply that $Y$ is $\mathcal{G}$-measurable? – Raul Guarini May 8 '17 at 23:40

Since $X$ is $\mathcal{G}$-measurable we have (by the product rule) that $$E(XY) = E(E(XY|\mathcal{G})) = E(XE(Y|\mathcal{G})) = E(X^2).$$ Similarly, $$E(Y^2) = E(E(Y^2|\mathcal{G})) = E(X^2).$$ Thus, $$E((X-Y)^2) = E(X^2)+E(Y^2) - 2E(XY) = 0.$$ Hence, $$P((X-Y)^2 = 0) = 1.$$ The last line follows from the non-negativity of $(X-Y)^2$.