Magic Squares
A Chinese legend tells the story of a flood by the Lo river. People offered sacrifices to appease the river. Each time a turtle emerged, walked around the sacrifice, and returned to the water. Fuh-Hi, the founder of Chinese civilization, interpreted this to mean that the river was still cranky. Fortunately, a child noticed that on its shell the turtle had the pattern on the left below, which is today called Lo Shu (“river scroll”).
The dots make the matrix on the right where the rows, columns, and diagonals add to . Now that the people knew how much to sacrifice, the river’s anger cooled.
A square matrix is magic if each row, column, and diagonal adds to the same number, the matrix’s magic number.
Another magic square appears in the engraving Melencolia I by Dürer.
One interpretation is that it depicts melancholy, a depressed state. The figure, genius, has a wealth of fascinating things to explore including the compass, the geometrical solid, the scale, and the hourglass. But the figure is unmoved; all of the things lie unused. One of the potential delights, in the upper right, is a matrix whose rows, columns, and diagonals add to .
The middle entries on the bottom row give , the date of the engraving.
The above two squares are arrangements of . They are normal. The square whose sole entry is is normal, Exercise 2 shows that there is no normal magic square, and there are normal magic squares of every other size; see [Wikipedia, Magic Square]. Finding how many normal magic squares there are of each size is an unsolved problem; see [Online Encyclopedia of Integer Sequences].
If we don’t require that the squares be normal then we can say much more. Every square is magic, trivially. If the rows, columns, and diagonals of a matrix
add to then , , , , , and . Exercise 2 shows that this system has the unique solution . So the set of magic squares is a one-dimensional subspace of .
A sum of two same-sized magic squares is magic and a scalar multiple of a magic square is magic so the set of magic squares is a vector space, a subspace of . This Topic shows that for the dimension of is . The set of magic squares with magic number is another subspace and we will verify the formula for its dimension also: when .
We will first prove that . Define the trace of a matrix to be the sum down its upper-left to lower-right diagonal . Consider the restriction of the trace to the magic squares . The null space is the set of magic squares with magic number zero . Observe that the trace is onto because for any in the codomain the matrix whose entries are all is a magic square with magic number . Theorem Two.II.2.14 says that for any linear map the dimension of the domain equals the dimension of the range space plus the dimension of the null space, the map’s rank plus its nullity. Here the domain is , the range space is and the null space is , so we have that .
We will finish by finding the dimension of the vector space . For the dimension is clearly . Exercise 3 shows that is also for .
That leaves showing that for . The fact that the squares in this vector space are magic gives us a linear system of restrictions, and the fact that they have magic number zero makes this system homogeneous: for instance consider the case. The restriction that the rows, columns, and diagonals of
add to zero gives this linear system.
We will find the dimension of the space by finding the number of free variables in the linear system.
The matrix of coefficients for the particular cases of and are below, with the rows and columns numbered to help in reading the proof. With respect to the standard basis, each represents a linear map . The domain has dimension so if we show that the rank of the matrix is then we will have what we want, that the dimension of the null space is .
We want to show that the rank of the matrix of coefficients, the number of rows in a maximal linearly independent set, is . The first rows of the matrix of coefficients add to the same vector as the second rows, the vector of all ones. So a maximal linearly independent must omit at least one row. We will show that the set of all rows but the first is linearly independent. So consider this linear relationship.
Now it gets messy. Focus on the lower left of the tables. Observe that in the final two rows, in the first columns, is a subrow that is all zeros except that it starts with a one in column and a subrow that is all zeros except that it ends with a one in column .
First, with omitted, both column and column contain only two ones. Since the only rows in () with nonzero column entries are rows and , which have ones, we must have . Likewise considering the -th entries of the vectors in () gives that .
Next consider the columns between those two— in the table this includes only column while in the table it includes both columns and . Each such column has a single one. That is, for each column index the column consists of only zeros except for a one in row , and hence .
On to the next block of columns, from through . Column has only two ones (because the ones in the last two rows do not fall in the first column of this block). Thus and therefore . Likewise, from column we conclude that and so .
Because there is at least one column between column and column . In at least one of those columns a one appears in . If a one also appears in that column in then we have since for . If a one does not appear in that column in then we have . In either case , and thus and .
If the next block of -many columns is not the last then similarly conclude from its first column that .
Keep this up until we reach the last block of columns, those numbered through . Because column gives that .
Therefore the rank of the matrix is , as required.
The classic source on normal magic squares is [Ball & Coxeter]. More on the Lo Shu square is at [Wikipedia, Lo Shu Square]. The proof given here began with [Ward].
Exercises
Exercise 1 Supplied answer
Let be a magic square with magic number .
Prove that the sum of ’s entries is .
Prove that .
Prove that is the average of the entries in its row, its column, and in each diagonal.
Prove that is the median of ’s entries.
Answer.
The sum of the entries of is the sum of the sums of the three rows.
The constraints on entries of involving the center entry make this system.
Adding those four equations counts each matrix entry once and only once, except that we count the center entry four times. Thus the left side sums to while the right sums to . So .
The second row adds to so , giving that . The same goes for the column and the diagonals.
By the prior exercise either both and are equal to or else one is greater while one is smaller. Thus is the median of the set . The same reasoning applied to the second column shows that Thus is the median of the set . Extending to the two diagonals shows it is the median of the set of all entries.
Exercise 4 Supplied answer
Let the trace function be . Define also the sum down the other diagonal .
Show that the two functions are linear.
Show that the function given by is linear.
Generalize the prior item.
Answer.
Where we have where all numbers are real, so the trace preserves linear combinations. The argument for is similar.
It preserves linear combinations: where all numbers are real, .
Where are linear then so is given by . The proof just follows the proof of the prior item.
Exercise 5 Supplied answer
A square matrix is semimagic if the rows and columns add to the same value, that is, if we drop the condition on the diagonals.
Show that the set of semimagic squares is a subspace of .
Show that the set of semimagic squares with magic number is also a subspace of .
Answer.
The sum of two semimagic squares is semimagic, as is a scalar multiple of a semimagic square.
As with the prior item, a linear combination of two semimagic squares with magic number zero is also such a matrix.
References cited in this section
Wikipedia, Magic Square
Magic square, http://en.wikipedia.org/wiki/Magic_square, 2012-Feb-17.
Online Encyclopedia of Integer Sequences
Number of different magic squares of order n that can be formed from the numbers , …, , http://oeis.org/A006052, 2012-Feb-17.
Ball & Coxeter
W.W. Rouse Ball, Mathematical Recreations and Essays, revised by H.S.M. Coxeter, MacMillan, 1962.
Wikipedia, Lo Shu Square
Lo Shu Square, http://en.wikipedia.org/wiki/Lo_Shu_Square, 2012-Feb-17.
Ward
James E. Ward III, Vector Spaces of Magic Squares, Mathematics Magazine, vol 53 no 2 (Mar 1980), p 108–111.