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.