Canonical decomposition of a 3x3 semi-magic square
ProvedMagicSquares.sm3_canonicalEvery semi-magic square with nonnegative integer entries and line sum can be written uniquely as a nonnegative integer combination
of the six order-three permutation matrices, normalized by . Here are the three even transversals (the identity and the two -cycles) and the three odd ones (the transpositions).
Existence. Put , , and subtract ; the residual is again semi-magic and each of its three even transversals has minimum . Writing in the four-parameter form
the three vanishing minima read
If then each of the three ways for the middle minimum to vanish forces the opposite inequality: is impossible, gives and hence from , and gives and hence from . So , and symmetrically ; thus , which is exactly the statement that is a combination of alone.
Uniqueness. The normalization is essential: without it the single relation (both sides equal the all-ones matrix) would identify distinct -tuples. With the coefficients are recovered from by , , and , , .
Formalization Note sm3Of is defined over with truncated
subtraction where necessary, so every recovery identity has to be stated with
the admissibility inequalities as explicit hypotheses.
import Mathlib import Definitions.Def_MagicSquares import Definitions.Def_MagicSquaresSemiMagic3 open MagicSquares
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
Confirmed by the mission captain (proposal self-audit).