# Affine Magic Squares, Continued

## How Many Affine Magic Squares of Order 4 Exist?

To answer this question, we must look closely at affine functions on F24, and particularly at their linear parts. We need some notation; we shall let (f0, f1,f2, f3) be the dual basis to (e0, e1, e2, e3), so that fi(ej) is 1 if i=j and 0 otherwise. We know from the definition of an affine magic square that we need four linear functions which are independent, and are non-zero on certain subspaces. Specifically, each one must be nonzero on either e0 or e1 in order to get the magic property for columns; it must be nonzero on either e2 or e3 in order to get the magic property for rows; and it must be nonzero on either e0 + e2 or e1 + e3 in order to get the magic property on diagonals. There are six linear functions that are eligible:

 L1=f1+f2; L2=f0+f2+f3; L3=f0+f1+f3; L4=f1+f2+f3; L5=f0+f3; L6=f0+f1+f2.

To construct an affine magic square, we must select a set of four functions which do not satisfy any linear relation. Among the six eligible functions, there are not many linear relations. A relation between two functions would be of the form A = B, because we are calculating over F2. A relation among three functions, A + B + C = 0, is equivalent to A + B = C . There are two such relations:

L1 + L2 + L3 = 0;

L4 + L5 + L6 = 0.

A relation among four functions is of the form A + B = C + D. But it turns out that a nonzero function which is not among the eligible ones can be expressed as a sum of two eligible functions in only one way; so, there are no four-term relations among the eligible functions.

From 6 eligible functions, a set of 4 can be selected in 15 ways. Each of the three-term relations excludes 3 of those sets. There remain 9 linearly independent sets of eligible linear functions. Now a set of linear functions determines 16 sets of four affine functions, because each affine function can have a constant part of either 0 or 1. So there are 144 possible sets of four affine functions. For each of these, there are 4! = 24 possible arrangements. Therefore the total number of affine magic squares of order 4 is 144 ×24 = 3456. If we take the 8 geometrical symmetries of the square into account, the number of distinct affine magic squares is 3456 ÷8 = 432.

See below for more on the number of affine magic squares of other orders.

## A Complete Census of 4×4 Magic Squares, and a Classification

Bernard Frénicle de Bessey made a complete enumeration of the magic squares of order 4, in the seventeenth century. In 1976, Benson and Jacoby checked his work using a computer. A further detailed study, with analysis and proofs, was made by Ollerenshaw and Bondi. There are 880 different magic squares of order 4. Of these, 48 are pandiagonal,. and 384 are semi-pandiagonal. So there are 48 + 384 = 432 algebraic magic squares.

Now every affine magic square must be algebraic. Therefore the affine magic squares coincide with the algebraic magic squares. This is a nice result, but a proof that depends on enumeration of 432 cases is not nice. A better proof is given below.

From Frénicle on down, students of magic squares of order 4 have classified them according to the relative positions of complementary numbers in the square. If the numbers range from 1 to 16, then "complementary" numbers are a pair whose sum is 17. If the numbers in the square start with 0, then complementary numbers are a pair whose sum is 15. Twelve patterns are found; see, for instance, Andrews, Chap. VIII, Benson and Jacoby, Chap. 18, or Ollerenshaw and Bondi, Appendix 2. The patterns are reproduced here, as Figure 1.

Figure 1. The basic types of magic squares of order 4.

The positions of complementary numbers in an affine magic square are related to the geometry of F24. In F24, any two points together constitute a 1-flat, or more simply a line. In a nonsingular affine square, the pairs of complementary numbers are situated on parallel lines. to see this, we define the vector c = (1,1,1,1), and note that for any two vectors u and v in F24,

v = u + c if and only if C(u) + C(v) = 15.

If L is the linear part of the content mapping of the square, and q is a vector in F24 such that Lq = c, then two cells in the square have complementary values if and only if they are the images, under the position map, of vectors which differ by q. In other words, each complementary pair is the image of a line parallel to {0, q}.

The equation Lq = c = (1,1,1,1) does not depend on the order of the linear parts of the comtent functions, but only on the set of eligible linear functions. It is not hard to check that the 9 independent sets of eligible functions determine the vectors q as in the following table. The third column gives the type, as in figure 1.

 Linear parts q Class L1 L2 L4 L5 (1,1,0,0) VI L1 L2 L4 L6 (0,0,1,0) V L1 L2 L5 L6 (0,1,0,1) II L1 L3 L4 L5 (1,0,1,0) I L1 L3 L4 L6 (0,1,0,0) IV L1 L3 L5 L6 (0,0,1,1) VI L2 L3 L4 L5 (0,0,0,1) IV L2 L3 L4 L6 (1,1,1,1) III L2 L3 L5 L6 (1,0,0,0) V
Table 1. Digit functions and basic types of magic squares of order 4

A reflection around the diagonal of the square corresponds to switching the first and second halves of the position vector. The vectors (1,0,1,0), (0,1,0,1), and (1,1,1,1) are unchanged by this transformation, so their patterns of parallel lines are also unchanged. Each of these patterns contributes one type of magic square (I, II, and III respectively); as remarked before, the number of distinct squares generated by each of these patterns is 24 × 16 ÷ 8 = 48. The other possible values of q are interchanged by that transformation, so each type is contributed to by two values, and the number of quasi-pandiagonal squares in each of these types (IV, V, and VI) is (2 × 24 × 16) ÷ 8 = 96.

There are other squares of type VI that are not affine. There are also the remaining types, which obviously cannot be affine because the complementary pairs are not all parallel in F24. But they are not very far from being all parallel: in each type, there are two families of four parallel lines.

## All Algebraic Magic Squares are Affine

The proof is based on finding constraints on the distribution of odd and even numbers in an algebraic magic square. To describe these constraints, we study the geometry of the positions in the square, identified with the points in F24. We show that if we replace each even number by 0 and each odd number by 1, the result must be an affine function. This proves that the (1) bit position of the square is affine. Also, there are two 0's and two 1's on every row, column, diagonal, or short broken diagonal. Thus if we subtract the parity bits we get a square with uniform sums on the rows, columns, and diagonals; the numbers in it are all even. If we divide them all be 2, we get another square with uniform sums, and the parity bits in this square are in the (2) bit positions of the original square. But this square is not magic in the usual sense, because the numbers in it are repeated. We find we need to have planned ahead, and made sure that the analysis of the parity bits works for squares of this new type.

My technique owes much to Ollerenshaw and Bondi -- a reference which I will abbreviate as OB. As far as I know, the statement and proof are original.

### 1. Introduction

In this section, mostly from OB, all squares, magic or not, are of order 4. We use this notation for the cells of a square:

 a b c d e f g h i k l m n o p q

We identify the positions in this square with the points in F24. The numbers assigned to those positions will be called values.

1.1. Definition. The magic sum of a square is one fourth of the sum of the values assigned to the points.

1.2. Definition. A quad is a set of four points in the square. A quadset is a set of four quads, no two of which overlap.

1.3. Definition. A magic quad is one whose values add up to the magic sum, and a magic quadset is one consisting of four magic quads.

1.4. Definition. A magic square is one in which the rows, columns, and diagonals are magic quads.

1.5. Definition. A partition of a quad is a division of the quad into two pairs of points.

### 2. Properties of a magic square

This section is also largely from OB.

2.1. Definition. The Frénicle quadset of a square is the quadset {{a,d,n,q}, {b,c,o,p}, {e,h,i,m}, {f,g,k,l}}.

2.2. Proposition. In a magic square, the Frénicle quadset is magic.

Proof. Let S be the magic sum of the square. We add the first and fourth rows and the two diagonals, to get 2a + b + c + 2d + f + g +k + l + 2n + o + p + 2q = 4S. From this we subtract the second and third columns, to get 2a + 2d + 2n + 2q = 2S. Thus the first quad of the Frénicle quadset is magic. By adding the first and fourth rows, and subtracting the first Frénicle quad, we get (a + b + c + d) + (n + o + p + q) - (a + d + n + q) = S + S - S, which is to say that b + c + o + p = S; thus the second Frénicle quad is magic. Likewise, from the first and fourth columns, and the first Frénicle quad, we find that the third Frénicle quad is magic. Finally, we subtract the second Frénile quad from the sum of the second and third columns to get the fourth Frénicle quad.

2.3. Definition. The corner quadset of a square is {{a,b,e,f}, {c,d,g,h}, {i,k,n,o}, {l,m,p,q}}. The extended corner quadset of a square is {{a,c,i,l}, {b,d,k,m}, {e,g,n,p}, {f,h,o,q}}.

2.4. Definition. The diagonal quadset of a square is {{a,f,l,q}, {b,e,m,o}, {c,h,i,o}, {d,g,k,n}}. Thus it contains the diagonals and the short broken diagonals.

2.5. Proposition. In a magic square, the following conditions are equivalent:
(a) one corner quad is magic;
(b) the corner quadset is magic;
(c) one of the short broken diagonals is magic;
(d) the diagonal quadset is magic;
(e) one extended corner quad is magic;
(f) the extended corner quadset is magic.

Proof. Let S be the magic sum of the square. Suppose the first corner quad satisfies a + b + e + f = S + ε. Subtracting this from the sum of the first two rows, we get c + d + g + h = S - ε. Similarly with the first two columns we get i + k + n + o = S - ε, and therefore l + m + p + q = S + ε. Clearly, if one corner quad is magic then they all are; that is, (a) and (b) are equivalent.

We treat the extended corner quads in the same way. Supposing that a + c + i + l = S + δ, we find that b + d + k + m = S - δ, and similarly e + g + n + p = S - δ. From either of the latter equations we get f + h + o + g = S + δ. We find therefore that (e) and (f) are equivalent.

From two opposite corner quads and the main diagonal, we find (a + b + e + f) + (l + m + p + q) - (a + f + l + q) = 2(S + ε) - S, that is, b + e + m + p = S + 2ε. Similarly, c + h + i + o = S - 2ε. This relates the short broken diagonals to the corner quads.

But we can also relate the broken diagonals to the extended corner quads. In fact, (a + c + i + l) + (f + h + o + q) - (a + f + l + q) = 2(S + δ) - S, that is, c + h + i + o = S + 2δ. We see that ε = - δ. The corner quads, the extended corner quads, and the short broken diagonals are all related so that if one of them is magic, so are all the rest.

2.6. Definition. An algebraic magic square is a magic square that satisfies the conditions (a)-(f) of Proposition 2.5.

### 3. Introducing the affine structure

In this section and the next, we are concerned with geometrical structures in F24.

3.1. Definition. An affine quad is a quad which is identified with a 2-flat of F24, and an affine quadset is a set of four affine quads corresponding to parallel flats.

Note that the row, column, and diagonal quadsets are affine. So are the Frénicle, corner, and extended corner quadsets.

3.2. Definition A hyperplane is a 3-flat in F24.

Recall that a line is a 1-flat, or simply a pair of points.

3.3. Proposition. Two parallel affine quads together make up a hyperplane.

Proof. Let the parallel quads be Q and R. They are parallel to a linear subspace, generated by two vectors v1 and v2. Let v3 be a vector from a point in Q to one in R. Then the union of Q and R is parallel to the linear subspace generated by v1, v2, and v3.

3.4. Proposition. An affine quad is contained in exactly three hyperplanes.

Proof. An affine quad Q is a member of an affine quadset, {Q, Q1, Q2, Q3}. By Proposition 3.3, the union of Q with Qi is a hyperplane. Conversely, it is easily seen that every hyperplane containing Q is of this form.

3.5. Definition. Two affine quads are connected if they intersect in a line (that is, in two points).

3.6. Proposition. If two affine quads are connected, then they are contained in a hyperplane.

Proof. Let the two affine quads be Q and R. Let p0 be a point in the intersection of Q and R, and let v1 be the vector from p0 to the other point in that intersection. Let v2 be the vector from p0 to another point that is in Q but not in R, and let v3 be the vector from p0 to another point that is in R but not in Q. Then Q and R are contained in the hyperplane through p0 parallel to the linear subspace generated by v1, v2, and v3.

3.7. Proposition. If two distinct affine quads are contained in a hyperplane, then they are either parallel or connected.

Proof. Let Q and R be the two quads on the statement of the proposition. As in Proposition 3.3, the points that are in the hyperplane but not in Q form an affine quad Q′ parallel to Q. Now three points determine an affine quad; therefore, if the affine quad R is distinct from both Q and Q′, then it must have at least exactly two points in common with each.

3.8. Definition. Two affine quadsets Σ and Σ′ are connected if one quad belonging to Σ is connected with one quad belonging to Σ′.

3.9. Proposition. If two affine quadsets Σ and Σ′ are connected, then every quad belonging to Σ is connected with two quads belonging to Σ′.

Proof. Let Q be a quad belonging to Σ, and let Q′ be a quad belonging to Σ′ and connected with Q. Let v be a vector which connects a point in the intersection of Q and Q′ with another point that is in Q but not in Q′. Then Q′ + v is an affine quad, parallel to Q′ and so belonging to Σ′, that is connected with Q. Thus Q is connected with two quads belonging to Σ′.

Now, let R be another quad belonging to Σ, and let w be a vector connecting a point in Q to a point in R.. Then Q′ + w is a quad belonging to Σ′ and connected to R. Thus every quad belonging to Σ is connected to a quad belonging to Σ′, and by the argument of the preceding paragraph it must be connected to two of them.

Note that the Frénicle, corner, and extended corner quadsets are each connected to the row, column, and diagonal quadsets.

3.10. Definition. A partition of an affine quad Q and a partition of an affine quad R overlap if the two quads are connected and the intersection of the two quads is a pair belonging to both partitions.

3.11. Definition. Two affine quadsets Σ and Σ′ are transversal if every quad belonging to Σ intersects every quad belonging to Σ′ in exactly one point.

Note that the row, column, and diagonal quadsets are all transversal to one another. Likewise, the Frénicle, corner, and extended corner quadsets are all transversal to one another.

### 4. Linking partitions in an affine quadset

All quadsets mentioned in this section are affine.

4.1. Definition. A quadset Σ′ is linked by three quadsets Σ1, Σ2, and Σ3 if the latter three are transversal to one another and are connected to Σ′.

The Frénicle quadset is linked by the row, column, and diagonal quadsets. This example, which is implicit in OB, will be important in the proof that algebraic squares are affine.

4.2. Proposition. Let the quadset Σ′ be linked by the quadsets Σ1, Σ2, and Σ3 . Then for every pair of quads Q and R in Σ′, there is a quad in one of the quadsets Σi which is connected with Q and R.

(Remark: This proposition, and its proof, are easier to understand if one considers an example. The quadsets Σi can be the row, column, and diagonal quadsets, while Σ′ is the Frénicle quadset.)

Proof. By Proposition 3.9, Q is connected to two quads belonging to Σi; by Proposition 3.3, these parallel quads form a hyperplane Hi. These three hyperplanes must be distinct; for if Hi = Hj where i ≠ j , then the hyperplanes belonging to Σi would be connected with those belonging to Σj, whereas by hypothesis these two quadsets are transversal. But, by Proposition 3.4, there are only three hyperplanes containing Q; so the hyperplane containing Q and R must be one of the Hi. It then follows that Q and R are connected with quads in Σi.

4.3. Proposition. Let the quadset Σ′ be linked by the quadsets Σ1, Σ2, and Σ3, and let Q be a quad belonging to Σ′. Then every partition of Q overlaps with partitions in two quads which belong to one, and only one, of the quadsets Σ1, Σ2, and Σ3.

Proof. There are three partitions of Q. Proposition 3.9 implies that each quadset Σi contains two quads which are connected to Q, and these determine a partition in Q which overlaps with partitions in the latter two quads. The quadsets Σi must determine different partitions, otherwise they would not be transversal to one another. Therefore each partition in Q corresponds to one of the quadsets Σi.

4.4. Definition. Let the quadset Σ′ be linked by the quadsets Σ1, Σ2, and Σ3, and let Q and R be quads belonging to Σ′; then a partition in Q is linked by Σ1, Σ2, and Σ3 with a partition in R if these two partitions both overlap with partitions belonging to one of the quadsets Σi.

### 5. Normal and part-normal squares

So far, we have made no assumption about whether the values assigned to points in the square are consecutive, or whether they are allowed to repeat. There is a reason for this—in order to prove the theorem about "normal" magic squares we shall have to know things about magic squares where the numbers do repeat.

5.1. Definition. A square is part-normal of level λ, where λ is 0, 1, 2, or 3, if the values assigned to points in the square are 0, ..., 24 - λ - 1, each one repeated 2λ times. A square is normal if it is part-normal of level 0.

5.2. Proposition. In a magic square which is part-normal of level λ, the magic sum is S = 2(24-λ - 1).

Proof. The average of all the numbers in a part-normal square of level λ is (24-λ - 1)/2. Four times this must be the magic sum.

5.3. Proposition. In a part-normal magic square, a magic quad must contain an even number of points to which odd values are assigned.

Proof. This follows immediately from the fact that the magic sum S is even.

5.4. Proposition. In a part-normal magic square, the points of two magic quads that do not intersect cannot all be assigned values of the same parity.

Proof. If the points of the two quads all had odd values, they would include all the odd numbers in the square. But it is easily checked that the odd values in a part-normal square of level λ add up to 26 - λ, which is not 2S. Likewise, the sum of all the even values is not 2S.

5.5. Definition. A balanced quad is one in which two points have odd values and two have even values.

5.6. Proposition. A magic quadset in a part-normal magic square must have either two or four balanced quads.

Proof. From Proposition 5.2, the number of odd values in a magic quad must be 0, 2, or 4. The number of odd values in the square is a multiple of 4, so the number of balanced quads in the quadset must be even; it cannot be 0, because then two quads would have to contain all odd elements, contrary to Proposition 5.4.

5.7. Proposition. In a part-normal algebraic magic square, let the affine magic quadset Σ′ be linked by the affine magic quadsets Σ1, Σ2, and Σ3. Then all the quads in Σ′ are balanced.

Proof. Consider the partitions of a magic quad. Because the sum of values in the quad is even, the sums of the values in one part of a partition has the same parity as that of the other part, so we may say that the partition itself is even or odd. If the quad is balanced, then two of the partitions are odd and one is even. If the values in the quad are all of the same parity, then all three partitions are even.

Our task is to rule out the possibility that two of the quads of Σ′ have all even partitions. But consider the fact that when partitions in two quads of Σ′ are linked (Definition 4.4), they must have the same parity. Moreover, by Proposition 4.5, every partition in every quad is linked with a unique partition in another quad. Now suppose that two of the quads of Σ′ had all even partitions. Then the other two quads would be forced to have at least two even partitions apiece, which is ruled out by Proposition 5.6.

5.8. Proposition. In a part-normal algebraic magic square, the row, column, diagonal, Frénicle, corner, and extended corner quadsets all consist of balanced quads.

Proof. The row, column, and diagonal quadsets are magic by hypothesis, and are mutually transversal. They link each of the Frénicle, corner, and extended corner quadsets. Therefore, by Proposition 5.7, the Frénicle, corner, and extended corner quadsets consist of balanced quads.

But the Frénicle, corner, and extended corner quadsets are also magic; see Proposition 2.2, Definition 2.6, and Theorem 2.5. Moreover, they link each of the row, column, and diagonal quadsets. Therefore, by another application of Proposition 5.7, the latter quadsets contain all balanced quads.

### 6. Completion of the proof

Theorem. Every part-normal algebraic magic square of order 4 is affine.

Outline of proof. We first look at the pattern of the parities of the numbers in the magic square. The results we have proved are sufficient to imply many constraints on this pattern, and we show that these constraints require the parities to be given by an affine function. If the square is of level 3, then we are done. Otherwise, we subtract the parity bits from the square, and show that the resulting square, consisting of even numbers, is still magic and algebraic. We then divide by 2, to give a part-normal square of one level higher. Thus the proof is completed by downward mathematical induction.

Details. The row, column, diagonal, Frénicle, corner, and extended corner quadsets all consist of balanced quads, by Proposition 5.8. Let us consider what this implies for the square of 0's and 1's that denote the parity of the numbers in the square.

Without loss of generality we may assume that the parity at position a is 0. Because the first row is balanced, there are three possibilities: 0011, 0101, and 0110.

Let us consider the case that the first row is 0011. Because the corner quads are balanced, the second row must be 1100. Now consider the third row, iklm; because the extended corner quads are balanced, i and l must have opposite values, and so must k and m. Moreover, because the Frénicle quad ehim is balanced, i and m must have opposite values. Thus there are two possibilites for the third row: 0011 and 1100. Whichever one is chosen, the other one is required for the fourth row. Thus there are two possible patterns:

 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0

and

 0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1

Each of these is affine.

The other two cases each lead to two patterns, all of which are affine. Thus we recover the linear functions L1, ..., L6 that were discussed in the section on counting affine magic squares.

We now know that the parity bits are given by an affine function, and are balanced on all six quadsets. If we subtract the parity bits from the values in the square, we get a square of even numbers that is still algebraic magic; the magic sum has been reduced by two. If we divide by two, we get an algebraic magic square that is part-normal of one higher level. By induction, the latter square is affine, that is, each bit position is given by an affine function. These, together with the parity bits of the original square, are all the bit positions of the original square, and so we are done.

## Bimagic and Trimagic Affine Magic Squares

A square is multimagic of degree d if it remains magic when the numbers in the square are replaced by their k-th powers, for k=2, ..., d. For small values of d the words "bimagic," "trimagic," etc. are used.

Is there a property of an affine map that will cause the associated affine square to be multimagic?

1. Definition. Let E be a vector subspace of Fp2m. Then an affine map A is uniform on E of degree d if, for every set of d components of A, their linear parts are linearly independent on E.

Note that "uniform of degree 1" is the same as "uniform" as this was defined on the page on affine magic squares. Also, it is clear that a map which is uniform of degree d on a certain subspace is also uniform of degree k, for k = 1, 2, ..., d-1.

2. Proposition. Let E be a vector subspace of Fp2m of dimension r, and let A be an affine map which is uniform of degree d on E. Then, on any flat parallel to E, any set of d components of A takes on each set (v1, ..., vd) of values pr-d times.

Proof. Let A1, ..., Ad be an set of d components of A. Let L1, ..., Ld be their linear parts; by hypothesis, they are linearly independent on E. Therefore, the linear map sending a vector u of E into (L1u, ..., Ld u) maps E onto Fpd, so it has a null space of dimension r-d. Thus every vector in Fpd is the image of an affine subspace of dimension r-d. But the same thing is true for the map of any flat parallel to E, taking a vector u into (A1u, ..., Ad u).

3. Proposition. Let E be a vector subspace of Fp2m, and let A be an affine map which is uniform of degree d on E. Then, in the affine square determined by A, the sum of the d-th powers of the values is the same on every flat parallel to E.

Proof. Let the components of A be A1, ..., A2m. Then the value at the position corresponding to x is

p2m-1A1 (x) + ... + A2m(x).

The d-th power of this sum is a linear combination of terms of the form

Ai1 (x)...Aid(x).

By Proposition 2, such a term takes the same values, each the same number of times, on every flat parallel to E. Therefore, its contribution to the sum of d-th powers is the same for each of those flats.

4. Proposition. Let A be an affine map which is uniform of degree d on the subspaces of Fp2m corresponding to rows, columns, and diagonals. Then the affine square determined by A is multimagic of order d.

Proof. This follows immediately from Proposition 3.

Several affine squares, that are multimagic in view of Proposition 4, have been independently discovered.

Derksen, Eggermont, and van den Essen have recently studied multimagic squares, and have defined a condition on an affine square identical to that of being uniform of degree d.

## Magic Cubes

What is a magic cube? Certainly a (normal) magic cube of order N will be an arrangement of the numbers 1, ..., N3 in a cubical array, such that many of the straight lines of N cells add up to a common value. Now there are many such straight lines; which of them shall we require?

I shall follow the terminology of Harvey Heinz's web site on magic cubes, with some additions from Benson and Jacoby. There are three classes of "orthogonals," that is, lines parallel to the sides of the cube; they are "rows," "columns," and "pillars." There are likewise six classes of "diagonals," which are the diagonals of plane cross-sections of the cube. Finally there are "triagonals," which connect opposite corners of the cube; these are called "full diagonals" by Benson and Jacoby.

A "simple magic cube" is one in which rows, columns, pillars, and triagonals all add to a common sum. A "diagonal magic cube" is one in which rows, columns, pillars, diagonals, and triagonals all add to a common sum. (Benson and Jacoby call this a "perfect magic cube," but Heinz uses that term differently.)

### Affine Magic Cubes

It is not hard to extend the theory of affine squares to a theory of affine cubes. A cube whose order is a prime power pm corresponds to a vector space Fp3m. Each class of orthogonals is a family of parallel flats of dimension m. The triagonals are also flats; if p = 2, then they are parallel, but if p > 2 then they intersect. Thus when p is odd, it is much easier to construct a "semi-affine" magic cube than a fully affine one.

Some of the magic cubes given in the published literature are in fact affine. For instance, one recently published by Zhu is affine, though this fact is not stated in the paper.

## Odd Orders, Not Necessarily Prime Powers

When the order of a square is any number n, it is easy to interpret the row and column coordinates of a cell as numbers in Zn, which stands for "the integers modulo n". In Zn we can add, subtract, and multiply; we cannot divide, unless the divisor is a number that has no common factors with n.

Represent a member of Zn2 by u = (x,y). The generalization of "content coordinates" is

A1(u) = αx+βy+κ ,
A2(u) = γx+δy+λ .

The "affine map" will be nonsingular if and only if αδ–βγ is non-zero and relatively prime to n.

We want each content coordinate to take every possible value exactly once on each row and on each column. This imposes the requirement that α, β, γ, and δ must each be non-zero and relatively prime to n.

For an affine magic square, each digit coordinate must take every possible value on each diagonal. This imposes the requirement that α+β, α–β, γ+δ, and γ–δ must each be non-zero and relatively prime to n. Then the square will be pan-diagonal, that is, all the broken diagonals are magic.

If the diagonal requirement is not satisfied, then the square will not be pan-diagonal. In this case, the values of κ and/or λ can be chosen to make a semi-affine magic square. If A1 does not take each value equally often, then κ must be chosen so that on the center square A1 takes the value (n–1)/2. A similar rule holds for A2.

This method of constructing magic squares of odd order is already known, and includes some old methods as special cases. Benson and Jacoby describe the method in Chapter 9, "A New Approach," of their book. Their description is differently formulated. In effect, they define two elements of Zn2, which I will call (-R, C) and (-r, c), such that

A1(u + (-R,C)) = A1(u),
A2(u + (-R,C)) = A2(u) + 1,
A1(u + (-r,c)) = A1(u) + 1,
A2(u + (-r,c)) = A2(u).

They also choose an arbitrary starting point, which I will call (x,y), such that

A1((x,y)) = 0, A2((x,y)) = 0.

In my description of their method, I put minus signs on the first component of the vectors because Benson and Jacoby count rows going up, whereas I count them going down. They add some generality to their value map. To the value of A1(u) they assign an upper-case letter; for instance, if n = 5, then they map (0→A, 1→B, ... 4→E). Similarly they assign a lower-case letter to the value of A2(u). With these letters, they fill in an "intermediate square." First, the pair [A+a] is placed in an arbitrary cell (x,y). The rest of the "A series," that is, [A+b], etc., is entered in the square; at each step they move to a position which is R rows up and C columns to the right. The "B series," series, beginning with [B+a], starts at a cell which, relative to [A+a], is r rows up and c columns to the right. The "C series" is similarly displaced relative to the "B series," and so on.

When the intermediate square is filled, they translate the letters to numbers. One series of letters, say (A, B,...), is assigned values from (0, n, 2n, ..., (n-1)n), in an arbitrary order. The other series of letters is assigned values from (1, ..., n), also in arbitrary order.

Here is an interactive demo which can be used to construct magic squares of odd order between 3 and 31 according to this method. (For simplicity's sake I assign number values to letters in increasing order.) The applet provides controls to choose the order n and the values of α, β, γ, δ, κ, and λ. For each coefficient of the digit coordinates, the choice of "indeterminate" is represented by a dash. Note that when some of α, β, γ, and δ have been chosen, the possible choices of the others in this list are restricted by the requirement that αδ–βγ must be non-zero and relatively prime to n. Next to the controls for κ and λ are buttons marked with an asterisk; each of these causes the respective value to be chosen so that the content coordinate takes the value (n–1)/2 in the central square. If the values chosen for coefficients of one of the two affine functions are such that this choice of the constant is necessary for a fully magic square, then they are highlighted in yellow. When you choose the asterisk, and the linear part of that content coordinate is fully determined, the κ or λ control moves to the appropriate value.

N:
 α: β: κ: γ: δ: λ: R: 000 C: 000 r: 000 c: 000 x: 000 y: 000

I think that the theory of affine magic squares could be further generalized to squares of order nd, where the square is identified with Zn2d . The technicalities would be more difficult. Zn is in general a ring, not a field; and Zn2d is in general a module, not a vector space.

## Counting Affine Magic Squares

Here is a "calculator" which displays the number of affine squares for a given prime-power order. As in other places there are menus to select the values of p and m, giving the order of the magic square as pm. To count affine magic squares, one begins by counting the bases, that is, the linearly independent sets of linear functions which are uniform for the desired subspaces. This problem has several subproblems: rows only; rows and columns; or rows, columns, and diagonals. When p is odd, there is a difference between requiring uniformity on the main diagonal alone, or on both diagonals.

For each class of bases, there is the number of affine spaces that can be formed. When p is odd, there is also the number of affine squares that are magic for both the main and the opposite diagonals, even though some of the digit coordinates are not uniform on one or both diagonals.

P:
M:

Are hyphens acceptable to break really long numbers at the ends of lines? I sure hope so.

The number of bases that are uniform on rows is 000.

The number of bases that are uniform on rows and columns is 000.

The number of bases that are uniform on rows, columns, and diagonals is 000. The number of magic squares that can be formed from these bases is 000; taking geometric symmetries into account, the number of distinct squares is 000.

The number of bases that are uniform on rows, columns, and the main diagonal is 000. The number of magic squares that can be formed from these bases is 000; taking geometric symmetries into account, the number of distinct squares is 000.

The number of bases that are uniform on rows, columns, and both diagonals is 000. The number of magic squares that can be formed from these bases is 000; taking geometric symmetries into account, the number of distinct squares is 000.

The number of affine magic squares is 000; taking geometric symmetries into account, the number of distinct squares is 000.

The theory behind these calculations is found in a technical paper.

Last modified on \$Date: 2015-06-08 09:53:30 -0400 (Mon, 08 Jun 2015) \$

Christopher J. Henrich