Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The complete count of the special order-three magic squares

Proved
MagicSquares.special_three_count

by Yuxuan Xu · Sep 18, 2026 · Mathlib 0df444a (Lean v4.33.1)

combinatoricsenumerative-combinatoricsmagic-squares

The special classes of order-three magic squares, counted completely.

Let P3(t)P_{3}(t)P3​(t) be the number of panmagic (pandiagonal) squares of order three and line sum ttt — those 3×33\times33×3 arrays of nonnegative integers whose rows, columns and all six broken diagonals sum to ttt — and let S3(t)S_{3}(t)S3​(t) be the number of symmetric magic squares of order three and line sum ttt. The theorem determines both, for every ttt:

P3(t)={1,3∣t0,3∤t,S3(t)={2t3+1,3∣t0,3∤t.P_{3}(t)=\begin{cases}1,&3\mid t\\ 0,&3\nmid t\end{cases}, \qquad S_{3}(t)=\begin{cases}\dfrac{2t}{3}+1,&3\mid t\\[2mm] 0,&3\nmid t\end{cases}.P3​(t)={1,0,​3∣t3∤t​,S3​(t)=⎩⎨⎧​32t​+1,0,​3∣t3∤t​.

What the answers say. Where MacMahon's count for the plain magic squares of order three is quadratic (M3(3e)=2e2+2e+1M_{3}(3e)=2e^{2}+2e+1M3​(3e)=2e2+2e+1), the two special classes are degenerate in opposite ways. The six broken diagonals are so restrictive that they collapse the whole two-parameter family to the single constant square: for line sum 3e3e3e that is the array all of whose entries equal eee. Symmetry, by contrast, removes only three of the eight line conditions, and what survives is a genuine one-parameter family

(a2e−ae2e−aeaea2e−a),a=0,1,…,2e,\begin{pmatrix} a & 2e-a & e\\ 2e-a & e & a\\ e & a & 2e-a\end{pmatrix}, \qquad a=0,1,\dots,2e ,​a2e−ae​2e−aea​ea2e−a​​,a=0,1,…,2e,

giving the linear count 2e+12e+12e+1. In both cases the divisibility obstruction for order-three magic squares — the centre equals one third of the line sum, by center_of_order_three — forces the vanishing off multiples of three.

Proof. The two evaluations at t=3et=3et=3e are supplied by pan_three_card and by symm_three_bij composed with the cardinality of the parameter interval {0,…,2e}\{0,\dots,2e\}{0,…,2e}; the two vanishing cases are supplied by pan_three_otherwise and symm_three_otherwise, both of which reduce to the centre identity. Splitting on whether 3∣t3\mid t3∣t and substituting t=3et=3et=3e finishes the count.

Context. This is the fourth and last instalment of the order-three programme: after counting all squares (Mission I), all semi-magic ones (Mission II) and classifying the normal ones (Mission III), the special classes complete the picture. The comparison between the three counts — quadratic, linear and constant — is the point of the order-three study, and it is what is lost at order four, where no closed form is known.

Preamble
import Mathlib
import Definitions.Def_MagicSquares
import Definitions.Def_MagicSquaresSpecial3
open MagicSquares
Formal statement
namespace MagicSquares

theorem special_three_count (t : ℕ) :
    panMagicCount 3 t = (if 3 ∣ t then 1 else 0) ∧
      symmetricMagicCount 3 t = (if 3 ∣ t then 2 * (t / 3) + 1 else 0) := by sorry

end MagicSquares
Source
P. A. MacMahon, Combinatory Analysis, Vol. II, Cambridge University Press, 1916; M. Beck, T. Cohen, J. Cuomo and P. Gribelyuk, The number of "magic" squares, cubes and hypercubes, Amer. Math. Monthly 110 (2003), 707--717 (arXiv:math/0201013); W. S. Andrews, Magic Squares and Cubes, 2nd ed., Dover, 1960.
Human review
  • Endorsed by Shuze Chen · Sep 18, 2026

  • Endorsed by Yuxuan Xu · Sep 18, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, licensed under Apache 2.0.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTermsJoin SlackJoin Zulip© 2026 Prove2Me