arXiv:2610.38386math.COOct 2026

Manuscript Offprint

arXiv:2610.38386

Moments of Magic Squares: Line-Sum Conditions, a Permutation Threshold, and Random Energies

Kyle Elliott Mathewson

Abstract

Every semi-magic square of order nn satisfies the axial moment identities ∑i,jsijjm=∑i,jsijim=M(n)∑jjm\sum_{i,j} s_{ij} j^m = \sum_{i,j} s_{ij} i^m = M(n) \sum_j j^m for all m≥1m \geq 1, where M(n)=n(n2+1)/2M(n) = n(n^2 + 1)/2. For real matrices the converse requires 1≤m≤n−11 \leq m \leq n-1, whereas for arrangements of {1,…,n2}\{1, \ldots, n^2\} fewer moments suffice once n≥14n \geq 14. We define the permutation threshold k∗(n)k^*(n) as the least kk such that every arrangement satisfying these identities for 1≤m≤k1 \leq m \leq k is semi-magic. In terms of the column-sum deviations γj\gamma_j, the degree-kk conditions state that ∑jγjtj\sum_j \gamma_j t^j is divisible by (t−1)k+1(t-1)^{k+1}, linking k∗(n)k^*(n) to the Prouhet–Tarry–Escott problem. While Schur’s bound on real zeros gives k∗(n)≤2(n−1)log⁡(n4/4)k^*(n) \leq \sqrt{2(n-1)} \log(n^4/4), we prove the converse realisability bound k∗(n)≥(2−o(1))nk^*(n) \geq (\sqrt{2}-o(1))\sqrt{n} (and k∗(n)≥(6−o(1))nk^*(n) \geq (\sqrt{6}-o(1))\sqrt{n} when 4∣n4 \mid n) by perturbing semi-magic squares with complementary row pairs via horizontal swaps. We also show that k∗(n)=n−1k^*(n) = n-1 for 3≤n≤133 \leq n \leq 13, k∗(n)=n−2k^*(n) = n-2 for 14≤n≤1714 \leq n \leq 17, and k∗(n)≤n−3k^*(n) \leq n-3 for n≥18n \geq 18, and determine k∗(n)k^*(n) for 18≤n≤4018 \leq n \leq 40 with computer assistance. Finally, at the k=1k=1 level of the hierarchy, we specialise the Mantel–Hubert quadratic assignment variance formula to obtain exact means, variances, and limit laws under a uniform random arrangement for the full line-sum energy EfullE_{\text{full}}, for the four-term energy E4E_4 combining the first moments and the two diagonals, and for Loly’s moment of inertia, and find that ∣L4∣=14,639,440|L_4| = 14,639,440 arrangements of order 4 satisfy E4=0E_4 = 0.

Keywords: magic squares, Prouhet–Tarry–Escott problem, polynomials with integer coefficients, permutation statistics, combinatorial central limit theorem, moment of inertia

MSC 2020: 05B20 (primary); 05A05, 11C08, 60C05, 60F05

1 Introduction

Magic squares are among the oldest objects of recreational mathematics: the 3×33 \times 3 Lo Shu appears in Chinese sources more than two millennia old, a 4×44 \times 4 square is engraved in Dürer’s Melencolia I (1514), and constructions for every order have been known since the seventeenth century [4, 36]. The modern literature treats them through enumeration and the geometry of the associated polytopes [41, 17, 1, 6, 5], through spectral and matrix properties [28, 34, 35, 13], and, in work of Loly and collaborators, through physical invariants such as the moment of inertia and the multipole moments [26, 38, 39].

Definition 1.1 (Magic square). An arrangement of order nn is a bijection S=(sij)S = (s_{ij}) from the cells of the n×nn \times n grid onto {1,…,n2}\{1, \ldots, n^2\}. It is a magic square if every row, every column and both main diagonals sum to the magic constant M(n)=n(n2+1)/2M(n) = n(n^2 + 1)/2, and semi-magic if the rows and columns do.

We centre both the grid and the entries (Definition 2.1): the cell (i,j)(i,j) sits at (xj,yi)=(j−n−12,n−12−i)(x_j, y_i) = (j - \frac{n-1}{2}, \frac{n-1}{2} - i) and carries the centred value zij=sij−n2+12z_{ij} = s_{ij} - \frac{n^2+1}{2}. A test function is a real function φ\varphi on the cells, paired with zz through the normalised inner product ⟨φ,z⟩=n−2∑i,jφijzij\langle \varphi, z \rangle = n^{-2} \sum_{i,j} \varphi_{ij} z_{ij}. Requiring a line LL to sum to M(n)M(n) is equivalent to requiring zz to be orthogonal to the centred indicator of LL, so an arrangement is magic if and only if zz is orthogonal to a fixed 2n2n-dimensional subspace WW of test functions—recovering the classical fact that real magic squares of order n≥3n \geq 3 form a vector space of dimension n2−2nn^2 - 2n [44]—while the squared length of the line-deviation vector, ∑LδL2\sum_L \delta_L^2, is the energy functional studied in the Monte Carlo work of Pinn and Wieczerkowski [37].

In the companion paper [30], the triples (xj,yi,zij)(x_j, y_i, z_{ij}) are viewed geometrically as a lifted point set in R3\mathbb{R}^3 whose convex hull is the Magic Gem of the square. Here we ask a complementary algebraic and probabilistic question: how closely do low-degree polynomial moments of zz approximate the full line-sum conditions when SS is constrained to be a permutation of {1,…,n2}\{1, \ldots, n^2\}? This question leads to two interconnected problems—one extremal, one quantitative—that form the two halves of the paper.

The permutation threshold. Replacing the line indicators by the powers xmx^m and ymy^m, 1≤m≤k1 \leq m \leq k, gives the degree-kk conditions ∑i,jzijxjm=∑i,jzijyim=0\sum_{i,j} z_{ij} x_j^m = \sum_{i,j} z_{ij} y_i^m = 0; equivalently, the moments of orders 1,…,k1, \ldots, k of the vector of column-sum deviations and of the vector of row-sum deviations vanish (Lemma 3.2). They hold for every semi-magic square, and for real-valued zz they imply equal row and column sums if and only if k≥n−1k \geq n-1 (Vandermonde). For arrangements, integrality and the bounded size of the line sums lower this threshold. Let k∗(n)k^*(n) be the least kk such that every arrangement satisfying the degree-kk conditions is semi-magic. A witness for k∗(n)≥Kk^*(n) \geq K is an arrangement that satisfies the degree-(K−1)(K-1) conditions and is not semi-magic. The degree-kk conditions say that the polynomial ∑jγjtj\sum_j \gamma_j t^j formed from the column deviations is divisible by (t−1)k+1(t-1)^{k+1}, and similarly for the rows, so that the positive and negative parts of γ\gamma form a solution of a Prouhet–Tarry–Escott system [45, 10]. Our main result is the lower bound in Theorem 3.7(b); together with Schur’s bound, Theorem 3.7(a), it gives

(2−o(1))n≤k∗(n)≤2(n−1)log⁡(n4/4)≤22nlog⁡n,(\sqrt{2}-o(1))\sqrt{n}\leq k^{*}(n)\leq\sqrt{2(n-1)\log(n^{4}/4)}\leq2\sqrt{2}\sqrt{n\log n},

with 6\sqrt{6} in place of 2\sqrt{2} when 4∣n4 \mid n. We also prove k∗(n)=n−1k^{*}(n) = n - 1 for 3≤n≤133 \leq n \leq 13, k∗(n)=n−2k^{*}(n) = n - 2 for 14≤n≤1714 \leq n \leq 17 and k∗(n)≤n−3k^{*}(n) \leq n - 3 for all n≥18n \geq 18, with short proofs in which the lower bounds rest on explicit witness arrangements (printed in Appendix D for n≤13n \leq 13), and, separately and with computer assistance, we determine k∗(n)k^{*}(n) for 18≤n≤4018 \leq n \leq 40 (Table 2).

The upper bound does not use that γ\gamma comes from an arrangement, only that it is a nonzero integer vector with ∥γ∥1≤n4/4\|\gamma\|_1 \leq n^4/4. For such vectors it is Schur's bound on the number of real zeros [40, 19]; the same order follows from Mignotte's lower bound for the height of an integer polynomial with a zero of high order at 1 [31, 3] and from [11, Thm. 2.1]. It is below n−1n-1 from n=24n=24 on and improves on k∗(n)≤n−3k^*(n) \leq n-3 from n=30n=30 on. In the other direction, Amoroso's upper bound [3, Thm. 2], obtained from the Bombieri–Vaaler form of Siegel's lemma [9], gives, for large nn, such vectors with a zero of order (24−o(1))n(\sqrt{24}-o(1))\sqrt{n} at 1, and between the orders 24n\sqrt{24n} and 8nlog⁡n\sqrt{8n\log n} lies the known gap, by a factor of order log⁡n\sqrt{\log n}, between the constructions and the bounds for integer polynomials with a zero of prescribed order at 1 [31, 9, 3, 11]. The new ingredient is the realisability direction behind the lower bound: integer vectors of this kind must be column-deviation vectors of arrangements whose row sums all equal M(n)M(n). We obtain them from semi-magic squares with many pairs of complementary rows, in which swaps realise prescribed column deviations, combined with the pigeonhole principle. Whether k∗(n)k^*(n) grows like n\sqrt{n} or like nlog⁡n\sqrt{n\log n} remains open, and the computed values for 14≤n≤10014 \leq n \leq 100 (exact for n≤40n \leq 40, upper bounds beyond) do not decide it (Figure 2). Let U(n)U(n) be the least kk for which the lattice of admissible γ\gamma contains no nonzero vector obeying the size constraints satisfied by column deviations, so that k∗(n)≤U(n)k^*(n) \leq U(n). Then k∗(n)=U(n)k^*(n) = U(n) for n≤40n \leq 40, witnesses prove k∗(n)≥U(n)k^*(n) \geq U(n) for 41≤n≤4641 \leq n \leq 46 (with U(n)U(n) computed but not certified), and we conjecture that k∗(n)=U(n)k^*(n) = U(n) for all nn (Conjecture 3.15).

Random arrangements and the k=1k=1 relaxation. While Section 3 asks when degree-kk axial moments force semi-magicness, Sections 4 and 5 examine the lowest non-trivial level k=1k=1 of the moment hierarchy across the entire permutation group Sn2S_{n^2}. For a uniformly random arrangement, each inner product ⟨φ,z⟩\langle \varphi, z \rangle is a linear permutation statistic, so both the full line-sum energy Efull=N−2∑LδL2E_{\mathrm{full}} = N^{-2} \sum_L \delta_L^2 (N=n2N = n^2, all 2n+22n + 2 lines) and the four-term energy E4E_4—which replaces the 2n2n row and column sums by the two degree-1 axial moments ⟨x,z⟩\langle x, z \rangle and ⟨y,z⟩\langle y, z \rangle while keeping the two main diagonals (Definition 2.4)—are quadratic forms in a random permutation of the centred values, i.e. quadratic assignment statistics. Specialising the permutation variance formula of Mantel [29] and Hubert [23] to symmetric matrices with zero row sums via Möbius inversion on the partition lattice (Proposition 4.3), we express the variance in terms of three matrix trace invariants and obtain exact closed-form means and variances for both energies at every order nn (Theorem 4.4). Hoeffding's combinatorial central limit theorem then shows that E4/E[E4]→dExp(1)E_4/\mathbb{E}[E_4] \xrightarrow{d} \mathrm{Exp}(1) as n→∞n \to \infty (Corollary 4.5), dominated by the two first-moment terms ⟨x,z⟩2+⟨y,z⟩2\langle x, z \rangle^2 + \langle y, z \rangle^2. As a byproduct, the same inner-product framework yields the exact mean and variance of Loly's moment-of-inertia invariant I(S)=∑sij(xj2+yi2)I(S) = \sum s_{ij}(x_j^2 + y_i^2) over random permutations (Corollary 4.2), showing that Loly's constant n2(n4−1)/12n^2(n^4 - 1)/12 for semi-magic squares [26] is simply the null expectation E[I(S)]\mathbb{E}[I(S)].

Finally, in Section 5 we study the zero set Ln={E4=0}L_n = \{E_4 = 0\} for small nn. Although k∗(3)=2k^*(3) = 2 for axial moments alone, we give a short elementary proof that adding the two main diagonals at n=3n = 3 collapses the k=1k = 1 zero set L3L_3 to the 8 magic squares (Proposition 5.1). At order n=4n = 4, by contrast, a meet-in-the-middle enumeration shows that exactly ∣L4∣=14,639,440|L_4| = 14,639,440 of the 16! arrangements satisfy E4=0E_4 = 0, of which 7,040 are magic (Proposition 5.3), in close agreement with a Gaussian local-limit heuristic.

Organisation. Section 2 sets up the centred coordinates, the orthogonal decomposition onto the line space WW, and the classical permutation-statistic tools, summarised in Table 1. Section 3 treats the polynomial moment hierarchy and proves Theorem 3.7 on the permutation threshold k∗(n)k^*(n) (with the complementary-row square constructions in Appendix B and explicit witnesses in Appendix D). Section 4 establishes the exact mean, variance and limit law of EfullE_{\mathrm{full}}, E4E_4 and I(S)I(S) for random arrangements (with the explicit trace evaluations in Appendix C), Section 5 analyses the zero sets L3L_3 and L4L_4 and single-transposition energy gaps, and Section 6 collects open questions. All computational verifications and exact certificates are documented in Appendix A.