# The sum of squares revisited

February 24, 2016

In my previous note, I was interested in finding simple approaches for determining the closed form formula for the sum of squares for the first $$n$$ natural numbers:

$1^2 + 2^2 + 3^2 + \cdots + n^2 = \frac{n(n+1)(2n+1)}{6}$

While studying nonparametric statistical analysis methodologies, I came across another approach, which I think is beautiful. The method is described in Practical Nonparametric Statistics, Second Edition, pp. 39-40 [John Wiley and Sons, 1980] by W.J. Conover.

Let $$S$$ be the sum of squares of the first $$n$$ natural numbers, such that

$S = 1^2 + 2^2 + 3^2 + \cdots + n^2.$

This can be rewritten as:

\begin{aligned} S = 1 + 2 + 3 + 4 + \cdots + n\ + &\\ 2 + 3 + 4 + \cdots + n\ + &\\ 3 + 4 + \cdots + n\ + &\\ 4 + \cdots + n\ + &\\ \cdots &\\ n &. \end{aligned}

Each row of sums is the sum of the first $$n$$ natural numbers, minus the sum of the first $$(i - 1)$$ natural numbers, where $$i$$ is the row number. For instance, the third row of sums $$(3 + 4 + \cdots + n)$$ can be rewritten as $$(1 + 2 + 3 + 4 + \cdots + n) - (1 + 2)$$. In general, therefore, the sum of row $$i$$ can be written as:

$R_i = \frac{n(n + 1)}{2} - \frac{i(i - 1)}{2} = \frac{n^2 + n + i - i^2}{2}.$

Since we have $$n$$ rows, the sum of squares is given by:

\begin{aligned} S &= \sum_{i = 1}^{n}R_i\\ &= \sum_{i = 1}^{n}(\frac{n^2 + n + i - i^2}{2})\\ &= \sum_{i = 1}^{n}\frac{n^2}{2} + \sum_{i = 1}^{n}\frac{n}{2} + \sum_{i = 1}^{n}\frac{i}{2} - \sum_{i = 1}^{n}\frac{i^2}{2}\\ &= \frac{n^3}{2} + \frac{n^2}{2} + \frac{n(n+1)}{4} - \frac{S}{2}\\ &= \frac{2n^3 + 2n^2 + n^2 + n - 2S}{4}\\ &= \frac{2n^3 + 3n^2 + n - 2S}{4}. \end{aligned}

This gives us

$4S + 2S = 2n^3 + 3n^2 + n = n(n+1)(2n+1),$

and therefore,

$S = \frac{n(n+1)(2n+1)}{6}.$