Throughout, measurability of a real-valued map is with respect to the named σ-algebra and B(R), and we use freely that constants, indicators of measurable sets, sums, scalar multiples, products, absolute values, maxima and pointwise limits of measurable real-valued maps are measurable (claims 1--5 of Arithmetic, Absolute Values, and Pointwise Limits of Measurable Real-Valued Functions).
Step 1: claim 1. Preimages commute with complements and countable unions: D−1(Y)=Ω, Ω∖D−1(B)=D−1(Y∖B), and ⋃nD−1(Bn)=D−1(⋃nBn); since Y is a σ-algebra, σ(D) is a σ-algebra on Ω, and σ(D)⊆F because D is measurable with respect to F and Y. That D is measurable with respect to σ(D) and Y is the definition of σ(D).
Let H be as in the statement, the family of sets A∈F for which there is A′∈σ(D) with P(A△A′)=0. Then H is a σ-algebra: Ω∈H (take A′=Ω); if A∈H with witness A′ then (Ω∖A)△(Ω∖A′)=A△A′, so Ω∖A∈H; and if An∈H with witnesses An′ then (⋃nAn)△(⋃nAn′)⊆⋃n(An△An′), a countable union of sets of F of probability 0, hence of probability 0 by countable subadditivity (Basic Properties of a Measure), so ⋃nAn∈H. Moreover σ(D)⊆H (take A′=A) and N⊆H (take A′=∅; then A△∅=A has probability 0). Hence the σ-algebra GN generated by σ(D)∪N satisfies σ(D)⊆GN⊆H⊆F.
Conversely H⊆GN: let A∈H with witness A′∈σ(D). The sets A∖A′ and A′∖A lie in F and are contained in A△A′, hence have probability 0 by monotonicity of P (Basic Properties of a Measure), so both lie in N. Since
A=(A′∖(A′∖A))∪(A∖A′)
and GN is a σ-algebra containing A′, A′∖A and A∖A′, we get A∈GN. So GN=H, and in particular GN is D-generated up to null sets.
Finally, if G is any σ-algebra on Ω that is D-generated up to null sets, then by definition every A∈G lies in F and admits a witness in σ(D), that is G⊆H=GN; and conversely a σ-algebra G with σ(D)⊆G⊆H is D-generated up to null sets, again by the definition of H. This proves the remaining assertions of claim 1.
Step 2: claim 2, the easy direction. Let g:Y→R be Y-measurable and Z=g∘D. For A∈B(R) we have Z−1(A)=D−1(g−1(A)) with g−1(A)∈Y, so Z−1(A)∈σ(D) and Z is σ(D)-measurable.
Step 3: claim 2, the factorisation. Let Z:Ω→R be σ(D)-measurable. For a natural number n and an integer k with ∣k∣≤n2n put
En,k={ω∈Ω: k2−n≤Z(ω)<(k+1)2−n},
an element of σ(D), since it is the preimage under Z of a Borel set. For fixed n these sets are pairwise disjoint. Choose Bn,k∈Y with En,k=D−1(Bn,k), and replace Bn,k by Bn,k∖⋃k′<kBn,k′ (a finite union, so the result lies in Y); this does not change the preimage, because
D−1(Bn,k∖k′<k⋃Bn,k′)=En,k∖k′<k⋃En,k′=En,k
by the disjointness of the En,k. So we may and do assume that for each fixed n the sets Bn,k are pairwise disjoint. Put
gn=k=−n2n∑n2nk2−n1Bn,k,
a finite sum of constants times indicators of members of Y, hence Y-measurable.
Fix ω∈Ω and put y=D(ω). If ∣Z(ω)∣≤n, then ω∈En,k for exactly one k with ∣k∣≤n2n, namely the integer k with k2−n≤Z(ω)<(k+1)2−n; then y∈Bn,k, and y lies in no other Bn,k′ by disjointness, so gn(y)=k2−n and ∣gn(y)−Z(ω)∣≤2−n. Since Z(ω) is a real number, ∣Z(ω)∣≤n for all large n, so the sequence (gn(D(ω)))n converges to Z(ω).
Let L be the set of y∈Y for which (gn(y))n is a Cauchy sequence of real numbers. Then
L=k≥1⋂ M≥1⋃ n≥M⋂ m≥M⋂{y:∣gn(y)−gm(y)∣≤1/k},
a countable intersection of countable unions of countable intersections of members of Y, hence L∈Y. Put hn=gn1L, Y-measurable. At every y∈L the sequence (hn(y))n=(gn(y))n converges to a real number by Every Cauchy Sequence of Real Numbers Converges; at every y∈/L it is constantly 0. So (hn(y))n converges to a real number for every y, and by claim 5 of Arithmetic, Absolute Values, and Pointwise Limits of Measurable Real-Valued Functions the map g(y)=limnhn(y) is Y-measurable. For every ω, D(ω)∈L by the previous paragraph (a convergent sequence is Cauchy), so g(D(ω))=limngn(D(ω))=Z(ω). Thus Z=g∘D, proving claim 2.
Step 4: claim 3. Let Y be a conditional expectation of X given σ(D), which exists by Existence and Uniqueness of Conditional Expectation for Square-Integrable Random Variables. Conditions (i) and (ii) of Conditional Expectation of a Square-Integrable Random Variable for G hold: Y is σ(D)-measurable, hence G-measurable because σ(D)⊆G, and Y is square-integrable. For (iii), let A∈G and choose A′∈σ(D) with P(A△A′)=0. Then 1A and 1A′ differ only on A△A′, so 1A and 1A′ are almost surely equal; hence X1A and X1A′ are almost surely equal integrable random variables and have the same expectation, and likewise for Y. Therefore
E[X1A]=E[X1A′]=E[Y1A′]=E[Y1A],
the middle equality by property 3 of Existence and Uniqueness of Conditional Expectation for Square-Integrable Random Variables for σ(D). So Y is a conditional expectation of X given G. By the uniqueness assertion of Existence and Uniqueness of Conditional Expectation for Square-Integrable Random Variables applied to G, any conditional expectation of X given G is almost surely equal to Y, and by the same assertion applied to σ(D), so is any conditional expectation of X given σ(D). Almost surely equal square-integrable random variables are at mean-square distance 0 by Square-Integrable Random Variables and the Mean-Square Inner Product, so X−E[X∣G] and X−E[X∣σ(D)] are almost surely equal and the displayed expectations agree.
Step 5: claim 4. The zero map is Y-measurable with 0∘D=0 square-integrable, so M=∅ and the displayed set of real numbers is nonempty; it is bounded below by 0, so it has a greatest lower bound.
Let Y be a conditional expectation of X given σ(D). By claim 2 there is a Y-measurable g⋆ with Y=g⋆∘D; since Y is square-integrable, g⋆∈M. Conversely, for every g∈M the random variable g∘D is σ(D)-measurable by Step 2 and square-integrable, so property 1 of Existence and Uniqueness of Conditional Expectation for Square-Integrable Random Variables gives ∥X−Y∥2≤∥X−g∘D∥2, that is E[(X−Y)2]≤E[(X−g∘D)2]. Since Y=g⋆∘D with g⋆∈M, the value E[(X−Y)2] belongs to the set and is a lower bound for it, so it is the greatest lower bound and it is attained. By claim 3 it equals E[(X−E[X∣G])2], which proves claim 4.
Step 6: claim 5. The map (X,D):Ω→R×Y is measurable with respect to F and B(R)⊗Y. Indeed, the family E of sets C⊆R×Y with (X,D)−1(C)∈F is a σ-algebra on R×Y, because preimages commute with complements and countable unions and (X,D)−1(R×Y)=Ω; and E contains every set A×B with A∈B(R) and B∈Y, since (X,D)−1(A×B)=X−1(A)∩D−1(B)∈F. Such sets generate B(R)⊗Y by Product Sigma-Algebra, and a σ-algebra containing a family contains the σ-algebra it generates, so B(R)⊗Y⊆E, which is the asserted measurability. The same argument applies to (X′,D′). Write L for the common image measure on B(R)⊗Y, a probability measure by claim 1 of that lemma.
For a Y-measurable g:Y→R define Fg:R×Y→[0,∞) by Fg(a,y)=(a−g(y))2. The coordinate maps (a,y)↦a and (a,y)↦g(y) are measurable with respect to B(R)⊗Y, the first because the preimage of A∈B(R) is A×Y and the second because the preimage of A is R×g−1(A); hence Fg is measurable. Moreover Fg∘(X,D)=(X−g∘D)2 and Fg∘(X′,D′)=(X′−g∘D′)2 pointwise. By the change of variables of claim 2 of Image Measures, Measures with Densities, and Change of Variables, applied to the nonnegative measurable Fg,
E[(X−g∘D)2]=∫R×YFgdL=E′[(X′−g∘D′)2]in [0,∞],
both outer expectations being integrals of nonnegative measurable maps in the sense of Lebesgue Integral of a Nonnegative Measurable Function. Taking g the zero map shows E[X2]=E′[X′2], so X′ is square-integrable if and only if X is; and for general g the displayed identity shows that g∘D is square-integrable if and only if g∘D′ is, because (g∘D)2≤2(X−g∘D)2+2X2 and (X−g∘D)2≤2X2+2(g∘D)2 pointwise, with the symmetric bounds on the primed space, and expectation is monotone and additive on nonnegative random variables by Linearity and Monotonicity of the Lebesgue Integral. Hence the set M of claim 4 formed on (Ω,F,P) with D coincides with the set formed on (Ω′,F′,P′) with D′, and for every g in it the two expectations agree. By claim 4 applied on each space,
E[(X−E[X∣G])2]=g∈MinfE[(X−g∘D)2]=g∈MinfE′[(X′−g∘D′)2]=E′[(X′−E′[X′∣G′])2],
the two greatest lower bounds being those of the same set of real numbers. ■