Learn R Programming

spray (version 1.0-16)

zero: The zero polynomial

Description

Test for the zero, or empty, polynomial

Usage

zero(d)
is.zero(L)
is.empty(L)

Arguments

L

A two-element list of indices and values, possibly a spray object

d

Integer specifying dimensionality of the spray (the arity)

Details

Functions is.empty() and is.zero() are synonyms. If spray objects are interpreted as multivariate polynomials, “is.zero()” is more intuitive, if sprays are interpreted as sparse arrays, “is.empty()” is better (for me).

If spray() is passed a zero-row index matrix, the return value does not remember the dimensionality of the input:

> dput(spray(matrix(0,1,5),0))
structure(list(index = NULL, value = NULL), class = "spray")

Arguably, the output should include the fact that we are dealing with a 5-dimensional array; but the index matrix is NULL so this information is lost (note that the value is NULL too). However, observe that the following works:

> a1 <- spray(matrix(0,1,5),0)
> a2 <- spray(t(1:5))
> a1+a2
               val
 1 2 3 4 5  =    1
 >

Examples

Run this code
# NOT RUN {
a <- lone(1,3)

is.zero(a-a)  # should be TRUE

is.zero(zero(6))

x <- spray(t(0:1))
y <- spray(t(1:0))

is.zero((x+y)*(x-y)-(x^2-y^2)) # TRUE





# }

Run the code above in your browser using DataLab