To answer this question, we must look closely at affine functions on F_{2}^{4}, and particularly at their linear parts. We need some notation; we shall let (f_{0}, f_{1},f_{2}, f_{3}) be the dual basis to (e_{0}, e_{1}, e_{2}, e_{3}), so that f_{i}(e_{j}) 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 e_{0} or e_{1} in order to get the magic property for columns; it must be nonzero on either e_{2} or e_{3} in order to get the magic property for rows; and it must be nonzero on either e_{0} + e_{2} or e_{1} + e_{3} in order to get the magic property on diagonals. There are six linear functions that are eligible:
L_{1}=f_{1}+f_{2}; | L_{2}=f_{0}+f_{2}+f_{3}; | L_{3}=f_{0}+f_{1}+f_{3}; |
L_{4}=f_{1}+f_{2}+f_{3}; | L_{5}=f_{0}+f_{3}; | L_{6}=f_{0}+f_{1}+f_{2}. |
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 F_{2}. A relation among three functions, A + B + C = 0, is equivalent to A + B = C . There are two such relations:
L_{1} + L_{2} + L_{3} = 0;
L_{4} + L_{5} + L_{6} = 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.
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.
The positions of complementary numbers in an affine magic square are related to the geometry of F_{2}^{4}. In F_{2}^{4}, 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 F_{2}^{4},
If L is the linear part of the content mapping of the square, and q is a vector in F_{2}^{4} 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 | |||||
L_{1} | L_{2} | L_{4} | L_{5} | (1,1,0,0) | VI | ||
L_{1} | L_{2} | L_{4} | L_{6} | (0,0,1,0) | V | ||
L_{1} | L_{2} | L_{5} | L_{6} | (0,1,0,1) | II | ||
L_{1} | L_{3} | L_{4} | L_{5} | (1,0,1,0) | I | ||
L_{1} | L_{3} | L_{4} | L_{6} | (0,1,0,0) | IV | ||
L_{1} | L_{3} | L_{5} | L_{6} | (0,0,1,1) | VI | ||
L_{2} | L_{3} | L_{4} | L_{5} | (0,0,0,1) | IV | ||
L_{2} | L_{3} | L_{4} | L_{6} | (1,1,1,1) | III | ||
L_{2} | L_{3} | L_{5} | L_{6} | (1,0,0,0) | V |
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 F_{2}^{4}. But they are not very far from being all parallel: in each type, there are two families of four parallel lines.
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 F_{2}^{4}. 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.
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 F_{2}^{4}. 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.
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.
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.
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.
In this section and the next, we are concerned with geometrical structures in F_{2}^{4}.
3.1. Definition. An affine quad is a quad which is identified with a 2-flat of F_{2}^{4}, 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 F_{2}^{4}.
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 v_{1} and v_{2}. Let v_{3} 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 v_{1}, v_{2}, and v_{3}.
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, Q_{1}, Q_{2}, Q_{3}}. By Proposition 3.3, the union of Q with Q_{i} 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 p_{0} be a point in the intersection of Q and R, and let v_{1} be the vector from p_{0} to the other point in that intersection. Let v_{2} be the vector from p_{0} to another point that is in Q but not in R, and let v_{3} be the vector from p_{0} to another point that is in R but not in Q. Then Q and R are contained in the hyperplane through p_{0} parallel to the linear subspace generated by v_{1}, v_{2}, and v_{3}.
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.
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 H_{i}. These three hyperplanes must be distinct; for if H_{i} = H_{j} 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 H_{i}. 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}.
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, ..., 2^{4 - λ} - 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(2^{4-λ} - 1).
Proof. The average of all the numbers in a part-normal square of level λ is (2^{4-λ} - 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 2^{6 - λ}, 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.
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 L_{1}, ..., L_{6} 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.
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 F_{p}^{2m}. 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 F_{p}^{2m} 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 (v_{1}, ..., v_{d}) of values p^{r-d} times.
Proof. Let A_{1}, ..., A_{d} be an set of d components of A. Let L_{1}, ..., L_{d} be their linear parts; by hypothesis, they are linearly independent on E. Therefore, the linear map sending a vector u of E into (L_{1}u, ..., L_{d} u) maps E onto F_{p}^{d}, so it has a null space of dimension r-d. Thus every vector in F_{p}^{d} 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 (A_{1}u, ..., A_{d} u).
3. Proposition. Let E be a vector subspace of F_{p}^{2m}, 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 A_{1}, ..., A_{2m}. Then the value at the position corresponding to x is
p^{2m-1}A_{1} (x) + ... + A_{2m}(x).
The d-th power of this sum is a linear combination of terms of the form
A_{i1} (x)...A_{id}(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 F_{p}^{2m} 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.
What is a magic cube? Certainly a (normal) magic cube of order N will be an arrangement of the numbers 1, ..., N^{3} 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.)
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 p^{m} corresponds to a vector space F_{p}^{3m}. 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.
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 Z_{n}, which stands for "the integers modulo n". In Z_{n} 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 Z_{n}^{2} by u = (x,y). The generalization of "content coordinates" is
The "affine map" will be nonsingular if and only if
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
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 A_{1} does not take each value equally often, then
κ must be chosen so that on the center square
A_{1} takes the value
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 Z_{n}^{2}, which I will call (-R, C) and (-r, c), such that
They also choose an arbitrary starting point, which I will call (x,y), such that
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 A_{1}(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 A_{2}(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
α: | β: | κ: | ||||
γ: | δ: | λ: | ||||
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 n^{d}, where the square is identified with Z_{n}^{2d} . The technicalities would be more difficult. Z_{n} is in general a ring, not a field; and Z_{n}^{2d} is in general a module, not a vector space.
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 p^{m}. 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.
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.