Interior (positive) semi-magic counting function
DefinitionMagicSquares_positiveInteriorCountFor order and line sum , let be the number of semi-magic squares with nonnegative integer entries, line sum , and every entry strictly positive. In other words,
counted, as with , over arrays with entries in (which loses nothing since every entry of a line-sum- square is at most ).
These are exactly the interior lattice points of the dilated Birkhoff polytope : dilating the polytope of doubly stochastic matrices and counting interior integral points. The count is the bridge between the Ehrhart--Macdonald reciprocity law, which evaluates the Ehrhart polynomial at negative integers in terms of interior points, and the elementary shift bijection that identifies positive squares of line sum with ordinary squares of line sum .
Formalization Note Lean counts over Square n (Fin (t+1)) with positivity stated as 1 ≤ (M i j : ℕ) for the Fin-valued entries coerced to naturals, mirroring semiMagicCount.
import Definitions.Def_MagicSquares
set_option autoImplicit false
namespace MagicSquares
/-- The interior count: semi-magic squares of order `n` and line sum `t` with every entry positive. -/
noncomputable def positiveInteriorCount (n t : ℕ) : ℕ :=
by classical exact (Finset.univ.filter (fun M : Square n (Fin (t + 1)) =>
IsSemiMagic (fun i j => (M i j : ℕ)) t ∧ ∀ i j, 1 ≤ (M i j : ℕ))).card
end MagicSquares