Skip to contents

Allows arithmetic operators to be used for spray calculations, such as addition, multiplication, division, integer powers, etc. Objects of class spray are interpreted as sparse multivariate polynomials.

Usage

# S3 method for class 'spray'
Ops(e1, e2 = NULL)
spray_negative(S)
spray_times_spray(S1,S2)
spray_times_scalar(S,x)
spray_plus_spray(S1,S2)
spray_plus_scalar(S,x)
spray_power_scalar(S,n)
spray_power_scalar_stla(S,n)
spray_eq_spray(S1,S2)
spray_eq_numeric(S1,x)

Arguments

e1,e2,S,S1,S2

Objects of class spray, here interpreted as sparse multivariate polynomials

x

Real valued scalar

n

Non-negative integer

Details

The function Ops.spray() passes unary and binary arithmetic operators (“+”, “-”, “*”, “/”,“==”, and “^”) to the appropriate specialist function.

The most interesting operators are “*” and “+” which execute multivariate polynomial multiplication and addition respectively.

Testing for equality uses spray_eq_spray(). Note that spray_eq_spray(S1,S2) is algebraically equivalent to is.zero(S1-S2), but faster (FALSE is returned as soon as a mismatch is found).

Function spray_power_scalar() is the functional representation for powers: spray_power_scalar(X,n) is the same as X^n. Function spray_power_scalar_stla() is an experimental replacement for spray_power_scalar() that may offer speed advantages.

Value

The functions all return spray objects except “==”, which returns a logical.

Author

Robin K. S. Hankin

See also

Examples



M <- matrix(sample(0:3,21,replace=TRUE),ncol=3)
a <- spray(M,sample(7))
b <- homog(3,4)


# arithmetic operators mostly work as expected:
a + 2*b
#>            val
#>  1 2 1  =    2
#>  0 2 2  =    2
#>  1 1 2  =    2
#>  1 0 3  =    2
#>  0 3 1  =    2
#>  0 0 4  =    2
#>  2 2 2  =    6
#>  1 0 0  =    3
#>  2 0 2  =    2
#>  0 4 0  =    2
#>  4 0 0  =    2
#>  3 0 1  =    2
#>  1 3 0  =    2
#>  3 2 1  =    1
#>  2 2 0  =    2
#>  3 1 0  =    2
#>  0 1 3  =    2
#>  1 1 3  =    4
#>  0 0 0  =    7
#>  2 1 1  =    7
#>  3 3 3  =    2
a - a*b^2/4
#>                  val
#>   5  4  4  =   -8.00
#>   3  8  1  =   -2.50
#>   8  2  3  =   -2.00
#>   3  4  2  =   -6.75
#>   3  3  7  =   -9.00
#>   6  4  2  =  -10.00
#>   9  1  2  =   -2.50
#>   7  2  4  =   -4.00
#>   7  3  3  =   -3.00
#>   3  4  7  =   -9.75
#>   2  4  6  =   -5.00
#>   5  3  6  =  -13.50
#>   4  2  7  =   -8.00
#>   1  1 11  =   -1.00
#>   7  4  1  =   -5.00
#>   3 10  4  =   -1.00
#>   7  0  1  =   -3.50
#>   4  4  6  =  -15.00
#>   5  1  7  =   -5.00
#>   4  8  2  =   -5.50
#>   3  2  9  =   -3.25
#>   8  2  4  =   -5.50
#>   0  8  0  =   -1.75
#>   2  0  6  =   -5.25
#>   4  0  5  =   -3.00
#>   5  4  3  =  -12.50
#>   4  7  6  =   -4.00
#>   2  6  0  =   -5.25
#>   1  7  5  =   -3.00
#>   4  1  4  =   -6.00
#>   3  3  2  =  -17.50
#>   2  7  4  =   -4.00
#>   4  2  3  =   -7.50
#>   6  1  5  =   -6.25
#>   5  3  9  =   -1.50
#>   4  2  6  =   -7.50
#>   4  6  4  =  -15.50
#>   2  4  7  =   -8.00
#>   6  1  6  =   -4.00
#>   2  5  5  =   -6.25
#>   3  5  9  =   -1.50
#>   2  9  1  =   -1.25
#>   6  3  4  =   -6.00
#>   7  1  5  =   -3.00
#>   2  2  8  =   -2.50
#>   5  1  2  =  -10.50
#>   4  5  0  =   -3.00
#>   2  7  0  =   -1.50
#>   2  1  9  =   -1.25
#>   5  3  1  =   -6.00
#>   1  8  0  =   -0.75
#>   7  6  4  =   -4.00
#>   7  2  0  =   -2.25
#>   8  1  3  =   -3.75
#>  11  2  1  =   -0.25
#>   6  0  2  =   -5.25
#>   5  5  4  =  -17.50
#>   6  3  8  =   -2.00
#>   2  2  4  =  -15.75
#>   2  6  6  =   -7.50
#>   2  7  3  =   -3.75
#>   2  8  4  =   -4.50
#>   6  4  3  =   -4.00
#>   2  3  7  =   -3.75
#>   1  2  6  =   -2.25
#>   3  6  3  =   -7.50
#>   2  2  5  =   -4.50
#>   0  3  5  =   -7.00
#>   1  1  3  =    4.00
#>   5  1  6  =   -5.00
#>   1  3  9  =   -3.00
#>   2  5  2  =   -4.50
#>   3  1  4  =  -14.00
#>   3  7  3  =   -3.00
#>   2  5  1  =  -10.50
#>   1  6  1  =   -7.00
#>   2  2  2  =    6.00
#>   3  7  2  =   -5.00
#>   0  6  2  =   -5.25
#>   2  9  3  =   -3.00
#>   4  3  6  =  -10.00
#>   2  5  7  =   -6.00
#>   5  3  0  =   -7.00
#>   1  4  8  =   -4.00
#>   5  7  2  =   -7.50
#>   1  7  0  =   -3.50
#>   7  1  4  =   -5.00
#>   4  7  3  =  -10.50
#>   6  6  5  =   -5.00
#>   2  1  6  =   -3.00
#>   3  5  6  =  -13.00
#>   9  4  1  =   -0.75
#>   7  4  3  =  -11.25
#>   6  2  5  =   -6.00
#>   4  3  5  =  -11.25
#>   1  1  7  =   -1.50
#>   9  3  5  =   -1.50
#>   7  3  7  =   -2.50
#>   4  5  8  =   -3.00
#>   3  3  6  =   -7.50
#>   5  7  5  =   -4.50
#>   3  4  6  =  -10.00
#>   4  2  8  =   -5.00
#>   3  2  4  =   -6.75
#>   4  4  9  =   -2.00
#>   2  6  4  =   -5.00
#>   3  6  8  =   -2.00
#>   2  2 10  =   -1.50
#>   2 10  2  =   -1.50
#>   3  3 11  =   -0.50
#>   5  5  2  =  -10.00
#>   7  5  2  =   -8.00
#>   7  1  0  =   -3.50
#>   6  5  1  =   -6.25
#>   6  1  1  =   -7.00
#>   2  3  9  =   -3.00
#>   2  7  5  =   -6.00
#>   3  3  3  =   -5.50
#>   5  8  1  =   -0.75
#>   5  3  5  =   -9.00
#>   5  2  2  =   -6.75
#>   4  1  8  =   -4.00
#>   1  8  4  =   -2.00
#>   6  1  2  =   -4.50
#>   1  0  8  =   -0.75
#>   3  7  4  =  -10.00
#>   4  2  2  =  -15.75
#>   8  6  3  =   -2.00
#>   9  5  3  =   -1.50
#>   5  4  5  =  -17.25
#>   4  1  3  =  -14.00
#>   5  2  5  =  -10.00
#>   6  4  7  =   -4.00
#>   0  0  8  =   -1.75
#>  10  3  4  =   -1.00
#>   3  7  7  =   -2.50
#>   8  2  2  =   -5.00
#>   6  6  2  =   -9.50
#>   6  2  0  =   -5.25
#>   3  9  2  =   -3.50
#>   3 11  3  =   -0.50
#>  11  3  3  =   -0.50
#>   7  3  4  =  -11.00
#>  10  1  1  =   -1.25
#>   5  4  8  =   -3.00
#>   2  5  6  =   -8.00
#>   1  5  7  =   -5.00
#>   2  1 10  =   -2.00
#>   5  0  4  =   -3.75
#>   4  3  7  =  -10.00
#>   3  1  8  =   -2.50
#>   7  7  3  =   -2.50
#>   6  3  0  =   -3.00
#>   1  7  1  =   -1.50
#>   6  0  3  =   -3.00
#>   4  8  5  =   -3.00
#>   8  0  0  =   -1.75
#>   3  1  9  =   -3.00
#>   8  4  2  =   -6.00
#>   3  4  1  =  -14.00
#>   3  3  8  =   -6.50
#>   1  3  5  =   -3.00
#>   5  2  6  =   -8.00
#>   4  5  5  =  -17.00
#>   1  3  4  =  -14.00
#>   4  9  1  =   -0.50
#>   2  3  3  =  -17.50
#>   2  1  1  =    5.00
#>   3  6  0  =   -2.25
#>   2  6  1  =   -3.00
#>   8  1  4  =   -2.00
#>   7  6  1  =   -1.25
#>   6  2  6  =   -8.50
#>   2  1  5  =  -10.50
#>   1  1  6  =   -7.00
#>   3  5  5  =   -9.00
#>   4  3 10  =   -1.00
#>   7  3  2  =   -7.50
#>   4  9  4  =   -2.00
#>   5  2  7  =   -6.75
#>   4  1  7  =   -3.75
#>   0  4  4  =   -8.75
#>   9  2  3  =   -3.75
#>   0  7  1  =   -3.50
#>   5  3  4  =  -12.50
#>   4  6  7  =   -4.00
#>   3  0  5  =   -7.00
#>   0  0  0  =    7.00
#>   4  4  1  =   -6.00
#>   8  4  5  =   -3.00
#>   1  0  0  =    3.00
#>   7  2  3  =   -7.50
#>   9  2  1  =   -2.50
#>   2  3  4  =   -6.00
#>   5  6  6  =   -5.00
#>   4  5  4  =   -8.00
#>   3  2  1  =    1.00
#>   6  2  1  =   -4.50
#>   4  3  1  =  -14.00
#>   4  7  1  =   -3.75
#>   6  7  4  =   -4.00
#>   5  2  1  =  -10.50
#>   2  3  8  =   -6.00
#>   6  7  1  =   -1.00
#>   4  4  0  =   -8.75
#>   5  6  1  =   -5.00
#>   2  4  2  =  -15.75
#>   3  5  1  =   -4.50
#>   4  3  2  =   -7.50
#>   1  5  2  =  -10.50
#>   6  2  4  =  -10.00
#>   5  0  3  =   -7.00
#>   5  5  7  =   -4.50
#>   3  2  3  =  -17.50
#>   7  2  5  =   -7.25
#>   1  6  2  =   -2.25
#>   6  3  5  =  -14.00
#>  10  2  2  =   -2.00
#>   8  0  1  =   -1.50
#>   4 10  3  =   -1.00
#>   4  4  5  =  -10.00
#>   3  6  4  =   -6.00
#>   1  2  5  =  -10.50
#>   9  3  2  =   -4.00
#>   3  4  5  =  -10.00
#>   6  5  3  =  -14.50
#>   1  4  3  =  -14.00
#>   0  2  6  =   -5.25
#>  10  3  1  =   -0.50
#>   1  0  7  =   -3.50
#>   3  2  8  =   -6.00
#>   8  3  1  =   -3.75
#>  10  4  3  =   -1.00
#>   5  1  3  =   -6.00
#>   2  6  5  =   -6.00
#>   3  5  4  =  -10.00
#>   3  1  5  =   -4.50
#>   3 10  1  =   -0.25
#>   3  8  6  =   -2.00
#>   3  8  3  =   -6.75
#>   6  3  3  =  -11.25
#>   1  6  6  =   -4.00
#>   1  2 10  =   -2.00
#>   3  2  7  =   -5.00
#>   2  2  9  =   -4.00
#>   5  5  3  =   -5.00
#>   8  5  1  =   -1.00
#>   3  0  6  =   -2.25
#>   8  1  0  =   -1.50
#>   8  5  4  =   -3.00
#>   1  9  3  =   -1.00
#>   8  3  3  =   -7.50
#>   8  3  6  =   -2.00
#>   7  5  5  =   -4.50
#>   7  1  1  =   -3.00
#>   3  9  5  =   -1.50
#>   7  0  2  =   -2.25
#>   4  6  2  =   -7.50
#>   5  4  0  =   -3.75
#>   9  1  3  =   -1.00
#>   0  5  3  =   -7.00
#>   4  6  3  =   -4.00
#>   2  4  8  =   -4.50
#>   2  8  2  =   -2.50
#>   0  1  7  =   -3.50
#>   1  5  3  =   -3.00
#>   5  8  4  =   -3.00
#>   6  5  6  =   -5.00
#>   1  4  4  =   -3.75
#>   2  4  3  =   -6.00
#>   4  5  3  =  -11.25
#>   5  6  3  =  -14.25
#>   6  8  3  =   -2.00
#>   5  9  3  =   -1.50
#>   3  4 10  =   -1.00
#>   6  4  4  =  -16.00
#>   2  8  3  =   -2.00
#>   3  6  5  =  -13.25
#>   4  4  4  =  -12.50
#>   4  0  4  =   -8.75
#>   2  0  7  =   -1.50
#>   9  4  4  =   -2.00
#>   7  4  6  =   -4.00
#>   9  0  0  =   -0.75
#>   3  5  0  =   -7.00
a+b
#>            val
#>  3 1 0  =    1
#>  2 2 0  =    1
#>  1 2 1  =    1
#>  0 2 2  =    1
#>  1 3 0  =    1
#>  0 0 4  =    1
#>  2 2 2  =    6
#>  1 0 0  =    3
#>  1 1 2  =    1
#>  1 0 3  =    1
#>  0 3 1  =    1
#>  2 0 2  =    1
#>  0 4 0  =    1
#>  4 0 0  =    1
#>  3 0 1  =    1
#>  3 2 1  =    1
#>  1 1 3  =    4
#>  0 0 0  =    7
#>  0 1 3  =    1
#>  2 1 1  =    6
#>  3 3 3  =    2

S1 <- spray(partitions::compositions(4,3))
S2 <- spray(diag(3))  # S2 = x+y+z


stopifnot( (S1+S2)^3 == S1^3 + 3*S1^2*S2 + 3*S1*S2^2 + S2^3 )