Convert a 3-layer nested summation into an algebraic formula I am asked to work out a piece of code (3 nested loops) that can be translated into the following summation:
$\sum\limits_{i=1}^n\ \sum\limits_{j=i+1}^n\ \sum\limits_{k=j+1}^n1$
Can I turn this summation into an algebraic formula, like I can turn $\sum\limits_{i=0}^{n} \binom{n}{i}$ into ${2^{n}}$ ?
Thanks for any advice.
 A: More or less by definition, this summation counts the number of triples $(i, j, k)$ of integers satisfying $1 \leq i < j < k \leq n$. But this just as well counts the unordered triples $(i, j, k)$ of distinct integers $1 \leq i, j, k \leq n$, by counting only the ordered triples $(i, j, k)$ in ascending order, and there are $$\color{#bf0000}{\boxed{{n \choose 3} = \tfrac{1}{6} n (n - 1) (n - 2)}}$$ of these.
A: Proceeding naively:
$\begin{array}\\
\sum\limits_{i=1}^n\ \sum\limits_{j=i+1}^n\ \sum\limits_{k=j+1}^n1
&=\sum\limits_{i=1}^n\ \sum\limits_{j=i+1}^n\ (n-(j+1)+1)\\
&=\sum\limits_{i=1}^n\ \sum\limits_{j=i+1}^n\ (n-j)\\
&=\sum\limits_{i=1}^n\ \left(\sum\limits_{j=i+1}^nn-\sum\limits_{j=i+1}^nj\right)\\
&=\sum\limits_{i=1}^n\ \left(\sum\limits_{j=i+1}^nn-\left(\sum\limits_{j=1}^nj-\sum\limits_{j=1}^ij\right)\right)\\
&=\sum\limits_{i=1}^n\ \left((n-(i+1)+1)n-\frac12(n(n+1)-i(i+1))\right)\\
&=\sum\limits_{i=1}^n\ \left((n-i)n-\frac12(n^2+n-i^2-i)\right)\\
&=\sum\limits_{i=1}^n\ \left(n^2-ni-\frac12(n^2+n-i^2-i)\right)\\
&=\sum\limits_{i=1}^n\ \left(\frac12(2n^2-2ni-n^2-n+i^2+i)\right)\\
&=\frac12\sum\limits_{i=1}^n\ \left(n^2-2ni-n+i^2+i)\right)\\
&=\frac12\left(n(n^2-n)-2n\sum\limits_{i=1}^ni+\sum\limits_{i=1}^ni^2+\sum\limits_{i=1}^ni\right)\\
&=\frac12\left(n(n^2-n)-2n\frac12 n(n+1)+\frac16 n(n+1)(2n+1)+\frac12 n(n+1)\right)\\
&=\frac12\left(n^3-n^2-n^3-n^2+\frac16 (2n^3+3n^2+n)+\frac12 (n^2+n)\right)\\
&=\frac12\left(\frac13 n^3+n^2(-2+\frac12+\frac12)+n(\frac16+\frac12)\right)\\
&=\frac12\left(\frac13 n^3-n^2+\frac23 n\right)\\
&=\frac16 n\left(n^2-3n+2\right)\\
&=\frac16 n(n-1)(n-2)\\
\end{array}
$
Of course there were
a few errors along the way,
but they are not there now:)
