For a single discrete variable \(X\) with probability function \(p(x)\), the expected value of \(g(X)\) is

\[ E[g(X)] \;=\; \sum_{\text{all }x} {g(x) \times p(x)} \]

Each possible value of \(g(x)\) is weighted by its probability being observed.

For two discrete random variables, we have a similar definition

Definition

If \(X\) and \(Y\) are discrete random variables with joint probability function \(p(x,y)\), then the expected value of a function of the variables, \(g(X,Y)\), is defined to be

\[ E[g(X,Y)] \;=\; \sum_{\text{all }x,y} {g(x,y) \times p(x,y)} \]

This can be expressed as a double-summation,

\[ E[g(X,Y)] \;=\; \sum_{\text{all }x} {\sum_{\text{all }y}{g(x,y) \times p(x,y)}} \]

Example: Maximum – minimum for three dice

Earlier, we gave the joint probability function of the maximum and minimum values in rolls of three fair dice.

\[ p(x,y) \;\;=\;\; \begin{cases} {\large\frac 1 {6^3}} & \quad\text{if }x = y \;\;\text{ and }\;\; 1 \le x,y \le 6 \\[0.4em] {\large\frac {x-y}{6^2}} & \quad\text{if } 1 \le y \lt x \le 6 \\[0.4em] 0 & \quad\text{otherwise} \end{cases} \]

What is the expected value of the difference between the maximum and minimum?

(Solved in full version)