Learn R Programming

magic (version 1.3-20)

as.standard: Standard form for magic squares

Description

Transforms a magic square or magic hypercube into Fr'{e}nicle's standard form

Usage

as.standard(a)
is.standard(a)

Arguments

a
Magic square or hypercube (array) to be tested or transformed

Details

For a square, as.standard() transforms a magic square into Fr'{e}nicle'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. Firstly, 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. is.standard() returns TRUE if the magic square or hypercube is in standard form. is.standard() and as.standard() check for neither magicness nor normality (use is.magic and is.normal for this).

See Also

magic, eq

Examples

Run this code
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,])

Run the code above in your browser using DataLab