Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The magic squares of order two

Proved
MagicSquares.magic_count_two

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

combinatoricsenumerative-combinatoricsmagic-squares

The order-two magic count. Writing Mn(t)M_{n}(t)Mn​(t) for the number of n×nn\times nn×n arrays of nonnegative integers whose rows, columns and two main diagonals all sum to ttt, the theorem states

M2(t)={1,2∣t,0,2∤t.M_{2}(t)=\begin{cases}1,&2\mid t,\\ 0,&2\nmid t.\end{cases}M2​(t)={1,0,​2∣t,2∤t.​

The single square is the constant array with every entry t/2t/2t/2. Proof. In the (at−at−aa)\begin{pmatrix} a & t-a\\ t-a & a\end{pmatrix}(at−a​t−aa​) family the two diagonals read 2a2a2a and 2(t−a)2(t-a)2(t−a); requiring both to equal ttt forces 2a=t2a=t2a=t. This is the first instance of the divisibility obstruction that governs every magic-square count: the diagonal conditions are not automatic, and they vanish off a sublattice of line sums.

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

theorem magic_count_two (t : ℕ) : magicCount 2 t = if 2 ∣ t then 1 else 0 := by sorry

end MagicSquares
Source
M. Beck, M. Cohen, J. Cuomo and P. Gribelyuk, The number of "magic" squares, cubes and hypercubes, Amer. Math. Monthly 110 (2003), 707--717 (arXiv:math/0201013).

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