| pmax | R Documentation |
Parallel (pairwise) maxima and minima for sprays.
maxpair_spray(S1, S2)
minpair_spray(S1, S2)
## S3 method for class 'spray'
pmax(x, ...)
## S3 method for class 'spray'
pmin(x, ...)
x, S1, S2 |
Spray objects |
... |
spray objects to be compared |
Function maxpair_spray() finds the pairwise maximum for two
sprays. Specifically, if S3 <- maxpair_spray(S1, S2), then
S3[v] == max(S1[v],S2[v]) for every index vector v.
Function pmax.spray() is the method for the generic
pmax(), which takes any number of arguments. If S3 <-
maxpair_spray(S1, S2, ...), then S3[v] == max(S1[v], S2[v], ...) for
every index vector v.
Function pmax.spray() operates right-associatively:
pmax(S1, S2, S3, S4) == f(S1, f(S2, f(S3, S4))) where f() is
short for maxpair_spray(). So if performance is important, put
the smallest spray (in terms of number of nonzero entries) last.
In these functions, a scalar is interpreted as a sort of global maximum.
Thus if S3 <- pmax(S,x) we have S3[v] == max(S[v], x) for
every index v. Observe that this operation is not defined if
x>0, for then there would be an infinity of v for which
S3[v] != 0, an impossibility (or at least counter to the
principles of a sparse array). The frab package discussses
this issue in vignette inst/wittgenstein.Rmd. Note also that
x cannot have length >1 as the elements of a spray
object are stored in an arbitrary order, following disordR
discipline.
Functions minpair_spray() and pmin.spray() are analogous.
Note that minpair_spray(S1, S2) is algebraically equivalent to
-pmax_spray(-S1, -S2); see the examples.
The value of pmax(S) is problematic. Suppose
all(coeffs(S) < 0); the current implementation returns
pmax(S) == S but there is a case for returning the null polynomial.
Returns a spray object
Robin K. S. Hankin
S1 <- rspray(100, vals=sample(100)-50)
S2 <- rspray(100, vals=sample(100)-50)
S3 <- rspray(100, vals=sample(100)-50)
# following comparisons should all be TRUE:
jj <- pmax(S1, S2, S3)
jj == maxpair_spray(S1, maxpair_spray(S2, S3))
jj == maxpair_spray(maxpair_spray(S1, S2), S3)
pmax(S1, S2, S3) == -pmin(-S1, -S2, -S3)
pmin(S1, S2, S3) == -pmax(-S1, -S2, -S3)
pmax(S1, -Inf) == S1
pmin(S1, Inf) == S2
pmax(S1, -3)
## Not run:
pmax(S1, 3) # not defined
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.