Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Ehrhart-Macdonald reciprocity for the semi-magic counting function

Open
MagicSquares.semi_magic_reciprocity

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

combinatoricsehrhartenumerative-combinatoricsmagic-squares

The reciprocity law. Let n≥1n\ge 1n≥1 and let p∈Q[X]p\in\mathbb{Q}[X]p∈Q[X] agree with HnH_{n}Hn​ on the nonnegative integers. Then p(−n−t)=(−1)n−1p(t)p(-n-t)=(-1)^{n-1}p(t)p(−n−t)=(−1)n−1p(t) for every integer ttt. This is the reflection t↦−n−tt\mapsto -n-tt↦−n−t of the lattice-point count, rescaled by the sign (−1)n−1(-1)^{n-1}(−1)n−1; its right-hand side counts the interior of the corresponding polytope, by the Ehrhart--Macdonald reciprocity law. The identity is not visible from the combinatorial definition of HnH_{n}Hn​, which is stated only for nonnegative ttt.

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

theorem semi_magic_reciprocity (n : ℕ) (hn : 1 ≤ n) (p : Polynomial ℚ)
    (hp : ∀ t : ℕ, p.eval (t : ℚ) = (semiMagicCount n t : ℚ)) :
    ∀ t : ℤ, p.eval (((-(n : ℤ) - t : ℤ) : ℚ))
      = (-1 : ℚ) ^ (n - 1) * p.eval ((t : ℤ) : ℚ) := 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); E. Ehrhart (1973); R. P. Stanley, Duke Math. J. 40 (1973) 607--632; J. Spencer, Amer. Math. Monthly 87 (1980) 397--399; M. Beck and D. Paxton, The Ehrhart polynomial of the Birkhoff polytope (arXiv:math.CO/0202267).
Read-back

What the Lean code literally says, in plain math · deepseek-v4.1-flash (WorkBuddy blind sub-agent)

Let nnn be a natural number with 1≤n1\le n1≤n, and let p∈Q[X]p\in\mathbb{Q}[X]p∈Q[X] be any polynomial satisfying that for every natural number ttt, p(t)=semiMagicCount⁡(n,t)p(t)=\operatorname{semiMagicCount}(n,t)p(t)=semiMagicCount(n,t) (both sides viewed in Q\mathbb{Q}Q). Then for every integer ttt,

p((−n)−t)=(−1) n−1⋅p(t),p((-n)-t)=(-1)^{\,n-1}\cdot p(t),p((−n)−t)=(−1)n−1⋅p(t),

where (−n)−t(-n)-t(−n)−t denotes −n-n−n minus ttt (i.e. the integer −(n+t)-(n+t)−(n+t), with nnn first coerced to Z\mathbb{Z}Z and negated, then subtracting ttt, and finally lifted to Q\mathbb{Q}Q), and the exponent n−1n-1n−1 is the natural-number subtraction (safe because 1≤n1\le n1≤n). The base (−1)(-1)(−1) is the rational number −1-1−1 raised to the natural power n−1n-1n−1. Thus the theorem asserts a symmetry of ppp under the reflection t↦−n−tt\mapsto -n-tt↦−n−t, rescaled by the factor (−1)n−1(-1)^{n-1}(−1)n−1.

Human review
  • Endorsed by Shuze Chen · Sep 19, 2026

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