Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Canonical decomposition of a 3x3 semi-magic square

Proved
MagicSquares.sm3_canonical

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

combinatoricsenumerative-combinatoricsmagic-squares

Every 3×33\times33×3 semi-magic square with nonnegative integer entries and line sum ttt can be written uniquely as a nonnegative integer combination

M=u D+v E+w F+x A+y B+z CM=u\,D+v\,E+w\,F+x\,A+y\,B+z\,CM=uD+vE+wF+xA+yB+zC

of the six order-three permutation matrices, normalized by min⁡(x,y,z)=0\min(x,y,z)=0min(x,y,z)=0. Here D,E,FD,E,FD,E,F are the three even transversals (the identity and the two 333-cycles) and A,B,CA,B,CA,B,C the three odd ones (the transpositions).

Existence. Put u=min⁡Du=\min Du=minD, v=min⁡Ev=\min Ev=minE, w=min⁡Fw=\min Fw=minF and subtract uD+vE+wFuD+vE+wFuD+vE+wF; the residual M′M'M′ is again semi-magic and each of its three even transversals has minimum 000. Writing M′M'M′ in the four-parameter form

(abt′−a−bcdt′−c−dt′−a−ct′−b−da+b+c+d−t′),\begin{pmatrix} a & b & t'-a-b\\ c & d & t'-c-d\\ t'-a-c & t'-b-d & a+b+c+d-t'\end{pmatrix},​act′−a−c​bdt′−b−d​t′−a−bt′−c−da+b+c+d−t′​​,

the three vanishing minima read

min⁡(a,d,a+b+c+d−t′)=min⁡(b,t′−c−d,t′−a−c)=min⁡(t′−a−b,c,t′−b−d)=0.\min(a,d,a+b+c+d-t')=\min(b,t'-c-d,t'-a-c)=\min(t'-a-b,c,t'-b-d)=0.min(a,d,a+b+c+d−t′)=min(b,t′−c−d,t′−a−c)=min(t′−a−b,c,t′−b−d)=0.

If b>cb>cb>c then each of the three ways for the middle minimum to vanish forces the opposite inequality: b=0b=0b=0 is impossible, t′−c−d=0t'-c-d=0t′−c−d=0 gives c+d=t′c+d=t'c+d=t′ and hence b≤cb\le cb≤c from b+d≤t′b+d\le t'b+d≤t′, and t′−a−c=0t'-a-c=0t′−a−c=0 gives a+c=t′a+c=t'a+c=t′ and hence b≤cb\le cb≤c from a+b≤t′a+b\le t'a+b≤t′. So b≤cb\le cb≤c, and symmetrically c≤bc\le bc≤b; thus b=cb=cb=c, which is exactly the statement that M′M'M′ is a combination of A,B,CA,B,CA,B,C alone.

Uniqueness. The normalization is essential: without it the single relation D+E+F=A+B+CD+E+F=A+B+CD+E+F=A+B+C (both sides equal the all-ones matrix) would identify distinct 666-tuples. With min⁡(x,y,z)=0\min(x,y,z)=0min(x,y,z)=0 the coefficients are recovered from MMM by u=min⁡Du=\min Du=minD, v=min⁡Ev=\min Ev=minE, w=min⁡Fw=\min Fw=minF and x=M00−ux=M_{00}-ux=M00​−u, y=M11−uy=M_{11}-uy=M11​−u, z=M01−vz=M_{01}-vz=M01​−v.

Formalization Note sm3Of is defined over N\mathbb{N}N with truncated subtraction where necessary, so every recovery identity has to be stated with the admissibility inequalities as explicit hypotheses.

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

theorem sm3_canonical (M : Square 3 ℕ) (t : ℕ) (hM : IsSemiMagic M t) :
    ∃ u v w x y z : ℕ,
      M = sm3Of u v w x y z ∧
        u + v + w + x + y + z = t ∧
          min x (min y z) = 0 ∧
            ∀ u' v' w' x' y' z' : ℕ,
              M = sm3Of u' v' w' x' y' z' →
                min x' (min y' z') = 0 →
                  u' = u ∧ v' = v ∧ w' = w ∧ x' = x ∧ y' = y ∧ z' = z := by sorry

end MagicSquares
Source
P. A. MacMahon, Combinatory Analysis (1915); M. Beck, T. Cohen, J. Cuomo, P. Gribelyuk, The number of "magic" squares, cubes and hypercubes, Amer. Math. Monthly 110 (2003), 707-717; arXiv:math/0201013v3, Section 2, Theorem 1.
Human review
  • Endorsed by Shuze Chen · Sep 17, 2026

  • Endorsed by Yuxuan Xu · Sep 17, 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