Magic square

A mathematical arrangement in which the natural numbers from 1 to n² are placed in an n×n grid so that the sums of the rows, columns, and diagonals are equal.

Magic square

Overview

A magic square (魔方陣, magic square) is an arrangement in which the natural numbers from 1 to n² are placed without repetition in an n×n square grid so that the sums of the numbers in each row, each column, and the two main diagonals are all equal. The common sum is called the magic constant, and the magic constant of an n-th-order magic square is calculated as n(n²+1)/2. Magic squares have been objects of mathematical curiosity and mysticism since ancient times, and today they are studied and used in various fields such as combinatorics, puzzles, art, and education.

Main content

Definition and basic properties

An n-th-order magic square is represented as an n×n matrix, and each element is an integer from 1 to n². The sum of every row, the sum of every column, and the sum of the two diagonals must be identical. The magic constant of a 3rd-order magic square is 3(9+1)/2 = 15. Magic squares exist from n=3 onward, and a 2nd-order magic square does not exist. The number of n-th-order magic squares increases exponentially as n grows; for order 3, there is 1 type excluding rotations and reflections, and for order 4, there are 880 types.

History

The origin of magic squares traces back to an ancient Chinese legend. The 'Luoshu (洛書)', which is said to have originated from a pattern carved on the back of a turtle that emerged from the Luo River during the reign of Yu the Great of the Xia dynasty, is known as an example of a 3rd-order magic square. It later spread to India, Arabia, and Europe, and in medieval Europe it was sometimes used with mystical and astrological meanings. The German painter Albrecht Dürer included a 4th-order magic square in his 1514 work 'Melencolia I'.

Types

  • Odd-order magic squares: When n is odd. They can be easily constructed using the Siamese method or the De la Loubère method.
  • Even-order magic squares: When n is even. They are further divided into 'doubly even-order' when n is a multiple of 4 and 'singly even-order' when n is not a multiple of 4. Doubly even-order squares are constructed by methods such as exchanging diagonals, and singly even-order squares by a method using auxiliary magic squares.
  • Panmagic square: A magic square in which not only the main diagonals but also all diagonals (including broken diagonals) have the same sum.
  • Most-perfect magic square: A magic square satisfying stronger conditions, such as the sums of 2×2 subsquares also being constant.
  • Magic cube: A concept extended to three-dimensional arrays.

Construction methods

The representative construction method for odd-order magic squares is the Siamese method. Place the first number, 1, in the center of the first row, then place subsequent numbers in the diagonal direction toward the upper right. If a position falls outside the grid, move to the opposite side; if the cell is already filled with a number, place the number in the cell directly below. This method can create all odd-order magic squares, including order 3, 5, and 7. Even-order magic squares require more complex algorithms; for 4th-order magic squares, a widely known method is to fill the numbers 1 through 16 in order and then symmetrically exchange the numbers on the main diagonal and the anti-diagonal.

Applications and significance

Magic squares are used beyond pure mathematical interest as educational tools for developing combinatorial thinking. They have also inspired puzzles, ciphers, artworks, architectural decoration, and more. Recently, research on generating and classifying magic squares using computer algorithms has been active, and attempts to search for magic squares using artificial intelligence are also being made.

Recent trends

As of 2024–2025, magic squares continue to receive steady attention in the mathematical community and in educational settings. In particular, research is underway to efficiently search for magic squares of larger orders by combining generative AI and combinatorial optimization algorithms. In addition, generative art works that use the symmetries and patterns of magic squares are increasing, and some researchers are exploring the possibility of applying magic square structures to qubit arrangements in quantum computing or to the design of error-correcting codes. In education, gamified learning content using magic squares has been developed and is contributing to the improvement of mathematical thinking skills.

Related topics

  • [[Combinatorics]]
  • [[Puzzle]]
  • [[History of mathematics]]
  • [[Latin square]]
  • [[Generative art]]