Solution (source code)

= Solution

The <conditional expectation> $\mathbb E[X\mid\mathcal G]$ is a $\mathcal G$-measurable integrable <random variable> $Z$ such that
$$
\boxed{\mathbb E[Z\mathbf1_A]=\mathbb E[X\mathbf1_A]\quad\text{for every }A\in\mathcal G.}
$$
It is defined up to <almost sure equality>. Measurability with respect to the sub-<sigma-algebra> and equality of these integrals are both essential: the first expresses that only the information in $\mathcal G$ is retained, and the second preserves all averages visible through that information. Existence follows from the <Radon-Nikodym theorem>; uniqueness is up to sets of probability zero.