Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Transposing a magic square preserves magicness

Proved
MagicSquares.transpose_preserves_magic

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

combinatoricsmagic-squares

Transposition. If AAA is a magic square of line sum SSS, so is its transpose ATA^{\mathsf T}AT, with the same line sum.

The square is a symmetry of the n×nn\times nn×n grid, so it permutes the lines: rows of ATA^{\mathsf T}AT are the columns of AAA and vice versa, while each main diagonal is fixed. Hence every line of ATA^{\mathsf T}AT is a line of AAA and still sums to SSS, and the same holds verbatim for panmagic (pandiagonal) squares, whose broken diagonals are also carried to broken diagonals.

Formalization Note transpose is the entrywise flip (i,j)↦(j,i)(i,j)\mapsto(j,i)(i,j)↦(j,i) from Definitions.Def_MagicSquaresTransforms. The four line sums are tracked by rowSum_transpose, colSum_transpose, diagSum_transpose and antiDiagSum_transpose; the anti-diagonal case uses that i↦n−1−ii\mapsto n-1-ii↦n−1−i is a bijection of Fin n\mathrm{Fin}\,nFinn, so reindexing the sum is legitimate.

Preamble
import Mathlib
import Definitions.Def_MagicSquares
import Definitions.Def_MagicSquaresTransforms
Formal statement
namespace MagicSquares

theorem transpose_preserves_magic {n : ℕ} {α : Type*} [AddCommMonoid α]
    (M : Square n α) (s : α) (hM : IsMagic M s) :
    IsMagic (transpose M) s := by sorry

end MagicSquares
Source
Beck, Cohen, Cuomo & Gribelyuk, The number of ``magic'' squares, cubes and hypercubes, Amer. Math. Monthly 110 (2003), 707--717; arXiv:math/0201013v3.

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