Standard form for magic squares
Transforms a magic square or magic hypercube into Frenicle's standard form
as.standard(a, toroidal = FALSE, one_minus=FALSE) is.standard(a, toroidal = FALSE, one_minus=FALSE)
a |
Magic square or hypercube (array) to be tested or transformed |
toroidal |
Boolean, with default |
one_minus |
Boolean, with |
For a square, as.standard()
transforms a magic square into
Frenicle's standard form. The four numbers at each of
the four corners are determined. First, the square is rotated so the
smallest of the four is at the upper left. Then, element [1,2]
is compared with element[2,1]
and, if it is larger, the transpose
is taken.
Thus all eight rotated and transposed versions of a magic square have the same standard form.
The square returned by magic()
is in standard form.
For hypercubes, the algorithm is generalized. First, the hypercube is
reflected so that a[1,1,...,1,1]
is the smallest of the 2^d
corner elements (eg a[1,n,1,...,1,1]
).
Next, aperm()
is called so that
a[1,1,...,1,2] < a[1,1,...,2,1] < ... < a[2,1,...,1,1]
.
Note that the inequalities are strict as hypercubes are assumed to be
normal. As of version 1.3-1, as.standard()
will accept arrays of
any dimension (ie arrays a
with minmax(dim(a))==FALSE
will
be handled sensibly).
An array with any dimension of extent zero is in standard form by definition; dimensions of length one are dropped.
If argument toroidal
is TRUE
, then the array a
is
translated using ashift()
so that a[1,1,...,1] == min(a)
.
Such translations preserve the properties of semimagicness and
pandiagonalness (but not magicness or associativity).
It is easier (for me at least) to visualise this by considering
two-dimensional arrays, tiling the plane with copies of a
.
Next, the array is shifted so that a[2,1,1,...,1] <
a[dim(a)[1],1,1,...,1]
and a[1,2,1,..,1] <
a[1,dim(a)[2],1,...,1]
and so on.
Then aperm()
is called as per the non-toroidal case above.
There does not appear to be a way to make the third letter of “Frenicle” have an acute accent, as it should do.
Robin K. S. Hankin
is.standard(magic.2np1(4)) as.standard(magic.4n(3)) as.standard(magichypercube.4n(1,5)) ##non-square arrays: as.standard(magic(7)[1:3,]) ## Toroidal transforms preserve pandiagonalness: is.pandiagonal(as.standard(hudson(11))) ## but not magicness: is.magic(as.standard(magic(10),TRUE))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.