TITLE: How to change the order of summation?
QUESTION [41 upvotes]: I have stumbled upon, multiple times, on cases where I need to change
the order of summation (usally of finite sums).
One problem I saw was simple
$$
\sum_{i=1}^{\infty}\sum_{j=i}^{\infty}f(i,j)=\sum_{j=1}^{\infty}\sum_{i=1}^{j}f(i,j)
$$
and I can go from the first sum to the second by noting that the
constraints are 
$$
1\leq i\leq j<\infty
$$
so the first double sum does not constrain on $i$ and constrains
$j$ to $j\geq i$. The second double summation doesn't put any constrains
on $j$ but constrains $i$ relative to $j$ $(1\leq i\leq j)$.
While this approach works for simple examples such as this. I am having
problems using it where the bounds are more complicated.
The current problem interchanges the following 
$$
\sum_{i=1}^{n-1}\sum_{k=2}^{n-i+1}\to\sum_{k=2}^{n}\sum_{i=1}^{n+1-k}
$$
I started by writing
$$
k\leq n-i+1
$$
and got
$$
i\leq n-k+1
$$
but all other bounds are not clear to me..
the problem is that I can't use this technique since I can't write
the inequalities in the same form of 
$$
1\leq i\leq f(j)\leq n
$$
where $n$ is some bound (possibly $\infty$).
My question is how to approach the second example by a technique that
should be able to handle similar cases

REPLY [13 votes]: I've found the Iverson bracket extremely useful for this sort of calculation. For a reference on the technique, I learned it from Concrete Mathematics 
The Iverson bracket is a function whose argument is a proposition, and is defined by the formula
$$ [P] = \begin{cases} 0 & P \text{ is false} \\ 1 & P  \text{ is true} \end{cases} $$
You use this to express summations, such as
$$ \sum_{n=a}^b f(n) = \sum_{n \in \mathbb{Z}} [a \leq n \leq b] f(n) $$
When using this technique, you generally take all sums to be over all integers and use the Iverson brackets to control which terms are actually summed over. I will henceforth suppress the $\in \mathbb{Z}$.
It's additionally useful to use the convention that when $P$ is false, that $[P]$ is strongly zero; that is, when P is false, we always say $[P] t  = 0$ no matter what $t$ is, even when $t$ is undefined. As an example of this usage:
$$ \frac{\pi^2}{6} = \sum_{n} [n \geq 1] \frac{1}{n^2} $$
Normally we would say the right hand side is undefined, since $\frac{1}{n^2}$ is undefined when $n=0$. But by the "strongly zero" convention, we say that $[n \geq 1] \frac{1}{n^2}$ is well-defined and zero when $n=0$, so this sum makes sense.

Now, to apply it to your example:

$$\sum_{i=1}^{n-1}\sum_{k=2}^{n-i+1}\to\sum_{k=2}^{n}\sum_{i=1}^{n+1-k}$$

$$\sum_{i=1}^{n-1}\sum_{k=2}^{n-i+1}
= \sum_{i,k} [1 \leq i \leq n-1] [2 \leq k \leq n-i+1] $$
Note that $[P][Q] = [P \text{ and } Q]$. Multiplication is somewhat more convenient notation, though, so I leave it expressed as a product.
One could approach this problem by finding a different way of expressing this system of inequalities. We can rewrite them as
$$ 1 \leq i  \qquad i \leq n-1 \qquad \qquad 2 \leq k \qquad \qquad i \leq n+1-k $$
The $i \leq n-1$ condition is redundant. Having "solved" the last inequality for $i$ it's clear that we can rewrite
$$ [1 \leq i \leq n-1] [2 \leq k \leq n-i+1] = [2 \leq k] [1 \leq i \leq n+1-k] $$
Depending on our purposes, it may help to observe the implicit $1 \leq n+1-k$ constraint and solve it for $k$ to make it more explicit, so we have
$$ \ldots = [2 \leq k \leq n] [1 \leq i \leq n+1-k] $$
It's clear now that
$$ \sum_{i,k} [2 \leq k \leq n] [1 \leq i \leq n+1-k] = \sum_{k=2}^n \sum_{i=1}^{n+1-k} $$
if we really want to rewrite the summation back into this form.

One way in which this notation becomes really useful, in my opinion, when you consider changing variables. If I was given
$$ \sum_{i,k} [1 \leq i \leq n-1] [2 \leq k \leq n-i+1] $$
I would often consider simplifying the upper bound by making a substitution $j = n-i+1$ (or $i = n-j+1$), replacing the sum over $i$ with a sum over $j$
$$ \ldots = \sum_{j,k} [1 \leq n-j+1 \leq n-1] [2 \leq k \leq j] 
\\=  \sum_{j,k} [1 \leq n-j+1] [n-j+1 \leq n-1] [2 \leq k \leq j]  
\\=  \sum_{j,k} [j \leq n] [2 \leq j] [2 \leq k \leq j]  
\\=  \sum_{j,k} [2 \leq k \leq j \leq n] $$
which makes it easy to see other ways to rewrite this. E.g. if I wanted to sum over $k$ first, it's clear this becomes
$$ \ldots = \sum_{j,k} [2 \leq k \leq n] [k \leq j \leq n] 
\\= \sum_{k=2}^n \sum_{j=k}^n $$
Or I could change $j$ back to $i$ first if I wanted.