## `iszero` -- generic zero test

#### Introduction

`iszero(`object`)` checks whether `object` is the zero element in the domain of `object`.

#### Call(s)

`iszero(object)`

#### Parameters

`object` | - | an arbitrary MuPAD object

#### Returns

either `TRUE` or `FALSE`

### Overloadable:

`object`

#### Related Functions

`_equal`, `Ax::normalRep`, `bool`, `is`, `normal`, `simplify`, `sign`

#### Details

- Use the condition `iszero(`object`)` instead of `object = 0` to decide whether `object` is the zero element, because `iszero(`object`)` is more general than `object = 0`. If the call `bool(object = 0)` returns `TRUE`, then `iszero(`object`)` returns `TRUE` as well, but in general not vice versa (see example 1).

- If `object` is an element of a basic type, then `iszero` returns `TRUE` precisely if one of the following is true: `object` is the integer `0` (of domain type `DOM_INT`), the floating point value `0.0` (of domain type `DOM_FLOAT`), or the zero polynomial (of domain type `DOM_POLY`). In the case of a polynomial, the result `FALSE` is guaranteed to be correct only if the coefficients of the polynomial are in normal form (i.e., if zero has a unique representation in the coefficient ring). See also `Ax::normalRep`.

- If `object` is an element of a library domain, then the method `"`iszero" of the domain is called and the result is returned. If this method does not exist, then the function `iszero` returns `FALSE`.

- `iszero` performs a purely syntactical zero test. If `iszero` returns `TRUE`, then the answer is always correct. If `iszero` returns `FALSE`, however, then it may still be true that mathematically `object` represents zero (see example 3). In such cases, the MuPAD functions `normal` or `simplify` may be able to recognize this.

- `iszero` does not take into account properties of identifiers in `object` that have been set via `assume`. In particular, you should not use `iszero` in an argument passed to `assume` or `is`; use the form `object = 0` instead (see example 2).

- Do not use `iszero` in a condition passed to `piecewise`. In contrast to `object = 0`, the command `iszero(`object`)` is evaluated immediately, before it is passed to `piecewise`, while the evaluation of `object = 0` is handled by `piecewise` itself. Thus using `iszero` in a `piecewise` command usually leads to unwanted effects (see example 4).

- `iszero` is a function of the system kernel.

#### Example 1

`iszero` handles the basic data types:

    >> iszero(0), iszero(1/2), iszero(0.0), iszero(I)

                             TRUE, FALSE, TRUE, FALSE

`iszero` works for polynomials:

    >> p:= poly(x^2 + y, [x]):
       iszero(p)

                                       FALSE

    >> iszero(poly(0, [x, y]))

                                       TRUE

`iszero` is more general than `=`:

    >> bool(0 = 0), bool(0.0 = 0), bool(poly(0, [x]) = 0)

                                TRUE, FALSE, FALSE

    >> iszero(0), iszero(0.0), iszero(poly(0, [x]))

                                 TRUE, TRUE, TRUE

#### Example 2

`iszero` does not react to properties:

    >> assume(a = b): is(a - b = 0)

                                       TRUE

    >> iszero(a - b)

                                       FALSE

#### Example 3

Although `iszero` returns `FALSE` in the following example, the expression in question mathematically represents zero:

    >> iszero(sin(x)^2 + cos(x)^2 - 1)

                                       FALSE

In this case `simplify` is able to decide this:

    >> simplify(sin(x)^2 + cos(x)^2 - 1)

                                         0

#### Example 4

`iszero` should not be used in a condition passed to `piecewise`:

    >> delete x:
       piecewise([iszero(x), 0], [x <> 0, 1])

                              piecewise(1 if x <> 0)

The first branch was discarded because `iszero(`x`)` immediately evaluates to `FALSE`. Instead, use the condition `x = 0`, which is passed unevaluated to `piecewise`:

    >> piecewise([x = 0, 0], [x <> 0, 1])

                        piecewise(0 if x = 0, 1 if x <> 0)

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000