## `abs` -- the absolute value of a real or complex number

#### Introduction

`abs(`z`)` returns the absolute value of the number `z`.

#### Call(s)

`abs(z)`

#### Parameters

`z` | - | an arithmetical expression

#### Returns

an arithmetical expression.

### Overloadable:

`z`

#### Side Effects

`abs` respects properties of identifiers.

#### Related Functions

`conjugate`, `Im`, `norm`, `Re`, `sign`

#### Details

- For many constant expressions, `abs` returns the absolute value as an explicit number or expression. Cf. example 1.
- A symbolic call of `abs` is returned if the absolute value cannot be determined (e.g., because the argument involves identifiers). The result is subject to certain simplifications. In particular, `abs` extracts constant factors. Properties of identifiers are taken into account. Cf. examples 2 and 3.
- The `expand` function rewrites the absolute value of a product to a product of absolute values. E.g., `expand(abs(x*y))` yields `abs(x)*abs(y)`. Cf. example 4.
- The symbolic constants `CATALAN`, `E`, `EULER`, and `PI` are processed by `abs`. Cf. example 5.
- The absolute value of symbolic function calls can be defined via the slot `"abs"` of function environments. Cf. example 7.
- In the same way, the absolute value of domain elements can be defined via overloading. Cf. example 8.

#### Example 1

For many constant expressions, the absolute value can be computed explicitly:

    >> abs(1.2), abs(-8/3), abs(3 + I), abs(sqrt(-3))

                                           1/2   1/2
                               1.2, 8/3, 10   , 3

    >> abs(sin(42)), abs(PI^2 - 10), abs(exp(3) - tan(157/100))

                                      2
                     -sin(42), 10 - PI , tan(157/100) - exp(3)

    >> abs(exp(3 + I) - sqrt(2))

                         2       2                     1/2 2 1/2
                  (sin(1)  exp(3)  + (cos(1) exp(3) - 2   ) )

#### Example 2

Symbolic calls are returned if the argument contains identifiers without properties:

    >> abs(x), abs(x + 1), abs(sin(x + y))

                        abs(x), abs(x + 1), abs(sin(x + y))

The result is subject to some simplifications. In particular, `abs` splits off constant factors in products:

    >> abs(PI*x*y), abs((1 + I)*x), abs(sin(4)*(x + sqrt(3)))

                                      1/2                    1/2
                 PI abs(x y), abs(x) 2   , - sin(4) abs(x + 3   )

#### Example 3

`abs` is sensitive to properties of identifiers:

    >> assume(x < 0):  abs(3*x), abs(PI - x), abs(I*x), abs(x + I)

                                               2     1/2
                           -3 x, PI - x, -x, (x  + 1)

    >> unassume(x):

#### Example 4

The `expand` function produces products of `abs` calls:

    >> abs(x*(y + 1)), expand(abs(x*(y + 1)))

                         abs(x (y + 1)), abs(x) abs(y + 1)

#### Example 5

The absolut value of the symbolic constants `PI`, `EULER` etc. are known:

    >> abs(PI), abs(EULER + CATALAN^2)

                                                  2
                               PI, EULER + CATALAN

#### Example 6

Expressions containing `abs` can be differentiated:

    >> diff(abs(x), x),  diff(abs(x), x, x)

                                sign(x), 2 dirac(x)

#### Example 7

The slot `"`abs" of a function environment `f` defines the absolute value of symbolic calls of `f`:

    >> abs(f(x))

                                     abs(f(x))

    >> f := funcenv(f): f::abs := x -> f(x)/sign(f(x)): abs(f(x))

                                       f(x)
                                    ----------
                                    sign(f(x))

    >> delete f:

#### Example 8

The slot `"`abs" of a domain `d` defines the absolute value of its elements:

    >> d := newDomain("d"):  e1 := new(d, 2): e2 := new(d, x):
       abs(e1), abs(e2)

                          abs(new(d, 2)), abs(new(d, x))

    >> d::abs := x -> abs(extop(x, 1)):  abs(e1), abs(e2)

                                     2, abs(x)

    >> delete d, e1, e2:

#### Changes

- no changes

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