Next: Functions for Complex Numbers, Previous: Mathematical Functions, Up: Mathematical Functions [Contents][Index]

### 10.1 Functions for Numbers

Function: abs (z)

  The `abs` function represents the mathematical absolute value function and works for both numerical and symbolic values. If the argument, z, is a real or complex number, `abs` returns the absolute value of z. If possible, symbolic expressions using the absolute value function are also simplified.

  Maxima can differentiate, integrate and calculate limits for expressions containing `abs`. The `abs_integrate` package further extends Maxima’s ability to calculate integrals involving the abs function. See (%i12) in the examples below.

  When applied to a list or matrix, `abs` automatically distributes over the terms. Similarly, it distributes over both sides of an equation. To alter this behaviour, see the variable `distribute_over`.

  See also `cabs`.

  Examples:

  Calculation of `abs` for real and complex numbers, including numerical constants and various infinities. The first example shows how `abs` distributes over the elements of a list.

      (%i1) abs([-4, 0, 1, 1+%i]);
      (%o1)                  [4, 0, 1, sqrt(2)]

      (%i2) abs((1+%i)*(1-%i));
      (%o2)                           2
      (%i3) abs(%e+%i);
                                      2
      (%o3)                    sqrt(%e  + 1)
      (%i4) abs([inf, infinity, minf]);
      (%o4)                   [inf, inf, inf]

  Simplification of expressions containing `abs`:

      (%i5) abs(x^2);
                                      2
      (%o5)                          x
      (%i6) abs(x^3);
                                   2
      (%o6)                       x  abs(x)

      (%i7) abs(abs(x));
      (%o7)                       abs(x)
      (%i8) abs(conjugate(x));
      (%o8)                       abs(x)

  Integrating and differentiating with the `abs` function. Note that more integrals involving the `abs` function can be performed, if the `abs_integrate` package is loaded. The last example shows the Laplace transform of `abs`: see `laplace`.

      (%i9) diff(x*abs(x),x),expand;
      (%o9)                       2 abs(x)

      (%i10) integrate(abs(x),x);
                                   x abs(x)
      (%o10)                       --------
                                      2

      (%i11) integrate(x*abs(x),x);
                                 /
                                 [
      (%o11)                     I x abs(x) dx
                                 ]
                                 /

      (%i12) load("abs_integrate")$
      (%i13) integrate(x*abs(x),x);
                            2           3
                           x  abs(x)   x  signum(x)
      (%o13)               --------- - ------------
                               2            6

      (%i14) integrate(abs(x),x,-2,%pi);
                                     2
                                  %pi
      (%o14)                      ---- + 2
                                   2

      (%i15) laplace(abs(x),x,s);
                                     1
      (%o15)                         --
                                      2
                                     s

  Categories:Mathematical functions ·

Function: ceiling (x)

  When x is a real number, return the least integer that is greater than or equal to x.

  If x is a constant expression (`10 * %pi`, for example), `ceiling` evaluates x using big floating point numbers, and applies `ceiling` to the resulting big float. Because `ceiling` uses floating point evaluation, it’s possible, although unlikely, that `ceiling` could return an erroneous value for constant inputs. To guard against errors, the floating point evaluation is done using three values for `fpprec`.

  For non-constant inputs, `ceiling` tries to return a simplified value. Here are examples of the simplifications that `ceiling` knows about:

      (%i1) ceiling (ceiling (x));
      (%o1)                      ceiling(x)

      (%i2) ceiling (floor (x));
      (%o2)                       floor(x)

      (%i3) declare (n, integer)$

      (%i4) [ceiling (n), ceiling (abs (n)), ceiling (max (n, 6))];
      (%o4)                [n, abs(n), max(6, n)]

      (%i5) assume (x > 0, x < 1)$

      (%i6) ceiling (x);
      (%o6)                           1

      (%i7) tex (ceiling (a));
      $$\left \lceil a \right \rceil$$
      (%o7)                         false

  The `ceiling` function distributes over lists, matrices and equations. See `distribute_over`.

  Finally, for all inputs that are manifestly complex, `ceiling` returns a noun form.

  If the range of a function is a subset of the integers, it can be declared to be `integervalued`. Both the `ceiling` and `floor` functions can use this information; for example:

      (%i1) declare (f, integervalued)$

      (%i2) floor (f(x));
      (%o2)                         f(x)

      (%i3) ceiling (f(x) - 1);
      (%o3)                       f(x) - 1

  Example use:

      (%i1) unitfrac(r) := block([uf : [], q],
          if not(ratnump(r)) then
             error("unitfrac: argument must be a rational number"),
          while r # 0 do (
              uf : cons(q : 1/ceiling(1/r), uf),
              r : r - q),
          reverse(uf));
      (%o1) unitfrac(r) := block([uf : [], q],
      if not ratnump(r) then
      error("unitfrac: argument must be a rational number"),
                                        1
      while r # 0 do (uf : cons(q : ----------, uf), r : r - q),
                                            1
                                    ceiling(-)
                                            r
      reverse(uf))

      (%i2) unitfrac (9/10);
                                  1  1  1
      (%o2)                      [-, -, --]
                                  2  3  15

      (%i3) apply ("+", %);
                                     9
      (%o3)                          --
                                     10

      (%i4) unitfrac (-9/10);
                                        1
      (%o4)                       [- 1, --]
                                        10

      (%i5) apply ("+", %);
                                      9
      (%o5)                         - --
                                      10

      (%i6) unitfrac (36/37);
                              1  1  1  1    1
      (%o6)                  [-, -, -, --, ----]
                              2  3  8  69  6808

      (%i7) apply ("+", %);
                                     36
      (%o7)                          --
                                     37

  Categories:Mathematical functions ·

Function: entier (x)

  Returns the largest integer less than or equal to x where x is numeric. `fix` (as in `fixnum`) is a synonym for this, so `fix(x)` is precisely the same.

  Categories:Mathematical functions ·

Function: floor (x)

  When x is a real number, return the largest integer that is less than or equal to x.

  If x is a constant expression (`10 * %pi`, for example), `floor` evaluates x using big floating point numbers, and applies `floor` to the resulting big float. Because `floor` uses floating point evaluation, it’s possible, although unlikely, that `floor` could return an erroneous value for constant inputs. To guard against errors, the floating point evaluation is done using three values for `fpprec`.

  For non-constant inputs, `floor` tries to return a simplified value. Here are examples of the simplifications that `floor` knows about:

      (%i1) floor (ceiling (x));
      (%o1)                      ceiling(x)

      (%i2) floor (floor (x));
      (%o2)                       floor(x)

      (%i3) declare (n, integer)$

      (%i4) [floor (n), floor (abs (n)), floor (min (n, 6))];
      (%o4)                [n, abs(n), min(6, n)]

      (%i5) assume (x > 0, x < 1)$

      (%i6) floor (x);
      (%o6)                           0

      (%i7) tex (floor (a));
      $$\left \lfloor a \right \rfloor$$
      (%o7)                         false

  The `floor` function distributes over lists, matrices and equations. See `distribute_over`.

  Finally, for all inputs that are manifestly complex, `floor` returns a noun form.

  If the range of a function is a subset of the integers, it can be declared to be `integervalued`. Both the `ceiling` and `floor` functions can use this information; for example:

      (%i1) declare (f, integervalued)$

      (%i2) floor (f(x));
      (%o2)                         f(x)

      (%i3) ceiling (f(x) - 1);
      (%o3)                       f(x) - 1

  Categories:Mathematical functions ·

Function: fix (x)

  A synonym for `entier (x)`.

  Categories:Mathematical functions ·

Function: hstep (x)

  The Heaviside unit step function, equal to 0 if x is negative, equal to 1 if x is positive and equal to 1/2 if x is equal to zero.

  If you want a unit step function that takes on the value of 0 at x equal to zero, use `unit_step`.

  Categories:Laplace transform ·Mathematical functions ·

Function: lmax (L)

  When L is a list or a set, return `apply ('max, args (L))`. When L is not a list or a set, signal an error. See also `lmin` and `max`.

  Categories:Mathematical functions ·Lists ·Sets ·

Function: lmin (L)

  When L is a list or a set, return `apply ('min, args (L))`. When L is not a list or a set, signal an error. See also `lmax` and `min`.

  Categories:Mathematical functions ·Lists ·Sets ·

Function: max (x_1, …, x_n)

  Return a simplified value for the numerical maximum of the expressions x_1 through x_n. For an empty argument list, `max` yields `minf`.

  The option variable `maxmin_effort` controls which simplification methods are applied. Using the default value of twelve for `maxmin_effort`, `max` uses all available simplification methods. To to inhibit all simplifications, set `maxmin_effort` to zero.

  When `maxmin_effort` is one or more, for an explicit list of real numbers, `max` returns a number.

  Unless `max` needs to simplify a lengthy list of expressions, we suggest using the default value of `maxmin_effort`. Setting `maxmin_effort` to zero (no simplifications), will cause problems for some Maxima functions; accordingly, generally `maxmin_effort` should be nonzero.

  See also `min`, `lmax`., and `lmin`..

  Examples:

  In the first example, setting `maxmin_effort` to zero suppresses simplifications.

      (%i1) block([maxmin_effort : 0], max(1,2,x,x, max(a,b)));
      (%o1) max(1,2,max(a,b),x,x)

      (%i2) block([maxmin_effort : 1], max(1,2,x,x, max(a,b)));
      (%o2) max(2,a,b,x)

  When `maxmin_effort` is two or more, `max` compares pairs of members:

      (%i1) block([maxmin_effort : 1], max(x,x+1,x+3));
      (%o1) max(x,x+1,x+3)

      (%i2) block([maxmin_effort : 2], max(x,x+1,x+3));
      (%o2) x+3

  Finally, when `maxmin_effort` is three or more, `max` compares triples members and excludes those that are in between; for example

      (%i1) block([maxmin_effort : 4], max(x, 2*x, 3*x, 4*x));
      (%o1) max(x,4*x)

  Categories:Mathematical functions ·

Function: min (x_1, …, x_n)

  Return a simplified value for the numerical minimum of the expressions x_1 through x_n. For an empty argument list, `minf` yields `inf`.

  The option variable `maxmin_effort` controls which simplification methods are applied. Using the default value of twelve for `maxmin_effort`, `max` uses all available simplification methods. To to inhibit all simplifications, set `maxmin_effort` to zero.

  When `maxmin_effort` is one or more, for an explicit list of real numbers, `min` returns a number.

  Unless `min` needs to simplify a lengthy list of expressions, we suggest using the default value of `maxmin_effort`. Setting `maxmin_effort` to zero (no simplifications), will cause problems for some Maxima functions; accordingly, generally `maxmin_effort` should be nonzero.

  See also `max`, `lmax`., and `lmin`..

  Examples:

  In the first example, setting `maxmin_effort` to zero suppresses simplifications.

      (%i1) block([maxmin_effort : 0], min(1,2,x,x, min(a,b)));
      (%o1) min(1,2,a,b,x,x)

      (%i2) block([maxmin_effort : 1], min(1,2,x,x, min(a,b)));
      (%o2) min(1,a,b,x)

  When `maxmin_effort` is two or more, `min` compares pairs of members:

      (%i1) block([maxmin_effort : 1], min(x,x+1,x+3));
      (%o1) min(x,x+1,x+3)

      (%i2) block([maxmin_effort : 2], min(x,x+1,x+3));
      (%o2) x

  Finally, when `maxmin_effort` is three or more, `min` compares triples members and excludes those that are in between; for example

      (%i1) block([maxmin_effort : 4], min(x, 2*x, 3*x, 4*x));
      (%o1) max(x,4*x)

  Categories:Mathematical functions ·

Function: round (x)

  When x is a real number, returns the closest integer to x. Multiples of 1/2 are rounded to the nearest even integer. Evaluation of x is similar to `floor` and `ceiling`.

  The `round` function distributes over lists, matrices and equations. See `distribute_over`.

  Categories:Mathematical functions ·

Function: signum (x)

  For either real or complex numbers x, the signum function returns 0 if x is zero; for a nonzero numeric input x, the signum function returns `x/abs(x)`.

  For non-numeric inputs, Maxima attempts to determine the sign of the input. When the sign is negative, zero, or positive, `signum` returns -1,0, 1, respectively. For all other values for the sign, `signum` a simplified but equivalent form. The simplifications include reflection (`signum(-x)` gives `-signum(x)`) and multiplicative identity (`signum(x*y)` gives `signum(x) * signum(y)`).

  The `signum` function distributes over a list, a matrix, or an equation. See `sign` and `distribute_over`.

  Categories:Mathematical functions ·

Function: truncate (x)

  When x is a real number, return the closest integer to x not greater in absolute value than x. Evaluation of x is similar to `floor` and `ceiling`.

  The `truncate` function distributes over lists, matrices and equations. See `distribute_over`.

  Categories:Mathematical functions ·

Next: Functions for Complex Numbers, Previous: Mathematical Functions, Up: Mathematical Functions [Contents][Index]