DS in the Real World
MAGIC SQUARES AS GIFTS
Magic squares of numbers are beautiful objects that connect mathematics with part of their history; moreover, their understanding does not require too elaborate knowledge. Here we give an unconventional way to approach these squares from systems of linear equations. We will see how solving this equation allows you to build your own square, with your date of birth on the front line!
A square of numbers and a turtle
A magic square is an arrangement of n² numbers placed in the boxes of an n×n square so that the sums along each line, each column, and the two main diagonals are equal. The oldest of these squares has its origin in China. It includes the numbers 1,2,…,9 arranged on a 3×3 square; the associated sum is therefore equal to 15:
4+9+2=3+5+7=8+1+6=15,
4+3+8=9+5+1=2+7+6=15,
4+5+6=2+5+8=15.
This square is universally known as Luo Shu. The word “shu” means turtle, while Luo is the name of a river. An old legend says that during a flood, the Chinese emperor went there to offer flowers and plants as offerings to the gods. A turtle has put them all back on the edge of the river. This turtle had on its shell 45 marks arranged like the numbers which appear in the magic square 3 × 3.
Among all the magic squares, the most famous is undoubtedly that of Khajuraho, also called Chautisa Yantra (the word “chautisa” means 34).
It is important to note that in general, the terminology “magic square” is only used for squares n × n filled with the numbers 1,2, …, n². For these squares, the value of the corresponding sum is therefore equal to
But for now, our goal here is to do some linear algebra, we will drop these restrictions.
How to “rediscover” all 3 × 3 magic squares
Here is the first calculation. We have indicated that we are not going to impose any a priori condition on the numbers to be used other than the “magic properties”, that is to say, that the sums along the lines, columns, and the two main diagonals are the same. For 3 × 3 squares, this means that we are looking for the “most general” formulas for the “unknowns” x, y, z, u, v, w, p, q, r so as to satisfy the equalities.
x+y+z=u+v+w=p+q+r=
=x+u+p=y+v+q=z+w+r=
=x+v+r=z+v+p,
the square under consideration being
This calculation is not difficult. It seems to have been made for the first time by Édouard Lucas in the 19th century. The formulas are expressed as follows:
Here, the numbers ℓ, m, n are arbitrary (they can be non-integer, even non-real!). Indeed :
(ℓ-m) + (ℓ + m + n) + (ℓ-n) = 3ℓ,
(ℓ + m-n) + (ℓ) + (ℓ-m + n) = 3ℓ,
(ℓ + n) + (ℓ-m-n) + (ℓ + m) = 3ℓ,
(ℓ-m) + (ℓ + m-n) + (ℓ + n) = 3ℓ,
(ℓ + m + n) + (ℓ) + (ℓ-m-n) = 3ℓ,
(ℓ-n) + (ℓ-m + n) + (ℓ + m) = 3ℓ,
(ℓ-m) + (ℓ) + (ℓ + m) = (ℓ-n) + (ℓ) + (ℓ + n) = 3ℓ.
If we want the numbers 1,…, 9 to appear, we have to take ℓ = 5. Indeed, the sum of all the coefficients is 9ℓ, and it is equal to:
1 + 2 + … + 9 = 45.
From there, it is not difficult to determine all the possibilities: there are 8. The squares obtained correspond to each other by geometric movements (4 rotations and 4 reflections [1]). Luo Shu is obtained by making m = 1 and n = 3.
Another interesting 3 × 3 magic square is deduced by doing ℓ = 59, m = −12 and n = 42. It is the magic square of smallest (distinct) prime numbers that can exist.
4 × 4 (pan)magic squares
A magic square is said to be pan magic (or diabolical) if the sums along all the diagonals (including those which are broken [2]) are the same. The 3 × 3 magic squares are never pan magic, except obviously if the numbers of all the boxes are equal (this follows directly from the formulas of Lucas above). On the other hand, there exist 4 × 4 pan magic squares, even with the numbers 1,2,…, 16. In fact, Chautisa Yantra, observed above, is an example.
It turns out that for pan magic squares, other combinations than those of rows, columns and diagonals also lead to the same sum. In other words, pan magic relationships lead to new relationships (here we recognize the idea of “linear dependence”), so that from the 16 that we originally imposed (4 rows, 4 columns, 8 diagonals, represented by the first, second, third and last square below), we finally arrive at 52. This is illustrated below for Chautisa Yantra. In each square, the numbers of the boxes of the same color have the sum of 34.
There are 384 different ways to put the numbers 1,2,…, 16 on a 4 × 4 square so as to obtain a pan magic square. In addition, one can move from one to the other by very special movements [3]. As for the most general formula for a 4 × 4 pan magic square, its calculation is still a nice exercise in linear algebra. A particularly comfortable way to express it is as follows:
Test at least that the 52 sums above give the same value with these general algebraic expressions. You will surprise yourself!
Ramanujan’s magic square
Srinivasa Ramanujan, a famous Indian mathematician, composed the magic square below for himself [4]. Even if he satisfies only 36 of the 52 relationships of the Chautisa Yantra, he has the distinction of entering his date of birth on the first line: December 22, 1887 [5].
Why didn’t Ramanujan try to create a pan magic square with his date of birth on the front line? The answer comes from the general formula above. Indeed, we clearly see that to obtain such a pan magic square composed of whole numbers, the date of birth must lead to a sum a + b + c + d which is even. However, for Ramanujan, this sum is equal to 22 + 12 + 18 + 87 = 139 … Nothing to do.
For any prescribed first line there is, however, a square with all the relationships of that of Ramanujan and whole numbers. Below, the most general formula for a 4 × 4 square that satisfies that the 34 combinations above lead to the same sum.
Put your date of birth on the first line, give any values to m and n, and calculate your own magic square!
And there we go! By magic squares, the world of human beings is inexorably divided in two. On the one hand, there are those (wealthy) who were born on a date that gives an even number, and who therefore have wholes numbers of pan magic squares [6]. On the other, there are those like the unfortunate Ramanujan — or myself — who only have half-pan magic squares, because of being born on an odd date …
The 5 × 5 pan magic squares as ordinary
One of the greatest mathematicians in history, Leonhard Euler, was very interested in magic squares, and he even wrote a paper on them. He was born on April 15, 1707, and died on September 18, 1783 (age 77). In his honor, I composed the lower square. You will quickly notice: the numbers in the colored boxes correspond to his dates of birth and death, and the square is pan magic with a sum equal to 77. I was forced, all the same, to put negative values.
It should be added that on any 5 × 5 pan magic square there are additional relationships that appear. Indeed, for any “pentagonal configuration” (staggered) as below (and centered at any point [7]), the sum remains the same as for the rows, columns, and diagonals. Thus, for the Euler obituary square above, there are 120 configurations of numbers whose sum is 77 (count 5 rows, 5 columns, 10 diagonals and 4 x 25 = 100 staggered).
And here is the general formula of 5 × 5 magic pan squares from which we can easily see the additional relationships of staggered rows [8].
It is interesting to note that the sum associated with this square is equal to
k+ℓ+m+n+p+q+r+s−3μ.
Consequently, if one wishes to place a person’s dates of birth and death on a pan magic square as higher having as a sum the number of years lived, a certain condition of divisibility by 3 must be satisfied by these numbers. Again, Ramanujan comes out unhappy.
Finally, let’s forget the dates a bit to admire the most beautiful of the 5 × 5 pan magic squares. It is made up of the numbers 1,…, 25, and it has the additional property that the sum of the number of each cell plus the one in the opposite cell with respect to the center is equal to 26, the central cell is occupied by 13 = 26/2 [9].
The size of the squares
The presentation of magic squares as derived from systems of linear equations is not the most usual, in part because an old tradition wants them to be filled with consecutive numbers, and it is not at all clear in looking at the general solutions higher than what can be done.
It is therefore not strange that a lot of researchers, starting with Nārāyaṇa in India and Philippe de la Hire in France (who was perhaps the first researcher of the “modern” period of magic squares in the West), and in passing through Euler and even Ramanujan, sought to write magic squares like Greco-Latin squares. Recall that a Greco-Latin square is a square n × n which is the sum of two squares with the property of being filled with n distinct numbers each of which appears n times but never on the same line or on the same column. Here is such writing for 5 × 5 pan magic squares. Test at least that the pan magic properties are satisfied!
It turns out that the final expression on the right is quite equivalent to that given above. A fairly illustrative way to convince yourself of this is to count the number of “free” parameters available in each case. Above, we used 9 parameters: k, ℓ, m, n, p, q, r, s, μ. With the Greco-Latin squares, there would seem to be 10, but in reality, there are only 9 because we can play to subtract any quantity T from all the Greek numbers and then add this same T to all the Latin numbers, obtaining the same pan magic square at the end.
In fact, one can move from a higher square formula to another by changes in appropriate variables.
The more knowledgeable reader will immediately recognize that this notion of “number of free parameters” is nothing other than the “dimension” of all the magic squares when we think of it as a vector space (we can sum magic squares to get others, as well as multiply them by scalars by multiplying each entry by this scalar). And here is good news: these dimensions were calculated for all n by X. Houa, A. Lecuona, G. Mullen, and J. Sellers in a relatively recent article [10].
In short, if you want to incorporate more numbers into your own magic square, just choose the right size!
Life is not that simple (and neither are the squares)
Even if, today, magic squares are not part of the most “modern” and “sophisticated” mathematics, there are still many open questions which sometimes have links to important current problems. For example, the problem of counting magic squares n × n filled with 1,…, n² is not yet solved: from n = 6 we do not know the total number!
Of course, for n = 6 this is a problem that can be passed to a computer. It would suffice to test, for each possible permutation, if the magic properties are satisfied (it takes 14 sums per permutation). However, the number of these permutations is “astronomical”: it is worth
36!=1×2×3×⋯×35×36,
which is equal to
371993326789901217467999448150835200000000
(remember quickly why: we have 36 breaks to place the 1; once placed, there are 35 breaks to place the 2; etc; the total number of permutations is, therefore, the product in question). We thus see a more general problem appear which consists of developing algorithms that make it possible to better deal with this type of counting situation. It is very likely that in the coming years we may know the answer to our particular problem for n = 6, but can we say something for n = 2019, for example?
To conclude, here is another open problem. Among Euler’s many contributions around magic squares, here is one of the most beautiful: it is a 4 × 4 magic square with all the entries being squares of whole numbers (distinct). Test it!
Is there a 3 × 3 analog? This is a question that dates back almost 250 years, a fascinating problem linked to a deep theory of mathematics of great activity today: that of elliptical curves.
x2+y2+z2=u2+v2+w2=p2+q2+r2=
=x2+u2+p2=y2+v2+q2=z2+w2+r2=
=x2+v2+r2=z2+v2+p2
We can finally ask ourselves: is there a turtle in a river in the world whose shell contains these numbers x, y, z, u, v, w, p, q, r still unknown? [11]
Harmony of numbers
To conclude, I would like to add my personal experience with magic squares.
Last year, I gave a lot of presentations to the general public, which started with these squares and led to contemporary mathematics. In high schools, I also proposed as a class activity to create your own magic square. And the students were always happy to see their date of birth among numbers with surprising properties! [12].
In parallel, and as a kind of social experiment, on the birthdays of my friends I gave them as gifts their own magic squares [13]. And I’ve always seen the same reaction of surprise accompanied by a small smile.
I think high school students and my friends have experienced this wonder a little at the numbers that we mathematicians have every day when we do math. I am convinced that magic squares are both a good learning tool in high school and a good communication channel for a non-mathematician audience. Besides, it is not trivial that before arriving in Europe from China, India and the Persian and Arab world, these squares had a completely different name (much better to tell the truth): called them “harmonious arrangements of numbers.”
Finally, I think that with magic squares, you can feel the harmony of mathematics a bit …
NOTE
[1] These transformations form our dear dihedral group D4.
[2] We illustrate two of these broken diagonals in the third square below: one is formed by the boxes in pink and the other by the breaks in sky blue. The other four broken diagonals are shown in the last square.
[3] These permutations form an isomorphic group to the group of hypercube automorphisms.
[4] Ramanujan’s First Book, the one that contains his research while he was still in high school, is full of — sometimes surprising — formulas on magic squares (a summary of these notebooks can be found here). We will see at minute 4:08 of the superb film The Man Who Knew Infinity a reproduction of this notebook will open on a page where some of these squares are found (among other formulas).
[5] In honor of Ramanujan, December 22 was proclaimed the Official Math Day in India. Globally, a request has been made by several countries to UNESCO to establish March 14 as International Math Day. Why this date? It’s easy to guess: think of π.
[6] If you are wealthy, use the formula in the previous paragraph (choosing a good integer k) to make your own pan magic square!
[7] Here we could talk about “broken” configurations like we did with the diagonals before.
[8] You will find on this Wikipedia page a very good argument to establish this without needing to know the general formula.
[9] This choice is not by chance: these squares come from the Arab world where the central box obviously symbolized Allah, around whom everything should circulate.
[10] The article in question is “On the dimension of the space of magic squares over a field”, Linear Algebra and its Applications 438 (2013), 3463–3475.
We could notice, however, that the phenomena of modulo 3 parity and congruence to which we refer above show that the problem of finding the dimensions of spaces of magic square (pan) with integer coordinates as modules on ℤ remains very interesting.
[11] Research with computers shows that these numbers — if they exist — must be gigantic. It is therefore very likely that the turtle in question does not exist (or perhaps it exists and that it has developed a digital rating system smarter than ours …).
[12] The resulting magic squares are particularly neat because, unlike the author (and many readers), high school students were born in the 21st century, so their dates of birth often lead to squares with numbers between 1 and 31.
[13] I have not made the slightest difference between even and odd human beings.