[ < ] [ > ]   [ << ] [ 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.

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
·

@ref{Category: 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
·

@ref{Category: 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.

·

@ref{Category: 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
·

@ref{Category: Mathematical functions}

Function: fix (x)

A synonym for entier (x).

·

@ref{Category: 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.

·

@ref{Category: Mathematical functions} · @ref{Category: Lists} · @ref{Category: 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.

·

@ref{Category: Mathematical functions} · @ref{Category: Lists} · @ref{Category: 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.

·

@ref{Category: 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.

·

@ref{Category: 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.

·

@ref{Category: 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.

·

@ref{Category: 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.

·

@ref{Category: 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

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

If cabs returns a noun form this most commonly is caused by some properties of the variables involved not being known:

(%i1) cabs (a+%i*b);
                                2    2
(%o1)                     sqrt(b  + a )
(%i2) declare(a,real,b,real);
(%o2)                         done
(%i3) cabs (a+%i*b);
                                2    2
(%o3)                     sqrt(b  + a )
(%i4) assume(a>0,b>0);
(%o4)                    [a > 0, b > 0]
(%i5) cabs (a+%i*b);
                                2    2
(%o5)                     sqrt(b  + a )

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))
·

@ref{Category: 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));
                               sin(1)
(%o3)                     atan(------)
                               cos(1)
(%i4) carg (exp (%pi * %i));
(%o4)                          %pi
(%i5) carg (exp (3/2 * %pi * %i));
                                %pi
(%o5)                         - ---
                                 2
(%i6) carg (17 * exp (2 * %i));
                            sin(2)
(%o6)                  atan(------) + %pi
                            cos(2)

If carg returns a noun form this most communly is caused by some properties of the variables involved not being known:

(%i1) carg (a+%i*b);
(%o1)                      atan2(b, a)
(%i2) declare(a,real,b,real);
(%o2)                         done
(%i3) carg (a+%i*b);
(%o3)                      atan2(b, a)
(%i4) assume(a>0,b>0);
(%o4)                    [a > 0, b > 0]
(%i5) carg (a+%i*b);
                                  b
(%o5)                        atan(-)
                                  a
·

@ref{Category: 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)                        yy + xx
·

@ref{Category: 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)
·

@ref{Category: 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
·

@ref{Category: Complex variables} · @ref{Category: 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
·

@ref{Category: 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
·

@ref{Category: 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).

·

@ref{Category: Gamma and factorial functions} · @ref{Category: 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)
·

@ref{Category: 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)!
·

@ref{Category: 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) [4, 77!, 0.3430658398165453 %i + 0.6529654964201667]
(%i4) [2.86b0!, 1.0b0+%i)!];
incorrect syntax: Missing ]
[2.86b0!, 1.0b0+%i)
                 ^

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) [0.3430658398165453 %i + 0.6529654964201667, 
         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.44668037931197, 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
·

@ref{Category: Gamma and factorial functions} · @ref{Category: Operators}

Option variable: factlim

Default value: 100000

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

·

@ref{Category: 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.

·

@ref{Category: 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!!.

·

@ref{Category: 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)
·

@ref{Category: Number theory}

Option variable: sumsplitfact

Default value: true

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

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

@ref{Category: Gamma and factorial functions} · @ref{Category: 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.

·

@ref{Category: Exponential and logarithm functions} · @ref{Category: 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
·

@ref{Category: Exponential and logarithm functions} · @ref{Category: 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
·

@ref{Category: Exponential and logarithm functions} · @ref{Category: 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))
·

@ref{Category: 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.248273182099423 - 6.113257028817991 %i
(%i5) li [3] (7);
(%o5)                        li (7)
                               3
(%i6) li [2] (7), numer;
(%o6)       1.248273182099423 - 6.113257028817991 %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.0, 0.2676526390827326, 0.5822405264650125, 
0.978469392930306, 1.644934066848226, 
2.190177011441645 - 0.7010261415046585 %i, 
2.37439527027248 - 1.2738062049196 %i, 
2.448686765338205 - 1.758084848210787 %i, 
2.467401100272339 - 2.177586090303601 %i]
(%i9) map (lambda ([x], li [3] (x)), L);
(%o9) [0.0, 0.2584613953442624, 0.537213192678042, 
0.8444258046482203, 1.2020569, 1.642866878950322
 - 0.07821473130035025 %i, 2.060877505514697
 - 0.2582419849982037 %i, 2.433418896388322
 - 0.4919260182322965 %i, 2.762071904015935
 - 0.7546938285978846 %i]
·

@ref{Category: 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.

·

@ref{Category: 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.

·

@ref{Category: Exponential and logarithm functions} · @ref{Category: Integral calculus} · @ref{Category: 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.

·

@ref{Category: Exponential and logarithm functions} · @ref{Category: Simplification flags and variables} · @ref{Category: 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)).

·

@ref{Category: Exponential and logarithm functions} · @ref{Category: 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)).

·

@ref{Category: 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.

When logexpand is set to all or super, the logarithm of a product expression simplifies to a summation of logarithms.

Examples:

When logexpand is true, log(a^b) simplifies to b*log(a).

(%i1) log(n^2), logexpand=true;
(%o1)                       2 log(n)

When logexpand is all, log(a*b) simplifies to log(a)+log(b).

(%i1) log(10*x), logexpand=all;
(%o1)                   log(x) + log(10)

When logexpand is super, log(a/b) simplifies to log(a)-log(b) for rational numbers a/b with a#1.

(%i1) log(a/(n + 1)), logexpand=super;
(%o1)                  log(a) - log(n + 1)

When logexpand is set to all or super, the logarithm of a product expression simplifies to a summation of logarithms.

(%i1) my_product : product (X(i), i, 1, n);
                             n
                           /===\
                            ! !
(%o1)                       ! !  X(i)
                            ! !
                           i = 1
(%i2) log(my_product), logexpand=all;
                          n
                         ====
                         \
(%o2)                     >    log(X(i))
                         /
                         ====
                         i = 1
(%i3) log(my_product), logexpand=super;
                          n
                         ====
                         \
(%o3)                     >    log(X(i))
                         /
                         ====
                         i = 1

When logexpand is false, these simplifications are disabled.

(%i1) logexpand : false $
(%i2) log(n^2);
                                  2
(%o2)                        log(n )
(%i3) log(10*x);
(%o3)                       log(10 x)
(%i4) log(a/(n + 1));
                                 a
(%o4)                      log(-----)
                               n + 1
(%i5) log ('product (X(i), i, 1, n));
                               n
                             /===\
                              ! !
(%o5)                    log( ! !  X(i))
                              ! !
                             i = 1
·

@ref{Category: Exponential and logarithm functions} · @ref{Category: 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.

·

@ref{Category: Exponential and logarithm functions} · @ref{Category: 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.

·

@ref{Category: Exponential and logarithm functions} · @ref{Category: Simplification flags and variables}

Function: plog (x)

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

·

@ref{Category: Exponential and logarithm functions} · @ref{Category: Complex variables}

Function: sqrt (x)

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

·

@ref{Category: 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.

·

@ref{Category: 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)   ]
·

@ref{Category: Trigonometric functions} · @ref{Category: 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)
·

@ref{Category: Trigonometric functions} · @ref{Category: Hyperbolic functions} · @ref{Category: Simplification flags and variables}

Function: acos (x)

- Arc Cosine.

·

@ref{Category: Trigonometric functions}

Function: acosh (x)

- Hyperbolic Arc Cosine.

·

@ref{Category: Hyperbolic functions}

Function: acot (x)

- Arc Cotangent.

·

@ref{Category: Trigonometric functions}

Function: acoth (x)

- Hyperbolic Arc Cotangent.

·

@ref{Category: Hyperbolic functions}

Function: acsc (x)

- Arc Cosecant.

·

@ref{Category: Trigonometric functions}

Function: acsch (x)

- Hyperbolic Arc Cosecant.

·

@ref{Category: Hyperbolic functions}

Function: asec (x)

- Arc Secant.

·

@ref{Category: Trigonometric functions}

Function: asech (x)

- Hyperbolic Arc Secant.

·

@ref{Category: Hyperbolic functions}

Function: asin (x)

- Arc Sine.

·

@ref{Category: Trigonometric functions}

Function: asinh (x)

- Hyperbolic Arc Sine.

·

@ref{Category: Hyperbolic functions}

Function: atan (x)

- Arc Tangent.

·

@ref{Category: Trigonometric functions}

Function: atan2 (y, x)

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

·

@ref{Category: Trigonometric functions}

Function: atanh (x)

- Hyperbolic Arc Tangent.

·

@ref{Category: 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.

·

@ref{Category: Trigonometric functions} · @ref{Category: Package atrig1}

Function: cos (x)

- Cosine.

·

@ref{Category: Trigonometric functions}

Function: cosh (x)

- Hyperbolic Cosine.

·

@ref{Category: Hyperbolic functions}

Function: cot (x)

- Cotangent.

·

@ref{Category: Trigonometric functions}

Function: coth (x)

- Hyperbolic Cotangent.

·

@ref{Category: Hyperbolic functions}

Function: csc (x)

- Cosecant.

·

@ref{Category: Trigonometric functions}

Function: csch (x)

- Hyperbolic Cosecant.

·

@ref{Category: 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$
(%i2) sin (x / 2);
                                 x
(%o2)                        sin(-)
                                 2
(%i3) halfangles : true$
(%i4) sin (x / 2);
                            x
                    floor(-----)
                          2 %pi
               (- 1)             sqrt(1 - cos(x))
(%o4)          ----------------------------------
                            sqrt(2)
(%i5) assume(x>0, x<2*%pi)$
(%i6) sin(x / 2);
                        sqrt(1 - cos(x))
(%o6)                   ----------------
                            sqrt(2)
·

@ref{Category: Trigonometric functions} · @ref{Category: 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.

·

@ref{Category: Trigonometric functions} · @ref{Category: Package ntrig}

Function: sec (x)

- Secant.

·

@ref{Category: Trigonometric functions}

Function: sech (x)

- Hyperbolic Secant.

·

@ref{Category: Hyperbolic functions}

Function: sin (x)

- Sine.

·

@ref{Category: Trigonometric functions}

Function: sinh (x)

- Hyperbolic Sine.

·

@ref{Category: Hyperbolic functions}

Function: tan (x)

- Tangent.

·

@ref{Category: Trigonometric functions}

Function: tanh (x)

- Hyperbolic Tangent.

·

@ref{Category: 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)
·

@ref{Category: Trigonometric functions} · @ref{Category: 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.

·

@ref{Category: Trigonometric functions} · @ref{Category: 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.

·

@ref{Category: Trigonometric functions} · @ref{Category: 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.

·

@ref{Category: Trigonometric functions} · @ref{Category: 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
·

@ref{Category: Trigonometric functions} · @ref{Category: 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.

·

@ref{Category: Trigonometric functions} · @ref{Category: 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.

·

@ref{Category: Trigonometric functions} · @ref{Category: 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
·

@ref{Category: Trigonometric functions} · @ref{Category: 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.

·

@ref{Category: Random numbers}

Function: set_random_state (s)

Copies s to the random number generator state.

set_random_state always returns done.

·

@ref{Category: 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)                  0.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)                 0.2310127244107132
(%i12) random (10.0);
(%o12)                  4.394553645870825
(%i13) random (100.0);
(%o13)                  32.28666704056853
·

@ref{Category: Random numbers} · @ref{Category: Numerical methods}


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

This document was generated by dpb build user on March, 28 2018 using texi2html 1.76.