LINEAR TYPE-p MOST-PERFECT SQUARES

JOHN LORCH

Abstract. We describe a generalization of most-perfect squares, called type-p most- perfect squares, and in prime-power orders we give a linear construction of these squares reminiscent of de la Loub`ere’sclassical magic square construction method. Type-p most- perfect squares can be used to construct other interesting squares (e.g., generalized Franklin squares) and our linear construction may have implications for counting type-p most-perfect squares.

1. Introduction

Let n be a divisible by p. A natural R of order n is said to be a most-perfect square of type-p if the following two properties hold: (i) (Complementary property) Starting from any location in R, consider the symbol in that location together with the p−1 other symbols lying in the same broken main- p(n2 − 1) diagonal n/p units apart from one another. The sum of these symbols is . 2 (ii) (p × p property) The symbols in any p × p subsquare formed from consecutive rows p2(n2 − 1) and columns (allowing wraparound) sum to . 2 Examples of type-2 and type-3 most-perfect squares are given in Figure 1.

0 16 23 63 79 59 45 34 41 0 31 48 47 56 39 8 23 64 80 57 46 35 39 1 17 21 59 36 11 20 3 28 51 44 47 33 40 2 15 22 65 78 58 6 25 54 41 62 33 14 17 7 14 18 70 77 54 52 32 36 61 34 13 18 5 26 53 42 71 75 55 53 30 37 8 12 19 7 24 55 40 63 32 15 16 51 31 38 6 13 20 69 76 56 60 35 12 19 4 27 52 43 5 9 25 68 72 61 50 27 43 1 30 49 46 57 38 9 22 66 73 62 48 28 44 3 10 26 58 37 10 21 2 29 50 45 49 29 42 4 11 24 67 74 60

Figure 1. Left: A type-2 (classical) most-perfect square of order-8. Right: A type-3 most-perfect square of order 9. The gridlines serve as an aid in locating complementary entries. In this article we use a linear method to construct certain type-p most-perfect squares of order pr, where p is any prime. In 1688 French diplomat Simon de la Loub`erereturned

Date: December 27, 2017. 2010 Mathematics Subject Classification. 05B30, 15B33. 1 2 JOHN LORCH from Thailand and wrote an account of his travels [5]. In that account he relates a “knight’s move” magic square construction method he learned from his hosts; see [1] for a description. We view De la Loub´ere’smethod as a linear construction over a finite field. Magic squares constructed by this method, or some suitable variation, are called linear magic squares. This technique has shown promise in constructing new magic squares and rectangles (e.g., see [2] and [3]), and now we apply it to type-p most-perfect squares. Type-p most-perfect squares specialize to classical most-perfect squares when p = 2, in which case n must be doubly even [10]. The tasks of counting and constructing classical most-perfect squares were first approached by McClintock [6] and culminate in the work of Ollerenshaw and Bree [8], which gives a count of the classical most-perfect squares for any doubly even order n, along with a construction method for all such squares. Also, classical most-perfect squares are useful in constructing Franklin magic squares (see [11] and [7], and [9] for historical background). Aside being interesting in its own right, there are two primary motives for our linear construction of type-p most-perfect squares. First, a generalized notion of Franklin magic squares is presented in [4]. Such squares have orders that are triply divisible by some prime p, whereas the classical Franklin squares (more precisely, the ones of which we are aware) have orders triply divisible by 2. Type-p most-perfect squares can be used to produce examples of these generalized Franklin squares. Second, one may observe that all of the ten McClintock order-8 classical most-perfect squares are linear magic squares. These ten squares generate all most-perfect squares of order 8 ([6] and [8]). This scant evidence suggests that it may be possible to cast the construction and counting of type-p most-perfect squares of order pr in terms of linear squares.

2. A Characterization of Certain Type-p Most-Perfect Squares

In this section we present a characterization of type-p most-perfect squares with order divisible by p2. Establishing the validity of our linear construction of such squares (Section 4) is made easier through the use of this characterization.

Lemma 2.1. Let m, n ∈ N and consider a nonnegative integer array A of size (mp + 1) × (np + 1) with a v b

A = u D w .

c z d Here a, b, c, d ∈ Z, u, w are lists of length mp − 1, v, z are lists of length np − 1, and D is an (mp − 1) × (np − 1) array. If A possesses the p × p property then a + d = c + b.

Proof. By the p × p property a + u + v + D = b + v + w + D = c + u + z + D = d + z + w + D, LINEAR TYPE-p MOST-PERFECT SQUARES 3 where the additions indicate the total sums of symbols in each type of list. It follows that (a + u + v + D) + (d + z + w + D) = (b + v + w + D) + (c + u + z + D), and cancellation gives the result.  Proposition 2.2. Let n be a multiple of p2. Any natural square of order n that possesses both the complementary property and the p × p property is a most-perfect square of type p.

Proof. Let R be a square satisfying the hypotheses of the theorem. It suffices to show that R is a pandiagonal magic square. The complementary property implies that broken main diagonals (i.e., translates–not cosets–of the main diagonal) achieve the magic sum. It remains to show that the same is true for rows, columns, and broken off-diagonals.

Let ρj (0 ≤ j ≤ n − 1) denote the integer sum of entries in the j-th row of R. By the complementary property we have p(n2 − 1) ρ + ρ + ρ + ··· + ρ = n · , 0 n/p 2n/p (p−1)n/p 2 where in the righthand side the right term is the complementary sum, and n is the number of entries per row. Meanwhile, because n/p is a multiple of p, the p × p property implies that

ρ0 = ρn/p = ρ2n/p = ··· = ρ(p−1)n/p. Conclude that 1 n(n2 − 1) ρ = [ρ + ρ + ρ + ··· + ρ ] = . 0 p 0 n/p 2n/p (p−1)n/p 2 Therefore the top row of R has the magic sum; the same argument may be applied to any row or column of R. It remains to show that R is pandiagonal. We do this by showing that R must have the following off-diagonal complementary property: Starting from any location in R, consider the symbol in that location together with the p − 1 other symbols lying in the same broken p(n2 − 1) off-diagonal n/p units apart from one another. The sum of these symbols is . 2 Our strategy is to show that each of these broken off-diagonal sums corresponds to a broken main-diagonal sum. This is evident when p = 2, so we assume that p is odd. Subdivide R 2 into (n/p) × (n/p) subsquares–there are p such squares. Let ai,j represent the entry in the lower-left corner of the (i, j)-subsquare, with 0 ≤ i, j ≤ p − 1 counting from left to right and top to bottom. Observe that

S = ap−1,0 + ap−2,1 + ··· + a0,p−1 is an off-diagonal sum as described above in the off-diagonal complementary property. By Lemma 2.1 (which requires that n/p be a multiple of p) we have

S = [ap−1,0 + a1,p−2] + [ap−2,1 + a2,p−3] + ··· + [a(p+1)/2,(p−3)/2 + a(p−1)/2,(p−1)/2] + a0,p−1

= [a1,0 + ap−1,p−2] + [a2,1 + ap−2,p−3] + ··· + [a(p−1)/2,(p−3)/2 + a(p+1)/2,(p−1)/2] + a0,p−1. 4 JOHN LORCH

Observe that the latter sum in the equation above is a main broken diagonal complementary sum. Therefore, by the complementary property for main broken diagonals we have S = p(n2−1) 2 , as desired. A similar argument can be applied to any complementary broken off- diagonal sum. The position of the terms in the complementary sums described above is illustrated in the following array:

a0,p−1

a1,0 a1,p−2

a2,1 a2,p−3

ap−2,1 ap−2,p−3

ap−1,0 ap−1,p−2 

3. Magic Squares via Linearity

In this section we show how linear transformations can be used to construct arrays of numbers, including magic squares. The essence of these ideas dates back to Simon de la Loub`ere’sclassical method for constructing magic squares. r r 2r Locations in a p ×p array can be described by elements of the vector space Zp . Rows are enumerated from the top, beginning with 0 and ending with pr − 1; columns are enumerated in the same way from left to right. By expressing each row number in base p we can identify r r row locations with Zp. Similarly we can identify column locations with Zp, and therefore any 2r grid location (row,column) may be identified with an element of Zp . By way of illustration, 2·3 the symbol “26” in the left portion of Figure 1 lies in location 011101 ∈ Z2 , where the first three entries indicate the row location and the last three entries indicate the column location. Symbols in the set S = {0, 1, . . . , p2r − 1} ⊂ Z may be placed in a pr × pr array. These 2r symbols can also be described by elements of Zp . Each symbol Λ has a unique base-p expansion 2r−1 2r−2 1 0 Λ = λp2r−1 p + λp2r−2 p + ··· + λp · p + λ1 · p , 2r−1 where λpj ∈ {0, 1, . . . , p − 1} for each j ∈ {0, 1, . . . , p }. Therefore we can make the identification 2r Λ ∈ Z ←→ (λp2r−1 , . . . , λp0 ) ∈ Zp . For example, if p = 2 and r = 3 as in the left portion of Figure 1, then the symbol Λ = 26 2·3 corresponds to 011010 ∈ Z2 . A linear assignment of symbols to locations is as follows. Let M be a 2r × 2r with 2r 2r entries in Zp. Define a linear mapping TM : Zp → Zp by TM (Λ) = MΛ. The mapping TM r r r+s uniquely determines a p × p array with entries in {0, 1, . . . , p − 1} by declaring TM (Λ) LINEAR TYPE-p MOST-PERFECT SQUARES 5 to be the array location housing the number with base-p representation Λ (as described in the previous paragraphs). When p = 2, r = 3, and  1 1 0 1 1 1   0 0 0 0 1 1     0 0 0 1 1 0  (1) M =   ,  1 1 1 1 1 0   0 1 1 0 0 0  1 1 0 0 0 0 the mapping TM determines the array in the left portion of Figure 1. To see that the number 26 is sent the to the correct location, recall that Λ = 011010 and so MΛ = 011101, which is indeed the location housing 26 as described above. Similarly, the matrix  2 2 2 0   0 0 1 1  (2) M =    2 0 2 2  1 1 0 0 determines the order-9 array in the right portion of Figure 1. Any magic square that possesses a linear representation as described above will be referred to as a linear magic square.

4. A Linear Construction of Most-Perfect Squares

In this section we describe a linear construction of type-p most-perfect squares of order pr, where r ≥ 2. In case r = 1, a type-p most-perfect square of order p is simply a pandiagonal magic square of prime order; de la Loub`ere’smethod can be applied in that case as described in [1]. We will be performing arithmetic over Z and over Zp; we occasionally let ⊕ denote addition over Z to distinguish it from addition over Zp. 2r−j 2r For r ≥ 2 let αj = p for 1 ≤ j ≤ 2r. When considered as vectors in Zp as described 2r 1 in Section 3, the set {α1, . . . , α2r} is the standard basis for Zp . Let Lr denote the r × r symmetric matrix with 1’s on and below the off diagonal and 0’s elsewhere. Therefore, if Lr = (`ij) then  0 0 ··· 1  ( . . 1 i + j > r  . ..   0 . 1  `ij = and Lr =  .  . 0 i + j ≤ r  . 1 ··· 1  1 1 ··· 1 Let L denote the 2r × 2r symmetric matrix matrix with block form  0 L  L = r , Lr 0

1 Other bases for the space of symbols, such as a reordering the the αj’s, would work just as well and give different linear most-perfect magic squares. 6 JOHN LORCH ˜ ˜ and let L be the 2r × 2r matrix with entries in Zp whose columns `j satisfy ˜ `j + (e1 + er+1) = `j 1 ≤ j ≤ 2r, 2r ˜ where e1, . . . , e2r are the elementary vectors in Zp . The matrix L has the form  −1 −1 −1 −1 · · · −1 −1 −1 · · · −1 −1 −1 −1 0  0 0 0 0 ··· 0 0 0 ··· 0 0 0 1 1  0 0 0 0 ··· 0 0 0 ··· 0 0 1 1 1     0 0 0 0 ··· 0 0 0 ··· 0 1 1 1 1   0 0 0 0 ··· 0 0 0 ··· 1 1 1 1 1   ......   . . . . ··· ......    L˜ =  0 0 0 0 ··· 0 0 1 ··· 1 1 1 1 1  .  −1 · · · −1 −1 −1 −1 0 −1 −1 −1 −1 · · · −1 −1     0 ··· 0 0 0 1 1 0 0 0 0 ··· 0 0   0 ··· 0 0 1 1 1 0 0 0 0 ··· 0 0   0 ··· 0 1 1 1 1 0 0 0 0 ··· 0 0     0 ··· 1 1 1 1 1 0 0 0 0 ··· 0 0   ......  ...... ··· . . 1 ··· 1 1 1 1 1 0 0 0 0 ··· 0 0 Following Section 3, we regard L˜ as a candidate for a matrix producing a linear most-perfect r ˜ square of order p , with column `j being the location of symbol αj for 1 ≤ j ≤ 2r. The matrix L˜ is a good candidate for the following reasons: Observe that the columns of L consist of the possible location vectors one can add to an existing location vector in order to move one unit right or one unit down from that existing location. It is desirable to have control over these vectors to establish the p × p property in the resulting magic square. Meanwhile, translates of the location vector e1 + er+1 play an important role in the complementary property. The matrix L˜ gives some control over both of these features. Unfortunately, for reasons that will be made apparent as we proceed, L˜ won’t quite work 2r because aside from r = 2 there is no symbol δ ∈ Zp such that δ is nonzero in all of its ˜ ˜ components and L.δ = e1 +er+1. To fix this problem we modify L to obtain a 2r ×2r matrix M over Zp with columns m1, . . . , m2r satisfying ˜ • mj = `j for 1 ≤ j < r and r < j < 2r. r−1 ˜ X j+1 ˜ • mr = `r + (−1) `r−j j=2 r−1 ˜ X j+1 ˜ • m2r = `2r + (−1) `2r−j j=2 If r = 2 then M = L˜. If r > 2 then M agrees with L˜ in all but the r-th and 2r-th columns, and those columns of M are obtained from the respective columns of L˜ by applying elementary column operations on L˜. Further, if we put r X r+j (3) δ = (−1) [ej + er+j] j=1 then δ is non-zero in all of its components and M.δ = e1 + er+1. LINEAR TYPE-p MOST-PERFECT SQUARES 7

The matrix M has form shown below, where the undetermined elements depend on the parity of r (left option when r is odd, right option when r is even):  −1 −1 −1 −1 · · · −1 0 or − 1 −1 · · · −1 −1 −1 −1 1 or 0  0 0 0 0 ··· 0 0 0 ··· 0 0 0 1 1  0 0 0 0 ··· 0 0 0 ··· 0 0 1 1 0     0 0 0 0 ··· 0 0 0 ··· 0 1 1 1 1   0 0 0 0 ··· 0 0 0 ··· 1 1 1 1 0   ......   . . . . ··· ......    M =  0 0 0 0 ··· 0 0 1 ··· 1 1 1 1 0 or 1   −1 · · · −1 −1 −1 −1 1 or 0 −1 −1 −1 −1 · · · −1 0 or − 1     0 ··· 0 0 0 1 1 0 0 0 0 ··· 0 0   0 ··· 0 0 1 1 0 0 0 0 0 ··· 0 0   0 ··· 0 1 1 1 1 0 0 0 0 ··· 0 0     0 ··· 1 1 1 1 0 0 0 0 0 ··· 0 0   ......  ...... ··· . . 1 ··· 1 1 1 1 0 or 1 0 0 0 0 ··· 0 0 As described in Section 3, let R denote the square of order pr (r ≥ 2) obtained by viewing M as the matrix of the linear transformation carrying symbols {0, 1,..., (pr)2 − 1}, each expressed as 2r-tuples with respect to the basis {α1, . . . , α2r} and viewed as a member of 2r 2r Zp , to locations determined by members of Zp . Specific examples of M are given in (1) and (2) in the cases p = 2, r = 3 and p = 3, r = 2, respectively. These M give rise to the most-perfect squares R shown in Figure 1 (left and right, respectively). We will show that R is a most-perfect magic square by checking that R satisfies the hypotheses of Proposition 2.2. This will require several lemmas. Lemma 4.1. R is a natural square.

Proof. We show M is nonsingular. Since M is obtained from L˜ by elementary column operations, it suffices to show that L˜ is nonsingular. If we replace the (r + 1)-st row of L˜ by the sum of that row and the negative of the first row, we obtain a matrix Lˆ of the form  −1 −1 −1 −1 · · · −1 −1 −1 · · · −1 −1 −1 −1 0  0 0 0 0 ··· 0 0 0 ··· 0 0 0 1 1  0 0 0 0 ··· 0 0 0 ··· 0 0 1 1 1     0 0 0 0 ··· 0 0 0 ··· 0 1 1 1 1   0 0 0 0 ··· 0 0 0 ··· 1 1 1 1 1   ......   . . . . ··· ......    Lˆ =  0 0 0 0 ··· 0 0 1 ··· 1 1 1 1 1  .  0 ··· 0 0 0 0 1 0 0 0 0 ··· 0 0     0 ··· 0 0 0 1 1 0 0 0 0 ··· 0 0   0 ··· 0 0 1 1 1 0 0 0 0 ··· 0 0   0 ··· 0 1 1 1 1 0 0 0 0 ··· 0 0     0 ··· 1 1 1 1 1 0 0 0 0 ··· 0 0   ......  ...... ··· . . 1 ··· 1 1 1 1 1 0 0 0 0 ··· 0 0 By expanding along the top row of Lˆ, we see that 2r−1 X det(Lˆ) = ± (−1)j = ±1 6= 0. j=1 8 JOHN LORCH

We conclude that M is nonsingular.  Lemma 4.2. R possesses the complementary property.

Proof. Let v be location in R. We need to show that the symbols in R with locations p(p2r − 1) {v + j · (e + e ) | j ∈ } add to . Therefore, if ν = (ν , ν , . . . , ν ) ∈ 2r with 1 r+1 Zp 2 1 2 2r Zp M.ν = v, and M.δ = e1 + er+1, we need to show that M p(p2r − 1) (4) (ν + j · δ) := ν ⊕ (ν + δ) ⊕ (ν + 2δ) ⊕ · · · ⊕ (ν + (p − 1)δ) = . 2 j∈Zp

Let 1 ≤ k ≤ 2r and δk the k-th component of δ. Because δk is nonzero in Zp, we know that upon rearrangement M p(p − 1) (ν + j · δ ) = 0 ⊕ 1 ⊕ · · · ⊕ (p − 1) = . k k 2 j∈Zp Therefore, if we apply the base-p addition algorithm in (4), we obtain M p(p − 1) (ν + j · δ) = (α ⊕ α ⊕ · · · ⊕ α ) 2 1 2 2r j∈Zp p(p − 1) = (p2r−1 ⊕ p2r−2 ⊕ · · · ⊕ p1 ⊕ 1) 2 p(p2r − 1) = , 2 as desired.  Lemma 4.3. R possesses the p × p property.

Proof. It suffices to verify that if A is any (p + 1) × (p + 1)-subsquare of R formed from consecutive rows and columns (allowing wraparound), with

a11 a12 . . . a1p a1,p+1 a21 a22 . . . a2p a2,p+1 . . . . . A = . . . . . , ap1 ap2 . . . app ap,p+1 ap+1,1 ap+1,2 . . . ap+1,p ap+1,p+1 p p p p M M M M then a1j = ap+1,j and aj1 = aj,p+1. (This is enough to show that all p × p j=1 j=1 j=1 j=1 subsquares in R formed from consecutive rows and columns possess the same integer sum. That common integer sum is the sum of all symbols in R divided by the number of p × p p2(p2r − 1) subsquares needed to tile R. Since R is natural, this computation yields for the 2 common sum of symbols in p × p subsquares, as desired.) LINEAR TYPE-p MOST-PERFECT SQUARES 9

p p M M We show that aj1 = aj,p+1. The other sum has a similar verification. We find the j=1 j=1 location for aj1 by moving j − 1 steps down from a11, so

j X aj1 = a11 + di where M.di ∈ {`r+1, `r+2, . . . , `2r}. i=2 Observe that for r + 1 ≤ j ≤ 2r  (e1 + er+1) + mj if r + 1 ≤ j < 2r, ˜  r−1 `j = e1 + er+1 + `j = X (e + e ) + m − (−1)k+1m if j = 2r.  1 r+1 2r 2r−k k=2

From the construction of R via M, it follows that di = δ + βi where

r−1 X k+1 βi ∈ {αr+1, . . . , α2r−1, α2r − (−1) α2r−k} ⊆ span{αr+1, . . . , α2r}, k=2 and that j X (5) aj1 = (j − 1)δ + a11 + βi. i=2

Meanwhile, we obtain aj,p+1 by moving p steps to the right from aj1. Therefore

" j # p+1 X X aj,p+1 = (j − 1)δ + a11 + βi + ri where M.ri ∈ {`1, . . . , `r}. i=2 i=2

Pr−1 k+1 Likewise it follows that ri = δ + γi where γi ∈ {α1, . . . , αr−1, αr − k=2(−1) αr−k}. Therefore " j # p+1 X X aj,p+1 = (j − 1)δ + a11 + βi + (δ + γi) i=2 i=2 " j # p+1 X X (6) = (j − 1)δ + a11 + βi + γi i=2 i=2 " j # X = (j − 1)δ + a11 + βi + γ, i=2 Pp where γ = i=1 γi ∈ span{α1, . . . , αr} and we recall p·δ = 0 in Zp. To finish this verification it suffices to show equality of integer sums in each component. That is, we seek to show p p M M that (aj1)k = (aj,p+1)k for 1 ≤ k ≤ 2r. If r + 1 ≤ k ≤ 2r then, because γ ∈ j=1 j=1 10 JOHN LORCH span{α1, . . . , αr}, we have " j # X (aj,p+1)k = (j − 1)δ + a11 + βi = (aj1)k. i=2 k p p M M It follows that (aj1)k = (aj,p+1)k for r + 1 ≤ k ≤ 2r. Meanwhile, if 1 ≤ k ≤ r then j=1 j=1 (aj1)k = [(j − 1)δ + a11]k and (aj,p+1)k = [(j − 1)δ + a11 + γ]k. Because δk is nonzero, upon reordering we have p p M M (aj1)k = 1 ⊕ 2 ⊕ · · · ⊕ p − 1 = (aj,p+1)k. j=1 j=1  Theorem 4.4. The square R, as constructed above via M, is a linear type-p most-perfect square of order pr.

Proof. By Proposition 2.2 it suffices to show that R is natural, complementary, and possesses the p×p property. These characteristics are verified in Lemmas 4.1, 4.2, and 4.3, respectively. 

References [1] W. W. R. Ball and H. S. M. Coxeter, Mathematical Recreations and Essays, thirteenth edition, Dover Publications, New York, 1987. [2] J. Lorch, Linear magic rectangles, Linear Multilinear Algebra 62 no. 4 (2014), 530-537. [3] J. Lorch, Magic squares and , Amer. Math. Monthly, 119 (2012), 759-770. [4] J. Lorch, Pandiagonal type-p Franklin squares, preprint. [5] S. de la Loub`ere, A New Historical Relation of the Kingdom of Siam, Printed by F.L. for Tho. Horne, London, 1693. [6] E. McClintock, On the most perfect forms of magic squares, with methods for their production, Amer. J. Math. 19 (1897), 99-120. [7] R. Nordgren, On Franklin and complete magic square matrices, Fibonacci Quart. 54 no. 4 (2016), 304-318. [8] Ollerenshaw and Bree, Most Perfect Pandiagonal Squares, Institute of Mathematics and its Applications, 1998. [9] P. Pasles, The lost squares of Dr. Franklin: Ben Franklin’s missing squares and the secret of the magic circle, Amer. Math. Monthly 108 (2001), 489-511. [10] C. Planck, Pandiagonal magic squares of order 6 and 10 with minimal numbers, The Monist 29 (1919), 307-316. [11] D. Schindel, M. Rempel, and P. Loly, Enumerating the bent diagonal squares of Dr FRS, Proc. R. Soc. A 462 (2006), 2271-2279.

Department of Mathematical Sciences, Ball State University, Muncie, IN 47306-0490 E-mail address: [email protected]