A pandiagonal magic square or panmagic square (also diabolic square, diabolical square or diabolical magic square) is a magic square with the additional property that the broken diagonals, i.e. the diagonals that wrap round at the edges of the square, also add up to the magic constant.
A pandiagonal magic square remains pandiagonally magic not only under rotation or reflection, but also if a row or column is moved from one side of the square to the opposite side. As such, an n×n pandiagonal magic square can be regarded as having 8n2 orientations.
It is easily shown that non-trivial pandiagonal numerical magic squares of order 3 do not exist. However, if the magic square concept is generalized to include geometric shapes instead of numbers—the geometric magic squares discovered by Lee Sallows—a 3×3 panmagic square does exist.
The smallest non-trivial pandiagonal magic squares consisting of numbers are 4×4 squares.
In 4×4 panmagic squares, the magic constant of 34 can be seen in a number of patterns in addition to the rows, columns and diagonals:
Thus of the 86 possible sums adding to 34, 52 of them form regular patterns, compared with 10 for an ordinary 4×4 magic square.
There are only three distinct 4×4 pandiagonal magic squares, namely A above and the following:
These three are very closely related. B and C can be seen to differ only because the components of each semi-diagonal are reversed. It is not as easy to see how A relates to the other two but:
i: if the components of each semi-diagonal of A are reversed (A1) and the left-hand column of A1 is moved to the extreme right (A2), the result is a reflection of B
ii: if the left-hand column of A is moved to the extreme right (A3), the components of each semi-diagonal of A3 are reversed (A4), and the right-hand column of A4 is moved to the extreme left (A5), the result is C
In any 4×4 pandiagonal magic square, the two numbers at the opposite corners of any 3×3 square add up to 17. Consequently, no 4×4 panmagic squares are associative, though they all fulfil the further requirement for a 4×4 most-perfect magic square, that each 2×2 subsquare sums to 34.
There are many 5×5 pandiagonal magic squares. Unlike 4×4 panmagic squares, these can be associative. The following is a 5×5 associative panmagic square: