1 2 3 47 6 Journal of Integer Sequences, Vol. 13 (2010), Article 10.3.8 23 11 Six Little Squares and How Their Numbers Grow Matthias Beck1 Department of Mathematics San Francisco State University 1600 Holloway Avenue San Francisco, CA 94132 USA beck@math.sfsu.edu Thomas Zaslavsky2 Department of Mathematical Sciences Binghamton University Binghamton, NY 13902-6000 USA zaslav@math.binghamton.edu Abstract We count the 3 × 3 magic, semimagic, and magilatin squares, as functions either of the magic sum or of an upper bound on the entries in the square. Our results on magic and semimagic squares differ from previous ones, in that we require the entries in the square to be distinct from each other and we derive our results not by ad hoc reasoning, but from the general geometric and algebraic method of our paper “An enumerative geometry for magic and magilatin labellings”. Here we illustrate that method with a detailed analysis of 3 × 3 squares. 1 2 Research partially supported by National Science Foundation grant DMS-0810105. Research partially supported by National Science Foundation grant DMS-0070729 and by the SGPNR. 1 1 Introduction “Today, the study of magic squares is not regarded as a subject of mathematics, but many earlier mathematicians in China and Japan studied it.” These words from Shigeru’s history of old Japanese mathematics [14, p. 435] are no longer completely true. While the construction of magic squares remains for the most part recreational, their counting has become part of the mainstream of enumerative combinatorics, as an example of quasipolynomial counting formulas and as an application of Ehrhart’s theory of lattice points in polytopes. There are several classical [12, 11, 16] and recent [1, 2] mathematical works on counting something like magic squares, but without the requirement that the entries be distinct, and often omitting the diagonals. In previous articles [5, 6] we established the groundwork for an enumerative theory of magic squares with distinct entries. Here we apply those geometrical and algebraic methods to solve the problem of counting three kinds of magical 3 × 3 squares. Each square x = (xjk )3×3 has positive integral entries that satisfy certain line-sum equations and distinctness conditions. In a weakly semimagic square every row and column sum is the same (their common value is called the magic sum); in a weakly magic square each of the two diagonals also adds up to the magic sum. Such squares have been studied before (see, e.g., Beck et al. [2] and Stanley [17]); the difference here is that we count strongly magic or semimagic squares, where all entries of the square are distinct. (Since strongly magic squares are closest to what are classically known as “magic squares”—see the introduction to our general magic article [6]—we call strong squares simply “magic” or “semimagic” without qualification.) The third type we count is a magilatin square; this is a weakly semimagic square with the restriction that the entries be distinct within a row or column. The numbers of standard magic squares (with entries 1, 2, . . . , n2 ) and latin squares (in which each row or column has entries 1, 2, . . . , n) are special evaluations of our counting functions. We count the squares in two ways: by magic sum (an affine count), and by an upper bound on the numbers in the square (a cubic count). Letting N (t) denote the number of squares in terms of a parameter t which is either the magic sum or a strict upper bound on the entries, we know by our previous work [6] that N is a quasipolynomial, that is, there are a positive integer p and polynomials N0 , N1 , . . . , Np−1 so that N (t) = Nt (mod p) (t) . The minimal such p is the period of N ; the polynomials N0 , N1 , . . . , Np−1 are the constituents of N , and N0 is the principal constituent. Here we find an of constituents Pexplicit list t and also the explicit rational generating function N(x) = t>0 N (t)x (from which the quasipolynomial is easily extracted). Each magic and semimagic square also has an order type, which is the arrangement of the cells in order of increasing value of their entries. The order type is a linear ordering of the cells because all entries are distinct in these squares. There are 9! = 362880 possible linear orderings but only a handful are order types of squares. Our approach finds the actual number of order types for each kind of square; it is the absolute value of the constant term of the principal constituent, that is, |N0 (0)|. (See Theorems 3.4 and 3.14 and Examples 3.11, 3.12, and 3.21 in our paper on magic labellings [6].) Obviously, this number will be the same for cubic and affine counts of the same kind of square. (There is also an order type for 2 magilatin squares, which is a linear ordering only within each row and column. As it is not a simple permutation of the cells, we shall not discuss it any further.) One of our purposes is to illustrate the technique of our general treatment [6]. Another is to provide data for the further study of magic squares and their relatives; to this end we list the exact numbers of each type for small values of the parameter and also the numbers of symmetry types, reduced squares, and reduced symmetry types of each type (and we refer to the On-Line Encyclopedia of Integer Sequences (OEIS) [15] for the first 10,000 values of each counting sequence). A square is reduced by subtracting the smallest entry from all entries; thus, the smallest entry in a reduced square is 0. A square is normalized by being put into a form that is unique in each symmetry class. Clearly, the number of normalized squares, i.e., of equivalence classes under symmetry, is fundamental; and the number of reduced, normalized squares is more fundamental yet. There are other ways to find exact formulas. Xin [18] tackles 3×3 magic squares, counted by by magic sum, using MacMahon’s partition calculus. He gets a generating function that agrees with ours (thereby confirming both). Stanley’s idea of Möbius inversion over the partition lattice [17, Exercise 4.10] is similar to ours in spirit, but it is less flexible and requires more computation. Beck and van Herick [3] have counted 4 × 4 magic squares using the same basic geometrical setup as ours but with a more direct counting method. Our paper is organized as follows. Section 2 gives an outline of our theoretical and computational setup, as well as some comments on checks and feasibility. In Section 3 we give a detailed analysis of our computations for counting magic 3 × 3 squares. Sections 4 and 5 contain the setup and the results of similar computations for 3 × 3 semimagic and magilatin squares. We conclude in Section 6 with some questions and conjectures. We hope that these results, and still more the method, will interest both magic squares enthusiasts and mathematicians. 2 2.1 The technique General method The means by which we solve the specific examples of 3 × 3 magic, semimagic, and magilatin squares is inside-out Ehrhart theory [5]. That means counting the number of 1/t-fractional points in the interior of a convex polytope P that do not lie in any of a certain set H of hyperplanes. The number of such points is a quasipolynomial function EP◦ ◦ ,H(t), the open Ehrhart quasipolynomial of the open inside-out polytope (P ◦ , H). The exact polytope and hyperplanes depend on which of the six problems it is, but we can describe the general picture. First, there are the equations of magic; they determine a subspace s of all 3 × 3 real matrices which we like to call the magic subspace—though mostly we work in a smaller overall space Rd that results from various reductions. Then there is the polytope P of 2 constraints, which is the intersection with s of either a hypercube [0, 1]3 or a standard P 2 simplex {x ∈ R3 : x ≥ 0, xjk = 1}: the former when we impose an upper bound on the magic square entries and the latter when we predetermine the magic sum. The parameter t is the strict upper bound in the former case (which we call cubical due to the shape of P ), the magic sum in the latter (which we call affine as P lies in a proper affine subspace). Finally 3 there are the strong magical exclusions, the hyperplanes that must be avoided in order to ensure the entries are distinct—or in the magilatin examples, as distinct as they ought to be. These all have the form xij = xkl . The combination of P and the excluded hyperplanes forms the vertices of (P, H), which are all the points of intersection of facets of P and hyperplanes in H that lie in or on the boundary of P . Thus, we count as a vertex every vertex of P itself, each point that is the intersection of some facets and some hyperplanes in H, and any point that is the intersection of some hyperplanes and belongs to P , but not intersection points that are outside P . (Points of each kind do occur in our examples.) The denominator of (P, H) is the least common denominator of all the coordinates of all the vertices of (P, H). The period of EP◦ ◦ ,H(t) divides the denominator; this gives us a known bound on it. This geometry might best be explained with an example. Let us consider magic 3 × 3 squares, x11 x12 x13 2 x21 x22 x23 ∈ Z3>0 . x31 x32 x33 The magic subspace is x11 x12 x13 2 s = x21 x22 x23 ∈ R3 : x31 x32 x33 x11 + x12 + x13 = x21 + x22 + x23 = x31 + x32 + x33 = x11 + x21 + x31 = x12 + x22 + x32 = x13 + x23 + x33 = x11 + x22 + x33 = x13 + x22 + x31 The hyperplane arrangement H that captures the distinctness of the entries is . H = {(x11 = x12 ) ∩ s, (x11 = x21 ) ∩ s, . . . , (x32 = x33 ) ∩ s} . Finally, there are two polytopes associated to magic 3 × 3 squares, depending on whether we count them by an upper bound on the entries: 2 Pc = s ∩ [0, 1]3 , or by magic sum: x11 x12 x13 2 Pa = s ∩ x21 x22 x23 ∈ R3≥0 : x11 + x12 + x13 = 1 . x31 x32 x33 Our cubical counting function computes the number of magic squares all of whose entries satisfy 0 < xij < t, in terms of an integral parameter t. These squares are the lattice points in [ 32 H ∩ 1t Z . Pc◦ \ Our second, affine, counting function computes the number of magic squares with positive entries and magic sum t. These squares are the lattice points in [ 32 Pa◦ \ H ∩ 1t Z . 4 In general, the number of squares we want to count, N (t), is the Ehrhart quasipolynomial EP◦ ◦ ,H(t) of an open inside-out polytope (P ◦ , H). We obtain the necessary Ehrhart quasipolynomials by means of the computer program LattE [9]. It computes the closed Ehrhart generating function EP (x) := 1 + ∞ X EP (t)xt of the values EP (t) := # P ∩ t=1 d 1 Z t . Counting only interior points gives the open Ehrhart quasipolynomial EP ◦ (t) and its generating function ∞ X EP ◦ (x) := EP ◦ (t)xt . t=1 P ◦ t Since we want the open inside-out Ehrhart generating function E◦P ◦ ,H(x) = ∞ t=1 EP ◦ ,H(t)x , we need several transformations. One is Ehrhart reciprocity [10], which is the following identity of rational generating functions: EP ◦ (t) = (−1)1+dim P EP (x−1 ) . (1) The inside-out version [5, Equation (4.6)] is E◦P ◦ ,H(x) = (−1)1+dim P EP,H(x−1 ) . (2) We need to express the inside-out generating functions in terms of ordinary Ehrhart generating functions. To do that we take the intersection poset T L(P ◦ , H) := P ◦ ∩ S : S ⊆ H \ ∅ , which is ordered by reverse inclusion. Note that L(P ◦ , H) and L(P, H), defined similarly but with P instead of P ◦ , are isomorphic posets because H is transverse to P ; specifically, L(P, H) = {ū : u ∈ L(P ◦ , H)}, where ū is the (topological) closure of u. Now we have the Möbius inversion formulas [5, Equations (4.7) and (4.8)] X E◦P ◦ ,H(x) = µ(0̂, u) Eu (x) (3) u∈L(P ◦ ,H) and EP,H(x) = X |µ(0̂, u)| Eu (x) (4) u∈L(P,H) (since H is transverse to P ; see our general paper [6]). Here µ is the Möbius function of L(P ◦ , H) [17]. Thus we begin by getting all the cross-sectional generating functions Eu (x) from LattE. Then we either sum them by (4) and apply inside-out reciprocity (2), or apply ordinary reciprocity (1) first and then sum by (3). (We did whichever of these seemed more convenient.) In the semimagic and magilatin counts we need a third step because the generating functions we computed pertain to a reduced problem; those of the original problem are obtained through multiplication by another generating function. 5 Once we have the generating function we extract the quasipolynomial, essentially by the binomial series. If an Ehrhart quasipolynomial q of a rational convex polytope has period p and degree d, then its generating function q can be written as a rational function of the form X ap(d+1) xp(d+1) + ap(d+1)−1 xp(d+1)−1 + · · · + a1 x q(x) := q(t) xt = (5) p )d+1 (1 − x t≥1 for some nonnegative integers a1 , a2 , . . . , ap(d+1) . Grouping the terms in the numerator of (5) according to the residue class of the degree modulo p and expanding the denominator, we get " d Pp Pd # p pj+r X X X d+k−j j=0 apj+r x r=1 apj+r = xpk+r . q(x) = d (1 − xp )d+1 r=1 k≥0 j=0 Hence the rth constituent of the quasipolynomial q is qr (t) = d X j=0 2.2 apj+r d+ t−r p d −j for r = 1, . . . , p. How we apply the method The initial step is always to reduce the size of the problem by applying symmetry. Each problem has a normal form under symmetry, which is a strong square. The number of all magic or semimagic squares is a constant multiple of the number of symmetry types, because every such square has the same symmetry group. For magilatin squares, there are several symmetry types with symmetry groups of different sizes, so each type must be counted separately. Semimagic and magilatin squares also have an interesting reduced form, in which the values are shifted by a constant so that the smallest cell contains 0; and a reduced normal form; the latter two are not strong but are aids to computation. Reduced squares are counted either by magic sum (the “affine” counting rule) or by the largest cell value (the “cubic” count). All reduced normal semimagic squares correspond to the same number of unreduced squares, while the different symmetry types of magilatin square give reduced normal squares whose corresponding number of unreduced squares depends on the symmetry type. The total number of squares, N (t), and P the number of reduced squares, R(t), are connected by a convolution identity N (t) = s f (t − s)R(s), where f is a periodic constant (by which we mean a quasipolynomial of degree 0; we say constant term for the degree-0 term of a quasipolynomial, even though the “constant term” may or a linear polyP vary periodically) t nomial. P Writing for the generating functions N(x) := t>0 N (t)x and similarly R(x), and f (x) := t≥0 f (t)xt , we have N(x) = f (x)R(x). It follows from the form of the denominator in Equation (5) that the period of N divides the product of the periods of f and R. The reduced number R(t) is, in the semimagic case, a constant multiple of the number n(t) of reduced, normal semimagic squares; in the magilatin case it is a sum of different multiples, depending on a symmetry group, of the number of reduced, normal magilatin squares of each 6 different type T . Each n(t) is the open Ehrhart quasipolynomial EQ◦ ◦ ,I(t) of an inside-out polytope (Q, I) which is smaller than the original polytope P . P We compute n(x) := t>0 n(t)xt from the Ehrhart generating functions Eu (x) of the nonvoid sections u of Q◦ by flats of I through the following procedure: 1. We calculate the flats and sections by hand. 2. We feed each u into the computer program LattE [9], which returns the closed generating function Eū (x), whose constant term equals 1 because u is nonvoid and convex. 3. With semimagic squares, by Equations (1)–(4) we have the Möbius-inversion formulas X n(x) = E◦Q◦ ,I(x) = µL(0̂, u)Eu (x) u∈L = (−1)1+dim Q X |µL(0̂, u)| Eū (x−1 ). (6) u∈L ◦ where L := L(Q , I), the intersection poset of (Q◦ , I). The procedure for magilatin squares is similar but taking account of the several types. 2.3 Checks We check our results in a variety of ways. The degree is the dimension of the polytope, or the number of independent variables in the magic-sum equations. The leading coefficient is the volume of the polytope. (The volume is normalized so that a fundamental domain in the affine space spanned by the polytope has unit volume.) This check is also not difficult. The volume is easy to find by hand in the magic examples. In affine semimagic the polytope is the Birkhoff polytope B3 , whose volume is well known (Section 4.2). The cubical semimagic volume is not well known but it was easy to find (Section 4.1.1). The magilatin polytopes are the same as the semimagic ones. The firmest verification is to compare the results of the generating function approach with those of direct enumeration. If we count the squares individually for t ≤ t1 where t1 ≥ pd, only the correct quasipolynomial can agree with the counts (given that we know the degree d and period p from the geometry). Though t1 = pd is too large to reach in some of the examples, still we gain considerable confidence if even a smaller value of t1 yields numbers that agree with those derived from the quasipolynomial or generating function. We performed this check in each case. 2.4 Feasibility Based on our solutions of the six 3 × 3 examples we believe our counting method is practical. The calculations are simple and readily verified. Linear algebra tells us the degree, geometry tells us the period; we obtain the generating function using the Ehrhart package LattE [9] and then apply reciprocity (Equation (1) or (2)) and Möbius inversion (Equation (3) or (4)), and extract the constituents, all with Maple. The programming is not too difficult. 7 In the magic square problems we found the denominator by calculating the vertices of the inside-out polytope. Then we took two different routes. In one we applied LattE and Equation (3). In the other we calculated N (t) for small values of t by generating all magic squares, taking enough values of t that we could fit the quasipolynomial constituents to the data. This was easy to program accurately and quick to compute, and it gave the same answer. The programs can be found at our “Six Little Squares” Web site [7]. In principle the semimagic and magilatin problems can be solved in the same two ways. The geometrical method with Möbius inversion gave complete answers in a few minutes of computer time after a simple hand analysis of the geometry (see Section 4). Direct enumeration on the computer proved unwieldy (at best), especially in the affine case, where the period is largest. A straightforward computer count of semimagic squares by magic sum (performed in Maple—admittedly not the language of choice—on a personal computer) seemed destined to take a million years. Switching to a count of reduced normal squares, the calculation threatened to take only a thousand years. These programs are at our “Six Little Squares” Web site [7], as is a complicated “supernormalized formula” that greatly speeds up affine semimagic counting (see Section 4.2.7). 2.5 Notation We use a lot of notation. To keep track of it we try to be reasonably systematic. M, m refer to magic squares (Section 3). S, s and subscript s refer to semimagic squares (Section 4). L, l and subscript ml refer to magilatin squares (Section 5). R, r refer to reduced squares (the minimum entry is 0), while M, S, L, et al. refer to ordinary squares (all positive entries). c refers to “cubic” counting, by an upper bound on the entries. a refers to “affine” counting, by a specified magic sum. X (capital) refers to all squares of that type. x (minuscule) refers to symmetry types of squares, or equivalently normalized squares. 8 3 Magic squares of order 3 The standard form of a magic square of order 3 is well known; it is α+γ −α − β + γ β+γ −α + β + γ γ α−β+γ −β + γ α+β+γ −α + γ (7) where the magic sum is s = 3γ. Taking account of the 8-fold symmetry, under which we may assume the largest corner value is α + γ and the next largest is β + γ, and the distinctness of the values, we have α > β > 0 and α 6= 2β. One must also have γ > α + β to ensure positivity. In this pair of examples, the dimension of the problem is small enough that there is no advantage in working with the reduced normal form (where γ = 0). 3.1 Magic squares: Cubical count (by upper bound) Here we count by a strict upper bound t on the permitted values; since the largest entry is α + β + γ, the bound is α + β + γ < t. The number of squaresSwith upper bound t is Mc (t). We think of each magic square as a t−1 -lattice point in Pc◦ \ Hc , the (relative) interior of the inside-out polytope Pc := {(x, y, z) : 0 ≤ y ≤ x, x + y ≤ z, x + y + z ≤ 1}, Hc := {h} where h : x = 2y, but multiplied by t to make the entries integers. Here we use normalized coordinates x = α/t, y = β/t, and z = γ/t. The semilattice of flats is L(Pc◦ , Hc ) = {Pc◦ , h ∩ Pc◦ } with Pc◦ < h ∩ Pc◦ . The vertices are O = (0, 0, 0), C = (0, 0, 1), D = ( 21 , 0, 12 ), E = ( 13 , 16 , 21 ), F = ( 14 , 41 , 21 ), of which O, C, D, F are the vertices of Pc and O, C, E are those of h ∩ Pc . (Both these polytopes are simplices.) From Equation (3), Mc (x) = 8E◦Pc◦ ,Hc (x) = 8 EPc◦ (x) − Eh∩Pc◦ (x) 9 which we evaluate by LattE and Ehrhart reciprocity, Equation (1): x8 x8 =8 − (1 − x)2 (1 − x2 )(1 − x4 ) (1 − x)2 (1 − x6 ) = 8x10 (2x2 + 1) (1 − x)2 (1 − x4 )(1 − x6 ) 8x10 (2x2 + 1)(x4 − x2 + 1)(x11 + x10 + · · · + x + 1)2 (x10 + x8 + · · · + x2 + 1) = . (1 − x12 )4 From this generating function we extract the quasipolynomial 3 t −16t2 +76t−96 = (t−2)(t−6)(t−8) , if t ≡ 0, 2, 6, 8 (mod 12); 6 6 2 t3 −16t2 +73t−58 = (t−1)(t −15t+58) , if t ≡ 1 (mod 12); 6 6 2 t3 −16t2 +73t−102 = (t−3)(t −13t+34) , if t ≡ 3, 11 (mod 12); 6 6 Mc (t) = 3 −16t2 +76t−112 (t−4)(t2 −12t+28) t = , if t ≡ 4, 10 (mod 12); 6 6 t3 −16t2 +73t−90 = (t−2)(t−5)(t−9) , if t ≡ 5, 9 (mod 12); 6 6 t3 −16t2 +73t−70 = (t−7)(t2 −9t+10) , if t ≡ 7 (mod 12); 6 6 (8) and the first few nonzero values for t > 0: t Mc (t) mc (t) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 8 16 40 64 96 128 184 240 320 400 504 608 744 880 1056 1 2 5 8 12 16 23 30 40 50 63 76 93 110 132 The last row is the number of symmetry classes, or normal squares, i.e., Mc (t)/8. The rows are sequences A108576 and A108577 in the OEIS [15]. The symmetry of the constituents about residue 1 is curious. The principal constituent is t3 − 16t2 + 76t − 96 (t − 2)(t − 6)(t − 8) = . 6 6 Its unsigned constant term, 16, is the number of linear orderings of the cells that are induced by magic squares. Thus, up to the symmetries of a magic square, there are just two order types, even allowing arbitrarily large cell values. (The order types are illustrated in Example 3.11 of our general magic article, [6].) We confirmed these results by direct enumeration, counting the strongly magic squares for t ≤ 60 [7]. Compare this quasipolynomial to the weak quasipolynomial: 3 2 t −3t +5t−3 = (t−1)(t2 −2t+3) , if t is odd; 6 6 t3 −3t2 +8t−6 = 6 (t−1)(t2 −2t+6) 6 10 , if t is even; with generating function 3.1.1 (x2 + 2x − 1)(2x3 − x2 + 1) . (1 − x)2 (1 − x2 )2 Reduced magic squares A more fundamental count than the number of magic squares with an upper bound is the number of reduced squares. Let Rmc (t) be the number of 3 × 3 reduced magic squares with maximum cell value t, and rmc (t) the number of reduced symmetry types, or equivalently of normalized reduced squares with maximum t. Then we have the formulas Mc (t) = t−1 X (t − 1 − k)Rmc (k) and mc (t) = k=0 t−1 X (t − 1 − k)rmc (k), k=0 since every reduced square with maximum k gives t−1−k unreduced squares with maximum < t (and positive entries) by adding l to each entry where 1 ≤ l ≤ t − 1 − k. In terms of generating functions, Mc (x) = x2 Rmc (x) (1 − x)2 and mc (x) = x2 rmc (x). (1 − x)2 (9) We deduce the generating functions rmc (x) = x8 (2x2 + 1) (1 − x4 )(1 − x6 ) and Rmc (x) = 8rmc (x), and from the latter the quasipolynomial 2t − 16, if t ≡ 0 2t − 4, if t ≡ 2, 10 mod 12; Rmc (t) = 2t − 8, if t ≡ 4, 8 2t − 12, if t ≡ 6 0, if t is odd (10) (1/8-th of these for rmc (t)) as well as the first few nonzero values: t Rmc (t) rmc (t) 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 8 16 8 24 24 24 32 40 32 48 48 48 56 64 56 1 2 1 3 3 3 4 5 4 6 6 6 7 8 7 38 40 42 72 72 72 9 9 9 The sequences are A174256 and A174257 in the OEIS [15]. The principal constituent is 2t − 16, whose constant term in absolute value, 16, is the number of linear orderings of the cells that are induced by magic squares—necessarily, the same number as with Mc (t). We confirmed the constituents by testing them against the coefficients of the generating function for several periods. 11 Our way of reasoning, from all squares to reduced squares, is backward; logically, one should count reduced squares and then deduce the ordinary magic square numbers from them via Equation (9). Counting magic squares is not hard enough to require that approach, but in treating semimagic and magilatin squares we follow the logical progression since then reduced squares are much easier to handle. 3.2 Magic squares: Affine count (by magic sum) The number of magic squares with magic sum t = 3γ is Ma (t). We take the normalized coordinates x = α/t and y = β/t. The inside-out polytope is Pa : 0 ≤ y ≤ x, x + y ≤ 13 , Ha : {h} where h : x = 2y. The semilattice of flats is L(Pa◦ , Ha ) = {Pa◦ , h ∩ Pa◦ } with Pa◦ < h ∩ Pa◦ . The vertices are O = (0, 0), D = ( 31 , 0), E = ( 92 , 19 ), F = ( 16 , 61 ), of which O, D, F are the vertices of Pa and O, E are the vertices of h ∩ Pa . From Equations (1)–(3), Ma (x) = 8E◦Pa◦ ,Ha (x) = 8 EPa◦ (x) − Eh∩Pa◦ (x) x12 x12 − =8 (1 − x3 )2 (1 − x6 ) (1 − x3 )(1 − x9 ) = 8x15 (2x3 + 1) (1 − x3 )(1 − x6 )(1 − x9 ) = 8x15 (2x3 + 1)(x9 + 1)(x12 + x6 + 1)(x15 + x12 + · · · + x3 + 1) . (1 − x18 )3 From this generating function we extract the quasipolynomial 2 2t −32t+144 = 92 (t2 − 16t + 72), if t ≡ 0 (mod 18); 9 2t2 −32t+78 = 92 (t − 3)(t − 13), if t ≡ 3 (mod 18); 9 2t2 −32t+120 = 92 (t − 6)(t − 10), if t ≡ 6 (mod 18); 9 2 Ma (t) = 2t −32t+126 = 92 (t − 7)(t − 9), if t ≡ 9 (mod 18); 9 2t2 −32t+96 = 92 (t − 4)(t − 12), if t ≡ 12 (mod 18); 9 2 = 92 (t2 − 16t + 51), if t ≡ 15 (mod 18); 2t −32t+102 9 0, if t 6≡ 0 (mod 3); and the first few nonzero values for t > 0: t Ma (t) ma (t) 15 18 21 24 27 30 33 36 39 42 45 48 51 54 8 24 32 56 80 104 136 176 208 256 304 352 408 472 1 3 4 7 10 13 17 22 26 32 38 44 51 59 12 (11) The last row is the number of symmetry classes, or normalized squares, which is Ma (t)/8. The two sequences are A108578 and A108579 in the OEIS [15]. The principal constituent is 2t2 − 32t + 144 2 = (t2 − 16t + 72), 9 9 whose constant term, 16, is the number of linear orderings of the cells that are induced by magic squares—the same number as with Mc (t). We verified our results by direct enumeration, counting the strong magic squares for t ≤ 72 [7]. Compare the magic-square quasipolynomial to the weak quasipolynomial: ( 2 2t −6t+9 , if t ≡ 0 (mod 3); 9 0, if t 6≡ 0 (mod 3); due to MacMahon [12, Vol. II, par. 409, p. 163], with generating function 5x6 − 2x3 + 1 . (1 − x3 )3 3.2.1 Reduced magic squares Let Rma (t) be the number of 3 × 3 reduced magic squares with magic sum t, and rma (t) the number of reduced symmetry types, or equivalently of normalized reduced squares with magic sum t. Then X X rma (s), Rma (s) and ma (t) = Ma (t) = 0<s<t s≡t (mod 3) 0<s<t s≡t (mod 3) since every reduced square with sum s = t − 3k, where 0 < 3k ≤ t − 3, gives one unreduced square with sum t (and positive entries) by adding 3k to each entry. In terms of generating functions, x3 ma (x) = rma (x) ; 1 − x3 thus, x12 (2x3 + 1) rma (x) = ; (1 − x6 )(1 − x9 ) and Rma (x) = 8rma (x). The quasipolynomial is 4 t − 16 = 43 (t − 12), if t ≡ 0 3 4 4 t − 4 = (t − 3), if t ≡ 3, 15 3 3 mod 18; 4 4 t − 8 = (t − 6), if t ≡ 6, 12 (12) Rma (t) = 8rma (t) = 3 3 4 t − 12 = 43 (t − 9), if t ≡ 9 3 0, if t 6≡ 0 mod 18. 13 The initial nonzero values: t Rma (t) rma (t) 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 8 16 8 24 24 24 32 40 32 48 48 48 56 64 56 72 72 72 1 2 1 3 3 3 4 5 4 6 6 6 7 8 7 9 9 9 These sequences are A174256 and A174257 in the OEIS [15]. One of the remarkable properties of magic squares of order 3 is that Rmc (2k) = Rma (3k). The reason is that the middle term of a reduced 3 × 3 magic square equals s/3, if s is the magic sum, and the largest entry is 2s/3. Thus, the reduced squares of cubic and affine type, allowing for the difference in parameters, are the same, and although the counts of magic squares by magic sum and by upper bound differ, the only reason is that the reduced squares are adjusted differently to get all squares. The principal constituent 43 t − 16 has constant term whose absolute value is the same as with all other reduced magic quasipolynomials. We confirmed the constituents by comparing their values to the coefficients of the generating function for several periods. 4 Semimagic squares of order 3 Now we apply our approach to counting semimagic squares. Here is the general form of a reduced, normalized 3 × 3 semimagic square, in which the magic sum is s = 2α + 2β + γ: 0 β 2α + β + γ α+β α+β+γ−δ δ α+β+γ α+δ β−δ (13) Proposition 1. A reduced and normalized 3 × 3 semimagic square has the form (13) with the restrictions 0 < α, β, γ; (14) 0 < δ < β; and β+γ β−α β 2 , 2, 2 , δ 6= β − α, α + γ; γ. 14 β+α+γ ; 2 (15) The largest entry in the square is w := x13 = 2α + β + γ. Each reduced normal square with largest entry w corresponds to exactly 72(t − w − 1) different magic squares with entries in the range (0, t), for 0 < w < t. Each reduced normal square with magic sum s corresponds to exactly 72 different magic squares with magic sum equal to t, if t ≡ s (mod 3), and none otherwise, for 0 < s < t. Proof. By permuting rows and columns we can arrange that x11 = min xij and that the top row and left column are increasing. By flipping the square over the main diagonal we can further force x21 > x12 . By subtracting the least entry from every entry we ensure that x11 = 0. Thus we account for the 72(t − w − 1) semimagic squares that correspond to each reduced normal square. The form of the top and left sides in (13) is explained by the fact that x11 < x12 < x21 < x31 < x13 . The conditions xij > x11 for i, j = 2, 3, together with the row-sum and column-sum equations, imply that x13 is the largest entry and that x23 < x12 . The only possible equalities amongst the entries are ruled out by the following inequations: x22 = 6 x12 , x21 , x23 ; x32 = 6 x12 , x22 ; x33 = 6 x23 , x32 . These correspond to the restrictions (15): x22 = 6 x12 ⇐⇒ δ = 6 α + γ; x22 = 6 x21 ⇐⇒ δ = 6 γ; β+α+γ ; x22 6= x23 ⇐⇒ δ 6= 2 x32 6= x12 ⇐⇒ δ 6= β − α; x32 6= x22 ⇐⇒ δ 6= β + γ − δ ⇐⇒ δ 6= x33 6= x23 ⇐⇒ δ 6= β − δ ⇐⇒ δ 6= β+γ ; 2 β ; 2 x33 6= x32 ⇐⇒ δ 6= α + δ 6= β − δ ⇐⇒ δ 6= 4.1 β−α . 2 Semimagic squares: Cubical count (by upper bound) We are counting squares by a strict upper bound on the allowed value of an entry; this bound is the parameter t. Let Sc (t), for t > 0, be the number of semimagic squares of order 3 in which every entry belongs to the range (0, t). 4.1.1 Counting the weak squares The polytope Pc is the 5-dimensional intersection of [0, 1]9 with the semimagic subspace in which all row and column sums are equal. This polytope is integral because it is the intersection with an integral polytope of a subspace whose constraint matrix is totally unimodular; 15 so the quasipolynomial is a polynomial. By contrast, the inside-out polytope (P, H) for enumerating strong semimagic squares has denominator 60. We verified by computer counts for t ≤ 18 that the weak polynomial is 3t5 − 15t4 + 35t3 − 45t2 + 32t − 10 (t − 1)(t2 − 2t + 2)(3t2 − 6t + 5) = 10 10 with generating function (7x2 − 2x + 1)(2x3 + x2 + 4x − 1) . (1 − x)6 We conclude that Pc has volume 3/10. 4.1.2 Reduction of the number of strong squares We compute Sc (t) via Rc (w), the number of reduced squares with largest entry equal to w. The formula is t−1 X Sc (t) = (t − 1 − w)Rc (w). (16) w=0 The value Rc (w) = 72rc (w) where rc (w) is the number of normal reduced squares (in which we know the largest entry to be x13 ). Thus rc (s) counts the number of 1s -integral points in the interior of the 3-dimensional polytope Qc defined by 0 ≤ x, y; 0 ≤ z ≤ y; x+y ≤ 1 2 (17) with the seven excluded (hyper)planes z= y − x y 1 − y − 2x 1 − x − y , , , , y − x, 1 − x − 2y, 1 − 2x − 2y , 2 2 2 2 (18) the three coordinates being x = α/w, y = β/w, and z = δ/w. The hyperplane arrangement for reduced normal squares is that of (18). We call it Ic . Thus rc (s) = EQ◦ ◦c ,Ic (s). 4.1.3 Geometrical analysis of the reduced normal polytope We apply Möbius inversion, Equation (3), over the intersection poset L(Q◦c , Ic ). We need to know not only L(Q◦c , Ic ) but also all the vertices of (Qc , Ic ), since they are required for computing the Ehrhart generating function and estimating the period of the reduced normal quasipolynomial. 16 We number the planes: π1 π2 π3 π4 π5 π6 π7 : x − y + 2z = 0, : y − 2z = 0, : 2x + 2z = 1, : x + 2z = 1, : x − y + z = 0, : x + y + z = 1, : 2x + y + z = 1. The intersection of two planes, πj ∩ πk , is a line we call ljk ; π3 ∩ π5 ∩ π6 is a line we also call l356 . The intersection of three planes is, in general, a point but not usually a vertex of (Qc , Ic ). Our notation for the line segment with endpoints X, Y is XY , while XY denotes the entire line spanned by the points. The triangular convex hull of three noncollinear points X, Y, Z is XY Z. We do not need quadrilaterals, as the intersection of each plane with Q is a triangle. We need to find the intersections of the planes with Q◦c , separately and in combination. Here is a list of significant points; we shall see it is the list of vertices of (Qc , Ic ). The first column has the vertices of Qc , the second the vertices of (Qc , Ic ) that lie in open edges, the third the vertices that lie in open facets, and the last is the sole interior vertex. O = (0, 0, 0), A = ( 12 , 0, 0), Bc = (0, 1, 0), Cc = (0, 1, 1), Dc Ec Ec′ Ec′′ = (0, 21 , 21 ) ∈ OC, = ( 31 , 13 , 0) ∈ AB, = ( 31 , 13 , 31 ) ∈ AC, = (0, 1, 12 ) ∈ BC, Fc Gc G′c G′′c = (0, 23 , 13 ) ∈ OBC, = ( 14 , 21 , 41 ) ∈ ABC, = ( 15 , 53 , 51 ) ∈ ABC, = ( 15 , 53 , 52 ) ∈ ABC, Hc = ( 51 , 25 , 51 ). (19) The denominator of (Qc , Ic ) is the least common denominator of all the points; it evidently equals 4 · 3 · 5 = 60. The intersections of the planes with the edges of Qc are in Table 1. The subscript c is omitted. Table 2 shows the lines generated by pairwise intersection of planes. 17 Plane Intersection with edge Intersection OA OB OC AB AC BC with Q π1 O O O E ∈ /Q E ′′ OEE ′′ π2 OA O O A A E ′′ OAE ′′ π3 A ∅ D A A E ′′ ADE ′′ π4 ∈ /Q ∅ D ∈ /Q E′ E ′′ DE ′′ E ′ π5 O O OC E C C OCE π6 ∈ /Q B D B E′ B BDE ′ π7 A B D AB A B ABD Table 1: Intersections of planes of I with edges of Q. A vertex of Q contained in πj will show up three times in the row of πj . In order to clarify the geometry, we distinguish between a plane’s meeting an edge line outside Q and not meeting it at all (i.e., their being parallel). π1 π2 π3 π2 π3 π4 π5 x=0 y = 2z x + z = 12 y − z = 21 y = 2z x + z = 12 y =1 x + 2z = 1 y = 2z x+y =1 x=0 z = 12 z =0 x=y y = 2z x=z l356 : x = 1 − 2z y =1−z π4 π5 π6 z = 2y − 1 x = 2 − 3y y = 2z x + 3z = 1 x + z = 12 y = 21 x = 1 − 2z y =z l356 π6 π7 x + z = 13 y − z = 31 y = 2z 2x + 3z = 1 x + z = 12 y =z x = 1 − 2z y = 3z − 1 x = 1 − 2y z = 3y − 1 x=0 y+z =1 Table 2: The equations of the pairwise intersections of planes of Ic . In Table 3 we describe the intersection of each line with Qc and with its interior. The subscript c is omitted. 18 π2 ′′ π1 π2 π3 OE (OBC) π3 π4 ′′ ′′ E (BC) AE ′′ (ABC) E (BC) E ′′ (BC) DE ′′ (OBC) π5 π6 π7 OE (OAB) F G′ EF OG FG AF DG′′ π4 DE ′ (OAC) AD (OAC) D (OC) l356 ED l356 : DG π5 BD (OBC) π6 Table 3: The intersections of lines with Q and Q◦ . The second (parenthesized) row in each box shows the smallest face of Q to which the intersection belongs, if that is not Q itself; these intersections are not part of the intersection poset of (Q◦ , I). Last, we need the intersection points of three planes of Ic ; or, of a plane and a line. Some are not in Qc at all; them we can ignore. Some are on the boundary of Qc ; they are necessary in finding the denominator, but all of them are points already listed in (19). It turns out that π2 ∩ π5 ∩ π7 = Hc is the only vertex in Q◦c , so it is the only one we need for the intersection poset. Here, then, is the intersection poset (Figure 1). The subscript c is omitted. In the figure, for simplicity, we write πj , etc., when the actual element is the simplex πj ∩ Q◦ , etc.; we also state the vertices of the simplex. The Möbius function µ(0̂, u) equals (−1)codim u with the exception of µ(0̂, l356 ) = 2. 4.1.4 Generating functions and the quasipolynomial ◦ That was the first half of the work. The second half begins with finding rc (w) = E(Q ◦ ,I ) (w) c c from the Ehrhart generating functions Eu (t) of the intersections by means of (6). The next step, then, is to calculate all necessary generating functions. This is done by LattE. rc (x) is the result of applying reciprocity to the sum of all these rational functions (with the appropriate Möbius-function multiplier −1, excepting EDG◦ (x) whose multiplier is −2). The 19 H l45 (DG′′ ) l16 (F G′ ) l17 (EF ) π4 (DE ′′ E ′ ) π1 (OEE ′′ ) l356 (DG) π6 (BDE ′ ) l26 (F G) π5 (OCE) l57 (ED) l25 (OG) l27 (AF ) π3 (ADE ′′ ) π7 (ABD) π2 (OAE ′′ ) R3 (OABC) Figure 1: The intersection poset L(Q◦ , I) for semimagic squares. The diagram shows both the flats and (in parentheses) their intersections with Q. result is: −rc (1/x) = EOABC (x) + EOEE ′′ (x) + EOAE ′′ (x) + EADE ′′ (x) + EDE ′ E ′′ (x) + EOCE (x) + EBDE ′ (x) + EABD (x) + EF G′ (x) + EEF (x) + EOG (x) + EF G (x) + EAF (x) + 2EDG (x) + EDG′′ (x) + EDE (x) + EH (x) 1 1 1 + + = 3 2 2 3 (1 − x) (1 − x ) (1 − x)(1 − x )(1 − x ) (1 − x)(1 − x2 )2 1 1 1 + + + (1 − x2 )3 (1 − x2 )2 (1 − x3 ) (1 − x)2 (1 − x3 ) 1 1 1 + + + 2 3 2 2 3 (1 − x)(1 − x )(1 − x ) (1 − x)(1 − x ) (1 − x )(1 − x5 ) 1 1 1 + + + 3 2 4 3 (1 − x ) (1 − x)(1 − x ) (1 − x )(1 − x4 ) 1 1 1 +2 + + 2 3 2 4 2 (1 − x )(1 − x ) (1 − x )(1 − x ) (1 − x )(1 − x5 ) 1 1 + . + (1 − x2 )(1 − x3 ) 1 − x5 20 (20) Then by (16) the generating function for cubically counted semimagic squares is Sc (x) = 72 x2 rc (x) (1 − x)2 72x10 [18 x9 + 46 x8 + 69 x7 + 74 x6 + 65 x5 + 46 x4 + 26 x3 + 11 x2 + 4 x + 1] . (1 − x2 )2 (1 − x3 )2 (1 − x4 )(1 − x5 ) (21) From the geometrical denominator 60 or the (standard-form) algebraic denominator (1 − x60 )5 we know the period of Sc (t) divides 60. We compute the constituents of Sc (t) by the method of Section 2.1; the result is that 3 5 75 4 331 3 5989 2 t − t + t − t + c1 (t)t − c0 (t), if t is even; 10 8 3 10 Sc (t) = (22) 75 331 11933 3 t5 − t4 + t3 − t2 + c1 (t)t − c0 (t), if t is odd; 10 8 3 20 = where c1 varies with period 6, given by 1464, 1456, c1 (t) = 2831 , 2 2847 , 2 if if if if t ≡ 0, 2 t≡4 t≡1 t ≡ 3, 5 (mod 6); and c0 , given by Table 4, varies with period 60. (It is curious that the even constant terms have half the period of the odd terms.) Thus the period of Sc turns out to be 60, the largest it could be. 21 t c0 (t) t c0 (t) t c0 (t) t c0 (t) t c0 (t) 0 1296 12 1296 24 36 110413 120 3824 3 47727 40 18152 15 25705 24 6192 5 25193 24 19552 15 44847 40 3544 3 130253 120 13 120781 120 19552 15 9315 8 16856 15 25705 24 6624 5 129421 120 3824 3 41391 40 3544 3 140621 120 25 29 41 6192 5 23465 24 19552 15 47727 40 3544 3 121613 120 48 1 6624 5 23465 24 18256 15 9315 8 18152 15 131981 120 30 1296 42 1296 54 31 119053 120 3824 3 44847 40 18152 15 27433 24 43 129421 120 19552 15 8739 8 16856 15 27433 24 55 6624 5 120781 120 3824 3 44271 40 3544 3 131981 120 6624 5 25193 24 18256 15 8739 8 18152 15 140621 120 2 3 4 5 6 7 8 9 10 11 14 15 16 17 18 19 20 21 22 23 26 27 28 32 33 34 35 37 38 39 40 44 45 46 47 49 50 51 52 53 56 57 58 59 Table 4: Constant terms (without the negative sign) of the constituents of the semimagic cubical quasipolynomial Sc (t). The principal constituent (for t ≡ 0) is 3 5 75 4 331 3 5989 2 t − t + t − t + 1464t − 1296. 10 8 3 10 Its unsigned constant term, 1296, is the number of order types of semimagic squares. Allowing for the 72 symmetries of a semimagic square, there are just 18 symmetry classes of order types. For the first few nonzero values of Sc (t) see the following table. (This is sequence A173546 in the OEIS [15].) The third row is the number of normalized squares, or symmetry classes (sequence A173723), which equals Sc (t)/72. The other lines give the numbers of reduced squares (sequence A173727) and of reduced normal squares (i.e., symmetry types of reduced squares; sequence A173724), which may be of interest. t Sc (t) sc (t) Rc (t) rc (t) 8 9 10 11 12 13 14 15 16 17 18 19 0 0 72 288 936 2592 5760 11520 20952 35712 57168 88272 0 0 1 4 13 36 80 160 291 496 794 1226 72 144 432 1008 1512 2592 3672 5328 6696 9648 11736 15552 1 2 6 14 21 36 51 74 93 134 163 216 Compare the strong to the weak quasipolynomial. The leading coefficients agree and the strong coefficient of t4 is constant. These facts, of which we made no use in deducing 22 the quasipolynomial, provide additional verification of the correctness of the counts and constituents. 4.1.5 Another method: Direct counting We checked the constituents by directly counting (in Maple) all semimagic squares for t ≤ 100. The numbers agreed with those derived from the generating function and quasipolynomial above. 4.2 Semimagic squares: Affine count (by magic sum) Now we count squares by magic sum: we compute Sa (t), the number of squares with magic sum t. 4.2.1 The Birkhoff polytope The polytope P for semimagic squares of order 3, counted by magic sum, is 4-dimensional and integral. (It is the polytope of doubly stochastic matrices of order 3, i.e., a Birkhoff polytope [8, 4].) 4.2.2 Affine weak semimagic The polytope for weak semimagic squares of order 3 is the same P . The weak quasipolynomial, or rather, polynomial, first computed by MacMahon [12, Vol. II, par. 407, p. 161], is t4 − 6t3 + 15t2 − 18t + 8 (t − 1)(t − 2)(t2 − 3t + 4) = 8 8 with generating function 4.2.3 6x4 − 9x3 + 10x2 − 5x + 1 . (1 − x)5 Reduction The count is via Ra (s), the number of reduced squares with magic sum s. The formula is X Ra (s) if t > 0. (23) Sa (t) = 0<s≤t−3 s≡t (mod 3) We have Ra (s) = 72ra (w), where ra (s) is the number of reduced, normalized squares with magic sum s, equivalently the number of 1s -integral points in the interior of the 3-dimensional polytope Qa defined by 0 ≤ x, y; 0 ≤ z ≤ y; 23 x+y ≤ 1 2 (24) with the seven excluded (hyper)planes z= y − x y 1 − y − 2x 1 − x − y , , , , y − x, 1 − x − 2y, 1 − 2x − 2y , 2 2 2 2 (25) the three coordinates being x = α/s, y = β/s, and z = δ/s. The hyperplane arrangement for reduced, normalized squares is that of (25). We call it Ia . Thus ra (s) = EQ◦ ◦a ,Ia (s). 4.2.4 The reduced, normalized weak polytopal quasipolynomial This function simply counts 1s -lattice points in Q◦a . The counting formula is summed over all triples that satisfy (14). It simplifies to X ⌊ s−1 ⌋ − α 2 , 2 α which gives the Ehrhart quasipolynomial s−1 2 = s−1 3 ⌊ 2 ⌋ EQ◦a (s) = = s−2 3 2 = 3 1 (s 48 P P P δ 1, (26) 1 (s 48 − 2)(s − 4)(s − 6), for even s. EP ◦ (x) = x7 (1 + x) (1 − x2 )4 EP (x) = 1+x . (1 − x2 )4 and by reciprocity that Geometrical analysis of the reduced, normalized polytope We apply Möbius inversion, Equation (6), over the intersection poset L(Q◦a , I). We number the planes: π1 π2 π3 π4 π5 π6 π7 β − 1)(s − 3)(s − 5), for odd s; The leading coefficient is vol Qa . We deduce from (26) that 4.2.5 α : x − y + 2z : y − 2z : 2x + y + 2z : x + y + 2z : x−y+z : x + 2y + z : 2x + 2y + z 24 = 0, = 0, = 1, = 1, = 0, = 1, = 1. The intersection of two planes, πj ∩ πk , is a line we call ljk ; π3 ∩ π5 ∩ π6 is a line we also call l356 . The intersection of three planes is, in general, a point but not usually a vertex of (Qa , Ia ). Our geometrical notation is as in the cubical analysis. We need to find the intersections of the planes with Q◦a , separately and in combination. Here is a list of significant points; we shall see it is the list of vertices of (Qa , Ia ). The first column has the vertices of Qa , the second the vertices of (Qa , Ia ) that lie in open edges, the third the vertices that lie in open facets, and the last is the sole interior vertex. O = (0, 0, 0), A = ( 21 , 0, 0), Ba = (0, 21 , 0), Ca = (0, 21 , 21 ), Da Ea Ea′ Ea′′ = (0, 13 , 13 ) ∈ OC, = ( 14 , 41 , 0) ∈ AB, = ( 41 , 41 , 41 ) ∈ AC, = (0, 21 , 14 ) ∈ BC, Fa Ga G′a G′′a = (0, 25 , 51 ) ∈ OBC, = ( 61 , 62 , 16 ) ∈ ABC, = ( 18 , 83 , 18 ) ∈ ABC, = ( 81 , 83 , 28 ) ∈ ABC. Ha = ( 71 , 72 , 17 ), (27) The least common denominator of O, A, Ba , Ca explains the period 2 of EQ◦a . The denominator of (Qa , Ia ) is the least common denominator of all the points; it evidently equals 8 · 3 · 5 · 7 = 840. The intersections of the planes with the edges of Qa are in Table 1. Table 5 shows the lines generated by pairwise intersection of planes. Table 3 describes the intersection of each line with Qa and with Q◦a . π2 π1 π2 π3 π3 x=0 x= y = 2z y= x+y 1−4z 3 1+2z 3 = 21 y = 2z π4 π5 π6 x=y x = 2 − 5y x= z =0 z = 3y − 1 y= x = 1 − 2y x=z x = 1 − 5z x= y = 2z y = 2z y = 2z y = 2z x + 2z = y= 1 2 1 2 x=0 y = 1 − 2z π4 π5 l356 : x+z = y= 1 3 1 3 x = 3y − 1 x = 1 − 3y z = 1 − 2y z =y l356 π7 1−5z 4 1+3z 4 1−5z 2 2x + 3y = 1 z =y x+y = z= 1 3 1 3 x = 1 − 3y z = 4y − 1 x=0 π6 z = 1 − 2y Table 5: The equations of the pairwise intersections of planes of Ia . Last, we need the intersection points of three planes of Ia ; or, of a plane and a line. Some are not in Qa at all; them we can ignore. Some are on the boundary of Qa ; they are necessary in finding the denominator, but all of them are points already listed in (27). It turns out 25 that π2 ∩ π5 ∩ π7 = Ha is the only vertex in Q◦a , so it is the only one we need for the intersection poset. The combinatorial structure and the intersection poset (Figure 1) for the affine count are identical to those for the cubical count. The reason is that the affine polytope Pa is the 4-dimensional section of Pc by the flat in which the magic sum equals 1, and this flat is orthogonal to the line of intersection of the whole arrangement Ha . 4.2.6 Generating functions and the quasipolynomial The second half of the affine solution is to find ra (s) = E◦(Q◦a ,Ia ) (s) by applying Equations (1)– (4) after finding the Ehrhart generating functions Eu (s) for u ∈ L(Q◦a , Ia ). The next step, then, is to calculate those generating functions. This is done by LattE. Then (−1)3 ra (x−1 ) is the sum of all these rational functions; that is, −ra (1/x) = EOABC (x) + EOEE ′′ (x) + EOAE ′′ (x) + EADE ′′ (x) + EDE ′′ E ′ (x) + EOCE (x) + EBDE ′ (x) + EABD (x) + EF G′ (x) + EEF (x) + EOG (x) + EF G (x) + EAF (x) + 2EDG (x) + EDG′′ (x) + EDE (x) + EH (x) 1 1 1 = + + 2 3 4 2 (1 − x)(1 − x ) (1 − x)(1 − x ) (1 − x)(1 − x2 )(1 − x4 ) 1 1 1 + + + 2 3 4 3 4 2 (1 − x )(1 − x )(1 − x ) (1 − x )(1 − x ) (1 − x)(1 − x2 )(1 − x4 ) 1 1 1 + + + (1 − x2 )(1 − x3 )(1 − x4 ) (1 − x2 )2 (1 − x3 ) (1 − x5 )(1 − x8 ) 1 1 1 + + + 4 5 6 5 (1 − x )(1 − x ) (1 − x)(1 − x ) (1 − x )(1 − x6 ) 1 1 1 +2 + + 2 5 3 6 3 (1 − x )(1 − x ) (1 − x )(1 − x ) (1 − x )(1 − x8 ) 1 1 + + . 3 4 (1 − x )(1 − x ) 1 − x7 (28) The generating function for the affine count of semimagic squares, by (23), is Sa (x) = 72 72x15 ( x3 ra (x) = 1 − x3 18x21 + 5x20 + 15x19 + 11x17 − 8x16 + x15 − 23x14 − 13x13 − 22x12 − 9x11 − 16x10 + x9 − 3x8 + 7x7 + 7x6 + 9x5 + 7x4 + 6x3 + 4x2 + 2x + 1 (1 − x3 )2 (1 − x4 )(1 − x5 )(1 − x6 )(1 − x7 )(1 − x8 ) ) . (29) 26 From the geometrical or generating-function denominator we know that the period of Sa (t) divides 840 = lcm(3, 4, 6, 7, 8). This is long, but it can be simplified. The factor 7 in the period is due to a single term in (28). If we treat it separately we have ra as a sum x7 of the H-term x7 /(1 − x7 ) and a “truncated” generating function for ra (x) + 1−x 7 , and a corresponding truncated expression x10 = (1 − x3 )(1 − x7 ) ) ( 17x19 + 5x18 + 15x17 + x16 + 12x15 − 7x14 + 2x13 − 7x12 − 8x11 − 9x10 − 9x9 − 6x8 − 6x7 − x6 + x4 + x3 − 1 Sa (x) − 72 −72x10 (1 − x3 )2 (1 − x4 )(1 − x5 )(1 − x6 )(1 − x8 ) . We extract the constituents from this expression as in Section 2.1, separately for the two parts of the generating function. The constituents are all of the form 9 1 Sa (t) = t4 − t3 + a2 (t)t2 − a1 (t)t + a0 (t) − 72S7 (t), 8 2 (30) where S7 (t) is a correction, to be defined in a moment, and 243 , if t ≡ 0 4 218 , if t ≡ 1, 5 4 (mod 6); a2 (t) = 227 , if t ≡ 2, 4 4 234 , if t ≡ 3 4 1968 , if t ≡ 0 5 1158 , if t ≡ 1, 5 5 1383 , if t ≡ 2, 10 5 1653 , if t ≡ 3 5 (mod 12); a1 (t) = 1428 , if t ≡ 4, 8 5 1923 , if t ≡ 6 5 1113 , if t ≡ 7, 11 5 1698 , if t ≡ 9 5 and a0 (t) is given in Table 6. We call the constituents of the quasipolynomial 9 1 Sa (t) + 72S7 (t) = t4 − t3 + a2 (t)t2 − a1 (t)t + a0 (t) 8 2 the truncated constituents of Sa (t), since they correspond to the truncated generating function mentioned just above. The S7 term that undoes the truncation is ( 1, if t ≡ 10, 13, 16, 17, 19, 20 (mod 21); t−1 + S7 (t) := 21 0, otherwise 27 t − t̄ + s7 (t), 21 where t̄ := the least positive residue of t modulo 7 and ( 1, if t ≡ 10, 13, 16, 17, 19, 20 (mod 21); s7 (t) := 0, otherwise. = Note that t̄ = 21 if t ≡ 0, so that S7 (0) = −1 and in general S7 (21k) = k − 1. t a0 (t) t a0 (t) t a0 (t) t a0 (t) t a0 (t) t a0 (t) 0 1224 20 524 40 584 60 1188 80 560 100 548 1 21 89 29979 40 1921 5 −613 40 5652 5 2431 8 1333 5 27963 40 2344 5 7451 40 101 69 8699 40 1621 5 24507 40 2632 5 1951 8 4833 5 3803 40 2044 5 32571 40 81 49 6299 40 5121 5 347 40 2332 5 6975 8 1453 5 4283 40 5544 5 8411 40 61 29 31419 40 1741 5 827 40 5832 5 2143 8 1513 5 26523 40 2164 5 8891 40 41 9 7259 40 1801 5 23067 40 2452 5 2239 8 4653 5 5243 40 2224 5 31131 40 109 7739 40 4941 5 1787 40 2512 5 6687 8 1633 5 2843 40 5364 5 9851 40 10 413 30 1017 50 389 70 377 90 1053 110 353 11 539 40 5796 5 7547 40 1477 5 5823 8 2488 5 8603 40 4689 5 2651 40 31 2939 40 2656 5 28827 40 1777 5 799 8 5508 5 11003 40 1189 5 26811 40 51 24219 40 2596 5 6587 40 4797 5 1279 8 2368 5 32283 40 1489 5 1691 40 71 1979 40 5976 5 6107 40 1657 5 5535 8 2308 5 10043 40 4509 5 4091 40 91 1499 40 2476 5 30267 40 1597 5 1087 8 5688 5 9563 40 1369 5 25371 40 111 25659 40 2776 5 5147 40 4977 5 991 8 2188 5 33723 40 1309 5 3131 40 2 3 4 5 6 7 8 12 13 14 15 16 17 18 19 22 23 24 25 26 27 28 32 33 34 35 36 37 38 39 42 43 44 45 46 47 48 52 53 54 55 56 57 58 59 62 63 64 65 66 67 68 72 73 74 75 76 77 78 79 82 83 84 85 86 87 88 92 93 94 95 96 97 98 99 102 103 104 105 106 107 108 112 113 114 115 116 117 118 119 Table 6: Constant terms of the truncated constituents of Sa (t). The period of the constant term of the truncated constituents is 120. It follows that Sa (t) has period 7 · 840, that is, 840. 28 The principal constituent of Sa (t) (that is, for t ≡ 0) is 1 4 9 3 243 2 13896 t − t + t − t + 1296. 8 2 4 35 (This incorporates the effect of the term −72S7 .) The constant term is the same as in the cubic count, as it is the number of order types of semimagic squares. We give the first few nonzero values of Sa (t) in the following table. (This sequence is A173547 in the OEIS [15].) The third row is the number of normalized squares, or symmetry classes (sequence A173725); this is Sa (t)/72. The last rows are the numbers of reduced squares (sequence A173728) and of reduced, normalized squares (sequence A173726) with magic sum t. t Sa (t) sa (t) Ra (t) ra (t) 4.2.7 12 13 14 15 16 17 18 19 20 21 22 23 24 0 0 0 72 144 288 576 864 1440 2088 3024 3888 5904 0 0 0 1 2 4 8 12 20 29 42 54 82 72 144 288 504 720 1152 1512 2160 2448 3816 3960 5544 6264 1 2 4 7 10 16 21 30 34 53 55 77 87 Alternative methods: Direct counting and direct computation We verified our formulas by computing Sa (t) for t ≤ 100 through direct enumeration of normal squares. The results agree with those computed by expanding the generating function. We also applied Proposition 1 to derive a formula, independent of all other methods, by which we calculated numbers (which we are not describing; see the “Six Little Squares” Web page [7]) that allowed us to find the 840 constituents by interpolation. These interpolated constituents fully agreed with the ones given above. 5 Magilatin squares of order 3 A magilatin square is like a semimagic square except that entries may be equal if they are in different rows and columns. The inside-out polytope is the same as with semimagic squares except that we omit those hyperplanes that prevent equality of entries in different rows and columns. Thus, in our count of reduced squares, we have to count the fractional lattice points in some of the faces of the polytope. The reduced normal form of a magilatin square is the same as that of a semimagic square except that the restrictions are weaker. It might be thought that this would introduce ambiguity into the standard form because the minimum can occur in several cells, but it turns out that it does not. Proposition 2. A reduced, normal 3 × 3 magilatin square has the form (13) with the restrictions 0 < β, γ; 0 ≤ α; (31) 0 ≤ δ ≤ β; 29 and (15). Each reduced square with w in the upper right corner corresponds to exactly t − w − 1 different magilatin squares with entries in the range (0, t), for 0 < w < t. Each reduced square with magic sum s corresponds to one magilatin square with magic sum equal to t, if t ≡ s (mod 3), and none otherwise, for 0 < s < t. Proof. The proof is similar to that for semimagic squares; we can arrange the square by permuting rows and columns and by reflection in the main diagonal so that x11 is the smallest entry, the first row and column are each increasing, and x21 ≥ x12 . We cannot say x21 > x12 because entries that do not share a row or column may be equal. Still, we obtain the form (13) with the bounds (31) and the same inequations (15) as in semimagic because all the latter depend on having no two equal values in the same line (row or column). Each reduced, normal magilatin square gives rise to a family of true magilatin squares by adding a positive constant to each entry and by symmetries, which are generated by row and column permutations and reflection in the main diagonal. Call the set of symmetries G. As with semimagic, |G| = 2(3!)2 = 72. Each normal, reduced square S gives rise to |G/GS | = 72/|GS | squares via symmetries, where GS is the stabilizer subgroup of S. If all entries are distinct, then the square is semimagic, GS is trivial, and everything is as with semimagic squares. However, if α = 0 or δ = 0 or δ = β, the stabilizer is nontrivial. We consider each case in turn. The case α = 0 < δ. Here δ < β because no line can repeat a value. To fix the square we cannot permute any rows or columns but we can reflect in the main diagonal, so |GS | = 2. Moreover, (15) reduces to β β+γ . δ 6= γ, , 2 2 We are in OBC, the x = 0 facet of Q, with the induced arrangement of three lines, Ix=0 . The number of reduced magilatin squares of this kind is 36rOBC (t), where rOBC (t) is the number of 1t -lattice points in the open facet and, equivalently, the number of symmetry types of reduced magilatin squares of this kind. We apply Equations (1)–(4) to the intersection poset L(OBC ◦ , Ix=0 ), which is found in Figure 2. The Möbius function µ(OBC, u) equals (−1)codim u . The case δ = 0 < α. In this case a nontrivial member of GS can only exchange the two zero positions. Such a symmetry that preserves the increase of the first row and column is unique (as one can easily see); thus |GS | = 2. Furthermore, (15) reduces to α 6= β. We are in OAB, the z = 0 facet, with the induced arrangement Iz=0 of one line. The number of reduced magilatin squares of this kind is 36rOAB (t), where rOAB (t) is the number of 1t lattice points in the open facet and, equivalently, the number of symmetry types of reduced squares. We apply Equations (1)–(4) to the intersection poset L(OAB ◦ , Iz=0 ), shown in Figure 2. The Möbius function µ(OAB, u) equals (−1)codim u . The case δ = β. Here we must have α > 0. There are two zero positions in opposite corners. A symmetry that exchanges them and preserves increase in the first row and column is uniquely determined, so |GS | = 2. The inequations reduce to β 6= γ, α + γ. 30 We are in OAC, the facet where y = z, with the two-line induced arrangement Iy=z . The number of reduced magilatin squares of this kind is 36rOAC (t), where rOAC (t) is the number of 1t -lattice points in the open facet, equally the number of reduced symmetry types. We apply Equations (1)–(4) to the intersection poset L(OAC ◦ , Iy=z ) in Figure 2. The Möbius function µ(OAC, u) equals (−1)codim u . The case α = 0 = δ. In these squares there are three zero positions and the whole square is a cyclic latin square. Any symmetry that fixes the zero positions also fixes the rest of the square. There are 3! symmetries that permute the zero positions, generated by row and column permutations. They all preserve the entire square. Therefore |GS | = 6. The inequations disappear. We are in the edge OB, which is the face where x = z = 0, with the empty arrangement, Ix=z=0 = ∅. The number of reduced magilatin squares of this kind is 12rOB (t), where rOB (t) is the number of 1t -lattice points in the open edge, also the number of reduced symmetry types. The intersection poset L(OB ◦ , ∅) consists of the one element OB, whose Möbius function µ(OB, OB) = 1. To get the intersection posets we may examine Tables 1 and 3 to find the edges and vertices of (Q◦ , I) in each closed facet. We also need to know which vertex is in which edge; this is easy. Although we do not need the fourth facet, ABC, we include it for the interest of its more complicated geometry. Of course all the functions rs and Rml depend on whether we are counting cubically or affinely (thus, subscripted c or a); the two types will be treated separately. But the general conclusions hold that Rml (x) = 72rs (x) + 36[rOAB (x) + rOAC (x) + rOBC (x)] + 12rOB (x), (32) and for the number of reduced symmetry types, rml (t) with generating function rml (x), rml (x) = rs (x) + rOAB (x) + rOAC (x) + rOBC (x) + rOB (x), (33) where rs (x) is from semimagic and, by Equation (4) since |µ(X, Y )| = 1 for every lower interval in each facet poset (except facet ABC, which we do not use), (−1)3 rOAB (1/x) = EOAB (x) + EOE (x), (−1)3 rOAC (1/x) = EOAC (x) + EAD (x) + EDE ′ (x), (−1)3 rOBC (1/x) = EOBC (x) + EOE ′′ (x) + EBD (x) + EDE ′′ (x) + EF (x), (−1)2 rOB (1/x) = EOB (x); (34) the sign and reciprocal on the left result from Equation (6). There is also the generating function of the number of cubical or affine symmetry classes, l(t), whose generating function is l(x). This is obtained from rml (t) in the same way as L(t) is from Rml (t), the exact way depending on whether the count is affine or cubic. 5.1 Magilatin squares: Cubical count (by upper bound) The weak quasipolynomial is exactly as in the semimagic cubical problem. 31 F OE DE ′ AD OE ′′ OAB BD DE ′′ OAC OBC L(OAB ◦ , Iz=0 ) L(OAC ◦ , Iy=z ) G′ L(ABC ◦ , Ix+y=1/2 ) EE ′′ L(OBC ◦ , Ix=0 ) G′′ G BE ′ AE ′′ CE E ′ E ′′ ABC Figure 2: The four facet intersection posets of (Q◦ , I). 32 5.1.1 Magilatin squares by upper bound The number of 3 × 3 magilatin squares with strict upper bound t is Lc (t). We count them via Rmlc (w), the number of reduced magilatin squares with largest entry (which we know to be x13 ) equal to w. The formula is t−1 X Lc (t) = (t − 1 − w)Rmlc (w). (35) w=0 Equivalently, Rmlc (w) counts w1 -integral points in the interior and part of the boundary of the inside-out polytope (Qc , Ic ) of Section 4.1, weighted variably by 72/|GS |. Now we must calculate the closed Ehrhart generating function for each necessary face. This is done by LattE; here are the results. First, OABc : (−1)3 rOABc (1/x) = EOABc (x) + EOEc (x) 1 1 + = 2 2 (1 − x) (1 − x ) (1 − x)(1 − x)3 x+2 = . (1 − x)(1 − x2 )(1 − x3 ) (36) (−1)3 rOACc (1/x) = EOACc (x) + EADc (x) + EDc Ec′ (x) 1 1 1 + + = 2 2 2 2 2 (1 − x) (1 − x ) (1 − x ) (1 − x )(1 − x3 ) x2 + 2x + 3 = . (1 − x2 )2 (1 − x3 ) (37) Next is OACc : The last facet is OBc Cc : (−1)3 rOBc Cc (1/x) = EOBc Cc (x) + EOEc′′ (x) + EBc Dc (x) + EDc Ec′′ (x) + EFc (x) = 1 1 1 + + 3 2 (1 − x) (1 − x)(1 − x ) (1 − x)(1 − x2 ) + = (38) 2x2 + 1 1 + 2 2 (1 − x ) 1 − x3 −2x5 + 4x2 + 5x + 5 . (1 − x2 )2 (1 − x3 ) Finally, the edge OBc : (−1)2 rOBc (1/x) = EOBc (x) = 33 1 . (1 − x)2 (39) Now Rmlc (x) results from (32), and then from (35) we see that Lc (x) = 12x4 ( x2 Rmlc (x) = (1 − x)2 ) 79x15 + 190x14 + 260x13 + 250x12 + 211x11 + 179x10 + 181x9 + 198x8 + 210x7 + 181x6 + 125x5 + 61x4 + 22x3 + 8x2 + 4x + 1 (1 − x4 )(1 − x5 )(1 − x3 )2 (1 − x2 )2 (40) . The constituents of Lc are extracted as described in Section 2.1, and here they are: 3 5 51 4 202 3 3769 2 10 t − 8 t + 3 t − 10 t + c1 (t)t − c0 (t), if t is even; (41) Lc (t) = 3 51 202 7493 5 4 3 2 t − t + t − t + c1 (t)t − c0 (t), if t is odd; 10 8 3 20 where c1 varies with period 6, given by 994, 986, c1 (t) = 1909 , 2 1925 , 2 if if if if t ≡ 0, 2 t≡4 t≡1 t ≡ 3, 5 and c0 , given by Table 7, varies with period 60. 34 (mod 6); t c0 (t) t c0 (t) t c0 (t) t c0 (t) t c0 (t) 0 948 12 948 24 36 76933 120 2780 3 35607 40 13292 15 18433 24 4452 5 18497 24 14332 15 32727 40 2572 3 93893 120 13 87301 120 14332 15 6891 8 11996 15 18433 24 4884 5 95941 120 2780 3 29271 40 2572 3 104261 120 25 29 41 4452 5 16769 24 14332 15 35607 40 2572 3 85253 120 48 1 4884 5 16769 24 13036 15 6891 8 13292 15 95621 120 30 948 42 948 54 31 85573 120 2780 3 32727 40 13292 15 20161 24 43 95941 120 14332 15 6315 8 11996 15 20161 24 55 4884 5 87301 120 2780 3 32151 40 2572 3 95621 120 4884 5 18497 24 13036 15 6315 8 13292 15 104261 120 2 3 4 5 6 7 8 9 10 11 14 15 16 17 18 19 20 21 22 23 26 27 28 32 33 34 35 37 38 39 40 44 45 46 47 49 50 51 52 53 56 57 58 59 Table 7: Constant terms of the constituents of Lc (t), counting all magilatin squares by upper bound. Thus the period of Lc turns out to be 60, just like that of Sc (not a surprise). However, again as with Sc , the even constant terms have half the period of the odd constant terms. That means Lc (2t) has period equal to half the denominator of the corresponding inside-out polytope (2P, H). We have no explanation for this. The principal constituent, that for t ≡ 0 (mod 60), is 3 5 51 4 202 3 3769 2 t − t + t − t + 994t − 948. 10 8 3 10 The constant term for magilatin squares does not have the simple interpretation as a number of linear orderings that it does for magic and semimagic squares, because the entries in the square need not all be different. (Still, there is an interpretation as a number of partial orderings of the nine cells; see Theorem 4.1 in our general magic and magilatin paper [6], and recall that an acyclic orientation of a graph can be represented by a partial ordering of the vertices.) We confirmed the formulas by generating all magilatin squares and comparing the count with the coefficients of Lc (x) up to t = 91. 35 5.1.2 Symmetry types of magilatin squares, counted by upper bound The number of symmetry types with strict bound t is lc (t). We count them via rmlc (w), given by Equation (33); then lc (t) = t−1 X (t − 1 − w) rmlc (w). (42) w=0 Equivalently, rmlc (w) counts the w1 -integral points in the interior and part of the boundary of the inside-out polytope (Qc , Ic ) of Section 4.1. We get rmlc (x) from (33); then from (42) we see that lc (x) = x4 ( x2 rmlc (x) = (1 − x)2 9x15 + 20x14 + 23x13 + 16x12 + 10x11 + 13x10 + 27x9 + 43x8 + 54x7 + 52x6 + 41x5 + 25x4 + 14x3 + 8x2 + 4x + 1 ) (1 − x2 )2 (1 − x3 )2 (1 − x4 )(1 − x5 ) The constituents of lc are: 1 5 3 t − t4 + 240 64 lc (t) = 1 t5 − 3 t4 + 240 64 (43) . 97 3 2029 2 t − t + ĉ1 (t)t − ĉ0 (t), if t is even; 216 720 97 3 4013 2 t − t + ĉ1 (t)t − ĉ0 (t), if t is odd; 216 1440 where ĉ1 varies with period 6, given by 17 , 2 151 , 18 ĉ1 (t) = 1163 , 144 131 , 16 if if if if t ≡ 0, 2 t≡4 t≡1 t ≡ 3, 5 and ĉ0 , given by Table 8, varies with period 60. 36 (mod 6), t ĉ0 (t) 0 9 12 1 49213 8640 235 27 2823 320 1144 135 12313 1728 41 5 12953 1728 1229 135 2503 320 218 27 63293 8640 13 2 3 4 5 6 7 8 9 10 11 t 14 15 16 17 18 19 20 21 22 23 ĉ0 (t) t ĉ0 (t) t ĉ0 (t) t ĉ0 (t) 9 24 36 25 29 41 41 5 11225 1728 1229 135 2823 320 218 27 54653 8640 48 59581 8640 1229 135 539 64 982 135 12313 1728 47 5 68221 8640 235 27 2119 320 218 27 73661 8640 47 5 11225 1728 1067 135 539 64 1144 135 65021 8640 30 9 42 9 54 31 57853 8640 235 27 2503 320 1144 135 14041 1728 43 68221 8640 1229 135 475 64 982 135 14041 1728 55 47 5 59581 8640 235 27 2439 320 218 27 65021 8640 47 5 12953 1728 1067 135 475 64 1144 135 73661 8640 26 27 28 32 33 34 35 37 38 39 40 44 45 46 47 49 50 51 52 53 56 57 58 59 Table 8: Constant terms of the constituents of lc (t), counting symmetry types of magilatin squares by upper bound. Thus the period of lc turns out to be 60. As with Sc and Lc , the period of the even constant terms is half that of the odd constant terms. The principal constituent of lc is 3 97 3 2029 2 17 1 5 t − t4 + t − t + t − 9. 240 64 216 720 2 5.1.3 Some real numbers For the first several nonzero values of the numbers of magilatin squares and of symmetry types, consult this table: t Lc (t) lc (t) Rmlc (t) rmlc (t) 4 5 6 7 8 9 10 11 12 13 14 15 12 48 120 384 1068 2472 4896 9072 15516 25608 40296 61608 1 4 10 24 53 106 191 328 528 822 1230 1794 12 24 36 192 420 720 1020 1752 2268 3648 4596 6624 1 2 3 8 15 24 32 52 63 94 114 156 The third line contains the number of symmetry classes of 3 × 3 magilatin squares, counted by upper bound. The main numbers, Lc (t) and lc (t), are sequences A173548 and A173729 in the OEIS [15]. The reduced numbers, Rmlc (t) and rmlc (t), are sequences A174018 and A174019. In contrast to the semimagic case, the number of squares is not a simple multiple of the number of symmetry types. 37 5.2 Magilatin squares: Affine count (by magic sum) The last example is 3 × 3 magilatin squares, counted affinely. Let La (t) be the number of 3 × 3 magilatin squares with magic sum t > 0. The weak quasipolynomial is the same as in affine semimagic. 5.2.1 Magilatin squares by magic sum We compute La (t), the number of squares with magic sum t, via Rmla (s), the number of reduced squares with magic sum s. The formula is X Rmla (s) if t > 0. (44) La (t) = 0<s≤t−3 s≡t (mod 3) Equivalently, Rmla (s) counts 1s -integral points in the interior and part of the boundary of the inside-out polytope (Qa , Ia ) of Section 4.2, each weighted by 72/|GS |. Now we calculate (by LattE) the closed Ehrhart generating function for each necessary face. First, OABa : (−1)3 rOABa (1/x) = EOABa (x) + EOEa (x) 1 1 + = 2 2 (1 − x)(1 − x ) (1 − x)(1 − x4 ) 2 . = (1 − x)(1 − x2 )(1 − x4 ) (45) Next is OACa : (−1)3 rOACa (1/x) = EOACa (x) + EADa (x) + EDa Ea′ (x) 1 1 1 = + + 2 2 2 3 3 (1 − x)(1 − x ) (1 − x )(1 − x ) (1 − x )(1 − x4 ) x3 + x2 + x + 3 = . (1 − x2 )(1 − x3 )(1 − x4 ) (46) The last facet is OBa Ca : (−1)3 rOBa Ca (1/x) = EOBa Ca (x) + EOEa′′ (x) + EBa Da (x) + EDa Ea′′ (x) + EFa (x) 1 1 1 + + = 2 2 4 2 (1 − x)(1 − x ) (1 − x)(1 − x ) (1 − x )(1 − x3 ) 1 1 + + 3 4 (1 − x )(1 − x ) 1 − x5 (47) x5 + 4x4 + 6x3 + 7x2 + 7x + 5 . = (1 − x5 )(1 − x3 )(1 − x4 )(1 + x) Finally, the edge OBa : (−1)2 rOBa (1/x) = EOBa (x) = 38 1 . (1 − x)(1 − x2 ) (48) Now we get Rmla (x) from (32); then by (44) we deduce that x3 Rmla (x) 1 − x3 2 3 4 5 6 7 8 1 + 3x + 7x + 15x + 33x + 65x + 128x + 208x + 316x + 434x9 + 566x10 + 676x11 + 784x12 + 852x13 + 911x14 + 936x15 12x6 + 967x16 + 967x17 + 1001x18 + 995x19 + 1000x20 + 955x21 22 23 24 25 26 27 28 + 893x + 752x + 624x + 456x + 322x + 174x + 79x . = (1 + x)(1 + x + x2 )(1 + x2 )(1 − x3 )(1 − x5 )(1 − x6 )(1 − x7 )(1 − x8 ) La (x) = (49) The constituents of La are the following: 1 La (t) = t4 − 3t3 + a2 (t)t2 − a1 (t)t + a0 (t) − 72S7 (t), 8 where a2 varies with period 6, given by 151 , 4 135 , a2 (t) = 634 , 2 71 , 2 if if if if t≡0 t ≡ 2, 4 t ≡ 1, 5 t≡3 the linear coefficient varies with period 12, given by 1296 , if t ≡ 0 5 1347 , if t ≡ 1, 5 10 831 , if t ≡ 2, 10 5 2097 , if t ≡ 3 10 a1 (t) = 876 5 , if t ≡ 4, 8 1251 , if t ≡ 6 5 1257 10 , if t ≡ 7, 11 2187 , if t ≡ 9 10 (50) (mod 6); (mod 12); the constant term a0 , given by Table 9, varies with period 120; and S7 is as in the affine semimagic count. 39 t a0 (t) 0 876 20 340 40 400 60 1 21 49 3283 40 3597 5 −941 40 1484 5 4887 8 821 5 2131 40 3948 5 5107 40 61 29 21843 40 1037 5 −461 40 4164 5 1367 8 881 5 17811 40 1388 5 5587 40 41 9 4243 40 1097 5 15219 40 1604 5 1463 8 3201 5 3091 40 1448 5 21267 40 10 265 30 705 50 11 −1037 40 4092 5 4819 40 809 5 4023 8 1676 5 5011 40 3273 5 787 40 31 1363 40 1772 5 19539 40 1109 5 311 8 3876 5 7411 40 593 5 18387 40 51 2 3 4 5 6 7 8 12 13 14 15 16 17 18 19 t a0 (t) 22 23 24 25 26 27 28 32 33 34 35 36 37 38 39 t a0 (t) 42 43 44 45 46 47 48 52 53 54 55 56 57 58 59 t a0 (t) t a0 (t) 840 80 376 100 364 81 89 20403 40 1217 5 −1901 40 3984 5 1655 8 701 5 19251 40 1568 5 4147 40 101 69 5683 40 917 5 16659 40 1784 5 1175 8 3381 5 1651 40 1268 5 22707 40 109 4723 40 3417 5 499 40 1664 5 4599 8 1001 5 691 40 3768 5 6547 40 241 70 229 90 741 110 205 16083 40 1712 5 3859 40 3309 5 791 8 1556 5 22131 40 893 5 −173 40 71 403 40 4272 5 3379 40 989 5 3735 8 1496 5 6451 40 3093 5 2227 40 91 −77 40 1592 5 20979 40 929 5 599 8 4056 5 5971 40 773 5 16947 40 111 17523 40 1892 5 2419 40 3489 5 503 8 1376 5 23571 40 713 5 1267 40 62 63 64 65 66 67 68 72 73 74 75 76 77 78 79 82 83 84 85 86 87 88 92 93 94 95 96 97 98 99 t a0 (t) 102 103 104 105 106 107 108 112 113 114 115 116 117 118 119 Table 9: Constant terms of the truncated constituents of La (t), counting magilatin squares by magic sum. The period of La turns out to be 840—the period of the constant terms, due to the combination of a0 (t) and the constant term of S7 (t). This is equal to the denominator. The principal constituent of La , that is, for t ≡ 0 (mod 840), is 1 4 151 2 9192 t − 3t3 + t − t + 948 8 4 35 (incorporating the −72S7 term). (As with the cubical magilatin count, there is an interpretation of the constant term 948 in terms of partial orderings; see Theorem 4.7 in our general paper [6].) 40 We verified the results by comparing an actual count of magilatin squares with magic sum t ≤ 100 to the coefficients in La . 5.2.2 Symmetry types of magilatin squares, counted by magic sum We compute la (t), the number of symmetry types of squares with magic sum t, via rmla (s), the number of reduced symmetry types with magic sum s. The formula is X rmla (s) if t > 0. (51) la (t) = 0<s≤t−3 s≡t (mod 3) Equivalently, rmla (s) counts 1s -integral points in the interior and part of the boundary of the inside-out polytope(Qa , Ia ) of Section 4.2. From (32) we get rmla (x) and then from (51) we see that la (x) = x3 rmla (x) 1 − x3 2 3 4 5 6 7 8 9 1 + 3x + 7x + 13x + 23x + 37x + 60x + 86x + 118x + 149x + 180x10 + 199x11 + 212x12 + 208x13 + 196x14 + 171x15 6 x + 145x16 + 115x17 + 96x18 + 79x19 + 72x20 + 67x21 22 23 24 25 26 27 28 + 66x + 59x + 54x + 43x + 33x + 19x + 9x . = (1 + x)(1 + x + x2 )(1 + x2 )(1 − x3 )(1 − x5 )(1 − x6 )(1 − x7 )(1 − x8 ) The constituents of la are: la (t) = 1 1 4 t − t3 + â2 (t)t2 − â1 (t)t + â0 (t) − S7 (t), 576 48 where the quadratic term varies with period 6, given by 25 , if t ≡ 0 96 25 , if t ≡ 1, 5 (mod 6); â2 (t) = 144 59 , if t ≡ 2, 4 288 11 , if t ≡ 3 48 the linear term varies with period 12, given by 31 , if t ≡ 0 15 103 , if t ≡ 1, 5 120 133 , if t ≡ 2, 10 120 47 , if t ≡ 3 â1 (t) = 30 37 30 , if t ≡ 4, 8 233 , if t ≡ 6 120 11 15 , if t ≡ 7, 11 203 , if t ≡ 9 120 41 (mod 12); (52) and â0 , given by Table 10, varies with period 120. t â0 (t) 0 8 20 1 2027 2880 553 360 979 320 229 90 847 576 221 40 1739 2880 104 45 1427 320 149 72 −1813 2880 73 10 2891 2880 301 360 279 64 128 45 2219 2880 233 40 −277 2880 21 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 t â0 (t) 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 47 18 1523 320 493 360 −949 2880 38 5 751 576 409 360 1171 320 193 90 3083 2880 49 8 587 2880 131 45 1299 320 601 360 −17 576 69 10 4619 2880 157 360 1267 320 t â0 (t) 40 31 9 1067 2880 257 40 −1429 2880 199 90 343 64 349 360 779 2880 36 5 2603 2880 125 72 1043 320 247 90 1931 2880 229 40 463 576 113 45 1491 320 457 360 −1237 2880 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 t â0 (t) 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 15 2 3467 2880 373 360 1139 320 137 45 559 576 241 40 299 2880 163 90 1587 320 113 72 −373 2880 39 5 1451 2880 481 360 247 64 211 90 3659 2880 213 40 1163 2880 t â0 (t) 80 28 9 1363 320 673 360 −2389 2880 71 10 1039 576 229 360 1331 320 119 45 1643 2880 53 8 −853 2880 217 90 1459 320 421 360 271 576 37 5 3179 2880 337 360 1107 320 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 t â0 (t) 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 53 18 2507 2880 237 40 11 2880 122 45 311 64 529 360 −661 2880 67 10 4043 2880 89 72 1203 320 146 45 491 2880 249 40 175 576 181 90 1651 320 277 360 203 2880 Table 10: Constant terms of the truncated constituents of la (t), the number of symmetry types of magilatin squares with given magic sum. The period of la is 840. The principal constituent, that for t ≡ 0 (mod 840), is 1 25 74 1 4 t − t3 + t2 − t + 9. 576 48 96 35 (This incorporates the −S7 term.) 42 5.2.3 Some numbers The first several nonzero values are given in the table. The third line gives the number of symmetry classes of squares. t La (t) la (t) Rmla (t) rmla (t) 6 7 8 9 10 11 12 13 14 15 16 17 18 19 12 12 24 72 156 240 552 600 1020 1548 2004 2568 4008 4644 1 1 2 4 7 10 20 22 35 50 63 78 116 131 12 12 24 60 144 216 480 444 780 996 1404 1548 2640 3696 1 1 2 3 6 8 16 15 25 30 41 43 66 68 The sequences La (t) and la (t) are A173549 and A173730 in the OEIS [15]. The numbers Rmla (t) of reduced magilatin squares and rmla (t) of normalized, reduced squares with largest value t are sequences A174020 and A174021. 6 Observations and conjectures A remarkable fact is that the period of every one of our strong Ehrhart quasipolynomials equals the denominator, when it could be much smaller. For some small values of t we calculated Ma (t) = EP◦ ◦ ,H(t) by hand, which is feasible because the problem is 2-dimensional. The process of counting lattice points in a diagram drew our attention to some remarkable phenomena that apply to the semimagic and magilatin problems as well. Let δ := dim s; let ck be the coefficient in the quasipolynomial EP◦ ◦ ,H(t) w and let cw k be that in the Ehrhart quasipolynomial of P , and let pk , pk be their periods. We w observe that the variation in cδ−1 is exactly the same as that in cδ−1 , i.e., w cδ−1 (t) − cδ−1 (t − 1) = cw δ−1 (t) − cδ−1 (t − 1), but that is not so for most lower coefficients, especially c0 . The reason is that adding each new excluded hyperplane results in a constant deduction in degree δ − 1 (as we discussed at Equation (4.9) in our first article [5]) but a more irregular one in lower terms. We observe that pk increases—that is, there is longer-term variation in ck —as k decreases in every case. Thus we propose some daring conjectures. Conjecture 3. In an inside-out counting problem, let δ := dim P . w w (a) pw k | pk for 0 ≤ k ≤ δ. (We know that pδ−1 = pδ−1 because cδ−1 and cδ−1 have the same variation.) w (b) If pj = pw j for all j ≥ k, then the variation in ck is the same as that in ck . (c) The period ratios increase by a multiplicative factor as k decreases: pk pk−1 for 0 ≤ k ≤ δ. pw pw k k−1 We do not suggest pk | pk+1 because that is false in general in ordinary Ehrhart theory, according to McAllister and Woods [13]. However, it might be true for the kinds of insideout polytopes that arise in cubical and affine counting. 43 7 Acknowledgments The authors are grateful to the anonymous referee for several helpful suggestions. References [1] Maya Ahmed, Jesús De Loera, and Raymond Hemmecke, Polyhedral cones of magic cubes and squares, in Boris Aronov et al., eds., Discrete and Computational Geometry: The Goodman–Pollack Festschrift, Algorithms Combin., Vol. 25, Springer-Verlag, 2003, pp. 25–41. MR 2004m:05016. Zbl 1077.52506. [2] Matthias Beck, Moshe Cohen, Jessica Cuomo, and Paul Gribelyuk, The number of “magic” squares and hypercubes, Amer. Math. Monthly 110 (2003), 707–717. MR 2004k:05009. Zbl 1043.05501. [3] Matthias Beck and Andrew van Herick, Enumeration of 4 × 4 magic squares, Math. Comp., to appear. [4] Matthias Beck and Dennis Pixton, The Ehrhart polynomial of the Birkhoff polytope, Discrete Comput. Geom. 30 (2003), 623–637. MR 2004g:52015. Zbl 1065.52007. [5] Matthias Beck and Thomas Zaslavsky, Inside-out polytopes, Adv. Math. 205 (1) (2006), 134–162. MR 2007e:52017. Zbl 1107.52009. [6] Matthias Beck and Thomas Zaslavsky, An enumerative geometry for magic and magilatin labellings, Ann. Combin. 10 (2006), 395–413. MR 2007m:05010. Zbl 1116.05071. [7] Matthias Beck and Thomas Zaslavsky, “Six Little Squares and How their Numbers Grow” Web Site: With a detailed version (as of January 25, 2007) of this paper, Maple worksheets, and supporting documentation. URL http://www.math.binghamton.edu/zaslav/Tmath/SLSfiles/ [8] Garrett Birkhoff, Three observations on linear algebra (in Spanish), Rev. Univ. Nac. Tucumán, Ser. A 5 (1946), 147–151. MR 8, 561a. Zbl 60, 79f (e: 060.07906). [9] Jesús A. De Loera, David Haws, Raymond Hemmecke, Peter Huggins, Jeremy Tauzer, and Ruriko Yoshida, A User’s Guide for LattE v1.1, Univ. of California at Davis, 2003, URL http://www.math.ecdavis.edu/~ latte/ [10] Eugène Ehrhart, Sur un problème de géometrie diophantienne linéaire. I: Polyèdres et réseaux. II: Systèmes diophantiens linéaires, J. reine angew. Math. 226 (1967), 1–29; 227 (1967), 25–49. Correction, ibid. 231 (1968), 220. MR 35 #4184, 36 #105. Zbl 155.37503, 164.05304. [11] Eugène Ehrhart, Sur les carrés magiques, C. R. Acad. Sci. Paris Sér. A–B 277 (1973), A651–A654. MR 48 #10859. Zbl 267.05014. 44 [12] Percy A. MacMahon, Combinatory Analysis, Vols. I and II, Cambridge University Press, 1915–1916. Reprinted in one volume by Chelsea, 1960. MR 25 #5003. Zbl 101, 251 (e: 101.25102). [13] Tyrrell B. McAllister and Kevin M. Woods, The minimum period of the Ehrhart quasipolynomial of a rational polytope, J. Combin. Theory Ser. A 109 (2005), 345–352. MR 2005i:52018. Zbl 1063.52006. [14] Jochi Shigeru, The dawn of wasan (Japanese mathematics), in Helaine Selin and Ubiratan D’Ambrosio, eds., Mathematics Across Cultures: The History of Non-Western Mathematics, Science Across Cultures: The History of Non-Western Science, Vol. 2, Kluwer, 2000, pp. 423–454. MR (book) 1805670 (2002a:01001). Zbl 981.01005. [15] N. J. A. Sloane, The On-Line Encyclopedia http://www.research.att.com/~njas/sequences/ of Integer Sequences, [16] Richard P. Stanley, Linear homogeneous Diophantine equations and magic labelings of graphs, Duke Math. J. 40 (1973), 607–632. MR 47 #6519. Zbl 269.05109. [17] Richard P. Stanley, Enumerative Combinatorics, Vol. I, Wadsworth & Brooks/Cole, 1986. MR 87j:05003. Zbl 608.05001. Corrected reprint, Cambridge Stud. Adv. Math., Vol. 49, Cambridge University Press, 1997. MR 98a:05001. Zbl 889.05001, 945.05006. [18] Guoce Xin, Constructing all magic squares of order three, Discrete Math. 308 (2008), 3393–3398. MR 2423421 (2009e:05039). Zbl 1145.05012. 2010 Mathematics Subject Classification: Primary 05B15; Secondary 05A15, 52B20, 52C35. Keywords: magic square, semimagic square, magic graph, latin square, magilatin square, lattice-point counting, rational convex polytope, arrangement of hyperplanes. (Concerned with sequences A108235, A108236, A108576, A108577, A108578, A108579, A173546, A173547, A173548, A173549, A173723, A173724, A173725, A173726, A173727, A173728, A173729, A173730, A174018, A174019, A174020, A174021, A174256, and A174257.) Received March 9 2010; revised version received June 1 2010. Published in Journal of Integer Sequences, June 2 2010. Revised, June 8 2010. Return to Journal of Integer Sequences home page. 45