is.magic {magic} | R Documentation |
Returns TRUE
if the square is magic, semimagic, panmagic, associative,
normal. If argument give.answers
is TRUE
, also returns
additional information about the sums.
is.magic(m, give.answers = FALSE, FUN=sum, boolean=FALSE) is.panmagic(m, give.answers = FALSE, FUN=sum, boolean=FALSE) is.pandiagonal(m, give.answers = FALSE, FUN=sum, boolean=FALSE) is.semimagic(m, give.answers = FALSE, FUN=sum, boolean=FALSE) is.semimagic.default(m) is.associative(m) is.normal(m) is.sparse(m) is.mostperfect(m,give.answers=FALSE) is.2x2.correct(m,give.answers=FALSE) is.bree.correct(m,give.answers=FALSE) is.latin(m,give.answers=FALSE) is.antimagic(m, give.answers = FALSE, FUN=sum) is.totally.antimagic(m, give.answers = FALSE, FUN=sum) is.sam(m) is.stam(m)
m |
The square to be tested |
give.answers |
Boolean, with TRUE meaning return additional
information about the sums (see details) |
FUN |
A function that is evaluated for each row, column, and unbroken diagonal |
boolean |
Boolean, with TRUE meaning that the square is
deemed magic, semimagic, etc, if all applications of FUN
evaluate to TRUE . If boolean is FALSE , square
m is magic etc if all applications of FUN are
identical |
is.2x2.correct()
and
the second by is.bree.correct()
.
All most-perfect squares are panmagic.
is.square.palindromic()
. The definition extends to magic
hypercubes: a hypercube a
is associative if a+arev(a)
is constant.
is.latin()
is a wrapper
for is.latinhypercube()
because there is no natural way to
present the extra information given when give.answers
is
TRUE
in a manner consistent with the other functions
documented here.
SAM
.
Returns TRUE
if the square is semimagic, etc. and FALSE
if not.
If give.answers
is taken as an argument and is TRUE
,
return a list of at least five elements. The first element of the
list is the answer: it is TRUE
if the square is (semimagic,
magic, panmagic) and FALSE
otherwise. Elements 2-5 give the
result of a call to allsums()
, viz: rowwise and columnwise
sums; and broken major (ie NW-SE) and minor (ie NE-SW) diagonal sums.
Function is.bree.correct()
also returns the sums of
elements distant n/2 along a major diagonal
(diag.sums
); and function is.2x2.correct()
returns the
sum of each 2x2 submatrix (tbt.sums
); for
other size windows use subsums()
directly.
Function is.mostperfect()
returns both of these.
Function is.semimagic.default()
returns TRUE
if the
argument is semimagic [with respect to sum()
] using a faster
method than is.semimagic()
.
Functions that take a FUN
argument apply that function to each
row, column, and diagonal as necessary. If FUN
takes its
default value of sum()
, the sum will be returned; if
prod()
, the product will be returned, and so on. There are
many choices for this argument that produce interesting tests;
consider FUN=max
, for example. With this, a “magic”
square is one whose row, sum and (leading) diagonals have identical
maxima. Thus diag(5)
is magic with respect to max()
,
but diag(6)
isn't.
Function is.magic()
is vectorized; if a list is supplied, the
defaults are assumed.
Robin K. S. Hankin
http://mathworld.wolfram.com/MagicSquare.html
minmax
,is.perfect
,is.semimagichypercube
is.magic(magic(4)) is.magic(diag(9),FUN=max) #should be TRUE stopifnot(is.magic(magic(3:8))) is.panmagic(panmagic.4()) is.panmagic(panmagic.8()) data(Ollerenshaw) is.mostperfect(Ollerenshaw) proper.magic <- function(m){is.magic(m) & is.normal(m)} proper.magic(magic(20))