Exchange of Order of Summation with Dependency on Both Indices

Theorem

 * $\displaystyle \sum_{R \left({i}\right)} \sum_{S \left({i, j}\right)} a_{i j} = \sum_{S' \left({j}\right)} \sum_{R' \left({i, j}\right)} a_{i j}$

where:
 * $\displaystyle \sum_{R \left({i}\right)} a_i$ denotes the summation over $a_i$ for all $i$ that satisfy the propositional function $R \left({i}\right)$
 * $S \left({i, j}\right)$ is a propositional function that depends on both $i$ and $j$
 * $S' \left({j}\right)$ denotes the propositional function:
 * there exists an $i$ such that both $R \left({i}\right)$ and $S \left({i, j}\right)$ hold
 * $R' \left({i, j}\right)$ denotes the propositional function:
 * both $R \left({i}\right)$ and $S \left({i, j}\right)$ hold.