Magic square


In mathematics, especially historical and recreational mathematics, a square array of numbers, usually positive integers, is called a magic square if the sums of the numbers in each row, each column, and both main diagonals are the same. The order of the magic square is the number of integers along one side, and the constant sum is called the magic constant. If the array includes just the positive integers, the magic square is said to be normal. Many authors take magic square to mean normal magic square.
Magic squares that include repeated entries do not fall under this definition and are referred to as trivial. Some well-known examples, including the Sagrada Família magic square are trivial in this sense. When all the rows and columns but not both diagonals sum to the magic constant, this gives a semimagic square.
The mathematical study of magic squares typically deals with its construction, classification, and enumeration. Although completely general methods for producing all the magic squares of all orders do not exist, historically three general techniques have been discovered: by bordering, by making composite magic squares, and by adding two preliminary squares. There are also more specific strategies like the continuous enumeration method that reproduces specific patterns. Magic squares are generally classified according to their order n as: odd if n is odd, evenly even if n is a multiple of 4, oddly even if n is any other even number. This classification is based on different techniques required to construct odd, evenly even, and oddly even squares. Beside this, depending on further properties, magic squares are also classified as associative magic squares, pandiagonal magic squares, most-perfect magic squares, and so on. More challengingly, attempts have also been made to classify all the magic squares of a given order as transformations of a smaller set of squares. Except for n ≤ 5, the enumeration of higher-order magic squares is still an open challenge. The enumeration of most-perfect magic squares of any order was only accomplished in the late 20th century.
Magic squares have a long history, dating back to at least 190 BCE in China. At various times they have acquired occult or mythical significance, and have appeared as symbols in works of art. In modern times they have been generalized a number of ways, including using extra or different constraints, multiplying instead of adding cells, using alternate shapes or more than two dimensions, and replacing numbers with shapes and addition with geometric operations.
File:Dürer Melancholia I.jpg|thumb|Melencolia I includes an order 4 square with magic sum 34

History

The third-order magic square was known to Chinese mathematicians as early as 190 BCE, and explicitly given by the first century of the common era. The first dateable instance of the fourth-order magic square occurred in 587 CE in India. Specimens of magic squares of order 3 to 9 appear in an encyclopedia from Baghdad, the Encyclopedia of the Brethren of Purity. By the end of the 12th century, the general methods for constructing magic squares were well established. Around this time, some of these squares were increasingly used in conjunction with magic letters, as in Shams Al-ma'arif, for occult purposes. In India, all the fourth-order pandiagonal magic squares were enumerated by Narayana in 1356. Magic squares were made known to Europe through translation of Arabic sources as occult objects during the Renaissance, and the general theory had to be re-discovered independent of prior developments in China, India, and Middle East. Also notable are the ancient cultures with a tradition of mathematics and numerology that did not discover the magic squares: Greeks, Babylonians, Egyptians, and Pre-Columbian Americans.
Magic squares also appear in art. For example, a magic square appears in Albrecht Dürer's Melencolia. Another one appears in Wilfredo Lam's Bélial, Emperor of the Flies, a magic square is seen in the lower left quadrant of the painting.

China

While ancient references to the pattern of even and odd numbers in the 3×3 magic square appear in the I Ching, the first unequivocal instance of this magic square appears in the chapter called Mingtang of a 1st-century book Da Dai Liji, which purported to describe ancient Chinese rites of the Zhou dynasty.
These numbers also occur in a possibly earlier mathematical text called Shushu jiyi, said to be written in 190 BCE. This is the earliest appearance of a magic square on record; and it was mainly used for divination and astrology. The 3×3 magic square was referred to as the "Nine Halls" by earlier Chinese mathematicians. The identification of the 3×3 magic square to the legendary Luoshu chart was only made in the 12th century, after which it was referred to as the Luoshu square. The oldest surviving Chinese treatise that displays magic squares of order larger than 3 is Yang Hui's Xugu zheqi suanfa written in 1275. The contents of Yang Hui's treatise were collected from older works, both native and foreign; and he only explains the construction of third and fourth-order magic squares, while merely passing on the finished diagrams of larger squares. He gives a magic square of order 3, two squares for each order of 4 to 8, one of order nine, and one semi-magic square of order 10. He also gives six magic circles of varying complexity.
492
357
816

216133
115810
79126
144115

12316421
151471811
24171392
20819126
53102225

132218271120
314369292
122114231625
303532347
172610191524
835281633

468162029749
340353618412
4412332319386
28261125392422
5373127171345
4891514321047
143343021424

613264577660
125455916505113
2046471724424321
3727264033313036
2935343225393828
4422234148181945
5214154956101153
559588163624

317613368118297411
224058274563203856
674497295465247
307512327714347916
213957234159254361
663486855070752
358017287310337815
264462193755244260
718536414669651

The above magic squares of orders 3 to 9 are taken from Yang Hui's treatise, in which the Luo Shu principle is clearly evident. The order 5 square is a bordered magic square, with central 3×3 square formed according to Luo Shu principle. The order 9 square is a composite magic square, in which the nine 3×3 sub squares are also magic. After Yang Hui, magic squares frequently occur in Chinese mathematics such as in Ding Yidong's Dayan suoyin, Cheng Dawei's Suanfa tongzong, Fang Zhongtong's Shuduyan which contains magic circles, cubes and spheres, Zhang Chao's Xinzhai zazu, who published China's first magic square of order ten, and lastly Bao Qishou's Binaishanfang ji, who gave various three dimensional magic configurations. However, despite being the first to discover the magic squares and getting a head start by several centuries, the Chinese development of the magic squares are much inferior compared to the Indian, Middle Eastern, or European developments. The high point of Chinese mathematics that deals with the magic squares seems to be contained in the work of Yang Hui; but even as a collection of older methods, this work is much more primitive, lacking general methods for constructing magic squares of any order, compared to a similar collection written around the same time by the Byzantine scholar Manuel Moschopoulos. This is possibly because of the Chinese scholars' enthralment with the Lo Shu principle, which they tried to adapt to solve higher squares; and after Yang Hui and the fall of Yuan dynasty, their systematic purging of the foreign influences in Chinese mathematics.

Japan

Japan and China have similar mathematical traditions and have repeatedly influenced each other in the history of magic squares. The Japanese interest in magic squares began after the dissemination of Chinese works—Yang Hui's Suanfa and Cheng Dawei's Suanfa tongzong—in the 17th century, and as a result, almost all the wasans devoted their time to its study.
In the 1660 edition of Ketsugi-sho, Isomura Kittoku gave both odd and even ordered bordered magic squares as well as magic circles; while the 1684 edition of the same book contained a large section on magic squares, demonstrating that he had a general method for constructing bordered magic squares. In Jinko-ki by Muramatsu Kudayu Mosei, both magic squares and magic circles are displayed. The largest square Mosei constructs is of 19th order. Various magic squares and magic circles were also published by Nozawa Teicho in Dokai-sho, Sato Seiko in Kongenki, and Hosino Sanenobu in Ko-ko-gen Sho. One of Seki Takakazu's Seven Books is devoted completely to magic squares and circles. This is the first Japanese book to give a general treatment of magic squares in which the algorithms for constructing odd, singly even and doubly even bordered magic squares are clearly described. In 1694 and 1695, Yueki Ando gave different methods to create the magic squares and displayed squares of order 3 to 30. A fourth-order magic cube was constructed by Yoshizane Tanaka in Rakusho-kikan. The study of magic squares was continued by Seki's pupils, notably by Katahiro Takebe, whose squares were displayed in the fourth volume of Ichigen Kappo by Shukei Irie, Yoshisuke Matsunaga in Hojin-Shin-jutsu, Yoshihiro Kurushima in Kyushi Iko who rediscovered a method to produce the odd squares given by Agrippa, and Naonobu Ajima. Thus by the beginning of the 18th century, the Japanese mathematicians were in possession of methods to construct magic squares of arbitrary order. After this, attempts at enumerating the magic squares was initiated by Nushizumi Yamaji.

India

The 3×3 magic square first appears in India in Gargasamhita by Garga, who recommends its use to pacify the nine planets. The oldest version of this text dates from 100 CE, but the passage on planets could not have been written earlier than 400 CE. The first dateable instance of 3×3 magic square in India occur in a medical text Siddhayog by Vrnda, which was prescribed to women in labor in order to have easy delivery.
The oldest dateable fourth order magic square in the world is found in an encyclopaedic work written by Varahamihira around 587 CE called Brhat Samhita. The magic square is constructed for the purpose of making perfumes using 4 substances selected from 16 different substances. Each cell of the square represents a particular ingredient, while the number in the cell represents the proportion of the associated ingredient, such that the mixture of any four combination of ingredients along the columns, rows, diagonals, and so on, gives the total volume of the mixture to be 18. Although the book is mostly about divination, the magic square is given as a matter of combinatorial design, and no magical properties are attributed to it. The special features of this magic square were commented on by Bhattotpala
2358
5823
4176
7641

103138
516211
49714
156121

The square of Varahamihira as given above has sum of 18. Here the numbers 1 to 8 appear twice in the square. It is a pan-diagonal magic square. Four different magic squares can be obtained by adding 8 to one of the two sets of 1 to 8 sequence. The sequence is selected such that the number 8 is added exactly twice in each row, each column and each of the main diagonals. One of the possible magic squares shown in the right side. This magic square is remarkable in that it is a 90 degree rotation of a magic square that appears in the 13th century Islamic world as one of the most popular magic squares.
The construction of 4th-order magic square is detailed in a work titled Kaksaputa, composed by the alchemist Nagarjuna around 10th century CE. All of the squares given by Nagarjuna are 4×4 magic squares, and one of them is called Nagarjuniya after him. Nagarjuna gave a method of constructing 4×4 magic square using a primary skeleton square, given an odd or even magic sum. The Nagarjuniya square is given below, and has the sum total of 100.
30161836
10442224
32142034
2826406

7146
2853
5328
4671

The Nagarjuniya square is a pan-diagonal magic square. It is made up of two arithmetic progressions starting from 6 and 16 with eight terms each, with a common difference between successive terms as 4. When these two progressions are reduced to the normal progression of 1 to 8, the adjacent square is obtained.
Around 12th-century, a 4×4 magic square was inscribed on the wall of Parshvanath temple in Khajuraho, India. Several Jain hymns teach how to make magic squares, although they are undateable.
As far as is known, the first systematic study of magic squares in India was conducted by Thakkar Pheru, a Jain scholar, in his Ganitasara Kaumudi. This work contains a small section on magic squares which consists of nine verses. Here he gives a square of order four, and alludes to its rearrangement; classifies magic squares into three according to its order; gives a square of order six; and prescribes one method each for constructing even and odd squares. For the even squares, Pheru divides the square into component squares of order four, and puts the numbers into cells according to the pattern of a standard square of order four. For odd squares, Pheru gives the method using horse move or knight's move. Although algorithmically different, it gives the same square as the De la Loubere's method.
The next comprehensive work on magic squares was taken up by Narayana Pandit, who in the fourteenth chapter of his Ganita Kaumudi gives general methods for their construction, along with the principles governing such constructions. It consists of 55 verses for rules and 17 verses for examples. Narayana gives a method to construct all the pan-magic squares of fourth order using knight's move; enumerates the number of pan-diagonal magic squares of order four, 384, including every variation made by rotation and reflection; three general methods for squares having any order and constant sum when a standard square of the same order is known; two methods each for constructing evenly even, oddly even, and odd squares when the sum is given. While Narayana describes one older method for each species of square, he claims the method of superposition for evenly even and odd squares and a method of interchange for oddly even squares to be his own invention. The superposition method was later re-discovered by De la Hire in Europe. In the last section, he conceives of other figures, such as circles, rectangles, and hexagons, in which the numbers may be arranged to possess properties similar to those of magic squares. Below are some of the magic squares constructed by Narayana:
816
357
492

114415
811510
132163
12796

161473023
241710831
322518114
528261912
136292220

135433326
2511928830
241418161722
132319212015
12262710297
362343531

3526171625344
4637211236455
5741322314566
6152433425167
2635445362711
1346556473122
2415667514233

605344374132029
314193059544338
585542392151831
116173257564140
615245365122128
611222762514635
635047347102326
89242564494833

The order 8 square is interesting in itself since it is an instance of the most-perfect magic square. Incidentally, Narayana states that the purpose of studying magic squares is to construct yantra, to destroy the ego of bad mathematicians, and for the pleasure of good mathematicians. The subject of magic squares is referred to as bhadraganita and Narayana states that it was first taught to men by god Shiva.

Middle East, North Africa, Muslim Iberia

Although the early history of magic squares in Persia and Arabia is not known, it has been suggested that they were known in pre-Islamic times. It is clear, however, that the study of magic squares was common in medieval Islam, and it was thought to have begun after the introduction of chess into the region. The first dateable appearance of a magic square of order 3 occurs in Jābir ibn Hayyān's Kitab al-mawazin al-Saghir where the magic square and its related numerology is associated with alchemy. While it is known that treatises on magic squares were written in the 9th century, the earliest extant treaties date from the 10th-century: one by Abu'l-Wafa al-Buzjani and another by Ali b. Ahmad al-Antaki. These early treatises were purely mathematical, and the Arabic designation for magic squares used is wafq al-a'dad, which translates as harmonious disposition of the numbers. By the end of 10th century, the two treatises by Buzjani and Antaki makes it clear that the Middle Eastern mathematicians had understood how to construct bordered squares of any order as well as simple magic squares of small orders which were used to make composite magic squares. A specimen of magic squares of orders 3 to 9 devised by Middle Eastern mathematicians appear in an encyclopedia from Baghdad, the Rasa'il Ikhwan al-Safa. The squares of order 3 to 7 from Rasa'il are given below:
276
951
438

414151
97612
511108
162313

21341225
15176198
102413216
18720911
11422235

11223252318
25167301320
276353643
1031123334
14198292615
24172891221

47118964549
4372017163546
2182621283248
4319272523317
38362229241412
40153033341310
13942414453

The 11th century saw the finding of several ways to construct simple magic squares for odd and evenly even orders; the more difficult case of oddly even case was solved by Ibn al-Haytham with k even, and completely by the beginning of 12th century, if not already in the latter half of the 11th century. Around the same time, pandiagonal squares were being constructed. Treaties on magic squares were numerous in the 11th and 12th century. These later developments tended to be improvements on or simplifications of existing methods. From the 13th century onwards, magic squares were increasingly put to occult purposes. However, much of these later texts written for occult purposes merely depict certain magic squares and mention their attributes, without describing their principle of construction, with only some authors keeping the general theory alive. One such occultist was the Algerian Ahmad al-Buni, who gave general methods on constructing bordered magic squares; some others were the 17th century Egyptian Shabramallisi and the 18th century Nigerian al-Kishnawi.
The magic square of order three was described as a child-bearing charm since its first literary appearances in the alchemical works of Jābir ibn Hayyān and al-Ghazālī and it was preserved in the tradition of the planetary tables. The earliest occurrence of the association of seven magic squares to the virtues of the seven heavenly bodies appear in Andalusian scholar Ibn Zarkali's Kitāb tadbīrāt al-kawākib. A century later, the Algerian scholar Ahmad al-Buni attributed mystical properties to magic squares in his highly influential book Shams al-Ma'arif, which also describes their construction. This tradition about a series of magic squares from order three to nine, which are associated with the seven planets, survives in Greek, Arabic, and Latin versions. There are also references to the use of magic squares in astrological calculations, a practice that seems to have originated with the Arabs.

Latin Europe

Unlike in Persia and Arabia, better documentation exists of how the magic squares were transmitted to Europe. Around 1315, influenced by Arab sources, the Greek Byzantine scholar Manuel Moschopoulos wrote a mathematical treatise on the subject of magic squares, leaving out the mysticism of his Middle Eastern predecessors, where he gave two methods for odd squares and two methods for evenly even squares. Moschopoulos was essentially unknown to the Latin Europe until the late 17th century, when Philippe de la Hire rediscovered his treatise in the Royal Library of Paris. However, he was not the first European to have written on magic squares; and the magic squares were disseminated to rest of Europe through Spain and Italy as occult objects. The early occult treaties that displayed the squares did not describe how they were constructed. Thus the entire theory had to be rediscovered.
Magic squares had first appeared in Europe in Kitāb tadbīrāt al-kawākib written by Ibn Zarkali of Toledo, Al-Andalus, as planetary squares by 11th century. The magic square of three was discussed in numerological manner in early 12th century by Jewish scholar Abraham ibn Ezra of Toledo, which influenced later Kabbalists. Ibn Zarkali's work was translated as Libro de Astromagia in the 1280s, due to Alfonso X of Castille. In the Alfonsine text, magic squares of different orders are assigned to the respective planets, as in the Islamic literature; unfortunately, of all the squares discussed, the Mars magic square of order five is the only square exhibited in the manuscript.
Magic squares surface again in Florence, Italy in the 14th century. A 6×6 and a 9×9 square are exhibited in a manuscript of the Trattato d'Abbaco by Paolo Dagomari. It is interesting to observe that Paolo Dagomari, like Pacioli after him, refers to the squares as a useful basis for inventing mathematical questions and games, and does not mention any magical use. Incidentally, though, he also refers to them as being respectively the Sun's and the Moon's squares, and mentions that they enter astrological calculations that are not better specified. As said, the same point of view seems to motivate the fellow Florentine Luca Pacioli, who describes 3×3 to 9×9 squares in his work De Viribus Quantitatis by the end of 15th century.

Europe after 15th century

The planetary squares had disseminated into northern Europe by the end of the 15th century. For instance, the Cracow manuscript of Picatrix from Poland displays magic squares of orders 3 to 9. The same set of squares as in the Cracow manuscript later appears in the writings of Paracelsus in Archidoxa Magica, although in highly garbled form. In 1514 Albrecht Dürer immortalized a 4×4 square in his famous engraving Melencolia I. Paracelsus' contemporary Heinrich Cornelius Agrippa von Nettesheim published his famous three volume book De occulta philosophia in 1531, where he devoted Chapter 22 of Book II to the planetary squares shown below. The same set of squares given by Agrippa reappear in 1539 in Practica Arithmetice by Girolamo Cardano, where he explains the construction of the odd ordered squares using "diamond method", which was later reproduced by Bachet. The tradition of planetary squares was continued into the 17th century by Athanasius Kircher in Oedipi Aegyptici. In Germany, mathematical treaties concerning magic squares were written in 1544 by Michael Stifel in Arithmetica Integra, who rediscovered the bordered squares, and Adam Riese, who rediscovered the continuous numbering method to construct odd ordered squares published by Agrippa. However, due to the religious upheavals of that time, these works were unknown to the rest of Europe.
492
357
816

414151
97612
511108
162313

11247203
41225816
17513219
101811422
23619215

632334351
7112728830
191416152324
182022211713
25291092612
365334231

2247164110354
5234817421129
3062449183612
1331725431937
3814321264420
213983322745
461540934328

858595462631
4915145253111056
4123224445191848
3234352928383925
4026273736303133
1747462021434224
955541213515016
642361606757

37782970216213545
63879307122631446
47739803172235515
16488408132642456
57174994173336525
26581850142743466
67275910512437535
36681960115234476
77286920611253445

In 1624 France, Claude Gaspard Bachet described the "diamond method" for constructing Agrippa's odd ordered squares in his book Problèmes Plaisants. During 1640 Bernard Frenicle de Bessy and Pierre Fermat exchanged letters on magic squares and cubes, and in one of the letters Fermat boasts of being able to construct 1,004,144,995,344 magic squares of order 8 by his method. An early account on the construction of bordered squares was given by Antoine Arnauld in his Nouveaux éléments de géométrie. In the two treatise Des quarrez ou tables magiques and Table générale des quarrez magiques de quatre de côté, published posthumously in 1693, twenty years after his death, Bernard Frenicle de Bessy demonstrated that there were exactly 880 distinct magic squares of order four. Frenicle gave methods to construct magic square of any odd and even order, where the even ordered squares were constructed using borders. He also showed that interchanging rows and columns of a magic square produced new magic squares. In 1691, Simon de la Loubère described the Indian continuous method of constructing odd ordered magic squares in his book Du Royaume de Siam, which he had learned while returning from a diplomatic mission to Siam, which was faster than Bachet's method. In an attempt to explain its working, de la Loubere used the primary numbers and root numbers, and rediscovered the method of adding two preliminary squares. This method was further investigated by Abbe Poignard in Traité des quarrés sublimes, by Philippe de La Hire in Mémoires de l'Académie des Sciences for the Royal Academy, and by Joseph Sauveur in Construction des quarrés magiques. Concentric bordered squares were also studied by De la Hire in 1705, while Sauveur introduced magic cubes and lettered squares, which was taken up later by Euler in 1776, who is often credited for devising them. In 1750 d'Ons-le-Bray rediscovered the method of constructing doubly even and singly even squares using bordering technique; while in 1767 Benjamin Franklin published a semi-magic square which had the properties of eponymous Franklin square. By this time the earlier mysticism attached to the magic squares had completely vanished, and the subject was treated as a part of recreational mathematics.
In the 19th century, Bernard Violle gave a comprehensive treatment of magic squares in his three volume Traité complet des carrés magiques, which also described magic cubes, parallelograms, parallelopipeds, and circles. Pandiagonal squares were extensively studied by Andrew Hollingworth Frost, who learned it while in the town of Nasik, India, in a series of articles: On the knight's path, On the General Properties of Nasik Squares, On the General Properties of Nasik Cubes, On the construction of Nasik Squares of any order. He showed that it is impossible to have normal singly-even pandiagonal magic square. Frederick A.P. Barnard constructed inlaid magic squares and other three dimensional magic figures like magic spheres and magic cylinders in Theory of magic squares and of magic cubes. In 1897, Emroy McClintock published On the most perfect form of magic squares, coining the words pandiagonal square and most perfect square, which had previously been referred to as perfect, or diabolic, or Nasik.

Some famous magic squares

Luo Shu magic square

Legends dating from as early as 650 BCE tell the story of the Lo Shu or "scroll of the river Lo". According to the legend, there was at one time in ancient China a huge flood. While the great king Yu was trying to channel the water out to sea, a turtle emerged from it with a curious pattern on its shell: a 3×3 grid in which circular dots of numbers were arranged, such that the sum of the numbers in each row, column and diagonal was the same: 15. According to the legend, thereafter people were able to use this pattern in a certain way to control the river and protect themselves from floods. The Lo Shu Square, as the magic square on the turtle shell is called, is the unique normal magic square of order three in which 1 is at the bottom and 2 is in the upper right corner. Every normal magic square of order three is obtained from the Lo Shu by rotation or reflection.

Magic square in Parshavnath temple

There is a well-known 12th-century 4×4 normal magic square inscribed on the wall of the Parshvanath temple in Khajuraho, India.
712114
213811
163105
96154

This is known as the Chautisa Yantra, since its magic sum is 34. It is one of the three 4×4 pandiagonal magic squares and is also an instance of the most-perfect magic square. The study of this square led to the appreciation of pandiagonal squares by European mathematicians in the late 19th century. Pandiagonal squares were referred to as Nasik squares or Jain squares in older English literature.

Albrecht Dürer's magic square

The order four normal magic square Albrecht Dürer immortalized in his 1514 engraving Melencolia I, referred to above, is believed to be the first seen in European art. The square associated with Jupiter appears as a talisman used to drive away melancholy. It is very similar to Yang Hui's square, which was created in China about 250 years before Dürer's time. As with every order 4 normal magic square, the magic sum is 34. But in the Durer square this sum is also found
in each of the quadrants, in the center four squares, and in the corner squares. This sum can also be found in the four outer numbers clockwise from the corners and likewise the four counter-clockwise, the two sets of four symmetrical numbers, the sum of the middle two entries of the two outer columns and rows, and in four kite or cross shaped quartets. The two numbers in the middle of the bottom row give the date of the engraving: 1514. The numbers 1 and 4 at either side of the date correspond respectively to the letters "A" and "D", the initials of the artist.
163213
510118
96712
415141

Dürer's magic square can also be extended to a magic cube.

Sagrada Família magic square

The Passion façade of the Sagrada Família church in Barcelona, conceptualized by Antoni Gaudí and designed by sculptor Josep Subirachs, features a trivial order 4 magic square: The magic constant of the square is 33, the age of Jesus at the time of the Passion. Structurally, it is very similar to the Melancholia magic square, but it has had the numbers in four of the cells reduced by 1.
114144
11769
810105
132315

Trivial squares such as this one are not generally mathematically interesting and only have historical significance. Lee Sallows has pointed out that, due to Subirachs's ignorance of magic square theory, the renowned sculptor made a needless blunder, and supports this assertion by giving several examples of non-trivial 4×4 magic squares showing the desired magic constant of 33.
Similarly to Dürer's magic square, the Sagrada Familia's magic square can also be extended to a magic cube.

Properties of magic squares

Magic constant

The constant that is the sum of any row, or column, or diagonal is called the magic constant or magic sum, M. Every normal magic square has a constant dependent on the order, calculated by the formula. This can be demonstrated by noting that the sum of is. Since the sum of each row is, the sum of rows is, which when divided by the order yields the magic constant as. For normal magic squares of orders n = 3, 4, 5, 6, 7, and 8, the magic constants are, respectively: 15, 34, 65, 111, 175, and 260.

Magic square of order 1 is trivial

The 1×1 magic square, with only one cell containing the number 1, is called trivial, because it is typically not under consideration when discussing magic squares; but it is indeed a magic square by definition, if a single cell is regarded as a square of order one.

Magic square of order 2 cannot be constructed

Normal magic squares of all sizes can be constructed except 2×2.

Center of mass

If the numbers in the magic square are seen as masses located in various cells, then the center of mass of a magic square coincides with its geometric center.

Moment of inertia

The moment of inertia of a magic square has been defined as the sum over all cells of the number in the cell times the squared distance from the center of the cell to the center of the square; here the unit of measurement is the width of one cell. Then all magic squares of a given order have the same moment of inertia as each other. For the order-3 case the moment of inertia is always 60, while for the order-4 case the moment of inertia is always 340. In general, for the n×''n'' case the moment of inertia is

Birkhoff–von Neumann decomposition

Dividing each number of the magic square by the magic constant will yield a doubly stochastic matrix, whose row sums and column sums equal to unity. However, unlike the doubly stochastic matrix, the diagonal sums of such matrices will also equal to unity. Thus, such matrices constitute a subset of doubly stochastic matrix. The Birkhoff–von Neumann theorem states that for any doubly stochastic matrix, there exists real numbers, where and permutation matrices such that
This representation may not be unique in general. By Marcus-Ree theorem, however, there need not be more than terms in any decomposition. Clearly, this decomposition carries over to magic squares as well, since a magic square can be recovered from a doubly stochastic matrix by multiplying it by the magic constant.

Classification of magic squares

While the classification of magic squares can be done in many ways, some useful categories are given below. An n×''n square array of integers 1, 2,..., n''2 is called:
  • Semi-magic square when its rows and columns sum to give the magic constant.
  • Simple magic square when its rows, columns, and two diagonals sum to give magic constant and no more. They are also known as ordinary magic squares or normal magic squares.
  • Self-complementary magic square when it is a magic square which when complemented will give a rotated or reflected version of the original magic square.
  • Associative magic square when it is a magic square with a further property that every number added to the number equidistant, in a straight line, from the center gives n2 + 1. They are also called symmetric magic squares. Associative magic squares do not exist for squares of singly even order. All associative magic square are self-complementary magic squares as well.
  • Pandiagonal magic square when it is a magic square with a further property that the broken diagonals sum to the magic constant. They are also called panmagic squares, perfect squares, diabolic squares, Jain squares, or Nasik squares. Panmagic squares do not exist for singly even orders. However, singly even non-normal squares can be panmagic.
  • Ultra magic square when it is both associative and pandiagonal magic square. Ultra magic square exist only for orders n ≥ 5.
  • Bordered magic square when it is a magic square and it remains magic when the rows and columns on the outer edge are removed. They are also called concentric bordered magic squares if removing a border of a square successively gives another smaller bordered magic square. Bordered magic square do not exist for order 4.
  • Composite magic square when it is a magic square that is created by "multiplying" smaller magic squares, such that the order of the composite magic square is a multiple of the order of the smaller squares. Such squares can usually be partitioned into smaller non-overlapping magic sub-squares.
  • Inlaid magic square when it is a magic square inside which a magic sub-square is embedded, regardless of construction technique. The embedded magic sub-squares are themselves referred to as inlays.
  • Most-perfect magic square when it is a pandiagonal magic square with two further properties each 2×2 subsquare add to 1/k of the magic constant where n = 4k, and all pairs of integers distant n/2 along any diagonal are complementary. The first property is referred to as compactness, while the second property is referred to as completeness. Most-perfect magic squares exist only for squares of doubly even order. All the pandiagonal squares of order 4 are also most perfect.
  • Franklin magic square when it is a doubly even magic square with three further properties every bent diagonal adds to the magic constant, every half row and half column starting at an outside edge adds to half the magic constant, and the square is compact.
  • Multimagic square when it is a magic square that remains magic even if all its numbers are replaced by their k-th power for 1 ≤ kP. They are also known as P-multimagic square or satanic squares. They are also referred to as bimagic squares, trimagic squares, tetramagic squares, and pentamagic squares when the value of P is 2, 3, 4, and 5 respectively.

    Enumeration of magic squares

;Low-order squares
There is only one magic square of order 1 and no magic square of order 2. As mentioned above, the set of normal squares of order three constitutes a single equivalence class-all equivalent to the Lo Shu square. Thus there is basically just one normal magic square of order 3.
The number of different n × n magic squares for n from 1 to 6, not counting rotations and reflections is:
; Magic tori
Cross-referenced to the above sequence, a new classification enumerates the magic tori that display these magic squares. The number of magic tori of order n from 1 to 5, is:
; Higher-order squares and tori
The number of distinct normal magic squares rapidly increases for higher orders.
The 880 magic squares of order 4 are displayed on 255 magic tori of order 4 and the 275,305,224 squares of order 5 are displayed on 251,449,712 magic tori of order 5. The numbers of magic tori and distinct normal squares are not yet known for orders beyond 5 and 6, respectively.
Algorithms tend to only generate magic squares of a certain type or classification, making counting all possible magic squares quite difficult. Since traditional counting methods have proven unsuccessful, statistical analysis using the Monte Carlo method has been applied. The basic principle applied to magic squares is to randomly generate n × n matrices of elements 1 to n2 and check if the result is a magic square. The probability that a randomly generated matrix of numbers is a magic square is then used to approximate the number of magic squares.
More intricate versions of the Monte Carlo method, such as the exchange Monte Carlo, and Monte Carlo backtracking have produced even more accurate estimations. Using these methods it has been shown that the probability of magic squares decreases rapidly as n increases. Using fitting functions give the curves seen to the right.

Transformations that preserve the magic property

For any magic square

  • A magic square remains magic when its numbers are multiplied by any constant.
  • A magic square remains magic when a constant is added or subtracted to its numbers, or if its numbers are subtracted from a constant. In particular, if every element in a normal magic square is subtracted from n2 + 1, the resulting square is the complement of the original square. In the example below, elements of 4×4 square on the left is subtracted from 17 to obtain the complement of the square on the right.
103138
516211
49714
156121

71449
121156
138103
211516

  • The numbers of a magic square can be substituted with corresponding numbers from a set of s arithmetic progressions with the same common difference among r terms, such that r × s = n2, and whose initial terms are also in arithmetic progression, to obtain a non-normal magic square. Here either s or r should be a multiple of n. Let us have s arithmetic progressions given by
115144
12679
810115
133216

117164
146711
812135
153218

111042317
18126524
25191371
22120148
93221615

161473023
241710831
322518114
528261912
136292220

  • Any magic square can be rotated and reflected to produce 8 trivially distinct squares. In magic square theory, all of these are generally deemed equivalent and the eight such squares are said to make up a single equivalence class. In discussing magic squares, equivalent squares are usually not considered as distinct. The 8 equivalent squares are given for the 3×3 magic square below:
816
357
492

618
753
294

276
951
438

438
951
276

294
753
618

492
357
816

834
159
672

672
159
834

  • Given any magic square, another magic square of the same order can be formed by interchanging the row and the column which intersect in a cell on a diagonal with the row and the column which intersect in the complementary cell of the same diagonal. For an even square, there are n/2 pairs of rows and columns that can be interchanged; thus we can obtain 2n/2 equivalent magic squares by combining such interchanges. For odd square, there are /2 pairs of rows and columns that can be interchanged; and 2/2 equivalent magic squares obtained by combining such interchanges. Interchanging all the rows and columns rotates the square by 180 degree. In the example using a 4×4 magic square, the left square is the original square, while the right square is the new square obtained by interchanging the 1st and 4th rows and columns.
115144
12679
810115
133216

163213
96712
510118
415141

  • Given any magic square, another magic square of the same order can be formed by interchanging two rows on one side of the center line, and then interchanging the corresponding two rows on the other side of the center line; then interchanging like columns. For an even square, since there are n/2 same sided rows and columns, there are n/8 pairs of such rows and columns that can be interchanged. Thus we can obtain 2n/8 equivalent magic squares by combining such interchanges. For odd square, since there are /2 same sided rows and columns, there are /8 pairs of such rows and columns that can be interchanged. Thus, there are 2/8 equivalent magic squares obtained by combining such interchanges. Interchanging every possible pairs of rows and columns rotates each quadrant of the square by 180 degree. In the example using a 4×4 magic square, the left square is the original square, while the right square is the new square obtained by this transformation. In the middle square, row 1 has been interchanged with row 2; and row 3 and 4 has been interchanged. The final square on the right is obtained by interchanging columns 1 and 2, and columns 3 and 4 of the middle square. In this particular example, this transform amounts to rotating the quadrants by 180 degree. The middle square is also a magic square, since the original square is an associative magic square.
115144
12679
810115
133216

12679
115144
133216
810115

61297
151414
313162
108511

  • A magic square remains magic when any of its non-central rows x and y are interchanged, along with the interchange of their complementary rows nx + 1 and ny + 1; and then interchanging like columns. This is a generalization of the above two transforms. When y = nx + 1, this transform reduces to the first of the above two transforms. When x and y are on the same side of the center line, this transform reduces to the second of the above two transforms. In the example below, the original square is on the left side, while the final square on the right. The middle square has been obtained by interchanging rows 1 and 3, and rows 2 and 4 of the original square. The final square on the right is obtained by interchanging columns 1 and 3, and columns 2 and 4 of the middle square. In this example, this transform amounts to interchanging the quadrants diagonally. Since the original square is associative, the middle square also happens to be magic.
115144
12679
810115
133216

810115
133216
115144
12679

115810
216133
144115
79126

  • A magic square remains magic when its quadrants are diagonally interchanged because this is another symmetric permutation of the form described above. For even-order, permute the rows and columns by permutation where for, and for. For odd-order, permute rows and columns by permutation where for, and for. For odd ordered square, the halves of the central row and column are also interchanged. Examples for order 4 and 5 magic squares are given below:
115144
12679
810115
133216

115810
216133
144115
79126

17241815
23571416
46132022
101219213
11182529

213191012
29251118
20221346
81511724
14167235

For associative magic squares

  • An associative magic square remains associative when two rows or columns equidistant from the center are interchanged. For an even square, there are n/2 pairs of rows or columns that can be interchanged; thus equivalent magic squares by combining such interchanges can be obtained. For odd square, there are pairs of rows or columns that can be interchanged; and 2n−1 equivalent magic squares obtained by combining such interchanges. Interchanging all the rows flips the square vertically, while interchanging all the columns flips the square horizontally. In the example below, a 4×4 associative magic square on the left is transformed into a square on the right by interchanging the second and third row, yielding the famous Durer's magic square.
163213
96712
510118
415141

163213
510118
96712
415141

  • An associative magic square remains associative when two same sided rows are interchanged along with corresponding other sided rows. For an even square, since there are n/2 same sided rows, there are n/8 pairs of such rows that can be interchanged. Thus, 2n/8 × 2n/8 = 2n/4 equivalent magic squares can be obtained by combining such interchanges. For odd square, since there are /2 same sided rows or columns, there are /8 pairs of such rows or columns that can be interchanged. Thus, there are 2/8 × 2/8 = 2/4 equivalent magic squares obtained by combining such interchanges. Interchanging all the same sided rows flips each quadrants of the square vertically, while interchanging all the same sided columns flips each quadrant of the square horizontally. In the example below, the original square is on the left, whose rows 1 and 2 are interchanged with each other, along with rows 3 and 4, to obtain the transformed square on the right.
115144
12679
810115
133216

12679
115144
133216
810115

For pan-diagonal magic squares

  • A pan-diagonal magic square remains a pan-diagonal magic square under cyclic shifting of rows or of columns or both. This allows us to position a given number in any one of the n2 cells of an n order square. Thus, for a given pan-magic square, there are n2 equivalent pan-magic squares. In the example below, the original square on the left is transformed by shifting the first row to the bottom to obtain a new pan-magic square in the middle. Next, the 1st and 2nd column of the middle pan-magic square is circularly shifted to the right to obtain a new pan-magic square on the right.
103138
516211
49714
156121

516211
49714
156121
103138

211516
71449
121156
138103

For bordered magic squares

  • A bordered magic square remains a bordered magic square after permuting the border cells in the rows or columns, together with their corresponding complementary terms, keeping the corner cells fixed. Since the cells in each row and column of every concentric border can be permuted independently, when the order n ≥ 5 is odd, there are equivalent bordered squares. When n ≥ 6 is even, there are equivalent bordered squares. In the example below, a square of order 5 is given whose border row has been permuted and 2 = 36 such equivalent squares can be obtained.
12316421
151471811
24171392
20819126
53102225

11623421
151471811
24171392
20819126
51032225

  • A bordered magic square remains a bordered magic square after each of its concentric borders are independently rotated or reflected with respect to the central core magic square. If there are b borders, then this transform will yield 8b equivalent squares. In the example below of the 5×5 magic square, the border has been rotated 90 degrees anti-clockwise.
12316421
151471811
24171392
20819126
53102225

21112625
41471822
161713910
23819123
11524205

For composite magic squares

  • A composite magic square remains a composite magic square when the embedded magic squares undergo transformations that do not disturb the magic property.

    Special methods of construction

Solving partially completed magic squares

Solving partially completed magic squares is a popular mathematical pastime. The techniques needed are similar to those used in Sudoku or KenKen puzzles, and involve deducing the values of unfilled squares using logic and permutation group theory.

Variations of the magic square

Extra constraints

Certain extra restrictions can be imposed on magic squares.
If raising each number to the nth power yields another magic square, the result is a bimagic, a trimagic, or, in general, a multimagic square.
A magic square in which the number of letters in the name of each number in the square generates another magic square is called an alphamagic square.
There are magic squares consisting entirely of primes. Rudolf Ondrejka discovered the following 3×3 magic square of primes, in this case nine Chen primes:
178971
113595
4729101

The Green–Tao theorem implies that there are arbitrarily large magic squares consisting of primes.
The following "reversible magic square" has a magic constant of 264 both upside down and right way up:
96118968
88699116
61861899
19986681

When the extra constraint is to display some date, especially a birth date, then such magic squares are called birthday magic square. An early instance of such birthday magic square was created by Srinivasa Ramanujan. He created a 4×4 square in which he entered his date of birth in DD-MM-CC-YY format in the top row and the magic happened with additions and subtractions of numbers in squares. Not only do the rows, columns, and diagonals add up to the same number, but the four corners, the four middle squares, the first and last rows two middle numbers, and the first and last columns two middle numbers all add up to the sum of 139.

Multiplicative magic squares

Instead of adding the numbers in each row, column and diagonal, one can apply some other operation. For example, a multiplicative magic square has a constant product of numbers. A multiplicative magic square can be derived from an additive magic square by raising 2 to the power of each element, because the logarithm of the product of 2 numbers is the sum of logarithm of each. Alternatively, if any 3 numbers in a line are 2a, 2b and 2c, their product is 2a+''b+c'', which is constant if a+''b+c'' is constant, as they would be if a, b and c were taken from ordinary magic square. For example, the original Lo-Shu magic square becomes:
165124
832128
256264

Other examples of multiplicative magic squares include:
2912
3661
3418

162056
402823
145244
128710

2750668413232
2452340547011
569204436656
5572911163630
4244560771226
1022483954863
787818403360

Multiplicative magic squares of complex numbers

Still using Ali Skalli's non iterative method, it is possible to produce an infinity of multiplicative magic squares of complex numbers belonging to set. On the example below, the real and imaginary parts are integer numbers, but they can also belong to the entire set of real numbers.
The product is: −352,507,340,640 − 400,599,719,520 i.
21+14i−70+30i−93−9i−105−217i16+50i4−14i14−8i
63−35i28+114i−14i2+6i3−11i211+357i−123−87i
31−15i13−13i−103+69i−261−213i49−49i−46+2i−6+2i
102−84i−28−14i43+247i−10−2i5+9i31−27i−77+91i
−22−6i7+7i8+14i50+20i−525−492i−28−42i−73+17i
54+68i138−165i−56−98i−63+35i4−8i2−4i70−53i
24+22i−46−16i6−4i17+20i110+160i84−189i42−14i

Additive-multiplicative magic and semimagic squares

Additive-multiplicative magic squares and semimagic squares satisfy properties of both ordinary and multiplicative magic squares and semimagic squares, respectively.

It is unknown if any additive-multiplicative magic squares smaller than 7×7 exist, but it has been proven that no 3×3 or 4×4 additive-multiplicative magic squares and no 3×3 additive-multiplicative semimagic squares exist.
12666509048184
207016541891106
100222983672135
96608141049165
363301761204528
991801425710832
212425218558015

Geometric magic squares

Magic squares may be constructed which contain geometric shapes instead of numbers. Such squares, known as geometric magic squares, were invented and named by Lee Sallows in 2001.
In the example shown the shapes appearing are two dimensional. It is clear that all magic squares are geometric, in that the numbers that appear in numerical magic squares can be interpreted as a shorthand notation which indicates the lengths of straight line segments that are the geometric 'shapes' occurring in the square. That is, numerical magic squares are that special case of a geometric magic square using one dimensional shapes.

Area magic squares

In 2017, following initial ideas of William Walkington and Inder Taneja, the first linear area magic square was constructed by Walter Trump.

Other magic shapes

Other two dimensional shapes than squares can be considered. The general case is to consider a design with N parts to be magic if the N parts are labeled with the numbers 1 through N and a number of identical sub-designs give the same sum. Examples include magic circles, magic rectangles, magic triangles magic stars, magic hexagons, magic diamonds. Going up in dimension results in magic spheres, magic cylinders, magic cubes, magic parallelepiped, magic solids, and other magic hypercubes.
Possible magic shapes are constrained by the number of equal-sized, equal-sum subsets of the chosen set of labels. For example, if one proposes to form a magic shape labeling the parts with, the sub-designs will have to be labeled with and.

Related problems

''n''-Queens problem

In 1992, Demirörs, Rafraf, and Tanik published a method for converting some magic squares into queens puzzle|n-queens] solutions, and vice versa.

Magic squares in occultism

Magic squares of order 3 through 9, assigned to the seven planets, and described as means to attract the influence of planets and their angels during magical practices, can be found in several manuscripts all around Europe starting at least since the 15th century. Among the best known, the Liber de Angelis, a magical handbook written around 1440, is included in Cambridge Univ. Lib. MS Dd.xi.45. The text of the Liber de Angelis is very close to that of De septem quadraturis planetarum seu quadrati magici, another handbook of planetary image magic contained in the Codex 793 of the Biblioteka Jagiellońska. The magical operations involve engraving the appropriate square on a plate made with the metal assigned to the corresponding planet, as well as performing a variety of rituals. For instance, the 3×3 square, that belongs to Saturn, has to be inscribed on a lead plate. It will, in particular, help women during a difficult childbirth.
In about 1510 Heinrich Cornelius Agrippa wrote De Occulta Philosophia, drawing on the Hermetic and magical works of Marsilio Ficino and Pico della Mirandola. In its 1531 edition, he expounded on the magical virtues of the seven magical squares of orders 3 to 9, each associated with one of the astrological planets, much in the same way as the older texts did. This book was very influential throughout Europe until the Counter-Reformation, and Agrippa's magic squares, sometimes called kameas, continue to be used within modern ceremonial magic in much the same way as he first prescribed.
Image:Hagiel sigil derivation.svg|thumb|The derivation of the sigil of Hagiel, the planetary intelligence of Venus, drawn on the magic square of Venus. Each Hebrew letter provides a numerical value, giving the vertices of the sigil.
The most common use for these kameas is to provide a pattern upon which to construct the sigils of spirits, angels or demons; the letters of the entity's name are converted into numbers, and lines are traced through the pattern that these successive numbers make on the kamea.
In a magical context, the term magic square is also applied to a variety of word squares or number squares found in magical grimoires, including some that do not follow any obvious pattern, and even those with differing numbers of rows and columns. They are generally intended for use as talismans. For instance the following squares are: The Sator square, one of the most famous magic squares found in a number of grimoires including the Key of Solomon; a square "to overcome envy", from The Book of Power; and two squares from The Book of the Sacred Magic of Abramelin the Mage, the first to cause the illusion of a superb palace to appear, and the second to be worn on the head of a child during an angelic invocation:
SATOR
AREPO
TENET
OPERA
ROTAS

666848938
811544839
111383839
273774447

HESEB
EQAL
S
EG
B

ADAM
DARA
ARAD
MADA