Maxima 5.36.0 Manual: 10. Mathematical Functions

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 10. Mathematical Functions

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [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`.

  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(n, 6)]
      (%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))$
      (%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(n, 6)]
      (%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: 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 maximum of the expressions x_1 through x_n. When `get (trylevel, maxmin)`, is 2 or greater, `max` uses the simplification `max (e, -e) --> |e|`. When `get (trylevel, maxmin)` is 3 or greater, max tries to eliminate expressions that are between two other arguments; for example, `max (x, 2*x, 3*x) --> max (x, 3*x)`. To set the value of `trylevel` to 2, use `put (trylevel, 2, maxmin)`.

  See also `min` and `lmax`.

  Categories: Mathematical functions

Function: min (x_1, …, x_n)

  Return a simplified value for the minimum of the expressions `x_1` through `x_n`. When `get (trylevel, maxmin)`, is 2 or greater, `min` uses the simplification `min (e, -e) --> -|e|`. When `get (trylevel, maxmin)` is 3 or greater, `min` tries to eliminate expressions that are between two other arguments; for example, `min (x, 2*x, 3*x) --> min (x, 3*x)`. To set the value of `trylevel` to 2, use `put (trylevel, 2, maxmin)`.

  See also `max` and `lmin`.

  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 `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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 10.2 Functions for Complex Numbers

Function: cabs (expr)

  Calculates the absolute value of an expression representing a complex number. Unlike the function `abs`, the `cabs` function always decomposes its argument into a real and an imaginary part. If `x` and `y` represent real variables or expressions, the `cabs` function calculates the absolute value of `x + %i*y` as

                                 2    2
                           sqrt(y  + x )

  The `cabs` function can use known properties like symmetry properties of complex functions to help it calculate the absolute value of an expression. If such identities exist, they can be advertised to `cabs` using function properties. The symmetries that `cabs` understands are: mirror symmetry, conjugate function and complex characteristic.

  `cabs` is a verb function and is not suitable for symbolic calculations. For such calculations (including integration, differentiation and taking limits of expressions containing absolute values), use `abs`.

  The result of `cabs` can include the absolute value function, `abs`, and the arc tangent, `atan2`.

  When applied to a list or matrix, `cabs` automatically distributes over the terms. Similarly, it distributes over both sides of an equation.

  For further ways to compute with complex numbers, see the functions `rectform`, `realpart`, `imagpart`, `carg`, `conjugate` and `polarform`.

  Examples:

  Examples with `sqrt` and `sin`.

      (%i1) cabs(sqrt(1+%i*x));
                                   2     1/4
      (%o1)                      (x  + 1)
      (%i2) cabs(sin(x+%i*y));
                          2        2         2        2
      (%o2)       sqrt(cos (x) sinh (y) + sin (x) cosh (y))

  The error function, `erf`, has mirror symmetry, which is used here in the calculation of the absolute value with a complex argument:

      (%i3) cabs(erf(x+%i*y));
                                                2
                 (erf(%i y + x) - erf(%i y - x))
      (%o3) sqrt(--------------------------------
                                4
                                                                     2
                                      (erf(%i y + x) + erf(%i y - x))
                                    - --------------------------------)
                                                     4

  Maxima knows complex identities for the Bessel functions, which allow it to compute the absolute value for complex arguments. Here is an example for `bessel_j`.

      (%i4) cabs(bessel_j(1,%i));
      (%o4)                 abs(bessel_j(1, %i))

  Categories: Complex variables

Function: carg (z)

  Returns the complex argument of z. The complex argument is an angle `theta` in `(-%pi, %pi]` such that `r exp (theta %i) = z` where `r` is the magnitude of z.

  `carg` is a computational function, not a simplifying function.

  See also `abs` (complex magnitude), `polarform`, `rectform`, `realpart`, and `imagpart`.

  Examples:

      (%i1) carg (1);
      (%o1)                           0
      (%i2) carg (1 + %i);
                                     %pi
      (%o2)                          ---
                                      4
      (%i3) carg (exp (%i));
      (%o3)                           1
      (%i4) carg (exp (%pi * %i));
      (%o4)                          %pi
      (%i5) carg (exp (3/2 * %pi * %i));
                                      %pi
      (%o5)                         - ---
                                       2
      (%i6) carg (17 * exp (2 * %i));
      (%o6)                           2

  Categories: Complex variables

Function: conjugate (x)

  Returns the complex conjugate of x.

      (%i1) declare ([aa, bb], real, cc, complex, ii, imaginary);

      (%o1)                         done
      (%i2) conjugate (aa + bb*%i);

      (%o2)                      aa - %i bb
      (%i3) conjugate (cc);

      (%o3)                     conjugate(cc)
      (%i4) conjugate (ii);

      (%o4)                         - ii
      (%i5) conjugate (xx + yy);

      (%o5)             conjugate(yy) + conjugate(xx)

  Categories: Complex variables

Function: imagpart (expr)

  Returns the imaginary part of the expression expr.

  `imagpart` is a computational function, not a simplifying function.

  See also `abs`, `carg`, `polarform`, `rectform`, and `realpart`.

  Example:

      (%i1) imagpart (a+b*%i);
      (%o1)                                  b
      (%i2) imagpart (1+sqrt(2)*%i);
      (%o2)                               sqrt(2)
      (%i3) imagpart (1);
      (%o3)                                  0
      (%i4) imagpart (sqrt(2)*%i);
      (%o4)                               sqrt(2)

  Categories: Complex variables

Function: polarform (expr)

  Returns an expression `r %e^(%i theta)` equivalent to expr, such that `r` and `theta` are purely real.

  Example:

      (%i1) polarform(a+b*%i);
                                    2    2    %i atan2(b, a)
      (%o1)                   sqrt(b  + a ) %e
      (%i2) polarform(1+%i);
                                               %i %pi
                                               ------
                                                 4
      (%o2)                          sqrt(2) %e
      (%i3) polarform(1+2*%i);
                                             %i atan(2)
      (%o3)                        sqrt(5) %e

  Categories: Complex variables · Exponential and logarithm functions

Function: realpart (expr)

  Returns the real part of expr. `realpart` and `imagpart` will work on expressions involving trigonometric and hyperbolic functions, as well as square root, logarithm, and exponentiation.

  Example:

      (%i1) realpart (a+b*%i);
      (%o1)                                  a
      (%i2) realpart (1+sqrt(2)*%i);
      (%o2)                                  1
      (%i3) realpart (sqrt(2)*%i);
      (%o3)                                  0
      (%i4) realpart (1);
      (%o4)                                  1

  Categories: Complex variables

Function: rectform (expr)

  Returns an expression `a + b %i` equivalent to expr, such that a and b are purely real.

  Example:

      (%i1) rectform(sqrt(2)*%e^(%i*%pi/4));
      (%o1)                               %i + 1
      (%i2) rectform(sqrt(b^2+a^2)*%e^(%i*atan2(b, a)));
      (%o2)                              %i b + a
      (%i3) rectform(sqrt(5)*%e^(%i*atan(2)));
      (%o3)                              2 %i + 1

  Categories: Complex variables

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 10.3 Combinatorial Functions

Operator: !!

  The double factorial operator.

  For an integer, float, or rational number `n`, `n!!` evaluates to the product `n (n-2) (n-4) (n-6) ... (n - 2 (k-1))` where `k` is equal to `entier (n/2)`, that is, the largest integer less than or equal to `n/2`. Note that this definition does not coincide with other published definitions for arguments which are not integers.

  For an even (or odd) integer `n`, `n!!` evaluates to the product of all the consecutive even (or odd) integers from 2 (or 1) through `n` inclusive.

  For an argument `n` which is not an integer, float, or rational, `n!!` yields a noun form `genfact (n, n/2, 2)`.

  Categories: Gamma and factorial functions · Operators

Function: binomial (x, y)

  The binomial coefficient `x!/(y! (x - y)!)`. If x and y are integers, then the numerical value of the binomial coefficient is computed. If y, or x - y, is an integer, the binomial coefficient is expressed as a polynomial.

  Examples:

      (%i1) binomial (11, 7);
      (%o1)                          330
      (%i2) 11! / 7! / (11 - 7)!;
      (%o2)                          330
      (%i3) binomial (x, 7);
              (x - 6) (x - 5) (x - 4) (x - 3) (x - 2) (x - 1) x
      (%o3)   -------------------------------------------------
                                    5040
      (%i4) binomial (x + 7, x);
            (x + 1) (x + 2) (x + 3) (x + 4) (x + 5) (x + 6) (x + 7)
      (%o4) -------------------------------------------------------
                                     5040
      (%i5) binomial (11, y);
      (%o5)                    binomial(11, y)

  Categories: Number theory

Function: factcomb (expr)

  Tries to combine the coefficients of factorials in expr with the factorials themselves by converting, for example, `(n + 1)*n!` into `(n + 1)!`.

  `sumsplitfact` if set to `false` will cause `minfactorial` to be applied after a `factcomb`.

  Example:

      (%i1) sumsplitfact;
      (%o1)                                true
      (%i2) (n + 1)*(n + 1)*n!;
                                               2
      (%o2)                             (n + 1)  n!
      (%i3) factcomb (%);
      (%o3)                         (n + 2)! - (n + 1)!
      (%i4) sumsplitfact: not sumsplitfact;
      (%o4)                                false
      (%i5) (n + 1)*(n + 1)*n!;
                                                2
      (%o5)                             (n + 1)  n!
      (%i6) factcomb (%);
      (%o6)                        n (n + 1)! + (n + 1)!

  Categories: Gamma and factorial functions

Function: factorial
Operator: !

  Represents the factorial function. Maxima treats `factorial (x)` the same as `x!`.

  For any complex number `x`, except for negative integers, `x!` is defined as `gamma(x+1)`.

  For an integer `x`, `x!` simplifies to the product of the integers from 1 to `x` inclusive. `0!` simplifies to 1. For a real or complex number in float or bigfloat precision `x`, `x!` simplifies to the value of `gamma (x+1)`. For `x` equal to `n/2` where `n` is an odd integer, `x!` simplifies to a rational factor times `sqrt (%pi)` (since `gamma (1/2)` is equal to `sqrt (%pi)`).

  The option variables `factlim` and `gammalim` control the numerical evaluation of factorials for integer and rational arguments. The functions `minfactorial` and `factcomb` simplifies expressions containing factorials.

  The functions `gamma`, `bffac`, and `cbffac` are varieties of the gamma function. `bffac` and `cbffac` are called internally by `gamma` to evaluate the gamma function for real and complex numbers in bigfloat precision.

  `makegamma` substitutes `gamma` for factorials and related functions.

  Maxima knows the derivative of the factorial function and the limits for specific values like negative integers.

  The option variable `factorial_expand` controls the simplification of expressions like `(n+x)!`, where `n` is an integer.

  See also `binomial`.

  The factorial of an integer is simplified to an exact number unless the operand is greater than `factlim`. The factorial for real and complex numbers is evaluated in float or bigfloat precision.

      (%i1) factlim:10;
      (%o1)                                 10
      (%i2) [0!, (7/2)!, 8!, 20!];
                                  105 sqrt(%pi)
      (%o2)                   [1, -------------, 40320, 20!]
                                       16
      (%i3) [4.77!, (1.0+%i)!];
      (%o3)    [81.44668037931197,
                .3430658398165454 %i + .6529654964201665]
      (%i4) [2.86b0!, (1.0b0+%i)!];
      (%o4) [5.046635586910012b0,
             3.430658398165454b-1 %i + 6.529654964201667b-1]

  The factorial of a known constant, or general expression is not simplified. Even so it may be possible to simplify the factorial after evaluating the operand.

      (%i1) [(%i + 1)!, %pi!, %e!, (cos(1) + sin(1))!];
      (%o1)      [(%i + 1)!, %pi!, %e!, (sin(1) + cos(1))!]
      (%i2) ev (%, numer, %enumer);
      (%o2) [.3430658398165454 %i + .6529654964201665,
             7.188082728976031,
             4.260820476357003, 1.227580202486819]

  Factorials are simplified, not evaluated. Thus `x!` may be replaced even in a quoted expression.

      (%i1) '([0!, (7/2)!, 4.77!, 8!, 20!]);
                105 sqrt(%pi)
      (%o1) [1, -------------, 81.44668037931199, 40320,
                     16
                                                   2432902008176640000]

  Maxima knows the derivative of the factorial function.

      (%i1) diff(x!,x);
      (%o1)                           x! psi (x + 1)
                                            0

  The option variable `factorial_expand` controls expansion and simplification of expressions with the factorial function.

      (%i1) (n+1)!/n!,factorial_expand:true;
      (%o1)                                n + 1

  Categories: Gamma and factorial functions · Operators

Option variable: factlim

  Default value: -1

  `factlim` specifies the highest factorial which is automatically expanded. If it is -1 then all integers are expanded.

  Categories: Gamma and factorial functions

Option variable: factorial_expand

  Default value: false

  The option variable `factorial_expand` controls the simplification of expressions like `(n+1)!`, where `n` is an integer. See `factorial` for an example.

  Categories: Gamma and factorial functions

Function: genfact (x, y, z)

  Returns the generalized factorial, defined as `x (x-z) (x - 2 z) ... (x - (y - 1) z)`. Thus, when x is an integer, `genfact (x, x, 1) = x!` and `genfact (x, x/2, 2) = x!!`.

  Categories: Gamma and factorial functions

Function: minfactorial (expr)

  Examines expr for occurrences of two factorials which differ by an integer. `minfactorial` then turns one into a polynomial times the other.

      (%i1) n!/(n+2)!;
                                     n!
      (%o1)                       --------
                                  (n + 2)!
      (%i2) minfactorial (%);
                                      1
      (%o2)                    ---------------
                               (n + 1) (n + 2)

  Categories: Number theory

Option variable: sumsplitfact

  Default value: `true`

  When `sumsplitfact` is `false`, `minfactorial` is applied after a `factcomb`.

      (%i1) sumsplitfact
      (%o1)                                true
      (%i2) n!/(2+n)!
                                            n!
      (%o2)                              --------
                                         (n + 2)!
      (%i3) factcomb(%)
                                            n!
      (%o3)                              --------
                                         (n + 2)!
      (%i4) sumsplitfact:not sumsplitfact
      (%o4)                                false
      (%i5) n!/(2+n)!
                                            n!
      (%o5)                              --------
                                         (n + 2)!
      (%i6) factcomb(%)
                                             1
      (%o6)                           ---------------
                                      (n + 1) (n + 2)

  Categories: Gamma and factorial functions · Simplification flags and variables

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 10.4 Root, Exponential and Logarithmic Functions

Option variable: %e_to_numlog

  Default value: `false`

  When `true`, `r` some rational number, and `x` some expression, `%e^(r*log(x))` will be simplified into `x^r` . It should be noted that the `radcan` command also does this transformation, and more complicated transformations of this ilk as well. The `logcontract` command "contracts" expressions containing `log`.

  Categories: Exponential and logarithm functions · Simplification flags and variables

Option variable: %emode

  Default value: `true`

  When `%emode` is `true`, `%e^(%pi %i x)` is simplified as follows.

  `%e^(%pi %i x)` simplifies to `cos (%pi x) + %i sin (%pi x)` if `x` is a floating point number, an integer, or a multiple of 1/2, 1/3, 1/4, or 1/6, and then further simplified.

  For other numerical `x`, `%e^(%pi %i x)` simplifies to `%e^(%pi %i y)` where `y` is `x - 2 k` for some integer `k` such that `abs(y) < 1`.

  When `%emode` is `false`, no special simplification of `%e^(%pi %i x)` is carried out.

      (%i1) %emode
      (%o1)                                true
      (%i2) %e^(%pi*%i*1)
      (%o2)                                 - 1
      (%i3) %e^(%pi*%i*216/144)
      (%o3)                                - %i
      (%i4) %e^(%pi*%i*192/144)
                                       sqrt(3) %i   1
      (%o4)                          - ---------- - -
                                           2        2
      (%i5) %e^(%pi*%i*180/144)
                                        %i         1
      (%o5)                         - ------- - -------
                                      sqrt(2)   sqrt(2)
      (%i6) %e^(%pi*%i*120/144)
                                       %i   sqrt(3)
      (%o6)                            -- - -------
                                       2       2
      (%i7) %e^(%pi*%i*121/144)
                                         121 %i %pi
                                         ----------
                                            144
      (%o7)                            %e

  Categories: Exponential and logarithm functions · Simplification flags and variables

Option variable: %enumer

  Default value: `false`

  When `%enumer` is `true`, `%e` is replaced by its numeric value 2.718… whenever `numer` is `true`.

  When `%enumer` is `false`, this substitution is carried out only if the exponent in `%e^x` evaluates to a number.

  See also `ev` and `numer`.

      (%i1) %enumer
      (%o1)                                false
      (%i2) numer
      (%o2)                                false
      (%i3) 2*%e
      (%o3)                                2 %e
      (%i4) %enumer:not %enumer
      (%o4)                                true
      (%i5) 2*%e
      (%o5)                                2 %e
      (%i6) numer:not numer
      (%o6)                                true
      (%i7) 2*%e
      (%o7)                          5.43656365691809
      (%i8) 2*%e^1
      (%o8)                          5.43656365691809
      (%i9) 2*%e^x
                                                     x
      (%o9)                       2 2.718281828459045

  Categories: Exponential and logarithm functions · Evaluation flags

Function: exp (x)

  Represents the exponential function. Instances of `exp (x)` in input are simplified to `%e^x`; `exp` does not appear in simplified expressions.

  `demoivre` if `true` causes `%e^(a + b %i)` to simplify to `%e^(a (cos(b) + %i sin(b)))` if `b` is free of `%i`. See `demoivre`.

  `%emode`, when `true`, causes `%e^(%pi %i x)` to be simplified. See `%emode`.

  `%enumer`, when `true` causes `%e` to be replaced by 2.718… whenever `numer` is `true`. See `%enumer`.

      (%i1) demoivre;
      (%o1)                                false
      (%i2) %e^(a + b*%i);
                                          %i b + a
      (%o2)                             %e
      (%i3) demoivre: not demoivre;
      (%o3)                                true
      (%i4) %e^(a + b*%i);
                                   a
      (%o4)                      %e  (%i sin(b) + cos(b))

  Categories: Exponential and logarithm functions

Function: li [s] (z)

  Represents the polylogarithm function of order s and argument z, defined by the infinite series

                                       inf
                                       ====   k
                                       \     z
                              Li (z) =  >    --
                                s      /      s
                                       ====  k
                                       k = 1

  `li [1]` is `- log (1 - z)`. `li [2]` and `li [3]` are the dilogarithm and trilogarithm functions, respectively.

  When the order is 1, the polylogarithm simplifies to `- log (1 - z)`, which in turn simplifies to a numerical value if z is a real or complex floating point number or the `numer` evaluation flag is present.

  When the order is 2 or 3, the polylogarithm simplifies to a numerical value if z is a real floating point number or the `numer` evaluation flag is present.

  Examples:

      (%i1) assume (x > 0);
      (%o1)                        [x > 0]
      (%i2) integrate ((log (1 - t)) / t, t, 0, x);
      (%o2)                       - li (x)
                                      2
      (%i3) li [2] (7);
      (%o3)                        li (7)
                                     2
      (%i4) li [2] (7), numer;
      (%o4)        1.24827317833392 - 6.113257021832577 %i
      (%i5) li [3] (7);
      (%o5)                        li (7)
                                     3
      (%i6) li [2] (7), numer;
      (%o6)        1.24827317833392 - 6.113257021832577 %i
      (%i7) L : makelist (i / 4.0, i, 0, 8);
      (%o7)   [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
      (%i8) map (lambda ([x], li [2] (x)), L);
      (%o8) [0, .2676526384986274, .5822405249432515,
      .9784693966661848, 1.64493407, 2.190177004178597
       - .7010261407036192 %i, 2.374395264042415
       - 1.273806203464065 %i, 2.448686757245154
       - 1.758084846201883 %i, 2.467401098097648
       - 2.177586087815347 %i]
      (%i9) map (lambda ([x], li [3] (x)), L);
      (%o9) [0, .2584613953442624, 0.537213192678042,
      .8444258046482203, 1.2020569, 1.642866878950322
       - .07821473130035025 %i, 2.060877505514697
       - .2582419849982037 %i, 2.433418896388322
       - .4919260182322965 %i, 2.762071904015935
       - .7546938285978846 %i]

  Categories: Exponential and logarithm functions

Function: log (x)

  Represents the natural (base e) logarithm of x.

  Maxima does not have a built-in function for the base 10 logarithm or other bases. `log10(x) := log(x) / log(10)` is a useful definition.

  Simplification and evaluation of logarithms is governed by several global flags:

  ``logexpand``

    causes `log(a^b)` to become `b*log(a)`. If it is set to `all`, `log(a*b)` will also simplify to `log(a)+log(b)`. If it is set to `super`, then `log(a/b)` will also simplify to `log(a)-log(b)` for rational numbers `a/b`, `a#1`. (`log(1/b)`, for `b` integer, always simplifies.) If it is set to `false`, all of these simplifications will be turned off.

  ``logsimp``

    if `false` then no simplification of `%e` to a power containing `log`'s is done.

  ``lognegint``

    if `true` implements the rule `log(-n)` -> `log(n)+%i*%pi` for `n` a positive integer.

  ``%e_to_numlog``

    when `true`, `r` some rational number, and `x` some expression, the expression `%e^(r*log(x))` will be simplified into `x^r`. It should be noted that the `radcan` command also does this transformation, and more complicated transformations of this as well. The `logcontract` command "contracts" expressions containing `log`.

  Categories: Exponential and logarithm functions

Option variable: logabs

  Default value: `false`

  When doing indefinite integration where logs are generated, e.g. `integrate(1/x,x)`, the answer is given in terms of `log(abs(...))` if `logabs` is `true`, but in terms of `log(...)` if `logabs` is `false`. For definite integration, the `logabs:true` setting is used, because here "evaluation" of the indefinite integral at the endpoints is often needed.

  Categories: Exponential and logarithm functions · Integral calculus · Global flags

Option variable: logarc
Function: logarc (expr)

  When the global variable `logarc` is `true`, inverse circular and hyperbolic functions are replaced by equivalent logarithmic functions. The default value of `logarc` is `false`.

  The function `logarc(expr)` carries out that replacement for an expression expr without setting the global variable `logarc`.

  Categories: Exponential and logarithm functions · Simplification flags and variables · Simplification functions

Option variable: logconcoeffp

  Default value: `false`

  Controls which coefficients are contracted when using `logcontract`. It may be set to the name of a predicate function of one argument. E.g. if you like to generate SQRTs, you can do `logconcoeffp:'logconfun$ logconfun(m):=featurep(m,integer) or ratnump(m)$` . Then `logcontract(1/2*log(x));` will give `log(sqrt(x))`.

  Categories: Exponential and logarithm functions · Simplification flags and variables

Function: logcontract (expr)

  Recursively scans the expression expr, transforming subexpressions of the form `a1*log(b1) + a2*log(b2) + c` into `log(ratsimp(b1^a1 * b2^a2)) + c`

      (%i1) 2*(a*log(x) + 2*a*log(y))$
      (%i2) logcontract(%);
                                       2  4
      (%o2)                     a log(x  y )

  The declaration `declare(n,integer)` causes `logcontract(2*a*n*log(x))` to simplify to `a*log(x^(2*n))`. The coefficients that "contract" in this manner are those such as the 2 and the `n` here which satisfy `featurep(coeff,integer)`. The user can control which coefficients are contracted by setting the option `logconcoeffp` to the name of a predicate function of one argument. E.g. if you like to generate SQRTs, you can do `logconcoeffp:'logconfun$ logconfun(m):=featurep(m,integer) or ratnump(m)$` . Then `logcontract(1/2*log(x));` will give `log(sqrt(x))`.

  Categories: Exponential and logarithm functions

Option variable: logexpand

  Default value: `true`

  If `true`, that is the default value, causes `log(a^b)` to become `b*log(a)`. If it is set to `all`, `log(a*b)` will also simplify to `log(a)+log(b)`. If it is set to `super`, then `log(a/b)` will also simplify to `log(a)-log(b)` for rational numbers `a/b`, `a#1`. (`log(1/b)`, for integer `b`, always simplifies.) If it is set to `false`, all of these simplifications will be turned off.

  Categories: Exponential and logarithm functions · Simplification flags and variables

Option variable: lognegint

  Default value: `false`

  If `true` implements the rule `log(-n)` -> `log(n)+%i*%pi` for `n` a positive integer.

  Categories: Exponential and logarithm functions · Simplification flags and variables

Option variable: logsimp

  Default value: `true`

  If `false` then no simplification of `%e` to a power containing `log`'s is done.

  Categories: Exponential and logarithm functions · Simplification flags and variables

Function: plog (x)

  Represents the principal branch of the complex-valued natural logarithm with `-%pi` < `carg(x)` <= `+%pi` .

  Categories: Exponential and logarithm functions · Complex variables

Function: sqrt (x)

  The square root of x. It is represented internally by `x^(1/2)`. See also `rootscontract`.

  `radexpand` if `true` will cause nth roots of factors of a product which are powers of n to be pulled outside of the radical, e.g. `sqrt(16*x^2)` will become `4*x` only if `radexpand` is `true`.

  Categories: Mathematical functions

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 10.5 Trigonometric Functions

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 10.5.1 Introduction to Trigonometric

Maxima has many trigonometric functions defined. Not all trigonometric identities are programmed, but it is possible for the user to add many of them using the pattern matching capabilities of the system. The trigonometric functions defined in Maxima are: `acos`, `acosh`, `acot`, `acoth`, `acsc`, `acsch`, `asec`, `asech`, `asin`, `asinh`, `atan`, `atanh`, `cos`, `cosh`, `cot`, `coth`, `csc`, `csch`, `sec`, `sech`, `sin`, `sinh`, `tan`, and `tanh`. There are a number of commands especially for handling trigonometric functions, see `trigexpand`, `trigreduce`, and the switch `trigsign`. Two share packages extend the simplification rules built into Maxima, `ntrig` and `atrig1`. Do `describe(command)` for details.

Categories: Trigonometric functions

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 10.5.2 Functions and Variables for Trigonometric

Option variable: %piargs

  Default value: `true`

  When `%piargs` is `true`, trigonometric functions are simplified to algebraic constants when the argument is an integer multiple of %pi, %pi/2, %pi/3, %pi/4, or %pi/6.

  Maxima knows some identities which can be applied when %pi, etc., are multiplied by an integer variable (that is, a symbol declared to be integer).

  Examples:

      (%i1) %piargs : false$
      (%i2) [sin (%pi), sin (%pi/2), sin (%pi/3)];
                                      %pi       %pi
      (%o2)            [sin(%pi), sin(---), sin(---)]
                                       2         3
      (%i3) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
                            %pi       %pi       %pi
      (%o3)            [sin(---), sin(---), sin(---)]
                             4         5         6
      (%i4) %piargs : true$
      (%i5) [sin (%pi), sin (%pi/2), sin (%pi/3)];
                                      sqrt(3)
      (%o5)                    [0, 1, -------]
                                         2
      (%i6) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
                               1         %pi   1
      (%o6)                [-------, sin(---), -]
                            sqrt(2)       5    2
      (%i7) [cos (%pi/3), cos (10*%pi/3), tan (10*%pi/3),
             cos (sqrt(2)*%pi/3)];
                      1    1               sqrt(2) %pi
      (%o7)          [-, - -, sqrt(3), cos(-----------)]
                      2    2                    3

  Some identities are applied when %pi and %pi/2 are multiplied by an integer variable.

      (%i1) declare (n, integer, m, even)$
      (%i2) [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
             cos (%pi/2 * m)];
                                            m/2
      (%o2)                  [0, 1, 0, (- 1)   ]

  Categories: Trigonometric functions · Simplification flags and variables

Option variable: %iargs

  Default value: `true`

  When `%iargs` is `true`, trigonometric functions are simplified to hyperbolic functions when the argument is apparently a multiple of the imaginary unit %i.

  Even when the argument is demonstrably real, the simplification is applied; Maxima considers only whether the argument is a literal multiple of %i.

  Examples:

      (%i1) %iargs : false$
      (%i2) [sin (%i * x), cos (%i * x), tan (%i * x)];
      (%o2)           [sin(%i x), cos(%i x), tan(%i x)]
      (%i3) %iargs : true$
      (%i4) [sin (%i * x), cos (%i * x), tan (%i * x)];
      (%o4)           [%i sinh(x), cosh(x), %i tanh(x)]

  Even when the argument is demonstrably real, the simplification is applied.

      (%i1) declare (x, imaginary)$
      (%i2) [featurep (x, imaginary), featurep (x, real)];
      (%o2)                     [true, false]
      (%i3) sin (%i * x);
      (%o3)                      %i sinh(x)

  Categories: Trigonometric functions · Hyperbolic functions · Simplification flags and variables

Function: acos (x)

  - Arc Cosine.

  Categories: Trigonometric functions

Function: acosh (x)

  - Hyperbolic Arc Cosine.

  Categories: Hyperbolic functions

Function: acot (x)

  - Arc Cotangent.

  Categories: Trigonometric functions

Function: acoth (x)

  - Hyperbolic Arc Cotangent.

  Categories: Hyperbolic functions

Function: acsc (x)

  - Arc Cosecant.

  Categories: Trigonometric functions

Function: acsch (x)

  - Hyperbolic Arc Cosecant.

  Categories: Hyperbolic functions

Function: asec (x)

  - Arc Secant.

  Categories: Trigonometric functions

Function: asech (x)

  - Hyperbolic Arc Secant.

  Categories: Hyperbolic functions

Function: asin (x)

  - Arc Sine.

  Categories: Trigonometric functions

Function: asinh (x)

  - Hyperbolic Arc Sine.

  Categories: Hyperbolic functions

Function: atan (x)

  - Arc Tangent.

  Categories: Trigonometric functions

Function: atan2 (y, x)

  - yields the value of `atan(y/x)` in the interval `-%pi` to `%pi`.

  Categories: Trigonometric functions

Function: atanh (x)

  - Hyperbolic Arc Tangent.

  Categories: Hyperbolic functions

Package: atrig1

  The `atrig1` package contains several additional simplification rules for inverse trigonometric functions. Together with rules already known to Maxima, the following angles are fully implemented: `0`, `%pi/6`, `%pi/4`, `%pi/3`, and `%pi/2`. Corresponding angles in the other three quadrants are also available. Do `load(atrig1);` to use them.

  Categories: Trigonometric functions · Package atrig1

Function: cos (x)

  - Cosine.

  Categories: Trigonometric functions

Function: cosh (x)

  - Hyperbolic Cosine.

  Categories: Hyperbolic functions

Function: cot (x)

  - Cotangent.

  Categories: Trigonometric functions

Function: coth (x)

  - Hyperbolic Cotangent.

  Categories: Hyperbolic functions

Function: csc (x)

  - Cosecant.

  Categories: Trigonometric functions

Function: csch (x)

  - Hyperbolic Cosecant.

  Categories: Hyperbolic functions

Option variable: halfangles

  Default value: `false`

  When `halfangles` is `true`, trigonometric functions of arguments `expr/2` are simplified to functions of expr.

  For a real argument x in the interval `0 < x < 2*%pi` the sine of the half-angle simplifies to a simple formula:

                               sqrt(1 - cos(x))
                               ----------------
                                   sqrt(2)

  A complicated factor is needed to make this formula correct for all complex arguments z:

                 realpart(z)
           floor(-----------)
                    2 %pi
      (- 1)                   (1 - unit_step(- imagpart(z))

                                  realpart(z)            realpart(z)
                            floor(-----------) - ceiling(-----------)
                                     2 %pi                  2 %pi
                      ((- 1)                                          + 1))

  Maxima knows this factor and similar factors for the functions `sin`, `cos`, `sinh`, and `cosh`. For special values of the argument z these factors simplify accordingly.

  Examples:

      (%i1) halfangles:false;
      (%o1)                                false
      (%i2) sin(x/2);
                                              x
      (%o2)                               sin(-)
                                              2
      (%i3) halfangles:true;
      (%o3)                                true
      (%i4) sin(x/2);
                                                          x
                                                  floor(-----)
                                                        2 %pi
                            sqrt(1 - cos(x)) (- 1)
      (%o4)                 ----------------------------------
                                         sqrt(2)
      (%i5) assume(x>0, x<2*%pi)$
      (%i6) sin(x/2);
                                     sqrt(1 - cos(x))
      (%o6)                          ----------------
                                         sqrt(2)

  Categories: Trigonometric functions · Simplification flags and variables

Package: ntrig

  The `ntrig` package contains a set of simplification rules that are used to simplify trigonometric function whose arguments are of the form `f(n %pi/10)` where f is any of the functions `sin`, `cos`, `tan`, `csc`, `sec` and `cot`.

  Categories: Trigonometric functions · Package ntrig

Function: sec (x)

  - Secant.

  Categories: Trigonometric functions

Function: sech (x)

  - Hyperbolic Secant.

  Categories: Hyperbolic functions

Function: sin (x)

  - Sine.

  Categories: Trigonometric functions

Function: sinh (x)

  - Hyperbolic Sine.

  Categories: Hyperbolic functions

Function: tan (x)

  - Tangent.

  Categories: Trigonometric functions

Function: tanh (x)

  - Hyperbolic Tangent.

  Categories: Hyperbolic functions

Function: trigexpand (expr)

  Expands trigonometric and hyperbolic functions of sums of angles and of multiple angles occurring in expr. For best results, expr should be expanded. To enhance user control of simplification, this function expands only one level at a time, expanding sums of angles or multiple angles. To obtain full expansion into sines and cosines immediately, set the switch `trigexpand: true`.

  `trigexpand` is governed by the following global flags:

  `trigexpand`

    If `true` causes expansion of all expressions containing sin's and cos's occurring subsequently.

  `halfangles`

    If `true` causes half-angles to be simplified away.

  `trigexpandplus`

    Controls the "sum" rule for `trigexpand`, expansion of sums (e.g. `sin(x + y)`) will take place only if `trigexpandplus` is `true`.

  `trigexpandtimes`

    Controls the "product" rule for `trigexpand`, expansion of products (e.g. `sin(2 x)`) will take place only if `trigexpandtimes` is `true`.

  Examples:

      (%i1) x+sin(3*x)/sin(x),trigexpand=true,expand;
                               2           2
      (%o1)               - sin (x) + 3 cos (x) + x
      (%i2) trigexpand(sin(10*x+y));
      (%o2)          cos(10 x) sin(y) + sin(10 x) cos(y)

  Categories: Trigonometric functions · Simplification functions

Option variable: trigexpandplus

  Default value: `true`

  `trigexpandplus` controls the "sum" rule for `trigexpand`. Thus, when the `trigexpand` command is used or the `trigexpand` switch set to `true`, expansion of sums (e.g. `sin(x+y))` will take place only if `trigexpandplus` is `true`.

  Categories: Trigonometric functions · Simplification flags and variables

Option variable: trigexpandtimes

  Default value: `true`

  `trigexpandtimes` controls the "product" rule for `trigexpand`. Thus, when the `trigexpand` command is used or the `trigexpand` switch set to `true`, expansion of products (e.g. `sin(2*x)`) will take place only if `trigexpandtimes` is `true`.

  Categories: Trigonometric functions · Simplification flags and variables

Option variable: triginverses

  Default value: `true`

  `triginverses` controls the simplification of the composition of trigonometric and hyperbolic functions with their inverse functions.

  If `all`, both e.g. `atan(tan(x))` and `tan(atan(x))` simplify to x.

  If `true`, the `arcfun(fun(x))` simplification is turned off.

  If `false`, both the `arcfun(fun(x))` and `fun(arcfun(x))` simplifications are turned off.

  Categories: Trigonometric functions · Simplification flags and variables

Function: trigreduce
`trigreduce` (expr, x)
`trigreduce` (expr)

  Combines products and powers of trigonometric and hyperbolic sin's and cos's of x into those of multiples of x. It also tries to eliminate these functions when they occur in denominators. If x is omitted then all variables in expr are used.

  See also `poissimp`.

      (%i1) trigreduce(-sin(x)^2+3*cos(x)^2+x);
                     cos(2 x)      cos(2 x)   1        1
      (%o1)          -------- + 3 (-------- + -) + x - -
                        2             2       2        2

  Categories: Trigonometric functions · Simplification functions

Option variable: trigsign

  Default value: `true`

  When `trigsign` is `true`, it permits simplification of negative arguments to trigonometric functions. E.g., `sin(-x)` will become `-sin(x)` only if `trigsign` is `true`.

  Categories: Trigonometric functions · Simplification flags and variables

Function: trigsimp (expr)

  Employs the identities sin(x)^2 + cos(x)^2 = 1 and cosh(x)^2 - sinh(x)^2 = 1 to simplify expressions containing `tan`, `sec`, etc., to `sin`, `cos`, `sinh`, `cosh`.

  `trigreduce`, `ratsimp`, and `radcan` may be able to further simplify the result.

  `demo ("trgsmp.dem")` displays some examples of `trigsimp`.

  Categories: Trigonometric functions · Simplification functions

Function: trigrat (expr)

  Gives a canonical simplified quasilinear form of a trigonometrical expression; expr is a rational fraction of several `sin`, `cos` or `tan`, the arguments of them are linear forms in some variables (or kernels) and `%pi/n` (n integer) with integer coefficients. The result is a simplified fraction with numerator and denominator linear in `sin` and `cos`. Thus `trigrat` linearize always when it is possible.

      (%i1) trigrat(sin(3*a)/sin(a+%pi/3));
      (%o1)            sqrt(3) sin(2 a) + cos(2 a) - 1

  The following example is taken from Davenport, Siret, and Tournier, Calcul Formel, Masson (or in English, Addison-Wesley), section 1.5.5, Morley theorem.

      (%i1) c : %pi/3 - a - b$
      (%i2) bc : sin(a)*sin(3*c)/sin(a+b);
                                                %pi
                        sin(a) sin(3 (- b - a + ---))
                                                 3
      (%o2)             -----------------------------
                                 sin(b + a)
      (%i3) ba : bc, c=a, a=c;
                                               %pi
                          sin(3 a) sin(b + a - ---)
                                                3
      (%o3)               -------------------------
                                        %pi
                                sin(a - ---)
                                         3
      (%i4) ac2 : ba^2 + bc^2 - 2*bc*ba*cos(b);
               2         2         %pi
            sin (3 a) sin (b + a - ---)
                                    3
      (%o4) ---------------------------
                      2     %pi
                   sin (a - ---)
                             3
                                             %pi
       - (2 sin(a) sin(3 a) sin(3 (- b - a + ---)) cos(b)
                                              3
                   %pi            %pi
       sin(b + a - ---))/(sin(a - ---) sin(b + a))
                    3              3
            2       2              %pi
         sin (a) sin (3 (- b - a + ---))
                                    3
       + -------------------------------
                      2
                   sin (b + a)
      (%i5) trigrat (ac2);
      (%o5) - (sqrt(3) sin(4 b + 4 a) - cos(4 b + 4 a)
       - 2 sqrt(3) sin(4 b + 2 a) + 2 cos(4 b + 2 a)
       - 2 sqrt(3) sin(2 b + 4 a) + 2 cos(2 b + 4 a)
       + 4 sqrt(3) sin(2 b + 2 a) - 8 cos(2 b + 2 a) - 4 cos(2 b - 2 a)
       + sqrt(3) sin(4 b) - cos(4 b) - 2 sqrt(3) sin(2 b) + 10 cos(2 b)
       + sqrt(3) sin(4 a) - cos(4 a) - 2 sqrt(3) sin(2 a) + 10 cos(2 a)
       - 9)/4

  Categories: Trigonometric functions · Simplification functions

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 10.6 Random Numbers

Function: make_random_state
`make_random_state` (n)
`make_random_state` (s)
`make_random_state` (true)
`make_random_state` (false)

  A random state object represents the state of the random number generator. The state comprises 627 32-bit words.

  `make_random_state (n)` returns a new random state object created from an integer seed value equal to n modulo 2^32. n may be negative.

  `make_random_state (s)` returns a copy of the random state s.

  `make_random_state (true)` returns a new random state object, using the current computer clock time as the seed.

  `make_random_state (false)` returns a copy of the current state of the random number generator.

  Categories: Random numbers

Function: set_random_state (s)

  Copies s to the random number generator state.

  `set_random_state` always returns `done`.

  Categories: Random numbers

Function: random (x)

  Returns a pseudorandom number. If x is an integer, `random (x)` returns an integer from 0 through `x - 1` inclusive. If x is a floating point number, `random (x)` returns a nonnegative floating point number less than x. `random` complains with an error if x is neither an integer nor a float, or if x is not positive.

  The functions `make_random_state` and `set_random_state` maintain the state of the random number generator.

  The Maxima random number generator is an implementation of the Mersenne twister MT 19937.

  Examples:

      (%i1) s1: make_random_state (654321)$
      (%i2) set_random_state (s1);
      (%o2)                         done
      (%i3) random (1000);
      (%o3)                          768
      (%i4) random (9573684);
      (%o4)                        7657880
      (%i5) random (2^75);
      (%o5)                11804491615036831636390
      (%i6) s2: make_random_state (false)$
      (%i7) random (1.0);
      (%o7)                   .2310127244107132
      (%i8) random (10.0);
      (%o8)                   4.394553645870825
      (%i9) random (100.0);
      (%o9)                   32.28666704056853
      (%i10) set_random_state (s2);
      (%o10)                        done
      (%i11) random (1.0);
      (%o11)                  .2310127244107132
      (%i12) random (10.0);
      (%o12)                  4.394553645870825
      (%i13) random (100.0);
      (%o13)                  32.28666704056853

  Categories: Random numbers · Numerical methods

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Robert Dodier on April, 9 2015 using texi2html 1.76.