Question about conditional expectation fact This fact comes from *Concentration of Measure for the Analysis of Randomised Algorithms * by Dubhashi and Panconesi (page 76, equation 5.2).

Let $X$ and $Y$ be two discrete random variables and two arbitrary functions $f$ and $g$. Then
$$E[E[f(X)g(X,Y) | X]] = E[f(X)E[g(X,Y)|X]]$$

This is how far I got in the proof:

*

*By law of iterated expectation $E[X] = E[E[X|Y]]$  we have that:
$$E[E[f(X)g(X,Y) | X]] = E[f(X) \cdot g(X,Y)]$$
Now I would like to apply something the $E[XY] = E[X] \cdot  E[Y]$ which only holds for two independent variables $X$ and $Y$. But I don't see $f(X)$ and $g(X,Y)$ as independent. Am I missing something here?
If they were independent I'd continue:

*

*$E[f(X) \cdot g(X,Y)] = E[f(X)] \cdot E[g(X,Y)]$

*Re-apply law of iterated expectation:
$$E[f(X)] \cdot E[g(X,Y)] = E[f(X)] \cdot E[E[g(X,Y)|X]] = E[f(X) \cdot E[g(X,Y)|X]] $$
$\square$
Could someone assist me in my thinking here?
 A: What is used is that
$$
\mathbb E\left[f(X)g\left(X,Y\right) | X\right]=f(X)\mathbb E\left[g\left(X,Y\right) | X\right],
$$
known as the pull-out property of the conditional expectation.
A: Claim: Let $X \in \mathscr{L}^1(\mathscr{G})$ and $Y \in \mathscr{L}^1(\mathscr{F})$, with $\mathscr{G}$ a subset of $\mathscr{F},$ of course, both being sigma fields. Then $\mathbf{E}(XY \mid \mathscr{G}) = X \mathbf{E}(Y \mid \mathscr{G}).$
Proof. By definition, $X \mathbf{E}(Y \mid \mathscr{G})$ is a version of $\mathbf{E}(XY \mid \mathscr{G})$ if for every $\mathrm{G} \in \mathscr{G},$ we have $\int\limits_\mathrm{G} XY = \int\limits_\mathrm{G} X\mathbf{E}(Y \mid \mathscr{G}).$ This last equality will be true, by definition of $\mathbf{E}(Y \mid \mathscr{G}),$ if $X = \mathbf{1}_\mathrm{G'},$ and by linearity, it will also be true if $X$ is a simple random variable. The usual way (approximation and convergence theorems) now shows this equality is always true for integrable random variables $X.$ QED
Now apply the previous claim with $\mathscr{G} = \sigma(X)$ and the "$Y$" in the claim being your "$f(X,Y).$"  We reach $\mathbf{E}(X f(X,Y) \mid X) = X \mathbf{E}(f(X,Y) \mid X).$ The expectations are therefore equal as well.
