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 -----------------------------------------------------------------------------
2289 @deffn {Function} acos (@var{x})
2293 @opencatbox{Categories:}
2294 @category{Trigonometric functions}
2298 @c -----------------------------------------------------------------------------
2300 @deffn {Function} acosh (@var{x})
2302 -- Hyperbolic Arc Cosine.
2304 @opencatbox{Categories:}
2305 @category{Hyperbolic functions}
2309 @c -----------------------------------------------------------------------------
2311 @deffn {Function} acot (@var{x})
2315 @opencatbox{Categories:}
2316 @category{Trigonometric functions}
2320 @c -----------------------------------------------------------------------------
2322 @deffn {Function} acoth (@var{x})
2324 -- Hyperbolic Arc Cotangent.
2326 @opencatbox{Categories:}
2327 @category{Hyperbolic functions}
2331 @c -----------------------------------------------------------------------------
2333 @deffn {Function} acsc (@var{x})
2337 @opencatbox{Categories:}
2338 @category{Trigonometric functions}
2342 @c -----------------------------------------------------------------------------
2344 @deffn {Function} acsch (@var{x})
2346 -- Hyperbolic Arc Cosecant.
2348 @opencatbox{Categories:}
2349 @category{Hyperbolic functions}
2353 @c -----------------------------------------------------------------------------
2355 @deffn {Function} asec (@var{x})
2359 @opencatbox{Categories:}
2360 @category{Trigonometric functions}
2364 @c -----------------------------------------------------------------------------
2366 @deffn {Function} asech (@var{x})
2368 -- Hyperbolic Arc Secant.
2370 @opencatbox{Categories:}
2371 @category{Hyperbolic functions}
2375 @c -----------------------------------------------------------------------------
2377 @deffn {Function} asin (@var{x})
2381 @opencatbox{Categories:}
2382 @category{Trigonometric functions}
2386 @c -----------------------------------------------------------------------------
2388 @deffn {Function} asinh (@var{x})
2390 -- Hyperbolic Arc Sine.
2392 @opencatbox{Categories:}
2393 @category{Hyperbolic functions}
2397 @c -----------------------------------------------------------------------------
2399 @deffn {Function} atan (@var{x})
2403 See also @mref{atan2}.
2405 @opencatbox{Categories:}
2406 @category{Trigonometric functions}
2410 @c -----------------------------------------------------------------------------
2412 @deffn {Function} atan2 (@var{y}, @var{x})
2414 -- yields the value of
2415 m4_math(<<<\tan^{-1}(y/x)>>>, atan(y/x))
2421 consideration the quadrant of the point
2422 m4_mathdot(<<<(x,y)>>>, <<<(x,y)>>>)
2424 Along the branch cut with @math{y = 0} and @math{x < 0}, @code{atan2}
2425 is continuous with the second quadrant.
2426 See also @mref{atan}.
2428 @opencatbox{Categories:}
2429 @category{Trigonometric functions}
2433 @c -----------------------------------------------------------------------------
2435 @deffn {Function} atanh (@var{x})
2437 -- Hyperbolic Arc Tangent.
2439 @opencatbox{Categories:}
2440 @category{Hyperbolic functions}
2444 @c -----------------------------------------------------------------------------
2446 @deffn {Function} cos (@var{x})
2450 @opencatbox{Categories:}
2451 @category{Trigonometric functions}
2455 @c -----------------------------------------------------------------------------
2457 @deffn {Function} cosh (@var{x})
2459 -- Hyperbolic Cosine.
2461 @opencatbox{Categories:}
2462 @category{Hyperbolic functions}
2466 @c -----------------------------------------------------------------------------
2468 @deffn {Function} cot (@var{x})
2472 @opencatbox{Categories:}
2473 @category{Trigonometric functions}
2477 @c -----------------------------------------------------------------------------
2479 @deffn {Function} coth (@var{x})
2481 -- Hyperbolic Cotangent.
2483 @opencatbox{Categories:}
2484 @category{Hyperbolic functions}
2488 @c -----------------------------------------------------------------------------
2490 @deffn {Function} csc (@var{x})
2494 @opencatbox{Categories:}
2495 @category{Trigonometric functions}
2499 @c -----------------------------------------------------------------------------
2501 @deffn {Function} csch (@var{x})
2503 -- Hyperbolic Cosecant.
2505 @opencatbox{Categories:}
2506 @category{Hyperbolic functions}
2510 @c -----------------------------------------------------------------------------
2512 @deffn {Function} sec (@var{x})
2516 @opencatbox{Categories:}
2517 @category{Trigonometric functions}
2521 @c -----------------------------------------------------------------------------
2523 @deffn {Function} sech (@var{x})
2525 -- Hyperbolic Secant.
2527 @opencatbox{Categories:}
2528 @category{Hyperbolic functions}
2532 @c -----------------------------------------------------------------------------
2534 @deffn {Function} sin (@var{x})
2538 @opencatbox{Categories:}
2539 @category{Trigonometric functions}
2543 @c -----------------------------------------------------------------------------
2545 @deffn {Function} sinh (@var{x})
2549 @opencatbox{Categories:}
2550 @category{Hyperbolic functions}
2554 @c -----------------------------------------------------------------------------
2556 @deffn {Function} tan (@var{x})
2560 @opencatbox{Categories:}
2561 @category{Trigonometric functions}
2565 @c -----------------------------------------------------------------------------
2567 @deffn {Function} tanh (@var{x})
2569 -- Hyperbolic Tangent.
2571 @opencatbox{Categories:}
2572 @category{Hyperbolic functions}
2577 @node Options Controlling Simplification, Explicit Simplifications Using Identities, Trigonometric and Hyperbolic Functions, Functions and Variables for Trigonometric
2578 @subsubsection Options Controlling Simplification
2579 @c -----------------------------------------------------------------------------
2581 @defvr {Option variable} %piargs
2582 Default value: @code{true}
2584 When @code{%piargs} is @code{true},
2585 trigonometric functions are simplified to algebraic constants
2586 when the argument is an integer multiple
2588 m4_mathcomma(\pi,%pi)
2589 m4_mathcomma(\pi/2,%pi/2)
2590 m4_mathcomma(\pi/4,%pi/4)
2592 m4_mathdot(\pi/6,%pi/6)
2594 @c @math{\pi}, @math{\pi/2}, @math{\pi/3}, @math{\pi/4}, or @math{\pi/6}.
2597 @c @math{%pi}, @math{%pi/2}, @math{%pi/3}, @math{%pi/4}, or @math{%pi/6}.
2600 Maxima knows some identities which can be applied when
2601 m4_mathcomma(\pi,%pi)
2604 @c Maxima knows some identities which can be applied when @math{\pi}, etc.,
2607 @c Maxima knows some identities which can be applied when @math{%pi}, etc.,
2609 are multiplied by an integer variable (that is, a symbol declared to be
2616 @c [sin (%pi), sin (%pi/2), sin (%pi/3)];
2617 @c [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2619 @c [sin (%pi), sin (%pi/2), sin (%pi/3)];
2620 @c [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2621 @c [cos (%pi/3), cos (10*%pi/3), tan (10*%pi/3),
2622 @c cos (sqrt(2)*%pi/3)];
2625 (%i1) %piargs : false$
2627 (%i2) [sin (%pi), sin (%pi/2), sin (%pi/3)];
2629 (%o2) [sin(%pi), sin(---), sin(---)]
2633 (%i3) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2635 (%o3) [sin(---), sin(---), sin(---)]
2638 (%i4) %piargs : true$
2640 (%i5) [sin (%pi), sin (%pi/2), sin (%pi/3)];
2642 (%o5) [0, 1, -------]
2646 (%i6) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2648 (%o6) [-------, sin(---), -]
2652 (%i7) [cos (%pi/3), cos (10*%pi/3), tan (10*%pi/3),
2653 cos (sqrt(2)*%pi/3)];
2655 (%o7) [-, - -, sqrt(3), cos(-----------)]
2660 Some identities are applied when
2663 m4_math(\pi/2,%pi/2)
2665 multiplied by an integer variable.
2667 @c Some identities are applied when @math{\pi} and @math{\pi/2} are multiplied by
2668 @c an integer variable.
2671 @c Some identities are applied when @math{%pi} and @math{%pi/2} are multiplied by
2672 @c an integer variable.
2676 @c declare (n, integer, m, even)$
2677 @c [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
2678 @c cos (%pi/2 * m)];
2681 (%i1) declare (n, integer, m, even)$
2683 (%i2) [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
2686 (%o2) [0, 1, 0, (- 1) ]
2690 @opencatbox{Categories:}
2691 @category{Trigonometric functions}
2692 @category{Simplification flags and variables}
2696 @c -----------------------------------------------------------------------------
2698 @defvr {Option variable} %iargs
2699 Default value: @code{true}
2701 When @code{%iargs} is @code{true},
2702 trigonometric functions are simplified to hyperbolic functions
2703 when the argument is apparently a multiple of the imaginary
2707 @c when the argument is apparently a multiple of the imaginary unit @math{i}.
2710 @c when the argument is apparently a multiple of the imaginary unit @math{%i}.
2713 Even when the argument is demonstrably real, the simplification is applied;
2714 Maxima considers only whether the argument is a literal multiple
2718 @c Maxima considers only whether the argument is a literal multiple of @math{i}.
2721 @c Maxima considers only whether the argument is a literal multiple of @math{%i}.
2728 @c [sin (%i * x), cos (%i * x), tan (%i * x)];
2730 @c [sin (%i * x), cos (%i * x), tan (%i * x)];
2733 (%i1) %iargs : false$
2735 (%i2) [sin (%i * x), cos (%i * x), tan (%i * x)];
2736 (%o2) [sin(%i x), cos(%i x), tan(%i x)]
2738 (%i3) %iargs : true$
2740 (%i4) [sin (%i * x), cos (%i * x), tan (%i * x)];
2741 (%o4) [%i sinh(x), cosh(x), %i tanh(x)]
2745 Even when the argument is demonstrably real, the simplification is applied.
2748 @c declare (x, imaginary)$
2749 @c [featurep (x, imaginary), featurep (x, real)];
2753 (%i1) declare (x, imaginary)$
2755 (%i2) [featurep (x, imaginary), featurep (x, real)];
2764 @opencatbox{Categories:}
2765 @category{Trigonometric functions}
2766 @category{Hyperbolic functions}
2767 @category{Simplification flags and variables}
2771 @c -----------------------------------------------------------------------------
2773 @defvr {Option variable} halfangles
2774 Default value: @code{false}
2776 When @code{halfangles} is @code{true}, trigonometric functions of arguments
2777 @code{@var{expr}/2} are simplified to functions of @var{expr}.
2779 For a real argument @math{x} in the interval
2780 m4_mathcomma(<<<0 \le x < 2\pi>>>, 0 <= x < 2*%pi)
2781 m4_math(<<<\sin{x\over 2}>>>, sin(x/2))
2782 simplifies to a simple formula:
2784 {\sqrt{1-\cos x}\over\sqrt{2}},
2792 A complicated factor is needed to make this formula correct for all complex
2793 arguments @math{z = x+iy}:
2795 (-1)^{\lfloor{x/(2\pi)}\rfloor}
2796 \left[1-\rm{unit\_step}(-y)
2797 \left(1+(-1)^{\lfloor{x/(2\pi)}\rfloor - \lceil{x/(2\pi)}\rceil}\right)\right]
2801 floor(-----) floor(-----) - ceiling(-----)
2803 (- 1) (1 - ((- 1) + 1)
2808 Maxima knows this factor and similar factors for the functions @code{sin},
2809 @code{cos}, @code{sinh}, and @code{cosh}. For special values of the argument
2810 @math{z} these factors simplify accordingly.
2815 @c halfangles : false$
2817 @c halfangles : true$
2819 @c assume(x>0, x<2*%pi)$
2823 (%i1) halfangles : false$
2830 (%i3) halfangles : true$
2836 (- 1) sqrt(1 - cos(x))
2837 (%o4) ----------------------------------
2840 (%i5) assume(x>0, x<2*%pi)$
2844 (%o6) ----------------
2849 @opencatbox{Categories:}
2850 @category{Trigonometric functions}
2851 @category{Simplification flags and variables}
2855 @c -----------------------------------------------------------------------------
2857 @defvr {Option variable} trigsign
2858 Default value: @code{true}
2860 When @code{trigsign} is @code{true}, it permits simplification of negative
2861 arguments to trigonometric functions. E.g.,
2862 m4_math(\sin(-x),@code{sin(-x)})
2865 m4_math(-\sin x, @code{-sin(x)})
2866 only if @code{trigsign} is @code{true}.
2868 @opencatbox{Categories:}
2869 @category{Trigonometric functions}
2870 @category{Simplification flags and variables}
2875 @node Explicit Simplifications Using Identities, Additional Functions, Options Controlling Simplification, Functions and Variables for Trigonometric
2876 @subsubsection Explicit Simplifications Using Identities
2877 @c NEEDS CLARIFICATION AND EXAMPLES
2879 @c -----------------------------------------------------------------------------
2881 @deffn {Function} trigexpand (@var{expr})
2883 Expands trigonometric and hyperbolic functions of
2884 sums of angles and of multiple angles occurring in @var{expr}. For best
2885 results, @var{expr} should be expanded. To enhance user control of
2886 simplification, this function expands only one level at a time,
2887 expanding sums of angles or multiple angles. To obtain full expansion
2888 into sines and cosines immediately, set the switch @code{trigexpand: true}.
2890 @code{trigexpand} is governed by the following global flags:
2893 @item @mref{trigexpand}
2894 If @code{true} causes expansion of all
2895 expressions containing sin's and cos's occurring subsequently.
2896 @item @mref{halfangles}
2897 If @code{true} causes half-angles to be simplified
2899 @item @mref{trigexpandplus}
2900 Controls the "sum" rule for @code{trigexpand},
2901 expansion of sums (e.g. @code{sin(x + y)}) will take place only if
2902 @code{trigexpandplus} is @code{true}.
2903 @item @mref{trigexpandtimes}
2904 Controls the "product" rule for @code{trigexpand},
2905 expansion of products (e.g. @code{sin(2 x)}) will take place only if
2906 @code{trigexpandtimes} is @code{true}.
2912 @c x+sin(3*x)/sin(x),trigexpand=true,expand;
2913 @c trigexpand(sin(10*x+y));
2917 (%i1) x+sin(3*x)/sin(x),trigexpand=true,expand;
2919 (%o1) - sin (x) + 3 cos (x) + x
2922 (%i2) trigexpand(sin(10*x+y));
2923 (%o2) cos(10 x) sin(y) + sin(10 x) cos(y)
2927 @opencatbox{Categories:}
2928 @category{Trigonometric functions}
2929 @category{Simplification functions}
2933 @c -----------------------------------------------------------------------------
2934 @anchor{trigexpandplus}
2935 @defvr {Option variable} trigexpandplus
2936 Default value: @code{true}
2938 @code{trigexpandplus} controls the "sum" rule for
2939 @mref{trigexpand}. Thus, when the @mref{trigexpand} command is used or the
2940 @mref{trigexpand} switch set to @code{true}, expansion of sums
2941 (e.g. @code{sin(x+y))} will take place only if @code{trigexpandplus} is
2944 @opencatbox{Categories:}
2945 @category{Trigonometric functions}
2946 @category{Simplification flags and variables}
2950 @c -----------------------------------------------------------------------------
2951 @anchor{trigexpandtimes}
2952 @defvr {Option variable} trigexpandtimes
2953 Default value: @code{true}
2955 @code{trigexpandtimes} controls the "product" rule for @mref{trigexpand}.
2956 Thus, when the @mref{trigexpand} command is used or the @mref{trigexpand}
2957 switch set to @code{true}, expansion of products (e.g. @code{sin(2*x)})
2958 will take place only if @code{trigexpandtimes} is @code{true}.
2960 @opencatbox{Categories:}
2961 @category{Trigonometric functions}
2962 @category{Simplification flags and variables}
2966 @c -----------------------------------------------------------------------------
2967 @anchor{triginverses}
2968 @defvr {Option variable} triginverses
2969 Default value: @code{true}
2971 @code{triginverses} controls the simplification of the
2972 composition of trigonometric and hyperbolic functions with their inverse
2975 If @code{all}, both e.g. @code{atan(tan(@var{x}))}
2976 and @code{tan(atan(@var{x}))} simplify to @var{x}.
2978 If @code{true}, the @code{@var{arcfun}(@var{fun}(@var{x}))}
2979 simplification is turned off.
2981 If @code{false}, both the
2982 @code{@var{arcfun}(@var{fun}(@var{x}))} and
2983 @code{@var{fun}(@var{arcfun}(@var{x}))}
2984 simplifications are turned off.
2986 @opencatbox{Categories:}
2987 @category{Trigonometric functions}
2988 @category{Simplification flags and variables}
2992 @c -----------------------------------------------------------------------------
2994 @deffn {Function} trigreduce @
2995 @fname{trigreduce} (@var{expr}, @var{x}) @
2996 @fname{trigreduce} (@var{expr})
2998 Combines products and powers of trigonometric
2999 and hyperbolic sin's and cos's of @var{x} into those of multiples of @var{x}.
3000 It also tries to eliminate these functions when they occur in
3001 denominators. If @var{x} is omitted then all variables in @var{expr} are used.
3003 See also @mref{poissimp}.
3006 @c trigreduce(-sin(x)^2+3*cos(x)^2+x);
3010 (%i1) trigreduce(-sin(x)^2+3*cos(x)^2+x);
3011 cos(2 x) cos(2 x) 1 1
3012 (%o1) -------- + 3 (-------- + -) + x - -
3019 @c The behavior was changed in order to avoid calling expand in the core
3020 @c simplifier (trigi.lisp rev 1.31)
3021 @c See http://www.math.utexas.edu/pipermail/maxima/2008/010919.html.
3023 @c The trigonometric simplification routines will use declared
3024 @c information in some simple cases. Declarations about variables are
3025 @c used as follows, e.g.
3028 @c declare(j, integer, e, even, o, odd)$
3029 @c sin(x + (e + 1/2)*%pi);
3030 @c sin(x + (o + 1/2)*%pi);
3033 @c (%i1) declare(j, integer, e, even, o, odd)$
3034 @c (%i2) sin(x + (e + 1/2)*%pi);
3036 @c (%i3) sin(x + (o + 1/2)*%pi);
3040 @opencatbox{Categories:}
3041 @category{Trigonometric functions}
3042 @category{Simplification functions}
3046 @c -----------------------------------------------------------------------------
3048 @deffn {Function} trigsimp (@var{expr})
3051 Employs the identities
3052 m4_math(<<<\sin\left(x\right)^2 + \cos\left(x\right)^2 = 1>>>,
3053 <<<sin(x)^2+cos(x)^2 = 1>>>)
3055 m4_math(<<<\cosh\left(x\right)^2 - \sinh\left(x\right)^2 = 1>>>,
3056 <<<cosh(x)^2-sinh(x)^2 = 1>>>)
3060 @c $\sin\left(x\right)^2 + \cos\left(x\right)^2 = 1$
3064 @c $\cosh\left(x\right)^2 - \sinh\left(x\right)^2 = 1$
3066 simplify expressions containing @code{tan}, @code{sec},
3067 etc., to @code{sin}, @code{cos}, @code{sinh}, @code{cosh}.
3070 @c Employs the identities @math{sin(x)^2 + cos(x)^2 = 1} and
3071 @c @math{cosh(x)^2 - sinh(x)^2 = 1} to simplify expressions containing @code{tan},
3072 @c @code{sec}, etc., to @code{sin}, @code{cos}, @code{sinh}, @code{cosh}.
3075 @mref{trigreduce}, @mref{ratsimp}, and @mref{radcan} may be
3076 able to further simplify the result.
3078 @code{demo ("trgsmp.dem")} displays some examples of @code{trigsimp}.
3079 @c MERGE EXAMPLES INTO THIS ITEM
3081 @opencatbox{Categories:}
3082 @category{Trigonometric functions}
3083 @category{Simplification functions}
3087 @c NEEDS CLARIFICATION
3089 @c -----------------------------------------------------------------------------
3091 @deffn {Function} trigrat (@var{expr})
3093 Gives a canonical simplified quasilinear form of a trigonometrical expression;
3094 @var{expr} is a rational fraction of several @code{sin}, @code{cos} or
3095 @code{tan}, the arguments of them are linear forms in some variables (or
3096 kernels) and @code{%pi/@var{n}} (@var{n} integer) with integer coefficients.
3097 The result is a simplified fraction with numerator and denominator linear in
3098 @code{sin} and @code{cos}. Thus @code{trigrat} linearize always when it is
3102 @c trigrat(sin(3*a)/sin(a+%pi/3));
3106 (%i1) trigrat(sin(3*a)/sin(a+%pi/3));
3107 (%o1) sqrt(3) sin(2 a) + cos(2 a) - 1
3111 The following example is taken from
3112 Davenport, Siret, and Tournier, @i{Calcul Formel}, Masson (or in English,
3113 Addison-Wesley), section 1.5.5, Morley theorem.
3116 @c c : %pi/3 - a - b$
3117 @c bc : sin(a)*sin(3*c)/sin(a+b);
3118 @c ba : bc, c=a, a=c;
3119 @c ac2 : ba^2 + bc^2 - 2*bc*ba*cos(b);
3123 (%i1) c : %pi/3 - a - b$
3125 (%i2) bc : sin(a)*sin(3*c)/sin(a+b);
3127 sin(a) sin(3 (- b - a + ---))
3129 (%o2) -----------------------------
3133 (%i3) ba : bc, c=a, a=c;
3135 sin(3 a) sin(b + a - ---)
3137 (%o3) -------------------------
3143 (%i4) ac2 : ba^2 + bc^2 - 2*bc*ba*cos(b);
3145 sin (3 a) sin (b + a - ---)
3147 (%o4) ---------------------------
3152 - (2 sin(a) sin(3 a) sin(3 (- b - a + ---)) cos(b)
3155 sin(b + a - ---))/(sin(a - ---) sin(b + a))
3158 sin (a) sin (3 (- b - a + ---))
3160 + -------------------------------
3165 (%i5) trigrat (ac2);
3166 (%o5) - (sqrt(3) sin(4 b + 4 a) - cos(4 b + 4 a)
3167 - 2 sqrt(3) sin(4 b + 2 a) + 2 cos(4 b + 2 a)
3168 - 2 sqrt(3) sin(2 b + 4 a) + 2 cos(2 b + 4 a)
3169 + 4 sqrt(3) sin(2 b + 2 a) - 8 cos(2 b + 2 a) - 4 cos(2 b - 2 a)
3170 + sqrt(3) sin(4 b) - cos(4 b) - 2 sqrt(3) sin(2 b) + 10 cos(2 b)
3171 + sqrt(3) sin(4 a) - cos(4 a) - 2 sqrt(3) sin(2 a) + 10 cos(2 a)
3176 @opencatbox{Categories:}
3177 @category{Trigonometric functions}
3178 @category{Simplification functions}
3183 @node Additional Functions, , Explicit Simplifications Using Identities, Functions and Variables for Trigonometric
3184 @subsubsection Additional Functions
3185 @c IS THIS DESCRIPTION ACCURATE ??
3186 @c LET'S BE EXPLICIT ABOUT EXACTLY WHAT ARE THE RULES IMPLEMENTED BY THIS PACKAGE
3188 @c -----------------------------------------------------------------------------
3190 @defvr {Package} atrig1
3192 The @code{atrig1} package contains several additional simplification rules
3193 for inverse trigonometric functions. Together with rules
3194 already known to Maxima, the following angles are fully implemented:
3196 m4_mathcomma(\pi/6,%pi/6)
3197 m4_mathcomma(\pi/4,%pi/4)
3198 m4_mathcomma(\pi/3,%pi/3)
3200 m4_mathdot(\pi/2,%pi/2)
3201 Corresponding angles in the other three quadrants are also available.
3202 Do @code{load("atrig1");} to use them.
3204 @opencatbox{Categories:}
3205 @category{Trigonometric functions}
3206 @category{Package atrig1}
3210 @c IS THIS DESCRIPTION ACCURATE ??
3211 @c LET'S BE EXPLICIT ABOUT EXACTLY WHAT ARE THE RULES IMPLEMENTED BY THIS PACKAGE
3213 @c -----------------------------------------------------------------------------
3215 @defvr {Package} ntrig
3217 The @code{ntrig} package contains a set of simplification rules that are
3218 used to simplify trigonometric function whose arguments are of the form
3219 @code{@var{f}(@var{n} %pi/10)} where @var{f} is any of the functions
3220 @code{sin}, @code{cos}, @code{tan}, @code{csc}, @code{sec} and @code{cot}.
3221 @c NEED TO LOAD THIS PACKAGE ??
3223 @opencatbox{Categories:}
3224 @category{Trigonometric functions}
3225 @category{Package ntrig}
3229 @c -----------------------------------------------------------------------------
3231 @node Random Numbers, , Trigonometric Functions, Elementary Functions
3232 @section Random Numbers
3233 @c -----------------------------------------------------------------------------
3235 @c -----------------------------------------------------------------------------
3236 @anchor{make_random_state}
3237 @deffn {Function} make_random_state @
3238 @fname{make_random_state} (@var{n}) @
3239 @fname{make_random_state} (@var{s}) @
3240 @fname{make_random_state} (true) @
3241 @fname{make_random_state} (false)
3243 @c OMIT THIS FOR NOW. SEE COMMENT BELOW.
3244 @c @defunx make_random_state (@var{a})
3246 A random state object represents the state of the random number generator.
3247 The state comprises 627 32-bit words.
3249 @code{make_random_state (@var{n})} returns a new random state object
3250 created from an integer seed value equal to @var{n} modulo 2^32.
3251 @var{n} may be negative.
3253 @c OMIT THIS FOR NOW. NOT SURE HOW THIS IS SUPPOSED TO WORK.
3254 @c @code{make_random_state (@var{a})} returns a new random state object
3255 @c created from an array @var{a}, which must be a Lisp array of 32 unsigned bytes.
3257 @code{make_random_state (@var{s})} returns a copy of the random state @var{s}.
3259 @code{make_random_state (true)} returns a new random state object,
3260 using the current computer clock time as the seed.
3262 @code{make_random_state (false)} returns a copy of the current state
3263 of the random number generator.
3265 @opencatbox{Categories:}
3266 @category{Random numbers}
3270 @c -----------------------------------------------------------------------------
3271 @anchor{set_random_state}
3272 @deffn {Function} set_random_state (@var{s})
3274 Copies @var{s} to the random number generator state.
3276 @code{set_random_state} always returns @code{done}.
3278 @opencatbox{Categories:}
3279 @category{Random numbers}
3283 @c -----------------------------------------------------------------------------
3285 @deffn {Function} random (@var{x})
3287 Returns a pseudorandom number. If @var{x} is an integer,
3288 @code{random (@var{x})} returns an integer from 0 through @code{@var{x} - 1}
3289 inclusive. If @var{x} is a floating point number, @code{random (@var{x})}
3290 returns a nonnegative floating point number less than @var{x}. @code{random}
3291 complains with an error if @var{x} is neither an integer nor a float, or if
3292 @var{x} is not positive.
3294 The functions @code{make_random_state} and @code{set_random_state}
3295 maintain the state of the random number generator.
3297 The Maxima random number generator is an implementation of the Mersenne twister
3303 @c s1: make_random_state (654321)$
3304 @c set_random_state (s1);
3306 @c random (9573684);
3308 @c s2: make_random_state (false)$
3312 @c set_random_state (s2);
3318 (%i1) s1: make_random_state (654321)$
3320 (%i2) set_random_state (s1);
3324 (%i3) random (1000);
3328 (%i4) random (9573684);
3332 (%i5) random (2^75);
3333 (%o5) 11804491615036831636390
3335 (%i6) s2: make_random_state (false)$
3338 (%o7) 0.2310127244107132
3341 (%i8) random (10.0);
3342 (%o8) 4.3945536458708245
3345 (%i9) random (100.0);
3346 (%o9) 32.28666704056853
3349 (%i10) set_random_state (s2);
3353 (%i11) random (1.0);
3354 (%o11) 0.2310127244107132
3357 (%i12) random (10.0);
3358 (%o12) 4.3945536458708245
3361 (%i13) random (100.0);
3362 (%o13) 32.28666704056853
3366 @opencatbox{Categories:}
3367 @category{Random numbers}
3368 @category{Numerical methods}