# pmax

##### Parallel maxima and minima for sprays

Parallel (pairwise) maxima and minima for sprays.

##### Usage

```
maxpair_spray(S1,S2)
minpair_spray(S1,S2)
# S3 method for spray
pmax(x, ...)
# S3 method for spray
pmin(x, ...)
```

##### Arguments

- x,S1,S2
Spray objects

- …
spray objects to be compared

##### Details

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). Note also that `x`

cannot have
length `>1`

as the elements of a spray object are stored in an
arbitrary order.

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(value(S)<0)`

; the current implementation returns
`pmax(S)==S`

but there is a case for returning the null polynomial.

##### Value

Returns a spray object

##### Examples

```
# NOT RUN {
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
# }
# NOT RUN {
# }
```

*Documentation reproduced from package spray, version 1.0-7, License: GPL (>= 2)*