Condition for Independence from Product of Expectations

Theorem
Let $\left({\Omega, \Sigma, \Pr}\right)$ be a probability space.

Let $X$ and $Y$ be discrete random variables on $\left({\Omega, \Sigma, \Pr}\right)$.

Let $E$ denote the expectation function.

Then $X$ and $Y$ are independent iff:
 * $E \left({g \left({X}\right) h \left({Y}\right)}\right) = E \left({g \left({X}\right)}\right) E \left({h \left({Y}\right)}\right)$

for all functions $g, h: \R \to \R$ for which the latter two expectations exist.

Sufficient Condition
Suppose that $X$ and $Y$ were not independent.

That is:
 * $\Pr \left({X = a, Y = b}\right) \ne \Pr \left({X = a}\right)\Pr \left({Y = b}\right)$

for some $a, b \in \R$.

Now, suppose that
 * $E \left({g \left({X}\right) h \left({Y}\right)}\right) = E \left({g \left({X}\right)}\right) E \left({h \left({Y}\right)}\right)$

for all functions $g, h: \R \to \R$ for which the latter two expectations exist.

Let us define $g$ and $h$ as examples of such functions as follows:


 * $(1): \quad g \left({x}\right) := \begin{cases}

1 & : x = a \\ 0 & : x \ne a \end{cases}$


 * $(2): \quad h \left({y}\right) := \begin{cases}

1 & : y = b \\ 0 & : y \ne b \end{cases}$

where $a \in \R$ and $b \in \R$ are arbitrary real numbers.

Then:

So by hypothesis:
 * $\Pr \left({X = a, Y = b}\right) = \Pr \left({X = a}\right)\Pr \left({Y = b}\right)$

But also by hypothesis:
 * $\Pr \left({X = a, Y = b}\right) \ne \Pr \left({X = a}\right)\Pr \left({Y = b}\right)$

This contradicts our supposition that:
 * $E \left({g \left({X}\right) h \left({Y}\right)}\right) = E \left({g \left({X}\right)}\right) E \left({h \left({Y}\right)}\right)$

for all functions $g, h: \R \to \R$ for which the latter two expectations exist.

So, if the above supposition holds, then $X$ and $Y$ have to be independent.

Necessary Condition
Suppose $X$ and $Y$ are independent.

Let $g, h: \R \to \R$ be any real functions such that $E \left({g \left({X}\right)}\right)$ and $E \left({h \left({Y}\right)}\right)$ exist.

Then:

thus proving that
 * $E \left({g \left({X}\right) h \left({Y}\right)}\right) = E \left({g \left({X}\right)}\right) E \left({h \left({Y}\right)}\right)$

whatever $g$ and $h$ are.