BASIC CONSTRUCTION CONCEPTS

Construction of the order-4 pan-magic squares has been described in various ways. A method of construction of these squares that can be extended to higher dimensions is discussed below. It is similar to that of Grogono except for the concept of base lines. Many of the concepts discussed using the squares may seem trivial. Many are, when applied to the square, but they become important when applied to higher order figures. It is far easier to show many of the concepts using the squares. A concept can often be described in more than one way. In some cases more than one description for the same concept is given. Hopefully, the different points of view are useful.

Base lines

The basis for construction is the concept of base lines. For the purposes of this discussion a base line for the magic square is a 4-bit code containing equal numbers of 0's and 1's. There are only three 4-bit codes starting with 0, that have equal numbers of 0's and 1's, 0101, 0011, and 0110. There are also three codes starting with 1 but these will be ignored for now.

Rather than type out 0101, etc. every time one of the base lines is described, a shorthand description has been adopted. The 0101 base line is designated A0. Note that it is just 01 followed by a repetition of 01. The other two base lines start with 00 and 01. The second half of these two base lines is derived by a bit code inversion of the first half. In other words the second half is made by changing zero's and one's in the first half to one's and zero's in the second. These are the B base lines and are designated B0 and B1 based on the first two bits of the code converted from binary to base ten.

Square base line Cube base line Symbol
binarydecimalbinarydecimal
010150101010185A0
001130011001151B0
0110601100110102B1
--0000111115C0
--0001111030C1
--0010110145C2
--0011110060C3
--0100101175C4
--0101101090C5
--01101001105C6
--01111000120C7

The shorthand description for base lines can easily be generalized to higher dimensions as shown in the table at right. The letters A, B, C, etc. represent the bit length of a unit of the base line. This bit length is 2 for A, 4 for B, 8 for C, etc., increasing by powers of 2. The number represents the bit code to be placed in the first half of the unit. The other half of the unit is just the inverse of the first half. The unit is repeated until the base line is filled. For the cube the base line is eight bits long. The cube's B1 unit starts with 01 for the first half. This is followed by 10, the inverse of 01. The resulting 4-bit unit is then repeated to make the B1 base line 01100110. The C2 unit starts with 0010 the 4-bit representation of 2. A C base line is eight bits long and the second half of the C2 unit is 1101. Since the cubes base lines are only eight bits long, the 00101101 unit is not repeated. The C2 unit would be repeated for a 16-bit tesseract's base line.

Weaving base lines

Pairs of base lines can be combined to make base squares. For purposes of this discussion a base square is a magic square consisting of just 0's and 1's. Base squares can be generated using an exclusive OR combination of two base lines, one base line for the row and one for the column. For square I below the base lines are 0110 for the row and 0101 for the column. The exclusive OR function results in a zero when two ones or two zeros are combined and it results in a 1 when a zero and a one are combined. The second bit of 0110 is a one in the x direction and the fourth bit of 0101 is also a 1, but in the y direction. When combined using the exclusive OR function, the number at their juncture in square I at the fourth row from the top and second column from the left is a zero as seen below. Since the first digit of all the base lines is zero and an exclusive OR of the zero with either a 0 or 1 yields the 0 or 1, the base lines for all four squares below are also the top row and left column of the respective squares.

The resulting base squares have the appearance of simple woven cloth, especially when viewed as repeating units in all directions. For square I below the row base lines are the warp threads and the column base lines the weft threads. To make the square use four white strings for the warp. The first and last strings are down and the middle two up. Slide a black string through the middle and push it to the top (this is upside down for most looms). Reverse the up/down positions of the warp threads and add the next black string. Push next to the first black string. Reverse and add the third string and reverse and add once more to make the square. The resulting cloth appears the same as square I below where black represents 0's and white 1's.

Base square magic constant

I
0110
1001
0110
1001
II
0011
1100
0011
1100
III
0101
1010
1010
0101
IV
0101
0101
1010
1010

The base squares must have all of the addition properties desired in the final square, i.e. all rows, columns, diagonals, etc. add to the magic constant. The magic constant is just 2 for these base squares. To meet this requirement the base square must have an equal number of 0's and 1's in all the desired groups of four. It is relatively easy to generate order-4 squares having these properties, but there are only four unique squares with a zero in the upper left corner and these are shown at right. The other four order-4 pan-magic base squares can be made from the first four by translations. The latter four have ones in the upper left corner. Assignment of the zero to the upper left corner is traditional although somewhat arbitrary. The zero must go somewhere in the square, however, and assignment to the upper left simplifies construction. The four squares are designated I, II, III, and IV at right. All four of these can be generated by exclusive OR combinations of two base lines. The combinations are B1A0 for square I, B0A0 for II, A0B1 for III, and A0B0 for IV where the first base line is the row code and the second the column.

Proof of base square magic constant

Not all exclusive OR combinations of two base lines will give base squares that add up to 2 in all the desired ways. The above four squares are the only possible squares with a 0, or origin, in the upper left corner that add to 2 in all the desired ways. They all contain the A0 base line in one direction and one of the B base lines in the other. If two A0's are combined the diagonals do not add up properly. Combinations of two B base lines also give erroneous base squares. The reason for this is simple. If two A0 base lines are combined and their intersection at a point in the square is the exclusive OR combination of two 0's, then all adjacent diagonal points are the exclusive OR combination of two 1's. The next position along the diagonal will again be an exclusive OR combination of two 0's. The diagonals will therefore be all 0's. If on the other hand the position is the exclusive OR combination of a 0 and a 1 then the next diagonal position will be an exclusive OR combination of a 1 and a 0 resulting in diagonals of all 1's. The combination of two B0's, two B1's, or a B0 with a B1 will give the same result for some diagonals. For a combination of an A0 base line with one of the B base lines, for any position of the square, the position located a (2,2) vector away will always be its inverse. These two points will always be on a diagonal. Therefore for any two adjacent points on a diagonal the other two points on the diagonal will be their inverse resulting in two 0's and two 1's on that diagonal. This is because the last two bits of the B base lines are the inverse of the first two bits and the last two bits of the A0 base line are the same as the first two bits.

Base square combinations

There are two rules that are essential for combining base squares. These rules also apply to higher dimensional figures as well.

  1. If two base squares, with all the appropriate addition properties, are added together the resulting square will also have the correct addition properties. For the order-4 square case, the added squares will add to four in all the appropriate ways but there will be an uneven distribution of numbers, 4 zeros, 8 ones, and 4 twos in the resulting intermediate square. This is true for any two order-4 base squares, even the same two.
  2. If a base square has all of the appropriate addition properties, then a multiple of that square will also have those properties. In this case the resulting square will consist of an equal number of zeros and the multiple.

From these rules it is apparent that if one base square is multiplied by two and a second is added without multiplication, the result will have the correct addition properties. In the order-4 square case, using two different base squares will always result in uniform integral distribution, i.e. there will be 4 zeros, 4 ones, 4 twos, and 4 threes in the resulting intermediate square. The uniform integral distribution happens to be true for any pair of the order-4 base squares combined by multiplying one by 2 and adding the second, provided the base squares are different. Uniform integral distribution is not guaranteed for all pair combinations of higher dimensional base figures. Combinations that do not yield uniform integral distribution, will not yield valid magic figures. They will, however, add to the correct sum in all directions.

One can envisage adding a third base square in two ways. A third base square can be multiplied by four and added to the first two giving numbers from zero to seven. Alternatively the two base square combination can be doubled and a third base square added. Both approaches are used in the cube generator. For the order-4 square case, for either approach after addition there will be two of each integer, 0-7, or uniform integral distribution. Again this is always true for the order-4 squares, when three different base squares are used, but not for higher dimensions. The fourth order-4 base square is added in a similar manner making a magic square with all the numbers from 0 to 15.

Base line description of magic squares

I x 2
0220
2002
0220
2002
+
II x 1
0011
1100
0011
1100
+
III x 8
0808
8080
8080
0808
+
IV x 4
0404
0404
4040
4040
=
Magic Square
014313
11586
122151
79410

As discussed above the four base squares can be combined to make magic squares by multiplying one square by 8, another square by 4, a third square by 2, and the fourth by 1. The four multiplied squares are then added together to make a magic square as in the example at right. The multipliers may be placed in any order making 24 visually different squares with a zero at the origin or upper left corner. The base line description of the square at right would be A0B1, A0B0, B1A0, B0A0. The first part of each pair is the base line for the row and the second, the base line for the column. The base line pairs are ordered from highest to lowest power of two multiplier, i.e. x8, x4, x2, and x1.

Bit Codes by Position
0000111000111101
1011010110000110
1100001011110001
0111100101001010

Bit code by position magic square construction

The square can also be constructed by combining the individual bits of the four base squares by position. The base squares are first arranged in the order of decreasing power of 2 multiplier. After rearrangement, the lower left corners of base squares III, IV, I, and II respectively are 0, 1, 1, and 1. The binary number in the lower left corner of the bit codes by position array at right is therefore 0111 for the magic square constructed above. This is just the binary equivalent of 7 in base ten. This corresponds to the 7 in the lower left corner of the magic square above. The other 4-bit codes at right can also be converted from base two to the corresponding base ten numbers in the magic square above.

Multiplier shuffling

Rearranging the multipliers into the 24 possible arrangements rearranges the codes in the bit code by position array correspondingly. For example the first bit of each code might be exchanged with the third bit to make a new base square. This would be the same as multiplying the Square I by 8 and square III by 2 without changing squares II and IV. No matter what the arrangement of the multipliers all 16 of the possible 4-bit code arrangements will be present somewhere in the resulting array. This means that all 24 arrangements will contain all numbers from 0 to 15. Since the addition of base squares and/or multiplied base squares always results in a valid magic square, all 24 of the possible magic squares are indeed pan-magic squares. This concept is the basis for the unique cube, unique tesseract, etc. discussed later.

Master weaving

Because of the way the square is generated the other numbers in the square can be determined from an exclusive OR combination of the first row and first column. To do this the zero must be the first number in the row and the column. These are the master base lines of the square. For the cube above the third number in the top row is 3 and the fourth number in the first column is 7. These are 0011 and 0111 in binary as can also be seen in the bit codes by position table above. The exclusive OR combination of the bit pairs at each position is 0100 or 4 in base ten. The number at the juncture of the third column and fourth row is 4. This property is true for higher dimensional figures of the type described here as well. It is not true of all perfect magic cubes, i.e. those similar to Barnard's or those with different orders.

To weave with the numbers in the master base lines or magic lines consider each number to be a bundle of four strings representing the four bit binary equivalent of the number read left to right for the warp and from top down for the weft. In the warp bundles some strings are initially down, the 0's, and some are initially up, the 1's. There are four bundles of four white strings in the warp. A space or different colored strings could be used to separate the bundles. In the weft will be added four bundles of four black strings representing the master base lines in the other direction. When the weft string being added represents a 0 the warp threads will be as described above prior to its addition. When the weft string represents a 1 the warp strings will be reversed and the weft string added. Each added weft string is pushed to the top prior to warp reversal of the addition of the next string. The resulting weave will be a 4x4 square of 16 4x4 patterns of strings. The diagonal of each of these smaller 4x4 string patterns from left top to right bottom will be the binary equivalent of the number at that position of the magic square.

Translated a (2,3) vector
86115
151122
41079
313014
Translated a (1,1) vector
10794
130143
61158
112215

Translations

The pan-magic squares are still magic when the rows and/or columns are moved from one side to the opposite side. This is often described as a wrap around property. It can also be called a translation. Most magic squares do not have this property. There are16 different positions in the square for any of the values resulting in 16 visually different magic squares. Since there are 24 visually different squares with a zero at the upper left corner, there are 24 x 16 = 384 visually different magic squares with zero's at all possible positions. Two examples of translations of the above magic square are shown at right. Translations are visually different and are sometimes considered to be different squares. Translations of squares and higher figures will be considered to be the same here since the ability to carry out translations is an inherent property of the pan-magic squares. The generators do, however, allow translations to be done.

Rotations

Rotated 90° clockwise
712110
92514
41583
101613
Translated a (1,0) vector
071211
14925
34158
131016

If the square is rotated 90° clockwise, the resulting square has a visually different appearance as seen at right. When the zero of this rotated square is translated back to the upper left corner, one of the other 24 possible pan-magic squares with a zero at the upper left corner is generated, as seen at the far right. In this case the base lines for the new magic square will be B0A0, B1A0, A0B1, A0B0. Compare this to the original magic square values of A0B1, A0B0, B1A0, B0A0. For a 90° rotation in either direction the order of the base lines in each pair will reverse. For a clockwise rotation if the second member of the pair is initially a B0 it will be a B1 after rotation and vice versa. The A0's are unchanged. For a counterclockwise rotation the first member of the pair will undergo the change. Rotating another 90° clockwise gives the base lines A0B0, A0B1, B0A0, B1A0 and a third rotation gives B1A0, B0A0, A0B0, A0B1. These four squares are visually different, however, they are clearly the same square.

Inversions (Reflections)

Inverted through center x axis
79410
122151
11586
014313
Translated a (0,1) vector
014313
79410
122151
11586

The square can also be inverted through either the center vertical or horizontal axis. This is frequently referred to as reflection to indicate the the resulting figure is a mirror image of the starting figure. As with rotation the zero can then be translated back to the upper left corner as shown at right. Reflecting through either axis reverses the order of the numbers in the square. Note that in the original magic square that the corners of the square are 0, 11, 6, and 13 in a clockwise direction. After the inversion this order of numbers goes in a counterclockwise direction. The reflected squares are visually different but they are considered to be the same square. The reflected squares can be rotated into four positions giving the four base line sets, A0B0, A0B1, B1A0, B0A0; B1A0, B0A0, A0B1, A0B0; A0B1, A0B0, B0A0, B1A0; and B0A0, B1A0, A0B0, A0B1. In the vernacular of magic square aficionados rotations and reflections create different aspects of the square. The different aspects are considered to be the same square. The 384 visually different magic squares, that can be made using different base line arrangements and translations, are actually only three distinct order-4 pan-magic squares.

Row and Column Exchanges

Exchanging rows or columns that are spaced two apart in the order-4 pan-magic squares generates a different order-4 pan-magic square. All such exchanges are possible and multiple exchanges can be done in any order. In this type of exchange the A0 base lines remain unchanged. The B0 base lines becomes a B1 base line and vice versa. The exchange also exchanges the numbers in the associated master base lines.

A double exchange is also possible. If rows or columns 1 and 2 are exchanged in concert with rows or columns 3 and 4 it gives a different magic square. In this case it is the same square that would be created by exchanging rows or columns spaced 2 apart. For this type of exchange the A0 base lines become A1 base lines and the B type base lines are unchanged. Translation of the zero back to the upper left corner after all exchanges will confirm their equality.

Traditional magic square

Traditional pan-magic square
115414
12697
133162
810511

A square generated by the above approach uses the numbers from 0 to 15. To make the more traditional magic square using the numbers from 1 to 16 simply add 1 to all the values in the square. In general the range from 0 to 15 (or 0 to 511 for the cube, etc.) are easier to use for the manipulations carried out in the cube generator. Addition of one to make the traditional magic figure is done last and superficially. The above pan-magic square is converted to a traditional magic square at right.

Base lines starting with one

The above magic squares will always be generated with the origin at the upper left corner because the base lines all start with zero. The zero can be moved to any other position without changing the properties of the square by wrapping columns or rows around to the opposite side. If the base lines were required to start at the upper left corner, then translating the zero to a different position would change the base lines describing the square. Some of the new base lines would start with 1's in order to allow a number other than zero on the upper left corner. The base line A1, 1010, can replace A0, B3 can replace B0, and B2 replace B1for these translations. Use of these additional codes can be confusing, however, as some combinations are redundant. For instance the combination A0B0 is the same as A1B3. It is easier to work with just the codes starting with 0 and describe translations as a vector relative to a zero in the upper left corner.