[proofplan]
Uniqueness follows from the [integral](/page/Integral)-matching condition: if two versions $Y, Y'$ both satisfy conditions (i) and (ii), then $\mathbb{E}[(Y - Y') \mathbb{1}_A] = 0$ for all $A \in \mathcal{G}$, and choosing $A = \{Y > Y'\}$ forces $Y \leq Y'$ a.s.; symmetry gives equality. Existence proceeds in three stages of increasing generality: first for $X \in L^2$ via the [Orthogonal Projection](/theorems/437) onto the closed subspace $L^2(\Omega, \mathcal{G}, \mathbb{P})$, then for non-negative $X$ by truncation and the [Monotone Convergence Theorem](/theorems/509), and finally for general $X \in L^1$ by decomposing $X = X^+ - X^-$.
[/proofplan]
[step:Prove uniqueness by testing on the [set](/page/Set) $\{Y > Y'\}$]
Suppose $Y$ and $Y'$ both satisfy conditions (i) and (ii). Both are $\mathcal{G}$-measurable, so the set $A = \{Y > Y'\}$ belongs to $\mathcal{G}$. Applying the integral-matching condition (ii) to both $Y$ and $Y'$:
\begin{align*}
\mathbb{E}[(Y - Y') \mathbb{1}_A] = \mathbb{E}[Y \mathbb{1}_A] - \mathbb{E}[Y' \mathbb{1}_A] = \mathbb{E}[X \mathbb{1}_A] - \mathbb{E}[X \mathbb{1}_A] = 0.
\end{align*}
Since $(Y - Y') \mathbb{1}_A \geq 0$ and has zero expectation, we conclude $(Y - Y') \mathbb{1}_A = 0$ a.s., hence $Y \leq Y'$ a.s. Repeating the argument with $A' = \{Y' > Y\}$ gives $Y' \leq Y$ a.s. Together, $Y = Y'$ a.s.
[guided]
The uniqueness argument is a standard technique in measure theory: to show that a non-negative random variable is zero a.s., one verifies that its expectation is zero.
We are given two $\mathcal{G}$-measurable random variables $Y$ and $Y'$, both satisfying the integral-matching condition $\mathbb{E}[Y \mathbb{1}_A] = \mathbb{E}[X \mathbb{1}_A]$ and $\mathbb{E}[Y' \mathbb{1}_A] = \mathbb{E}[X \mathbb{1}_A]$ for all $A \in \mathcal{G}$. The set $A = \{Y > Y'\} = \{\omega \in \Omega : Y(\omega) > Y'(\omega)\}$ is $\mathcal{G}$-measurable because $Y$ and $Y'$ are both $\mathcal{G}$-measurable (the preimage of an [open set](/page/Open%20Set) under a measurable [function](/page/Function) is measurable). Therefore we may test the integral-matching condition on this specific set:
\begin{align*}
\mathbb{E}[(Y - Y') \mathbb{1}_A] = \mathbb{E}[X \mathbb{1}_A] - \mathbb{E}[X \mathbb{1}_A] = 0.
\end{align*}
On $A$, the integrand $(Y - Y')$ is strictly positive, so $(Y - Y') \mathbb{1}_A \geq 0$. A non-negative random variable with zero expectation must be zero a.s., yielding $\mathbb{P}(Y > Y') = 0$. The symmetric argument (testing on $A' = \{Y' > Y\}$) gives $\mathbb{P}(Y' > Y) = 0$.
[/guided]
[/step]
[step:Construct $\mathbb{E}[X \mid \mathcal{G}]$ for $X \in L^2$ via [orthogonal projection](/theorems/437)]
The space $L^2(\Omega, \mathcal{F}, \mathbb{P})$ is a [Hilbert space](/page/Hilbert%20Space) with inner product $(f, g)_{L^2} = \mathbb{E}[fg]$. The subspace $L^2(\Omega, \mathcal{G}, \mathbb{P}) = \{f \in L^2(\Omega, \mathcal{F}, \mathbb{P}) : f \text{ is } \mathcal{G}\text{-measurable}\}$ is a closed subspace: if $(f_n)$ is a [sequence](/page/Sequence) in $L^2(\mathcal{G})$ converging in $L^2$ to $f$, then a subsequence converges a.s., and the a.s. [limit](/page/Limit) of $\mathcal{G}$-[measurable functions](/page/Measurable%20Functions) is $\mathcal{G}$-measurable.
By the [Orthogonal Projection Theorem](/theorems/437), there exist unique $Y \in L^2(\mathcal{G})$ and $Z \in L^2(\mathcal{G})^\perp$ such that $X = Y + Z$. The variable $Y$ is $\mathcal{G}$-measurable by construction. For every $A \in \mathcal{G}$, the indicator $\mathbb{1}_A$ belongs to $L^2(\mathcal{G})$ (since $\mathbb{1}_A$ is bounded and $\mathcal{G}$-measurable), so the orthogonality condition $\mathbb{E}[Z \cdot \mathbb{1}_A] = 0$ gives:
\begin{align*}
\mathbb{E}[X \mathbb{1}_A] = \mathbb{E}[Y \mathbb{1}_A] + \mathbb{E}[Z \mathbb{1}_A] = \mathbb{E}[Y \mathbb{1}_A].
\end{align*}
Thus $Y$ satisfies both defining conditions (i) and (ii).
[guided]
Why start with $L^2$? The $L^2$ case is the most transparent because Hilbert space geometry (inner products, orthogonal projections) provides the conditional expectation for free. The price is that $L^2$ is a strictly smaller space than $L^1$, so this argument alone does not establish existence for all integrable $X$.
The [Orthogonal Projection Theorem](/theorems/437) requires that $L^2(\Omega, \mathcal{G}, \mathbb{P})$ be a *closed* subspace of $L^2(\Omega, \mathcal{F}, \mathbb{P})$. We verify this: suppose $f_n \in L^2(\mathcal{G})$ and $f_n \to f$ in $L^2(\mathcal{F})$. By passing to a subsequence (which exists because $L^2$-convergence implies the existence of an a.s.-convergent subsequence), $f_{n_k} \to f$ a.s. Each $f_{n_k}$ is $\mathcal{G}$-measurable, and the pointwise limit of measurable functions is measurable, so $f$ is $\mathcal{G}$-measurable.
With closedness verified, the projection theorem decomposes $X = Y + Z$ where $Y$ is the closest element of $L^2(\mathcal{G})$ to $X$, and $Z = X - Y$ is orthogonal to $L^2(\mathcal{G})$. The orthogonality condition $\mathbb{E}[Z \cdot g] = 0$ for all $g \in L^2(\mathcal{G})$ is tested with $g = \mathbb{1}_A$ (which belongs to $L^2(\mathcal{G})$ for $A \in \mathcal{G}$ since $\|\mathbb{1}_A\|_{L^2}^2 = \mathbb{P}(A) \leq 1$), giving:
\begin{align*}
\mathbb{E}[X \mathbb{1}_A] = \mathbb{E}[(Y + Z) \mathbb{1}_A] = \mathbb{E}[Y \mathbb{1}_A] + 0 = \mathbb{E}[Y \mathbb{1}_A].
\end{align*}
This is precisely the integral-matching condition (ii).
[/guided]
[/step]
[step:Verify that the $L^2$ conditional expectation preserves non-negativity]
If $X \geq 0$, then $Y = \mathbb{E}[X \mid \mathcal{G}] \geq 0$ a.s. To see this, note that $\{Y < 0\} \in \mathcal{G}$. The integral-matching condition gives:
\begin{align*}
\mathbb{E}[Y \mathbb{1}_{\{Y < 0\}}] = \mathbb{E}[X \mathbb{1}_{\{Y < 0\}}].
\end{align*}
The left side is non-positive (since $Y < 0$ on $\{Y < 0\}$), while the right side is non-negative (since $X \geq 0$). Both sides must therefore equal zero, and since $Y \mathbb{1}_{\{Y < 0\}} \leq 0$ with zero expectation, we conclude $\mathbb{P}(Y < 0) = 0$.
[/step]
[step:Extend existence to non-negative $X$ by truncation and monotone convergence]
For $X \geq 0$ with $X \in L^1$, define $X_n = \min(X, n)$ for each $n \geq 1$. Since $0 \leq X_n \leq n$, we have $X_n \in L^2$, so by the $L^2$ case there exist $\mathcal{G}$-measurable random variables $Y_n$ satisfying $\mathbb{E}[Y_n \mathbb{1}_A] = \mathbb{E}[X_n \mathbb{1}_A]$ for all $A \in \mathcal{G}$.
Since $X_n \leq X_{n+1}$, the integral-matching condition and the non-negativity preservation from the previous step give $Y_n \leq Y_{n+1}$ a.s.: for the difference $X_{n+1} - X_n \geq 0$, we have $\mathbb{E}[X_{n+1} - X_n \mid \mathcal{G}] = Y_{n+1} - Y_n \geq 0$ a.s.
Define $Y = \lim_{n \to \infty} Y_n$, which exists a.s. (as a limit of an increasing sequence) and is $\mathcal{G}$-measurable. Since $X_n \uparrow X$ pointwise and $Y_n \mathbb{1}_A \uparrow Y \mathbb{1}_A$ for each $A \in \mathcal{G}$, the [Monotone Convergence Theorem](/theorems/509) gives:
\begin{align*}
\mathbb{E}[Y \mathbb{1}_A] = \lim_{n \to \infty} \mathbb{E}[Y_n \mathbb{1}_A] = \lim_{n \to \infty} \mathbb{E}[X_n \mathbb{1}_A] = \mathbb{E}[X \mathbb{1}_A]
\end{align*}
for all $A \in \mathcal{G}$. Taking $A = \Omega$ confirms $\mathbb{E}[Y] = \mathbb{E}[X] < \infty$, so $Y \in L^1$.
[guided]
The strategy here is approximation from below. We cannot apply the $L^2$ construction directly to $X$ because an $L^1$ function need not belong to $L^2$ (consider $X = n^{-1}$ on sets of probability $n^{-1}$, arranged to give a convergent [series](/page/Series) for $\mathbb{E}[|X|]$ but not for $\mathbb{E}[X^2]$). However, truncating at level $n$ produces bounded (hence $L^2$) approximations.
The monotonicity $Y_n \leq Y_{n+1}$ a.s. is the crucial structural property that allows passage to the limit. It follows from the positivity of conditional expectation: $X_{n+1} - X_n = \min(X, n+1) - \min(X, n) \geq 0$, so $Y_{n+1} - Y_n = \mathbb{E}[X_{n+1} - X_n \mid \mathcal{G}] \geq 0$ a.s.
The [Monotone Convergence Theorem](/theorems/509) is applied twice: once to the sequence $Y_n \mathbb{1}_A \uparrow Y \mathbb{1}_A$ (which is increasing and non-negative since each $Y_n \geq 0$) and once to $X_n \mathbb{1}_A \uparrow X \mathbb{1}_A$.
[/guided]
[/step]
[step:Extend existence to general $X \in L^1$ by decomposition into positive and negative parts]
For general $X \in L^1$, write $X = X^+ - X^-$ where $X^+ = \max(X, 0)$ and $X^- = \max(-X, 0)$. Both $X^+$ and $X^-$ are non-negative and integrable (since $X^+, X^- \leq |X|$), so by the preceding step there exist $\mathcal{G}$-measurable $Y^+ = \mathbb{E}[X^+ \mid \mathcal{G}]$ and $Y^- = \mathbb{E}[X^- \mid \mathcal{G}]$, each in $L^1$.
Define $Y = Y^+ - Y^-$. Then $Y$ is $\mathcal{G}$-measurable, $Y \in L^1$ (since $\mathbb{E}[|Y|] \leq \mathbb{E}[Y^+] + \mathbb{E}[Y^-] = \mathbb{E}[X^+] + \mathbb{E}[X^-] = \mathbb{E}[|X|]$), and for every $A \in \mathcal{G}$:
\begin{align*}
\mathbb{E}[Y \mathbb{1}_A] = \mathbb{E}[Y^+ \mathbb{1}_A] - \mathbb{E}[Y^- \mathbb{1}_A] = \mathbb{E}[X^+ \mathbb{1}_A] - \mathbb{E}[X^- \mathbb{1}_A] = \mathbb{E}[X \mathbb{1}_A].
\end{align*}
[/step]