# Converting a double summation to a single summation

The following is an equation from my probability textbook:

$\displaystyle\sum_y\sum_{\{x\ |\ g(x)=y\}}g(x)p_X(x)=\sum_x g(x)p_X(x)$

Could someone please give me a step-by-step explanation of why this is true?

• Probably because probabilities add-up to one.. – Eduardo Longa May 7 '17 at 18:16
• @EduardoLonga I like the probably...in a question on probability ;) – TheGeekGreek May 7 '17 at 18:17

Interpretation 1 (no need for probability): The right-hand side is a sum over all possible values of $x$. The left-hand side is also a sum over all possible values of $x$, but they are "grouped" by the value of $g(x)$ so that you sum over each group first, and then add up the group totals.
Interpretation 2: Leg $p_X$ be the probability mass function of $X$. The right-hand side is $E[g(X)]$ while the left-hand side is $\sum_y E[g(X) \cdot \mathbf{1}_{g(X)=y}]$. The equality follows by noting that $\sum_y \mathbf{1}_{g(x)=y}=1$ for any $x$.