Determine if an expression is positive, negative, or zero.
is_zero(object)
is_nonneg(object)
is_nonpos(object)
An Expression object.
A logical value.
pos <- Constant(1)
neg <- Constant(-1)
zero <- Constant(0)
unknown <- Variable()
is_zero(pos)
#> [1] FALSE
is_zero(-zero)
#> [1] TRUE
is_zero(unknown)
#> [1] FALSE
is_zero(pos + neg)
#> [1] FALSE
is_nonneg(pos + zero)
#> [1] TRUE
is_nonneg(pos * neg)
#> [1] FALSE
is_nonneg(pos - neg)
#> [1] TRUE
is_nonneg(unknown)
#> [1] FALSE
is_nonpos(-pos)
#> [1] TRUE
is_nonpos(pos + neg)
#> [1] FALSE
is_nonpos(neg * zero)
#> [1] TRUE
is_nonpos(neg - pos)
#> [1] TRUE