In general, let Sn be the number of squares (n ≥ 1) of a grid with n points on a side.
Then Sn = n * (n -1) * (2n - 1)/6
Note S4 = 4*3*7/6 = 14
S5 =5*4*9/6 = 30
Proof by Mathematical Induction
Let n = 1. With only one point there are no squares.
S1 = 1* 0 * 1/6 = 0, so the formula works with 1 point.
Assume the formula is true for n = k points and consider (k + 1) points.
_ _ _ _B
A |_|_|_|_| This is a rough representation of
|_|_|_|_| what is being done.
|_|_|_|_|
|_|_|_|_|
Start with the grid of size k x k
When another point is added, then the new row A and
new column B are created.
The new grid is now (k+1) x (k+1)
Any new rectangles would be obtained from the new row A
and row B. Let m be the number of new rectangles.
The size of the new rectangles is from size 1 to k.
∴ Sk+1 = Sk + m
The sizes of the new rectangles are from size 1 to k.
The number of new rectangles of size 1 is k from row A and (k-1) from column B.
This is one less than from row A because the top right rectangle has already
been counted as part of the count in row A.
The number of new size 1 rectangles is 2*k-1
The number of new rectangles of size 2, starting from the second column, is (k-1)
and from column B is (k-2). Again the top right rectangle has been included only
once.
The number of new size 2 rectangles is 2*k-3
Continuing this process:
The number of size 3 is 2*k-5
The number of size 4 is 2*k-7
.
.
.
The number of size k-1 is 3
The number of size k is 1
Then the number of new rectangles m = (2k-1) + (2k-3) + .. + 3 + 1
= ∑(2i - 1) [i from 1 to k]
= 2∑i - k
= 2 *k(k+1)/2 - k
= k2 +k - k = k2
From, Sk+1 = Sk + m and Sk= k * (k -1) * (2k - 1)/6
∴ Sk+1 = k * (k -1) * (2k - 1)/6 + k2
= (k/6)(2k2 - 3k + 1 + 6k)
= (k/6)(2k2 + 3k + 1)
= (k/6)(2k+1)(k+1)
= (k+1)([k+1]-1)(2[k+1]-1)/6
Since the result for Sk+1 is the same as Sn evaluated with n=k+1, the result is
true by mathematical induction.
David W.
07/09/16