Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Total sum of a semi-magic square is n times the line sum

Proved
MagicSquares.total_sum_eq_n_line_sum

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

combinatoricsmagic-squares

Row-sum aggregation. Let AAA be an n×nn\times nn×n array over an additive commutative monoid, and suppose every row sums to the same value SSS (a semi-magic square of line sum SSS). Then the sum of all n2n^{2}n2 entries is

∑i∑jAij  =  n S.\sum_{i}\sum_{j} A_{ij} \;=\; n\,S .i∑​j∑​Aij​=nS.

Indeed the total is the sum of the nnn row sums, each of which equals SSS. This is the first structural identity of the theory: it is what converts the row condition into a global constraint, and it is the reason the magic constant of a normal magic square of order nnn must be n(n2+1)/2n(n^{2}+1)/2n(n2+1)/2 — the entries are 1,…,n21,\dots,n^{2}1,…,n2, whose total is n2(n2+1)/2n^{2}(n^{2}+1)/2n2(n2+1)/2, and dividing by nnn gives the line sum.

Formalization Note Entries live in an arbitrary AddCommMonoid, so the statement reads n∙Sn\bullet Sn∙S (nsmul) rather than n⋅Sn\cdot Sn⋅S; over N\mathbb{N}N or a semiring the two coincide. Only the row half of IsSemiMagic is used.

Preamble
import Mathlib
import Definitions.Def_MagicSquares
Formal statement
namespace MagicSquares

theorem total_sum_eq_n_line_sum {n : ℕ} {α : Type*} [AddCommMonoid α]
    (M : Square n α) (s : α) (hM : IsSemiMagic M s) :
    totalSum M = n • 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