My professor analyzed an algorithm using summations and I am very confused on how he simplified/created a closed form out of the summations. He said he used the change of variable method but he didn't explain how.
(i is a constant here):
$$\sum_{i=1}^{n} \sum_{j=i}^{n} j - i + 1$$ this was simplified to: $$\sum_{i=1}^{n} \sum_{j=1}^{n - i + 1} j$$
I am confused as to how he rearranged the summation. He did another simplification that confused me: $$\frac{1}{2}\sum_{i=1}^{n}(n - i + 1)(n - i + 2)$$ this was simplified to:
$$\frac{1}{2}\sum_{i=1}^{n} i(i + 1)$$
Change of variables by linear substitution. Remember the token is arbitrary; it can be alpha substituted for any token that is freely available, including linear functions of itself. However, for clarity, we'll use the free token, $k$, for a bit.
$$\begin{align}&\qquad\sum_{i=1}^{n} \sum_{j=i}^{n} (j - i + 1) \\&=~\sum_{i=1}^{n} \sum_{k+i-1=i}^{n} (k+i-1 - i + 1) && \text{Substitute }j\gets (k+i-1)\\ &=~\sum_{i=1}^n\sum_{k=1}^{n-i+1} k\\ &=~\sum_{i=1}^{n} \sum_{j=1}^{n - i + 1} j && \text{Substitute }k\gets j\end{align}$$ That is it.