Sums of squares and cubes¶
Patterns and sequences · level 7, lesson 5 of 6
A question to start¶
Cannonballs used to be stacked in square pyramids: one ball on top, then a layer of 2 by 2, then 3 by 3, and so on down to the bottom layer. A pyramid with a 10 by 10 base holds
How many is that? You can add it up (try it), but what about a pyramid with a 100 by 100 base? And here is something stranger. Add up cubes instead:
Every answer is a perfect square: \(1^2, 3^2, 6^2, 10^2\). And the numbers being squared, 1, 3, 6, 10, are the triangular numbers. Coincidence? This lesson finds formulas for both sums and proves why they are true.
The idea¶
Why the old trick does not work¶
For \(1 + 2 + \cdots + n\) we wrote the sum forwards and backwards, and every column added to the same number (lesson 2). Try that with squares: \(1^2 + 2^2 + 3^2\) forwards and \(3^2 + 2^2 + 1^2\) backwards give columns \(10, 8, 10\). Not equal. The squares are not evenly spaced, so pairing the ends fails. We need new ideas: first a way to guess the formula, then a way to prove it.
Step 1: guess the shape with differences¶
Let \(S(n) = 1^2 + 2^2 + \cdots + n^2\). Make a table and take differences, as in level 5:
| \(n\) | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| \(S(n)\) | 0 | 1 | 5 | 14 | 30 | 55 | 91 |
| 1st differences | 1 | 4 | 9 | 16 | 25 | 36 | |
| 2nd differences | 3 | 5 | 7 | 9 | 11 | ||
| 3rd differences | 2 | 2 | 2 | 2 |
The first differences are just the squares (of course: each step adds the next square). The third differences are constant, so \(S(n)\) is a cubic: \(S(n) = an^3 + bn^2 + cn + d\). (A quadratic has constant second differences; a cubic has constant third differences.)
Step 2: find the coefficients¶
Put in \(n = 0, 1, 2, 3\):
- \(n = 0\): \(d = 0\).
- \(n = 1\): \(a + b + c = 1\).
- \(n = 2\): \(8a + 4b + 2c = 5\).
- \(n = 3\): \(27a + 9b + 3c = 14\).
Take twice the second equation from the third: \(6a + 2b = 3\). Take three times the second from the fourth: \(24a + 6b = 11\). Then take three times \(6a + 2b = 3\) from that: \(6a = 2\), so \(a = \frac13\), then \(b = \frac12\), then \(c = 1 - \frac13 - \frac12 = \frac16\). So
This fits \(n = 0, 1, 2, 3\) by construction. Check it on one we did not use: \(n = 6\) gives \(\frac{6 \times 7 \times 13}{6} = 91\). ✓ But a guess that fits the table is still a guess. (Patterns can trick you, as level 3 showed.) We need a proof.
Step 3: prove it by telescoping¶
Here is a proof that needs nothing but algebra and the collapsing sums of lesson 1. Expand
Write this out for \(k = 1, 2, \ldots, n\) and add all \(n\) lines:
On the left, everything cancels except \((n + 1)^3 - 1\). On the right, we get three sums:
Now solve for \(S(n)\). Move the last two terms over, noting \(-1 - n = -(n + 1)\):
And \(n^2 + \frac{n}{2} = \frac{n(2n + 1)}{2}\), so \(3S(n) = \frac{n(n + 1)(2n + 1)}{2}\), which gives
for every \(n\), not just the ones in the table. The same trick with \((k + 1)^2 - k^2 = 2k + 1\) gives Gauss's sum \(\sum k = \frac{n(n+1)}{2}\), and with \((k + 1)^4 - k^4\) it gives the sum of cubes. Each formula is built from the one before.
(There is also a lovely picture proof: three copies of the cannonball pyramid, made of unit cubes, can be fitted together into a box measuring \(n\) by \(n + 1\) by \(n + \frac12\). The volume of that box is three times the sum.)
The cubes: a square made of L-shapes¶
Now the second surprise: \(1^3 + 2^3 + \cdots + n^3 = (1 + 2 + \cdots + n)^2\). Here is the picture for \(n = 3\). Take a square of side \(1 + 2 + 3 = 6\). Cut it into a small square and two L-shaped borders, at sides 1, 3 and 6 (the triangular numbers).
The pieces have areas \(1\), \(8\) and \(27\), which are \(1^3\), \(2^3\) and \(3^3\), and together they make the \(6 \times 6\) square. So \(1^3 + 2^3 + 3^3 = 6^2\).
Why this works for every \(n\). Write \(T_k = \frac{k(k + 1)}{2}\) for the \(k\)th triangular number. The \(k\)th L-shape is the square of side \(T_k\) with the square of side \(T_{k-1}\) removed, so its area is
Now \(T_k - T_{k-1} = k\) (the triangle grows by a row of \(k\)), and \(T_k + T_{k-1} = \frac{k(k + 1)}{2} + \frac{(k - 1)k}{2} = \frac{k \cdot 2k}{2} = k^2\) (two neighbouring triangles make a square, as in level 3). So the \(k\)th L-shape has area \(k \cdot k^2 = k^3\). Stacking the L-shapes for \(k = 1, 2, \ldots, n\) fills the square of side \(T_n\), so
This is sometimes called Nicomachus's theorem, after a Greek writer of about 100 CE who described the pattern behind it.
Worked examples¶
1. The cannonballs. A square pyramid with a 10 by 10 base: \(\frac{10 \times 11 \times 21}{6} = \frac{2310}{6} = 385\) balls. With a 100 by 100 base: \(\frac{100 \times 101 \times 201}{6} = 338\,350\) balls.
2. A sum that does not start at 1. Find \(11^2 + 12^2 + \cdots + 20^2\).
3. Mixing the formulas. Find \(1 \times 2 + 2 \times 3 + 3 \times 4 + \cdots + 10 \times 11\).
The \(k\)th term is \(k(k + 1) = k^2 + k\), so the sum splits:
In general, \(\sum_{k=1}^{n} k(k + 1) = \frac{n(n+1)(2n+1)}{6} + \frac{n(n+1)}{2} = \frac{n(n+1)}{6}(2n + 1 + 3) = \frac{n(n + 1)(n + 2)}{3}\). For \(n = 10\): \(\frac{10 \times 11 \times 12}{3} = 440\). ✓
4. The odd squares. Find a formula for \(1^2 + 3^2 + 5^2 + \cdots + (2n - 1)^2\).
\((2k - 1)^2 = 4k^2 - 4k + 1\), so the sum is
Check \(n = 3\): \(1 + 9 + 25 = 35\) and \(\frac{3 \times 5 \times 7}{3} = 35\). ✓
5. A big sum of cubes. \(1^3 + 2^3 + \cdots + 100^3 = 5050^2 = 25\,502\,500\).
Try it¶
- Find \(1^2 + 2^2 + \cdots + 20^2\).
- Find \(1^3 + 2^3 + \cdots + 20^3\).
- Find \(\displaystyle\sum_{k=1}^{10} (3k^2 - 2k)\).
- How many squares of all sizes are there on an 8 by 8 chessboard? (Hint: count the \(1 \times 1\), \(2 \times 2\), ... squares. How many positions does a \(7 \times 7\) square have?)
- For which \(n\) is \(1^3 + 2^3 + \cdots + n^3 = 2025\)?
- Find \(2^2 + 4^2 + 6^2 + \cdots + 20^2\).
- A rectangle on a chessboard is fixed by choosing two of the 9 vertical grid lines and two of the 9 horizontal ones. Show that an 8 by 8 board has \(36^2\) rectangles, and explain why this equals \(1^3 + 2^3 + \cdots + 8^3\).
- Show that \(1^3 + 3^3 + 5^3 + \cdots + (2n - 1)^3 = n^2(2n^2 - 1)\), by taking the even cubes away from all the cubes up to \((2n)^3\).
Answers
- \(\frac{20 \times 21 \times 41}{6} =\) 2870.
- \(\left(\frac{20 \times 21}{2}\right)^2 = 210^2 =\) 44 100.
- \(3 \times 385 - 2 \times 55 = 1155 - 110 =\) 1045.
- A \(k \times k\) square can start in \(9 - k\) places across and \(9 - k\) places down, so there are \((9 - k)^2\) of them: \(64\) of size 1, \(49\) of size 2, ..., \(1\) of size 8. The total is \(1^2 + 2^2 + \cdots + 8^2 = \frac{8 \times 9 \times 17}{6} =\) 204.
- We need \(\left(\frac{n(n+1)}{2}\right)^2 = 2025 = 45^2\), so \(\frac{n(n+1)}{2} = 45\), \(n(n + 1) = 90\), \(n = 9\).
- \(2^2(1^2 + 2^2 + \cdots + 10^2) = 4 \times 385 =\) 1540.
- Two of 9 lines can be chosen in \(\frac{9 \times 8}{2} = 36\) ways, both across and down, so there are \(36 \times 36 = 36^2 = 1296\) rectangles. And \(36 = 1 + 2 + \cdots + 8\), so by Nicomachus's theorem \(36^2 = 1^3 + 2^3 + \cdots + 8^3\). (Two ways of counting the same thing must agree: a favourite trick in Counting.)
- All cubes up to \((2n)^3\): \(\left(\frac{2n(2n+1)}{2}\right)^2 = n^2(2n + 1)^2\). The even cubes: \(2^3 + 4^3 + \cdots + (2n)^3 = 8(1^3 + \cdots + n^3) = 8 \cdot \frac{n^2(n+1)^2}{4} = 2n^2(n + 1)^2\). The odd cubes are the difference: \(n^2\bigl[(2n + 1)^2 - 2(n + 1)^2\bigr] = n^2(4n^2 + 4n + 1 - 2n^2 - 4n - 2) = n^2(2n^2 - 1)\). Check \(n = 2\): \(1 + 27 = 28 = 4 \times 7\). ✓
Common mistake¶
Thinking the sum of squares is the square of the sum. \(1^2 + 2^2 + 3^2 = 14\), but \((1 + 2 + 3)^2 = 36\). For cubes, by a lucky theorem, the sum is the square of \(1 + 2 + \cdots + n\); for squares it is not.
Trusting a fitted formula without proof. Four points always fit some cubic. That the cubic keeps working for every \(n\) needs a proof, such as the telescoping argument, or the induction proof you will write in level 8.
Where it leads¶
- Back: Recursion and the golden ratio · Next: Sequences as functions.
- Level 7 page · Patterns topic page
- Differences and quadratic patterns: Level 5. Square and triangular numbers as dots: Level 3.
- Proving formulas like these by induction: Level 8.
- The sum of squares is what you need to find the area under \(y = x^2\) with thin rectangles, the first integral in calculus: MAT137 Unit 7.