Exchange of Order of Summation with Dependency on Both Indices

Theorem
Let $R: \Z \to \left\{ {\mathrm T, \mathrm F}\right\}$ be a propositional function on the set of integers.

Let $S: \Z \times \Z \to \left\{ {\mathrm T, \mathrm F}\right\}$ be a propositional function on the Cartesian product of the set of integers with itself.

Let $\displaystyle \sum_{R \left({i}\right)} x_i$ denote a summation over $R$.

Let the fiber of truth of both $R$ and $S$ be finite.

Then:
 * $\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:
 * $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.