In
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 (''n''), 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'. Some 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 and the Parker 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 (sometimes called orthomagic square).
The mathematical study of magic squares typically deals with their 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 method, 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 (also referred to as "doubly even") if ''n'' is a multiple of 4, oddly even (also known as "singly 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 square
In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement f ...
s,
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.
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
Baghdad (; ar, بَغْدَاد , ) is the capital of Iraq and the second-largest city in the Arab world after Cairo. It is located on the Tigris near the ruins of the ancient city of Babylon and the Sassanid Persian capital of Ctesipho ...
, the ''
Encyclopedia of the Brethren of Purity'' (''Rasa'il Ikhwan al-Safa''). By the end of 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.
China

While ancient references to the pattern of even and odd numbers in the 3×3 magic square appears in the ''
I Ching'', the first unequivocal instance of this magic square appears in the chapter called ''Mingtang'' (Bright Hall) of a 1st-century book ''Da Dai Liji'' (Record of Rites by the Elder Dai), which purported to describe ancient Chinese rites of the Zhou dynasty.
These numbers also occur in a possibly earlier mathematical text called ''Shushu jiyi'' (Memoir on Some Traditions of Mathematical Art), 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'' (Continuation of Ancient Mathematical Methods for Elucidating the Strange) 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.
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'' (1593), Fang Zhongtong's ''Shuduyan'' (1661) 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
Manuel Moschopoulos ( Latinized as Manuel Moschopulus; el, ), was a Byzantine commentator and grammarian, who lived during the end of the 13th and the beginning of the 14th century and was an important figure in the Palaiologan Renaissance. ''Mos ...
.
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'' (1665) 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'' (1666), Sato Seiko in ''Kongenki'' (1666), and Hosino Sanenobu in ''Ko-ko-gen Sho'' (1673).
One of
Seki Takakazu's ''Seven Books'' (''Hojin Yensan'') (1683) 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 (1651–1719) in ''Rakusho-kikan'' (1683). 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 (''navagraha''). 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'' (c. 900 CE) 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 (c. 966 CE)
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
Nāgārjuna . 150 – c. 250 CE (disputed)was an Indian Mahāyāna Buddhist thinker, scholar-saint and philosopher. He is widely considered one of the most important Buddhist philosophers.Garfield, Jay L. (1995), ''The Fundamental Wisdom of ...
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.
The Nagarjuniya square is a
pan-diagonal magic square. The Nagarjuniya square 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
''Parshvanatha'' (), also known as ''Parshva'' () and ''Parasnath'', was the 23rd of 24 '' Tirthankaras'' (supreme preacher of dharma) of Jainism. He is the only Tirthankara who gained the title of ''Kalīkālkalpataru ( Kalpavriksha in this " ...
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'' (c. 1315). 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 (odd, evenly even, and oddly even) 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'' (1356) 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 of 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:
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
Shiva (; sa, शिव, lit=The Auspicious One, Śiva ), also known as Mahadeva (; ɐɦaːd̪eːʋɐ, or Hara, is one of the principal deities of Hinduism. He is the Supreme Being in Shaivism, one of the major traditions within Hin ...
.
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
Chess is a board game for two players, called White and Black, each controlling an army of chess pieces in their color, with the objective to checkmate the opponent's king. It is sometimes called international chess or Western chess to dist ...
into the region.
The first dateable appearance of a magic square of order 3 occurs in
Jābir ibn Hayyān's (fl. c. 721 – c. 815) ''Kitab al-mawazin al-Saghir'' (The Small Book of Balances) 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
Abū al-Wafāʾ, Muḥammad ibn Muḥammad ibn Yaḥyā ibn Ismāʿīl ibn al-ʿAbbās al-Būzjānī or Abū al-Wafā Būzhjānī ( fa, ابوالوفا بوزجانی or بوژگانی) (10 June 940 – 15 July 998) was a Persian mathematician ...
() 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 (''n'' ≤ 6) 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
Baghdad (; ar, بَغْدَاد , ) is the capital of Iraq and the second-largest city in the Arab world after Cairo. It is located on the Tigris near the ruins of the ancient city of Babylon and the Sassanid Persian capital of Ctesipho ...
, the
Rasa'il Ikhwan al-Safa (the
Encyclopedia of the Brethren of Purity).
The squares of order 3 to 7 from Rasa'il are given below:
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 evenly-odd case (''n = 4k + 2'') was solved by
Ibn al-Haytham with ''k'' even (c. 1040), 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 on wards, 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
upShams al-Ma'arif al-Kubra, a manuscript copy, beginning of 17th century
Sharaf al-Din or Shihab al-Din or Muḥyi al-Din Abu al-Abbas Aḥmad ibn Ali ibn Yusuf al-Qurashi al-Sufi, better known as Ahmad al-Buni ( ar, أحمد البوني), born ...
(c. 1225), 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 (fl. c. 721 – c. 815)
and
al-Ghazālī
Al-Ghazali ( – 19 December 1111; ), full name (), and known in Persian-speaking countries as Imam Muhammad-i Ghazali (Persian: امام محمد غزالی) or in Medieval Europe by the Latinized as Algazelus or Algazel, was a Persian polymat ...
(1058–1111) 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 (known as Azarquiel in Europe) (1029–1087) ''Kitāb tadbīrāt al-kawākib'' (''Book on the Influences of the Planets'').
A century later, the Algerian scholar Ahmad al-Buni attributed mystical properties to magic squares in his highly influential book ''Shams al-Ma'arif'' (''The Book of the Sun of Gnosis and the Subtleties of Elevated Things''), 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
Manuel Moschopoulos ( Latinized as Manuel Moschopulus; el, ), was a Byzantine commentator and grammarian, who lived during the end of the 13th and the beginning of the 14th century and was an important figure in the Palaiologan Renaissance. ''Mos ...
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'' (''Book on the Influences of the Planets'') 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'' (Treatise of the Abacus) by
Paolo Dagomari
Paolo Dagomari da Prato (1282–1374), known in Latin as Paulus Geometrus (''Paolo il Geometra'', "Paul the Geometer"), was a noted Florentine mathematician and astronomer, such a ''maestro dell'abbaco'' (master/teacher of the abacus) that he ...
. 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 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'' (1567), 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
Heinrich Cornelius Agrippa von Nettesheim (; ; 14 September 1486 – 18 February 1535) was a German polymath, physician, legal scholar, soldier, theologian, and occult writer. Agrippa's ''Three Books of Occult Philosophy'' published in 1533 drew ...
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
Athanasius Kircher (2 May 1602 – 27 November 1680) was a German Jesuit scholar and polymath who published around 40 major works, most notably in the fields of comparative religion, geology, and medicine. Kircher has been compared to ...
in ''Oedipi Aegyptici'' (1653). 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
Adam Ries (17 January 1492 – 30 March 1559) was a German mathematician. He is also known by the name Adam Riese.
Life
Almost nothing is known about Ries' childhood, youth and education. The exact year of his birth is not known. The caption o ...
, who rediscovered the continuous numbering method to construct odd ordered squares published by Agrippa. However, due to the religious upheavals of that time, these work were unknown to the rest of Europe.
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
Bernard (''Bernhard'') is a French and West Germanic masculine given name. It is also a surname.
The name is attested from at least the 9th century. West Germanic ''Bernhard'' is composed from the two elements ''bern'' "bear" and ''hard'' "brav ...
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
Antoine Arnauld (6 February 16128 August 1694) was a French Catholic theologian, philosopher and mathematician. He was one of the leading intellectuals of the Jansenist group of Port-Royal and had a very thorough knowledge of patristics. Cont ...
in his ''Nouveaux éléments de géométrie'' (1667). 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
Bernard (''Bernhard'') is a French and West Germanic masculine given name. It is also a surname.
The name is attested from at least the 9th century. West Germanic ''Bernhard'' is composed from the two elements ''bern'' "bear" and ''hard'' "brav ...
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'' (1704), by
Philippe de La Hire in ''Mémoires de l'Académie des Sciences'' for the Royal Academy (1705), and by
Joseph Sauveur
Joseph Sauveur (24 March 1653 – 9 July 1716) was a French mathematician and physicist. He was a professor of mathematics and in 1696 became a member of the French Academy of Sciences.
Life
Joseph Sauveur was born in La Flèche, the son of a ...
in ''Construction des quarrés magiques'' (1710). 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
Benjamin Franklin ( April 17, 1790) was an American polymath who was active as a writer, scientist, inventor
An invention is a unique or novel device, method, composition, idea or process. An invention may be an improvement upon a m ...
published a semi-magic square that 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'' (1837–1838), 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, (thus calling them Nasik squares) in a series of articles: ''On the knight's path'' (1877), ''On the General Properties of Nasik Squares'' (1878), ''On the General Properties of Nasik Cubes'' (1878), ''On the construction of Nasik Squares of any order'' (1896). He showed that it is impossible to have normal singly-even pandiagonal magic squares. 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'' (1888).
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
The Luoshu (pinyin), Lo Shu ( Wade-Giles), or Nine Halls Diagram is an ancient Chinese diagram and named for the Luo River near Luoyang, Henan. The Luoshu appears in myths concerning the invention of writing by Cangjie and other culture heroes. ...
(洛書) 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
''Parshvanatha'' (), also known as ''Parshva'' () and ''Parasnath'', was the 23rd of 24 '' Tirthankaras'' (supreme preacher of dharma) of Jainism. He is the only Tirthankara who gained the title of ''Kalīkālkalpataru ( Kalpavriksha in this " ...
temple in
Khajuraho, India.
This is known as the ''Chautisa Yantra'' (''Chautisa'', 34; ''
Yantra'', lit. "device"), 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 (of the 4×4 as well as the four contained 3×3 grids). This sum can also be found in the four outer numbers clockwise from the corners (3+8+14+9) and likewise the four counter-clockwise (the locations of four
queens
Queens is a borough of New York City, coextensive with Queens County, in the U.S. state of New York. Located on Long Island, it is the largest New York City borough by area. It is bordered by the borough of Brooklyn at the western tip of Long ...
in the two solutions of the
4 queens puzzle), the two sets of four symmetrical numbers (2+8+9+15 and 3+5+12+14), the sum of the middle two entries of the two outer columns and rows (5+9+8+12 and 3+2+15+14), and in four kite or cross shaped quartets (3+5+11+15, 2+10+8+14, 3+9+7+15, and 2+6+12+14). 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," which are the initials of the artist.
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
Barcelona ( , , ) is a city on the coast of northeastern Spain. It is the capital and largest city of the autonomous community of Catalonia, as well as the second most populous municipality of Spain. With a population of 1.6 million within ...
, 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
Jesus, likely from he, יֵשׁוּעַ, translit=Yēšūaʿ, label=Hebrew/Aramaic ( AD 30 or 33), also referred to as Jesus Christ or Jesus of Nazareth (among other names and titles), was a first-century Jewish preacher and religiou ...
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.
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.
Parker square
The Parker Square, named after recreational mathematician
Matt Parker,
is an attempt to create a 33 magic square of squares — a prized unsolved problem since
Euler. The Parker Square is a trivial semimagic square since it uses some numbers more than once, and the diagonal sums to , not as for all the other rows, columns, or diagonal. The Parker Square became a "mascot for people who give it a go, but ultimately fall short". It is also a metaphor for something that is almost right, but is a little off.
Gardner square
The Gardner Square, named after recreational mathematician
Martin Gardner, similar to the Parker square,
is given as a problem to determine a, b, c and d;
This solution for a=74, b=113, c=94 and d=97 gives a semimagic square; the diagonal sums to , not as for all the other rows, columns and diagonal;
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. 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 (sequence
A006003 in the
OEIS).
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 (that is, where order ''n'' = 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.
[ (Thus for example a corner cell of a 3×3 square has a distance of a non-corner edge cell has a distance of 1, and the center cell has a distance of 0.) 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 (i.e. each number subtracted from ''n''2 + 1) will give a rotated or reflected version of the original magic square.
* ''Associative magic square
In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement f ...
'' 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 ''n''2 + 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" (in some sense) 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 (i) each 2×2 subsquare add to 1/''k'' of the magic constant where ''n'' = 4''k'', and (ii) all pairs of integers distant ''n''/2 along any diagonal (major or broken) are complementary (i.e. they sum to ''n''2 + 1). 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 (i) every bent diagonal adds to the magic constant, (ii) every half row and half column starting at an outside edge adds to half the magic constant, and (iii) 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 ≤ ''k'' ≤ ''P''. They are also known as ''P-multimagic square'' or ''satanic squares''. They are also referred to as ''bimagic squares'', ''trimagic squares'', ''tetramagic squares'', ''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 (trivial) 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
In mathematics, when the elements of some set S have a notion of equivalence (formalized as an equivalence relation), then one may naturally split the set S into equivalence classes. These equivalence classes are constructed so that elements ...
-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 5, not counting rotations and reflections is:
: 1, 0, 1, 880, 275305224.
The number for ''n'' = 6 has been estimated to be ["Number of Magic Squares From Parallel Tempering Monte Carlo]
arxiv.org, April 9, 1998. Retrieved November 2, 2013.
; 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:
: 1, 0, 1, 255, 251449712 .
; 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 number of magic tori and distinct normal squares is not yet known for any higher order.[Anything but square: from magic squares to Sudoku]
by Hardeep Aiden, Plus Magazine, March 1, 2006
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
Monte Carlo methods, or Monte Carlo experiments, are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. The underlying concept is to use randomness to solve problems that might be deter ...
has been applied. The basic principle applied to magic squares is to randomly generate ''n'' × ''n'' matrices of elements 1 to ''n''2 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
* The sum of any two magic squares of the same order by matrix addition is a magic square.
* A magic square remains magic when all of its numbers undergo the same linear transformation (i.e., a function of the form ). For example, a magic square remains magic when its numbers are multiplied by any constant. Moreover, 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 of order is subtracted from , the complement of the original square is obtained. In the example below, each element of the magic square on the left is subtracted from 17 to obtain the complement magic square on the right.
* A magic square remains magic when transformed by any element of , the symmetry group of a square (see ). Every combination of one or more rotations
Rotation, or spin, is the circular movement of an object around a '' central axis''. A two-dimensional rotating object has only one possible central axis and can rotate in either a clockwise or counterclockwise direction. A three-dimensional ...
of 90 degrees, reflections, or both produce eight trivially distinct squares which are generally considered equivalent. The eight such squares are said to make up a single equivalence class
In mathematics, when the elements of some set S have a notion of equivalence (formalized as an equivalence relation), then one may naturally split the set S into equivalence classes. These equivalence classes are constructed so that elements ...
. The eight equivalent magic squares for the 3×3 magic square are shown below:
* A magic square of order remains magic when both its rows and columns are symmetrically permuted by such that for . Every permutation of the rows or columns preserves all row and column sums, but generally not the two diagonal sums. If the same permutation is applied to both the rows and columns, then diagonal element in row and column is mapped to row and column which is on the same diagonal; therefore, applying the same permutation to rows and columns preserves the main (upper left to lower right) diagonal sum. If the permutation is symmetric as described, then the diagonal element in row and column is mapped to row and column which is on the same diagonal; therefore, applying the same symmetric permutation to both rows and columns preserves both diagonal sums. For even , there are such symmetric permutations, and for odd. In the example below, the original magic square on the left has its rows and columns symmetrically permuted by resulting in the magic square on the right.
* A magic square of order remains magic when rows and are exchanged and columns and are exchanged because this is a symmetric permutation of the form described above. In the example below, the square on the right is obtained by interchanging the 1st and 4th rows and columns of the original square on the left.
* A magic square of order remains magic when rows and are exchanged, rows and are exchanged, columns and are exchanged, and columns and are exchanged where