1@menu
2* Functions for Numbers::
3* Functions for Complex Numbers::
4* Combinatorial Functions::
5* Root Exponential and Logarithmic Functions::
6* Trigonometric Functions::
7* Random Numbers::
8@end menu
9
10@c -----------------------------------------------------------------------------
11@node Functions for Numbers, Functions for Complex Numbers, Mathematical Functions, Mathematical Functions
12@section Functions for Numbers
13@c -----------------------------------------------------------------------------
14
15@c -----------------------------------------------------------------------------
16@anchor{abs}
17@deffn {Function} abs (@var{z})
18
19The @code{abs} function represents the mathematical absolute value function and
20works for both numerical and symbolic values. If the argument, @var{z}, is a
21real or complex number, @code{abs} returns the absolute value of @var{z}. If
22possible, symbolic expressions using the absolute value function are
23also simplified.
24
25Maxima can differentiate, integrate and calculate limits for expressions
26containing @code{abs}. The @code{abs_integrate} package further extends
27Maxima's ability to calculate integrals involving the abs function. See
28(%i12) in the examples below.
29
30When applied to a list or matrix, @code{abs} automatically distributes over
31the terms. Similarly, it distributes over both sides of an
32equation. To alter this behaviour, see the variable @mrefdot{distribute_over}
33
34See also @mrefdot{cabs}
35
36Examples:
37
38Calculation of @code{abs} for real and complex numbers, including numerical
39constants and various infinities. The first example shows how @code{abs}
40distributes over the elements of a list.
41
42@c ===beg===
43@c abs([-4, 0, 1, 1+%i]);
44@c abs((1+%i)*(1-%i));
45@c abs(%e+%i);
46@c abs([inf, infinity, minf]);
47@c ===end===
48@example
49(%i1) abs([-4, 0, 1, 1+%i]);
50(%o1)                  [4, 0, 1, sqrt(2)]
51
52(%i2) abs((1+%i)*(1-%i));
53(%o2)                           2
54(%i3) abs(%e+%i);
55                                2
56(%o3)                    sqrt(%e  + 1)
57(%i4) abs([inf, infinity, minf]);
58(%o4)                   [inf, inf, inf]
59@end example
60
61Simplification of expressions containing @code{abs}:
62
63@c ===beg===
64@c abs(x^2);
65@c abs(x^3);
66@c abs(abs(x));
67@c abs(conjugate(x));
68@c ===end===
69@example
70(%i5) abs(x^2);
71                                2
72(%o5)                          x
73(%i6) abs(x^3);
74                             2
75(%o6)                       x  abs(x)
76
77(%i7) abs(abs(x));
78(%o7)                       abs(x)
79(%i8) abs(conjugate(x));
80(%o8)                       abs(x)
81@end example
82
83Integrating and differentiating with the @code{abs} function. Note that more
84integrals involving the @code{abs} function can be performed, if the
85@code{abs_integrate} package is loaded. The last example shows the Laplace
86transform of @code{abs}: see @mrefdot{laplace}
87
88@c ===beg===
89@c diff(x*abs(x),x),expand;
90@c integrate(abs(x),x);
91@c integrate(x*abs(x),x);
92@c load("abs_integrate")$
93@c integrate(x*abs(x),x);
94@c integrate(abs(x),x,-2,%pi);
95@c laplace(abs(x),x,s);
96@c ===end===
97@example
98(%i9) diff(x*abs(x),x),expand;
99(%o9)                       2 abs(x)
100
101(%i10) integrate(abs(x),x);
102                             x abs(x)
103(%o10)                       --------
104                                2
105
106(%i11) integrate(x*abs(x),x);
107                           /
108                           [
109(%o11)                     I x abs(x) dx
110                           ]
111                           /
112
113(%i12) load("abs_integrate")$
114(%i13) integrate(x*abs(x),x);
115                      2           3
116                     x  abs(x)   x  signum(x)
117(%o13)               --------- - ------------
118                         2            6
119
120(%i14) integrate(abs(x),x,-2,%pi);
121                               2
122                            %pi
123(%o14)                      ---- + 2
124                             2
125
126(%i15) laplace(abs(x),x,s);
127                               1
128(%o15)                         --
129                                2
130                               s
131@end example
132
133@opencatbox
134@category{Mathematical functions}
135@closecatbox
136@end deffn
137
138@c -----------------------------------------------------------------------------
139@anchor{ceiling}
140@deffn {Function} ceiling (@var{x})
141
142When @var{x} is a real number, return the least integer that
143is greater than or equal to @var{x}.
144
145If @var{x} is a constant expression (@code{10 * %pi}, for example),
146@code{ceiling} evaluates @var{x} using big floating point numbers, and
147applies @code{ceiling} to the resulting big float.  Because @code{ceiling} uses
148floating point evaluation, it's possible, although unlikely, that @code{ceiling}
149could return an erroneous value for constant inputs.  To guard against errors,
150the floating point evaluation is done using three values for @mrefdot{fpprec}
151
152For non-constant inputs, @code{ceiling} tries to return a simplified value.
153Here are examples of the simplifications that @code{ceiling} knows about:
154
155@c ===beg===
156@c ceiling (ceiling (x));
157@c ceiling (floor (x));
158@c declare (n, integer)$
159@c [ceiling (n), ceiling (abs (n)), ceiling (max (n, 6))];
160@c assume (x > 0, x < 1)$
161@c ceiling (x);
162@c tex (ceiling (a));
163@c ===end===
164@example
165@group
166(%i1) ceiling (ceiling (x));
167(%o1)                      ceiling(x)
168@end group
169@group
170(%i2) ceiling (floor (x));
171(%o2)                       floor(x)
172@end group
173(%i3) declare (n, integer)$
174@group
175(%i4) [ceiling (n), ceiling (abs (n)), ceiling (max (n, 6))];
176(%o4)                [n, abs(n), max(6, n)]
177@end group
178(%i5) assume (x > 0, x < 1)$
179@group
180(%i6) ceiling (x);
181(%o6)                           1
182@end group
183@group
184(%i7) tex (ceiling (a));
185$$\left \lceil a \right \rceil$$
186(%o7)                         false
187@end group
188@end example
189
190The @code{ceiling} function distributes over lists, matrices and equations.
191See @mrefdot{distribute_over}
192
193Finally, for all inputs that are manifestly complex, @code{ceiling} returns
194a noun form.
195
196If the range of a function is a subset of the integers, it can be declared to
197be @code{integervalued}.  Both the @code{ceiling} and @mref{floor} functions
198can use this information; for example:
199
200@c ===beg===
201@c declare (f, integervalued)$
202@c floor (f(x));
203@c ceiling (f(x) - 1);
204@c ===end===
205@example
206(%i1) declare (f, integervalued)$
207@group
208(%i2) floor (f(x));
209(%o2)                         f(x)
210@end group
211@group
212(%i3) ceiling (f(x) - 1);
213(%o3)                       f(x) - 1
214@end group
215@end example
216
217Example use:
218
219@c ===beg===
220@c unitfrac(r) := block([uf : [], q],
221@c     if not(ratnump(r)) then
222@c        error("unitfrac: argument must be a rational number"),
223@c     while r # 0 do (
224@c         uf : cons(q : 1/ceiling(1/r), uf),
225@c         r : r - q),
226@c     reverse(uf));
227@c unitfrac (9/10);
228@c apply ("+", %);
229@c unitfrac (-9/10);
230@c apply ("+", %);
231@c unitfrac (36/37);
232@c apply ("+", %);
233@c ===end===
234@example
235(%i1) unitfrac(r) := block([uf : [], q],
236    if not(ratnump(r)) then
237       error("unitfrac: argument must be a rational number"),
238    while r # 0 do (
239        uf : cons(q : 1/ceiling(1/r), uf),
240        r : r - q),
241    reverse(uf));
242(%o1) unitfrac(r) := block([uf : [], q],
243if not ratnump(r) then error("unitfrac: argument must be a rational number"
244                                     1
245), while r # 0 do (uf : cons(q : ----------, uf), r : r - q),
246                                         1
247                                 ceiling(-)
248                                         r
249reverse(uf))
250@group
251(%i2) unitfrac (9/10);
252                            1  1  1
253(%o2)                      [-, -, --]
254                            2  3  15
255@end group
256@group
257(%i3) apply ("+", %);
258                               9
259(%o3)                          --
260                               10
261@end group
262@group
263(%i4) unitfrac (-9/10);
264                                  1
265(%o4)                       [- 1, --]
266                                  10
267@end group
268@group
269(%i5) apply ("+", %);
270                                9
271(%o5)                         - --
272                                10
273@end group
274@group
275(%i6) unitfrac (36/37);
276                        1  1  1  1    1
277(%o6)                  [-, -, -, --, ----]
278                        2  3  8  69  6808
279@end group
280@group
281(%i7) apply ("+", %);
282                               36
283(%o7)                          --
284                               37
285@end group
286@end example
287
288@opencatbox
289@category{Mathematical functions}
290@closecatbox
291@end deffn
292
293@c -----------------------------------------------------------------------------
294@anchor{entier}
295@deffn {Function} entier (@var{x})
296
297Returns the largest integer less than or equal to @var{x} where @var{x} is
298numeric.  @mref{fix} (as in @code{fixnum}) is a synonym for this, so
299@code{fix(@var{x})} is precisely the same.
300
301@opencatbox
302@category{Mathematical functions}
303@closecatbox
304@end deffn
305
306@c -----------------------------------------------------------------------------
307@anchor{floor}
308@deffn {Function} floor (@var{x})
309
310When @var{x} is a real number, return the largest integer that is less than or
311equal to @var{x}.
312
313If @var{x} is a constant expression (@code{10 * %pi}, for example), @code{floor}
314evaluates @var{x} using big floating point numbers, and applies @code{floor} to
315the resulting big float. Because @code{floor} uses floating point evaluation,
316it's possible, although unlikely, that @code{floor} could return an erroneous
317value for constant inputs.  To guard against errors, the floating point
318evaluation is done using three values for @mrefdot{fpprec}
319
320For non-constant inputs, @code{floor} tries to return a simplified value.  Here
321are examples of the simplifications that @code{floor} knows about:
322
323@c ===beg===
324@c floor (ceiling (x));
325@c floor (floor (x));
326@c declare (n, integer)$
327@c [floor (n), floor (abs (n)), floor (min (n, 6))];
328@c assume (x > 0, x < 1)$
329@c floor (x);
330@c tex (floor (a));
331@c ===end===
332@example
333@group
334(%i1) floor (ceiling (x));
335(%o1)                      ceiling(x)
336@end group
337@group
338(%i2) floor (floor (x));
339(%o2)                       floor(x)
340@end group
341(%i3) declare (n, integer)$
342@group
343(%i4) [floor (n), floor (abs (n)), floor (min (n, 6))];
344(%o4)                [n, abs(n), min(6, n)]
345@end group
346(%i5) assume (x > 0, x < 1)$
347@group
348(%i6) floor (x);
349(%o6)                           0
350@end group
351@group
352(%i7) tex (floor (a));
353$$\left \lfloor a \right \rfloor$$
354(%o7)                         false
355@end group
356@end example
357
358The @code{floor} function distributes over lists, matrices and equations.
359See @mrefdot{distribute_over}
360
361Finally, for all inputs that are manifestly complex, @code{floor} returns
362a noun form.
363
364If the range of a function is a subset of the integers, it can be declared to
365be @code{integervalued}.  Both the @mref{ceiling} and @code{floor} functions
366can use this information; for example:
367
368@c ===beg===
369@c declare (f, integervalued)$
370@c floor (f(x));
371@c ceiling (f(x) - 1);
372@c ===end===
373@example
374(%i1) declare (f, integervalued)$
375@group
376(%i2) floor (f(x));
377(%o2)                         f(x)
378@end group
379@group
380(%i3) ceiling (f(x) - 1);
381(%o3)                       f(x) - 1
382@end group
383@end example
384
385@opencatbox
386@category{Mathematical functions}
387@closecatbox
388@end deffn
389
390@c -----------------------------------------------------------------------------
391@anchor{fix}
392@deffn {Function} fix (@var{x})
393
394A synonym for @code{entier (@var{x})}.
395
396@opencatbox
397@category{Mathematical functions}
398@closecatbox
399@end deffn
400
401@c -----------------------------------------------------------------------------
402@anchor{lmax}
403@deffn {Function} lmax (@var{L})
404
405When @var{L} is a list or a set, return @code{apply ('max, args (@var{L}))}.
406When @var{L} is not a list or a set, signal an error.
407See also @mref{lmin} and @mrefdot{max}
408
409@opencatbox
410@category{Mathematical functions}
411@category{Lists}
412@category{Sets}
413@closecatbox
414@end deffn
415
416@c -----------------------------------------------------------------------------
417@anchor{lmin}
418@deffn {Function} lmin (@var{L})
419
420When @var{L} is a list or a set, return @code{apply ('min, args (@var{L}))}.
421When @var{L} is not a list or a set, signal an error.
422See also @mref{lmax} and @mrefdot{min}
423
424@opencatbox
425@category{Mathematical functions}
426@category{Lists}
427@category{Sets}
428@closecatbox
429@end deffn
430
431@c -----------------------------------------------------------------------------
432@anchor{max}
433@deffn {Function} max (@var{x_1}, @dots{}, @var{x_n})
434
435Return a simplified value for the maximum of the expressions @var{x_1} through
436@var{x_n}.  When @code{get (trylevel, maxmin)}, is 2 or greater, @code{max}
437uses the simplification @code{max (e, -e) --> |e|}.  When
438@code{get (trylevel, maxmin)} is 3 or greater, @var{max} tries to eliminate
439expressions that are between two other arguments; for example,
440@code{max (x, 2*x, 3*x) --> max (x, 3*x)}.  To set the value of @code{trylevel}
441to 2, use @code{put (trylevel, 2, maxmin)}.
442
443See also @mref{min} and @mrefdot{lmax}
444
445@opencatbox
446@category{Mathematical functions}
447@closecatbox
448@end deffn
449
450@c -----------------------------------------------------------------------------
451@anchor{min}
452@deffn {Function} min (@var{x_1}, @dots{}, @var{x_n})
453
454Return a simplified value for the minimum of the expressions @code{x_1} through
455@code{x_n}.  When @code{get (trylevel, maxmin)}, is 2 or greater, @code{min}
456uses the simplification @code{min (e, -e) --> -|e|}.  When
457@code{get (trylevel, maxmin)} is 3 or greater, @code{min} tries to eliminate
458expressions that are between two other arguments; for example,
459@code{min (x, 2*x, 3*x) --> min (x, 3*x)}.  To set the value of @code{trylevel}
460to 2, use @code{put (trylevel, 2, maxmin)}.
461
462See also @mref{max} and @mrefdot{lmin}
463
464@opencatbox
465@category{Mathematical functions}
466@closecatbox
467@end deffn
468
469@c -----------------------------------------------------------------------------
470@anchor{round}
471@deffn {Function} round (@var{x})
472
473When @var{x} is a real number, returns the closest integer to @var{x}.
474Multiples of 1/2 are rounded to the nearest even integer.  Evaluation of
475@var{x} is similar to @mref{floor} and @mrefdot{ceiling}
476
477The @code{round} function distributes over lists, matrices and equations.
478See @mrefdot{distribute_over}
479
480@opencatbox
481@category{Mathematical functions}
482@closecatbox
483@end deffn
484
485@c -----------------------------------------------------------------------------
486@anchor{signum}
487@deffn {Function} signum (@var{x})
488
489For either real or complex numbers @var{x}, the signum function returns
4900 if @var{x} is zero; for a nonzero numeric input @var{x}, the signum function
491returns @code{x/abs(x)}.
492
493For non-numeric inputs, Maxima attempts to determine the sign of the input.
494When the sign is negative, zero, or positive, @code{signum} returns -1,0, 1,
495respectively.  For all other values for the sign, @code{signum} a simplified but
496equivalent form.  The simplifications include reflection (@code{signum(-x)}
497gives @code{-signum(x)}) and multiplicative identity (@code{signum(x*y)} gives
498@code{signum(x) * signum(y)}).
499
500The @code{signum} function distributes over a list, a matrix, or an
501equation.  See @mrefdot{distribute_over}
502
503@opencatbox
504@category{Mathematical functions}
505@closecatbox
506@end deffn
507
508@c -----------------------------------------------------------------------------
509@anchor{truncate}
510@deffn {Function} truncate (@var{x})
511
512When @var{x} is a real number, return the closest integer to @var{x} not
513greater in absolute value than @var{x}.  Evaluation of @var{x} is similar
514to @mref{floor} and @mrefdot{ceiling}
515
516The @code{truncate} function distributes over lists, matrices and equations.
517See @mrefdot{distribute_over}
518
519@opencatbox
520@category{Mathematical functions}
521@closecatbox
522@end deffn
523
524@c -----------------------------------------------------------------------------
525@node Functions for Complex Numbers, Combinatorial Functions, Functions for Numbers, Mathematical Functions
526@section Functions for Complex Numbers
527@c -----------------------------------------------------------------------------
528
529@c -----------------------------------------------------------------------------
530@anchor{cabs}
531@deffn {Function} cabs (@var{expr})
532
533Calculates the absolute value of an expression representing a complex
534number.  Unlike the function @mrefcomma{abs} the @code{cabs} function always
535decomposes its argument into a real and an imaginary part.  If @code{x} and
536@code{y} represent real variables or expressions, the @code{cabs} function
537calculates the absolute value of @code{x + %i*y} as
538
539@c ===beg===
540@c cabs (1);
541@c cabs (1 + %i);
542@c cabs (exp (%i));
543@c cabs (exp (%pi * %i));
544@c cabs (exp (3/2 * %pi * %i));
545@c cabs (17 * exp (2 * %i));
546@c ===end===
547@example
548@group
549(%i1) cabs (1);
550(%o1)                           1
551@end group
552@group
553(%i2) cabs (1 + %i);
554(%o2)                        sqrt(2)
555@end group
556@group
557(%i3) cabs (exp (%i));
558(%o3)                           1
559@end group
560@group
561(%i4) cabs (exp (%pi * %i));
562(%o4)                           1
563@end group
564@group
565(%i5) cabs (exp (3/2 * %pi * %i));
566(%o5)                           1
567@end group
568@group
569(%i6) cabs (17 * exp (2 * %i));
570(%o6)                          17
571@end group
572@end example
573
574If @code{cabs} returns a noun form this most commonly is caused by
575some properties of the variables involved not being known:
576
577@c ===beg===
578@c cabs (a+%i*b);
579@c declare(a,real,b,real);
580@c cabs (a+%i*b);
581@c assume(a>0,b>0);
582@c cabs (a+%i*b);
583@c ===end===
584@example
585@group
586(%i1) cabs (a+%i*b);
587                                2    2
588(%o1)                     sqrt(b  + a )
589@end group
590@group
591(%i2) declare(a,real,b,real);
592(%o2)                         done
593@end group
594@group
595(%i3) cabs (a+%i*b);
596                                2    2
597(%o3)                     sqrt(b  + a )
598@end group
599@group
600(%i4) assume(a>0,b>0);
601(%o4)                    [a > 0, b > 0]
602@end group
603@group
604(%i5) cabs (a+%i*b);
605                                2    2
606(%o5)                     sqrt(b  + a )
607@end group
608@end example
609
610The @code{cabs} function can use known properties like symmetry properties of
611complex functions to help it calculate the absolute value of an expression.  If
612such identities exist, they can be advertised to @code{cabs} using function
613properties.  The symmetries that @code{cabs} understands are: mirror symmetry,
614conjugate function and complex characteristic.
615
616@code{cabs} is a verb function and is not suitable for symbolic
617calculations.  For such calculations (including integration,
618differentiation and taking limits of expressions containing absolute
619values), use @mrefdot{abs}
620
621The result of @code{cabs} can include the absolute value function,
622@mrefcomma{abs} and the arc tangent, @mrefdot{atan2}
623
624When applied to a list or matrix, @code{cabs} automatically distributes over
625the terms.  Similarly, it distributes over both sides of an equation.
626
627For further ways to compute with complex numbers, see the functions
628@mrefcomma{rectform} @mrefcomma{realpart} @mrefcomma{imagpart}@w{}
629@mrefcomma{carg} @mref{conjugate} and @mrefdot{polarform}
630
631Examples:
632
633Examples with @mref{sqrt} and @mrefdot{sin}
634
635@c ===beg===
636@c cabs(sqrt(1+%i*x));
637@c cabs(sin(x+%i*y));
638@c ===end===
639@example
640(%i1) cabs(sqrt(1+%i*x));
641                             2     1/4
642(%o1)                      (x  + 1)
643(%i2) cabs(sin(x+%i*y));
644                    2        2         2        2
645(%o2)       sqrt(cos (x) sinh (y) + sin (x) cosh (y))
646@end example
647
648The error function, @mrefcomma{erf} has mirror symmetry, which is used here in
649the calculation of the absolute value with a complex argument:
650
651@c ===beg===
652@c cabs(erf(x+%i*y));
653@c ===end===
654@example
655(%i3) cabs(erf(x+%i*y));
656                                          2
657           (erf(%i y + x) - erf(%i y - x))
658(%o3) sqrt(--------------------------------
659                          4
660                                                               2
661                                (erf(%i y + x) + erf(%i y - x))
662                              - --------------------------------)
663                                               4
664@end example
665
666Maxima knows complex identities for the Bessel functions, which allow
667it to compute the absolute value for complex arguments.  Here is an
668example for @mrefdot{bessel_j}
669
670@c ===beg===
671@c cabs(bessel_j(1,%i));
672@c ===end===
673@example
674(%i4) cabs(bessel_j(1,%i));
675(%o4)                 abs(bessel_j(1, %i))
676@end example
677
678@opencatbox
679@category{Complex variables}
680@closecatbox
681@end deffn
682
683@c -----------------------------------------------------------------------------
684@anchor{carg}
685@deffn {Function} carg (@var{z})
686
687Returns the complex argument of @var{z}.  The complex argument is an angle
688@code{theta} in @code{(-%pi, %pi]} such that @code{r exp (theta %i) = @var{z}}
689where @code{r} is the magnitude of @var{z}.
690
691@code{carg} is a computational function, not a simplifying function.
692@c PROBABLY NEED TO EXPLAIN IMPLICATIONS OF ABOVE STATEMENT
693
694See also @mref{abs} (complex magnitude), @mrefcomma{polarform}@w{}
695@mrefcomma{rectform} @mrefcomma{realpart} and @mrefdot{imagpart}
696
697Examples:
698
699@c ===beg===
700@c carg (1);
701@c carg (1 + %i);
702@c carg (exp (%i));
703@c carg (exp (%pi * %i));
704@c carg (exp (3/2 * %pi * %i));
705@c carg (17 * exp (2 * %i));
706@c ===end===
707@example
708@group
709(%i1) carg (1);
710(%o1)                           0
711@end group
712@group
713(%i2) carg (1 + %i);
714                               %pi
715(%o2)                          ---
716                                4
717@end group
718@group
719(%i3) carg (exp (%i));
720                               sin(1)
721(%o3)                     atan(------)
722                               cos(1)
723@end group
724@group
725(%i4) carg (exp (%pi * %i));
726(%o4)                          %pi
727@end group
728@group
729(%i5) carg (exp (3/2 * %pi * %i));
730                                %pi
731(%o5)                         - ---
732                                 2
733@end group
734@group
735(%i6) carg (17 * exp (2 * %i));
736                            sin(2)
737(%o6)                  atan(------) + %pi
738                            cos(2)
739@end group
740@end example
741
742If @code{carg} returns a noun form this most communly is caused by
743some properties of the variables involved not being known:
744
745@c ===beg===
746@c carg (a+%i*b);
747@c declare(a,real,b,real);
748@c carg (a+%i*b);
749@c assume(a>0,b>0);
750@c carg (a+%i*b);
751@c ===end===
752@example
753@group
754(%i1) carg (a+%i*b);
755(%o1)                      atan2(b, a)
756@end group
757@group
758(%i2) declare(a,real,b,real);
759(%o2)                         done
760@end group
761@group
762(%i3) carg (a+%i*b);
763(%o3)                      atan2(b, a)
764@end group
765@group
766(%i4) assume(a>0,b>0);
767(%o4)                    [a > 0, b > 0]
768@end group
769@group
770(%i5) carg (a+%i*b);
771                                  b
772(%o5)                        atan(-)
773                                  a
774@end group
775@end example
776
777@opencatbox
778@category{Complex variables}
779@closecatbox
780@end deffn
781
782@c -----------------------------------------------------------------------------
783@anchor{conjugate}
784@deffn {Function} conjugate (@var{x})
785
786Returns the complex conjugate of @var{x}.
787
788@c ===beg===
789@c declare ([aa, bb], real, cc, complex, ii, imaginary);
790@c conjugate (aa + bb*%i);
791@c conjugate (cc);
792@c conjugate (ii);
793@c conjugate (xx + yy);
794@c ===end===
795@example
796@group
797(%i1) declare ([aa, bb], real, cc, complex, ii, imaginary);
798(%o1)                         done
799@end group
800@group
801(%i2) conjugate (aa + bb*%i);
802(%o2)                      aa - %i bb
803@end group
804@group
805(%i3) conjugate (cc);
806(%o3)                     conjugate(cc)
807@end group
808@group
809(%i4) conjugate (ii);
810(%o4)                         - ii
811@end group
812@group
813(%i5) conjugate (xx + yy);
814(%o5)                        yy + xx
815@end group
816@end example
817
818@opencatbox
819@category{Complex variables}
820@closecatbox
821@end deffn
822
823@c -----------------------------------------------------------------------------
824@anchor{imagpart}
825@deffn {Function} imagpart (@var{expr})
826
827Returns the imaginary part of the expression @var{expr}.
828
829@code{imagpart} is a computational function, not a simplifying function.
830@c PROBABLY NEED TO EXPLAIN IMPLICATIONS OF ABOVE STATEMENT
831@c SEE ALSO SF BUG REPORT # 902290
832
833See also @mrefcomma{abs} @mrefcomma{carg} @mrefcomma{polarform}@w{}
834@mrefcomma{rectform} and @mrefdot{realpart}
835
836Example:
837
838@c ===beg===
839@c imagpart (a+b*%i);
840@c imagpart (1+sqrt(2)*%i);
841@c imagpart (1);
842@c imagpart (sqrt(2)*%i);
843@c ===end===
844@example
845@group
846(%i1) imagpart (a+b*%i);
847(%o1)                           b
848@end group
849@group
850(%i2) imagpart (1+sqrt(2)*%i);
851(%o2)                        sqrt(2)
852@end group
853@group
854(%i3) imagpart (1);
855(%o3)                           0
856@end group
857@group
858(%i4) imagpart (sqrt(2)*%i);
859(%o4)                        sqrt(2)
860@end group
861@end example
862
863@opencatbox
864@category{Complex variables}
865@closecatbox
866@end deffn
867
868@c NEEDS EXAMPLES
869
870@c -----------------------------------------------------------------------------
871@anchor{polarform}
872@deffn {Function} polarform (@var{expr})
873
874Returns an expression @code{r %e^(%i theta)} equivalent to @var{expr},
875such that @code{r} and @code{theta} are purely real.
876
877Example:
878
879@c ===beg===
880@c polarform(a+b*%i);
881@c polarform(1+%i);
882@c polarform(1+2*%i);
883@c ===end===
884@example
885@group
886(%i1) polarform(a+b*%i);
887                       2    2    %i atan2(b, a)
888(%o1)            sqrt(b  + a ) %e
889@end group
890@group
891(%i2) polarform(1+%i);
892                                  %i %pi
893                                  ------
894                                    4
895(%o2)                   sqrt(2) %e
896@end group
897@group
898(%i3) polarform(1+2*%i);
899                                %i atan(2)
900(%o3)                 sqrt(5) %e
901@end group
902@end example
903
904@opencatbox
905@category{Complex variables}
906@category{Exponential and logarithm functions}
907@closecatbox
908@end deffn
909
910@c -----------------------------------------------------------------------------
911@anchor{realpart}
912@deffn {Function} realpart (@var{expr})
913
914Returns the real part of @var{expr}.  @code{realpart} and @mref{imagpart} will
915work on expressions involving trigonometric and hyperbolic functions,
916as well as square root, logarithm, and exponentiation.
917
918Example:
919
920@c ===beg===
921@c realpart (a+b*%i);
922@c realpart (1+sqrt(2)*%i);
923@c realpart (sqrt(2)*%i);
924@c realpart (1);
925@c ===end===
926@example
927@group
928(%i1) realpart (a+b*%i);
929(%o1)                           a
930@end group
931@group
932(%i2) realpart (1+sqrt(2)*%i);
933(%o2)                           1
934@end group
935@group
936(%i3) realpart (sqrt(2)*%i);
937(%o3)                           0
938@end group
939@group
940(%i4) realpart (1);
941(%o4)                           1
942@end group
943@end example
944
945@opencatbox
946@category{Complex variables}
947@closecatbox
948@end deffn
949
950@c -----------------------------------------------------------------------------
951@anchor{rectform}
952@deffn {Function} rectform (@var{expr})
953
954Returns an expression @code{a + b %i} equivalent to @var{expr},
955such that @var{a} and @var{b} are purely real.
956
957Example:
958
959@c ===beg===
960@c rectform(sqrt(2)*%e^(%i*%pi/4));
961@c rectform(sqrt(b^2+a^2)*%e^(%i*atan2(b, a)));
962@c rectform(sqrt(5)*%e^(%i*atan(2)));
963@c ===end===
964@example
965@group
966(%i1) rectform(sqrt(2)*%e^(%i*%pi/4));
967(%o1)                        %i + 1
968@end group
969@group
970(%i2) rectform(sqrt(b^2+a^2)*%e^(%i*atan2(b, a)));
971(%o2)                       %i b + a
972@end group
973@group
974(%i3) rectform(sqrt(5)*%e^(%i*atan(2)));
975(%o3)                       2 %i + 1
976@end group
977@end example
978
979@opencatbox
980@category{Complex variables}
981@closecatbox
982@end deffn
983
984@c -----------------------------------------------------------------------------
985@node Combinatorial Functions, Root Exponential and Logarithmic Functions, Functions for Complex Numbers, Mathematical Functions
986@section Combinatorial Functions
987@c -----------------------------------------------------------------------------
988
989@c -----------------------------------------------------------------------------
990@anchor{!!}
991@deffn {Operator} !!
992@ifinfo
993@fnindex Double factorial
994@end ifinfo
995
996The double factorial operator.
997
998For an integer, float, or rational number @code{n}, @code{n!!} evaluates to the
999product @code{n (n-2) (n-4) (n-6) ... (n - 2 (k-1))} where @code{k} is equal to
1000@code{entier (n/2)}, that is, the largest integer less than or equal to
1001@code{n/2}.  Note that this definition does not coincide with other published
1002definitions for arguments which are not integers.
1003@c REPORTED TO BUG TRACKER AS BUG # 1093138 !!!
1004
1005For an even (or odd) integer @code{n}, @code{n!!} evaluates to the product of
1006all the consecutive even (or odd) integers from 2 (or 1) through @code{n}
1007inclusive.
1008
1009For an argument @code{n} which is not an integer, float, or rational, @code{n!!}
1010yields a noun form @code{genfact (n, n/2, 2)}.
1011@c n!! IS NEITHER SIMPLIFIED NOR EVALUATED IN THIS CASE
1012@c -- MENTION THAT? OR TOO MUCH DETAIL ???
1013
1014@opencatbox
1015@category{Gamma and factorial functions}
1016@category{Operators}
1017@closecatbox
1018@end deffn
1019
1020@c -----------------------------------------------------------------------------
1021@anchor{binomial}
1022@deffn {Function} binomial (@var{x}, @var{y})
1023
1024The binomial coefficient @code{@var{x}!/(@var{y}! (@var{x} - @var{y})!)}.
1025If @var{x} and @var{y} are integers, then the numerical value of the binomial
1026coefficient is computed.  If @var{y}, or @var{x - y}, is an integer, the
1027binomial coefficient is expressed as a polynomial.
1028
1029Examples:
1030
1031@c ===beg===
1032@c binomial (11, 7);
1033@c 11! / 7! / (11 - 7)!;
1034@c binomial (x, 7);
1035@c binomial (x + 7, x);
1036@c binomial (11, y);
1037@c ===end===
1038@example
1039@group
1040(%i1) binomial (11, 7);
1041(%o1)                          330
1042@end group
1043@group
1044(%i2) 11! / 7! / (11 - 7)!;
1045(%o2)                          330
1046@end group
1047@group
1048(%i3) binomial (x, 7);
1049        (x - 6) (x - 5) (x - 4) (x - 3) (x - 2) (x - 1) x
1050(%o3)   -------------------------------------------------
1051                              5040
1052@end group
1053@group
1054(%i4) binomial (x + 7, x);
1055      (x + 1) (x + 2) (x + 3) (x + 4) (x + 5) (x + 6) (x + 7)
1056(%o4) -------------------------------------------------------
1057                               5040
1058@end group
1059@group
1060(%i5) binomial (11, y);
1061(%o5)                    binomial(11, y)
1062@end group
1063@end example
1064
1065@opencatbox
1066@category{Number theory}
1067@closecatbox
1068@end deffn
1069
1070@c -----------------------------------------------------------------------------
1071@anchor{factcomb}
1072@deffn {Function} factcomb (@var{expr})
1073
1074Tries to combine the coefficients of factorials in @var{expr}
1075with the factorials themselves by converting, for example, @code{(n + 1)*n!}
1076into @code{(n + 1)!}.
1077
1078@mref{sumsplitfact} if set to @code{false} will cause @mref{minfactorial} to be
1079applied after a @code{factcomb}.
1080
1081Example:
1082
1083@c ===beg===
1084@c sumsplitfact;
1085@c (n + 1)*(n + 1)*n!;
1086@c factcomb (%);
1087@c sumsplitfact: not sumsplitfact;
1088@c (n + 1)*(n + 1)*n!;
1089@c factcomb (%);
1090@c ===end===
1091@example
1092@group
1093(%i1) sumsplitfact;
1094(%o1)                         true
1095@end group
1096@group
1097(%i2) (n + 1)*(n + 1)*n!;
1098                                  2
1099(%o2)                      (n + 1)  n!
1100@end group
1101@group
1102(%i3) factcomb (%);
1103(%o3)                  (n + 2)! - (n + 1)!
1104@end group
1105@group
1106(%i4) sumsplitfact: not sumsplitfact;
1107(%o4)                         false
1108@end group
1109@group
1110(%i5) (n + 1)*(n + 1)*n!;
1111                                  2
1112(%o5)                      (n + 1)  n!
1113@end group
1114@group
1115(%i6) factcomb (%);
1116(%o6)                 n (n + 1)! + (n + 1)!
1117@end group
1118@end example
1119
1120@opencatbox
1121@category{Gamma and factorial functions}
1122@closecatbox
1123@end deffn
1124
1125@c -----------------------------------------------------------------------------
1126@anchor{!}
1127@anchor{factorial}
1128@deffn  {Function} factorial
1129@deffnx {Operator} !
1130
1131Represents the factorial function.  Maxima treats @code{factorial (@var{x})}
1132the same as @code{@var{x}!}.
1133
1134For any complex number @code{x}, except for negative integers, @code{x!} is
1135defined as @code{gamma(x+1)}.
1136
1137For an integer @code{x}, @code{x!} simplifies to the product of the integers
1138from 1 to @code{x} inclusive.  @code{0!} simplifies to 1.  For a real or complex
1139number in float or bigfloat precision @code{x}, @code{x!} simplifies to the
1140value of @code{gamma (x+1)}.  For @code{x} equal to @code{n/2} where @code{n} is
1141an odd integer, @code{x!} simplifies to a rational factor times
1142@code{sqrt (%pi)} (since @code{gamma (1/2)} is equal to @code{sqrt (%pi)}).
1143
1144The option variables @mref{factlim} and @mref{gammalim} control the numerical
1145evaluation of factorials for integer and rational arguments.  The functions
1146@mref{minfactorial} and @mref{factcomb} simplifies expressions containing
1147factorials.
1148
1149The functions @mrefcomma{gamma} @mrefcomma{bffac} and @mref{cbffac} are
1150varieties of the gamma function.  @code{bffac} and @code{cbffac} are called
1151internally by @code{gamma} to evaluate the gamma function for real and complex
1152numbers in bigfloat precision.
1153
1154@mref{makegamma} substitutes @code{gamma} for factorials and related functions.
1155
1156Maxima knows the derivative of the factorial function and the limits for
1157specific values like negative integers.
1158
1159The option variable @mref{factorial_expand} controls the simplification of
1160expressions like @code{(n+x)!}, where @code{n} is an integer.
1161
1162See also @mrefdot{binomial}
1163
1164The factorial of an integer is simplified to an exact number unless the operand
1165is greater than @code{factlim}.  The factorial for real and complex numbers is
1166evaluated in float or bigfloat precision.
1167
1168@c ===beg===
1169@c factlim : 10;
1170@c [0!, (7/2)!, 8!, 20!];
1171@c [4,77!, (1.0+%i)!];
1172@c [2.86b0!, (1.0b0+%i)!];
1173@c ===end===
1174@example
1175@group
1176(%i1) factlim : 10;
1177(%o1)                          10
1178@end group
1179@group
1180(%i2) [0!, (7/2)!, 8!, 20!];
1181                     105 sqrt(%pi)
1182(%o2)            [1, -------------, 40320, 20!]
1183                          16
1184@end group
1185@group
1186(%i3) [4,77!, (1.0+%i)!];
1187(%o3) [4, 77!, 0.3430658398165453 %i + 0.6529654964201667]
1188@end group
1189@group
1190(%i4) [2.86b0!, 1.0b0+%i)!];
1191incorrect syntax: Missing ]
1192[2.86b0!, 1.0b0+%i)
1193                 ^
1194@end group
1195@end example
1196
1197The factorial of a known constant, or general expression is not simplified.
1198Even so it may be possible to simplify the factorial after evaluating the
1199operand.
1200
1201@c ===beg===
1202@c [(%i + 1)!, %pi!, %e!, (cos(1) + sin(1))!];
1203@c ev (%, numer, %enumer);
1204@c ===end===
1205@example
1206@group
1207(%i1) [(%i + 1)!, %pi!, %e!, (cos(1) + sin(1))!];
1208(%o1)      [(%i + 1)!, %pi!, %e!, (sin(1) + cos(1))!]
1209@end group
1210@group
1211(%i2) ev (%, numer, %enumer);
1212(%o2) [0.3430658398165453 %i + 0.6529654964201667,
1213         7.188082728976031, 4.260820476357003, 1.227580202486819]
1214@end group
1215@end example
1216
1217@c REMOVING THIS EXAMPLE. IT IS NOT SPECIFIC FOR THE FACTORIAL FUNCTION:
1218@c The factorial of an unbound symbol is not simplified.
1219
1220@c @c ===beg===
1221@c @c kill (foo);
1222@c @c foo!;
1223@c @c ===end===
1224@c @example
1225@c (%i1) kill (foo);
1226@c (%o1)                         done
1227@c (%i2) foo!;
1228@c (%o2)                         foo!
1229@c @end example
1230
1231Factorials are simplified, not evaluated.
1232Thus @code{x!} may be replaced even in a quoted expression.
1233
1234@c ===beg===
1235@c '([0!, (7/2)!, 4.77!, 8!, 20!]);
1236@c ===end===
1237@example
1238@group
1239(%i1) '([0!, (7/2)!, 4.77!, 8!, 20!]);
1240          105 sqrt(%pi)
1241(%o1) [1, -------------, 81.44668037931197, 40320,
1242               16
1243                                             2432902008176640000]
1244@end group
1245@end example
1246
1247Maxima knows the derivative of the factorial function.
1248
1249@c ===beg===
1250@c diff(x!,x);
1251@c ===end===
1252@example
1253@group
1254(%i1) diff(x!,x);
1255(%o1)                    x! psi (x + 1)
1256                               0
1257@end group
1258@end example
1259
1260The option variable @code{factorial_expand} controls expansion and
1261simplification of expressions with the factorial function.
1262
1263@c ===beg===
1264@c (n+1)!/n!,factorial_expand:true;
1265@c ===end===
1266@example
1267@group
1268(%i1) (n+1)!/n!,factorial_expand:true;
1269(%o1)                         n + 1
1270@end group
1271@end example
1272
1273@opencatbox
1274@category{Gamma and factorial functions}
1275@category{Operators}
1276@closecatbox
1277@end deffn
1278
1279@c NEEDS EXAMPLES
1280
1281@c -----------------------------------------------------------------------------
1282@anchor{factlim}
1283@defvr {Option variable} factlim
1284Default value: 100000
1285
1286@code{factlim} specifies the highest factorial which is
1287automatically expanded.  If it is -1 then all integers are expanded.
1288
1289@opencatbox
1290@category{Gamma and factorial functions}
1291@closecatbox
1292@end defvr
1293
1294@c -----------------------------------------------------------------------------
1295@anchor{factorial_expand}
1296@defvr {Option variable} factorial_expand
1297Default value: false
1298
1299The option variable @code{factorial_expand} controls the simplification of
1300expressions like @code{(n+1)!}, where @code{n} is an integer.
1301See @mref{factorial} for an example.
1302
1303@opencatbox
1304@category{Gamma and factorial functions}
1305@closecatbox
1306@end defvr
1307
1308@c IS THIS DEFINITION CORRECT ??
1309
1310@c -----------------------------------------------------------------------------
1311@anchor{genfact}
1312@deffn {Function} genfact (@var{x}, @var{y}, @var{z})
1313
1314Returns the generalized factorial, defined as
1315@code{x (x-z) (x - 2 z) ... (x - (y - 1) z)}.  Thus, when @var{x} is an integer,
1316@code{genfact (x, x, 1) = x!} and @code{genfact (x, x/2, 2) = x!!}.
1317
1318@opencatbox
1319@category{Gamma and factorial functions}
1320@closecatbox
1321@end deffn
1322
1323@c -----------------------------------------------------------------------------
1324@anchor{minfactorial}
1325@deffn {Function} minfactorial (@var{expr})
1326
1327Examines @var{expr} for occurrences of two factorials
1328which differ by an integer.
1329@code{minfactorial} then turns one into a polynomial times the other.
1330
1331@c I CAN'T TELL WHAT THIS IS SUPPOSED TO MEAN. !!!
1332@c minfactorial DOESN'T SEEM TO DO ANYTHING binomial DOESN'T DO BY ITSELF !!!
1333@c LOOKING AT THE minfactorial CODE DOESN'T HELP !!!
1334@c If exp involves binomial coefficients then they will be
1335@c converted into ratios of factorials.
1336
1337@c ===beg===
1338@c n!/(n+2)!;
1339@c minfactorial (%);
1340@c ===end===
1341@example
1342(%i1) n!/(n+2)!;
1343                               n!
1344(%o1)                       --------
1345                            (n + 2)!
1346(%i2) minfactorial (%);
1347                                1
1348(%o2)                    ---------------
1349                         (n + 1) (n + 2)
1350@end example
1351
1352@opencatbox
1353@category{Number theory}
1354@closecatbox
1355@end deffn
1356
1357@c -----------------------------------------------------------------------------
1358@anchor{sumsplitfact}
1359@defvr {Option variable} sumsplitfact
1360Default value: @code{true}
1361
1362When @code{sumsplitfact} is @code{false},
1363@c "IS APPLIED" -- UNDER WHAT CIRCUMSTANCES EXACTLY ??
1364@mref{minfactorial} is applied after a @mrefdot{factcomb}
1365
1366@c ===beg===
1367@c sumsplitfact;
1368@c n!/(n+2)!;
1369@c factcomb(%);
1370@c sumsplitfact: not sumsplitfact ;
1371@c n!/(n+2)!;
1372@c factcomb(%);
1373@c ===end===
1374@example
1375@group
1376(%i1) sumsplitfact;
1377(%o1)                         true
1378@end group
1379@group
1380(%i2) n!/(n+2)!;
1381                               n!
1382(%o2)                       --------
1383                            (n + 2)!
1384@end group
1385@group
1386(%i3) factcomb(%);
1387                               n!
1388(%o3)                       --------
1389                            (n + 2)!
1390@end group
1391@group
1392(%i4) sumsplitfact: not sumsplitfact ;
1393(%o4)                         false
1394@end group
1395@group
1396(%i5) n!/(n+2)!;
1397                               n!
1398(%o5)                       --------
1399                            (n + 2)!
1400@end group
1401@group
1402(%i6) factcomb(%);
1403                                1
1404(%o6)                    ---------------
1405                         (n + 1) (n + 2)
1406@end group
1407@end example
1408
1409@opencatbox
1410@category{Gamma and factorial functions}
1411@category{Simplification flags and variables}
1412@closecatbox
1413@end defvr
1414
1415@c -----------------------------------------------------------------------------
1416@node Root Exponential and Logarithmic Functions, Trigonometric Functions, Combinatorial Functions, Mathematical Functions
1417@section Root, Exponential and Logarithmic Functions
1418@c -----------------------------------------------------------------------------
1419
1420@c -----------------------------------------------------------------------------
1421@anchor{%e_to_numlog}
1422@defvr {Option variable} %e_to_numlog
1423Default value: @code{false}
1424
1425When @code{true}, @code{r} some rational number, and @code{x} some expression,
1426@code{%e^(r*log(x))} will be simplified into @code{x^r} .  It should be noted
1427that the @code{radcan} command also does this transformation, and more
1428complicated transformations of this ilk as well.  The @code{logcontract}
1429command "contracts" expressions containing @code{log}.
1430
1431@opencatbox
1432@category{Exponential and logarithm functions}
1433@category{Simplification flags and variables}
1434@closecatbox
1435@end defvr
1436
1437@c -----------------------------------------------------------------------------
1438@anchor{%emode}
1439@defvr {Option variable} %emode
1440Default value: @code{true}
1441
1442When @code{%emode} is @code{true}, @code{%e^(%pi %i x)} is simplified as
1443follows.
1444
1445@code{%e^(%pi %i x)} simplifies to @code{cos (%pi x) + %i sin (%pi x)} if
1446@code{x} is a floating point number, an integer, or a multiple of 1/2, 1/3, 1/4,
1447or 1/6, and then further simplified.
1448
1449For other numerical @code{x}, @code{%e^(%pi %i x)} simplifies to
1450@code{%e^(%pi %i y)} where @code{y} is @code{x - 2 k} for some integer @code{k}
1451such that @code{abs(y) < 1}.
1452
1453When @code{%emode} is @code{false}, no special simplification of
1454@code{%e^(%pi %i x)} is carried out.
1455
1456@c ===beg===
1457@c %emode;
1458@c %e^(%pi*%i*1);
1459@c %e^(%pi*%i*216/144);
1460@c %e^(%pi*%i*192/144);
1461@c %e^(%pi*%i*180/144);
1462@c %e^(%pi*%i*120/144);
1463@c %e^(%pi*%i*121/144);
1464@c ===end===
1465@example
1466@group
1467(%i1) %emode;
1468(%o1)                         true
1469@end group
1470@group
1471(%i2) %e^(%pi*%i*1);
1472(%o2)                          - 1
1473@end group
1474@group
1475(%i3) %e^(%pi*%i*216/144);
1476(%o3)                         - %i
1477@end group
1478@group
1479(%i4) %e^(%pi*%i*192/144);
1480                          sqrt(3) %i    1
1481(%o4)                  (- ----------) - -
1482                              2         2
1483@end group
1484@group
1485(%i5) %e^(%pi*%i*180/144);
1486                           %i          1
1487(%o5)                 (- -------) - -------
1488                         sqrt(2)    sqrt(2)
1489@end group
1490@group
1491(%i6) %e^(%pi*%i*120/144);
1492                          %i   sqrt(3)
1493(%o6)                     -- - -------
1494                          2       2
1495@end group
1496@group
1497(%i7) %e^(%pi*%i*121/144);
1498                            121 %i %pi
1499                            ----------
1500                               144
1501(%o7)                     %e
1502@end group
1503@end example
1504
1505@opencatbox
1506@category{Exponential and logarithm functions}
1507@category{Simplification flags and variables}
1508@closecatbox
1509@end defvr
1510
1511@c -----------------------------------------------------------------------------
1512@anchor{%enumer}
1513@defvr {Option variable} %enumer
1514Default value: @code{false}
1515
1516When @code{%enumer} is @code{true}, @code{%e} is replaced by its numeric value
15172.718@dots{}  whenever @code{numer} is @code{true}.
1518
1519When @code{%enumer} is @code{false}, this substitution is carried out
1520only if the exponent in @code{%e^x} evaluates to a number.
1521
1522See also @mref{ev} and @mrefdot{numer}
1523
1524@c ===beg===
1525@c %enumer;
1526@c numer;
1527@c 2*%e;
1528@c %enumer: not %enumer;
1529@c 2*%e;
1530@c numer: not numer;
1531@c 2*%e;
1532@c 2*%e^1;
1533@c 2*%e^x;
1534@c ===end===
1535@example
1536@group
1537(%i1) %enumer;
1538(%o1)                         false
1539@end group
1540@group
1541(%i2) numer;
1542(%o2)                         false
1543@end group
1544@group
1545(%i3) 2*%e;
1546(%o3)                         2 %e
1547@end group
1548@group
1549(%i4) %enumer: not %enumer;
1550(%o4)                         true
1551@end group
1552@group
1553(%i5) 2*%e;
1554(%o5)                         2 %e
1555@end group
1556@group
1557(%i6) numer: not numer;
1558(%o6)                         true
1559@end group
1560@group
1561(%i7) 2*%e;
1562(%o7)                   5.43656365691809
1563@end group
1564@group
1565(%i8) 2*%e^1;
1566(%o8)                   5.43656365691809
1567@end group
1568@group
1569(%i9) 2*%e^x;
1570                                         x
1571(%o9)                 2 2.718281828459045
1572@end group
1573@end example
1574
1575@opencatbox
1576@category{Exponential and logarithm functions}
1577@category{Evaluation flags}
1578@closecatbox
1579@end defvr
1580
1581@c PROBABLY MORE TO BE SAID HERE
1582
1583@c -----------------------------------------------------------------------------
1584@anchor{exp}
1585@deffn {Function} exp (@var{x})
1586
1587Represents the exponential function.  Instances of @code{exp (@var{x})} in input
1588are simplified to @code{%e^@var{x}}; @code{exp} does not appear in simplified
1589expressions.
1590
1591@code{demoivre} if @code{true} causes @code{%e^(a + b %i)} to simplify to
1592@code{%e^(a (cos(b) + %i sin(b)))} if @code{b} is free of @code{%i}.
1593See @mrefdot{demoivre}
1594
1595@code{%emode}, when @code{true}, causes @code{%e^(%pi %i x)} to be simplified.
1596See @mrefdot{%emode}
1597
1598@code{%enumer}, when @code{true} causes @code{%e} to be replaced by
15992.718@dots{} whenever @code{numer} is @code{true}.  See @mrefdot{%enumer}
1600
1601@c ===beg===
1602@c demoivre;
1603@c %e^(a + b*%i);
1604@c demoivre: not demoivre;
1605@c %e^(a + b*%i);
1606@c ===end===
1607@example
1608@group
1609(%i1) demoivre;
1610(%o1)                         false
1611@end group
1612@group
1613(%i2) %e^(a + b*%i);
1614                             %i b + a
1615(%o2)                      %e
1616@end group
1617@group
1618(%i3) demoivre: not demoivre;
1619(%o3)                         true
1620@end group
1621@group
1622(%i4) %e^(a + b*%i);
1623                      a
1624(%o4)               %e  (%i sin(b) + cos(b))
1625@end group
1626@end example
1627
1628@opencatbox
1629@category{Exponential and logarithm functions}
1630@closecatbox
1631@end deffn
1632
1633
1634@c -----------------------------------------------------------------------------
1635@anchor{li}
1636@deffn {Function} li [@var{s}] (@var{z})
1637
1638Represents the polylogarithm function of order @var{s} and argument @var{z},
1639defined by the infinite series
1640
1641@tex
1642$${\rm Li}_s \left(z\right) = \sum_{k=1}^\infty {z^k \over k^s}$$
1643@end tex
1644@ifnottex
1645@example
1646                                 inf
1647                                 ====   k
1648                                 \     z
1649                        Li (z) =  >    --
1650                          s      /      s
1651                                 ====  k
1652                                 k = 1
1653@end example
1654@end ifnottex
1655
1656@code{li [1]} is @code{- log (1 - z)}.  @code{li [2]} and @code{li [3]} are the
1657dilogarithm and trilogarithm functions, respectively.
1658
1659When the order is 1, the polylogarithm simplifies to @code{- log (1 - z)}, which
1660in turn simplifies to a numerical value if @var{z} is a real or complex floating
1661point number or the @code{numer} evaluation flag is present.
1662
1663When the order is 2 or 3,
1664the polylogarithm simplifies to a numerical value
1665if @var{z} is a real floating point number
1666or the @code{numer} evaluation flag is present.
1667
1668Examples:
1669
1670@c ===beg===
1671@c assume (x > 0);
1672@c integrate ((log (1 - t)) / t, t, 0, x);
1673@c li [2] (7);
1674@c li [2] (7), numer;
1675@c li [3] (7);
1676@c li [2] (7), numer;
1677@c L : makelist (i / 4.0, i, 0, 8);
1678@c map (lambda ([x], li [2] (x)), L);
1679@c map (lambda ([x], li [3] (x)), L);
1680@c ===end===
1681@example
1682@group
1683(%i1) assume (x > 0);
1684(%o1)                        [x > 0]
1685@end group
1686@group
1687(%i2) integrate ((log (1 - t)) / t, t, 0, x);
1688(%o2)                       - li (x)
1689                                2
1690@end group
1691@group
1692(%i3) li [2] (7);
1693(%o3)                        li (7)
1694                               2
1695@end group
1696@group
1697(%i4) li [2] (7), numer;
1698(%o4)       1.248273182099423 - 6.113257028817991 %i
1699@end group
1700@group
1701(%i5) li [3] (7);
1702(%o5)                        li (7)
1703                               3
1704@end group
1705@group
1706(%i6) li [2] (7), numer;
1707(%o6)       1.248273182099423 - 6.113257028817991 %i
1708@end group
1709@group
1710(%i7) L : makelist (i / 4.0, i, 0, 8);
1711(%o7)   [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
1712@end group
1713@group
1714(%i8) map (lambda ([x], li [2] (x)), L);
1715(%o8) [0.0, 0.2676526390827326, 0.5822405264650125,
17160.978469392930306, 1.644934066848226,
17172.190177011441645 - 0.7010261415046585 %i,
17182.37439527027248 - 1.2738062049196 %i,
17192.448686765338205 - 1.758084848210787 %i,
17202.467401100272339 - 2.177586090303601 %i]
1721@end group
1722@group
1723(%i9) map (lambda ([x], li [3] (x)), L);
1724(%o9) [0.0, 0.2584613953442624, 0.537213192678042,
17250.8444258046482203, 1.2020569, 1.642866878950322
1726 - 0.07821473130035025 %i, 2.060877505514697
1727 - 0.2582419849982037 %i, 2.433418896388322
1728 - 0.4919260182322965 %i, 2.762071904015935
1729 - 0.7546938285978846 %i]
1730@end group
1731@end example
1732
1733@opencatbox
1734@category{Exponential and logarithm functions}
1735@closecatbox
1736@end deffn
1737
1738@c -----------------------------------------------------------------------------
1739@anchor{log}
1740@deffn {Function} log (@var{x})
1741
1742Represents the natural (base @math{e}) logarithm of @var{x}.
1743
1744Maxima does not have a built-in function for the base 10 logarithm or other
1745bases. @code{log10(x) := log(x) / log(10)} is a useful definition.
1746
1747Simplification and evaluation of logarithms is governed by several global flags:
1748
1749@table @code
1750@item @code{logexpand}
1751causes @code{log(a^b)} to become @code{b*log(a)}. If it is
1752set to @code{all}, @code{log(a*b)} will also simplify to @code{log(a)+log(b)}.
1753If it is set to @code{super}, then @code{log(a/b)} will also simplify to
1754@code{log(a)-log(b)} for rational numbers @code{a/b}, @code{a#1}.
1755(@code{log(1/b)}, for @code{b} integer, always simplifies.) If it is set to
1756@code{false}, all of these simplifications will be turned off.
1757
1758@item @code{logsimp}
1759if @code{false} then no simplification of @code{%e} to a power containing
1760@code{log}'s is done.
1761
1762@item @code{lognegint}
1763if @code{true} implements the rule @code{log(-n)} -> @code{log(n)+%i*%pi} for
1764@code{n} a positive integer.
1765
1766@item @code{%e_to_numlog}
1767when @code{true}, @code{r} some rational number, and @code{x} some expression,
1768the expression @code{%e^(r*log(x))} will be simplified into @code{x^r}.  It
1769should be noted that the @code{radcan} command also does this transformation,
1770and more complicated transformations of this as well. The @code{logcontract}
1771command "contracts" expressions containing @code{log}.
1772@end table
1773
1774@opencatbox
1775@category{Exponential and logarithm functions}
1776@closecatbox
1777@end deffn
1778
1779@c -----------------------------------------------------------------------------
1780@anchor{logabs}
1781@defvr {Option variable} logabs
1782Default value: @code{false}
1783
1784When doing indefinite integration where logs are generated, e.g.
1785@code{integrate(1/x,x)}, the answer is given in terms of @code{log(abs(...))}
1786if @code{logabs} is @code{true}, but in terms of @code{log(...)} if
1787@code{logabs} is @code{false}.  For definite integration, the @code{logabs:true}
1788setting is used, because here "evaluation" of the indefinite integral at the
1789endpoints is often needed.
1790
1791@opencatbox
1792@category{Exponential and logarithm functions}
1793@category{Integral calculus}
1794@category{Global flags}
1795@closecatbox
1796@end defvr
1797
1798@c NEEDS EXAMPLES
1799
1800@c -----------------------------------------------------------------------------
1801@deffn {Function} logarc (@var{expr})
1802
1803The function @code{logarc(@var{expr})} carries out the replacement of
1804inverse circular and hyperbolic functions with equivalent logarithmic
1805functions for an expression @var{expr} without setting the global
1806variable @code{logarc}.
1807
1808@opencatbox
1809@category{Exponential and logarithm functions}
1810@category{Simplification flags and variables}
1811@category{Simplification functions}
1812@closecatbox
1813@end deffn
1814
1815@anchor{logarc}
1816@defvr  {Option variable} logarc
1817
1818When the global variable @code{logarc} is @code{true},
1819inverse circular and hyperbolic functions are replaced by
1820equivalent logarithmic functions.
1821The default value of @code{logarc} is @code{false}.
1822
1823@opencatbox
1824@category{Exponential and logarithm functions}
1825@category{Simplification flags and variables}
1826@category{Simplification functions}
1827@closecatbox
1828@end defvr
1829
1830@c -----------------------------------------------------------------------------
1831@anchor{logconcoeffp}
1832@defvr {Option variable} logconcoeffp
1833Default value: @code{false}
1834
1835Controls which coefficients are
1836contracted when using @code{logcontract}.  It may be set to the name of a
1837predicate function of one argument.  E.g. if you like to generate
1838SQRTs, you can do @code{logconcoeffp:'logconfun$
1839logconfun(m):=featurep(m,integer) or ratnump(m)$} .  Then
1840@code{logcontract(1/2*log(x));} will give @code{log(sqrt(x))}.
1841
1842@opencatbox
1843@category{Exponential and logarithm functions}
1844@category{Simplification flags and variables}
1845@closecatbox
1846@end defvr
1847
1848@c -----------------------------------------------------------------------------
1849@anchor{logcontract}
1850@deffn {Function} logcontract (@var{expr})
1851
1852Recursively scans the expression @var{expr}, transforming
1853subexpressions of the form @code{a1*log(b1) + a2*log(b2) + c} into
1854@code{log(ratsimp(b1^a1 * b2^a2)) + c}
1855
1856@c ===beg===
1857@c 2*(a*log(x) + 2*a*log(y))$
1858@c logcontract(%);
1859@c ===end===
1860@example
1861(%i1) 2*(a*log(x) + 2*a*log(y))$
1862@group
1863(%i2) logcontract(%);
1864                                 2  4
1865(%o2)                     a log(x  y )
1866@end group
1867@end example
1868
1869The declaration @code{declare(n,integer)} causes
1870@code{logcontract(2*a*n*log(x))} to simplify to @code{a*log(x^(2*n))}.  The
1871coefficients that "contract" in this manner are those such as the 2 and the
1872@code{n} here which satisfy @code{featurep(coeff,integer)}.  The user can
1873control which coefficients are contracted by setting the option
1874@code{logconcoeffp} to the name of a predicate function of one argument.
1875E.g. if you like to generate SQRTs, you can do @code{logconcoeffp:'logconfun$
1876logconfun(m):=featurep(m,integer) or ratnump(m)$} .  Then
1877@code{logcontract(1/2*log(x));} will give @code{log(sqrt(x))}.
1878
1879@opencatbox
1880@category{Exponential and logarithm functions}
1881@closecatbox
1882@end deffn
1883
1884@c -----------------------------------------------------------------------------
1885@anchor{logexpand}
1886@defvr {Option variable} logexpand
1887Default value: @code{true}
1888
1889If @code{true}, that is the default value, causes @code{log(a^b)} to become
1890@code{b*log(a)}.  If it is set to @code{all}, @code{log(a*b)} will also simplify
1891to @code{log(a)+log(b)}.  If it is set to @code{super}, then @code{log(a/b)}
1892will also simplify to @code{log(a)-log(b)} for rational numbers @code{a/b},
1893@code{a#1}.  (@code{log(1/b)}, for integer @code{b}, always simplifies.) If it
1894is set to @code{false}, all of these simplifications will be turned off.
1895
1896When @code{logexpand} is set to @code{all} or @code{super},
1897the logarithm of a product expression simplifies to a summation of logarithms.
1898
1899Examples:
1900
1901When @code{logexpand} is @code{true},
1902@code{log(a^b)} simplifies to @code{b*log(a)}.
1903
1904@c ===beg===
1905@c log(n^2), logexpand=true;
1906@c ===end===
1907@example
1908(%i1) log(n^2), logexpand=true;
1909(%o1)                       2 log(n)
1910@end example
1911
1912When @code{logexpand} is @code{all},
1913@code{log(a*b)} simplifies to @code{log(a)+log(b)}.
1914
1915@c ===beg===
1916@c log(10*x), logexpand=all;
1917@c ===end===
1918@example
1919(%i1) log(10*x), logexpand=all;
1920(%o1)                   log(x) + log(10)
1921@end example
1922
1923When @code{logexpand} is @code{super},
1924@code{log(a/b)} simplifies to @code{log(a)-log(b)}
1925for rational numbers @code{a/b} with @code{a#1}.
1926
1927@c ===beg===
1928@c log(a/(n + 1)), logexpand=super;
1929@c ===end===
1930@example
1931(%i1) log(a/(n + 1)), logexpand=super;
1932(%o1)                  log(a) - log(n + 1)
1933@end example
1934
1935When @code{logexpand} is set to @code{all} or @code{super},
1936the logarithm of a product expression simplifies to a summation of logarithms.
1937
1938@c ===beg===
1939@c my_product : product (X(i), i, 1, n);
1940@c log(my_product), logexpand=all;
1941@c log(my_product), logexpand=super;
1942@c ===end===
1943@example
1944(%i1) my_product : product (X(i), i, 1, n);
1945                             n
1946                           /===\
1947                            ! !
1948(%o1)                       ! !  X(i)
1949                            ! !
1950                           i = 1
1951(%i2) log(my_product), logexpand=all;
1952                          n
1953                         ====
1954                         \
1955(%o2)                     >    log(X(i))
1956                         /
1957                         ====
1958                         i = 1
1959(%i3) log(my_product), logexpand=super;
1960                          n
1961                         ====
1962                         \
1963(%o3)                     >    log(X(i))
1964                         /
1965                         ====
1966                         i = 1
1967@end example
1968
1969When @code{logexpand} is @code{false},
1970these simplifications are disabled.
1971
1972@c ===beg===
1973@c logexpand : false $
1974@c log(n^2);
1975@c log(10*x);
1976@c log(a/(n + 1));
1977@c log ('product (X(i), i, 1, n));
1978@c ===end===
1979@example
1980(%i1) logexpand : false $
1981(%i2) log(n^2);
1982                                  2
1983(%o2)                        log(n )
1984(%i3) log(10*x);
1985(%o3)                       log(10 x)
1986(%i4) log(a/(n + 1));
1987                                 a
1988(%o4)                      log(-----)
1989                               n + 1
1990(%i5) log ('product (X(i), i, 1, n));
1991                               n
1992                             /===\
1993                              ! !
1994(%o5)                    log( ! !  X(i))
1995                              ! !
1996                             i = 1
1997@end example
1998
1999@opencatbox
2000@category{Exponential and logarithm functions}
2001@category{Simplification flags and variables}
2002@closecatbox
2003@end defvr
2004
2005@c -----------------------------------------------------------------------------
2006@anchor{lognegint}
2007@defvr {Option variable} lognegint
2008Default value: @code{false}
2009
2010If @code{true} implements the rule
2011@code{log(-n)} -> @code{log(n)+%i*%pi} for @code{n} a positive integer.
2012
2013@opencatbox
2014@category{Exponential and logarithm functions}
2015@category{Simplification flags and variables}
2016@closecatbox
2017@end defvr
2018
2019@c -----------------------------------------------------------------------------
2020@anchor{logsimp}
2021@defvr {Option variable} logsimp
2022Default value: @code{true}
2023
2024If @code{false} then no simplification of @code{%e} to a
2025power containing @code{log}'s is done.
2026
2027@opencatbox
2028@category{Exponential and logarithm functions}
2029@category{Simplification flags and variables}
2030@closecatbox
2031@end defvr
2032
2033@c -----------------------------------------------------------------------------
2034@anchor{plog}
2035@deffn {Function} plog (@var{x})
2036
2037Represents the principal branch of the complex-valued natural
2038logarithm with @code{-%pi} < @code{carg(@var{x})} <= @code{+%pi} .
2039
2040@opencatbox
2041@category{Exponential and logarithm functions}
2042@category{Complex variables}
2043@closecatbox
2044@end deffn
2045
2046@c -----------------------------------------------------------------------------
2047@anchor{sqrt}
2048@deffn {Function} sqrt (@var{x})
2049
2050The square root of @var{x}.  It is represented internally by
2051@code{@var{x}^(1/2)}.  See also @mref{rootscontract} and @mrefdot{radexpand}
2052
2053@opencatbox
2054@category{Mathematical functions}
2055@closecatbox
2056@end deffn
2057
2058@c -----------------------------------------------------------------------------
2059@page
2060@node Trigonometric Functions, Random Numbers, Root Exponential and Logarithmic Functions, Mathematical Functions
2061@section Trigonometric Functions
2062@c -----------------------------------------------------------------------------
2063
2064@menu
2065* Introduction to Trigonometric::
2066* Functions and Variables for Trigonometric::
2067@end menu
2068
2069@c -----------------------------------------------------------------------------
2070@node Introduction to Trigonometric, Functions and Variables for Trigonometric, Trigonometric Functions, Trigonometric Functions
2071@subsection Introduction to Trigonometric
2072@c -----------------------------------------------------------------------------
2073
2074Maxima has many trigonometric functions defined.  Not all trigonometric
2075identities are programmed, but it is possible for the user to add many
2076of them using the pattern matching capabilities of the system.  The
2077trigonometric functions defined in Maxima are: @code{acos},
2078@code{acosh}, @code{acot}, @code{acoth}, @code{acsc},
2079@code{acsch}, @code{asec}, @code{asech}, @code{asin},
2080@code{asinh}, @code{atan}, @code{atanh}, @code{cos},
2081@code{cosh}, @code{cot}, @code{coth}, @code{csc}, @code{csch},
2082@code{sec}, @code{sech}, @code{sin}, @code{sinh}, @code{tan},
2083and @code{tanh}.  There are a number of commands especially for
2084handling trigonometric functions, see @code{trigexpand},
2085@code{trigreduce}, and the switch @code{trigsign}.  Two share
2086packages extend the simplification rules built into Maxima,
2087@code{ntrig} and @code{atrig1}.  Do @code{describe(@var{command})}
2088for details.
2089
2090@opencatbox
2091@category{Trigonometric functions}
2092@closecatbox
2093
2094@c -----------------------------------------------------------------------------
2095@node Functions and Variables for Trigonometric,  , Introduction to Trigonometric, Trigonometric Functions
2096@subsection Functions and Variables for Trigonometric
2097@c -----------------------------------------------------------------------------
2098
2099@c -----------------------------------------------------------------------------
2100@anchor{%piargs}
2101@defvr {Option variable} %piargs
2102Default value: @code{true}
2103
2104When @code{%piargs} is @code{true},
2105trigonometric functions are simplified to algebraic constants
2106when the argument is an integer multiple of
2107@iftex
2108@math{\pi}, @math{\pi/2}, @math{\pi/3}, @math{\pi/4}, or @math{\pi/6}.
2109@end iftex
2110@ifnottex
2111@math{%pi}, @math{%pi/2}, @math{%pi/3}, @math{%pi/4}, or @math{%pi/6}.
2112@end ifnottex
2113
2114@iftex
2115Maxima knows some identities which can be applied when @math{\pi}, etc.,
2116@end iftex
2117@ifnottex
2118Maxima knows some identities which can be applied when @math{%pi}, etc.,
2119@end ifnottex
2120are multiplied by an integer variable (that is, a symbol declared to be
2121integer).
2122
2123Examples:
2124
2125@c ===beg===
2126@c %piargs : false$
2127@c [sin (%pi), sin (%pi/2), sin (%pi/3)];
2128@c [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2129@c %piargs : true$
2130@c [sin (%pi), sin (%pi/2), sin (%pi/3)];
2131@c [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2132@c [cos (%pi/3), cos (10*%pi/3), tan (10*%pi/3),
2133@c        cos (sqrt(2)*%pi/3)];
2134@c ===end===
2135@example
2136(%i1) %piargs : false$
2137@group
2138(%i2) [sin (%pi), sin (%pi/2), sin (%pi/3)];
2139                                %pi       %pi
2140(%o2)            [sin(%pi), sin(---), sin(---)]
2141                                 2         3
2142@end group
2143@group
2144(%i3) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2145                      %pi       %pi       %pi
2146(%o3)            [sin(---), sin(---), sin(---)]
2147                       4         5         6
2148@end group
2149(%i4) %piargs : true$
2150@group
2151(%i5) [sin (%pi), sin (%pi/2), sin (%pi/3)];
2152                                sqrt(3)
2153(%o5)                    [0, 1, -------]
2154                                   2
2155@end group
2156@group
2157(%i6) [sin (%pi/4), sin (%pi/5), sin (%pi/6)];
2158                         1         %pi   1
2159(%o6)                [-------, sin(---), -]
2160                      sqrt(2)       5    2
2161@end group
2162@group
2163(%i7) [cos (%pi/3), cos (10*%pi/3), tan (10*%pi/3),
2164       cos (sqrt(2)*%pi/3)];
2165                1    1               sqrt(2) %pi
2166(%o7)          [-, - -, sqrt(3), cos(-----------)]
2167                2    2                    3
2168@end group
2169@end example
2170
2171@iftex
2172Some identities are applied when @math{\pi} and @math{\pi/2} are multiplied by
2173an integer variable.
2174@end iftex
2175@ifnottex
2176Some identities are applied when @math{%pi} and @math{%pi/2} are multiplied by
2177an integer variable.
2178@end ifnottex
2179
2180@c ===beg===
2181@c declare (n, integer, m, even)$
2182@c [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
2183@c        cos (%pi/2 * m)];
2184@c ===end===
2185@example
2186(%i1) declare (n, integer, m, even)$
2187@group
2188(%i2) [sin (%pi * n), cos (%pi * m), sin (%pi/2 * m),
2189       cos (%pi/2 * m)];
2190                                      m/2
2191(%o2)                  [0, 1, 0, (- 1)   ]
2192@end group
2193@end example
2194
2195@opencatbox
2196@category{Trigonometric functions}
2197@category{Simplification flags and variables}
2198@closecatbox
2199@end defvr
2200
2201@c -----------------------------------------------------------------------------
2202@anchor{%iargs}
2203@defvr {Option variable} %iargs
2204Default value: @code{true}
2205
2206When @code{%iargs} is @code{true},
2207trigonometric functions are simplified to hyperbolic functions
2208@iftex
2209when the argument is apparently a multiple of the imaginary unit @math{i}.
2210@end iftex
2211@ifnottex
2212when the argument is apparently a multiple of the imaginary unit @math{%i}.
2213@end ifnottex
2214
2215Even when the argument is demonstrably real, the simplification is applied;
2216@iftex
2217Maxima considers only whether the argument is a literal multiple of @math{i}.
2218@end iftex
2219@ifnottex
2220Maxima considers only whether the argument is a literal multiple of @math{%i}.
2221@end ifnottex
2222
2223Examples:
2224
2225@c ===beg===
2226@c %iargs : false$
2227@c [sin (%i * x), cos (%i * x), tan (%i * x)];
2228@c %iargs : true$
2229@c [sin (%i * x), cos (%i * x), tan (%i * x)];
2230@c ===end===
2231@example
2232(%i1) %iargs : false$
2233@group
2234(%i2) [sin (%i * x), cos (%i * x), tan (%i * x)];
2235(%o2)           [sin(%i x), cos(%i x), tan(%i x)]
2236@end group
2237(%i3) %iargs : true$
2238@group
2239(%i4) [sin (%i * x), cos (%i * x), tan (%i * x)];
2240(%o4)           [%i sinh(x), cosh(x), %i tanh(x)]
2241@end group
2242@end example
2243
2244Even when the argument is demonstrably real, the simplification is applied.
2245
2246@c ===beg===
2247@c declare (x, imaginary)$
2248@c [featurep (x, imaginary), featurep (x, real)];
2249@c sin (%i * x);
2250@c ===end===
2251@example
2252(%i1) declare (x, imaginary)$
2253@group
2254(%i2) [featurep (x, imaginary), featurep (x, real)];
2255(%o2)                     [true, false]
2256@end group
2257@group
2258(%i3) sin (%i * x);
2259(%o3)                      %i sinh(x)
2260@end group
2261@end example
2262
2263@opencatbox
2264@category{Trigonometric functions}
2265@category{Hyperbolic functions}
2266@category{Simplification flags and variables}
2267@closecatbox
2268@end defvr
2269
2270@c -----------------------------------------------------------------------------
2271@anchor{acos}
2272@deffn {Function} acos (@var{x})
2273
2274-- Arc Cosine.
2275
2276@opencatbox
2277@category{Trigonometric functions}
2278@closecatbox
2279@end deffn
2280
2281@c -----------------------------------------------------------------------------
2282@anchor{acosh}
2283@deffn {Function} acosh (@var{x})
2284
2285-- Hyperbolic Arc Cosine.
2286
2287@opencatbox
2288@category{Hyperbolic functions}
2289@closecatbox
2290@end deffn
2291
2292@c -----------------------------------------------------------------------------
2293@anchor{acot}
2294@deffn {Function} acot (@var{x})
2295
2296-- Arc Cotangent.
2297
2298@opencatbox
2299@category{Trigonometric functions}
2300@closecatbox
2301@end deffn
2302
2303@c -----------------------------------------------------------------------------
2304@anchor{acoth}
2305@deffn {Function} acoth (@var{x})
2306
2307-- Hyperbolic Arc Cotangent.
2308
2309@opencatbox
2310@category{Hyperbolic functions}
2311@closecatbox
2312@end deffn
2313
2314@c -----------------------------------------------------------------------------
2315@anchor{acsc}
2316@deffn {Function} acsc (@var{x})
2317
2318-- Arc Cosecant.
2319
2320@opencatbox
2321@category{Trigonometric functions}
2322@closecatbox
2323@end deffn
2324
2325@c -----------------------------------------------------------------------------
2326@anchor{acsch}
2327@deffn {Function} acsch (@var{x})
2328
2329-- Hyperbolic Arc Cosecant.
2330
2331@opencatbox
2332@category{Hyperbolic functions}
2333@closecatbox
2334@end deffn
2335
2336@c -----------------------------------------------------------------------------
2337@anchor{asec}
2338@deffn {Function} asec (@var{x})
2339
2340-- Arc Secant.
2341
2342@opencatbox
2343@category{Trigonometric functions}
2344@closecatbox
2345@end deffn
2346
2347@c -----------------------------------------------------------------------------
2348@anchor{asech}
2349@deffn {Function} asech (@var{x})
2350
2351-- Hyperbolic Arc Secant.
2352
2353@opencatbox
2354@category{Hyperbolic functions}
2355@closecatbox
2356@end deffn
2357
2358@c -----------------------------------------------------------------------------
2359@anchor{asin}
2360@deffn {Function} asin (@var{x})
2361
2362-- Arc Sine.
2363
2364@opencatbox
2365@category{Trigonometric functions}
2366@closecatbox
2367@end deffn
2368
2369@c -----------------------------------------------------------------------------
2370@anchor{asinh}
2371@deffn {Function} asinh (@var{x})
2372
2373-- Hyperbolic Arc Sine.
2374
2375@opencatbox
2376@category{Hyperbolic functions}
2377@closecatbox
2378@end deffn
2379
2380@c -----------------------------------------------------------------------------
2381@anchor{atan}
2382@deffn {Function} atan (@var{x})
2383
2384-- Arc Tangent.
2385
2386See also @mref{atan2}.
2387
2388@opencatbox
2389@category{Trigonometric functions}
2390@closecatbox
2391@end deffn
2392
2393@c -----------------------------------------------------------------------------
2394@anchor{atan2}
2395@deffn {Function} atan2 (@var{y}, @var{x})
2396
2397-- yields the value of @code{atan(@var{y}/@var{x})} in the interval @code{-%pi}
2398to @code{%pi}.
2399
2400See also @mref{atan}.
2401
2402@opencatbox
2403@category{Trigonometric functions}
2404@closecatbox
2405@end deffn
2406
2407@c -----------------------------------------------------------------------------
2408@anchor{atanh}
2409@deffn {Function} atanh (@var{x})
2410
2411-- Hyperbolic Arc Tangent.
2412
2413@opencatbox
2414@category{Hyperbolic functions}
2415@closecatbox
2416@end deffn
2417
2418@c IS THIS DESCRIPTION ACCURATE ??
2419@c LET'S BE EXPLICIT ABOUT EXACTLY WHAT ARE THE RULES IMPLEMENTED BY THIS PACKAGE
2420
2421@c -----------------------------------------------------------------------------
2422@anchor{atrig1}
2423@defvr {Package} atrig1
2424
2425The @code{atrig1} package contains several additional simplification rules
2426for inverse trigonometric functions.  Together with rules
2427already known to Maxima, the following angles are fully implemented:
2428@code{0}, @code{%pi/6}, @code{%pi/4}, @code{%pi/3}, and @code{%pi/2}.
2429Corresponding angles in the other three quadrants are also available.
2430Do @code{load("atrig1");} to use them.
2431
2432@opencatbox
2433@category{Trigonometric functions}
2434@category{Package atrig1}
2435@closecatbox
2436@end defvr
2437
2438@c -----------------------------------------------------------------------------
2439@anchor{cos}
2440@deffn {Function} cos (@var{x})
2441
2442-- Cosine.
2443
2444@opencatbox
2445@category{Trigonometric functions}
2446@closecatbox
2447@end deffn
2448
2449@c -----------------------------------------------------------------------------
2450@anchor{cosh}
2451@deffn {Function} cosh (@var{x})
2452
2453-- Hyperbolic Cosine.
2454
2455@opencatbox
2456@category{Hyperbolic functions}
2457@closecatbox
2458@end deffn
2459
2460@c -----------------------------------------------------------------------------
2461@anchor{cot}
2462@deffn {Function} cot (@var{x})
2463
2464-- Cotangent.
2465
2466@opencatbox
2467@category{Trigonometric functions}
2468@closecatbox
2469@end deffn
2470
2471@c -----------------------------------------------------------------------------
2472@anchor{coth}
2473@deffn {Function} coth (@var{x})
2474
2475-- Hyperbolic Cotangent.
2476
2477@opencatbox
2478@category{Hyperbolic functions}
2479@closecatbox
2480@end deffn
2481
2482@c -----------------------------------------------------------------------------
2483@anchor{csc}
2484@deffn {Function} csc (@var{x})
2485
2486-- Cosecant.
2487
2488@opencatbox
2489@category{Trigonometric functions}
2490@closecatbox
2491@end deffn
2492
2493@c -----------------------------------------------------------------------------
2494@anchor{csch}
2495@deffn {Function} csch (@var{x})
2496
2497-- Hyperbolic Cosecant.
2498
2499@opencatbox
2500@category{Hyperbolic functions}
2501@closecatbox
2502@end deffn
2503
2504@c -----------------------------------------------------------------------------
2505@anchor{halfangles}
2506@defvr {Option variable} halfangles
2507Default value: @code{false}
2508
2509When @code{halfangles} is @code{true}, trigonometric functions of arguments
2510@code{@var{expr}/2} are simplified to functions of @var{expr}.
2511
2512For a real argument @var{x} in the interval @code{0 < x < 2*%pi} the sine of
2513the half-angle simplifies to a simple formula:
2514
2515@example
2516                         sqrt(1 - cos(x))
2517                         ----------------
2518                             sqrt(2)
2519@end example
2520
2521A complicated factor is needed to make this formula correct for all complex
2522arguments @var{z}:
2523
2524@verbatim
2525           realpart(z)
2526     floor(-----------)
2527              2 %pi
2528(- 1)                   (1 - unit_step(- imagpart(z))
2529
2530                            realpart(z)            realpart(z)
2531                      floor(-----------) - ceiling(-----------)
2532                               2 %pi                  2 %pi
2533                ((- 1)                                          + 1))
2534@end verbatim
2535
2536Maxima knows this factor and similar factors for the functions @code{sin},
2537@code{cos}, @code{sinh}, and @code{cosh}.  For special values of the argument
2538@math{z} these factors simplify accordingly.
2539
2540Examples:
2541
2542@c ===beg===
2543@c halfangles : false$
2544@c sin (x / 2);
2545@c halfangles : true$
2546@c sin (x / 2);
2547@c assume(x>0, x<2*%pi)$
2548@c sin(x / 2);
2549@c ===end===
2550@example
2551(%i1) halfangles : false$
2552@group
2553(%i2) sin (x / 2);
2554                                 x
2555(%o2)                        sin(-)
2556                                 2
2557@end group
2558(%i3) halfangles : true$
2559@group
2560(%i4) sin (x / 2);
2561                            x
2562                    floor(-----)
2563                          2 %pi
2564               (- 1)             sqrt(1 - cos(x))
2565(%o4)          ----------------------------------
2566                            sqrt(2)
2567@end group
2568(%i5) assume(x>0, x<2*%pi)$
2569@group
2570(%i6) sin(x / 2);
2571                        sqrt(1 - cos(x))
2572(%o6)                   ----------------
2573                            sqrt(2)
2574@end group
2575@end example
2576
2577@opencatbox
2578@category{Trigonometric functions}
2579@category{Simplification flags and variables}
2580@closecatbox
2581@end defvr
2582
2583@c IS THIS DESCRIPTION ACCURATE ??
2584@c LET'S BE EXPLICIT ABOUT EXACTLY WHAT ARE THE RULES IMPLEMENTED BY THIS PACKAGE
2585
2586@c -----------------------------------------------------------------------------
2587@defvr {Package} ntrig
2588
2589The @code{ntrig} package contains a set of simplification rules that are
2590used to simplify trigonometric function whose arguments are of the form
2591@code{@var{f}(@var{n} %pi/10)} where @var{f} is any of the functions
2592@code{sin}, @code{cos}, @code{tan}, @code{csc}, @code{sec} and @code{cot}.
2593@c NEED TO LOAD THIS PACKAGE ??
2594
2595@opencatbox
2596@category{Trigonometric functions}
2597@category{Package ntrig}
2598@closecatbox
2599@end defvr
2600
2601@c -----------------------------------------------------------------------------
2602@anchor{sec}
2603@deffn {Function} sec (@var{x})
2604
2605-- Secant.
2606
2607@opencatbox
2608@category{Trigonometric functions}
2609@closecatbox
2610@end deffn
2611
2612@c -----------------------------------------------------------------------------
2613@anchor{sech}
2614@deffn {Function} sech (@var{x})
2615
2616-- Hyperbolic Secant.
2617
2618@opencatbox
2619@category{Hyperbolic functions}
2620@closecatbox
2621@end deffn
2622
2623@c -----------------------------------------------------------------------------
2624@anchor{sin}
2625@deffn {Function} sin (@var{x})
2626
2627-- Sine.
2628
2629@opencatbox
2630@category{Trigonometric functions}
2631@closecatbox
2632@end deffn
2633
2634@c -----------------------------------------------------------------------------
2635@anchor{sinh}
2636@deffn {Function} sinh (@var{x})
2637
2638-- Hyperbolic Sine.
2639
2640@opencatbox
2641@category{Hyperbolic functions}
2642@closecatbox
2643@end deffn
2644
2645@c -----------------------------------------------------------------------------
2646@anchor{tan}
2647@deffn {Function} tan (@var{x})
2648
2649-- Tangent.
2650
2651@opencatbox
2652@category{Trigonometric functions}
2653@closecatbox
2654@end deffn
2655
2656@c -----------------------------------------------------------------------------
2657@anchor{tanh}
2658@deffn {Function} tanh (@var{x})
2659
2660-- Hyperbolic Tangent.
2661
2662@opencatbox
2663@category{Hyperbolic functions}
2664@closecatbox
2665@end deffn
2666
2667@c NEEDS CLARIFICATION AND EXAMPLES
2668
2669@c -----------------------------------------------------------------------------
2670@anchor{trigexpand}
2671@deffn {Function} trigexpand (@var{expr})
2672
2673Expands trigonometric and hyperbolic functions of
2674sums of angles and of multiple angles occurring in @var{expr}.  For best
2675results, @var{expr} should be expanded.  To enhance user control of
2676simplification, this function expands only one level at a time,
2677expanding sums of angles or multiple angles.  To obtain full expansion
2678into sines and cosines immediately, set the switch @code{trigexpand: true}.
2679
2680@code{trigexpand} is governed by the following global flags:
2681
2682@table @code
2683@item trigexpand
2684If @code{true} causes expansion of all
2685expressions containing sin's and cos's occurring subsequently.
2686@item halfangles
2687If @code{true} causes half-angles to be simplified
2688away.
2689@item trigexpandplus
2690Controls the "sum" rule for @code{trigexpand},
2691expansion of sums (e.g. @code{sin(x + y)}) will take place only if
2692@code{trigexpandplus} is @code{true}.
2693@item trigexpandtimes
2694Controls the "product" rule for @code{trigexpand},
2695expansion of products (e.g. @code{sin(2 x)}) will take place only if
2696@code{trigexpandtimes} is @code{true}.
2697@end table
2698
2699Examples:
2700
2701@c ===beg===
2702@c x+sin(3*x)/sin(x),trigexpand=true,expand;
2703@c trigexpand(sin(10*x+y));
2704@c ===end===
2705@example
2706@group
2707(%i1) x+sin(3*x)/sin(x),trigexpand=true,expand;
2708                         2            2
2709(%o1)              (- sin (x)) + 3 cos (x) + x
2710@end group
2711@group
2712(%i2) trigexpand(sin(10*x+y));
2713(%o2)          cos(10 x) sin(y) + sin(10 x) cos(y)
2714@end group
2715@end example
2716
2717@opencatbox
2718@category{Trigonometric functions}
2719@category{Simplification functions}
2720@closecatbox
2721@end deffn
2722
2723@c -----------------------------------------------------------------------------
2724@anchor{trigexpandplus}
2725@defvr {Option variable} trigexpandplus
2726Default value: @code{true}
2727
2728@code{trigexpandplus} controls the "sum" rule for
2729@code{trigexpand}.  Thus, when the @code{trigexpand} command is used or the
2730@code{trigexpand} switch set to @code{true}, expansion of sums
2731(e.g. @code{sin(x+y))} will take place only if @code{trigexpandplus} is
2732@code{true}.
2733
2734@opencatbox
2735@category{Trigonometric functions}
2736@category{Simplification flags and variables}
2737@closecatbox
2738@end defvr
2739
2740@c -----------------------------------------------------------------------------
2741@anchor{trigexpandtimes}
2742@defvr {Option variable} trigexpandtimes
2743Default value: @code{true}
2744
2745@code{trigexpandtimes} controls the "product" rule for @code{trigexpand}.
2746Thus, when the @code{trigexpand} command is used or the @code{trigexpand}
2747switch set to @code{true}, expansion of products (e.g. @code{sin(2*x)})
2748will take place only if @code{trigexpandtimes} is @code{true}.
2749
2750@opencatbox
2751@category{Trigonometric functions}
2752@category{Simplification flags and variables}
2753@closecatbox
2754@end defvr
2755
2756@c -----------------------------------------------------------------------------
2757@anchor{triginverses}
2758@defvr {Option variable} triginverses
2759Default value: @code{true}
2760
2761@code{triginverses} controls the simplification of the
2762composition of trigonometric and hyperbolic functions with their inverse
2763functions.
2764
2765If @code{all}, both e.g. @code{atan(tan(@var{x}))}
2766and @code{tan(atan(@var{x}))} simplify to @var{x}.
2767
2768If @code{true}, the @code{@var{arcfun}(@var{fun}(@var{x}))}
2769simplification is turned off.
2770
2771If @code{false}, both the
2772@code{@var{arcfun}(@var{fun}(@var{x}))} and
2773@code{@var{fun}(@var{arcfun}(@var{x}))}
2774simplifications are turned off.
2775
2776@opencatbox
2777@category{Trigonometric functions}
2778@category{Simplification flags and variables}
2779@closecatbox
2780@end defvr
2781
2782@c -----------------------------------------------------------------------------
2783@anchor{trigreduce}
2784@deffn  {Function} trigreduce @
2785@fname{trigreduce} (@var{expr}, @var{x}) @
2786@fname{trigreduce} (@var{expr})
2787
2788Combines products and powers of trigonometric
2789and hyperbolic sin's and cos's of @var{x} into those of multiples of @var{x}.
2790It also tries to eliminate these functions when they occur in
2791denominators.  If @var{x} is omitted then all variables in @var{expr} are used.
2792
2793See also @mref{poissimp}.
2794
2795@c ===beg===
2796@c trigreduce(-sin(x)^2+3*cos(x)^2+x);
2797@c ===end===
2798@example
2799@group
2800(%i1) trigreduce(-sin(x)^2+3*cos(x)^2+x);
2801               cos(2 x)      cos(2 x)   1        1
2802(%o1)          -------- + 3 (-------- + -) + x - -
2803                  2             2       2        2
2804@end group
2805@end example
2806
2807@c
2808@c     OBSOLETE
2809@c     The behavior was changed in order to avoid calling expand in the core
2810@c     simplifier (trigi.lisp rev 1.31)
2811@c     See http://www.math.utexas.edu/pipermail/maxima/2008/010919.html.
2812@c
2813@c The trigonometric simplification routines will use declared
2814@c information in some simple cases.  Declarations about variables are
2815@c used as follows, e.g.
2816@c
2817@c ---beg---
2818@c declare(j, integer, e, even, o, odd)$
2819@c sin(x + (e + 1/2)*%pi);
2820@c sin(x + (o + 1/2)*%pi);
2821@c ---end---
2822@c @example
2823@c (%i1) declare(j, integer, e, even, o, odd)$
2824@c (%i2) sin(x + (e + 1/2)*%pi);
2825@c (%o2)                        cos(x)
2826@c (%i3) sin(x + (o + 1/2)*%pi);
2827@c (%o3)                       - cos(x)
2828@c @end example
2829
2830@opencatbox
2831@category{Trigonometric functions}
2832@category{Simplification functions}
2833@closecatbox
2834@end deffn
2835
2836@c -----------------------------------------------------------------------------
2837@anchor{trigsign}
2838@defvr {Option variable} trigsign
2839Default value: @code{true}
2840
2841When @code{trigsign} is @code{true}, it permits simplification of negative
2842arguments to trigonometric functions.  E.g., @code{sin(-x)} will become
2843@code{-sin(x)} only if @code{trigsign} is @code{true}.
2844
2845@opencatbox
2846@category{Trigonometric functions}
2847@category{Simplification flags and variables}
2848@closecatbox
2849@end defvr
2850
2851@c -----------------------------------------------------------------------------
2852@anchor{trigsimp}
2853@deffn {Function} trigsimp (@var{expr})
2854
2855@iftex
2856Employs the identities
2857@tex
2858$\sin\left(x\right)^2 + \cos\left(x\right)^2 = 1$
2859@end tex
2860and
2861@tex
2862$\cosh\left(x\right)^2 - \sinh\left(x\right)^2 = 1$
2863@end tex
2864to simplify expressions containing @code{tan}, @code{sec},
2865etc., to @code{sin}, @code{cos}, @code{sinh}, @code{cosh}.
2866@end iftex
2867@ifnottex
2868Employs the identities @math{sin(x)^2 + cos(x)^2 = 1} and
2869@math{cosh(x)^2 - sinh(x)^2 = 1} to simplify expressions containing @code{tan},
2870@code{sec}, etc., to @code{sin}, @code{cos}, @code{sinh}, @code{cosh}.
2871@end ifnottex
2872
2873@code{trigreduce}, @code{ratsimp}, and @code{radcan} may be
2874able to further simplify the result.
2875
2876@code{demo ("trgsmp.dem")} displays some examples of @code{trigsimp}.
2877@c MERGE EXAMPLES INTO THIS ITEM
2878
2879@opencatbox
2880@category{Trigonometric functions}
2881@category{Simplification functions}
2882@closecatbox
2883@end deffn
2884
2885@c NEEDS CLARIFICATION
2886
2887@c -----------------------------------------------------------------------------
2888@anchor{trigrat}
2889@deffn {Function} trigrat (@var{expr})
2890
2891Gives a canonical simplified quasilinear form of a trigonometrical expression;
2892@var{expr} is a rational fraction of several @code{sin}, @code{cos} or
2893@code{tan}, the arguments of them are linear forms in some variables (or
2894kernels) and @code{%pi/@var{n}} (@var{n} integer) with integer coefficients.
2895The result is a simplified fraction with numerator and denominator linear in
2896@code{sin} and @code{cos}.  Thus @code{trigrat} linearize always when it is
2897possible.
2898
2899@c ===beg===
2900@c trigrat(sin(3*a)/sin(a+%pi/3));
2901@c ===end===
2902@example
2903@group
2904(%i1) trigrat(sin(3*a)/sin(a+%pi/3));
2905(%o1)            sqrt(3) sin(2 a) + cos(2 a) - 1
2906@end group
2907@end example
2908
2909The following example is taken from
2910Davenport, Siret, and Tournier, @i{Calcul Formel}, Masson (or in English,
2911Addison-Wesley), section 1.5.5, Morley theorem.
2912
2913@c ===beg===
2914@c c : %pi/3 - a - b$
2915@c bc : sin(a)*sin(3*c)/sin(a+b);
2916@c ba : bc, c=a, a=c;
2917@c ac2 : ba^2 + bc^2 - 2*bc*ba*cos(b);
2918@c trigrat (ac2);
2919@c ===end===
2920@example
2921(%i1) c : %pi/3 - a - b$
2922@group
2923(%i2) bc : sin(a)*sin(3*c)/sin(a+b);
2924                                           %pi
2925                 sin(a) sin(3 ((- b) - a + ---))
2926                                            3
2927(%o2)            -------------------------------
2928                           sin(b + a)
2929@end group
2930@group
2931(%i3) ba : bc, c=a, a=c;
2932                                         %pi
2933                    sin(3 a) sin(b + a - ---)
2934                                          3
2935(%o3)               -------------------------
2936                                  %pi
2937                          sin(a - ---)
2938                                   3
2939@end group
2940@group
2941(%i4) ac2 : ba^2 + bc^2 - 2*bc*ba*cos(b);
2942         2         2         %pi
2943      sin (3 a) sin (b + a - ---)
2944                              3
2945(%o4) ---------------------------
2946                2     %pi
2947             sin (a - ---)
2948                       3
2949                                         %pi
2950 - (2 sin(a) sin(3 a) sin(3 ((- b) - a + ---)) cos(b)
2951                                          3
2952             %pi            %pi
2953 sin(b + a - ---))/(sin(a - ---) sin(b + a))
2954              3              3
2955      2       2                %pi
2956   sin (a) sin (3 ((- b) - a + ---))
2957                                3
2958 + ---------------------------------
2959                 2
2960              sin (b + a)
2961@end group
2962@group
2963(%i5) trigrat (ac2);
2964(%o5) - (sqrt(3) sin(4 b + 4 a) - cos(4 b + 4 a)
2965 - 2 sqrt(3) sin(4 b + 2 a) + 2 cos(4 b + 2 a)
2966 - 2 sqrt(3) sin(2 b + 4 a) + 2 cos(2 b + 4 a)
2967 + 4 sqrt(3) sin(2 b + 2 a) - 8 cos(2 b + 2 a) - 4 cos(2 b - 2 a)
2968 + sqrt(3) sin(4 b) - cos(4 b) - 2 sqrt(3) sin(2 b) + 10 cos(2 b)
2969 + sqrt(3) sin(4 a) - cos(4 a) - 2 sqrt(3) sin(2 a) + 10 cos(2 a)
2970 - 9)/4
2971@end group
2972@end example
2973
2974@opencatbox
2975@category{Trigonometric functions}
2976@category{Simplification functions}
2977@closecatbox
2978@end deffn
2979
2980@c -----------------------------------------------------------------------------
2981@page
2982@node Random Numbers, , Trigonometric Functions, Mathematical Functions
2983@section Random Numbers
2984@c -----------------------------------------------------------------------------
2985
2986@c -----------------------------------------------------------------------------
2987@anchor{make_random_state}
2988@deffn  {Function} make_random_state @
2989@fname{make_random_state} (@var{n}) @
2990@fname{make_random_state} (@var{s}) @
2991@fname{make_random_state} (true) @
2992@fname{make_random_state} (false)
2993
2994@c OMIT THIS FOR NOW. SEE COMMENT BELOW.
2995@c @defunx make_random_state (@var{a})
2996
2997A random state object represents the state of the random number generator.
2998The state comprises 627 32-bit words.
2999
3000@code{make_random_state (@var{n})} returns a new random state object
3001created from an integer seed value equal to @var{n} modulo 2^32.
3002@var{n} may be negative.
3003
3004@c OMIT THIS FOR NOW. NOT SURE HOW THIS IS SUPPOSED TO WORK.
3005@c @code{make_random_state (@var{a})} returns a new random state object
3006@c created from an array @var{a}, which must be a Lisp array of 32 unsigned bytes.
3007
3008@code{make_random_state (@var{s})} returns a copy of the random state @var{s}.
3009
3010@code{make_random_state (true)} returns a new random state object,
3011using the current computer clock time as the seed.
3012
3013@code{make_random_state (false)} returns a copy of the current state
3014of the random number generator.
3015
3016@opencatbox
3017@category{Random numbers}
3018@closecatbox
3019@end deffn
3020
3021@c -----------------------------------------------------------------------------
3022@anchor{set_random_state}
3023@deffn {Function} set_random_state (@var{s})
3024
3025Copies @var{s} to the random number generator state.
3026
3027@code{set_random_state} always returns @code{done}.
3028
3029@opencatbox
3030@category{Random numbers}
3031@closecatbox
3032@end deffn
3033
3034@c -----------------------------------------------------------------------------
3035@anchor{random}
3036@deffn {Function} random (@var{x})
3037
3038Returns a pseudorandom number.  If @var{x} is an integer,
3039@code{random (@var{x})} returns an integer from 0 through @code{@var{x} - 1}
3040inclusive.  If @var{x} is a floating point number, @code{random (@var{x})}
3041returns a nonnegative floating point number less than @var{x}.  @code{random}
3042complains with an error if @var{x} is neither an integer nor a float, or if
3043@var{x} is not positive.
3044
3045The functions @code{make_random_state} and @code{set_random_state}
3046maintain the state of the random number generator.
3047
3048The Maxima random number generator is an implementation of the Mersenne twister
3049MT 19937.
3050
3051Examples:
3052
3053@c ===beg===
3054@c s1: make_random_state (654321)$
3055@c set_random_state (s1);
3056@c random (1000);
3057@c random (9573684);
3058@c random (2^75);
3059@c s2: make_random_state (false)$
3060@c random (1.0);
3061@c random (10.0);
3062@c random (100.0);
3063@c set_random_state (s2);
3064@c random (1.0);
3065@c random (10.0);
3066@c random (100.0);
3067@c ===end===
3068@example
3069(%i1) s1: make_random_state (654321)$
3070@group
3071(%i2) set_random_state (s1);
3072(%o2)                         done
3073@end group
3074@group
3075(%i3) random (1000);
3076(%o3)                          768
3077@end group
3078@group
3079(%i4) random (9573684);
3080(%o4)                        7657880
3081@end group
3082@group
3083(%i5) random (2^75);
3084(%o5)                11804491615036831636390
3085@end group
3086(%i6) s2: make_random_state (false)$
3087@group
3088(%i7) random (1.0);
3089(%o7)                  0.2310127244107132
3090@end group
3091@group
3092(%i8) random (10.0);
3093(%o8)                   4.394553645870825
3094@end group
3095@group
3096(%i9) random (100.0);
3097(%o9)                   32.28666704056853
3098@end group
3099@group
3100(%i10) set_random_state (s2);
3101(%o10)                        done
3102@end group
3103@group
3104(%i11) random (1.0);
3105(%o11)                 0.2310127244107132
3106@end group
3107@group
3108(%i12) random (10.0);
3109(%o12)                  4.394553645870825
3110@end group
3111@group
3112(%i13) random (100.0);
3113(%o13)                  32.28666704056853
3114@end group
3115@end example
3116
3117@opencatbox
3118@category{Random numbers}
3119@category{Numerical methods}
3120@closecatbox
3121@end deffn
3122
3123