1 @c -*- mode: texinfo -*-
3 * Functions for Numbers::
4 * Functions for Complex Numbers::
5 * Combinatorial Functions::
6 * Root Exponential and Logarithmic Functions::
7 * Trigonometric Functions::
11 @c -----------------------------------------------------------------------------
12 @node Functions for Numbers, Functions for Complex Numbers, , Elementary Functions
13 @section Functions for Numbers
14 @c -----------------------------------------------------------------------------
16 @c -----------------------------------------------------------------------------
18 @deffn {Function} abs (@var{z})
20 The @code{abs} function represents the mathematical absolute value function and
21 works for both numerical and symbolic values. If the argument, @var{z}, is a
22 real or complex number, @code{abs} returns the absolute value of @var{z}. If
23 possible, symbolic expressions using the absolute value function are
26 Maxima can differentiate, integrate and calculate limits for expressions
27 containing @code{abs}. The @code{abs_integrate} package further extends
28 Maxima's ability to calculate integrals involving the abs function. See
29 (%i12) in the examples below.
31 When applied to a list or matrix, @code{abs} automatically distributes over
32 the terms. Similarly, it distributes over both sides of an
33 equation. To alter this behaviour, see the variable @mrefdot{distribute_over}
35 See also @mrefdot{cabs}
39 Calculation of @code{abs} for real and complex numbers, including numerical
40 constants and various infinities. The first example shows how @code{abs}
41 distributes over the elements of a list.
44 @c abs([-4, 0, 1, 1+%i]);
45 @c abs((1+%i)*(1-%i));
47 @c abs([inf, infinity, minf]);
51 (%i1) abs([-4, 0, 1, 1+%i]);
52 (%o1) [4, 0, 1, sqrt(2)]
55 (%i2) abs((1+%i)*(1-%i));
64 (%i4) abs([inf, infinity, minf]);
69 Simplification of expressions containing @code{abs}:
93 (%i4) abs(conjugate(x));
98 Integrating and differentiating with the @code{abs} function. Note that more
99 integrals involving the @code{abs} function can be performed, if the
100 @code{abs_integrate} package is loaded. The last example shows the Laplace
101 transform of @code{abs}: see @mrefdot{laplace}
104 @c diff(x*abs(x),x),expand;
105 @c integrate(abs(x),x);
106 @c integrate(x*abs(x),x);
107 @c load("abs_integrate")$
108 @c integrate(x*abs(x),x);
109 @c integrate(abs(x),x,-2,%pi);
110 @c laplace(abs(x),x,s);
114 (%i1) diff(x*abs(x),x),expand;
118 (%i2) integrate(abs(x),x);
124 (%i3) integrate(x*abs(x),x);
131 (%i4) load("abs_integrate")$
133 (%i5) integrate(x*abs(x),x);
140 (%i6) integrate(abs(x),x,-2,%pi);
147 (%i7) laplace(abs(x),x,s);
155 @opencatbox{Categories:}
156 @category{Mathematical functions}
160 @c -----------------------------------------------------------------------------
162 @deffn {Function} ceiling (@var{x})
164 When @var{x} is a real number, return the least integer that
165 is greater than or equal to @var{x}.
167 If @var{x} is a constant expression (@code{10 * %pi}, for example),
168 @code{ceiling} evaluates @var{x} using big floating point numbers, and
169 applies @code{ceiling} to the resulting big float. Because @code{ceiling} uses
170 floating point evaluation, it's possible, although unlikely, that @code{ceiling}
171 could return an erroneous value for constant inputs. To guard against errors,
172 the floating point evaluation is done using three values for @mrefdot{fpprec}
174 For non-constant inputs, @code{ceiling} tries to return a simplified value.
175 Here are examples of the simplifications that @code{ceiling} knows about:
178 @c ceiling (ceiling (x));
179 @c ceiling (floor (x));
180 @c declare (n, integer)$
181 @c [ceiling (n), ceiling (abs (n)), ceiling (max (n, 6))];
182 @c assume (x > 0, x < 1)$
184 @c tex (ceiling (a));
188 (%i1) ceiling (ceiling (x));
192 (%i2) ceiling (floor (x));
195 (%i3) declare (n, integer)$
197 (%i4) [ceiling (n), ceiling (abs (n)), ceiling (max (n, 6))];
198 (%o4) [n, abs(n), max(6, n)]
200 (%i5) assume (x > 0, x < 1)$
206 (%i7) tex (ceiling (a));
207 $$\left \lceil a \right \rceil$$
212 The @code{ceiling} function distributes over lists, matrices and equations.
213 See @mrefdot{distribute_over}
215 Finally, for all inputs that are manifestly complex, @code{ceiling} returns
218 If the range of a function is a subset of the integers, it can be declared to
219 be @code{integervalued}. Both the @code{ceiling} and @mref{floor} functions
220 can use this information; for example:
223 @c declare (f, integervalued)$
225 @c ceiling (f(x) - 1);
228 (%i1) declare (f, integervalued)$
234 (%i3) ceiling (f(x) - 1);
242 @c unitfrac(r) := block([uf : [], q],
243 @c if not(ratnump(r)) then
244 @c error("unitfrac: argument must be a rational number"),
246 @c uf : cons(q : 1/ceiling(1/r), uf),
258 (%i1) unitfrac(r) := block([uf : [], q],
259 if not(ratnump(r)) then
260 error("unitfrac: argument must be a rational number"),
262 uf : cons(q : 1/ceiling(1/r), uf),
265 (%o1) unitfrac(r) := block([uf : [], q],
266 if not ratnump(r) then error("unitfrac: argument must be a rational number"
268 ), while r # 0 do (uf : cons(q : ----------, uf), r : r - q),
275 (%i2) unitfrac (9/10);
281 (%i3) apply ("+", %);
287 (%i4) unitfrac (-9/10);
293 (%i5) apply ("+", %);
299 (%i6) unitfrac (36/37);
301 (%o6) [-, -, -, --, ----]
305 (%i7) apply ("+", %);
312 @opencatbox{Categories:}
313 @category{Mathematical functions}
317 @c -----------------------------------------------------------------------------
319 @deffn {Function} entier (@var{x})
321 Returns the largest integer less than or equal to @var{x} where @var{x} is
322 numeric. @mref{fix} (as in @code{fixnum}) is a synonym for this, so
323 @code{fix(@var{x})} is precisely the same.
325 @opencatbox{Categories:}
326 @category{Mathematical functions}
330 @c -----------------------------------------------------------------------------
332 @deffn {Function} floor (@var{x})
334 When @var{x} is a real number, return the largest integer that is less than or
337 If @var{x} is a constant expression (@code{10 * %pi}, for example), @code{floor}
338 evaluates @var{x} using big floating point numbers, and applies @code{floor} to
339 the resulting big float. Because @code{floor} uses floating point evaluation,
340 it's possible, although unlikely, that @code{floor} could return an erroneous
341 value for constant inputs. To guard against errors, the floating point
342 evaluation is done using three values for @mrefdot{fpprec}
344 For non-constant inputs, @code{floor} tries to return a simplified value. Here
345 are examples of the simplifications that @code{floor} knows about:
348 @c floor (ceiling (x));
349 @c floor (floor (x));
350 @c declare (n, integer)$
351 @c [floor (n), floor (abs (n)), floor (min (n, 6))];
352 @c assume (x > 0, x < 1)$
358 (%i1) floor (ceiling (x));
362 (%i2) floor (floor (x));
365 (%i3) declare (n, integer)$
367 (%i4) [floor (n), floor (abs (n)), floor (min (n, 6))];
368 (%o4) [n, abs(n), min(6, n)]
370 (%i5) assume (x > 0, x < 1)$
376 (%i7) tex (floor (a));
377 $$\left \lfloor a \right \rfloor$$
382 The @code{floor} function distributes over lists, matrices and equations.
383 See @mrefdot{distribute_over}
385 Finally, for all inputs that are manifestly complex, @code{floor} returns
388 If the range of a function is a subset of the integers, it can be declared to
389 be @code{integervalued}. Both the @mref{ceiling} and @code{floor} functions
390 can use this information; for example:
393 @c declare (f, integervalued)$
395 @c ceiling (f(x) - 1);
398 (%i1) declare (f, integervalued)$
404 (%i3) ceiling (f(x) - 1);
409 @opencatbox{Categories:}
410 @category{Mathematical functions}
414 @c -----------------------------------------------------------------------------
416 @deffn {Function} fix (@var{x})
418 A synonym for @code{entier (@var{x})}.
420 @opencatbox{Categories:}
421 @category{Mathematical functions}
425 @c -----------------------------------------------------------------------------
427 @deffn {Function} hstep (@var{x})
428 The Heaviside unit step function, equal to 0 if @var{x} is negative,
429 equal to 1 if @var{x} is positive and equal to 1/2 if @var{x} is equal
432 If you want a unit step function that takes on the value of 0 at @var{x}
433 equal to zero, use @mrefdot{unit_step}
435 @opencatbox{Categories:}
436 @category{Laplace transform}
437 @category{Mathematical functions}
442 @c -----------------------------------------------------------------------------
444 @deffn {Function} lmax (@var{L})
446 When @var{L} is a list or a set, return @code{apply ('max, args (@var{L}))}.
447 When @var{L} is not a list or a set, signal an error.
448 See also @mref{lmin} and @mrefdot{max}
450 @opencatbox{Categories:}
451 @category{Mathematical functions}
457 @c -----------------------------------------------------------------------------
459 @deffn {Function} lmin (@var{L})
461 When @var{L} is a list or a set, return @code{apply ('min, args (@var{L}))}.
462 When @var{L} is not a list or a set, signal an error.
463 See also @mref{lmax} and @mrefdot{min}
465 @opencatbox{Categories:}
466 @category{Mathematical functions}
472 @c -----------------------------------------------------------------------------
474 @deffn {Function} max (@var{x_1}, @dots{}, @var{x_n})
476 Return a simplified value for the numerical maximum of the expressions @var{x_1}
477 through @var{x_n}. For an empty argument list, @code{max} yields @code{minf}.
479 The option variable @code{maxmin_effort} controls which simplification methods are
480 applied. Using the default value of @emph{twelve} for @code{maxmin_effort},
481 @code{max} uses @emph{all} available simplification methods. To to inhibit all
482 simplifications, set @code{maxmin_effort} to zero.
484 When @code{maxmin_effort} is one or more, for an explicit list of real numbers,
485 @code{max} returns a number.
487 Unless @code{max} needs to simplify a lengthy list of expressions, we suggest using
488 the default value of @code{maxmin_effort}. Setting @code{maxmin_effort} to zero
489 (no simplifications), will cause problems for some Maxima functions; accordingly,
490 generally @code{maxmin_effort} should be nonzero.
492 See also @mref{min}, @mrefdot{lmax}, and @mrefdot{lmin}.
496 In the first example, setting @code{maxmin_effort} to zero suppresses simplifications.
498 (%i1) block([maxmin_effort : 0], max(1,2,x,x, max(a,b)));
499 (%o1) max(1,2,max(a,b),x,x)
501 (%i2) block([maxmin_effort : 1], max(1,2,x,x, max(a,b)));
505 When @code{maxmin_effort} is two or more, @code{max} compares pairs of members:
507 (%i1) block([maxmin_effort : 1], max(x,x+1,x+3));
510 (%i2) block([maxmin_effort : 2], max(x,x+1,x+3));
514 Finally, when @code{maxmin_effort} is three or more, @code{max} compares triples
515 members and excludes those that are in between; for example
517 (%i1) block([maxmin_effort : 4], max(x, 2*x, 3*x, 4*x));
521 @opencatbox{Categories:}
522 @category{Mathematical functions}
527 @deffn {Function} min (@var{x_1}, @dots{}, @var{x_n})
529 Return a simplified value for the numerical minimum of the expressions @var{x_1}
530 through @var{x_n}. For an empty argument list, @code{minf} yields @code{inf}.
532 The option variable @code{maxmin_effort} controls which simplification methods are
533 applied. Using the default value of @emph{twelve} for @code{maxmin_effort},
534 @code{max} uses @emph{all} available simplification methods. To to inhibit all
535 simplifications, set @code{maxmin_effort} to zero.
537 When @code{maxmin_effort} is one or more, for an explicit list of real numbers,
538 @code{min} returns a number.
540 Unless @code{min} needs to simplify a lengthy list of expressions, we suggest using
541 the default value of @code{maxmin_effort}. Setting @code{maxmin_effort} to zero
542 (no simplifications), will cause problems for some Maxima functions; accordingly,
543 generally @code{maxmin_effort} should be nonzero.
545 See also @mref{max}, @mrefdot{lmax}, and @mrefdot{lmin}.
549 In the first example, setting @code{maxmin_effort} to zero suppresses simplifications.
551 (%i1) block([maxmin_effort : 0], min(1,2,x,x, min(a,b)));
552 (%o1) min(1,2,a,b,x,x)
554 (%i2) block([maxmin_effort : 1], min(1,2,x,x, min(a,b)));
558 When @code{maxmin_effort} is two or more, @code{min} compares pairs of members:
560 (%i1) block([maxmin_effort : 1], min(x,x+1,x+3));
563 (%i2) block([maxmin_effort : 2], min(x,x+1,x+3));
567 Finally, when @code{maxmin_effort} is three or more, @code{min} compares triples
568 members and excludes those that are in between; for example
570 (%i1) block([maxmin_effort : 4], min(x, 2*x, 3*x, 4*x));
574 @opencatbox{Categories:}
575 @category{Mathematical functions}
579 @c -----------------------------------------------------------------------------
581 @deffn {Function} round (@var{x})
583 When @var{x} is a real number, returns the closest integer to @var{x}.
584 Multiples of 1/2 are rounded to the nearest even integer. Evaluation of
585 @var{x} is similar to @mref{floor} and @mrefdot{ceiling}
587 The @code{round} function distributes over lists, matrices and equations.
588 See @mrefdot{distribute_over}
590 @opencatbox{Categories:}
591 @category{Mathematical functions}
595 @c -----------------------------------------------------------------------------
597 @deffn {Function} signum (@var{x})
599 For either real or complex numbers @var{x}, the signum function returns
600 0 if @var{x} is zero; for a nonzero numeric input @var{x}, the signum function
601 returns @code{x/abs(x)}.
603 For non-numeric inputs, Maxima attempts to determine the sign of the input.
604 When the sign is negative, zero, or positive, @code{signum} returns -1,0, 1,
605 respectively. For all other values for the sign, @code{signum} a simplified but
606 equivalent form. The simplifications include reflection (@code{signum(-x)}
607 gives @code{-signum(x)}) and multiplicative identity (@code{signum(x*y)} gives
608 @code{signum(x) * signum(y)}).
610 The @code{signum} function distributes over a list, a matrix, or an
611 equation. See @mref{sign} and @mrefdot{distribute_over}
613 @opencatbox{Categories:}
614 @category{Mathematical functions}
618 @c -----------------------------------------------------------------------------
620 @deffn {Function} truncate (@var{x})
622 When @var{x} is a real number, return the closest integer to @var{x} not
623 greater in absolute value than @var{x}. Evaluation of @var{x} is similar
624 to @mref{floor} and @mrefdot{ceiling}
626 The @code{truncate} function distributes over lists, matrices and equations.
627 See @mrefdot{distribute_over}
629 @opencatbox{Categories:}
630 @category{Mathematical functions}
634 @c -----------------------------------------------------------------------------
635 @node Functions for Complex Numbers, Combinatorial Functions, Functions for Numbers, Elementary Functions
636 @section Functions for Complex Numbers
637 @c -----------------------------------------------------------------------------
639 @c -----------------------------------------------------------------------------
641 @deffn {Function} cabs (@var{expr})
643 Calculates the absolute value of an expression representing a complex
644 number. Unlike the function @mrefcomma{abs} the @code{cabs} function always
645 decomposes its argument into a real and an imaginary part. If @code{x} and
646 @code{y} represent real variables or expressions, the @code{cabs} function
647 calculates the absolute value of @code{x + %i*y} as
653 @c cabs (exp (%pi * %i));
654 @c cabs (exp (3/2 * %pi * %i));
655 @c cabs (17 * exp (2 * %i));
667 (%i3) cabs (exp (%i));
671 (%i4) cabs (exp (%pi * %i));
675 (%i5) cabs (exp (3/2 * %pi * %i));
679 (%i6) cabs (17 * exp (2 * %i));
684 If @code{cabs} returns a noun form this most commonly is caused by
685 some properties of the variables involved not being known:
689 @c declare(a,real,b,real);
701 (%i2) declare(a,real,b,real);
710 (%i4) assume(a>0,b>0);
720 The @code{cabs} function can use known properties like symmetry properties of
721 complex functions to help it calculate the absolute value of an expression. If
722 such identities exist, they can be advertised to @code{cabs} using function
723 properties. The symmetries that @code{cabs} understands are: mirror symmetry,
724 conjugate function and complex characteristic.
726 @code{cabs} is a verb function and is not suitable for symbolic
727 calculations. For such calculations (including integration,
728 differentiation and taking limits of expressions containing absolute
729 values), use @mrefdot{abs}
731 The result of @code{cabs} can include the absolute value function,
732 @mrefcomma{abs} and the arc tangent, @mrefdot{atan2}
734 When applied to a list or matrix, @code{cabs} automatically distributes over
735 the terms. Similarly, it distributes over both sides of an equation.
737 For further ways to compute with complex numbers, see the functions
738 @mrefcomma{rectform} @mrefcomma{realpart} @mrefcomma{imagpart}@w{}
739 @mrefcomma{carg} @mref{conjugate} and @mrefdot{polarform}
743 Examples with @mref{sqrt} and @mrefdot{sin}
746 @c cabs(sqrt(1+%i*x));
747 @c cabs(sin(x+%i*y));
751 (%i1) cabs(sqrt(1+%i*x));
756 (%i2) cabs(sin(x+%i*y));
758 (%o2) sqrt(cos (x) sinh (y) + sin (x) cosh (y))
762 The error function, @mrefcomma{erf} has mirror symmetry, which is used here in
763 the calculation of the absolute value with a complex argument:
766 @c cabs(erf(x+%i*y));
770 (%i1) cabs(erf(x+%i*y));
772 (erf(%i y + x) - erf(%i y - x))
773 (%o1) sqrt(--------------------------------
776 (- erf(%i y + x) - erf(%i y - x))
777 - ----------------------------------)
782 Maxima knows complex identities for the Bessel functions, which allow
783 it to compute the absolute value for complex arguments. Here is an
784 example for @mrefdot{bessel_j}
787 @c cabs(bessel_j(1,%i));
791 (%i1) cabs(bessel_j(1,%i));
796 @opencatbox{Categories:}
797 @category{Complex variables}
801 @c -----------------------------------------------------------------------------
803 @deffn {Function} carg (@var{z})
805 Returns the complex argument of @var{z}. The complex argument is an angle
806 @code{theta} in @code{(-%pi, %pi]} such that @code{r exp (theta %i) = @var{z}}
807 where @code{r} is the magnitude of @var{z}.
809 @code{carg} is a computational function, not a simplifying function.
810 @c PROBABLY NEED TO EXPLAIN IMPLICATIONS OF ABOVE STATEMENT
812 See also @mref{abs} (complex magnitude), @mrefcomma{polarform}@w{}
813 @mrefcomma{rectform} @mrefcomma{realpart} and @mrefdot{imagpart}
821 @c carg (exp (%pi * %i));
822 @c carg (exp (3/2 * %pi * %i));
823 @c carg (17 * exp (2 * %i));
837 (%i3) carg (exp (%i));
843 (%i4) carg (exp (%pi * %i));
847 (%i5) carg (exp (3/2 * %pi * %i));
853 (%i6) carg (17 * exp (2 * %i));
855 (%o6) atan(------) + %pi
860 If @code{carg} returns a noun form this most commonly is caused by
861 some properties of the variables involved not being known:
865 @c declare(a,real,b,real);
876 (%i2) declare(a,real,b,real);
884 (%i4) assume(a>0,b>0);
895 @opencatbox{Categories:}
896 @category{Complex variables}
900 @c -----------------------------------------------------------------------------
902 @deffn {Function} conjugate (@var{x})
904 Returns the complex conjugate of @var{x}.
907 @c declare ([aa, bb], real, cc, complex, ii, imaginary);
908 @c conjugate (aa + bb*%i);
911 @c conjugate (xx + yy);
915 (%i1) declare ([aa, bb], real, cc, complex, ii, imaginary);
919 (%i2) conjugate (aa + bb*%i);
923 (%i3) conjugate (cc);
927 (%i4) conjugate (ii);
931 (%i5) conjugate (xx + yy);
936 @opencatbox{Categories:}
937 @category{Complex variables}
941 @c -----------------------------------------------------------------------------
943 @deffn {Function} imagpart (@var{expr})
945 Returns the imaginary part of the expression @var{expr}.
947 @code{imagpart} is a computational function, not a simplifying function.
948 @c PROBABLY NEED TO EXPLAIN IMPLICATIONS OF ABOVE STATEMENT
949 @c SEE ALSO SF BUG REPORT # 902290
951 See also @mrefcomma{abs} @mrefcomma{carg} @mrefcomma{polarform}@w{}
952 @mrefcomma{rectform} and @mrefdot{realpart}
957 @c imagpart (a+b*%i);
958 @c imagpart (1+sqrt(2)*%i);
960 @c imagpart (sqrt(2)*%i);
964 (%i1) imagpart (a+b*%i);
968 (%i2) imagpart (1+sqrt(2)*%i);
976 (%i4) imagpart (sqrt(2)*%i);
981 @opencatbox{Categories:}
982 @category{Complex variables}
988 @c -----------------------------------------------------------------------------
990 @deffn {Function} polarform (@var{expr})
992 Returns an expression @code{r %e^(%i theta)} equivalent to @var{expr},
993 such that @code{r} and @code{theta} are purely real.
998 @c polarform(a+b*%i);
1000 @c polarform(1+2*%i);
1004 (%i1) polarform(a+b*%i);
1006 (%o1) sqrt(b + a ) %e
1009 (%i2) polarform(1+%i);
1016 (%i3) polarform(1+2*%i);
1022 @opencatbox{Categories:}
1023 @category{Complex variables}
1024 @category{Exponential and logarithm functions}
1028 @c -----------------------------------------------------------------------------
1030 @deffn {Function} realpart (@var{expr})
1032 Returns the real part of @var{expr}. @code{realpart} and @mref{imagpart} will
1033 work on expressions involving trigonometric and hyperbolic functions,
1034 as well as square root, logarithm, and exponentiation.
1039 @c realpart (a+b*%i);
1040 @c realpart (1+sqrt(2)*%i);
1041 @c realpart (sqrt(2)*%i);
1046 (%i1) realpart (a+b*%i);
1050 (%i2) realpart (1+sqrt(2)*%i);
1054 (%i3) realpart (sqrt(2)*%i);
1063 @opencatbox{Categories:}
1064 @category{Complex variables}
1068 @c -----------------------------------------------------------------------------
1070 @deffn {Function} rectform (@var{expr})
1072 Returns an expression @code{a + b %i} equivalent to @var{expr},
1073 such that @var{a} and @var{b} are purely real.
1078 @c rectform(sqrt(2)*%e^(%i*%pi/4));
1079 @c rectform(sqrt(b^2+a^2)*%e^(%i*atan2(b, a)));
1080 @c rectform(sqrt(5)*%e^(%i*atan(2)));
1084 (%i1) rectform(sqrt(2)*%e^(%i*%pi/4));
1088 (%i2) rectform(sqrt(b^2+a^2)*%e^(%i*atan2(b, a)));
1092 (%i3) rectform(sqrt(5)*%e^(%i*atan(2)));
1097 @opencatbox{Categories:}
1098 @category{Complex variables}
1102 @c -----------------------------------------------------------------------------
1103 @node Combinatorial Functions, Root Exponential and Logarithmic Functions, Functions for Complex Numbers, Elementary Functions
1104 @section Combinatorial Functions
1105 @c -----------------------------------------------------------------------------
1107 @c -----------------------------------------------------------------------------
1109 @fnindex Double factorial
1110 @deffn {Operator} !!
1112 The double factorial operator.
1114 For an integer, float, or rational number @code{n}, @code{n!!} evaluates to the
1115 product @code{n (n-2) (n-4) (n-6) ... (n - 2 (k-1))} where @code{k} is equal to
1116 @code{entier (n/2)}, that is, the largest integer less than or equal to
1117 @code{n/2}. Note that this definition does not coincide with other published
1118 definitions for arguments which are not integers.
1119 @c REPORTED TO BUG TRACKER AS BUG # 1093138 !!!
1121 For an even (or odd) integer @code{n}, @code{n!!} evaluates to the product of
1122 all the consecutive even (or odd) integers from 2 (or 1) through @code{n}
1125 For an argument @code{n} which is not an integer, float, or rational, @code{n!!}
1126 yields a noun form @code{genfact (n, n/2, 2)}.
1127 @c n!! IS NEITHER SIMPLIFIED NOR EVALUATED IN THIS CASE
1128 @c -- MENTION THAT? OR TOO MUCH DETAIL ???
1130 @opencatbox{Categories:}
1131 @category{Gamma and factorial functions}
1132 @category{Operators}
1136 @c -----------------------------------------------------------------------------
1138 @deffn {Function} binomial (@var{x}, @var{y})
1140 The binomial coefficient @code{@var{x}!/(@var{y}! (@var{x} - @var{y})!)}.
1141 If @var{x} and @var{y} are integers, then the numerical value of the binomial
1142 coefficient is computed. If @var{y}, or @var{x - y}, is an integer, the
1143 binomial coefficient is expressed as a polynomial.
1148 @c binomial (11, 7);
1149 @c 11! / 7! / (11 - 7)!;
1151 @c binomial (x + 7, x);
1152 @c binomial (11, y);
1156 (%i1) binomial (11, 7);
1160 (%i2) 11! / 7! / (11 - 7)!;
1164 (%i3) binomial (x, 7);
1165 (x - 6) (x - 5) (x - 4) (x - 3) (x - 2) (x - 1) x
1166 (%o3) -------------------------------------------------
1170 (%i4) binomial (x + 7, x);
1171 (x + 1) (x + 2) (x + 3) (x + 4) (x + 5) (x + 6) (x + 7)
1172 (%o4) -------------------------------------------------------
1176 (%i5) binomial (11, y);
1177 (%o5) binomial(11, y)
1181 @opencatbox{Categories:}
1182 @category{Number theory}
1186 @c -----------------------------------------------------------------------------
1188 @deffn {Function} factcomb (@var{expr})
1190 Tries to combine the coefficients of factorials in @var{expr}
1191 with the factorials themselves by converting, for example, @code{(n + 1)*n!}
1192 into @code{(n + 1)!}.
1194 @mref{sumsplitfact} if set to @code{false} will cause @mref{minfactorial} to be
1195 applied after a @code{factcomb}.
1201 @c (n + 1)*(n + 1)*n!;
1203 @c sumsplitfact: not sumsplitfact;
1204 @c (n + 1)*(n + 1)*n!;
1213 (%i2) (n + 1)*(n + 1)*n!;
1219 (%o3) (n + 2)! - (n + 1)!
1222 (%i4) sumsplitfact: not sumsplitfact;
1226 (%i5) (n + 1)*(n + 1)*n!;
1232 (%o6) n (n + 1)! + (n + 1)!
1236 @opencatbox{Categories:}
1237 @category{Gamma and factorial functions}
1241 @c -----------------------------------------------------------------------------
1244 @deffn {Function} factorial
1245 @deffnx {Operator} !
1247 Represents the factorial function. Maxima treats @code{factorial (@var{x})}
1248 the same as @code{@var{x}!}.
1250 For any complex number @code{x}, except for negative integers, @code{x!} is
1251 defined as @code{gamma(x+1)}.
1253 For an integer @code{x}, @code{x!} simplifies to the product of the integers
1254 from 1 to @code{x} inclusive. @code{0!} simplifies to 1. For a real or complex
1255 number in float or bigfloat precision @code{x}, @code{x!} simplifies to the
1256 value of @code{gamma (x+1)}. For @code{x} equal to @code{n/2} where @code{n} is
1257 an odd integer, @code{x!} simplifies to a rational factor times
1258 @code{sqrt (%pi)} (since @code{gamma (1/2)} is equal to @code{sqrt (%pi)}).
1260 The option variables @mref{factlim} and @mref{gammalim} control the numerical
1261 evaluation of factorials for integer and rational arguments. The functions
1262 @mref{minfactorial} and @mref{factcomb} simplifies expressions containing
1265 The functions @mrefcomma{gamma} @mrefcomma{bffac} and @mref{cbffac} are
1266 varieties of the gamma function. @code{bffac} and @code{cbffac} are called
1267 internally by @code{gamma} to evaluate the gamma function for real and complex
1268 numbers in bigfloat precision.
1270 @mref{makegamma} substitutes @code{gamma} for factorials and related functions.
1272 Maxima knows the derivative of the factorial function and the limits for
1273 specific values like negative integers.
1275 The option variable @mref{factorial_expand} controls the simplification of
1276 expressions like @code{(n+x)!}, where @code{n} is an integer.
1278 See also @mrefdot{binomial}
1280 The factorial of an integer is simplified to an exact number unless the operand
1281 is greater than @code{factlim}. The factorial for real and complex numbers is
1282 evaluated in float or bigfloat precision.
1286 @c [0!, (7/2)!, 8!, 20!];
1287 @c [4,77!, (1.0+%i)!];
1288 @c [2.86b0!, (1.0b0+%i)!];
1296 (%i2) [0!, (7/2)!, 8!, 20!];
1298 (%o2) [1, -------------, 40320, 20!]
1302 (%i3) [4,77!, (1.0+%i)!];
1303 (%o3) [4, 77!, 0.3430658398165453 %i + 0.6529654964201667]
1306 (%i4) [2.86b0!, (1.0b0+%i)!];
1307 (%o4) [5.046635586910012b0, 3.430658398165454b-1 %i
1308 + 6.529654964201667b-1]
1312 The factorial of a known constant, or general expression is not simplified.
1313 Even so it may be possible to simplify the factorial after evaluating the
1317 @c [(%i + 1)!, %pi!, %e!, (cos(1) + sin(1))!];
1318 @c ev (%, numer, %enumer);
1322 (%i1) [(%i + 1)!, %pi!, %e!, (cos(1) + sin(1))!];
1323 (%o1) [(%i + 1)!, %pi!, %e!, (sin(1) + cos(1))!]
1326 (%i2) ev (%, numer, %enumer);
1327 (%o2) [0.3430658398165453 %i + 0.6529654964201667,
1328 7.188082728976031, 4.260820476357003, 1.227580202486819]
1332 @c REMOVING THIS EXAMPLE. IT IS NOT SPECIFIC FOR THE FACTORIAL FUNCTION:
1333 @c The factorial of an unbound symbol is not simplified.
1340 @c (%i1) kill (foo);
1346 Factorials are simplified, not evaluated.
1347 Thus @code{x!} may be replaced even in a quoted expression.
1350 @c '([0!, (7/2)!, 4.77!, 8!, 20!]);
1354 (%i1) '([0!, (7/2)!, 4.77!, 8!, 20!]);
1356 (%o1) [1, -------------, 81.44668037931197, 40320,
1358 2432902008176640000]
1362 Maxima knows the derivative of the factorial function.
1370 (%o1) x! psi (x + 1)
1375 The option variable @code{factorial_expand} controls expansion and
1376 simplification of expressions with the factorial function.
1379 @c (n+1)!/n!,factorial_expand:true;
1383 (%i1) (n+1)!/n!,factorial_expand:true;
1388 @opencatbox{Categories:}
1389 @category{Gamma and factorial functions}
1390 @category{Operators}
1396 @c -----------------------------------------------------------------------------
1398 @defvr {Option variable} factlim
1399 Default value: 100000
1401 @code{factlim} specifies the highest factorial which is
1402 automatically expanded. If it is -1 then all integers are expanded.
1404 @opencatbox{Categories:}
1405 @category{Gamma and factorial functions}
1409 @c -----------------------------------------------------------------------------
1410 @anchor{factorial_expand}
1411 @defvr {Option variable} factorial_expand
1412 Default value: false
1414 The option variable @code{factorial_expand} controls the simplification of
1415 expressions like @code{(x+n)!}, where @code{n} is an integer.
1416 See @mref{factorial} for an example.
1418 @opencatbox{Categories:}
1419 @category{Gamma and factorial functions}
1423 @c IS THIS DEFINITION CORRECT ??
1425 @c -----------------------------------------------------------------------------
1427 @deffn {Function} genfact (@var{x}, @var{y}, @var{z})
1429 Returns the generalized factorial, defined as
1430 @code{x (x-z) (x - 2 z) ... (x - (y - 1) z)}. Thus, when @var{x} is an integer,
1431 @code{genfact (x, x, 1) = x!} and @code{genfact (x, x/2, 2) = x!!}.
1433 @opencatbox{Categories:}
1434 @category{Gamma and factorial functions}
1438 @c -----------------------------------------------------------------------------
1439 @anchor{minfactorial}
1440 @deffn {Function} minfactorial (@var{expr})
1442 Examines @var{expr} for occurrences of two factorials
1443 which differ by an integer.
1444 @code{minfactorial} then turns one into a polynomial times the other.
1446 @c I CAN'T TELL WHAT THIS IS SUPPOSED TO MEAN. !!!
1447 @c minfactorial DOESN'T SEEM TO DO ANYTHING binomial DOESN'T DO BY ITSELF !!!
1448 @c LOOKING AT THE minfactorial CODE DOESN'T HELP !!!
1449 @c If exp involves binomial coefficients then they will be
1450 @c converted into ratios of factorials.
1454 @c minfactorial (%);
1464 (%i2) minfactorial (%);
1466 (%o2) ---------------
1471 @opencatbox{Categories:}
1472 @category{Number theory}
1476 @c -----------------------------------------------------------------------------
1477 @anchor{sumsplitfact}
1478 @defvr {Option variable} sumsplitfact
1479 Default value: @code{true}
1481 When @code{sumsplitfact} is @code{false},
1482 @c "IS APPLIED" -- UNDER WHAT CIRCUMSTANCES EXACTLY ??
1483 @mref{minfactorial} is applied after a @mrefdot{factcomb}
1489 @c sumsplitfact: not sumsplitfact ;
1511 (%i4) sumsplitfact: not sumsplitfact ;
1523 (%o6) ---------------
1528 @opencatbox{Categories:}
1529 @category{Gamma and factorial functions}
1530 @category{Simplification flags and variables}
1534 @c -----------------------------------------------------------------------------
1535 @node Root Exponential and Logarithmic Functions, Trigonometric Functions, Combinatorial Functions, Elementary Functions
1536 @section Root, Exponential and Logarithmic Functions
1537 @c -----------------------------------------------------------------------------
1539 @c -----------------------------------------------------------------------------
1540 @anchor{%e_to_numlog}
1541 @defvr {Option variable} %e_to_numlog
1542 Default value: @code{false}
1544 When @code{true}, @code{r} some rational number, and @code{x} some expression,
1545 @code{%e^(r*log(x))} will be simplified into @code{x^r} . It should be noted
1546 that the @code{radcan} command also does this transformation, and more
1547 complicated transformations of this ilk as well. The @code{logcontract}
1548 command "contracts" expressions containing @code{log}.
1550 @opencatbox{Categories:}
1551 @category{Exponential and logarithm functions}
1552 @category{Simplification flags and variables}
1556 @c -----------------------------------------------------------------------------
1558 @defvr {Option variable} %emode
1559 Default value: @code{true}
1561 When @code{%emode} is @code{true}, @code{%e^(%pi %i x)} is simplified as
1564 @code{%e^(%pi %i x)} simplifies to @code{cos (%pi x) + %i sin (%pi x)} if
1565 @code{x} is a floating point number, an integer, or a multiple of 1/2, 1/3, 1/4,
1566 or 1/6, and then further simplified.
1568 For other numerical @code{x}, @code{%e^(%pi %i x)} simplifies to
1569 @code{%e^(%pi %i y)} where @code{y} is @code{x - 2 k} for some integer @code{k}
1570 such that @code{abs(y) < 1}.
1572 When @code{%emode} is @code{false}, no special simplification of
1573 @code{%e^(%pi %i x)} is carried out.
1578 @c %e^(%pi*%i*216/144);
1579 @c %e^(%pi*%i*192/144);
1580 @c %e^(%pi*%i*180/144);
1581 @c %e^(%pi*%i*120/144);
1582 @c %e^(%pi*%i*121/144);
1590 (%i2) %e^(%pi*%i*1);
1594 (%i3) %e^(%pi*%i*216/144);
1598 (%i4) %e^(%pi*%i*192/144);
1600 (%o4) - ---------- - -
1604 (%i5) %e^(%pi*%i*180/144);
1606 (%o5) - ------- - -------
1610 (%i6) %e^(%pi*%i*120/144);
1616 (%i7) %e^(%pi*%i*121/144);
1624 @opencatbox{Categories:}
1625 @category{Exponential and logarithm functions}
1626 @category{Simplification flags and variables}
1630 @c -----------------------------------------------------------------------------
1632 @defvr {Option variable} %enumer
1633 Default value: @code{false}
1635 When @code{%enumer} is @code{true}, @code{%e} is replaced by its numeric value
1636 2.718@dots{} whenever @code{numer} is @code{true}.
1638 When @code{%enumer} is @code{false}, this substitution is carried out
1639 only if the exponent in @code{%e^x} evaluates to a number.
1641 See also @mref{ev} and @mrefdot{numer}
1647 @c %enumer: not %enumer;
1649 @c numer: not numer;
1668 (%i4) %enumer: not %enumer;
1676 (%i6) numer: not numer;
1681 (%o7) 5.43656365691809
1685 (%o8) 5.43656365691809
1690 (%o9) 2 2.718281828459045
1694 @opencatbox{Categories:}
1695 @category{Exponential and logarithm functions}
1696 @category{Evaluation flags}
1700 @c PROBABLY MORE TO BE SAID HERE
1702 @c -----------------------------------------------------------------------------
1704 @deffn {Function} exp (@var{x})
1706 Represents the exponential function. Instances of @code{exp (@var{x})} in input
1707 are simplified to @code{%e^@var{x}}; @code{exp} does not appear in simplified
1710 @code{demoivre} if @code{true} causes @code{%e^(a + b %i)} to simplify to
1711 @code{%e^(a (cos(b) + %i sin(b)))} if @code{b} is free of @code{%i}.
1712 See @mrefdot{demoivre}
1714 @code{%emode}, when @code{true}, causes @code{%e^(%pi %i x)} to be simplified.
1715 See @mrefdot{%emode}
1717 @code{%enumer}, when @code{true} causes @code{%e} to be replaced by
1718 2.718@dots{} whenever @code{numer} is @code{true}. See @mrefdot{%enumer}
1723 @c demoivre: not demoivre;
1732 (%i2) %e^(a + b*%i);
1737 (%i3) demoivre: not demoivre;
1741 (%i4) %e^(a + b*%i);
1743 (%o4) %e (%i sin(b) + cos(b))
1747 @opencatbox{Categories:}
1748 @category{Exponential and logarithm functions}
1753 @c -----------------------------------------------------------------------------
1755 @deffn {Function} li [@var{s}] (@var{z})
1757 Represents the polylogarithm function of order @var{s} and argument @var{z},
1758 defined by the infinite series
1761 <<<{\rm Li}_s \left(z\right) = \sum_{k=1}^\infty {z^k \over k^s}>>>,
1776 m4_mathdot(-\log(1 - z),-log(1-z))
1777 @code{li[2]} and @code{li[3]} are the
1778 dilogarithm and trilogarithm functions, respectively.
1780 When the order is 1, the polylogarithm simplifies to @code{- log (1 - z)}, which
1781 in turn simplifies to a numerical value if @var{z} is a real or complex floating
1782 point number or the @code{numer} evaluation flag is present.
1784 When the order is 2 or 3,
1785 the polylogarithm simplifies to a numerical value
1786 if @var{z} is a real floating point number
1787 or the @code{numer} evaluation flag is present.
1793 @c integrate ((log (1 - t)) / t, t, 0, x);
1800 @c li [2] (7), numer;
1802 @c li [2] (7), numer;
1803 @c L : makelist (i / 4.0, i, 0, 8);
1804 @c map (lambda ([x], li [2] (x)), L);
1805 @c map (lambda ([x], li [3] (x)), L);
1809 (%i1) assume (x > 0);
1813 (%i2) integrate ((log (1 - t)) / t, t, 0, x);
1832 (%o5) ---- - -------
1839 (%o6) %catalan %i - ----
1846 (%o7) ------------- + ---- + %catalan %i
1855 (%i9) li [2] (7), numer;
1856 (%o9) 1.2482731820994244 - 6.1132570288179915 %i
1864 (%i11) li [2] (7), numer;
1865 (%o11) 1.2482731820994244 - 6.1132570288179915 %i
1868 (%i12) L : makelist (i / 4.0, i, 0, 8);
1869 (%o12) [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
1872 (%i13) map (lambda ([x], li [2] (x)), L);
1873 (%o13) [0.0, 0.2676526390827326, 0.5822405264650125,
1874 0.978469392930306, 1.6449340668482264,
1875 2.1901770114416452 - 0.7010261415046585 %i,
1876 2.3743952702724798 - 1.2738062049196004 %i,
1877 2.448686765338203 - 1.7580848482107874 %i,
1878 2.4674011002723395 - 2.177586090303602 %i]
1881 (%i14) map (lambda ([x], li [3] (x)), L);
1882 (%o14) [0.0, 0.25846139579657335, 0.5372131936080402,
1883 0.8444258088622044, 1.2020569031595942,
1884 1.6428668813178295 - 0.07821473138972386 %i,
1885 2.0608775073202805 - 0.258241985293288 %i,
1886 2.433418898226189 - 0.49192601879440423 %i,
1887 2.762071906228924 - 0.7546938294602477 %i]
1891 @opencatbox{Categories:}
1892 @category{Exponential and logarithm functions}
1896 @c -----------------------------------------------------------------------------
1898 @deffn {Function} log (@var{x})
1900 Represents the natural (base @math{e}) logarithm of @var{x}.
1902 Maxima does not have a built-in function for the base 10 logarithm or other
1903 bases. @code{log10(x) := log(x) / log(10)} is a useful definition.
1905 Simplification and evaluation of logarithms is governed by several global flags:
1908 @item @code{logexpand}
1909 causes @code{log(a^b)} to become @code{b*log(a)}. If it is
1910 set to @code{all}, @code{log(a*b)} will also simplify to @code{log(a)+log(b)}.
1911 If it is set to @code{super}, then @code{log(a/b)} will also simplify to
1912 @code{log(a)-log(b)} for rational numbers @code{a/b}, @code{a#1}.
1913 (@code{log(1/b)}, for @code{b} integer, always simplifies.) If it is set to
1914 @code{false}, all of these simplifications will be turned off.
1916 @item @code{logsimp}
1917 if @code{false} then no simplification of @code{%e} to a power containing
1918 @code{log}'s is done.
1920 @item @code{lognegint}
1921 if @code{true} implements the rule @code{log(-n) -> log(n)+%i*%pi} for
1922 @code{n} a positive integer.
1924 @item @code{%e_to_numlog}
1925 when @code{true}, @code{r} some rational number, and @code{x} some expression,
1926 the expression @code{%e^(r*log(x))} will be simplified into @code{x^r}. It
1927 should be noted that the @code{radcan} command also does this transformation,
1928 and more complicated transformations of this as well. The @code{logcontract}
1929 command "contracts" expressions containing @code{log}.
1932 @opencatbox{Categories:}
1933 @category{Exponential and logarithm functions}
1937 @c -----------------------------------------------------------------------------
1939 @defvr {Option variable} logabs
1940 Default value: @code{false}
1942 When doing indefinite integration where logs are generated, e.g.
1943 @code{integrate(1/x,x)}, the answer is given in terms of @code{log(abs(...))}
1944 if @code{logabs} is @code{true}, but in terms of @code{log(...)} if
1945 @code{logabs} is @code{false}. For definite integration, the @code{logabs:true}
1946 setting is used, because here "evaluation" of the indefinite integral at the
1947 endpoints is often needed.
1949 @opencatbox{Categories:}
1950 @category{Exponential and logarithm functions}
1951 @category{Integral calculus}
1952 @category{Global flags}
1958 @c -----------------------------------------------------------------------------
1959 @deffn {Function} logarc (@var{expr})
1961 The function @code{logarc(@var{expr})} carries out the replacement of
1962 inverse circular and hyperbolic functions with equivalent logarithmic
1963 functions for an expression @var{expr} without setting the global
1964 variable @code{logarc}.
1966 @opencatbox{Categories:}
1967 @category{Exponential and logarithm functions}
1968 @category{Simplification flags and variables}
1969 @category{Simplification functions}
1974 @defvr {Option variable} logarc
1976 When the global variable @code{logarc} is @code{true},
1977 inverse circular and hyperbolic functions are replaced by
1978 equivalent logarithmic functions.
1979 The default value of @code{logarc} is @code{false}.
1981 @opencatbox{Categories:}
1982 @category{Exponential and logarithm functions}
1983 @category{Simplification flags and variables}
1984 @category{Simplification functions}
1988 @c -----------------------------------------------------------------------------
1989 @anchor{logconcoeffp}
1990 @defvr {Option variable} logconcoeffp
1991 Default value: @code{false}
1993 Controls which coefficients are
1994 contracted when using @code{logcontract}. It may be set to the name of a
1995 predicate function of one argument. E.g. if you like to generate
1996 SQRTs, you can do @code{logconcoeffp:'logconfun$
1997 logconfun(m):=featurep(m,integer) or ratnump(m)$} . Then
1998 @code{logcontract(1/2*log(x));} will give @code{log(sqrt(x))}.
2000 @opencatbox{Categories:}
2001 @category{Exponential and logarithm functions}
2002 @category{Simplification flags and variables}
2006 @c -----------------------------------------------------------------------------
2007 @anchor{logcontract}
2008 @deffn {Function} logcontract (@var{expr})
2010 Recursively scans the expression @var{expr}, transforming
2011 subexpressions of the form @code{a1*log(b1) + a2*log(b2) + c} into
2012 @code{log(ratsimp(b1^a1 * b2^a2)) + c}
2015 @c 2*(a*log(x) + 2*a*log(y))$
2019 (%i1) 2*(a*log(x) + 2*a*log(y))$
2021 (%i2) logcontract(%);
2027 The declaration @code{declare(n,integer)} causes
2028 @code{logcontract(2*a*n*log(x))} to simplify to @code{a*log(x^(2*n))}. The
2029 coefficients that "contract" in this manner are those such as the 2 and the
2030 @code{n} here which satisfy @code{featurep(coeff,integer)}. The user can
2031 control which coefficients are contracted by setting the option
2032 @code{logconcoeffp} to the name of a predicate function of one argument.
2033 E.g. if you like to generate SQRTs, you can do @code{logconcoeffp:'logconfun$
2034 logconfun(m):=featurep(m,integer) or ratnump(m)$} . Then
2035 @code{logcontract(1/2*log(x));} will give @code{log(sqrt(x))}.
2037 @opencatbox{Categories:}
2038 @category{Exponential and logarithm functions}
2042 @c -----------------------------------------------------------------------------
2044 @defvr {Option variable} logexpand
2045 Default value: @code{true}
2047 If @code{true}, that is the default value, causes @code{log(a^b)} to become
2048 @code{b*log(a)}. If it is set to @code{all}, @code{log(a*b)} will also simplify
2049 to @code{log(a)+log(b)}. If it is set to @code{super}, then @code{log(a/b)}
2050 will also simplify to @code{log(a)-log(b)} for rational numbers @code{a/b},
2051 @code{a#1}. (@code{log(1/b)}, for integer @code{b}, always simplifies.) If it
2052 is set to @code{false}, all of these simplifications will be turned off.
2054 When @code{logexpand} is set to @code{all} or @code{super},
2055 the logarithm of a product expression simplifies to a summation of logarithms.
2059 When @code{logexpand} is @code{true},
2060 @code{log(a^b)} simplifies to @code{b*log(a)}.
2063 @c log(n^2), logexpand=true;
2067 (%i1) log(n^2), logexpand=true;
2072 When @code{logexpand} is @code{all},
2073 @code{log(a*b)} simplifies to @code{log(a)+log(b)}.
2076 @c log(10*x), logexpand=all;
2080 (%i1) log(10*x), logexpand=all;
2081 (%o1) log(x) + log(10)
2085 When @code{logexpand} is @code{super},
2086 @code{log(a/b)} simplifies to @code{log(a)-log(b)}
2087 for rational numbers @code{a/b} with @code{a#1}.
2090 @c log(a/(n + 1)), logexpand=super;
2094 (%i1) log(a/(n + 1)), logexpand=super;
2095 (%o1) log(a) - log(n + 1)
2099 When @code{logexpand} is set to @code{all} or @code{super},
2100 the logarithm of a product expression simplifies to a summation of logarithms.
2103 @c my_product : product (X(i), i, 1, n);
2104 @c log(my_product), logexpand=all;
2105 @c log(my_product), logexpand=super;
2109 (%i1) my_product : product (X(i), i, 1, n);
2118 (%i2) log(my_product), logexpand=all;
2128 (%i3) log(my_product), logexpand=super;
2139 When @code{logexpand} is @code{false},
2140 these simplifications are disabled.
2143 @c logexpand : false $
2147 @c log ('product (X(i), i, 1, n));
2150 (%i1) logexpand : false $
2161 (%i4) log(a/(n + 1));
2167 (%i5) log ('product (X(i), i, 1, n));
2177 @opencatbox{Categories:}
2178 @category{Exponential and logarithm functions}
2179 @category{Simplification flags and variables}
2183 @c -----------------------------------------------------------------------------
2185 @defvr {Option variable} lognegint
2186 Default value: @code{false}
2188 If @code{true} implements the rule
2189 @code{log(-n) -> log(n)+%i*%pi} for @code{n} a positive integer.
2191 @opencatbox{Categories:}
2192 @category{Exponential and logarithm functions}
2193 @category{Simplification flags and variables}
2197 @c -----------------------------------------------------------------------------
2199 @defvr {Option variable} logsimp
2200 Default value: @code{true}
2202 If @code{false} then no simplification of @code{%e} to a
2203 power containing @code{log}'s is done.
2205 @opencatbox{Categories:}
2206 @category{Exponential and logarithm functions}
2207 @category{Simplification flags and variables}
2211 @c -----------------------------------------------------------------------------
2213 @deffn {Function} plog (@var{x})
2215 Represents the principal branch of the complex-valued natural
2216 logarithm with @code{-%pi < carg(@var{x}) <= +%pi} .
2218 @opencatbox{Categories:}
2219 @category{Exponential and logarithm functions}
2220 @category{Complex variables}
2224 @c -----------------------------------------------------------------------------
2226 @deffn {Function} sqrt (@var{x})
2228 The square root of @var{x}. It is represented internally by
2229 @code{@var{x}^(1/2)}. See also @mref{rootscontract} and @mrefdot{radexpand}
2231 @opencatbox{Categories:}
2232 @category{Mathematical functions}
2236 @c -----------------------------------------------------------------------------
2238 @node Trigonometric Functions, Random Numbers, Root Exponential and Logarithmic Functions, Elementary Functions
2239 @section Trigonometric Functions
2240 @c -----------------------------------------------------------------------------
2243 * Introduction to Trigonometric::
2244 * Functions and Variables for Trigonometric::
2247 @c -----------------------------------------------------------------------------
2248 @node Introduction to Trigonometric, Functions and Variables for Trigonometric, Trigonometric Functions, Trigonometric Functions
2249 @subsection Introduction to Trigonometric
2250 @c -----------------------------------------------------------------------------
2252 Maxima has many trigonometric functions defined. Not all trigonometric
2253 identities are programmed, but it is possible for the user to add many
2254 of them using the pattern matching capabilities of the system. The
2255 trigonometric functions defined in Maxima are: @mref{acos},
2256 @mref{acosh}, @mref{acot}, @mref{acoth}, @mref{acsc},
2257 @mref{acsch}, @mref{asec}, @mref{asech}, @mref{asin},
2258 @mref{asinh}, @mref{atan}, @mref{atanh}, @mref{cos},
2259 @mref{cosh}, @mref{cot}, @mref{coth}, @mref{csc}, @mref{csch},
2260 @mref{sec}, @mref{sech}, @mref{sin}, @mref{sinh}, @mref{tan},
2261 and @mref{tanh}. There are a number of commands especially for
2262 handling trigonometric functions, see @mref{trigexpand},
2263 @mref{trigreduce}, and the switch @mref{trigsign}. Two share
2264 packages extend the simplification rules built into Maxima,
2265 @mref{ntrig} and @mref{atrig1}. Do @code{describe(@var{command})}
2268 @opencatbox{Categories:}
2269 @category{Trigonometric functions}
2272 @c -----------------------------------------------------------------------------
2273 @node Functions and Variables for Trigonometric, , Introduction to Trigonometric, Trigonometric Functions
2274 @subsection Functions and Variables for Trigonometric
2275 @c -----------------------------------------------------------------------------
2278 * Trigonometric and Hyperbolic Functions::
2279 * Options Controlling Simplification::
2280 * Explicit Simplifications Using Identities::
2281 * Additional Functions::
2284 @node Trigonometric and Hyperbolic Functions, Options Controlling Simplification, Functions and Variables for Trigonometric, Functions and Variables for Trigonometric
2285 @subsubsection Trigonometric and Hyperbolic Functions
2287 @c Use this to make the same cross-references to variables that
2288 @c control simplification of trig (and hyperbolic) functions.
2289 @macro xreftrigvars{}
2290 For variables that control simplification @pxref{%piargs},
2291 @ref{%iargs}, @ref{halfangles}, @ref{triginverses}, and
2295 @c -----------------------------------------------------------------------------
2297 @deffn {Function} acos (@var{x})
2303 @opencatbox{Categories:}
2304 @category{Trigonometric functions}
2308 @c -----------------------------------------------------------------------------
2310 @deffn {Function} acosh (@var{x})
2312 -- Hyperbolic Arc Cosine.
2316 @opencatbox{Categories:}
2317 @category{Hyperbolic functions}
2321 @c -----------------------------------------------------------------------------
2323 @deffn {Function} acot (@var{x})
2329 @opencatbox{Categories:}
2330 @category{Trigonometric functions}
2334 @c -----------------------------------------------------------------------------
2336 @deffn {Function} acoth (@var{x})
2338 -- Hyperbolic Arc Cotangent.
2342 @opencatbox{Categories:}
2343 @category{Hyperbolic functions}
2347 @c -----------------------------------------------------------------------------
2349 @deffn {Function} acsc (@var{x})
2355 @opencatbox{Categories:}
2356 @category{Trigonometric functions}
2360 @c -----------------------------------------------------------------------------
2362 @deffn {Function} acsch (@var{x})
2364 -- Hyperbolic Arc Cosecant.
2368 @opencatbox{Categories:}
2369 @category{Hyperbolic functions}
2373 @c -----------------------------------------------------------------------------
2375 @deffn {Function} asec (@var{x})
2381 @opencatbox{Categories:}
2382 @category{Trigonometric functions}
2386 @c -----------------------------------------------------------------------------
2388 @deffn {Function} asech (@var{x})
2390 -- Hyperbolic Arc Secant.
2394 @opencatbox{Categories:}
2395 @category{Hyperbolic functions}
2399 @c -----------------------------------------------------------------------------
2401 @deffn {Function} asin (@var{x})
2407 @opencatbox{Categories:}
2408 @category{Trigonometric functions}
2412 @c -----------------------------------------------------------------------------
2414 @deffn {Function} asinh (@var{x})
2416 -- Hyperbolic Arc Sine.
2420 @opencatbox{Categories:}
2421 @category{Hyperbolic functions}
2425 @c -----------------------------------------------------------------------------
2427 @deffn {Function} atan (@var{x})
2431 See also @mref{atan2}.
2435 @opencatbox{Categories:}
2436 @category{Trigonometric functions}
2440 @c -----------------------------------------------------------------------------
2442 @deffn {Function} atan2 (@var{y}, @var{x})
2444 -- yields the value of
2445 m4_math(<<<\tan^{-1}(y/x)>>>, atan(y/x))
2451 consideration the quadrant of the point
2452 m4_mathdot(<<<(x,y)>>>, <<<(x,y)>>>)
2454 Along the branch cut with @math{y = 0} and @math{x < 0}, @code{atan2}
2455 is continuous with the second quadrant.
2456 See also @mref{atan}.
2460 @opencatbox{Categories:}
2461 @category{Trigonometric functions}
2465 @c -----------------------------------------------------------------------------
2467 @deffn {Function} atanh (@var{x})
2469 -- Hyperbolic Arc Tangent.
2473 @opencatbox{Categories:}
2474 @category{Hyperbolic functions}
2478 @c -----------------------------------------------------------------------------
2480 @deffn {Function} cos (@var{x})
2486 @opencatbox{Categories:}
2487 @category{Trigonometric functions}
2491 @c -----------------------------------------------------------------------------
2493 @deffn {Function} cosh (@var{x})
2495 -- Hyperbolic Cosine.
2499 @opencatbox{Categories:}
2500 @category{Hyperbolic functions}
2504 @c -----------------------------------------------------------------------------
2506 @deffn {Function} cot (@var{x})
2512 @opencatbox{Categories:}
2513 @category{Trigonometric functions}
2517 @c -----------------------------------------------------------------------------
2519 @deffn {Function} coth (@var{x})
2521 -- Hyperbolic Cotangent.
2525 @opencatbox{Categories:}
2526 @category{Hyperbolic functions}
2530 @c -----------------------------------------------------------------------------
2532 @deffn {Function} csc (@var{x})
2538 @opencatbox{Categories:}
2539 @category{Trigonometric functions}
2543 @c -----------------------------------------------------------------------------
2545 @deffn {Function} csch (@var{x})
2547 -- Hyperbolic Cosecant.
2551 @opencatbox{Categories:}
2552 @category{Hyperbolic functions}
2556 @c -----------------------------------------------------------------------------
2558 @deffn {Function} sec (@var{x})
2564 @opencatbox{Categories:}
2565 @category{Trigonometric functions}
2569 @c -----------------------------------------------------------------------------
2571 @deffn {Function} sech (@var{x})
2573 -- Hyperbolic Secant.
2577 @opencatbox{Categories:}
2578 @category{Hyperbolic functions}
2582 @c -----------------------------------------------------------------------------
2584 @deffn {Function} sin (@var{x})
2590 @opencatbox{Categories:}
2591 @category{Trigonometric functions}
2595 @c -----------------------------------------------------------------------------
2597 @deffn {Function} sinh (@var{x})
2603 @opencatbox{Categories:}
2604 @category{Hyperbolic functions}
2608 @c -----------------------------------------------------------------------------
2610 @deffn {Function} tan (@var{x})
2616 @opencatbox{Categories:}
2617 @category{Trigonometric functions}
2621 @c -----------------------------------------------------------------------------
2623 @deffn {Function} tanh (@var{x})
2625 -- Hyperbolic Tangent.
2629 @opencatbox{Categories:}
2630 @category{Hyperbolic functions}
2634 @unmacro xreftrigvars
2636 @node Options Controlling Simplification, Explicit Simplifications Using Identities, Trigonometric and Hyperbolic Functions, Functions and Variables for Trigonometric
2637 @subsubsection Options Controlling Simplification
2638 @c -----------------------------------------------------------------------------
2640 @defvr {Option variable} %piargs
2641 Default value: @code{true}
2643 When @code{%piargs} is @code{true},
2644 trigonometric functions are simplified to algebraic constants
2645 when the argument is an integer multiple
2647 m4_mathcomma(\pi,%pi)
2648 m4_mathcomma(\pi/2,%pi/2)
2649 m4_mathcomma(\pi/4,%pi/4)
2651 m4_mathdot(\pi/6,%pi/6)
2653 @c @math{\pi}, @math{\pi/2}, @math{\pi/3}, @math{\pi/4}, or @math{\pi/6}.
2656 @c @math{%pi}, @math{%pi/2}, @math{%pi/3}, @math{%pi/4}, or @math{%pi/6}.
2659 Maxima knows some identities which can be applied when
2660 m4_mathcomma(\pi,%pi)
2663 @c Maxima knows some identities which can be applied when @math{\pi}, etc.,
2666 @c Maxima knows some identities which can be applied when @math{%pi}, etc.,
2668 are multiplied by an integer variable (that is, a symbol declared to be
2675 @c [sin (%pi), sin (%pi/2), sin (%pi/3)];
2676 @c [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2678 @c [sin (%pi), sin (%pi/2), sin (%pi/3)];
2679 @c [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2680 @c [cos (%pi/3), cos (10*%pi/3), tan (10*%pi/3),
2681 @c cos (sqrt(2)*%pi/3)];
2684 (%i1) %piargs : false$
2686 (%i2) [sin (%pi), sin (%pi/2), sin (%pi/3)];
2688 (%o2) [sin(%pi), sin(---), sin(---)]
2692 (%i3) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2694 (%o3) [sin(---), sin(---), sin(---)]
2697 (%i4) %piargs : true$
2699 (%i5) [sin (%pi), sin (%pi/2), sin (%pi/3)];
2701 (%o5) [0, 1, -------]
2705 (%i6) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2707 (%o6) [-------, sin(---), -]
2711 (%i7) [cos (%pi/3), cos (10*%pi/3), tan (10*%pi/3),
2712 cos (sqrt(2)*%pi/3)];
2714 (%o7) [-, - -, sqrt(3), cos(-----------)]
2719 Some identities are applied when
2722 m4_math(\pi/2,%pi/2)
2724 multiplied by an integer variable.
2726 @c Some identities are applied when @math{\pi} and @math{\pi/2} are multiplied by
2727 @c an integer variable.
2730 @c Some identities are applied when @math{%pi} and @math{%pi/2} are multiplied by
2731 @c an integer variable.
2735 @c declare (n, integer, m, even)$
2736 @c [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
2737 @c cos (%pi/2 * m)];
2740 (%i1) declare (n, integer, m, even)$
2742 (%i2) [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
2745 (%o2) [0, 1, 0, (- 1) ]
2749 @opencatbox{Categories:}
2750 @category{Trigonometric functions}
2751 @category{Simplification flags and variables}
2755 @c -----------------------------------------------------------------------------
2757 @defvr {Option variable} %iargs
2758 Default value: @code{true}
2760 When @code{%iargs} is @code{true},
2761 trigonometric functions are simplified to hyperbolic functions
2762 when the argument is apparently a multiple of the imaginary
2766 @c when the argument is apparently a multiple of the imaginary unit @math{i}.
2769 @c when the argument is apparently a multiple of the imaginary unit @math{%i}.
2772 Even when the argument is demonstrably real, the simplification is applied;
2773 Maxima considers only whether the argument is a literal multiple
2777 @c Maxima considers only whether the argument is a literal multiple of @math{i}.
2780 @c Maxima considers only whether the argument is a literal multiple of @math{%i}.
2787 @c [sin (%i * x), cos (%i * x), tan (%i * x)];
2789 @c [sin (%i * x), cos (%i * x), tan (%i * x)];
2792 (%i1) %iargs : false$
2794 (%i2) [sin (%i * x), cos (%i * x), tan (%i * x)];
2795 (%o2) [sin(%i x), cos(%i x), tan(%i x)]
2797 (%i3) %iargs : true$
2799 (%i4) [sin (%i * x), cos (%i * x), tan (%i * x)];
2800 (%o4) [%i sinh(x), cosh(x), %i tanh(x)]
2804 Even when the argument is demonstrably real, the simplification is applied.
2807 @c declare (x, imaginary)$
2808 @c [featurep (x, imaginary), featurep (x, real)];
2812 (%i1) declare (x, imaginary)$
2814 (%i2) [featurep (x, imaginary), featurep (x, real)];
2823 @opencatbox{Categories:}
2824 @category{Trigonometric functions}
2825 @category{Hyperbolic functions}
2826 @category{Simplification flags and variables}
2830 @c -----------------------------------------------------------------------------
2832 @defvr {Option variable} halfangles
2833 Default value: @code{false}
2835 When @code{halfangles} is @code{true}, trigonometric functions of arguments
2836 @code{@var{expr}/2} are simplified to functions of @var{expr}.
2838 For a real argument @math{x} in the interval
2839 m4_mathcomma(<<<0 \le x < 2\pi>>>, 0 <= x < 2*%pi)
2840 m4_math(<<<\sin{x\over 2}>>>, sin(x/2))
2841 simplifies to a simple formula:
2843 {\sqrt{1-\cos x}\over\sqrt{2}},
2851 A complicated factor is needed to make this formula correct for all complex
2852 arguments @math{z = x+iy}:
2854 (-1)^{\lfloor{x/(2\pi)}\rfloor}
2855 \left[1-\rm{unit\_step}(-y)
2856 \left(1+(-1)^{\lfloor{x/(2\pi)}\rfloor - \lceil{x/(2\pi)}\rceil}\right)\right]
2860 floor(-----) floor(-----) - ceiling(-----)
2862 (- 1) (1 - ((- 1) + 1)
2867 Maxima knows this factor and similar factors for the functions @code{sin},
2868 @code{cos}, @code{sinh}, and @code{cosh}. For special values of the argument
2869 @math{z} these factors simplify accordingly.
2874 @c halfangles : false$
2876 @c halfangles : true$
2878 @c assume(x>0, x<2*%pi)$
2882 (%i1) halfangles : false$
2889 (%i3) halfangles : true$
2895 (- 1) sqrt(1 - cos(x))
2896 (%o4) ----------------------------------
2899 (%i5) assume(x>0, x<2*%pi)$
2903 (%o6) ----------------
2908 @opencatbox{Categories:}
2909 @category{Trigonometric functions}
2910 @category{Simplification flags and variables}
2914 @c -----------------------------------------------------------------------------
2916 @defvr {Option variable} trigsign
2917 Default value: @code{true}
2919 When @code{trigsign} is @code{true}, it permits simplification of negative
2920 arguments to trigonometric functions. E.g.,
2921 m4_math(\sin(-x),@code{sin(-x)})
2924 m4_math(-\sin x, @code{-sin(x)})
2925 only if @code{trigsign} is @code{true}.
2927 @opencatbox{Categories:}
2928 @category{Trigonometric functions}
2929 @category{Simplification flags and variables}
2934 @node Explicit Simplifications Using Identities, Additional Functions, Options Controlling Simplification, Functions and Variables for Trigonometric
2935 @subsubsection Explicit Simplifications Using Identities
2936 @c NEEDS CLARIFICATION AND EXAMPLES
2938 @c -----------------------------------------------------------------------------
2940 @deffn {Function} trigexpand (@var{expr})
2942 Expands trigonometric and hyperbolic functions of
2943 sums of angles and of multiple angles occurring in @var{expr}. For best
2944 results, @var{expr} should be expanded. To enhance user control of
2945 simplification, this function expands only one level at a time,
2946 expanding sums of angles or multiple angles. To obtain full expansion
2947 into sines and cosines immediately, set the switch @code{trigexpand: true}.
2949 @code{trigexpand} is governed by the following global flags:
2952 @item @mref{trigexpand}
2953 If @code{true} causes expansion of all
2954 expressions containing sin's and cos's occurring subsequently.
2955 @item @mref{halfangles}
2956 If @code{true} causes half-angles to be simplified
2958 @item @mref{trigexpandplus}
2959 Controls the "sum" rule for @code{trigexpand},
2960 expansion of sums (e.g. @code{sin(x + y)}) will take place only if
2961 @code{trigexpandplus} is @code{true}.
2962 @item @mref{trigexpandtimes}
2963 Controls the "product" rule for @code{trigexpand},
2964 expansion of products (e.g. @code{sin(2 x)}) will take place only if
2965 @code{trigexpandtimes} is @code{true}.
2971 @c x+sin(3*x)/sin(x),trigexpand=true,expand;
2972 @c trigexpand(sin(10*x+y));
2976 (%i1) x+sin(3*x)/sin(x),trigexpand=true,expand;
2978 (%o1) - sin (x) + 3 cos (x) + x
2981 (%i2) trigexpand(sin(10*x+y));
2982 (%o2) cos(10 x) sin(y) + sin(10 x) cos(y)
2986 @opencatbox{Categories:}
2987 @category{Trigonometric functions}
2988 @category{Simplification functions}
2992 @c -----------------------------------------------------------------------------
2993 @anchor{trigexpandplus}
2994 @defvr {Option variable} trigexpandplus
2995 Default value: @code{true}
2997 @code{trigexpandplus} controls the "sum" rule for
2998 @mref{trigexpand}. Thus, when the @mref{trigexpand} command is used or the
2999 @mref{trigexpand} switch set to @code{true}, expansion of sums
3000 (e.g. @code{sin(x+y))} will take place only if @code{trigexpandplus} is
3003 @opencatbox{Categories:}
3004 @category{Trigonometric functions}
3005 @category{Simplification flags and variables}
3009 @c -----------------------------------------------------------------------------
3010 @anchor{trigexpandtimes}
3011 @defvr {Option variable} trigexpandtimes
3012 Default value: @code{true}
3014 @code{trigexpandtimes} controls the "product" rule for @mref{trigexpand}.
3015 Thus, when the @mref{trigexpand} command is used or the @mref{trigexpand}
3016 switch set to @code{true}, expansion of products (e.g. @code{sin(2*x)})
3017 will take place only if @code{trigexpandtimes} is @code{true}.
3019 @opencatbox{Categories:}
3020 @category{Trigonometric functions}
3021 @category{Simplification flags and variables}
3025 @c -----------------------------------------------------------------------------
3026 @anchor{triginverses}
3027 @defvr {Option variable} triginverses
3028 Default value: @code{true}
3030 @code{triginverses} controls the simplification of the
3031 composition of trigonometric and hyperbolic functions with their inverse
3034 If @code{all}, both e.g. @code{atan(tan(@var{x}))}
3035 and @code{tan(atan(@var{x}))} simplify to @var{x}.
3037 If @code{true}, the @code{@var{arcfun}(@var{fun}(@var{x}))}
3038 simplification is turned off.
3040 If @code{false}, both the
3041 @code{@var{arcfun}(@var{fun}(@var{x}))} and
3042 @code{@var{fun}(@var{arcfun}(@var{x}))}
3043 simplifications are turned off.
3045 @opencatbox{Categories:}
3046 @category{Trigonometric functions}
3047 @category{Simplification flags and variables}
3051 @c -----------------------------------------------------------------------------
3053 @deffn {Function} trigreduce @
3054 @fname{trigreduce} (@var{expr}, @var{x}) @
3055 @fname{trigreduce} (@var{expr})
3057 Combines products and powers of trigonometric
3058 and hyperbolic sin's and cos's of @var{x} into those of multiples of @var{x}.
3059 It also tries to eliminate these functions when they occur in
3060 denominators. If @var{x} is omitted then all variables in @var{expr} are used.
3062 See also @mref{poissimp}.
3065 @c trigreduce(-sin(x)^2+3*cos(x)^2+x);
3069 (%i1) trigreduce(-sin(x)^2+3*cos(x)^2+x);
3070 cos(2 x) cos(2 x) 1 1
3071 (%o1) -------- + 3 (-------- + -) + x - -
3078 @c The behavior was changed in order to avoid calling expand in the core
3079 @c simplifier (trigi.lisp rev 1.31)
3080 @c See http://www.math.utexas.edu/pipermail/maxima/2008/010919.html.
3082 @c The trigonometric simplification routines will use declared
3083 @c information in some simple cases. Declarations about variables are
3084 @c used as follows, e.g.
3087 @c declare(j, integer, e, even, o, odd)$
3088 @c sin(x + (e + 1/2)*%pi);
3089 @c sin(x + (o + 1/2)*%pi);
3092 @c (%i1) declare(j, integer, e, even, o, odd)$
3093 @c (%i2) sin(x + (e + 1/2)*%pi);
3095 @c (%i3) sin(x + (o + 1/2)*%pi);
3099 @opencatbox{Categories:}
3100 @category{Trigonometric functions}
3101 @category{Simplification functions}
3105 @c -----------------------------------------------------------------------------
3107 @deffn {Function} trigsimp (@var{expr})
3110 Employs the identities
3111 m4_math(<<<\sin\left(x\right)^2 + \cos\left(x\right)^2 = 1>>>,
3112 <<<sin(x)^2+cos(x)^2 = 1>>>)
3114 m4_math(<<<\cosh\left(x\right)^2 - \sinh\left(x\right)^2 = 1>>>,
3115 <<<cosh(x)^2-sinh(x)^2 = 1>>>)
3119 @c $\sin\left(x\right)^2 + \cos\left(x\right)^2 = 1$
3123 @c $\cosh\left(x\right)^2 - \sinh\left(x\right)^2 = 1$
3125 simplify expressions containing @code{tan}, @code{sec},
3126 etc., to @code{sin}, @code{cos}, @code{sinh}, @code{cosh}.
3129 @c Employs the identities @math{sin(x)^2 + cos(x)^2 = 1} and
3130 @c @math{cosh(x)^2 - sinh(x)^2 = 1} to simplify expressions containing @code{tan},
3131 @c @code{sec}, etc., to @code{sin}, @code{cos}, @code{sinh}, @code{cosh}.
3134 @mref{trigreduce}, @mref{ratsimp}, and @mref{radcan} may be
3135 able to further simplify the result.
3137 @code{demo ("trgsmp.dem")} displays some examples of @code{trigsimp}.
3138 @c MERGE EXAMPLES INTO THIS ITEM
3140 @opencatbox{Categories:}
3141 @category{Trigonometric functions}
3142 @category{Simplification functions}
3146 @c NEEDS CLARIFICATION
3148 @c -----------------------------------------------------------------------------
3150 @deffn {Function} trigrat (@var{expr})
3152 Gives a canonical simplified quasilinear form of a trigonometrical expression;
3153 @var{expr} is a rational fraction of several @code{sin}, @code{cos} or
3154 @code{tan}, the arguments of them are linear forms in some variables (or
3155 kernels) and @code{%pi/@var{n}} (@var{n} integer) with integer coefficients.
3156 The result is a simplified fraction with numerator and denominator linear in
3157 @code{sin} and @code{cos}. Thus @code{trigrat} linearize always when it is
3161 @c trigrat(sin(3*a)/sin(a+%pi/3));
3165 (%i1) trigrat(sin(3*a)/sin(a+%pi/3));
3166 (%o1) sqrt(3) sin(2 a) + cos(2 a) - 1
3170 The following example is taken from
3171 Davenport, Siret, and Tournier, @i{Calcul Formel}, Masson (or in English,
3172 Addison-Wesley), section 1.5.5, Morley theorem.
3175 @c c : %pi/3 - a - b$
3176 @c bc : sin(a)*sin(3*c)/sin(a+b);
3177 @c ba : bc, c=a, a=c;
3178 @c ac2 : ba^2 + bc^2 - 2*bc*ba*cos(b);
3182 (%i1) c : %pi/3 - a - b$
3184 (%i2) bc : sin(a)*sin(3*c)/sin(a+b);
3186 sin(a) sin(3 (- b - a + ---))
3188 (%o2) -----------------------------
3192 (%i3) ba : bc, c=a, a=c;
3194 sin(3 a) sin(b + a - ---)
3196 (%o3) -------------------------
3202 (%i4) ac2 : ba^2 + bc^2 - 2*bc*ba*cos(b);
3204 sin (3 a) sin (b + a - ---)
3206 (%o4) ---------------------------
3211 - (2 sin(a) sin(3 a) sin(3 (- b - a + ---)) cos(b)
3214 sin(b + a - ---))/(sin(a - ---) sin(b + a))
3217 sin (a) sin (3 (- b - a + ---))
3219 + -------------------------------
3224 (%i5) trigrat (ac2);
3225 (%o5) - (sqrt(3) sin(4 b + 4 a) - cos(4 b + 4 a)
3226 - 2 sqrt(3) sin(4 b + 2 a) + 2 cos(4 b + 2 a)
3227 - 2 sqrt(3) sin(2 b + 4 a) + 2 cos(2 b + 4 a)
3228 + 4 sqrt(3) sin(2 b + 2 a) - 8 cos(2 b + 2 a) - 4 cos(2 b - 2 a)
3229 + sqrt(3) sin(4 b) - cos(4 b) - 2 sqrt(3) sin(2 b) + 10 cos(2 b)
3230 + sqrt(3) sin(4 a) - cos(4 a) - 2 sqrt(3) sin(2 a) + 10 cos(2 a)
3235 @opencatbox{Categories:}
3236 @category{Trigonometric functions}
3237 @category{Simplification functions}
3242 @node Additional Functions, , Explicit Simplifications Using Identities, Functions and Variables for Trigonometric
3243 @subsubsection Additional Functions
3244 @c IS THIS DESCRIPTION ACCURATE ??
3245 @c LET'S BE EXPLICIT ABOUT EXACTLY WHAT ARE THE RULES IMPLEMENTED BY THIS PACKAGE
3247 @c -----------------------------------------------------------------------------
3249 @defvr {Package} atrig1
3251 The @code{atrig1} package contains several additional simplification rules
3252 for inverse trigonometric functions. Together with rules
3253 already known to Maxima, the following angles are fully implemented:
3255 m4_mathcomma(\pi/6,%pi/6)
3256 m4_mathcomma(\pi/4,%pi/4)
3257 m4_mathcomma(\pi/3,%pi/3)
3259 m4_mathdot(\pi/2,%pi/2)
3260 Corresponding angles in the other three quadrants are also available.
3261 Do @code{load("atrig1");} to use them.
3263 @opencatbox{Categories:}
3264 @category{Trigonometric functions}
3265 @category{Package atrig1}
3269 @c IS THIS DESCRIPTION ACCURATE ??
3270 @c LET'S BE EXPLICIT ABOUT EXACTLY WHAT ARE THE RULES IMPLEMENTED BY THIS PACKAGE
3272 @c -----------------------------------------------------------------------------
3274 @defvr {Package} ntrig
3276 The @code{ntrig} package contains a set of simplification rules that are
3277 used to simplify trigonometric function whose arguments are of the form
3278 @code{@var{f}(@var{n} %pi/10)} where @var{f} is any of the functions
3279 @code{sin}, @code{cos}, @code{tan}, @code{csc}, @code{sec} and @code{cot}.
3280 @c NEED TO LOAD THIS PACKAGE ??
3282 @opencatbox{Categories:}
3283 @category{Trigonometric functions}
3284 @category{Package ntrig}
3288 @c -----------------------------------------------------------------------------
3290 @node Random Numbers, , Trigonometric Functions, Elementary Functions
3291 @section Random Numbers
3292 @c -----------------------------------------------------------------------------
3294 @c -----------------------------------------------------------------------------
3295 @anchor{make_random_state}
3296 @deffn {Function} make_random_state @
3297 @fname{make_random_state} (@var{n}) @
3298 @fname{make_random_state} (@var{s}) @
3299 @fname{make_random_state} (true) @
3300 @fname{make_random_state} (false)
3302 @c OMIT THIS FOR NOW. SEE COMMENT BELOW.
3303 @c @defunx make_random_state (@var{a})
3305 A random state object represents the state of the random number generator.
3306 The state comprises 627 32-bit words.
3308 @code{make_random_state (@var{n})} returns a new random state object
3309 created from an integer seed value equal to @var{n} modulo 2^32.
3310 @var{n} may be negative.
3312 @c OMIT THIS FOR NOW. NOT SURE HOW THIS IS SUPPOSED TO WORK.
3313 @c @code{make_random_state (@var{a})} returns a new random state object
3314 @c created from an array @var{a}, which must be a Lisp array of 32 unsigned bytes.
3316 @code{make_random_state (@var{s})} returns a copy of the random state @var{s}.
3318 @code{make_random_state (true)} returns a new random state object,
3319 using the current computer clock time as the seed.
3321 @code{make_random_state (false)} returns a copy of the current state
3322 of the random number generator.
3324 @opencatbox{Categories:}
3325 @category{Random numbers}
3329 @c -----------------------------------------------------------------------------
3330 @anchor{set_random_state}
3331 @deffn {Function} set_random_state (@var{s})
3333 Copies @var{s} to the random number generator state.
3335 @code{set_random_state} always returns @code{done}.
3337 @opencatbox{Categories:}
3338 @category{Random numbers}
3342 @c -----------------------------------------------------------------------------
3344 @deffn {Function} random (@var{x})
3346 Returns a pseudorandom number. If @var{x} is an integer,
3347 @code{random (@var{x})} returns an integer from 0 through @code{@var{x} - 1}
3348 inclusive. If @var{x} is a floating point number, @code{random (@var{x})}
3349 returns a nonnegative floating point number less than @var{x}. @code{random}
3350 complains with an error if @var{x} is neither an integer nor a float, or if
3351 @var{x} is not positive.
3353 The functions @code{make_random_state} and @code{set_random_state}
3354 maintain the state of the random number generator.
3356 The Maxima random number generator is an implementation of the Mersenne twister
3362 @c s1: make_random_state (654321)$
3363 @c set_random_state (s1);
3365 @c random (9573684);
3367 @c s2: make_random_state (false)$
3371 @c set_random_state (s2);
3377 (%i1) s1: make_random_state (654321)$
3379 (%i2) set_random_state (s1);
3383 (%i3) random (1000);
3387 (%i4) random (9573684);
3391 (%i5) random (2^75);
3392 (%o5) 11804491615036831636390
3394 (%i6) s2: make_random_state (false)$
3397 (%o7) 0.2310127244107132
3400 (%i8) random (10.0);
3401 (%o8) 4.3945536458708245
3404 (%i9) random (100.0);
3405 (%o9) 32.28666704056853
3408 (%i10) set_random_state (s2);
3412 (%i11) random (1.0);
3413 (%o11) 0.2310127244107132
3416 (%i12) random (10.0);
3417 (%o12) 4.3945536458708245
3420 (%i13) random (100.0);
3421 (%o13) 32.28666704056853
3425 @opencatbox{Categories:}
3426 @category{Random numbers}
3427 @category{Numerical methods}