Making magic squares

 16   3   2   13 
 5   10   11   8 
 9   6   7   12 
 4   15   14   1 

This is probably the most famous magic square. It is shown in Dürer's woodcut 'Melancholy' and its properties are that each row and each column and both diagonals add to the same sum of 34. This is called the magic sum. It also uses each of the numbers from 1 to 16 once and only once. This square has one extra property which is that each of the 2 x 2 squares in the corners and the 2 x 2 square in the centre all have the same sum of 34.

Strictly speaking, any magic square should have all these properties except for the last one. So, for example, a 3 x 3 magic square will use the numbers from 1 to 9.
I show below a copy of the earliest known magic square, the Chinese Loh-Shu, from about 2800 BC.

The Loh-Shu square
I've added colour here to make the distinction between the odd and even numbers stand out more clearly. In fact the yellow blobs should be white, being Yang symbols or emblems of heaven, and the red blobs should be black, being Yin symbols or emblems of earth.
Now we'll look at 4 x 4 squares in more detail. If we relax the rule about the numbers having to run from 1 to 16 we can vastly increase the possibilities and also see some interesting maths in action.

All magic squares obey two fundamental rules.
Rule (1)   If you multiply every element in a magic square by the same number then the result is also a magic square.
Here's an example, showing M, the Dürer magic square, and 3M.

 16   3   2   13 
 5   10   11   8 
 9   6   7   12 
 4   15   14   1 
  and  
 48   9   6   39 
 15   30   33   24 
 27   18   21   36 
 12   45   42   3 


You can see that the basic structure of the square is maintained and the new magic square has a magic sum of 3 x 34 = 102.

Rule (2)    If you add two magic squares then the result is also a magic square. I've shown an example of this below, using M and a new square, N.

16 3 2 13
 5   10   11   8 
 9   6   7   12 
 4   15   14   1 
  +  
20 16 6 7
 2   11   13   23 
 19   21   4   5 
 8   1   26   14 
  =  
36 19 8 20
 7   21   24   31 
 28   27   11   17 
 12   16   40   15 

Again, because the internal structures of the squares are unchanged, the result of adding them is another magic square. In this example the magic sums go 34 + 51 = 85.

We could now make some new magic squares using various combinations of M and N but it would be more interesting if we could have a wider variety of starter squares. But how can we get them? Suppose we consider the simplest possibility of all, a square with a magic sum of 1 in which all the entries are either 1 or 0. (Magic squares with very restricted entries like this are sometimes called magic carpets.)
Here is an example of such a square.
100 0
0001
0100
0010

How many others are there like this one? Imagine this square is slotted into a frame. In how many ways is it possible to twist it or turn it over so that it exactly fits in the frame but with the numbers in new positions?


I've shown all the eight possible squares below, using coloured corners so you can see how the twists and turns work.

Starting with A, we then have 1/4, 1/2 and 3/4 turns anticlockwise on the top row and reflections in the horizontal and vertical and two diagonal axes of symmetry of the square on the bottom row. These are the eight symmetry transformations of a square.
Are these magic squares independent of each other or can we describe any one of them in terms of the others? We'll try describing A. We'll have to use G to give us the first one in the top left-hand corner. but then we have to take off the extra ones we've collected in places we don't want them. By a process of adding what we want and taking out what we don't want we get
A = B - C + D - E - F + G + H.

All seven of the other squares are required to describe A so we have found seven base squares to use as a way to build new squares. (You can choose any seven from the eight.) We just need to use our two rules of combination that we wrote down above. Briefly, these are:-
Rule (1)   If Q is a magic square then so also is aQ where a is any chosen whole number which multiplies every entry in Q. (Magic squares always have whole number or integer entries so we want a to be a whole number too.)
Rule (2)   If Q and S are magic squares then so is Q + S.
Here's an example made by taking P = 6A + 2B + C + 8D + 13E + 5F + 11G + 5H.

 17   3   10   21 
 18   13   12   8 
 9   11   15   16 
 7   24   14   6 

In general, we can make new magic squares by working out aA + bB + cC + dD + eE + fF + gG + hH where a,b,c etc stand for our numbers of choice and A,B,C etc stand for the eight magic squares whose magic sum is 1.
Since all the entries in these squares are 1 or 0 we can see how the combination above gives the new magic square by showing how a,b,c etc fit into the entries of the combination square. This is how it works.

a + gb + c f + hd + e
e + hd + f c + ga + b
c + da + hb + e f + g
b + fe + g a + dc + h

Here's A, B, C etc again to make it easier to see how this works.

Can we describe any magic square in terms of these eight squares?
Suppose we have Q = aA + bB + cC + dD + eE + fF + gG + hH.
In fact, we know that we only need seven of the eight since any one of these can be described in terms of the other seven. I'll choose to leave out H by letting h = 0.
Now we need to show that, for any given Q, the numbers a,b,c,d,e,f and g are uniquely determined. I'll take the Dürer magic square as an example of how this works. (Exactly the same argument works in the general case.)
We compare the Dürer square with the square with the letter entries, putting h = 0. I show the two squares below.

163 213
510118
96712
415141
  and  
a + gb + c fd + e
ed + f c + ga + b
c + da b + ef + g
b + fe + g a + dc


Comparing single letter cells gives us f = 2, e = 5, a = 6 and c = 1.
Then a + g = 16 so g = 10 and b + c = 3 so b = 2 and d + e =13 so d = 8. These values are consistent with all the other entries.
We see the Dürer square is given by   6A + 2B + C + 8D + 5E + 2F + 10G.
So where is the link to other maths?
Let's look at the two rules of combination again. These are:
Rule (1)   If Q is a magic square then so also is aQ where a is any chosen whole number which multiplies every entry in Q.
Rule (2)   If Q and S are magic squares then so is Q + S.

These are the same rules which we use for handling vectors where the vectors are representing such things as displacement, force or velocity except that, with magic squares, we are dealing with only whole number entries. Also, working in our 3-dimensional world, we find we can describe any such vector as a combination of the three base vectors i, j and k using exactly the same two rules. These three vectors form what mathematicians call a basis for a 3-dimensional space which contains all the possible displacement, force or velocity vectors with which we are working. (In fact, any three vectors in this space can form a basis provided none of them are parallel and, between them, they involve each of the vectors i, j and k at least once.) In just the same way, we have found a basis of seven magic squares which can describe any 4 x 4 magic square. It seems we are in a 7-dimensional vector space if we widen the definition of vectors to include anything which obeys the two rules of combination above. Sometimes mathematicians find it convenient to do this.
There is one other difference between the magic square vectors and the vectors which represent displacement, force , velocity etc. Can you see what it is?
Now I'll do some measuring

The second group of vectors all have a property of magnitude associated with them so, for example, displacement has a length and force has a size. Magic squares have no obvious defined magnitude.
Back to the book homepage