The Magic Encyclopedia ™

Panmagic squares of prime order
(by Aale de Winkel)

Discussions <Harvey Heinz> led me to reinvestigate panmagic squares of prime order.
Below a study is presented which derives all(?) panmagic squares (of prime order) with mere basic assumptions, it poses a way to parametrize those squares in a systematic manner. One of the ingredients is the "pan-flip transformation" which move the first row (column) below the last row (right to the column) and a reflection to move it back to the original position, this horizontal (vertical) flip is just one of the possible transformations possible in any panmagic square.

prime order panmagic squares
basic ingredients of panmagic squares
Latin square
generating formula
LS(a)
factor: m - 3
Latin squares obtained by formula
LS(a): Li,j = (a j + i) % m ; i,j ε [0,..,m-1]; a = 2 .. m - 2
"intermediate" or
most basic
panmagic squares
amount:
(m-4)(m-3)/2
S = m * LS(a) + LS(b) + 1; a < m/2; b != a
the a is limited to the first half of the range since using the other half merely
introduces a horizontal pan-flip variant (which we want to avoid), with b = a the
square becomes irregular (which we also don't want)
There are (m-3)/2 a's and (m-4) b's satisfying the conditions.
(m-4)(m-3)/2
5
7
11
13
1
6
28
45
most essential
panmagic squares
amount:
[(m-4)(m-3)/2](m-14)
S = m * LS(a)[p,q,r,s] + LS(b) + 1; a < m/2; b != a; p < {q,r,s}
The number p is located just right of the top left '0', q just below, r the last number
of the first column and s the last number of the firts row. The thus positioned numbers
regulate whether the square is in normalized position by imposing the conditions:
p < q (transposition)
p < s (horizontal pan flip)
q < r (vertical pan flip)
however once established that p < (q,r,s), the numbers q,r and s can be freely permuted
merely introducing squares which need a vertical pan flip to be put in normalized position
it's easily recognized the these squares are independent of the other squares, this fact
and the first two (q < r not considered of course) conditions above compensate the random
positioning of the 4 selected numbers [p,q,r,s] (ie 4!/(22/3!) the selection of these four
numbers (from m-1 possible numbers) can of course be done in (m-14) ways.
In the most essential square both sets (q,r,s) and the remaining (m-5) numbers are
put in their natural ordering by the here imposed definition.
[(m-4)(m-3)/2](m-14)
5
7
11
13
1
90
5,880
22,275
normalized positioned
panmagic squares
amount:
[(m-4)(m-3)/2](m-14)
3!(m-5)!(m-1)!
S = m * LS(a)[p,q,r,s]=P(q,r,s)=P([1..m-1]\{p,q,r,s}) + LS(b)=P((m-1)+1) + 1;
a < m/2; b != a; p < {q,r,s}
All panmagic squares now can be found by using digit changing permutations on both the
high and the low component latin squares. Note that the permutation denoted by
=P([1..m-1]\{p,q,r,s}) is a permutation on the remaining numbers
all three mentioned permutations are independent of one another introducing the mentioned
factors 3! (m-5)! and (m-1)! onto the total amount of panmagic squares obtainable from
described method, which (I believe) are all different by construction.
[(m-4)(m-3)/2](m-14)3!(m-5)!(m-1)!
5
7
11
13
144
777,600
92,177,326,080,000
2,581,228,494,028,800,000
panmagic squares
amount:
[(m-4)(m-3)/2](m-14)
3!(m-5)!(m-1)!m2 =
[(m-4)(m-3)/2](m!)2/4
S = [m * LS(a)[p,q,r,s]=P(q,r,s)=P([1..m-1]\{p,q,r,s}) + LS(b)=P((m-1)+1) + 1]@[x,y];
a < m/2; b != a; p < {q,r,s}; x,y ε [0..m-1]
Panrelocating the topleft corner '1' gives the total amount of panmagic squares
[(m-4)(m-3)/2](m-14)3!(m-5)!(m-1)!m2
5
7
11
13
3,600
38,102,400
11,153,456,455,680,000
436,227,615,490,867,000,000
panmagic squares
[(m-4)(m-3)/2](m!)2
S = [m * LS(a)=P(m) + LS(b)=P(m) + 1];a < m/2; b != a;
Allowing all digits to get changed on both components of course also gives all
panmagic squares, the factor 4 discrepancy between this number and the previous
is due to the fact that also reflectional variants are obtained by this method
Selfcomplementairy
panmagic squares
[(m-4)(m-3)/2]((m-1)!!)2/4
S = [m * LS(a)=P(a;m) + LS(b)=P(b;m) + 1];a < m/2; b != a;
with P(a;m) permutations such that P[(a+1)i] + P[(a+1)(m-1-i)] = m
In order for the complete square to fullfill the selfcomplementairy condition,
ie S[i,j] + S[m-1-i,m-1-j] = m2+1 it is neccessairy for each component to
be selfcomplementairy. A little figuring showed me that this is established with
digit changing permutations which is merely some permutation of a symmetric
permutation given exactly by the above stated condition. For a prime order m
the amount of symmetric permutations is given by (m-1)!!, the deviding factor
of 4 takes care of the reflectional variants the method introduces
[(m-4)(m-3)/2](m-1)!!/4
5
7
11
13
16
3,456
103,219,200
23,887,872,000



Recent discussions with <Günther Sterten> on the email forwarding service: http://groups.yahoo.com/group/magiccubes made me aware of none-linear permutations that satisfy the "square pandiagonality conditions" {P[i] + m +/-i; i = 0..m-1} ε {P[0..m-1]} (see below), these kind of permutation can be handle in a simular way as the mere linear permutations handled in the previous section. A search for these permutations revealed none in the order below m = 13, so this feature is present from order 13 on which augments the basic permutations used from mere 5 to 141, 174 if one allows reflected permutations with P[1] <= (m-1)/2, complementairy permutations {m-P[i]; i = 1..m-1} doubling this number to 348 (m = 13). The higher orders left for future estimation.

prime order panmagic squares
basic ingredients of panmagic squares
pandiagonal latin square
permutation generated
LS(P[0..m-1])
factor: Fm
currently known:
F13 = 348
Latin squares obtained using the natural permutatio on the x-axis
and a permutation on the y-axis satisfying the pandiagonal condition
LS(P[0..m-1]): Li,j = (P[j] + i) % m ; i,j ε [0,..,m-1]
{P[i] + m +/-i; i = 0..m-1} ε {P[0..m-1]}
let P[0..m-1] be a permutation of the numbers 0..m-1 and {P[0..m-1]} the set of
all these permutations (m! members), with Pm,0 (the natural permutation of
m digits is [0,1,...,m-1,m-1] on the x-axis, and some other permutation on the y-axis, in
order to obtain a pure latin square the diagonal and subdiagonal need to consitst of
permutations themselves, this results in the two conditions:
{P[i] + m +/-i; i = 0..m-1} ε {P[0..m-1]}
This ensures that the latin square:
LS(P[0..m-1]): Li,j = (P[j] + i) % m ; i,j ε [0,..,m-1]
is a {pandiagonal} latin square
Orthogonal pairing
factor Om
yet to be determinined
A pair of permutations {P1m,k,P2m,k} with P1[i] != P2[i]; i= 1..m-1
When the condition P1[i] != P2[i]; i= 1..m-1 is satisfied the resulting latin
squares are automatically orthogonal themselves, such that no double numbers
occur in the resulting square
these pairs are yet to be found, with the linear it was simple selecting an other
parameter, this new situation needs some further study;
The amount of orthogonal permutation is the set of permutations the satisfy the pandiagonality
conditon determine the amount of the "most basic" pandiagonal magic squares, another matter took
too much time to determine that number. The argumenttion further remains the same as in the
table above,some (near future (I hope)) upload more details will be given.


A furthr possibility exist from order 13 on, being latin squares with rows not in linear prograssion. These can't be handled with the method discussed above, and is left for future investigation.


A while back <Marián Trenkler> sent me an interesting paper "ADDITIVE AND MULTIPLICATIVE MAGIC CUBES" (submitted for publication) which showed that multiplicative squares (athough be it with a highly irregular number range)can easely be obtained from additive magic squares. Below the resulting panmagic multiplicative magic squares.

prime order panmagic multiplicative squares
panmagic multiplicative squares in relation to panmagic addititive squares
panmagic additive square S = [m * LS(a)=P(m) + LS(b)=P(m) + 1];a < m/2; b != a;
See derivation in previous table
panmagic multiplicative square P = [p1(LS(a)=P(m)) * p2(LS(b)=P(m))]; p1 != p2 (relatively prime)
given the fact that the panmagic additive squares of prime order (given by S) consists of
all the numbers in the range [1 .. n2] and the fact that all composite numbers
have a unique decomposition in primes ensures that all the numbers in P are unique numbers
albeit with many a gap.
magic product p = i=0m-1Pi,j = i=0m-1 [p1LS(a) * p2LS(b)] = [p1^(i=0m-1 LS(a)) * p2^(i=0m-1LS(b))] =
p1m(m-1)/2 p2m(m-1)/2 = (p1 p2) m(m-1)/2
Although the above is worked out in only 1 1-agonal direction the derivation hold on any
1-agonal and (broken) 2-agonal the crucial step is the fact that i=0m-1 LS(a)
on each line sums over all the digits [0 .. m-1] on any line, henche this sums to m(m-1)/2
Seen the construction of these squares the amount of square is the same of the amount of
additive magic squares for every chosen pair of relative primes p1 and p2,
below the magic products are calculated for the case p1 = 2 and p2 = 3
(2 * 3) m(m-1)/2
5
7
11
13
60.466.176
21.936.950.640.377.900
6.285.195.213.566 * 1030
4.963.608.617.944.920 * 1045

The above generalises of course trivially to the higher dimensioned hypercube the magic product for a n dimensional hypercube generalizes to i=1npim(m-1)/2 with all pi unequal primes (in principle relatively prime suffices)