# Why these $2$ methods give the exact same answer for sum of squares?

Consider $$n = 8$$, the sum of squares from $$1$$ through $$8$$ is:

$$1 \times 1 + 2 \times 2 + 3 \times 3 + 4 \times 4 + 5 \times 5 + 6 \times 6 + 7 \times 7 + 8 \times 8 = 204$$.

Also, equal to $$1 \times 8 + 3 \times 7 + 5 \times 6 + 7 \times 5 + 9 \times 4 + 11 \times 3 + 13 \times 2 + 15 \times 1 = 204$$.

The second one logic is that I start with $$1$$, then I increment by $$2$$ each time and subtract $$1$$ from the second one, until I reach $$1$$.

For $$n = 2$$.
$$1 \times 1 + 2 \times 2 = 4 = 1 \times 2 + 3 \times 1$$.

For $$n = 3$$.

$$1 \times 1 + 2 \times 2 + 3 \times 3 = 1 \times 3 + 3 \times 2 + 5 \times 1$$

The question is, why is it supposed to be the equal the one above? I tried it with a lot of values for $$n$$?

Visual proof of $$\sum_{k=1}^{n}k^2=\sum_{k=1}^{n} (2k-1)(n+1-k).$$ Take a look at this picture for $$n=5$$.

$$1+2^2+3^2+4^2+5^2=\underbrace{1\cdot 5}_{k=1}+\underbrace{3\cdot 4}_{k=2} +\underbrace{5\cdot 3}_{k=3}+ \underbrace{7\cdot 2}_{k=4}+ \underbrace{9\cdot 1}_{k=5}.$$

• +1 Absolutely brilliant ! – Sinπ Feb 4 at 10:37
• Very nice illustration ! $\to +1$ – Claude Leibovici Feb 4 at 11:07
• Thanks for your nice comments! – Robert Z Feb 4 at 13:00

The first sum is $$\sum _{n=1} ^k n^2$$ , while the second sum is $$\sum _{n=1} ^k (2n-1)(k+1-n)$$ .

Let us try to relate the two. We have :-

$$\sum _{n=1} ^k(2n-1)(k+1-n) =k\sum _{n=1} ^k(2n-1) -2\cdot\sum_{n=1} ^kn^2+\sum_{n=1}^kn+\sum_{n=1}^k2n-1$$ $$=2k\cdot\frac{k\cdot(k+1)}{2} - k^2 -2\sum_{n=1}^kn^2+\frac{k\cdot(k+1)}{2} +2\cdot\frac{k(k+1)}{2}-k= \frac{k\cdot(k+1)\cdot(2k+1)}{2}-2\sum _{n=0}^kn^2= 3\cdot \sum _{n=0}^kn^2-2\sum _{n=0}^kn^2=\boxed {\sum _ {n=1} ^k n^2}$$

• Second term in second row should be $k(k+1)$ instead of $k$ because it comes from $k\sum_{n=0}^k1$. – gandalf61 Feb 4 at 11:01
• @gandalf61 It seems I’ve made quite a bunch of silly errors ! Thank you for pointing one out . – Sinπ Feb 4 at 11:12

Alternatively: $$\sum_{k=1}^n k^2=1^2+2^2+3^2+\cdots +n^2=\\ \color{red}1+(\color{red}1+\color{blue}3)+(\color{red}1+\color{blue}3+\color{green}5)+\cdots +(\color{red}1+\color{blue}3+\color{green}5+\cdots +\color{brown}{(2n-1)})=\\ \color{red}1\cdot n+\color{blue}3\cdot (n-1)+\color{green}5\cdot (n-2)+\cdots +\color{brown}{(2n-1)}\cdot 1.$$

Note: This is an algebraic presentation of Robert Z's wonderful PWW!

We have $$\sum_{k=1}^j (2k-1)\cdot (j+1-k)=(j+1)\sum_{k=1}^j (2k-1)-2\sum_{k=1}^j k^2+\sum_{k=1}^j k$$ $$=(j+1)j^2-\frac{j(j+1)(2j+1)}{3}+\frac{j(j+1)}{2}$$ $$=\frac{j(j+1)(2j+1)}{6}=\sum_{k=1}^j k^2$$ showing that the equality is no coincidence , but holds for every positive integer $$j$$.

Proof by induction that $$\sum_{k=1}^{n} (2k-1)(n-k+1) = \sum_{k=1}^{n} k^2 \space \forall n \ge 1$$:

Base case: For $$n=1$$ we have $$1 \times 1 = 1$$

Assume true for $$n=k$$.

For $$n=k+1$$:

$$\sum_{k=1}^{n+1} (2k-1)((n+1)-k+1) \\ =\sum_{k=1}^{n+1} (2k-1)((n-k+1) + \sum_{k=1}^{n+1} (2k-1) \\ =\sum_{k=1}^{n} (2k-1)((n-k+1) + (2(n+1)-1)(n-(n+1)+1) + \sum_{k=1}^{n+1} (2k-1) \\ =\sum_{k=1}^{n} k^2 +(2n+1)\times0 + (n+1)^2 \\ =\sum_{k=1}^{n+1} k^2$$

Nice observation!

It is indeed true that $$\sum_{k=0}^{n - 1} (2 k + 1) (n - k) = \sum_{k=1}^{n} k^2$$.

This can be proved by using the formulas for $$\sum 1, \sum k, \sum k^2$$.

In you increase $$n$$ by $$1$$, all terms increase by $$2k+1$$ and there comes an extra term $$2n+1$$. Then $$k^2+2k+1=(k+1)^2$$.