Magic Squares - Edited

A magic square is a collection of numbers arranged in a square so that the sum of entries in any row, column or diagonal is a constant; the magic constant. A basic introduction to magic squares can be found here.

Magic squares have intrigued people for thousands of years and in ancient times they were thought to be connected with the supernatural and hence, magical.

The squares intrigued me when I found that their construction was far from easy. For the simple 3 x 3, (we say "order 3") magic square, trial and improvement quickly does the job; but for higher than order 4 magic squares a method is necessary. We need to split the problem of construction into two cases because I know of no method which works for constructing magic squares of both even and odd orders. For the purposes of this article, I will be considering only the kind of magic squares that are constructed using consecutive integers from 1 to n2 , where n is the order of the magic square - the number of integers on one side of the square.

Magic squares of odd order are fairly easily constructed using the one of the following methods:

The first two methods are described in some detail on this web site [1] and De Meziriac's method can be found in this book [2]. Another way, which I prefer, is the extended Pyramid method (also called diagonals). This simple method consists of three steps:

  1. Draw a pyramid on each side of the magic square. The pyramid should have two fewer squares on its base than the number of squares on the side of the magic square. This creates a square standing on a vertex.
  2. Sequentially place the numbers 1 to n2 of the n x n magic square in the diagonals as shown in Figures 1 and 2.
  3. Relocate any number not in the n x n square (that appears in the pyramids you added) to the opposite hole inside the square (shaded).

Figure 1


The same Pyramid method can be used for any odd order magic square as shown below for the 5x5 square in Figure 2.

Figure 2


Notice that when used for a given order n this method always produces the same magic squareTo make different ones we can use some special transformation properties of magic squares to alter the squares found by the method above; e.g.

  1. A magic square will remain magic if any number is added to every entry in a magic square.
  2. A magic square will remain magic if every entry is multiplied by a given number.
  3. A magic square will remain magic if two rows, or columns, equidistant from the centre are interchanged.
  4. An even order magic square (n x n where n is even) will remain magic if the quadrants are interchanged.
  5. An odd order magic square will remain magic if the partial quadrants and the row is interchanged. (TODO: this is far from clear)

These transformations of magic squares are subject of another article, found here. (TODO link)

Constructing the even order magic squares does present more of a challenge. There are many different ways, which can be found at [1], a useful starting point if you wish to learn about them. All the methods I have seen in the literature are rather complicated, in that they require the use of two or more algorithms. There are claims for a simple method for the construction of even order magic squares, but I have yet to find one. The following method, which I have developed, uses just one algorithm and will work for any even sided square. I call it the "paired exchange method". The theory behind the paired method is actually fairly straightforward.

Consider the first and last column of an even order n x n magic square. Starting by placing the integers 1 to n2 in order across the rows of the square (see figure 3), the difference between the first and last number in any row will be n - 1. Since there are n rows in the square, there will be a total difference of (n - 1) between the first and last column of the square. To balance the total for the first and last columns we must exchange pairs of numbers between the first and last columns and each exchanged pair must be from the same row, so as not to change the sum total of the row. How many times must we exchange pairs to equalise the columns? When a pair is exchanged in a row the difference between the columns changes by 2(- 1). If t is the number of times pairs must be exchanged, then

t x 2(n - 1) = n (n - 1),
2t = n,
so t = n/2 (an integer since n is even).

Consider the 4 x 4 magic square, so that t = 2. The choice of pairs to exchange is limited if we want the sum of the numbers on the diagonals to equal the magic constant. The pairs must be on the diagonals. By reflecting in the centre lines x and then y we achieve the same as a single reflection in the lines y = x and y = - x . Or to state it another way, we exchange the numbers with their opposite numbers equidistant from the centre along the diagonals (see figure 3). We have exchanged two pairs in each row and column of the square and the results is a magic square. A similar argument can be made for the 2nd and the next to last columns, since the only change in the above formulae will be to substitute (n - 3) for (n - 1). The resulting t stays the same. In the same manner, all columns paired from the centre line of the square can be made to be equal, and since the numbers in the original square are consecutive integers, all the columns will be equal to the magic constant for the n x n magic square. Of course, columns are just rows seen from a different viewpoint, hence all rows can be made to equal the magic constant similarly. Now let's look at a few examples.

Figure 3

 
 

The 6 x 6 magic square is constructed in the same manner, but here t = 3, hence we have much more freedom in our choice of pairs for each column and row. We exchange all the pairs on the diagonal, which is equivalent to exchanging two pairs from each pair of rows and columns, so we must now exchange one more pair from each pair of rows and columns to equalise them. One such choice in the construction of a 6 x 6 magic square is shown in figures 4, 5 and 6 below.

Figure 4


Exchange the pairs in the diagonals.

Here we equalise the rows before the columns, the opposite order to that discussed in the text. It can be done in any order.

Figure 5


Exchange the pairs in the columns.

Figure 6


Exchange the pairs in the rows.

How many other choices we have is possible to calculate, but I will leave that for another time. In the meantime try making a 7 x 7 magic square, or a 8 x 8, or a 10 x 10, or ....

The next article in the series is Magic Squares II (TODO, change)

References

[1] http://mathworld.wolfram.com/MagicSquare.html gives a brief account of many kinds of magic square and their construction methods.
[2] Mathematical Games and Puzzles - page 76, by Trevor Rice and published by B.T Batsford Limited, London.