Manuscript Offprint
arXiv:2610.38386Moments of Magic Squares: Line-Sum Conditions, a Permutation Threshold, and Random Energies
Abstract
Every semi-magic square of order satisfies the axial moment identities for all , where . For real matrices the converse requires , whereas for arrangements of fewer moments suffice once . We define the permutation threshold as the least such that every arrangement satisfying these identities for is semi-magic. In terms of the column-sum deviations , the degree- conditions state that is divisible by , linking to the Prouhet–Tarry–Escott problem. While Schur’s bound on real zeros gives , we prove the converse realisability bound (and when ) by perturbing semi-magic squares with complementary row pairs via horizontal swaps. We also show that for , for , and for , and determine for with computer assistance. Finally, at the 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 , for the four-term energy combining the first moments and the two diagonals, and for Loly’s moment of inertia, and find that arrangements of order 4 satisfy .
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 Lo Shu appears in Chinese sources more than two millennia old, a 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 is a bijection from the cells of the grid onto . It is a magic square if every row, every column and both main diagonals sum to the magic constant , and semi-magic if the rows and columns do.
We centre both the grid and the entries (Definition 2.1): the cell sits at and carries the centred value . A test function is a real function on the cells, paired with through the normalised inner product . Requiring a line to sum to is equivalent to requiring to be orthogonal to the centred indicator of , so an arrangement is magic if and only if is orthogonal to a fixed -dimensional subspace of test functions—recovering the classical fact that real magic squares of order form a vector space of dimension [44]—while the squared length of the line-deviation vector, , is the energy functional studied in the Monte Carlo work of Pinn and Wieczerkowski [37].
In the companion paper [30], the triples are viewed geometrically as a lifted point set in 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 approximate the full line-sum conditions when is constrained to be a permutation of ? 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 and , , gives the degree- conditions ; equivalently, the moments of orders 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 they imply equal row and column sums if and only if (Vandermonde). For arrangements, integrality and the bounded size of the line sums lower this threshold. Let be the least such that every arrangement satisfying the degree- conditions is semi-magic. A witness for is an arrangement that satisfies the degree- conditions and is not semi-magic. The degree- conditions say that the polynomial formed from the column deviations is divisible by , and similarly for the rows, so that the positive and negative parts of 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
with in place of when . We also prove for , for and for all , with short proofs in which the lower bounds rest on explicit witness arrangements (printed in Appendix D for ), and, separately and with computer assistance, we determine for (Table 2).
The upper bound does not use that comes from an arrangement, only that it is a nonzero integer vector with . 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 from on and improves on from 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 , such vectors with a zero of order at 1, and between the orders and lies the known gap, by a factor of order , 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 . 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 grows like or like remains open, and the computed values for (exact for , upper bounds beyond) do not decide it (Figure 2). Let be the least for which the lattice of admissible contains no nonzero vector obeying the size constraints satisfied by column deviations, so that . Then for , witnesses prove for (with computed but not certified), and we conjecture that for all (Conjecture 3.15).
Random arrangements and the relaxation. While Section 3 asks when degree- axial moments force semi-magicness, Sections 4 and 5 examine the lowest non-trivial level of the moment hierarchy across the entire permutation group . For a uniformly random arrangement, each inner product is a linear permutation statistic, so both the full line-sum energy (, all lines) and the four-term energy —which replaces the row and column sums by the two degree-1 axial moments and 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 (Theorem 4.4). Hoeffding's combinatorial central limit theorem then shows that as (Corollary 4.5), dominated by the two first-moment terms . As a byproduct, the same inner-product framework yields the exact mean and variance of Loly's moment-of-inertia invariant over random permutations (Corollary 4.2), showing that Loly's constant for semi-magic squares [26] is simply the null expectation .
Finally, in Section 5 we study the zero set for small . Although for axial moments alone, we give a short elementary proof that adding the two main diagonals at collapses the zero set to the 8 magic squares (Proposition 5.1). At order , by contrast, a meet-in-the-middle enumeration shows that exactly of the 16! arrangements satisfy , 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 , 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 (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 , and for random arrangements (with the explicit trace evaluations in Appendix C), Section 5 analyses the zero sets and and single-transposition energy gaps, and Section 6 collects open questions. All computational verifications and exact certificates are documented in Appendix A.
2.1 Centred coordinates
Throughout, and . Cells are pairs with (i the row from the top, j the column from the left).
Definition 2.1 (Centred coordinates). To the cell of an arrangement assign
We call the centred entries of , and regard and as functions on the cells.
The function is the vertical coordinate of the lifted points studied in the companion paper [30]. A line is one of the rows , the columns , the main diagonal or the anti-diagonal , and denotes the indicator of a line . Each line has cells, and since the deviation of a line is
We write , , , for the deviations of row , column and the two diagonals; . On the space we use and ; is the mean of and its centred version. For vectors in , such as and , and denote the usual and Euclidean norms.
Lemma 2.2. For every arrangement, , , , , and for every line .
Proof. and take and equally spaced values centred at 0, each equally often; ; the last claim is (2).
2.2 The line space and the energies
Let be the centred indicator of a line and , , , . denotes the orthogonal projection onto .
Lemma 2.3 (The line space). Let . For lines . Consequently:
-
consists of the zero-mean functions of the row index and of the zero-mean functions of the column index; both have dimension , and the orthogonal projection of onto them is , resp. .
-
, , are mutually orthogonal, and the Gram matrix of is with , for odd and -1 for even ; its eigenvalues are (odd ) and (even ).
-
has dimension 2n, and if and only if S is magic.
Proof. Each line has of the cells, which gives the inner products: a row meets every column and each diagonal in one cell, two distinct rows (or columns) are disjoint, and the diagonals meet in the centre cell if and only if is odd. The projection onto the functions of the row index replaces by its row means . Finally by Lemma 2.2.
Part 3 is equivalent to the classical fact that the real magic squares of order (all line sums equal to a common, arbitrary value) form a space of dimension [44].
Definition 2.4 (Energies). For an arrangement S with centred entries z,
We call the four-term energy.
keeps the diagonal conditions and replaces the 2n-2 independent row and column conditions by the two degree-1 moment conditions (Proposition 3.3); it is -invariant and has a fixed number of terms, which makes it a test case for a limit law (Corollary 4.5). By Lemma 2.2,
the sum of the squared deviations of all lines, a non-negative integer. This is the energy of the Monte Carlo study of Pinn and Wieczerkowski [37], who use ; we follow them in calling and energies. if and only if is magic, and depends on only through its projection onto (Figure 1). Both energies are invariant under the dihedral group of the square, which permutes the lines and maps to itself. All rows and columns are kept in (3): the last row and column are redundant for the zero set, but omitting them would destroy the -invariance.
Remark 2.5 (The four conditions). consists of four linear conditions on z, and “magic” of 2n independent ones; for every the four conditions are therefore strictly weaker than the magic conditions on real-valued z. For permutations the two coincide when n=3 (Proposition 5.1) but not when n=4: the arrangement
has both diagonal sums 34, row sums (28, 38, 44, 26) and column sums (37, 25, 43, 31), so and , and ; so while . Both orders are treated in Section 5.1.
Remark 2.6 (Linear functionals and ). By Lemma 2.3, with ,
and since the eigenvalues of are for odd and for even , comparison with (5) gives , with for odd and for even . Hence for every ; for instance , so the centre of mass is controlled by .
(a) z and the line deviations
| 9 | 4 | 12 | 3 |
|---|---|---|---|
| 16 | 1 | 14 | 7 |
| 10 | 15 | 11 | 8 |
| 2 | 5 | 6 | 13 |
column and row deviations
(b) if and only if magic

(c) and the subspaces
Figure 1: The line space for . is the -dimensional span of the centred line indicators, and (dimension ) is its orthogonal complement among the zero-mean functions. (a) The arrangement of Remark 2.5, shaded by , with its row and column deviations (both diagonal deviations are 0). (b) Schematic of the orthogonal splitting ; the arrangement is magic if and only if . (c) The squared norms and that of the complement, for the arrangement of (a) and for Dürer's magic square (all of lies in the complement).
2.3 Permutation statistics
Let be a uniformly random permutation of and . For the linear permutation statistics one has (here ) and, by the theorem of Wald and Wolfowitz [43, 33] (polarised),
For a uniformly random arrangement, with the centred values , ; we put
Hoeffding's combinatorial central limit theorem [22, Thm. 4 and condition (14), p. 560] states that for real vectors , the statistic is asymptotically normal, i.e. converges in distribution to , if
Motoo [32] gives a Lindeberg-type condition and Bolthausen [8] a Berry–Esseen bound.
2.4 Known counts
There are 8 magic squares of order 3, all images of the Lo Shu under ; 7,040 of order 4, forming the 880 -orbits listed by Frénicle de Bessy [20] and recounted many times since [5]; and 275,305,224 -orbits of order 5, i.e. 2,202,441,792 squares, counted by Schroeppel in 1973 and reported by Gardner [21]. For only statistical estimates are known [37, 42].
2.5 Notation
Table 1 lists the main symbols and where they are defined.
| symbol | meaning (where defined) |
|---|---|
| order, number of cells, magic constant (Definition 1.1) | |
| cell in row and column (); entry of the arrangement | |
| centred column and row coordinates, centred entries (Definition 2.1) | |
| , its norm, the mean and the centred version of (Section 2.1) | |
| deviation of the line ; row and column deviation vectors; (2) | |
| span of the centred line indicators; its row, column and diagonal parts; orthogonal projection onto (Lemma 2.3) | |
| times the Gram matrix of the centred diagonal indicators; ( odd), ( even) (Lemma 2.3) | |
| line-sum energy and four-term energy (Definition 2.4) | |
| (7) | |
| (Section 3.1) | |
| (Section 3.2) | |
| permutation threshold (Definition 3.6) | |
| least such that no nonzero vector of satisfies (10) (Section 3.5) | |
| for a random arrangement; standard deviation of (Section 4) | |
| Gram matrix of the centred test functions of an energy; correlation matrix of the four statistics of (Proposition 4.1, Corollary 4.5) | |
| matrix of an energy as a quadratic form in ; (Section 4.2, Appendix C) | |
| arrangements with ; the four additive statistics defining ; their covariance matrix (Section 5.1) |
Table 1: Notation.
3 Moment conditions and the permutation threshold
3.1 Moment conditions
For a centred let and be its column and row sums; for these are the deviations of . For put .
Definition 3.1 (Degree- conditions). A centred satisfies the degree- conditions () if for . For these read .
Lemma 3.2 (Polynomial form). If depends only on the column index, ; similarly for rows. For and the following are equivalent: (i) for ; (ii) for ; (iii) divides . Hence a centred satisfies the degree- conditions if and only if divides both and .
Proof. The first statement is . The families and both span the restrictions to of the polynomials of degree at most in , so (i) (ii); and is the Taylor expansion at , so (ii) (iii). The case of (i) holds for every centred .
Proposition 3.3 (Moment conditions). Let and let be centred.
(a) If , then for all functions on ; in particular satisfies the degree- conditions for every . For with magic, also .
(b) If , the degree- conditions imply .
(c) If , the function (), (), satisfies the degree- conditions but not the degree- conditions, and .
Proof. (a) is the first statement of Lemma 3.2. (b) A nonzero polynomial of degree at most is not divisible by . (c) Here and .
Part (a) contains the vanishing of the centre of mass and of all axial moments , of a semi-magic square, in the spirit of the multipole analysis of a magic cube by Rogers and Loly [39]. Parts (b) and (c) are the invertibility of a Vandermonde matrix. The mixed moments are not determined by the line sums:
Remark 3.4 (Mixed moments). The magic square with rows , , , (square #45 in the Frénicle numbering of [30]) has mixed moment (Loly's product of inertia). Among the 880 magic squares of order 4 up to , the mixed moment is nonzero for 824 and takes 48 distinct absolute values between 0 and 60, and the mixed moments , are nonzero for 623 and 773 of them. For the mixed moment vanishes for all eight magic squares, because for centrally opposite cells, so is odd under while is even.
Corollary 3.5 (Loly's invariant [26]). Let be the moment of inertia about the centre of the masses placed at . For every arrangement,
Hence if and only if the single condition holds; it is implied by the degree-2 conditions, hence by the semi-magic property.
Proof. Substitute and use Lemma 2.2 and Lemma 3.2: .
Loly’s derivation uses the row and column sums in the same way [26]. The single condition is much weaker than the degree-2 conditions: for of the 9! arrangements have , while 72 (the semi-magic squares, Remark 5.2) satisfy the degree-2 conditions. The energy of (4) combines the degree-1 conditions with the two diagonal conditions: .
3.2 The permutation threshold
By Proposition 3.3, for real-valued the degree- conditions force equal row and column sums exactly when . For arrangements the deviations are integers of bounded size, and the threshold drops.
Definition 3.6. For , is the least such that every arrangement of order satisfying the degree- conditions is semi-magic. A witness for is an arrangement that satisfies the degree- conditions and is not semi-magic.
By Proposition 3.3(b), . By Lemma 3.2, an arrangement satisfies the degree- conditions if and only if and lie in
(identifying with ; the quotient of an integer polynomial by the monic polynomial has integer coefficients), a lattice of rank . Writing with , the condition says that the multisets in which occurs , resp. , times have equal power sums of degrees : a Prouhet–Tarry–Escott system [45, 10]. Small vectors in are classical: the Prouhet–Thue–Morse vector ( the binary digit sum) has entries and lies in [45, 2], and Borwein, Erdélyi and Kós construct polynomials of degree with coefficients in vanishing to order at 1 [11, Thm. 2.7]; Borwein and Mossinghoff determine the least degree of such a polynomial with a zero of order at 1 for [12]. The question is therefore how large can be for vectors that are column-deviation vectors of arrangements.
Theorem 3.7 (The permutation threshold).
Part (a) is Schur’s bound on real zeros applied to (Lemma 3.9) and does not use that comes from an arrangement beyond the bound of Lemma 3.8; the constant is about 2.83. It is below from on, gives from on and improves on (c) from on; at and it gives 32 and 58, against the exact value 26 and the computed upper bound 45 (Figure 2). In part (c) the lower bounds rest on witness arrangements checked in exact arithmetic (printed in Appendix D for and documented in Appendix A for ), while the upper bounds are proved by hand. Part (d) is computer-assisted: its upper bounds come from an exact lattice enumeration backed by an arithmetic certificate, and its lower bounds from witness arrangements found by computer search and checked in exact arithmetic (Section 3.5).
3.3 Proof of the upper bound
Lemma 3.8 (Majorisation bound for column deviations). Let be the column-deviation vector of an arrangement. For every set of columns,
In particular , and . The same holds for .
Proof. The cells of carry distinct values, whose sum is at most that of the largest values, ; subtracting gives the upper bound, and the lower bound is symmetric. With the number of positive , . Finally, is majorised by the vector with , (equal totals, , and (10) bounds the partial sums of sorted in decreasing order by ; , and is Schur-convex.
Lemma 3.9 (Schur's bound at ). Let with for some . Then .
Proof. By a theorem of Schur [40] (see [19, (1.4)]), a polynomial with has at most real zeros, counted with multiplicity. Write with , and let . The nonzero coefficients of are the nonzero entries of , so the product of its constant and leading coefficients is a nonzero integer, the sum of their absolute values is , and . The polynomial has degree , the same nonzero coefficients, and is divisible by , so it has the real zeros , each of multiplicity at least . Hence .
The same argument gives the form of Schur's theorem for positive zeros in [11, Thm. A]. Mignotte's lower bound for the logarithmic height of a nonzero integer polynomial of degree less than with a zero of order at 1 [31], quoted in [3, Sect. 1], rests on the same theorem; with and Lemma 3.8 it gives . The order also follows from [11, Thms. 2.1 and 2.8], applied to .
Proof of Theorem 3.7(a). Let satisfy the degree- conditions with . If , then (Lemma 3.2) and (Lemma 3.8), contradicting Lemma 3.9. So , and likewise . The second inequality follows from .
Lemma 3.9 uses only that is a nonzero integer vector with , and Lemma 3.8 does not restrict the order of vanishing much further. By Amoroso's upper bound [3, Thm. 2], obtained from the Bombieri-Vaaler form of Siegel's lemma [9], as with and there are nonzero integer polynomials of degree less than with a zero of order at 1 whose coefficients are at most in absolute value. For and with this is for large ; then , and for , and also for since . So for large the lattice with contains nonzero vectors satisfying (10), and an upper bound for below this order must use more than Lemma 3.8. The pigeonhole principle alone, as in the proof of (b) below, gives the constant in place of . Between and Lemma 3.9 lies the gap, by a factor of order in the height, between the known lower and upper bounds for the least height of an integer polynomial of degree less than with
We read this theorem in the author's manuscript, not in the published version. The proof there (Section 5) begins by assuming , which is stronger than the hypothesis of the theorem and fails when K is of order , as here. What we say below about the order therefore rests on the theorem as stated, not on a proof we have checked.
a zero of order at 1 [31, 9, 3]; for coefficients in the analogous gap is between the orders and , and closing it “looks quite difficult” [11, Sect. 2]. Arguments that use integrality only through the size of one coefficient cannot close it: rescaled, [11, Thm. 2.3] gives real polynomials of degree with constant coefficient 1 and all coefficients at most in absolute value that have a zero of order at least at 1; see [18, Thms. 2.1 and 2.2] for explicit constants in the normalisations.
3.4 Proof of the lower bound: complementary-row swaps and a pigeonhole collision
To prove a lower bound , we must construct a witness arrangement whose row sums all equal (so ), whose column-deviation vector is nonzero, and whose polynomial is divisible by . The difficulty is that cannot be chosen freely in the lattice : it must arise from an actual permutation of with balanced rows.
Our strategy is to start from a semi-magic square and perturb it by horizontal transpositions—swapping two entries within the same row—which automatically preserve every row sum. Specifically, we group the columns into adjacent pairs with . Any horizontal swap between columns and changes the column-deviation vector by a multiple of , which contributes a dipole term to . Summing over all , the resulting polynomial factors as
Thus, if we can choose the net swap amplitudes so that the first binomial moments all vanish, then , which implies and hence .
How do we find a nonzero vector of achievable swap amplitudes with vanishing moments? By the pigeonhole principle (in the spirit of Siegel's lemma): in each column pair , we select rows and consider all subset sums of their swap differences . If the box has more elements than the number of possible moment tuples , two distinct subset-sum vectors must share the exact same moments, so their difference has for all .
There is just one catch: is a difference of two subset sums, meaning we must apply for and for simultaneously in disjoint rows. This is why we build our starting semi-magic squares out of complementary pairs of rows: if row and row sum to in every column, then the entry difference in row is the exact negative of the entry difference in row , giving us both and on disjoint cells.
Definition 3.10. Rows of an arrangement are complementary on a set of columns if for all .
Lemma 3.11 (Swaps in complementary rows). Let be semi-magic, let rows be complementary on , let and . Exchanging the entries of row in columns changes the column deviations by , exchanging those of row changes them by , and neither changes a row sum. Exchanges involving pairwise disjoint sets of cells can be combined, and their effects add.
Lemma 3.12 (Squares with many complementary rows).
-
If with even, or with odd and , there is a semi-magic square of order in which rows and are complementary on all columns, for .
-
If is odd, there is a semi-magic square of order in which rows and are complementary on the columns , for .
Part (1) does not cover ; this is irrelevant for Theorem 3.7(b), which concerns large . The proof is a direct construction, given in Appendix B.
Proposition 3.13 (Pigeonhole criterion). Let be a semi-magic square of order , let and with , and put for . For each let pairwise disjoint pairs of rows be complementary on the columns , let be the differences for the first rows of these pairs, and let be the set of subset sums , . If and
then there is an arrangement with all row sums and that satisfies the degree- conditions; hence .
Proof. The elements of lie in an interval of length . For the binomial moments , , are integers in intervals of lengths at most , so by (11) there are with for all . Write and . For every , perform the exchange of Lemma 3.11 in the first row of each pair in and in the second row of each pair in ; all these exchanges involve disjoint cells. The result has all row sums and with . Then with . Since for , Lemma 3.2 gives , so and . With , the arrangement satisfies the degree- conditions, and .
The are nonzero, and at least of them have the same sign; their partial sums, together with 0, are distinct, so . For the squares of Lemma 3.12 we take , and for even , and , and for odd : the -th pair then consists of the columns , and the complementary rows of Lemma 3.12(2) cover both columns if and only if and .
Proof of Theorem 3.7(b), first part. Fix and let ; we show that (11) holds, with replaced by , for all large covered by Lemma 3.12 (every is covered).
Right side. , and , so each factor is at most . From and ,
hence and
Left side. For even it is at least , with logarithm . For odd , with , , once (), so . Hence
Since , (11) holds for large , and .
The odd case thus gives the same constant as the even case, but more slowly: (11) with first gives at for even and only at for odd , and at and against . Notice why the general bound above stops at : it uses only the generic estimate , which gives . When , we can construct a semi-magic square whose swap differences in column pair form a shifted arithmetic progression , expanding the subset-sum set from to and tripling to , which boosts the threshold from to .
Proposition 3.14 (All subset sums). Let with even, and for put and .
(i) The square with , and is semi-magic, and its rows and are complementary on all columns.
(ii) With , and the pairs of rows , the sets of Proposition 3.13 satisfy for .
(iii) Hence as with .
Proof. (i) As runs over , the numbers and run over the odd numbers , so the entries , of rows and are , each once. In row the two entries in columns add up to , so the row sum is since is even; the same holds for row . Each column contains pairs of entries adding up to .
(ii) Here , so is the number of subset sums of . For the sums of the -element subsets of are all integers in (pass from to by raising one element by 1 at a time), so the sums of the -element subsets of form a set of integers in . Let . If , then , since and . So the sets with , are pairwise disjoint; each has more than elements, and their number is
using , and . Hence .
(iii) Fix and let . By (ii) the logarithm of the left side of (11) is at least . The bound for the right side in the proof of Theorem 3.7(b) uses only and , so its logarithm is at most . Since , (11) holds for large , and Proposition 3.13 gives .
Proposition 3.14(iii) is the second part of Theorem 3.7(b). The proof of (i) uses only that is even, so it re-proves Lemma 3.12(1) for even . For even, is at least for every , against in the count used for the first part. The convergence is slow: with , (11) gives at and at , and with the exact for the square of Proposition 3.14 it gives and , against and (Figure 2). Thus
(4|n),
with in place of for general n.
3.5 Exact values
Proof of Theorem 3.7(c). . Here , and the lower bound needs a witness for , i.e. an arrangement satisfying the degree- conditions that is not semi-magic. For n = 3 and n = 4,
In both cases and , so the degree- conditions hold. For we found arrangements with and , i.e. (Appendix D).
The lattices and . has rank 1 and is spanned by . If with , then , which exceeds for , contradicting Lemma 3.8. (At , ; passing from to multiplies the left side by 2 for even and by for odd , and the right side by , which decreases in and equals at ). So for ; at the bound fails , and the witness has central entry 924.
has rank 2: with . At , by Lemma 3.8; since for , and . By Parseval, (twice a Catalan number). At this factor is . From to the left side grows by the factor and the right side by . So for the bound of Lemma 3.8 forces , and . (At the next step has rank 3, with , where eliminating the three parameters requires more than evaluating at and Parseval's identity, so from onward we turn to exact lattice enumeration.)
Lower bounds for . For each of these we found an arrangement with all row sums whose column deviations satisfy and (verified in exact integer arithmetic, Appendix A; is listed in Table 2).
Proof of Theorem 3.7(d). Upper bounds. If no nonzero vector of satisfies (10) for every , then . By Lemma 3.8 only vectors with need be examined; we enumerated them exactly with two independent implementations (Appendix A). At the ball contains no nonzero vector for 16 of the 23 values of , since the Gram-Schmidt norms of the reduced basis already exceed the radius. For it contains 2, 2, 6, 6, 6, 2, 2 vectors. Each violates (10), in every case but one already with ; the exception is , where two of the six vectors need . The ancillary certificate (Appendix A) lists the reduced bases and, for each vector, a violated instance .
Lower bounds. For each we found a witness for , with the value of Table 2: an arrangement with all row sums whose column deviations satisfy and ; each was verified in exact integer arithmetic.
The witnesses. The target vectors were chosen among the shortest vectors of satisfying (10), as produced by the enumeration. Starting from a semi-magic square of Lemma 3.12 (or a Siamese (de la Loubère) magic square [4]), a steepest-descent search over exchanges within a row, which fix the row sums, minimised , with random exchanges to leave local minima; for the hardest cases a simulated annealing over arbitrary exchanges, with energy the squared distance of both row and column sums to their targets, was used. Some witnesses come close to the bound of Lemma 3.8: against 1014 at , and
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 12 | 13 | 14 | 15 | 15 | 16 | 16 | 17 | 17 | 18 | 18 | 19 | 19 | 20 | |
| 297 | 572 | 1001 | 2002 | 1430 | 2860 | 1794 | 3094 | 2210 | 3638 | 2380 | 4522 | 2736 | 4541 | |
| 1274 | 1575 | 1920 | 2312 | 2754 | 3249 | 3800 | 4410 | 5082 | 5819 | 6624 | 7500 | 8450 | 9477 | |
| 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | ||
| 21 | 21 | 22 | 22 | 23 | 23 | 23 | 24 | 24 | 25 | 25 | 26 | 26 | ||
| 8892 | 6405 | 11737 | 9330 | 14881 | 11799 | 9177 | 18147 | 14766 | 24150 | 16515 | 26520 | 22233 | ||
| 10584 | 11774 | 13050 | 14415 | 15872 | 17424 | 19074 | 20825 | 22680 | 24642 | 26714 | 28899 | 31200 |
Table 2: Exact values of the permutation threshold for (Theorem 3.7(c),(d)), the largest column deviation of the witness arrangement, and the bound of Lemma 3.8. The upper bounds for were computed by two independent exact lattice enumerations and, for , also by integer programming (Appendix A).
(a)

(b)

Figure 2: The permutation threshold. (a) Exact values of for (dots), computer-assisted upper bounds for (two independent implementations agree, not certified; open circles), the linear-algebra threshold , the bound of Theorem 3.7(a), the lower bounds given by (11) with (open squares, shown where they give ) and for with the square of Proposition 3.14 (crosses), and , the asymptotic order of (b) for . (b) The same exact values and upper bounds divided by and by .
24150 against 24642 at . For each the witness search succeeded at the last at which still contains a nonzero vector satisfying (10). Let be the least such that no nonzero vector of satisfies (10) for every ; by Lemma 3.8, , and the proofs of (c) and (d) show for .
Conjecture 3.15. for every .
We tested Conjecture 3.15 for , where both implementations give (not certified). For each of these the same search, run on the vectors of in the ball that satisfy (10), found a witness (verified in exact arithmetic; Appendix A). So , i.e. , holds unconditionally for ; only the upper bounds are uncertified, and the conjecture holds for these if they are correct. The hardest case was , where the ball contains a single such vector up to sign, with slack 7 in one instance of (10) with ; it and one of the 50 vectors for were realised only by a longer two-stage annealing. Beyond the values are computer-assisted upper bounds for (two independent implementations agree for every , but the values carry no certificate); for instance , and . In Figure 2(b), (and beyond ) grows from 3.2 at to 4.5 at , while the same values divided by stay between 2.06 and 2.18 for . These data do not discriminate between the orders and : by Section 3.3, the unconditional pigeonhole bound already gives (and Amoroso's bound gives ), so a steady rise of across is expected even if is of order .
4 The energy of a random arrangement
This section specialises classical results on permutation statistics. The energies are quadratic forms in a random permutation of fixed values, i.e. quadratic assignment statistics, a form that goes back to Daniels's generalised correlation coefficient [15]; Bloemena [7] proved asymptotic normality for the number of edges of a graph joining randomly sampled points, and Mantel [29] and Hubert [23] give the general mean and variance. What is specific here is the evaluation of the invariants for the energies, with its dependence on the parity of (Theorem 4.4).
Let be a uniformly random arrangement: with uniform and the centred values , . For a test function put with , a linear permutation statistic (Section 2.3); recall that and (7). Throughout this section , Var and Cov refer to the random arrangement.
4.1 Means
Proposition 4.1 (Means and covariance structure). For all test functions and . Consequently
The covariance matrix of the vector of statistics in (resp. ) is , with the Gram matrix of the centred test functions of the energy; its eigenvalues are
for odd ; for even the pair is replaced by .
Proof. gives , and (6) with gives . The entries of follow from Lemma 2.3: , two lines meeting in cells have , and are orthogonal to each other and to the centred diagonal indicators, since a diagonal meets every row and every column once. The rows give the block , the columns likewise, and the means are the traces.
The means are elementary (sampling without replacement): a line sum is the sum of a sample of size drawn without replacement from , so . The two means differ only through the terms of and the row and column terms of , whose means are and . These agree if and only if , i.e. , where both energies have mean .
Corollary 4.2 (Mean and variance of Loly's invariant). For a uniformly random arrangement, of Corollary 3.5 satisfies
The mean equals Loly's value for every random arrangement with for every cell (for instance any distribution invariant under complementation ); magic and semi-magic squares take this value exactly.
Proof. By (9), , so Proposition 4.1 gives the mean and . Since depends only on the column and only on the row, , so with and , which gives .
For , and takes 29 values from 46 to 74; for , and .
4.2 Variances
Write a random energy as a quadratic form with , where . A is symmetric with zero row sums.
Proposition 4.3 (Mantel [29], Hubert [23]; specialised to zero row sums and centred values). Let be a symmetric matrix with zero row sums, , and let be a uniformly random permutation of the centred values , . Then and
Proof. Because , the power sums satisfy and for , where . Since each row of sums to zero, , giving .
To compute the second moment , observe that the expectation depends only on the equality pattern of the 4-tuple , which is a set partition of . Let be the restricted sum of over tuples with exact equality pattern , and let be the unrestricted sum over all tuples satisfying at least the equalities of . By Möbius inversion on the partition lattice ,
Here the zero-row-sum hypothesis produces a dramatic simplification: if a partition contains any singleton block, the corresponding cell index appears in only one factor of and is summed freely over all cells, yielding a row sum of , which is zero! Thus for all eleven partitions with singletons. Only the four singleton-free partitions survive: the three pair partitions 12|34, 13|24, 14|23—which evaluate to , , and —and the single-block partition 1234, which evaluates to . Substituting the Möbius coefficients and along with and (Appendix C) and subtracting yields (16).
For the energies and , the three trace invariants are explicit rational functions of n (Appendix C); even and odd orders n give different rational expressions because the two main diagonals intersect at the centre cell if and only if n is odd, yet their asymptotic expansions agree to the first three leading orders.
Theorem 4.4 (Variances of the energies). For every ,
where
For both parities,
Proof. Substituting and the explicit trace invariants (18)–(19) of Appendix C into Proposition 4.3 yields the rational variance formulas and their Laurent expansions.
At the formulas give and , the values obtained by enumerating all 9! arrangements.
4.3 Limit law
Corollary 4.5 (Limit law). Let , , , , , and let (the diagonal of ). As , converges in distribution to a standard Gaussian vector in , and
Proof. Fix and let be the corresponding combination of the four vectors . Then with , and
is the square root of the quotient in (8). The second factor tends to . For the first, , and is for and and for a diagonal indicator (a centred indicator of of the cells). Since by (6), for every , so with the correlation matrix of , which tends to the identity because the only nonzero off-diagonal correlation is for even . Hence , condition (8) holds, [22, Thm. 4] with its condition (14) gives asymptotic normality of every such combination, and the Cramér–Wold device gives the joint limit . In (note and ) the diagonal weights satisfy , so ; and .
The diagonal terms are thus negligible in the limit: their share of is 0.25, 0.074 and 0.020 at n=3,5,8, and the same argument shows that , divided by its mean, has the same limit . The diagonals matter in the exact moments and in Section 5.1.
Remark 4.6 (The -mixture approximation at finite ). The -mixture approximation, which treats the statistics of an energy as jointly Gaussian, replaces the energy by , with independent variables and weights the eigenvalues (14); its density can be computed by inversion of the characteristic function [24] (Figure 3). It has the exact mean but variance , and by Theorem 4.4 the ratio of the exact variance to this value is
(E_{4}).
The -mixture variance is . In (16) the coefficient of is this value times , while the and terms are negative—reflecting the negative fourth-cumulant correlations induced by sampling the permutation entries without replacement. For these two negative terms produce the leading variance deficit ; for all three terms contribute only at order , total . For the number of statistics grows with and Corollary 4.5 does not apply. The approximation is poor for small : at the -mixture standard deviation of is about twice the exact one (Table 3).
| n | energy | -mixture sd | variance ratio | ||
|---|---|---|---|---|---|
| 3 | 40/27 | 0.8370 | 1.171 | 0.511 | |
| 3 | 40/27 | 0.4266 | 0.869 | 0.241 | |
| 4 | 391/96 | 3.1284 | 3.586 | 0.761 | |
| 4 | 85/32 | 0.9074 | 1.349 | 0.453 | |
| 5 | 234/25 | 8.0483 | 8.694 | 0.857 | |
| 5 | 104/25 | 1.3966 | 1.867 | 0.560 | |
| 6 | 2035/108 | 17.122 | 18.007 | 0.904 | |
| 6 | 1295/216 | 1.9671 | 2.459 | 0.640 | |
| 7 | 5050/147 | 32.174 | 33.349 | 0.931 | |
| 7 | 400/49 | 2.5697 | 3.089 | 0.692 | |
| 8 | 22295/384 | 55.377 | 56.888 | 0.948 | |
| 8 | 1365/128 | 3.2352 | 3.777 | 0.734 |
Table 3: Exact means and standard deviations of the two energies (Proposition 4.1, Theorem 4.4), the standard deviation of the -mixture approximation of Remark 4.6, and the ratio of the exact to the -mixture variance.
(a)

(b)
(c)
Figure 3: Energy of a uniformly random arrangement. (a) Distribution of for (all 9! arrangements) and ( Monte Carlo samples each), with the densities of the -mixture approximation (dashed) and the limit of Corollary 4.5 (dotted). (b) The same for , where the -mixture approximation improves slowly (Remark 4.6). (c) Exact mean (solid) and standard deviation (dashed) of both energies for , with Monte Carlo values for (open markers).
5 Computations for small orders
All counts below were computed in exact integer arithmetic; the methods are described in Appendix A, and every number is produced by a script in the ancillary directory anc/.
5.1 The classes and
Let be the class of arrangements whose first moments vanish and whose diagonal sums equal , i.e. the arrangements with : and both diagonal sums equal to . With cells indexed by , these are the conditions and on the sums , , , , which are additive over cells.
Proposition 5.1. For , if and only if is magic; that is, consists of the eight magic squares.
Proof. Write the centred entries as , so that , , and every line sum of is the deviation of that line. The degree-1 conditions with give and , and the diagonal conditions give . The middle row, the middle column and the two diagonals cover every cell once and the centre three more times, so ; as is an integer, and with . Put , , , , so that . The diagonals give ; the first and last rows (sum ) and columns (sum ) then give
so . The four corners are distinct, so , and , hence ; therefore is a multiple of 3 and at most 15, and . So . If , then makes odd, so (as it is at least 5) and ; 11 is not a sum of two squares, and gives , which is not either. So , , and divisible by 3 forces . Hence : all rows, columns and diagonals have deviation 0, and is magic. The converse is clear.
Remark 5.2. Although the four conditions are strictly weaker than the 2n magic conditions for real arrays z, the proof above uses that the entries are distinct integers satisfying . Among all 9! = 362,880 arrangements of order 3, exactly 760 satisfy the degree-1 conditions, 4,224 have both diagonal sums equal to 15, 72 (the semi-magic squares) satisfy the degree-2 conditions, and their intersection with the diagonal condition consists solely of the 8 magic squares.
For n = 4 the equivalence fails (Remark 2.5).
Proposition 5.3 (The size of ). (Proposition 5.1), and
of which 7,040 are magic squares. The class (the arrangements whose lifted point sets in [30] have diagonal second-moment matrix) has 6,697,177,424 members for n = 4, and the class with both diagonal sums equal to 34 has 49,932,288,000.
Computation. A meet-in-the-middle enumeration over , splitting the grid into the top two and bottom two rows (Appendix A); the matching pairs were expanded to obtain the breakdown of Table 4. The same program reproduces the brute-force counts for (8, 760, 4224, and 72 semi-magic squares) and, with the line sums in place of , the 7,040 magic and 549,504 semi-magic squares of order 4. Two further programs written independently (Appendix A) together reproduce , the first-moment count 6,697,177,424 and every entry of Table 4. The diagonal-only count also follows from a direct count: there are 2150 ordered pairs of disjoint 4-subsets of with sum 34, and .
Since acts freely on the set of all arrangements (entries are distinct) and preserves , consists of 1,829,930 orbits of size 8.
| rows with sum 34 | columns with sum 34 | |||
|---|---|---|---|---|
| 0 | 1 | 4 | total | |
| 0 | 9637312 | 2172824 | 100728 | 11910864 |
| 1 | 2172824 | 429312 | 9336 | 2611472 |
| 4 | 100728 | 9336 | 7040 (magic) | 117104 |
| total | 11910864 | 2611472 | 117104 | 14639440 |
Table 4: The members of by the number of rows and of columns with sum ; the table is symmetric under transposition.
Exactly two or three rows with sum 34 are impossible in : the row deviations satisfy and , which cannot hold with exactly one or two nonzero ; the same holds for columns. Thus of is magic, and 9,637,312 members (66%) have no row or column with sum 34, among them the arrangement of Remark 2.5.
A local-limit heuristic. Under a uniformly random arrangement the vector has mean equal to the target vector and covariance matrix given by (6): are uncorrelated with each other and with the diagonal sums, which have correlation for even and 0 for odd . Since any two arrangements differ by a product of transpositions, the differences of generate the same lattice as the increments of single transpositions; by a Smith normal form computation () this lattice is . A Gaussian local limit would therefore give the heuristic estimate . This estimate is 13.6 for () and for , so is 0.80 times the estimate; for the two-condition classes the ratios at are 0.59, 0.91 (first moments) and 1.10, 0.96 (diagonals). For Monte Carlo ( and samples, 328 and 62 members of ) gives () and (), ratios 0.76 and 0.78 to the estimate. Since grows like , the heuristic suggests . Neither statement is proved here; local limit theorems for permutation statistics of this kind are studied in [25, 16], and related counts of matrices with prescribed margins in [14].
5.2 Single swaps
Remark 5.4 (Single-swap formula). Let be obtained from by exchanging the entries of cells , let , let be the number of lines containing exactly one of , and . Expanding (5),
the incremental evaluation used in local search [37]. Here a,bD_m] + [exactly one of lies on for , . For a magic square , , so no two magic squares differ by a transposition, and the increase of under a transposition lies in the set . The smallest increase satisfies : the value 2 occurs if and only if two consecutive values lie in a common row or column and off both diagonals, and consecutive values give at most 6.
Call a local minimum with respect to transpositions if no transposition lowers the energy. For the local minima of are the eight magic squares and eight non-magic arrangements with , all strict; has 344 local minima, of which 336 are non-magic, and only 72 of them (64 non-magic) are strict.
6 Open questions
The main results are the lower bounds , and for , for the permutation threshold, which together with Schur's bound give
; the exact values for (computer-assisted when ); and exact second moments of the line-sum energies of a random arrangement. The following questions remain.
-
The order of . Is of order or of order ? The question has two parts. The upper bound uses only that is a nonzero integer vector with , and among the vectors satisfying (10) there are, for large , vectors vanishing to order at 1 (Section 3.3); whether there are vectors of larger order, up to , is the known logarithmic gap between the bounds for the least height of an integer polynomial with a zero of high order at 1 [31, 9, 3]. The part specific to arrangements is realisability: which vectors satisfying (10) are column-deviation vectors. Our constructions realise vectors with a zero of order at 1, and for ; Conjecture 3.15 asserts that realisability is no restriction at the threshold, so that and the question reduces to the lattice problem.
-
The lattice threshold. Prove Conjecture 3.15, or find with . It holds for ; for witnesses prove , and equality holds if the uncertified values of are correct.
-
The size of . Is with bounded away from 0 and , i.e. does a local limit theorem hold for the four statistics of Section 5.1? The ratio is 0.59, 0.80 for and about 0.76, 0.78 for .
-
Other families. The orthogonality formulation applies to pandiagonal and Franklin squares [27], with replaced by the span of the relevant line indicators. The corresponding thresholds and random energies have not been worked out.
Acknowledgments
Large language models (Anthropic’s Claude and Google’s Gemini) were used to assist with mathematical exploration, software implementation, and manuscript editing; all proofs and exact computational certificates have been verified by the author, who takes full responsibility for the content.
References
[1] Maya M. Ahmed, Jesús A. De Loera, and Raymond Hemmecke. Polyhedral cones of magic cubes and squares. In Discrete and Computational Geometry, volume 25 of Algorithms and Combinatorics, pages 25–41. Springer, 2003.
[2] Jean-Paul Allouche and Jeffrey Shallit. The ubiquitous Prouhet–Thue–Morse sequence. In Sequences and Their Applications (Singapore, 1998), Springer Ser. Discrete Math. Theor. Comput. Sci., pages 1–16. Springer, London, 1999.
[3] Francesco Amoroso. Polynomials with prescribed vanishing at roots of unity. Bollettino della Unione Matematica Italiana B (7), 9(4):1021–1042, 1995.
[4] W. S. Andrews. Magic Squares and Cubes. Dover Publications, 2nd edition, 1960.
[5] Matthias Beck and Andrew van Herick. Enumeration of magic squares. Mathematics of Computation, 80(273):617–621, 2011.
[6] Matthias Beck and Thomas Zaslavsky. Inside-out polytopes. Advances in Mathematics, 205(1):134–162, 2006.
[7] A. R. Bloemena. Sampling from a Graph, volume 2 of Mathematical Centre Tracts. Mathematisch Centrum, Amsterdam, 1964.
[8] Erwin Bolthausen. An estimate of the remainder in a combinatorial central limit theorem. Zeitschrift für Wahrscheinlichkeitstheorie und Verwandte Gebiete, 66:379–386, 1984.
[9] E. Bombieri and J. D. Vaaler. Polynomials with low height and prescribed vanishing. In Analytic Number Theory and Diophantine Problems (Stillwater, 1984), volume 70 of Progress in Mathematics, pages 53–73. Birkhäuser, Boston, 1987.
[10] Peter Borwein. Computational Excursions in Analysis and Number Theory. CMS Books in Mathematics. Springer, New York, 2002.
[11] Peter Borwein, Tamás Erdélyi, and Géza Kós. Littlewood-type problems on [0,1]. Proceedings of the London Mathematical Society (3), 79(1):22–46, 1999.
[12] Peter Borwein and Michael J. Mossinghoff. Polynomials with height 1 and prescribed vanishing at 1. Experimental Mathematics, 9(3):425–433, 2000.
[13] Ian Cameron, Adam Rogers, and Peter D. Loly. Signatura of magic and Latin integer squares: isentropic clans and indexing. Discussiones Mathematicae Probability and Statistics, 33(1-2):121–149, 2013.
[14] E. Rodney Canfield and Brendan D. McKay. Asymptotic enumeration of integer matrices with large equal row and column sums. Combinatorica, 30:655–680, 2010.
[15] H. E. Daniels. The relation between measures of correlation in the universe of sample permutations. Biometrika, 33(2):129–135, 1944.
[16] Sean Eberhard, Freddie Manners, and Rudi Mrazović. Additive triples of bijections, or the toroidal semiqueens problem. Journal of the European Mathematical Society, 21:441–463, 2019.
[17] Eugène Ehrhart. Sur les carrés magiques. Comptes Rendus de l'Académie des Sciences, Série A, 277:651–654, 1973.
[18] Tamás Erdélyi. Coppersmith–Rivlin type inequalities and the order of vanishing of polynomials at 1. Acta Arithmetica, 172(3):271–284, 2016.
[19] P. Erdős and P. Turán. On the distribution of roots of polynomials. Annals of Mathematics (2), 51(1):105–119, 1950.
[20] Bernard Frénicle de Bessy. Des quarrez ou tables magiques. In Divers ouvrages de mathématique et de physique, par Messieurs de l'Académie Royale des Sciences, pages 423–483. Imprimerie Royale, Paris, 1693.
[21] Martin Gardner. Mathematical games: A breakthrough in magic squares, and the first perfect magic cube. Scientific American, 234(1):118–123, 1976.
[22] Wassily Hoeffding. A combinatorial central limit theorem. Annals of Mathematical Statistics, 22(4):558–566, 1951.
[23] Lawrence Hubert. Assignment Methods in Combinatorial Data Analysis. Marcel Dekker, New York, 1987.
[24] J. P. Imhof. Computing the distribution of quadratic forms in normal variables. Biometrika, 48(3/4):419–426, 1961.
[25] Greg Kuperberg, Shachar Lovett, and Ron Peled. Probabilistic existence of regular combinatorial structures. Geometric and Functional Analysis, 27:919–972, 2017.
[26] Peter D. Loly. The invariance of the moment of inertia of magic squares. The Mathematical Gazette, 88(511):151–153, 2004. Note 88.30.
[27] Peter D. Loly. Franklin squares: A chapter in the scientific studies of magical squares. Complex Systems, 17(2):143–161, 2007.
[28] Peter D. Loly, Ian Cameron, Walter Trump, and Daniel Schindel. Magic square spectra. Linear Algebra and its Applications, 430(10):2659–2680, 2009.
[29] Nathan Mantel. The detection of disease clustering and a generalized regression approach. Cancer Research, 27:209–220, 1967.
[30] Kyle Elliott Mathewson. Magic gems: Convex hulls of lifted magic squares. arXiv:2512.09170, 2025.
[31] Maurice Mignotte. Estimations élémentaires effectives sur les nombres algébriques. In J. V. Armitage, editor, Journées Arithmétiques 1980, volume 56 of London Mathematical Society Lecture Note Series, pages 364–371. Cambridge University Press, Cambridge, 1982.
[32] Minoru Motoo. On the Hoeffding's combinatorial central limit theorem. Annals of the Institute of Statistical Mathematics, 8:145–154, 1957.
[33] Gottfried E. Noether. On a theorem by Wald and Wolfowitz. Annals of Mathematical Statistics, 20:455–458, 1949.
[34] R. P. Nordgren. On properties of special magic square matrices. Linear Algebra and its Applications, 437(8):2009–2025, 2012.
[35] R. P. Nordgren. Spectra of order-4 special magic squares. Linear Algebra and its Applications, 458:80–98, 2014.
[36] Clifford A. Pickover. The Zen of Magic Squares, Circles, and Stars. Princeton University Press, 2002.
[37] K. Pinn and C. Wieczerkowski. Number of magic squares from parallel tempering Monte Carlo. International Journal of Modern Physics C, 9(4):541–546, 1998.
[38] Adam Rogers and Peter D. Loly. The inertia tensor of a magic cube. American Journal of Physics, 72(6):786–789, 2004.
[39] Adam Rogers and Peter D. Loly. The electric multipole expansion for a magic cube. European Journal of Physics, 26(5):809–813, 2005.
[40] Issai Schur. Untersuchungen über algebraische Gleichungen. Sitzungsberichte der Preußischen Akademie der Wissenschaften, Physikalisch-Mathematische Klasse, pages 403–428, 1933.
[41] Richard P. Stanley. Linear homogeneous Diophantine equations and magic labelings of graphs. Duke Mathematical Journal, 40:607–632, 1973.
[42] Walter Trump. Notes on magic squares and cubes. https://www.trump.de/magic-squares/. Accessed 7 October 2026.
[43] Abraham Wald and Jacob Wolfowitz. Statistical tests based on permutations of the observations. Annals of Mathematical Statistics, 15(4):358–372, 1944.
[44] James E. Ward, III. Vector spaces of magic squares. Mathematics Magazine, 53(2):108–111, 1980.
[45] E. M. Wright. Prouhet's 1851 solution of the Tarry-Escott problem of 1910. American Mathematical Monthly, 66:199–201, 1959.
A Computational methods
All computations were run on an Apple M4 Max under macOS with Python 3.9 (NumPy, SciPy, SymPy) and C compiled with Apple clang; uniformly random arrangements were generated by Fisher-Yates shuffles. The scripts and data are in anc/, with a README listing the commands that regenerate every table and figure.
The permutation threshold. anc/kstar_verify.py checks in exact integer arithmetic that each witness arrangement is a permutation of with all row sums , and computes the order of vanishing of at 1 from the binomial moments . For the upper bounds it reduces the basis of by LLL (exact integer arithmetic) and enumerates all lattice vectors with by the Fincke-Pohst method with exact rational Gram-Schmidt coefficients, testing (10) for every . Since , the existence of a nonzero vector satisfying (10) is monotone in , and the least for which contains no such vector is the upper bound. A second implementation, written independently (anc/kstar Enum_independent.py, with its own exact LLL reduction and enumeration), reproduces the upper bounds for and writes the certificate anc/kstar_certificates.json: for each the reduced basis of , the exact squared Gram-Schmidt norms, and every nonzero vector of the ball with a violated instance of (10). The short script anc/kstar_check_certificates.py checks in exact arithmetic that each basis lies in and has the same Gram determinant as , hence generates it; recomputes the Gram-Schmidt norms (when all of them exceed the radius, the ball contains no nonzero lattice vector); otherwise enumerates exactly, from the certified basis, every nonzero lattice vector in the ball and checks that these are precisely the listed vectors (this happens for ); and checks each violated instance. For the upper bounds were also reproduced by floating-point integer programming (anc/kstar_crosscheck/). The witnesses were found with anc/realise.py and anc/anneal2.c, starting from the squares of Lemma 3.12 (anc/constructions.py; an independent implementation of the construction is anc/twin_squares.py). anc/kstar_subset_sums.py checks Proposition 3.14(i) for and the counting in the proof of (ii) for , and evaluates (11) with the exact ; anc/kstar_beyond40.py reruns or checks the tests of Conjecture 3.15 for , which were run under Linux.
Variances. anc/variance_proof.py derives (16) symbolically by Möbius inversion over the 15 set partitions of , checks it by enumerating all permutations for random matrices with , computes the invariants (18)–(19) symbolically and checks them against the explicit matrices for , and compares the result with the enumeration of all 9! arrangements for . Monte Carlo with arrangements per order () agrees with the exact means and standard deviations to within relative error (anc/mc_results.json). The densities in Figure 3 were computed by numerical inversion of the characteristic function [24].
Meet-in-the-middle enumeration of . The 16 cells are split into the top two rows and the bottom two rows . For each of the value sets and each of the 8! bijections the partial vector is packed into an integer key; for the complementary set and each bijection the key of the target minus the partial vector is formed; the two key lists are sorted and merged, and the sum over matching keys of the products of multiplicities is . This touches about partial vectors instead of arrangements (anc/lowmode Enum.c). The NumPy programs anc/lowmode_recount.py and anc/table4_recount.py use the same split with a different packing of the keys and tag each half by its number of rows (and the sum of a chosen column) equal to 34; together with a direct enumeration of the members of whose four rows all sum to 34, they recount , the first-moment class and every entry of Table 4.
anc/verify_numbers.py, anc/n3_lowmode_proof.py and anc/algorithms.py recompute the remaining small-order counts and local-minimum statistics in exact arithmetic.
B Squares with many complementary rows
Proof of Lemma 3.12(1). Give the value the weight , an odd number in ; each weight belongs to exactly the two complementary values . Index the weights by , . It suffices to partition the indices into sets of size and choose signs with for every : then row receives the values , , in any order, and row their complements in the same columns. Every value occurs once, row sums to , row to , and every column to . A domino (for odd , any two consecutive unused indices; they need not be of the form ) with signs or ) contributes . If is even, give each row of the dominoes with alternating sign patterns. If is odd, give row the four indices with signs , contributing ; the two indices and with signs , contributing ; and dominoes with alternating sign patterns. The quadruples fill and the fill ; consecutive leave gaps of exactly 6 indices, and the remaining interval has even length because . So the unused indices form dominoes, as required.
Proof of Lemma 3.12(2). Start with a magic square and border it successively to the orders 9, 11, ..., n by the following step, which turns a semi-magic square T of order n - 2 into one of order n = 2h + 1 (h ≥ 4) whose top and bottom rows are complementary on the inner columns. Let , , A = 4h, B = 4h - 2. The inner block is , which uses the values 2n - 1, ..., N - 2n + 2; each inner row and column then sums to . The border uses the 4h = 2n - 2 complementary pairs , . Put , , , . Let and , both of size 2h - 1, so . Choose an h-subset of [2h, 4h - 3] and an -subset of with . This is possible: the subsets of a given size of an interval of integers have as sums all integers between the smallest and the largest such sum (raise one element by 1 at a time), so takes every integer in , which contains for . The inner top row consists of the values ( ) and ( ); the inner bottom row of their complements in the same columns; the inner left column of ( ) and ( ); and the inner right column of their complements in the same rows. The top row sums to , and the left column to , because . The bottom row and right column then sum to , each inner row and column to , and every value 1, ..., N occurs once. Bordering shifts the inner square by a constant , and whenever equals the previous , so earlier complementary relations persist; this gives the complementary rows on the columns for .
C Derivation of the variance formulas
Joint moments. Let be a vector with , , and a uniformly random permutation of . For distinct cells, , and with ,
by Möbius inversion of the power sums over set partitions. Write for when the equality pattern of is exactly the partition of the positions , and for any of block type (e.g. for ); the displayed moments are , , , and .
Evaluation of the Möbius coefficients in Proposition 4.3. From the Möbius inversion on in the proof of Proposition 4.3, the coefficients of the four surviving singleton-free partitions and are
For the centred values , and , so these coefficients simplify to and ; subtracting gives (16).
The invariants. With and ,
For a line, . Hence for and for , where are the diagonal indicators. The entries of are given in the proof of Proposition 4.1. The sums needed are , , , for either diagonal , and , where is 1 for odd and 0 for even . Collecting terms gives the following invariants; where two values are given, the first is for odd and the second for even . For :
(18)
For :
(19)
D Witnesses for ,
The arrangement
has all row sums and column sums 66, 61, 71, 61, 66, i.e. and ; it satisfies the degree-3 conditions without being semi-magic. The arrangements below have, in the same way, all row sums and , so , and prove for . They are also in anc/data_witnesses_variances.json; the witnesses for are in anc/kstar_witnesses.json.