1This is maxima.info, produced by makeinfo version 6.6 from maxima.texi.
2
3This is a Texinfo Maxima Manual
4
5   Copyright 1994,2001 William F. Schelter
6
7INFO-DIR-SECTION Math
8START-INFO-DIR-ENTRY
9* Maxima: (maxima).     A computer algebra system.
10END-INFO-DIR-ENTRY
11
12
13File: maxima.info,  Node: ctensor,  Next: atensor,  Prev: itensor,  Up: Top
14
1526 ctensor
16**********
17
18* Menu:
19
20* Introduction to ctensor::
21* Functions and Variables for ctensor::
22
23
24File: maxima.info,  Node: Introduction to ctensor,  Next: Functions and Variables for ctensor,  Prev: ctensor,  Up: ctensor
25
2626.1 Introduction to ctensor
27============================
28
29'ctensor' is a component tensor manipulation package.  To use the
30'ctensor' package, type 'load("ctensor")'.  To begin an interactive
31session with 'ctensor', type 'csetup()'.  You are first asked to specify
32the dimension of the manifold.  If the dimension is 2, 3 or 4 then the
33list of coordinates defaults to '[x,y]', '[x,y,z]' or '[x,y,z,t]'
34respectively.  These names may be changed by assigning a new list of
35coordinates to the variable 'ct_coords' (described below) and the user
36is queried about this.  Care must be taken to avoid the coordinate names
37conflicting with other object definitions.
38
39   Next, the user enters the metric either directly or from a file by
40specifying its ordinal position.  The metric is stored in the matrix
41'lg'.  Finally, the metric inverse is computed and stored in the matrix
42'ug'.  One has the option of carrying out all calculations in a power
43series.
44
45   A sample protocol is begun below for the static, spherically
46symmetric metric (standard coordinates) which will be applied to the
47problem of deriving Einstein's vacuum equations (which lead to the
48Schwarzschild solution) as an example.  Many of the functions in
49'ctensor' will be displayed for the standard metric as examples.
50
51     (%i1) load("ctensor");
52     (%o1)      /share/tensor/ctensor.mac
53     (%i2) csetup();
54     Enter the dimension of the coordinate system:
55     4;
56     Do you wish to change the coordinate names?
57     n;
58     Do you want to
59     1. Enter a new metric?
60
61     2. Enter a metric from a file?
62
63     3. Approximate a metric with a Taylor series?
64     1;
65
66     Is the matrix  1. Diagonal  2. Symmetric  3. Antisymmetric  4. General
67     Answer 1, 2, 3 or 4
68     1;
69     Row 1 Column 1:
70     a;
71     Row 2 Column 2:
72     x^2;
73     Row 3 Column 3:
74     x^2*sin(y)^2;
75     Row 4 Column 4:
76     -d;
77
78     Matrix entered.
79     Enter functional dependencies with the DEPENDS function or 'N' if none
80     depends([a,d],x);
81     Do you wish to see the metric?
82     y;
83                               [ a  0       0        0  ]
84                               [                        ]
85                               [     2                  ]
86                               [ 0  x       0        0  ]
87                               [                        ]
88                               [         2    2         ]
89                               [ 0  0   x  sin (y)   0  ]
90                               [                        ]
91                               [ 0  0       0       - d ]
92     (%o2)                                done
93     (%i3) christof(mcs);
94                                                 a
95                                                  x
96     (%t3)                          mcs        = ---
97                                       1, 1, 1   2 a
98
99                                                  1
100     (%t4)                           mcs        = -
101                                        1, 2, 2   x
102
103                                                  1
104     (%t5)                           mcs        = -
105                                        1, 3, 3   x
106
107                                                 d
108                                                  x
109     (%t6)                          mcs        = ---
110                                       1, 4, 4   2 d
111
112                                                   x
113     (%t7)                          mcs        = - -
114                                       2, 2, 1     a
115
116                                                cos(y)
117     (%t8)                         mcs        = ------
118                                      2, 3, 3   sin(y)
119
120                                                    2
121                                               x sin (y)
122     (%t9)                      mcs        = - ---------
123                                   3, 3, 1         a
124
125     (%t10)                   mcs        = - cos(y) sin(y)
126                                 3, 3, 2
127
128                                                 d
129                                                  x
130     (%t11)                         mcs        = ---
131                                       4, 4, 1   2 a
132     (%o11)                               done
133
134
135
136File: maxima.info,  Node: Functions and Variables for ctensor,  Prev: Introduction to ctensor,  Up: ctensor
137
13826.2 Functions and Variables for ctensor
139========================================
140
14126.2.1 Initialization and setup
142-------------------------------
143
144 -- Function: csetup ()
145     A function in the 'ctensor' (component tensor) package which
146     initializes the package and allows the user to enter a metric
147     interactively.  See 'ctensor' for more details.
148
149 -- Function: cmetric
150          cmetric (<dis>)
151          cmetric ()
152
153     A function in the 'ctensor' (component tensor) package that
154     computes the metric inverse and sets up the package for further
155     calculations.
156
157     If 'cframe_flag' is 'false', the function computes the inverse
158     metric 'ug' from the (user-defined) matrix 'lg'.  The metric
159     determinant is also computed and stored in the variable 'gdet'.
160     Furthermore, the package determines if the metric is diagonal and
161     sets the value of 'diagmetric' accordingly.  If the optional
162     argument <dis> is present and not equal to 'false', the user is
163     prompted to see the metric inverse.
164
165     If 'cframe_flag' is 'true', the function expects that the values of
166     'fri' (the inverse frame matrix) and 'lfg' (the frame metric) are
167     defined.  From these, the frame matrix 'fr' and the inverse frame
168     metric 'ufg' are computed.
169
170 -- Function: ct_coordsys
171          ct_coordsys (<coordinate_system>, <extra_arg>)
172          ct_coordsys (<coordinate_system>)
173
174     Sets up a predefined coordinate system and metric.  The argument
175     <coordinate_system> can be one of the following symbols:
176
177
178           SYMBOL             Dim Coordinates     Description/comments
179           ------------------------------------------------------------------
180           cartesian2d           2  [x,y]             Cartesian 2D coordinate
181                                                      system
182           polar                 2  [r,phi]           Polar coordinate system
183           elliptic              2  [u,v]             Elliptic coord. system
184           confocalelliptic      2  [u,v]             Confocal elliptic
185                                                      coordinates
186           bipolar               2  [u,v]             Bipolar coord. system
187           parabolic             2  [u,v]             Parabolic coord. system
188           cartesian3d           3  [x,y,z]           Cartesian 3D coordinate
189                                                      system
190           polarcylindrical      3  [r,theta,z]       Polar 2D with
191                                                      cylindrical z
192           ellipticcylindrical   3  [u,v,z]           Elliptic 2D with
193                                                      cylindrical z
194           confocalellipsoidal   3  [u,v,w]           Confocal ellipsoidal
195           bipolarcylindrical    3  [u,v,z]           Bipolar 2D with
196                                                      cylindrical z
197           paraboliccylindrical  3  [u,v,z]           Parabolic 2D with
198                                                      cylindrical z
199           paraboloidal          3  [u,v,phi]         Paraboloidal coords.
200           conical               3  [u,v,w]           Conical coordinates
201           toroidal              3  [phi,u,v]         Toroidal coordinates
202           spherical             3  [r,theta,phi]     Spherical coord. system
203           oblatespheroidal      3  [u,v,phi]         Oblate spheroidal
204                                                      coordinates
205           oblatespheroidalsqrt  3  [u,v,phi]
206           prolatespheroidal     3  [u,v,phi]         Prolate spheroidal
207                                                      coordinates
208           prolatespheroidalsqrt 3  [u,v,phi]
209           ellipsoidal           3  [r,theta,phi]     Ellipsoidal coordinates
210           cartesian4d           4  [x,y,z,t]         Cartesian 4D coordinate
211                                                      system
212           spherical4d           4  [r,theta,eta,phi] Spherical 4D coordinate
213                                                      system
214           exteriorschwarzschild 4  [t,r,theta,phi]   Schwarzschild metric
215           interiorschwarzschild 4  [t,z,u,v]         Interior Schwarzschild
216                                                      metric
217           kerr_newman           4  [t,r,theta,phi]   Charged axially
218                                                      symmetric metric
219
220     'coordinate_system' can also be a list of transformation functions,
221     followed by a list containing the coordinate variables.  For
222     instance, you can specify a spherical metric as follows:
223
224
225          (%i1) load("ctensor");
226          (%o1)       /share/tensor/ctensor.mac
227          (%i2) ct_coordsys([r*cos(theta)*cos(phi),r*cos(theta)*sin(phi),
228                r*sin(theta),[r,theta,phi]]);
229          (%o2)                                done
230          (%i3) lg:trigsimp(lg);
231                                     [ 1  0         0        ]
232                                     [                       ]
233                                     [     2                 ]
234          (%o3)                      [ 0  r         0        ]
235                                     [                       ]
236                                     [         2    2        ]
237                                     [ 0  0   r  cos (theta) ]
238          (%i4) ct_coords;
239          (%o4)                           [r, theta, phi]
240          (%i5) dim;
241          (%o5)                                  3
242
243
244     Transformation functions can also be used when 'cframe_flag' is
245     'true':
246
247
248          (%i1) load("ctensor");
249          (%o1)       /share/tensor/ctensor.mac
250          (%i2) cframe_flag:true;
251          (%o2)                                true
252          (%i3) ct_coordsys([r*cos(theta)*cos(phi),r*cos(theta)*sin(phi),
253                r*sin(theta),[r,theta,phi]]);
254          (%o3)                                done
255          (%i4) fri;
256          (%o4)
257           [cos(phi)cos(theta) -cos(phi) r sin(theta) -sin(phi) r cos(theta)]
258           [                                                                ]
259           [sin(phi)cos(theta) -sin(phi) r sin(theta)  cos(phi) r cos(theta)]
260           [                                                                ]
261           [    sin(theta)           r cos(theta)                0          ]
262
263          (%i5) cmetric();
264          (%o5)                                false
265          (%i6) lg:trigsimp(lg);
266                                     [ 1  0         0        ]
267                                     [                       ]
268                                     [     2                 ]
269          (%o6)                      [ 0  r         0        ]
270                                     [                       ]
271                                     [         2    2        ]
272                                     [ 0  0   r  cos (theta) ]
273
274
275     The optional argument <extra_arg> can be any one of the following:
276
277     'cylindrical' tells 'ct_coordsys' to attach an additional
278     cylindrical coordinate.
279
280     'minkowski' tells 'ct_coordsys' to attach an additional coordinate
281     with negative metric signature.
282
283     'all' tells 'ct_coordsys' to call 'cmetric' and 'christof(false)'
284     after setting up the metric.
285
286     If the global variable 'verbose' is set to 'true', 'ct_coordsys'
287     displays the values of 'dim', 'ct_coords', and either 'lg' or 'lfg'
288     and 'fri', depending on the value of 'cframe_flag'.
289
290 -- Function: init_ctensor ()
291     Initializes the 'ctensor' package.
292
293     The 'init_ctensor' function reinitializes the 'ctensor' package.
294     It removes all arrays and matrices used by 'ctensor', resets all
295     flags, resets 'dim' to 4, and resets the frame metric to the
296     Lorentz-frame.
297
29826.2.2 The tensors of curved space
299----------------------------------
300
301The main purpose of the 'ctensor' package is to compute the tensors of
302curved space(time), most notably the tensors used in general relativity.
303
304   When a metric base is used, 'ctensor' can compute the following
305tensors:
306
307
308      lg  -- ug
309        \      \
310         lcs -- mcs -- ric -- uric
311                   \      \       \
312                    \      tracer - ein -- lein
313                     \
314                      riem -- lriem -- weyl
315                          \
316                           uriem
317
318
319
320   'ctensor' can also work using moving frames.  When 'cframe_flag' is
321set to 'true', the following tensors can be calculated:
322
323
324      lfg -- ufg
325          \
326      fri -- fr -- lcs -- mcs -- lriem -- ric -- uric
327           \                       |  \      \       \
328            lg -- ug               |   weyl   tracer - ein -- lein
329                                   |\
330                                   | riem
331                                   |
332                                   \uriem
333
334 -- Function: christof (<dis>)
335     A function in the 'ctensor' (component tensor) package.  It
336     computes the Christoffel symbols of both kinds.  The argument <dis>
337     determines which results are to be immediately displayed.  The
338     Christoffel symbols of the first and second kinds are stored in the
339     arrays 'lcs[i,j,k]' and 'mcs[i,j,k]' respectively and defined to be
340     symmetric in the first two indices.  If the argument to 'christof'
341     is 'lcs' or 'mcs' then the unique non-zero values of 'lcs[i,j,k]'
342     or 'mcs[i,j,k]', respectively, will be displayed.  If the argument
343     is 'all' then the unique non-zero values of 'lcs[i,j,k]' and
344     'mcs[i,j,k]' will be displayed.  If the argument is 'false' then
345     the display of the elements will not occur.  The array elements
346     'mcs[i,j,k]' are defined in such a manner that the final index is
347     contravariant.
348
349 -- Function: ricci (<dis>)
350     A function in the 'ctensor' (component tensor) package.  'ricci'
351     computes the covariant (symmetric) components 'ric[i,j]' of the
352     Ricci tensor.  If the argument <dis> is 'true', then the non-zero
353     components are displayed.
354
355 -- Function: uricci (<dis>)
356     This function first computes the covariant components 'ric[i,j]' of
357     the Ricci tensor.  Then the mixed Ricci tensor is computed using
358     the contravariant metric tensor.  If the value of the argument
359     <dis> is 'true', then these mixed components, 'uric[i,j]' (the
360     index 'i' is covariant and the index 'j' is contravariant), will be
361     displayed directly.  Otherwise, 'ricci(false)' will simply compute
362     the entries of the array 'uric[i,j]' without displaying the
363     results.
364
365 -- Function: scurvature ()
366     Returns the scalar curvature (obtained by contracting the Ricci
367     tensor) of the Riemannian manifold with the given metric.
368
369 -- Function: einstein (<dis>)
370     A function in the 'ctensor' (component tensor) package.  'einstein'
371     computes the mixed Einstein tensor after the Christoffel symbols
372     and Ricci tensor have been obtained (with the functions 'christof'
373     and 'ricci').  If the argument <dis> is 'true', then the non-zero
374     values of the mixed Einstein tensor 'ein[i,j]' will be displayed
375     where 'j' is the contravariant index.  The variable 'rateinstein'
376     will cause the rational simplification on these components.  If
377     'ratfac' is 'true' then the components will also be factored.
378
379 -- Function: leinstein (<dis>)
380     Covariant Einstein-tensor.  'leinstein' stores the values of the
381     covariant Einstein tensor in the array 'lein'.  The covariant
382     Einstein-tensor is computed from the mixed Einstein tensor 'ein' by
383     multiplying it with the metric tensor.  If the argument <dis> is
384     'true', then the non-zero values of the covariant Einstein tensor
385     are displayed.
386
387 -- Function: riemann (<dis>)
388     A function in the 'ctensor' (component tensor) package.  'riemann'
389     computes the Riemann curvature tensor from the given metric and the
390     corresponding Christoffel symbols.  The following index conventions
391     are used:
392
393                          l      _l       _l       _l   _m    _l   _m
394           R[i,j,k,l] =  R    = |      - |      + |    |   - |    |
395                          ijk     ij,k     ik,j     mk   ij    mj   ik
396
397     This notation is consistent with the notation used by the 'itensor'
398     package and its 'icurvature' function.  If the optional argument
399     <dis> is 'true', the unique non-zero components 'riem[i,j,k,l]'
400     will be displayed.  As with the Einstein tensor, various switches
401     set by the user control the simplification of the components of the
402     Riemann tensor.  If 'ratriemann' is 'true', then rational
403     simplification will be done.  If 'ratfac' is 'true' then each of
404     the components will also be factored.
405
406     If the variable 'cframe_flag' is 'false', the Riemann tensor is
407     computed directly from the Christoffel-symbols.  If 'cframe_flag'
408     is 'true', the covariant Riemann-tensor is computed first from the
409     frame field coefficients.
410
411 -- Function: lriemann (<dis>)
412     Covariant Riemann-tensor ('lriem[]').
413
414     Computes the covariant Riemann-tensor as the array 'lriem'.  If the
415     argument <dis> is 'true', unique non-zero values are displayed.
416
417     If the variable 'cframe_flag' is 'true', the covariant Riemann
418     tensor is computed directly from the frame field coefficients.
419     Otherwise, the (3,1) Riemann tensor is computed first.
420
421     For information on index ordering, see 'riemann'.
422
423 -- Function: uriemann (<dis>)
424     Computes the contravariant components of the Riemann curvature
425     tensor as array elements 'uriem[i,j,k,l]'.  These are displayed if
426     <dis> is 'true'.
427
428 -- Function: rinvariant ()
429     Forms the Kretchmann-invariant ('kinvariant') obtained by
430     contracting the tensors
431
432          lriem[i,j,k,l]*uriem[i,j,k,l].
433
434     This object is not automatically simplified since it can be very
435     large.
436
437 -- Function: weyl (<dis>)
438     Computes the Weyl conformal tensor.  If the argument <dis> is
439     'true', the non-zero components 'weyl[i,j,k,l]' will be displayed
440     to the user.  Otherwise, these components will simply be computed
441     and stored.  If the switch 'ratweyl' is set to 'true', then the
442     components will be rationally simplified; if 'ratfac' is 'true'
443     then the results will be factored as well.
444
44526.2.3 Taylor series expansion
446------------------------------
447
448The 'ctensor' package has the ability to truncate results by assuming
449that they are Taylor-series approximations.  This behavior is controlled
450by the 'ctayswitch' variable; when set to true, 'ctensor' makes use
451internally of the function 'ctaylor' when simplifying results.
452
453   The 'ctaylor' function is invoked by the following 'ctensor'
454functions:
455
456
457         Function     Comments
458         ---------------------------------
459         christof()   For mcs only
460         ricci()
461         uricci()
462         einstein()
463         riemann()
464         weyl()
465         checkdiv()
466 -- Function: ctaylor ()
467
468     The 'ctaylor' function truncates its argument by converting it to a
469     Taylor-series using 'taylor', and then calling 'ratdisrep'.  This
470     has the combined effect of dropping terms higher order in the
471     expansion variable 'ctayvar'.  The order of terms that should be
472     dropped is defined by 'ctaypov'; the point around which the series
473     expansion is carried out is specified in 'ctaypt'.
474
475     As an example, consider a simple metric that is a perturbation of
476     the Minkowski metric.  Without further restrictions, even a
477     diagonal metric produces expressions for the Einstein tensor that
478     are far too complex:
479
480
481          (%i1) load("ctensor");
482          (%o1)       /share/tensor/ctensor.mac
483          (%i2) ratfac:true;
484          (%o2)                                true
485          (%i3) derivabbrev:true;
486          (%o3)                                true
487          (%i4) ct_coords:[t,r,theta,phi];
488          (%o4)                         [t, r, theta, phi]
489          (%i5) lg:matrix([-1,0,0,0],[0,1,0,0],[0,0,r^2,0],
490                          [0,0,0,r^2*sin(theta)^2]);
491                                  [ - 1  0  0         0        ]
492                                  [                            ]
493                                  [  0   1  0         0        ]
494                                  [                            ]
495          (%o5)                   [          2                 ]
496                                  [  0   0  r         0        ]
497                                  [                            ]
498                                  [              2    2        ]
499                                  [  0   0  0   r  sin (theta) ]
500          (%i6) h:matrix([h11,0,0,0],[0,h22,0,0],[0,0,h33,0],[0,0,0,h44]);
501                                      [ h11   0    0    0  ]
502                                      [                    ]
503                                      [  0   h22   0    0  ]
504          (%o6)                       [                    ]
505                                      [  0    0   h33   0  ]
506                                      [                    ]
507                                      [  0    0    0   h44 ]
508          (%i7) depends(l,r);
509          (%o7)                               [l(r)]
510          (%i8) lg:lg+l*h;
511                [ h11 l - 1      0          0                 0            ]
512                [                                                          ]
513                [     0      h22 l + 1      0                 0            ]
514                [                                                          ]
515          (%o8) [                        2                                 ]
516                [     0          0      r  + h33 l            0            ]
517                [                                                          ]
518                [                                    2    2                ]
519                [     0          0          0       r  sin (theta) + h44 l ]
520          (%i9) cmetric(false);
521          (%o9)                                done
522          (%i10) einstein(false);
523          (%o10)                               done
524          (%i11) ntermst(ein);
525          [[1, 1], 62]
526          [[1, 2], 0]
527          [[1, 3], 0]
528          [[1, 4], 0]
529          [[2, 1], 0]
530          [[2, 2], 24]
531          [[2, 3], 0]
532          [[2, 4], 0]
533          [[3, 1], 0]
534          [[3, 2], 0]
535          [[3, 3], 46]
536          [[3, 4], 0]
537          [[4, 1], 0]
538          [[4, 2], 0]
539          [[4, 3], 0]
540          [[4, 4], 46]
541          (%o12)                               done
542
543
544     However, if we recompute this example as an approximation that is
545     linear in the variable 'l', we get much simpler expressions:
546
547
548          (%i14) ctayswitch:true;
549          (%o14)                               true
550          (%i15) ctayvar:l;
551          (%o15)                                 l
552          (%i16) ctaypov:1;
553          (%o16)                                 1
554          (%i17) ctaypt:0;
555          (%o17)                                 0
556          (%i18) christof(false);
557          (%o18)                               done
558          (%i19) ricci(false);
559          (%o19)                               done
560          (%i20) einstein(false);
561          (%o20)                               done
562          (%i21) ntermst(ein);
563          [[1, 1], 6]
564          [[1, 2], 0]
565          [[1, 3], 0]
566          [[1, 4], 0]
567          [[2, 1], 0]
568          [[2, 2], 13]
569          [[2, 3], 2]
570          [[2, 4], 0]
571          [[3, 1], 0]
572          [[3, 2], 2]
573          [[3, 3], 9]
574          [[3, 4], 0]
575          [[4, 1], 0]
576          [[4, 2], 0]
577          [[4, 3], 0]
578          [[4, 4], 9]
579          (%o21)                               done
580          (%i22) ratsimp(ein[1,1]);
581                                   2      2  4               2     2
582          (%o22) - (((h11 h22 - h11 ) (l )  r  - 2 h33 l    r ) sin (theta)
583                                        r               r r
584
585                                      2               2      4    2
586                        - 2 h44 l    r  - h33 h44 (l ) )/(4 r  sin (theta))
587                                 r r                r
588
589
590
591
592     This capability can be useful, for instance, when working in the
593     weak field limit far from a gravitational source.
594
59526.2.4 Frame fields
596-------------------
597
598When the variable 'cframe_flag' is set to true, the 'ctensor' package
599performs its calculations using a moving frame.
600 -- Function: frame_bracket (<fr>, <fri>, <diagframe>)
601     The frame bracket ('fb[]').
602
603     Computes the frame bracket according to the following definition:
604
605             c          c         c        d     e
606          ifb   = ( ifri    - ifri    ) ifr   ifr
607             ab         d,e       e,d      a     b
608
60926.2.5 Algebraic classification
610-------------------------------
611
612A new feature (as of November, 2004) of 'ctensor' is its ability to
613compute the Petrov classification of a 4-dimensional spacetime metric.
614For a demonstration of this capability, see the file
615'share/tensor/petrov.dem'.
616 -- Function: nptetrad ()
617     Computes a Newman-Penrose null tetrad ('np') and its raised-index
618     counterpart ('npi').  See 'petrov' for an example.
619
620     The null tetrad is constructed on the assumption that a
621     four-dimensional orthonormal frame metric with metric signature
622     (-,+,+,+) is being used.  The components of the null tetrad are
623     related to the inverse frame matrix as follows:
624
625
626          np  = (fri  + fri ) / sqrt(2)
627            1       1      2
628
629          np  = (fri  - fri ) / sqrt(2)
630            2       1      2
631
632          np  = (fri  + %i fri ) / sqrt(2)
633            3       3         4
634
635          np  = (fri  - %i fri ) / sqrt(2)
636            4       3         4
637
638
639 -- Function: psi (<dis>)
640     Computes the five Newman-Penrose coefficients 'psi[0]'...'psi[4]'.
641     If 'dis' is set to 'true', the coefficients are displayed.  See
642     'petrov' for an example.
643
644     These coefficients are computed from the Weyl-tensor in a
645     coordinate base.  If a frame base is used, the Weyl-tensor is first
646     converted to a coordinate base, which can be a computationally
647     expensive procedure.  For this reason, in some cases it may be more
648     advantageous to use a coordinate base in the first place before the
649     Weyl tensor is computed.  Note however, that constructing a
650     Newman-Penrose null tetrad requires a frame base.  Therefore, a
651     meaningful computation sequence may begin with a frame base, which
652     is then used to compute 'lg' (computed automatically by 'cmetric')
653     and then 'ug'.  See 'petrov' for an example.  At this point, you
654     can switch back to a coordinate base by setting 'cframe_flag' to
655     false before beginning to compute the Christoffel symbols.
656     Changing to a frame base at a later stage could yield inconsistent
657     results, as you may end up with a mixed bag of tensors, some
658     computed in a frame base, some in a coordinate base, with no means
659     to distinguish between the two.
660
661 -- Function: petrov ()
662     Computes the Petrov classification of the metric characterized by
663     'psi[0]'...'psi[4]'.
664
665     For example, the following demonstrates how to obtain the
666     Petrov-classification of the Kerr metric:
667
668          (%i1) load("ctensor");
669          (%o1)       /share/tensor/ctensor.mac
670          (%i2) (cframe_flag:true,gcd:spmod,ctrgsimp:true,ratfac:true);
671          (%o2)                                true
672          (%i3) ct_coordsys(exteriorschwarzschild,all);
673          (%o3)                                done
674          (%i4) ug:invert(lg)$
675          (%i5) weyl(false);
676          (%o5)                                done
677          (%i6) nptetrad(true);
678          (%t6) np =
679
680          [ sqrt(r - 2 m)           sqrt(r)                                 ]
681          [---------------   ---------------------    0            0        ]
682          [sqrt(2) sqrt(r)   sqrt(2) sqrt(r - 2 m)                          ]
683          [                                                                 ]
684          [ sqrt(r - 2 m)            sqrt(r)                                ]
685          [---------------  - ---------------------   0            0        ]
686          [sqrt(2) sqrt(r)    sqrt(2) sqrt(r - 2 m)                         ]
687          [                                                                 ]
688          [                                          r      %i r sin(theta) ]
689          [       0                    0          -------   --------------- ]
690          [                                       sqrt(2)       sqrt(2)     ]
691          [                                                                 ]
692          [                                          r       %i r sin(theta)]
693          [       0                    0          -------  - ---------------]
694          [                                       sqrt(2)        sqrt(2)    ]
695
696                                       sqrt(r)         sqrt(r - 2 m)
697          (%t7) npi = matrix([- ---------------------,---------------, 0, 0],
698                                sqrt(2) sqrt(r - 2 m) sqrt(2) sqrt(r)
699
700                    sqrt(r)            sqrt(r - 2 m)
701          [- ---------------------, - ---------------, 0, 0],
702             sqrt(2) sqrt(r - 2 m)    sqrt(2) sqrt(r)
703
704                     1               %i
705          [0, 0, ---------, --------------------],
706                 sqrt(2) r  sqrt(2) r sin(theta)
707
708                     1                 %i
709          [0, 0, ---------, - --------------------])
710                 sqrt(2) r    sqrt(2) r sin(theta)
711
712          (%o7)                                done
713          (%i7) psi(true);
714          (%t8)                              psi  = 0
715                                                0
716
717          (%t9)                              psi  = 0
718                                                1
719
720                                                    m
721          (%t10)                             psi  = --
722                                                2    3
723                                                    r
724
725          (%t11)                             psi  = 0
726                                                3
727
728          (%t12)                             psi  = 0
729                                                4
730          (%o12)                               done
731          (%i12) petrov();
732          (%o12)                                 D
733
734
735     The Petrov classification function is based on the algorithm
736     published in "Classifying geometries in general relativity: III
737     Classification in practice" by Pollney, Skea, and d'Inverno, Class.
738     Quant.  Grav.  17 2885-2902 (2000).  Except for some simple test
739     cases, the implementation is untested as of December 19, 2004, and
740     is likely to contain errors.
741
74226.2.6 Torsion and nonmetricity
743-------------------------------
744
745'ctensor' has the ability to compute and include torsion and
746nonmetricity coefficients in the connection coefficients.
747
748   The torsion coefficients are calculated from a user-supplied tensor
749'tr', which should be a rank (2,1) tensor.  From this, the torsion
750coefficients 'kt' are computed according to the following formulae:
751
752
753                   m          m      m
754            - g  tr   - g   tr   - tr   g
755               im  kj    jm   ki     ij  km
756     kt   = -------------------------------
757       ijk                 2
758
759
760       k     km
761     kt   = g   kt
762       ij         ijm
763
764
765   Note that only the mixed-index tensor is calculated and stored in the
766array 'kt'.
767
768   The nonmetricity coefficients are calculated from the user-supplied
769nonmetricity vector 'nm'.  From this, the nonmetricity coefficients
770'nmc' are computed as follows:
771
772
773                  k    k        km
774            -nm  D  - D  nm  + g   nm  g
775        k      i  j    i   j         m  ij
776     nmc  = ------------------------------
777        ij                2
778
779
780   where D stands for the Kronecker-delta.
781
782   When 'ctorsion_flag' is set to 'true', the values of 'kt' are
783subtracted from the mixed-indexed connection coefficients computed by
784'christof' and stored in 'mcs'.  Similarly, if 'cnonmet_flag' is set to
785'true', the values of 'nmc' are subtracted from the mixed-indexed
786connection coefficients.
787
788   If necessary, 'christof' calls the functions 'contortion' and
789'nonmetricity' in order to compute 'kt' and 'nm'.
790 -- Function: contortion (<tr>)
791
792     Computes the (2,1) contortion coefficients from the torsion tensor
793     <tr>.
794
795 -- Function: nonmetricity (<nm>)
796
797     Computes the (2,1) nonmetricity coefficients from the nonmetricity
798     vector <nm>.
799
80026.2.7 Miscellaneous features
801-----------------------------
802
803 -- Function: ctransform (<M>)
804     A function in the 'ctensor' (component tensor) package which will
805     perform a coordinate transformation upon an arbitrary square
806     symmetric matrix <M>.  The user must input the functions which
807     define the transformation.  (Formerly called 'transform'.)
808
809 -- Function: findde (<A>, <n>)
810
811     returns a list of the unique differential equations (expressions)
812     corresponding to the elements of the <n> dimensional square array
813     <A>.  Presently, <n> may be 2 or 3.  'deindex' is a global list
814     containing the indices of <A> corresponding to these unique
815     differential equations.  For the Einstein tensor ('ein'), which is
816     a two dimensional array, if computed for the metric in the example
817     below, 'findde' gives the following independent differential
818     equations:
819
820          (%i1) load("ctensor");
821          (%o1)       /share/tensor/ctensor.mac
822          (%i2) derivabbrev:true;
823          (%o2)                                true
824          (%i3) dim:4;
825          (%o3)                                  4
826          (%i4) lg:matrix([a, 0, 0, 0], [ 0, x^2, 0, 0],
827                                        [0, 0, x^2*sin(y)^2, 0], [0,0,0,-d]);
828                                    [ a  0       0        0  ]
829                                    [                        ]
830                                    [     2                  ]
831                                    [ 0  x       0        0  ]
832          (%o4)                     [                        ]
833                                    [         2    2         ]
834                                    [ 0  0   x  sin (y)   0  ]
835                                    [                        ]
836                                    [ 0  0       0       - d ]
837          (%i5) depends([a,d],x);
838          (%o5)                            [a(x), d(x)]
839          (%i6) ct_coords:[x,y,z,t];
840          (%o6)                            [x, y, z, t]
841          (%i7) cmetric();
842          (%o7)                                done
843          (%i8) einstein(false);
844          (%o8)                                done
845          (%i9) findde(ein,2);
846                                                      2
847          (%o9) [d  x - a d + d, 2 a d d    x - a (d )  x - a  d d  x
848                  x                     x x         x        x    x
849
850                                                        2          2
851                                    + 2 a d d   - 2 a  d , a  x + a  - a]
852                                             x       x      x
853          (%i10) deindex;
854          (%o10)                     [[1, 1], [2, 2], [4, 4]]
855
856 -- Function: cograd ()
857     Computes the covariant gradient of a scalar function allowing the
858     user to choose the corresponding vector name as the example under
859     'contragrad' illustrates.
860
861 -- Function: contragrad ()
862
863     Computes the contravariant gradient of a scalar function allowing
864     the user to choose the corresponding vector name as the example
865     below for the Schwarzschild metric illustrates:
866
867          (%i1) load("ctensor");
868          (%o1)       /share/tensor/ctensor.mac
869          (%i2) derivabbrev:true;
870          (%o2)                                true
871          (%i3) ct_coordsys(exteriorschwarzschild,all);
872          (%o3)                                done
873          (%i4) depends(f,r);
874          (%o4)                               [f(r)]
875          (%i5) cograd(f,g1);
876          (%o5)                                done
877          (%i6) listarray(g1);
878          (%o6)                            [0, f , 0, 0]
879                                                r
880          (%i7) contragrad(f,g2);
881          (%o7)                                done
882          (%i8) listarray(g2);
883                                         f  r - 2 f  m
884                                          r        r
885          (%o8)                      [0, -------------, 0, 0]
886                                               r
887
888 -- Function: dscalar ()
889     computes the tensor d'Alembertian of the scalar function once
890     dependencies have been declared upon the function.  For example:
891
892          (%i1) load("ctensor");
893          (%o1)       /share/tensor/ctensor.mac
894          (%i2) derivabbrev:true;
895          (%o2)                                true
896          (%i3) ct_coordsys(exteriorschwarzschild,all);
897          (%o3)                                done
898          (%i4) depends(p,r);
899          (%o4)                               [p(r)]
900          (%i5) factor(dscalar(p));
901                                    2
902                              p    r  - 2 m p    r + 2 p  r - 2 m p
903                               r r           r r        r          r
904          (%o5)               --------------------------------------
905                                                 2
906                                                r
907
908 -- Function: checkdiv ()
909
910     computes the covariant divergence of the mixed second rank tensor
911     (whose first index must be covariant) by printing the corresponding
912     n components of the vector field (the divergence) where n = 'dim'.
913     If the argument to the function is 'g' then the divergence of the
914     Einstein tensor will be formed and must be zero.  In addition, the
915     divergence (vector) is given the array name 'div'.
916
917 -- Function: cgeodesic (<dis>)
918     A function in the 'ctensor' (component tensor) package.
919     'cgeodesic' computes the geodesic equations of motion for a given
920     metric.  They are stored in the array 'geod[i]'.  If the argument
921     <dis> is 'true' then these equations are displayed.
922
923 -- Function: bdvac (<f>)
924
925     generates the covariant components of the vacuum field equations of
926     the Brans- Dicke gravitational theory.  The scalar field is
927     specified by the argument <f>, which should be a (quoted) function
928     name with functional dependencies, e.g., ''p(x)'.
929
930     The components of the second rank covariant field tensor are
931     represented by the array 'bd'.
932
933 -- Function: invariant1 ()
934
935     generates the mixed Euler- Lagrange tensor (field equations) for
936     the invariant density of R^2.  The field equations are the
937     components of an array named 'inv1'.
938
939 -- Function: invariant2 ()
940
941     *** NOT YET IMPLEMENTED ***
942
943     generates the mixed Euler- Lagrange tensor (field equations) for
944     the invariant density of 'ric[i,j]*uriem[i,j]'.  The field
945     equations are the components of an array named 'inv2'.
946
947 -- Function: bimetric ()
948
949     *** NOT YET IMPLEMENTED ***
950
951     generates the field equations of Rosen's bimetric theory.  The
952     field equations are the components of an array named 'rosen'.
953
95426.2.8 Utility functions
955------------------------
956
957 -- Function: diagmatrixp (<M>,<n>)
958
959     Returns 'true' if the first <n> rows and <n> columns of <M> form a
960     diagonal matrix or (2D) array.
961
962 -- Function: symmetricp (<M>, <n>)
963
964     Returns 'true' if <M> is a <n> by <n> symmetric matrix or
965     two-dimensional array, otherwise 'false'.
966
967     If <n> is less than the size of <M>, 'symmetricp' considers only
968     the <n> by <n> submatrix (respectively, subarray) comprising rows 1
969     through <n> and columns 1 through <n>.
970
971 -- Function: ntermst (<f>)
972     gives the user a quick picture of the "size" of the doubly
973     subscripted tensor (array) <f>.  It prints two element lists where
974     the second element corresponds to NTERMS of the components
975     specified by the first elements.  In this way, it is possible to
976     quickly find the non-zero expressions and attempt simplification.
977
978 -- Function: cdisplay (<ten>)
979     displays all the elements of the tensor <ten>, as represented by a
980     multidimensional array.  Tensors of rank 0 and 1, as well as other
981     types of variables, are displayed as with 'ldisplay'.  Tensors of
982     rank 2 are displayed as 2-dimensional matrices, while tensors of
983     higher rank are displayed as a list of 2-dimensional matrices.  For
984     instance, the Riemann-tensor of the Schwarzschild metric can be
985     viewed as:
986
987          (%i1) load("ctensor");
988          (%o1)       /share/tensor/ctensor.mac
989          (%i2) ratfac:true;
990          (%o2)                                true
991          (%i3) ct_coordsys(exteriorschwarzschild,all);
992          (%o3)                                done
993          (%i4) riemann(false);
994          (%o4)                                done
995          (%i5) cdisplay(riem);
996                    [ 0               0                   0           0     ]
997                    [                                                       ]
998                    [                              2                        ]
999                    [      3 m (r - 2 m)   m    2 m                         ]
1000                    [ 0  - ------------- + -- - ----      0           0     ]
1001                    [            4          3     4                         ]
1002                    [           r          r     r                          ]
1003                    [                                                       ]
1004          riem    = [                                m (r - 2 m)            ]
1005              1, 1  [ 0               0              -----------      0     ]
1006                    [                                     4                 ]
1007                    [                                    r                  ]
1008                    [                                                       ]
1009                    [                                           m (r - 2 m) ]
1010                    [ 0               0                   0     ----------- ]
1011                    [                                                4      ]
1012                    [                                               r       ]
1013
1014                                          [    2 m (r - 2 m)       ]
1015                                          [ 0  -------------  0  0 ]
1016                                          [          4             ]
1017                                          [         r              ]
1018                               riem     = [                        ]
1019                                   1, 2   [ 0        0        0  0 ]
1020                                          [                        ]
1021                                          [ 0        0        0  0 ]
1022                                          [                        ]
1023                                          [ 0        0        0  0 ]
1024
1025                                          [         m (r - 2 m)    ]
1026                                          [ 0  0  - -----------  0 ]
1027                                          [              4         ]
1028                                          [             r          ]
1029                               riem     = [                        ]
1030                                   1, 3   [ 0  0        0        0 ]
1031                                          [                        ]
1032                                          [ 0  0        0        0 ]
1033                                          [                        ]
1034                                          [ 0  0        0        0 ]
1035
1036                                          [            m (r - 2 m) ]
1037                                          [ 0  0  0  - ----------- ]
1038                                          [                 4      ]
1039                                          [                r       ]
1040                               riem     = [                        ]
1041                                   1, 4   [ 0  0  0        0       ]
1042                                          [                        ]
1043                                          [ 0  0  0        0       ]
1044                                          [                        ]
1045                                          [ 0  0  0        0       ]
1046
1047                                         [       0         0  0  0 ]
1048                                         [                         ]
1049                                         [       2 m               ]
1050                                         [ - ------------  0  0  0 ]
1051                              riem     = [    2                    ]
1052                                  2, 1   [   r  (r - 2 m)          ]
1053                                         [                         ]
1054                                         [       0         0  0  0 ]
1055                                         [                         ]
1056                                         [       0         0  0  0 ]
1057
1058                       [     2 m                                         ]
1059                       [ ------------  0        0               0        ]
1060                       [  2                                              ]
1061                       [ r  (r - 2 m)                                    ]
1062                       [                                                 ]
1063                       [      0        0        0               0        ]
1064                       [                                                 ]
1065            riem     = [                         m                       ]
1066                2, 2   [      0        0  - ------------        0        ]
1067                       [                     2                           ]
1068                       [                    r  (r - 2 m)                 ]
1069                       [                                                 ]
1070                       [                                         m       ]
1071                       [      0        0        0         - ------------ ]
1072                       [                                     2           ]
1073                       [                                    r  (r - 2 m) ]
1074
1075                                          [ 0  0       0        0 ]
1076                                          [                       ]
1077                                          [            m          ]
1078                                          [ 0  0  ------------  0 ]
1079                               riem     = [        2              ]
1080                                   2, 3   [       r  (r - 2 m)    ]
1081                                          [                       ]
1082                                          [ 0  0       0        0 ]
1083                                          [                       ]
1084                                          [ 0  0       0        0 ]
1085
1086                                          [ 0  0  0       0       ]
1087                                          [                       ]
1088                                          [               m       ]
1089                                          [ 0  0  0  ------------ ]
1090                               riem     = [           2           ]
1091                                   2, 4   [          r  (r - 2 m) ]
1092                                          [                       ]
1093                                          [ 0  0  0       0       ]
1094                                          [                       ]
1095                                          [ 0  0  0       0       ]
1096
1097                                                [ 0  0  0  0 ]
1098                                                [            ]
1099                                                [ 0  0  0  0 ]
1100                                                [            ]
1101                                     riem     = [ m          ]
1102                                         3, 1   [ -  0  0  0 ]
1103                                                [ r          ]
1104                                                [            ]
1105                                                [ 0  0  0  0 ]
1106
1107                                                [ 0  0  0  0 ]
1108                                                [            ]
1109                                                [ 0  0  0  0 ]
1110                                                [            ]
1111                                     riem     = [    m       ]
1112                                         3, 2   [ 0  -  0  0 ]
1113                                                [    r       ]
1114                                                [            ]
1115                                                [ 0  0  0  0 ]
1116
1117                                         [   m                      ]
1118                                         [ - -   0   0       0      ]
1119                                         [   r                      ]
1120                                         [                          ]
1121                                         [        m                 ]
1122                                         [  0   - -  0       0      ]
1123                              riem     = [        r                 ]
1124                                  3, 3   [                          ]
1125                                         [  0    0   0       0      ]
1126                                         [                          ]
1127                                         [              2 m - r     ]
1128                                         [  0    0   0  ------- + 1 ]
1129                                         [                 r        ]
1130
1131                                              [ 0  0  0    0   ]
1132                                              [                ]
1133                                              [ 0  0  0    0   ]
1134                                              [                ]
1135                                   riem     = [            2 m ]
1136                                       3, 4   [ 0  0  0  - --- ]
1137                                              [             r  ]
1138                                              [                ]
1139                                              [ 0  0  0    0   ]
1140
1141                                          [       0        0  0  0 ]
1142                                          [                        ]
1143                                          [       0        0  0  0 ]
1144                                          [                        ]
1145                               riem     = [       0        0  0  0 ]
1146                                   4, 1   [                        ]
1147                                          [      2                 ]
1148                                          [ m sin (theta)          ]
1149                                          [ -------------  0  0  0 ]
1150                                          [       r                ]
1151
1152                                          [ 0        0        0  0 ]
1153                                          [                        ]
1154                                          [ 0        0        0  0 ]
1155                                          [                        ]
1156                               riem     = [ 0        0        0  0 ]
1157                                   4, 2   [                        ]
1158                                          [         2              ]
1159                                          [    m sin (theta)       ]
1160                                          [ 0  -------------  0  0 ]
1161                                          [          r             ]
1162
1163                                        [ 0  0          0          0 ]
1164                                        [                            ]
1165                                        [ 0  0          0          0 ]
1166                                        [                            ]
1167                             riem     = [ 0  0          0          0 ]
1168                                 4, 3   [                            ]
1169                                        [                2           ]
1170                                        [         2 m sin (theta)    ]
1171                                        [ 0  0  - ---------------  0 ]
1172                                        [                r           ]
1173
1174                     [        2                                             ]
1175                     [   m sin (theta)                                      ]
1176                     [ - -------------         0                0         0 ]
1177                     [         r                                            ]
1178                     [                                                      ]
1179                     [                         2                            ]
1180                     [                    m sin (theta)                     ]
1181          riem     = [        0         - -------------         0         0 ]
1182              4, 4   [                          r                           ]
1183                     [                                                      ]
1184                     [                                          2           ]
1185                     [                                   2 m sin (theta)    ]
1186                     [        0                0         ---------------  0 ]
1187                     [                                          r           ]
1188                     [                                                      ]
1189                     [        0                0                0         0 ]
1190
1191          (%o5)                                done
1192
1193
1194 -- Function: deleten (<L>, <n>)
1195     Returns a new list consisting of <L> with the <n>'th element
1196     deleted.
1197
119826.2.9 Variables used by 'ctensor'
1199----------------------------------
1200
1201 -- Option variable: dim
1202     Default value: 4
1203
1204     An option in the 'ctensor' (component tensor) package.  'dim' is
1205     the dimension of the manifold with the default 4.  The command
1206     'dim: n' will reset the dimension to any other value 'n'.
1207
1208 -- Option variable: diagmetric
1209     Default value: 'false'
1210
1211     An option in the 'ctensor' (component tensor) package.  If
1212     'diagmetric' is 'true' special routines compute all geometrical
1213     objects (which contain the metric tensor explicitly) by taking into
1214     consideration the diagonality of the metric.  Reduced run times
1215     will, of course, result.  Note: this option is set automatically by
1216     'csetup' if a diagonal metric is specified.
1217
1218 -- Option variable: ctrgsimp
1219
1220     Causes trigonometric simplifications to be used when tensors are
1221     computed.  Presently, 'ctrgsimp' affects only computations
1222     involving a moving frame.
1223
1224 -- Option variable: cframe_flag
1225
1226     Causes computations to be performed relative to a moving frame as
1227     opposed to a holonomic metric.  The frame is defined by the inverse
1228     frame array 'fri' and the frame metric 'lfg'.  For computations
1229     using a Cartesian frame, 'lfg' should be the unit matrix of the
1230     appropriate dimension; for computations in a Lorentz frame, 'lfg'
1231     should have the appropriate signature.
1232
1233 -- Option variable: ctorsion_flag
1234
1235     Causes the contortion tensor to be included in the computation of
1236     the connection coefficients.  The contortion tensor itself is
1237     computed by 'contortion' from the user-supplied tensor 'tr'.
1238
1239 -- Option variable: cnonmet_flag
1240
1241     Causes the nonmetricity coefficients to be included in the
1242     computation of the connection coefficients.  The nonmetricity
1243     coefficients are computed from the user-supplied nonmetricity
1244     vector 'nm' by the function 'nonmetricity'.
1245
1246 -- Option variable: ctayswitch
1247
1248     If set to 'true', causes some 'ctensor' computations to be carried
1249     out using Taylor-series expansions.  Presently, 'christof',
1250     'ricci', 'uricci', 'einstein', and 'weyl' take into account this
1251     setting.
1252
1253 -- Option variable: ctayvar
1254
1255     Variable used for Taylor-series expansion if 'ctayswitch' is set to
1256     'true'.
1257
1258 -- Option variable: ctaypov
1259
1260     Maximum power used in Taylor-series expansion when 'ctayswitch' is
1261     set to 'true'.
1262
1263 -- Option variable: ctaypt
1264
1265     Point around which Taylor-series expansion is carried out when
1266     'ctayswitch' is set to 'true'.
1267
1268 -- System variable: gdet
1269
1270     The determinant of the metric tensor 'lg'.  Computed by 'cmetric'
1271     when 'cframe_flag' is set to 'false'.
1272
1273 -- Option variable: ratchristof
1274
1275     Causes rational simplification to be applied by 'christof'.
1276
1277 -- Option variable: rateinstein
1278     Default value: 'true'
1279
1280     If 'true' rational simplification will be performed on the non-zero
1281     components of Einstein tensors; if 'ratfac' is 'true' then the
1282     components will also be factored.
1283
1284 -- Option variable: ratriemann
1285     Default value: 'true'
1286
1287     One of the switches which controls simplification of Riemann
1288     tensors; if 'true', then rational simplification will be done; if
1289     'ratfac' is 'true' then each of the components will also be
1290     factored.
1291
1292 -- Option variable: ratweyl
1293     Default value: 'true'
1294
1295     If 'true', this switch causes the 'weyl' function to apply rational
1296     simplification to the values of the Weyl tensor.  If 'ratfac' is
1297     'true', then the components will also be factored.
1298
1299 -- Variable: lfg
1300     The covariant frame metric.  By default, it is initialized to the
1301     4-dimensional Lorentz frame with signature (+,+,+,-).  Used when
1302     'cframe_flag' is 'true'.
1303
1304 -- Variable: ufg
1305     The inverse frame metric.  Computed from 'lfg' when 'cmetric' is
1306     called while 'cframe_flag' is set to 'true'.
1307
1308 -- Variable: riem
1309     The (3,1) Riemann tensor.  Computed when the function 'riemann' is
1310     invoked.  For information about index ordering, see the description
1311     of 'riemann'.
1312
1313     If 'cframe_flag' is 'true', 'riem' is computed from the covariant
1314     Riemann-tensor 'lriem'.
1315
1316 -- Variable: lriem
1317
1318     The covariant Riemann tensor.  Computed by 'lriemann'.
1319
1320 -- Variable: uriem
1321
1322     The contravariant Riemann tensor.  Computed by 'uriemann'.
1323
1324 -- Variable: ric
1325
1326     The covariant Ricci-tensor.  Computed by 'ricci'.
1327
1328 -- Variable: uric
1329
1330     The mixed-index Ricci-tensor.  Computed by 'uricci'.
1331
1332 -- Variable: lg
1333
1334     The metric tensor.  This tensor must be specified (as a 'dim' by
1335     'dim' matrix) before other computations can be performed.
1336
1337 -- Variable: ug
1338
1339     The inverse of the metric tensor.  Computed by 'cmetric'.
1340
1341 -- Variable: weyl
1342
1343     The Weyl tensor.  Computed by 'weyl'.
1344
1345 -- Variable: fb
1346
1347     Frame bracket coefficients, as computed by 'frame_bracket'.
1348
1349 -- Variable: kinvariant
1350
1351     The Kretchmann invariant.  Computed by 'rinvariant'.
1352
1353 -- Variable: np
1354
1355     A Newman-Penrose null tetrad.  Computed by 'nptetrad'.
1356
1357 -- Variable: npi
1358
1359     The raised-index Newman-Penrose null tetrad.  Computed by
1360     'nptetrad'.  Defined as 'ug.np'.  The product 'np.transpose(npi)'
1361     is constant:
1362
1363          (%i39) trigsimp(np.transpose(npi));
1364                                        [  0   - 1  0  0 ]
1365                                        [                ]
1366                                        [ - 1   0   0  0 ]
1367          (%o39)                        [                ]
1368                                        [  0    0   0  1 ]
1369                                        [                ]
1370                                        [  0    0   1  0 ]
1371
1372 -- Variable: tr
1373
1374     User-supplied rank-3 tensor representing torsion.  Used by
1375     'contortion'.
1376
1377 -- Variable: kt
1378
1379     The contortion tensor, computed from 'tr' by 'contortion'.
1380
1381 -- Variable: nm
1382
1383     User-supplied nonmetricity vector.  Used by 'nonmetricity'.
1384
1385 -- Variable: nmc
1386
1387     The nonmetricity coefficients, computed from 'nm' by
1388     'nonmetricity'.
1389
1390 -- System variable: tensorkill
1391
1392     Variable indicating if the tensor package has been initialized.
1393     Set and used by 'csetup', reset by 'init_ctensor'.
1394
1395 -- Option variable: ct_coords
1396     Default value: '[]'
1397
1398     An option in the 'ctensor' (component tensor) package.  'ct_coords'
1399     contains a list of coordinates.  While normally defined when the
1400     function 'csetup' is called, one may redefine the coordinates with
1401     the assignment 'ct_coords: [j1, j2, ..., jn]' where the j's are the
1402     new coordinate names.  See also 'csetup'.
1403
140426.2.10 Reserved names
1405----------------------
1406
1407The following names are used internally by the 'ctensor' package and
1408should not be redefined:
1409
1410       Name         Description
1411       ---------------------------------------------------------------------
1412       _lg()        Evaluates to lfg if frame metric used, lg otherwise
1413       _ug()        Evaluates to ufg if frame metric used, ug otherwise
1414       cleanup()    Removes items drom the deindex list
1415       contract4()  Used by psi()
1416       filemet()    Used by csetup() when reading the metric from a file
1417       findde1()    Used by findde()
1418       findde2()    Used by findde()
1419       findde3()    Used by findde()
1420       kdelt()      Kronecker-delta (not generalized)
1421       newmet()     Used by csetup() for setting up a metric interactively
1422       setflags()   Used by init_ctensor()
1423       readvalue()
1424       resimp()
1425       sermet()     Used by csetup() for entering a metric as Taylor-series
1426       txyzsum()
1427       tmetric()    Frame metric, used by cmetric() when cframe_flag:true
1428       triemann()   Riemann-tensor in frame base, used when cframe_flag:true
1429       tricci()     Ricci-tensor in frame base, used when cframe_flag:true
1430       trrc()       Ricci rotation coefficients, used by christof()
1431       yesp()
1432
143326.2.11 Changes
1434---------------
1435
1436In November, 2004, the 'ctensor' package was extensively rewritten.
1437Many functions and variables have been renamed in order to make the
1438package compatible with the commercial version of Macsyma.
1439
1440       New Name     Old Name        Description
1441       ---------------------------------------------------------------------
1442       ctaylor()    DLGTAYLOR()     Taylor-series expansion of an expression
1443       lgeod[]      EM              Geodesic equations
1444       ein[]        G[]             Mixed Einstein-tensor
1445       ric[]        LR[]            Mixed Ricci-tensor
1446       ricci()      LRICCICOM()     Compute the mixed Ricci-tensor
1447       ctaypov      MINP            Maximum power in Taylor-series expansion
1448       cgeodesic()  MOTION          Compute geodesic equations
1449       ct_coords    OMEGA           Metric coordinates
1450       ctayvar      PARAM           Taylor-series expansion variable
1451       lriem[]      R[]             Covariant Riemann-tensor
1452       uriemann()   RAISERIEMANN()  Compute the contravariant Riemann-tensor
1453       ratriemann   RATRIEMAN       Rational simplif. of the Riemann-tensor
1454       uric[]       RICCI[]         Contravariant Ricci-tensor
1455       uricci()     RICCICOM()      Compute the contravariant Ricci-tensor
1456       cmetric()    SETMETRIC()     Set up the metric
1457       ctaypt       TAYPT           Point for Taylor-series expansion
1458       ctayswitch   TAYSWITCH       Taylor-series setting switch
1459       csetup()     TSETUP()        Start interactive setup session
1460       ctransform() TTRANSFORM()    Interactive coordinate transformation
1461       uriem[]      UR[]            Contravariant Riemann-tensor
1462       weyl[]       W[]             (3,1) Weyl-tensor
1463
1464
1465
1466File: maxima.info,  Node: atensor,  Next: Sums Products and Series,  Prev: ctensor,  Up: Top
1467
146827 atensor
1469**********
1470
1471* Menu:
1472
1473* Introduction to atensor::
1474* Functions and Variables for atensor::
1475
1476
1477File: maxima.info,  Node: Introduction to atensor,  Next: Functions and Variables for atensor,  Prev: atensor,  Up: atensor
1478
147927.1 Introduction to atensor
1480============================
1481
1482'atensor' is an algebraic tensor manipulation package.  To use
1483'atensor', type 'load("atensor")', followed by a call to the
1484'init_atensor' function.
1485
1486   The essence of 'atensor' is a set of simplification rules for the
1487noncommutative (dot) product operator ("'.'").  'atensor' recognizes
1488several algebra types; the corresponding simplification rules are put
1489into effect when the 'init_atensor' function is called.
1490
1491   The capabilities of 'atensor' can be demonstrated by defining the
1492algebra of quaternions as a Clifford-algebra Cl(0,2) with two basis
1493vectors.  The three quaternionic imaginary units are then the two basis
1494vectors and their product, i.e.:
1495
1496         i = v     j = v     k = v  . v
1497              1         2         1    2
1498
1499   Although the 'atensor' package has a built-in definition for the
1500quaternion algebra, it is not used in this example, in which we
1501endeavour to build the quaternion multiplication table as a matrix:
1502
1503     (%i1) load("atensor");
1504     (%o1)       /share/tensor/atensor.mac
1505     (%i2) init_atensor(clifford,0,0,2);
1506     (%o2)                                done
1507     (%i3) atensimp(v[1].v[1]);
1508     (%o3)                                 - 1
1509     (%i4) atensimp((v[1].v[2]).(v[1].v[2]));
1510     (%o4)                                 - 1
1511     (%i5) q:zeromatrix(4,4);
1512                                     [ 0  0  0  0 ]
1513                                     [            ]
1514                                     [ 0  0  0  0 ]
1515     (%o5)                           [            ]
1516                                     [ 0  0  0  0 ]
1517                                     [            ]
1518                                     [ 0  0  0  0 ]
1519     (%i6) q[1,1]:1;
1520     (%o6)                                  1
1521     (%i7) for i thru adim do q[1,i+1]:q[i+1,1]:v[i];
1522     (%o7)                                done
1523     (%i8) q[1,4]:q[4,1]:v[1].v[2];
1524     (%o8)                               v  . v
1525                                          1    2
1526     (%i9) for i from 2 thru 4 do for j from 2 thru 4 do
1527           q[i,j]:atensimp(q[i,1].q[1,j]);
1528     (%o9)                                done
1529     (%i10) q;
1530                        [    1        v         v      v  . v  ]
1531                        [              1         2      1    2 ]
1532                        [                                      ]
1533                        [   v         - 1     v  . v    - v    ]
1534                        [    1                 1    2      2   ]
1535     (%o10)             [                                      ]
1536                        [   v      - v  . v     - 1      v     ]
1537                        [    2        1    2              1    ]
1538                        [                                      ]
1539                        [ v  . v      v        - v       - 1   ]
1540                        [  1    2      2          1            ]
1541
1542   'atensor' recognizes as base vectors indexed symbols, where the
1543symbol is that stored in 'asymbol' and the index runs between 1 and
1544'adim'.  For indexed symbols, and indexed symbols only, the bilinear
1545forms 'sf', 'af', and 'av' are evaluated.  The evaluation substitutes
1546the value of 'aform[i,j]' in place of 'fun(v[i],v[j])' where 'v'
1547represents the value of 'asymbol' and 'fun' is either 'af' or 'sf'; or,
1548it substitutes 'v[aform[i,j]]' in place of 'av(v[i],v[j])'.
1549
1550   Needless to say, the functions 'sf', 'af' and 'av' can be redefined.
1551
1552   When the 'atensor' package is loaded, the following flags are set:
1553
1554     dotscrules:true;
1555     dotdistrib:true;
1556     dotexptsimp:false;
1557
1558   If you wish to experiment with a nonassociative algebra, you may also
1559consider setting 'dotassoc' to 'false'.  In this case, however,
1560'atensimp' will not always be able to obtain the desired
1561simplifications.
1562
1563
1564File: maxima.info,  Node: Functions and Variables for atensor,  Prev: Introduction to atensor,  Up: atensor
1565
156627.2 Functions and Variables for atensor
1567========================================
1568
1569 -- Function: init_atensor
1570          init_atensor (<alg_type>, <opt_dims>)
1571          init_atensor (<alg_type>)
1572
1573     Initializes the 'atensor' package with the specified algebra type.
1574     <alg_type> can be one of the following:
1575
1576     'universal': The universal algebra has no commutation rules.
1577
1578     'grassmann': The Grassman algebra is defined by the commutation
1579     relation 'u.v+v.u=0'.
1580
1581     'clifford': The Clifford algebra is defined by the commutation
1582     relation 'u.v+v.u=-2*sf(u,v)' where 'sf' is a symmetric
1583     scalar-valued function.  For this algebra, <opt_dims> can be up to
1584     three nonnegative integers, representing the number of positive,
1585     degenerate, and negative dimensions of the algebra, respectively.
1586     If any <opt_dims> values are supplied, 'atensor' will configure the
1587     values of 'adim' and 'aform' appropriately.  Otherwise, 'adim' will
1588     default to 0 and 'aform' will not be defined.
1589
1590     'symmetric': The symmetric algebra is defined by the commutation
1591     relation 'u.v-v.u=0'.
1592
1593     'symplectic': The symplectic algebra is defined by the commutation
1594     relation 'u.v-v.u=2*af(u,v)' where 'af' is an antisymmetric
1595     scalar-valued function.  For the symplectic algebra, <opt_dims> can
1596     be up to two nonnegative integers, representing the nondegenerate
1597     and degenerate dimensions, respectively.  If any <opt_dims> values
1598     are supplied, 'atensor' will configure the values of 'adim' and
1599     'aform' appropriately.  Otherwise, 'adim' will default to 0 and
1600     'aform' will not be defined.
1601
1602     'lie_envelop': The algebra of the Lie envelope is defined by the
1603     commutation relation 'u.v-v.u=2*av(u,v)' where 'av' is an
1604     antisymmetric function.
1605
1606     The 'init_atensor' function also recognizes several predefined
1607     algebra types:
1608
1609     'complex' implements the algebra of complex numbers as the Clifford
1610     algebra Cl(0,1).  The call 'init_atensor(complex)' is equivalent to
1611     'init_atensor(clifford,0,0,1)'.
1612
1613     'quaternion' implements the algebra of quaternions.  The call
1614     'init_atensor (quaternion)' is equivalent to 'init_atensor
1615     (clifford,0,0,2)'.
1616
1617     'pauli' implements the algebra of Pauli-spinors as the
1618     Clifford-algebra Cl(3,0).  A call to 'init_atensor(pauli)' is
1619     equivalent to 'init_atensor(clifford,3)'.
1620
1621     'dirac' implements the algebra of Dirac-spinors as the
1622     Clifford-algebra Cl(3,1).  A call to 'init_atensor(dirac)' is
1623     equivalent to 'init_atensor(clifford,3,0,1)'.
1624
1625 -- Function: atensimp (<expr>)
1626
1627     Simplifies an algebraic tensor expression <expr> according to the
1628     rules configured by a call to 'init_atensor'.  Simplification
1629     includes recursive application of commutation relations and
1630     resolving calls to 'sf', 'af', and 'av' where applicable.  A
1631     safeguard is used to ensure that the function always terminates,
1632     even for complex expressions.
1633
1634 -- Function: alg_type
1635     The algebra type.  Valid values are 'universal', 'grassmann',
1636     'clifford', 'symmetric', 'symplectic' and 'lie_envelop'.
1637
1638 -- Variable: adim
1639     Default value: 0
1640
1641     The dimensionality of the algebra.  'atensor' uses the value of
1642     'adim' to determine if an indexed object is a valid base vector.
1643     See 'abasep'.
1644
1645 -- Variable: aform
1646     Default value: 'ident(3)'
1647
1648     Default values for the bilinear forms 'sf', 'af', and 'av'.  The
1649     default is the identity matrix 'ident(3)'.
1650
1651 -- Variable: asymbol
1652     Default value: 'v'
1653
1654     The symbol for base vectors.
1655
1656 -- Function: sf (<u>, <v>)
1657
1658     A symmetric scalar function that is used in commutation relations.
1659     The default implementation checks if both arguments are base
1660     vectors using 'abasep' and if that is the case, substitutes the
1661     corresponding value from the matrix 'aform'.
1662
1663 -- Function: af (<u>, <v>)
1664
1665     An antisymmetric scalar function that is used in commutation
1666     relations.  The default implementation checks if both arguments are
1667     base vectors using 'abasep' and if that is the case, substitutes
1668     the corresponding value from the matrix 'aform'.
1669
1670 -- Function: av (<u>, <v>)
1671
1672     An antisymmetric function that is used in commutation relations.
1673     The default implementation checks if both arguments are base
1674     vectors using 'abasep' and if that is the case, substitutes the
1675     corresponding value from the matrix 'aform'.
1676
1677     For instance:
1678
1679          (%i1) load("atensor");
1680          (%o1)       /share/tensor/atensor.mac
1681          (%i2) adim:3;
1682          (%o2)                                  3
1683          (%i3) aform:matrix([0,3,-2],[-3,0,1],[2,-1,0]);
1684                                         [  0    3   - 2 ]
1685                                         [               ]
1686          (%o3)                          [ - 3   0    1  ]
1687                                         [               ]
1688                                         [  2   - 1   0  ]
1689          (%i4) asymbol:x;
1690          (%o4)                                  x
1691          (%i5) av(x[1],x[2]);
1692          (%o5)                                 x
1693                                                 3
1694
1695 -- Function: abasep (<v>)
1696
1697     Checks if its argument is an 'atensor' base vector.  That is, if it
1698     is an indexed symbol, with the symbol being the same as the value
1699     of 'asymbol', and the index having a numeric value between 1 and
1700     'adim'.
1701
1702
1703File: maxima.info,  Node: Sums Products and Series,  Next: Number Theory,  Prev: atensor,  Up: Top
1704
170528 Sums, Products, and Series
1706*****************************
1707
1708* Menu:
1709
1710* Functions and Variables for Sums and Products::
1711* Introduction to Series::
1712* Functions and Variables for Series::
1713* Introduction to Fourier series::
1714* Functions and Variables for Fourier series::
1715* Functions and Variables for Poisson series::
1716
1717
1718File: maxima.info,  Node: Functions and Variables for Sums and Products,  Next: Introduction to Series,  Prev: Sums Products and Series,  Up: Sums Products and Series
1719
172028.1 Functions and Variables for Sums and Products
1721==================================================
1722
1723 -- Function: bashindices (<expr>)
1724
1725     Transforms the expression <expr> by giving each summation and
1726     product a unique index.  This gives 'changevar' greater precision
1727     when it is working with summations or products.  The form of the
1728     unique index is 'j<number>'.  The quantity <number> is determined
1729     by referring to 'gensumnum', which can be changed by the user.  For
1730     example, 'gensumnum:0$' resets it.
1731
1732 -- Function: lsum (<expr>, <x>, <L>)
1733
1734     Represents the sum of <expr> for each element <x> in <L>.  A noun
1735     form ''lsum' is returned if the argument <L> does not evaluate to a
1736     list.
1737
1738     Examples:
1739
1740          (%i1) lsum (x^i, i, [1, 2, 7]);
1741                                      7    2
1742          (%o1)                      x  + x  + x
1743          (%i2) lsum (i^2, i, rootsof (x^3 - 1, x));
1744                               ====
1745                               \      2
1746          (%o2)                 >    i
1747                               /
1748                               ====
1749                                             3
1750                               i in rootsof(x  - 1, x)
1751
1752 -- Function: intosum (<expr>)
1753
1754     Moves multiplicative factors outside a summation to inside.  If the
1755     index is used in the outside expression, then the function tries to
1756     find a reasonable index, the same as it does for 'sumcontract'.
1757     This is essentially the reverse idea of the 'outative' property of
1758     summations, but note that it does not remove this property, it only
1759     bypasses it.
1760
1761     In some cases, a 'scanmap (multthru, <expr>)' may be necessary
1762     before the 'intosum'.
1763
1764 -- Option variable: simpproduct
1765     Default value: 'false'
1766
1767     When 'simpproduct' is 'true', the result of a 'product' is
1768     simplified.  This simplification may sometimes be able to produce a
1769     closed form.  If 'simpproduct' is 'false' or if the quoted form
1770     ''product' is used, the value is a product noun form which is a
1771     representation of the pi notation used in mathematics.
1772
1773 -- Function: product (<expr>, <i>, <i_0>, <i_1>)
1774
1775     Represents a product of the values of <expr> as the index <i>
1776     varies from <i_0> to <i_1>.  The noun form ''product' is displayed
1777     as an uppercase letter pi.
1778
1779     'product' evaluates <expr> and lower and upper limits <i_0> and
1780     <i_1>, 'product' quotes (does not evaluate) the index <i>.
1781
1782     If the upper and lower limits differ by an integer, <expr> is
1783     evaluated for each value of the index <i>, and the result is an
1784     explicit product.
1785
1786     Otherwise, the range of the index is indefinite.  Some rules are
1787     applied to simplify the product.  When the global variable
1788     'simpproduct' is 'true', additional rules are applied.  In some
1789     cases, simplification yields a result which is not a product;
1790     otherwise, the result is a noun form ''product'.
1791
1792     See also 'nouns' and 'evflag'.
1793
1794     Examples:
1795
1796          (%i1) product (x + i*(i+1)/2, i, 1, 4);
1797          (%o1)           (x + 1) (x + 3) (x + 6) (x + 10)
1798          (%i2) product (i^2, i, 1, 7);
1799          (%o2)                       25401600
1800          (%i3) product (a[i], i, 1, 7);
1801          (%o3)                 a  a  a  a  a  a  a
1802                                 1  2  3  4  5  6  7
1803          (%i4) product (a(i), i, 1, 7);
1804          (%o4)          a(1) a(2) a(3) a(4) a(5) a(6) a(7)
1805          (%i5) product (a(i), i, 1, n);
1806                                       n
1807                                     /===\
1808                                      ! !
1809          (%o5)                       ! !  a(i)
1810                                      ! !
1811                                     i = 1
1812          (%i6) product (k, k, 1, n);
1813                                         n
1814                                       /===\
1815                                        ! !
1816          (%o6)                         ! !  k
1817                                        ! !
1818                                       k = 1
1819          (%i7) product (k, k, 1, n), simpproduct;
1820          (%o7)                          n!
1821          (%i8) product (integrate (x^k, x, 0, 1), k, 1, n);
1822                                       n
1823                                     /===\
1824                                      ! !    1
1825          (%o8)                       ! !  -----
1826                                      ! !  k + 1
1827                                     k = 1
1828          (%i9) product (if k <= 5 then a^k else b^k, k, 1, 10);
1829                                        15  40
1830          (%o9)                        a   b
1831
1832 -- Option variable: simpsum
1833     Default value: 'false'
1834
1835     When 'simpsum' is 'true', the result of a 'sum' is simplified.
1836     This simplification may sometimes be able to produce a closed form.
1837     If 'simpsum' is 'false' or if the quoted form ''sum' is used, the
1838     value is a sum noun form which is a representation of the sigma
1839     notation used in mathematics.
1840
1841 -- Function: sum (<expr>, <i>, <i_0>, <i_1>)
1842
1843     Represents a summation of the values of <expr> as the index <i>
1844     varies from <i_0> to <i_1>.  The noun form ''sum' is displayed as
1845     an uppercase letter sigma.
1846
1847     'sum' evaluates its summand <expr> and lower and upper limits <i_0>
1848     and <i_1>, 'sum' quotes (does not evaluate) the index <i>.
1849
1850     If the upper and lower limits differ by an integer, the summand
1851     <expr> is evaluated for each value of the summation index <i>, and
1852     the result is an explicit sum.
1853
1854     Otherwise, the range of the index is indefinite.  Some rules are
1855     applied to simplify the summation.  When the global variable
1856     'simpsum' is 'true', additional rules are applied.  In some cases,
1857     simplification yields a result which is not a summation; otherwise,
1858     the result is a noun form ''sum'.
1859
1860     When the 'evflag' (evaluation flag) 'cauchysum' is 'true', a
1861     product of summations is expressed as a Cauchy product, in which
1862     the index of the inner summation is a function of the index of the
1863     outer one, rather than varying independently.
1864
1865     The global variable 'genindex' is the alphabetic prefix used to
1866     generate the next index of summation, when an automatically
1867     generated index is needed.
1868
1869     'gensumnum' is the numeric suffix used to generate the next index
1870     of summation, when an automatically generated index is needed.
1871     When 'gensumnum' is 'false', an automatically-generated index is
1872     only 'genindex' with no numeric suffix.
1873
1874     See also 'lsum', 'sumcontract', 'intosum', 'bashindices',
1875     'niceindices', 'nouns', 'evflag', and *note zeilberger-pkg::
1876
1877     Examples:
1878
1879          (%i1) sum (i^2, i, 1, 7);
1880          (%o1)                          140
1881          (%i2) sum (a[i], i, 1, 7);
1882          (%o2)           a  + a  + a  + a  + a  + a  + a
1883                           7    6    5    4    3    2    1
1884          (%i3) sum (a(i), i, 1, 7);
1885          (%o3)    a(7) + a(6) + a(5) + a(4) + a(3) + a(2) + a(1)
1886          (%i4) sum (a(i), i, 1, n);
1887                                      n
1888                                     ====
1889                                     \
1890          (%o4)                       >    a(i)
1891                                     /
1892                                     ====
1893                                     i = 1
1894          (%i5) sum (2^i + i^2, i, 0, n);
1895                                    n
1896                                   ====
1897                                   \       i    2
1898          (%o5)                     >    (2  + i )
1899                                   /
1900                                   ====
1901                                   i = 0
1902          (%i6) sum (2^i + i^2, i, 0, n), simpsum;
1903                                        3      2
1904                             n + 1   2 n  + 3 n  + n
1905          (%o6)             2      + --------------- - 1
1906                                            6
1907          (%i7) sum (1/3^i, i, 1, inf);
1908                                      inf
1909                                      ====
1910                                      \     1
1911          (%o7)                        >    --
1912                                      /      i
1913                                      ====  3
1914                                      i = 1
1915          (%i8) sum (1/3^i, i, 1, inf), simpsum;
1916                                          1
1917          (%o8)                           -
1918                                          2
1919          (%i9) sum (i^2, i, 1, 4) * sum (1/i^2, i, 1, inf);
1920                                        inf
1921                                        ====
1922                                        \     1
1923          (%o9)                      30  >    --
1924                                        /      2
1925                                        ====  i
1926                                        i = 1
1927          (%i10) sum (i^2, i, 1, 4) * sum (1/i^2, i, 1, inf), simpsum;
1928                                            2
1929          (%o10)                       5 %pi
1930          (%i11) sum (integrate (x^k, x, 0, 1), k, 1, n);
1931                                      n
1932                                     ====
1933                                     \       1
1934          (%o11)                      >    -----
1935                                     /     k + 1
1936                                     ====
1937                                     k = 1
1938          (%i12) sum (if k <= 5 then a^k else b^k, k, 1, 10);
1939                    10    9    8    7    6    5    4    3    2
1940          (%o12)   b   + b  + b  + b  + b  + a  + a  + a  + a  + a
1941
1942 -- Function: sumcontract (<expr>)
1943
1944     Combines all sums of an addition that have upper and lower bounds
1945     that differ by constants.  The result is an expression containing
1946     one summation for each set of such summations added to all
1947     appropriate extra terms that had to be extracted to form this sum.
1948     'sumcontract' combines all compatible sums and uses one of the
1949     indices from one of the sums if it can, and then try to form a
1950     reasonable index if it cannot use any supplied.
1951
1952     It may be necessary to do an 'intosum (<expr>)' before the
1953     'sumcontract'.
1954
1955 -- Option variable: sumexpand
1956     Default value: 'false'
1957
1958     When 'sumexpand' is 'true', products of sums and exponentiated sums
1959     simplify to nested sums.
1960
1961     See also 'cauchysum'.
1962
1963     Examples:
1964
1965          (%i1) sumexpand: true$
1966          (%i2) sum (f (i), i, 0, m) * sum (g (j), j, 0, n);
1967                               m      n
1968                              ====   ====
1969                              \      \
1970          (%o2)                >      >     f(i1) g(i2)
1971                              /      /
1972                              ====   ====
1973                              i1 = 0 i2 = 0
1974          (%i3) sum (f (i), i, 0, m)^2;
1975                               m      m
1976                              ====   ====
1977                              \      \
1978          (%o3)                >      >     f(i3) f(i4)
1979                              /      /
1980                              ====   ====
1981                              i3 = 0 i4 = 0
1982
1983
1984File: maxima.info,  Node: Introduction to Series,  Next: Functions and Variables for Series,  Prev: Functions and Variables for Sums and Products,  Up: Sums Products and Series
1985
198628.2 Introduction to Series
1987===========================
1988
1989Maxima contains functions 'taylor' and 'powerseries' for finding the
1990series of differentiable functions.  It also has tools such as 'nusum'
1991capable of finding the closed form of some series.  Operations such as
1992addition and multiplication work as usual on series.  This section
1993presents the global variables which control the expansion.
1994
1995
1996File: maxima.info,  Node: Functions and Variables for Series,  Next: Introduction to Fourier series,  Prev: Introduction to Series,  Up: Sums Products and Series
1997
199828.3 Functions and Variables for Series
1999=======================================
2000
2001 -- Option variable: cauchysum
2002     Default value: 'false'
2003
2004     When multiplying together sums with 'inf' as their upper limit, if
2005     'sumexpand' is 'true' and 'cauchysum' is 'true' then the Cauchy
2006     product will be used rather than the usual product.  In the Cauchy
2007     product the index of the inner summation is a function of the index
2008     of the outer one rather than varying independently.
2009
2010     Example:
2011
2012          (%i1) sumexpand: false$
2013          (%i2) cauchysum: false$
2014          (%i3) s: sum (f(i), i, 0, inf) * sum (g(j), j, 0, inf);
2015                                inf         inf
2016                                ====        ====
2017                                \           \
2018          (%o3)                ( >    f(i))  >    g(j)
2019                                /           /
2020                                ====        ====
2021                                i = 0       j = 0
2022          (%i4) sumexpand: true$
2023          (%i5) cauchysum: true$
2024          (%i6) expand(s,0,0);
2025                           inf     i1
2026                           ====   ====
2027                           \      \
2028          (%o6)             >      >     g(i1 - i2) f(i2)
2029                           /      /
2030                           ====   ====
2031                           i1 = 0 i2 = 0
2032
2033 -- Function: deftaylor (<f_1>(<x_1>), <expr_1>, ..., <f_n>(<x_n>),
2034          <expr_n>)
2035
2036     For each function <f_i> of one variable <x_i>, 'deftaylor' defines
2037     <expr_i> as the Taylor series about zero.  <expr_i> is typically a
2038     polynomial in <x_i> or a summation; more general expressions are
2039     accepted by 'deftaylor' without complaint.
2040
2041     'powerseries (<f_i>(<x_i>), <x_i>, 0)' returns the series defined
2042     by 'deftaylor'.
2043
2044     'deftaylor' returns a list of the functions <f_1>, ..., <f_n>.
2045     'deftaylor' evaluates its arguments.
2046
2047     Example:
2048
2049          (%i1) deftaylor (f(x), x^2 + sum(x^i/(2^i*i!^2), i, 4, inf));
2050          (%o1)                          [f]
2051          (%i2) powerseries (f(x), x, 0);
2052                                inf
2053                                ====      i1
2054                                \        x         2
2055          (%o2)                  >     -------- + x
2056                                /       i1    2
2057                                ====   2   i1!
2058                                i1 = 4
2059          (%i3) taylor (exp (sqrt (f(x))), x, 0, 4);
2060                                2         3          4
2061                               x    3073 x    12817 x
2062          (%o3)/T/     1 + x + -- + ------- + -------- + . . .
2063                               2     18432     307200
2064
2065 -- Option variable: maxtayorder
2066     Default value: 'true'
2067
2068     When 'maxtayorder' is 'true', then during algebraic manipulation of
2069     (truncated) Taylor series, 'taylor' tries to retain as many terms
2070     as are known to be correct.
2071
2072 -- Function: niceindices (<expr>)
2073
2074     Renames the indices of sums and products in <expr>.  'niceindices'
2075     attempts to rename each index to the value of 'niceindicespref[1]',
2076     unless that name appears in the summand or multiplicand, in which
2077     case 'niceindices' tries the succeeding elements of
2078     'niceindicespref' in turn, until an unused variable is found.  If
2079     the entire list is exhausted, additional indices are constructed by
2080     appending integers to the value of 'niceindicespref[1]', e.g.,
2081     'i0', 'i1', 'i2', ...
2082
2083     'niceindices' returns an expression.  'niceindices' evaluates its
2084     argument.
2085
2086     Example:
2087
2088          (%i1) niceindicespref;
2089          (%o1)                  [i, j, k, l, m, n]
2090          (%i2) product (sum (f (foo + i*j*bar), foo, 1, inf), bar, 1, inf);
2091                           inf    inf
2092                          /===\   ====
2093                           ! !    \
2094          (%o2)            ! !     >      f(bar i j + foo)
2095                           ! !    /
2096                          bar = 1 ====
2097                                  foo = 1
2098          (%i3) niceindices (%);
2099                               inf  inf
2100                              /===\ ====
2101                               ! !  \
2102          (%o3)                ! !   >    f(i j l + k)
2103                               ! !  /
2104                              l = 1 ====
2105                                    k = 1
2106
2107 -- Option variable: niceindicespref
2108     Default value: '[i, j, k, l, m, n]'
2109
2110     'niceindicespref' is the list from which 'niceindices' takes the
2111     names of indices for sums and products.
2112
2113     The elements of 'niceindicespref' are typically names of variables,
2114     although that is not enforced by 'niceindices'.
2115
2116     Example:
2117
2118          (%i1) niceindicespref: [p, q, r, s, t, u]$
2119          (%i2) product (sum (f (foo + i*j*bar), foo, 1, inf), bar, 1, inf);
2120                           inf    inf
2121                          /===\   ====
2122                           ! !    \
2123          (%o2)            ! !     >      f(bar i j + foo)
2124                           ! !    /
2125                          bar = 1 ====
2126                                  foo = 1
2127          (%i3) niceindices (%);
2128                               inf  inf
2129                              /===\ ====
2130                               ! !  \
2131          (%o3)                ! !   >    f(i j q + p)
2132                               ! !  /
2133                              q = 1 ====
2134                                    p = 1
2135
2136 -- Function: nusum (<expr>, <x>, <i_0>, <i_1>)
2137
2138     Carries out indefinite hypergeometric summation of <expr> with
2139     respect to <x> using a decision procedure due to R.W. Gosper.
2140     <expr> and the result must be expressible as products of integer
2141     powers, factorials, binomials, and rational functions.
2142
2143     The terms "definite" and "indefinite summation" are used
2144     analogously to "definite" and "indefinite integration".  To sum
2145     indefinitely means to give a symbolic result for the sum over
2146     intervals of variable length, not just e.g.  0 to inf.  Thus, since
2147     there is no formula for the general partial sum of the binomial
2148     series, 'nusum' can't do it.
2149
2150     'nusum' and 'unsum' know a little about sums and differences of
2151     finite products.  See also 'unsum'.
2152
2153     Examples:
2154
2155          (%i1) nusum (n*n!, n, 0, n);
2156
2157          Dependent equations eliminated:  (1)
2158          (%o1)                     (n + 1)! - 1
2159          (%i2) nusum (n^4*4^n/binomial(2*n,n), n, 0, n);
2160                               4        3       2              n
2161                2 (n + 1) (63 n  + 112 n  + 18 n  - 22 n + 3) 4      2
2162          (%o2) ------------------------------------------------ - ------
2163                              693 binomial(2 n, n)                 3 11 7
2164          (%i3) unsum (%, n);
2165                                        4  n
2166                                       n  4
2167          (%o3)                   ----------------
2168                                  binomial(2 n, n)
2169          (%i4) unsum (prod (i^2, i, 1, n), n);
2170                              n - 1
2171                              /===\
2172                               ! !   2
2173          (%o4)              ( ! !  i ) (n - 1) (n + 1)
2174                               ! !
2175                              i = 1
2176          (%i5) nusum (%, n, 1, n);
2177
2178          Dependent equations eliminated:  (2 3)
2179                                      n
2180                                    /===\
2181                                     ! !   2
2182          (%o5)                      ! !  i  - 1
2183                                     ! !
2184                                    i = 1
2185
2186 -- Function: pade (<taylor_series>, <numer_deg_bound>,
2187          <denom_deg_bound>)
2188
2189     Returns a list of all rational functions which have the given
2190     Taylor series expansion where the sum of the degrees of the
2191     numerator and the denominator is less than or equal to the
2192     truncation level of the power series, i.e.  are "best"
2193     approximants, and which additionally satisfy the specified degree
2194     bounds.
2195
2196     <taylor_series> is a univariate Taylor series.  <numer_deg_bound>
2197     and <denom_deg_bound> are positive integers specifying degree
2198     bounds on the numerator and denominator.
2199
2200     <taylor_series> can also be a Laurent series, and the degree bounds
2201     can be 'inf' which causes all rational functions whose total degree
2202     is less than or equal to the length of the power series to be
2203     returned.  Total degree is defined as '<numer_deg_bound> +
2204     <denom_deg_bound>'.  Length of a power series is defined as
2205     '"truncation level" + 1 - min(0, "order of series")'.
2206
2207          (%i1) taylor (1 + x + x^2 + x^3, x, 0, 3);
2208                                        2    3
2209          (%o1)/T/             1 + x + x  + x  + . . .
2210          (%i2) pade (%, 1, 1);
2211                                           1
2212          (%o2)                       [- -----]
2213                                         x - 1
2214          (%i3) t: taylor(-(83787*x^10 - 45552*x^9 - 187296*x^8
2215                             + 387072*x^7 + 86016*x^6 - 1507328*x^5
2216                             + 1966080*x^4 + 4194304*x^3 - 25165824*x^2
2217                             + 67108864*x - 134217728)
2218                 /134217728, x, 0, 10);
2219                              2    3       4       5       6        7
2220                       x   3 x    x    15 x    23 x    21 x    189 x
2221          (%o3)/T/ 1 - - + ---- - -- - ----- + ----- - ----- - ------
2222                       2    16    32   1024    2048    32768   65536
2223
2224                                            8         9          10
2225                                      5853 x    2847 x    83787 x
2226                                    + ------- + ------- - --------- + . . .
2227                                      4194304   8388608   134217728
2228          (%i4) pade (t, 4, 4);
2229          (%o4)                          []
2230
2231     There is no rational function of degree 4 numerator/denominator,
2232     with this power series expansion.  You must in general have degree
2233     of the numerator and degree of the denominator adding up to at
2234     least the degree of the power series, in order to have enough
2235     unknown coefficients to solve.
2236
2237          (%i5) pade (t, 5, 5);
2238                               5                4                 3
2239          (%o5) [- (520256329 x  - 96719020632 x  - 489651410240 x
2240
2241                            2
2242           - 1619100813312 x  - 2176885157888 x - 2386516803584)
2243
2244                         5                 4                  3
2245          /(47041365435 x  + 381702613848 x  + 1360678489152 x
2246
2247                            2
2248           + 2856700692480 x  + 3370143559680 x + 2386516803584)]
2249
2250 -- Function: powerseries (<expr>, <x>, <a>)
2251
2252     Returns the general form of the power series expansion for <expr>
2253     in the variable <x> about the point <a> (which may be 'inf' for
2254     infinity):
2255                     inf
2256                     ====
2257                     \               n
2258                      >    b  (x - a)
2259                     /      n
2260                     ====
2261                     n = 0
2262
2263     If 'powerseries' is unable to expand <expr>, 'taylor' may give the
2264     first several terms of the series.
2265
2266     When 'verbose' is 'true', 'powerseries' prints progress messages.
2267
2268          (%i1) verbose: true$
2269          (%i2) powerseries (log(sin(x)/x), x, 0);
2270          can't expand
2271                                           log(sin(x))
2272          so we'll try again after applying the rule:
2273                                                  d
2274                                                / -- (sin(x))
2275                                                [ dx
2276                                  log(sin(x)) = i ----------- dx
2277                                                ]   sin(x)
2278                                                /
2279          in the first simplification we have returned:
2280                                       /
2281                                       [
2282                                       i cot(x) dx - log(x)
2283                                       ]
2284                                       /
2285                              inf
2286                              ====        i1  2 i1             2 i1
2287                              \      (- 1)   2     bern(2 i1) x
2288                               >     ------------------------------
2289                              /                i1 (2 i1)!
2290                              ====
2291                              i1 = 1
2292          (%o2)                -------------------------------------
2293                                                2
2294
2295 -- Option variable: psexpand
2296     Default value: 'false'
2297
2298     When 'psexpand' is 'true', an extended rational function expression
2299     is displayed fully expanded.  The switch 'ratexpand' has the same
2300     effect.
2301
2302     When 'psexpand' is 'false', a multivariate expression is displayed
2303     just as in the rational function package.
2304
2305     When 'psexpand' is 'multi', then terms with the same total degree
2306     in the variables are grouped together.
2307
2308 -- Function: revert (<expr>, <x>)
2309 -- Function: revert2 (<expr>, <x>, <n>)
2310
2311     These functions return the reversion of <expr>, a Taylor series
2312     about zero in the variable <x>.  'revert' returns a polynomial of
2313     degree equal to the highest power in <expr>.  'revert2' returns a
2314     polynomial of degree <n>, which may be greater than, equal to, or
2315     less than the degree of <expr>.
2316
2317     'load ("revert")' loads these functions.
2318
2319     Examples:
2320
2321          (%i1) load ("revert")$
2322          (%i2) t: taylor (exp(x) - 1, x, 0, 6);
2323                             2    3    4    5     6
2324                            x    x    x    x     x
2325          (%o2)/T/      x + -- + -- + -- + --- + --- + . . .
2326                            2    6    24   120   720
2327          (%i3) revert (t, x);
2328                         6       5       4       3       2
2329                     10 x  - 12 x  + 15 x  - 20 x  + 30 x  - 60 x
2330          (%o3)/R/ - --------------------------------------------
2331                                          60
2332          (%i4) ratexpand (%);
2333                               6    5    4    3    2
2334                              x    x    x    x    x
2335          (%o4)             - -- + -- - -- + -- - -- + x
2336                              6    5    4    3    2
2337          (%i5) taylor (log(x+1), x, 0, 6);
2338                              2    3    4    5    6
2339                             x    x    x    x    x
2340          (%o5)/T/       x - -- + -- - -- + -- - -- + . . .
2341                             2    3    4    5    6
2342          (%i6) ratsimp (revert (t, x) - taylor (log(x+1), x, 0, 6));
2343          (%o6)                           0
2344          (%i7) revert2 (t, x, 4);
2345                                    4    3    2
2346                                   x    x    x
2347          (%o7)                  - -- + -- - -- + x
2348                                   4    3    2
2349
2350 -- Function: taylor
2351          taylor (<expr>, <x>, <a>, <n>)
2352          taylor (<expr>, [<x_1>, <x_2>, ...], <a>, <n>)
2353          taylor (<expr>, [<x>, <a>, <n>, 'asymp])
2354          taylor (<expr>, [<x_1>, <x_2>, ...], [<a_1>, <a_2>, ...],
2355          [<n_1>, <n_2>, ...])
2356          taylor (<expr>, [<x_1>, <a_1>, <n_1>], [<x_2>, <a_2>, <n_2>],
2357          ...)
2358
2359     'taylor (<expr>, <x>, <a>, <n>)' expands the expression <expr> in a
2360     truncated Taylor or Laurent series in the variable <x> around the
2361     point <a>, containing terms through '(<x> - <a>)^<n>'.
2362
2363     If <expr> is of the form '<f>(<x>)/<g>(<x>)' and '<g>(<x>)' has no
2364     terms up to degree <n> then 'taylor' attempts to expand '<g>(<x>)'
2365     up to degree '2 <n>'.  If there are still no nonzero terms,
2366     'taylor' doubles the degree of the expansion of '<g>(<x>)' so long
2367     as the degree of the expansion is less than or equal to '<n>
2368     2^taylordepth'.
2369
2370     'taylor (<expr>, [<x_1>, <x_2>, ...], <a>, <n>)' returns a
2371     truncated power series of degree <n> in all variables <x_1>, <x_2>,
2372     ... about the point '(<a>, <a>, ...)'.
2373
2374     'taylor (<expr>, [<x_1>, <a_1>, <n_1>], [<x_2>, <a_2>, <n_2>],
2375     ...)' returns a truncated power series in the variables <x_1>,
2376     <x_2>, ... about the point '(<a_1>, <a_2>, ...)', truncated at
2377     <n_1>, <n_2>, ...
2378
2379     'taylor (<expr>, [<x_1>, <x_2>, ...], [<a_1>, <a_2>, ...], [<n_1>,
2380     <n_2>, ...])' returns a truncated power series in the variables
2381     <x_1>, <x_2>, ... about the point '(<a_1>, <a_2>, ...)', truncated
2382     at <n_1>, <n_2>, ...
2383
2384     'taylor (<expr>, [<x>, <a>, <n>, 'asymp])' returns an expansion of
2385     <expr> in negative powers of '<x> - <a>'.  The highest order term
2386     is '(<x> - <a>)^<-n>'.
2387
2388     When 'maxtayorder' is 'true', then during algebraic manipulation of
2389     (truncated) Taylor series, 'taylor' tries to retain as many terms
2390     as are known to be correct.
2391
2392     When 'psexpand' is 'true', an extended rational function expression
2393     is displayed fully expanded.  The switch 'ratexpand' has the same
2394     effect.  When 'psexpand' is 'false', a multivariate expression is
2395     displayed just as in the rational function package.  When
2396     'psexpand' is 'multi', then terms with the same total degree in the
2397     variables are grouped together.
2398
2399     See also the 'taylor_logexpand' switch for controlling expansion.
2400
2401     Examples:
2402
2403          (%i1) taylor (sqrt (sin(x) + a*x + 1), x, 0, 3);
2404                                     2             2
2405                       (a + 1) x   (a  + 2 a + 1) x
2406          (%o1)/T/ 1 + --------- - -----------------
2407                           2               8
2408
2409                                             3      2             3
2410                                         (3 a  + 9 a  + 9 a - 1) x
2411                                       + -------------------------- + . . .
2412                                                     48
2413          (%i2) %^2;
2414                                              3
2415                                             x
2416          (%o2)/T/           1 + (a + 1) x - -- + . . .
2417                                             6
2418          (%i3) taylor (sqrt (x + 1), x, 0, 5);
2419                                 2    3      4      5
2420                            x   x    x    5 x    7 x
2421          (%o3)/T/      1 + - - -- + -- - ---- + ---- + . . .
2422                            2   8    16   128    256
2423          (%i4) %^2;
2424          (%o4)/T/                  1 + x + . . .
2425          (%i5) product ((1 + x^i)^2.5, i, 1, inf)/(1 + x^2);
2426                                   inf
2427                                  /===\
2428                                   ! !    i     2.5
2429                                   ! !  (x  + 1)
2430                                   ! !
2431                                  i = 1
2432          (%o5)                   -----------------
2433                                        2
2434                                       x  + 1
2435          (%i6) ev (taylor(%, x,  0, 3), keepfloat);
2436                                         2           3
2437          (%o6)/T/    1 + 2.5 x + 3.375 x  + 6.5625 x  + . . .
2438          (%i7) taylor (1/log (x + 1), x, 0, 3);
2439                                         2       3
2440                           1   1   x    x    19 x
2441          (%o7)/T/         - + - - -- + -- - ----- + . . .
2442                           x   2   12   24    720
2443          (%i8) taylor (cos(x) - sec(x), x, 0, 5);
2444                                          4
2445                                     2   x
2446          (%o8)/T/                - x  - -- + . . .
2447                                         6
2448          (%i9) taylor ((cos(x) - sec(x))^3, x, 0, 5);
2449          (%o9)/T/                    0 + . . .
2450          (%i10) taylor (1/(cos(x) - sec(x))^3, x, 0, 5);
2451                                                         2          4
2452                      1     1       11      347    6767 x    15377 x
2453          (%o10)/T/ - -- + ---- + ------ - ----- - ------- - --------
2454                       6      4        2   15120   604800    7983360
2455                      x    2 x    120 x
2456
2457                                                                    + . . .
2458          (%i11) taylor (sqrt (1 - k^2*sin(x)^2), x, 0, 6);
2459                         2  2       4      2   4
2460                        k  x    (3 k  - 4 k ) x
2461          (%o11)/T/ 1 - ----- - ----------------
2462                          2            24
2463
2464                                              6       4       2   6
2465                                         (45 k  - 60 k  + 16 k ) x
2466                                       - -------------------------- + . . .
2467                                                    720
2468          (%i12) taylor ((x + 1)^n, x, 0, 4);
2469                                2       2     3      2         3
2470                              (n  - n) x    (n  - 3 n  + 2 n) x
2471          (%o12)/T/ 1 + n x + ----------- + --------------------
2472                                   2                 6
2473
2474                                         4      3       2         4
2475                                       (n  - 6 n  + 11 n  - 6 n) x
2476                                     + ---------------------------- + . . .
2477                                                    24
2478          (%i13) taylor (sin (y + x), x, 0, 3, y, 0, 3);
2479                         3                 2
2480                        y                 y
2481          (%o13)/T/ y - -- + . . . + (1 - -- + . . .) x
2482                        6                 2
2483
2484                              3                       2
2485                         y   y            2      1   y            3
2486                    + (- - + -- + . . .) x  + (- - + -- + . . .) x  + . . .
2487                         2   12                  6   12
2488          (%i14) taylor (sin (y + x), [x, y], 0, 3);
2489                               3        2      2      3
2490                              x  + 3 y x  + 3 y  x + y
2491          (%o14)/T/   y + x - ------------------------- + . . .
2492                                          6
2493          (%i15) taylor (1/sin (y + x), x, 0, 3, y, 0, 3);
2494                    1   y              1    1               1            2
2495          (%o15)/T/ - + - + . . . + (- -- + - + . . .) x + (-- + . . .) x
2496                    y   6               2   6                3
2497                                       y                    y
2498
2499                                                     1            3
2500                                                + (- -- + . . .) x  + . . .
2501                                                      4
2502                                                     y
2503          (%i16) taylor (1/sin (y + x), [x, y], 0, 3);
2504                                       3         2       2        3
2505                      1     x + y   7 x  + 21 y x  + 21 y  x + 7 y
2506          (%o16)/T/ ----- + ----- + ------------------------------- + . . .
2507                    x + y     6                   360
2508
2509 -- Option variable: taylordepth
2510     Default value: 3
2511
2512     If there are still no nonzero terms, 'taylor' doubles the degree of
2513     the expansion of '<g>(<x>)' so long as the degree of the expansion
2514     is less than or equal to '<n> 2^taylordepth'.
2515
2516 -- Function: taylorinfo (<expr>)
2517
2518     Returns information about the Taylor series <expr>.  The return
2519     value is a list of lists.  Each list comprises the name of a
2520     variable, the point of expansion, and the degree of the expansion.
2521
2522     'taylorinfo' returns 'false' if <expr> is not a Taylor series.
2523
2524     Example:
2525
2526          (%i1) taylor ((1 - y^2)/(1 - x), x, 0, 3, [y, a, inf]);
2527                            2                       2
2528          (%o1)/T/ - (y - a)  - 2 a (y - a) + (1 - a )
2529
2530                   2                        2
2531           + (1 - a  - 2 a (y - a) - (y - a) ) x
2532
2533                   2                        2   2
2534           + (1 - a  - 2 a (y - a) - (y - a) ) x
2535
2536                   2                        2   3
2537           + (1 - a  - 2 a (y - a) - (y - a) ) x  + . . .
2538          (%i2) taylorinfo(%);
2539          (%o2)               [[y, a, inf], [x, 0, 3]]
2540
2541 -- Function: taylorp (<expr>)
2542
2543     Returns 'true' if <expr> is a Taylor series, and 'false' otherwise.
2544
2545 -- Option variable: taylor_logexpand
2546     Default value: 'true'
2547
2548     'taylor_logexpand' controls expansions of logarithms in 'taylor'
2549     series.
2550
2551     When 'taylor_logexpand' is 'true', all logarithms are expanded
2552     fully so that zero-recognition problems involving logarithmic
2553     identities do not disturb the expansion process.  However, this
2554     scheme is not always mathematically correct since it ignores branch
2555     information.
2556
2557     When 'taylor_logexpand' is set to 'false', then the only expansion
2558     of logarithms that occur is that necessary to obtain a formal power
2559     series.
2560
2561 -- Option variable: taylor_order_coefficients
2562     Default value: 'true'
2563
2564     'taylor_order_coefficients' controls the ordering of coefficients
2565     in a Taylor series.
2566
2567     When 'taylor_order_coefficients' is 'true', coefficients of taylor
2568     series are ordered canonically.
2569
2570 -- Function: taylor_simplifier (<expr>)
2571
2572     Simplifies coefficients of the power series <expr>.  'taylor' calls
2573     this function.
2574
2575 -- Option variable: taylor_truncate_polynomials
2576     Default value: 'true'
2577
2578     When 'taylor_truncate_polynomials' is 'true', polynomials are
2579     truncated based upon the input truncation levels.
2580
2581     Otherwise, polynomials input to 'taylor' are considered to have
2582     infinite precison.
2583
2584 -- Function: taytorat (<expr>)
2585
2586     Converts <expr> from 'taylor' form to canonical rational expression
2587     (CRE) form.  The effect is the same as 'rat (ratdisrep (<expr>))',
2588     but faster.
2589
2590 -- Function: trunc (<expr>)
2591
2592     Annotates the internal representation of the general expression
2593     <expr> so that it is displayed as if its sums were truncated Taylor
2594     series.  <expr> is not otherwise modified.
2595
2596     Example:
2597
2598          (%i1) expr: x^2 + x + 1;
2599                                      2
2600          (%o1)                      x  + x + 1
2601          (%i2) trunc (expr);
2602                                          2
2603          (%o2)                  1 + x + x  + . . .
2604          (%i3) is (expr = trunc (expr));
2605          (%o3)                         true
2606
2607 -- Function: unsum (<f>, <n>)
2608
2609     Returns the first backward difference '<f>(<n>) - <f>(<n> - 1)'.
2610     Thus 'unsum' in a sense is the inverse of 'sum'.
2611
2612     See also 'nusum'.
2613
2614     Examples:
2615
2616          (%i1) g(p) := p*4^n/binomial(2*n,n);
2617                                               n
2618                                            p 4
2619          (%o1)               g(p) := ----------------
2620                                      binomial(2 n, n)
2621          (%i2) g(n^4);
2622                                        4  n
2623                                       n  4
2624          (%o2)                   ----------------
2625                                  binomial(2 n, n)
2626          (%i3) nusum (%, n, 0, n);
2627                               4        3       2              n
2628                2 (n + 1) (63 n  + 112 n  + 18 n  - 22 n + 3) 4      2
2629          (%o3) ------------------------------------------------ - ------
2630                              693 binomial(2 n, n)                 3 11 7
2631          (%i4) unsum (%, n);
2632                                        4  n
2633                                       n  4
2634          (%o4)                   ----------------
2635                                  binomial(2 n, n)
2636
2637 -- Option variable: verbose
2638     Default value: 'false'
2639
2640     When 'verbose' is 'true', 'powerseries' prints progress messages.
2641
2642
2643File: maxima.info,  Node: Introduction to Fourier series,  Next: Functions and Variables for Fourier series,  Prev: Functions and Variables for Series,  Up: Sums Products and Series
2644
264528.4 Introduction to Fourier series
2646===================================
2647
2648The 'fourie' package comprises functions for the symbolic computation of
2649Fourier series.  There are functions in the 'fourie' package to
2650calculate Fourier integral coefficients and some functions for
2651manipulation of expressions.
2652
2653
2654File: maxima.info,  Node: Functions and Variables for Fourier series,  Next: Functions and Variables for Poisson series,  Prev: Introduction to Fourier series,  Up: Sums Products and Series
2655
265628.5 Functions and Variables for Fourier series
2657===============================================
2658
2659 -- Function: equalp (<x>, <y>)
2660
2661     Returns 'true' if 'equal (<x>, <y>)' otherwise 'false' (doesn't
2662     give an error message like 'equal (x, y)' would do in this case).
2663
2664 -- Function: remfun
2665          remfun (<f>, <expr>)
2666          remfun (<f>, <expr>, <x>)
2667
2668     'remfun (<f>, <expr>)' replaces all occurrences of '<f> (<arg>)' by
2669     <arg> in <expr>.
2670
2671     'remfun (<f>, <expr>, <x>)' replaces all occurrences of '<f>
2672     (<arg>)' by <arg> in <expr> only if <arg> contains the variable
2673     <x>.
2674
2675 -- Function: funp
2676          funp (<f>, <expr>)
2677          funp (<f>, <expr>, <x>)
2678
2679     'funp (<f>, <expr>)' returns 'true' if <expr> contains the function
2680     <f>.
2681
2682     'funp (<f>, <expr>, <x>)' returns 'true' if <expr> contains the
2683     function <f> and the variable <x> is somewhere in the argument of
2684     one of the instances of <f>.
2685
2686 -- Function: absint
2687          absint (<f>, <x>, <halfplane>)
2688          absint (<f>, <x>)
2689          absint (<f>, <x>, <a>, <b>)
2690
2691     'absint (<f>, <x>, <halfplane>)' returns the indefinite integral of
2692     <f> with respect to <x> in the given halfplane ('pos', 'neg', or
2693     'both').  <f> may contain expressions of the form 'abs (x)', 'abs
2694     (sin (x))', 'abs (a) * exp (-abs (b) * abs (x))'.
2695
2696     'absint (<f>, <x>)' is equivalent to 'absint (<f>, <x>, pos)'.
2697
2698     'absint (<f>, <x>, <a>, <b>)' returns the definite integral of <f>
2699     with respect to <x> from <a> to <b>.  <f> may include absolute
2700     values.
2701
2702 -- Function: fourier (<f>, <x>, <p>)
2703
2704     Returns a list of the Fourier coefficients of '<f>(<x>)' defined on
2705     the interval '[-p, p]'.
2706
2707 -- Function: foursimp (<l>)
2708
2709     Simplifies 'sin (n %pi)' to 0 if 'sinnpiflag' is 'true' and 'cos (n
2710     %pi)' to '(-1)^n' if 'cosnpiflag' is 'true'.
2711
2712 -- Option variable: sinnpiflag
2713     Default value: 'true'
2714
2715     See 'foursimp'.
2716
2717 -- Option variable: cosnpiflag
2718     Default value: 'true'
2719
2720     See 'foursimp'.
2721
2722 -- Function: fourexpand (<l>, <x>, <p>, <limit>)
2723
2724     Constructs and returns the Fourier series from the list of Fourier
2725     coefficients <l> up through <limit> terms (<limit> may be 'inf').
2726     <x> and <p> have same meaning as in 'fourier'.
2727
2728 -- Function: fourcos (<f>, <x>, <p>)
2729
2730     Returns the Fourier cosine coefficients for '<f>(<x>)' defined on
2731     '[0, <p>]'.
2732
2733 -- Function: foursin (<f>, <x>, <p>)
2734
2735     Returns the Fourier sine coefficients for '<f>(<x>)' defined on
2736     '[0, <p>]'.
2737
2738 -- Function: totalfourier (<f>, <x>, <p>)
2739
2740     Returns 'fourexpand (foursimp (fourier (<f>, <x>, <p>)), <x>, <p>,
2741     'inf)'.
2742
2743 -- Function: fourint (<f>, <x>)
2744
2745     Constructs and returns a list of the Fourier integral coefficients
2746     of '<f>(<x>)' defined on '[minf, inf]'.
2747
2748 -- Function: fourintcos (<f>, <x>)
2749
2750     Returns the Fourier cosine integral coefficients for '<f>(<x>)' on
2751     '[0, inf]'.
2752
2753 -- Function: fourintsin (<f>, <x>)
2754
2755     Returns the Fourier sine integral coefficients for '<f>(<x>)' on
2756     '[0, inf]'.
2757
2758
2759File: maxima.info,  Node: Functions and Variables for Poisson series,  Prev: Functions and Variables for Fourier series,  Up: Sums Products and Series
2760
276128.6 Functions and Variables for Poisson series
2762===============================================
2763
2764 -- Function: intopois (<a>)
2765     Converts <a> into a Poisson encoding.
2766
2767 -- Function: outofpois (<a>)
2768
2769     Converts <a> from Poisson encoding to general representation.  If
2770     <a> is not in Poisson form, 'outofpois' carries out the conversion,
2771     i.e., the return value is 'outofpois (intopois (<a>))'.  This
2772     function is thus a canonical simplifier for sums of powers of sine
2773     and cosine terms of a particular type.
2774
2775 -- Function: poisdiff (<a>, <b>)
2776
2777     Differentiates <a> with respect to <b>.  <b> must occur only in the
2778     trig arguments or only in the coefficients.
2779
2780 -- Function: poisexpt (<a>, <b>)
2781
2782     Functionally identical to 'intopois (<a>^<b>)'.  <b> must be a
2783     positive integer.
2784
2785 -- Function: poisint (<a>, <b>)
2786
2787     Integrates in a similarly restricted sense (to 'poisdiff').
2788     Non-periodic terms in <b> are dropped if <b> is in the trig
2789     arguments.
2790
2791 -- Option variable: poislim
2792     Default value: 5
2793
2794     'poislim' determines the domain of the coefficients in the
2795     arguments of the trig functions.  The initial value of 5
2796     corresponds to the interval [-2^(5-1)+1,2^(5-1)], or [-15,16], but
2797     it can be set to [-2^(n-1)+1, 2^(n-1)].
2798
2799 -- Function: poismap (<series>, <sinfn>, <cosfn>)
2800
2801     will map the functions <sinfn> on the sine terms and <cosfn> on the
2802     cosine terms of the Poisson series given.  <sinfn> and <cosfn> are
2803     functions of two arguments which are a coefficient and a
2804     trigonometric part of a term in series respectively.
2805
2806 -- Function: poisplus (<a>, <b>)
2807
2808     Is functionally identical to 'intopois (a + b)'.
2809
2810 -- Function: poissimp (<a>)
2811
2812     Converts <a> into a Poisson series for <a> in general
2813     representation.
2814
2815 -- Special symbol: poisson
2816
2817     The symbol '/P/' follows the line label of Poisson series
2818     expressions.
2819
2820 -- Function: poissubst (<a>, <b>, <c>)
2821
2822     Substitutes <a> for <b> in <c>.  <c> is a Poisson series.
2823
2824     (1) Where <B> is a variable <u>, <v>, <w>, <x>, <y>, or <z>, then
2825     <a> must be an expression linear in those variables (e.g., '6*u +
2826     4*v').
2827
2828     (2) Where <b> is other than those variables, then <a> must also be
2829     free of those variables, and furthermore, free of sines or cosines.
2830
2831     'poissubst (<a>, <b>, <c>, <d>, <n>)' is a special type of
2832     substitution which operates on <a> and <b> as in type (1) above,
2833     but where <d> is a Poisson series, expands 'cos(<d>)' and
2834     'sin(<d>)' to order <n> so as to provide the result of substituting
2835     '<a> + <d>' for <b> in <c>.  The idea is that <d> is an expansion
2836     in terms of a small parameter.  For example, 'poissubst (u, v,
2837     cos(v), %e, 3)' yields 'cos(u)*(1 - %e^2/2) - sin(u)*(%e -
2838     %e^3/6)'.
2839
2840 -- Function: poistimes (<a>, <b>)
2841
2842     Is functionally identical to 'intopois (<a>*<b>)'.
2843
2844 -- Function: poistrim ()
2845
2846     is a reserved function name which (if the user has defined it) gets
2847     applied during Poisson multiplication.  It is a predicate function
2848     of 6 arguments which are the coefficients of the <u>, <v>, ..., <z>
2849     in a term.  Terms for which 'poistrim' is 'true' (for the
2850     coefficients of that term) are eliminated during multiplication.
2851
2852 -- Function: printpois (<a>)
2853
2854     Prints a Poisson series in a readable format.  In common with
2855     'outofpois', it will convert <a> into a Poisson encoding first, if
2856     necessary.
2857
2858
2859File: maxima.info,  Node: Number Theory,  Next: Symmetries,  Prev: Sums Products and Series,  Up: Top
2860
286129 Number Theory
2862****************
2863
2864* Menu:
2865
2866* Functions and Variables for Number Theory::
2867
2868
2869File: maxima.info,  Node: Functions and Variables for Number Theory,  Prev: Number Theory,  Up: Number Theory
2870
287129.1 Functions and Variables for Number Theory
2872==============================================
2873
2874 -- Function: bern (<n>)
2875
2876     Returns the <n>'th Bernoulli number for integer <n>.  Bernoulli
2877     numbers equal to zero are suppressed if 'zerobern' is 'false'.
2878
2879     See also 'burn'.
2880
2881          (%i1) zerobern: true$
2882          (%i2) map (bern, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
2883                                1  1       1      1        1
2884          (%o2)           [1, - -, -, 0, - --, 0, --, 0, - --]
2885                                2  6       30     42       30
2886          (%i3) zerobern: false$
2887          (%i4) map (bern, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
2888                                1  1    1   1     1   5     691   7
2889          (%o4)           [1, - -, -, - --, --, - --, --, - ----, -]
2890                                2  6    30  42    30  66    2730  6
2891
2892 -- Function: bernpoly (<x>, <n>)
2893
2894     Returns the <n>'th Bernoulli polynomial in the variable <x>.
2895
2896 -- Function: bfzeta (<s>, <n>)
2897
2898     Returns the Riemann zeta function for the argument <s>.  The return
2899     value is a big float (bfloat); <n> is the number of digits in the
2900     return value.
2901
2902 -- Function: bfhzeta (<s>, <h>, <n>)
2903
2904     Returns the Hurwitz zeta function for the arguments <s> and <h>.
2905     The return value is a big float (bfloat); <n> is the number of
2906     digits in the return value.
2907
2908     The Hurwitz zeta function is defined as
2909
2910                                  inf
2911                                  ====
2912                                  \        1
2913                   zeta (s,h)  =   >    --------
2914                                  /            s
2915                                  ====  (k + h)
2916                                  k = 0
2917
2918     'load ("bffac")' loads this function.
2919
2920 -- Function: burn (<n>)
2921
2922     Returns a rational number, which is an approximation of the <n>'th
2923     Bernoulli number for integer <n>.  'burn' exploits the observation
2924     that (rational) Bernoulli numbers can be approximated by
2925     (transcendental) zetas with tolerable efficiency:
2926
2927                             n - 1  1 - 2 n
2928                        (- 1)      2        zeta(2 n) (2 n)!
2929               B(2 n) = ------------------------------------
2930                                          2 n
2931                                       %pi
2932
2933     'burn' may be more efficient than 'bern' for large, isolated <n> as
2934     'bern' computes all the Bernoulli numbers up to index <n> before
2935     returning.  'burn' invokes the approximation for even integers <n>
2936     > 255.  For odd integers and <n> <= 255 the function 'bern' is
2937     called.
2938
2939     'load ("bffac")' loads this function.  See also 'bern'.
2940
2941 -- Function: chinese ([<r_1>, ..., <r_n>], [<m_1>, ..., <m_n>])
2942
2943     Solves the system of congruences 'x = r_1 mod m_1', ..., 'x = r_n
2944     mod m_n'.  The remainders <r_n> may be arbitrary integers while the
2945     moduli <m_n> have to be positive and pairwise coprime integers.
2946
2947          (%i1) mods : [1000, 1001, 1003, 1007];
2948          (%o1)                   [1000, 1001, 1003, 1007]
2949          (%i2) lreduce('gcd, mods);
2950          (%o2)                               1
2951          (%i3) x : random(apply("*", mods));
2952          (%o3)                         685124877004
2953          (%i4) rems : map(lambda([z], mod(x, z)), mods);
2954          (%o4)                       [4, 568, 54, 624]
2955          (%i5) chinese(rems, mods);
2956          (%o5)                         685124877004
2957          (%i6) chinese([1, 2], [3, n]);
2958          (%o6)                    chinese([1, 2], [3, n])
2959          (%i7) %, n = 4;
2960          (%o7)                              10
2961
2962 -- Function: cf (<expr>)
2963
2964     Computes a continued fraction approximation.  <expr> is an
2965     expression comprising continued fractions, square roots of
2966     integers, and literal real numbers (integers, rational numbers,
2967     ordinary floats, and bigfloats).  'cf' computes exact expansions
2968     for rational numbers, but expansions are truncated at 'ratepsilon'
2969     for ordinary floats and '10^(-fpprec)' for bigfloats.
2970
2971     Operands in the expression may be combined with arithmetic
2972     operators.  Maxima does not know about operations on continued
2973     fractions outside of 'cf'.
2974
2975     'cf' evaluates its arguments after binding 'listarith' to 'false'.
2976     'cf' returns a continued fraction, represented as a list.
2977
2978     A continued fraction 'a + 1/(b + 1/(c + ...))' is represented by
2979     the list '[a, b, c, ...]'.  The list elements 'a', 'b', 'c', ...
2980     must evaluate to integers.  <expr> may also contain 'sqrt (n)'
2981     where 'n' is an integer.  In this case 'cf' will give as many terms
2982     of the continued fraction as the value of the variable 'cflength'
2983     times the period.
2984
2985     A continued fraction can be evaluated to a number by evaluating the
2986     arithmetic representation returned by 'cfdisrep'.  See also
2987     'cfexpand' for another way to evaluate a continued fraction.
2988
2989     See also 'cfdisrep', 'cfexpand', and 'cflength'.
2990
2991     Examples:
2992
2993        * <expr> is an expression comprising continued fractions and
2994          square roots of integers.
2995
2996               (%i1) cf ([5, 3, 1]*[11, 9, 7] + [3, 7]/[4, 3, 2]);
2997               (%o1)               [59, 17, 2, 1, 1, 1, 27]
2998               (%i2) cf ((3/17)*[1, -2, 5]/sqrt(11) + (8/13));
2999               (%o2)        [0, 1, 1, 1, 3, 2, 1, 4, 1, 9, 1, 9, 2]
3000
3001        * 'cflength' controls how many periods of the continued fraction
3002          are computed for algebraic, irrational numbers.
3003
3004               (%i1) cflength: 1$
3005               (%i2) cf ((1 + sqrt(5))/2);
3006               (%o2)                    [1, 1, 1, 1, 2]
3007               (%i3) cflength: 2$
3008               (%i4) cf ((1 + sqrt(5))/2);
3009               (%o4)               [1, 1, 1, 1, 1, 1, 1, 2]
3010               (%i5) cflength: 3$
3011               (%i6) cf ((1 + sqrt(5))/2);
3012               (%o6)           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
3013
3014        * A continued fraction can be evaluated by evaluating the
3015          arithmetic representation returned by 'cfdisrep'.
3016
3017               (%i1) cflength: 3$
3018               (%i2) cfdisrep (cf (sqrt (3)))$
3019               (%i3) ev (%, numer);
3020               (%o3)                   1.731707317073171
3021
3022        * Maxima does not know about operations on continued fractions
3023          outside of 'cf'.
3024
3025               (%i1) cf ([1,1,1,1,1,2] * 3);
3026               (%o1)                     [4, 1, 5, 2]
3027               (%i2) cf ([1,1,1,1,1,2]) * 3;
3028               (%o2)                  [3, 3, 3, 3, 3, 6]
3029
3030 -- Function: cfdisrep (<list>)
3031
3032     Constructs and returns an ordinary arithmetic expression of the
3033     form 'a + 1/(b + 1/(c + ...))' from the list representation of a
3034     continued fraction '[a, b, c, ...]'.
3035
3036          (%i1) cf ([1, 2, -3] + [1, -2, 1]);
3037          (%o1)                     [1, 1, 1, 2]
3038          (%i2) cfdisrep (%);
3039                                            1
3040          (%o2)                     1 + ---------
3041                                              1
3042                                        1 + -----
3043                                                1
3044                                            1 + -
3045                                                2
3046
3047 -- Function: cfexpand (<x>)
3048
3049     Returns a matrix of the numerators and denominators of the last
3050     (column 1) and next-to-last (column 2) convergents of the continued
3051     fraction <x>.
3052
3053          (%i1) cf (rat (ev (%pi, numer)));
3054
3055          `rat' replaced 3.141592653589793 by 103993/33102 =3.141592653011902
3056          (%o1)                  [3, 7, 15, 1, 292]
3057          (%i2) cfexpand (%);
3058                                   [ 103993  355 ]
3059          (%o2)                    [             ]
3060                                   [ 33102   113 ]
3061          (%i3) %[1,1]/%[2,1], numer;
3062          (%o3)                   3.141592653011902
3063
3064 -- Option variable: cflength
3065     Default value: 1
3066
3067     'cflength' controls the number of terms of the continued fraction
3068     the function 'cf' will give, as the value 'cflength' times the
3069     period.  Thus the default is to give one period.
3070
3071          (%i1) cflength: 1$
3072          (%i2) cf ((1 + sqrt(5))/2);
3073          (%o2)                    [1, 1, 1, 1, 2]
3074          (%i3) cflength: 2$
3075          (%i4) cf ((1 + sqrt(5))/2);
3076          (%o4)               [1, 1, 1, 1, 1, 1, 1, 2]
3077          (%i5) cflength: 3$
3078          (%i6) cf ((1 + sqrt(5))/2);
3079          (%o6)           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
3080
3081 -- Function: divsum
3082          divsum (<n>, <k>)
3083          divsum (<n>)
3084
3085     'divsum (<n>, <k>)' returns the sum of the divisors of <n> raised
3086     to the <k>'th power.
3087
3088     'divsum (<n>)' returns the sum of the divisors of <n>.
3089
3090          (%i1) divsum (12);
3091          (%o1)                          28
3092          (%i2) 1 + 2 + 3 + 4 + 6 + 12;
3093          (%o2)                          28
3094          (%i3) divsum (12, 2);
3095          (%o3)                          210
3096          (%i4) 1^2 + 2^2 + 3^2 + 4^2 + 6^2 + 12^2;
3097          (%o4)                          210
3098
3099 -- Function: euler (<n>)
3100
3101     Returns the <n>'th Euler number for nonnegative integer <n>.  Euler
3102     numbers equal to zero are suppressed if 'zerobern' is 'false'.
3103
3104     For the Euler-Mascheroni constant, see '%gamma'.
3105
3106          (%i1) zerobern: true$
3107          (%i2) map (euler, [0, 1, 2, 3, 4, 5, 6]);
3108          (%o2)               [1, 0, - 1, 0, 5, 0, - 61]
3109          (%i3) zerobern: false$
3110          (%i4) map (euler, [0, 1, 2, 3, 4, 5, 6]);
3111          (%o4)               [1, - 1, 5, - 61, 1385, - 50521, 2702765]
3112
3113 -- Option variable: factors_only
3114     Default value: 'false'
3115
3116     Controls the value returned by 'ifactors'.  The default 'false'
3117     causes 'ifactors' to provide information about multiplicities of
3118     the computed prime factors.  If 'factors_only' is set to 'true',
3119     'ifactors' returns nothing more than a list of prime factors.
3120
3121     Example: See 'ifactors'.
3122
3123 -- Function: fib (<n>)
3124
3125     Returns the <n>'th Fibonacci number.  'fib(0)' is equal to 0 and
3126     'fib(1)' equal to 1, and 'fib (-<n>)' equal to '(-1)^(<n> + 1) *
3127     fib(<n>)'.
3128
3129     After calling 'fib', 'prevfib' is equal to 'fib(<n> - 1)', the
3130     Fibonacci number preceding the last one computed.
3131
3132          (%i1) map (fib, [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
3133          (%o1)           [- 3, 2, - 1, 1, 0, 1, 1, 2, 3, 5, 8, 13, 21]
3134
3135 -- Function: fibtophi (<expr>)
3136
3137     Expresses Fibonacci numbers in <expr> in terms of the constant
3138     '%phi', which is '(1 + sqrt(5))/2', approximately 1.61803399.
3139
3140     Examples:
3141
3142          (%i1) fibtophi (fib (n));
3143                                     n             n
3144                                 %phi  - (1 - %phi)
3145          (%o1)                  -------------------
3146                                     2 %phi - 1
3147          (%i2) fib (n-1) + fib (n) - fib (n+1);
3148          (%o2)          - fib(n + 1) + fib(n) + fib(n - 1)
3149          (%i3) fibtophi (%);
3150                      n + 1             n + 1       n             n
3151                  %phi      - (1 - %phi)        %phi  - (1 - %phi)
3152          (%o3) - --------------------------- + -------------------
3153                          2 %phi - 1                2 %phi - 1
3154                                                    n - 1             n - 1
3155                                                %phi      - (1 - %phi)
3156                                              + ---------------------------
3157                                                        2 %phi - 1
3158          (%i4) ratsimp (%);
3159          (%o4)                           0
3160
3161 -- Function: ifactors (<n>)
3162
3163     For a positive integer <n> returns the factorization of <n>.  If
3164     'n=p1^e1..pk^nk' is the decomposition of <n> into prime factors,
3165     ifactors returns '[[p1, e1], ... , [pk, ek]]'.
3166
3167     Factorization methods used are trial divisions by primes up to
3168     9973, Pollard's rho and p-1 method and elliptic curves.
3169
3170     If the variable 'ifactor_verbose' is set to 'true' ifactor produces
3171     detailed output about what it is doing including immediate feedback
3172     as soon as a factor has been found.
3173
3174     The value returned by 'ifactors' is controlled by the option
3175     variable 'factors_only'.  The default 'false' causes 'ifactors' to
3176     provide information about the multiplicities of the computed prime
3177     factors.  If 'factors_only' is set to 'true', 'ifactors' simply
3178     returns the list of prime factors.
3179
3180          (%i1) ifactors(51575319651600);
3181          (%o1)     [[2, 4], [3, 2], [5, 2], [1583, 1], [9050207, 1]]
3182          (%i2) apply("*", map(lambda([u], u[1]^u[2]), %));
3183          (%o2)                        51575319651600
3184          (%i3) ifactors(51575319651600), factors_only : true;
3185          (%o3)                   [2, 3, 5, 1583, 9050207]
3186
3187 -- Function: igcdex (<n>, <k>)
3188
3189     Returns a list '[<a>, <b>, <u>]' where <u> is the greatest common
3190     divisor of <n> and <k>, and <u> is equal to '<a> <n> + <b> <k>'.
3191     The arguments <n> and <k> must be integers.
3192
3193     'igcdex' implements the Euclidean algorithm.  See also 'gcdex'.
3194
3195     The command 'load("gcdex")' loads the function.
3196
3197     Examples:
3198
3199          (%i1) load("gcdex")$
3200
3201          (%i2) igcdex(30,18);
3202          (%o2)                      [- 1, 2, 6]
3203          (%i3) igcdex(1526757668, 7835626735736);
3204          (%o3)            [845922341123, - 164826435, 4]
3205          (%i4) igcdex(fib(20), fib(21));
3206          (%o4)                   [4181, - 2584, 1]
3207
3208 -- Function: inrt (<x>, <n>)
3209
3210     Returns the integer <n>'th root of the absolute value of <x>.
3211
3212          (%i1) l: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]$
3213          (%i2) map (lambda ([a], inrt (10^a, 3)), l);
3214          (%o2) [2, 4, 10, 21, 46, 100, 215, 464, 1000, 2154, 4641, 10000]
3215
3216 -- Function: inv_mod (<n>, <m>)
3217
3218     Computes the inverse of <n> modulo <m>.  'inv_mod (n,m)' returns
3219     'false', if <n> is a zero divisor modulo <m>.
3220
3221          (%i1) inv_mod(3, 41);
3222          (%o1)                           14
3223          (%i2) ratsimp(3^-1), modulus = 41;
3224          (%o2)                           14
3225          (%i3) inv_mod(3, 42);
3226          (%o3)                          false
3227
3228 -- Function: isqrt (<x>)
3229
3230     Returns the "integer square root" of the absolute value of <x>,
3231     which is an integer.
3232
3233 -- Function: jacobi (<p>, <q>)
3234
3235     Returns the Jacobi symbol of <p> and <q>.
3236
3237          (%i1) l: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]$
3238          (%i2) map (lambda ([a], jacobi (a, 9)), l);
3239          (%o2)         [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0]
3240
3241 -- Function: lcm (<expr_1>, ..., <expr_n>)
3242
3243     Returns the least common multiple of its arguments.  The arguments
3244     may be general expressions as well as integers.
3245
3246     'load ("functs")' loads this function.
3247
3248 -- Function: lucas (<n>)
3249
3250     Returns the <n>'th Lucas number.  'lucas(0)' is equal to 2 and
3251     'lucas(1)' equal to 1, and 'lucas(-<n>)' equal to '(-1)^(-<n>) *
3252     lucas(<n>)'.
3253
3254          (%i1) map (lucas, [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
3255          (%o1)             [7, - 4, 3, - 1, 2, 1, 3, 4, 7, 11, 18, 29, 47]
3256
3257     After calling 'lucas', the global variable 'next_lucas' is equal to
3258     'lucas (<n> + 1)', the Lucas number following the last returned.
3259     The example shows how Fibonacci numbers can be computed via 'lucas'
3260     and 'next_lucas'.
3261
3262          (%i1) fib_via_lucas(n) :=
3263                   block([lucas : lucas(n)],
3264                   signum(n) * (2*next_lucas - lucas)/5 )$
3265          (%i2) map (fib_via_lucas, [-4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
3266          (%o2)             [- 3, 2, - 1, 1, 0, 1, 1, 2, 3, 5, 8, 13, 21]
3267
3268 -- Function: mod (<x>, <y>)
3269
3270     If <x> and <y> are real numbers and <y> is nonzero, return '<x> -
3271     <y> * floor(<x> / <y>)'.  Further for all real <x>, we have 'mod
3272     (<x>, 0) = <x>'.  For a discussion of the definition 'mod (<x>, 0)
3273     = <x>', see Section 3.4, of "Concrete Mathematics," by Graham,
3274     Knuth, and Patashnik.  The function 'mod (<x>, 1)' is a sawtooth
3275     function with period 1 with 'mod (1, 1) = 0' and 'mod (0, 1) = 0'.
3276
3277     To find the principal argument (a number in the interval '(-%pi,
3278     %pi]') of a complex number, use the function '<x> |-> %pi - mod
3279     (%pi - <x>, 2*%pi)', where <x> is an argument.
3280
3281     When <x> and <y> are constant expressions ('10 * %pi', for
3282     example), 'mod' uses the same big float evaluation scheme that
3283     'floor' and 'ceiling' uses.  Again, it's possible, although
3284     unlikely, that 'mod' could return an erroneous value in such cases.
3285
3286     For nonnumerical arguments <x> or <y>, 'mod' knows several
3287     simplification rules:
3288
3289          (%i1) mod (x, 0);
3290          (%o1)                           x
3291          (%i2) mod (a*x, a*y);
3292          (%o2)                      a mod(x, y)
3293          (%i3) mod (0, x);
3294          (%o3)                           0
3295
3296 -- Function: next_prime (<n>)
3297
3298     Returns the smallest prime bigger than <n>.
3299
3300          (%i1) next_prime(27);
3301          (%o1)                       29
3302
3303 -- Function: partfrac (<expr>, <var>)
3304
3305     Expands the expression <expr> in partial fractions with respect to
3306     the main variable <var>.  'partfrac' does a complete partial
3307     fraction decomposition.  The algorithm employed is based on the
3308     fact that the denominators of the partial fraction expansion (the
3309     factors of the original denominator) are relatively prime.  The
3310     numerators can be written as linear combinations of denominators,
3311     and the expansion falls out.
3312
3313     'partfrac' ignores the value 'true' of the option variable
3314     'keepfloat'.
3315
3316          (%i1) 1/(1+x)^2 - 2/(1+x) + 2/(2+x);
3317                                2       2        1
3318          (%o1)               ----- - ----- + --------
3319                              x + 2   x + 1          2
3320                                              (x + 1)
3321          (%i2) ratsimp (%);
3322                                           x
3323          (%o2)                 - -------------------
3324                                   3      2
3325                                  x  + 4 x  + 5 x + 2
3326          (%i3) partfrac (%, x);
3327                                2       2        1
3328          (%o3)               ----- - ----- + --------
3329                              x + 2   x + 1          2
3330                                              (x + 1)
3331
3332 -- Function: power_mod (<a>, <n>, <m>)
3333
3334     Uses a modular algorithm to compute 'a^n mod m' where <a> and <n>
3335     are integers and <m> is a positive integer.  If <n> is negative,
3336     'inv_mod' is used to find the modular inverse.
3337
3338          (%i1) power_mod(3, 15, 5);
3339          (%o1)                          2
3340          (%i2) mod(3^15,5);
3341          (%o2)                          2
3342          (%i3) power_mod(2, -1, 5);
3343          (%o3)                          3
3344          (%i4) inv_mod(2,5);
3345          (%o4)                          3
3346
3347 -- Function: primep (<n>)
3348
3349     Primality test.  If 'primep (<n>)' returns 'false', <n> is a
3350     composite number and if it returns 'true', <n> is a prime number
3351     with very high probability.
3352
3353     For <n> less than 341550071728321 a deterministic version of
3354     Miller-Rabin's test is used.  If 'primep (<n>)' returns 'true',
3355     then <n> is a prime number.
3356
3357     For <n> bigger than 341550071728321 'primep' uses
3358     'primep_number_of_tests' Miller-Rabin's pseudo-primality tests and
3359     one Lucas pseudo-primality test.  The probability that a non-prime
3360     <n> will pass one Miller-Rabin test is less than 1/4.  Using the
3361     default value 25 for 'primep_number_of_tests', the probability of
3362     <n> being composite is much smaller that 10^-15.
3363
3364 -- Option variable: primep_number_of_tests
3365     Default value: 25
3366
3367     Number of Miller-Rabin's tests used in 'primep'.
3368
3369 -- Function: primes (<start>, <end>)
3370
3371     Returns the list of all primes from <start> to <end>.
3372
3373          (%i1) primes(3, 7);
3374          (%o1)                     [3, 5, 7]
3375
3376 -- Function: prev_prime (<n>)
3377
3378     Returns the greatest prime smaller than <n>.
3379
3380          (%i1) prev_prime(27);
3381          (%o1)                       23
3382
3383 -- Function: qunit (<n>)
3384
3385     Returns the principal unit of the real quadratic number field 'sqrt
3386     (<n>)' where <n> is an integer, i.e., the element whose norm is
3387     unity.  This amounts to solving Pell's equation 'a^2 - <n> b^2 =
3388     1'.
3389
3390          (%i1) qunit (17);
3391          (%o1)                     sqrt(17) + 4
3392          (%i2) expand (% * (sqrt(17) - 4));
3393          (%o2)                           1
3394
3395 -- Function: totient (<n>)
3396
3397     Returns the number of integers less than or equal to <n> which are
3398     relatively prime to <n>.
3399
3400 -- Option variable: zerobern
3401     Default value: 'true'
3402
3403     When 'zerobern' is 'false', 'bern' excludes the Bernoulli numbers
3404     and 'euler' excludes the Euler numbers which are equal to zero.
3405     See 'bern' and 'euler'.
3406
3407 -- Function: zeta (<n>)
3408
3409     Returns the Riemann zeta function.  If <n> is a negative integer,
3410     0, or a positive even integer, the Riemann zeta function simplifies
3411     to an exact value.  For a positive even integer the option variable
3412     'zeta%pi' has to be 'true' in addition (See 'zeta%pi').  For a
3413     floating point or bigfloat number the Riemann zeta function is
3414     evaluated numerically.  Maxima returns a noun form 'zeta (<n>)' for
3415     all other arguments, including rational noninteger, and complex
3416     arguments, or for even integers, if 'zeta%pi' has the value
3417     'false'.
3418
3419     'zeta(1)' is undefined, but Maxima knows the limit 'limit(zeta(x),
3420     x, 1)' from above and below.
3421
3422     The Riemann zeta function distributes over lists, matrices, and
3423     equations.
3424
3425     See also 'bfzeta' and 'zeta%pi'.
3426
3427     Examples:
3428
3429          (%i1) zeta([-2, -1, 0, 0.5, 2, 3, 1+%i]);
3430                                                       2
3431                      1     1                       %pi
3432          (%o1) [0, - --, - -, - 1.460354508809586, ----, zeta(3),
3433                      12    2                        6
3434                                                              zeta(%i + 1)]
3435          (%i2) limit(zeta(x),x,1,plus);
3436          (%o2)                          inf
3437          (%i3) limit(zeta(x),x,1,minus);
3438          (%o3)                         minf
3439
3440 -- Option variable: zeta%pi
3441     Default value: 'true'
3442
3443     When 'zeta%pi' is 'true', 'zeta' returns an expression proportional
3444     to '%pi^n' for even integer 'n'.  Otherwise, 'zeta' returns a noun
3445     form 'zeta (n)' for even integer 'n'.
3446
3447     Examples:
3448
3449          (%i1) zeta%pi: true$
3450          (%i2) zeta (4);
3451                                           4
3452                                        %pi
3453          (%o2)                         ----
3454                                         90
3455          (%i3) zeta%pi: false$
3456          (%i4) zeta (4);
3457          (%o4)                        zeta(4)
3458
3459 -- Function: zn_add_table (<n>)
3460
3461     Shows an addition table of all elements in (Z/<n>Z).
3462
3463     See also 'zn_mult_table', 'zn_power_table'.
3464
3465 -- Function: zn_characteristic_factors (<n>)
3466
3467     Returns a list containing the characteristic factors of the totient
3468     of <n>.
3469
3470     Using the characteristic factors a multiplication group modulo <n>
3471     can be expressed as a group direct product of cyclic subgroups.
3472
3473     In case the group itself is cyclic the list only contains the
3474     totient and using 'zn_primroot' a generator can be computed.  If
3475     the totient splits into more than one characteristic factors
3476     'zn_factor_generators' finds generators of the corresponding
3477     subgroups.
3478
3479     Each of the 'r' factors in the list divides the right following
3480     factors.  For the last factor 'f_r' therefore holds 'a^f_r = 1 (mod
3481     n)' for all 'a' coprime to <n>.  This factor is also known as
3482     Carmichael function or Carmichael lambda.
3483
3484     If 'n > 2', then 'totient(n)/2^r' is the number of quadratic
3485     residues, and each of these has '2^r' square roots.
3486
3487     See also 'totient', 'zn_primroot', 'zn_factor_generators'.
3488
3489     Examples:
3490
3491     The multiplication group modulo '14' is cyclic and its '6' elements
3492     can be generated by a primitive root.
3493
3494          (%i1) [zn_characteristic_factors(14), phi: totient(14)];
3495          (%o1)                              [[6], 6]
3496          (%i2) [zn_factor_generators(14), g: zn_primroot(14)];
3497          (%o2)                              [[3], 3]
3498          (%i3) M14: makelist(power_mod(g,i,14), i,0,phi-1);
3499          (%o3)                         [1, 3, 9, 13, 11, 5]
3500
3501     The multiplication group modulo '15' is not cyclic and its '8'
3502     elements can be generated by two factor generators.
3503
3504          (%i1) [[f1,f2]: zn_characteristic_factors(15), totient(15)];
3505          (%o1)                             [[2, 4], 8]
3506          (%i2) [[g1,g2]: zn_factor_generators(15), zn_primroot(15)];
3507          (%o2)                           [[11, 7], false]
3508          (%i3) UG1: makelist(power_mod(g1,i,15), i,0,f1-1);
3509          (%o3)                               [1, 11]
3510          (%i4) UG2: makelist(power_mod(g2,i,15), i,0,f2-1);
3511          (%o4)                            [1, 7, 4, 13]
3512          (%i5) M15: create_list(mod(i*j,15), i,UG1, j,UG2);
3513          (%o5)                      [1, 7, 4, 13, 11, 2, 14, 8]
3514
3515     For the last characteristic factor '4' it holds that 'a^4 = 1 (mod
3516     15)' for all 'a' in 'M15'.
3517
3518     'M15' has two characteristic factors and therefore '8/2^2'
3519     quadratic residues, and each of these has '2^2' square roots.
3520
3521          (%i6) zn_power_table(15);
3522                                         [ 1   1  1   1 ]
3523                                         [              ]
3524                                         [ 2   4  8   1 ]
3525                                         [              ]
3526                                         [ 4   1  4   1 ]
3527                                         [              ]
3528                                         [ 7   4  13  1 ]
3529          (%o6)                          [              ]
3530                                         [ 8   4  2   1 ]
3531                                         [              ]
3532                                         [ 11  1  11  1 ]
3533                                         [              ]
3534                                         [ 13  4  7   1 ]
3535                                         [              ]
3536                                         [ 14  1  14  1 ]
3537          (%i7) map(lambda([i], zn_nth_root(i,2,15)), [1,4]);
3538          (%o7)                   [[1, 4, 11, 14], [2, 7, 8, 13]]
3539
3540 -- Function: zn_carmichael_lambda (<n>)
3541
3542     Returns '1' if <n> is '1' and otherwise the greatest characteristic
3543     factor of the totient of <n>.
3544
3545     For remarks and examples see 'zn_characteristic_factors'.
3546
3547 -- Function: zn_determinant (<matrix>, <p>)
3548
3549     Uses the technique of LU-decomposition to compute the determinant
3550     of <matrix> over (Z/<p>Z). <p> must be a prime.
3551
3552     However if the determinant is equal to zero the LU-decomposition
3553     might fail.  In that case 'zn_determinant' computes the determinant
3554     non-modular and reduces thereafter.
3555
3556     See also 'zn_invert_by_lu'.
3557
3558     Examples:
3559
3560          (%i1) m : matrix([1,3],[2,4]);
3561                                          [ 1  3 ]
3562          (%o1)                           [      ]
3563                                          [ 2  4 ]
3564          (%i2) zn_determinant(m, 5);
3565          (%o2)                               3
3566          (%i3) m : matrix([2,4,1],[3,1,4],[4,3,2]);
3567                                         [ 2  4  1 ]
3568                                         [         ]
3569          (%o3)                          [ 3  1  4 ]
3570                                         [         ]
3571                                         [ 4  3  2 ]
3572          (%i4) zn_determinant(m, 5);
3573          (%o4)                               0
3574
3575 -- Function: zn_factor_generators (<n>)
3576
3577     Returns a list containing factor generators corresponding to the
3578     characteristic factors of the totient of <n>.
3579
3580     For remarks and examples see 'zn_characteristic_factors'.
3581
3582 -- Function: zn_invert_by_lu (<matrix>, <p>)
3583
3584     Uses the technique of LU-decomposition to compute the modular
3585     inverse of <matrix> over (Z/<p>Z). <p> must be a prime and <matrix>
3586     invertible.  'zn_invert_by_lu' returns 'false' if <matrix> is not
3587     invertible.
3588
3589     See also 'zn_determinant'.
3590
3591     Example:
3592
3593          (%i1) m : matrix([1,3],[2,4]);
3594                                          [ 1  3 ]
3595          (%o1)                           [      ]
3596                                          [ 2  4 ]
3597          (%i2) zn_determinant(m, 5);
3598          (%o2)                               3
3599          (%i3) mi : zn_invert_by_lu(m, 5);
3600                                          [ 3  4 ]
3601          (%o3)                           [      ]
3602                                          [ 1  2 ]
3603          (%i4) matrixmap(lambda([a], mod(a, 5)), m . mi);
3604                                          [ 1  0 ]
3605          (%o4)                           [      ]
3606                                          [ 0  1 ]
3607
3608 -- Function: zn_log
3609          zn_log (<a>, <g>, <n>)
3610          zn_log (<a>, <g>, <n>, [[<p1>, <e1>], ..., [<pk>, <ek>]])
3611
3612     Computes the discrete logarithm.  Let (Z/<n>Z)* be a cyclic group,
3613     <g> a primitive root modulo <n> and let <a> be a member of this
3614     group.  'zn_log (a, g, n)' then solves the congruence 'g^x = a mod
3615     n'.
3616
3617     The applied algorithm needs a prime factorization of 'totient(n)'.
3618     This factorization might be time consuming as well and in some
3619     cases it can be useful to factor first and then to pass the list of
3620     factors to 'zn_log' as the fourth argument.  The list must be of
3621     the same form as the list returned by 'ifactors(totient(n))' using
3622     the default option 'factors_only : false'.
3623
3624     The algorithm uses a Pohlig-Hellman-reduction and Pollard's
3625     Rho-method for discrete logarithms.  The run time of 'zn_log'
3626     primarily depends on the bitlength of the totient's greatest prime
3627     factor.
3628
3629     See also 'zn_primroot', 'zn_order', 'ifactors', 'totient'.
3630
3631     Examples:
3632
3633     'zn_log (a, g, n)' solves the congruence 'g^x = a mod n'.
3634
3635          (%i1) n : 22$
3636          (%i2) g : zn_primroot(n);
3637          (%o2)                               7
3638          (%i3) ord_7 : zn_order(7, n);
3639          (%o3)                              10
3640          (%i4) powers_7 : makelist(power_mod(g, x, n), x, 0, ord_7 - 1);
3641          (%o4)              [1, 7, 5, 13, 3, 21, 15, 17, 9, 19]
3642          (%i5) zn_log(21, g, n);
3643          (%o5)                               5
3644          (%i6) map(lambda([x], zn_log(x, g, n)), powers_7);
3645          (%o6)                [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
3646
3647     The optional fourth argument must be of the same form as the list
3648     returned by 'ifactors(totient(n))'.  The run time primarily depends
3649     on the bitlength of the totient's greatest prime factor.
3650
3651          (%i1) (p : 2^127-1, primep(p));
3652          (%o1)                             true
3653          (%i2) ifs : ifactors(p - 1)$
3654          (%i3) g : zn_primroot(p, ifs);
3655          (%o3)                              43
3656          (%i4) a : power_mod(g, 1234567890, p)$
3657          (%i5) zn_log(a, g, p, ifs);
3658          (%o5)                          1234567890
3659          (%i6) time(%o5);
3660          (%o6)                            [1.204]
3661          (%i7) f_max : last(ifs);
3662          (%o7)                       [77158673929, 1]
3663          (%i8) slength( printf(false, "~b", f_max[1]) );
3664          (%o8)                              37
3665
3666 -- Function: zn_mult_table
3667          zn_mult_table (<n>)
3668          zn_mult_table (<n>, <gcd>)
3669
3670     Without the optional argument <gcd> 'zn_mult_table(n)' shows a
3671     multiplication table of all elements in (Z/<n>Z)* which are all
3672     elements coprime to <n>.
3673
3674     The optional second argument <gcd> allows to select a specific
3675     subset of (Z/<n>Z). If <gcd> is an integer, a multiplication table
3676     of all residues 'x' with 'gcd(x,n) = '<gcd> are returned.
3677     Additionally row and column headings are added for better
3678     readability.  If necessary, these can be easily removed by
3679     'submatrix(1, table, 1)'.
3680
3681     If <gcd> is set to 'all', the table is printed for all non-zero
3682     elements in (Z/<n>Z).
3683
3684     The second example shows an alternative way to create a
3685     multiplication table for subgroups.
3686
3687     See also 'zn_add_table', 'zn_power_table'.
3688
3689     Examples:
3690
3691     The default table shows all elements in (Z/<n>Z)* and allows to
3692     demonstrate and study basic properties of modular multiplication
3693     groups.  E.g.  the principal diagonal contains all quadratic
3694     residues, each row and column contains every element, the tables
3695     are symmetric, etc..
3696
3697     If <gcd> is set to 'all', the table is printed for all non-zero
3698     elements in (Z/<n>Z).
3699
3700          (%i1) zn_mult_table(8);
3701                                          [ 1  3  5  7 ]
3702                                          [            ]
3703                                          [ 3  1  7  5 ]
3704          (%o1)                           [            ]
3705                                          [ 5  7  1  3 ]
3706                                          [            ]
3707                                          [ 7  5  3  1 ]
3708          (%i2) zn_mult_table(8, all);
3709                                      [ 1  2  3  4  5  6  7 ]
3710                                      [                     ]
3711                                      [ 2  4  6  0  2  4  6 ]
3712                                      [                     ]
3713                                      [ 3  6  1  4  7  2  5 ]
3714                                      [                     ]
3715          (%o2)                       [ 4  0  4  0  4  0  4 ]
3716                                      [                     ]
3717                                      [ 5  2  7  4  1  6  3 ]
3718                                      [                     ]
3719                                      [ 6  4  2  0  6  4  2 ]
3720                                      [                     ]
3721                                      [ 7  6  5  4  3  2  1 ]
3722
3723     If <gcd> is an integer, row and column headings are added for
3724     better readability.
3725
3726     If the subset chosen by <gcd> is a group there is another way to
3727     create a multiplication table.  An isomorphic mapping from a group
3728     with '1' as identity builds a table which is easy to read.  The
3729     mapping is accomplished via CRT.
3730
3731     In the second version of 'T36_4' the identity, here '28', is placed
3732     in the top left corner, just like in table 'T9'.
3733
3734          (%i1) T36_4: zn_mult_table(36,4);
3735                                  [ *   4   8   16  20  28  32 ]
3736                                  [                            ]
3737                                  [ 4   16  32  28  8   4   20 ]
3738                                  [                            ]
3739                                  [ 8   32  28  20  16  8   4  ]
3740                                  [                            ]
3741          (%o1)                   [ 16  28  20  4   32  16  8  ]
3742                                  [                            ]
3743                                  [ 20  8   16  32  4   20  28 ]
3744                                  [                            ]
3745                                  [ 28  4   8   16  20  28  32 ]
3746                                  [                            ]
3747                                  [ 32  20  4   8   28  32  16 ]
3748          (%i2) T9: zn_mult_table(36/4);
3749                                       [ 1  2  4  5  7  8 ]
3750                                       [                  ]
3751                                       [ 2  4  8  1  5  7 ]
3752                                       [                  ]
3753                                       [ 4  8  7  2  1  5 ]
3754          (%o2)                        [                  ]
3755                                       [ 5  1  2  7  8  4 ]
3756                                       [                  ]
3757                                       [ 7  5  1  8  4  2 ]
3758                                       [                  ]
3759                                       [ 8  7  5  4  2  1 ]
3760          (%i3) T36_4: matrixmap(lambda([x], chinese([0,x],[4,9])), T9);
3761                                    [ 28  20  4   32  16  8  ]
3762                                    [                        ]
3763                                    [ 20  4   8   28  32  16 ]
3764                                    [                        ]
3765                                    [ 4   8   16  20  28  32 ]
3766          (%o3)                     [                        ]
3767                                    [ 32  28  20  16  8   4  ]
3768                                    [                        ]
3769                                    [ 16  32  28  8   4   20 ]
3770                                    [                        ]
3771                                    [ 8   16  32  4   20  28 ]
3772
3773 -- Function: zn_nth_root
3774          zn_nth_root (<x>, <n>, <m>)
3775          zn_nth_root (<x>, <n>, <m>, [[<p1>, <e1>], ..., [<pk>, <ek>]])
3776
3777     Returns a list with all <n>-th roots of <x> from the multiplication
3778     subgroup of (Z/<m>Z) which contains <x>, or 'false', if <x> is no
3779     <n>-th power modulo <m> or not contained in any multiplication
3780     subgroup of (Z/<m>Z).
3781
3782     <x> is an element of a multiplication subgroup modulo <m>, if the
3783     greatest common divisor 'g = gcd(x,m)' is coprime to 'm/g'.
3784
3785     'zn_nth_root' is based on an algorithm by Adleman, Manders and
3786     Miller and on theorems about modulo multiplication groups by Daniel
3787     Shanks.
3788
3789     The algorithm needs a prime factorization of the modulus <m>.  So
3790     in case the factorization of <m> is known, the list of factors can
3791     be passed as the fourth argument.  This optional argument must be
3792     of the same form as the list returned by 'ifactors(m)' using the
3793     default option 'factors_only: false'.
3794
3795     Examples:
3796
3797     A power table of the multiplication group modulo '14' followed by a
3798     list of lists containing all <n>-th roots of '1' with <n> from '1'
3799     to '6'.
3800
3801          (%i1) zn_power_table(14);
3802                                   [ 1   1   1   1   1   1 ]
3803                                   [                       ]
3804                                   [ 3   9   13  11  5   1 ]
3805                                   [                       ]
3806                                   [ 5   11  13  9   3   1 ]
3807          (%o1)                    [                       ]
3808                                   [ 9   11  1   9   11  1 ]
3809                                   [                       ]
3810                                   [ 11  9   1   11  9   1 ]
3811                                   [                       ]
3812                                   [ 13  1   13  1   13  1 ]
3813          (%i2) makelist(zn_nth_root(1,n,14), n,1,6);
3814          (%o2)  [[1], [1, 13], [1, 9, 11], [1, 13], [1], [1, 3, 5, 9, 11, 13]]
3815
3816     In the following example <x> is not coprime to <m>, but is a member
3817     of a multiplication subgroup of (Z/<m>Z) and any <n>-th root is a
3818     member of the same subgroup.
3819
3820     The residue class '3' is no member of any multiplication subgroup
3821     of (Z/63Z) and is therefore not returned as a third root of '27'.
3822
3823     Here 'zn_power_table' shows all residues 'x' in (Z/63Z) with
3824     'gcd(x,63) = 9'.  This subgroup is isomorphic to (Z/7Z)* and its
3825     identity '36' is computed via CRT.
3826
3827          (%i1) m: 7*9$
3828
3829          (%i2) zn_power_table(m,9);
3830                                   [ 9   18  36  9   18  36 ]
3831                                   [                        ]
3832                                   [ 18  9   36  18  9   36 ]
3833                                   [                        ]
3834                                   [ 27  36  27  36  27  36 ]
3835          (%o2)                    [                        ]
3836                                   [ 36  36  36  36  36  36 ]
3837                                   [                        ]
3838                                   [ 45  9   27  18  54  36 ]
3839                                   [                        ]
3840                                   [ 54  18  27  9   45  36 ]
3841          (%i3) zn_nth_root(27,3,m);
3842          (%o3)                           [27, 45, 54]
3843          (%i4) id7:1$  id63_9: chinese([id7,0],[7,9]);
3844          (%o5)                                36
3845
3846     In the following RSA-like example, where the modulus 'N' is
3847     squarefree, i.e.  it splits into exclusively first power factors,
3848     every 'x' from '0' to 'N-1' is contained in a multiplication
3849     subgroup.
3850
3851     The process of decryption needs the 'e'-th root.  'e' is coprime to
3852     'totient(N)' and therefore the 'e'-th root is unique.  In this case
3853     'zn_nth_root' effectively performs CRT-RSA. (Please note that
3854     'flatten' removes braces but no solutions.)
3855
3856          (%i1) [p,q,e]: [5,7,17]$  N: p*q$
3857
3858          (%i3) xs: makelist(x,x,0,N-1)$
3859
3860          (%i4) ys: map(lambda([x],power_mod(x,e,N)),xs)$
3861
3862          (%i5) zs: flatten(map(lambda([y], zn_nth_root(y,e,N)), ys))$
3863
3864          (%i6) is(zs = xs);
3865          (%o6)                             true
3866
3867     In the following example the factorization of the modulus is known
3868     and passed as the fourth argument.
3869
3870          (%i1) p: 2^107-1$  q: 2^127-1$  N: p*q$
3871
3872          (%i4) ibase: obase: 16$
3873
3874          (%i5) msg: 11223344556677889900aabbccddeeff$
3875
3876          (%i6) enc: power_mod(msg, 10001, N);
3877          (%o6)    1a8db7892ae588bdc2be25dd5107a425001fe9c82161abc673241c8b383
3878          (%i7) zn_nth_root(enc, 10001, N, [[p,1],[q,1]]);
3879          (%o7)               [11223344556677889900aabbccddeeff]
3880
3881 -- Function: zn_order
3882          zn_order (<x>, <n>)
3883          zn_order (<x>, <n>, [[<p1>, <e1>], ..., [<pk>, <ek>]])
3884
3885     Returns the order of <x> if it is a unit of the finite group
3886     (Z/<n>Z)* or returns 'false'.  <x> is a unit modulo <n> if it is
3887     coprime to <n>.
3888
3889     The applied algorithm needs a prime factorization of 'totient(n)'.
3890     This factorization might be time consuming in some cases and it can
3891     be useful to factor first and then to pass the list of factors to
3892     'zn_log' as the third argument.  The list must be of the same form
3893     as the list returned by 'ifactors(totient(n))' using the default
3894     option 'factors_only : false'.
3895
3896     See also 'zn_primroot', 'ifactors', 'totient'.
3897
3898     Examples:
3899
3900     'zn_order' computes the order of the unit <x> in (Z/<n>Z)*.
3901
3902          (%i1) n : 22$
3903          (%i2) g : zn_primroot(n);
3904          (%o2)                               7
3905          (%i3) units_22 : sublist(makelist(i,i,1,21), lambda([x], gcd(x, n) = 1));
3906          (%o3)              [1, 3, 5, 7, 9, 13, 15, 17, 19, 21]
3907          (%i4) (ord_7 : zn_order(7, n)) = totient(n);
3908          (%o4)                            10 = 10
3909          (%i5) powers_7 : makelist(power_mod(g,i,n), i,0,ord_7 - 1);
3910          (%o5)              [1, 7, 5, 13, 3, 21, 15, 17, 9, 19]
3911          (%i6) map(lambda([x], zn_order(x, n)), powers_7);
3912          (%o6)              [1, 10, 5, 10, 5, 2, 5, 10, 5, 10]
3913          (%i7) map(lambda([x], ord_7/gcd(x, ord_7)), makelist(i, i,0,ord_7 - 1));
3914          (%o7)              [1, 10, 5, 10, 5, 2, 5, 10, 5, 10]
3915          (%i8) totient(totient(n));
3916          (%o8)                               4
3917
3918     The optional third argument must be of the same form as the list
3919     returned by 'ifactors(totient(n))'.
3920
3921          (%i1) (p : 2^142 + 217, primep(p));
3922          (%o1)                             true
3923          (%i2) ifs : ifactors( totient(p) )$
3924          (%i3) g : zn_primroot(p, ifs);
3925          (%o3)                               3
3926          (%i4) is( (ord_3 : zn_order(g, p, ifs)) = totient(p) );
3927          (%o4)                             true
3928          (%i5) map(lambda([x], ord_3/zn_order(x, p, ifs)), makelist(i,i,2,15));
3929          (%o5)        [22, 1, 44, 10, 5, 2, 22, 2, 8, 2, 1, 1, 20, 1]
3930
3931 -- Function: zn_power_table
3932          zn_power_table (<n>)
3933          zn_power_table (<n>, <gcd>)
3934          zn_power_table (<n>, <gcd>, <max_exp>)
3935
3936     Without any optional argument 'zn_power_table(n)' shows a power
3937     table of all elements in (Z/<n>Z)* which are all residue classes
3938     coprime to <n>.  The exponent loops from '1' to the greatest
3939     characteristic factor of 'totient(n)' (also known as Carmichael
3940     function or Carmichael lambda) and the table ends with a column of
3941     ones on the right side.
3942
3943     The optional second argument <gcd> allows to select powers of a
3944     specific subset of (Z/<n>Z). If <gcd> is an integer, powers of all
3945     residue classes 'x' with 'gcd(x,n) = '<gcd> are returned, i.e.  the
3946     default value for <gcd> is '1'.  If <gcd> is set to 'all', the
3947     table contains powers of all elements in (Z/<n>Z).
3948
3949     If the optional third argument <max_exp> is given, the exponent
3950     loops from '1' to <max_exp>.
3951
3952     See also 'zn_add_table', 'zn_mult_table'.
3953
3954     Examples:
3955
3956     The default which is <gcd>' = 1' allows to demonstrate and study
3957     basic theorems of e.g.  Fermat and Euler.
3958
3959     The argument <gcd> allows to select subsets of (Z/<n>Z) and to
3960     study multiplication subgroups and isomorphisms.  E.g.  the groups
3961     'G10' and 'G10_2' are under multiplication both isomorphic to 'G5'.
3962     '1' is the identity in 'G5'.  So are '1' resp.  '6' the identities
3963     in 'G10' resp.  'G10_2'.  There are corresponding mappings for
3964     primitive roots, n-th roots, etc..
3965
3966          (%i1) zn_power_table(10);
3967                                        [ 1  1  1  1 ]
3968                                        [            ]
3969                                        [ 3  9  7  1 ]
3970          (%o1)                         [            ]
3971                                        [ 7  9  3  1 ]
3972                                        [            ]
3973                                        [ 9  1  9  1 ]
3974          (%i2) zn_power_table(10,2);
3975                                        [ 2  4  8  6 ]
3976                                        [            ]
3977                                        [ 4  6  4  6 ]
3978          (%o2)                         [            ]
3979                                        [ 6  6  6  6 ]
3980                                        [            ]
3981                                        [ 8  4  2  6 ]
3982          (%i3) zn_power_table(10,5);
3983          (%o3)                         [ 5  5  5  5 ]
3984          (%i4) zn_power_table(10,10);
3985          (%o4)                         [ 0  0  0  0 ]
3986          (%i5) G5: [1,2,3,4];
3987          (%o6)                          [1, 2, 3, 4]
3988          (%i6) G10_2: map(lambda([x], chinese([0,x],[2,5])), G5);
3989          (%o6)                          [6, 2, 8, 4]
3990          (%i7) G10: map(lambda([x], power_mod(3, zn_log(x,2,5), 10)), G5);
3991          (%o7)                          [1, 3, 7, 9]
3992
3993     If <gcd> is set to 'all', the table contains powers of all elements
3994     in (Z/<n>Z).
3995
3996     The third argument <max_exp> allows to set the highest exponent.
3997     The following table shows a very small example of RSA.
3998
3999          (%i1) N:2*5$ phi:totient(N)$ e:7$ d:inv_mod(e,phi)$
4000
4001          (%i5) zn_power_table(N, all, e*d);
4002                 [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 ]
4003                 [                                                               ]
4004                 [ 1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 ]
4005                 [                                                               ]
4006                 [ 2  4  8  6  2  4  8  6  2  4  8  6  2  4  8  6  2  4  8  6  2 ]
4007                 [                                                               ]
4008                 [ 3  9  7  1  3  9  7  1  3  9  7  1  3  9  7  1  3  9  7  1  3 ]
4009                 [                                                               ]
4010                 [ 4  6  4  6  4  6  4  6  4  6  4  6  4  6  4  6  4  6  4  6  4 ]
4011          (%o5)  [                                                               ]
4012                 [ 5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5 ]
4013                 [                                                               ]
4014                 [ 6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6 ]
4015                 [                                                               ]
4016                 [ 7  9  3  1  7  9  3  1  7  9  3  1  7  9  3  1  7  9  3  1  7 ]
4017                 [                                                               ]
4018                 [ 8  4  2  6  8  4  2  6  8  4  2  6  8  4  2  6  8  4  2  6  8 ]
4019                 [                                                               ]
4020                 [ 9  1  9  1  9  1  9  1  9  1  9  1  9  1  9  1  9  1  9  1  9 ]
4021
4022 -- Function: zn_primroot
4023          zn_primroot (<n>)
4024          zn_primroot (<n>, [[<p1>, <e1>], ..., [<pk>, <ek>]])
4025
4026     If the multiplicative group (Z/<n>Z)* is cyclic, 'zn_primroot'
4027     computes the smallest primitive root modulo <n>.  (Z/<n>Z)* is
4028     cyclic if <n> is equal to '2', '4', 'p^k' or '2*p^k', where 'p' is
4029     prime and greater than '2' and 'k' is a natural number.
4030     'zn_primroot' performs an according pretest if the option variable
4031     'zn_primroot_pretest' (default: 'false') is set to 'true'.  In any
4032     case the computation is limited by the upper bound
4033     'zn_primroot_limit'.
4034
4035     If (Z/<n>Z)* is not cyclic or if there is no primitive root up to
4036     'zn_primroot_limit', 'zn_primroot' returns 'false'.
4037
4038     The applied algorithm needs a prime factorization of 'totient(n)'.
4039     This factorization might be time consuming in some cases and it can
4040     be useful to factor first and then to pass the list of factors to
4041     'zn_log' as an additional argument.  The list must be of the same
4042     form as the list returned by 'ifactors(totient(n))' using the
4043     default option 'factors_only : false'.
4044
4045     See also 'zn_primroot_p', 'zn_order', 'ifactors', 'totient'.
4046
4047     Examples:
4048
4049     'zn_primroot' computes the smallest primitive root modulo <n> or
4050     returns 'false'.
4051
4052          (%i1) n : 14$
4053          (%i2) g : zn_primroot(n);
4054          (%o2)                               3
4055          (%i3) zn_order(g, n) = totient(n);
4056          (%o3)                             6 = 6
4057          (%i4) n : 15$
4058          (%i5) zn_primroot(n);
4059          (%o5)                             false
4060
4061     The optional second argument must be of the same form as the list
4062     returned by 'ifactors(totient(n))'.
4063
4064          (%i1) (p : 2^142 + 217, primep(p));
4065          (%o1)                             true
4066          (%i2) ifs : ifactors( totient(p) )$
4067          (%i3) g : zn_primroot(p, ifs);
4068          (%o3)                               3
4069          (%i4) [time(%o2), time(%o3)];
4070          (%o4)                    [[15.556972], [0.004]]
4071          (%i5) is(zn_order(g, p, ifs) = p - 1);
4072          (%o5)                             true
4073          (%i6) n : 2^142 + 216$
4074          (%i7) ifs : ifactors(totient(n))$
4075          (%i8) zn_primroot(n, ifs),
4076                zn_primroot_limit : 200, zn_primroot_verbose : true;
4077          `zn_primroot' stopped at zn_primroot_limit = 200
4078          (%o8)                             false
4079
4080 -- Option variable: zn_primroot_limit
4081     Default value: '1000'
4082
4083     If 'zn_primroot' cannot find a primitve root, it stops at this
4084     upper bound.  If the option variable 'zn_primroot_verbose'
4085     (default: 'false') is set to 'true', a message will be printed when
4086     'zn_primroot_limit' is reached.
4087
4088 -- Function: zn_primroot_p
4089          zn_primroot_p (<x>, <n>)
4090          zn_primroot_p (<x>, <n>, [[<p1>, <e1>], ..., [<pk>, <ek>]])
4091
4092     Checks whether <x> is a primitive root in the multiplicative group
4093     (Z/<n>Z)*.
4094
4095     The applied algorithm needs a prime factorization of 'totient(n)'.
4096     This factorization might be time consuming and in case
4097     'zn_primroot_p' will be consecutively applied to a list of
4098     candidates it can be useful to factor first and then to pass the
4099     list of factors to 'zn_log' as a third argument.  The list must be
4100     of the same form as the list returned by 'ifactors(totient(n))'
4101     using the default option 'factors_only : false'.
4102
4103     See also 'zn_primroot', 'zn_order', 'ifactors', 'totient'.
4104
4105     Examples:
4106
4107     'zn_primroot_p' as a predicate function.
4108
4109          (%i1) n : 14$
4110          (%i2) units_14 : sublist(makelist(i,i,1,13), lambda([i], gcd(i, n) = 1));
4111          (%o2)                     [1, 3, 5, 9, 11, 13]
4112          (%i3) zn_primroot_p(13, n);
4113          (%o3)                            false
4114          (%i4) sublist(units_14, lambda([x], zn_primroot_p(x, n)));
4115          (%o4)                            [3, 5]
4116          (%i5) map(lambda([x], zn_order(x, n)), units_14);
4117          (%o5)                      [1, 6, 6, 3, 3, 2]
4118
4119     The optional third argument must be of the same form as the list
4120     returned by 'ifactors(totient(n))'.
4121
4122          (%i1) (p : 2^142 + 217, primep(p));
4123          (%o1)                             true
4124          (%i2) ifs : ifactors( totient(p) )$
4125          (%i3) sublist(makelist(i,i,1,50), lambda([x], zn_primroot_p(x, p, ifs)));
4126          (%o3)      [3, 12, 13, 15, 21, 24, 26, 27, 29, 33, 38, 42, 48]
4127          (%i4) [time(%o2), time(%o3)];
4128          (%o4)                   [[7.748484], [0.036002]]
4129
4130 -- Option variable: zn_primroot_pretest
4131     Default value: 'false'
4132
4133     The multiplicative group (Z/<n>Z)* is cyclic if <n> is equal to
4134     '2', '4', 'p^k' or '2*p^k', where 'p' is prime and greater than '2'
4135     and 'k' is a natural number.
4136
4137     'zn_primroot_pretest' controls whether 'zn_primroot' will check if
4138     one of these cases occur before it computes the smallest primitive
4139     root.  Only if 'zn_primroot_pretest' is set to 'true' this pretest
4140     will be performed.
4141
4142 -- Option variable: zn_primroot_verbose
4143     Default value: 'false'
4144
4145     Controls whether 'zn_primroot' prints a message when reaching
4146     'zn_primroot_limit'.
4147
4148
4149File: maxima.info,  Node: Symmetries,  Next: Groups,  Prev: Number Theory,  Up: Top
4150
415130 Symmetries
4152*************
4153
4154* Menu:
4155
4156* Introduction to Symmetries::
4157* Functions and Variables for Symmetries::
4158
4159
4160File: maxima.info,  Node: Introduction to Symmetries,  Next: Functions and Variables for Symmetries,  Prev: Symmetries,  Up: Symmetries
4161
416230.1 Introduction to Symmetries
4163===============================
4164
4165'sym' is a package for working with symmetric groups of polynomials.
4166
4167   It was written for Macsyma-Symbolics by Annick Valibouze
4168(<http://www-calfor.lip6.fr/~avb/>).  The algorithms are described in
4169the following papers:
4170
4171  1. Fonctions syme'triques et changements de bases.  Annick Valibouze.
4172     EUROCAL'87 (Leipzig, 1987), 323-332, Lecture Notes in Comput.  Sci
4173     378.  Springer, Berlin, 1989.
4174     <http://www.stix.polytechnique.fr/publications/1984-1994.html>
4175
4176  2. Re'solvantes et fonctions syme'triques.  Annick Valibouze.
4177     Proceedings of the ACM-SIGSAM 1989 International Symposium on
4178     Symbolic and Algebraic Computation, ISSAC'89 (Portland, Oregon).
4179     ACM Press, 390-399, 1989.
4180     <http://www-calfor.lip6.fr/~avb/DonneesTelechargeables/MesArticles/issac89ACMValibouze.pdf>
4181
4182  3. Symbolic computation with symmetric polynomials, an extension to
4183     Macsyma.  Annick Valibouze.  Computers and Mathematics (MIT, USA,
4184     June 13-17, 1989), Springer-Verlag, New York Berlin, 308-320, 1989.
4185     <http://www.stix.polytechnique.fr/publications/1984-1994.html>
4186
4187  4. The'orie de Galois Constructive.  Annick Valibouze.  Me'moire
4188     d'habilitation a` diriger les recherches (HDR), Universite' P. et
4189     M. Curie (Paris VI), 1994.
4190
4191
4192File: maxima.info,  Node: Functions and Variables for Symmetries,  Prev: Introduction to Symmetries,  Up: Symmetries
4193
419430.2 Functions and Variables for Symmetries
4195===========================================
4196
419730.2.1 Changing bases
4198---------------------
4199
4200 -- Function: comp2pui (<n>, <L>)
4201     implements passing from the complete symmetric functions given in
4202     the list <L> to the elementary symmetric functions from 0 to <n>.
4203     If the list <L> contains fewer than <n+1> elements, it will be
4204     completed with formal values of the type <h1>, <h2>, etc.  If the
4205     first element of the list <L> exists, it specifies the size of the
4206     alphabet, otherwise the size is set to <n>.
4207
4208          (%i1) comp2pui (3, [4, g]);
4209                                  2                    2
4210          (%o1)    [4, g, 2 h2 - g , 3 h3 - g h2 + g (g  - 2 h2)]
4211
4212 -- Function: ele2pui (<m>, <L>)
4213     goes from the elementary symmetric functions to the complete
4214     functions.  Similar to 'comp2ele' and 'comp2pui'.
4215
4216     Other functions for changing bases: 'comp2ele'.
4217
4218 -- Function: ele2comp (<m>, <L>)
4219     Goes from the elementary symmetric functions to the compete
4220     functions.  Similar to 'comp2ele' and 'comp2pui'.
4221
4222     Other functions for changing bases: 'comp2ele'.
4223
4224 -- Function: elem (<ele>, <sym>, <lvar>)
4225     decomposes the symmetric polynomial <sym>, in the variables
4226     contained in the list <lvar>, in terms of the elementary symmetric
4227     functions given in the list <ele>.  If the first element of <ele>
4228     is given, it will be the size of the alphabet, otherwise the size
4229     will be the degree of the polynomial <sym>.  If values are missing
4230     in the list <ele>, formal values of the type <e1>, <e2>, etc.  will
4231     be added.  The polynomial <sym> may be given in three different
4232     forms: contracted ('elem' should then be 1, its default value),
4233     partitioned ('elem' should be 3), or extended (i.e.  the entire
4234     polynomial, and 'elem' should then be 2).  The function 'pui' is
4235     used in the same way.
4236
4237     On an alphabet of size 3 with <e1>, the first elementary symmetric
4238     function, with value 7, the symmetric polynomial in 3 variables
4239     whose contracted form (which here depends on only two of its
4240     variables) is <x^4-2*x*y> decomposes as follows in elementary
4241     symmetric functions:
4242
4243          (%i1) elem ([3, 7], x^4 - 2*x*y, [x, y]);
4244          (%o1) 7 (e3 - 7 e2 + 7 (49 - e2)) + 21 e3
4245
4246                                                   + (- 2 (49 - e2) - 2) e2
4247          (%i2) ratsimp (%);
4248                                        2
4249          (%o2)             28 e3 + 2 e2  - 198 e2 + 2401
4250
4251     Other functions for changing bases: 'comp2ele'.
4252
4253 -- Function: mon2schur (<L>)
4254     The list <L> represents the Schur function S_L: we have L = [i_1,
4255     i_2, ..., i_q], with i_1 <= i_2 <= ... <= i_q.  The Schur function
4256     S_[i_1, i_2, ..., i_q] is the minor of the infinite matrix h_[i-j],
4257     i <= 1, j <= 1, consisting of the q first rows and the columns 1 +
4258     i_1, 2 + i_2, ..., q + i_q.
4259
4260     This Schur function can be written in terms of monomials by using
4261     'treinat' and 'kostka'.  The form returned is a symmetric
4262     polynomial in a contracted representation in the variables
4263     x_1,x_2,...
4264
4265          (%i1) mon2schur ([1, 1, 1]);
4266          (%o1)                       x1 x2 x3
4267          (%i2) mon2schur ([3]);
4268                                            2        3
4269          (%o2)                x1 x2 x3 + x1  x2 + x1
4270          (%i3) mon2schur ([1, 2]);
4271                                                2
4272          (%o3)                  2 x1 x2 x3 + x1  x2
4273
4274     which means that for 3 variables this gives:
4275
4276             2 x1 x2 x3 + x1^2 x2 + x2^2 x1 + x1^2 x3 + x3^2 x1
4277              + x2^2 x3 + x3^2 x2
4278     Other functions for changing bases: 'comp2ele'.
4279
4280 -- Function: multi_elem (<l_elem>, <multi_pc>, <l_var>)
4281     decomposes a multi-symmetric polynomial in the multi-contracted
4282     form <multi_pc> in the groups of variables contained in the list of
4283     lists <l_var> in terms of the elementary symmetric functions
4284     contained in <l_elem>.
4285
4286          (%i1) multi_elem ([[2, e1, e2], [2, f1, f2]], a*x + a^2 + x^3,
4287                [[x, y], [a, b]]);
4288                                                            3
4289          (%o1)         - 2 f2 + f1 (f1 + e1) - 3 e1 e2 + e1
4290          (%i2) ratsimp (%);
4291                                   2                       3
4292          (%o2)         - 2 f2 + f1  + e1 f1 - 3 e1 e2 + e1
4293
4294     Other functions for changing bases: 'comp2ele'.
4295
4296 -- Function: multi_pui
4297     is to the function 'pui' what the function 'multi_elem' is to the
4298     function 'elem'.
4299
4300          (%i1) multi_pui ([[2, p1, p2], [2, t1, t2]], a*x + a^2 + x^3,
4301                [[x, y], [a, b]]);
4302                                                      3
4303                                          3 p1 p2   p1
4304          (%o1)              t2 + p1 t1 + ------- - ---
4305                                             2       2
4306
4307 -- Function: pui (<L>, <sym>, <lvar>)
4308     decomposes the symmetric polynomial <sym>, in the variables in the
4309     list <lvar>, in terms of the power functions in the list <L>.  If
4310     the first element of <L> is given, it will be the size of the
4311     alphabet, otherwise the size will be the degree of the polynomial
4312     <sym>.  If values are missing in the list <L>, formal values of the
4313     type <p1>, <p2> , etc.  will be added.  The polynomial <sym> may be
4314     given in three different forms: contracted ('elem' should then be
4315     1, its default value), partitioned ('elem' should be 3), or
4316     extended (i.e.  the entire polynomial, and 'elem' should then be
4317     2).  The function 'pui' is used in the same way.
4318
4319          (%i1) pui;
4320          (%o1)                           1
4321          (%i2) pui ([3, a, b], u*x*y*z, [x, y, z]);
4322                                 2
4323                             a (a  - b) u   (a b - p3) u
4324          (%o2)              ------------ - ------------
4325                                  6              3
4326          (%i3) ratsimp (%);
4327                                                 3
4328                                (2 p3 - 3 a b + a ) u
4329          (%o3)                 ---------------------
4330                                          6
4331     Other functions for changing bases: 'comp2ele'.
4332
4333 -- Function: pui2comp (<n>, <lpui>)
4334     renders the list of the first <n> complete functions (with the
4335     length first) in terms of the power functions given in the list
4336     <lpui>.  If the list <lpui> is empty, the cardinal is <n>,
4337     otherwise it is its first element (as in 'comp2ele' and
4338     'comp2pui').
4339
4340          (%i1) pui2comp (2, []);
4341                                                 2
4342                                          p2 + p1
4343          (%o1)                   [2, p1, --------]
4344                                             2
4345          (%i2) pui2comp (3, [2, a1]);
4346                                                      2
4347                                           a1 (p2 + a1 )
4348                                   2  p3 + ------------- + a1 p2
4349                            p2 + a1              2
4350          (%o2)     [2, a1, --------, --------------------------]
4351                               2                  3
4352          (%i3) ratsimp (%);
4353                                      2                     3
4354                               p2 + a1   2 p3 + 3 a1 p2 + a1
4355          (%o3)        [2, a1, --------, --------------------]
4356                                  2               6
4357     Other functions for changing bases: 'comp2ele'.
4358
4359 -- Function: pui2ele (<n>, <lpui>)
4360     effects the passage from power functions to the elementary
4361     symmetric functions.  If the flag 'pui2ele' is 'girard', it will
4362     return the list of elementary symmetric functions from 1 to <n>,
4363     and if the flag is 'close', it will return the <n>-th elementary
4364     symmetric function.
4365
4366     Other functions for changing bases: 'comp2ele'.
4367
4368 -- Function: puireduc (<n>, <lpui>)
4369     <lpui> is a list whose first element is an integer <m>.  'puireduc'
4370     gives the first <n> power functions in terms of the first <m>.
4371
4372          (%i1) puireduc (3, [2]);
4373                                                   2
4374                                             p1 (p1  - p2)
4375          (%o1)          [2, p1, p2, p1 p2 - -------------]
4376                                                   2
4377          (%i2) ratsimp (%);
4378                                                     3
4379                                         3 p1 p2 - p1
4380          (%o2)              [2, p1, p2, -------------]
4381                                               2
4382
4383 -- Function: schur2comp (<P>, <l_var>)
4384     <P> is a polynomial in the variables of the list <l_var>.  Each of
4385     these variables represents a complete symmetric function.  In
4386     <l_var> the <i>-th complete symmetric function is represented by
4387     the concatenation of the letter 'h' and the integer <i>: 'h<i>'.
4388     This function expresses <P> in terms of Schur functions.
4389
4390          (%i1) schur2comp (h1*h2 - h3, [h1, h2, h3]);
4391          (%o1)                         s
4392                                         1, 2
4393          (%i2) schur2comp (a*h3, [h3]);
4394          (%o2)                         s  a
4395                                         3
4396
439730.2.2 Changing representations
4398-------------------------------
4399
4400 -- Function: cont2part (<pc>, <lvar>)
4401     returns the partitioned polynomial associated to the contracted
4402     form <pc> whose variables are in <lvar>.
4403
4404          (%i1) pc: 2*a^3*b*x^4*y + x^5;
4405                                     3    4      5
4406          (%o1)                   2 a  b x  y + x
4407          (%i2) cont2part (pc, [x, y]);
4408                                             3
4409          (%o2)              [[1, 5, 0], [2 a  b, 4, 1]]
4410
4411 -- Function: contract (<psym>, <lvar>)
4412     returns a contracted form (i.e.  a monomial orbit under the action
4413     of the symmetric group) of the polynomial <psym> in the variables
4414     contained in the list <lvar>.  The function 'explose' performs the
4415     inverse operation.  The function 'tcontract' tests the symmetry of
4416     the polynomial.
4417
4418          (%i1) psym: explose (2*a^3*b*x^4*y, [x, y, z]);
4419                   3      4      3      4      3    4        3    4
4420          (%o1) 2 a  b y z  + 2 a  b x z  + 2 a  b y  z + 2 a  b x  z
4421
4422                                                     3      4      3    4
4423                                                + 2 a  b x y  + 2 a  b x  y
4424          (%i2) contract (psym, [x, y, z]);
4425                                        3    4
4426          (%o2)                      2 a  b x  y
4427
4428 -- Function: explose (<pc>, <lvar>)
4429     returns the symmetric polynomial associated with the contracted
4430     form <pc>.  The list <lvar> contains the variables.
4431
4432          (%i1) explose (a*x + 1, [x, y, z]);
4433          (%o1)                  a z + a y + a x + 1
4434
4435 -- Function: part2cont (<ppart>, <lvar>)
4436     goes from the partitioned form to the contracted form of a
4437     symmetric polynomial.  The contracted form is rendered with the
4438     variables in <lvar>.
4439
4440          (%i1) part2cont ([[2*a^3*b, 4, 1]], [x, y]);
4441                                        3    4
4442          (%o1)                      2 a  b x  y
4443
4444 -- Function: partpol (<psym>, <lvar>)
4445     <psym> is a symmetric polynomial in the variables of the list
4446     <lvar>.  This function retturns its partitioned representation.
4447
4448          (%i1) partpol (-a*(x + y) + 3*x*y, [x, y]);
4449          (%o1)               [[3, 1, 1], [- a, 1, 0]]
4450
4451 -- Function: tcontract (<pol>, <lvar>)
4452     tests if the polynomial <pol> is symmetric in the variables of the
4453     list <lvar>.  If so, it returns a contracted representation like
4454     the function 'contract'.
4455
4456 -- Function: tpartpol (<pol>, <lvar>)
4457     tests if the polynomial <pol> is symmetric in the variables of the
4458     list <lvar>.  If so, it returns its partitioned representation like
4459     the function 'partpol'.
4460
446130.2.3 Groups and orbits
4462------------------------
4463
4464 -- Function: direct ([<p_1>, ..., <p_n>], <y>, <f>, [<lvar_1>, ...,
4465          <lvar_n>])
4466     calculates the direct image (see M. Giusti, D. Lazard et A.
4467     Valibouze, ISSAC 1988, Rome) associated to the function <f>, in the
4468     lists of variables <lvar_1>, ..., <lvar_n>, and in the polynomials
4469     <p_1>, ..., <p_n> in a variable <y>.  The arity of the function <f>
4470     is important for the calulation.  Thus, if the expression for <f>
4471     does not depend on some variable, it is useless to include this
4472     variable, and not including it will also considerably reduce the
4473     amount of computation.
4474
4475          (%i1) direct ([z^2  - e1* z + e2, z^2  - f1* z + f2],
4476                        z, b*v + a*u, [[u, v], [a, b]]);
4477                 2
4478          (%o1) y  - e1 f1 y
4479
4480                                           2            2             2   2
4481                            - 4 e2 f2 - (e1  - 2 e2) (f1  - 2 f2) + e1  f1
4482                          + -----------------------------------------------
4483                                                   2
4484          (%i2) ratsimp (%);
4485                        2                2                   2
4486          (%o2)        y  - e1 f1 y + (e1  - 4 e2) f2 + e2 f1
4487          (%i3) ratsimp (direct ([z^3-e1*z^2+e2*z-e3,z^2  - f1* z + f2],
4488                        z, b*v + a*u, [[u, v], [a, b]]));
4489                 6            5         2                        2    2   4
4490          (%o3) y  - 2 e1 f1 y  + ((2 e1  - 6 e2) f2 + (2 e2 + e1 ) f1 ) y
4491
4492                                    3                               3   3
4493           + ((9 e3 + 5 e1 e2 - 2 e1 ) f1 f2 + (- 2 e3 - 2 e1 e2) f1 ) y
4494
4495                   2       2        4    2
4496           + ((9 e2  - 6 e1  e2 + e1 ) f2
4497
4498                              2       2       2                   2    4
4499           + (- 9 e1 e3 - 6 e2  + 3 e1  e2) f1  f2 + (2 e1 e3 + e2 ) f1 )
4500
4501            2          2                      2     3          2
4502           y  + (((9 e1  - 27 e2) e3 + 3 e1 e2  - e1  e2) f1 f2
4503
4504                           2            2    3                5
4505           + ((15 e2 - 2 e1 ) e3 - e1 e2 ) f1  f2 - 2 e2 e3 f1 ) y
4506
4507                     2                   3           3     2   2    3
4508           + (- 27 e3  + (18 e1 e2 - 4 e1 ) e3 - 4 e2  + e1  e2 ) f2
4509
4510                   2      3                   3    2   2
4511           + (27 e3  + (e1  - 9 e1 e2) e3 + e2 ) f1  f2
4512
4513                             2    4        2   6
4514           + (e1 e2 e3 - 9 e3 ) f1  f2 + e3  f1
4515
4516     Finding the polynomial whose roots are the sums a+u where a is a
4517     root of z^2 - e_1 z + e_2 and u is a root of z^2 - f_1 z + f_2.
4518
4519          (%i1) ratsimp (direct ([z^2 - e1* z + e2, z^2 - f1* z + f2],
4520                                    z, a + u, [[u], [a]]));
4521                 4                    3             2
4522          (%o1) y  + (- 2 f1 - 2 e1) y  + (2 f2 + f1  + 3 e1 f1 + 2 e2
4523
4524               2   2                              2               2
4525           + e1 ) y  + ((- 2 f1 - 2 e1) f2 - e1 f1  + (- 2 e2 - e1 ) f1
4526
4527                            2                     2            2
4528           - 2 e1 e2) y + f2  + (e1 f1 - 2 e2 + e1 ) f2 + e2 f1  + e1 e2 f1
4529
4530               2
4531           + e2
4532
4533     'direct' accepts two flags: 'elementaires' and 'puissances'
4534     (default) which allow decomposing the symmetric polynomials
4535     appearing in the calculation into elementary symmetric functions,
4536     or power functions, respectively.
4537
4538     Functions of 'sym' used in this function:
4539
4540     'multi_orbit' (so 'orbit'), 'pui_direct', 'multi_elem' (so 'elem'),
4541     'multi_pui' (so 'pui'), 'pui2ele', 'ele2pui' (if the flag 'direct'
4542     is in 'puissances').
4543
4544 -- Function: multi_orbit (<P>, [<lvar_1>, <lvar_2>,..., <lvar_p>])
4545
4546     <P> is a polynomial in the set of variables contained in the lists
4547     <lvar_1>, <lvar_2>, ..., <lvar_p>.  This function returns the orbit
4548     of the polynomial <P> under the action of the product of the
4549     symmetric groups of the sets of variables represented in these <p>
4550     lists.
4551
4552          (%i1) multi_orbit (a*x + b*y, [[x, y], [a, b]]);
4553          (%o1)                [b y + a x, a y + b x]
4554          (%i2) multi_orbit (x + y + 2*a, [[x, y], [a, b, c]]);
4555          (%o2)        [y + x + 2 c, y + x + 2 b, y + x + 2 a]
4556     Also see: 'orbit' for the action of a single symmetric group.
4557
4558 -- Function: multsym (<ppart_1>, <ppart_2>, <n>)
4559     returns the product of the two symmetric polynomials in <n>
4560     variables by working only modulo the action of the symmetric group
4561     of order <n>.  The polynomials are in their partitioned form.
4562
4563     Given the 2 symmetric polynomials in <x>, <y>: '3*(x + y) + 2*x*y'
4564     and '5*(x^2 + y^2)' whose partitioned forms are '[[3, 1], [2, 1,
4565     1]]' and '[[5, 2]]', their product will be
4566
4567          (%i1) multsym ([[3, 1], [2, 1, 1]], [[5, 2]], 2);
4568          (%o1)         [[10, 3, 1], [15, 3, 0], [15, 2, 1]]
4569     that is '10*(x^3*y + y^3*x) + 15*(x^2*y + y^2*x) + 15*(x^3 + y^3)'.
4570
4571     Functions for changing the representations of a symmetric
4572     polynomial:
4573
4574     'contract', 'cont2part', 'explose', 'part2cont', 'partpol',
4575     'tcontract', 'tpartpol'.
4576
4577 -- Function: orbit (<P>, <lvar>)
4578     computes the orbit of the polynomial <P> in the variables in the
4579     list <lvar> under the action of the symmetric group of the set of
4580     variables in the list <lvar>.
4581
4582          (%i1) orbit (a*x + b*y, [x, y]);
4583          (%o1)                [a y + b x, b y + a x]
4584          (%i2) orbit (2*x + x^2, [x, y]);
4585                                  2         2
4586          (%o2)                 [y  + 2 y, x  + 2 x]
4587     See also 'multi_orbit' for the action of a product of symmetric
4588     groups on a polynomial.
4589
4590 -- Function: pui_direct (<orbite>, [<lvar_1>, ..., <lvar_n>], [<d_1>,
4591          <d_2>, ..., <d_n>])
4592
4593     Let <f> be a polynomial in <n> blocks of variables <lvar_1>, ...,
4594     <lvar_n>.  Let <c_i> be the number of variables in <lvar_i>, and
4595     <SC> be the product of <n> symmetric groups of degree <c_1>, ...,
4596     <c_n>.  This group acts naturally on <f>.  The list <orbite> is the
4597     orbit, denoted '<SC>(<f>)', of the function <f> under the action of
4598     <SC>.  (This list may be obtained by the function 'multi_orbit'.)
4599     The <di> are integers s.t.  c_1 <= d_1, c_2 <= d_2, ..., c_n <=
4600     d_n.
4601
4602     Let <SD> be the product of the symmetric groups S_[d_1] x S_[d_2] x
4603     ... x S_[d_n].  The function 'pui_direct' returns the first <n>
4604     power functions of '<SD>(<f>)' deduced from the power functions of
4605     '<SC>(<f>)', where <n> is the size of '<SD>(<f>)'.
4606
4607     The result is in multi-contracted form w.r.t.  <SD>, i.e.  only one
4608     element is kept per orbit, under the action of <SD>.
4609
4610          (%i1) l: [[x, y], [a, b]];
4611          (%o1)                   [[x, y], [a, b]]
4612          (%i2) pui_direct (multi_orbit (a*x + b*y, l), l, [2, 2]);
4613                                                 2  2
4614          (%o2)               [a x, 4 a b x y + a  x ]
4615          (%i3) pui_direct (multi_orbit (a*x + b*y, l), l, [3, 2]);
4616                                       2  2     2    2        3  3
4617          (%o3) [2 a x, 4 a b x y + 2 a  x , 3 a  b x  y + 2 a  x ,
4618
4619              2  2  2  2      3    3        4  4
4620          12 a  b  x  y  + 4 a  b x  y + 2 a  x ,
4621
4622              3  2  3  2      4    4        5  5
4623          10 a  b  x  y  + 5 a  b x  y + 2 a  x ,
4624
4625              3  3  3  3       4  2  4  2      5    5        6  6
4626          40 a  b  x  y  + 15 a  b  x  y  + 6 a  b x  y + 2 a  x ]
4627          (%i4) pui_direct ([y + x + 2*c, y + x + 2*b, y + x + 2*a],
4628                [[x, y], [a, b, c]], [2, 3]);
4629                                       2              2
4630          (%o4) [3 x + 2 a, 6 x y + 3 x  + 4 a x + 4 a ,
4631
4632                           2                   3        2       2        3
4633                        9 x  y + 12 a x y + 3 x  + 6 a x  + 12 a  x + 8 a ]
4634
463530.2.4 Partitions
4636-----------------
4637
4638 -- Function: kostka (<part_1>, <part_2>)
4639     written by P. Esperet, calculates the Kostka number of the
4640     partition <part_1> and <part_2>.
4641
4642          (%i1) kostka ([3, 3, 3], [2, 2, 2, 1, 1, 1]);
4643          (%o1)                           6
4644
4645 -- Function: lgtreillis (<n>, <m>)
4646     returns the list of partitions of weight <n> and length <m>.
4647
4648          (%i1) lgtreillis (4, 2);
4649          (%o1)                   [[3, 1], [2, 2]]
4650     Also see: 'ltreillis', 'treillis' and 'treinat'.
4651
4652 -- Function: ltreillis (<n>, <m>)
4653     returns the list of partitions of weight <n> and length less than
4654     or equal to <m>.
4655
4656          (%i1) ltreillis (4, 2);
4657          (%o1)               [[4, 0], [3, 1], [2, 2]]
4658     Also see: 'lgtreillis', 'treillis' and 'treinat'.
4659
4660 -- Function: treillis (<n>)
4661     returns all partitions of weight <n>.
4662
4663          (%i1) treillis (4);
4664          (%o1)    [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
4665
4666     See also: 'lgtreillis', 'ltreillis' and 'treinat'.
4667
4668 -- Function: treinat (<part>)
4669     retruns the list of partitions inferior to the partition <part>
4670     w.r.t.  the natural order.
4671
4672          (%i1) treinat ([5]);
4673          (%o1)                         [[5]]
4674          (%i2) treinat ([1, 1, 1, 1, 1]);
4675          (%o2) [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1],
4676
4677                                                           [1, 1, 1, 1, 1]]
4678          (%i3) treinat ([3, 2]);
4679          (%o3)                 [[5], [4, 1], [3, 2]]
4680
4681     See also: 'lgtreillis', 'ltreillis' and 'treillis'.
4682
468330.2.5 Polynomials and their roots
4684----------------------------------
4685
4686 -- Function: ele2polynome (<L>, <z>)
4687     returns the polynomial in <z> s.t.  the elementary symmetric
4688     functions of its roots are in the list '<L> = [<n>, <e_1>, ...,
4689     <e_n>]', where <n> is the degree of the polynomial and <e_i> the
4690     <i>-th elementary symmetric function.
4691
4692          (%i1) ele2polynome ([2, e1, e2], z);
4693                                    2
4694          (%o1)                    z  - e1 z + e2
4695          (%i2) polynome2ele (x^7 - 14*x^5 + 56*x^3  - 56*x + 22, x);
4696          (%o2)          [7, 0, - 14, 0, 56, 0, - 56, - 22]
4697          (%i3) ele2polynome ([7, 0, -14, 0, 56, 0, -56, -22], x);
4698                            7       5       3
4699          (%o3)            x  - 14 x  + 56 x  - 56 x + 22
4700     The inverse: 'polynome2ele (<P>, <z>)'.
4701
4702     Also see: 'polynome2ele', 'pui2polynome'.
4703
4704 -- Function: polynome2ele (<P>, <x>)
4705     gives the list '<l> = [<n>, <e_1>, ..., <e_n>]' where <n> is the
4706     degree of the polynomial <P> in the variable <x> and <e_i> is the
4707     <i>-the elementary symmetric function of the roots of <P>.
4708
4709          (%i1) polynome2ele (x^7 - 14*x^5 + 56*x^3 - 56*x + 22, x);
4710          (%o1)          [7, 0, - 14, 0, 56, 0, - 56, - 22]
4711          (%i2) ele2polynome ([7, 0, -14, 0, 56, 0, -56, -22], x);
4712                            7       5       3
4713          (%o2)            x  - 14 x  + 56 x  - 56 x + 22
4714     The inverse: 'ele2polynome (<l>, <x>)'
4715
4716 -- Function: prodrac (<L>, <k>)
4717     <L> is a list containing the elementary symmetric functions on a
4718     set <A>.  'prodrac' returns the polynomial whose roots are the <k>
4719     by <k> products of the elements of <A>.
4720
4721     Also see 'somrac'.
4722
4723 -- Function: pui2polynome (<x>, <lpui>)
4724     calculates the polynomial in <x> whose power functions of the roots
4725     are given in the list <lpui>.
4726
4727          (%i1) pui;
4728          (%o1)                           1
4729          (%i2) kill(labels);
4730          (%o0)                         done
4731          (%i1) polynome2ele (x^3 - 4*x^2 + 5*x - 1, x);
4732          (%o1)                     [3, 4, 5, 1]
4733          (%i2) ele2pui (3, %);
4734          (%o2)                     [3, 4, 6, 7]
4735          (%i3) pui2polynome (x, %);
4736                                  3      2
4737          (%o3)                  x  - 4 x  + 5 x - 1
4738     See also: 'polynome2ele', 'ele2polynome'.
4739
4740 -- Function: somrac (<L>, <k>)
4741     The list <L> contains elementary symmetric functions of a
4742     polynomial <P> .  The function computes the polynomial whose roots
4743     are the <k> by <k> distinct sums of the roots of <P>.
4744
4745     Also see 'prodrac'.
4746
474730.2.6 Resolvents
4748-----------------
4749
4750 -- Function: resolvante (<P>, <x>, <f>, [<x_1>,..., <x_d>])
4751     calculates the resolvent of the polynomial <P> in <x> of degree <n>
4752     >= <d> by the function <f> expressed in the variables <x_1>, ...,
4753     <x_d>.  For efficiency of computation it is important to not
4754     include in the list '[<x_1>, ..., <x_d>]' variables which do not
4755     appear in the transformation function <f>.
4756
4757     To increase the efficiency of the computation one may set flags in
4758     'resolvante' so as to use appropriate algorithms:
4759
4760     If the function <f> is unitary:
4761        * A polynomial in a single variable,
4762        * linear,
4763        * alternating,
4764        * a sum,
4765        * symmetric,
4766        * a product,
4767        * the function of the Cayley resolvent (usable up to degree 5)
4768
4769               (x1*x2 + x2*x3 + x3*x4 + x4*x5 + x5*x1 -
4770                    (x1*x3 + x3*x5 + x5*x2 + x2*x4 + x4*x1))^2
4771
4772          general,
4773     the flag of 'resolvante' may be, respectively:
4774        * unitaire,
4775        * lineaire,
4776        * alternee,
4777        * somme,
4778        * produit,
4779        * cayley,
4780        * generale.
4781
4782          (%i1) resolvante: unitaire$
4783          (%i2) resolvante (x^7 - 14*x^5 + 56*x^3 - 56*x + 22, x, x^3 - 1,
4784                [x]);
4785
4786          " resolvante unitaire " [7, 0, 28, 0, 168, 0, 1120, - 154, 7840,
4787                                   - 2772, 56448, - 33880,
4788
4789          413952, - 352352, 3076668, - 3363360, 23114112, - 30494464,
4790
4791          175230832, - 267412992, 1338886528, - 2292126760]
4792            3       6      3       9      6      3
4793          [x  - 1, x  - 2 x  + 1, x  - 3 x  + 3 x  - 1,
4794
4795           12      9      6      3       15      12       9       6      3
4796          x   - 4 x  + 6 x  - 4 x  + 1, x   - 5 x   + 10 x  - 10 x  + 5 x
4797
4798                 18      15       12       9       6      3
4799           - 1, x   - 6 x   + 15 x   - 20 x  + 15 x  - 6 x  + 1,
4800
4801           21      18       15       12       9       6      3
4802          x   - 7 x   + 21 x   - 35 x   + 35 x  - 21 x  + 7 x  - 1]
4803          [- 7, 1127, - 6139, 431767, - 5472047, 201692519, - 3603982011]
4804                 7      6        5         4          3           2
4805          (%o2) y  + 7 y  - 539 y  - 1841 y  + 51443 y  + 315133 y
4806
4807                                                        + 376999 y + 125253
4808          (%i3) resolvante: lineaire$
4809          (%i4) resolvante (x^4 - 1, x, x1 + 2*x2 + 3*x3, [x1, x2, x3]);
4810
4811          " resolvante lineaire "
4812                 24       20         16            12             8
4813          (%o4) y   + 80 y   + 7520 y   + 1107200 y   + 49475840 y
4814
4815                                                              4
4816                                                 + 344489984 y  + 655360000
4817          (%i5) resolvante: general$
4818          (%i6) resolvante (x^4 - 1, x, x1 + 2*x2 + 3*x3, [x1, x2, x3]);
4819
4820          " resolvante generale "
4821                 24       20         16            12             8
4822          (%o6) y   + 80 y   + 7520 y   + 1107200 y   + 49475840 y
4823
4824                                                              4
4825                                                 + 344489984 y  + 655360000
4826          (%i7) resolvante (x^4 - 1, x, x1 + 2*x2 + 3*x3, [x1, x2, x3, x4]);
4827
4828          " resolvante generale "
4829                 24       20         16            12             8
4830          (%o7) y   + 80 y   + 7520 y   + 1107200 y   + 49475840 y
4831
4832                                                              4
4833                                                 + 344489984 y  + 655360000
4834          (%i8) direct ([x^4 - 1], x, x1 + 2*x2 + 3*x3, [[x1, x2, x3]]);
4835                 24       20         16            12             8
4836          (%o8) y   + 80 y   + 7520 y   + 1107200 y   + 49475840 y
4837
4838                                                              4
4839                                                 + 344489984 y  + 655360000
4840          (%i9) resolvante :lineaire$
4841          (%i10) resolvante (x^4 - 1, x, x1 + x2 + x3, [x1, x2, x3]);
4842
4843          " resolvante lineaire "
4844                                        4
4845          (%o10)                       y  - 1
4846          (%i11) resolvante: symetrique$
4847          (%i12) resolvante (x^4 - 1, x, x1 + x2 + x3, [x1, x2, x3]);
4848
4849          " resolvante symetrique "
4850                                        4
4851          (%o12)                       y  - 1
4852          (%i13) resolvante (x^4 + x + 1, x, x1 - x2, [x1, x2]);
4853
4854          " resolvante symetrique "
4855                                     6      2
4856          (%o13)                    y  - 4 y  - 1
4857          (%i14) resolvante: alternee$
4858          (%i15) resolvante (x^4 + x + 1, x, x1 - x2, [x1, x2]);
4859
4860          " resolvante alternee "
4861                      12      8       6        4        2
4862          (%o15)     y   + 8 y  + 26 y  - 112 y  + 216 y  + 229
4863          (%i16) resolvante: produit$
4864          (%i17) resolvante (x^7 - 7*x + 3, x, x1*x2*x3, [x1, x2, x3]);
4865
4866          " resolvante produit "
4867                  35      33         29        28         27        26
4868          (%o17) y   - 7 y   - 1029 y   + 135 y   + 7203 y   - 756 y
4869
4870                   24           23          22            21           20
4871           + 1323 y   + 352947 y   - 46305 y   - 2463339 y   + 324135 y
4872
4873                    19           18             17              15
4874           - 30618 y   - 453789 y   - 40246444 y   + 282225202 y
4875
4876                       14              12             11            10
4877           - 44274492 y   + 155098503 y   + 12252303 y   + 2893401 y
4878
4879                        9            8            7             6
4880           - 171532242 y  + 6751269 y  + 2657205 y  - 94517766 y
4881
4882                      5             3
4883           - 3720087 y  + 26040609 y  + 14348907
4884          (%i18) resolvante: symetrique$
4885          (%i19) resolvante (x^7 - 7*x + 3, x, x1*x2*x3, [x1, x2, x3]);
4886
4887          " resolvante symetrique "
4888                  35      33         29        28         27        26
4889          (%o19) y   - 7 y   - 1029 y   + 135 y   + 7203 y   - 756 y
4890
4891                   24           23          22            21           20
4892           + 1323 y   + 352947 y   - 46305 y   - 2463339 y   + 324135 y
4893
4894                    19           18             17              15
4895           - 30618 y   - 453789 y   - 40246444 y   + 282225202 y
4896
4897                       14              12             11            10
4898           - 44274492 y   + 155098503 y   + 12252303 y   + 2893401 y
4899
4900                        9            8            7             6
4901           - 171532242 y  + 6751269 y  + 2657205 y  - 94517766 y
4902
4903                      5             3
4904           - 3720087 y  + 26040609 y  + 14348907
4905          (%i20) resolvante: cayley$
4906          (%i21) resolvante (x^5 - 4*x^2 + x + 1, x, a, []);
4907
4908          " resolvante de Cayley "
4909                  6       5         4          3            2
4910          (%o21) x  - 40 x  + 4080 x  - 92928 x  + 3772160 x  + 37880832 x
4911
4912                                                                 + 93392896
4913
4914     For the Cayley resolvent, the 2 last arguments are neutral and the
4915     input polynomial must necessarily be of degree 5.
4916
4917     See also:
4918     'resolvante_bipartite', 'resolvante_produit_sym',
4919     'resolvante_unitaire', 'resolvante_alternee1', 'resolvante_klein',
4920     'resolvante_klein3', 'resolvante_vierer', 'resolvante_diedrale'.
4921
4922 -- Function: resolvante_alternee1 (<P>, <x>)
4923     calculates the transformation '<P>(<x>)' of degree <n> by the
4924     function product(x_i - x_j, 1 <= i < j <= n - 1).
4925
4926     See also:
4927     'resolvante_produit_sym', 'resolvante_unitaire',
4928     'resolvante', 'resolvante_klein', 'resolvante_klein3',
4929     'resolvante_vierer', 'resolvante_diedrale', 'resolvante_bipartite'.
4930
4931 -- Function: resolvante_bipartite (<P>, <x>)
4932     calculates the transformation of '<P>(<x>)' of even degree <n> by
4933     the function x_1 x_2 ... x_[n/2] + x_[n/2 + 1] ... x_n.
4934
4935          (%i1) resolvante_bipartite (x^6 + 108, x);
4936                        10        8           6             4
4937          (%o1)        y   - 972 y  + 314928 y  - 34012224 y
4938
4939     See also:
4940     'resolvante_produit_sym', 'resolvante_unitaire',
4941     'resolvante', 'resolvante_klein', 'resolvante_klein3',
4942     'resolvante_vierer', 'resolvante_diedrale', 'resolvante_alternee1'.
4943
4944 -- Function: resolvante_diedrale (<P>, <x>)
4945     calculates the transformation of '<P>(<x>)' by the function '<x_1>
4946     <x_2> + <x_3> <x_4>'.
4947
4948          (%i1) resolvante_diedrale (x^5 - 3*x^4 + 1, x);
4949                 15       12       11       10        9         8         7
4950          (%o1) x   - 21 x   - 81 x   - 21 x   + 207 x  + 1134 x  + 2331 x
4951
4952                  6         5          4          3          2
4953           - 945 x  - 4970 x  - 18333 x  - 29079 x  - 20745 x  - 25326 x
4954
4955           - 697
4956
4957     See also:
4958     'resolvante_produit_sym', 'resolvante_unitaire',
4959     'resolvante_alternee1', 'resolvante_klein', 'resolvante_klein3',
4960     'resolvante_vierer', 'resolvante'.
4961
4962 -- Function: resolvante_klein (<P>, <x>)
4963     calculates the transformation of '<P>(<x>)' by the function '<x_1>
4964     <x_2> <x_4> + <x_4>'.
4965
4966     See also:
4967     'resolvante_produit_sym', 'resolvante_unitaire',
4968     'resolvante_alternee1', 'resolvante', 'resolvante_klein3',
4969     'resolvante_vierer', 'resolvante_diedrale'.
4970
4971 -- Function: resolvante_klein3 (<P>, <x>)
4972     calculates the transformation of '<P>(<x>)' by the function '<x_1>
4973     <x_2> <x_4> + <x_4>'.
4974
4975     See also:
4976     'resolvante_produit_sym', 'resolvante_unitaire',
4977     'resolvante_alternee1', 'resolvante_klein', 'resolvante',
4978     'resolvante_vierer', 'resolvante_diedrale'.
4979
4980 -- Function: resolvante_produit_sym (<P>, <x>)
4981     calculates the list of all product resolvents of the polynomial
4982     '<P>(<x>)'.
4983
4984          (%i1) resolvante_produit_sym (x^5 + 3*x^4 + 2*x - 1, x);
4985                  5      4             10      8       7       6       5
4986          (%o1) [y  + 3 y  + 2 y - 1, y   - 2 y  - 21 y  - 31 y  - 14 y
4987
4988              4       3      2       10      8       7    6       5       4
4989           - y  + 14 y  + 3 y  + 1, y   + 3 y  + 14 y  - y  - 14 y  - 31 y
4990
4991                 3      2       5      4
4992           - 21 y  - 2 y  + 1, y  - 2 y  - 3 y - 1, y - 1]
4993          (%i2) resolvante: produit$
4994          (%i3) resolvante (x^5 + 3*x^4 + 2*x - 1, x, a*b*c, [a, b, c]);
4995
4996          " resolvante produit "
4997                 10      8       7    6        5       4       3     2
4998          (%o3) y   + 3 y  + 14 y  - y  - 14 y  - 31 y  - 21 y  - 2 y  + 1
4999
5000     See also:
5001     'resolvante', 'resolvante_unitaire',
5002     'resolvante_alternee1', 'resolvante_klein',
5003     'resolvante_klein3', 'resolvante_vierer',
5004     'resolvante_diedrale'.
5005
5006 -- Function: resolvante_unitaire (<P>, <Q>, <x>)
5007     computes the resolvent of the polynomial '<P>(<x>)' by the
5008     polynomial '<Q>(<x>)'.
5009
5010     See also:
5011     'resolvante_produit_sym', 'resolvante',
5012     'resolvante_alternee1', 'resolvante_klein', 'resolvante_klein3',
5013     'resolvante_vierer', 'resolvante_diedrale'.
5014
5015 -- Function: resolvante_vierer (<P>, <x>)
5016     computes the transformation of '<P>(<x>)' by the function '<x_1>
5017     <x_2> - <x_3> <x_4>'.
5018
5019     See also:
5020     'resolvante_produit_sym', 'resolvante_unitaire',
5021     'resolvante_alternee1', 'resolvante_klein', 'resolvante_klein3',
5022     'resolvante', 'resolvante_diedrale'.
5023
502430.2.7 Miscellaneous
5025--------------------
5026
5027 -- Function: multinomial (<r>, <part>)
5028     where <r> is the weight of the partition <part>.  This function
5029     returns the associate multinomial coefficient: if the parts of
5030     <part> are <i_1>, <i_2>, ..., <i_k>, the result is '<r>!/(<i_1>!
5031     <i_2>! ... <i_k>!)'.
5032
5033 -- Function: permut (<L>)
5034     returns the list of permutations of the list <L>.
5035
5036
5037File: maxima.info,  Node: Groups,  Next: Runtime Environment,  Prev: Symmetries,  Up: Top
5038
503931 Groups
5040*********
5041
5042* Menu:
5043
5044* Functions and Variables for Groups::
5045
5046
5047File: maxima.info,  Node: Functions and Variables for Groups,  Prev: Groups,  Up: Groups
5048
504931.1 Functions and Variables for Groups
5050=======================================
5051
5052 -- Function: todd_coxeter
5053          todd_coxeter (<relations>, <subgroup>)
5054          todd_coxeter (<relations>)
5055
5056     Find the order of G/H where G is the Free Group modulo <relations>,
5057     and H is the subgroup of G generated by <subgroup>.  <subgroup> is
5058     an optional argument, defaulting to [].  In doing this it produces
5059     a multiplication table for the right action of G on G/H, where the
5060     cosets are enumerated [H,Hg2,Hg3,...].  This can be seen internally
5061     in the variable 'todd_coxeter_state'.
5062
5063     Example:
5064
5065          (%i1) symet(n):=create_list(
5066                  if (j - i) = 1 then (p(i,j))^^3 else
5067                      if (not i = j) then (p(i,j))^^2 else
5068                          p(i,i) , j, 1, n-1, i, 1, j);
5069                                                                 <3>
5070          (%o1) symet(n) := create_list(if j - i = 1 then p(i, j)
5071
5072                                          <2>
5073           else (if not i = j then p(i, j)    else p(i, i)), j, 1, n - 1,
5074
5075          i, 1, j)
5076          (%i2) p(i,j) := concat(x,i).concat(x,j);
5077          (%o2)        p(i, j) := concat(x, i) . concat(x, j)
5078          (%i3) symet(5);
5079                   <2>           <3>    <2>           <2>           <3>
5080          (%o3) [x1   , (x1 . x2)   , x2   , (x1 . x3)   , (x2 . x3)   ,
5081
5082                      <2>           <2>           <2>           <3>    <2>
5083                    x3   , (x1 . x4)   , (x2 . x4)   , (x3 . x4)   , x4   ]
5084          (%i4) todd_coxeter(%o3);
5085
5086          Rows tried 426
5087          (%o4)                          120
5088          (%i5) todd_coxeter(%o3,[x1]);
5089
5090          Rows tried 213
5091          (%o5)                          60
5092          (%i6) todd_coxeter(%o3,[x1,x2]);
5093
5094          Rows tried 71
5095          (%o6)                          20
5096
5097
5098File: maxima.info,  Node: Runtime Environment,  Next: Miscellaneous Options,  Prev: Groups,  Up: Top
5099
510032 Runtime Environment
5101**********************
5102
5103* Menu:
5104
5105* Introduction for Runtime Environment::
5106* Interrupts::
5107* Functions and Variables for Runtime Environment::
5108
5109
5110File: maxima.info,  Node: Introduction for Runtime Environment,  Next: Interrupts,  Prev: Runtime Environment,  Up: Runtime Environment
5111
511232.1 Introduction for Runtime Environment
5113=========================================
5114
5115'maxima-init.mac' is a file which is loaded automatically when Maxima
5116starts.  You can use 'maxima-init.mac' to customize your Maxima
5117environment.  'maxima-init.mac', if it exists, is typically placed in
5118the directory named by 'maxima_userdir', although it can be in any
5119directory searched by the function 'file_search'.
5120
5121   Here is an example 'maxima-init.mac' file:
5122
5123     setup_autoload ("specfun.mac", ultraspherical, assoc_legendre_p);
5124     showtime:all;
5125
5126   In this example, 'setup_autoload' tells Maxima to load the specified
5127file ('specfun.mac') if any of the functions ('ultraspherical',
5128'assoc_legendre_p') are called but not yet defined.  Thus you needn't
5129remember to load the file before calling the functions.
5130
5131   The statement 'showtime: all' tells Maxima to set the 'showtime'
5132variable.  The 'maxima-init.mac' file can contain any other assignments
5133or other Maxima statements.
5134
5135
5136File: maxima.info,  Node: Interrupts,  Next: Functions and Variables for Runtime Environment,  Prev: Introduction for Runtime Environment,  Up: Runtime Environment
5137
513832.2 Interrupts
5139===============
5140
5141The user can stop a time-consuming computation with the ^C (control-C)
5142character.  The default action is to stop the computation and print
5143another user prompt.  In this case, it is not possible to restart a
5144stopped computation.
5145
5146   If the Lisp variable '*debugger-hook*' is set to 'nil', by executing
5147
5148     :lisp (setq *debugger-hook* nil)
5149
5150then upon receiving ^C, Maxima will enter the Lisp debugger, and the
5151user may use the debugger to inspect the Lisp environment.  The stopped
5152computation can be restarted by entering 'continue' in the Lisp
5153debugger.  The means of returning to Maxima from the Lisp debugger
5154(other than running the computation to completion) is different for each
5155version of Lisp.
5156
5157   On Unix systems, the character ^Z (control-Z) causes Maxima to stop
5158altogether, and control is returned to the shell prompt.  The 'fg'
5159command causes Maxima to resume from the point at which it was stopped.
5160
5161
5162File: maxima.info,  Node: Functions and Variables for Runtime Environment,  Prev: Interrupts,  Up: Runtime Environment
5163
516432.3 Functions and Variables for Runtime Environment
5165====================================================
5166
5167 -- System variable: maxima_tempdir
5168
5169     'maxima_tempdir' names the directory in which Maxima creates some
5170     temporary files.  In particular, temporary files for plotting are
5171     created in 'maxima_tempdir'.
5172
5173     The initial value of 'maxima_tempdir' is the user's home directory,
5174     if Maxima can locate it; otherwise Maxima makes a guess about a
5175     suitable directory.
5176
5177     'maxima_tempdir' may be assigned a string which names a directory.
5178
5179 -- System variable: maxima_userdir
5180
5181     'maxima_userdir' names a directory which Maxima searches to find
5182     Maxima and Lisp files.  (Maxima searches some other directories as
5183     well; 'file_search_maxima' and 'file_search_lisp' are the complete
5184     lists.)
5185
5186     The initial value of 'maxima_userdir' is a subdirectory of the
5187     user's home directory, if Maxima can locate it; otherwise Maxima
5188     makes a guess about a suitable directory.
5189
5190     'maxima_userdir' may be assigned a string which names a directory.
5191     However, assigning to 'maxima_userdir' does not automatically
5192     change 'file_search_maxima' and 'file_search_lisp'; those variables
5193     must be changed separately.
5194
5195 -- Function: room
5196          room ()
5197          room (true)
5198          room (false)
5199
5200     Prints out a description of the state of storage and stack
5201     management in Maxima.  'room' calls the Lisp function of the same
5202     name.
5203
5204        * 'room ()' prints out a moderate description.
5205        * 'room (true)' prints out a verbose description.
5206        * 'room (false)' prints out a terse description.
5207
5208 -- Function: sstatus (<keyword>, <item>)
5209
5210     When <keyword> is the symbol 'feature', <item> is put on the list
5211     of system features.  After 'sstatus (keyword, item)' is executed,
5212     'status (feature, item)' returns 'true'.  If <keyword> is the
5213     symbol 'nofeature', <item> is deleted from the list of system
5214     features.  This can be useful for package writers, to keep track of
5215     what features they have loaded in.
5216
5217     See also 'status'.
5218
5219 -- Function: status
5220          status ('feature')
5221          status ('feature', <item>)
5222
5223     Returns information about the presence or absence of certain
5224     system-dependent features.
5225
5226        * 'status (feature)' returns a list of system features.  These
5227          include Lisp version, operating system type, etc.  The list
5228          may vary from one Lisp type to another.
5229
5230        * 'status (feature, item)' returns 'true' if <item> is on the
5231          list of items returned by 'status (feature)' and 'false'
5232          otherwise.  'status' quotes the argument <item>.  The
5233          quote-quote operator '''' defeats quotation.  A feature whose
5234          name contains a special character, such as a hyphen, must be
5235          given as a string argument.  For example, 'status (feature,
5236          "ansi-cl")'.
5237
5238     See also 'sstatus'.
5239
5240     The variable 'features' contains a list of features which apply to
5241     mathematical expressions.  See 'features' and 'featurep' for more
5242     information.
5243
5244 -- Function: system (<command>)
5245
5246     Executes <command> as a separate process.  The command is passed to
5247     the default shell for execution.  'system' is not supported by all
5248     operating systems, but generally exists in Unix and Unix-like
5249     environments.
5250
5251     Supposing '_hist.out' is a list of frequencies which you wish to
5252     plot as a bar graph using 'xgraph'.
5253
5254          (%i1) (with_stdout("_hist.out",
5255                     for i:1 thru length(hist) do (
5256                       print(i,hist[i]))),
5257                 system("xgraph -bar -brw .7 -nl < _hist.out"));
5258
5259     In order to make the plot be done in the background (returning
5260     control to Maxima) and remove the temporary file after it is done
5261     do:
5262
5263          system("(xgraph -bar -brw .7 -nl < _hist.out;  rm -f _hist.out)&")
5264
5265 -- Function: time (%o1, %o2, %o3, ...)
5266
5267     Returns a list of the times, in seconds, taken to compute the
5268     output lines '%o1', '%o2', '%o3', ... The time returned is Maxima's
5269     estimate of the internal computation time, not the elapsed time.
5270     'time' can only be applied to output line variables; for any other
5271     variables, 'time' returns 'unknown'.
5272
5273     Set 'showtime: true' to make Maxima print out the computation time
5274     and elapsed time with each output line.
5275
5276 -- Function: timedate
5277          timedate (<T>, <tz_offset>)
5278          timedate (<T>)
5279          timedate ()
5280
5281     'timedate(<T>, <tz_offset>)' returns a string representing the time
5282     <T> in the time zone <tz_offset>.  The string format is 'YYYY-MM-DD
5283     HH:MM:SS.NNN[+|-]ZZ:ZZ' (using as many digits as necessary to
5284     represent the fractional part) if <T> has a nonzero fractional
5285     part, or 'YYYY-MM-DD HH:MM:SS[+|-]ZZ:ZZ' if its fractional part is
5286     zero.
5287
5288     <T> measures time, in seconds, since midnight, January 1, 1900, in
5289     the GMT time zone.
5290
5291     <tz_offset> measures the offset of the time zone, in hours, east
5292     (positive) or west (negative) of GMT. <tz_offset> must be an
5293     integer, rational, or float between -24 and 24, inclusive.  If
5294     <tz_offset> is not a multiple of 1/60, it is rounded to the nearest
5295     multiple of 1/60.
5296
5297     'timedate(<T>)' is equivalent to 'timedate(<T>, <tz_offset>)' with
5298     <tz_offset> equal to the offset of the local time zone.
5299
5300     'timedate()' is equivalent to 'timedate(absolute_real_time())'.
5301     That is, it returns the current time in the local time zone.
5302
5303     Example:
5304
5305     'timedate' with no argument returns a string representing the
5306     current time and date.
5307
5308          (%i1) d : timedate ();
5309          (%o1)                      2010-06-08 04:08:09+01:00
5310          (%i2) print ("timedate reports current time", d) $
5311          timedate reports current time 2010-06-08 04:08:09+01:00
5312
5313     'timedate' with an argument returns a string representing the
5314     argument.
5315
5316          (%i1) timedate (0);
5317          (%o1)                      1900-01-01 01:00:00+01:00
5318          (%i2) timedate (absolute_real_time () - 7*24*3600);
5319          (%o2)                      2010-06-01 04:19:51+01:00
5320
5321     'timedate' with optional timezone offset.
5322
5323          (%i1) timedate (1000000000, -9.5);
5324          (%o1)               1931-09-09 16:16:40-09:30
5325
5326 -- Function: parse_timedate
5327          parse_timedate (<S>)
5328
5329     Parses a string <S> representing a date or date and time of day and
5330     returns the number of seconds since midnight, January 1, 1900 GMT.
5331     If there is a nonzero fractional part, the value returned is a
5332     rational number, otherwise, it is an integer.  'parse_timedate'
5333     returns 'false' if it cannot parse <S> according to any of the
5334     allowed formats.
5335
5336     The string <S> must have one of the following formats, optionally
5337     followed by a timezone designation:
5338
5339        * 'YYYY-MM-DD[ T]hh:mm:ss[,.]nnn'
5340        * 'YYYY-MM-DD[ T]hh:mm:ss'
5341        * 'YYYY-MM-DD'
5342
5343     where the fields are year, month, day, hours, minutes, seconds, and
5344     fraction of a second, and square brackets indicate acceptable
5345     alternatives.  The fraction may contain one or more digits.
5346
5347     Except for the fraction of a second, each field must have exactly
5348     the number of digits indicated: four digits for the year, and two
5349     for the month, day of the month, hours, minutes, and seconds.
5350
5351     A timezone designation must have one of the following forms:
5352
5353        * '[+-]hh:mm'
5354        * '[+-]hhmm'
5355        * '[+-]hh'
5356        * 'Z'
5357
5358     where 'hh' and 'mm' indicate hours and minutes east ('+') or west
5359     ('-') of GMT. The timezone may be from +24 hours (inclusive) to -24
5360     hours (inclusive).
5361
5362     A literal character 'Z' is equivalent to '+00:00' and its variants,
5363     indicating GMT.
5364
5365     If no timezone is indicated, the time is assumed to be in the local
5366     time zone.
5367
5368     Any leading or trailing whitespace (space, tab, newline, and
5369     carriage return) is ignored, but any other leading or trailing
5370     characters cause 'parse_timedate' to fail and return 'false'.
5371
5372     See also 'timedate' and 'absolute_real_time'.
5373
5374     Examples:
5375
5376     Midnight, January 1, 1900, in the local time zone, in each
5377     acceptable format.  The result is the number of seconds the local
5378     time zone is ahead (negative result) or behind (positive result)
5379     GMT. In this example, the local time zone is 8 hours behind GMT.
5380
5381          (%i1) parse_timedate ("1900-01-01 00:00:00,000");
5382          (%o1)                         28800
5383          (%i2) parse_timedate ("1900-01-01 00:00:00.000");
5384          (%o2)                         28800
5385          (%i3) parse_timedate ("1900-01-01T00:00:00,000");
5386          (%o3)                         28800
5387          (%i4) parse_timedate ("1900-01-01T00:00:00.000");
5388          (%o4)                         28800
5389          (%i5) parse_timedate ("1900-01-01 00:00:00");
5390          (%o5)                         28800
5391          (%i6) parse_timedate ("1900-01-01T00:00:00");
5392          (%o6)                         28800
5393          (%i7) parse_timedate ("1900-01-01");
5394          (%o7)                         28800
5395
5396     Midnight, January 1, 1900, GMT, in different indicated time zones.
5397
5398          (%i1) parse_timedate ("1900-01-01 19:00:00+19:00");
5399          (%o1)                           0
5400          (%i2) parse_timedate ("1900-01-01 07:00:00+07:00");
5401          (%o2)                           0
5402          (%i3) parse_timedate ("1900-01-01 01:00:00+01:00");
5403          (%o3)                           0
5404          (%i4) parse_timedate ("1900-01-01Z");
5405          (%o4)                           0
5406          (%i5) parse_timedate ("1899-12-31 21:00:00-03:00");
5407          (%o5)                           0
5408          (%i6) parse_timedate ("1899-12-31 13:00:00-11:00");
5409          (%o6)                           0
5410          (%i7) parse_timedate ("1899-12-31 08:00:00-16:00");
5411          (%o7)                           0
5412
5413 -- Function: encode_time
5414          encode_time (<year>, <month>, <day>, <hours>, <minutes>,
5415          <seconds>, <tz_offset>)
5416          encode_time (<year>, <month>, <day>, <hours>, <minutes>,
5417          <seconds>)
5418
5419     Given a time and date specified by <year>, <month>, <day>, <hours>,
5420     <minutes>, and <seconds>, 'encode_time' returns the number of
5421     seconds (possibly including a fractional part) since midnight,
5422     January 1, 1900 GMT.
5423
5424     <year> must be an integer greater than or equal to 1899.  However,
5425     1899 is allowed only if the resulting encoded time is greater than
5426     or equal to 0.
5427
5428     <month> must be an integer from 1 to 12, inclusive.
5429
5430     <day> must be an integer from 1 to <n>, inclusive, where <n> is the
5431     number of days in the month specified by <month>.
5432
5433     <hours> must be an integer from 0 to 23, inclusive.
5434
5435     <minutes> must be an integer from 0 to 59, inclusive.
5436
5437     <seconds> must be an integer, rational, or float greater than or
5438     equal to 0 and less than 60.  When <seconds> is not an integer,
5439     'encode_time' returns a rational, such that the fractional part of
5440     the return value is equal to the fractional part of <seconds>.
5441     Otherwise, <seconds> is an integer, and the return value is
5442     likewise an integer.
5443
5444     <tz_offset> measures the offset of the time zone, in hours, east
5445     (positive) or west (negative) of GMT. <tz_offset> must be an
5446     integer, rational, or float between -24 and 24, inclusive.  If
5447     <tz_offset> is not a multiple of 1/3600, it is rounded to the
5448     nearest multiple of 1/3600.
5449
5450     If <tz_offset> is not present, the offset of the local time zone is
5451     assumed.
5452
5453     See also 'decode_time'.
5454
5455     Examples:
5456
5457          (%i1) encode_time (1900, 1, 1, 0, 0, 0, 0);
5458          (%o1)                           0
5459          (%i2) encode_time (1970, 1, 1, 0, 0, 0, 0);
5460          (%o2)                      2208988800
5461          (%i3) encode_time (1970, 1, 1, 8, 30, 0, 8.5);
5462          (%o3)                      2208988800
5463          (%i4) encode_time (1969, 12, 31, 16, 0, 0, -8);
5464          (%o4)                      2208988800
5465          (%i5) encode_time (1969, 12, 31, 16, 0, 1/1000, -8);
5466                                    2208988800001
5467          (%o5)                     -------------
5468                                        1000
5469          (%i6) % - 2208988800;
5470                                         1
5471          (%o6)                         ----
5472                                        1000
5473
5474 -- Function: decode_time
5475          decode_time (<T>, <tz_offset>)
5476          decode_time (<T>)
5477
5478     Given the number of seconds (possibly including a fractional part)
5479     since midnight, January 1, 1900 GMT, returns the date and time as
5480     represented by a list comprising the year, month, day of the month,
5481     hours, minutes, seconds, and time zone offset.
5482
5483     <tz_offset> measures the offset of the time zone, in hours, east
5484     (positive) or west (negative) of GMT. <tz_offset> must be an
5485     integer, rational, or float between -24 and 24, inclusive.  If
5486     <tz_offset> is not a multiple of 1/3600, it is rounded to the
5487     nearest multiple of 1/3600.
5488
5489     If <tz_offset> is not present, the offset of the local time zone is
5490     assumed.
5491
5492     See also 'encode_time'.
5493
5494     Examples:
5495
5496          (%i1) decode_time (0, 0);
5497          (%o1)               [1900, 1, 1, 0, 0, 0, 0]
5498          (%i2) decode_time (0);
5499          (%o2)             [1899, 12, 31, 16, 0, 0, - 8]
5500          (%i3) decode_time (2208988800, 9.25);
5501                                                    37
5502          (%o3)              [1970, 1, 1, 9, 15, 0, --]
5503                                                    4
5504          (%i4) decode_time (2208988800);
5505          (%o4)             [1969, 12, 31, 16, 0, 0, - 8]
5506          (%i5) decode_time (2208988800 + 1729/1000, -6);
5507                                                1729
5508          (%o5)           [1969, 12, 31, 18, 0, ----, - 6]
5509                                                1000
5510          (%i6) decode_time (2208988800 + 1729/1000);
5511                                                1729
5512          (%o6)           [1969, 12, 31, 16, 0, ----, - 8]
5513                                                1000
5514
5515 -- Function: absolute_real_time ()
5516
5517     Returns the number of seconds since midnight, January 1, 1900 GMT.
5518     The return value is an integer.
5519
5520     See also 'elapsed_real_time' and 'elapsed_run_time'.
5521
5522     Example:
5523
5524          (%i1) absolute_real_time ();
5525          (%o1)                      3385045277
5526          (%i2) 1900 + absolute_real_time () / (365.25 * 24 * 3600);
5527          (%o2)                   2007.265612087104
5528
5529 -- Function: elapsed_real_time ()
5530
5531     Returns the number of seconds (including fractions of a second)
5532     since Maxima was most recently started or restarted.  The return
5533     value is a floating-point number.
5534
5535     See also 'absolute_real_time' and 'elapsed_run_time'.
5536
5537     Example:
5538
5539          (%i1) elapsed_real_time ();
5540          (%o1)                       2.559324
5541          (%i2) expand ((a + b)^500)$
5542          (%i3) elapsed_real_time ();
5543          (%o3)                       7.552087
5544
5545 -- Function: elapsed_run_time ()
5546
5547     Returns an estimate of the number of seconds (including fractions
5548     of a second) which Maxima has spent in computations since Maxima
5549     was most recently started or restarted.  The return value is a
5550     floating-point number.
5551
5552     See also 'absolute_real_time' and 'elapsed_real_time'.
5553
5554     Example:
5555
5556          (%i1) elapsed_run_time ();
5557          (%o1)                         0.04
5558          (%i2) expand ((a + b)^500)$
5559          (%i3) elapsed_run_time ();
5560          (%o3)                         1.26
5561
5562
5563File: maxima.info,  Node: Miscellaneous Options,  Next: Rules and Patterns,  Prev: Runtime Environment,  Up: Top
5564
556533 Miscellaneous Options
5566************************
5567
5568* Menu:
5569
5570* Introduction to Miscellaneous Options::
5571* Share::
5572* Functions and Variables for Miscellaneous Options::
5573
5574
5575File: maxima.info,  Node: Introduction to Miscellaneous Options,  Next: Share,  Prev: Miscellaneous Options,  Up: Miscellaneous Options
5576
557733.1 Introduction to Miscellaneous Options
5578==========================================
5579
5580In this section various options are discussed which have a global effect
5581on the operation of Maxima.  Also various lists such as the list of all
5582user defined functions, are discussed.
5583
5584
5585File: maxima.info,  Node: Share,  Next: Functions and Variables for Miscellaneous Options,  Prev: Introduction to Miscellaneous Options,  Up: Miscellaneous Options
5586
558733.2 Share
5588==========
5589
5590The Maxima "share" directory contains programs and other files of
5591interest to Maxima users, but not part of the core implementation of
5592Maxima.  These programs are typically loaded via 'load' or
5593'setup_autoload'.
5594
5595   ':lisp *maxima-sharedir*' displays the location of the share
5596directory within the user's file system.
5597
5598   'printfile ("share.usg")' prints an out-of-date list of share
5599packages.  Users may find it more informative to browse the share
5600directory using a file system browser.
5601
5602
5603File: maxima.info,  Node: Functions and Variables for Miscellaneous Options,  Prev: Share,  Up: Miscellaneous Options
5604
560533.3 Functions and Variables for Miscellaneous Options
5606======================================================
5607
5608 -- System variable: askexp
5609
5610     When 'asksign' is called, 'askexp' is the expression 'asksign' is
5611     testing.
5612
5613     At one time, it was possible for a user to inspect 'askexp' by
5614     entering a Maxima break with control-A.
5615
5616 -- Option variable: genindex
5617     Default value: 'i'
5618
5619     'genindex' is the alphabetic prefix used to generate the next
5620     variable of summation when necessary.
5621
5622 -- Option variable: gensumnum
5623     Default value: 0
5624
5625     'gensumnum' is the numeric suffix used to generate the next
5626     variable of summation.  If it is set to 'false' then the index will
5627     consist only of 'genindex' with no numeric suffix.
5628
5629 -- Function: gensym
5630          gensym ()
5631          gensym (<x>)
5632
5633     'gensym()' creates and returns a fresh symbol.
5634
5635     The name of the new symbol is the concatenation of a prefix, which
5636     defaults to "g", and a suffix, which is an integer that defaults to
5637     the value of an internal counter.
5638
5639     If <x> is supplied, and is a string, then that string is used as a
5640     prefix instead of "g" for this call to gensym only.
5641
5642     If <x> is supplied, and is a nonnegative integer, then that
5643     integer, instead of the value of the internal counter, is used as
5644     the suffix for this call to gensym only.
5645
5646     If and only if no explicit suffix is supplied, the internal counter
5647     is incremented after it is used.
5648
5649     Examples:
5650
5651          (%i1) gensym();
5652          (%o1)                         g887
5653          (%i2) gensym("new");
5654          (%o2)                        new888
5655          (%i3) gensym(123);
5656          (%o3)                         g123
5657
5658 -- Option variable: packagefile
5659     Default value: 'false'
5660
5661     Package designers who use 'save' or 'translate' to create packages
5662     (files) for others to use may want to set 'packagefile: true' to
5663     prevent information from being added to Maxima's information-lists
5664     (e.g.  'values', 'functions') except where necessary when the file
5665     is loaded in.  In this way, the contents of the package will not
5666     get in the user's way when he adds his own data.  Note that this
5667     will not solve the problem of possible name conflicts.  Also note
5668     that the flag simply affects what is output to the package file.
5669     Setting the flag to 'true' is also useful for creating Maxima init
5670     files.
5671
5672 -- Function: remvalue
5673          remvalue (<name_1>, ..., <name_n>)
5674          remvalue remvalue (all)
5675
5676     Removes the values of user variables <name_1>, ..., <name_n> (which
5677     can be subscripted) from the system.
5678
5679     'remvalue (all)' removes the values of all variables in 'values',
5680     the list of all variables given names by the user (as opposed to
5681     those which are automatically assigned by Maxima).
5682
5683     See also 'values'.
5684
5685 -- Function: rncombine (<expr>)
5686
5687     Transforms <expr> by combining all terms of <expr> that have
5688     identical denominators or denominators that differ from each other
5689     by numerical factors only.  This is slightly different from the
5690     behavior of 'combine', which collects terms that have identical
5691     denominators.
5692
5693     Setting 'pfeformat: true' and using 'combine' yields results
5694     similar to those that can be obtained with 'rncombine', but
5695     'rncombine' takes the additional step of cross-multiplying
5696     numerical denominator factors.  This results in neater forms, and
5697     the possibility of recognizing some cancellations.
5698
5699     'load(rncomb)' loads this function.
5700
5701 -- Function: setup_autoload (<filename>, <function_1>, ...,
5702          <function_n>)
5703
5704     Specifies that if any of <function_1>, ..., <function_n> are
5705     referenced and not yet defined, <filename> is loaded via 'load'.
5706     <filename> usually contains definitions for the functions
5707     specified, although that is not enforced.
5708
5709     'setup_autoload' does not work for 'memoizing functions'.
5710
5711     'setup_autoload' quotes its arguments.
5712
5713     Example:
5714
5715          (%i1) legendre_p (1, %pi);
5716          (%o1)                  legendre_p(1, %pi)
5717          (%i2) setup_autoload ("specfun.mac", legendre_p, ultraspherical);
5718          (%o2)                         done
5719          (%i3) ultraspherical (2, 1/2, %pi);
5720          Warning - you are redefining the Macsyma function ultraspherical
5721          Warning - you are redefining the Macsyma function legendre_p
5722                                      2
5723                           3 (%pi - 1)
5724          (%o3)            ------------ + 3 (%pi - 1) + 1
5725                                2
5726          (%i4) legendre_p (1, %pi);
5727          (%o4)                          %pi
5728          (%i5) legendre_q (1, %pi);
5729                                        %pi + 1
5730                                %pi log(-------)
5731                                        1 - %pi
5732          (%o5)                 ---------------- - 1
5733                                       2
5734
5735 -- Function: tcl_output
5736          tcl_output (<list>, <i0>, <skip>)
5737          tcl_output (<list>, <i0>)
5738          tcl_output ([<list_1>, ..., <list_n>], <i>)
5739
5740     Prints elements of a list enclosed by curly braces '{ }', suitable
5741     as part of a program in the Tcl/Tk language.
5742
5743     'tcl_output (<list>, <i0>, <skip>)' prints <list>, beginning with
5744     element <i0> and printing elements '<i0> + <skip>', '<i0> + 2
5745     <skip>', etc.
5746
5747     'tcl_output (<list>, <i0>)' is equivalent to 'tcl_output (<list>,
5748     <i0>, 2)'.
5749
5750     'tcl_output ([<list_1>, ..., <list_n>], <i>)' prints the <i>'th
5751     elements of <list_1>, ..., <list_n>.
5752
5753     Examples:
5754
5755          (%i1) tcl_output ([1, 2, 3, 4, 5, 6], 1, 3)$
5756
5757           {1.000000000     4.000000000
5758           }
5759          (%i2) tcl_output ([1, 2, 3, 4, 5, 6], 2, 3)$
5760
5761           {2.000000000     5.000000000
5762           }
5763          (%i3) tcl_output ([3/7, 5/9, 11/13, 13/17], 1)$
5764
5765           {((RAT SIMP) 3 7) ((RAT SIMP) 11 13)
5766           }
5767          (%i4) tcl_output ([x1, y1, x2, y2, x3, y3], 2)$
5768
5769           {$Y1 $Y2 $Y3
5770           }
5771          (%i5) tcl_output ([[1, 2, 3], [11, 22, 33]], 1)$
5772
5773           {SIMP 1.000000000     11.00000000
5774           }
5775
5776
5777File: maxima.info,  Node: Rules and Patterns,  Next: Sets,  Prev: Miscellaneous Options,  Up: Top
5778
577934 Rules and Patterns
5780*********************
5781
5782* Menu:
5783
5784* Introduction to Rules and Patterns::
5785* Functions and Variables for Rules and Patterns::
5786
5787
5788File: maxima.info,  Node: Introduction to Rules and Patterns,  Next: Functions and Variables for Rules and Patterns,  Prev: Rules and Patterns,  Up: Rules and Patterns
5789
579034.1 Introduction to Rules and Patterns
5791=======================================
5792
5793This section describes user-defined pattern matching and simplification
5794rules.  There are two groups of functions which implement somewhat
5795different pattern matching schemes.  In one group are 'tellsimp',
5796'tellsimpafter', 'defmatch', 'defrule', 'apply1', 'applyb1', and
5797'apply2'.  In the other group are 'let' and 'letsimp'.  Both schemes
5798define patterns in terms of pattern variables declared by
5799'matchdeclare'.
5800
5801   Pattern-matching rules defined by 'tellsimp' and 'tellsimpafter' are
5802applied automatically by the Maxima simplifier.  Rules defined by
5803'defmatch', 'defrule', and 'let' are applied by an explicit function
5804call.
5805
5806   There are additional mechanisms for rules applied to polynomials by
5807'tellrat', and for commutative and noncommutative algebra in 'affine'
5808package.
5809
5810
5811File: maxima.info,  Node: Functions and Variables for Rules and Patterns,  Prev: Introduction to Rules and Patterns,  Up: Rules and Patterns
5812
581334.2 Functions and Variables for Rules and Patterns
5814===================================================
5815
5816 -- Function: apply1 (<expr>, <rule_1>, ..., <rule_n>)
5817
5818     Repeatedly applies <rule_1> to <expr> until it fails, then
5819     repeatedly applies the same rule to all subexpressions of <expr>,
5820     left to right, until <rule_1> has failed on all subexpressions.
5821     Call the result of transforming <expr> in this manner <expr_2>.
5822     Then <rule_2> is applied in the same fashion starting at the top of
5823     <expr_2>.  When <rule_n> fails on the final subexpression, the
5824     result is returned.
5825
5826     'maxapplydepth' is the depth of the deepest subexpressions
5827     processed by 'apply1' and 'apply2'.
5828
5829     See also 'applyb1', 'apply2' and 'let'.
5830
5831 -- Function: apply2 (<expr>, <rule_1>, ..., <rule_n>)
5832
5833     If <rule_1> fails on a given subexpression, then <rule_2> is
5834     repeatedly applied, etc.  Only if all rules fail on a given
5835     subexpression is the whole set of rules repeatedly applied to the
5836     next subexpression.  If one of the rules succeeds, then the same
5837     subexpression is reprocessed, starting with the first rule.
5838
5839     'maxapplydepth' is the depth of the deepest subexpressions
5840     processed by 'apply1' and 'apply2'.
5841
5842     See also 'apply1' and 'let'.
5843
5844 -- Function: applyb1 (<expr>, <rule_1>, ..., <rule_n>)
5845
5846     Repeatedly applies <rule_1> to the deepest subexpression of <expr>
5847     until it fails, then repeatedly applies the same rule one level
5848     higher (i.e., larger subexpressions), until <rule_1> has failed on
5849     the top-level expression.  Then <rule_2> is applied in the same
5850     fashion to the result of <rule_1>.  After <rule_n> has been applied
5851     to the top-level expression, the result is returned.
5852
5853     'applyb1' is similar to 'apply1' but works from the bottom up
5854     instead of from the top down.
5855
5856     'maxapplyheight' is the maximum height which 'applyb1' reaches
5857     before giving up.
5858
5859     See also 'apply1', 'apply2' and 'let'.
5860
5861 -- Option variable: current_let_rule_package
5862     Default value: 'default_let_rule_package'
5863
5864     'current_let_rule_package' is the name of the rule package that is
5865     used by functions in the 'let' package ('letsimp', etc.)  if no
5866     other rule package is specified.  This variable may be assigned the
5867     name of any rule package defined via the 'let' command.
5868
5869     If a call such as 'letsimp (expr, rule_pkg_name)' is made, the rule
5870     package 'rule_pkg_name' is used for that function call only, and
5871     the value of 'current_let_rule_package' is not changed.
5872
5873 -- Option variable: default_let_rule_package
5874     Default value: 'default_let_rule_package'
5875
5876     'default_let_rule_package' is the name of the rule package used
5877     when one is not explicitly set by the user with 'let' or by
5878     changing the value of 'current_let_rule_package'.
5879
5880 -- Function: defmatch
5881          defmatch (<progname>, <pattern>, <x_1>, ..., <x_n>)
5882          defmatch (<progname>, <pattern>)
5883
5884     Defines a function '<progname>(<expr>, <x_1>, ..., <x_n>)' which
5885     tests <expr> to see if it matches <pattern>.
5886
5887     <pattern> is an expression containing the pattern arguments <x_1>,
5888     ..., <x_n> (if any) and some pattern variables (if any).  The
5889     pattern arguments are given explicitly as arguments to 'defmatch'
5890     while the pattern variables are declared by the 'matchdeclare'
5891     function.  Any variable not declared as a pattern variable in
5892     'matchdeclare' or as a pattern argument in 'defmatch' matches only
5893     itself.
5894
5895     The first argument to the created function <progname> is an
5896     expression to be matched against the pattern and the other
5897     arguments are the actual arguments which correspond to the dummy
5898     variables <x_1>, ..., <x_n> in the pattern.
5899
5900     If the match is successful, <progname> returns a list of equations
5901     whose left sides are the pattern arguments and pattern variables,
5902     and whose right sides are the subexpressions which the pattern
5903     arguments and variables matched.  The pattern variables, but not
5904     the pattern arguments, are assigned the subexpressions they match.
5905     If the match fails, <progname> returns 'false'.
5906
5907     A literal pattern (that is, a pattern which contains neither
5908     pattern arguments nor pattern variables) returns 'true' if the
5909     match succeeds.
5910
5911     See also 'matchdeclare', 'defrule', 'tellsimp' and 'tellsimpafter'.
5912
5913     Examples:
5914
5915     Define a function 'linearp(expr, x)' which tests 'expr' to see if
5916     it is of the form 'a*x + b' such that 'a' and 'b' do not contain
5917     'x' and 'a' is nonzero.  This match function matches expressions
5918     which are linear in any variable, because the pattern argument 'x'
5919     is given to 'defmatch'.
5920
5921          (%i1) matchdeclare (a, lambda ([e], e#0 and freeof(x, e)), b,
5922                              freeof(x));
5923          (%o1)                         done
5924          (%i2) defmatch (linearp, a*x + b, x);
5925          (%o2)                        linearp
5926          (%i3) linearp (3*z + (y + 1)*z + y^2, z);
5927                                   2
5928          (%o3)              [b = y , a = y + 4, x = z]
5929          (%i4) a;
5930          (%o4)                         y + 4
5931          (%i5) b;
5932                                          2
5933          (%o5)                          y
5934          (%i6) x;
5935          (%o6)                           x
5936
5937     Define a function 'linearp(expr)' which tests 'expr' to see if it
5938     is of the form 'a*x + b' such that 'a' and 'b' do not contain 'x'
5939     and 'a' is nonzero.  This match function only matches expressions
5940     linear in 'x', not any other variable, because no pattern argument
5941     is given to 'defmatch'.
5942
5943          (%i1) matchdeclare (a, lambda ([e], e#0 and freeof(x, e)), b,
5944                              freeof(x));
5945          (%o1)                         done
5946          (%i2) defmatch (linearp, a*x + b);
5947          (%o2)                        linearp
5948          (%i3) linearp (3*z + (y + 1)*z + y^2);
5949          (%o3)                         false
5950          (%i4) linearp (3*x + (y + 1)*x + y^2);
5951                                       2
5952          (%o4)                  [b = y , a = y + 4]
5953
5954     Define a function 'checklimits(expr)' which tests 'expr' to see if
5955     it is a definite integral.
5956
5957          (%i1) matchdeclare ([a, f], true);
5958          (%o1)                         done
5959          (%i2) constinterval (l, h) := constantp (h - l);
5960          (%o2)        constinterval(l, h) := constantp(h - l)
5961          (%i3) matchdeclare (b, constinterval (a));
5962          (%o3)                         done
5963          (%i4) matchdeclare (x, atom);
5964          (%o4)                         done
5965          (%i5) simp : false;
5966          (%o5)                         false
5967          (%i6) defmatch (checklimits, 'integrate (f, x, a, b));
5968          (%o6)                      checklimits
5969          (%i7) simp : true;
5970          (%o7)                         true
5971          (%i8) 'integrate (sin(t), t, %pi + x, 2*%pi + x);
5972                                 x + 2 %pi
5973                                /
5974                                [
5975          (%o8)                 I          sin(t) dt
5976                                ]
5977                                /
5978                                 x + %pi
5979          (%i9) checklimits (%);
5980          (%o9)    [b = x + 2 %pi, a = x + %pi, x = t, f = sin(t)]
5981
5982 -- Function: defrule (<rulename>, <pattern>, <replacement>)
5983
5984     Defines and names a replacement rule for the given pattern.  If the
5985     rule named <rulename> is applied to an expression (by 'apply1',
5986     'applyb1', or 'apply2'), every subexpression matching the pattern
5987     will be replaced by the replacement.  All variables in the
5988     replacement which have been assigned values by the pattern match
5989     are assigned those values in the replacement which is then
5990     simplified.
5991
5992     The rules themselves can be treated as functions which transform an
5993     expression by one operation of the pattern match and replacement.
5994     If the match fails, the rule function returns 'false'.
5995
5996 -- Function: disprule
5997          disprule (<rulename_1>, ..., <rulename_2>)
5998          disprule (all)
5999
6000     Display rules with the names <rulename_1>, ..., <rulename_n>, as
6001     returned by 'defrule', 'tellsimp', or 'tellsimpafter', or a pattern
6002     defined by 'defmatch'.  Each rule is displayed with an intermediate
6003     expression label ('%t').
6004
6005     'disprule (all)' displays all rules.
6006
6007     'disprule' quotes its arguments.  'disprule' returns the list of
6008     intermediate expression labels corresponding to the displayed
6009     rules.
6010
6011     See also 'letrules', which displays rules defined by 'let'.
6012
6013     Examples:
6014
6015          (%i1) tellsimpafter (foo (x, y), bar (x) + baz (y));
6016          (%o1)                   [foorule1, false]
6017          (%i2) tellsimpafter (x + y, special_add (x, y));
6018          (%o2)                   [+rule1, simplus]
6019          (%i3) defmatch (quux, mumble (x));
6020          (%o3)                         quux
6021          (%i4) disprule (foorule1, ?\+rule1, quux);
6022          (%t4)        foorule1 : foo(x, y) -> baz(y) + bar(x)
6023
6024          (%t5)          +rule1 : y + x -> special_add(x, y)
6025
6026          (%t6)                quux : mumble(x) -> []
6027
6028          (%o6)                    [%t4, %t5, %t6]
6029          (%i7) ev(%);
6030          (%o7) [foorule1 : foo(x, y) -> baz(y) + bar(x),
6031               +rule1 : y + x -> special_add(x, y), quux : mumble(x) -> []]
6032
6033 -- Function: let
6034          let (<prod>, <repl>, <predname>, <arg_1>, ..., <arg_n>)
6035          let ([<prod>, <repl>, <predname>, <arg_1>, ..., <arg_n>],
6036          <package_name>)
6037
6038     Defines a substitution rule for 'letsimp' such that <prod> is
6039     replaced by <repl>.  <prod> is a product of positive or negative
6040     powers of the following terms:
6041
6042        * Atoms which 'letsimp' will search for literally unless
6043          previous to calling 'letsimp' the 'matchdeclare' function is
6044          used to associate a predicate with the atom.  In this case
6045          'letsimp' will match the atom to any term of a product
6046          satisfying the predicate.
6047        * Kernels such as 'sin(x)', 'n!', 'f(x,y)', etc.  As with atoms
6048          above 'letsimp' will look for a literal match unless
6049          'matchdeclare' is used to associate a predicate with the
6050          argument of the kernel.
6051
6052     A term to a positive power will only match a term having at least
6053     that power.  A term to a negative power on the other hand will only
6054     match a term with a power at least as negative.  In the case of
6055     negative powers in <prod> the switch 'letrat' must be set to
6056     'true'.  See also 'letrat'.
6057
6058     If a predicate is included in the 'let' function followed by a list
6059     of arguments, a tentative match (i.e.  one that would be accepted
6060     if the predicate were omitted) is accepted only if 'predname
6061     (arg_1', ..., arg_n')' evaluates to 'true' where <arg_i'> is the
6062     value matched to <arg_i>.  The <arg_i> may be the name of any atom
6063     or the argument of any kernel appearing in <prod>.  <repl> may be
6064     any rational expression.  If any of the atoms or arguments from
6065     <prod> appear in <repl> the appropriate substitutions are made.
6066
6067     The global flag 'letrat' controls the simplification of quotients
6068     by 'letsimp'.  When 'letrat' is 'false', 'letsimp' simplifies the
6069     numerator and denominator of <expr> separately, and does not
6070     simplify the quotient.  Substitutions such as 'n!/n' goes to
6071     '(n-1)!' then fail.  When 'letrat' is 'true', then the numerator,
6072     denominator, and the quotient are simplified in that order.
6073
6074     These substitution functions allow you to work with several rule
6075     packages at once.  Each rule package can contain any number of
6076     'let' rules and is referenced by a user-defined name.  The command
6077     'let ([<prod>, <repl>, <predname>, <arg_1>, ..., <arg_n>],
6078     <package_name>)' adds the rule <predname> to the rule package
6079     <package_name>.  The command 'letsimp (<expr>, <package_name>)'
6080     applies the rules in <package_name>.  'letsimp (<expr>,
6081     <package_name1>, <package_name2>, ...)' is equivalent to 'letsimp
6082     (<expr>, <package_name1>)' followed by 'letsimp (%,
6083     <package_name2>)', ...
6084
6085     'current_let_rule_package' is the name of the rule package that is
6086     presently being used.  This variable may be assigned the name of
6087     any rule package defined via the 'let' command.  Whenever any of
6088     the functions comprising the 'let' package are called with no
6089     package name, the package named by 'current_let_rule_package' is
6090     used.  If a call such as 'letsimp (<expr>, <rule_pkg_name>)' is
6091     made, the rule package <rule_pkg_name> is used for that 'letsimp'
6092     command only, and 'current_let_rule_package' is not changed.  If
6093     not otherwise specified, 'current_let_rule_package' defaults to
6094     'default_let_rule_package'.
6095
6096          (%i1) matchdeclare ([a, a1, a2], true)$
6097          (%i2) oneless (x, y) := is (x = y-1)$
6098          (%i3) let (a1*a2!, a1!, oneless, a2, a1);
6099          (%o3)         a1 a2! --> a1! where oneless(a2, a1)
6100          (%i4) letrat: true$
6101          (%i5) let (a1!/a1, (a1-1)!);
6102                                  a1!
6103          (%o5)                   --- --> (a1 - 1)!
6104                                  a1
6105          (%i6) letsimp (n*m!*(n-1)!/m);
6106          (%o6)                      (m - 1)! n!
6107          (%i7) let (sin(a)^2, 1 - cos(a)^2);
6108                                  2               2
6109          (%o7)                sin (a) --> 1 - cos (a)
6110          (%i8) letsimp (sin(x)^4);
6111                                  4           2
6112          (%o8)                cos (x) - 2 cos (x) + 1
6113
6114 -- Option variable: letrat
6115     Default value: 'false'
6116
6117     When 'letrat' is 'false', 'letsimp' simplifies the numerator and
6118     denominator of a ratio separately, and does not simplify the
6119     quotient.
6120
6121     When 'letrat' is 'true', the numerator, denominator, and their
6122     quotient are simplified in that order.
6123
6124          (%i1) matchdeclare (n, true)$
6125          (%i2) let (n!/n, (n-1)!);
6126                                   n!
6127          (%o2)                    -- --> (n - 1)!
6128                                   n
6129          (%i3) letrat: false$
6130          (%i4) letsimp (a!/a);
6131                                         a!
6132          (%o4)                          --
6133                                         a
6134          (%i5) letrat: true$
6135          (%i6) letsimp (a!/a);
6136          (%o6)                       (a - 1)!
6137
6138 -- Function: letrules
6139          letrules ()
6140          letrules (<package_name>)
6141
6142     Displays the rules in a rule package.  'letrules ()' displays the
6143     rules in the current rule package.  'letrules (<package_name>)'
6144     displays the rules in <package_name>.
6145
6146     The current rule package is named by 'current_let_rule_package'.
6147     If not otherwise specified, 'current_let_rule_package' defaults to
6148     'default_let_rule_package'.
6149
6150     See also 'disprule', which displays rules defined by 'tellsimp' and
6151     'tellsimpafter'.
6152
6153 -- Function: letsimp
6154          letsimp (<expr>)
6155          letsimp (<expr>, <package_name>)
6156          letsimp (<expr>, <package_name_1>, ..., <package_name_n>)
6157
6158     Repeatedly applies the substitution rules defined by 'let' until no
6159     further change is made to <expr>.
6160
6161     'letsimp (<expr>)' uses the rules from 'current_let_rule_package'.
6162
6163     'letsimp (<expr>, <package_name>)' uses the rules from
6164     <package_name> without changing 'current_let_rule_package'.
6165
6166     'letsimp (<expr>, <package_name_1>, ..., <package_name_n>)' is
6167     equivalent to 'letsimp (<expr>, <package_name_1>)', followed by
6168     'letsimp (%, <package_name_2>)', and so on.
6169
6170     See also 'let'.  For other ways to do substitutions see also
6171     'subst', 'psubst', 'at' and 'ratsubst'.
6172
6173          (%i1) e0:e(k)=-(9*y(k))/(5*z)-u(k-1)/(5*z)+(4*y(k))/(5*z^2)+(3*u(k-1))/(5*z^2)+y(k)-(2*u(k-1))/5;
6174                          9 y(k)    u(k - 1)   4 y(k)   3 u(k - 1)
6175          (%o1) e(k) = (- ------) - -------- + ------ + ---------- + y(k)
6176                           5 z        5 z          2          2
6177                                                5 z        5 z
6178                                                                 2 u(k - 1)
6179                                                               - ----------
6180                                                                     5
6181          (%i2) matchdeclare(h,any)$
6182          (%i3) let(u(h)/z,u(h-1));
6183                                  u(h)
6184          (%o3)                   ---- --> u(h - 1)
6185                                   z
6186          (%i4) let(y(h)/z, y(h-1));
6187                                  y(h)
6188          (%o4)                   ---- --> y(h - 1)
6189                                   z
6190          (%i5) e1:letsimp(e0);
6191                          2 u(k - 1)           3 u(k - 3)   4 y(k - 2)
6192          (%o5) e(k) = (- ----------) + y(k) + ---------- + ----------
6193                              5                    5            5
6194                                                 u(k - 2)       9 y(k - 1)
6195                                            + (- --------) + (- ----------)
6196                                                    5               5
6197
6198 -- Option variable: let_rule_packages
6199     Default value: '[default_let_rule_package]'
6200
6201     'let_rule_packages' is a list of all user-defined let rule packages
6202     plus the default package 'default_let_rule_package'.
6203
6204 -- Function: matchdeclare (<a_1>, <pred_1>, ..., <a_n>, <pred_n>)
6205
6206     Associates a predicate <pred_k> with a variable or list of
6207     variables <a_k> so that <a_k> matches expressions for which the
6208     predicate returns anything other than 'false'.
6209
6210     A predicate is the name of a function, or a lambda expression, or a
6211     function call or lambda call missing the last argument, or 'true'
6212     or 'all'.  Any expression matches 'true' or 'all'.  If the
6213     predicate is specified as a function call or lambda call, the
6214     expression to be tested is appended to the list of arguments; the
6215     arguments are evaluated at the time the match is evaluated.
6216     Otherwise, the predicate is specified as a function name or lambda
6217     expression, and the expression to be tested is the sole argument.
6218     A predicate function need not be defined when 'matchdeclare' is
6219     called; the predicate is not evaluated until a match is attempted.
6220
6221     A predicate may return a Boolean expression as well as 'true' or
6222     'false'.  Boolean expressions are evaluated by 'is' within the
6223     constructed rule function, so it is not necessary to call 'is'
6224     within the predicate.
6225
6226     If an expression satisfies a match predicate, the match variable is
6227     assigned the expression, except for match variables which are
6228     operands of addition '+' or multiplication '*'.  Only addition and
6229     multiplication are handled specially; other n-ary operators (both
6230     built-in and user-defined) are treated like ordinary functions.
6231
6232     In the case of addition and multiplication, the match variable may
6233     be assigned a single expression which satisfies the match
6234     predicate, or a sum or product (respectively) of such expressions.
6235     Such multiple-term matching is greedy: predicates are evaluated in
6236     the order in which their associated variables appear in the match
6237     pattern, and a term which satisfies more than one predicate is
6238     taken by the first predicate which it satisfies.  Each predicate is
6239     tested against all operands of the sum or product before the next
6240     predicate is evaluated.  In addition, if 0 or 1 (respectively)
6241     satisfies a match predicate, and there are no other terms which
6242     satisfy the predicate, 0 or 1 is assigned to the match variable
6243     associated with the predicate.
6244
6245     The algorithm for processing addition and multiplication patterns
6246     makes some match results (for example, a pattern in which a "match
6247     anything" variable appears) dependent on the ordering of terms in
6248     the match pattern and in the expression to be matched.  However, if
6249     all match predicates are mutually exclusive, the match result is
6250     insensitive to ordering, as one match predicate cannot accept terms
6251     matched by another.
6252
6253     Calling 'matchdeclare' with a variable <a> as an argument changes
6254     the 'matchdeclare' property for <a>, if one was already declared;
6255     only the most recent 'matchdeclare' is in effect when a rule is
6256     defined.  Later changes to the 'matchdeclare' property (via
6257     'matchdeclare' or 'remove') do not affect existing rules.
6258
6259     'propvars (matchdeclare)' returns the list of all variables for
6260     which there is a 'matchdeclare' property.  'printprops (<a>,
6261     matchdeclare)' returns the predicate for variable 'a'.  'printprops
6262     (all, matchdeclare)' returns the list of predicates for all
6263     'matchdeclare' variables.  'remove (<a>, matchdeclare)' removes the
6264     'matchdeclare' property from <a>.
6265
6266     The functions 'defmatch', 'defrule', 'tellsimp', 'tellsimpafter',
6267     and 'let' construct rules which test expressions against patterns.
6268
6269     'matchdeclare' quotes its arguments.  'matchdeclare' always returns
6270     'done'.
6271
6272     Examples:
6273
6274     A predicate is the name of a function, or a lambda expression, or a
6275     function call or lambda call missing the last argument, or 'true'
6276     or 'all'.
6277
6278          (%i1) matchdeclare (aa, integerp);
6279          (%o1)                         done
6280          (%i2) matchdeclare (bb, lambda ([x], x > 0));
6281          (%o2)                         done
6282          (%i3) matchdeclare (cc, freeof (%e, %pi, %i));
6283          (%o3)                         done
6284          (%i4) matchdeclare (dd, lambda ([x, y], gcd (x, y) = 1) (1728));
6285          (%o4)                         done
6286          (%i5) matchdeclare (ee, true);
6287          (%o5)                         done
6288          (%i6) matchdeclare (ff, all);
6289          (%o6)                         done
6290
6291     If an expression satisfies a match predicate, the match variable is
6292     assigned the expression.
6293
6294          (%i1) matchdeclare (aa, integerp, bb, atom);
6295          (%o1)                         done
6296          (%i2) defrule (r1, bb^aa, ["integer" = aa, "atom" = bb]);
6297                              aa
6298          (%o2)        r1 : bb   -> [integer = aa, atom = bb]
6299          (%i3) r1 (%pi^8);
6300          (%o3)               [integer = 8, atom = %pi]
6301
6302     In the case of addition and multiplication, the match variable may
6303     be assigned a single expression which satisfies the match
6304     predicate, or a sum or product (respectively) of such expressions.
6305
6306          (%i1) matchdeclare (aa, atom, bb, lambda ([x], not atom(x)));
6307          (%o1)                         done
6308          (%i2) defrule (r1, aa + bb, ["all atoms" = aa, "all nonatoms" =
6309                         bb]);
6310          (%o2)  r1 : bb + aa -> [all atoms = aa, all nonatoms = bb]
6311          (%i3) r1 (8 + a*b + sin(x));
6312          (%o3)     [all atoms = 8, all nonatoms = sin(x) + a b]
6313          (%i4) defrule (r2, aa * bb, ["all atoms" = aa, "all nonatoms" =
6314                         bb]);
6315          (%o4)   r2 : aa bb -> [all atoms = aa, all nonatoms = bb]
6316          (%i5) r2 (8 * (a + b) * sin(x));
6317          (%o5)    [all atoms = 8, all nonatoms = (b + a) sin(x)]
6318
6319     When matching arguments of '+' and '*', if all match predicates are
6320     mutually exclusive, the match result is insensitive to ordering, as
6321     one match predicate cannot accept terms matched by another.
6322
6323          (%i1) matchdeclare (aa, atom, bb, lambda ([x], not atom(x)));
6324          (%o1)                         done
6325          (%i2) defrule (r1, aa + bb, ["all atoms" = aa, "all nonatoms" =
6326                         bb]);
6327          (%o2)  r1 : bb + aa -> [all atoms = aa, all nonatoms = bb]
6328          (%i3) r1 (8 + a*b + %pi + sin(x) - c + 2^n);
6329                                                               n
6330          (%o3) [all atoms = %pi + 8, all nonatoms = sin(x) + 2  - c + a b]
6331          (%i4) defrule (r2, aa * bb, ["all atoms" = aa, "all nonatoms" =
6332                         bb]);
6333          (%o4)   r2 : aa bb -> [all atoms = aa, all nonatoms = bb]
6334          (%i5) r2 (8 * (a + b) * %pi * sin(x) / c * 2^n);
6335                                                          n + 3
6336                                                 (b + a) 2      sin(x)
6337          (%o5) [all atoms = %pi, all nonatoms = ---------------------]
6338                                                           c
6339
6340     The functions 'propvars' and 'printprops' return information about
6341     match variables.
6342
6343          (%i1) matchdeclare ([aa, bb, cc], atom, [dd, ee], integerp);
6344          (%o1)                         done
6345          (%i2) matchdeclare (ff, floatnump, gg, lambda ([x], x > 100));
6346          (%o2)                         done
6347          (%i3) propvars (matchdeclare);
6348          (%o3)             [aa, bb, cc, dd, ee, ff, gg]
6349          (%i4) printprops (ee, matchdeclare);
6350          (%o4)                    [integerp(ee)]
6351          (%i5) printprops (gg, matchdeclare);
6352          (%o5)              [lambda([x], x > 100, gg)]
6353          (%i6) printprops (all, matchdeclare);
6354          (%o6) [lambda([x], x > 100, gg), floatnump(ff), integerp(ee),
6355                                integerp(dd), atom(cc), atom(bb), atom(aa)]
6356
6357 -- Option variable: maxapplydepth
6358     Default value: 10000
6359
6360     'maxapplydepth' is the maximum depth to which 'apply1' and 'apply2'
6361     will delve.
6362
6363 -- Option variable: maxapplyheight
6364     Default value: 10000
6365
6366     'maxapplyheight' is the maximum height to which 'applyb1' will
6367     reach before giving up.
6368
6369 -- Function: remlet
6370          remlet (<prod>, <name>)
6371          remlet ()
6372          remlet (all)
6373          remlet (all, <name>)
6374
6375     Deletes the substitution rule, <prod> -> repl, most recently
6376     defined by the 'let' function.  If name is supplied the rule is
6377     deleted from the rule package name.
6378
6379     'remlet()' and 'remlet(all)' delete all substitution rules from the
6380     current rule package.  If the name of a rule package is supplied,
6381     e.g.  'remlet (all, <name>)', the rule package <name> is also
6382     deleted.
6383
6384     If a substitution is to be changed using the same product, 'remlet'
6385     need not be called, just redefine the substitution using the same
6386     product (literally) with the 'let' function and the new replacement
6387     and/or predicate name.  Should 'remlet (<prod>)' now be called the
6388     original substitution rule is revived.
6389
6390     See also 'remrule', which removes a rule defined by 'tellsimp' or
6391     'tellsimpafter'.
6392
6393 -- Function: remrule
6394          remrule (<op>, <rulename>)
6395          remrule (<op>, all)
6396
6397     Removes rules defined by 'tellsimp' or 'tellsimpafter'.
6398
6399     'remrule (<op>, <rulename>)' removes the rule with the name
6400     <rulename> from the operator <op>.  When <op> is a built-in or
6401     user-defined operator (as defined by 'infix', 'prefix', etc.), <op>
6402     and <rulename> must be enclosed in double quote marks.
6403
6404     'remrule (<op>, all)' removes all rules for the operator <op>.
6405
6406     See also 'remlet', which removes a rule defined by 'let'.
6407
6408     Examples:
6409
6410          (%i1) tellsimp (foo (aa, bb), bb - aa);
6411          (%o1)                   [foorule1, false]
6412          (%i2) tellsimpafter (aa + bb, special_add (aa, bb));
6413          (%o2)                   [+rule1, simplus]
6414          (%i3) infix ("@@");
6415          (%o3)                          @@
6416          (%i4) tellsimp (aa @@ bb, bb/aa);
6417          (%o4)                   [@@rule1, false]
6418          (%i5) tellsimpafter (quux (%pi, %e), %pi - %e);
6419          (%o5)                  [quuxrule1, false]
6420          (%i6) tellsimpafter (quux (%e, %pi), %pi + %e);
6421          (%o6)             [quuxrule2, quuxrule1, false]
6422          (%i7) [foo (aa, bb), aa + bb, aa @@ bb, quux (%pi, %e),
6423                 quux (%e, %pi)];
6424                                               bb
6425          (%o7) [bb - aa, special_add(aa, bb), --, %pi - %e, %pi + %e]
6426                                               aa
6427          (%i8) remrule (foo, foorule1);
6428          (%o8)                          foo
6429          (%i9) remrule ("+", ?\+rule1);
6430          (%o9)                           +
6431          (%i10) remrule ("@@", ?\@\@rule1);
6432          (%o10)                         @@
6433          (%i11) remrule (quux, all);
6434          (%o11)                        quux
6435          (%i12) [foo (aa, bb), aa + bb, aa @@ bb, quux (%pi, %e),
6436                  quux (%e, %pi)];
6437          (%o12) [foo(aa, bb), bb + aa, aa @@ bb, quux(%pi, %e),
6438                                                             quux(%e, %pi)]
6439
6440 -- Function: tellsimp (<pattern>, <replacement>)
6441
6442     is similar to 'tellsimpafter' but places new information before old
6443     so that it is applied before the built-in simplification rules.
6444
6445     'tellsimp' is used when it is important to modify the expression
6446     before the simplifier works on it, for instance if the simplifier
6447     "knows" something about the expression, but what it returns is not
6448     to your liking.  If the simplifier "knows" something about the main
6449     operator of the expression, but is simply not doing enough for you,
6450     you probably want to use 'tellsimpafter'.
6451
6452     The pattern may not be a sum, product, single variable, or number.
6453
6454     The system variable 'rules' is the list of rules defined by
6455     'defrule', 'defmatch', 'tellsimp', and 'tellsimpafter'.
6456
6457     Examples:
6458
6459          (%i1) matchdeclare (x, freeof (%i));
6460          (%o1)                         done
6461          (%i2) %iargs: false$
6462          (%i3) tellsimp (sin(%i*x), %i*sinh(x));
6463          (%o3)                 [sinrule1, simp-%sin]
6464          (%i4) trigexpand (sin (%i*y + x));
6465          (%o4)         sin(x) cos(%i y) + %i cos(x) sinh(y)
6466          (%i5) %iargs:true$
6467          (%i6) errcatch(0^0);
6468           0
6469          0  has been generated
6470          (%o6)                          []
6471          (%i7) ev (tellsimp (0^0, 1), simp: false);
6472          (%o7)                  [^rule1, simpexpt]
6473          (%i8) 0^0;
6474          (%o8)                           1
6475          (%i9) remrule ("^", %th(2)[1]);
6476          (%o9)                           ^
6477          (%i10) tellsimp (sin(x)^2, 1 - cos(x)^2);
6478          (%o10)                 [^rule2, simpexpt]
6479          (%i11) (1 + sin(x))^2;
6480                                                2
6481          (%o11)                    (sin(x) + 1)
6482          (%i12) expand (%);
6483                                             2
6484          (%o12)               2 sin(x) - cos (x) + 2
6485          (%i13) sin(x)^2;
6486                                            2
6487          (%o13)                     1 - cos (x)
6488          (%i14) kill (rules);
6489          (%o14)                        done
6490          (%i15) matchdeclare (a, true);
6491          (%o15)                        done
6492          (%i16) tellsimp (sin(a)^2, 1 - cos(a)^2);
6493          (%o16)                 [^rule3, simpexpt]
6494          (%i17) sin(y)^2;
6495                                            2
6496          (%o17)                     1 - cos (y)
6497
6498 -- Function: tellsimpafter (<pattern>, <replacement>)
6499
6500     Defines a simplification rule which the Maxima simplifier applies
6501     after built-in simplification rules.  <pattern> is an expression,
6502     comprising pattern variables (declared by 'matchdeclare') and other
6503     atoms and operators, considered literals for the purpose of pattern
6504     matching.  <replacement> is substituted for an actual expression
6505     which matches <pattern>; pattern variables in <replacement> are
6506     assigned the values matched in the actual expression.
6507
6508     <pattern> may be any nonatomic expression in which the main
6509     operator is not a pattern variable; the simplification rule is
6510     associated with the main operator.  The names of functions (with
6511     one exception, described below), lists, and arrays may appear in
6512     <pattern> as the main operator only as literals (not pattern
6513     variables); this rules out expressions such as 'aa(x)' and 'bb[y]'
6514     as patterns, if 'aa' and 'bb' are pattern variables.  Names of
6515     functions, lists, and arrays which are pattern variables may appear
6516     as operators other than the main operator in <pattern>.
6517
6518     There is one exception to the above rule concerning names of
6519     functions.  The name of a subscripted function in an expression
6520     such as 'aa[x](y)' may be a pattern variable, because the main
6521     operator is not 'aa' but rather the Lisp atom 'mqapply'.  This is a
6522     consequence of the representation of expressions involving
6523     subscripted functions.
6524
6525     Simplification rules are applied after evaluation (if not
6526     suppressed through quotation or the flag 'noeval').  Rules
6527     established by 'tellsimpafter' are applied in the order they were
6528     defined, and after any built-in rules.  Rules are applied
6529     bottom-up, that is, applied first to subexpressions before
6530     application to the whole expression.  It may be necessary to
6531     repeatedly simplify a result (for example, via the quote-quote
6532     operator '''' or the flag 'infeval') to ensure that all rules are
6533     applied.
6534
6535     Pattern variables are treated as local variables in simplification
6536     rules.  Once a rule is defined, the value of a pattern variable
6537     does not affect the rule, and is not affected by the rule.  An
6538     assignment to a pattern variable which results from a successful
6539     rule match does not affect the current assignment (or lack of it)
6540     of the pattern variable.  However, as with all atoms in Maxima, the
6541     properties of pattern variables (as declared by 'put' and related
6542     functions) are global.
6543
6544     The rule constructed by 'tellsimpafter' is named after the main
6545     operator of <pattern>.  Rules for built-in operators, and
6546     user-defined operators defined by 'infix', 'prefix', 'postfix',
6547     'matchfix', and 'nofix', have names which are Lisp identifiers.
6548     Rules for other functions have names which are Maxima identifiers.
6549
6550     The treatment of noun and verb forms is slightly confused.  If a
6551     rule is defined for a noun (or verb) form and a rule for the
6552     corresponding verb (or noun) form already exists, the newly-defined
6553     rule applies to both forms (noun and verb).  If a rule for the
6554     corresponding verb (or noun) form does not exist, the newly-defined
6555     rule applies only to the noun (or verb) form.
6556
6557     The rule constructed by 'tellsimpafter' is an ordinary Lisp
6558     function.  If the name of the rule is '$foorule1', the construct
6559     ':lisp (trace $foorule1)' traces the function, and ':lisp
6560     (symbol-function '$foorule1)' displays its definition.
6561
6562     'tellsimpafter' quotes its arguments.  'tellsimpafter' returns the
6563     list of rules for the main operator of <pattern>, including the
6564     newly established rule.
6565
6566     See also 'matchdeclare', 'defmatch', 'defrule', 'tellsimp', 'let',
6567     'kill', 'remrule' and 'clear_rules'.
6568
6569     Examples:
6570
6571     <pattern> may be any nonatomic expression in which the main
6572     operator is not a pattern variable.
6573
6574          (%i1) matchdeclare (aa, atom, [ll, mm], listp, xx, true)$
6575          (%i2) tellsimpafter (sin (ll), map (sin, ll));
6576          (%o2)                 [sinrule1, simp-%sin]
6577          (%i3) sin ([1/6, 1/4, 1/3, 1/2, 1]*%pi);
6578                              1     1     sqrt(3)
6579          (%o3)              [-, -------, -------, 1, 0]
6580                              2  sqrt(2)     2
6581          (%i4) tellsimpafter (ll^mm, map ("^", ll, mm));
6582          (%o4)                  [^rule1, simpexpt]
6583          (%i5) [a, b, c]^[1, 2, 3];
6584                                          2   3
6585          (%o5)                      [a, b , c ]
6586          (%i6) tellsimpafter (foo (aa (xx)), aa (foo (xx)));
6587          (%o6)                   [foorule1, false]
6588          (%i7) foo (bar (u - v));
6589          (%o7)                    bar(foo(u - v))
6590
6591     Rules are applied in the order they were defined.  If two rules can
6592     match an expression, the rule which was defined first is applied.
6593
6594          (%i1) matchdeclare (aa, integerp);
6595          (%o1)                         done
6596          (%i2) tellsimpafter (foo (aa), bar_1 (aa));
6597          (%o2)                   [foorule1, false]
6598          (%i3) tellsimpafter (foo (aa), bar_2 (aa));
6599          (%o3)              [foorule2, foorule1, false]
6600          (%i4) foo (42);
6601          (%o4)                       bar_1(42)
6602
6603     Pattern variables are treated as local variables in simplification
6604     rules.  (Compare to 'defmatch', which treats pattern variables as
6605     global variables.)
6606
6607          (%i1) matchdeclare (aa, integerp, bb, atom);
6608          (%o1)                         done
6609          (%i2) tellsimpafter (foo(aa, bb), bar('aa=aa, 'bb=bb));
6610          (%o2)                   [foorule1, false]
6611          (%i3) bb: 12345;
6612          (%o3)                         12345
6613          (%i4) foo (42, %e);
6614          (%o4)                 bar(aa = 42, bb = %e)
6615          (%i5) bb;
6616          (%o5)                         12345
6617
6618     As with all atoms, properties of pattern variables are global even
6619     though values are local.  In this example, an assignment property
6620     is declared via 'define_variable'.  This is a property of the atom
6621     'bb' throughout Maxima.
6622
6623          (%i1) matchdeclare (aa, integerp, bb, atom);
6624          (%o1)                         done
6625          (%i2) tellsimpafter (foo(aa, bb), bar('aa=aa, 'bb=bb));
6626          (%o2)                   [foorule1, false]
6627          (%i3) foo (42, %e);
6628          (%o3)                 bar(aa = 42, bb = %e)
6629          (%i4) define_variable (bb, true, boolean);
6630          (%o4)                         true
6631          (%i5) foo (42, %e);
6632          translator: bb was declared with mode boolean, but it has value:
6633                                                                         %e
6634           -- an error. To debug this try: debugmode(true);
6635
6636     Rules are named after main operators.  Names of rules for built-in
6637     and user-defined operators are Lisp identifiers, while names for
6638     other functions are Maxima identifiers.
6639
6640          (%i1) tellsimpafter (foo (%pi + %e), 3*%pi);
6641          (%o1)                   [foorule1, false]
6642          (%i2) tellsimpafter (foo (%pi * %e), 17*%e);
6643          (%o2)              [foorule2, foorule1, false]
6644          (%i3) tellsimpafter (foo (%i ^ %e), -42*%i);
6645          (%o3)         [foorule3, foorule2, foorule1, false]
6646          (%i4) tellsimpafter (foo (9) + foo (13), quux (22));
6647          (%o4)                   [+rule1, simplus]
6648          (%i5) tellsimpafter (foo (9) * foo (13), blurf (22));
6649          (%o5)                  [*rule1, simptimes]
6650          (%i6) tellsimpafter (foo (9) ^ foo (13), mumble (22));
6651          (%o6)                  [^rule1, simpexpt]
6652          (%i7) rules;
6653          (%o7) [foorule1, foorule2, foorule3, +rule1, *rule1, ^rule1]
6654          (%i8) foorule_name: first (%o1);
6655          (%o8)                       foorule1
6656          (%i9) plusrule_name: first (%o4);
6657          (%o9)                        +rule1
6658          (%i10) remrule (foo, foorule1);
6659          (%o10)                         foo
6660          (%i11) remrule ("^", ?\^rule1);
6661          (%o11)                          ^
6662          (%i12) rules;
6663          (%o12)        [foorule2, foorule3, +rule1, *rule1]
6664
6665     A worked example: anticommutative multiplication.
6666
6667          (%i1) gt (i, j) := integerp(j) and i < j;
6668          (%o1)          gt(i, j) := integerp(j) and (i < j)
6669          (%i2) matchdeclare (i, integerp, j, gt(i));
6670          (%o2)                         done
6671          (%i3) tellsimpafter (s[i]^^2, 1);
6672          (%o3)                 [^^rule1, simpncexpt]
6673          (%i4) tellsimpafter (s[i] . s[j], -s[j] . s[i]);
6674          (%o4)                   [.rule1, simpnct]
6675          (%i5) s[1] . (s[1] + s[2]);
6676          (%o5)                    s  . (s  + s )
6677                                    1     2    1
6678          (%i6) expand (%);
6679          (%o6)                      1 - s  . s
6680                                          2    1
6681          (%i7) factor (expand (sum (s[i], i, 0, 9)^^5));
6682          (%o7) 100 (s  + s  + s  + s  + s  + s  + s  + s  + s  + s )
6683                      9    8    7    6    5    4    3    2    1    0
6684
6685 -- Function: clear_rules ()
6686
6687     Executes 'kill (rules)' and then resets the next rule number to 1
6688     for addition '+', multiplication '*', and exponentiation '^'.
6689
6690
6691File: maxima.info,  Node: Sets,  Next: Function Definition,  Prev: Rules and Patterns,  Up: Top
6692
669335 Sets
6694*******
6695
6696* Menu:
6697
6698* Introduction to Sets::
6699* Functions and Variables for Sets::
6700
6701
6702File: maxima.info,  Node: Introduction to Sets,  Next: Functions and Variables for Sets,  Prev: Sets,  Up: Sets
6703
670435.1 Introduction to Sets
6705=========================
6706
6707Maxima provides set functions, such as intersection and union, for
6708finite sets that are defined by explicit enumeration.  Maxima treats
6709lists and sets as distinct objects.  This feature makes it possible to
6710work with sets that have members that are either lists or sets.
6711
6712   In addition to functions for finite sets, Maxima provides some
6713functions related to combinatorics; these include the Stirling numbers
6714of the first and second kind, the Bell numbers, multinomial
6715coefficients, partitions of nonnegative integers, and a few others.
6716Maxima also defines a Kronecker delta function.
6717
671835.1.1 Usage
6719------------
6720
6721To construct a set with members 'a_1, ..., a_n', write 'set(a_1, ...,
6722a_n)' or '{a_1, ..., a_n}'; to construct the empty set, write 'set()' or
6723'{}'.  In input, 'set(...)' and '{ ... }' are equivalent.  Sets are
6724always displayed with curly braces.
6725
6726   If a member is listed more than once, simplification eliminates the
6727redundant member.
6728
6729     (%i1) set();
6730     (%o1)                          {}
6731     (%i2) set(a, b, a);
6732     (%o2)                        {a, b}
6733     (%i3) set(a, set(b));
6734     (%o3)                       {a, {b}}
6735     (%i4) set(a, [b]);
6736     (%o4)                       {a, [b]}
6737     (%i5) {};
6738     (%o5)                          {}
6739     (%i6) {a, b, a};
6740     (%o6)                        {a, b}
6741     (%i7) {a, {b}};
6742     (%o7)                       {a, {b}}
6743     (%i8) {a, [b]};
6744     (%o8)                       {a, [b]}
6745
6746   Two would-be elements <x> and <y> are redundant (i.e., considered the
6747same for the purpose of set construction) if and only if 'is(<x> = <y>)'
6748yields 'true'.  Note that 'is(equal(<x>, <y>))' can yield 'true' while
6749'is(<x> = <y>)' yields 'false'; in that case the elements <x> and <y>
6750are considered distinct.
6751
6752     (%i1) x: a/c + b/c;
6753                                   b   a
6754     (%o1)                         - + -
6755                                   c   c
6756     (%i2) y: a/c + b/c;
6757                                   b   a
6758     (%o2)                         - + -
6759                                   c   c
6760     (%i3) z: (a + b)/c;
6761                                   b + a
6762     (%o3)                         -----
6763                                     c
6764     (%i4) is (x = y);
6765     (%o4)                         true
6766     (%i5) is (y = z);
6767     (%o5)                         false
6768     (%i6) is (equal (y, z));
6769     (%o6)                         true
6770     (%i7) y - z;
6771                                b + a   b   a
6772     (%o7)                    - ----- + - + -
6773                                  c     c   c
6774     (%i8) ratsimp (%);
6775     (%o8)                           0
6776     (%i9) {x, y, z};
6777                               b + a  b   a
6778     (%o9)                    {-----, - + -}
6779                                 c    c   c
6780
6781   To construct a set from the elements of a list, use 'setify'.
6782
6783     (%i1) setify ([b, a]);
6784     (%o1)                        {a, b}
6785
6786   Set members 'x' and 'y' are equal provided 'is(x = y)' evaluates to
6787'true'.  Thus 'rat(x)' and 'x' are equal as set members; consequently,
6788
6789     (%i1) {x, rat(x)};
6790     (%o1)                          {x}
6791
6792   Further, since 'is((x - 1)*(x + 1) = x^2 - 1)' evaluates to 'false',
6793'(x - 1)*(x + 1)' and 'x^2 - 1' are distinct set members; thus
6794
6795     (%i1) {(x - 1)*(x + 1), x^2 - 1};
6796                                            2
6797     (%o1)               {(x - 1) (x + 1), x  - 1}
6798
6799   To reduce this set to a singleton set, apply 'rat' to each set
6800member:
6801
6802     (%i1) {(x - 1)*(x + 1), x^2 - 1};
6803                                            2
6804     (%o1)               {(x - 1) (x + 1), x  - 1}
6805     (%i2) map (rat, %);
6806                                   2
6807     (%o2)/R/                    {x  - 1}
6808
6809   To remove redundancies from other sets, you may need to use other
6810simplification functions.  Here is an example that uses 'trigsimp':
6811
6812     (%i1) {1, cos(x)^2 + sin(x)^2};
6813                                 2         2
6814     (%o1)                {1, sin (x) + cos (x)}
6815     (%i2) map (trigsimp, %);
6816     (%o2)                          {1}
6817
6818   A set is simplified when its members are non-redundant and sorted.
6819The current version of the set functions uses the Maxima function
6820'orderlessp' to order sets; however, future versions of the set
6821functions might use a different ordering function.
6822
6823   Some operations on sets, such as substitution, automatically force a
6824re-simplification; for example,
6825
6826     (%i1) s: {a, b, c}$
6827     (%i2) subst (c=a, s);
6828     (%o2)                        {a, b}
6829     (%i3) subst ([a=x, b=x, c=x], s);
6830     (%o3)                          {x}
6831     (%i4) map (lambda ([x], x^2), set (-1, 0, 1));
6832     (%o4)                        {0, 1}
6833
6834   Maxima treats lists and sets as distinct objects; functions such as
6835'union' and 'intersection' complain if any argument is not a set.  If
6836you need to apply a set function to a list, use the 'setify' function to
6837convert it to a set.  Thus
6838
6839     (%i1) union ([1, 2], {a, b});
6840     Function union expects a set, instead found [1,2]
6841      -- an error.  Quitting.  To debug this try debugmode(true);
6842     (%i2) union (setify ([1, 2]), {a, b});
6843     (%o2)                     {1, 2, a, b}
6844
6845   To extract all set elements of a set 's' that satisfy a predicate
6846'f', use 'subset(s, f)'.  (A predicate is a boolean-valued function.)
6847For example, to find the equations in a given set that do not depend on
6848a variable 'z', use
6849
6850     (%i1) subset ({x + y + z, x - y + 4, x + y - 5},
6851                                         lambda ([e], freeof (z, e)));
6852     (%o1)               {- y + x + 4, y + x - 5}
6853
6854   The section *note Functions and Variables for Sets:: has a complete
6855list of the set functions in Maxima.
6856
685735.1.2 Set Member Iteration
6858---------------------------
6859
6860There two ways to to iterate over set members.  One way is the use
6861'map'; for example:
6862
6863     (%i1) map (f, {a, b, c});
6864     (%o1)                  {f(a), f(b), f(c)}
6865
6866   The other way is to use 'for <x> in <s> do'
6867
6868     (%i1) s: {a, b, c};
6869     (%o1)                       {a, b, c}
6870     (%i2) for si in s do print (concat (si, 1));
6871     a1
6872     b1
6873     c1
6874     (%o2)                         done
6875
6876   The Maxima functions 'first' and 'rest' work correctly on sets.
6877Applied to a set, 'first' returns the first displayed element of a set;
6878which element that is may be implementation-dependent.  If 's' is a set,
6879then 'rest(s)' is equivalent to 'disjoin(first(s), s)'.  Currently,
6880there are other Maxima functions that work correctly on sets.  In future
6881versions of the set functions, 'first' and 'rest' may function
6882differently or not at all.
6883
6884   Maxima's 'orderless' and 'ordergreat' mechanisms are incompatible
6885with the set functions.  If you need to use either 'orderless' or
6886'ordergreat', call those functions before constructing any sets, and do
6887not call 'unorder'.
6888
688935.1.3 Authors
6890--------------
6891
6892Stavros Macrakis of Cambridge, Massachusetts and Barton Willis of the
6893University of Nebraska at Kearney (UNK) wrote the Maxima set functions
6894and their documentation.
6895
6896
6897File: maxima.info,  Node: Functions and Variables for Sets,  Prev: Introduction to Sets,  Up: Sets
6898
689935.2 Functions and Variables for Sets
6900=====================================
6901
6902 -- Function: adjoin (<x>, <a>)
6903
6904     Returns the union of the set <a> with '{<x>}'.
6905
6906     'adjoin' complains if <a> is not a literal set.
6907
6908     'adjoin(<x>, <a>)' and 'union(set(<x>), <a>)' are equivalent;
6909     however, 'adjoin' may be somewhat faster than 'union'.
6910
6911     See also 'disjoin'.
6912
6913     Examples:
6914
6915          (%i1) adjoin (c, {a, b});
6916          (%o1)                       {a, b, c}
6917          (%i2) adjoin (a, {a, b});
6918          (%o2)                        {a, b}
6919
6920 -- Function: belln (<n>)
6921
6922     Represents the n-th Bell number.  'belln(n)' is the number of
6923     partitions of a set with <n> members.
6924
6925     For nonnegative integers <n>, 'belln(<n>)' simplifies to the n-th
6926     Bell number.  'belln' does not simplify for any other arguments.
6927
6928     'belln' distributes over equations, lists, matrices, and sets.
6929
6930     Examples:
6931
6932     'belln' applied to nonnegative integers.
6933
6934          (%i1) makelist (belln (i), i, 0, 6);
6935          (%o1)               [1, 1, 2, 5, 15, 52, 203]
6936          (%i2) is (cardinality (set_partitions ({})) = belln (0));
6937          (%o2)                         true
6938          (%i3) is (cardinality (set_partitions ({1, 2, 3, 4, 5, 6})) =
6939                                 belln (6));
6940          (%o3)                         true
6941
6942     'belln' applied to arguments which are not nonnegative integers.
6943
6944          (%i1) [belln (x), belln (sqrt(3)), belln (-9)];
6945          (%o1)        [belln(x), belln(sqrt(3)), belln(- 9)]
6946
6947 -- Function: cardinality (<a>)
6948
6949     Returns the number of distinct elements of the set <a>.
6950
6951     'cardinality' ignores redundant elements even when simplification
6952     is disabled.
6953
6954     Examples:
6955
6956          (%i1) cardinality ({});
6957          (%o1)                           0
6958          (%i2) cardinality ({a, a, b, c});
6959          (%o2)                           3
6960          (%i3) simp : false;
6961          (%o3)                         false
6962          (%i4) cardinality ({a, a, b, c});
6963          (%o4)                           3
6964
6965 -- Function: cartesian_product (<b_1>, ... , <b_n>)
6966     Returns a set of lists of the form '[<x_1>, ..., <x_n>]', where
6967     <x_1>, ..., <x_n> are elements of the sets <b_1>, ...  , <b_n>,
6968     respectively.
6969
6970     'cartesian_product' complains if any argument is not a literal set.
6971
6972     See also 'cartesian_product_list'.
6973
6974     Examples:
6975
6976          (%i1) cartesian_product ({0, 1});
6977          (%o1)                      {[0], [1]}
6978          (%i2) cartesian_product ({0, 1}, {0, 1});
6979          (%o2)           {[0, 0], [0, 1], [1, 0], [1, 1]}
6980          (%i3) cartesian_product ({x}, {y}, {z});
6981          (%o3)                      {[x, y, z]}
6982          (%i4) cartesian_product ({x}, {-1, 0, 1});
6983          (%o4)              {[x, - 1], [x, 0], [x, 1]}
6984
6985 -- Function: cartesian_product_list (<b_1>, ... , <b_n>)
6986     Returns a list of lists of the form '[<x_1>, ..., <x_n>]', where
6987     <x_1>, ..., <x_n> are elements of the lists <b_1>, ...  , <b_n>,
6988     respectively, comprising all possible combinations of the elements
6989     of <b_1>, ...  , <b_n>.
6990
6991     The list returned by 'cartesian_product_list' is equivalent to the
6992     following recursive definition.  Let <L> be the list returned by
6993     'cartesian_product_list(<b_2>, ..., <b_n>)'.  Then
6994     'cartesian_product_list(<b_1>, <b_2>, ..., <b_n>)' (i.e., <b_1> in
6995     addition to <b_2>, ..., <b_n>) returns a list comprising each
6996     element of <L> appended to the first element of <b_1>, each element
6997     of <L> appended to the second element of <b_1>, each element of <L>
6998     appended to the third element of <b_1>, etc.  The order of the list
6999     returned by 'cartesian_product_list(<b_1>, <b_2>, ..., <b_n>)' may
7000     therefore be summarized by saying the lesser indices (1, 2, 3, ...)
7001     vary more slowly than the greater indices.
7002
7003     The list returned by 'cartesian_product_list' contains duplicate
7004     elements if any argument <b_1>, ..., <b_n> contains duplicates.  In
7005     this respect, 'cartesian_product_list' differs from
7006     'cartesian_product', which returns no duplicates.  Also, the
7007     ordering of the list returned 'cartesian_product_list' is
7008     determined by the order of the elements of <b_1>, ..., <b_n>.
7009     Again, this differs from 'cartesian_product', which returns a set
7010     (with order determined by 'orderlessp').
7011
7012     The length of the list returned by 'cartesian_product_list' is
7013     equal to the product of the lengths of the arguments <b_1>, ...,
7014     <b_n>.
7015
7016     See also 'cartesian_product'.
7017
7018     'cartesian_product_list' complains if any argument is not a list.
7019
7020     Examples:
7021
7022     'cartesian_product_list' returns a list of lists comprising all
7023     possible combinations.
7024
7025          (%i1) cartesian_product_list ([0, 1]);
7026          (%o1)                      [[0], [1]]
7027          (%i2) cartesian_product_list ([0, 1], [0, 1]);
7028          (%o2)           [[0, 0], [0, 1], [1, 0], [1, 1]]
7029          (%i3) cartesian_product_list ([x], [y], [z]);
7030          (%o3)                      [[x, y, z]]
7031          (%i4) cartesian_product_list ([x], [-1, 0, 1]);
7032          (%o4)              [[x, - 1], [x, 0], [x, 1]]
7033          (%i5) cartesian_product_list ([a, h, e], [c, b, 4]);
7034          (%o5) [[a, c], [a, b], [a, 4], [h, c], [h, b], [h, 4], [e, c],
7035                                                            [e, b], [e, 4]]
7036
7037     The order of the list returned by 'cartesian_product_list' may be
7038     summarized by saying the lesser indices vary more slowly than the
7039     greater indices.
7040
7041          (%i1) cartesian_product_list ([1, 2, 3], [a, b], [i, ii]);
7042          (%o1) [[1, a, i], [1, a, ii], [1, b, i], [1, b, ii], [2, a, i],
7043          [2, a, ii], [2, b, i], [2, b, ii], [3, a, i], [3, a, ii],
7044          [3, b, i], [3, b, ii]]
7045
7046     The list returned by 'cartesian_product_list' contains duplicate
7047     elements if any argument contains duplicates.
7048
7049          (%i1) cartesian_product_list ([e, h], [3, 7, 3]);
7050          (%o1)   [[e, 3], [e, 7], [e, 3], [h, 3], [h, 7], [h, 3]]
7051
7052     The length of the list returned by 'cartesian_product_list' is
7053     equal to the product of the lengths of the arguments.
7054
7055          (%i1) foo: cartesian_product_list ([1, 1, 2, 2, 3], [h, z, h]);
7056          (%o1) [[1, h], [1, z], [1, h], [1, h], [1, z], [1, h], [2, h],
7057            [2, z], [2, h], [2, h], [2, z], [2, h], [3, h], [3, z], [3, h]]
7058          (%i2) is (length (foo) = 5*3);
7059          (%o2)                         true
7060
7061 -- Function: disjoin (<x>, <a>)
7062     Returns the set <a> without the member <x>.  If <x> is not a member
7063     of <a>, return <a> unchanged.
7064
7065     'disjoin' complains if <a> is not a literal set.
7066
7067     'disjoin(<x>, <a>)', 'delete(<x>, <a>)', and 'setdifference(<a>,
7068     set(<x>))' are all equivalent.  Of these, 'disjoin' is generally
7069     faster than the others.
7070
7071     Examples:
7072
7073          (%i1) disjoin (a, {a, b, c, d});
7074          (%o1)                       {b, c, d}
7075          (%i2) disjoin (a + b, {5, z, a + b, %pi});
7076          (%o2)                      {5, %pi, z}
7077          (%i3) disjoin (a - b, {5, z, a + b, %pi});
7078          (%o3)                  {5, %pi, b + a, z}
7079
7080 -- Function: disjointp (<a>, <b>)
7081     Returns 'true' if and only if the sets <a> and <b> are disjoint.
7082
7083     'disjointp' complains if either <a> or <b> is not a literal set.
7084
7085     Examples:
7086
7087          (%i1) disjointp ({a, b, c}, {1, 2, 3});
7088          (%o1)                         true
7089          (%i2) disjointp ({a, b, 3}, {1, 2, 3});
7090          (%o2)                         false
7091
7092 -- Function: divisors (<n>)
7093
7094     Represents the set of divisors of <n>.
7095
7096     'divisors(<n>)' simplifies to a set of integers when <n> is a
7097     nonzero integer.  The set of divisors includes the members 1 and
7098     <n>.  The divisors of a negative integer are the divisors of its
7099     absolute value.
7100
7101     'divisors' distributes over equations, lists, matrices, and sets.
7102
7103     Examples:
7104
7105     We can verify that 28 is a perfect number: the sum of its divisors
7106     (except for itself) is 28.
7107
7108          (%i1) s: divisors(28);
7109          (%o1)                 {1, 2, 4, 7, 14, 28}
7110          (%i2) lreduce ("+", args(s)) - 28;
7111          (%o2)                          28
7112
7113     'divisors' is a simplifying function.  Substituting 8 for 'a' in
7114     'divisors(a)' yields the divisors without reevaluating
7115     'divisors(8)'.
7116
7117          (%i1) divisors (a);
7118          (%o1)                      divisors(a)
7119          (%i2) subst (8, a, %);
7120          (%o2)                     {1, 2, 4, 8}
7121
7122     'divisors' distributes over equations, lists, matrices, and sets.
7123
7124          (%i1) divisors (a = b);
7125          (%o1)               divisors(a) = divisors(b)
7126          (%i2) divisors ([a, b, c]);
7127          (%o2)        [divisors(a), divisors(b), divisors(c)]
7128          (%i3) divisors (matrix ([a, b], [c, d]));
7129                            [ divisors(a)  divisors(b) ]
7130          (%o3)             [                          ]
7131                            [ divisors(c)  divisors(d) ]
7132          (%i4) divisors ({a, b, c});
7133          (%o4)        {divisors(a), divisors(b), divisors(c)}
7134
7135 -- Function: elementp (<x>, <a>)
7136     Returns 'true' if and only if <x> is a member of the set <a>.
7137
7138     'elementp' complains if <a> is not a literal set.
7139
7140     Examples:
7141
7142          (%i1) elementp (sin(1), {sin(1), sin(2), sin(3)});
7143          (%o1)                         true
7144          (%i2) elementp (sin(1), {cos(1), cos(2), cos(3)});
7145          (%o2)                         false
7146
7147 -- Function: emptyp (<a>)
7148     Return 'true' if and only if <a> is the empty set or the empty
7149     list.
7150
7151     Examples:
7152
7153          (%i1) map (emptyp, [{}, []]);
7154          (%o1)                     [true, true]
7155          (%i2) map (emptyp, [a + b, {{}}, %pi]);
7156          (%o2)                 [false, false, false]
7157
7158 -- Function: equiv_classes (<s>, <F>)
7159     Returns a set of the equivalence classes of the set <s> with
7160     respect to the equivalence relation <F>.
7161
7162     <F> is a function of two variables defined on the Cartesian product
7163     of <s> with <s>.  The return value of <F> is either 'true' or
7164     'false', or an expression <expr> such that 'is(<expr>)' is either
7165     'true' or 'false'.
7166
7167     When <F> is not an equivalence relation, 'equiv_classes' accepts it
7168     without complaint, but the result is generally incorrect in that
7169     case.
7170
7171     Examples:
7172
7173     The equivalence relation is a lambda expression which returns
7174     'true' or 'false'.
7175
7176          (%i1) equiv_classes ({1, 1.0, 2, 2.0, 3, 3.0},
7177                                  lambda ([x, y], is (equal (x, y))));
7178          (%o1)            {{1, 1.0}, {2, 2.0}, {3, 3.0}}
7179
7180     The equivalence relation is the name of a relational function which
7181     'is' evaluates to 'true' or 'false'.
7182
7183          (%i1) equiv_classes ({1, 1.0, 2, 2.0, 3, 3.0}, equal);
7184          (%o1)            {{1, 1.0}, {2, 2.0}, {3, 3.0}}
7185
7186     The equivalence classes are numbers which differ by a multiple of
7187     3.
7188
7189          (%i1) equiv_classes ({1, 2, 3, 4, 5, 6, 7},
7190                               lambda ([x, y], remainder (x - y, 3) = 0));
7191          (%o1)              {{1, 4, 7}, {2, 5}, {3, 6}}
7192
7193 -- Function: every
7194          every (<f>, <s>)
7195          every (<f>, <L_1>, ..., <L_n>)
7196
7197     Returns 'true' if the predicate <f> is 'true' for all given
7198     arguments.
7199
7200     Given one set as the second argument, 'every(<f>, <s>)' returns
7201     'true' if 'is(<f>(<a_i>))' returns 'true' for all <a_i> in <s>.
7202     'every' may or may not evaluate <f> for all <a_i> in <s>.  Since
7203     sets are unordered, 'every' may evaluate '<f>(<a_i>)' in any order.
7204
7205     Given one or more lists as arguments, 'every(<f>, <L_1>, ...,
7206     <L_n>)' returns 'true' if 'is(<f>(<x_1>, ..., <x_n>))' returns
7207     'true' for all <x_1>, ..., <x_n> in <L_1>, ..., <L_n>,
7208     respectively.  'every' may or may not evaluate <f> for every
7209     combination <x_1>, ..., <x_n>.  'every' evaluates lists in the
7210     order of increasing index.
7211
7212     Given an empty set '{}' or empty lists '[]' as arguments, 'every'
7213     returns 'true'.
7214
7215     When the global flag 'maperror' is 'true', all lists <L_1>, ...,
7216     <L_n> must have equal lengths.  When 'maperror' is 'false', list
7217     arguments are effectively truncated to the length of the shortest
7218     list.
7219
7220     Return values of the predicate <f> which evaluate (via 'is') to
7221     something other than 'true' or 'false' are governed by the global
7222     flag 'prederror'.  When 'prederror' is 'true', such values are
7223     treated as 'false', and the return value from 'every' is 'false'.
7224     When 'prederror' is 'false', such values are treated as 'unknown',
7225     and the return value from 'every' is 'unknown'.
7226
7227     Examples:
7228
7229     'every' applied to a single set.  The predicate is a function of
7230     one argument.
7231
7232          (%i1) every (integerp, {1, 2, 3, 4, 5, 6});
7233          (%o1)                         true
7234          (%i2) every (atom, {1, 2, sin(3), 4, 5 + y, 6});
7235          (%o2)                         false
7236
7237     'every' applied to two lists.  The predicate is a function of two
7238     arguments.
7239
7240          (%i1) every ("=", [a, b, c], [a, b, c]);
7241          (%o1)                         true
7242          (%i2) every ("#", [a, b, c], [a, b, c]);
7243          (%o2)                         false
7244
7245     Return values of the predicate <f> which evaluate to something
7246     other than 'true' or 'false' are governed by the global flag
7247     'prederror'.
7248
7249          (%i1) prederror : false;
7250          (%o1)                         false
7251          (%i2) map (lambda ([a, b], is (a < b)), [x, y, z],
7252                             [x^2, y^2, z^2]);
7253          (%o2)              [unknown, unknown, unknown]
7254          (%i3) every ("<", [x, y, z], [x^2, y^2, z^2]);
7255          (%o3)                        unknown
7256          (%i4) prederror : true;
7257          (%o4)                         true
7258          (%i5) every ("<", [x, y, z], [x^2, y^2, z^2]);
7259          (%o5)                         false
7260
7261 -- Function: extremal_subset
7262          extremal_subset (<s>, <f>, max)
7263          extremal_subset (<s>, <f>, min)
7264
7265     Returns the subset of <s> for which the function <f> takes on
7266     maximum or minimum values.
7267
7268     'extremal_subset(<s>, <f>, max)' returns the subset of the set or
7269     list <s> for which the real-valued function <f> takes on its
7270     maximum value.
7271
7272     'extremal_subset(<s>, <f>, min)' returns the subset of the set or
7273     list <s> for which the real-valued function <f> takes on its
7274     minimum value.
7275
7276     Examples:
7277
7278          (%i1) extremal_subset ({-2, -1, 0, 1, 2}, abs, max);
7279          (%o1)                       {- 2, 2}
7280          (%i2) extremal_subset ({sqrt(2), 1.57, %pi/2}, sin, min);
7281          (%o2)                       {sqrt(2)}
7282
7283 -- Function: flatten (<expr>)
7284
7285     Collects arguments of subexpressions which have the same operator
7286     as <expr> and constructs an expression from these collected
7287     arguments.
7288
7289     Subexpressions in which the operator is different from the main
7290     operator of 'expr' are copied without modification, even if they,
7291     in turn, contain some subexpressions in which the operator is the
7292     same as for 'expr'.
7293
7294     It may be possible for 'flatten' to construct expressions in which
7295     the number of arguments differs from the declared arguments for an
7296     operator; this may provoke an error message from the simplifier or
7297     evaluator.  'flatten' does not try to detect such situations.
7298
7299     Expressions with special representations, for example, canonical
7300     rational expressions (CRE), cannot be flattened; in such cases,
7301     'flatten' returns its argument unchanged.
7302
7303     Examples:
7304
7305     Applied to a list, 'flatten' gathers all list elements that are
7306     lists.
7307
7308          (%i1) flatten ([a, b, [c, [d, e], f], [[g, h]], i, j]);
7309          (%o1)            [a, b, c, d, e, f, g, h, i, j]
7310
7311     Applied to a set, 'flatten' gathers all members of set elements
7312     that are sets.
7313
7314          (%i1) flatten ({a, {b}, {{c}}});
7315          (%o1)                       {a, b, c}
7316          (%i2) flatten ({a, {[a], {a}}});
7317          (%o2)                       {a, [a]}
7318
7319     'flatten' is similar to the effect of declaring the main operator
7320     n-ary.  However, 'flatten' has no effect on subexpressions which
7321     have an operator different from the main operator, while an n-ary
7322     declaration affects those.
7323
7324          (%i1) expr: flatten (f (g (f (f (x)))));
7325          (%o1)                     f(g(f(f(x))))
7326          (%i2) declare (f, nary);
7327          (%o2)                         done
7328          (%i3) ev (expr);
7329          (%o3)                      f(g(f(x)))
7330
7331     'flatten' treats subscripted functions the same as any other
7332     operator.
7333
7334          (%i1) flatten (f[5] (f[5] (x, y), z));
7335          (%o1)                      f (x, y, z)
7336                                      5
7337
7338     It may be possible for 'flatten' to construct expressions in which
7339     the number of arguments differs from the declared arguments for an
7340     operator;
7341
7342          (%i1) 'mod (5, 'mod (7, 4));
7343          (%o1)                   mod(5, mod(7, 4))
7344          (%i2) flatten (%);
7345          (%o2)                     mod(5, 7, 4)
7346          (%i3) ''%, nouns;
7347          Wrong number of arguments to mod
7348           -- an error.  Quitting.  To debug this try debugmode(true);
7349
7350 -- Function: full_listify (<a>)
7351     Replaces every set operator in <a> by a list operator, and returns
7352     the result.  'full_listify' replaces set operators in nested
7353     subexpressions, even if the main operator is not 'set'.
7354
7355     'listify' replaces only the main operator.
7356
7357     Examples:
7358
7359          (%i1) full_listify ({a, b, {c, {d, e, f}, g}});
7360          (%o1)               [a, b, [c, [d, e, f], g]]
7361          (%i2) full_listify (F (G ({a, b, H({c, d, e})})));
7362          (%o2)              F(G([a, b, H([c, d, e])]))
7363
7364 -- Function: fullsetify (<a>)
7365     When <a> is a list, replaces the list operator with a set operator,
7366     and applies 'fullsetify' to each member which is a set.  When <a>
7367     is not a list, it is returned unchanged.
7368
7369     'setify' replaces only the main operator.
7370
7371     Examples:
7372
7373     In line '(%o2)', the argument of 'f' isn't converted to a set
7374     because the main operator of 'f([b])' isn't a list.
7375
7376          (%i1) fullsetify ([a, [a]]);
7377          (%o1)                       {a, {a}}
7378          (%i2) fullsetify ([a, f([b])]);
7379          (%o2)                      {a, f([b])}
7380
7381 -- Function: identity (<x>)
7382
7383     Returns <x> for any argument <x>.
7384
7385     Examples:
7386
7387     'identity' may be used as a predicate when the arguments are
7388     already Boolean values.
7389
7390          (%i1) every (identity, [true, true]);
7391          (%o1)                         true
7392
7393 -- Function: integer_partitions
7394          integer_partitions (<n>)
7395          integer_partitions (<n>, <len>)
7396
7397     Returns integer partitions of <n>, that is, lists of integers which
7398     sum to <n>.
7399
7400     'integer_partitions(<n>)' returns the set of all partitions of the
7401     integer <n>.  Each partition is a list sorted from greatest to
7402     least.
7403
7404     'integer_partitions(<n>, <len>)' returns all partitions that have
7405     length <len> or less; in this case, zeros are appended to each
7406     partition with fewer than <len> terms to make each partition have
7407     exactly <len> terms.  Each partition is a list sorted from greatest
7408     to least.
7409
7410     A list [a_1, ..., a_m] is a partition of a nonnegative integer n
7411     when (1) each a_i is a nonzero integer, and (2) a_1 + ... + a_m =
7412     n. Thus 0 has no partitions.
7413
7414     Examples:
7415
7416          (%i1) integer_partitions (3);
7417          (%o1)               {[1, 1, 1], [2, 1], [3]}
7418          (%i2) s: integer_partitions (25)$
7419          (%i3) cardinality (s);
7420          (%o3)                         1958
7421          (%i4) map (lambda ([x], apply ("+", x)), s);
7422          (%o4)                         {25}
7423          (%i5) integer_partitions (5, 3);
7424          (%o5) {[2, 2, 1], [3, 1, 1], [3, 2, 0], [4, 1, 0], [5, 0, 0]}
7425          (%i6) integer_partitions (5, 2);
7426          (%o6)               {[3, 2], [4, 1], [5, 0]}
7427
7428     To find all partitions that satisfy a condition, use the function
7429     'subset'; here is an example that finds all partitions of 10 that
7430     consist of prime numbers.
7431
7432          (%i1) s: integer_partitions (10)$
7433          (%i2) cardinality (s);
7434          (%o2)                          42
7435          (%i3) xprimep(x) := integerp(x) and (x > 1) and primep(x)$
7436          (%i4) subset (s, lambda ([x], every (xprimep, x)));
7437          (%o4) {[2, 2, 2, 2, 2], [3, 3, 2, 2], [5, 3, 2], [5, 5], [7, 3]}
7438
7439 -- Function: intersect (<a_1>, ..., <a_n>)
7440
7441     'intersect' is the same as 'intersection', which see.
7442
7443 -- Function: intersection (<a_1>, ..., <a_n>)
7444     Returns a set containing the elements that are common to the sets
7445     <a_1> through <a_n>.
7446
7447     'intersection' complains if any argument is not a literal set.
7448
7449     Examples:
7450
7451          (%i1) S_1 : {a, b, c, d};
7452          (%o1)                     {a, b, c, d}
7453          (%i2) S_2 : {d, e, f, g};
7454          (%o2)                     {d, e, f, g}
7455          (%i3) S_3 : {c, d, e, f};
7456          (%o3)                     {c, d, e, f}
7457          (%i4) S_4 : {u, v, w};
7458          (%o4)                       {u, v, w}
7459          (%i5) intersection (S_1, S_2);
7460          (%o5)                          {d}
7461          (%i6) intersection (S_2, S_3);
7462          (%o6)                       {d, e, f}
7463          (%i7) intersection (S_1, S_2, S_3);
7464          (%o7)                          {d}
7465          (%i8) intersection (S_1, S_2, S_3, S_4);
7466          (%o8)                          {}
7467
7468 -- Function: kron_delta (<x1>, <x2>, ..., <xp>)
7469
7470     Represents the Kronecker delta function.
7471
7472     'kron_delta' simplifies to 1 when <xi> and <yj> are equal for all
7473     pairs of arguments, and it simplifies to 0 when <xi> and <yj> are
7474     not equal for some pair of arguments.  Equality is determined using
7475     'is(equal(xi,xj))' and inequality by 'is(notequal(xi,xj))'.  For
7476     exactly one argument, 'kron_delta' signals an error.
7477
7478     Examples:
7479
7480          (%i1) kron_delta(a,a);
7481          (%o1)                                  1
7482          (%i2) kron_delta(a,b,a,b);
7483          (%o2)                          kron_delta(a, b)
7484          (%i3) kron_delta(a,a,b,a+1);
7485          (%o3)                                  0
7486          (%i4) assume(equal(x,y));
7487          (%o4)                            [equal(x, y)]
7488          (%i5) kron_delta(x,y);
7489          (%o5)                                  1
7490
7491 -- Function: listify (<a>)
7492
7493     Returns a list containing the members of <a> when <a> is a set.
7494     Otherwise, 'listify' returns <a>.
7495
7496     'full_listify' replaces all set operators in <a> by list operators.
7497
7498     Examples:
7499
7500          (%i1) listify ({a, b, c, d});
7501          (%o1)                     [a, b, c, d]
7502          (%i2) listify (F ({a, b, c, d}));
7503          (%o2)                    F({a, b, c, d})
7504
7505 -- Function: makeset (<expr>, <x>, <s>)
7506
7507     Returns a set with members generated from the expression <expr>,
7508     where <x> is a list of variables in <expr>, and <s> is a set or
7509     list of lists.  To generate each set member, <expr> is evaluated
7510     with the variables <x> bound in parallel to a member of <s>.
7511
7512     Each member of <s> must have the same length as <x>.  The list of
7513     variables <x> must be a list of symbols, without subscripts.  Even
7514     if there is only one symbol, <x> must be a list of one element, and
7515     each member of <s> must be a list of one element.
7516
7517     See also 'makelist'.
7518
7519     Examples:
7520
7521          (%i1) makeset (i/j, [i, j], [[1, a], [2, b], [3, c], [4, d]]);
7522                                     1  2  3  4
7523          (%o1)                     {-, -, -, -}
7524                                     a  b  c  d
7525          (%i2) S : {x, y, z}$
7526          (%i3) S3 : cartesian_product (S, S, S);
7527          (%o3) {[x, x, x], [x, x, y], [x, x, z], [x, y, x], [x, y, y],
7528          [x, y, z], [x, z, x], [x, z, y], [x, z, z], [y, x, x],
7529          [y, x, y], [y, x, z], [y, y, x], [y, y, y], [y, y, z],
7530          [y, z, x], [y, z, y], [y, z, z], [z, x, x], [z, x, y],
7531          [z, x, z], [z, y, x], [z, y, y], [z, y, z], [z, z, x],
7532          [z, z, y], [z, z, z]}
7533          (%i4) makeset (i + j + k, [i, j, k], S3);
7534          (%o4) {3 x, 3 y, y + 2 x, 2 y + x, 3 z, z + 2 x, z + y + x,
7535                                                 z + 2 y, 2 z + x, 2 z + y}
7536          (%i5) makeset (sin(x), [x], {[1], [2], [3]});
7537          (%o5)               {sin(1), sin(2), sin(3)}
7538
7539 -- Function: moebius (<n>)
7540
7541     Represents the Moebius function.
7542
7543     When <n> is product of k distinct primes, 'moebius(<n>)' simplifies
7544     to (-1)^k; when <n> = 1, it simplifies to 1; and it simplifies to 0
7545     for all other positive integers.
7546
7547     'moebius' distributes over equations, lists, matrices, and sets.
7548
7549     Examples:
7550
7551          (%i1) moebius (1);
7552          (%o1)                           1
7553          (%i2) moebius (2 * 3 * 5);
7554          (%o2)                          - 1
7555          (%i3) moebius (11 * 17 * 29 * 31);
7556          (%o3)                           1
7557          (%i4) moebius (2^32);
7558          (%o4)                           0
7559          (%i5) moebius (n);
7560          (%o5)                      moebius(n)
7561          (%i6) moebius (n = 12);
7562          (%o6)                    moebius(n) = 0
7563          (%i7) moebius ([11, 11 * 13, 11 * 13 * 15]);
7564          (%o7)                      [- 1, 1, 1]
7565          (%i8) moebius (matrix ([11, 12], [13, 14]));
7566                                     [ - 1  0 ]
7567          (%o8)                      [        ]
7568                                     [ - 1  1 ]
7569          (%i9) moebius ({21, 22, 23, 24});
7570          (%o9)                      {- 1, 0, 1}
7571
7572 -- Function: multinomial_coeff
7573          multinomial_coeff (<a_1>, ..., <a_n>)
7574          multinomial_coeff ()
7575
7576     Returns the multinomial coefficient.
7577
7578     When each <a_k> is a nonnegative integer, the multinomial
7579     coefficient gives the number of ways of placing '<a_1> + ... +
7580     <a_n>' distinct objects into n boxes with <a_k> elements in the
7581     k'th box.  In general, 'multinomial_coeff (<a_1>, ..., <a_n>)'
7582     evaluates to '(<a_1> + ... + <a_n>)!/(<a_1>! ... <a_n>!)'.
7583
7584     'multinomial_coeff()' (with no arguments) evaluates to 1.
7585
7586     'minfactorial' may be able to simplify the value returned by
7587     'multinomial_coeff'.
7588
7589     Examples:
7590
7591          (%i1) multinomial_coeff (1, 2, x);
7592                                      (x + 3)!
7593          (%o1)                       --------
7594                                        2 x!
7595          (%i2) minfactorial (%);
7596                               (x + 1) (x + 2) (x + 3)
7597          (%o2)                -----------------------
7598                                          2
7599          (%i3) multinomial_coeff (-6, 2);
7600                                       (- 4)!
7601          (%o3)                       --------
7602                                      2 (- 6)!
7603          (%i4) minfactorial (%);
7604          (%o4)                          10
7605
7606 -- Function: num_distinct_partitions
7607          num_distinct_partitions (<n>)
7608          num_distinct_partitions (<n>, list)
7609
7610     Returns the number of distinct integer partitions of <n> when <n>
7611     is a nonnegative integer.  Otherwise, 'num_distinct_partitions'
7612     returns a noun expression.
7613
7614     'num_distinct_partitions(<n>, list)' returns a list of the number
7615     of distinct partitions of 1, 2, 3, ..., <n>.
7616
7617     A distinct partition of <n> is a list of distinct positive integers
7618     k_1, ..., k_m such that <n> = k_1 + ... + k_m.
7619
7620     Examples:
7621
7622          (%i1) num_distinct_partitions (12);
7623          (%o1)                          15
7624          (%i2) num_distinct_partitions (12, list);
7625          (%o2)      [1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 10, 12, 15]
7626          (%i3) num_distinct_partitions (n);
7627          (%o3)              num_distinct_partitions(n)
7628
7629 -- Function: num_partitions
7630          num_partitions (<n>)
7631          num_partitions (<n>, list)
7632
7633     Returns the number of integer partitions of <n> when <n> is a
7634     nonnegative integer.  Otherwise, 'num_partitions' returns a noun
7635     expression.
7636
7637     'num_partitions(<n>, list)' returns a list of the number of integer
7638     partitions of 1, 2, 3, ..., <n>.
7639
7640     For a nonnegative integer <n>, 'num_partitions(<n>)' is equal to
7641     'cardinality(integer_partitions(<n>))'; however, 'num_partitions'
7642     does not actually construct the set of partitions, so it is much
7643     faster.
7644
7645     Examples:
7646
7647          (%i1) num_partitions (5) = cardinality (integer_partitions (5));
7648          (%o1)                         7 = 7
7649          (%i2) num_partitions (8, list);
7650          (%o2)            [1, 1, 2, 3, 5, 7, 11, 15, 22]
7651          (%i3) num_partitions (n);
7652          (%o3)                   num_partitions(n)
7653
7654 -- Function: partition_set (<a>, <f>)
7655
7656     Partitions the set <a> according to the predicate <f>.
7657
7658     'partition_set' returns a list of two sets.  The first set
7659     comprises the elements of <a> for which <f> evaluates to 'false',
7660     and the second comprises any other elements of <a>.
7661     'partition_set' does not apply 'is' to the return value of <f>.
7662
7663     'partition_set' complains if <a> is not a literal set.
7664
7665     See also 'subset'.
7666
7667     Examples:
7668
7669          (%i1) partition_set ({2, 7, 1, 8, 2, 8}, evenp);
7670          (%o1)                   [{1, 7}, {2, 8}]
7671          (%i2) partition_set ({x, rat(y), rat(y) + z, 1},
7672                               lambda ([x], ratp(x)));
7673          (%o2)/R/              [{1, x}, {y, y + z}]
7674
7675 -- Function: permutations (<a>)
7676
7677     Returns a set of all distinct permutations of the members of the
7678     list or set <a>.  Each permutation is a list, not a set.
7679
7680     When <a> is a list, duplicate members of <a> are included in the
7681     permutations.
7682
7683     'permutations' complains if <a> is not a literal list or set.
7684
7685     See also 'random_permutation'.
7686
7687     Examples:
7688
7689          (%i1) permutations ([a, a]);
7690          (%o1)                       {[a, a]}
7691          (%i2) permutations ([a, a, b]);
7692          (%o2)           {[a, a, b], [a, b, a], [b, a, a]}
7693
7694 -- Function: powerset
7695          powerset (<a>)
7696          powerset (<a>, <n>)
7697
7698     Returns the set of all subsets of <a>, or a subset of that set.
7699
7700     'powerset(<a>)' returns the set of all subsets of the set <a>.
7701     'powerset(<a>)' has '2^cardinality(<a>)' members.
7702
7703     'powerset(<a>, <n>)' returns the set of all subsets of <a> that
7704     have cardinality <n>.
7705
7706     'powerset' complains if <a> is not a literal set, or if <n> is not
7707     a nonnegative integer.
7708
7709     Examples:
7710
7711          (%i1) powerset ({a, b, c});
7712          (%o1) {{}, {a}, {a, b}, {a, b, c}, {a, c}, {b}, {b, c}, {c}}
7713          (%i2) powerset ({w, x, y, z}, 4);
7714          (%o2)                    {{w, x, y, z}}
7715          (%i3) powerset ({w, x, y, z}, 3);
7716          (%o3)     {{w, x, y}, {w, x, z}, {w, y, z}, {x, y, z}}
7717          (%i4) powerset ({w, x, y, z}, 2);
7718          (%o4)   {{w, x}, {w, y}, {w, z}, {x, y}, {x, z}, {y, z}}
7719          (%i5) powerset ({w, x, y, z}, 1);
7720          (%o5)                 {{w}, {x}, {y}, {z}}
7721          (%i6) powerset ({w, x, y, z}, 0);
7722          (%o6)                         {{}}
7723
7724 -- Function: random_permutation (<a>)
7725
7726     Returns a random permutation of the set or list <a>, as constructed
7727     by the Knuth shuffle algorithm.
7728
7729     The return value is a new list, which is distinct from the argument
7730     even if all elements happen to be the same.  However, the elements
7731     of the argument are not copied.
7732
7733     Examples:
7734
7735          (%i1) random_permutation ([a, b, c, 1, 2, 3]);
7736          (%o1)                  [c, 1, 2, 3, a, b]
7737          (%i2) random_permutation ([a, b, c, 1, 2, 3]);
7738          (%o2)                  [b, 3, 1, c, a, 2]
7739          (%i3) random_permutation ({x + 1, y + 2, z + 3});
7740          (%o3)                 [y + 2, z + 3, x + 1]
7741          (%i4) random_permutation ({x + 1, y + 2, z + 3});
7742          (%o4)                 [x + 1, y + 2, z + 3]
7743
7744 -- Function: setdifference (<a>, <b>)
7745
7746     Returns a set containing the elements in the set <a> that are not
7747     in the set <b>.
7748
7749     'setdifference' complains if either <a> or <b> is not a literal
7750     set.
7751
7752     Examples:
7753
7754          (%i1) S_1 : {a, b, c, x, y, z};
7755          (%o1)                  {a, b, c, x, y, z}
7756          (%i2) S_2 : {aa, bb, c, x, y, zz};
7757          (%o2)                 {aa, bb, c, x, y, zz}
7758          (%i3) setdifference (S_1, S_2);
7759          (%o3)                       {a, b, z}
7760          (%i4) setdifference (S_2, S_1);
7761          (%o4)                     {aa, bb, zz}
7762          (%i5) setdifference (S_1, S_1);
7763          (%o5)                          {}
7764          (%i6) setdifference (S_1, {});
7765          (%o6)                  {a, b, c, x, y, z}
7766          (%i7) setdifference ({}, S_1);
7767          (%o7)                          {}
7768
7769 -- Function: setequalp (<a>, <b>)
7770
7771     Returns 'true' if sets <a> and <b> have the same number of elements
7772     and 'is(<x> = <y>)' is 'true' for 'x' in the elements of <a> and
7773     'y' in the elements of <b>, considered in the order determined by
7774     'listify'.  Otherwise, 'setequalp' returns 'false'.
7775
7776     Examples:
7777
7778          (%i1) setequalp ({1, 2, 3}, {1, 2, 3});
7779          (%o1)                         true
7780          (%i2) setequalp ({a, b, c}, {1, 2, 3});
7781          (%o2)                         false
7782          (%i3) setequalp ({x^2 - y^2}, {(x + y) * (x - y)});
7783          (%o3)                         false
7784
7785 -- Function: setify (<a>)
7786
7787     Constructs a set from the elements of the list <a>.  Duplicate
7788     elements of the list <a> are deleted and the elements are sorted
7789     according to the predicate 'orderlessp'.
7790
7791     'setify' complains if <a> is not a literal list.
7792
7793     Examples:
7794
7795          (%i1) setify ([1, 2, 3, a, b, c]);
7796          (%o1)                  {1, 2, 3, a, b, c}
7797          (%i2) setify ([a, b, c, a, b, c]);
7798          (%o2)                       {a, b, c}
7799          (%i3) setify ([7, 13, 11, 1, 3, 9, 5]);
7800          (%o3)                {1, 3, 5, 7, 9, 11, 13}
7801
7802 -- Function: setp (<a>)
7803
7804     Returns 'true' if and only if <a> is a Maxima set.
7805
7806     'setp' returns 'true' for unsimplified sets (that is, sets with
7807     redundant members) as well as simplified sets.
7808
7809     'setp' is equivalent to the Maxima function 'setp(a) := not atom(a)
7810     and op(a) = 'set'.
7811
7812     Examples:
7813
7814          (%i1) simp : false;
7815          (%o1)                         false
7816          (%i2) {a, a, a};
7817          (%o2)                       {a, a, a}
7818          (%i3) setp (%);
7819          (%o3)                         true
7820
7821 -- Function: set_partitions
7822          set_partitions (<a>)
7823          set_partitions (<a>, <n>)
7824
7825     Returns the set of all partitions of <a>, or a subset of that set.
7826
7827     'set_partitions(<a>, <n>)' returns a set of all decompositions of
7828     <a> into <n> nonempty disjoint subsets.
7829
7830     'set_partitions(<a>)' returns the set of all partitions.
7831
7832     'stirling2' returns the cardinality of the set of partitions of a
7833     set.
7834
7835     A set of sets P is a partition of a set S when
7836
7837       1. each member of P is a nonempty set,
7838       2. distinct members of P are disjoint,
7839       3. the union of the members of P equals S.
7840
7841     Examples:
7842
7843     The empty set is a partition of itself, the conditions 1 and 2
7844     being vacuously true.
7845
7846          (%i1) set_partitions ({});
7847          (%o1)                         {{}}
7848
7849     The cardinality of the set of partitions of a set can be found
7850     using 'stirling2'.
7851
7852          (%i1) s: {0, 1, 2, 3, 4, 5}$
7853          (%i2) p: set_partitions (s, 3)$
7854          (%i3) cardinality(p) = stirling2 (6, 3);
7855          (%o3)                        90 = 90
7856
7857     Each member of 'p' should have <n> = 3 members; let's check.
7858
7859          (%i1) s: {0, 1, 2, 3, 4, 5}$
7860          (%i2) p: set_partitions (s, 3)$
7861          (%i3) map (cardinality, p);
7862          (%o3)                          {3}
7863
7864     Finally, for each member of 'p', the union of its members should
7865     equal 's'; again let's check.
7866
7867          (%i1) s: {0, 1, 2, 3, 4, 5}$
7868          (%i2) p: set_partitions (s, 3)$
7869          (%i3) map (lambda ([x], apply (union, listify (x))), p);
7870          (%o3)                 {{0, 1, 2, 3, 4, 5}}
7871
7872 -- Function: some
7873          some (<f>, <a>)
7874          some (<f>, <L_1>, ..., <L_n>)
7875
7876     Returns 'true' if the predicate <f> is 'true' for one or more given
7877     arguments.
7878
7879     Given one set as the second argument, 'some(<f>, <s>)' returns
7880     'true' if 'is(<f>(<a_i>))' returns 'true' for one or more <a_i> in
7881     <s>.  'some' may or may not evaluate <f> for all <a_i> in <s>.
7882     Since sets are unordered, 'some' may evaluate '<f>(<a_i>)' in any
7883     order.
7884
7885     Given one or more lists as arguments, 'some(<f>, <L_1>, ...,
7886     <L_n>)' returns 'true' if 'is(<f>(<x_1>, ..., <x_n>))' returns
7887     'true' for one or more <x_1>, ..., <x_n> in <L_1>, ..., <L_n>,
7888     respectively.  'some' may or may not evaluate <f> for some
7889     combinations <x_1>, ..., <x_n>.  'some' evaluates lists in the
7890     order of increasing index.
7891
7892     Given an empty set '{}' or empty lists '[]' as arguments, 'some'
7893     returns 'false'.
7894
7895     When the global flag 'maperror' is 'true', all lists <L_1>, ...,
7896     <L_n> must have equal lengths.  When 'maperror' is 'false', list
7897     arguments are effectively truncated to the length of the shortest
7898     list.
7899
7900     Return values of the predicate <f> which evaluate (via 'is') to
7901     something other than 'true' or 'false' are governed by the global
7902     flag 'prederror'.  When 'prederror' is 'true', such values are
7903     treated as 'false'.  When 'prederror' is 'false', such values are
7904     treated as 'unknown'.
7905
7906     Examples:
7907
7908     'some' applied to a single set.  The predicate is a function of one
7909     argument.
7910
7911          (%i1) some (integerp, {1, 2, 3, 4, 5, 6});
7912          (%o1)                         true
7913          (%i2) some (atom, {1, 2, sin(3), 4, 5 + y, 6});
7914          (%o2)                         true
7915
7916     'some' applied to two lists.  The predicate is a function of two
7917     arguments.
7918
7919          (%i1) some ("=", [a, b, c], [a, b, c]);
7920          (%o1)                         true
7921          (%i2) some ("#", [a, b, c], [a, b, c]);
7922          (%o2)                         false
7923
7924     Return values of the predicate <f> which evaluate to something
7925     other than 'true' or 'false' are governed by the global flag
7926     'prederror'.
7927
7928          (%i1) prederror : false;
7929          (%o1)                         false
7930          (%i2) map (lambda ([a, b], is (a < b)), [x, y, z],
7931                     [x^2, y^2, z^2]);
7932          (%o2)              [unknown, unknown, unknown]
7933          (%i3) some ("<", [x, y, z], [x^2, y^2, z^2]);
7934          (%o3)                        unknown
7935          (%i4) some ("<", [x, y, z], [x^2, y^2, z + 1]);
7936          (%o4)                         true
7937          (%i5) prederror : true;
7938          (%o5)                         true
7939          (%i6) some ("<", [x, y, z], [x^2, y^2, z^2]);
7940          (%o6)                         false
7941          (%i7) some ("<", [x, y, z], [x^2, y^2, z + 1]);
7942          (%o7)                         true
7943
7944 -- Function: stirling1 (<n>, <m>)
7945
7946     Represents the Stirling number of the first kind.
7947
7948     When <n> and <m> are nonnegative integers, the magnitude of
7949     'stirling1 (<n>, <m>)' is the number of permutations of a set with
7950     <n> members that have <m> cycles.
7951
7952     'stirling1' is a simplifying function.  Maxima knows the following
7953     identities:
7954
7955       1. stirling1(1,k) = kron_delta(1,k), k >= 0,(see
7956          <http://dlmf.nist.gov/26.8.E2>)
7957       2. stirling1(n,n) = 1, n >= 0 (see
7958          <http://dlmf.nist.gov/26.8.E1>)
7959       3. stirling1(n,n-1) = -binomial(n,2), n >= 1, (see
7960          <http://dlmf.nist.gov/26.8.E16>)
7961       4. stirling1(n,0) = kron_delta(n,0), n >=0 (see
7962          <http://dlmf.nist.gov/26.8.E14> and
7963          <http://dlmf.nist.gov/26.8.E1>)
7964       5. stirling1(n,1) =(-1)^(n-1) (n-1)!, n >= 1 (see
7965          <http://dlmf.nist.gov/26.8.E14>)
7966       6. stirling1(n,k) = 0, n >= 0 and k > n.
7967
7968     These identities are applied when the arguments are literal
7969     integers or symbols declared as integers, and the first argument is
7970     nonnegative.  'stirling1' does not simplify for non-integer
7971     arguments.
7972
7973     Examples:
7974
7975          (%i1) declare (n, integer)$
7976          (%i2) assume (n >= 0)$
7977          (%i3) stirling1 (n, n);
7978          (%o3)                           1
7979
7980 -- Function: stirling2 (<n>, <m>)
7981
7982     Represents the Stirling number of the second kind.
7983
7984     When <n> and <m> are nonnegative integers, 'stirling2 (<n>, <m>)'
7985     is the number of ways a set with cardinality <n> can be partitioned
7986     into <m> disjoint subsets.
7987
7988     'stirling2' is a simplifying function.  Maxima knows the following
7989     identities.
7990
7991       1. stirling2(n,0) = 1, n >= 1 (see
7992          <http://dlmf.nist.gov/26.8.E17> and stirling2(0,0) = 1)
7993       2. stirling2(n,n) = 1, n >= 0, (see
7994          <http://dlmf.nist.gov/26.8.E4>)
7995       3. stirling2(n,1) = 1, n >= 1, (see
7996          <http://dlmf.nist.gov/26.8.E17> and stirling2(0,1) = 0)
7997       4. stirling2(n,2) = 2^(n-1) -1, n >= 1, (see
7998          <http://dlmf.nist.gov/26.8.E17>)
7999       5. stirling2(n,n-1) = binomial(n,2), n>= 1 (see
8000          <http://dlmf.nist.gov/26.8.E16>)
8001       6. stirling2(n,k) = 0, n >= 0 and k > n.
8002
8003     These identities are applied when the arguments are literal
8004     integers or symbols declared as integers, and the first argument is
8005     nonnegative.  'stirling2' does not simplify for non-integer
8006     arguments.
8007
8008     Examples:
8009
8010          (%i1) declare (n, integer)$
8011          (%i2) assume (n >= 0)$
8012          (%i3) stirling2 (n, n);
8013          (%o3)                           1
8014
8015     'stirling2' does not simplify for non-integer arguments.
8016
8017          (%i1) stirling2 (%pi, %pi);
8018          (%o1)                  stirling2(%pi, %pi)
8019
8020 -- Function: subset (<a>, <f>)
8021
8022     Returns the subset of the set <a> that satisfies the predicate <f>.
8023
8024     'subset' returns a set which comprises the elements of <a> for
8025     which <f> returns anything other than 'false'.  'subset' does not
8026     apply 'is' to the return value of <f>.
8027
8028     'subset' complains if <a> is not a literal set.
8029
8030     See also 'partition_set'.
8031
8032     Examples:
8033
8034          (%i1) subset ({1, 2, x, x + y, z, x + y + z}, atom);
8035          (%o1)                     {1, 2, x, z}
8036          (%i2) subset ({1, 2, 7, 8, 9, 14}, evenp);
8037          (%o2)                      {2, 8, 14}
8038
8039 -- Function: subsetp (<a>, <b>)
8040
8041     Returns 'true' if and only if the set <a> is a subset of <b>.
8042
8043     'subsetp' complains if either <a> or <b> is not a literal set.
8044
8045     Examples:
8046
8047          (%i1) subsetp ({1, 2, 3}, {a, 1, b, 2, c, 3});
8048          (%o1)                         true
8049          (%i2) subsetp ({a, 1, b, 2, c, 3}, {1, 2, 3});
8050          (%o2)                         false
8051
8052 -- Function: symmdifference (<a_1>, ..., <a_n>)
8053
8054     Returns the symmetric difference of sets <a_1>, ..., <a_n>.
8055
8056     Given two arguments, 'symmdifference (<a>, <b>)' is the same as
8057     'union (setdifference (<a>, <b>), setdifference (<b>, <a>))'.
8058
8059     'symmdifference' complains if any argument is not a literal set.
8060
8061     Examples:
8062
8063          (%i1) S_1 : {a, b, c};
8064          (%o1)                       {a, b, c}
8065          (%i2) S_2 : {1, b, c};
8066          (%o2)                       {1, b, c}
8067          (%i3) S_3 : {a, b, z};
8068          (%o3)                       {a, b, z}
8069          (%i4) symmdifference ();
8070          (%o4)                          {}
8071          (%i5) symmdifference (S_1);
8072          (%o5)                       {a, b, c}
8073          (%i6) symmdifference (S_1, S_2);
8074          (%o6)                        {1, a}
8075          (%i7) symmdifference (S_1, S_2, S_3);
8076          (%o7)                        {1, b, z}
8077          (%i8) symmdifference ({}, S_1, S_2, S_3);
8078          (%o8)                        {1,b, z}
8079
8080 -- Function: union (<a_1>, ..., <a_n>)
8081     Returns the union of the sets <a_1> through <a_n>.
8082
8083     'union()' (with no arguments) returns the empty set.
8084
8085     'union' complains if any argument is not a literal set.
8086
8087     Examples:
8088
8089          (%i1) S_1 : {a, b, c + d, %e};
8090          (%o1)                   {%e, a, b, d + c}
8091          (%i2) S_2 : {%pi, %i, %e, c + d};
8092          (%o2)                 {%e, %i, %pi, d + c}
8093          (%i3) S_3 : {17, 29, 1729, %pi, %i};
8094          (%o3)                {17, 29, 1729, %i, %pi}
8095          (%i4) union ();
8096          (%o4)                          {}
8097          (%i5) union (S_1);
8098          (%o5)                   {%e, a, b, d + c}
8099          (%i6) union (S_1, S_2);
8100          (%o6)              {%e, %i, %pi, a, b, d + c}
8101          (%i7) union (S_1, S_2, S_3);
8102          (%o7)       {17, 29, 1729, %e, %i, %pi, a, b, d + c}
8103          (%i8) union ({}, S_1, S_2, S_3);
8104          (%o8)       {17, 29, 1729, %e, %i, %pi, a, b, d + c}
8105
8106
8107File: maxima.info,  Node: Function Definition,  Next: Program Flow,  Prev: Sets,  Up: Top
8108
810936 Function Definition
8110**********************
8111
8112* Menu:
8113
8114* Introduction to Function Definition::
8115* Function::
8116* Macros::
8117* Functions and Variables for Function Definition::
8118
8119
8120File: maxima.info,  Node: Introduction to Function Definition,  Next: Function,  Prev: Function Definition,  Up: Function Definition
8121
812236.1 Introduction to Function Definition
8123========================================
8124
8125
8126File: maxima.info,  Node: Function,  Next: Macros,  Prev: Introduction to Function Definition,  Up: Function Definition
8127
812836.2 Function
8129=============
8130
813136.2.1 Ordinary functions
8132-------------------------
8133
8134To define a function in Maxima you use the ':=' operator.  E.g.
8135
8136     f(x) := sin(x)
8137
8138defines a function 'f'.  Anonymous functions may also be created using
8139'lambda'.  For example
8140
8141     lambda ([i, j], ...)
8142
8143can be used instead of 'f' where
8144
8145     f(i,j) := block ([], ...);
8146     map (lambda ([i], i+1), l)
8147
8148would return a list with 1 added to each term.
8149
8150   You may also define a function with a variable number of arguments,
8151by having a final argument which is assigned to a list of the extra
8152arguments:
8153
8154     (%i1) f ([u]) := u;
8155     (%o1)                      f([u]) := u
8156     (%i2) f (1, 2, 3, 4);
8157     (%o2)                     [1, 2, 3, 4]
8158     (%i3) f (a, b, [u]) := [a, b, u];
8159     (%o3)               f(a, b, [u]) := [a, b, u]
8160     (%i4) f (1, 2, 3, 4, 5, 6);
8161     (%o4)                 [1, 2, [3, 4, 5, 6]]
8162
8163   The right hand side of a function is an expression.  Thus if you want
8164a sequence of expressions, you do
8165
8166     f(x) := (expr1, expr2, ...., exprn);
8167
8168   and the value of <exprn> is what is returned by the function.
8169
8170   If you wish to make a 'return' from some expression inside the
8171function then you must use 'block' and 'return'.
8172
8173     block ([], expr1, ..., if (a > 10) then return(a), ..., exprn)
8174
8175   is itself an expression, and so could take the place of the right
8176hand side of a function definition.  Here it may happen that the return
8177happens earlier than the last expression.
8178
8179   The first '[]' in the block, may contain a list of variables and
8180variable assignments, such as '[a: 3, b, c: []]', which would cause the
8181three variables 'a','b',and 'c' to not refer to their global values, but
8182rather have these special values for as long as the code executes inside
8183the 'block', or inside functions called from inside the 'block'.  This
8184is called dynamic binding, since the variables last from the start of
8185the block to the time it exits.  Once you return from the 'block', or
8186throw out of it, the old values (if any) of the variables will be
8187restored.  It is certainly a good idea to protect your variables in this
8188way.  Note that the assignments in the block variables, are done in
8189parallel.  This means, that if you had used 'c: a' in the above, the
8190value of 'c' would have been the value of 'a' at the time you just
8191entered the block, but before 'a' was bound.  Thus doing something like
8192
8193     block ([a: a], expr1, ... a: a+3, ..., exprn)
8194
8195   will protect the external value of 'a' from being altered, but would
8196let you access what that value was.  Thus the right hand side of the
8197assignments, is evaluated in the entering context, before any binding
8198occurs.  Using just 'block ([x], ...)' would cause the 'x' to have
8199itself as value, just as if it would have if you entered a fresh Maxima
8200session.
8201
8202   The actual arguments to a function are treated in exactly same way as
8203the variables in a block.  Thus in
8204
8205     f(x) := (expr1, ..., exprn);
8206
8207   and
8208
8209     f(1);
8210
8211   we would have a similar context for evaluation of the expressions as
8212if we had done
8213
8214     block ([x: 1], expr1, ..., exprn)
8215
8216   Inside functions, when the right hand side of a definition, may be
8217computed at runtime, it is useful to use 'define' and possibly 'buildq'.
8218
821936.2.2 Memoizing Functions
8220--------------------------
8221
8222A memoizing function caches the result the first time it is called with
8223a given argument, and returns the stored value, without recomputing it,
8224when that same argument is given.  Memoizing functions are often called
8225array function and are in fact handled like arrays in many ways:
8226
8227   The names of memoizing functions are appended to the global list
8228'arrays' (not the global list 'functions').  'arrayinfo' returns the
8229list of arguments for which there are stored values, and 'listarray'
8230returns the stored values.  'dispfun' and 'fundef' return the array
8231function definition.
8232
8233   'arraymake' constructs an array function call, analogous to 'funmake'
8234for ordinary functions.  'arrayapply' applies an array function to its
8235arguments, analogous to 'apply' for ordinary functions.  There is
8236nothing exactly analogous to 'map' for array functions, although
8237'map(lambda([<x>], <a>[<x>]), <L>)' or 'makelist(<a>[<x>], <x>, <L>)',
8238where <L> is a list, are not too far off the mark.
8239
8240   'remarray' removes an array function definition (including any stored
8241function values), analogous to 'remfunction' for ordinary functions.
8242
8243   'kill(<a>[<x>])' removes the value of the array function <a> stored
8244for the argument <x>; the next time <a> is called with argument <x>, the
8245function value is recomputed.  However, there is no way to remove all of
8246the stored values at once, except for 'kill(<a>)' or 'remarray(<a>)',
8247which also remove the function definition.
8248
8249   Examples
8250
8251   If evaluating the function needs much time and only a limited number
8252of points is ever evaluated (which means not much time is spent looking
8253up results in a long list of cached results) Memoizing functions can
8254speed up calculations considerably.
8255     (%i1) showtime:true$
8256     Evaluation took 0.0000 seconds (0.0000 elapsed) using 0 bytes.
8257     (%i2) a[x]:=float(sum(sin(x*t),t,1,10000));
8258     Evaluation took 0.0000 seconds (0.0000 elapsed) using 0 bytes.
8259     (%o2)        a  := float(sum(sin(x t), t, 1, 10000))
8260                   x
8261     (%i3) a[1];
8262     Evaluation took 5.1250 seconds (5.1260 elapsed) using 775.250 MB.
8263     (%o3)                   1.633891021792447
8264     (%i4) a[1];
8265     Evaluation took 0.0000 seconds (0.0000 elapsed) using 0 bytes.
8266     (%o4)                   1.633891021792447
8267
8268   As the memoizing function is only evaluated once for each input value
8269changes in variables the memoizing function uses are not considered for
8270values that are already cached:
8271     (%i1) a[x]:=b*x;
8272     (%o1)                       a  := b x
8273                                  x
8274     (%i2) b:1;
8275     (%o2)                           1
8276     (%i3) a[2];
8277     (%o3)                           2
8278     (%i4) b:2;
8279     (%o4)                           2
8280     (%i5) a[1];
8281     (%o5)                           2
8282     (%i6) a[2];
8283     (%o6)                           2
8284
8285
8286File: maxima.info,  Node: Macros,  Next: Functions and Variables for Function Definition,  Prev: Function,  Up: Function Definition
8287
828836.3 Macros
8289===========
8290
8291 -- Function: buildq (<L>, <expr>)
8292
8293     Substitutes variables named by the list <L> into the expression
8294     <expr>, in parallel, without evaluating <expr>.  The resulting
8295     expression is simplified, but not evaluated, after 'buildq' carries
8296     out the substitution.
8297
8298     The elements of <L> are symbols or assignment expressions
8299     '<symbol>: <value>', evaluated in parallel.  That is, the binding
8300     of a variable on the right-hand side of an assignment is the
8301     binding of that variable in the context from which 'buildq' was
8302     called, not the binding of that variable in the variable list <L>.
8303     If some variable in <L> is not given an explicit assignment, its
8304     binding in 'buildq' is the same as in the context from which
8305     'buildq' was called.
8306
8307     Then the variables named by <L> are substituted into <expr> in
8308     parallel.  That is, the substitution for every variable is
8309     determined before any substitution is made, so the substitution for
8310     one variable has no effect on any other.
8311
8312     If any variable <x> appears as 'splice (<x>)' in <expr>, then <x>
8313     must be bound to a list, and the list is spliced (interpolated)
8314     into <expr> instead of substituted.
8315
8316     Any variables in <expr> not appearing in <L> are carried into the
8317     result verbatim, even if they have bindings in the context from
8318     which 'buildq' was called.
8319
8320     Examples
8321
8322     'a' is explicitly bound to 'x', while 'b' has the same binding
8323     (namely 29) as in the calling context, and 'c' is carried through
8324     verbatim.  The resulting expression is not evaluated until the
8325     explicit evaluation '''%'.
8326
8327          (%i1) (a: 17, b: 29, c: 1729)$
8328          (%i2) buildq ([a: x, b], a + b + c);
8329          (%o2)                      x + c + 29
8330          (%i3) ''%;
8331          (%o3)                       x + 1758
8332
8333     'e' is bound to a list, which appears as such in the arguments of
8334     'foo', and interpolated into the arguments of 'bar'.
8335
8336          (%i1) buildq ([e: [a, b, c]], foo (x, e, y));
8337          (%o1)                 foo(x, [a, b, c], y)
8338          (%i2) buildq ([e: [a, b, c]], bar (x, splice (e), y));
8339          (%o2)                  bar(x, a, b, c, y)
8340
8341     The result is simplified after substitution.  If simplification
8342     were applied before substitution, these two results would be the
8343     same.
8344
8345          (%i1) buildq ([e: [a, b, c]], splice (e) + splice (e));
8346          (%o1)                    2 c + 2 b + 2 a
8347          (%i2) buildq ([e: [a, b, c]], 2 * splice (e));
8348          (%o2)                        2 a b c
8349
8350     The variables in <L> are bound in parallel; if bound sequentially,
8351     the first result would be 'foo (b, b)'.  Substitutions are carried
8352     out in parallel; compare the second result with the result of
8353     'subst', which carries out substitutions sequentially.
8354
8355          (%i1) buildq ([a: b, b: a], foo (a, b));
8356          (%o1)                       foo(b, a)
8357          (%i2) buildq ([u: v, v: w, w: x, x: y, y: z, z: u],
8358                        bar (u, v, w, x, y, z));
8359          (%o2)                 bar(v, w, x, y, z, u)
8360          (%i3) subst ([u=v, v=w, w=x, x=y, y=z, z=u],
8361                       bar (u, v, w, x, y, z));
8362          (%o3)                 bar(u, u, u, u, u, u)
8363
8364     Construct a list of equations with some variables or expressions on
8365     the left-hand side and their values on the right-hand side.
8366     'macroexpand' shows the expression returned by 'show_values'.
8367
8368          (%i1) show_values ([L]) ::= buildq ([L], map ("=", 'L, L));
8369          (%o1)   show_values([L]) ::= buildq([L], map("=", 'L, L))
8370          (%i2) (a: 17, b: 29, c: 1729)$
8371          (%i3) show_values (a, b, c - a - b);
8372          (%o3)          [a = 17, b = 29, c - b - a = 1683]
8373          (%i4) macroexpand (show_values (a, b, c - a - b));
8374          (%o4)    map(=, '([a, b, c - b - a]), [a, b, c - b - a])
8375
8376     Given a function of several arguments, create another function for
8377     which some of the arguments are fixed.
8378
8379          (%i1) curry (f, [a]) :=
8380                  buildq ([f, a], lambda ([[x]], apply (f, append (a, x))))$
8381          (%i2) by3 : curry ("*", 3);
8382          (%o2)        lambda([[x]], apply(*, append([3], x)))
8383          (%i3) by3 (a + b);
8384          (%o3)                       3 (b + a)
8385
8386 -- Function: macroexpand (<expr>)
8387
8388     Returns the macro expansion of <expr> without evaluating it, when
8389     'expr' is a macro function call.  Otherwise, 'macroexpand' returns
8390     <expr>.
8391
8392     If the expansion of <expr> yields another macro function call, that
8393     macro function call is also expanded.
8394
8395     'macroexpand' quotes its argument.  However, if the expansion of a
8396     macro function call has side effects, those side effects are
8397     executed.
8398
8399     See also '::=', 'macros', and 'macroexpand1'..
8400
8401     Examples
8402
8403          (%i1) g (x) ::= x / 99;
8404                                              x
8405          (%o1)                      g(x) ::= --
8406                                              99
8407          (%i2) h (x) ::= buildq ([x], g (x - a));
8408          (%o2)            h(x) ::= buildq([x], g(x - a))
8409          (%i3) a: 1234;
8410          (%o3)                         1234
8411          (%i4) macroexpand (h (y));
8412                                        y - a
8413          (%o4)                         -----
8414                                         99
8415          (%i5) h (y);
8416                                      y - 1234
8417          (%o5)                       --------
8418                                         99
8419
8420 -- Function: macroexpand1 (<expr>)
8421
8422     Returns the macro expansion of <expr> without evaluating it, when
8423     'expr' is a macro function call.  Otherwise, 'macroexpand1' returns
8424     <expr>.
8425
8426     'macroexpand1' quotes its argument.  However, if the expansion of a
8427     macro function call has side effects, those side effects are
8428     executed.
8429
8430     If the expansion of <expr> yields another macro function call, that
8431     macro function call is not expanded.
8432
8433     See also '::=', 'macros', and 'macroexpand'.
8434
8435     Examples
8436
8437          (%i1) g (x) ::= x / 99;
8438                                              x
8439          (%o1)                      g(x) ::= --
8440                                              99
8441          (%i2) h (x) ::= buildq ([x], g (x - a));
8442          (%o2)            h(x) ::= buildq([x], g(x - a))
8443          (%i3) a: 1234;
8444          (%o3)                         1234
8445          (%i4) macroexpand1 (h (y));
8446          (%o4)                       g(y - a)
8447          (%i5) h (y);
8448                                      y - 1234
8449          (%o5)                       --------
8450                                         99
8451
8452 -- Global variable: macros
8453     Default value: '[]'
8454
8455     'macros' is the list of user-defined macro functions.  The macro
8456     function definition operator '::=' puts a new macro function onto
8457     this list, and 'kill', 'remove', and 'remfunction' remove macro
8458     functions from the list.
8459
8460     See also 'infolists'.
8461
8462 -- Function: splice (<a>)
8463
8464     Splices (interpolates) the list named by the atom <a> into an
8465     expression, but only if 'splice' appears within 'buildq';
8466     otherwise, 'splice' is treated as an undefined function.  If
8467     appearing within 'buildq' as <a> alone (without 'splice'), <a> is
8468     substituted (not interpolated) as a list into the result.  The
8469     argument of 'splice' can only be an atom; it cannot be a literal
8470     list or an expression which yields a list.
8471
8472     Typically 'splice' supplies the arguments for a function or
8473     operator.  For a function 'f', the expression 'f (splice (<a>))'
8474     within 'buildq' expands to 'f (<a>[1], <a>[2], <a>[3], ...)'.  For
8475     an operator 'o', the expression '"o" (splice (<a>))' within
8476     'buildq' expands to '"o" (<a>[1], <a>[2], <a>[3], ...)', where 'o'
8477     may be any type of operator (typically one which takes multiple
8478     arguments).  Note that the operator must be enclosed in double
8479     quotes '"'.
8480
8481     Examples
8482
8483          (%i1) buildq ([x: [1, %pi, z - y]], foo (splice (x)) / length (x));
8484                                 foo(1, %pi, z - y)
8485          (%o1)                -----------------------
8486                               length([1, %pi, z - y])
8487          (%i2) buildq ([x: [1, %pi]], "/" (splice (x)));
8488                                          1
8489          (%o2)                          ---
8490                                         %pi
8491          (%i3) matchfix ("<>", "<>");
8492          (%o3)                          <>
8493          (%i4) buildq ([x: [1, %pi, z - y]], "<>" (splice (x)));
8494          (%o4)                   <>1, %pi, z - y<>
8495
8496
8497File: maxima.info,  Node: Functions and Variables for Function Definition,  Prev: Macros,  Up: Function Definition
8498
849936.4 Functions and Variables for Function Definition
8500====================================================
8501
8502 -- Function: apply (<F>, [<x_1>, ..., <x_n>])
8503
8504     Constructs and evaluates an expression '<F>(<arg_1>, ...,
8505     <arg_n>)'.
8506
8507     'apply' does not attempt to distinguish a 'memoizing function' from
8508     an ordinary function; when <F> is the name of a memoizing function,
8509     'apply' evaluates '<F>(...)' (that is, a function call with
8510     parentheses instead of square brackets).  'arrayapply' evaluates a
8511     function call with square brackets in this case.
8512
8513     See also 'funmake' and 'args'.
8514
8515     Examples:
8516
8517     'apply' evaluates its arguments.  In this example, 'min' is applied
8518     to the value of 'L'.
8519
8520          (%i1) L : [1, 5, -10.2, 4, 3];
8521          (%o1)                 [1, 5, - 10.2, 4, 3]
8522          (%i2) apply (min, L);
8523          (%o2)                        - 10.2
8524
8525     'apply' evaluates arguments, even if the function <F> quotes them.
8526
8527          (%i1) F (x) := x / 1729;
8528                                             x
8529          (%o1)                     F(x) := ----
8530                                            1729
8531          (%i2) fname : F;
8532          (%o2)                           F
8533          (%i3) dispfun (F);
8534                                             x
8535          (%t3)                     F(x) := ----
8536                                            1729
8537
8538          (%o3)                         [%t3]
8539          (%i4) dispfun (fname);
8540          fundef: no such function: fname
8541           -- an error. To debug this try: debugmode(true);
8542          (%i5) apply (dispfun, [fname]);
8543                                             x
8544          (%t5)                     F(x) := ----
8545                                            1729
8546
8547          (%o5)                         [%t5]
8548
8549     'apply' evaluates the function name <F>.  Single quote ''' defeats
8550     evaluation.  'demoivre' is the name of a global variable and also a
8551     function.
8552
8553          (%i1) demoivre;
8554          (%o1)                         false
8555          (%i2) demoivre (exp (%i * x));
8556          (%o2)                  %i sin(x) + cos(x)
8557          (%i3) apply (demoivre, [exp (%i * x)]);
8558          apply: found false where a function was expected.
8559           -- an error. To debug this try: debugmode(true);
8560          (%i4) apply ('demoivre, [exp (%i * x)]);
8561          (%o4)                  %i sin(x) + cos(x)
8562
8563     How to convert a nested list into a matrix:
8564
8565          (%i1) a:[[1,2],[3,4]];
8566          (%o1)                   [[1, 2], [3, 4]]
8567          (%i2) apply(matrix,a);
8568                                      [ 1  2 ]
8569          (%o2)                       [      ]
8570                                      [ 3  4 ]
8571
8572 -- Function: block
8573          block ([<v_1>, ..., <v_m>], <expr_1>, ..., <expr_n>)
8574          block (<expr_1>, ..., <expr_n>)
8575
8576     The function 'block' allows to make the variables <v_1>, ..., <v_m>
8577     to be local for a sequence of commands.  If these variables are
8578     already bound 'block' saves the current values of the variables
8579     <v_1>, ..., <v_m> (if any) upon entry to the block, then unbinds
8580     the variables so that they evaluate to themselves; The local
8581     variables may be bound to arbitrary values within the block but
8582     when the block is exited the saved values are restored, and the
8583     values assigned within the block are lost.
8584
8585     If there is no need to define local variables then the list at the
8586     beginning of the 'block' command may be omitted.  In this case if
8587     neither 'return' nor 'go' are used 'block' behaves similar to the
8588     following construct:
8589
8590          ( expr_1, expr_2,... , expr_n );
8591
8592     <expr_1>, ..., <expr_n> will be evaluated in sequence and the value
8593     of the last expression will be returned.  The sequence can be
8594     modified by the 'go', 'throw', and 'return' functions.  The last
8595     expression is <expr_n> unless 'return' or an expression containing
8596     'throw' is evaluated.
8597
8598     The declaration 'local(<v_1>, ..., <v_m>)' within 'block' saves the
8599     properties associated with the symbols <v_1>, ..., <v_m>, removes
8600     any properties before evaluating other expressions, and restores
8601     any saved properties on exit from the block.  Some declarations are
8602     implemented as properties of a symbol, including ':=', 'array',
8603     'dependencies', 'atvalue', 'matchdeclare', 'atomgrad', 'constant',
8604     'nonscalar', 'assume', and some others.  The effect of 'local' is
8605     to make such declarations effective only within the block;
8606     otherwise declarations within a block are actually global
8607     declarations.
8608
8609     'block' may appear within another 'block'.  Local variables are
8610     established each time a new 'block' is evaluated.  Local variables
8611     appear to be global to any enclosed blocks.  If a variable is
8612     non-local in a block, its value is the value most recently assigned
8613     by an enclosing block, if any, otherwise, it is the value of the
8614     variable in the global environment.  This policy may coincide with
8615     the usual understanding of "dynamic scope".
8616
8617     The value of the block is the value of the last statement or the
8618     value of the argument to the function 'return' which may be used to
8619     exit explicitly from the block.  The function 'go' may be used to
8620     transfer control to the statement of the block that is tagged with
8621     the argument to 'go'.  To tag a statement, precede it by an atomic
8622     argument as another statement in the block.  For example: 'block
8623     ([x], x:1, loop, x: x+1, ..., go(loop), ...)'.  The argument to
8624     'go' must be the name of a tag appearing within the block.  One
8625     cannot use 'go' to transfer to a tag in a block other than the one
8626     containing the 'go'.
8627
8628     Blocks typically appear on the right side of a function definition
8629     but can be used in other places as well.
8630
8631     See also 'return' and 'go'.
8632
8633 -- Function: break (<expr_1>, ..., <expr_n>)
8634
8635     Evaluates and prints <expr_1>, ..., <expr_n> and then causes a
8636     Maxima break at which point the user can examine and change his
8637     environment.  Upon typing 'exit;' the computation resumes.
8638
8639 -- Function: catch (<expr_1>, ..., <expr_n>)
8640
8641     Evaluates <expr_1>, ..., <expr_n> one by one; if any leads to the
8642     evaluation of an expression of the form 'throw (arg)', then the
8643     value of the 'catch' is the value of 'throw (arg)', and no further
8644     expressions are evaluated.  This "non-local return" thus goes
8645     through any depth of nesting to the nearest enclosing 'catch'.  If
8646     there is no 'catch' enclosing a 'throw', an error message is
8647     printed.
8648
8649     If the evaluation of the arguments does not lead to the evaluation
8650     of any 'throw' then the value of 'catch' is the value of <expr_n>.
8651
8652          (%i1) lambda ([x], if x < 0 then throw(x) else f(x))$
8653          (%i2) g(l) := catch (map (''%, l))$
8654          (%i3) g ([1, 2, 3, 7]);
8655          (%o3)               [f(1), f(2), f(3), f(7)]
8656          (%i4) g ([1, 2, -3, 7]);
8657          (%o4)                          - 3
8658
8659     The function 'g' returns a list of 'f' of each element of 'l' if
8660     'l' consists only of non-negative numbers; otherwise, 'g' "catches"
8661     the first negative element of 'l' and "throws" it up.
8662
8663 -- Function: compfile
8664          compfile (<filename>, <f_1>, ..., <f_n>)
8665          compfile (<filename>, functions)
8666          compfile (<filename>, all)
8667
8668     Translates Maxima functions into Lisp and writes the translated
8669     code into the file <filename>.
8670
8671     'compfile(<filename>, <f_1>, ..., <f_n>)' translates the specified
8672     functions.  'compfile (<filename>, functions)' and 'compfile
8673     (<filename>, all)' translate all user-defined functions.
8674
8675     The Lisp translations are not evaluated, nor is the output file
8676     processed by the Lisp compiler.  'translate' creates and evaluates
8677     Lisp translations.  'compile_file' translates Maxima into Lisp, and
8678     then executes the Lisp compiler.
8679
8680     See also 'translate', 'translate_file', and 'compile_file'.
8681
8682 -- Function: compile
8683          compile (<f_1>, ..., <f_n>)
8684          compile (functions)
8685          compile (all)
8686
8687     Translates Maxima functions <f_1>, ..., <f_n> into Lisp, evaluates
8688     the Lisp translations, and calls the Lisp function 'COMPILE' on
8689     each translated function.  'compile' returns a list of the names of
8690     the compiled functions.
8691
8692     'compile (all)' or 'compile (functions)' compiles all user-defined
8693     functions.
8694
8695     'compile' quotes its arguments; the quote-quote operator ''''
8696     defeats quotation.
8697
8698     Compiling a function to native code can mean a big increase in
8699     speed and might cause the memory footprint to reduce drastically.
8700     Code tends to be especially effective when the flexibility it needs
8701     to provide is limited.  If compilation doesn't provide the speed
8702     that is needed a few ways to limit the code's functionality are the
8703     following:
8704        * If the function accesses global variables the complexity of
8705          the function can be drastically be reduced by limiting these
8706          variables to one data type, for example using 'mode_declare'
8707          or a statement like the following one: 'put(x_1, bigfloat,
8708          numerical_type)'
8709        * The compiler might warn about undeclared variables if text
8710          could either be a named option to a command or (if they are
8711          assigned a value to) the name of a variable.  Prepending the
8712          option with a single quote ''' tells the compiler that the
8713          text is meant as an option.
8714
8715 -- Function: define
8716          define (<f>(<x_1>, ..., <x_n>), <expr>)
8717          define (<f>[<x_1>, ..., <x_n>], <expr>)
8718          define (<f>[<x_1>, ..., <x_n>](<y_1>, ..., <y_m>), <expr>)
8719          define (funmake (<f>, [<x_1>, ..., <x_n>]), <expr>)
8720          define (arraymake (<f>, [<x_1>, ..., <x_n>]), <expr>)
8721          define (ev (<expr_1>), <expr_2>)
8722
8723     Defines a function named <f> with arguments <x_1>, ..., <x_n> and
8724     function body <expr>.  'define' always evaluates its second
8725     argument (unless explicitly quoted).  The function so defined may
8726     be an ordinary Maxima function (with arguments enclosed in
8727     parentheses) or a 'memoizing function' (with arguments enclosed in
8728     square brackets).
8729
8730     When the last or only function argument <x_n> is a list of one
8731     element, the function defined by 'define' accepts a variable number
8732     of arguments.  Actual arguments are assigned one-to-one to formal
8733     arguments <x_1>, ..., <x_(n - 1)>, and any further actual
8734     arguments, if present, are assigned to <x_n> as a list.
8735
8736     When the first argument of 'define' is an expression of the form
8737     '<f>(<x_1>, ..., <x_n>)' or '<f>[<x_1>, ..., <x_n>]', the function
8738     arguments are evaluated but <f> is not evaluated, even if there is
8739     already a function or variable by that name.
8740
8741     When the first argument is an expression with operator 'funmake',
8742     'arraymake', or 'ev', the first argument is evaluated; this allows
8743     for the function name to be computed, as well as the body.
8744
8745     All function definitions appear in the same namespace; defining a
8746     function 'f' within another function 'g' does not automatically
8747     limit the scope of 'f' to 'g'.  However, 'local(f)' makes the
8748     definition of function 'f' effective only within the block or other
8749     compound expression in which 'local' appears.
8750
8751     If some formal argument <x_k> is a quoted symbol (after
8752     evaluation), the function defined by 'define' does not evaluate the
8753     corresponding actual argument.  Otherwise all actual arguments are
8754     evaluated.
8755
8756     See also ':=' and '::='.
8757
8758     Examples:
8759
8760     'define' always evaluates its second argument (unless explicitly
8761     quoted).
8762
8763          (%i1) expr : cos(y) - sin(x);
8764          (%o1)                    cos(y) - sin(x)
8765          (%i2) define (F1 (x, y), expr);
8766          (%o2)              F1(x, y) := cos(y) - sin(x)
8767          (%i3) F1 (a, b);
8768          (%o3)                    cos(b) - sin(a)
8769          (%i4) F2 (x, y) := expr;
8770          (%o4)                   F2(x, y) := expr
8771          (%i5) F2 (a, b);
8772          (%o5)                    cos(y) - sin(x)
8773
8774     The function defined by 'define' may be an ordinary Maxima function
8775     or a 'memoizing function'.
8776
8777          (%i1) define (G1 (x, y), x.y - y.x);
8778          (%o1)               G1(x, y) := x . y - y . x
8779          (%i2) define (G2 [x, y], x.y - y.x);
8780          (%o2)                G2     := x . y - y . x
8781                                 x, y
8782
8783     When the last or only function argument <x_n> is a list of one
8784     element, the function defined by 'define' accepts a variable number
8785     of arguments.
8786
8787          (%i1) define (H ([L]), '(apply ("+", L)));
8788          (%o1)                H([L]) := apply("+", L)
8789          (%i2) H (a, b, c);
8790          (%o2)                       c + b + a
8791
8792     When the first argument is an expression with operator 'funmake',
8793     'arraymake', or 'ev', the first argument is evaluated.
8794
8795          (%i1) [F : I, u : x];
8796          (%o1)                        [I, x]
8797          (%i2) funmake (F, [u]);
8798          (%o2)                         I(x)
8799          (%i3) define (funmake (F, [u]), cos(u) + 1);
8800          (%o3)                  I(x) := cos(x) + 1
8801          (%i4) define (arraymake (F, [u]), cos(u) + 1);
8802          (%o4)                   I  := cos(x) + 1
8803                                   x
8804          (%i5) define (foo (x, y), bar (y, x));
8805          (%o5)                foo(x, y) := bar(y, x)
8806          (%i6) define (ev (foo (x, y)), sin(x) - cos(y));
8807          (%o6)             bar(y, x) := sin(x) - cos(y)
8808
8809 -- Function: define_variable (<name>, <default_value>, <mode>)
8810
8811     Introduces a global variable into the Maxima environment.
8812     'define_variable' is useful in user-written packages, which are
8813     often translated or compiled as it gives the compiler hints of the
8814     type ("mode") of a variable and therefore avoids requiring it to
8815     generate generic code that can deal with every variable being an
8816     integer, float, maxima object, array etc.
8817
8818     'define_variable' carries out the following steps:
8819
8820       1. 'mode_declare (<name>, <mode>)' declares the mode ("type") of
8821          <name> to the translator which can considerably speed up
8822          compiled code as it allows having to create generic code.  See
8823          'mode_declare' for a list of the possible modes.
8824
8825       2. If the variable is unbound, <default_value> is assigned to
8826          <name>.
8827
8828       3. Associates <name> with a test function to ensure that <name>
8829          is only assigned values of the declared mode.
8830
8831     The 'value_check' property can be assigned to any variable which
8832     has been defined via 'define_variable' with a mode other than
8833     'any'.  The 'value_check' property is a lambda expression or the
8834     name of a function of one variable, which is called when an attempt
8835     is made to assign a value to the variable.  The argument of the
8836     'value_check' function is the would-be assigned value.
8837
8838     'define_variable' evaluates 'default_value', and quotes 'name' and
8839     'mode'.  'define_variable' returns the current value of 'name',
8840     which is 'default_value' if 'name' was unbound before, and
8841     otherwise it is the previous value of 'name'.
8842
8843     Examples:
8844
8845     'foo' is a Boolean variable, with the initial value 'true'.
8846
8847          (%i1) define_variable (foo, true, boolean);
8848          (%o1)                         true
8849          (%i2) foo;
8850          (%o2)                         true
8851          (%i3) foo: false;
8852          (%o3)                         false
8853          (%i4) foo: %pi;
8854          translator: foo was declared with mode boolean
8855                                                    , but it has value: %pi
8856           -- an error. To debug this try: debugmode(true);
8857          (%i5) foo;
8858          (%o5)                         false
8859
8860     'bar' is an integer variable, which must be prime.
8861
8862          (%i1) define_variable (bar, 2, integer);
8863          (%o1)                           2
8864          (%i2) qput (bar, prime_test, value_check);
8865          (%o2)                      prime_test
8866          (%i3) prime_test (y) := if not primep(y) then
8867                                     error (y, "is not prime.");
8868          (%o3) prime_test(y) := if not primep(y)
8869                                             then error(y, "is not prime.")
8870          (%i4) bar: 1439;
8871          (%o4)                         1439
8872          (%i5) bar: 1440;
8873          1440 is not prime.
8874          #0: prime_test(y=1440)
8875           -- an error. To debug this try: debugmode(true);
8876          (%i6) bar;
8877          (%o6)                         1439
8878
8879     'baz_quux' is a variable which cannot be assigned a value.  The
8880     mode 'any_check' is like 'any', but 'any_check' enables the
8881     'value_check' mechanism, and 'any' does not.
8882
8883          (%i1) define_variable (baz_quux, 'baz_quux, any_check);
8884          (%o1)                       baz_quux
8885          (%i2) F: lambda ([y], if y # 'baz_quux then
8886                           error ("Cannot assign to `baz_quux'."));
8887          (%o2) lambda([y], if y # 'baz_quux
8888                                  then error(Cannot assign to `baz_quux'.))
8889          (%i3) qput (baz_quux, ''F, value_check);
8890          (%o3) lambda([y], if y # 'baz_quux
8891                                  then error(Cannot assign to `baz_quux'.))
8892          (%i4) baz_quux: 'baz_quux;
8893          (%o4)                       baz_quux
8894          (%i5) baz_quux: sqrt(2);
8895          Cannot assign to `baz_quux'.
8896          #0: lambda([y],if y # 'baz_quux then error("Cannot assign to `baz_quux'."))(y=sqrt(2))
8897           -- an error. To debug this try: debugmode(true);
8898          (%i6) baz_quux;
8899          (%o6)                       baz_quux
8900
8901 -- Function: dispfun
8902          dispfun (<f_1>, ..., <f_n>)
8903          dispfun (all)
8904
8905     Displays the definition of the user-defined functions <f_1>, ...,
8906     <f_n>.  Each argument may be the name of a macro (defined with
8907     '::='), an ordinary function (defined with ':=' or 'define'), an
8908     array function (defined with ':=' or 'define', but enclosing
8909     arguments in square brackets '[ ]'), a subscripted function
8910     (defined with ':=' or 'define', but enclosing some arguments in
8911     square brackets and others in parentheses '( )'), one of a family
8912     of subscripted functions selected by a particular subscript value,
8913     or a subscripted function defined with a constant subscript.
8914
8915     'dispfun (all)' displays all user-defined functions as given by the
8916     'functions', 'arrays', and 'macros' lists, omitting subscripted
8917     functions defined with constant subscripts.
8918
8919     'dispfun' creates an intermediate expression label ('%t1', '%t2',
8920     etc.)  for each displayed function, and assigns the function
8921     definition to the label.  In contrast, 'fundef' returns the
8922     function definition.
8923
8924     'dispfun' quotes its arguments; the quote-quote operator ''''
8925     defeats quotation.  'dispfun' returns the list of intermediate
8926     expression labels corresponding to the displayed functions.
8927
8928     Examples:
8929
8930          (%i1) m(x, y) ::= x^(-y);
8931                                               - y
8932          (%o1)                   m(x, y) ::= x
8933          (%i2) f(x, y) :=  x^(-y);
8934                                               - y
8935          (%o2)                    f(x, y) := x
8936          (%i3) g[x, y] :=  x^(-y);
8937                                              - y
8938          (%o3)                     g     := x
8939                                     x, y
8940          (%i4) h[x](y) :=  x^(-y);
8941                                              - y
8942          (%o4)                     h (y) := x
8943                                     x
8944          (%i5) i[8](y) :=  8^(-y);
8945                                              - y
8946          (%o5)                     i (y) := 8
8947                                     8
8948          (%i6) dispfun (m, f, g, h, h[5], h[10], i[8]);
8949                                               - y
8950          (%t6)                   m(x, y) ::= x
8951
8952                                               - y
8953          (%t7)                    f(x, y) := x
8954
8955                                              - y
8956          (%t8)                     g     := x
8957                                     x, y
8958
8959                                              - y
8960          (%t9)                     h (y) := x
8961                                     x
8962
8963                                              1
8964          (%t10)                     h (y) := --
8965                                      5        y
8966                                              5
8967
8968                                               1
8969          (%t11)                    h  (y) := ---
8970                                     10         y
8971                                              10
8972
8973                                              - y
8974          (%t12)                    i (y) := 8
8975                                     8
8976
8977          (%o12)       [%t6, %t7, %t8, %t9, %t10, %t11, %t12]
8978          (%i13) ''%;
8979                               - y              - y            - y
8980          (%o13) [m(x, y) ::= x   , f(x, y) := x   , g     := x   ,
8981                                                      x, y
8982                            - y           1              1             - y
8983                  h (y) := x   , h (y) := --, h  (y) := ---, i (y) := 8   ]
8984                   x              5        y   10         y   8
8985                                          5             10
8986
8987 -- Function: fullmap (<f>, <expr_1>, ...)
8988
8989     Similar to 'map', but 'fullmap' keeps mapping down all
8990     subexpressions until the main operators are no longer the same.
8991
8992     'fullmap' is used by the Maxima simplifier for certain matrix
8993     manipulations; thus, Maxima sometimes generates an error message
8994     concerning 'fullmap' even though 'fullmap' was not explicitly
8995     called by the user.
8996
8997     Examples:
8998
8999          (%i1) a + b * c;
9000          (%o1)                        b c + a
9001          (%i2) fullmap (g, %);
9002          (%o2)                   g(b) g(c) + g(a)
9003          (%i3) map (g, %th(2));
9004          (%o3)                     g(b c) + g(a)
9005
9006 -- Function: fullmapl (<f>, <list_1>, ...)
9007
9008     Similar to 'fullmap', but 'fullmapl' only maps onto lists and
9009     matrices.
9010
9011     Example:
9012
9013          (%i1) fullmapl ("+", [3, [4, 5]], [[a, 1], [0, -1.5]]);
9014          (%o1)                [[a + 3, 4], [4, 3.5]]
9015
9016 -- System variable: functions
9017     Default value: '[]'
9018
9019     'functions' is the list of ordinary Maxima functions in the current
9020     session.  An ordinary function is a function constructed by
9021     'define' or ':=' and called with parentheses '()'.  A function may
9022     be defined at the Maxima prompt or in a Maxima file loaded by
9023     'load' or 'batch'.
9024
9025     'Memoizing functions' (called with square brackets, e.g., 'F[x]')
9026     and subscripted functions (called with square brackets and
9027     parentheses, e.g., 'F[x](y)') are listed by the global variable
9028     'arrays', and not by 'functions'.
9029
9030     Lisp functions are not kept on any list.
9031
9032     Examples:
9033
9034          (%i1) F_1 (x) := x - 100;
9035          (%o1)                   F_1(x) := x - 100
9036          (%i2) F_2 (x, y) := x / y;
9037                                                x
9038          (%o2)                    F_2(x, y) := -
9039                                                y
9040          (%i3) define (F_3 (x), sqrt (x));
9041          (%o3)                   F_3(x) := sqrt(x)
9042          (%i4) G_1 [x] := x - 100;
9043          (%o4)                    G_1  := x - 100
9044                                      x
9045          (%i5) G_2 [x, y] := x / y;
9046                                               x
9047          (%o5)                     G_2     := -
9048                                       x, y    y
9049          (%i6) define (G_3 [x], sqrt (x));
9050          (%o6)                    G_3  := sqrt(x)
9051                                      x
9052          (%i7) H_1 [x] (y) := x^y;
9053                                                y
9054          (%o7)                     H_1 (y) := x
9055                                       x
9056          (%i8) functions;
9057          (%o8)              [F_1(x), F_2(x, y), F_3(x)]
9058          (%i9) arrays;
9059          (%o9)                 [G_1, G_2, G_3, H_1]
9060
9061 -- Function: fundef (<f>)
9062
9063     Returns the definition of the function <f>.
9064
9065     The argument may be
9066        * the name of a macro (defined with '::='),
9067        * an ordinary function (defined with ':=' or 'define'),
9068        * a 'memoizing function' (defined with ':=' or 'define', but
9069          enclosing arguments in square brackets '[ ]'),
9070        * a subscripted function (defined with ':=' or 'define', but
9071          enclosing some arguments in square brackets and others in
9072          parentheses '( )'),
9073        * one of a family of subscripted functions selected by a
9074          particular subscript value,
9075        * or a subscripted function defined with a constant subscript.
9076
9077     'fundef' quotes its argument; the quote-quote operator '''' defeats
9078     quotation.
9079
9080     'fundef (<f>)' returns the definition of <f>.  In contrast,
9081     'dispfun (<f>)' creates an intermediate expression label and
9082     assigns the definition to the label.
9083
9084 -- Function: funmake (<F>, [<arg_1>, ..., <arg_n>])
9085
9086     Returns an expression '<F>(<arg_1>, ..., <arg_n>)'.  The return
9087     value is simplified, but not evaluated, so the function <F> is not
9088     called, even if it exists.
9089
9090     'funmake' does not attempt to distinguish 'memoizing functions'
9091     from ordinary functions; when <F> is the name of a memoizing
9092     function, 'funmake' returns '<F>(...)' (that is, a function call
9093     with parentheses instead of square brackets).  'arraymake' returns
9094     a function call with square brackets in this case.
9095
9096     'funmake' evaluates its arguments.
9097
9098     See also 'apply' and 'args'.
9099
9100     Examples:
9101
9102     'funmake' applied to an ordinary Maxima function.
9103
9104          (%i1) F (x, y) := y^2 - x^2;
9105                                             2    2
9106          (%o1)                  F(x, y) := y  - x
9107          (%i2) funmake (F, [a + 1, b + 1]);
9108          (%o2)                    F(a + 1, b + 1)
9109          (%i3) ''%;
9110                                        2          2
9111          (%o3)                  (b + 1)  - (a + 1)
9112
9113     'funmake' applied to a macro.
9114
9115          (%i1) G (x) ::= (x - 1)/2;
9116                                            x - 1
9117          (%o1)                    G(x) ::= -----
9118                                              2
9119          (%i2) funmake (G, [u]);
9120          (%o2)                         G(u)
9121          (%i3) ''%;
9122                                        u - 1
9123          (%o3)                         -----
9124                                          2
9125
9126     'funmake' applied to a subscripted function.
9127
9128          (%i1) H [a] (x) := (x - 1)^a;
9129                                                  a
9130          (%o1)                   H (x) := (x - 1)
9131                                   a
9132          (%i2) funmake (H [n], [%e]);
9133                                                 n
9134          (%o2)               lambda([x], (x - 1) )(%e)
9135          (%i3) ''%;
9136                                              n
9137          (%o3)                       (%e - 1)
9138          (%i4) funmake ('(H [n]), [%e]);
9139          (%o4)                        H (%e)
9140                                        n
9141          (%i5) ''%;
9142                                              n
9143          (%o5)                       (%e - 1)
9144
9145     'funmake' applied to a symbol which is not a defined function of
9146     any kind.
9147
9148          (%i1) funmake (A, [u]);
9149          (%o1)                         A(u)
9150          (%i2) ''%;
9151          (%o2)                         A(u)
9152
9153     'funmake' evaluates its arguments, but not the return value.
9154
9155          (%i1) det(a,b,c) := b^2 -4*a*c;
9156                                              2
9157          (%o1)              det(a, b, c) := b  - 4 a c
9158          (%i2) (x : 8, y : 10, z : 12);
9159          (%o2)                          12
9160          (%i3) f : det;
9161          (%o3)                          det
9162          (%i4) funmake (f, [x, y, z]);
9163          (%o4)                    det(8, 10, 12)
9164          (%i5) ''%;
9165          (%o5)                         - 284
9166
9167     Maxima simplifies 'funmake''s return value.
9168
9169          (%i1) funmake (sin, [%pi / 2]);
9170          (%o1)                           1
9171
9172 -- Function: lambda
9173          lambda ([<x_1>, ..., <x_m>], <expr_1>, ..., <expr_n>)
9174          lambda ([[<L>]], <expr_1>, ..., <expr_n>)
9175          lambda ([<x_1>, ..., <x_m>, [<L>]], <expr_1>, ..., <expr_n>)
9176
9177     Defines and returns a lambda expression (that is, an anonymous
9178     function).  The function may have required arguments <x_1>, ...,
9179     <x_m> and/or optional arguments <L>, which appear within the
9180     function body as a list.  The return value of the function is
9181     <expr_n>.  A lambda expression can be assigned to a variable and
9182     evaluated like an ordinary function.  A lambda expression may
9183     appear in some contexts in which a function name is expected.
9184
9185     When the function is evaluated, unbound local variables <x_1>, ...,
9186     <x_m> are created.  'lambda' may appear within 'block' or another
9187     'lambda'; local variables are established each time another 'block'
9188     or 'lambda' is evaluated.  Local variables appear to be global to
9189     any enclosed 'block' or 'lambda'.  If a variable is not local, its
9190     value is the value most recently assigned in an enclosing 'block'
9191     or 'lambda', if any, otherwise, it is the value of the variable in
9192     the global environment.  This policy may coincide with the usual
9193     understanding of "dynamic scope".
9194
9195     After local variables are established, <expr_1> through <expr_n>
9196     are evaluated in turn.  The special variable '%%', representing the
9197     value of the preceding expression, is recognized.  'throw' and
9198     'catch' may also appear in the list of expressions.
9199
9200     'return' cannot appear in a lambda expression unless enclosed by
9201     'block', in which case 'return' defines the return value of the
9202     block and not of the lambda expression, unless the block happens to
9203     be <expr_n>.  Likewise, 'go' cannot appear in a lambda expression
9204     unless enclosed by 'block'.
9205
9206     'lambda' quotes its arguments; the quote-quote operator ''''
9207     defeats quotation.
9208
9209     Examples:
9210
9211        * A lambda expression can be assigned to a variable and
9212          evaluated like an ordinary function.
9213
9214          (%i1) f: lambda ([x], x^2);
9215                                                2
9216          (%o1)                    lambda([x], x )
9217          (%i2) f(a);
9218                                          2
9219          (%o2)                          a
9220
9221        * A lambda expression may appear in contexts in which a function
9222          evaluation is expected.
9223
9224          (%i1) lambda ([x], x^2) (a);
9225                                          2
9226          (%o1)                          a
9227          (%i2) apply (lambda ([x], x^2), [a]);
9228                                          2
9229          (%o2)                          a
9230          (%i3) map (lambda ([x], x^2), [a, b, c, d, e]);
9231                                  2   2   2   2   2
9232          (%o3)                 [a , b , c , d , e ]
9233
9234        * Argument variables are local variables.  Other variables
9235          appear to be global variables.  Global variables are evaluated
9236          at the time the lambda expression is evaluated, unless some
9237          special evaluation is forced by some means, such as ''''.
9238
9239          (%i1) a: %pi$
9240          (%i2) b: %e$
9241          (%i3) g: lambda ([a], a*b);
9242          (%o3)                   lambda([a], a b)
9243          (%i4) b: %gamma$
9244          (%i5) g(1/2);
9245                                       %gamma
9246          (%o5)                        ------
9247                                         2
9248          (%i6) g2: lambda ([a], a*''b);
9249          (%o6)                 lambda([a], a %gamma)
9250          (%i7) b: %e$
9251          (%i8) g2(1/2);
9252                                       %gamma
9253          (%o8)                        ------
9254                                         2
9255
9256        * Lambda expressions may be nested.  Local variables within the
9257          outer lambda expression appear to be global to the inner
9258          expression unless masked by local variables of the same names.
9259
9260          (%i1) h: lambda ([a, b], h2: lambda ([a], a*b), h2(1/2));
9261                                                             1
9262          (%o1)     lambda([a, b], h2 : lambda([a], a b), h2(-))
9263                                                             2
9264          (%i2) h(%pi, %gamma);
9265                                       %gamma
9266          (%o2)                        ------
9267                                         2
9268
9269        * Since 'lambda' quotes its arguments, lambda expression 'i'
9270          below does not define a "multiply by 'a'" function.  Such a
9271          function can be defined via 'buildq', as in lambda expression
9272          'i2' below.
9273
9274          (%i1) i: lambda ([a], lambda ([x], a*x));
9275          (%o1)             lambda([a], lambda([x], a x))
9276          (%i2) i(1/2);
9277          (%o2)                   lambda([x], a x)
9278          (%i3) i2: lambda([a], buildq([a: a], lambda([x], a*x)));
9279          (%o3)    lambda([a], buildq([a : a], lambda([x], a x)))
9280          (%i4) i2(1/2);
9281                                              1
9282          (%o4)                  lambda([x], (-) x)
9283                                              2
9284          (%i5) i2(1/2)(%pi);
9285                                         %pi
9286          (%o5)                          ---
9287                                          2
9288
9289        * A lambda expression may take a variable number of arguments,
9290          which are indicated by '[<L>]' as the sole or final argument.
9291          The arguments appear within the function body as a list.
9292
9293          (%i1) f : lambda ([aa, bb, [cc]], aa * cc + bb);
9294          (%o1)          lambda([aa, bb, [cc]], aa cc + bb)
9295          (%i2) f (foo, %i, 17, 29, 256);
9296          (%o2)       [17 foo + %i, 29 foo + %i, 256 foo + %i]
9297          (%i3) g : lambda ([[aa]], apply ("+", aa));
9298          (%o3)             lambda([[aa]], apply(+, aa))
9299          (%i4) g (17, 29, x, y, z, %e);
9300          (%o4)                  z + y + x + %e + 46
9301
9302 -- Function: local (<v_1>, ..., <v_n>)
9303
9304     Saves the properties associated with the symbols <v_1>, ..., <v_n>,
9305     removes any properties before evaluating other expressions, and
9306     restores any saved properties on exit from the block or other
9307     compound expression in which 'local' appears.
9308
9309     Some declarations are implemented as properties of a symbol,
9310     including ':=', 'array', 'dependencies', 'atvalue', 'matchdeclare',
9311     'atomgrad', 'constant', 'nonscalar', 'assume', and some others.
9312     The effect of 'local' is to make such declarations effective only
9313     within the block or other compound expression in which 'local'
9314     appears; otherwise such declarations are global declarations.
9315
9316     'local' can only appear in 'block' or in the body of a function
9317     definition or 'lambda' expression, and only one occurrence is
9318     permitted in each.
9319
9320     'local' quotes its arguments.  'local' returns 'done'.
9321
9322     Example:
9323
9324     A local function definition.
9325
9326          (%i1) foo (x) := 1 - x;
9327          (%o1)                    foo(x) := 1 - x
9328          (%i2) foo (100);
9329          (%o2)                         - 99
9330          (%i3) block (local (foo), foo (x) := 2 * x, foo (100));
9331          (%o3)                          200
9332          (%i4) foo (100);
9333          (%o4)                         - 99
9334
9335 -- Option variable: macroexpansion
9336     Default value: 'false'
9337
9338     'macroexpansion' controls whether the expansion (that is, the
9339     return value) of a macro function is substituted for the macro
9340     function call.  A substitution may speed up subsequent expression
9341     evaluations, at the cost of storing the expansion.
9342
9343     'false'
9344          The expansion of a macro function is not substituted for the
9345          macro function call.
9346     'expand'
9347          The first time a macro function call is evaluated, the
9348          expansion is stored.  The expansion is not recomputed on
9349          subsequent calls; any side effects (such as 'print' or
9350          assignment to global variables) happen only when the macro
9351          function call is first evaluated.  Expansion in an expression
9352          does not affect other expressions which have the same macro
9353          function call.
9354     'displace'
9355          The first time a macro function call is evaluated, the
9356          expansion is substituted for the call, thus modifying the
9357          expression from which the macro function was called.  The
9358          expansion is not recomputed on subsequent calls; any side
9359          effects happen only when the macro function call is first
9360          evaluated.  Expansion in an expression does not affect other
9361          expressions which have the same macro function call.
9362
9363     Examples
9364
9365     When 'macroexpansion' is 'false', a macro function is called every
9366     time the calling expression is evaluated, and the calling
9367     expression is not modified.
9368
9369          (%i1) f (x) := h (x) / g (x);
9370                                            h(x)
9371          (%o1)                     f(x) := ----
9372                                            g(x)
9373          (%i2) g (x) ::= block (print ("x + 99 is equal to", x),
9374                                 return (x + 99));
9375          (%o2) g(x) ::= block(print("x + 99 is equal to", x),
9376                                                            return(x + 99))
9377          (%i3) h (x) ::= block (print ("x - 99 is equal to", x),
9378                                 return (x - 99));
9379          (%o3) h(x) ::= block(print("x - 99 is equal to", x),
9380                                                            return(x - 99))
9381          (%i4) macroexpansion: false;
9382          (%o4)                         false
9383          (%i5) f (a * b);
9384          x - 99 is equal to x
9385          x + 99 is equal to x
9386                                      a b - 99
9387          (%o5)                       --------
9388                                      a b + 99
9389          (%i6) dispfun (f);
9390                                            h(x)
9391          (%t6)                     f(x) := ----
9392                                            g(x)
9393
9394          (%o6)                         [%t6]
9395          (%i7) f (a * b);
9396          x - 99 is equal to x
9397          x + 99 is equal to x
9398                                      a b - 99
9399          (%o7)                       --------
9400                                      a b + 99
9401
9402     When 'macroexpansion' is 'expand', a macro function is called once,
9403     and the calling expression is not modified.
9404
9405          (%i1) f (x) := h (x) / g (x);
9406                                            h(x)
9407          (%o1)                     f(x) := ----
9408                                            g(x)
9409          (%i2) g (x) ::= block (print ("x + 99 is equal to", x),
9410                                 return (x + 99));
9411          (%o2) g(x) ::= block(print("x + 99 is equal to", x),
9412                                                            return(x + 99))
9413          (%i3) h (x) ::= block (print ("x - 99 is equal to", x),
9414                                 return (x - 99));
9415          (%o3) h(x) ::= block(print("x - 99 is equal to", x),
9416                                                            return(x - 99))
9417          (%i4) macroexpansion: expand;
9418          (%o4)                        expand
9419          (%i5) f (a * b);
9420          x - 99 is equal to x
9421          x + 99 is equal to x
9422                                      a b - 99
9423          (%o5)                       --------
9424                                      a b + 99
9425          (%i6) dispfun (f);
9426                                mmacroexpanded(x - 99, h(x))
9427          (%t6)         f(x) := ----------------------------
9428                                mmacroexpanded(x + 99, g(x))
9429
9430          (%o6)                         [%t6]
9431          (%i7) f (a * b);
9432                                      a b - 99
9433          (%o7)                       --------
9434                                      a b + 99
9435
9436     When 'macroexpansion' is 'displace', a macro function is called
9437     once, and the calling expression is modified.
9438
9439          (%i1) f (x) := h (x) / g (x);
9440                                            h(x)
9441          (%o1)                     f(x) := ----
9442                                            g(x)
9443          (%i2) g (x) ::= block (print ("x + 99 is equal to", x),
9444                                 return (x + 99));
9445          (%o2) g(x) ::= block(print("x + 99 is equal to", x),
9446                                                            return(x + 99))
9447          (%i3) h (x) ::= block (print ("x - 99 is equal to", x),
9448                                 return (x - 99));
9449          (%o3) h(x) ::= block(print("x - 99 is equal to", x),
9450                                                            return(x - 99))
9451          (%i4) macroexpansion: displace;
9452          (%o4)                       displace
9453          (%i5) f (a * b);
9454          x - 99 is equal to x
9455          x + 99 is equal to x
9456                                      a b - 99
9457          (%o5)                       --------
9458                                      a b + 99
9459          (%i6) dispfun (f);
9460                                           x - 99
9461          (%t6)                    f(x) := ------
9462                                           x + 99
9463
9464          (%o6)                         [%t6]
9465          (%i7) f (a * b);
9466                                      a b - 99
9467          (%o7)                       --------
9468                                      a b + 99
9469
9470 -- Function: mode_declare (<y_1>, <mode_1>, ..., <y_n>, <mode_n>)
9471
9472     A 'mode_declare' informs the compiler which type (lisp programmers
9473     name the type: "mode") a function parameter or its return value
9474     will be of.  This can greatly boost the efficiency of the code the
9475     compiler generates: Without knowing the type of all variables and
9476     knowing the return value of all functions a function uses in
9477     advance very generic (and thus potentially slow) code needs to be
9478     generated.
9479
9480     The arguments of 'mode_declare' are pairs consisting of a variable
9481     (or a list of variables all having the same mode) and a mode.
9482     Available modes ("types") are:
9483          array            an declared array (see the detailed description below)
9484          string           a string
9485          boolean          true or false
9486          integer          integers (including arbitrary-size integers)
9487          fixnum           integers (excluding arbitrary-size integers)
9488          float            machine-size floating-point numbers
9489          real             machine-size floating-point or integer
9490          number           Numbers
9491          even             Even integers
9492          odd              Odd integers
9493          any              any kind of object (useful for arrays of any)
9494
9495     A function parameter named 'a' can be declared as an array filled
9496     with elements of the type 't' the following way:
9497          mode_declare (a, array(t, dim1, dim2, ...))
9498     If none of the elements of the array 'a' needs to be checked if it
9499     still doesn't contain a value additional code can be omitted by
9500     declaring this fact, too:
9501          mode_declare (a, array (t, complete, dim1, dim2, ...))
9502     The 'complete' has no effect if all array elements are of the type
9503     'fixnum' or 'float': Machine-sized numbers inevitably contain a
9504     value (and will automatically be initialized to 0 in most lisp
9505     implementations).
9506
9507     Another way to tell that all entries of the array 'a' are of the
9508     type ("mode") 'm' and have been assigned a value to would be:
9509          mode_declare (completearray (a), m))
9510
9511     Numeric code using arrays might run faster still if the size of the
9512     array is known at compile time, as well, as in:
9513          mode_declare (completearray (a [10, 10]), float)
9514     for a floating point number array named 'a' which is 10 x 10.
9515
9516     'mode_declare' also can be used in order to declare the type of the
9517     result of a function.  In this case the function compilation needs
9518     to be preceded by another 'mode_declare' statement.  For example
9519     the expression,
9520          mode_declare ([function (f_1, f_2, ...)], fixnum)
9521     declares that the values returned by 'f_1', 'f_2', ... are
9522     single-word integers.
9523
9524     'modedeclare' is a synonym for 'mode_declare'.
9525
9526     If the type of function parameters and results doesn't match the
9527     declaration by 'mode_declare' the function may misbehave or a
9528     warning or an error might occur, see 'mode_checkp',
9529     'mode_check_errorp' and 'mode_check_warnp'.
9530
9531     See 'mode_identity' for declaring the type of lists and
9532     'define_variable' for declaring the type of all global variables
9533     compiled code uses, as well.
9534
9535     Example:
9536          (%i1) square_float(f):=(
9537               mode_declare(f,float),
9538               f*f
9539           );
9540          (%o1)   square_float(f) := (mode_declare(f, float), f f)
9541          (%i2) mode_declare([function(f)],float);
9542          (%o2)                    [[function(f)]]
9543          (%i3) compile(square_float);
9544          (%o3)                    [square_float]
9545          (%i4) square_float(100.0);
9546          (%o4)                        10000.0
9547
9548 -- Option variable: mode_checkp
9549     Default value: 'true'
9550
9551     When 'mode_checkp' is 'true', 'mode_declare' does not only define
9552     which type a variable will be of so the compiler can generate more
9553     efficient code, but will also create a runtime warning if the
9554     variable isn't of the variable type the code was compiled to deal
9555     with.
9556
9557          (%i1) mode_checkp:true;
9558          (%o1)                         true
9559          (%i2) square(f):=(
9560              mode_declare(f,float),
9561              f^2);
9562                                                             2
9563          (%o2)       square(f) := (mode_declare(f, float), f )
9564          (%i3) compile(square);
9565          (%o3)                       [square]
9566          (%i4) square(2.3);
9567          (%o4)                   5.289999999999999
9568          (%i5) square(4);
9569          Maxima encountered a Lisp error:
9570
9571           The value
9572             4
9573           is not of type
9574             DOUBLE-FLOAT
9575           when binding $F
9576
9577          Automatically continuing.
9578          To enable the Lisp debugger set *debugger-hook* to nil.
9579
9580 -- Option variable: mode_check_errorp
9581     Default value: 'false'
9582
9583     When 'mode_check_errorp' is 'true', 'mode_declare' calls error.
9584
9585 -- Option variable: mode_check_warnp
9586     Default value: 'true'
9587
9588     When 'mode_check_warnp' is 'true', mode errors are described.
9589
9590 -- Function: mode_identity (<arg_1>, <arg_2>)
9591
9592     'mode_identity' works similar to 'mode_declare', but is used for
9593     informing the compiler that a thing like a 'macro' or a list
9594     operation will only return a specific type of object.  The purpose
9595     of doing so is that maxima supports many objects: Machine integers,
9596     arbitrary length integers, equations, machine floats, big floats,
9597     which means that for everything that deals with return values of
9598     operations that can result in any object the compiler needs to
9599     output generic (and therefore potentially slow) code.
9600
9601     The first argument to 'mode_identity' is the type of return value
9602     something will return (for possible types see 'mode_declare').
9603     (i.e., one of 'float', 'fixnum', 'number', The second argument is
9604     the expression that will return an object of this type.
9605
9606     If the the return value of this expression is of a type the code
9607     was not compiled for error or warning is signalled.
9608
9609     If you knew that 'first (l)' returned a number then you could write
9610
9611          mode_identity (number, first (l)).
9612     However, if you need this construct more often it would be more
9613     efficient to define a function that returns a number fist:
9614          firstnumb (x) ::= buildq ([x], mode_identity (number, first(x)));
9615          compile(firstnumb)
9616     'firstnumb' now can be used every time you need the first element
9617     of a list that is guaranteed to be filled with numbers.
9618
9619 -- Function: remfunction
9620          remfunction (<f_1>, ..., <f_n>)
9621          remfunction (all)
9622
9623     Unbinds the function definitions of the symbols <f_1>, ..., <f_n>.
9624     The arguments may be the names of ordinary functions (created by
9625     ':=' or 'define') or macro functions (created by '::=').
9626
9627     'remfunction (all)' unbinds all function definitions.
9628
9629     'remfunction' quotes its arguments.
9630
9631     'remfunction' returns a list of the symbols for which the function
9632     definition was unbound.  'false' is returned in place of any symbol
9633     for which there is no function definition.
9634
9635     'remfunction' does not apply to 'memoizing functions' or
9636     subscripted functions.  'remarray' applies to those types of
9637     functions.
9638
9639 -- Option variable: savedef
9640     Default value: 'true'
9641
9642     When 'savedef' is 'true', the Maxima version of a user function is
9643     preserved when the function is translated.  This permits the
9644     definition to be displayed by 'dispfun' and allows the function to
9645     be edited.
9646
9647     When 'savedef' is 'false', the names of translated functions are
9648     removed from the 'functions' list.
9649
9650 -- Option variable: transcompile
9651     Default value: 'true'
9652
9653     When 'transcompile' is 'true', 'translate' and 'translate_file'
9654     generate declarations to make the translated code more suitable for
9655     compilation.
9656
9657     'compfile' sets 'transcompile: true' for the duration.
9658
9659 -- Function: translate
9660          translate (<f_1>, ..., <f_n>)
9661          translate (functions)
9662          translate (all)
9663
9664     Translates the user-defined functions <f_1>, ..., <f_n> from the
9665     Maxima language into Lisp and evaluates the Lisp translations.
9666     Typically the translated functions run faster than the originals.
9667
9668     'translate (all)' or 'translate (functions)' translates all
9669     user-defined functions.
9670
9671     Functions to be translated should include a call to 'mode_declare'
9672     at the beginning when possible in order to produce more efficient
9673     code.  For example:
9674
9675          f (x_1, x_2, ...) := block ([v_1, v_2, ...],
9676              mode_declare (v_1, mode_1, v_2, mode_2, ...), ...)
9677
9678     where the <x_1>, <x_2>, ... are the parameters to the function and
9679     the <v_1>, <v_2>, ... are the local variables.
9680
9681     The names of translated functions are removed from the 'functions'
9682     list if 'savedef' is 'false' (see below) and are added to the
9683     'props' lists.
9684
9685     Functions should not be translated unless they are fully debugged.
9686
9687     Expressions are assumed simplified; if they are not, correct but
9688     non-optimal code gets generated.  Thus, the user should not set the
9689     'simp' switch to 'false' which inhibits simplification of the
9690     expressions to be translated.
9691
9692     The switch 'translate', if 'true', causes automatic translation of
9693     a user's function to Lisp.
9694
9695     Note that translated functions may not run identically to the way
9696     they did before translation as certain incompatibilities may exist
9697     between the Lisp and Maxima versions.  Principally, the 'rat'
9698     function with more than one argument and the 'ratvars' function
9699     should not be used if any variables are 'mode_declare''d canonical
9700     rational expressions (CRE). Also the 'prederror: false' setting
9701     will not translate.
9702
9703     'savedef' - if 'true' will cause the Maxima version of a user
9704     function to remain when the function is 'translate''d.  This
9705     permits the definition to be displayed by 'dispfun' and allows the
9706     function to be edited.
9707
9708     'transrun' - if 'false' will cause the interpreted version of all
9709     functions to be run (provided they are still around) rather than
9710     the translated version.
9711
9712     The result returned by 'translate' is a list of the names of the
9713     functions translated.
9714
9715 -- Function: translate_file
9716          translate_file (<maxima_filename>)
9717          translate_file (<maxima_filename>, <lisp_filename>)
9718
9719     Translates a file of Maxima code into a file of Lisp code.
9720     'translate_file' returns a list of three filenames: the name of the
9721     Maxima file, the name of the Lisp file, and the name of file
9722     containing additional information about the translation.
9723     'translate_file' evaluates its arguments.
9724
9725     'translate_file ("foo.mac"); load("foo.LISP")' is the same as the
9726     command 'batch ("foo.mac")' except for certain restrictions, the
9727     use of '''' and '%', for example.
9728
9729     'translate_file (<maxima_filename>)' translates a Maxima file
9730     <maxima_filename> into a similarly-named Lisp file.  For example,
9731     'foo.mac' is translated into 'foo.LISP'.  The Maxima filename may
9732     include a directory name or names, in which case the Lisp output
9733     file is written to the same directory from which the Maxima input
9734     comes.
9735
9736     'translate_file (<maxima_filename>, <lisp_filename>)' translates a
9737     Maxima file <maxima_filename> into a Lisp file <lisp_filename>.
9738     'translate_file' ignores the filename extension, if any, of
9739     'lisp_filename'; the filename extension of the Lisp output file is
9740     always 'LISP'.  The Lisp filename may include a directory name or
9741     names, in which case the Lisp output file is written to the
9742     specified directory.
9743
9744     'translate_file' also writes a file of translator warning messages
9745     of various degrees of severity.  The filename extension of this
9746     file is 'UNLISP'.  This file may contain valuable information,
9747     though possibly obscure, for tracking down bugs in translated code.
9748     The 'UNLISP' file is always written to the same directory from
9749     which the Maxima input comes.
9750
9751     'translate_file' emits Lisp code which causes some declarations and
9752     definitions to take effect as soon as the Lisp code is compiled.
9753     See 'compile_file' for more on this topic.
9754
9755     See also
9756     'tr_array_as_ref'
9757     'tr_bound_function_applyp',
9758     'tr_exponent'
9759     'tr_file_tty_messagesp',
9760     'tr_float_can_branch_complex',
9761     'tr_function_call_default',
9762     'tr_numer',
9763     'tr_optimize_max_loop',
9764     'tr_semicompile',
9765     'tr_state_vars',
9766     'tr_warnings_get',
9767     'tr_warn_bad_function_calls'
9768     'tr_warn_fexpr',
9769     'tr_warn_meval',
9770     'tr_warn_mode',
9771     'tr_warn_undeclared',
9772     and 'tr_warn_undefined_variable'.
9773
9774 -- Option variable: transrun
9775     Default value: 'true'
9776
9777     When 'transrun' is 'false' will cause the interpreted version of
9778     all functions to be run (provided they are still around) rather
9779     than the translated version.
9780
9781 -- Option variable: tr_array_as_ref
9782     Default value: 'true'
9783
9784     If 'translate_fast_arrays' is 'false', array references in Lisp
9785     code emitted by 'translate_file' are affected by 'tr_array_as_ref'.
9786     When 'tr_array_as_ref' is 'true', array names are evaluated,
9787     otherwise array names appear as literal symbols in translated code.
9788
9789     'tr_array_as_ref' has no effect if 'translate_fast_arrays' is
9790     'true'.
9791
9792 -- Option variable: tr_bound_function_applyp
9793     Default value: 'true'
9794
9795     When 'tr_bound_function_applyp' is 'true', Maxima gives a warning
9796     if a bound variable (such as a function argument) is found being
9797     used as a function.  'tr_bound_function_applyp' does not affect the
9798     code generated in such cases.
9799
9800     For example, an expression such as 'g (f, x) := f (x+1)' will
9801     trigger the warning message.
9802
9803 -- Option variable: tr_file_tty_messagesp
9804     Default value: 'false'
9805
9806     When 'tr_file_tty_messagesp' is 'true', messages generated by
9807     'translate_file' during translation of a file are displayed on the
9808     console and inserted into the UNLISP file.  When 'false', messages
9809     about translation of the file are only inserted into the UNLISP
9810     file.
9811
9812 -- Option variable: tr_float_can_branch_complex
9813     Default value: 'true'
9814
9815     Tells the Maxima-to-Lisp translator to assume that the functions
9816     'acos', 'asin', 'asec', and 'acsc' can return complex results.
9817
9818     The ostensible effect of 'tr_float_can_branch_complex' is the
9819     following.  However, it appears that this flag has no effect on the
9820     translator output.
9821
9822     When it is 'true' then 'acos(x)' is of mode 'any' even if 'x' is of
9823     mode 'float' (as set by 'mode_declare').  When 'false' then
9824     'acos(x)' is of mode 'float' if and only if 'x' is of mode 'float'.
9825
9826 -- Option variable: tr_function_call_default
9827     Default value: 'general'
9828
9829     'false' means give up and call 'meval', 'expr' means assume Lisp
9830     fixed arg function.  'general', the default gives code good for
9831     'mexprs' and 'mlexprs' but not 'macros'.  'general' assures
9832     variable bindings are correct in compiled code.  In 'general' mode,
9833     when translating F(X), if F is a bound variable, then it assumes
9834     that 'apply (f, [x])' is meant, and translates a such, with
9835     appropriate warning.  There is no need to turn this off.  With the
9836     default settings, no warning messages implies full compatibility of
9837     translated and compiled code with the Maxima interpreter.
9838
9839 -- Option variable: tr_numer
9840     Default value: 'false'
9841
9842     When 'tr_numer' is 'true', 'numer' properties are used for atoms
9843     which have them, e.g.  '%pi'.
9844
9845 -- Option variable: tr_optimize_max_loop
9846     Default value: 100
9847
9848     'tr_optimize_max_loop' is the maximum number of times the
9849     macro-expansion and optimization pass of the translator will loop
9850     in considering a form.  This is to catch macro expansion errors,
9851     and non-terminating optimization properties.
9852
9853 -- Option variable: tr_semicompile
9854     Default value: 'false'
9855
9856     When 'tr_semicompile' is 'true', 'translate_file' and 'compfile'
9857     output forms which will be macroexpanded but not compiled into
9858     machine code by the Lisp compiler.
9859
9860 -- System variable: tr_state_vars
9861     Default value:
9862          [transcompile, tr_semicompile, tr_warn_undeclared, tr_warn_meval,
9863          tr_warn_fexpr, tr_warn_mode, tr_warn_undefined_variable,
9864          tr_function_call_default, tr_array_as_ref,tr_numer]
9865
9866     The list of the switches that affect the form of the translated
9867     output.  This information is useful to system people when trying to
9868     debug the translator.  By comparing the translated product to what
9869     should have been produced for a given state, it is possible to
9870     track down bugs.
9871
9872 -- Function: tr_warnings_get ()
9873
9874     Prints a list of warnings which have been given by the translator
9875     during the current translation.
9876
9877 -- Option variable: tr_warn_bad_function_calls
9878     Default value: 'true'
9879
9880     - Gives a warning when when function calls are being made which may
9881     not be correct due to improper declarations that were made at
9882     translate time.
9883
9884 -- Option variable: tr_warn_fexpr
9885     Default value: 'compfile'
9886
9887     - Gives a warning if any FEXPRs are encountered.  FEXPRs should not
9888     normally be output in translated code, all legitimate special
9889     program forms are translated.
9890
9891 -- Option variable: tr_warn_meval
9892     Default value: 'compfile'
9893
9894     - Gives a warning if the function 'meval' gets called.  If 'meval'
9895     is called that indicates problems in the translation.
9896
9897 -- Option variable: tr_warn_mode
9898     Default value: 'all'
9899
9900     - Gives a warning when variables are assigned values inappropriate
9901     for their mode.
9902
9903 -- Option variable: tr_warn_undeclared
9904     Default value: 'compile'
9905
9906     - Determines when to send warnings about undeclared variables to
9907     the TTY.
9908
9909 -- Option variable: tr_warn_undefined_variable
9910     Default value: 'all'
9911
9912     - Gives a warning when undefined global variables are seen.
9913
9914 -- Function: compile_file
9915          compile_file (<filename>)
9916          compile_file (<filename>, <compiled_filename>)
9917          compile_file (<filename>, <compiled_filename>,
9918          <lisp_filename>)
9919
9920     Translates the Maxima file <filename> into Lisp, executes the Lisp
9921     compiler, and, if the translation and compilation succeed, loads
9922     the compiled code into Maxima.
9923
9924     'compile_file' returns a list of the names of four files: the
9925     original Maxima file, the Lisp translation, notes on translation,
9926     and the compiled code.  If the compilation fails, the fourth item
9927     is 'false'.
9928
9929     Some declarations and definitions take effect as soon as the Lisp
9930     code is compiled (without loading the compiled code).  These
9931     include functions defined with the ':=' operator, macros define
9932     with the '::=' operator, 'alias', 'declare', 'define_variable',
9933     'mode_declare', and 'infix', 'matchfix', 'nofix', 'postfix',
9934     'prefix', and 'compfile'.
9935
9936     Assignments and function calls are not evaluated until the compiled
9937     code is loaded.  In particular, within the Maxima file, assignments
9938     to the translation flags ('tr_numer', etc.)  have no effect on the
9939     translation.
9940
9941     <filename> may not contain ':lisp' statements.
9942
9943     'compile_file' evaluates its arguments.
9944
9945 -- Function: declare_translated (<f_1>, <f_2>, ...)
9946
9947     When translating a file of Maxima code to Lisp, it is important for
9948     the translator to know which functions it sees in the file are to
9949     be called as translated or compiled functions, and which ones are
9950     just Maxima functions or undefined.  Putting this declaration at
9951     the top of the file, lets it know that although a symbol does which
9952     does not yet have a Lisp function value, will have one at call
9953     time.  '(MFUNCTION-CALL fn arg1 arg2 ...)' is generated when the
9954     translator does not know 'fn' is going to be a Lisp function.
9955
9956
9957File: maxima.info,  Node: Program Flow,  Next: Debugging,  Prev: Function Definition,  Up: Top
9958
995937 Program Flow
9960***************
9961
9962* Menu:
9963
9964* Lisp and Maxima::
9965* Garbage Collection::
9966* Introduction to Program Flow::
9967* Functions and Variables for Program Flow::
9968
9969
9970File: maxima.info,  Node: Lisp and Maxima,  Next: Garbage Collection,  Prev: Program Flow,  Up: Program Flow
9971
997237.1 Lisp and Maxima
9973====================
9974
9975Maxima is a fairly complete programming language.  But since it is
9976written in Lisp, it additionally can provide easy access to Lisp
9977functions and variables from Maxima and vice versa.  Lisp and Maxima
9978symbols are distinguished by a naming convention.  A Lisp symbol which
9979begins with a dollar sign '$' corresponds to a Maxima symbol without the
9980dollar sign.
9981
9982   A Maxima symbol which begins with a question mark '?' corresponds to
9983a Lisp symbol without the question mark.  For example, the Maxima symbol
9984'foo' corresponds to the Lisp symbol '$FOO', while the Maxima symbol
9985'?foo' corresponds to the Lisp symbol 'FOO'.  Note that '?foo' is
9986written without a space between '?' and 'foo'; otherwise it might be
9987mistaken for 'describe ("foo")'.
9988
9989   Hyphen '-', asterisk '*', or other special characters in Lisp symbols
9990must be escaped by backslash '\' where they appear in Maxima code.  For
9991example, the Lisp identifier '*foo-bar*' is written '?\*foo\-bar\*' in
9992Maxima.
9993
9994   Lisp code may be executed from within a Maxima session.  A single
9995line of Lisp (containing one or more forms) may be executed by the
9996special command ':lisp'.  For example,
9997
9998     (%i1) :lisp (foo $x $y)
9999
10000calls the Lisp function 'foo' with Maxima variables 'x' and 'y' as
10001arguments.  The ':lisp' construct can appear at the interactive prompt
10002or in a file processed by 'batch' or 'demo', but not in a file processed
10003by 'load', 'batchload', 'translate_file', or 'compile_file'.
10004
10005   The function 'to_lisp' opens an interactive Lisp session.  Entering
10006'(to-maxima)' closes the Lisp session and returns to Maxima.
10007
10008   Lisp functions and variables which are to be visible in Maxima as
10009functions and variables with ordinary names (no special punctuation)
10010must have Lisp names beginning with the dollar sign '$'.
10011
10012   Maxima is case-sensitive, distinguishing between lowercase and
10013uppercase letters in identifiers.  There are some rules governing the
10014translation of names between Lisp and Maxima.
10015
10016  1. A Lisp identifier not enclosed in vertical bars corresponds to a
10017     Maxima identifier in lowercase.  Whether the Lisp identifier is
10018     uppercase, lowercase, or mixed case, is ignored.  E.g., Lisp
10019     '$foo', '$FOO', and '$Foo' all correspond to Maxima 'foo'.  But
10020     this is because '$foo', '$FOO' and '$Foo' are converted by the Lisp
10021     reader by default to the Lisp symbol '$FOO'.
10022  2. A Lisp identifier which is all uppercase or all lowercase and
10023     enclosed in vertical bars corresponds to a Maxima identifier with
10024     case reversed.  That is, uppercase is changed to lowercase and
10025     lowercase to uppercase.  E.g., Lisp '|$FOO|' and '|$foo|'
10026     correspond to Maxima 'foo' and 'FOO', respectively.
10027  3. A Lisp identifier which is mixed uppercase and lowercase and
10028     enclosed in vertical bars corresponds to a Maxima identifier with
10029     the same case.  E.g., Lisp '|$Foo|' corresponds to Maxima 'Foo'.
10030
10031   The '#$' Lisp macro allows the use of Maxima expressions in Lisp
10032code.  '#$<expr>$' expands to a Lisp expression equivalent to the Maxima
10033expression <expr>.
10034
10035     (msetq $foo #$[x, y]$)
10036
10037This has the same effect as entering
10038
10039     (%i1) foo: [x, y];
10040
10041The Lisp function 'displa' prints an expression in Maxima format.
10042
10043     (%i1) :lisp #$[x, y, z]$
10044     ((MLIST SIMP) $X $Y $Z)
10045     (%i1) :lisp (displa '((MLIST SIMP) $X $Y $Z))
10046     [x, y, z]
10047     NIL
10048
10049   Functions defined in Maxima are not ordinary Lisp functions.  The
10050Lisp function 'mfuncall' calls a Maxima function.  For example:
10051
10052     (%i1) foo(x,y) := x*y$
10053     (%i2) :lisp (mfuncall '$foo 'a 'b)
10054     ((MTIMES SIMP) A B)
10055
10056   Some Lisp functions are shadowed in the Maxima package, namely the
10057following.
10058
10059   complement     continue      //
10060   float          functionp     array
10061   exp            listen        signum
10062   atan           asin          acos
10063   asinh          acosh         atanh
10064   tanh           cosh          sinh
10065   tan            break         gcd
10066
10067
10068File: maxima.info,  Node: Garbage Collection,  Next: Introduction to Program Flow,  Prev: Lisp and Maxima,  Up: Program Flow
10069
1007037.2 Garbage Collection
10071=======================
10072
10073One of the advantages of using lisp is that it uses "Garbage
10074Collection".  In other words it automatically takes care of freeing
10075memory occupied for example of intermediate results that were used
10076during symbolic computation.
10077
10078   Garbage Collection avoids many errors frequently found in C programs
10079(memory being freed too early, multiple times or not at all).
10080
10081 -- Function: garbage_collect ()
10082
10083     Tries to manually trigger the lisp's garbage collection.  This
10084     rarely is necessary as the lisp will employ an excellent algorithm
10085     for determining when to start garbage collection.
10086
10087     If maxima knows how to do manually trigger the garbage collection
10088     for the current lisp 'garbage_collect' returns 'true', else
10089     'false'.
10090
10091
10092File: maxima.info,  Node: Introduction to Program Flow,  Next: Functions and Variables for Program Flow,  Prev: Garbage Collection,  Up: Program Flow
10093
1009437.3 Introduction to Program Flow
10095=================================
10096
10097Maxima provides a 'do' loop for iteration, as well as more primitive
10098constructs such as 'go'.
10099
10100
10101File: maxima.info,  Node: Functions and Variables for Program Flow,  Prev: Introduction to Program Flow,  Up: Program Flow
10102
1010337.4 Functions and Variables for Program Flow
10104=============================================
10105
10106 -- Function: backtrace
10107          backtrace ()
10108          backtrace (<n>)
10109
10110     Prints the call stack, that is, the list of functions which called
10111     the currently active function.
10112
10113     'backtrace ()' prints the entire call stack.
10114
10115     'backtrace (<n>)' prints the <n> most recent functions, including
10116     the currently active function.
10117
10118     'backtrace' can be called from a script, a function, or the
10119     interactive prompt (not only in a debugging context).
10120
10121     Examples:
10122
10123        * 'backtrace ()' prints the entire call stack.
10124
10125               (%i1) h(x) := g(x/7)$
10126               (%i2) g(x) := f(x-11)$
10127               (%i3) f(x) := e(x^2)$
10128               (%i4) e(x) := (backtrace(), 2*x + 13)$
10129               (%i5) h(10);
10130               #0: e(x=4489/49)
10131               #1: f(x=-67/7)
10132               #2: g(x=10/7)
10133               #3: h(x=10)
10134                                             9615
10135               (%o5)                         ----
10136                                              49
10137
10138        * 'backtrace (<n>)' prints the <n> most recent functions,
10139          including the currently active function.
10140
10141               (%i1) h(x) := (backtrace(1), g(x/7))$
10142               (%i2) g(x) := (backtrace(1), f(x-11))$
10143               (%i3) f(x) := (backtrace(1), e(x^2))$
10144               (%i4) e(x) := (backtrace(1), 2*x + 13)$
10145               (%i5) h(10);
10146               #0: h(x=10)
10147               #0: g(x=10/7)
10148               #0: f(x=-67/7)
10149               #0: e(x=4489/49)
10150                                             9615
10151               (%o5)                         ----
10152                                              49
10153
10154 -- Special operator: do
10155 -- Special operator: while
10156 -- Special operator: unless
10157 -- Special operator: for
10158 -- Special operator: from
10159 -- Special operator: thru
10160 -- Special operator: step
10161 -- Special operator: next
10162 -- Special operator: in
10163
10164     The 'do' statement is used for performing iteration.  The general
10165     form of the 'do' statements maxima supports is:
10166
10167        * 'for <variable>: <initial_value> step <increment> thru <limit>
10168          do <body>'
10169        * 'for <variable>: <initial_value> step <increment> while
10170          <condition> do <body>'
10171        * 'for <variable>: <initial_value> step <increment> unless
10172          <condition> do <body>'
10173        * 'for <variable> in <list> do <body>'
10174
10175     If the loop is expected to generate a list as output the command
10176     'makelist' may be the appropriate command to use instead, *Note
10177     Performance considerations for Lists::.
10178
10179     <initial_value>, <increment>, <limit>, and <body> can be any
10180     expression.  <list> is a list.  If the increment is 1 then "'step
10181     1'" may be omitted; As always, if 'body' needs to contain more than
10182     one command these commands can be specified as a comma-separated
10183     list surrounded by parenthesis or as a 'block'.  Due to its great
10184     generality the 'do' statement will be described in two parts.  The
10185     first form of the 'do' statement (which is shown in the first three
10186     items above) is analogous to that used in several other programming
10187     languages (Fortran, Algol, PL/I, etc.); then the other features
10188     will be mentioned.
10189
10190     The execution of the 'do' statement proceeds by first assigning the
10191     <initial_value> to the <variable> (henceforth called the
10192     control-variable).  Then: (1) If the control-variable has exceeded
10193     the limit of a 'thru' specification, or if the condition of the
10194     'unless' is 'true', or if the condition of the 'while' is 'false'
10195     then the 'do' terminates.  (2) The <body> is evaluated.  (3) The
10196     increment is added to the control-variable.  The process from (1)
10197     to (3) is performed repeatedly until the termination condition is
10198     satisfied.  One may also give several termination conditions in
10199     which case the 'do' terminates when any of them is satisfied.
10200
10201     In general the 'thru' test is satisfied when the control-variable
10202     is greater than the <limit> if the <increment> was non-negative, or
10203     when the control-variable is less than the <limit> if the
10204     <increment> was negative.  The <increment> and <limit> may be
10205     non-numeric expressions as long as this inequality can be
10206     determined.  However, unless the <increment> is syntactically
10207     negative (e.g.  is a negative number) at the time the 'do'
10208     statement is input, Maxima assumes it will be positive when the
10209     'do' is executed.  If it is not positive, then the 'do' may not
10210     terminate properly.
10211
10212     Note that the <limit>, <increment>, and termination condition are
10213     evaluated each time through the loop.  Thus if any of these involve
10214     much computation, and yield a result that does not change during
10215     all the executions of the <body>, then it is more efficient to set
10216     a variable to their value prior to the 'do' and use this variable
10217     in the 'do' form.
10218
10219     The value normally returned by a 'do' statement is the atom 'done'.
10220     However, the function 'return' may be used inside the <body> to
10221     exit the 'do' prematurely and give it any desired value.  Note
10222     however that a 'return' within a 'do' that occurs in a 'block' will
10223     exit only the 'do' and not the 'block'.  Note also that the 'go'
10224     function may not be used to exit from a 'do' into a surrounding
10225     'block'.
10226
10227     The control-variable is always local to the 'do' and thus any
10228     variable may be used without affecting the value of a variable with
10229     the same name outside of the 'do'.  The control-variable is unbound
10230     after the 'do' terminates.
10231
10232          (%i1) for a:-3 thru 26 step 7 do display(a)$
10233                                       a = - 3
10234
10235                                        a = 4
10236
10237                                       a = 11
10238
10239                                       a = 18
10240
10241                                       a = 25
10242
10243          (%i1) s: 0$
10244          (%i2) for i: 1 while i <= 10 do s: s+i;
10245          (%o2)                         done
10246          (%i3) s;
10247          (%o3)                          55
10248
10249     Note that the condition 'while i <= 10' is equivalent to 'unless i
10250     > 10' and also 'thru 10'.
10251
10252          (%i1) series: 1$
10253          (%i2) term: exp (sin (x))$
10254          (%i3) for p: 1 unless p > 7 do
10255                    (term: diff (term, x)/p,
10256                     series: series + subst (x=0, term)*x^p)$
10257          (%i4) series;
10258                            7    6     5    4    2
10259                           x    x     x    x    x
10260          (%o4)            -- - --- - -- - -- + -- + x + 1
10261                           90   240   15   8    2
10262
10263     which gives 8 terms of the Taylor series for 'e^sin(x)'.
10264
10265          (%i1) poly: 0$
10266          (%i2) for i: 1 thru 5 do
10267                    for j: i step -1 thru 1 do
10268                        poly: poly + i*x^j$
10269          (%i3) poly;
10270                            5      4       3       2
10271          (%o3)          5 x  + 9 x  + 12 x  + 14 x  + 15 x
10272          (%i4) guess: -3.0$
10273          (%i5) for i: 1 thru 10 do
10274                    (guess: subst (guess, x, 0.5*(x + 10/x)),
10275                     if abs (guess^2 - 10) < 0.00005 then return (guess));
10276          (%o5)                  - 3.162280701754386
10277
10278     This example computes the negative square root of 10 using the
10279     Newton- Raphson iteration a maximum of 10 times.  Had the
10280     convergence criterion not been met the value returned would have
10281     been 'done'.
10282
10283     Instead of always adding a quantity to the control-variable one may
10284     sometimes wish to change it in some other way for each iteration.
10285     In this case one may use 'next <expression>' instead of 'step
10286     <increment>'.  This will cause the control-variable to be set to
10287     the result of evaluating <expression> each time through the loop.
10288
10289          (%i6) for count: 2 next 3*count thru 20 do display (count)$
10290                                      count = 2
10291
10292                                      count = 6
10293
10294                                     count = 18
10295
10296     As an alternative to 'for <variable>: <value> ...do...' the syntax
10297     'for <variable> from <value> ...do...' may be used.  This permits
10298     the 'from <value>' to be placed after the 'step' or 'next' value or
10299     after the termination condition.  If 'from <value>' is omitted then
10300     1 is used as the initial value.
10301
10302     Sometimes one may be interested in performing an iteration where
10303     the control-variable is never actually used.  It is thus
10304     permissible to give only the termination conditions omitting the
10305     initialization and updating information as in the following example
10306     to compute the square-root of 5 using a poor initial guess.
10307
10308          (%i1) x: 1000$
10309          (%i2) thru 20 do x: 0.5*(x + 5.0/x)$
10310          (%i3) x;
10311          (%o3)                   2.23606797749979
10312          (%i4) sqrt(5), numer;
10313          (%o4)                   2.23606797749979
10314
10315     If it is desired one may even omit the termination conditions
10316     entirely and just give 'do <body>' which will continue to evaluate
10317     the <body> indefinitely.  In this case the function 'return' should
10318     be used to terminate execution of the 'do'.
10319
10320          (%i1) newton (f, x):= ([y, df, dfx], df: diff (f ('x), 'x),
10321                    do (y: ev(df), x: x - f(x)/y,
10322                        if abs (f (x)) < 5e-6 then return (x)))$
10323          (%i2) sqr (x) := x^2 - 5.0$
10324          (%i3) newton (sqr, 1000);
10325          (%o3)                   2.236068027062195
10326
10327     (Note that 'return', when executed, causes the current value of 'x'
10328     to be returned as the value of the 'do'.  The 'block' is exited and
10329     this value of the 'do' is returned as the value of the 'block'
10330     because the 'do' is the last statement in the block.)
10331
10332     One other form of the 'do' is available in Maxima.  The syntax is:
10333
10334          for <variable> in <list> <end_tests> do <body>
10335
10336     The elements of <list> are any expressions which will successively
10337     be assigned to the 'variable' on each iteration of the <body>.  The
10338     optional termination tests <end_tests> can be used to terminate
10339     execution of the 'do'; otherwise it will terminate when the <list>
10340     is exhausted or when a 'return' is executed in the <body>.  (In
10341     fact, 'list' may be any non-atomic expression, and successive parts
10342     are taken.)
10343
10344          (%i1)  for f in [log, rho, atan] do ldisp(f(1))$
10345          (%t1)                                  0
10346          (%t2)                                rho(1)
10347                                               %pi
10348          (%t3)                                 ---
10349                                                4
10350          (%i4) ev(%t3,numer);
10351          (%o4)                             0.78539816
10352
10353 -- Function: errcatch (<expr_1>, ..., <expr_n>)
10354
10355     Evaluates <expr_1>, ..., <expr_n> one by one and returns
10356     '[<expr_n>]' (a list) if no error occurs.  If an error occurs in
10357     the evaluation of any argument, 'errcatch' prevents the error from
10358     propagating and returns the empty list '[]' without evaluating any
10359     more arguments.
10360
10361     'errcatch' is useful in 'batch' files where one suspects an error
10362     might occur which would terminate the 'batch' if the error weren't
10363     caught.
10364
10365     See also 'errormsg'.
10366
10367 -- Function: error (<expr_1>, ..., <expr_n>)
10368 -- System variable: error
10369
10370     Evaluates and prints <expr_1>, ..., <expr_n>, and then causes an
10371     error return to top level Maxima or to the nearest enclosing
10372     'errcatch'.
10373
10374     The variable 'error' is set to a list describing the error.  The
10375     first element of 'error' is a format string, which merges all the
10376     strings among the arguments <expr_1>, ..., <expr_n>, and the
10377     remaining elements are the values of any non-string arguments.
10378
10379     'errormsg()' formats and prints 'error'.  This is effectively
10380     reprinting the most recent error message.
10381
10382 -- Function: warning (<expr_1>, ..., <expr_n>)
10383
10384     Evaluates and prints <expr_1>, ..., <expr_n>, as a warning message
10385     that is formatted in a standard way so a maxima front-end may be
10386     able to recognize the warning and to format it accordingly.
10387
10388     The function 'warning' always returns false.
10389
10390 -- Option variable: error_size
10391     Default value: 10
10392
10393     'error_size' modifies error messages according to the size of
10394     expressions which appear in them.  If the size of an expression (as
10395     determined by the Lisp function 'ERROR-SIZE') is greater than
10396     'error_size', the expression is replaced in the message by a
10397     symbol, and the symbol is assigned the expression.  The symbols are
10398     taken from the list 'error_syms'.
10399
10400     Otherwise, the expression is smaller than 'error_size', and the
10401     expression is displayed in the message.
10402
10403     See also 'error' and 'error_syms'.
10404
10405     Example:
10406
10407     The size of 'U', as determined by 'ERROR-SIZE', is 24.
10408
10409          (%i1) U: (C^D^E + B + A)/(cos(X-1) + 1)$
10410
10411          (%i2) error_size: 20$
10412
10413          (%i3) error ("Example expression is", U);
10414
10415          Example expression is errexp1
10416           -- an error.  Quitting.  To debug this try debugmode(true);
10417          (%i4) errexp1;
10418                                      E
10419                                     D
10420                                    C   + B + A
10421          (%o4)                    --------------
10422                                   cos(X - 1) + 1
10423          (%i5) error_size: 30$
10424
10425          (%i6) error ("Example expression is", U);
10426
10427                                   E
10428                                  D
10429                                 C   + B + A
10430          Example expression is --------------
10431                                cos(X - 1) + 1
10432           -- an error.  Quitting.  To debug this try debugmode(true);
10433
10434 -- Option variable: error_syms
10435     Default value: '[errexp1, errexp2, errexp3]'
10436
10437     In error messages, expressions larger than 'error_size' are
10438     replaced by symbols, and the symbols are set to the expressions.
10439     The symbols are taken from the list 'error_syms'.  The first
10440     too-large expression is replaced by 'error_syms[1]', the second by
10441     'error_syms[2]', and so on.
10442
10443     If there are more too-large expressions than there are elements of
10444     'error_syms', symbols are constructed automatically, with the
10445     <n>-th symbol equivalent to 'concat ('errexp, <n>)'.
10446
10447     See also 'error' and 'error_size'.
10448
10449 -- Function: errormsg ()
10450
10451     Reprints the most recent error message.  The variable 'error' holds
10452     the message, and 'errormsg' formats and prints it.
10453
10454 -- Option variable: errormsg
10455     Default value: 'true'
10456
10457     When 'false' the output of error messages is suppressed.
10458
10459     The option variable 'errormsg' can not be set in a block to a local
10460     value.  The global value of 'errormsg' is always present.
10461
10462          (%i1) errormsg;
10463          (%o1)                         true
10464          (%i2) sin(a,b);
10465          sin: wrong number of arguments.
10466           -- an error. To debug this try: debugmode(true);
10467          (%i3) errormsg:false;
10468          (%o3)                         false
10469          (%i4) sin(a,b);
10470           -- an error. To debug this try: debugmode(true);
10471
10472     The option variable 'errormsg' can not be set in a block to a local
10473     value.
10474
10475          (%i1) f(bool):=block([errormsg:bool], print ("value of errormsg is",errormsg))$
10476          (%i2) errormsg:true;
10477          (%o2)                         true
10478          (%i3) f(false);
10479          value of errormsg is true
10480          (%o3)                         true
10481          (%i4) errormsg:false;
10482          (%o4)                         false
10483          (%i5) f(true);
10484          value of errormsg is false
10485          (%o5)                         false
10486
10487 -- Function: go (<tag>)
10488
10489     is used within a 'block' to transfer control to the statement of
10490     the block which is tagged with the argument to 'go'.  To tag a
10491     statement, precede it by an atomic argument as another statement in
10492     the 'block'.  For example:
10493
10494          block ([x], x:1, loop, x+1, ..., go(loop), ...)
10495
10496     The argument to 'go' must be the name of a tag appearing in the
10497     same 'block'.  One cannot use 'go' to transfer to tag in a 'block'
10498     other than the one containing the 'go'.
10499
10500 -- Special operator: if
10501
10502     Represents conditional evaluation.  Various forms of 'if'
10503     expressions are recognized.
10504
10505     'if <cond_1> then <expr_1> else <expr_0>' evaluates to <expr_1> if
10506     <cond_1> evaluates to 'true', otherwise the expression evaluates to
10507     <expr_0>.
10508
10509     The command 'if <cond_1> then <expr_1> elseif <cond_2> then
10510     <expr_2> elseif ... else <expr_0>' evaluates to <expr_k> if
10511     <cond_k> is 'true' and all preceding conditions are 'false'.  If
10512     none of the conditions are 'true', the expression evaluates to
10513     'expr_0'.
10514
10515     A trailing 'else false' is assumed if 'else' is missing.  That is,
10516     the command 'if <cond_1> then <expr_1>' is equivalent to 'if
10517     <cond_1> then <expr_1> else false', and the command 'if <cond_1>
10518     then <expr_1> elseif ... elseif <cond_n> then <expr_n>' is
10519     equivalent to 'if <cond_1> then <expr_1> elseif ... elseif <cond_n>
10520     then <expr_n> else false'.
10521
10522     The alternatives <expr_0>, ..., <expr_n> may be any Maxima
10523     expressions, including nested 'if' expressions.  The alternatives
10524     are neither simplified nor evaluated unless the corresponding
10525     condition is 'true'.
10526
10527     The conditions <cond_1>, ..., <cond_n> are expressions which
10528     potentially or actually evaluate to 'true' or 'false'.  When a
10529     condition does not actually evaluate to 'true' or 'false', the
10530     behavior of 'if' is governed by the global flag 'prederror'.  When
10531     'prederror' is 'true', it is an error if any evaluated condition
10532     does not evaluate to 'true' or 'false'.  Otherwise, conditions
10533     which do not evaluate to 'true' or 'false' are accepted, and the
10534     result is a conditional expression.
10535
10536     Among other elements, conditions may comprise relational and
10537     logical operators as follows.
10538
10539          Operation            Symbol      Type
10540
10541          less than            <           relational infix
10542          less than            <=
10543            or equal to                    relational infix
10544          equality (syntactic) =           relational infix
10545          negation of =        #           relational infix
10546          equality (value)     equal       relational function
10547          negation of equal    notequal    relational function
10548          greater than         >=
10549            or equal to                    relational infix
10550          greater than         >           relational infix
10551          and                  and         logical infix
10552          or                   or          logical infix
10553          not                  not         logical prefix
10554
10555 -- Function: map (<f>, <expr_1>, ..., <expr_n>)
10556
10557     Returns an expression whose leading operator is the same as that of
10558     the expressions <expr_1>, ..., <expr_n> but whose subparts are the
10559     results of applying <f> to the corresponding subparts of the
10560     expressions.  <f> is either the name of a function of n arguments
10561     or is a 'lambda' form of n arguments.
10562
10563     'maperror' - if 'false' will cause all of the mapping functions to
10564     (1) stop when they finish going down the shortest <expr_i> if not
10565     all of the <expr_i> are of the same length and (2) apply <f> to
10566     [<expr_1>, <expr_2>, ...] if the <expr_i> are not all the same type
10567     of object.  If 'maperror' is 'true' then an error message will be
10568     given in the above two instances.
10569
10570     One of the uses of this function is to 'map' a function (e.g.
10571     'partfrac') onto each term of a very large expression where it
10572     ordinarily wouldn't be possible to use the function on the entire
10573     expression due to an exhaustion of list storage space in the course
10574     of the computation.
10575
10576     See also 'scanmap', 'maplist', 'outermap', 'matrixmap' and 'apply'.
10577
10578          (%i1) map(f,x+a*y+b*z);
10579          (%o1)                        f(b z) + f(a y) + f(x)
10580          (%i2) map(lambda([u],partfrac(u,x)),x+1/(x^3+4*x^2+5*x+2));
10581                                     1       1        1
10582          (%o2)                     ----- - ----- + -------- + x
10583                                   x + 2   x + 1          2
10584                                                   (x + 1)
10585          (%i3) map(ratsimp, x/(x^2+x)+(y^2+y)/y);
10586                                                1
10587          (%o3)                            y + ----- + 1
10588                                              x + 1
10589          (%i4) map("=",[a,b],[-0.5,3]);
10590          (%o4)                          [a = - 0.5, b = 3]
10591
10592
10593
10594 -- Function: mapatom (<expr>)
10595
10596     Returns 'true' if and only if <expr> is treated by the mapping
10597     routines as an atom.  "Mapatoms" are atoms, numbers (including
10598     rational numbers), and subscripted variables.
10599
10600 -- Option variable: maperror
10601     Default value: 'true'
10602
10603     When 'maperror' is 'false', causes all of the mapping functions,
10604     for example
10605
10606          map (<f>, <expr_1>, <expr_2>, ...)
10607
10608     to (1) stop when they finish going down the shortest <expr_i> if
10609     not all of the <expr_i> are of the same length and (2) apply <f> to
10610     [<expr_1>, <expr_2>, ...] if the <expr_i> are not all the same type
10611     of object.
10612
10613     If 'maperror' is 'true' then an error message is displayed in the
10614     above two instances.
10615
10616 -- Option variable: mapprint
10617     Default value: 'true'
10618
10619     When 'mapprint' is 'true', various information messages from 'map',
10620     'maplist', and 'fullmap' are produced in certain situations.  These
10621     include situations where 'map' would use 'apply', or 'map' is
10622     truncating on the shortest list.
10623
10624     If 'mapprint' is 'false', these messages are suppressed.
10625
10626 -- Function: maplist (<f>, <expr_1>, ..., <expr_n>)
10627
10628     Returns a list of the applications of <f> to the parts of the
10629     expressions <expr_1>, ..., <expr_n>.  <f> is the name of a
10630     function, or a lambda expression.
10631
10632     'maplist' differs from 'map(<f>, <expr_1>, ..., <expr_n>)' which
10633     returns an expression with the same main operator as <expr_i> has
10634     (except for simplifications and the case where 'map' does an
10635     'apply').
10636
10637 -- Option variable: prederror
10638     Default value: 'false'
10639
10640     When 'prederror' is 'true', an error message is displayed whenever
10641     the predicate of an 'if' statement or an 'is' function fails to
10642     evaluate to either 'true' or 'false'.
10643
10644     If 'false', 'unknown' is returned instead in this case.  The
10645     'prederror: false' mode is not supported in translated code;
10646     however, 'maybe' is supported in translated code.
10647
10648     See also 'is' and 'maybe'.
10649
10650 -- Function: return (<value>)
10651     May be used to exit explicitly from the current 'block', 'while',
10652     'for' or 'do' loop bringing its argument.  It therefore can be
10653     compared with the 'return' statement found in other programming
10654     languages but it yields one difference: In maxima only returns from
10655     the current block, not from the entire function it was called in.
10656     In this aspect it more closely resembles the 'break' statement from
10657     C.
10658
10659          (%i1) for i:1 thru 10 do o:i;
10660          (%o1)                         done
10661          (%i2) for i:1 thru 10 do if i=3 then return(i);
10662          (%o2)                           3
10663          (%i3) for i:1 thru 10 do
10664              (
10665                  block([i],
10666                      i:3,
10667                      return(i)
10668                  ),
10669                  return(8)
10670              );
10671          (%o3)                           8
10672          (%i4) block([i],
10673              i:4,
10674              block([o],
10675                  o:5,
10676                  return(o)
10677              ),
10678              return(i),
10679              return(10)
10680           );
10681          (%o4)                           4
10682
10683     See also 'for', 'while', 'do' and 'block'.
10684
10685 -- Function: scanmap
10686          scanmap (<f>, <expr>)
10687          scanmap (<f>, <expr>, bottomup)
10688
10689     Recursively applies <f> to <expr>, in a top down manner.  This is
10690     most useful when complete factorization is desired, for example:
10691
10692          (%i1) exp:(a^2+2*a+1)*y + x^2$
10693          (%i2) scanmap(factor,exp);
10694                                              2      2
10695          (%o2)                         (a + 1)  y + x
10696
10697     Note the way in which 'scanmap' applies the given function 'factor'
10698     to the constituent subexpressions of <expr>; if another form of
10699     <expr> is presented to 'scanmap' then the result may be different.
10700     Thus, '%o2' is not recovered when 'scanmap' is applied to the
10701     expanded form of 'exp':
10702
10703          (%i3) scanmap(factor,expand(exp));
10704                                     2                  2
10705          (%o3)                      a  y + 2 a y + y + x
10706
10707     Here is another example of the way in which 'scanmap' recursively
10708     applies a given function to all subexpressions, including
10709     exponents:
10710
10711          (%i4) expr : u*v^(a*x+b) + c$
10712          (%i5) scanmap('f, expr);
10713                              f(f(f(a) f(x)) + f(b))
10714          (%o5) f(f(f(u) f(f(v)                      )) + f(c))
10715
10716     'scanmap (<f>, <expr>, bottomup)' applies <f> to <expr> in a
10717     bottom-up manner.  E.g., for undefined 'f',
10718
10719          scanmap(f,a*x+b) ->
10720             f(a*x+b) -> f(f(a*x)+f(b)) -> f(f(f(a)*f(x))+f(b))
10721          scanmap(f,a*x+b,bottomup) -> f(a)*f(x)+f(b)
10722              -> f(f(a)*f(x))+f(b) ->
10723               f(f(f(a)*f(x))+f(b))
10724
10725     In this case, you get the same answer both ways.
10726
10727 -- Function: throw (<expr>)
10728
10729     Evaluates <expr> and throws the value back to the most recent
10730     'catch'.  'throw' is used with 'catch' as a nonlocal return
10731     mechanism.
10732
10733 -- Function: outermap (<f>, <a_1>, ..., <a_n>)
10734
10735     Applies the function <f> to each one of the elements of the outer
10736     product <a_1> cross <a_2> ... cross <a_n>.
10737
10738     <f> is the name of a function of n arguments or a lambda expression
10739     of n arguments.  Each argument <a_k> may be a list or nested list,
10740     or a matrix, or any other kind of expression.
10741
10742     The 'outermap' return value is a nested structure.  Let <x> be the
10743     return value.  Then <x> has the same structure as the first list,
10744     nested list, or matrix argument, '<x>[i_1]...[i_m]' has the same
10745     structure as the second list, nested list, or matrix argument,
10746     '<x>[i_1]...[i_m][j_1]...[j_n]' has the same structure as the third
10747     list, nested list, or matrix argument, and so on, where <m>, <n>,
10748     ... are the numbers of indices required to access the elements of
10749     each argument (one for a list, two for a matrix, one or more for a
10750     nested list).  Arguments which are not lists or matrices have no
10751     effect on the structure of the return value.
10752
10753     Note that the effect of 'outermap' is different from that of
10754     applying <f> to each one of the elements of the outer product
10755     returned by 'cartesian_product'.  'outermap' preserves the
10756     structure of the arguments in the return value, while
10757     'cartesian_product' does not.
10758
10759     'outermap' evaluates its arguments.
10760
10761     See also 'map', 'maplist', and 'apply'.
10762
10763     Examples:
10764
10765     Elementary examples of 'outermap'.  To show the argument
10766     combinations more clearly, 'F' is left undefined.
10767
10768          (%i1) outermap (F, [a, b, c], [1, 2, 3]);
10769          (%o1) [[F(a, 1), F(a, 2), F(a, 3)], [F(b, 1), F(b, 2), F(b, 3)],
10770                                               [F(c, 1), F(c, 2), F(c, 3)]]
10771          (%i2) outermap (F, matrix ([a, b], [c, d]), matrix ([1, 2], [3, 4]));
10772                   [ [ F(a, 1)  F(a, 2) ]  [ F(b, 1)  F(b, 2) ] ]
10773                   [ [                  ]  [                  ] ]
10774                   [ [ F(a, 3)  F(a, 4) ]  [ F(b, 3)  F(b, 4) ] ]
10775          (%o2)    [                                            ]
10776                   [ [ F(c, 1)  F(c, 2) ]  [ F(d, 1)  F(d, 2) ] ]
10777                   [ [                  ]  [                  ] ]
10778                   [ [ F(c, 3)  F(c, 4) ]  [ F(d, 3)  F(d, 4) ] ]
10779          (%i3) outermap (F, [a, b], x, matrix ([1, 2], [3, 4]));
10780                 [ F(a, x, 1)  F(a, x, 2) ]  [ F(b, x, 1)  F(b, x, 2) ]
10781          (%o3) [[                        ], [                        ]]
10782                 [ F(a, x, 3)  F(a, x, 4) ]  [ F(b, x, 3)  F(b, x, 4) ]
10783          (%i4) outermap (F, [a, b], matrix ([1, 2]), matrix ([x], [y]));
10784                 [ [ F(a, 1, x) ]  [ F(a, 2, x) ] ]
10785          (%o4) [[ [            ]  [            ] ],
10786                 [ [ F(a, 1, y) ]  [ F(a, 2, y) ] ]
10787                                        [ [ F(b, 1, x) ]  [ F(b, 2, x) ] ]
10788                                        [ [            ]  [            ] ]]
10789                                        [ [ F(b, 1, y) ]  [ F(b, 2, y) ] ]
10790          (%i5) outermap ("+", [a, b, c], [1, 2, 3]);
10791          (%o5) [[a + 1, a + 2, a + 3], [b + 1, b + 2, b + 3],
10792                                                     [c + 1, c + 2, c + 3]]
10793
10794     A closer examination of the 'outermap' return value.  The first,
10795     second, and third arguments are a matrix, a list, and a matrix,
10796     respectively.  The return value is a matrix.  Each element of that
10797     matrix is a list, and each element of each list is a matrix.
10798
10799          (%i1) arg_1 :  matrix ([a, b], [c, d]);
10800                                      [ a  b ]
10801          (%o1)                       [      ]
10802                                      [ c  d ]
10803          (%i2) arg_2 : [11, 22];
10804          (%o2)                       [11, 22]
10805          (%i3) arg_3 : matrix ([xx, yy]);
10806          (%o3)                      [ xx  yy ]
10807          (%i4) xx_0 : outermap (lambda ([x, y, z], x / y + z), arg_1,
10808                                                             arg_2, arg_3);
10809                         [  [      a        a  ]  [      a        a  ]  ]
10810                         [ [[ xx + --  yy + -- ], [ xx + --  yy + -- ]] ]
10811                         [  [      11       11 ]  [      22       22 ]  ]
10812          (%o4)  Col 1 = [                                              ]
10813                         [  [      c        c  ]  [      c        c  ]  ]
10814                         [ [[ xx + --  yy + -- ], [ xx + --  yy + -- ]] ]
10815                         [  [      11       11 ]  [      22       22 ]  ]
10816                           [  [      b        b  ]  [      b        b  ]  ]
10817                           [ [[ xx + --  yy + -- ], [ xx + --  yy + -- ]] ]
10818                           [  [      11       11 ]  [      22       22 ]  ]
10819                   Col 2 = [                                              ]
10820                           [  [      d        d  ]  [      d        d  ]  ]
10821                           [ [[ xx + --  yy + -- ], [ xx + --  yy + -- ]] ]
10822                           [  [      11       11 ]  [      22       22 ]  ]
10823          (%i5) xx_1 : xx_0 [1][1];
10824                     [      a        a  ]  [      a        a  ]
10825          (%o5)     [[ xx + --  yy + -- ], [ xx + --  yy + -- ]]
10826                     [      11       11 ]  [      22       22 ]
10827          (%i6) xx_2 : xx_0 [1][1] [1];
10828                                [      a        a  ]
10829          (%o6)                 [ xx + --  yy + -- ]
10830                                [      11       11 ]
10831          (%i7) xx_3 : xx_0 [1][1] [1] [1][1];
10832                                            a
10833          (%o7)                        xx + --
10834                                            11
10835          (%i8) [op (arg_1), op (arg_2), op (arg_3)];
10836          (%o8)                  [matrix, [, matrix]
10837          (%i9) [op (xx_0), op (xx_1), op (xx_2)];
10838          (%o9)                  [matrix, [, matrix]
10839
10840     'outermap' preserves the structure of the arguments in the return
10841     value, while 'cartesian_product' does not.
10842
10843          (%i1) outermap (F, [a, b, c], [1, 2, 3]);
10844          (%o1) [[F(a, 1), F(a, 2), F(a, 3)], [F(b, 1), F(b, 2), F(b, 3)],
10845                                               [F(c, 1), F(c, 2), F(c, 3)]]
10846          (%i2) setify (flatten (%));
10847          (%o2) {F(a, 1), F(a, 2), F(a, 3), F(b, 1), F(b, 2), F(b, 3),
10848                                                 F(c, 1), F(c, 2), F(c, 3)}
10849          (%i3) map (lambda ([L], apply (F, L)),
10850                               cartesian_product ({a, b, c}, {1, 2, 3}));
10851          (%o3) {F(a, 1), F(a, 2), F(a, 3), F(b, 1), F(b, 2), F(b, 3),
10852                                                 F(c, 1), F(c, 2), F(c, 3)}
10853          (%i4) is (equal (%, %th (2)));
10854          (%o4)                         true
10855
10856
10857File: maxima.info,  Node: Debugging,  Next: alt-display-pkg,  Prev: Program Flow,  Up: Top
10858
1085938 Debugging
10860************
10861
10862* Menu:
10863
10864* Source Level Debugging::
10865* Keyword Commands::
10866* Functions and Variables for Debugging::
10867
10868
10869File: maxima.info,  Node: Source Level Debugging,  Next: Keyword Commands,  Up: Debugging
10870
1087138.1 Source Level Debugging
10872===========================
10873
10874Maxima has a built-in source level debugger.  The user can set a
10875breakpoint at a function, and then step line by line from there.  The
10876call stack may be examined, together with the variables bound at that
10877level.
10878
10879   The command ':help' or ':h' shows the list of debugger commands.  (In
10880general, commands may be abbreviated if the abbreviation is unique.  If
10881not unique, the alternatives will be listed.)  Within the debugger, the
10882user can also use any ordinary Maxima functions to examine, define, and
10883manipulate variables and expressions.
10884
10885   A breakpoint is set by the ':br' command at the Maxima prompt.
10886Within the debugger, the user can advance one line at a time using the
10887':n' ("next") command.  The ':bt' ("backtrace") command shows a list of
10888stack frames.  The ':r' ("resume") command exits the debugger and
10889continues with execution.  These commands are demonstrated in the
10890example below.
10891
10892     (%i1) load ("/tmp/foobar.mac");
10893
10894     (%o1)                           /tmp/foobar.mac
10895
10896     (%i2) :br foo
10897     Turning on debugging debugmode(true)
10898     Bkpt 0 for foo (in /tmp/foobar.mac line 1)
10899
10900     (%i2) bar (2,3);
10901     Bkpt 0:(foobar.mac 1)
10902     /tmp/foobar.mac:1::
10903
10904     (dbm:1) :bt                        <-- :bt typed here gives a backtrace
10905     #0: foo(y=5)(foobar.mac line 1)
10906     #1: bar(x=2,y=3)(foobar.mac line 9)
10907
10908     (dbm:1) :n                         <-- Here type :n to advance line
10909     (foobar.mac 2)
10910     /tmp/foobar.mac:2::
10911
10912     (dbm:1) :n                         <-- Here type :n to advance line
10913     (foobar.mac 3)
10914     /tmp/foobar.mac:3::
10915
10916     (dbm:1) u;                         <-- Investigate value of u
10917     28
10918
10919     (dbm:1) u: 33;                     <-- Change u to be 33
10920     33
10921
10922     (dbm:1) :r                         <-- Type :r to resume the computation
10923
10924     (%o2)                                1094
10925
10926   The file '/tmp/foobar.mac' is the following:
10927
10928     foo(y) := block ([u:y^2],
10929       u: u+3,
10930       u: u^2,
10931       u);
10932
10933     bar(x,y) := (
10934       x: x+2,
10935       y: y+2,
10936       x: foo(y),
10937       x+y);
10938
10939   USE OF THE DEBUGGER THROUGH EMACS
10940
10941   If the user is running the code under GNU emacs in a shell window
10942(dbl shell), or is running the graphical interface version, Xmaxima,
10943then if he stops at a break point, he will see his current position in
10944the source file which will be displayed in the other half of the window,
10945either highlighted in red, or with a little arrow pointing at the right
10946line.  He can advance single lines at a time by typing M-n (Alt-n).
10947
10948   Under Emacs you should run in a 'dbl' shell, which requires the
10949'dbl.el' file in the elisp directory.  Make sure you install the elisp
10950files or add the Maxima elisp directory to your path: e.g., add the
10951following to your '.emacs' file or the 'site-init.el'
10952
10953     (setq load-path (cons "/usr/share/maxima/5.9.1/emacs" load-path))
10954     (autoload 'dbl "dbl")
10955
10956   then in emacs
10957
10958     M-x dbl
10959
10960   should start a shell window in which you can run programs, for
10961example Maxima, gcl, gdb etc.  This shell window also knows about source
10962level debugging, and display of source code in the other window.
10963
10964   The user may set a break point at a certain line of the file by
10965typing 'C-x space'.  This figures out which function the cursor is in,
10966and then it sees which line of that function the cursor is on.  If the
10967cursor is on, say, line 2 of 'foo', then it will insert in the other
10968window the command, "':br foo 2'", to break 'foo' at its second line.
10969To have this enabled, the user must have maxima-mode.el turned on in the
10970window in which the file 'foobar.mac' is visiting.  There are additional
10971commands available in that file window, such as evaluating the function
10972into the Maxima, by typing 'Alt-Control-x'.
10973
10974
10975File: maxima.info,  Node: Keyword Commands,  Next: Functions and Variables for Debugging,  Prev: Source Level Debugging,  Up: Debugging
10976
1097738.2 Keyword Commands
10978=====================
10979
10980Keyword commands are special keywords which are not interpreted as
10981Maxima expressions.  A keyword command can be entered at the Maxima
10982prompt or the debugger prompt, although not at the break prompt.
10983Keyword commands start with a colon, '':''.  For example, to evaluate a
10984Lisp form you may type ':lisp' followed by the form to be evaluated.
10985
10986     (%i1) :lisp (+ 2 3)
10987     5
10988
10989   The number of arguments taken depends on the particular command.
10990Also, you need not type the whole command, just enough to be unique
10991among the break keywords.  Thus ':br' would suffice for ':break'.
10992
10993   The keyword commands are listed below.
10994
10995':break F n'
10996     Set a breakpoint in function 'F' at line offset 'n' from the
10997     beginning of the function.  If 'F' is given as a string, then it is
10998     assumed to be a file, and 'n' is the offset from the beginning of
10999     the file.  The offset is optional.  If not given, it is assumed to
11000     be zero (first line of the function or file).
11001':bt'
11002     Print a backtrace of the stack frames
11003':continue'
11004     Continue the computation
11005':delete'
11006     Delete the specified breakpoints, or all if none are specified
11007':disable'
11008     Disable the specified breakpoints, or all if none are specified
11009':enable'
11010     Enable the specified breakpoints, or all if none are specified
11011':frame n'
11012     Print stack frame 'n', or the current frame if none is specified
11013':help'
11014     Print help on a debugger command, or all commands if none is
11015     specified
11016':info'
11017     Print information about item
11018':lisp some-form'
11019     Evaluate 'some-form' as a Lisp form
11020':lisp-quiet some-form'
11021     Evaluate Lisp form 'some-form' without any output
11022':next'
11023     Like ':step', except ':next' steps over function calls
11024':quit'
11025     Quit the current debugger level without completing the computation
11026':resume'
11027     Continue the computation
11028':step'
11029     Continue the computation until it reaches a new source line
11030':top'
11031     Return to the Maxima prompt (from any debugger level) without
11032     completing the computation
11033
11034
11035File: maxima.info,  Node: Functions and Variables for Debugging,  Prev: Keyword Commands,  Up: Debugging
11036
1103738.3 Functions and Variables for Debugging
11038==========================================
11039
11040 -- Option variable: debugmode
11041     Default value: 'false'
11042
11043     When a Maxima error occurs, Maxima will start the debugger if
11044     'debugmode' is 'true'.  The user may enter commands to examine the
11045     call stack, set breakpoints, step through Maxima code, and so on.
11046     See 'debugging' for a list of debugger commands.
11047
11048     Enabling 'debugmode' will not catch Lisp errors.
11049
11050 -- Option variable: refcheck
11051     Default value: 'false'
11052
11053     When 'refcheck' is 'true', Maxima prints a message each time a
11054     bound variable is used for the first time in a computation.
11055
11056 -- Option variable: setcheck
11057     Default value: 'false'
11058
11059     If 'setcheck' is set to a list of variables (which can be
11060     subscripted), Maxima prints a message whenever the variables, or
11061     subscripted occurrences of them, are bound with the ordinary
11062     assignment operator ':', the '::' assignment operator, or function
11063     argument binding, but not the function assignment ':=' nor the
11064     macro assignment '::=' operators.  The message comprises the name
11065     of the variable and the value it is bound to.
11066
11067     'setcheck' may be set to 'all' or 'true' thereby including all
11068     variables.
11069
11070     Each new assignment of 'setcheck' establishes a new list of
11071     variables to check, and any variables previously assigned to
11072     'setcheck' are forgotten.
11073
11074     The names assigned to 'setcheck' must be quoted if they would
11075     otherwise evaluate to something other than themselves.  For
11076     example, if 'x', 'y', and 'z' are already bound, then enter
11077
11078          setcheck: ['x, 'y, 'z]$
11079
11080     to put them on the list of variables to check.
11081
11082     No printout is generated when a variable on the 'setcheck' list is
11083     assigned to itself, e.g., 'X: 'X'.
11084
11085 -- Option variable: setcheckbreak
11086     Default value: 'false'
11087
11088     When 'setcheckbreak' is 'true', Maxima will present a break prompt
11089     whenever a variable on the 'setcheck' list is assigned a new value.
11090     The break occurs before the assignment is carried out.  At this
11091     point, 'setval' holds the value to which the variable is about to
11092     be assigned.  Hence, one may assign a different value by assigning
11093     to 'setval'.
11094
11095     See also 'setcheck' and 'setval'.
11096
11097 -- System variable: setval
11098
11099     Holds the value to which a variable is about to be set when a
11100     'setcheckbreak' occurs.  Hence, one may assign a different value by
11101     assigning to 'setval'.
11102
11103     See also 'setcheck' and 'setcheckbreak'.
11104
11105 -- Function: timer (<f_1>, ..., <f_n>)
11106          timer (all)
11107          timer ()
11108
11109     Given functions <f_1>, ..., <f_n>, 'timer' puts each one on the
11110     list of functions for which timing statistics are collected.
11111     'timer(f)$ timer(g)$' puts 'f' and then 'g' onto the list; the list
11112     accumulates from one call to the next.
11113
11114     'timer(all)' puts all user-defined functions (as named by the
11115     global variable 'functions') on the list of timed functions.
11116
11117     With no arguments, 'timer' returns the list of timed functions.
11118
11119     Maxima records how much time is spent executing each function on
11120     the list of timed functions.  'timer_info' returns the timing
11121     statistics, including the average time elapsed per function call,
11122     the number of calls, and the total time elapsed.  'untimer' removes
11123     functions from the list of timed functions.
11124
11125     'timer' quotes its arguments.  'f(x) := x^2$ g:f$ timer(g)$' does
11126     not put 'f' on the timer list.
11127
11128     If 'trace(f)' is in effect, then 'timer(f)' has no effect; 'trace'
11129     and 'timer' cannot both be in effect at the same time.
11130
11131     See also 'timer_devalue'.
11132
11133 -- Function: untimer (<f_1>, ..., <f_n>)
11134          untimer ()
11135
11136     Given functions <f_1>, ..., <f_n>, 'untimer' removes each function
11137     from the timer list.
11138
11139     With no arguments, 'untimer' removes all functions currently on the
11140     timer list.
11141
11142     After 'untimer (f)' is executed, 'timer_info (f)' still returns
11143     previously collected timing statistics, although 'timer_info()'
11144     (with no arguments) does not return information about any function
11145     not currently on the timer list.  'timer (f)' resets all timing
11146     statistics to zero and puts 'f' on the timer list again.
11147
11148 -- Option variable: timer_devalue
11149     Default value: 'false'
11150
11151     When 'timer_devalue' is 'true', Maxima subtracts from each timed
11152     function the time spent in other timed functions.  Otherwise, the
11153     time reported for each function includes the time spent in other
11154     functions.  Note that time spent in untimed functions is not
11155     subtracted from the total time.
11156
11157     See also 'timer' and 'timer_info'.
11158
11159 -- Function: timer_info (<f_1>, ..., <f_n>)
11160          timer_info ()
11161
11162     Given functions <f_1>, ..., <f_n>, 'timer_info' returns a matrix
11163     containing timing information for each function.  With no
11164     arguments, 'timer_info' returns timing information for all
11165     functions currently on the timer list.
11166
11167     The matrix returned by 'timer_info' contains the function name,
11168     time per function call, number of function calls, total time, and
11169     'gctime', which meant "garbage collection time" in the original
11170     Macsyma but is now always zero.
11171
11172     The data from which 'timer_info' constructs its return value can
11173     also be obtained by the 'get' function:
11174
11175          get(f, 'calls);  get(f, 'runtime);  get(f, 'gctime);
11176
11177     See also 'timer'.
11178
11179 -- Function: trace (<f_1>, ..., <f_n>)
11180          trace (all)
11181          trace ()
11182
11183     Given functions <f_1>, ..., <f_n>, 'trace' instructs Maxima to
11184     print out debugging information whenever those functions are
11185     called.  'trace(f)$ trace(g)$' puts 'f' and then 'g' onto the list
11186     of functions to be traced; the list accumulates from one call to
11187     the next.
11188
11189     'trace(all)' puts all user-defined functions (as named by the
11190     global variable 'functions') on the list of functions to be traced.
11191
11192     With no arguments, 'trace' returns a list of all the functions
11193     currently being traced.
11194
11195     The 'untrace' function disables tracing.  See also 'trace_options'.
11196
11197     'trace' quotes its arguments.  Thus, 'f(x) := x^2$ g:f$ trace(g)$'
11198     does not put 'f' on the trace list.
11199
11200     When a function is redefined, it is removed from the timer list.
11201     Thus after 'timer(f)$ f(x) := x^2$', function 'f' is no longer on
11202     the timer list.
11203
11204     If 'timer (f)' is in effect, then 'trace (f)' has no effect;
11205     'trace' and 'timer' can't both be in effect for the same function.
11206
11207 -- Function: trace_options (<f>, <option_1>, ..., <option_n>)
11208          trace_options (<f>)
11209
11210     Sets the trace options for function <f>.  Any previous options are
11211     superseded.  'trace_options (<f>, ...)' has no effect unless 'trace
11212     (<f>)' is also called (either before or after 'trace_options').
11213
11214     'trace_options (<f>)' resets all options to their default values.
11215
11216     The option keywords are:
11217
11218        * 'noprint' Do not print a message at function entry and exit.
11219        * 'break' Put a breakpoint before the function is entered, and
11220          after the function is exited.  See 'break'.
11221        * 'lisp_print' Display arguments and return values as Lisp
11222          objects.
11223        * 'info' Print '-> true' at function entry and exit.
11224        * 'errorcatch' Catch errors, giving the option to signal an
11225          error, retry the function call, or specify a return value.
11226
11227     Trace options are specified in two forms.  The presence of the
11228     option keyword alone puts the option into effect unconditionally.
11229     (Note that option <foo> is not put into effect by specifying
11230     '<foo>: true' or a similar form; note also that keywords need not
11231     be quoted.)  Specifying the option keyword with a predicate
11232     function makes the option conditional on the predicate.
11233
11234     The argument list to the predicate function is always '[level,
11235     direction, function, item]' where 'level' is the recursion level
11236     for the function, 'direction' is either 'enter' or 'exit',
11237     'function' is the name of the function, and 'item' is the argument
11238     list (on entering) or the return value (on exiting).
11239
11240     Here is an example of unconditional trace options:
11241
11242          (%i1) ff(n) := if equal(n, 0) then 1 else n * ff(n - 1)$
11243
11244          (%i2) trace (ff)$
11245
11246          (%i3) trace_options (ff, lisp_print, break)$
11247
11248          (%i4) ff(3);
11249
11250     Here is the same function, with the 'break' option conditional on a
11251     predicate:
11252
11253          (%i5) trace_options (ff, break(pp))$
11254
11255          (%i6) pp (level, direction, function, item) := block (print (item),
11256              return (function = 'ff and level = 3 and direction = exit))$
11257
11258          (%i7) ff(6);
11259
11260 -- Function: untrace
11261          untrace (<f_1>, ..., <f_n>)
11262          untrace ()
11263
11264     Given functions <f_1>, ..., <f_n>, 'untrace' disables tracing
11265     enabled by the 'trace' function.  With no arguments, 'untrace'
11266     disables tracing for all functions.
11267
11268     'untrace' returns a list of the functions for which it disabled
11269     tracing.
11270
11271
11272File: maxima.info,  Node: alt-display-pkg,  Next: asympa-pkg,  Prev: Debugging,  Up: Top
11273
1127439 alt-display
11275**************
11276
11277* Menu:
11278
11279* Introduction to alt-display::
11280* Functions and Variables for alt-display::
11281
11282
11283File: maxima.info,  Node: Introduction to alt-display,  Next: Functions and Variables for alt-display,  Prev: alt-display-pkg,  Up: alt-display-pkg
11284
1128539.1 Introduction to alt-display
11286================================
11287
11288The _alt-display_ package provides a means to change the way that Maxima
11289displays its output.  The <*alt-display1d*> and <*alt-display2d*> Lisp
11290hooks were introduced to Maxima in 2002, but were not easily accessible
11291from the Maxima REPL until the introduction of this package.
11292
11293   The package provides a general purpose function to define alternative
11294display functions, and a separate function to set the display function.
11295The package also provides customized display functions to produce output
11296in TeX, Texinfo, XML and all three output formats within Texinfo.
11297
11298   Here is a sample session:
11299
11300     (%i1) load("alt-display.mac")$
11301     (%i2) set_alt_display(2,tex_display)$
11302
11303     (%i3) x/(x^2+y^2) = 1;
11304     \mbox{\tt\red({\it \%o_3}) \black}$${{x}\over{y^2+x^2}}=1$$
11305
11306     (%i4) set_alt_display(2,mathml_display)$
11307
11308     (%i5) x/(x^2+y^2) = 1;
11309     <math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>mlabel</mi>
11310     <mfenced separators=""><msub><mi>%o</mi> <mn>5</mn></msub>
11311     <mo>,</mo><mfrac><mrow><mi>x</mi> </mrow> <mrow><msup><mrow>
11312     <mi>y</mi> </mrow> <mn>2</mn> </msup> <mo>+</mo> <msup><mrow>
11313     <mi>x</mi> </mrow> <mn>2</mn> </msup> </mrow></mfrac> <mo>=</mo>
11314     <mn>1</mn> </mfenced> </math>
11315
11316     (%i6) set_alt_display(2,multi_display_for_texinfo)$
11317
11318     (%i7) x/(x^2+y^2) = 1;
11319
11320     @iftex
11321     @tex
11322     \mbox{\tt\red({\it \%o_7}) \black}$${{x}\over{y^2+x^2}}=1$$
11323     @end tex
11324     @end iftex
11325     @ifhtml
11326     @html
11327
11328     <math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>mlabel</mi>
11329     <mfenced separators=""><msub><mi>%o</mi> <mn>7</mn></msub>
11330     <mo>,</mo><mfrac><mrow><mi>x</mi> </mrow> <mrow><msup><mrow>
11331     <mi>y</mi> </mrow> <mn>2</mn> </msup> <mo>+</mo> <msup><mrow>
11332     <mi>x</mi> </mrow> <mn>2</mn> </msup> </mrow></mfrac> <mo>=</mo>
11333     <mn>1</mn> </mfenced> </math>
11334     @end html
11335     @end ifhtml
11336     @ifinfo
11337     @example
11338     (%o7) x/(y^2+x^2) = 1
11339     @end example
11340     @end ifinfo
11341
11342   If the alternative display function causes an error, the error is
11343trapped and the display function is reset to the default display.  In
11344the following example, the 'error' function is set to display the
11345output.  This throws an error, which is handled by resetting the
113462d-display to the default.
11347
11348     (%i8) set_alt_display(2,?error)$
11349
11350     (%i9) x;
11351
11352     Error in *alt-display2d*.
11353     Messge: Condition designator ((MLABEL) $%O9 $X) is not of type (OR SYMBOL STRING
11354                                                                  FUNCTION).
11355     *alt-display2d* reset to nil.
11356      -- an error. To debug this try: debugmode(true);
11357
11358     (%i10) x;
11359     (%o10)                                 x
11360
11361
11362File: maxima.info,  Node: Functions and Variables for alt-display,  Prev: Introduction to alt-display,  Up: alt-display-pkg
11363
1136439.2 Functions and Variables for alt-display
11365============================================
11366
11367 -- Function: define_alt_display (<function>(<input>), <expr>)
11368     This function is similar to 'define': it evaluates its arguments
11369     and expands into a function definition.  The <function> is a
11370     function of a single input <input>.  For convenience, a
11371     substitution is applied to <expr> after evaluation, to provide easy
11372     access to Lisp variable names.
11373
11374     Set a time-stamp on each prompt:
11375          (%i1) load("alt-display.mac")$
11376
11377          (%i2) display2d:false$
11378
11379          (%i3) define_alt_display(time_stamp(x),
11380                             block([alt_display1d:false,alt_display2d:false],
11381                                   prompt_prefix:printf(false,"~a~%",timedate()),
11382                                   displa(x)));
11383
11384          (%o3) time_stamp(x):=block([\*alt\-display1d\*:false,
11385                                      \*alt\-display2d\*:false],
11386                           \*prompt\-prefix\*:printf(false,"~a~%",timedate()),displa(x))
11387          (%i4) set_alt_display(1,time_stamp);
11388
11389          (%o4) done
11390          2017-11-27 16:15:58-06:00
11391          (%i5)
11392
11393     The input line '%i3' defines 'time_stamp' using
11394     'define_alt_display'.  The output line '%o3' shows that the Maxima
11395     variable names 'alt_display1d', 'alt_display2d' and 'prompt_prefix'
11396     have been replaced by their Lisp translations, as has 'displa' been
11397     replaced by '?displa' (the display function).
11398
11399     The display variables 'alt_display1d' and 'alt_display2d' are both
11400     bound to 'false' in the body of 'time_stamp' to prevent an infinite
11401     recursion in 'displa'.
11402
11403 -- Function: info_display (<form>)
11404     This is an alias for the default 1-d display function.  It may be
11405     used as an alternative 1-d or 2-d display function.
11406
11407          (%i1) load("alt-display.mac")$
11408
11409          (%i2) set_alt_display(2,info_display);
11410
11411          (%o2) done
11412          (%i3) x/y;
11413
11414          (%o3) x/y
11415
11416 -- Function: mathml_display (<form>)
11417     Produces MathML output.
11418
11419          (%i1) load("alt-display.mac")$
11420
11421          (%i2) set_alt_display(2,mathml_display);
11422          <math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>mlabel</mi>
11423           <mfenced separators=""><msub><mi>%o</mi> <mn>2</mn></msub>
11424           <mo>,</mo><mi>done</mi> </mfenced> </math>
11425
11426 -- Function: tex_display (<form>)
11427     Produces TeX output.
11428
11429          (%i2) set_alt_display(2,tex_display);
11430          \mbox{\tt\red({\it \%o_2}) \black}$$\mathbf{done}$$
11431          (%i3) x/(x^2+y^2);
11432          \mbox{\tt\red({\it \%o_3}) \black}$${{x}\over{y^2+x^2}}$$
11433
11434 -- Function: multi_display_for_texinfo (<form>)
11435     Produces Texinfo output using all three display functions.
11436
11437          (%i2) set_alt_display(2,multi_display_for_texinfo)$
11438
11439          (%i3) x/(x^2+y^2);
11440
11441          @iftex
11442          @tex
11443          \mbox{\tt\red({\it \%o_3}) \black}$${{x}\over{y^2+x^2}}$$
11444          @end tex
11445          @end iftex
11446          @ifhtml
11447          @html
11448
11449             <math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>mlabel</mi>
11450             <mfenced separators=""><msub><mi>%o</mi> <mn>3</mn></msub>
11451             <mo>,</mo><mfrac><mrow><mi>x</mi> </mrow> <mrow><msup><mrow>
11452             <mi>y</mi> </mrow> <mn>2</mn> </msup> <mo>+</mo> <msup><mrow>
11453             <mi>x</mi> </mrow> <mn>2</mn> </msup> </mrow></mfrac> </mfenced> </math>
11454          @end html
11455          @end ifhtml
11456          @ifinfo
11457          @example
11458          (%o3) x/(y^2+x^2)
11459          @end example
11460          @end ifinfo
11461
11462 -- Functions: reset_displays ()
11463     Resets the prompt prefix and suffix to the empty string, and sets
11464     both 1-d and 2-d display functions to the default.
11465
11466 -- Function: set_alt_display (<num>, <display-function>)
11467     The input <num> is the display to set; it may be either 1 or 2.
11468     The second input <display-function> is the display function to use.
11469     The display function may be either a Maxima function or a 'lambda'
11470     expression.
11471
11472     Here is an example where the display function is a 'lambda'
11473     expression; it just displays the result as TeX.
11474          (%i1) load("alt-display.mac")$
11475
11476          (%i2) set_alt_display(2, lambda([form], tex(?caddr(form))))$
11477
11478          (%i3) integrate(exp(-t^2),t,0,inf);
11479          $${{\sqrt{\pi}}\over{2}}$$
11480
11481     A user-defined display function should take care that it _prints_
11482     its output.  A display function that returns a string will appear
11483     to display nothing, nor cause any errors.
11484
11485 -- Function: set_prompt (<fix>, <expr>)
11486     Set the prompt prefix or suffix to <expr>.  The input <fix> must
11487     evaluate to one of 'prefix', 'suffix', 'general', 'prolog' or
11488     'epilog'.  The input <expr> must evaluate to either a string or
11489     'false'; if 'false', the <fix> is reset to the default value.
11490
11491          (%i1) load("alt-display.mac")$
11492          (%i2) set_prompt('prefix,printf(false,"It is now: ~a~%",timedate()))$
11493
11494          It is now: 2014-01-07 15:23:23-05:00
11495          (%i3)
11496
11497     The following example shows the effect of each option, except
11498     'prolog'.  Note that the 'epilog' prompt is printed as Maxima
11499     closes down.  The 'general' is printed between the end of input and
11500     the output, unless the input line ends in '$'.
11501
11502     Here is an example to show where the prompt strings are placed.
11503
11504          (%i1) load("alt-display.mac")$
11505
11506          (%i2) set_prompt(prefix,"<<prefix>> ",suffix,"<<suffix>> ",general,
11507                     printf(false,"<<general>>~%"),epilog,printf(false,"<<epilog>>~%"));
11508
11509          (%o2)                                done
11510          <<prefix>> (%i3) <<suffix>> x/y;
11511          <<general>>
11512                                                 x
11513          (%o3)                                  -
11514                                                 y
11515          <<prefix>> (%i4) <<suffix>> quit();
11516          <<general>>
11517          <<epilog>>
11518
11519     Here is an example that shows how to colorize the input and output
11520     when Maxima is running in a terminal or terminal emulator like
11521     Emacs(1).
11522
11523          (%i1) load("alt-display.mac")$
11524
11525          (%i2) cs(s) := printf(false,"~c[~am",ascii(27),s)$
11526
11527          (%i3) set_prompt(prefix,cs("1;31"),suffix,cs("0;32"),general,cs("1;34"),epilog,cs("00;"));
11528          (%o3)                                done
11529          (%i4) integrate(exp(-x^2),x,0,inf);
11530                                             sqrt(%pi)
11531          (%o4)                              ---------
11532                                                 2
11533          (%i5)
11534
11535     Each prompt string starts with the ASCII escape character (27)
11536     followed by an open square bracket (91); each string ends with a
11537     lower-case m (109).  The webpages
11538     <http://misc.flogisoft.com/bash/tip_colors_and_formatting> and
11539     <http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html> provide
11540     information on how to use control strings to set the terminal
11541     colors.
11542
11543   ---------- Footnotes ----------
11544
11545   (1) Readers using the 'info' reader in 'Emacs' will see the actual
11546prompt strings; other readers will see the colorized output
11547
11548
11549File: maxima.info,  Node: asympa-pkg,  Next: augmented_lagrangian-pkg,  Prev: alt-display-pkg,  Up: Top
11550
1155140 asympa
11552*********
11553
11554* Menu:
11555
11556* Introduction to asympa::
11557* Functions and variables for asympa::
11558
11559
11560File: maxima.info,  Node: Introduction to asympa,  Next: Functions and variables for asympa,  Prev: asympa-pkg,  Up: asympa-pkg
11561
1156240.1 Introduction to asympa
11563===========================
11564
11565 -- Function: asympa
11566     'asympa' is a package for asymptotic analysis.  The package
11567     contains simplification functions for asymptotic analysis,
11568     including the "big O" and "little o" functions that are widely used
11569     in complexity analysis and numerical analysis.
11570
11571     'load ("asympa")' loads this package.
11572
11573
11574File: maxima.info,  Node: Functions and variables for asympa,  Prev: Introduction to asympa,  Up: asympa-pkg
11575
1157640.2 Functions and variables for asympa
11577=======================================
11578
11579
11580File: maxima.info,  Node: augmented_lagrangian-pkg,  Next: Bernstein-pkg,  Prev: asympa-pkg,  Up: Top
11581
1158241 augmented_lagrangian
11583***********************
11584
11585* Menu:
11586
11587* Functions and Variables for augmented_lagrangian::
11588
11589
11590File: maxima.info,  Node: Functions and Variables for augmented_lagrangian,  Prev: augmented_lagrangian-pkg,  Up: augmented_lagrangian-pkg
11591
1159241.1 Functions and Variables for augmented_lagrangian
11593=====================================================
11594
11595 -- Function: augmented_lagrangian_method
11596          augmented_lagrangian_method (<FOM>, <xx>, <C>, <yy>)
11597          augmented_lagrangian_method (<FOM>, <xx>, <C>, <yy>,
11598          optional_args)
11599          augmented_lagrangian_method ([<FOM>, <grad>], <xx>, <C>, <yy>)
11600
11601          augmented_lagrangian_method ([<FOM>, <grad>], <xx>, <C>, <yy>,
11602          optional_args)
11603
11604     Returns an approximate minimum of the expression <FOM> with respect
11605     to the variables <xx>, holding the constraints <C> equal to zero.
11606     <yy> is a list of initial guesses for <xx>.  The method employed is
11607     the augmented Lagrangian method (see Refs [1] and [2]).
11608
11609     <grad>, if present, is the gradient of <FOM> with respect to <xx>,
11610     represented as a list of expressions, one for each variable in
11611     <xx>.  If not present, the gradient is constructed automatically.
11612
11613     <FOM> and each element of <grad>, if present, must be ordinary
11614     expressions, not names of functions or lambda expressions.
11615
11616     'optional_args' represents additional arguments, specified as
11617     '<symbol> = <value>'.  The optional arguments recognized are:
11618
11619     'niter'
11620          Number of iterations of the augmented Lagrangian algorithm
11621     'lbfgs_tolerance'
11622          Tolerance supplied to LBFGS
11623     'iprint'
11624          IPRINT parameter (a list of two integers which controls
11625          verbosity) supplied to LBFGS
11626     '%lambda'
11627          Initial value of '%lambda' to be used for calculating the
11628          augmented Lagrangian
11629
11630     This implementation minimizes the augmented Lagrangian by applying
11631     the limited-memory BFGS (LBFGS) algorithm, which is a quasi-Newton
11632     algorithm.
11633
11634     'load("augmented_lagrangian")' loads this function.
11635
11636     See also *note lbfgs-pkg::
11637
11638     References:
11639
11640     [1]
11641     <http://www-fp.mcs.anl.gov/otc/Guide/OptWeb/continuous/constrained/nonlinearcon/auglag.html>
11642
11643     [2] <http://www.cs.ubc.ca/spider/ascher/542/chap10.pdf>
11644
11645     Examples:
11646
11647          (%i1) load ("lbfgs");
11648          (%o1)  /home/gunter/src/maxima-code/share/lbfgs/lbfgs.mac
11649          (%i2) load ("augmented_lagrangian");
11650          (%o2) /home/gunter/src/maxima-code/share/contrib/augmented_lagra\
11651          ngian.mac
11652          (%i3) FOM: x^2 + 2*y^2;
11653                                         2    2
11654          (%o3)                       2 y  + x
11655          (%i4) xx: [x, y];
11656          (%o4)                        [x, y]
11657          (%i5) C: [x + y - 1];
11658          (%o5)                      [y + x - 1]
11659          (%i6) yy: [1, 1];
11660          (%o6)                        [1, 1]
11661          (%i7) augmented_lagrangian_method(FOM, xx, C, yy, iprint=[-1,0]);
11662          (%o7) [[x = 0.666659841080023, y = 0.333340272455448],
11663                                           %lambda = [- 1.333337940892518]]
11664
11665     Same example as before, but this time the gradient is supplied as
11666     an argument.
11667
11668          (%i1) load ("lbfgs")$
11669          (%i2) load ("augmented_lagrangian")$
11670          (%i3) FOM: x^2 + 2*y^2;
11671                                         2    2
11672          (%o3)                       2 y  + x
11673          (%i4) xx: [x, y];
11674          (%o4)                        [x, y]
11675          (%i5) grad : [2*x, 4*y];
11676          (%o5)                      [2 x, 4 y]
11677          (%i6) C: [x + y - 1];
11678          (%o6)                      [y + x - 1]
11679          (%i7) yy: [1, 1];
11680          (%o7)                        [1, 1]
11681          (%i8) augmented_lagrangian_method ([FOM, grad], xx, C, yy,
11682                                       iprint = [-1, 0]);
11683          (%o8) [[x = 0.6666598410800247, y = 0.3333402724554464],
11684                                           %lambda = [- 1.333337940892525]]
11685
11686
11687File: maxima.info,  Node: Bernstein-pkg,  Next: bitwise-pkg,  Prev: augmented_lagrangian-pkg,  Up: Top
11688
1168942 Bernstein
11690************
11691
11692* Menu:
11693
11694* Functions and Variables for Bernstein::
11695
11696
11697File: maxima.info,  Node: Functions and Variables for Bernstein,  Prev: Bernstein-pkg,  Up: Bernstein-pkg
11698
1169942.1 Functions and Variables for Bernstein
11700==========================================
11701
11702 -- Function: bernstein_poly (<k>, <n>, <x>)
11703
11704     Provided 'k' is not a negative integer, the Bernstein polynomials
11705     are defined by 'bernstein_poly(k,n,x) = binomial(n,k) x^k
11706     (1-x)^(n-k)'; for a negative integer 'k', the Bernstein polynomial
11707     'bernstein_poly(k,n,x)' vanishes.  When either 'k' or 'n' are non
11708     integers, the option variable 'bernstein_explicit' controls the
11709     expansion of the Bernstein polynomials into its explicit form;
11710     example:
11711
11712          (%i1) load("bernstein")$
11713
11714          (%i2) bernstein_poly(k,n,x);
11715          (%o2)                bernstein_poly(k, n, x)
11716          (%i3) bernstein_poly(k,n,x), bernstein_explicit : true;
11717                                                 n - k  k
11718          (%o3)            binomial(n, k) (1 - x)      x
11719
11720     The Bernstein polynomials have both a gradef property and an
11721     integrate property:
11722
11723          (%i4) diff(bernstein_poly(k,n,x),x);
11724          (%o4) (bernstein_poly(k - 1, n - 1, x)
11725                                           - bernstein_poly(k, n - 1, x)) n
11726          (%i5) integrate(bernstein_poly(k,n,x),x);
11727          (%o5)
11728                                                                      k + 1
11729           hypergeometric([k + 1, k - n], [k + 2], x) binomial(n, k) x
11730           ----------------------------------------------------------------
11731                                        k + 1
11732
11733     For numeric inputs, both real and complex, the Bernstein
11734     polynomials evaluate to a numeric result:
11735
11736          (%i6) bernstein_poly(5,9, 1/2 + %i);
11737                                  39375 %i   39375
11738          (%o6)                   -------- + -----
11739                                    128       256
11740          (%i7) bernstein_poly(5,9, 0.5b0 + %i);
11741          (%o7)           3.076171875b2 %i + 1.5380859375b2
11742
11743     To use 'bernstein_poly', first 'load("bernstein")'.
11744
11745 -- Variable: bernstein_explicit
11746     Default value: 'false'
11747
11748     When either 'k' or 'n' are non integers, the option variable
11749     'bernstein_explicit' controls the expansion of 'bernstein(k,n,x)'
11750     into its explicit form; example:
11751
11752          (%i1) bernstein_poly(k,n,x);
11753          (%o1)                bernstein_poly(k, n, x)
11754          (%i2) bernstein_poly(k,n,x), bernstein_explicit : true;
11755                                                 n - k  k
11756          (%o2)            binomial(n, k) (1 - x)      x
11757     When both 'k' and 'n' are explicitly integers, 'bernstein(k,n,x)'
11758     _always_ expands to its explicit form.
11759
11760 -- Function: multibernstein_poly (<[k1,k2,..., kp]>, <[n1,n2,..., np]>,
11761          <[x1,x2,..., xp]>)
11762
11763     The multibernstein polynomial 'multibernstein_poly (<[k1, k2, ...,
11764     kp]>, <[n1, n2, ..., np]>, <[x1, x2, ..., xp]>)' is the product of
11765     bernstein polynomials 'bernstein_poly(k1, n1, x1)
11766     bernstein_poly(k2, n2, x2) ... bernstein_poly(kp, np, xp)'.
11767
11768     To use 'multibernstein_poly', first 'load("bernstein")'.
11769
11770 -- Function: bernstein_approx (<f>, <[x1, x1, ..., xn]>, n)
11771
11772     Return the 'n'-th order uniform Bernstein polynomial approximation
11773     for the function '(x1, x2, ..., xn) |--> f'.  Examples
11774
11775          (%i1) bernstein_approx(f(x),[x], 2);
11776                           2       1                          2
11777          (%o1)      f(1) x  + 2 f(-) (1 - x) x + f(0) (1 - x)
11778                                   2
11779          (%i2) bernstein_approx(f(x,y),[x,y], 2);
11780                         2  2       1                2
11781          (%o2) f(1, 1) x  y  + 2 f(-, 1) (1 - x) x y
11782                                    2
11783                            2  2          1   2
11784           + f(0, 1) (1 - x)  y  + 2 f(1, -) x  (1 - y) y
11785                                          2
11786                 1  1                               1         2
11787           + 4 f(-, -) (1 - x) x (1 - y) y + 2 f(0, -) (1 - x)  (1 - y) y
11788                 2  2                               2
11789                      2        2       1                      2
11790           + f(1, 0) x  (1 - y)  + 2 f(-, 0) (1 - x) x (1 - y)
11791                                       2
11792                            2        2
11793           + f(0, 0) (1 - x)  (1 - y)
11794
11795     To use 'bernstein_approx', first 'load("bernstein")'.
11796
11797 -- Function: bernstein_expand (<e>, <[x1, x1, ..., xn]>)
11798
11799     Express the _polynomial_ 'e' exactly as a linear combination of
11800     multi-variable Bernstein polynomials.
11801
11802          (%i1) bernstein_expand(x*y+1,[x,y]);
11803          (%o1)    2 x y + (1 - x) y + x (1 - y) + (1 - x) (1 - y)
11804          (%i2) expand(%);
11805          (%o2)                        x y + 1
11806
11807     Maxima signals an error when the first argument isn't a polynomial.
11808
11809     To use 'bernstein_expand', first 'load("bernstein")'.
11810
11811
11812File: maxima.info,  Node: bitwise-pkg,  Next: bode-pkg,  Prev: Bernstein-pkg,  Up: Top
11813
1181443 bitwise
11815**********
11816
11817The package 'bitwise' provides functions that allow to manipulate bits
11818of integer constants.  As always maxima attempts to simplify the result
11819of the operation if the actual value of a constant isn't known
11820considering attributes that might be known for the variables, see the
11821'declare' mechanism.
11822
11823* Menu:
11824
11825* Functions and Variables for bitwise::
11826
11827
11828File: maxima.info,  Node: Functions and Variables for bitwise,  Prev: Top,  Up: Top
11829
1183043.1 Functions and Variables for bitwise
11831========================================
11832
11833 -- Function: bit_not (<int>)
11834
11835     Inverts all bits of a signed integer.  The result of this action
11836     reads '-int - 1'.
11837
11838          (%i1) load("bitwise")$
11839          (%i2) bit_not(i);
11840          (%o2)                      bit_not(i)
11841          (%i3) bit_not(bit_not(i));
11842          (%o3)                           i
11843          (%i4) bit_not(3);
11844          (%o4)                          - 4
11845          (%i5) bit_not(100);
11846          (%o5)                         - 101
11847          (%i6) bit_not(-101);
11848          (%o6)                          100
11849
11850 -- Function: bit_and (<int1>, ...)
11851
11852     This function calculates a bitwise 'and' of two or more signed
11853     integers.
11854
11855          (%i1) load("bitwise")$
11856          (%i2) bit_and(i,i);
11857          (%o2)                           i
11858          (%i3) bit_and(i,i,i);
11859          (%o3)                           i
11860          (%i4) bit_and(1,3);
11861          (%o4)                           1
11862          (%i5) bit_and(-7,7);
11863          (%o5)                           1
11864
11865     If it is known if one of the parameters to 'bit_and' is even this
11866     information is taken into consideration by the function.
11867          (%i1) load("bitwise")$
11868          (%i2) declare(e,even,o,odd);
11869          (%o2)                         done
11870          (%i3) bit_and(1,e);
11871          (%o3)                           0
11872          (%i4) bit_and(1,o);
11873          (%o4)                           1
11874
11875 -- Function: bit_or (<int1>, ...)
11876
11877     This function calculates a bitwise 'or' of two or more signed
11878     integers.
11879
11880          (%i1) load("bitwise")$
11881          (%i2) bit_or(i,i);
11882          (%o2)                           i
11883          (%i3) bit_or(i,i,i);
11884          (%o3)                           i
11885          (%i4) bit_or(1,3);
11886          (%o4)                           3
11887          (%i5) bit_or(-7,7);
11888          (%o5)                          - 1
11889
11890     If it is known if one of the parameters to 'bit_or' is even this
11891     information is taken into consideration by the function.
11892          (%i1) load("bitwise")$
11893          (%i2) declare(e,even,o,odd);
11894          (%o2)                         done
11895          (%i3) bit_or(1,e);
11896          (%o3)                         e + 1
11897          (%i4) bit_or(1,o);
11898          (%o4)                           o
11899
11900 -- Function: bit_xor (<int1>, ...)
11901
11902     This function calculates a bitwise 'or' of two or more signed
11903     integers.
11904
11905          (%i1) load("bitwise")$
11906          (%i2) bit_xor(i,i);
11907          (%o2)                           0
11908          (%i3) bit_xor(i,i,i);
11909          (%o3)                           i
11910          (%i4) bit_xor(1,3);
11911          (%o4)                           2
11912          (%i5) bit_xor(-7,7);
11913          (%o5)                          - 2
11914
11915     If it is known if one of the parameters to 'bit_xor' is even this
11916     information is taken into consideration by the function.
11917          (%i1) load("bitwise")$
11918          (%i2) declare(e,even,o,odd);
11919          (%o2)                         done
11920          (%i3) bit_xor(1,e);
11921          (%o3)                         e + 1
11922          (%i4) bit_xor(1,o);
11923          (%o4)                         o - 1
11924
11925 -- Function: bit_lsh (<int>, <nBits>)
11926
11927     This function shifts all bits of the signed integer 'int' to the
11928     left by 'nBits' bits.  The width of the integer is extended by
11929     'nBits' for this process.  The result of 'bit_lsh' therefore is
11930     'int * 2'.
11931
11932          (%i1) load("bitwise")$
11933          (%i2) bit_lsh(0,1);
11934          (%o2)                           0
11935          (%i3) bit_lsh(1,0);
11936          (%o3)                           1
11937          (%i4) bit_lsh(1,1);
11938          (%o4)                           2
11939          (%i5) bit_lsh(1,i);
11940          (%o5)                     bit_lsh(1, i)
11941          (%i6) bit_lsh(-3,1);
11942          (%o6)                          - 6
11943          (%i7) bit_lsh(-2,1);
11944          (%o7)                          - 4
11945
11946 -- Function: bit_rsh (<int>, <nBits>)
11947
11948     This function shifts all bits of the signed integer 'int' to the
11949     right by 'nBits' bits.  The width of the integer is reduced by
11950     'nBits' for this process.
11951
11952          (%i1) load("bitwise")$
11953          (%i2) bit_rsh(0,1);
11954          (%o2)                           0
11955          (%i3) bit_rsh(2,0);
11956          (%o3)                           2
11957          (%i4) bit_rsh(2,1);
11958          (%o4)                           1
11959          (%i5) bit_rsh(2,2);
11960          (%o5)                           0
11961          (%i6) bit_rsh(-3,1);
11962          (%o6)                          - 2
11963          (%i7) bit_rsh(-2,1);
11964          (%o7)                          - 1
11965          (%i8) bit_rsh(-2,2);
11966          (%o8)                          - 1
11967
11968 -- Function: bit_length (<int>)
11969
11970     determines how many bits a variable needs to be long in order to
11971     store the number 'int'.  This function only operates on positive
11972     numbers.
11973
11974          (%i1) load("bitwise")$
11975          (%i2) bit_length(0);
11976          (%o2)                           0
11977          (%i3) bit_length(1);
11978          (%o3)                           1
11979          (%i4) bit_length(7);
11980          (%o4)                           3
11981          (%i5) bit_length(8);
11982          (%o5)                           4
11983
11984 -- Function: bit_onep (<int>, <nBit>)
11985
11986     determines if bits 'nBit' is set in the signed integer 'int'.
11987
11988          (%i1) load("bitwise")$
11989          (%i2) bit_onep(85,0);
11990          (%o2)                         true
11991          (%i3) bit_onep(85,1);
11992          (%o3)                         false
11993          (%i4) bit_onep(85,2);
11994          (%o4)                         true
11995          (%i5) bit_onep(85,3);
11996          (%o5)                         false
11997          (%i6) bit_onep(85,100);
11998          (%o6)                         false
11999          (%i7) bit_onep(i,100);
12000          (%o7)                   bit_onep(i, 100)
12001
12002     For signed numbers the sign bit is interpreted to be more than
12003     'nBit' to the left of the leftmost bit of 'int' that reads '1'.
12004          (%i1) load("bitwise")$
12005          (%i2) bit_onep(-2,0);
12006          (%o2)                         false
12007          (%i3) bit_onep(-2,1);
12008          (%o3)                         true
12009          (%i4) bit_onep(-2,2);
12010          (%o4)                         true
12011          (%i5) bit_onep(-2,3);
12012          (%o5)                         true
12013          (%i6) bit_onep(-2,4);
12014          (%o6)                         true
12015
12016     If it is known if the number to be tested is even this information
12017     is taken into consideration by the function.
12018          (%i1) load("bitwise")$
12019          (%i2) declare(e,even,o,odd);
12020          (%o2)                         done
12021          (%i3) bit_onep(e,0);
12022          (%o3)                         false
12023          (%i4) bit_onep(o,0);
12024          (%o4)                         true
12025
12026
12027File: maxima.info,  Node: bode-pkg,  Next: celine-pkg,  Prev: bitwise-pkg,  Up: Top
12028
1202944 bode
12030*******
12031
12032* Menu:
12033
12034* Functions and Variables for bode::
12035
12036
12037File: maxima.info,  Node: Functions and Variables for bode,  Prev: bode-pkg,  Up: bode-pkg
12038
1203944.1 Functions and Variables for bode
12040=====================================
12041
12042 -- Function: bode_gain (<H>, <range>, ...<plot_opts>...)
12043     Function to draw Bode gain plots.
12044
12045     Examples (1 through 7 from
12046          <http://www.swarthmore.edu/NatSci/echeeve1/Ref/Bode/BodeHow.html>,
12047     8 from Ron Crummett):
12048          (%i1) load("bode")$
12049
12050          (%i2) H1 (s) := 100 * (1 + s) / ((s + 10) * (s + 100))$
12051
12052          (%i3) bode_gain (H1 (s), [w, 1/1000, 1000])$
12053
12054          (%i4) H2 (s) := 1 / (1 + s/omega0)$
12055
12056          (%i5) bode_gain (H2 (s), [w, 1/1000, 1000]), omega0 = 10$
12057
12058          (%i6) H3 (s) := 1 / (1 + s/omega0)^2$
12059
12060          (%i7) bode_gain (H3 (s), [w, 1/1000, 1000]), omega0 = 10$
12061
12062          (%i8) H4 (s) := 1 + s/omega0$
12063
12064          (%i9) bode_gain (H4 (s), [w, 1/1000, 1000]), omega0 = 10$
12065
12066          (%i10) H5 (s) := 1/s$
12067
12068          (%i11) bode_gain (H5 (s), [w, 1/1000, 1000])$
12069
12070          (%i12) H6 (s) := 1/((s/omega0)^2 + 2 * zeta * (s/omega0) + 1)$
12071
12072          (%i13) bode_gain (H6 (s), [w, 1/1000, 1000]),
12073                            omega0 = 10, zeta = 1/10$
12074
12075          (%i14) H7 (s) := (s/omega0)^2 + 2 * zeta * (s/omega0) + 1$
12076
12077          (%i15) bode_gain (H7 (s), [w, 1/1000, 1000]),
12078                            omega0 = 10, zeta = 1/10$
12079
12080          (%i16) H8 (s) := 0.5 / (0.0001 * s^3 + 0.002 * s^2 + 0.01 * s)$
12081
12082          (%i17) bode_gain (H8 (s), [w, 1/1000, 1000])$
12083
12084     To use this function write first 'load("bode")'.  See also
12085     'bode_phase'.
12086
12087 -- Function: bode_phase (<H>, <range>, ...<plot_opts>...)
12088     Function to draw Bode phase plots.
12089
12090     Examples (1 through 7 from
12091          <http://www.swarthmore.edu/NatSci/echeeve1/Ref/Bode/BodeHow.html>,
12092     8 from Ron Crummett):
12093          (%i1) load("bode")$
12094
12095          (%i2) H1 (s) := 100 * (1 + s) / ((s + 10) * (s + 100))$
12096
12097          (%i3) bode_phase (H1 (s), [w, 1/1000, 1000])$
12098
12099          (%i4) H2 (s) := 1 / (1 + s/omega0)$
12100
12101          (%i5) bode_phase (H2 (s), [w, 1/1000, 1000]), omega0 = 10$
12102
12103          (%i6) H3 (s) := 1 / (1 + s/omega0)^2$
12104
12105          (%i7) bode_phase (H3 (s), [w, 1/1000, 1000]), omega0 = 10$
12106
12107          (%i8) H4 (s) := 1 + s/omega0$
12108
12109          (%i9) bode_phase (H4 (s), [w, 1/1000, 1000]), omega0 = 10$
12110
12111          (%i10) H5 (s) := 1/s$
12112
12113          (%i11) bode_phase (H5 (s), [w, 1/1000, 1000])$
12114
12115          (%i12) H6 (s) := 1/((s/omega0)^2 + 2 * zeta * (s/omega0) + 1)$
12116
12117          (%i13) bode_phase (H6 (s), [w, 1/1000, 1000]),
12118                             omega0 = 10, zeta = 1/10$
12119
12120          (%i14) H7 (s) := (s/omega0)^2 + 2 * zeta * (s/omega0) + 1$
12121
12122          (%i15) bode_phase (H7 (s), [w, 1/1000, 1000]),
12123                             omega0 = 10, zeta = 1/10$
12124
12125          (%i16) H8 (s) := 0.5 / (0.0001 * s^3 + 0.002 * s^2 + 0.01 * s)$
12126
12127          (%i17) bode_phase (H8 (s), [w, 1/1000, 1000])$
12128
12129          (%i18) block ([bode_phase_unwrap : false],
12130                        bode_phase (H8 (s), [w, 1/1000, 1000]));
12131
12132          (%i19) block ([bode_phase_unwrap : true],
12133                        bode_phase (H8 (s), [w, 1/1000, 1000]));
12134
12135     To use this function write first 'load("bode")'.  See also
12136     'bode_gain'.
12137
12138
12139File: maxima.info,  Node: celine-pkg,  Next: clebsch_gordan-pkg,  Prev: bode-pkg,  Up: Top
12140
1214145 celine
12142*********
12143
12144* Menu:
12145
12146* Introduction to celine::
12147
12148
12149File: maxima.info,  Node: Introduction to celine,  Up: celine-pkg
12150
1215145.1 Introduction to celine
12152===========================
12153
12154Maxima implementation of Sister Celine's method.  Barton Willis wrote
12155this code.  It is released under the Creative Commons CC0 license
12156(https://creativecommons.org/about/cc0).
12157
12158   Celine's method is described in Sections 4.1-4.4 of the book "A=B",
12159by Marko Petkovsek, Herbert S. Wilf, and Doron Zeilberger.  This book is
12160available at <http://www.math.rutgers.edu/~zeilberg/AeqB.pdf>
12161
12162   Let f = F(n,k).  The function celine returns a set of recursion
12163relations for F of the form
12164
12165   p_0(n) * fff(n,k) + p_1(n) * fff(n+1,k) + ...  + p_p(n) *
12166fff(n+p,k+q),
12167
12168   where p_0 through p_p are polynomials.  If Maxima is unable to
12169determine that sum(sum(a(i,j) * F(n+i,k+j),i,0,p),j,0,q) / F(n,k) is a
12170rational function of n and k, celine returns the empty set.  When f
12171involves parameters (variables other than n or k), celine might make
12172assumptions about these parameters.  Using 'put' with a key of
12173'proviso,' Maxima saves these assumptions on the input label.
12174
12175   To use this function, first load the package integer_sequence,
12176opsubst, and to_poly_solve.
12177
12178   Examples:
12179
12180     (%i1) load("integer_sequence")$
12181     (%i2) load("opsubst")$
12182     (%i3) load("to_poly_solve")$
12183     (%i4) load("celine")$
12184     (%i5) celine(n!,n,k,1,0);
12185     (%o5)       {fff(n + 1, k) - n fff(n, k) - fff(n, k)}
12186
12187   Verification that this result is correct:
12188     (%i1) load("integer_sequence")$
12189     (%i2) load("opsubst")$
12190     (%i3) load("to_poly_solve")$
12191     (%i4) load("celine")$
12192     (%i5) g1:{fff(n+1,k)-n*fff(n,k)-fff(n,k)};
12193     (%o5)       {fff(n + 1, k) - n fff(n, k) - fff(n, k)}
12194     (%i6) ratsimp(minfactorial(first(g1))),fff(n,k) := n!;
12195     (%o6)                           0
12196
12197   An example with parameters including the test that the result of the
12198example is correct:
12199     (%i1) load("integer_sequence")$
12200     (%i2) load("opsubst")$
12201     (%i3) load("to_poly_solve")$
12202     (%i4) load("celine")$
12203     (%i5) e : pochhammer(a,k) * pochhammer(-k,n) / (pochhammer(b,k));
12204                                (a)  (- k)
12205                                   k      n
12206     (%o5)                      -----------
12207                                   (b)
12208                                      k
12209     (%i6) recur : celine(e,n,k,2,1);
12210     (%o6) {fff(n + 2, k + 1) - fff(n + 2, k) - b fff(n + 1, k + 1)
12211      + n ((- fff(n + 1, k + 1)) + 2 fff(n + 1, k) - a fff(n, k)
12212      - fff(n, k)) + a (fff(n + 1, k) - fff(n, k)) + 2 fff(n + 1, k)
12213         2
12214      - n  fff(n, k)}
12215     (%i7) /* Test this result for correctness */
12216     (%i8) first(%), fff(n,k) := ''(e)$
12217     (%i9) makefact(makegamma(%))$
12218     (%o9)                           0
12219     (%i10) minfactorial(factor(minfactorial(factor(%))));
12220
12221   The proviso data suggests that setting a = b may result in a lower
12222order recursion which is shown by the following example:
12223     (%i1) load("integer_sequence")$
12224     (%i2) load("opsubst")$
12225     (%i3) load("to_poly_solve")$
12226     (%i4) load("celine")$
12227     (%i5) e : pochhammer(a,k) * pochhammer(-k,n) / (pochhammer(b,k));
12228                                (a)  (- k)
12229                                   k      n
12230     (%o5)                      -----------
12231                                   (b)
12232                                      k
12233     (%i6) recur : celine(e,n,k,2,1);
12234     (%o6) {fff(n + 2, k + 1) - fff(n + 2, k) - b fff(n + 1, k + 1)
12235      + n ((- fff(n + 1, k + 1)) + 2 fff(n + 1, k) - a fff(n, k)
12236      - fff(n, k)) + a (fff(n + 1, k) - fff(n, k)) + 2 fff(n + 1, k)
12237         2
12238      - n  fff(n, k)}
12239     (%i7) get('%,'proviso);
12240     (%o7)                         false
12241     (%i8) celine(subst(b=a,e),n,k,1,1);
12242     (%o8) {fff(n + 1, k + 1) - fff(n + 1, k) + n fff(n, k)
12243                                                          + fff(n, k)}
12244
12245
12246File: maxima.info,  Node: clebsch_gordan-pkg,  Next: cobyla-pkg,  Prev: celine-pkg,  Up: Top
12247
1224846 clebsch_gordan
12249*****************
12250
12251* Menu:
12252
12253* Functions and Variables for clebsch_gordan::
12254
12255
12256File: maxima.info,  Node: Functions and Variables for clebsch_gordan,  Prev: clebsch_gordan-pkg,  Up: clebsch_gordan-pkg
12257
1225846.1 Functions and Variables for clebsch_gordan
12259===============================================
12260
12261 -- Function: clebsch_gordan (<j1>, <j2>, <m1>, <m2>, <j>, <m>)
12262
12263     Compute the Clebsch-Gordan coefficient <j1, j2, m1, m2 | j, m>.
12264
12265 -- Function: racah_v (<a>, <b>, <c>, <a1>, <b1>, <c1>)
12266
12267     Compute Racah's V coefficient (computed in terms of a related
12268     Clebsch-Gordan coefficient).
12269
12270 -- Function: racah_w (<j1>, <j2>, <j5>, <j4>, <j3>, <j6>)
12271
12272     Compute Racah's W coefficient (computed in terms of a Wigner 6j
12273     symbol)
12274
12275 -- Function: wigner_3j (<j1>, <j2>, <j3>, <m1>, <m2>, <m3>)
12276
12277     Compute Wigner's 3j symbol (computed in terms of a related
12278     Clebsch-Gordan coefficient).
12279
12280 -- Function: wigner_6j (<j1>, <j2>, <j3>, <j4>, <j5>, <j6>)
12281
12282     Compute Wigner's 6j symbol.
12283
12284 -- Function: wigner_9j (<a>, <b>, <c>, <d>, <e>, <f>, <g>, <h>, <i>,
12285          <j>,)
12286
12287     Compute Wigner's 9j symbol.
12288
12289
12290File: maxima.info,  Node: cobyla-pkg,  Next: combinatorics-pkg,  Prev: clebsch_gordan-pkg,  Up: Top
12291
1229247 cobyla
12293*********
12294
12295* Menu:
12296
12297* Introduction to cobyla::
12298* Functions and Variables for cobyla::
12299* Examples for cobyla::
12300
12301
12302File: maxima.info,  Node: Introduction to cobyla,  Next: Functions and Variables for cobyla,  Prev: cobyla-pkg,  Up: cobyla-pkg
12303
1230447.1 Introduction to cobyla
12305===========================
12306
12307'fmin_cobyla' is a Common Lisp translation (via 'f2cl') of the Fortran
12308constrained optimization routine COBYLA by Powell[1][2][3].
12309
12310   COBYLA minimizes an objective function F(X) subject to M inequality
12311constraints of the form g(X) >= 0 on X, where X is a vector of variables
12312that has N components.
12313
12314   Equality constraints g(X)=0 can often be implemented by a pair of
12315inequality constraints g(X)>=0 and -g(X)>= 0.  Maxima's interface to
12316COBYLA allows equality constraints and internally converts the equality
12317constraints to a pair of inequality constraints.
12318
12319   The algorithm employs linear approximations to the objective and
12320constraint functions, the approximations being formed by linear
12321interpolation at N+1 points in the space of the variables.  The
12322interpolation points are regarded as vertices of a simplex.  The
12323parameter RHO controls the size of the simplex and it is reduced
12324automatically from RHOBEG to RHOEND. For each RHO the subroutine tries
12325to achieve a good vector of variables for the current size, and then RHO
12326is reduced until the value RHOEND is reached.  Therefore RHOBEG and
12327RHOEND should be set to reasonable initial changes to and the required
12328accuracy in the variables respectively, but this accuracy should be
12329viewed as a subject for experimentation because it is not guaranteed.
12330The routine treats each constraint individually when calculating a
12331change to the variables, rather than lumping the constraints together
12332into a single penalty function.  The name of the subroutine is derived
12333from the phrase Constrained Optimization BY Linear Approximations.
12334
12335   References:
12336
12337   [1] Fortran Code is from
12338<http://plato.asu.edu/sub/nlores.html#general>
12339
12340   [2] M. J. D. Powell, "A direct search optimization method that models
12341the objective and constraint functions by linear interpolation," in
12342Advances in Optimization and Numerical Analysis, eds.  S. Gomez and
12343J.-P. Hennart (Kluwer Academic: Dordrecht, 1994), p.  51-67.
12344
12345   [3] M. J. D. Powell, "Direct search algorithms for optimization
12346calculations," Acta Numerica 7, 287-336 (1998).  Also available as
12347University of Cambridge, Department of Applied Mathematics and
12348Theoretical Physics, Numerical Analysis Group, Report NA1998/04 from
12349<http://www.damtp.cam.ac.uk/user/na/reports.html>
12350
12351
12352File: maxima.info,  Node: Functions and Variables for cobyla,  Next: Examples for cobyla,  Prev: Introduction to cobyla,  Up: cobyla-pkg
12353
1235447.2 Functions and Variables for cobyla
12355=======================================
12356
12357 -- Function: fmin_cobyla
12358          fmin_cobyla (<F>, <X>, <Y>)
12359          fmin_cobyla (<F>, <X>, <Y>, optional_args)
12360
12361     Returns an approximate minimum of the expression <F> with respect
12362     to the variables <X>, subject to an optional set of constraints.
12363     <Y> is a list of initial guesses for <X>.
12364
12365     <F> must be an ordinary expressions, not names of functions or
12366     lambda expressions.
12367
12368     'optional_args' represents additional arguments, specified as
12369     '<symbol> = <value>'.  The optional arguments recognized are:
12370
12371     'constraints'
12372          List of inequality and equality constraints that must be
12373          satisfied by <X>.  The inequality constraints must be actual
12374          inequalities of the form 'g(<X>) >= h(<X>)' or 'g(<X>) <=
12375          h(<X>)'.  The equality constraints must be of the form 'g(<X>)
12376          = h(<X>)'.
12377     'rhobeg'
12378          Initial value of the internal RHO variable which controls the
12379          size of simplex.  (Defaults to 1.0)
12380     'rhoend'
12381          The desired final value rho parameter.  It is approximately
12382          the accuracy in the variables.  (Defaults to 1d-6.)
12383     'iprint'
12384          Verbose output level.  (Defaults to 0)
12385             * 0 - No output
12386             * 1 - Summary at the end of the calculation
12387             * 2 - Each new value of RHO and SIGMA is printed, including
12388               the vector of variables, some function information when
12389               RHO is reduced.
12390             * 3 - Like 2, but information is printed when F(X) is
12391               computed.
12392     'maxfun'
12393          The maximum number of function evaluations.  (Defaults to
12394          1000).
12395
12396     On return, a vector is given:
12397       1. The value of the variables giving the minimum.  This is a list
12398          of elements of the form '<var> = <value>' for each of the
12399          variables listed in <X>.
12400       2. The minimized function value
12401       3. The number of function evaluations.
12402       4. Return code with the following meanings
12403            1. 0 - No errors.
12404            2. 1 - Limit on maximum number of function evaluations
12405               reached.
12406            3. 2 - Rounding errors inhibiting progress.
12407
12408     'load("fmin_cobyla")' loads this function.
12409
12410 -- Function: bf_fmin_cobyla
12411          bf_fmin_cobyla (<F>, <X>, <Y>)
12412          bf_fmin_cobyla (<F>, <X>, <Y>, optional_args)
12413
12414     This function is identical to 'fmin_cobyla', except that bigfloat
12415     operations are used, and the default value for <rhoend> is
12416     '10^(fpprec/2)'.
12417
12418     See 'fmin_cobyla' for more information.
12419
12420     'load("bf_fmin_cobyla")' loads this function.
12421
12422
12423File: maxima.info,  Node: Examples for cobyla,  Prev: Functions and Variables for cobyla,  Up: cobyla-pkg
12424
1242547.3 Examples for cobyla
12426========================
12427
12428Minimize x1*x2 with 1-x1^2-x2^2 >= 0.  The theoretical solution is x1 =
124291/sqrt(2), x2 = -1/sqrt(2).
12430
12431     (%i1) load("fmin_cobyla")$
12432     (%i2) fmin_cobyla(x1*x2, [x1, x2], [1,1],
12433                       constraints = [x1^2+x2^2<=1], iprint=1);
12434        Normal return from subroutine COBYLA
12435
12436        NFVALS =   66   F =-5.000000E-01    MAXCV = 1.999845E-12
12437        X = 7.071058E-01  -7.071077E-01
12438     (%o2) [[x1 = 0.70710584934848, x2 = - 0.7071077130248],
12439            - 0.49999999999926, [[-1.999955756559757e-12],[]], 66]
12440
12441   There are additional examples in the share/cobyla/ex directory.
12442
12443
12444File: maxima.info,  Node: combinatorics-pkg,  Next: contrib_ode-pkg,  Prev: cobyla-pkg,  Up: Top
12445
1244648 combinatorics
12447****************
12448
12449* Menu:
12450
12451* Package combinatorics::
12452* Functions and Variables for Combinatorics::
12453
12454
12455File: maxima.info,  Node: Package combinatorics,  Next: Functions and Variables for Combinatorics,  Prev: combinatorics-pkg,  Up: combinatorics-pkg
12456
1245748.1 Package combinatorics
12458==========================
12459
12460The 'combinatorics' package provides several functions to work with
12461permutations and to permute elements of a list.  The permutations of
12462degree _n_ are all the _n_!  possible orderings of the first _n_
12463positive integers, 1, 2, ..., _n_.  The functions in this packages
12464expect a permutation to be represented by a list of those integers.
12465
12466   Cycles are represented as a list of two or more integers _i_1_,
12467_i_2_, ..., _i_m_, all different.  Such a list represents a permutation
12468where the integer _i_2_ appears in the _i_1_th position, the integer
12469_i_3_ appears in the _i_2_th position and so on, until the integer
12470_i_1_, which appears in the _i_m_th position.
12471
12472   For instance, [4, 2, 1, 3] is one of the 24 permutations of degree
12473four, which can also be represented by the cycle [1, 4, 3].  The
12474functions where cycles are used to represent permutations also require
12475the order of the permutation to avoid ambiguity.  For instance, the same
12476cycle [1, 4, 3] could refer to the permutation of order 6: [4, 2, 1, 3,
124775, 6].  A product of cycles must be represented by a list of cycles; the
12478cycles at the end of the list are applied first.  For example, [[2, 4],
12479[1, 3, 6, 5]] is equivalent to the permutation [3, 4, 6, 2, 1, 5].
12480
12481   A cycle can be written in several ways.  for instance, [1, 3, 6, 5],
12482[3, 6, 5, 1] and [6, 5, 1, 3] are all equivalent.  The canonical form
12483used in the package is the one that places the lowest index in the first
12484place.  A cycle with only two indices is also called a transposition and
12485if the two indices are consecutive, it is called an adjacent
12486transposition.
12487
12488   To run an interactive tutorial, use the command 'demo
12489(combinatorics)'.  Since this is an additional package, it must be
12490loaded with the command 'load("combinatorics")'.
12491
12492
12493File: maxima.info,  Node: Functions and Variables for Combinatorics,  Prev: Package combinatorics,  Up: combinatorics-pkg
12494
1249548.2 Functions and Variables for Combinatorics
12496==============================================
12497
12498 -- Function: apply_cycles (<cl>,<l>)
12499
12500     Permutes the list or set <l> applying to it the list of cycles
12501     <cl>.  The cycles at the end of the list are applied first and the
12502     first cycle in the list <cl> is the last one to be applied.
12503
12504     See also 'permute'.
12505
12506     Example:
12507
12508          (%i1) load("combinatorics")$
12509          (%i2) lis1:[a,b*c^2,4,z,x/y,1/2,ff23(x),0];
12510                                  2        x  1
12511          (%o2)            [a, b c , 4, z, -, -, ff23(x), 0]
12512                                           y  2
12513          (%i3) apply_cycles ([[1, 6], [2, 6, 5, 7]], lis1);
12514                            x  1                       2
12515          (%o3)            [-, -, 4, z, ff23(x), a, b c , 0]
12516                            y  2
12517
12518 -- Function: cyclep (<c>, <n>)
12519
12520     Returns true if <c> is a valid cycle of order <n> namely, a list of
12521     non-repeated positive integers less or equal to <n>.  Otherwise, it
12522     returns false.
12523
12524     See also 'permp'.
12525
12526     Examples:
12527
12528          (%i1) load("combinatorics")$
12529          (%i2) cyclep ([-2,3,4], 5);
12530          (%o2)                          false
12531          (%i3) cyclep ([2,3,4,2], 5);
12532          (%o3)                          false
12533          (%i4) cyclep ([6,3,4], 5);
12534          (%o4)                          false
12535          (%i5) cyclep ([6,3,4], 6);
12536          (%o5)                          true
12537
12538 -- Function: perm_cycles (<p>)
12539
12540     Returns permutation <p> as a product of cycles.  The cycles are
12541     written in a canonical form, in which the lowest index in the cycle
12542     is placed in the first position.
12543
12544     See also 'perm_decomp'.
12545
12546     Example:
12547
12548          (%i1) load("combinatorics")$
12549          (%i2) perm_cycles ([4, 6, 3, 1, 7, 5, 2, 8]);
12550          (%o2)                 [[1, 4], [2, 6, 5, 7]]
12551
12552 -- Function: perm_decomp (<p>)
12553
12554     Returns the minimum set of adjacent transpositions whose product
12555     equals the given permutation <p>.
12556
12557     See also 'perm_cycles'.
12558
12559     Example:
12560
12561          (%i1) load("combinatorics")$
12562          (%i2) perm_decomp ([4, 6, 3, 1, 7, 5, 2, 8]);
12563          (%o2) [[6, 7], [5, 6], [6, 7], [3, 4], [4, 5], [2, 3], [3, 4],
12564                                      [4, 5], [5, 6], [1, 2], [2, 3], [3, 4]]
12565
12566 -- Function: perm_inverse (<p>)
12567
12568     Returns the inverse of a permutation of <p>, namely, a permutation
12569     <q> such that the products <pq> and <qp> are equal to the identity
12570     permutation: [1, 2, 3, ..., <n>], where <n> is the length of <p>.
12571
12572     See also 'permult'.
12573
12574     Example:
12575
12576          (%i1) load("combinatorics")$
12577          (%i2) perm_inverse ([4, 6, 3, 1, 7, 5, 2, 8]);
12578          (%o2)                [4, 7, 3, 1, 6, 2, 5, 8]
12579
12580 -- Function: perm_length (<p>)
12581
12582     Determines the minimum number of adjacent transpositions necessary
12583     to write permutation <p> as a product of adjacent transpositions.
12584     An adjacent transposition is a cycle with only two numbers, which
12585     are consecutive integers.
12586
12587     See also 'perm_decomp'.
12588
12589     Example:
12590
12591          (%i1) load("combinatorics")$
12592          (%i2) perm_length ([4, 6, 3, 1, 7, 5, 2, 8]);
12593          (%o2)                           12
12594
12595 -- Function: perm_lex_next (<p>)
12596
12597     Returns the permutation that comes after the given permutation <p>,
12598     in the sequence of permutations in lexicographic order.
12599
12600     Example:
12601
12602          (%i1) load("combinatorics")$
12603          (%i2) perm_lex_next ([4, 6, 3, 1, 7, 5, 2, 8]);
12604          (%o2)                [4, 6, 3, 1, 7, 5, 8, 2]
12605
12606 -- Function: perm_lex_rank (<p>)
12607
12608     Finds the position of permutation <p>, an integer from 1 to the
12609     degree <n> of the permutation, in the sequence of permutations in
12610     lexicographic order.
12611
12612     See also 'perm_lex_unrank' and 'perms_lex'.
12613
12614     Example:
12615
12616          (%i1) load("combinatorics")$
12617          (%i2) perm_lex_rank ([4, 6, 3, 1, 7, 5, 2, 8]);
12618          (%o2)                          18255
12619
12620 -- Function: perm_lex_unrank (<n>, <i>)
12621
12622     Returns the _n_-degree permutation at position <i> (from 1 to _n_!)
12623     in the lexicographic ordering of permutations.
12624
12625     See also 'perm_lex_rank' and 'perms_lex'.
12626
12627     Example:
12628
12629          (%i1) load("combinatorics")$
12630          (%i2) perm_lex_unrank (8, 18255);
12631          (%o2)                [4, 6, 3, 1, 7, 5, 2, 8]
12632
12633 -- Function: perm_next (<p>)
12634
12635     Returns the permutation that comes after the given permutation <p>,
12636     in the sequence of permutations in Trotter-Johnson order.
12637
12638     See also 'perms'.
12639
12640     Example:
12641
12642          (%i1) load("combinatorics")$
12643          (%i2) perm_next ([4, 6, 3, 1, 7, 5, 2, 8]);
12644          (%o2)                [4, 6, 3, 1, 7, 5, 8, 2]
12645
12646 -- Function: perm_parity (<p>)
12647
12648     Finds the parity of permutation <p>: 0 if the minimum number of
12649     adjacent transpositions necessary to write permutation <p> as a
12650     product of adjacent transpositions is even, or 1 if that number is
12651     odd.
12652
12653     See also 'perm_decomp'.
12654
12655     Example:
12656
12657          (%i1) load("combinatorics")$
12658          (%i2) perm_parity ([4, 6, 3, 1, 7, 5, 2, 8]);
12659          (%o2)                            0
12660
12661 -- Function: perm_rank (<p>)
12662
12663     Finds the position of permutation <p>, an integer from 1 to the
12664     degree <n> of the permutation, in the sequence of permutations in
12665     Trotter-Johnson order.
12666
12667     See also 'perm_unrank' and 'perms'.
12668
12669     Example:
12670
12671          (%i1) load("combinatorics")$
12672          (%i2) perm_rank ([4, 6, 3, 1, 7, 5, 2, 8]);
12673          (%o2)                          19729
12674
12675 -- Function: perm_undecomp (<cl>, <n>)
12676
12677     Converts the list of cycles <cl> of degree <n> into an <n> degree
12678     permutation, equal to their product.
12679
12680     See also 'perm_decomp'.
12681
12682     Example:
12683
12684          (%i1) load("combinatorics")$
12685          (%i2) perm_undecomp ([[1,6],[2,6,5,7]], 8);
12686          (%o2)                [5, 6, 3, 4, 7, 1, 2, 8]
12687
12688 -- Function: perm_unrank (<n>, <i>)
12689
12690     Returns the _n_-degree permutation at position <i> (from 1 to _n_!)
12691     in the Trotter-Johnson ordering of permutations.
12692
12693     See also 'perm_rank' and 'perms'.
12694
12695     Example:
12696
12697          (%i1) load("combinatorics")$
12698          (%i2) perm_unrank (8, 19729);
12699          (%o2)                [4, 6, 3, 1, 7, 5, 2, 8]
12700
12701 -- Function: permp (<p>)
12702
12703     Returns true if <p> is a valid permutation namely, a list of length
12704     <n>, whose elements are all the positive integers from 1 to <n>,
12705     without repetitions.  Otherwise, it returns false.
12706
12707     Examples:
12708
12709          (%i1) load("combinatorics")$
12710          (%i2) permp ([2,0,3,1]);
12711          (%o2)                          false
12712          (%i3) permp ([2,1,4,3]);
12713          (%o3)                          true
12714
12715 -- Function: perms
12716          perms (<n>)
12717          perms (<n>, <i>)
12718          perms (<n>, <i>, <j>)
12719
12720     'perms(<n>)' returns a list of all _n_-degree permutations in the
12721     so-called Trotter-Johnson order.
12722
12723     'perms(<n>, <i>)' returns the _n_-degree permutation which is at
12724     the _i_th position (from 1 to _n_!)  in the Trotter-Johnson
12725     ordering of the permutations.
12726
12727     'perms(<n>, <i>, <j>)' returns a list of the _n_-degree
12728     permutations between positions <i> and <j> in the Trotter-Johnson
12729     ordering of the permutations.
12730
12731     The sequence of permutations in Trotter-Johnson order starts with
12732     the identity permutation and each consecutive permutation can be
12733     obtained from the previous one a by single adjacent transposition.
12734
12735     See also 'perm_next', 'perm_rank' and 'perm_unrank'.
12736
12737     Examples:
12738
12739          (%i1) load("combinatorics")$
12740          (%i2) perms (4);
12741          (%o2) [[1, 2, 3, 4], [1, 2, 4, 3], [1, 4, 2, 3], [4, 1, 2, 3],
12742          [4, 1, 3, 2], [1, 4, 3, 2], [1, 3, 4, 2], [1, 3, 2, 4],
12743          [3, 1, 2, 4], [3, 1, 4, 2], [3, 4, 1, 2], [4, 3, 1, 2],
12744          [4, 3, 2, 1], [3, 4, 2, 1], [3, 2, 4, 1], [3, 2, 1, 4],
12745          [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 3, 1], [4, 2, 3, 1],
12746          [4, 2, 1, 3], [2, 4, 1, 3], [2, 1, 4, 3], [2, 1, 3, 4]]
12747          (%i3) perms (4, 12);
12748          (%o3)                     [[4, 3, 1, 2]]
12749          (%i4) perms (4, 12, 14);
12750          (%o4)       [[4, 3, 1, 2], [4, 3, 2, 1], [3, 4, 2, 1]]
12751
12752 -- Function: perms_lex
12753          perms_lex (<n>)
12754          perms_lex (<n>, <i>)
12755          perms_lex (<n>, <i>, <j>)
12756
12757     'perms_lex(<n>)' returns a list of all _n_-degree permutations in
12758     the so-called lexicographic order.
12759
12760     'perms_lex(<n>, <i>)' returns the _n_-degree permutation which is
12761     at the _i_th position (from 1 to _n_!)  in the lexicographic
12762     ordering of the permutations.
12763
12764     'perms_lex(<n>, <i>, <j>)' returns a list of the _n_-degree
12765     permutations between positions <i> and <j> in the lexicographic
12766     ordering of the permutations.
12767
12768     The sequence of permutations in lexicographic order starts with all
12769     the permutations with the lowest index, 1, followed by all
12770     permutations starting with the following index, 2, and so on.  The
12771     permutations starting by an index _i_ are the permutations of the
12772     first _n_ integers different from _i_ and they are also placed in
12773     lexicographic order, where the permutations with the lowest of
12774     those integers are placed first and so on.
12775
12776     See also 'perm_lex_next', 'perm_lex_rank' and 'perm_lex_unrank'.
12777
12778     Examples:
12779
12780          (%i1) load("combinatorics")$
12781          (%i2) perms_lex (4);
12782          (%o2) [[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2],
12783          [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3],
12784          [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1],
12785          [3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1],
12786          [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 1, 3, 2],
12787          [4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]]
12788          (%i3) perms_lex (4, 12);
12789          (%o3)                     [[2, 4, 3, 1]]
12790          (%i4) perms_lex (4, 12, 14);
12791          (%o4)       [[2, 4, 3, 1], [3, 1, 2, 4], [3, 1, 4, 2]]
12792
12793 -- Function: permult (<p_1>, ..., <p_m>)
12794
12795     Returns the product of two or more permutations <p_1>, ..., <p_m>.
12796
12797     Example:
12798
12799          (%i1) load("combinatorics")$
12800          (%i2) permult ([2,3,1], [3,1,2], [2,1,3]);
12801          (%o2)                        [2, 1, 3]
12802
12803 -- Function: permute (<p>, <l>)
12804
12805     Applies the permutation <p> to the elements of the list (or set)
12806     <l>.
12807
12808     Example:
12809
12810          (%i1) load("combinatorics")$
12811          (%i2) lis1: [a,b*c^2,4,z,x/y,1/2,ff23(x),0];
12812                                  2        x  1
12813          (%o2)            [a, b c , 4, z, -, -, ff23(x), 0]
12814                                           y  2
12815          (%i3) permute ([4, 6, 3, 1, 7, 5, 2, 8], lis1);
12816                               1                 x     2
12817          (%o3)            [z, -, 4, a, ff23(x), -, b c , 0]
12818                               2                 y
12819
12820 -- Function: random_perm (<n>)
12821
12822     Returns a random permutation of degree <n>.
12823
12824     See also 'random_permutation'.
12825
12826     Example:
12827
12828          (%i1) load("combinatorics")$
12829          (%i2) random_perm (7);
12830          (%o2)                  [6, 3, 4, 7, 5, 1, 2]
12831
12832
12833File: maxima.info,  Node: contrib_ode-pkg,  Next: descriptive-pkg,  Prev: combinatorics-pkg,  Up: Top
12834
1283549 contrib_ode
12836**************
12837
12838* Menu:
12839
12840* Introduction to contrib_ode::
12841* Functions and Variables for contrib_ode::
12842* Possible improvements to contrib_ode::
12843* Test cases for contrib_ode::
12844* References for contrib_ode::
12845
12846
12847File: maxima.info,  Node: Introduction to contrib_ode,  Next: Functions and Variables for contrib_ode,  Prev: contrib_ode-pkg,  Up: contrib_ode-pkg
12848
1284949.1 Introduction to contrib_ode
12850================================
12851
12852Maxima's ordinary differential equation (ODE) solver 'ode2' solves
12853elementary linear ODEs of first and second order.  The function
12854'contrib_ode' extends 'ode2' with additional methods for linear and
12855non-linear first order ODEs and linear homogeneous second order ODEs.
12856The code is still under development and the calling sequence may change
12857in future releases.  Once the code has stabilized it may be moved from
12858the contrib directory and integrated into Maxima.
12859
12860   This package must be loaded with the command 'load('contrib_ode)'
12861before use.
12862
12863   The calling convention for 'contrib_ode' is identical to 'ode2'.  It
12864takes three arguments: an ODE (only the left hand side need be given if
12865the right hand side is 0), the dependent variable, and the independent
12866variable.  When successful, it returns a list of solutions.
12867
12868   The form of the solution differs from 'ode2'.  As non-linear
12869equations can have multiple solutions, 'contrib_ode' returns a list of
12870solutions.  Each solution can have a number of forms:
12871   * an explicit solution for the dependent variable,
12872
12873   * an implicit solution for the dependent variable,
12874
12875   * a parametric solution in terms of variable '%t', or
12876
12877   * a tranformation into another ODE in variable '%u'.
12878
12879   '%c' is used to represent the constant of integration for first order
12880equations.  '%k1' and '%k2' are the constants for second order
12881equations.  If 'contrib_ode' cannot obtain a solution for whatever
12882reason, it returns 'false', after perhaps printing out an error message.
12883
12884   It is necessary to return a list of solutions, as even first order
12885non-linear ODEs can have multiple solutions.  For example:
12886
12887     (%i1) load('contrib_ode)$
12888     (%i2) eqn:x*'diff(y,x)^2-(1+x*y)*'diff(y,x)+y=0;
12889                         dy 2             dy
12890     (%o2)            x (--)  - (1 + x y) -- + y = 0
12891                         dx               dx
12892     (%i3) contrib_ode(eqn,y,x);
12893                         dy 2             dy
12894     (%t3)            x (--)  - (1 + x y) -- + y = 0
12895                         dx               dx
12896
12897                   first order equation not linear in y'
12898
12899                                                  x
12900     (%o3)             [y = log(x) + %c, y = %c %e ]
12901     (%i4) method;
12902     (%o4)                        factor
12903
12904   Nonlinear ODEs can have singular solutions without constants of
12905integration, as in the second solution of the following example:
12906
12907     (%i1) load('contrib_ode)$
12908     (%i2) eqn:'diff(y,x)^2+x*'diff(y,x)-y=0;
12909                            dy 2     dy
12910     (%o2)                 (--)  + x -- - y = 0
12911                            dx       dx
12912     (%i3) contrib_ode(eqn,y,x);
12913                            dy 2     dy
12914     (%t3)                 (--)  + x -- - y = 0
12915                            dx       dx
12916
12917                   first order equation not linear in y'
12918
12919                                                2
12920                                      2        x
12921     (%o3)              [y = %c x + %c , y = - --]
12922                                               4
12923     (%i4) method;
12924     (%o4)                       clairault
12925
12926   The following ODE has two parametric solutions in terms of the dummy
12927variable '%t'.  In this case the parametric solutions can be manipulated
12928to give explicit solutions.
12929
12930     (%i1) load('contrib_ode)$
12931     (%i2) eqn:'diff(y,x)=(x+y)^2;
12932                               dy          2
12933     (%o2)                     -- = (x + y)
12934                               dx
12935     (%i3) contrib_ode(eqn,y,x);
12936     (%o3) [[x = %c - atan(sqrt(%t)), y = (- x) - sqrt(%t)],
12937                          [x = atan(sqrt(%t)) + %c, y = sqrt(%t) - x]]
12938     (%i4) method;
12939     (%o4)                       lagrange
12940
12941   The following example (Kamke 1.112) demonstrates an implicit
12942solution.
12943
12944     (%i1) load('contrib_ode)$
12945     (%i2) assume(x>0,y>0);
12946     (%o2)                    [x > 0, y > 0]
12947     (%i3) eqn:x*'diff(y,x)-x*sqrt(y^2+x^2)-y;
12948                          dy           2    2
12949     (%o3)              x -- - x sqrt(y  + x ) - y
12950                          dx
12951     (%i4) contrib_ode(eqn,y,x);
12952                                       y
12953     (%o4)                  [x - asinh(-) = %c]
12954                                       x
12955     (%i5) method;
12956     (%o5)                          lie
12957
12958   The following Riccati equation is transformed into a linear second
12959order ODE in the variable '%u'.  Maxima is unable to solve the new ODE,
12960so it is returned unevaluated.
12961     (%i1) load('contrib_ode)$
12962     (%i2) eqn:x^2*'diff(y,x)=a+b*x^n+c*x^2*y^2;
12963                         2 dy      2  2      n
12964     (%o2)              x  -- = c x  y  + b x  + a
12965                           dx
12966     (%i3) contrib_ode(eqn,y,x);
12967                    d%u
12968                    ---                            2
12969                    dx        2  a       n - 2    d %u
12970     (%o3)  [[y = - ----, %u c  (-- + b x     ) + ---- c = 0]]
12971                    %u c          2                 2
12972                                 x                dx
12973     (%i4) method;
12974     (%o4)                        riccati
12975
12976   For first order ODEs 'contrib_ode' calls 'ode2'.  It then tries the
12977following methods: factorization, Clairault, Lagrange, Riccati, Abel and
12978Lie symmetry methods.  The Lie method is not attempted on Abel equations
12979if the Abel method fails, but it is tried if the Riccati method returns
12980an unsolved second order ODE.
12981
12982   For second order ODEs 'contrib_ode' calls 'ode2' then 'odelin'.
12983
12984   Extensive debugging traces and messages are displayed if the command
12985'put('contrib_ode,true,'verbose)' is executed.
12986
12987
12988File: maxima.info,  Node: Functions and Variables for contrib_ode,  Next: Possible improvements to contrib_ode,  Prev: Introduction to contrib_ode,  Up: contrib_ode-pkg
12989
1299049.2 Functions and Variables for contrib_ode
12991============================================
12992
12993 -- Function: contrib_ode (<eqn>, <y>, <x>)
12994
12995     Returns a list of solutions of the ODE <eqn> with independent
12996     variable <x> and dependent variable <y>.
12997
12998 -- Function: odelin (<eqn>, <y>, <x>)
12999
13000     'odelin' solves linear homogeneous ODEs of first and second order
13001     with independent variable <x> and dependent variable <y>.  It
13002     returns a fundamental solution set of the ODE.
13003
13004     For second order ODEs, 'odelin' uses a method, due to Bronstein and
13005     Lafaille, that searches for solutions in terms of given special
13006     functions.
13007
13008          (%i1) load('contrib_ode)$
13009          (%i2) odelin(x*(x+1)*'diff(y,x,2)+(x+5)*'diff(y,x,1)+(-4)*y,y,x);
13010                 gauss_a(- 6, - 2, - 3, - x)  gauss_b(- 6, - 2, - 3, - x)
13011          (%o2) {---------------------------, ---------------------------}
13012                              4                            4
13013                             x                            x
13014
13015 -- Function: ode_check (<eqn>, <soln>)
13016
13017     Returns the value of ODE <eqn> after substituting a possible
13018     solution <soln>.  The value is equivalent to zero if <soln> is a
13019     solution of <eqn>.
13020
13021          (%i1) load('contrib_ode)$
13022          (%i2) eqn:'diff(y,x,2)+(a*x+b)*y;
13023                                   2
13024                                  d y
13025          (%o2)                   --- + (b + a x) y
13026                                    2
13027                                  dx
13028          (%i3) ans:[y = bessel_y(1/3,2*(a*x+b)^(3/2)/(3*a))*%k2*sqrt(a*x+b)
13029                   +bessel_j(1/3,2*(a*x+b)^(3/2)/(3*a))*%k1*sqrt(a*x+b)];
13030                                            3/2
13031                              1  2 (b + a x)
13032          (%o3) [y = bessel_y(-, --------------) %k2 sqrt(a x + b)
13033                              3       3 a
13034                                                    3/2
13035                                      1  2 (b + a x)
13036                           + bessel_j(-, --------------) %k1 sqrt(a x + b)]
13037                                      3       3 a
13038          (%i4) ode_check(eqn,ans[1]);
13039          (%o4)                           0
13040
13041 -- System variable: method
13042
13043     The variable 'method' is set to the successful solution method.
13044
13045 -- Variable: %c
13046
13047     '%c' is the integration constant for first order ODEs.
13048
13049 -- Variable: %k1
13050
13051     '%k1' is the first integration constant for second order ODEs.
13052
13053 -- Variable: %k2
13054
13055     '%k2' is the second integration constant for second order ODEs.
13056
13057 -- Function: gauss_a (<a>, <b>, <c>, <x>)
13058
13059     'gauss_a(a,b,c,x)' and 'gauss_b(a,b,c,x)' are 2F1 geometric
13060     functions.  They represent any two independent solutions of the
13061     hypergeometric differential equation 'x(1-x) diff(y,x,2) +
13062     [c-(a+b+1)x] diff(y,x) - aby = 0' (A&S 15.5.1).
13063
13064     The only use of these functions is in solutions of ODEs returned by
13065     'odelin' and 'contrib_ode'.  The definition and use of these
13066     functions may change in future releases of Maxima.
13067
13068     See also 'gauss_b', 'dgauss_a' and 'gauss_b'.
13069
13070 -- Function: gauss_b (<a>, <b>, <c>, <x>)
13071     See 'gauss_a'.
13072
13073 -- Function: dgauss_a (<a>, <b>, <c>, <x>)
13074     The derivative with respect to <x> of 'gauss_a(<a>, <b>, <c>,
13075     <x>)'.
13076
13077 -- Function: dgauss_b (<a>, <b>, <c>, <x>)
13078     The derivative with respect to <x> of 'gauss_b(<a>, <b>, <c>,
13079     <x>)'.
13080
13081 -- Function: kummer_m (<a>, <b>, <x>)
13082
13083     Kummer's M function, as defined in Abramowitz and Stegun, Handbook
13084     of Mathematical Functions, Section 13.1.2.
13085
13086     The only use of this function is in solutions of ODEs returned by
13087     'odelin' and 'contrib_ode'.  The definition and use of this
13088     function may change in future releases of Maxima.
13089
13090     See also 'kummer_u', 'dkummer_m', and 'dkummer_u'.
13091
13092 -- Function: kummer_u (<a>, <b>, <x>)
13093
13094     Kummer's U function, as defined in Abramowitz and Stegun, Handbook
13095     of Mathematical Functions, Section 13.1.3.
13096
13097     See 'kummer_m'.
13098
13099 -- Function: dkummer_m (<a>, <b>, <x>)
13100     The derivative with respect to <x> of 'kummer_m(<a>, <b>, <x>)'.
13101
13102 -- Function: dkummer_u (<a>, <b>, <x>)
13103     The derivative with respect to <x> of 'kummer_u(<a>, <b>, <x>)'.
13104
13105 -- Function: bessel_simplify (<expr>)
13106     Simplifies expressions containing Bessel functions bessel_j,
13107     bessel_y, bessel_i, bessel_k, hankel_1, hankel_2, strauve_h and
13108     strauve_l.  Recurrence relations (given in Abramowitz and Stegun,
13109     Handbook of Mathematical Functions, Section 9.1.27) are used to
13110     replace functions of highest order n by functions of order n-1 and
13111     n-2.
13112
13113     This process repeated until all the orders differ by less than 2.
13114
13115          (%i1) load('contrib_ode)$
13116          (%i2) bessel_simplify(4*bessel_j(n,x^2)*(x^2-n^2/x^2)
13117            +x*((bessel_j(n-2,x^2)-bessel_j(n,x^2))*x
13118            -(bessel_j(n,x^2)-bessel_j(n+2,x^2))*x)
13119            -2*bessel_j(n+1,x^2)+2*bessel_j(n-1,x^2));
13120          (%o2)                           0
13121          (%i3) bessel_simplify(-2*bessel_j(1,z)*z^3-10*bessel_j(2,z)*z^2
13122           +15*%pi*bessel_j(1,z)*struve_h(3,z)*z-15*%pi*struve_h(1,z)*bessel_j(3,z)*z
13123           -15*%pi*bessel_j(0,z)*struve_h(2,z)*z+15*%pi*struve_h(0,z)*bessel_j(2,z)*z
13124           -30*%pi*bessel_j(1,z)*struve_h(2,z)+30*%pi*struve_h(1,z)*bessel_j(2,z));
13125          (%o3)                           0
13126
13127 -- Function: expintegral_e_simplify (<expr>)
13128     Simplify expressions containing exponential integral expintegral_e
13129     using the recurrence (A&S 5.1.14).
13130
13131     expintegral_e(n+1,z) = (1/n) * (exp(-z)-z*expintegral_e(n,z)) n =
13132     1,2,3 ....
13133
13134
13135File: maxima.info,  Node: Possible improvements to contrib_ode,  Next: Test cases for contrib_ode,  Prev: Functions and Variables for contrib_ode,  Up: contrib_ode-pkg
13136
1313749.3 Possible improvements to contrib_ode
13138=========================================
13139
13140These routines are work in progress.  I still need to:
13141
13142   * Extend the FACTOR method 'ode1_factor' to work for multiple roots.
13143
13144   * Extend the FACTOR method 'ode1_factor' to attempt to solve higher
13145     order factors.  At present it only attemps to solve linear factors.
13146
13147   * Fix the LAGRANGE routine 'ode1_lagrange' to prefer real roots over
13148     complex roots.
13149
13150   * Add additional methods for Riccati equations.
13151
13152   * Improve the detection of Abel equations of second kind.  The
13153     exisiting pattern matching is weak.
13154
13155   * Work on the Lie symmetry group routine 'ode1_lie'.  There are quite
13156     a few problems with it: some parts are unimplemented; some test
13157     cases seem to run forever; other test cases crash; yet others
13158     return very complex "solutions".  I wonder if it really ready for
13159     release yet.
13160
13161   * Add more test cases.
13162
13163
13164File: maxima.info,  Node: Test cases for contrib_ode,  Next: References for contrib_ode,  Prev: Possible improvements to contrib_ode,  Up: contrib_ode-pkg
13165
1316649.4 Test cases for contrib_ode
13167===============================
13168
13169The routines have been tested on a approximately one thousand test cases
13170from Murphy, Kamke, Zwillinger and elsewhere.  These are included in the
13171tests subdirectory.
13172
13173   * The Clairault routine 'ode1_clairault' finds all known solutions,
13174     including singular solutions, of the Clairault equations in Murphy
13175     and Kamke.
13176
13177   * The other routines often return a single solution when multiple
13178     solutions exist.
13179
13180   * Some of the "solutions" from 'ode1_lie' are overly complex and
13181     impossible to check.
13182
13183   * There are some crashes.
13184
13185
13186File: maxima.info,  Node: References for contrib_ode,  Prev: Test cases for contrib_ode,  Up: contrib_ode-pkg
13187
1318849.5 References for contrib_ode
13189===============================
13190
13191  1. E. Kamke, Differentialgleichungen Losungsmethoden und Losungen, Vol
13192     1, Geest & Portig, Leipzig, 1961
13193
13194  2. G. M. Murphy, Ordinary Differential Equations and Their Solutions,
13195     Van Nostrand, New York, 1960
13196
13197  3. D. Zwillinger, Handbook of Differential Equations, 3rd edition,
13198     Academic Press, 1998
13199
13200  4. F. Schwarz, Symmetry Analysis of Abel's Equation, Studies in
13201     Applied Mathematics, 100:269-294 (1998)
13202
13203  5. F. Schwarz, Algorithmic Solution of Abel's Equation, Computing 61,
13204     39-49 (1998)
13205
13206  6. E. S. Cheb-Terrab, A. D. Roche, Symmetries and First Order ODE
13207     Patterns, Computer Physics Communications 113 (1998), p 239.
13208     (<http://lie.uwaterloo.ca/papers/ode_vii.pdf>)
13209
13210  7. E. S. Cheb-Terrab, T. Kolokolnikov, First Order ODEs, Symmetries
13211     and Linear Transformations, European Journal of Applied
13212     Mathematics, Vol.  14, No.  2, pp.  231-246 (2003).
13213     (<http://arxiv.org/abs/math-ph/0007023>,
13214     <http://lie.uwaterloo.ca/papers/ode_iv.pdf>)
13215
13216  8. G. W. Bluman, S. C. Anco, Symmetry and Integration Methods for
13217     Differential Equations, Springer, (2002)
13218
13219  9. M. Bronstein, S. Lafaille, Solutions of linear ordinary
13220     differential equations in terms of special functions, Proceedings
13221     of ISSAC 2002, Lille, ACM Press, 23-28.
13222     (<http://www-sop.inria.fr/cafe/Manuel.Bronstein/publications/issac2002.pdf>)
13223
13224
13225File: maxima.info,  Node: descriptive-pkg,  Next: diag-pkg,  Prev: contrib_ode-pkg,  Up: Top
13226
1322750 descriptive
13228**************
13229
13230* Menu:
13231
13232* Introduction to descriptive::
13233* Functions and Variables for data manipulation::
13234* Functions and Variables for descriptive statistics::
13235* Functions and Variables for statistical graphs::
13236
13237
13238File: maxima.info,  Node: Introduction to descriptive,  Next: Functions and Variables for data manipulation,  Prev: descriptive-pkg,  Up: descriptive-pkg
13239
1324050.1 Introduction to descriptive
13241================================
13242
13243Package 'descriptive' contains a set of functions for making descriptive
13244statistical computations and graphing.  Together with the source code
13245there are three data sets in your Maxima tree: 'pidigits.data',
13246'wind.data' and 'biomed.data'.
13247
13248   Any statistics manual can be used as a reference to the functions in
13249package 'descriptive'.
13250
13251   For comments, bugs or suggestions, please contact me at <'riotorto AT
13252yahoo DOT com'>.
13253
13254   Here is a simple example on how the descriptive functions in
13255'descriptive' do they work, depending on the nature of their arguments,
13256lists or matrices,
13257
13258     (%i1) load ("descriptive")$
13259     (%i2) /* univariate sample */   mean ([a, b, c]);
13260                                 c + b + a
13261     (%o2)                       ---------
13262                                     3
13263     (%i3) matrix ([a, b], [c, d], [e, f]);
13264                                 [ a  b ]
13265                                 [      ]
13266     (%o3)                       [ c  d ]
13267                                 [      ]
13268                                 [ e  f ]
13269     (%i4) /* multivariate sample */ mean (%);
13270                           e + c + a  f + d + b
13271     (%o4)                [---------, ---------]
13272                               3          3
13273
13274   Note that in multivariate samples the mean is calculated for each
13275column.
13276
13277   In case of several samples with possible different sizes, the Maxima
13278function 'map' can be used to get the desired results for each sample,
13279
13280     (%i1) load ("descriptive")$
13281     (%i2) map (mean, [[a, b, c], [d, e]]);
13282                             c + b + a  e + d
13283     (%o2)                  [---------, -----]
13284                                 3        2
13285
13286   In this case, two samples of sizes 3 and 2 were stored into a list.
13287
13288   Univariate samples must be stored in lists like
13289
13290     (%i1) s1 : [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5];
13291     (%o1)           [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
13292
13293   and multivariate samples in matrices as in
13294
13295     (%i1) s2 : matrix ([13.17, 9.29], [14.71, 16.88], [18.50, 16.88],
13296                  [10.58, 6.63], [13.33, 13.25], [13.21,  8.12]);
13297                             [ 13.17  9.29  ]
13298                             [              ]
13299                             [ 14.71  16.88 ]
13300                             [              ]
13301                             [ 18.5   16.88 ]
13302     (%o1)                   [              ]
13303                             [ 10.58  6.63  ]
13304                             [              ]
13305                             [ 13.33  13.25 ]
13306                             [              ]
13307                             [ 13.21  8.12  ]
13308
13309   In this case, the number of columns equals the random variable
13310dimension and the number of rows is the sample size.
13311
13312   Data can be introduced by hand, but big samples are usually stored in
13313plain text files.  For example, file 'pidigits.data' contains the first
13314100 digits of number '%pi':
13315           3
13316           1
13317           4
13318           1
13319           5
13320           9
13321           2
13322           6
13323           5
13324           3 ...
13325
13326   In order to load these digits in Maxima,
13327
13328     (%i1) s1 : read_list (file_search ("pidigits.data"))$
13329     (%i2) length (s1);
13330     (%o2)                          100
13331
13332   On the other hand, file 'wind.data' contains daily average wind
13333speeds at 5 meteorological stations in the Republic of Ireland (This is
13334part of a data set taken at 12 meteorological stations.  The original
13335file is freely downloadable from the StatLib Data Repository and its
13336analysis is discused in Haslett, J., Raftery, A. E. (1989) <Space-time
13337Modelling with Long-memory Dependence: Assessing Ireland's Wind Power
13338Resource, with Discussion>.  Applied Statistics 38, 1-50).  This loads
13339the data:
13340
13341     (%i1) s2 : read_matrix (file_search ("wind.data"))$
13342     (%i2) length (s2);
13343     (%o2)                          100
13344     (%i3) s2 [%]; /* last record */
13345     (%o3)            [3.58, 6.0, 4.58, 7.62, 11.25]
13346
13347   Some samples contain non numeric data.  As an example, file
13348'biomed.data' (which is part of another bigger one downloaded from the
13349StatLib Data Repository) contains four blood measures taken from two
13350groups of patients, 'A' and 'B', of different ages,
13351
13352     (%i1) s3 : read_matrix (file_search ("biomed.data"))$
13353     (%i2) length (s3);
13354     (%o2)                          100
13355     (%i3) s3 [1]; /* first record */
13356     (%o3)            [A, 30, 167.0, 89.0, 25.6, 364]
13357
13358   The first individual belongs to group 'A', is 30 years old and
13359his/her blood measures were 167.0, 89.0, 25.6 and 364.
13360
13361   One must take care when working with categorical data.  In the next
13362example, symbol 'a' is assigned a value in some previous moment and then
13363a sample with categorical value 'a' is taken,
13364
13365     (%i1) a : 1$
13366     (%i2) matrix ([a, 3], [b, 5]);
13367                                 [ 1  3 ]
13368     (%o2)                       [      ]
13369                                 [ b  5 ]
13370
13371
13372File: maxima.info,  Node: Functions and Variables for data manipulation,  Next: Functions and Variables for descriptive statistics,  Prev: Introduction to descriptive,  Up: descriptive-pkg
13373
1337450.2 Functions and Variables for data manipulation
13375==================================================
13376
13377 -- Function: build_sample
13378          build_sample (<list>)
13379          build_sample (<matrix>)
13380
13381     Builds a sample from a table of absolute frequencies.  The input
13382     table can be a matrix or a list of lists, all of them of equal
13383     size.  The number of columns or the length of the lists must be
13384     greater than 1.  The last element of each row or list is
13385     interpreted as the absolute frequency.  The output is always a
13386     sample in matrix form.
13387
13388     Examples:
13389
13390     Univariate frequency table.
13391
13392          (%i1) load ("descriptive")$
13393          (%i2) sam1: build_sample([[6,1], [j,2], [2,1]]);
13394                                 [ 6 ]
13395                                 [   ]
13396                                 [ j ]
13397          (%o2)                  [   ]
13398                                 [ j ]
13399                                 [   ]
13400                                 [ 2 ]
13401          (%i3) mean(sam1);
13402                                2 j + 8
13403          (%o3)                [-------]
13404                                   4
13405          (%i4) barsplot(sam1) $
13406
13407     Multivariate frequency table.
13408
13409          (%i1) load ("descriptive")$
13410          (%i2) sam2: build_sample([[6,3,1], [5,6,2], [u,2,1],[6,8,2]]) ;
13411                                     [ 6  3 ]
13412                                     [      ]
13413                                     [ 5  6 ]
13414                                     [      ]
13415                                     [ 5  6 ]
13416          (%o2)                      [      ]
13417                                     [ u  2 ]
13418                                     [      ]
13419                                     [ 6  8 ]
13420                                     [      ]
13421                                     [ 6  8 ]
13422          (%i3) cov(sam2);
13423                 [   2                 2                            ]
13424                 [  u  + 158   (u + 28)     2 u + 174   11 (u + 28) ]
13425                 [  -------- - ---------    --------- - ----------- ]
13426          (%o3)  [     6          36            6           12      ]
13427                 [                                                  ]
13428                 [ 2 u + 174   11 (u + 28)            21            ]
13429                 [ --------- - -----------            --            ]
13430                 [     6           12                 4             ]
13431          (%i4) barsplot(sam2, grouping=stacked) $
13432
13433 -- Function: continuous_freq
13434          continuous_freq (<data>)
13435          continuous_freq (<data>, <m>)
13436
13437     The first argument of 'continuous_freq' must be a list or
13438     1-dimensional array (as created by 'make_array') of numbers.
13439     Divides the range in intervals and counts how many values are
13440     inside them.  The second argument is optional and either equals the
13441     number of classes we want, 10 by default, or equals a list
13442     containing the class limits and the number of classes we want, or a
13443     list containing only the limits.
13444
13445     If sample values are all equal, this function returns only one
13446     class of amplitude 2.
13447
13448     Examples:
13449
13450     Optional argument indicates the number of classes we want.  The
13451     first list in the output contains the interval limits, and the
13452     second the corresponding counts: there are 16 digits inside the
13453     interval '[0, 1.8]', 24 digits in '(1.8, 3.6]', and so on.
13454
13455          (%i1) load ("descriptive")$
13456          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13457          (%i3) continuous_freq (s1, 5);
13458          (%o3) [[0, 1.8, 3.6, 5.4, 7.2, 9.0], [16, 24, 18, 17, 25]]
13459
13460     Optional argument indicates we want 7 classes with limits -2 and
13461     12:
13462
13463          (%i1) load ("descriptive")$
13464          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13465          (%i3) continuous_freq (s1, [-2,12,7]);
13466          (%o3) [[- 2, 0, 2, 4, 6, 8, 10, 12], [8, 20, 22, 17, 20, 13, 0]]
13467
13468     Optional argument indicates we want the default number of classes
13469     with limits -2 and 12:
13470
13471          (%i1) load ("descriptive")$
13472          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13473          (%i3) continuous_freq (s1, [-2,12]);
13474                          3  4  11  18     32  39  46  53
13475          (%o3)  [[- 2, - -, -, --, --, 5, --, --, --, --, 12],
13476                          5  5  5   5      5   5   5   5
13477                         [0, 8, 20, 12, 18, 9, 8, 25, 0, 0]]
13478
13479     The first argument may be an array.
13480
13481          (%i1) load ("descriptive")$
13482          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13483          (%i3) a1 : make_array (fixnum, length (s1)) $
13484          (%i4) fillarray (a1, s1);
13485          (%o4) {Lisp Array:
13486          #(3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 \
13487          5 0 2 8 8 4 1 9 7 1 6 9 3 9 9 3 7 5 1 0 5 8 2 0 9 7 4 9 4 4 5 9
13488            2 3 0 7 8 1 6 4 0 6 2 8 6 2 0 8 9 9 8 6 2 8 0 3 4 8 2 5 3 4 2 \
13489          1 1 7 0 6 7)}
13490          (%i5) continuous_freq (a1);
13491                     9   9  27  18  9  27  63  36  81
13492          (%o5) [[0, --, -, --, --, -, --, --, --, --, 9],
13493                     10  5  10  5   2  5   10  5   10
13494                                       [8, 8, 12, 12, 10, 8, 9, 8, 12, 13]]
13495
13496 -- Function: discrete_freq (<data>)
13497     Counts absolute frequencies in discrete samples, both numeric and
13498     categorical.  Its unique argument is a list, or 1-dimensional array
13499     (as created by 'make_array').
13500
13501          (%i1) load ("descriptive")$
13502          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13503          (%i3) discrete_freq (s1);
13504          (%o3) [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
13505                                       [8, 8, 12, 12, 10, 8, 9, 8, 12, 13]]
13506
13507     The first list gives the sample values and the second their
13508     absolute frequencies.  Commands '? col' and '? transpose' should
13509     help you to understand the last input.
13510
13511     The argument may be an array.
13512
13513          (%i1) load ("descriptive")$
13514          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13515          (%i3) a1 : make_array (fixnum, length (s1)) $
13516          (%i4) fillarray (a1, s1);
13517          (%o4) {Lisp Array:
13518          #(3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 \
13519          5 0 2 8 8 4 1 9 7 1 6 9 3 9 9 3 7 5 1 0 5 8 2 0 9 7 4 9 4 4 5 9
13520            2 3 0 7 8 1 6 4 0 6 2 8 6 2 0 8 9 9 8 6 2 8 0 3 4 8 2 5 3 4 2 \
13521          1 1 7 0 6 7)}
13522          (%i5) discrete_freq (a1);
13523          (%o5) [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
13524                                       [8, 8, 12, 12, 10, 8, 9, 8, 12, 13]]
13525
13526 -- Function: standardize
13527          standardize (<list>)
13528          standardize (<matrix>)
13529
13530     Subtracts to each element of the list the sample mean and divides
13531     the result by the standard deviation.  When the input is a matrix,
13532     'standardize' subtracts to each row the multivariate mean, and then
13533     divides each component by the corresponding standard deviation.
13534
13535 -- Function: subsample
13536          subsample (<data_matrix>, <predicate_function>)
13537          subsample (<data_matrix>, <predicate_function>, <col_num1>,
13538          <col_num2>, ...)
13539
13540     This is a sort of variant of the Maxima 'submatrix' function.  The
13541     first argument is the data matrix, the second is a predicate
13542     function and optional additional arguments are the numbers of the
13543     columns to be taken.  Its behaviour is better understood with
13544     examples.
13545
13546     These are multivariate records in which the wind speed in the first
13547     meteorological station were greater than 18.  See that in the
13548     lambda expression the <i>-th component is referred to as 'v[i]'.
13549          (%i1) load ("descriptive")$
13550          (%i2) s2 : read_matrix (file_search ("wind.data"))$
13551          (%i3) subsample (s2, lambda([v], v[1] > 18));
13552                        [ 19.38  15.37  15.12  23.09  25.25 ]
13553                        [                                   ]
13554                        [ 18.29  18.66  19.08  26.08  27.63 ]
13555          (%o3)         [                                   ]
13556                        [ 20.25  21.46  19.95  27.71  23.38 ]
13557                        [                                   ]
13558                        [ 18.79  18.96  14.46  26.38  21.84 ]
13559
13560     In the following example, we request only the first, second and
13561     fifth components of those records with wind speeds greater or equal
13562     than 16 in station number 1 and less than 25 knots in station
13563     number 4.  The sample contains only data from stations 1, 2 and 5.
13564     In this case, the predicate function is defined as an ordinary
13565     Maxima function.
13566          (%i1) load ("descriptive")$
13567          (%i2) s2 : read_matrix (file_search ("wind.data"))$
13568          (%i3) g(x):= x[1] >= 16 and x[4] < 25$
13569          (%i4) subsample (s2, g, 1, 2, 5);
13570                               [ 19.38  15.37  25.25 ]
13571                               [                     ]
13572                               [ 17.33  14.67  19.58 ]
13573          (%o4)                [                     ]
13574                               [ 16.92  13.21  21.21 ]
13575                               [                     ]
13576                               [ 17.25  18.46  23.87 ]
13577
13578     Here is an example with the categorical variables of 'biomed.data'.
13579     We want the records corresponding to those patients in group 'B'
13580     who are older than 38 years.
13581          (%i1) load ("descriptive")$
13582          (%i2) s3 : read_matrix (file_search ("biomed.data"))$
13583          (%i3) h(u):= u[1] = B and u[2] > 38 $
13584          (%i4) subsample (s3, h);
13585                          [ B  39  28.0  102.3  17.1  146 ]
13586                          [                               ]
13587                          [ B  39  21.0  92.4   10.3  197 ]
13588                          [                               ]
13589                          [ B  39  23.0  111.5  10.0  133 ]
13590                          [                               ]
13591                          [ B  39  26.0  92.6   12.3  196 ]
13592          (%o4)           [                               ]
13593                          [ B  39  25.0  98.7   10.0  174 ]
13594                          [                               ]
13595                          [ B  39  21.0  93.2   5.9   181 ]
13596                          [                               ]
13597                          [ B  39  18.0  95.0   11.3  66  ]
13598                          [                               ]
13599                          [ B  39  39.0  88.5   7.6   168 ]
13600
13601     Probably, the statistical analysis will involve only the blood
13602     measures,
13603          (%i1) load ("descriptive")$
13604          (%i2) s3 : read_matrix (file_search ("biomed.data"))$
13605          (%i3) subsample (s3, lambda([v], v[1] = B and v[2] > 38),
13606                           3, 4, 5, 6);
13607                             [ 28.0  102.3  17.1  146 ]
13608                             [                        ]
13609                             [ 21.0  92.4   10.3  197 ]
13610                             [                        ]
13611                             [ 23.0  111.5  10.0  133 ]
13612                             [                        ]
13613                             [ 26.0  92.6   12.3  196 ]
13614          (%o3)              [                        ]
13615                             [ 25.0  98.7   10.0  174 ]
13616                             [                        ]
13617                             [ 21.0  93.2   5.9   181 ]
13618                             [                        ]
13619                             [ 18.0  95.0   11.3  66  ]
13620                             [                        ]
13621                             [ 39.0  88.5   7.6   168 ]
13622
13623     This is the multivariate mean of 's3',
13624          (%i1) load ("descriptive")$
13625          (%i2) s3 : read_matrix (file_search ("biomed.data"))$
13626          (%i3) mean (s3);
13627                 65 B + 35 A  317          6 NA + 8144.999999999999
13628          (%o3) [-----------, ---, 87.178, ------------------------,
13629                     100      10                     100
13630                                                              3 NA + 19587
13631                                                      18.123, ------------]
13632                                                                  100
13633
13634     Here, the first component is meaningless, since 'A' and 'B' are
13635     categorical, the second component is the mean age of individuals in
13636     rational form, and the fourth and last values exhibit some strange
13637     behaviour.  This is because symbol 'NA' is used here to indicate
13638     <non available> data, and the two means are nonsense.  A possible
13639     solution would be to take out from the matrix those rows with 'NA'
13640     symbols, although this deserves some loss of information.
13641          (%i1) load ("descriptive")$
13642          (%i2) s3 : read_matrix (file_search ("biomed.data"))$
13643          (%i3) g(v):= v[4] # NA and v[6] # NA $
13644          (%i4) mean (subsample (s3, g, 3, 4, 5, 6));
13645          (%o4) [79.4923076923077, 86.2032967032967, 16.93186813186813,
13646                                                                      2514
13647                                                                      ----]
13648                                                                       13
13649
13650 -- Function: transform_sample (<matrix>, <varlist>, <exprlist>)
13651
13652     Transforms the sample <matrix>, where each column is called
13653     according to <varlist>, following expressions in <exprlist>.
13654
13655     Examples:
13656
13657     The second argument assigns names to the three columns.  With these
13658     names, a list of expressions define the transformation of the
13659     sample.
13660
13661          (%i1) load ("descriptive")$
13662          (%i2) data: matrix([3,2,7],[3,7,2],[8,2,4],[5,2,4]) $
13663          (%i3) transform_sample(data, [a,b,c], [c, a*b, log(a)]);
13664                                         [ 7  6   log(3) ]
13665                                         [               ]
13666                                         [ 2  21  log(3) ]
13667          (%o3)                          [               ]
13668                                         [ 4  16  log(8) ]
13669                                         [               ]
13670                                         [ 4  10  log(5) ]
13671
13672     Add a constant column and remove the third variable.
13673
13674          (%i1) load ("descriptive")$
13675          (%i2) data: matrix([3,2,7],[3,7,2],[8,2,4],[5,2,4]) $
13676          (%i3) transform_sample(data, [a,b,c], [makelist(1,k,length(data)),a,b]);
13677                                            [ 1  3  2 ]
13678                                            [         ]
13679                                            [ 1  3  7 ]
13680          (%o3)                             [         ]
13681                                            [ 1  8  2 ]
13682                                            [         ]
13683                                            [ 1  5  2 ]
13684
13685
13686File: maxima.info,  Node: Functions and Variables for descriptive statistics,  Next: Functions and Variables for statistical graphs,  Prev: Functions and Variables for data manipulation,  Up: descriptive-pkg
13687
1368850.3 Functions and Variables for descriptive statistics
13689=======================================================
13690
13691 -- Function: mean
13692          mean (<list>)
13693          mean (<matrix>)
13694
13695     This is the sample mean, defined as
13696                                 n
13697                               ====
13698                       _   1   \
13699                       x = -    >    x
13700                           n   /      i
13701                               ====
13702                               i = 1
13703
13704     Example:
13705
13706          (%i1) load ("descriptive")$
13707          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13708          (%i3) mean (s1);
13709                                         471
13710          (%o3)                          ---
13711                                         100
13712          (%i4) %, numer;
13713          (%o4)                         4.71
13714          (%i5) s2 : read_matrix (file_search ("wind.data"))$
13715          (%i6) mean (s2);
13716          (%o6)     [9.9485, 10.1607, 10.8685, 15.7166, 14.8441]
13717
13718 -- Function: var
13719          var (<list>)
13720          var (<matrix>)
13721
13722     This is the sample variance, defined as
13723                               n
13724                             ====
13725                     2   1   \          _ 2
13726                    s  = -    >    (x - x)
13727                         n   /       i
13728                             ====
13729                             i = 1
13730
13731     Example:
13732
13733          (%i1) load ("descriptive")$
13734          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13735          (%i3) var (s1), numer;
13736          (%o3)                   8.425899999999999
13737
13738     See also function 'var1'.
13739
13740 -- Function: var1
13741          var1 (<list>)
13742          var1 (<matrix>)
13743
13744     This is the sample variance, defined as
13745                               n
13746                             ====
13747                         1   \          _ 2
13748                        ---   >    (x - x)
13749                        n-1  /       i
13750                             ====
13751                             i = 1
13752
13753     Example:
13754
13755          (%i1) load ("descriptive")$
13756          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13757          (%i3) var1 (s1), numer;
13758          (%o3)                    8.5110101010101
13759          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13760          (%i5) var1 (s2);
13761          (%o5) [17.39586540404041, 15.13912778787879, 15.63204924242424,
13762                                      32.50152569696971, 24.66977392929294]
13763
13764     See also function 'var'.
13765
13766 -- Function: std
13767          std (<list>)
13768          std (<matrix>)
13769
13770     This is the square root of the function 'var', the variance with
13771     denominator n.
13772
13773     Example:
13774
13775          (%i1) load ("descriptive")$
13776          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13777          (%i3) std (s1), numer;
13778          (%o3)                   2.902740084816414
13779          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13780          (%i5) std (s2);
13781          (%o5) [4.149928523480858, 3.871399812729241, 3.933920277534866,
13782                                      5.672434260526957, 4.941970881136392]
13783
13784     See also functions 'var' and 'std1'.
13785
13786 -- Function: std1
13787          std1 (<list>)
13788          std1 (<matrix>)
13789
13790     This is the square root of the function 'var1', the variance with
13791     denominator n-1.
13792
13793     Example:
13794
13795          (%i1) load ("descriptive")$
13796          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13797          (%i3) std1 (s1), numer;
13798          (%o3)                   2.917363553109228
13799          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13800          (%i5) std1 (s2);
13801          (%o5) [4.170835096721089, 3.89090320978032, 3.953738641137555,
13802                                      5.701010936401517, 4.966867617451963]
13803
13804     See also functions 'var1' and 'std'.
13805
13806 -- Function: noncentral_moment
13807          noncentral_moment (<list>, <k>)
13808          noncentral_moment (<matrix>, <k>)
13809
13810     The non central moment of order k, defined as
13811                                 n
13812                               ====
13813                           1   \      k
13814                           -    >    x
13815                           n   /      i
13816                               ====
13817                               i = 1
13818
13819     Example:
13820
13821          (%i1) load ("descriptive")$
13822          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13823          (%i3) noncentral_moment (s1, 1), numer; /* the mean */
13824          (%o3)                         4.71
13825          (%i5) s2 : read_matrix (file_search ("wind.data"))$
13826          (%i6) noncentral_moment (s2, 5);
13827          (%o6) [319793.8724761505, 320532.1923892463,
13828                391249.5621381556, 2502278.205988911, 1691881.797742255]
13829
13830     See also function 'central_moment'.
13831
13832 -- Function: central_moment
13833          central_moment (<list>, <k>)
13834          central_moment (<matrix>, <k>)
13835
13836     The central moment of order k, defined as
13837                              n
13838                            ====
13839                        1   \          _ k
13840                        -    >    (x - x)
13841                        n   /       i
13842                            ====
13843                            i = 1
13844
13845     Example:
13846
13847          (%i1) load ("descriptive")$
13848          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13849          (%i3) central_moment (s1, 2), numer; /* the variance */
13850          (%o3)                   8.425899999999999
13851          (%i5) s2 : read_matrix (file_search ("wind.data"))$
13852          (%i6) central_moment (s2, 3);
13853          (%o6) [11.29584771375004, 16.97988248298583, 5.626661952750102,
13854                                       37.5986572057918, 25.85981904394192]
13855
13856     See also functions 'central_moment' and 'mean'.
13857
13858 -- Function: cv
13859          cv (<list>)
13860          cv (<matrix>)
13861
13862     The variation coefficient is the quotient between the sample
13863     standard deviation ('std') and the 'mean',
13864
13865          (%i1) load ("descriptive")$
13866          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13867          (%i3) cv (s1), numer;
13868          (%o3)                   .6193977819764815
13869          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13870          (%i5) cv (s2);
13871          (%o5) [.4192426091090204, .3829365309260502, 0.363779605385983,
13872                                      .3627381836021478, .3346021393989506]
13873
13874     See also functions 'std' and 'mean'.
13875
13876 -- Function: smin
13877          smin (<list>)
13878          smin (<matrix>)
13879
13880     This is the minimum value of the sample <list>.  When the argument
13881     is a matrix, 'smin' returns a list containing the minimum values of
13882     the columns, which are associated to statistical variables.
13883
13884          (%i1) load ("descriptive")$
13885          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13886          (%i3) smin (s1);
13887          (%o3)                           0
13888          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13889          (%i5) smin (s2);
13890          (%o5)             [0.58, 0.5, 2.67, 5.25, 5.17]
13891
13892     See also function 'smax'.
13893
13894 -- Function: smax
13895          smax (<list>)
13896          smax (<matrix>)
13897
13898     This is the maximum value of the sample <list>.  When the argument
13899     is a matrix, 'smax' returns a list containing the maximum values of
13900     the columns, which are associated to statistical variables.
13901
13902          (%i1) load ("descriptive")$
13903          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13904          (%i3) smax (s1);
13905          (%o3)                           9
13906          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13907          (%i5) smax (s2);
13908          (%o5)          [20.25, 21.46, 20.04, 29.63, 27.63]
13909
13910     See also function 'smin'.
13911
13912 -- Function: range
13913          range (<list>)
13914          range (<matrix>)
13915
13916     The range is the difference between the extreme values.
13917
13918     Example:
13919
13920          (%i1) load ("descriptive")$
13921          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13922          (%i3) range (s1);
13923          (%o3)                           9
13924          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13925          (%i5) range (s2);
13926          (%o5)          [19.67, 20.96, 17.37, 24.38, 22.46]
13927
13928 -- Function: quantile
13929          quantile (<list>, <p>)
13930          quantile (<matrix>, <p>)
13931
13932     This is the <p>-quantile, with <p> a number in [0, 1], of the
13933     sample <list>.  Although there are several definitions for the
13934     sample quantile (Hyndman, R. J., Fan, Y. (1996) <Sample quantiles
13935     in statistical packages>.  American Statistician, 50, 361-365), the
13936     one based on linear interpolation is implemented in package *note
13937     descriptive-pkg::
13938
13939     Example:
13940
13941          (%i1) load ("descriptive")$
13942          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13943          (%i3) /* 1st and 3rd quartiles */
13944                   [quantile (s1, 1/4), quantile (s1, 3/4)], numer;
13945          (%o3)                      [2.0, 7.25]
13946          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13947          (%i5) quantile (s2, 1/4);
13948          (%o5)    [7.2575, 7.477500000000001, 7.82, 11.28, 11.48]
13949
13950 -- Function: median
13951          median (<list>)
13952          median (<matrix>)
13953
13954     Once the sample is ordered, if the sample size is odd the median is
13955     the central value, otherwise it is the mean of the two central
13956     values.
13957
13958     Example:
13959
13960          (%i1) load ("descriptive")$
13961          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13962          (%i3) median (s1);
13963                                          9
13964          (%o3)                           -
13965                                          2
13966          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13967          (%i5) median (s2);
13968          (%o5)         [10.06, 9.855, 10.73, 15.48, 14.105]
13969
13970     The median is the 1/2-quantile.
13971
13972     See also function 'quantile'.
13973
13974 -- Function: qrange
13975          qrange (<list>)
13976          qrange (<matrix>)
13977
13978     The interquartilic range is the difference between the third and
13979     first quartiles, 'quantile(<list>,3/4) - quantile(<list>,1/4)',
13980
13981          (%i1) load ("descriptive")$
13982          (%i2) s1 : read_list (file_search ("pidigits.data"))$
13983          (%i3) qrange (s1);
13984                                         21
13985          (%o3)                          --
13986                                         4
13987          (%i4) s2 : read_matrix (file_search ("wind.data"))$
13988          (%i5) qrange (s2);
13989          (%o5) [5.385, 5.572499999999998, 6.022500000000001,
13990                                      8.729999999999999, 6.649999999999999]
13991
13992     See also function 'quantile'.
13993
13994 -- Function: mean_deviation
13995          mean_deviation (<list>)
13996          mean_deviation (<matrix>)
13997
13998     The mean deviation, defined as
13999                               n
14000                             ====
14001                         1   \          _
14002                         -    >    |x - x|
14003                         n   /       i
14004                             ====
14005                             i = 1
14006
14007     Example:
14008
14009          (%i1) load ("descriptive")$
14010          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14011          (%i3) mean_deviation (s1);
14012                                         51
14013          (%o3)                          --
14014                                         20
14015          (%i4) s2 : read_matrix (file_search ("wind.data"))$
14016          (%i5) mean_deviation (s2);
14017          (%o5) [3.287959999999999, 3.075342, 3.23907, 4.715664000000001,
14018                                                         4.028546000000002]
14019
14020     See also function 'mean'.
14021
14022 -- Function: median_deviation
14023          median_deviation (<list>)
14024          median_deviation (<matrix>)
14025
14026     The median deviation, defined as
14027                           n
14028                         ====
14029                     1   \
14030                     -    >    |x - med|
14031                     n   /       i
14032                         ====
14033                         i = 1
14034     where 'med' is the median of <list>.
14035
14036     Example:
14037
14038          (%i1) load ("descriptive")$
14039          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14040          (%i3) median_deviation (s1);
14041                                          5
14042          (%o3)                           -
14043                                          2
14044          (%i4) s2 : read_matrix (file_search ("wind.data"))$
14045          (%i5) median_deviation (s2);
14046          (%o5)           [2.75, 2.755, 3.08, 4.315, 3.31]
14047
14048     See also function 'mean'.
14049
14050 -- Function: harmonic_mean
14051          harmonic_mean (<list>)
14052          harmonic_mean (<matrix>)
14053
14054     The harmonic mean, defined as
14055                            n
14056                         --------
14057                          n
14058                         ====
14059                         \     1
14060                          >    --
14061                         /     x
14062                         ====   i
14063                         i = 1
14064
14065     Example:
14066
14067          (%i1) load ("descriptive")$
14068          (%i2) y : [5, 7, 2, 5, 9, 5, 6, 4, 9, 2, 4, 2, 5]$
14069          (%i3) harmonic_mean (y), numer;
14070          (%o3)                   3.901858027632205
14071          (%i4) s2 : read_matrix (file_search ("wind.data"))$
14072          (%i5) harmonic_mean (s2);
14073          (%o5) [6.948015590052786, 7.391967752360356, 9.055658197151745,
14074                                      13.44199028193692, 13.01439145898509]
14075
14076     See also functions 'mean' and 'geometric_mean'.
14077
14078 -- Function: geometric_mean
14079          geometric_mean (<list>)
14080          geometric_mean (<matrix>)
14081
14082     The geometric mean, defined as
14083                           /  n      \ 1/n
14084                           | /===\   |
14085                           |  ! !    |
14086                           |  ! !  x |
14087                           |  ! !   i|
14088                           | i = 1   |
14089                           \         /
14090
14091     Example:
14092
14093          (%i1) load ("descriptive")$
14094          (%i2) y : [5, 7, 2, 5, 9, 5, 6, 4, 9, 2, 4, 2, 5]$
14095          (%i3) geometric_mean (y), numer;
14096          (%o3)                   4.454845412337012
14097          (%i4) s2 : read_matrix (file_search ("wind.data"))$
14098          (%i5) geometric_mean (s2);
14099          (%o5) [8.82476274347979, 9.22652604739361, 10.0442675714889,
14100                                      14.61274126349021, 13.96184163444275]
14101
14102     See also functions 'mean' and 'harmonic_mean'.
14103
14104 -- Function: kurtosis
14105          kurtosis (<list>)
14106          kurtosis (<matrix>)
14107
14108     The kurtosis coefficient, defined as
14109                              n
14110                            ====
14111                      1     \          _ 4
14112                     ----    >    (x - x)  - 3
14113                        4   /       i
14114                     n s    ====
14115                            i = 1
14116
14117     Example:
14118
14119          (%i1) load ("descriptive")$
14120          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14121          (%i3) kurtosis (s1), numer;
14122          (%o3)                  - 1.273247946514421
14123          (%i4) s2 : read_matrix (file_search ("wind.data"))$
14124          (%i5) kurtosis (s2);
14125          (%o5) [- .2715445622195385, 0.119998784429451,
14126               - .4275233490482861, - .6405361979019522, - .4952382132352935]
14127
14128     See also functions 'mean', 'var' and 'skewness'.
14129
14130 -- Function: skewness
14131          skewness (<list>)
14132          skewness (<matrix>)
14133
14134     The skewness coefficient, defined as
14135                              n
14136                            ====
14137                      1     \          _ 3
14138                     ----    >    (x - x)
14139                        3   /       i
14140                     n s    ====
14141                            i = 1
14142
14143     Example:
14144
14145          (%i1) load ("descriptive")$
14146          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14147          (%i3) skewness (s1), numer;
14148          (%o3)                  .009196180476450424
14149          (%i4) s2 : read_matrix (file_search ("wind.data"))$
14150          (%i5) skewness (s2);
14151          (%o5) [.1580509020000978, .2926379232061854, .09242174416107717,
14152                                      .2059984348148687, .2142520248890831]
14153
14154     See also functions 'mean',, 'var' and 'kurtosis'.
14155
14156 -- Function: pearson_skewness
14157          pearson_skewness (<list>)
14158          pearson_skewness (<matrix>)
14159
14160     Pearson's skewness coefficient, defined as
14161                          _
14162                       3 (x - med)
14163                       -----------
14164                            s
14165     where <med> is the median of <list>.
14166
14167     Example:
14168
14169          (%i1) load ("descriptive")$
14170          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14171          (%i3) pearson_skewness (s1), numer;
14172          (%o3)                   .2159484029093895
14173          (%i4) s2 : read_matrix (file_search ("wind.data"))$
14174          (%i5) pearson_skewness (s2);
14175          (%o5) [- .08019976629211892, .2357036272952649,
14176                   .1050904062491204, .1245042340592368, .4464181795804519]
14177
14178     See also functions 'mean', 'var' and 'median'.
14179
14180 -- Function: quartile_skewness
14181          quartile_skewness (<list>)
14182          quartile_skewness (<matrix>)
14183
14184     The quartile skewness coefficient, defined as
14185                         c    - 2 c    + c
14186                          3/4      1/2    1/4
14187                         --------------------
14188                             c    - c
14189                              3/4    1/4
14190     where c_p is the <p>-quantile of sample <list>.
14191
14192     Example:
14193
14194          (%i1) load ("descriptive")$
14195          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14196          (%i3) quartile_skewness (s1), numer;
14197          (%o3)                  .04761904761904762
14198          (%i4) s2 : read_matrix (file_search ("wind.data"))$
14199          (%i5) quartile_skewness (s2);
14200          (%o5) [- 0.0408542246982353, .1467025572005382,
14201                 0.0336239103362392, .03780068728522298, .2105263157894735]
14202
14203     See also function 'quantile'.
14204
14205 -- Function: km
14206          km (<list>, <option> ...)
14207          km (<matrix>, <option> ...)
14208
14209     Kaplan Meier estimator of the survival, or reliability, function
14210     S(x)=1-F(x).
14211
14212     Data can be introduced as a list of pairs, or as a two column
14213     matrix.  The first component is the observed time, and the second
14214     component a censoring index (1 = non censored, 0 = right censored).
14215
14216     The optional argument is the name of the variable in the returned
14217     expression, which is <x> by default.
14218
14219     Examples:
14220
14221     Sample as a list of pairs.
14222
14223          (%i1) load ("descriptive")$
14224          (%i2) S: km([[2,1], [3,1], [5,0], [8,1]]);
14225                                 charfun((3 <= x) and (x < 8))
14226          (%o2) charfun(x < 0) + -----------------------------
14227                                               2
14228                          3 charfun((2 <= x) and (x < 3))
14229                        + -------------------------------
14230                                         4
14231                        + charfun((0 <= x) and (x < 2))
14232          (%i3) load ("draw")$
14233          (%i4) draw2d(
14234                  line_width = 3, grid = true,
14235                  explicit(S, x, -0.1, 10))$
14236
14237     Estimate survival probabilities.
14238
14239          (%i1) load ("descriptive")$
14240          (%i2) S(t):= ''(km([[2,1], [3,1], [5,0], [8,1]], t)) $
14241          (%i3) S(6);
14242                                      1
14243          (%o3)                       -
14244                                      2
14245
14246 -- Function: cdf_empirical
14247          cdf_empirical (<list>, <option> ...)
14248          cdf_empirical (<matrix>, <option> ...)
14249
14250     Empirical distribution function F(x).
14251
14252     Data can be introduced as a list of numbers, or as a one column
14253     matrix.
14254
14255     The optional argument is the name of the variable in the returned
14256     expression, which is <x> by default.
14257
14258     Example:
14259
14260     Empirical distribution function.
14261
14262          (%i1) load ("descriptive")$
14263          (%i2) F(x):= ''(cdf_empirical([1,3,3,5,7,7,7,8,9]));
14264          (%o2) F(x) := (charfun(x >= 9) + charfun(x >= 8)
14265                         + 3 charfun(x >= 7) + charfun(x >= 5)
14266                         + 2 charfun(x >= 3) + charfun(x >= 1))/9
14267          (%i3) F(6);
14268                                     4
14269          (%o3)                      -
14270                                     9
14271          (%i4) load(draw)$
14272          (%i5) draw2d(
14273                  line_width = 3,
14274                  grid       = true,
14275                  explicit(F(z), z, -2, 12)) $
14276
14277 -- Function: cov (<matrix>)
14278     The covariance matrix of the multivariate sample, defined as
14279                        n
14280                       ====
14281                    1  \           _        _
14282                S = -   >    (X  - X) (X  - X)'
14283                    n  /       j        j
14284                       ====
14285                       j = 1
14286     where X_j is the j-th row of the sample matrix.
14287
14288     Example:
14289
14290          (%i1) load ("descriptive")$
14291          (%i2) s2 : read_matrix (file_search ("wind.data"))$
14292          (%i3) fpprintprec : 7$  /* change precision for pretty output */
14293          (%i4) cov (s2);
14294                [ 17.22191  13.61811  14.37217  19.39624  15.42162 ]
14295                [                                                  ]
14296                [ 13.61811  14.98774  13.30448  15.15834  14.9711  ]
14297                [                                                  ]
14298          (%o4) [ 14.37217  13.30448  15.47573  17.32544  16.18171 ]
14299                [                                                  ]
14300                [ 19.39624  15.15834  17.32544  32.17651  20.44685 ]
14301                [                                                  ]
14302                [ 15.42162  14.9711   16.18171  20.44685  24.42308 ]
14303
14304     See also function 'cov1'.
14305
14306 -- Function: cov1 (<matrix>)
14307     The covariance matrix of the multivariate sample, defined as
14308                        n
14309                       ====
14310                   1   \           _        _
14311             S  = ---   >    (X  - X) (X  - X)'
14312              1   n-1  /       j        j
14313                       ====
14314                       j = 1
14315     where X_j is the j-th row of the sample matrix.
14316
14317     Example:
14318
14319          (%i1) load ("descriptive")$
14320          (%i2) s2 : read_matrix (file_search ("wind.data"))$
14321          (%i3) fpprintprec : 7$ /* change precision for pretty output */
14322          (%i4) cov1 (s2);
14323                [ 17.39587  13.75567  14.51734  19.59216  15.5774  ]
14324                [                                                  ]
14325                [ 13.75567  15.13913  13.43887  15.31145  15.12232 ]
14326                [                                                  ]
14327          (%o4) [ 14.51734  13.43887  15.63205  17.50044  16.34516 ]
14328                [                                                  ]
14329                [ 19.59216  15.31145  17.50044  32.50153  20.65338 ]
14330                [                                                  ]
14331                [ 15.5774   15.12232  16.34516  20.65338  24.66977 ]
14332
14333     See also function 'cov'.
14334
14335 -- Function: global_variances
14336          global_variances (<matrix>)
14337          global_variances (<matrix>, <options> ...)
14338
14339     Function 'global_variances' returns a list of global variance
14340     measures:
14341
14342        * <total variance>: 'trace(S_1)',
14343        * <mean variance>: 'trace(S_1)/p',
14344        * <generalized variance>: 'determinant(S_1)',
14345        * <generalized standard deviation>: 'sqrt(determinant(S_1))',
14346        * <efective variance> 'determinant(S_1)^(1/p)', (defined in:
14347          Pen~a, D. (2002) <Ana'lisis de datos multivariantes>;
14348          McGraw-Hill, Madrid.)
14349        * <efective standard deviation>: 'determinant(S_1)^(1/(2*p))'.
14350     where <p> is the dimension of the multivariate random variable and
14351     S_1 the covariance matrix returned by 'cov1'.
14352
14353     Option:
14354
14355        * ''data', default ''true', indicates whether the input matrix
14356          contains the sample data, in which case the covariance matrix
14357          'cov1' must be calculated, or not, and then the covariance
14358          matrix (symmetric) must be given, instead of the data.
14359
14360     Example:
14361
14362          (%i1) load ("descriptive")$
14363          (%i2) s2 : read_matrix (file_search ("wind.data"))$
14364          (%i3) global_variances (s2);
14365          (%o3) [105.338342060606, 21.06766841212119, 12874.34690469686,
14366                   113.4651792608501, 6.636590811800795, 2.576158149609762]
14367
14368     Calculate the 'global_variances' from the covariance matrix.
14369
14370          (%i1) load ("descriptive")$
14371          (%i2) s2 : read_matrix (file_search ("wind.data"))$
14372          (%i3) s : cov1 (s2)$
14373          (%i4) global_variances (s, data=false);
14374          (%o4) [105.338342060606, 21.06766841212119, 12874.34690469686,
14375                   113.4651792608501, 6.636590811800795, 2.576158149609762]
14376
14377     See also 'cov' and 'cov1'.
14378
14379 -- Function: cor
14380          cor (<matrix>)
14381          cor (<matrix>, <logical_value>)
14382
14383     The correlation matrix of the multivariate sample.
14384
14385     Option:
14386
14387        * ''data', default ''true', indicates whether the input matrix
14388          contains the sample data, in which case the covariance matrix
14389          'cov1' must be calculated, or not, and then the covariance
14390          matrix (symmetric) must be given, instead of the data.
14391
14392     Example:
14393
14394          (%i1) load ("descriptive")$
14395          (%i2) fpprintprec : 7 $
14396          (%i3) s2 : read_matrix (file_search ("wind.data"))$
14397          (%i4) cor (s2);
14398                [   1.0     .8476339  .8803515  .8239624  .7519506 ]
14399                [                                                  ]
14400                [ .8476339    1.0     .8735834  .6902622  0.782502 ]
14401                [                                                  ]
14402          (%o4) [ .8803515  .8735834    1.0     .7764065  .8323358 ]
14403                [                                                  ]
14404                [ .8239624  .6902622  .7764065    1.0     .7293848 ]
14405                [                                                  ]
14406                [ .7519506  0.782502  .8323358  .7293848    1.0    ]
14407
14408     Calculate de correlation matrix from the covariance matrix.
14409
14410          (%i1) load ("descriptive")$
14411          (%i2) fpprintprec : 7 $
14412          (%i3) s2 : read_matrix (file_search ("wind.data"))$
14413          (%i4) s : cov1 (s2)$
14414          (%i5) cor (s, data=false); /* this is faster */
14415                [   1.0     .8476339  .8803515  .8239624  .7519506 ]
14416                [                                                  ]
14417                [ .8476339    1.0     .8735834  .6902622  0.782502 ]
14418                [                                                  ]
14419          (%o5) [ .8803515  .8735834    1.0     .7764065  .8323358 ]
14420                [                                                  ]
14421                [ .8239624  .6902622  .7764065    1.0     .7293848 ]
14422                [                                                  ]
14423                [ .7519506  0.782502  .8323358  .7293848    1.0    ]
14424
14425     See also 'cov' and 'cov1'.
14426
14427 -- Function: list_correlations
14428          list_correlations (<matrix>)
14429          list_correlations (<matrix>, <options> ...)
14430
14431     Function 'list_correlations' returns a list of correlation
14432     measures:
14433
14434        * <precision matrix>: the inverse of the covariance matrix S_1,
14435                      -1     ij
14436                     S   = (s  )
14437                      1         i,j = 1,2,...,p
14438
14439        * <multiple correlation vector>: (R_1^2, R_2^2, ..., R_p^2),
14440          with
14441                      2          1
14442                     R  = 1 - -------
14443                      i        ii
14444                              s   s
14445                                   ii
14446          being an indicator of the goodness of fit of the linear
14447          multivariate regression model on X_i when the rest of
14448          variables are used as regressors.
14449
14450        * <partial correlation matrix>: with element (i, j) being
14451                                        ij
14452                                       s
14453                     r        = - ------------
14454                      ij.rest     / ii  jj\ 1/2
14455                                  |s   s  |
14456                                  \       /
14457
14458     Option:
14459
14460        * ''data', default ''true', indicates whether the input matrix
14461          contains the sample data, in which case the covariance matrix
14462          'cov1' must be calculated, or not, and then the covariance
14463          matrix (symmetric) must be given, instead of the data.
14464
14465     Example:
14466
14467          (%i1) load ("descriptive")$
14468          (%i2) s2 : read_matrix (file_search ("wind.data"))$
14469          (%i3) z : list_correlations (s2)$
14470          (%i4) fpprintprec : 5$ /* for pretty output */
14471          (%i5) z[1];  /* precision matrix */
14472                [  .38486   - .13856   - .15626   - .10239    .031179  ]
14473                [                                                      ]
14474                [ - .13856   .34107    - .15233    .038447   - .052842 ]
14475                [                                                      ]
14476          (%o5) [ - .15626  - .15233    .47296    - .024816  - .10054  ]
14477                [                                                      ]
14478                [ - .10239   .038447   - .024816   .10937    - .034033 ]
14479                [                                                      ]
14480                [ .031179   - .052842  - .10054   - .034033   .14834   ]
14481          (%i6) z[2];  /* multiple correlation vector */
14482          (%o6)      [.85063, .80634, .86474, .71867, .72675]
14483          (%i7) z[3];  /* partial correlation matrix */
14484                [  - 1.0     .38244   .36627   .49908   - .13049 ]
14485                [                                                ]
14486                [  .38244    - 1.0    .37927  - .19907   .23492  ]
14487                [                                                ]
14488          (%o7) [  .36627    .37927   - 1.0    .10911    .37956  ]
14489                [                                                ]
14490                [  .49908   - .19907  .10911   - 1.0     .26719  ]
14491                [                                                ]
14492                [ - .13049   .23492   .37956   .26719    - 1.0   ]
14493
14494     See also 'cov' and 'cov1'.
14495
14496 -- Function: principal_components
14497          principal_components (<matrix>)
14498          principal_components (<matrix>, <options> ...)
14499
14500     Calculates the principal componentes of a multivariate sample.
14501     Principal components are used in multivariate statistical analysis
14502     to reduce the dimensionality of the sample.
14503
14504     Option:
14505
14506        * ''data', default ''true', indicates whether the input matrix
14507          contains the sample data, in which case the covariance matrix
14508          'cov1' must be calculated, or not, and then the covariance
14509          matrix (symmetric) must be given, instead of the data.
14510
14511     The output of function 'principal_components' is a list with the
14512     following results:
14513
14514        * variances of the principal components,
14515        * percentage of total variance explained by each principal
14516          component,
14517        * rotation matrix.
14518
14519     Examples:
14520
14521     In this sample, the first component explains 83.13 per cent of
14522     total variance.
14523
14524          (%i1) load ("descriptive")$
14525          (%i2) s2 : read_matrix (file_search ("wind.data"))$
14526          (%i3) fpprintprec:4 $
14527          (%i4) res: principal_components(s2);
14528          0 errors, 0 warnings
14529          (%o4) [[87.57, 8.753, 5.515, 1.889, 1.613],
14530          [83.13, 8.31, 5.235, 1.793, 1.531],
14531          [ .4149  .03379   - .4757  - 0.581   - .5126 ]
14532          [                                            ]
14533          [ 0.369  - .3657  - .4298   .7237    - .1469 ]
14534          [                                            ]
14535          [ .3959  - .2178  - .2181  - .2749    .8201  ]]
14536          [                                            ]
14537          [ .5548   .7744    .1857    .2319    .06498  ]
14538          [                                            ]
14539          [ .4765  - .4669   0.712   - .09605  - .1969 ]
14540          (%i5) /* accumulated percentages  */
14541              block([ap: copy(res[2])],
14542                for k:2 thru length(ap) do ap[k]: ap[k]+ap[k-1],
14543                ap);
14544          (%o5)                 [83.13, 91.44, 96.68, 98.47, 100.0]
14545          (%i6) /* sample dimension */
14546                p: length(first(res));
14547          (%o6)                                  5
14548          (%i7) /* plot percentages to select number of
14549                   principal components for further work */
14550               draw2d(
14551                  fill_density = 0.2,
14552                  apply(bars, makelist([k, res[2][k], 1/2], k, p)),
14553                  points_joined = true,
14554                  point_type    = filled_circle,
14555                  point_size    = 3,
14556                  points(makelist([k, res[2][k]], k, p)),
14557                  xlabel = "Variances",
14558                  ylabel = "Percentages",
14559                  xtics  = setify(makelist([concat("PC",k),k], k, p))) $
14560
14561     In case de covariance matrix is known, it can be passed to the
14562     function, but option 'data=false' must be used.
14563
14564          (%i1) load ("descriptive")$
14565          (%i2) S: matrix([1,-2,0],[-2,5,0],[0,0,2]);
14566                                          [  1   - 2  0 ]
14567                                          [             ]
14568          (%o2)                           [ - 2   5   0 ]
14569                                          [             ]
14570                                          [  0    0   2 ]
14571          (%i3) fpprintprec:4 $
14572          (%i4) /* the argumment is a covariance matrix */
14573                res: principal_components(S, data=false);
14574          0 errors, 0 warnings
14575                                                            [ - .3827  0.0  .9239 ]
14576                                                            [                     ]
14577          (%o4) [[5.828, 2.0, .1716], [72.86, 25.0, 2.145], [  .9239   0.0  .3827 ]]
14578                                                            [                     ]
14579                                                            [   0.0    1.0   0.0  ]
14580          (%i5) /* transformation to get the principal components
14581                   from original records */
14582                matrix([a1,b2,c3],[a2,b2,c2]).last(res);
14583                       [ .9239 b2 - .3827 a1  1.0 c3  .3827 b2 + .9239 a1 ]
14584          (%o5)        [                                                  ]
14585                       [ .9239 b2 - .3827 a2  1.0 c2  .3827 b2 + .9239 a2 ]
14586
14587
14588File: maxima.info,  Node: Functions and Variables for statistical graphs,  Prev: Functions and Variables for descriptive statistics,  Up: descriptive-pkg
14589
1459050.4 Functions and Variables for statistical graphs
14591===================================================
14592
14593 -- Function: barsplot (<data1>, <data2>, ..., <option_1>, <option_2>,
14594          ...)
14595
14596     Plots bars diagrams for discrete statistical variables, both for
14597     one or multiple samples.
14598
14599     <data> can be a list of outcomes representing one sample, or a
14600     matrix of <m> rows and <n> columns, representing <n> samples of
14601     size <m> each.
14602
14603     Available options are:
14604
14605        * <box_width> (default, '3/4'): relative width of rectangles.
14606          This value must be in the range '[0,1]'.
14607
14608        * <grouping> (default, 'clustered'): indicates how multiple
14609          samples are shown.  Valid values are: 'clustered' and
14610          'stacked'.
14611
14612        * <groups_gap> (default, '1'): a positive integer number
14613          representing the gap between two consecutive groups of bars.
14614
14615        * <bars_colors> (default, '[]'): a list of colors for multiple
14616          samples.  When there are more samples than specified colors,
14617          the extra necessary colors are chosen at random.  See 'color'
14618          to learn more about them.
14619
14620        * <frequency> (default, 'absolute'): indicates the scale of the
14621          ordinates.  Possible values are: 'absolute', 'relative', and
14622          'percent'.
14623
14624        * <ordering> (default, 'orderlessp'): possible values are
14625          'orderlessp' or 'ordergreatp', indicating how statistical
14626          outcomes should be ordered on the <x>-axis.
14627
14628        * <sample_keys> (default, '[]'): a list with the strings to be
14629          used in the legend.  When the list length is other than 0 or
14630          the number of samples, an error message is returned.
14631
14632        * <start_at> (default, '0'): indicates where the plot begins to
14633          be plotted on the x axis.
14634
14635        * All global 'draw' options, except 'xtics', which is internally
14636          assigned by 'barsplot'.  If you want to set your own values
14637          for this option or want to build complex scenes, make use of
14638          'barsplot_description'.  See example below.
14639
14640        * The following local *note draw-pkg:: options: 'key',
14641          'color_draw', 'fill_color', 'fill_density' and 'line_width'.
14642          See also 'barsplot'.
14643
14644     There is also a function 'wxbarsplot' for creating embedded
14645     histograms in interfaces wxMaxima and iMaxima.  'barsplot' in a
14646     multiplot context.
14647
14648     Examples:
14649
14650     Univariate sample in matrix form.  Absolute frequencies.
14651
14652          (%i1) load ("descriptive")$
14653          (%i2) m : read_matrix (file_search ("biomed.data"))$
14654          (%i3) barsplot(
14655                  col(m,2),
14656                  title        = "Ages",
14657                  xlabel       = "years",
14658                  box_width    = 1/2,
14659                  fill_density = 3/4)$
14660
14661     Two samples of different sizes, with relative frequencies and user
14662     declared colors.
14663
14664          (%i1) load ("descriptive")$
14665          (%i2) l1:makelist(random(10),k,1,50)$
14666          (%i3) l2:makelist(random(10),k,1,100)$
14667          (%i4) barsplot(
14668                  l1,l2,
14669                  box_width    = 1,
14670                  fill_density = 1,
14671                  bars_colors  = [black, grey],
14672                  frequency = relative,
14673                  sample_keys = ["A", "B"])$
14674
14675     Four non numeric samples of equal size.
14676
14677          (%i1) load ("descriptive")$
14678          (%i2) barsplot(
14679                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
14680                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
14681                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
14682                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
14683                  title  = "Asking for something to four groups",
14684                  ylabel = "# of individuals",
14685                  groups_gap   = 3,
14686                  fill_density = 0.5,
14687                  ordering     = ordergreatp)$
14688
14689     Stacked bars.
14690
14691          (%i1) load ("descriptive")$
14692          (%i2) barsplot(
14693                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
14694                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
14695                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
14696                  makelist([Yes, No, Maybe][random(3)+1],k,1,50),
14697                  title  = "Asking for something to four groups",
14698                  ylabel = "# of individuals",
14699                  grouping     = stacked,
14700                  fill_density = 0.5,
14701                  ordering     = ordergreatp)$
14702
14703     For bars diagrams related options, see 'barsplot' of package *note
14704     draw-pkg:: See also functions 'histogram' and 'piechart'.
14705
14706 -- Function: barsplot_description (...)
14707
14708     Function 'barsplot_description' creates a graphic object suitable
14709     for creating complex scenes, together with other graphic objects.
14710
14711     Example: 'barsplot' in a multiplot context.
14712
14713          (%i1) load ("descriptive")$
14714          (%i2) l1:makelist(random(10),k,1,50)$
14715          (%i3) l2:makelist(random(10),k,1,100)$
14716          (%i4) bp1 :
14717                  barsplot_description(
14718                   l1,
14719                   box_width = 1,
14720                   fill_density = 0.5,
14721                   bars_colors = [blue],
14722                   frequency = relative)$
14723          (%i5) bp2 :
14724                  barsplot_description(
14725                   l2,
14726                   box_width = 1,
14727                   fill_density = 0.5,
14728                   bars_colors = [red],
14729                   frequency = relative)$
14730          (%i6) draw(gr2d(bp1), gr2d(bp2))$
14731
14732 -- Function: boxplot (<data>)
14733          boxplot (<data>, <option_1>, <option_2>, ...)
14734
14735     This function plots box-and-whisker diagrams.  Argument <data> can
14736     be a list, which is not of great interest, since these diagrams are
14737     mainly used for comparing different samples, or a matrix, so it is
14738     possible to compare two or more components of a multivariate
14739     statistical variable.  But it is also allowed <data> to be a list
14740     of samples with possible different sample sizes, in fact this is
14741     the only function in package 'descriptive' that admits this type of
14742     data structure.
14743
14744     The box is plotted from the first quartile to the third, with an
14745     horizontal segment situated at the second quartile or median.  By
14746     default, lower and upper whiskers are plotted at the minimum and
14747     maximum values, respectively.  Option <range> can be used to
14748     indicate that values greater than
14749     'quantile(x,3/4)+range*(quantile(x,3/4)-quantile(x,1/4))' or less
14750     than 'quantile(x,1/4)-range*(quantile(x,3/4)-quantile(x,1/4))' must
14751     be considered as outliers, in which case they are plotted as
14752     isolated points, and the whiskers are located at the extremes of
14753     the rest of the sample.
14754
14755     Available options are:
14756
14757        * <box_width> (default, '3/4'): relative width of boxes.  This
14758          value must be in the range '[0,1]'.
14759
14760        * <box_orientation> (default, 'vertical'): possible values:
14761          'vertical' and 'horizontal'.
14762
14763        * <range> (default, 'inf'): positive coefficient of the
14764          interquartilic range to set outliers boundaries.
14765
14766        * <outliers_size> (default, '1'): circle size for isolated
14767          outliers.
14768
14769        * All 'draw' options, except 'points_joined', 'point_size',
14770          'point_type', 'xtics', 'ytics', 'xrange', and 'yrange', which
14771          are internally assigned by 'boxplot'.  If you want to set your
14772          own values for this options or want to build complex scenes,
14773          make use of 'boxplot_description'.
14774
14775        * The following local 'draw' options: 'key', 'color', and
14776          'line_width'.
14777
14778     There is also a function 'wxboxplot' for creating embedded
14779     histograms in interfaces wxMaxima and iMaxima.
14780
14781     Examples:
14782
14783     Box-and-whisker diagram from a multivariate sample.
14784
14785          (%i1) load ("descriptive")$
14786          (%i2) s2 : read_matrix(file_search("wind.data"))$
14787          (%i3) boxplot(s2,
14788                  box_width  = 0.2,
14789                  title      = "Windspeed in knots",
14790                  xlabel     = "Stations",
14791                  color      = red,
14792                  line_width = 2)$
14793
14794     Box-and-whisker diagram from three samples of different sizes.
14795
14796          (%i1) load ("descriptive")$
14797          (%i2) A :
14798                 [[6, 4, 6, 2, 4, 8, 6, 4, 6, 4, 3, 2],
14799                  [8, 10, 7, 9, 12, 8, 10],
14800                  [16, 13, 17, 12, 11, 18, 13, 18, 14, 12]]$
14801          (%i3) boxplot (A, box_orientation = horizontal)$
14802
14803     Option <range> can be used to handle outliers.
14804
14805          (%i1) load ("descriptive")$
14806          (%i2) B: [[7, 15, 5, 8, 6, 5, 7, 3, 1],
14807                    [10, 8, 12, 8, 11, 9, 20],
14808                    [23, 17, 19, 7, 22, 19]] $
14809          (%i3) boxplot (B, range=1)$
14810          (%i4) boxplot (B, range=1.5, box_orientation = horizontal)$
14811          (%i5) draw2d(
14812                  boxplot_description(
14813                    B,
14814                    range            = 1.5,
14815                    line_width       = 3,
14816                    outliers_size    = 2,
14817                    color            = red,
14818                    background_color = light_gray),
14819                  xtics = {["Low",1],["Medium",2],["High",3]}) $
14820
14821 -- Function: boxplot_description (...)
14822
14823     Function 'boxplot_description' creates a graphic object suitable
14824     for creating complex scenes, together with other graphic objects.
14825
14826 -- Function: histogram
14827          histogram (<list>)
14828          histogram (<list>, <option_1>, <option_2>, ...)
14829          histogram (<one_column_matrix>)
14830          histogram (<one_column_matrix>, <option_1>, <option_2>, ...)
14831          histogram (<one_row_matrix>)
14832          histogram (<one_row_matrix>, <option_1>, <option_2>, ...)
14833
14834     This function plots an histogram from a continuous sample.  Sample
14835     data must be stored in a list of numbers or a one dimensional
14836     matrix.
14837
14838     Available options are:
14839
14840        * <nclasses> (default, '10'): number of classes of the
14841          histogram, or a list indicating the limits of the classes and
14842          the number of them, or only the limits.  This option also
14843          accepts bounds for varying bin widths, or a symbol with the
14844          name of one of the three optimal algorithms available for the
14845          number of classes: ''fd' (Freedman, D. and Diaconis, P. (1981)
14846          On the histogram as a density estimator: L_2 theory.
14847          Zeitschrift fuer Wahrscheinlichkeitstheorie und verwandte
14848          Gebiete 57, 453-476.), ''scott' (Scott, D. W. (1979) On
14849          optimal and data-based histograms.  Biometrika 66, 605-610.),
14850          and ''sturges' (Sturges, H. A. (1926) The choice of a class
14851          interval.  Journal of the American Statistical Association 21,
14852          65-66).
14853
14854        * <frequency> (default, 'absolute'): indicates the scale of the
14855          ordinates.  Possible values are: 'absolute', 'relative',
14856          'percent', and 'density'.  With 'density', the histogram area
14857          has a total area of one.
14858
14859        * <htics> (default, 'auto'): format of the histogram tics.
14860          Possible values are: 'auto', 'endpoints', 'intervals', or a
14861          list of labels.
14862
14863        * All global 'draw' options, except 'xrange', 'yrange', and
14864          'xtics', which are internally assigned by 'histogram'.  If you
14865          want to set your own values for these options, make use of
14866          'histogram_description'.  See examples bellow.
14867
14868        * The following local *note draw-pkg:: options: 'key', 'color',
14869          'fill_color', 'fill_density' and 'line_width'.  See also
14870          'barsplot'.
14871
14872     There is also a function 'wxhistogram' for creating embedded
14873     histograms in interfaces wxMaxima and iMaxima.
14874
14875     Examples:
14876
14877     A simple with eight classes:
14878
14879          (%i1) load ("descriptive")$
14880          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14881          (%i3) histogram (
14882                     s1,
14883                     nclasses     = 8,
14884                     title        = "pi digits",
14885                     xlabel       = "digits",
14886                     ylabel       = "Absolute frequency",
14887                     fill_color   = grey,
14888                     fill_density = 0.6)$
14889
14890     Setting the limits of the histogram to -2 and 12, with 3 classes.
14891     Also, we introduce predefined tics:
14892
14893          (%i1) load ("descriptive")$
14894          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14895          (%i3) histogram (
14896                     s1,
14897                     nclasses     = [-2,12,3],
14898                     htics        = ["A", "B", "C"],
14899                     terminal     = png,
14900                     fill_color   = "#23afa0",
14901                     fill_density = 0.6)$
14902
14903     Bounds for varying bin widths.
14904
14905          (%i1) load ("descriptive")$
14906          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14907          (%i3) histogram (s1, nclasses = {0,3,6,7,11})$
14908
14909     Freedmann - Diakonis robust method for optimal search of the number
14910     of classes.
14911
14912          (%i1) load ("descriptive")$
14913          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14914          (%i3) histogram(s1, nclasses=fd) $
14915
14916 -- Function: histogram_description (...)
14917
14918     Function 'histogram_description' creates a graphic object suitable
14919     for creating complex scenes, together with other graphic objects.
14920     We make use of 'histogram_description' for setting the 'xrange' and
14921     adding an explicit curve into the scene:
14922
14923          (%i1) load ("descriptive")$
14924          (%i2) ( load("distrib"),
14925                  m: 14, s: 2,
14926                  s2: random_normal(m, s, 1000) ) $
14927          (%i3) draw2d(
14928                  grid   = true,
14929                  xrange = [5, 25],
14930                  histogram_description(
14931                    s2,
14932                    nclasses     = 9,
14933                    frequency    = density,
14934                    fill_density = 0.5),
14935                  explicit(pdf_normal(x,m,s), x, m - 3*s, m + 3* s))$
14936
14937 -- Function: piechart
14938          piechart (<list>)
14939          piechart (<list>, <option_1>, <option_2>, ...)
14940          piechart (<one_column_matrix>)
14941          piechart (<one_column_matrix>, <option_1>, <option_2>, ...)
14942          piechart (<one_row_matrix>)
14943          piechart (<one_row_matrix>, <option_1>, <option_2>, ...)
14944
14945     Similar to 'barsplot', but plots sectors instead of rectangles.
14946
14947     Available options are:
14948
14949        * <sector_colors> (default, '[]'): a list of colors for sectors.
14950          When there are more sectors than specified colors, the extra
14951          necessary colors are chosen at random.  See 'color' to learn
14952          more about them.
14953
14954        * <pie_center> (default, '[0,0]'): diagram's center.
14955
14956        * <pie_radius> (default, '1'): diagram's radius.
14957
14958        * All global 'draw' options, except 'key', which is internally
14959          assigned by 'piechart'.  If you want to set your own values
14960          for this option or want to build complex scenes, make use of
14961          'piechart_description'.
14962
14963        * The following local 'draw' options: 'key', 'color',
14964          'fill_density' and 'line_width'.  See also 'ellipse'
14965
14966     There is also a function 'wxpiechart' for creating embedded
14967     histograms in interfaces wxMaxima and iMaxima.
14968
14969     Example:
14970
14971          (%i1) load ("descriptive")$
14972          (%i2) s1 : read_list (file_search ("pidigits.data"))$
14973          (%i3) piechart(
14974                  s1,
14975                  xrange  = [-1.1, 1.3],
14976                  yrange  = [-1.1, 1.1],
14977                  title   = "Digit frequencies in pi")$
14978
14979     See also function 'barsplot'.
14980
14981 -- Function: piechart_description (...)
14982
14983     Function 'piechart_description' creates a graphic object suitable
14984     for creating complex scenes, together with other graphic objects.
14985
14986 -- Function: scatterplot
14987          scatterplot (<list>)
14988          scatterplot (<list>, <option_1>, <option_2>, ...)
14989          scatterplot (<matrix>)
14990          scatterplot (<matrix>, <option_1>, <option_2>, ...)
14991
14992     Plots scatter diagrams both for univariate (<list>) and
14993     multivariate (<matrix>) samples.
14994
14995     Available options are the same admitted by 'histogram'.
14996
14997     There is also a function 'wxscatterplot' for creating embedded
14998     histograms in interfaces wxMaxima and iMaxima.
14999
15000     Examples:
15001
15002     Univariate scatter diagram from a simulated Gaussian sample.
15003
15004          (%i1) load ("descriptive")$
15005          (%i2) load ("distrib")$
15006          (%i3) scatterplot(
15007                  random_normal(0,1,200),
15008                  xaxis      = true,
15009                  point_size = 2,
15010                  dimensions = [600,150])$
15011
15012     Two dimensional scatter plot.
15013
15014          (%i1) load ("descriptive")$
15015          (%i2) s2 : read_matrix (file_search ("wind.data"))$
15016          (%i3) scatterplot(
15017                 submatrix(s2, 1,2,3),
15018                 title      = "Data from stations #4 and #5",
15019                 point_type = diamant,
15020                 point_size = 2,
15021                 color      = blue)$
15022
15023     Three dimensional scatter plot.
15024
15025          (%i1) load ("descriptive")$
15026          (%i2) s2 : read_matrix (file_search ("wind.data"))$
15027          (%i3) scatterplot(submatrix (s2, 1,2), nclasses=4)$
15028
15029     Five dimensional scatter plot, with five classes histograms.
15030
15031          (%i1) load ("descriptive")$
15032          (%i2) s2 : read_matrix (file_search ("wind.data"))$
15033          (%i3) scatterplot(
15034                  s2,
15035                  nclasses     = 5,
15036                  frequency    = relative,
15037                  fill_color   = blue,
15038                  fill_density = 0.3,
15039                  xtics        = 5)$
15040
15041     For plotting isolated or line-joined points in two and three
15042     dimensions, see 'points'.  See also 'histogram'.
15043
15044 -- Function: scatterplot_description (...)
15045
15046     Function 'scatterplot_description' creates a graphic object
15047     suitable for creating complex scenes, together with other graphic
15048     objects.
15049
15050 -- Function: starplot (<data1>, <data2>, ..., <option_1>, <option_2>,
15051          ...)
15052
15053     Plots star diagrams for discrete statistical variables, both for
15054     one or multiple samples.
15055
15056     <data> can be a list of outcomes representing one sample, or a
15057     matrix of <m> rows and <n> columns, representing <n> samples of
15058     size <m> each.
15059
15060     Available options are:
15061
15062        * <stars_colors> (default, '[]'): a list of colors for multiple
15063          samples.  When there are more samples than specified colors,
15064          the extra necessary colors are chosen at random.  See 'color'
15065          to learn more about them.
15066
15067        * <frequency> (default, 'absolute'): indicates the scale of the
15068          radii.  Possible values are: 'absolute' and 'relative'.
15069
15070        * <ordering> (default, 'orderlessp'): possible values are
15071          'orderlessp' or 'ordergreatp', indicating how statistical
15072          outcomes should be ordered.
15073
15074        * <sample_keys> (default, '[]'): a list with the strings to be
15075          used in the legend.  When the list length is other than 0 or
15076          the number of samples, an error message is returned.
15077
15078        * <star_center> (default, '[0,0]'): diagram's center.
15079
15080        * <star_radius> (default, '1'): diagram's radius.
15081
15082        * All global 'draw' options, except 'points_joined',
15083          'point_type', and 'key', which are internally assigned by
15084          'starplot'.  If you want to set your own values for this
15085          options or want to build complex scenes, make use of
15086          'starplot_description'.
15087
15088        * The following local 'draw' option: 'line_width'.
15089
15090     There is also a function 'wxstarplot' for creating embedded
15091     histograms in interfaces wxMaxima and iMaxima.
15092
15093     Example:
15094
15095     Plot based on absolute frequencies.  Location and radius defined by
15096     the user.
15097
15098          (%i1) load ("descriptive")$
15099          (%i2) l1: makelist(random(10),k,1,50)$
15100          (%i3) l2: makelist(random(10),k,1,200)$
15101          (%i4) starplot(
15102                  l1, l2,
15103                  stars_colors = [blue,red],
15104                  sample_keys = ["1st sample", "2nd sample"],
15105                  star_center = [1,2],
15106                  star_radius = 4,
15107                  proportional_axes = xy,
15108                  line_width = 2 ) $
15109
15110 -- Function: starplot_description (...)
15111
15112     Function 'starplot_description' creates a graphic object suitable
15113     for creating complex scenes, together with other graphic objects.
15114
15115 -- Function: stemplot
15116          stemplot (<data>)
15117          stemplot (<data>, <option>)
15118
15119     Plots stem and leaf diagrams.
15120
15121     Unique available option is:
15122
15123        * <leaf_unit> (default, '1'): indicates the unit of the leaves;
15124          must be a power of 10.
15125
15126     Example:
15127
15128          (%i1) load ("descriptive")$
15129          (%i2) load(distrib)$
15130          (%i3) stemplot(
15131                  random_normal(15, 6, 100),
15132                  leaf_unit = 0.1);
15133          -5|4
15134           0|37
15135           1|7
15136           3|6
15137           4|4
15138           5|4
15139           6|57
15140           7|0149
15141           8|3
15142           9|1334588
15143          10|07888
15144          11|01144467789
15145          12|12566889
15146          13|24778
15147          14|047
15148          15|223458
15149          16|4
15150          17|11557
15151          18|000247
15152          19|4467799
15153          20|00
15154          21|1
15155          22|2335
15156          23|01457
15157          24|12356
15158          25|455
15159          27|79
15160          key: 6|3 =  6.3
15161          (%o3)                  done
15162
15163
15164File: maxima.info,  Node: diag-pkg,  Next: distrib-pkg,  Prev: descriptive-pkg,  Up: Top
15165
1516651 diag
15167*******
15168
15169* Menu:
15170
15171* Functions and Variables for diag::
15172
15173
15174File: maxima.info,  Node: Functions and Variables for diag,  Prev: diag-pkg,  Up: diag-pkg
15175
1517651.1 Functions and Variables for diag
15177=====================================
15178
15179 -- Function: diag (<lm>)
15180     Constructs a matrix that is the block sum of the elements of <lm>.
15181     The elements of <lm> are assumed to be matrices; if an element is
15182     scalar, it treated as a 1 by 1 matrix.
15183
15184     The resulting matrix will be square if each of the elements of <lm>
15185     is square.
15186
15187     Example:
15188          (%i1) load("diag")$
15189
15190          (%i2) a1:matrix([1,2,3],[0,4,5],[0,0,6])$
15191
15192          (%i3) a2:matrix([1,1],[1,0])$
15193
15194          (%i4) diag([a1,x,a2]);
15195                             [ 1  2  3  0  0  0 ]
15196                             [                  ]
15197                             [ 0  4  5  0  0  0 ]
15198                             [                  ]
15199                             [ 0  0  6  0  0  0 ]
15200          (%o4)              [                  ]
15201                             [ 0  0  0  x  0  0 ]
15202                             [                  ]
15203                             [ 0  0  0  0  1  1 ]
15204                             [                  ]
15205                             [ 0  0  0  0  1  0 ]
15206          (%i5) diag ([matrix([1,2]), 3]);
15207                                  [ 1  2  0 ]
15208          (%o5)                   [         ]
15209                                  [ 0  0  3 ]
15210
15211     To use this function write first 'load("diag")'.
15212
15213 -- Function: JF (<lambda>,<n>)
15214     Returns the Jordan cell of order <n> with eigenvalue <lambda>.
15215
15216     Example:
15217          (%i1) load("diag")$
15218
15219          (%i2) JF(2,5);
15220                              [ 2  1  0  0  0 ]
15221                              [               ]
15222                              [ 0  2  1  0  0 ]
15223                              [               ]
15224          (%o2)               [ 0  0  2  1  0 ]
15225                              [               ]
15226                              [ 0  0  0  2  1 ]
15227                              [               ]
15228                              [ 0  0  0  0  2 ]
15229          (%i3) JF(3,2);
15230                                   [ 3  1 ]
15231          (%o3)                    [      ]
15232                                   [ 0  3 ]
15233
15234     To use this function write first 'load("diag")'.
15235
15236 -- Function: jordan (<mat>)
15237     Returns the Jordan form of matrix <mat>, encoded as a list in a
15238     particular format.  To get the corresponding matrix, call the
15239     function 'dispJordan' using the output of 'jordan' as the argument.
15240
15241     The elements of the returned list are themselves lists.  The first
15242     element of each is an eigenvalue of <mat>.  The remaining elements
15243     are positive integers which are the lengths of the Jordan blocks
15244     for this eigenvalue.  These integers are listed in decreasing
15245     order.  Eigenvalues are not repeated.
15246
15247     The functions 'dispJordan', 'minimalPoly' and 'ModeMatrix' expect
15248     the output of a call to 'jordan' as an argument.  If you construct
15249     this argument by hand, rather than by calling 'jordan', you must
15250     ensure that each eigenvalue only appears once and that the block
15251     sizes are listed in decreasing order, otherwise the functions might
15252     give incorrect answers.
15253
15254     Example:
15255          (%i1) load("diag")$
15256          (%i2) A: matrix([2,0,0,0,0,0,0,0],
15257                          [1,2,0,0,0,0,0,0],
15258                          [-4,1,2,0,0,0,0,0],
15259                          [2,0,0,2,0,0,0,0],
15260                          [-7,2,0,0,2,0,0,0],
15261                          [9,0,-2,0,1,2,0,0],
15262                          [-34,7,1,-2,-1,1,2,0],
15263                          [145,-17,-16,3,9,-2,0,3])$
15264          (%i3) jordan (A);
15265          (%o3)                [[2, 3, 3, 1], [3, 1]]
15266          (%i4) dispJordan (%);
15267                             [ 2  1  0  0  0  0  0  0 ]
15268                             [                        ]
15269                             [ 0  2  1  0  0  0  0  0 ]
15270                             [                        ]
15271                             [ 0  0  2  0  0  0  0  0 ]
15272                             [                        ]
15273                             [ 0  0  0  2  1  0  0  0 ]
15274          (%o4)              [                        ]
15275                             [ 0  0  0  0  2  1  0  0 ]
15276                             [                        ]
15277                             [ 0  0  0  0  0  2  0  0 ]
15278                             [                        ]
15279                             [ 0  0  0  0  0  0  2  0 ]
15280                             [                        ]
15281                             [ 0  0  0  0  0  0  0  3 ]
15282
15283     To use this function write first 'load("diag")'.  See also
15284     'dispJordan' and 'minimalPoly'.
15285
15286 -- Function: dispJordan (<l>)
15287     Returns a matrix in Jordan canonical form (JCF) corresponding to
15288     the list of eigenvalues and multiplicities given by <l>.  This list
15289     should be in the format given by the 'jordan' function.  See
15290     'jordan' for details of this format.
15291
15292     Example:
15293          (%i1) load("diag")$
15294
15295          (%i2) b1:matrix([0,0,1,1,1],
15296                          [0,0,0,1,1],
15297                          [0,0,0,0,1],
15298                          [0,0,0,0,0],
15299                          [0,0,0,0,0])$
15300
15301          (%i3) jordan(b1);
15302          (%o3)                  [[0, 3, 2]]
15303          (%i4) dispJordan(%);
15304                              [ 0  1  0  0  0 ]
15305                              [               ]
15306                              [ 0  0  1  0  0 ]
15307                              [               ]
15308          (%o4)               [ 0  0  0  0  0 ]
15309                              [               ]
15310                              [ 0  0  0  0  1 ]
15311                              [               ]
15312                              [ 0  0  0  0  0 ]
15313
15314     To use this function write first 'load("diag")'.  See also 'jordan'
15315     and 'minimalPoly'.
15316
15317 -- Function: minimalPoly (<l>)
15318     Returns the minimal polynomial of the matrix whose Jordan form is
15319     described by the list <l>.  This list should be in the format given
15320     by the 'jordan' function.  See 'jordan' for details of this format.
15321
15322     Example:
15323          (%i1) load("diag")$
15324
15325          (%i2) a:matrix([2,1,2,0],
15326                         [-2,2,1,2],
15327                         [-2,-1,-1,1],
15328                         [3,1,2,-1])$
15329
15330          (%i3) jordan(a);
15331          (%o3)               [[- 1, 1], [1, 3]]
15332          (%i4) minimalPoly(%);
15333                                      3
15334          (%o4)                (x - 1)  (x + 1)
15335
15336     To use this function write first 'load("diag")'.  See also 'jordan'
15337     and 'dispJordan'.
15338
15339 -- Function: ModeMatrix (<A>, [<jordan_info>])
15340     Returns an invertible matrix <M> such that (M^^-1).A.M is the
15341     Jordan form of <A>.
15342
15343     To calculate this, Maxima must find the Jordan form of <A>, which
15344     might be quite computationally expensive.  If that has already been
15345     calculated by a previous call to 'jordan', pass it as a second
15346     argument, <jordan_info>.  See 'jordan' for details of the required
15347     format.
15348
15349     Example:
15350          (%i1) load("diag")$
15351          (%i2) A: matrix([2,1,2,0], [-2,2,1,2], [-2,-1,-1,1], [3,1,2,-1])$
15352          (%i3) M: ModeMatrix (A);
15353                                [  1    - 1   1   1 ]
15354                                [                   ]
15355                                [   1               ]
15356                                [ - -   - 1   0   0 ]
15357                                [   9               ]
15358                                [                   ]
15359          (%o3)                 [   13              ]
15360                                [ - --   1   - 1  0 ]
15361                                [   9               ]
15362                                [                   ]
15363                                [  17               ]
15364                                [  --   - 1   1   1 ]
15365                                [  9                ]
15366          (%i4) is ((M^^-1) . A . M = dispJordan (jordan (A)));
15367          (%o4)                         true
15368
15369     Note that, in this example, the Jordan form of 'A' is computed
15370     twice.  To avoid this, we could have stored the output of
15371     'jordan(A)' in a variable and passed that to both 'ModeMatrix' and
15372     'dispJordan'.
15373
15374     To use this function write first 'load("diag")'.  See also 'jordan'
15375     and 'dispJordan'.
15376
15377 -- Function: mat_function (<f>,<A>)
15378     Returns f(A), where <f> is an analytic function and <A> a matrix.
15379     This computation is based on the Taylor expansion of <f>.  It is
15380     not efficient for numerical evaluation, but can give symbolic
15381     answers for small matrices.
15382
15383     Example 1:
15384
15385     The exponential of a matrix.  We only give the first row of the
15386     answer, since the output is rather large.
15387          (%i1) load("diag")$
15388          (%i2) A: matrix ([0,1,0], [0,0,1], [-1,-3,-3])$
15389          (%i3) ratsimp (mat_function (exp, t*A)[1]);
15390                     2              - t                   2   - t
15391                   (t  + 2 t + 2) %e       2        - t  t  %e
15392          (%o3)   [--------------------, (t  + t) %e   , --------]
15393                            2                               2
15394
15395     Example 2:
15396
15397     Comparison with the Taylor series for the exponential and also
15398     comparing 'exp(%i*A)' with sine and cosine.
15399          (%i1) load("diag")$
15400          (%i2) A: matrix ([0,1,1,1],
15401                           [0,0,0,1],
15402                           [0,0,0,1],
15403                           [0,0,0,0])$
15404          (%i3) ratsimp (mat_function (exp, t*A));
15405                                 [           2     ]
15406                                 [ 1  t  t  t  + t ]
15407                                 [                 ]
15408          (%o3)                  [ 0  1  0    t    ]
15409                                 [                 ]
15410                                 [ 0  0  1    t    ]
15411                                 [                 ]
15412                                 [ 0  0  0    1    ]
15413          (%i4) minimalPoly (jordan (A));
15414                                          3
15415          (%o4)                          x
15416          (%i5) ratsimp (ident(4) + t*A + 1/2*(t^2)*A^^2);
15417                                 [           2     ]
15418                                 [ 1  t  t  t  + t ]
15419                                 [                 ]
15420          (%o5)                  [ 0  1  0    t    ]
15421                                 [                 ]
15422                                 [ 0  0  1    t    ]
15423                                 [                 ]
15424                                 [ 0  0  0    1    ]
15425          (%i6) ratsimp (mat_function (exp, %i*t*A));
15426                            [                        2 ]
15427                            [ 1  %i t  %i t  %i t - t  ]
15428                            [                          ]
15429          (%o6)             [ 0   1     0      %i t    ]
15430                            [                          ]
15431                            [ 0   0     1      %i t    ]
15432                            [                          ]
15433                            [ 0   0     0        1     ]
15434          (%i7) ratsimp (mat_function (cos, t*A) + %i*mat_function (sin, t*A));
15435                            [                        2 ]
15436                            [ 1  %i t  %i t  %i t - t  ]
15437                            [                          ]
15438          (%o7)             [ 0   1     0      %i t    ]
15439                            [                          ]
15440                            [ 0   0     1      %i t    ]
15441                            [                          ]
15442                            [ 0   0     0        1     ]
15443
15444     Example 3:
15445
15446     Power operations.
15447          (%i1) load("diag")$
15448          (%i2) A: matrix([1,2,0], [0,1,0], [1,0,1])$
15449          (%i3) integer_pow(x) := block ([k], declare (k, integer), x^k)$
15450          (%i4) mat_function (integer_pow, A);
15451                                 [ 1     2 k     0 ]
15452                                 [                 ]
15453          (%o4)                  [ 0      1      0 ]
15454                                 [                 ]
15455                                 [ k  (k - 1) k  1 ]
15456          (%i5) A^^20;
15457                                   [ 1   40   0 ]
15458                                   [            ]
15459          (%o5)                    [ 0    1   0 ]
15460                                   [            ]
15461                                   [ 20  380  1 ]
15462
15463     To use this function write first 'load("diag")'.
15464
15465
15466File: maxima.info,  Node: distrib-pkg,  Next: draw-pkg,  Prev: diag-pkg,  Up: Top
15467
1546852 distrib
15469**********
15470
15471* Menu:
15472
15473* Introduction to distrib::
15474* Functions and Variables for continuous distributions::
15475* Functions and Variables for discrete distributions::
15476
15477
15478File: maxima.info,  Node: Introduction to distrib,  Next: Functions and Variables for continuous distributions,  Prev: distrib-pkg,  Up: distrib-pkg
15479
1548052.1 Introduction to distrib
15481============================
15482
15483Package 'distrib' contains a set of functions for making probability
15484computations on both discrete and continuous univariate models.
15485
15486   What follows is a short reminder of basic probabilistic related
15487definitions.
15488
15489   Let f(x) be the <density function> of an absolute continuous random
15490variable X. The <distribution function> is defined as
15491                            x
15492                           /
15493                           [
15494                    F(x) = I     f(u) du
15495                           ]
15496                           /
15497                            minf
15498   which equals the probability <Pr(X <= x)>.
15499
15500   The <mean> value is a localization parameter and is defined as
15501                          inf
15502                         /
15503                         [
15504                E[X]  =  I   x f(x) dx
15505                         ]
15506                         /
15507                          minf
15508
15509   The <variance> is a measure of variation,
15510                      inf
15511                     /
15512                     [                    2
15513              V[X] = I     f(x) (x - E[X])  dx
15514                     ]
15515                     /
15516                      minf
15517   which is a positive real number.  The square root of the variance is
15518the <standard deviation>, D[X]=sqrt(V[X]), and it is another measure of
15519variation.
15520
15521   The <skewness coefficient> is a measure of non-symmetry,
15522                      inf
15523                     /
15524                 1   [                    3
15525       SK[X] = ----- I     f(x) (x - E[X])  dx
15526                   3 ]
15527               D[X]  /
15528                      minf
15529
15530   And the <kurtosis coefficient> measures the peakedness of the
15531distribution,
15532                      inf
15533                     /
15534                 1   [                    4
15535       KU[X] = ----- I     f(x) (x - E[X])  dx - 3
15536                   4 ]
15537               D[X]  /
15538                      minf
15539   If X is gaussian, KU[X]=0.  In fact, both skewness and kurtosis are
15540shape parameters used to measure the non-gaussianity of a distribution.
15541
15542   If the random variable X is discrete, the density, or <probability>,
15543function f(x) takes positive values within certain countable set of
15544numbers x_i, and zero elsewhere.  In this case, the distribution
15545function is
15546                            ====
15547                            \
15548                     F(x) =  >    f(x )
15549                            /        i
15550                            ====
15551                           x <= x
15552                            i
15553
15554   The mean, variance, standard deviation, skewness coefficient and
15555kurtosis coefficient take the form
15556                            ====
15557                            \
15558                     E[X] =  >  x  f(x ) ,
15559                            /    i    i
15560                            ====
15561                             x
15562                              i
15563
15564                     ====
15565                     \                     2
15566             V[X] =   >    f(x ) (x - E[X])  ,
15567                     /        i    i
15568                     ====
15569                      x
15570                       i
15571
15572                    D[X] = sqrt(V[X]),
15573
15574                          ====
15575                   1      \                     3
15576       SK[X] =  -------    >    f(x ) (x - E[X])
15577                D[X]^3    /        i    i
15578                          ====
15579                           x
15580                            i
15581   and
15582                          ====
15583                   1      \                     4
15584       KU[X] =  -------    >    f(x ) (x - E[X])   - 3 ,
15585                D[X]^4    /        i    i
15586                          ====
15587                           x
15588                            i
15589   respectively.
15590
15591   There is a naming convention in package 'distrib'.  Every function
15592name has two parts, the first one makes reference to the function or
15593parameter we want to calculate,
15594     Functions:
15595        Density function            (pdf_*)
15596        Distribution function       (cdf_*)
15597        Quantile                    (quantile_*)
15598        Mean                        (mean_*)
15599        Variance                    (var_*)
15600        Standard deviation          (std_*)
15601        Skewness coefficient        (skewness_*)
15602        Kurtosis coefficient        (kurtosis_*)
15603        Random variate              (random_*)
15604
15605   The second part is an explicit reference to the probabilistic model,
15606     Continuous distributions:
15607        Normal              (*normal)
15608        Student             (*student_t)
15609        Chi^2               (*chi2)
15610        Noncentral Chi^2    (*noncentral_chi2)
15611        F                   (*f)
15612        Exponential         (*exp)
15613        Lognormal           (*lognormal)
15614        Gamma               (*gamma)
15615        Beta                (*beta)
15616        Continuous uniform  (*continuous_uniform)
15617        Logistic            (*logistic)
15618        Pareto              (*pareto)
15619        Weibull             (*weibull)
15620        Rayleigh            (*rayleigh)
15621        Laplace             (*laplace)
15622        Cauchy              (*cauchy)
15623        Gumbel              (*gumbel)
15624
15625     Discrete distributions:
15626        Binomial             (*binomial)
15627        Poisson              (*poisson)
15628        Bernoulli            (*bernoulli)
15629        Geometric            (*geometric)
15630        Discrete uniform     (*discrete_uniform)
15631        hypergeometric       (*hypergeometric)
15632        Negative binomial    (*negative_binomial)
15633        Finite discrete      (*general_finite_discrete)
15634
15635   For example, 'pdf_student_t(x,n)' is the density function of the
15636Student distribution with <n> degrees of freedom, 'std_pareto(a,b)' is
15637the standard deviation of the Pareto distribution with parameters <a>
15638and <b> and 'kurtosis_poisson(m)' is the kurtosis coefficient of the
15639Poisson distribution with mean <m>.
15640
15641   In order to make use of package 'distrib' you need first to load it
15642by typing
15643     (%i1) load("distrib")$
15644
15645   For comments, bugs or suggestions, please contact the author at
15646<'riotorto AT yahoo DOT com'>.
15647
15648
15649File: maxima.info,  Node: Functions and Variables for continuous distributions,  Next: Functions and Variables for discrete distributions,  Prev: Introduction to distrib,  Up: distrib-pkg
15650
1565152.2 Functions and Variables for continuous distributions
15652=========================================================
15653
15654 -- Function: pdf_normal (<x>,<m>,<s>)
15655     Returns the value at <x> of the density function of a Normal(m,s)
15656     random variable, with s>0.  To make use of this function, write
15657     first 'load("distrib")'.
15658
15659 -- Function: cdf_normal (<x>,<m>,<s>)
15660     Returns the value at <x> of the distribution function of a
15661     Normal(m,s) random variable, with s>0.  This function is defined in
15662     terms of Maxima's built-in error function 'erf'.
15663
15664          (%i1) load ("distrib")$
15665          (%i2) cdf_normal(x,m,s);
15666                                              x - m
15667                                        erf(---------)
15668                                            sqrt(2) s    1
15669          (%o2)                         -------------- + -
15670                                              2          2
15671
15672     See also 'erf'.
15673
15674 -- Function: quantile_normal (<q>,<m>,<s>)
15675     Returns the <q>-quantile of a Normal(m,s) random variable, with
15676     s>0; in other words, this is the inverse of 'cdf_normal'.  Argument
15677     <q> must be an element of [0,1].  To make use of this function,
15678     write first 'load("distrib")'.
15679
15680          (%i1) load ("distrib")$
15681          (%i2) quantile_normal(95/100,0,1);
15682                                                9
15683          (%o2)             sqrt(2) inverse_erf(--)
15684                                                10
15685          (%i3) float(%);
15686          (%o3)               1.644853626951472
15687
15688 -- Function: mean_normal (<m>,<s>)
15689     Returns the mean of a Normal(m,s) random variable, with s>0, namely
15690     <m>.  To make use of this function, write first 'load("distrib")'.
15691
15692 -- Function: var_normal (<m>,<s>)
15693     Returns the variance of a Normal(m,s) random variable, with s>0,
15694     namely <s^2>.  To make use of this function, write first
15695     'load("distrib")'.
15696
15697 -- Function: std_normal (<m>,<s>)
15698     Returns the standard deviation of a Normal(m,s) random variable,
15699     with s>0, namely <s>.  To make use of this function, write first
15700     'load("distrib")'.
15701
15702 -- Function: skewness_normal (<m>,<s>)
15703     Returns the skewness coefficient of a Normal(m,s) random variable,
15704     with s>0, which is always equal to 0.  To make use of this
15705     function, write first 'load("distrib")'.
15706
15707 -- Function: kurtosis_normal (<m>,<s>)
15708     Returns the kurtosis coefficient of a Normal(m,s) random variable,
15709     with s>0, which is always equal to 0.  To make use of this
15710     function, write first 'load("distrib")'.
15711
15712 -- Function: random_normal (<m>,<s>)
15713          random_normal (<m>,<s>,<n>)
15714
15715     Returns a Normal(m,s) random variate, with s>0.  Calling
15716     'random_normal' with a third argument <n>, a random sample of size
15717     <n> will be simulated.
15718
15719     This is an implementation of the Box-Mueller algorithm, as
15720     described in Knuth, D.E. (1981) <Seminumerical Algorithms.  The Art
15721     of Computer Programming.> Addison-Wesley.
15722
15723     To make use of this function, write first 'load("distrib")'.
15724
15725 -- Function: pdf_student_t (<x>,<n>)
15726     Returns the value at <x> of the density function of a Student
15727     random variable t(n), with n>0 degrees of freedom.  To make use of
15728     this function, write first 'load("distrib")'.
15729
15730 -- Function: cdf_student_t (<x>,<n>)
15731     Returns the value at <x> of the distribution function of a Student
15732     random variable t(n), with n>0 degrees of freedom.
15733
15734          (%i1) load ("distrib")$
15735          (%i2) cdf_student_t(1/2, 7/3);
15736                                                   7  1  28
15737                       beta_incomplete_regularized(-, -, --)
15738                                                   6  2  31
15739          (%o2)    1 - -------------------------------------
15740                                         2
15741          (%i3) float(%);
15742          (%o3)                .6698450596140415
15743
15744 -- Function: quantile_student_t (<q>,<n>)
15745     Returns the <q>-quantile of a Student random variable t(n), with
15746     n>0; in other words, this is the inverse of 'cdf_student_t'.
15747     Argument <q> must be an element of [0,1].  To make use of this
15748     function, write first 'load("distrib")'.
15749
15750 -- Function: mean_student_t (<n>)
15751     Returns the mean of a Student random variable t(n), with n>0, which
15752     is always equal to 0.  To make use of this function, write first
15753     'load("distrib")'.
15754
15755 -- Function: var_student_t (<n>)
15756     Returns the variance of a Student random variable t(n), with n>2.
15757
15758          (%i1) load ("distrib")$
15759          (%i2) var_student_t(n);
15760                                          n
15761          (%o2)                         -----
15762                                        n - 2
15763
15764 -- Function: std_student_t (<n>)
15765     Returns the standard deviation of a Student random variable t(n),
15766     with n>2.  To make use of this function, write first
15767     'load("distrib")'.
15768
15769 -- Function: skewness_student_t (<n>)
15770     Returns the skewness coefficient of a Student random variable t(n),
15771     with n>3, which is always equal to 0.  To make use of this
15772     function, write first 'load("distrib")'.
15773
15774 -- Function: kurtosis_student_t (<n>)
15775     Returns the kurtosis coefficient of a Student random variable t(n),
15776     with n>4.  To make use of this function, write first
15777     'load("distrib")'.
15778
15779 -- Function: random_student_t (<n>)
15780          random_student_t (<n>,<m>)
15781
15782     Returns a Student random variate t(n), with n>0.  Calling
15783     'random_student_t' with a second argument <m>, a random sample of
15784     size <m> will be simulated.
15785
15786     The implemented algorithm is based on the fact that if <Z> is a
15787     normal random variable N(0,1) and S^2 is a chi square random
15788     variable with <n> degrees of freedom, Chi^2(n), then
15789                                     Z
15790                           X = -------------
15791                               /   2  \ 1/2
15792                               |  S   |
15793                               | ---  |
15794                               \  n   /
15795     is a Student random variable with <n> degrees of freedom, t(n).
15796
15797     To make use of this function, write first 'load("distrib")'.
15798
15799 -- Function: pdf_noncentral_student_t (<x>,<n>,<ncp>)
15800     Returns the value at <x> of the density function of a noncentral
15801     Student random variable nc_t(n,ncp), with n>0 degrees of freedom
15802     and noncentrality parameter ncp.  To make use of this function,
15803     write first 'load("distrib")'.
15804
15805     Sometimes an extra work is necessary to get the final result.
15806
15807          (%i1) load ("distrib")$
15808          (%i2) expand(pdf_noncentral_student_t(3,5,0.1));
15809                                     7/2                         7/2
15810                0.04296414417400905 5      1.323650307289301e-6 5
15811          (%o2) ------------------------ + -------------------------
15812                   3/2   5/2                       sqrt(%pi)
15813                  2    14    sqrt(%pi)
15814                                                                  7/2
15815                                             1.94793720435093e-4 5
15816                                           + ------------------------
15817                                                       %pi
15818          (%i3) float(%);
15819          (%o3)          .02080593159405669
15820
15821 -- Function: cdf_noncentral_student_t (<x>,<n>,<ncp>)
15822     Returns the value at <x> of the distribution function of a
15823     noncentral Student random variable nc_t(n,ncp), with n>0 degrees of
15824     freedom and noncentrality parameter ncp.  This function has no
15825     closed form and it is numerically computed.
15826
15827          (%i1) load ("distrib")$
15828          (%i2) cdf_noncentral_student_t(-2,5,-5);
15829          (%o2)          .9952030093319743
15830
15831 -- Function: quantile_noncentral_student_t (<q>,<n>,<ncp>)
15832     Returns the <q>-quantile of a noncentral Student random variable
15833     nc_t(n,ncp), with n>0 degrees of freedom and noncentrality
15834     parameter ncp; in other words, this is the inverse of
15835     'cdf_noncentral_student_t'.  Argument <q> must be an element of
15836     [0,1].  To make use of this function, write first
15837     'load("distrib")'.
15838
15839 -- Function: mean_noncentral_student_t (<n>,<ncp>)
15840     Returns the mean of a noncentral Student random variable
15841     nc_t(n,ncp), with n>1 degrees of freedom and noncentrality
15842     parameter ncp.  To make use of this function, write first
15843     'load("distrib")'.
15844
15845          (%i1) load ("distrib")$
15846          (%i2) mean_noncentral_student_t(df,k);
15847                             df - 1
15848                       gamma(------) sqrt(df) k
15849                               2
15850          (%o2)        ------------------------
15851                                        df
15852                          sqrt(2) gamma(--)
15853                                        2
15854
15855 -- Function: var_noncentral_student_t (<n>,<ncp>)
15856     Returns the variance of a noncentral Student random variable
15857     nc_t(n,ncp), with n>2 degrees of freedom and noncentrality
15858     parameter ncp.  To make use of this function, write first
15859     'load("distrib")'.
15860
15861 -- Function: std_noncentral_student_t (<n>,<ncp>)
15862     Returns the standard deviation of a noncentral Student random
15863     variable nc_t(n,ncp), with n>2 degrees of freedom and noncentrality
15864     parameter ncp.  To make use of this function, write first
15865     'load("distrib")'.
15866
15867 -- Function: skewness_noncentral_student_t (<n>,<ncp>)
15868     Returns the skewness coefficient of a noncentral Student random
15869     variable nc_t(n,ncp), with n>3 degrees of freedom and noncentrality
15870     parameter ncp.  To make use of this function, write first
15871     'load("distrib")'.
15872
15873 -- Function: kurtosis_noncentral_student_t (<n>,<ncp>)
15874     Returns the kurtosis coefficient of a noncentral Student random
15875     variable nc_t(n,ncp), with n>4 degrees of freedom and noncentrality
15876     parameter ncp.  To make use of this function, write first
15877     'load("distrib")'.
15878
15879 -- Function: random_noncentral_student_t (<n>,<ncp>)
15880          random_noncentral_student_t (<n>,<ncp>,<m>)
15881
15882     Returns a noncentral Student random variate nc_t(n,ncp), with n>0.
15883     Calling 'random_noncentral_student_t' with a third argument <m>, a
15884     random sample of size <m> will be simulated.
15885
15886     The implemented algorithm is based on the fact that if <X> is a
15887     normal random variable N(ncp,1) and S^2 is a chi square random
15888     variable with <n> degrees of freedom, Chi^2(n), then
15889                                     X
15890                           U = -------------
15891                               /   2  \ 1/2
15892                               |  S   |
15893                               | ---  |
15894                               \  n   /
15895     is a noncentral Student random variable with <n> degrees of freedom
15896     and noncentrality parameter ncp, nc_t(n,ncp).
15897
15898     To make use of this function, write first 'load("distrib")'.
15899
15900 -- Function: pdf_chi2 (<x>,<n>)
15901     Returns the value at <x> of the density function of a Chi-square
15902     random variable Chi^2(n), with n>0.  The Chi^2(n) random variable
15903     is equivalent to the Gamma(n/2,2).
15904
15905          (%i1) load ("distrib")$
15906          (%i2) pdf_chi2(x,n);
15907                                   n/2 - 1   - x/2
15908                                  x        %e
15909          (%o2)                   ----------------
15910                                    n/2       n
15911                                   2    gamma(-)
15912                                              2
15913
15914 -- Function: cdf_chi2 (<x>,<n>)
15915     Returns the value at <x> of the distribution function of a
15916     Chi-square random variable Chi^2(n), with n>0.
15917
15918          (%i1) load ("distrib")$
15919          (%i2) cdf_chi2(3,4);
15920                                                         3
15921          (%o2)      1 - gamma_incomplete_regularized(2, -)
15922                                                         2
15923          (%i3) float(%);
15924          (%o3)               .4421745996289256
15925
15926 -- Function: quantile_chi2 (<q>,<n>)
15927     Returns the <q>-quantile of a Chi-square random variable Chi^2(n),
15928     with n>0; in other words, this is the inverse of 'cdf_chi2'.
15929     Argument <q> must be an element of [0,1].
15930
15931     This function has no closed form and it is numerically computed.
15932
15933          (%i1) load ("distrib")$
15934          (%i2) quantile_chi2(0.99,9);
15935          (%o2)                   21.66599433346194
15936
15937 -- Function: mean_chi2 (<n>)
15938     Returns the mean of a Chi-square random variable Chi^2(n), with
15939     n>0.
15940
15941     The Chi^2(n) random variable is equivalent to the Gamma(n/2,2).
15942
15943          (%i1) load ("distrib")$
15944          (%i2) mean_chi2(n);
15945          (%o2)                           n
15946
15947 -- Function: var_chi2 (<n>)
15948     Returns the variance of a Chi-square random variable Chi^2(n), with
15949     n>0.
15950
15951     The Chi^2(n) random variable is equivalent to the Gamma(n/2,2).
15952
15953          (%i1) load ("distrib")$
15954          (%i2) var_chi2(n);
15955          (%o2)                          2 n
15956
15957 -- Function: std_chi2 (<n>)
15958     Returns the standard deviation of a Chi-square random variable
15959     Chi^2(n), with n>0.
15960
15961     The Chi^2(n) random variable is equivalent to the Gamma(n/2,2).
15962
15963          (%i1) load ("distrib")$
15964          (%i2) std_chi2(n);
15965          (%o2)                    sqrt(2) sqrt(n)
15966
15967 -- Function: skewness_chi2 (<n>)
15968     Returns the skewness coefficient of a Chi-square random variable
15969     Chi^2(n), with n>0.
15970
15971     The Chi^2(n) random variable is equivalent to the Gamma(n/2,2).
15972
15973          (%i1) load ("distrib")$
15974          (%i2) skewness_chi2(n);
15975                                               3/2
15976                                              2
15977          (%o2)                              -------
15978                                             sqrt(n)
15979
15980 -- Function: kurtosis_chi2 (<n>)
15981     Returns the kurtosis coefficient of a Chi-square random variable
15982     Chi^2(n), with n>0.
15983
15984     The Chi^2(n) random variable is equivalent to the Gamma(n/2,2).
15985
15986          (%i1) load ("distrib")$
15987          (%i2) kurtosis_chi2(n);
15988                                         12
15989          (%o2)                          --
15990                                         n
15991
15992 -- Function: random_chi2 (<n>)
15993          random_chi2 (<n>,<m>)
15994
15995     Returns a Chi-square random variate Chi^2(n), with n>0.  Calling
15996     'random_chi2' with a second argument <m>, a random sample of size
15997     <m> will be simulated.
15998
15999     The simulation is based on the Ahrens-Cheng algorithm.  See
16000     'random_gamma' for details.
16001
16002     To make use of this function, write first 'load("distrib")'.
16003
16004 -- Function: pdf_noncentral_chi2 (<x>,<n>,<ncp>)
16005     Returns the value at <x> of the density function of a noncentral
16006     Chi-square random variable nc_Chi^2(n,ncp), with n>0 and
16007     noncentrality parameter ncp>=0.  To make use of this function,
16008     write first 'load("distrib")'.
16009
16010 -- Function: cdf_noncentral_chi2 (<x>,<n>,<ncp>)
16011     Returns the value at <x> of the distribution function of a
16012     noncentral Chi-square random variable nc_Chi^2(n,ncp), with n>0 and
16013     noncentrality parameter ncp>=0.  To make use of this function,
16014     write first 'load("distrib")'.
16015
16016 -- Function: quantile_noncentral_chi2 (<q>,<n>,<ncp>)
16017     Returns the <q>-quantile of a noncentral Chi-square random variable
16018     nc_Chi^2(n,ncp), with n>0 and noncentrality parameter ncp>=0; in
16019     other words, this is the inverse of 'cdf_noncentral_chi2'.
16020     Argument <q> must be an element of [0,1].
16021
16022     This function has no closed form and it is numerically computed.
16023
16024 -- Function: mean_noncentral_chi2 (<n>,<ncp>)
16025     Returns the mean of a noncentral Chi-square random variable
16026     nc_Chi^2(n,ncp), with n>0 and noncentrality parameter ncp>=0.
16027
16028 -- Function: var_noncentral_chi2 (<n>,<ncp>)
16029     Returns the variance of a noncentral Chi-square random variable
16030     nc_Chi^2(n,ncp), with n>0 and noncentrality parameter ncp>=0.
16031
16032 -- Function: std_noncentral_chi2 (<n>,<ncp>)
16033     Returns the standard deviation of a noncentral Chi-square random
16034     variable nc_Chi^2(n,ncp), with n>0 and noncentrality parameter
16035     ncp>=0.
16036
16037 -- Function: skewness_noncentral_chi2 (<n>,<ncp>)
16038     Returns the skewness coefficient of a noncentral Chi-square random
16039     variable nc_Chi^2(n,ncp), with n>0 and noncentrality parameter
16040     ncp>=0.
16041
16042 -- Function: kurtosis_noncentral_chi2 (<n>,<ncp>)
16043     Returns the kurtosis coefficient of a noncentral Chi-square random
16044     variable nc_Chi^2(n,ncp), with n>0 and noncentrality parameter
16045     ncp>=0.
16046
16047 -- Function: random_noncentral_chi2 (<n>,<ncp>)
16048          random_noncentral_chi2 (<n>,<ncp>,<m>)
16049
16050     Returns a noncentral Chi-square random variate nc_Chi^2(n,ncp),
16051     with n>0 and noncentrality parameter ncp>=0.  Calling
16052     'random_noncentral_chi2' with a third argument <m>, a random sample
16053     of size <m> will be simulated.
16054
16055     To make use of this function, write first 'load("distrib")'.
16056
16057 -- Function: pdf_f (<x>,<m>,<n>)
16058     Returns the value at <x> of the density function of a F random
16059     variable F(m,n), with m,n>0.  To make use of this function, write
16060     first 'load("distrib")'.
16061
16062 -- Function: cdf_f (<x>,<m>,<n>)
16063     Returns the value at <x> of the distribution function of a F random
16064     variable F(m,n), with m,n>0.
16065
16066          (%i1) load ("distrib")$
16067          (%i2) cdf_f(2,3,9/4);
16068                                                   9  3  3
16069          (%o2)    1 - beta_incomplete_regularized(-, -, --)
16070                                                   8  2  11
16071          (%i3) float(%);
16072          (%o3)                 0.66756728179008
16073
16074 -- Function: quantile_f (<q>,<m>,<n>)
16075     Returns the <q>-quantile of a F random variable F(m,n), with m,n>0;
16076     in other words, this is the inverse of 'cdf_f'.  Argument <q> must
16077     be an element of [0,1].
16078
16079          (%i1) load ("distrib")$
16080          (%i2) quantile_f(2/5,sqrt(3),5);
16081          (%o2)                   0.518947838573693
16082
16083 -- Function: mean_f (<m>,<n>)
16084     Returns the mean of a F random variable F(m,n), with m>0, n>2.  To
16085     make use of this function, write first 'load("distrib")'.
16086
16087 -- Function: var_f (<m>,<n>)
16088     Returns the variance of a F random variable F(m,n), with m>0, n>4.
16089     To make use of this function, write first 'load("distrib")'.
16090
16091 -- Function: std_f (<m>,<n>)
16092     Returns the standard deviation of a F random variable F(m,n), with
16093     m>0, n>4.  To make use of this function, write first
16094     'load("distrib")'.
16095
16096 -- Function: skewness_f (<m>,<n>)
16097     Returns the skewness coefficient of a F random variable F(m,n),
16098     with m>0, n>6.  To make use of this function, write first
16099     'load("distrib")'.
16100
16101 -- Function: kurtosis_f (<m>,<n>)
16102     Returns the kurtosis coefficient of a F random variable F(m,n),
16103     with m>0, n>8.  To make use of this function, write first
16104     'load("distrib")'.
16105
16106 -- Function: random_f (<m>,<n>)
16107          random_f (<m>,<n>,<k>)
16108
16109     Returns a F random variate F(m,n), with m,n>0.  Calling 'random_f'
16110     with a third argument <k>, a random sample of size <k> will be
16111     simulated.
16112
16113     The simulation algorithm is based on the fact that if <X> is a
16114     Chi^2(m) random variable and Y is a Chi^2(n) random variable, then
16115                                  n X
16116                              F = ---
16117                                  m Y
16118     is a F random variable with <m> and <n> degrees of freedom, F(m,n).
16119
16120     To make use of this function, write first 'load("distrib")'.
16121
16122 -- Function: pdf_exp (<x>,<m>)
16123     Returns the value at <x> of the density function of an
16124     Exponential(m) random variable, with m>0.
16125
16126     The Exponential(m) random variable is equivalent to the
16127     Weibull(1,1/m).
16128
16129          (%i1) load ("distrib")$
16130          (%i2) pdf_exp(x,m);
16131                                          - m x
16132          (%o2)                       m %e
16133
16134 -- Function: cdf_exp (<x>,<m>)
16135     Returns the value at <x> of the distribution function of an
16136     Exponential(m) random variable, with m>0.
16137
16138     The Exponential(m) random variable is equivalent to the
16139     Weibull(1,1/m).
16140
16141          (%i1) load ("distrib")$
16142          (%i2) cdf_exp(x,m);
16143                                           - m x
16144          (%o2)                      1 - %e
16145
16146 -- Function: quantile_exp (<q>,<m>)
16147     Returns the <q>-quantile of an Exponential(m) random variable, with
16148     m>0; in other words, this is the inverse of 'cdf_exp'.  Argument
16149     <q> must be an element of [0,1].
16150
16151     The Exponential(m) random variable is equivalent to the
16152     Weibull(1,1/m).
16153
16154          (%i1) load ("distrib")$
16155          (%i2) quantile_exp(0.56,5);
16156          (%o2)                   .1641961104139661
16157          (%i3) quantile_exp(0.56,m);
16158                                       0.8209805520698303
16159          (%o3)                        ------------------
16160                                               m
16161
16162 -- Function: mean_exp (<m>)
16163     Returns the mean of an Exponential(m) random variable, with m>0.
16164
16165     The Exponential(m) random variable is equivalent to the
16166     Weibull(1,1/m).
16167
16168          (%i1) load ("distrib")$
16169          (%i2) mean_exp(m);
16170                                          1
16171          (%o2)                           -
16172                                          m
16173
16174 -- Function: var_exp (<m>)
16175     Returns the variance of an Exponential(m) random variable, with
16176     m>0.
16177
16178     The Exponential(m) random variable is equivalent to the
16179     Weibull(1,1/m).
16180
16181          (%i1) load ("distrib")$
16182          (%i2) var_exp(m);
16183                                         1
16184          (%o2)                          --
16185                                          2
16186                                         m
16187
16188 -- Function: std_exp (<m>)
16189     Returns the standard deviation of an Exponential(m) random
16190     variable, with m>0.
16191
16192     The Exponential(m) random variable is equivalent to the
16193     Weibull(1,1/m).
16194
16195          (%i1) load ("distrib")$
16196          (%i2) std_exp(m);
16197                                          1
16198          (%o2)                           -
16199                                          m
16200
16201 -- Function: skewness_exp (<m>)
16202     Returns the skewness coefficient of an Exponential(m) random
16203     variable, with m>0.
16204
16205     The Exponential(m) random variable is equivalent to the
16206     Weibull(1,1/m).
16207
16208          (%i1) load ("distrib")$
16209          (%i2) skewness_exp(m);
16210          (%o2)                           2
16211
16212 -- Function: kurtosis_exp (<m>)
16213     Returns the kurtosis coefficient of an Exponential(m) random
16214     variable, with m>0.
16215
16216     The Exponential(m) random variable is equivalent to the
16217     Weibull(1,1/m).
16218
16219          (%i1) load ("distrib")$
16220          (%i2) kurtosis_exp(m);
16221          (%o3)                           6
16222
16223 -- Function: random_exp (<m>)
16224          random_exp (<m>,<k>)
16225
16226     Returns an Exponential(m) random variate, with m>0.  Calling
16227     'random_exp' with a second argument <k>, a random sample of size
16228     <k> will be simulated.
16229
16230     The simulation algorithm is based on the general inverse method.
16231
16232     To make use of this function, write first 'load("distrib")'.
16233
16234 -- Function: pdf_lognormal (<x>,<m>,<s>)
16235     Returns the value at <x> of the density function of a
16236     Lognormal(m,s) random variable, with s>0.  To make use of this
16237     function, write first 'load("distrib")'.
16238
16239 -- Function: cdf_lognormal (<x>,<m>,<s>)
16240     Returns the value at <x> of the distribution function of a
16241     Lognormal(m,s) random variable, with s>0.  This function is defined
16242     in terms of Maxima's built-in error function 'erf'.
16243
16244          (%i1) load ("distrib")$
16245          (%i2) cdf_lognormal(x,m,s);
16246                                     log(x) - m
16247                                 erf(----------)
16248                                     sqrt(2) s     1
16249          (%o2)                  --------------- + -
16250                                        2          2
16251
16252     See also 'erf'.
16253
16254 -- Function: quantile_lognormal (<q>,<m>,<s>)
16255     Returns the <q>-quantile of a Lognormal(m,s) random variable, with
16256     s>0; in other words, this is the inverse of 'cdf_lognormal'.
16257     Argument <q> must be an element of [0,1].  To make use of this
16258     function, write first 'load("distrib")'.
16259
16260          (%i1) load ("distrib")$
16261          (%i2) quantile_lognormal(95/100,0,1);
16262                            sqrt(2) inverse_erf(9/10)
16263          (%o2)           %e
16264          (%i3) float(%);
16265          (%o3)               5.180251602233015
16266
16267 -- Function: mean_lognormal (<m>,<s>)
16268     Returns the mean of a Lognormal(m,s) random variable, with s>0.  To
16269     make use of this function, write first 'load("distrib")'.
16270
16271 -- Function: var_lognormal (<m>,<s>)
16272     Returns the variance of a Lognormal(m,s) random variable, with s>0.
16273     To make use of this function, write first 'load("distrib")'.
16274
16275 -- Function: std_lognormal (<m>,<s>)
16276     Returns the standard deviation of a Lognormal(m,s) random variable,
16277     with s>0.  To make use of this function, write first
16278     'load("distrib")'.
16279
16280 -- Function: skewness_lognormal (<m>,<s>)
16281     Returns the skewness coefficient of a Lognormal(m,s) random
16282     variable, with s>0.  To make use of this function, write first
16283     'load("distrib")'.
16284
16285 -- Function: kurtosis_lognormal (<m>,<s>)
16286     Returns the kurtosis coefficient of a Lognormal(m,s) random
16287     variable, with s>0.  To make use of this function, write first
16288     'load("distrib")'.
16289
16290 -- Function: random_lognormal (<m>,<s>)
16291          random_lognormal (<m>,<s>,<n>)
16292
16293     Returns a Lognormal(m,s) random variate, with s>0.  Calling
16294     'random_lognormal' with a third argument <n>, a random sample of
16295     size <n> will be simulated.
16296
16297     Log-normal variates are simulated by means of random normal
16298     variates.  See 'random_normal' for details.
16299
16300     To make use of this function, write first 'load("distrib")'.
16301
16302 -- Function: pdf_gamma (<x>,<a>,<b>)
16303     Returns the value at <x> of the density function of a Gamma(a,b)
16304     random variable, with a,b>0.  To make use of this function, write
16305     first 'load("distrib")'.
16306
16307 -- Function: cdf_gamma (<x>,<a>,<b>)
16308     Returns the value at <x> of the distribution function of a
16309     Gamma(a,b) random variable, with a,b>0.
16310
16311          (%i1) load ("distrib")$
16312          (%i2) cdf_gamma(3,5,21);
16313                                                        1
16314          (%o2)     1 - gamma_incomplete_regularized(5, -)
16315                                                        7
16316          (%i3) float(%);
16317          (%o3)              4.402663157376807E-7
16318
16319 -- Function: quantile_gamma (<q>,<a>,<b>)
16320     Returns the <q>-quantile of a Gamma(a,b) random variable, with
16321     a,b>0; in other words, this is the inverse of 'cdf_gamma'.
16322     Argument <q> must be an element of [0,1].  To make use of this
16323     function, write first 'load("distrib")'.
16324
16325 -- Function: mean_gamma (<a>,<b>)
16326     Returns the mean of a Gamma(a,b) random variable, with a,b>0.  To
16327     make use of this function, write first 'load("distrib")'.
16328
16329 -- Function: var_gamma (<a>,<b>)
16330     Returns the variance of a Gamma(a,b) random variable, with a,b>0.
16331     To make use of this function, write first 'load("distrib")'.
16332
16333 -- Function: std_gamma (<a>,<b>)
16334     Returns the standard deviation of a Gamma(a,b) random variable,
16335     with a,b>0.  To make use of this function, write first
16336     'load("distrib")'.
16337
16338 -- Function: skewness_gamma (<a>,<b>)
16339     Returns the skewness coefficient of a Gamma(a,b) random variable,
16340     with a,b>0.  To make use of this function, write first
16341     'load("distrib")'.
16342
16343 -- Function: kurtosis_gamma (<a>,<b>)
16344     Returns the kurtosis coefficient of a Gamma(a,b) random variable,
16345     with a,b>0.  To make use of this function, write first
16346     'load("distrib")'.
16347
16348 -- Function: random_gamma (<a>,<b>)
16349          random_gamma (<a>,<b>,<n>)
16350
16351     Returns a Gamma(a,b) random variate, with a,b>0.  Calling
16352     'random_gamma' with a third argument <n>, a random sample of size
16353     <n> will be simulated.
16354
16355     The implemented algorithm is a combinantion of two procedures,
16356     depending on the value of parameter <a>:
16357
16358     For a>=1, Cheng, R.C.H. and Feast, G.M. (1979).  <Some simple gamma
16359     variate generators>.  Appl.  Stat., 28, 3, 290-295.
16360
16361     For 0<a<1, Ahrens, J.H. and Dieter, U. (1974).  <Computer methods
16362     for sampling from gamma, beta, poisson and binomial
16363     cdf_tributions>.  Computing, 12, 223-246.
16364
16365     To make use of this function, write first 'load("distrib")'.
16366
16367 -- Function: pdf_beta (<x>,<a>,<b>)
16368     Returns the value at <x> of the density function of a Beta(a,b)
16369     random variable, with a,b>0.  To make use of this function, write
16370     first 'load("distrib")'.
16371
16372 -- Function: cdf_beta (<x>,<a>,<b>)
16373     Returns the value at <x> of the distribution function of a
16374     Beta(a,b) random variable, with a,b>0.
16375
16376          (%i1) load ("distrib")$
16377          (%i2) cdf_beta(1/3,15,2);
16378                                       11
16379          (%o2)                     --------
16380                                    14348907
16381          (%i3) float(%);
16382          (%o3)              7.666089131388195E-7
16383
16384 -- Function: quantile_beta (<q>,<a>,<b>)
16385     Returns the <q>-quantile of a Beta(a,b) random variable, with
16386     a,b>0; in other words, this is the inverse of 'cdf_beta'.  Argument
16387     <q> must be an element of [0,1].  To make use of this function,
16388     write first 'load("distrib")'.
16389
16390 -- Function: mean_beta (<a>,<b>)
16391     Returns the mean of a Beta(a,b) random variable, with a,b>0.  To
16392     make use of this function, write first 'load("distrib")'.
16393
16394 -- Function: var_beta (<a>,<b>)
16395     Returns the variance of a Beta(a,b) random variable, with a,b>0.
16396     To make use of this function, write first 'load("distrib")'.
16397
16398 -- Function: std_beta (<a>,<b>)
16399     Returns the standard deviation of a Beta(a,b) random variable, with
16400     a,b>0.  To make use of this function, write first
16401     'load("distrib")'.
16402
16403 -- Function: skewness_beta (<a>,<b>)
16404     Returns the skewness coefficient of a Beta(a,b) random variable,
16405     with a,b>0.  To make use of this function, write first
16406     'load("distrib")'.
16407
16408 -- Function: kurtosis_beta (<a>,<b>)
16409     Returns the kurtosis coefficient of a Beta(a,b) random variable,
16410     with a,b>0.  To make use of this function, write first
16411     'load("distrib")'.
16412
16413 -- Function: random_beta (<a>,<b>)
16414          random_beta (<a>,<b>,<n>)
16415
16416     Returns a Beta(a,b) random variate, with a,b>0.  Calling
16417     'random_beta' with a third argument <n>, a random sample of size
16418     <n> will be simulated.
16419
16420     The implemented algorithm is defined in Cheng, R.C.H. (1978).
16421     <Generating Beta Variates with Nonintegral Shape Parameters>.
16422     Communications of the ACM, 21:317-322
16423
16424     To make use of this function, write first 'load("distrib")'.
16425
16426 -- Function: pdf_continuous_uniform (<x>,<a>,<b>)
16427     Returns the value at <x> of the density function of a Continuous
16428     Uniform(a,b) random variable, with a<b.  To make use of this
16429     function, write first 'load("distrib")'.
16430
16431 -- Function: cdf_continuous_uniform (<x>,<a>,<b>)
16432     Returns the value at <x> of the distribution function of a
16433     Continuous Uniform(a,b) random variable, with a<b.  To make use of
16434     this function, write first 'load("distrib")'.
16435
16436 -- Function: quantile_continuous_uniform (<q>,<a>,<b>)
16437     Returns the <q>-quantile of a Continuous Uniform(a,b) random
16438     variable, with a<b; in other words, this is the inverse of
16439     'cdf_continuous_uniform'.  Argument <q> must be an element of
16440     [0,1].  To make use of this function, write first
16441     'load("distrib")'.
16442
16443 -- Function: mean_continuous_uniform (<a>,<b>)
16444     Returns the mean of a Continuous Uniform(a,b) random variable, with
16445     a<b.  To make use of this function, write first 'load("distrib")'.
16446
16447 -- Function: var_continuous_uniform (<a>,<b>)
16448     Returns the variance of a Continuous Uniform(a,b) random variable,
16449     with a<b.  To make use of this function, write first
16450     'load("distrib")'.
16451
16452 -- Function: std_continuous_uniform (<a>,<b>)
16453     Returns the standard deviation of a Continuous Uniform(a,b) random
16454     variable, with a<b.  To make use of this function, write first
16455     'load("distrib")'.
16456
16457 -- Function: skewness_continuous_uniform (<a>,<b>)
16458     Returns the skewness coefficient of a Continuous Uniform(a,b)
16459     random variable, with a<b.  To make use of this function, write
16460     first 'load("distrib")'.
16461
16462 -- Function: kurtosis_continuous_uniform (<a>,<b>)
16463     Returns the kurtosis coefficient of a Continuous Uniform(a,b)
16464     random variable, with a<b.  To make use of this function, write
16465     first 'load("distrib")'.
16466
16467 -- Function: random_continuous_uniform (<a>,<b>)
16468          random_continuous_uniform (<a>,<b>,<n>)
16469
16470     Returns a Continuous Uniform(a,b) random variate, with a<b.
16471     Calling 'random_continuous_uniform' with a third argument <n>, a
16472     random sample of size <n> will be simulated.
16473
16474     This is a direct application of the 'random' built-in Maxima
16475     function.
16476
16477     See also 'random'.  To make use of this function, write first
16478     'load("distrib")'.
16479
16480 -- Function: pdf_logistic (<x>,<a>,<b>)
16481     Returns the value at <x> of the density function of a Logistic(a,b)
16482     random variable , with b>0.  To make use of this function, write
16483     first 'load("distrib")'.
16484
16485 -- Function: cdf_logistic (<x>,<a>,<b>)
16486     Returns the value at <x> of the distribution function of a
16487     Logistic(a,b) random variable , with b>0.  To make use of this
16488     function, write first 'load("distrib")'.
16489
16490 -- Function: quantile_logistic (<q>,<a>,<b>)
16491     Returns the <q>-quantile of a Logistic(a,b) random variable , with
16492     b>0; in other words, this is the inverse of 'cdf_logistic'.
16493     Argument <q> must be an element of [0,1].  To make use of this
16494     function, write first 'load("distrib")'.
16495
16496 -- Function: mean_logistic (<a>,<b>)
16497     Returns the mean of a Logistic(a,b) random variable , with b>0.  To
16498     make use of this function, write first 'load("distrib")'.
16499
16500 -- Function: var_logistic (<a>,<b>)
16501     Returns the variance of a Logistic(a,b) random variable , with b>0.
16502     To make use of this function, write first 'load("distrib")'.
16503
16504 -- Function: std_logistic (<a>,<b>)
16505     Returns the standard deviation of a Logistic(a,b) random variable ,
16506     with b>0.  To make use of this function, write first
16507     'load("distrib")'.
16508
16509 -- Function: skewness_logistic (<a>,<b>)
16510     Returns the skewness coefficient of a Logistic(a,b) random variable
16511     , with b>0.  To make use of this function, write first
16512     'load("distrib")'.
16513
16514 -- Function: kurtosis_logistic (<a>,<b>)
16515     Returns the kurtosis coefficient of a Logistic(a,b) random variable
16516     , with b>0.  To make use of this function, write first
16517     'load("distrib")'.
16518
16519 -- Function: random_logistic (<a>,<b>)
16520          random_logistic (<a>,<b>,<n>)
16521
16522     Returns a Logistic(a,b) random variate, with b>0.  Calling
16523     'random_logistic' with a third argument <n>, a random sample of
16524     size <n> will be simulated.
16525
16526     The implemented algorithm is based on the general inverse method.
16527
16528     To make use of this function, write first 'load("distrib")'.
16529
16530 -- Function: pdf_pareto (<x>,<a>,<b>)
16531     Returns the value at <x> of the density function of a Pareto(a,b)
16532     random variable, with a,b>0.  To make use of this function, write
16533     first 'load("distrib")'.
16534
16535 -- Function: cdf_pareto (<x>,<a>,<b>)
16536     Returns the value at <x> of the distribution function of a
16537     Pareto(a,b) random variable, with a,b>0.  To make use of this
16538     function, write first 'load("distrib")'.
16539
16540 -- Function: quantile_pareto (<q>,<a>,<b>)
16541     Returns the <q>-quantile of a Pareto(a,b) random variable, with
16542     a,b>0; in other words, this is the inverse of 'cdf_pareto'.
16543     Argument <q> must be an element of [0,1].  To make use of this
16544     function, write first 'load("distrib")'.
16545
16546 -- Function: mean_pareto (<a>,<b>)
16547     Returns the mean of a Pareto(a,b) random variable, with a>1,b>0.
16548     To make use of this function, write first 'load("distrib")'.
16549
16550 -- Function: var_pareto (<a>,<b>)
16551     Returns the variance of a Pareto(a,b) random variable, with
16552     a>2,b>0.  To make use of this function, write first
16553     'load("distrib")'.
16554
16555 -- Function: std_pareto (<a>,<b>)
16556     Returns the standard deviation of a Pareto(a,b) random variable,
16557     with a>2,b>0.  To make use of this function, write first
16558     'load("distrib")'.
16559
16560 -- Function: skewness_pareto (<a>,<b>)
16561     Returns the skewness coefficient of a Pareto(a,b) random variable,
16562     with a>3,b>0.  To make use of this function, write first
16563     'load("distrib")'.
16564
16565 -- Function: kurtosis_pareto (<a>,<b>)
16566     Returns the kurtosis coefficient of a Pareto(a,b) random variable,
16567     with a>4,b>0.  To make use of this function, write first
16568     'load("distrib")'.
16569
16570 -- Function: random_pareto (<a>,<b>)
16571          random_pareto (<a>,<b>,<n>)
16572
16573     Returns a Pareto(a,b) random variate, with a>0,b>0.  Calling
16574     'random_pareto' with a third argument <n>, a random sample of size
16575     <n> will be simulated.
16576
16577     The implemented algorithm is based on the general inverse method.
16578
16579     To make use of this function, write first 'load("distrib")'.
16580
16581 -- Function: pdf_weibull (<x>,<a>,<b>)
16582     Returns the value at <x> of the density function of a Weibull(a,b)
16583     random variable, with a,b>0.  To make use of this function, write
16584     first 'load("distrib")'.
16585
16586 -- Function: cdf_weibull (<x>,<a>,<b>)
16587     Returns the value at <x> of the distribution function of a
16588     Weibull(a,b) random variable, with a,b>0.  To make use of this
16589     function, write first 'load("distrib")'.
16590
16591 -- Function: quantile_weibull (<q>,<a>,<b>)
16592     Returns the <q>-quantile of a Weibull(a,b) random variable, with
16593     a,b>0; in other words, this is the inverse of 'cdf_weibull'.
16594     Argument <q> must be an element of [0,1].  To make use of this
16595     function, write first 'load("distrib")'.
16596
16597 -- Function: mean_weibull (<a>,<b>)
16598     Returns the mean of a Weibull(a,b) random variable, with a,b>0.  To
16599     make use of this function, write first 'load("distrib")'.
16600
16601 -- Function: var_weibull (<a>,<b>)
16602     Returns the variance of a Weibull(a,b) random variable, with a,b>0.
16603     To make use of this function, write first 'load("distrib")'.
16604
16605 -- Function: std_weibull (<a>,<b>)
16606     Returns the standard deviation of a Weibull(a,b) random variable,
16607     with a,b>0.  To make use of this function, write first
16608     'load("distrib")'.
16609
16610 -- Function: skewness_weibull (<a>,<b>)
16611     Returns the skewness coefficient of a Weibull(a,b) random variable,
16612     with a,b>0.  To make use of this function, write first
16613     'load("distrib")'.
16614
16615 -- Function: kurtosis_weibull (<a>,<b>)
16616     Returns the kurtosis coefficient of a Weibull(a,b) random variable,
16617     with a,b>0.  To make use of this function, write first
16618     'load("distrib")'.
16619
16620 -- Function: random_weibull (<a>,<b>)
16621          random_weibull (<a>,<b>,<n>)
16622
16623     Returns a Weibull(a,b) random variate, with a,b>0.  Calling
16624     'random_weibull' with a third argument <n>, a random sample of size
16625     <n> will be simulated.
16626
16627     The implemented algorithm is based on the general inverse method.
16628
16629     To make use of this function, write first 'load("distrib")'.
16630
16631 -- Function: pdf_rayleigh (<x>,<b>)
16632     Returns the value at <x> of the density function of a Rayleigh(b)
16633     random variable, with b>0.
16634
16635     The Rayleigh(b) random variable is equivalent to the
16636     Weibull(2,1/b).
16637
16638          (%i1) load ("distrib")$
16639          (%i2) pdf_rayleigh(x,b);
16640                                              2  2
16641                                     2     - b  x
16642          (%o2)                   2 b  x %e
16643
16644 -- Function: cdf_rayleigh (<x>,<b>)
16645     Returns the value at <x> of the distribution function of a
16646     Rayleigh(b) random variable, with b>0.
16647
16648     The Rayleigh(b) random variable is equivalent to the
16649     Weibull(2,1/b).
16650
16651          (%i1) load ("distrib")$
16652          (%i2) cdf_rayleigh(x,b);
16653                                             2  2
16654                                          - b  x
16655          (%o2)                     1 - %e
16656
16657 -- Function: quantile_rayleigh (<q>,<b>)
16658     Returns the <q>-quantile of a Rayleigh(b) random variable, with
16659     b>0; in other words, this is the inverse of 'cdf_rayleigh'.
16660     Argument <q> must be an element of [0,1].
16661
16662     The Rayleigh(b) random variable is equivalent to the
16663     Weibull(2,1/b).
16664
16665          (%i1) load ("distrib")$
16666          (%i2) quantile_rayleigh(0.99,b);
16667                                  2.145966026289347
16668          (%o2)                   -----------------
16669                                          b
16670
16671 -- Function: mean_rayleigh (<b>)
16672     Returns the mean of a Rayleigh(b) random variable, with b>0.
16673
16674     The Rayleigh(b) random variable is equivalent to the
16675     Weibull(2,1/b).
16676
16677          (%i1) load ("distrib")$
16678          (%i2) mean_rayleigh(b);
16679                                      sqrt(%pi)
16680          (%o2)                       ---------
16681                                         2 b
16682
16683 -- Function: var_rayleigh (<b>)
16684     Returns the variance of a Rayleigh(b) random variable, with b>0.
16685
16686     The Rayleigh(b) random variable is equivalent to the
16687     Weibull(2,1/b).
16688
16689          (%i1) load ("distrib")$
16690          (%i2) var_rayleigh(b);
16691                                           %pi
16692                                       1 - ---
16693                                            4
16694          (%o2)                        -------
16695                                          2
16696                                         b
16697
16698 -- Function: std_rayleigh (<b>)
16699     Returns the standard deviation of a Rayleigh(b) random variable,
16700     with b>0.
16701
16702     The Rayleigh(b) random variable is equivalent to the
16703     Weibull(2,1/b).
16704
16705          (%i1) load ("distrib")$
16706          (%i2) std_rayleigh(b);
16707                                             %pi
16708                                    sqrt(1 - ---)
16709                                              4
16710          (%o2)                     -------------
16711                                          b
16712
16713 -- Function: skewness_rayleigh (<b>)
16714     Returns the skewness coefficient of a Rayleigh(b) random variable,
16715     with b>0.
16716
16717     The Rayleigh(b) random variable is equivalent to the
16718     Weibull(2,1/b).
16719
16720          (%i1) load ("distrib")$
16721          (%i2) skewness_rayleigh(b);
16722                                   3/2
16723                                %pi      3 sqrt(%pi)
16724                                ------ - -----------
16725                                  4           4
16726          (%o2)                 --------------------
16727                                         %pi 3/2
16728                                    (1 - ---)
16729                                          4
16730
16731 -- Function: kurtosis_rayleigh (<b>)
16732     Returns the kurtosis coefficient of a Rayleigh(b) random variable,
16733     with b>0.
16734
16735     The Rayleigh(b) random variable is equivalent to the
16736     Weibull(2,1/b).
16737
16738          (%i1) load ("distrib")$
16739          (%i2) kurtosis_rayleigh(b);
16740                                            2
16741                                       3 %pi
16742                                   2 - ------
16743                                         16
16744          (%o2)                    ---------- - 3
16745                                        %pi 2
16746                                   (1 - ---)
16747                                         4
16748
16749 -- Function: random_rayleigh (<b>)
16750          random_rayleigh (<b>,<n>)
16751
16752     Returns a Rayleigh(b) random variate, with b>0.  Calling
16753     'random_rayleigh' with a second argument <n>, a random sample of
16754     size <n> will be simulated.
16755
16756     The implemented algorithm is based on the general inverse method.
16757
16758     To make use of this function, write first 'load("distrib")'.
16759
16760 -- Function: pdf_laplace (<x>,<a>,<b>)
16761     Returns the value at <x> of the density function of a Laplace(a,b)
16762     random variable, with b>0.  To make use of this function, write
16763     first 'load("distrib")'.
16764
16765 -- Function: cdf_laplace (<x>,<a>,<b>)
16766     Returns the value at <x> of the distribution function of a
16767     Laplace(a,b) random variable, with b>0.  To make use of this
16768     function, write first 'load("distrib")'.
16769
16770 -- Function: quantile_laplace (<q>,<a>,<b>)
16771     Returns the <q>-quantile of a Laplace(a,b) random variable, with
16772     b>0; in other words, this is the inverse of 'cdf_laplace'.
16773     Argument <q> must be an element of [0,1].  To make use of this
16774     function, write first 'load("distrib")'.
16775
16776 -- Function: mean_laplace (<a>,<b>)
16777     Returns the mean of a Laplace(a,b) random variable, with b>0.  To
16778     make use of this function, write first 'load("distrib")'.
16779
16780 -- Function: var_laplace (<a>,<b>)
16781     Returns the variance of a Laplace(a,b) random variable, with b>0.
16782     To make use of this function, write first 'load("distrib")'.
16783
16784 -- Function: std_laplace (<a>,<b>)
16785     Returns the standard deviation of a Laplace(a,b) random variable,
16786     with b>0.  To make use of this function, write first
16787     'load("distrib")'.
16788
16789 -- Function: skewness_laplace (<a>,<b>)
16790     Returns the skewness coefficient of a Laplace(a,b) random variable,
16791     with b>0.  To make use of this function, write first
16792     'load("distrib")'.
16793
16794 -- Function: kurtosis_laplace (<a>,<b>)
16795     Returns the kurtosis coefficient of a Laplace(a,b) random variable,
16796     with b>0.  To make use of this function, write first
16797     'load("distrib")'.
16798
16799 -- Function: random_laplace (<a>,<b>)
16800          random_laplace (<a>,<b>,<n>)
16801
16802     Returns a Laplace(a,b) random variate, with b>0.  Calling
16803     'random_laplace' with a third argument <n>, a random sample of size
16804     <n> will be simulated.
16805
16806     The implemented algorithm is based on the general inverse method.
16807
16808     To make use of this function, write first 'load("distrib")'.
16809
16810 -- Function: pdf_cauchy (<x>,<a>,<b>)
16811     Returns the value at <x> of the density function of a Cauchy(a,b)
16812     random variable, with b>0.  To make use of this function, write
16813     first 'load("distrib")'.
16814
16815 -- Function: cdf_cauchy (<x>,<a>,<b>)
16816     Returns the value at <x> of the distribution function of a
16817     Cauchy(a,b) random variable, with b>0.  To make use of this
16818     function, write first 'load("distrib")'.
16819
16820 -- Function: quantile_cauchy (<q>,<a>,<b>)
16821     Returns the <q>-quantile of a Cauchy(a,b) random variable, with
16822     b>0; in other words, this is the inverse of 'cdf_cauchy'.  Argument
16823     <q> must be an element of [0,1].  To make use of this function,
16824     write first 'load("distrib")'.
16825
16826 -- Function: random_cauchy (<a>,<b>)
16827          random_cauchy (<a>,<b>,<n>)
16828
16829     Returns a Cauchy(a,b) random variate, with b>0.  Calling
16830     'random_cauchy' with a third argument <n>, a random sample of size
16831     <n> will be simulated.
16832
16833     The implemented algorithm is based on the general inverse method.
16834
16835     To make use of this function, write first 'load("distrib")'.
16836
16837 -- Function: pdf_gumbel (<x>,<a>,<b>)
16838     Returns the value at <x> of the density function of a Gumbel(a,b)
16839     random variable, with b>0.  To make use of this function, write
16840     first 'load("distrib")'.
16841
16842 -- Function: cdf_gumbel (<x>,<a>,<b>)
16843     Returns the value at <x> of the distribution function of a
16844     Gumbel(a,b) random variable, with b>0.  To make use of this
16845     function, write first 'load("distrib")'.
16846
16847 -- Function: quantile_gumbel (<q>,<a>,<b>)
16848     Returns the <q>-quantile of a Gumbel(a,b) random variable, with
16849     b>0; in other words, this is the inverse of 'cdf_gumbel'.  Argument
16850     <q> must be an element of [0,1].  To make use of this function,
16851     write first 'load("distrib")'.
16852
16853 -- Function: mean_gumbel (<a>,<b>)
16854     Returns the mean of a Gumbel(a,b) random variable, with b>0.
16855
16856          (%i1) load ("distrib")$
16857          (%i2) mean_gumbel(a,b);
16858          (%o2)                     %gamma b + a
16859     where symbol '%gamma' stands for the Euler-Mascheroni constant.
16860     See also '%gamma'.
16861
16862 -- Function: var_gumbel (<a>,<b>)
16863     Returns the variance of a Gumbel(a,b) random variable, with b>0.
16864     To make use of this function, write first 'load("distrib")'.
16865
16866 -- Function: std_gumbel (<a>,<b>)
16867     Returns the standard deviation of a Gumbel(a,b) random variable,
16868     with b>0.  To make use of this function, write first
16869     'load("distrib")'.
16870
16871 -- Function: skewness_gumbel (<a>,<b>)
16872     Returns the skewness coefficient of a Gumbel(a,b) random variable,
16873     with b>0.
16874
16875          (%i1) load ("distrib")$
16876          (%i2) skewness_gumbel(a,b);
16877                                            3/2
16878                                         2 6    zeta(3)
16879          (%o2)                          --------------
16880                                                 3
16881                                              %pi
16882     where 'zeta' stands for the Riemann's zeta function.
16883
16884 -- Function: kurtosis_gumbel (<a>,<b>)
16885     Returns the kurtosis coefficient of a Gumbel(a,b) random variable,
16886     with b>0.  To make use of this function, write first
16887     'load("distrib")'.
16888
16889 -- Function: random_gumbel (<a>,<b>)
16890          random_gumbel (<a>,<b>,<n>)
16891
16892     Returns a Gumbel(a,b) random variate, with b>0.  Calling
16893     'random_gumbel' with a third argument <n>, a random sample of size
16894     <n> will be simulated.
16895
16896     The implemented algorithm is based on the general inverse method.
16897
16898     To make use of this function, write first 'load("distrib")'.
16899
16900
16901File: maxima.info,  Node: Functions and Variables for discrete distributions,  Prev: Functions and Variables for continuous distributions,  Up: distrib-pkg
16902
1690352.3 Functions and Variables for discrete distributions
16904=======================================================
16905
16906 -- Function: pdf_general_finite_discrete (<x>,<v>)
16907     Returns the value at <x> of the probability function of a general
16908     finite discrete random variable, with vector probabilities v, such
16909     that 'Pr(X=i) = v_i'.  Vector v can be a list of nonnegative
16910     expressions, whose components will be normalized to get a vector of
16911     probabilities.  To make use of this function, write first
16912     'load("distrib")'.
16913
16914          (%i1) load ("distrib")$
16915          (%i2) pdf_general_finite_discrete(2, [1/7, 4/7, 2/7]);
16916                                          4
16917          (%o2)                           -
16918                                          7
16919          (%i3) pdf_general_finite_discrete(2, [1, 4, 2]);
16920                                          4
16921          (%o3)                           -
16922                                          7
16923
16924 -- Function: cdf_general_finite_discrete (<x>,<v>)
16925     Returns the value at <x> of the distribution function of a general
16926     finite discrete random variable, with vector probabilities v.
16927
16928     See 'pdf_general_finite_discrete' for more details.
16929
16930          (%i1) load ("distrib")$
16931          (%i2) cdf_general_finite_discrete(2, [1/7, 4/7, 2/7]);
16932                                          5
16933          (%o2)                           -
16934                                          7
16935          (%i3) cdf_general_finite_discrete(2, [1, 4, 2]);
16936                                          5
16937          (%o3)                           -
16938                                          7
16939          (%i4) cdf_general_finite_discrete(2+1/2, [1, 4, 2]);
16940                                          5
16941          (%o4)                           -
16942                                          7
16943
16944 -- Function: quantile_general_finite_discrete (<q>,<v>)
16945     Returns the <q>-quantile of a general finite discrete random
16946     variable, with vector probabilities v.
16947
16948     See 'pdf_general_finite_discrete' for more details.
16949
16950 -- Function: mean_general_finite_discrete (<v>)
16951     Returns the mean of a general finite discrete random variable, with
16952     vector probabilities v.
16953
16954     See 'pdf_general_finite_discrete' for more details.
16955
16956 -- Function: var_general_finite_discrete (<v>)
16957     Returns the variance of a general finite discrete random variable,
16958     with vector probabilities v.
16959
16960     See 'pdf_general_finite_discrete' for more details.
16961
16962 -- Function: std_general_finite_discrete (<v>)
16963     Returns the standard deviation of a general finite discrete random
16964     variable, with vector probabilities v.
16965
16966     See 'pdf_general_finite_discrete' for more details.
16967
16968 -- Function: skewness_general_finite_discrete (<v>)
16969     Returns the skewness coefficient of a general finite discrete
16970     random variable, with vector probabilities v.
16971
16972     See 'pdf_general_finite_discrete' for more details.
16973
16974 -- Function: kurtosis_general_finite_discrete (<v>)
16975     Returns the kurtosis coefficient of a general finite discrete
16976     random variable, with vector probabilities v.
16977
16978     See 'pdf_general_finite_discrete' for more details.
16979
16980 -- Function: random_general_finite_discrete (<v>)
16981          random_general_finite_discrete (<v>,<m>)
16982
16983     Returns a general finite discrete random variate, with vector
16984     probabilities v.  Calling 'random_general_finite_discrete' with a
16985     second argument <m>, a random sample of size <m> will be simulated.
16986
16987     See 'pdf_general_finite_discrete' for more details.
16988
16989          (%i1) load ("distrib")$
16990          (%i2) random_general_finite_discrete([1,3,1,5]);
16991          (%o2)                          4
16992          (%i3) random_general_finite_discrete([1,3,1,5], 10);
16993          (%o3)           [4, 2, 2, 3, 2, 4, 4, 1, 2, 2]
16994
16995 -- Function: pdf_binomial (<x>,<n>,<p>)
16996     Returns the value at <x> of the probability function of a
16997     Binomial(n,p) random variable, with 0 \leq p \leq 1 and n a
16998     positive integer.  To make use of this function, write first
16999     'load("distrib")'.
17000
17001 -- Function: cdf_binomial (<x>,<n>,<p>)
17002     Returns the value at <x> of the distribution function of a
17003     Binomial(n,p) random variable, with 0 \leq p \leq 1 and n a
17004     positive integer.
17005
17006          (%i1) load ("distrib")$
17007          (%i2) cdf_binomial(5,7,1/6);
17008                                      7775
17009          (%o2)                       ----
17010                                      7776
17011          (%i3) float(%);
17012          (%o3)               .9998713991769548
17013
17014 -- Function: quantile_binomial (<q>,<n>,<p>)
17015     Returns the <q>-quantile of a Binomial(n,p) random variable, with 0
17016     \leq p \leq 1 and n a positive integer; in other words, this is the
17017     inverse of 'cdf_binomial'.  Argument <q> must be an element of
17018     [0,1].  To make use of this function, write first
17019     'load("distrib")'.
17020
17021 -- Function: mean_binomial (<n>,<p>)
17022     Returns the mean of a Binomial(n,p) random variable, with 0 \leq p
17023     \leq 1 and n a positive integer.  To make use of this function,
17024     write first 'load("distrib")'.
17025
17026 -- Function: var_binomial (<n>,<p>)
17027     Returns the variance of a Binomial(n,p) random variable, with 0
17028     \leq p \leq 1 and n a positive integer.  To make use of this
17029     function, write first 'load("distrib")'.
17030
17031 -- Function: std_binomial (<n>,<p>)
17032     Returns the standard deviation of a Binomial(n,p) random variable,
17033     with 0 \leq p \leq 1 and n a positive integer.  To make use of this
17034     function, write first 'load("distrib")'.
17035
17036 -- Function: skewness_binomial (<n>,<p>)
17037     Returns the skewness coefficient of a Binomial(n,p) random
17038     variable, with 0 \leq p \leq 1 and n a positive integer.  To make
17039     use of this function, write first 'load("distrib")'.
17040
17041 -- Function: kurtosis_binomial (<n>,<p>)
17042     Returns the kurtosis coefficient of a Binomial(n,p) random
17043     variable, with 0 \leq p \leq 1 and n a positive integer.  To make
17044     use of this function, write first 'load("distrib")'.
17045
17046 -- Function: random_binomial (<n>,<p>)
17047          random_binomial (<n>,<p>,<m>)
17048
17049     Returns a Binomial(n,p) random variate, with 0 \leq p \leq 1 and n
17050     a positive integer.  Calling 'random_binomial' with a third
17051     argument <m>, a random sample of size <m> will be simulated.
17052
17053     The implemented algorithm is based on the one described in
17054     Kachitvichyanukul, V. and Schmeiser, B.W. (1988) <Binomial Random
17055     Variate Generation>.  Communications of the ACM, 31, Feb., 216.
17056
17057     To make use of this function, write first 'load("distrib")'.
17058
17059 -- Function: pdf_poisson (<x>,<m>)
17060     Returns the value at <x> of the probability function of a
17061     Poisson(m) random variable, with m>0.  To make use of this
17062     function, write first 'load("distrib")'.
17063
17064 -- Function: cdf_poisson (<x>,<m>)
17065     Returns the value at <x> of the distribution function of a
17066     Poisson(m) random variable, with m>0.
17067
17068          (%i1) load ("distrib")$
17069          (%i2) cdf_poisson(3,5);
17070          (%o2)       gamma_incomplete_regularized(4, 5)
17071          (%i3) float(%);
17072          (%o3)               .2650259152973623
17073
17074 -- Function: quantile_poisson (<q>,<m>)
17075     Returns the <q>-quantile of a Poisson(m) random variable, with m>0;
17076     in other words, this is the inverse of 'cdf_poisson'.  Argument <q>
17077     must be an element of [0,1].  To make use of this function, write
17078     first 'load("distrib")'.
17079
17080 -- Function: mean_poisson (<m>)
17081     Returns the mean of a Poisson(m) random variable, with m>0.  To
17082     make use of this function, write first 'load("distrib")'.
17083
17084 -- Function: var_poisson (<m>)
17085     Returns the variance of a Poisson(m) random variable, with m>0.  To
17086     make use of this function, write first 'load("distrib")'.
17087
17088 -- Function: std_poisson (<m>)
17089     Returns the standard deviation of a Poisson(m) random variable,
17090     with m>0.  To make use of this function, write first
17091     'load("distrib")'.
17092
17093 -- Function: skewness_poisson (<m>)
17094     Returns the skewness coefficient of a Poisson(m) random variable,
17095     with m>0.  To make use of this function, write first
17096     'load("distrib")'.
17097
17098 -- Function: kurtosis_poisson (<m>)
17099     Returns the kurtosis coefficient of a Poisson random variable
17100     Poi(m), with m>0.  To make use of this function, write first
17101     'load("distrib")'.
17102
17103 -- Function: random_poisson (<m>)
17104          random_poisson (<m>,<n>)
17105
17106     Returns a Poisson(m) random variate, with m>0.  Calling
17107     'random_poisson' with a second argument <n>, a random sample of
17108     size <n> will be simulated.
17109
17110     The implemented algorithm is the one described in Ahrens, J.H. and
17111     Dieter, U. (1982) <Computer Generation of Poisson Deviates From
17112     Modified Normal Distributions>.  ACM Trans.  Math.  Software, 8, 2,
17113     June,163-179.
17114
17115     To make use of this function, write first 'load("distrib")'.
17116
17117 -- Function: pdf_bernoulli (<x>,<p>)
17118     Returns the value at <x> of the probability function of a
17119     Bernoulli(p) random variable, with 0 \leq p \leq 1.
17120
17121     The Bernoulli(p) random variable is equivalent to the
17122     Binomial(1,p).
17123
17124          (%i1) load ("distrib")$
17125          (%i2) pdf_bernoulli(1,p);
17126          (%o2)                           p
17127
17128 -- Function: cdf_bernoulli (<x>,<p>)
17129     Returns the value at <x> of the distribution function of a
17130     Bernoulli(p) random variable, with 0 \leq p \leq 1.  To make use of
17131     this function, write first 'load("distrib")'.
17132
17133 -- Function: quantile_bernoulli (<q>,<p>)
17134     Returns the <q>-quantile of a Bernoulli(p) random variable, with 0
17135     \leq p \leq 1; in other words, this is the inverse of
17136     'cdf_bernoulli'.  Argument <q> must be an element of [0,1].  To
17137     make use of this function, write first 'load("distrib")'.
17138
17139 -- Function: mean_bernoulli (<p>)
17140     Returns the mean of a Bernoulli(p) random variable, with 0 \leq p
17141     \leq 1.
17142
17143     The Bernoulli(p) random variable is equivalent to the
17144     Binomial(1,p).
17145
17146          (%i1) load ("distrib")$
17147          (%i2) mean_bernoulli(p);
17148          (%o2)                           p
17149
17150 -- Function: var_bernoulli (<p>)
17151     Returns the variance of a Bernoulli(p) random variable, with 0 \leq
17152     p \leq 1.
17153
17154     The Bernoulli(p) random variable is equivalent to the
17155     Binomial(1,p).
17156
17157          (%i1) load ("distrib")$
17158          (%i2) var_bernoulli(p);
17159          (%o2)                       (1 - p) p
17160
17161 -- Function: std_bernoulli (<p>)
17162     Returns the standard deviation of a Bernoulli(p) random variable,
17163     with 0 \leq p \leq 1.
17164
17165     The Bernoulli(p) random variable is equivalent to the
17166     Binomial(1,p).
17167
17168          (%i1) load ("distrib")$
17169          (%i2) std_bernoulli(p);
17170          (%o2)                           sqrt((1 - p) p)
17171
17172 -- Function: skewness_bernoulli (<p>)
17173     Returns the skewness coefficient of a Bernoulli(p) random variable,
17174     with 0 \leq p \leq 1.
17175
17176     The Bernoulli(p) random variable is equivalent to the
17177     Binomial(1,p).
17178
17179          (%i1) load ("distrib")$
17180          (%i2) skewness_bernoulli(p);
17181                                              1 - 2 p
17182          (%o2)                           ---------------
17183                                          sqrt((1 - p) p)
17184
17185 -- Function: kurtosis_bernoulli (<p>)
17186     Returns the kurtosis coefficient of a Bernoulli(p) random variable,
17187     with 0 \leq p \leq 1.
17188
17189     The Bernoulli(p) random variable is equivalent to the
17190     Binomial(1,p).
17191
17192          (%i1) load ("distrib")$
17193          (%i2) kurtosis_bernoulli(p);
17194                                   1 - 6 (1 - p) p
17195          (%o2)                    ---------------
17196                                      (1 - p) p
17197
17198 -- Function: random_bernoulli (<p>)
17199          random_bernoulli (<p>,<n>)
17200
17201     Returns a Bernoulli(p) random variate, with 0 \leq p \leq 1.
17202     Calling 'random_bernoulli' with a second argument <n>, a random
17203     sample of size <n> will be simulated.
17204
17205     This is a direct application of the 'random' built-in Maxima
17206     function.
17207
17208     See also 'random'.  To make use of this function, write first
17209     'load("distrib")'.
17210
17211 -- Function: pdf_geometric (<x>,<p>)
17212     Returns the value at <x> of the probability function of a
17213     Geometric(p) random variable, with 0 < p <= 1.
17214
17215     The probability function is defined as p (1 - p)^x.  This is
17216     interpreted as the probability of x failures before the first
17217     success.
17218
17219     'load("distrib")' loads this function.
17220
17221 -- Function: cdf_geometric (<x>,<p>)
17222     Returns the value at <x> of the distribution function of a
17223     Geometric(p) random variable, with 0 < p <= 1.
17224
17225     The probability from which the distribution function is derived is
17226     defined as p (1 - p)^x.  This is interpreted as the probability of
17227     x failures before the first success.
17228
17229     'load("distrib")' loads this function.
17230
17231 -- Function: quantile_geometric (<q>,<p>)
17232     Returns the <q>-quantile of a Geometric(p) random variable, with 0
17233     < p <= 1; in other words, this is the inverse of 'cdf_geometric'.
17234     Argument <q> must be an element of [0,1].
17235
17236     The probability from which the quantile is derived is defined as p
17237     (1 - p)^x.  This is interpreted as the probability of x failures
17238     before the first success.
17239
17240     'load("distrib")' loads this function.
17241
17242 -- Function: mean_geometric (<p>)
17243     Returns the mean of a Geometric(p) random variable, with 0 < p <=
17244     1.
17245
17246     The probability from which the mean is derived is defined as p (1 -
17247     p)^x.  This is interpreted as the probability of x failures before
17248     the first success.
17249
17250     'load("distrib")' loads this function.
17251
17252 -- Function: var_geometric (<p>)
17253     Returns the variance of a Geometric(p) random variable, with 0 < p
17254     <= 1.
17255
17256     The probability from which the variance is derived is defined as p
17257     (1 - p)^x.  This is interpreted as the probability of x failures
17258     before the first success.
17259
17260     'load("distrib")' loads this function.
17261
17262 -- Function: std_geometric (<p>)
17263     Returns the standard deviation of a Geometric(p) random variable,
17264     with 0 < p <= 1.
17265
17266     The probability from which the standard deviation is derived is
17267     defined as p (1 - p)^x.  This is interpreted as the probability of
17268     x failures before the first success.
17269
17270     'load("distrib")' loads this function.
17271
17272 -- Function: skewness_geometric (<p>)
17273     Returns the skewness coefficient of a Geometric(p) random variable,
17274     with 0 < p <= 1.
17275
17276     The probability from which the skewness is derived is defined as p
17277     (1 - p)^x.  This is interpreted as the probability of x failures
17278     before the first success.
17279
17280     'load("distrib")' loads this function.
17281
17282 -- Function: kurtosis_geometric (<p>)
17283     Returns the kurtosis coefficient of a geometric random variable
17284     Geometric(p), with 0 < p <= 1.
17285
17286     The probability from which the kurtosis is derived is defined as p
17287     (1 - p)^x.  This is interpreted as the probability of x failures
17288     before the first success.
17289
17290     'load("distrib")' loads this function.
17291
17292 -- Function: random_geometric (<p>)
17293          random_geometric (<p>,<n>)
17294
17295     'random_geometric(<p>)' returns one random sample from a
17296     Geometric(p) distribution, with 0 < p <= 1.
17297
17298     'random_geometric(<p>, <n>)' returns a list of <n> random samples.
17299
17300     The algorithm is based on simulation of Bernoulli trials.
17301
17302     The probability from which the random sample is derived is defined
17303     as p (1 - p)^x.  This is interpreted as the probability of x
17304     failures before the first success.
17305
17306     'load("distrib")' loads this function.
17307
17308 -- Function: pdf_discrete_uniform (<x>,<n>)
17309     Returns the value at <x> of the probability function of a Discrete
17310     Uniform(n) random variable, with n a strictly positive integer.  To
17311     make use of this function, write first 'load("distrib")'.
17312
17313 -- Function: cdf_discrete_uniform (<x>,<n>)
17314     Returns the value at <x> of the distribution function of a Discrete
17315     Uniform(n) random variable, with n a strictly positive integer.  To
17316     make use of this function, write first 'load("distrib")'.
17317
17318 -- Function: quantile_discrete_uniform (<q>,<n>)
17319     Returns the <q>-quantile of a Discrete Uniform(n) random variable,
17320     with n a strictly positive integer; in other words, this is the
17321     inverse of 'cdf_discrete_uniform'.  Argument <q> must be an element
17322     of [0,1].  To make use of this function, write first
17323     'load("distrib")'.
17324
17325 -- Function: mean_discrete_uniform (<n>)
17326     Returns the mean of a Discrete Uniform(n) random variable, with n a
17327     strictly positive integer.  To make use of this function, write
17328     first 'load("distrib")'.
17329
17330 -- Function: var_discrete_uniform (<n>)
17331     Returns the variance of a Discrete Uniform(n) random variable, with
17332     n a strictly positive integer.  To make use of this function, write
17333     first 'load("distrib")'.
17334
17335 -- Function: std_discrete_uniform (<n>)
17336     Returns the standard deviation of a Discrete Uniform(n) random
17337     variable, with n a strictly positive integer.  To make use of this
17338     function, write first 'load("distrib")'.
17339
17340 -- Function: skewness_discrete_uniform (<n>)
17341     Returns the skewness coefficient of a Discrete Uniform(n) random
17342     variable, with n a strictly positive integer.  To make use of this
17343     function, write first 'load("distrib")'.
17344
17345 -- Function: kurtosis_discrete_uniform (<n>)
17346     Returns the kurtosis coefficient of a Discrete Uniform(n) random
17347     variable, with n a strictly positive integer.  To make use of this
17348     function, write first 'load("distrib")'.
17349
17350 -- Function: random_discrete_uniform (<n>)
17351          random_discrete_uniform (<n>,<m>)
17352
17353     Returns a Discrete Uniform(n) random variate, with n a strictly
17354     positive integer.  Calling 'random_discrete_uniform' with a second
17355     argument <m>, a random sample of size <m> will be simulated.
17356
17357     This is a direct application of the 'random' built-in Maxima
17358     function.
17359
17360     See also 'random'.  To make use of this function, write first
17361     'load("distrib")'.
17362
17363 -- Function: pdf_hypergeometric (<x>,<n1>,<n2>,<n>)
17364     Returns the value at <x> of the probability function of a
17365     Hypergeometric(n1,n2,n) random variable, with <n1>, <n2> and <n>
17366     non negative integers and n<=n1+n2.  Being <n1> the number of
17367     objects of class A, <n2> the number of objects of class B, and <n>
17368     the size of the sample without replacement, this function returns
17369     the probability of event "exactly <x> objects are of class A".
17370
17371     To make use of this function, write first 'load("distrib")'.
17372
17373 -- Function: cdf_hypergeometric (<x>,<n1>,<n2>,<n>)
17374     Returns the value at <x> of the distribution function of a
17375     Hypergeometric(n1,n2,n) random variable, with <n1>, <n2> and <n>
17376     non negative integers and n<=n1+n2.  See 'pdf_hypergeometric' for a
17377     more complete description.
17378
17379     To make use of this function, write first 'load("distrib")'.
17380
17381 -- Function: quantile_hypergeometric (<q>,<n1>,<n2>,<n>)
17382     Returns the <q>-quantile of a Hypergeometric(n1,n2,n) random
17383     variable, with <n1>, <n2> and <n> non negative integers and
17384     n<=n1+n2; in other words, this is the inverse of
17385     'cdf_hypergeometric'.  Argument <q> must be an element of [0,1].
17386     To make use of this function, write first 'load("distrib")'.
17387
17388 -- Function: mean_hypergeometric (<n1>,<n2>,<n>)
17389     Returns the mean of a discrete uniform random variable
17390     Hyp(n1,n2,n), with <n1>, <n2> and <n> non negative integers and
17391     n<=n1+n2.  To make use of this function, write first
17392     'load("distrib")'.
17393
17394 -- Function: var_hypergeometric (<n1>,<n2>,<n>)
17395     Returns the variance of a hypergeometric random variable
17396     Hyp(n1,n2,n), with <n1>, <n2> and <n> non negative integers and
17397     n<=n1+n2.  To make use of this function, write first
17398     'load("distrib")'.
17399
17400 -- Function: std_hypergeometric (<n1>,<n2>,<n>)
17401     Returns the standard deviation of a Hypergeometric(n1,n2,n) random
17402     variable, with <n1>, <n2> and <n> non negative integers and
17403     n<=n1+n2.  To make use of this function, write first
17404     'load("distrib")'.
17405
17406 -- Function: skewness_hypergeometric (<n1>,<n2>,<n>)
17407     Returns the skewness coefficient of a Hypergeometric(n1,n2,n)
17408     random variable, with <n1>, <n2> and <n> non negative integers and
17409     n<=n1+n2.  To make use of this function, write first
17410     'load("distrib")'.
17411
17412 -- Function: kurtosis_hypergeometric (<n1>,<n2>,<n>)
17413     Returns the kurtosis coefficient of a Hypergeometric(n1,n2,n)
17414     random variable, with <n1>, <n2> and <n> non negative integers and
17415     n<=n1+n2.  To make use of this function, write first
17416     'load("distrib")'.
17417
17418 -- Function: random_hypergeometric (<n1>,<n2>,<n>)
17419          random_hypergeometric (<n1>,<n2>,<n>,<m>)
17420
17421     Returns a Hypergeometric(n1,n2,n) random variate, with <n1>, <n2>
17422     and <n> non negative integers and n<=n1+n2.  Calling
17423     'random_hypergeometric' with a fourth argument <m>, a random sample
17424     of size <m> will be simulated.
17425
17426     Algorithm described in Kachitvichyanukul, V., Schmeiser, B.W.
17427     (1985) <Computer generation of hypergeometric random variates.>
17428     Journal of Statistical Computation and Simulation 22, 127-145.
17429
17430     To make use of this function, write first 'load("distrib")'.
17431
17432 -- Function: pdf_negative_binomial (<x>,<n>,<p>)
17433     Returns the value at <x> of the probability function of a Negative
17434     Binomial(n,p) random variable, with 0 < p \leq 1 and n a positive
17435     number.  To make use of this function, write first
17436     'load("distrib")'.
17437
17438 -- Function: cdf_negative_binomial (<x>,<n>,<p>)
17439     Returns the value at <x> of the distribution function of a Negative
17440     Binomial(n,p) random variable, with 0 < p \leq 1 and n a positive
17441     number.
17442
17443          (%i1) load ("distrib")$
17444          (%i2) cdf_negative_binomial(3,4,1/8);
17445                                      3271
17446          (%o2)                      ------
17447                                     524288
17448
17449 -- Function: quantile_negative_binomial (<q>,<n>,<p>)
17450     Returns the <q>-quantile of a Negative Binomial(n,p) random
17451     variable, with 0 < p \leq 1 and n a positive number; in other
17452     words, this is the inverse of 'cdf_negative_binomial'.  Argument
17453     <q> must be an element of [0,1].  To make use of this function,
17454     write first 'load("distrib")'.
17455
17456 -- Function: mean_negative_binomial (<n>,<p>)
17457     Returns the mean of a Negative Binomial(n,p) random variable, with
17458     0 < p \leq 1 and n a positive number.  To make use of this
17459     function, write first 'load("distrib")'.
17460
17461 -- Function: var_negative_binomial (<n>,<p>)
17462     Returns the variance of a Negative Binomial(n,p) random variable,
17463     with 0 < p \leq 1 and n a positive number.  To make use of this
17464     function, write first 'load("distrib")'.
17465
17466 -- Function: std_negative_binomial (<n>,<p>)
17467     Returns the standard deviation of a Negative Binomial(n,p) random
17468     variable, with 0 < p \leq 1 and n a positive number.  To make use
17469     of this function, write first 'load("distrib")'.
17470
17471 -- Function: skewness_negative_binomial (<n>,<p>)
17472     Returns the skewness coefficient of a Negative Binomial(n,p) random
17473     variable, with 0 < p \leq 1 and n a positive number.  To make use
17474     of this function, write first 'load("distrib")'.
17475
17476 -- Function: kurtosis_negative_binomial (<n>,<p>)
17477     Returns the kurtosis coefficient of a Negative Binomial(n,p) random
17478     variable, with 0 < p \leq 1 and n a positive number.  To make use
17479     of this function, write first 'load("distrib")'.
17480
17481 -- Function: random_negative_binomial (<n>,<p>)
17482          random_negative_binomial (<n>,<p>,<m>)
17483
17484     Returns a Negative Binomial(n,p) random variate, with 0 < p \leq 1
17485     and n a positive number.  Calling 'random_negative_binomial' with a
17486     third argument <m>, a random sample of size <m> will be simulated.
17487
17488     Algorithm described in Devroye, L. (1986) <Non-Uniform Random
17489     Variate Generation>.  Springer Verlag, p.  480.
17490
17491     To make use of this function, write first 'load("distrib")'.
17492
17493
17494File: maxima.info,  Node: draw-pkg,  Next: drawdf-pkg,  Prev: distrib-pkg,  Up: Top
17495
1749653 draw
17497*******
17498
17499* Menu:
17500
17501* Introduction to draw::
17502* Functions and Variables for draw::
17503* Functions and Variables for pictures::
17504* Functions and Variables for worldmap::
17505
17506
17507File: maxima.info,  Node: Introduction to draw,  Next: Functions and Variables for draw,  Prev: draw-pkg,  Up: draw-pkg
17508
1750953.1 Introduction to draw
17510=========================
17511
17512'draw' is a Maxima-Gnuplot and a Maxima-vtk interface.
17513
17514   There are three main functions to be used at Maxima level:
17515   * 'draw2d', draws a single 2D scene.
17516   * 'draw3d', draws a single 3D scene.
17517   * 'draw', can be filled with multiple 'gr2d' and 'gr3d' commands that
17518     each creates a draw scene all sharing the same window.
17519   Each scene can contain any number of objects and 'key=value' pairs
17520with options for the scene or the following objects.
17521
17522   A selection of useful objects a scene can be made up from are:
17523   * 'explicit' plots a function.
17524   * 'implicit' plots all points an equation is true at.
17525   * 'points' plots points that are connected by lines if the option
17526     'points_joined' was set to 'true' in a previous line of the current
17527     scene.
17528   * 'parametric' allows to specify separate expressions that calculate
17529     the x, y (and in 3d plots also for the z) variable.
17530
17531   A short description of all draw commands and options including
17532example plots (in the html and pdf version of this manual) can be found
17533in the section *Note Functions and Variables for draw::.  A online
17534version of the html manual can be found at
17535<maxima.sourceforge.net/docs/manual/maxima_singlepage.html#draw>.  More
17536elaborated examples of this package can be found at the following
17537locations:
17538
17539   <http://tecnostats.net/Maxima/gnuplot>
17540<http://tecnostats.net/Maxima/vtk>
17541
17542   Example:
17543
17544     (%i1) draw2d(
17545               title="Two simple plots",
17546               xlabel="x",ylabel="y",grid=true,
17547
17548               color=red,key="A sinus",
17549               explicit(sin(x),x,1,10),
17550               color=blue,line_type=dots,key="A cosinus",
17551               explicit(cos(x),x,1,10)
17552     )$
17553   (Figure draw_intro)
17554
17555   You need Gnuplot 4.2 or newer to run draw; If you are using wxMaxima
17556as a front end 'wxdraw', 'wxdraw2d' and 'wxdraw3d' are drop-in
17557replacements for draw that do the same as 'draw', 'draw2d' and 'draw3d'
17558but embed the resulting plot in the worksheet.
17559
17560
17561File: maxima.info,  Node: Functions and Variables for draw,  Next: Functions and Variables for pictures,  Prev: Introduction to draw,  Up: draw-pkg
17562
1756353.2 Functions and Variables for draw
17564=====================================
17565
1756653.2.1 Scenes
17567-------------
17568
17569 -- Scene constructor: gr2d (<argument_1>, ...)
17570
17571     Function 'gr2d' builds an object describing a 2D scene.  Arguments
17572     are graphic options, graphic objects, or lists containing both
17573     graphic options and objects.  This scene is interpreted
17574     sequentially: graphic options affect those graphic objects placed
17575     on its right.  Some graphic options affect the global appearance of
17576     the scene.
17577
17578     This is the list of graphic objects available for scenes in two
17579     dimensions: 'bars', 'ellipse', 'explicit', 'image', 'implicit',
17580     'label', 'parametric', 'points', 'polar', 'polygon',
17581     'quadrilateral', 'rectangle', 'triangle', 'vector' and 'geomap'
17582     (this one defined in package 'worldmap').
17583
17584     See also 'draw' and 'draw2d'.
17585
17586          (%i1) draw(
17587              gr2d(
17588                  key="sin (x)",grid=[2,2],
17589                  explicit(
17590                      sin(x),
17591                      x,0,2*%pi
17592                  )
17593              ),
17594              gr2d(
17595                  key="cos (x)",grid=[2,2],
17596                  explicit(
17597                      cos(x),
17598                      x,0,2*%pi
17599                  )
17600              )
17601           );
17602          (%o1)           [gr2d(explicit), gr2d(explicit)]
17603     (Figure draw_scene)
17604
17605 -- Scene constructor: gr3d (<argument_1>, ...)
17606
17607     Function 'gr3d' builds an object describing a 3d scene.  Arguments
17608     are graphic options, graphic objects, or lists containing both
17609     graphic options and objects.  This scene is interpreted
17610     sequentially: graphic options affect those graphic objects placed
17611     on its right.  Some graphic options affect the global appearance of
17612     the scene.
17613
17614     This is the list of graphic objects available for scenes in three
17615     dimensions:
17616     'cylindrical', 'elevation_grid', 'explicit', 'implicit', 'label',
17617     'mesh', 'parametric',
17618     'parametric_surface', 'points', 'quadrilateral', 'spherical',
17619     'triangle', 'tube',
17620     'vector', and 'geomap' (this one defined in package 'worldmap').
17621
17622     See also 'draw' and 'draw3d'.
17623
1762453.2.2 Functions
17625----------------
17626
17627 -- Function: draw (<arg_1>, ...)
17628
17629     Plots a series of scenes; its arguments are 'gr2d' and/or 'gr3d'
17630     objects, together with some options, or lists of scenes and
17631     options.  By default, the scenes are put together in one column.
17632
17633     Besides scenes the function 'draw' accepts the following global
17634     options: 'terminal', 'columns', 'dimensions', 'file_name' and
17635     'delay'.
17636
17637     Functions 'draw2d' and 'draw3d' short cuts that can be used when
17638     only one scene is required, in two or three dimensions,
17639     respectively.
17640
17641     See also 'gr2d' and 'gr3d'.
17642
17643     Examples:
17644
17645          (%i1) scene1: gr2d(title="Ellipse",
17646                             nticks=300,
17647                             parametric(2*cos(t),5*sin(t),t,0,2*%pi))$
17648          (%i2) scene2: gr2d(title="Triangle",
17649                             polygon([4,5,7],[6,4,2]))$
17650          (%i3) draw(scene1, scene2, columns = 2)$
17651     (Figure draw_intro2)
17652
17653          (%i1) scene1: gr2d(title="A sinus",
17654                  grid=true,
17655                  explicit(sin(t),t,0,2*%pi))$
17656          (%i2) scene2: gr2d(title="A cosinus",
17657                  grid=true,
17658                  explicit(cos(t),t,0,2*%pi))$
17659          (%i3) draw(scene1, scene2)$
17660     (Figure draw_intro3)
17661
17662     The following two draw sentences are equivalent:
17663          (%i1) draw(gr3d(explicit(x^2+y^2,x,-1,1,y,-1,1)));
17664          (%o1)                          [gr3d(explicit)]
17665          (%i2) draw3d(explicit(x^2+y^2,x,-1,1,y,-1,1));
17666          (%o2)                          [gr3d(explicit)]
17667
17668     Creating an animated gif file:
17669          (%i1) draw(
17670                  delay     = 100,
17671                  file_name = "zzz",
17672                  terminal  = 'animated_gif,
17673                  gr2d(explicit(x^2,x,-1,1)),
17674                  gr2d(explicit(x^3,x,-1,1)),
17675                  gr2d(explicit(x^4,x,-1,1)));
17676          End of animation sequence
17677          (%o1)          [gr2d(explicit), gr2d(explicit), gr2d(explicit)]
17678     (Figure draw_equiv) See also 'gr2d', 'gr3d', 'draw2d' and 'draw3d'.
17679
17680 -- Function: draw2d (<argument_1>, ...)
17681
17682     This function is a shortcut for 'draw(gr2d(<options>, ...,
17683     <graphic_object>, ...))'.
17684
17685     It can be used to plot a unique scene in 2d, as can be seen in most
17686     examples below.
17687
17688     See also 'draw' and 'gr2d'.
17689
17690 -- Function: draw3d (<argument_1>, ...)
17691
17692     This function is a shortcut for 'draw(gr3d(<options>, ...,
17693     <graphic_object>, ...))'.
17694
17695     It can be used to plot a unique scene in 3d, as can be seen in many
17696     examples below.
17697
17698     See also 'draw' and 'gr3d'.
17699
17700 -- Function: draw_file (<graphic option>, ..., <graphic object>, ...)
17701
17702     Saves the current plot into a file.  Accepted graphics options are:
17703     'terminal', 'dimensions' and 'file_name'.
17704
17705     Example:
17706
17707          (%i1) /* screen plot */
17708                draw(gr3d(explicit(x^2+y^2,x,-1,1,y,-1,1)))$
17709          (%i2) /* same plot in eps format */
17710                draw_file(terminal  = eps,
17711                          dimensions = [5,5]) $
17712
17713 -- Function: multiplot_mode (<term>)
17714
17715     This function enables Maxima to work in one-window multiplot mode
17716     with terminal <term>; accepted arguments for this function are
17717     'screen', 'wxt', 'aquaterm', 'windows' and 'none'.
17718
17719     When multiplot mode is enabled, each call to 'draw' sends a new
17720     plot to the same window, without erasing the previous ones.  To
17721     disable the multiplot mode, write 'multiplot_mode(none)'.
17722
17723     When multiplot mode is enabled, global option 'terminal' is blocked
17724     and you have to disable this working mode before changing to
17725     another terminal.
17726
17727     On Windows this feature requires Gnuplot 5.0 or newer.  Note, that
17728     just plotting multiple expressions into the same plot doesn't
17729     require multiplot: It can be done by just issuing multiple
17730     'explicit' or similar commands in a row.
17731
17732     Example:
17733
17734          (%i1) set_draw_defaults(
17735                   xrange = [-1,1],
17736                   yrange = [-1,1],
17737                   grid   = true,
17738                   title  = "Step by step plot" )$
17739          (%i2) multiplot_mode(screen)$
17740          (%i3) draw2d(color=blue,  explicit(x^2,x,-1,1))$
17741          (%i4) draw2d(color=red,   explicit(x^3,x,-1,1))$
17742          (%i5) draw2d(color=brown, explicit(x^4,x,-1,1))$
17743          (%i6) multiplot_mode(none)$
17744     (Figure draw_multiplot)
17745
17746 -- Function: set_draw_defaults (<graphic option>, ..., <graphic
17747          object>, ...)
17748
17749     Sets user graphics options.  This function is useful for plotting a
17750     sequence of graphics with common graphics options.  Calling this
17751     function without arguments removes user defaults.
17752
17753     Example:
17754
17755          (%i1) set_draw_defaults(
17756                   xrange = [-10,10],
17757                   yrange = [-2, 2],
17758                   color  = blue,
17759                   grid   = true)$
17760          (%i2) /* plot with user defaults */
17761                draw2d(explicit(((1+x)**2/(1+x*x))-1,x,-10,10))$
17762          (%i3) set_draw_defaults()$
17763          (%i4) /* plot with standard defaults */
17764                draw2d(explicit(((1+x)**2/(1+x*x))-1,x,-10,10))$
17765
1776653.2.3 Graphics options
17767-----------------------
17768
17769 -- Graphic option: adapt_depth
17770     Default value: 10
17771
17772     'adapt_depth' is the maximum number of splittings used by the
17773     adaptive plotting routine.
17774
17775     This option is relevant only for 2d 'explicit' functions.
17776
17777     See also 'nticks'
17778
17779 -- Graphic option: allocation
17780     Default value: 'false'
17781
17782     With option 'allocation' it is possible to place a scene in the
17783     output window at will; this is of interest in multiplots.  When
17784     'false', the scene is placed automatically, depending on the value
17785     assigned to option 'columns'.  In any other case, 'allocation' must
17786     be set to a list of two pairs of numbers; the first corresponds to
17787     the position of the lower left corner of the scene, and the second
17788     pair gives the width and height of the plot.  All quantities must
17789     be given in relative coordinates, between 0 and 1.
17790
17791     Examples:
17792
17793     In site graphics.
17794
17795          (%i1) draw(
17796                  gr2d(
17797                    explicit(x^2,x,-1,1)),
17798                  gr2d(
17799                    allocation = [[1/4, 1/4],[1/2, 1/2]],
17800                    explicit(x^3,x,-1,1),
17801                    grid = true) ) $
17802     (Figure draw_allocation)
17803
17804     Multiplot with selected dimensions.
17805
17806          (%i1) draw(
17807                  terminal = wxt,
17808                  gr2d(
17809                    grid=[5,5],
17810                    allocation = [[0, 0],[1, 1/4]],
17811                    explicit(x^2,x,-1,1)),
17812                  gr3d(
17813                    allocation = [[0, 1/4],[1, 3/4]],
17814                    explicit(x^2+y^2,x,-1,1,y,-1,1) ))$
17815     (Figure draw_allocation2)
17816
17817     See also option 'columns'.
17818
17819 -- Graphic option: axis_3d
17820     Default value: 'true'
17821
17822     If 'axis_3d' is 'true', the <x>, <y> and <z> axis are shown in 3d
17823     scenes.
17824
17825     Since this is a global graphics option, its position in the scene
17826     description does not matter.
17827
17828     Example:
17829
17830          (%i1) draw3d(axis_3d = false,
17831                       explicit(sin(x^2+y^2),x,-2,2,y,-2,2) )$
17832     (Figure draw_axis3d)
17833
17834     See also 'axis_bottom', 'axis_left', 'axis_top', and 'axis_right'
17835     for axis in 2d.
17836
17837 -- Graphic option: axis_bottom
17838     Default value: 'true'
17839
17840     If 'axis_bottom' is 'true', the bottom axis is shown in 2d scenes.
17841
17842     Since this is a global graphics option, its position in the scene
17843     description does not matter.
17844
17845     Example:
17846
17847          (%i1) draw2d(axis_bottom = false,
17848                       explicit(x^3,x,-1,1))$
17849     (Figure draw_axis_bottom)
17850
17851     See also 'axis_left', 'axis_top', 'axis_right' and 'axis_3d'.
17852
17853 -- Graphic option: axis_left
17854     Default value: 'true'
17855
17856     If 'axis_left' is 'true', the left axis is shown in 2d scenes.
17857
17858     Since this is a global graphics option, its position in the scene
17859     description does not matter.
17860
17861     Example:
17862
17863          (%i1) draw2d(axis_left = false,
17864                       explicit(x^3,x,-1,1))$
17865
17866     See also 'axis_bottom', 'axis_top', 'axis_right' and 'axis_3d'.
17867
17868 -- Graphic option: axis_right
17869     Default value: 'true'
17870
17871     If 'axis_right' is 'true', the right axis is shown in 2d scenes.
17872
17873     Since this is a global graphics option, its position in the scene
17874     description does not matter.
17875
17876     Example:
17877
17878          (%i1) draw2d(axis_right = false,
17879                       explicit(x^3,x,-1,1))$
17880
17881     See also 'axis_bottom', 'axis_left', 'axis_top' and 'axis_3d'.
17882
17883 -- Graphic option: axis_top
17884     Default value: 'true'
17885
17886     If 'axis_top' is 'true', the top axis is shown in 2d scenes.
17887
17888     Since this is a global graphics option, its position in the scene
17889     description does not matter.
17890
17891     Example:
17892
17893          (%i1) draw2d(axis_top = false,
17894                       explicit(x^3,x,-1,1))$
17895
17896     See also 'axis_bottom', 'axis_left', 'axis_right', and 'axis_3d'.
17897
17898 -- Graphic option: background_color
17899     Default value: 'white'
17900
17901     Sets the background color for terminals.  Default background color
17902     is white.
17903
17904     Since this is a global graphics option, its position in the scene
17905     description does not matter.
17906
17907     This option das not work with terminals 'epslatex' and
17908     'epslatex_standalone'.
17909
17910     See also 'color'
17911
17912 -- Graphic option: border
17913     Default value: 'true'
17914
17915     If 'border' is 'true', borders of polygons are painted according to
17916     'line_type' and 'line_width'.
17917
17918     This option affects the following graphic objects:
17919
17920        * 'gr2d': 'polygon', 'rectangle' and 'ellipse'.
17921
17922     Example:
17923
17924          (%i1) draw2d(color       = brown,
17925                       line_width  = 8,
17926                       polygon([[3,2],[7,2],[5,5]]),
17927                       border      = false,
17928                       fill_color  = blue,
17929                       polygon([[5,2],[9,2],[7,5]]) )$
17930     (Figure draw_border)
17931
17932 -- Graphic option: capping
17933     Default value: '[false, false]'
17934
17935     A list with two possible elements, 'true' and 'false', indicating
17936     whether the extremes of a graphic object 'tube' remain closed or
17937     open.  By default, both extremes are left open.
17938
17939     Setting 'capping = false' is equivalent to 'capping = [false,
17940     false]', and 'capping = true' is equivalent to 'capping = [true,
17941     true]'.
17942
17943     Example:
17944
17945          (%i1) draw3d(
17946                  capping = [false, true],
17947                  tube(0, 0, a, 1,
17948                       a, 0, 8) )$
17949     (Figure draw_tube_extremes)
17950
17951 -- Graphic option: cbrange
17952     Default value: 'auto'
17953
17954     If 'cbrange' is 'auto', the range for the values which are colored
17955     when 'enhanced3d' is not 'false' is computed automatically.  Values
17956     outside of the color range use color of the nearest extreme.
17957
17958     When 'enhanced3d' or 'colorbox' is 'false', option 'cbrange' has no
17959     effect.
17960
17961     If the user wants a specific interval for the colored values, it
17962     must be given as a Maxima list, as in 'cbrange=[-2, 3]'.
17963
17964     Since this is a global graphics option, its position in the scene
17965     description does not matter.
17966
17967     Example:
17968
17969          (%i1) draw3d (
17970                  enhanced3d     = true,
17971                  color          = green,
17972                  cbrange = [-3,10],
17973                  explicit(x^2+y^2, x,-2,2,y,-2,2)) $
17974     (Figure draw_cbrange)
17975
17976     See also 'enhanced3d', 'colorbox' and 'cbtics'.
17977
17978 -- Graphic option: cbtics
17979     Default value: 'auto'
17980
17981     This graphic option controls the way tic marks are drawn on the
17982     colorbox when option 'enhanced3d' is not 'false'.
17983
17984     When 'enhanced3d' or 'colorbox' is 'false', option 'cbtics' has no
17985     effect.
17986
17987     See 'xtics' for a complete description.
17988
17989     Example :
17990
17991          (%i1) draw3d (
17992                  enhanced3d = true,
17993                  color      = green,
17994                  cbtics  = {["High",10],["Medium",05],["Low",0]},
17995                  cbrange = [0, 10],
17996                  explicit(x^2+y^2, x,-2,2,y,-2,2)) $
17997     (Figure draw_cbtics)
17998
17999     See also 'enhanced3d', 'colorbox' and 'cbrange'.
18000
18001 -- Graphic option: color
18002     Default value: 'blue'
18003
18004     'color' specifies the color for plotting lines, points, borders of
18005     polygons and labels.
18006
18007     Colors can be given as names or in hexadecimal rgb code.  If a
18008     gnuplot version >= 5.0 is used and the terminal that is in use
18009     supports this rgba colors with transparency information are also
18010     supported.
18011
18012     Available color names are:
18013     white            black            gray0            grey0
18014     gray10           grey10           gray20           grey20
18015     gray30           grey30           gray40           grey40
18016     gray50           grey50           gray60           grey60
18017     gray70           grey70           gray80           grey80
18018     gray90           grey90           gray100          grey100
18019     gray             grey             light_gray       light_grey
18020     dark_gray        dark_grey        red              light_red
18021     dark_red         yellow           light_yellow     dark_yellow
18022     green            light_green      dark_green       spring_green
18023     forest_green     sea_green        blue             light_blue
18024     dark_blue        midnight_blue    navy             medium_blue
18025     royalblue        skyblue          cyan             light_cyan
18026     dark_cyan        magenta          light_magenta    dark_magenta
18027     turquoise        light_turquoise  dark_turquoise   pink
18028     light_pink       dark_pink        coral            light_coral
18029     orange_red       salmon           light_salmon     dark_salmon
18030     aquamarine       khaki            dark_khaki       goldenrod
18031     light_goldenrod  dark_goldenrod   gold             beige
18032     brown            orange           dark_orange      violet
18033     dark_violet      plum             purple
18034
18035     Cromatic componentes in hexadecimal code are introduced in the form
18036     '"#rrggbb"'.
18037
18038     Example:
18039
18040          (%i1) draw2d(explicit(x^2,x,-1,1), /* default is black */
18041                       color = red,
18042                       explicit(0.5 + x^2,x,-1,1),
18043                       color = blue,
18044                       explicit(1 + x^2,x,-1,1),
18045                       color = light_blue,
18046                       explicit(1.5 + x^2,x,-1,1),
18047                       color = "#23ab0f",
18048                       label(["This is a label",0,1.2])  )$
18049     (Figure draw_color)
18050          (%i1) draw2d(
18051                       line_width=50,
18052                       color="#FF0000",
18053                       explicit(sin(x),x,0,10),
18054                       color="#0000FF80",
18055                       explicit(cos(x),x,0,10)
18056                );
18057     (Figure draw_color2)
18058
18059          (%i1) H(p,p_0):=%i/(2*%pi*(p-p_0));
18060                draw2d(
18061                    proportional_axes=xy,
18062                    ip_grid=[150,150],
18063                    grid=true,
18064                    makelist(
18065                        [
18066                            color=printf(false,"#~2,'0x~2,'0x~2,'0x",i*10,0,0),
18067                            key_pos=top_left,
18068                            key = if mod(i,5)=0 then sconcat("H=",i,"A/M") else "",
18069                            implicit(
18070                                cabs(H(x+%i*y,-1-%i)+H(x+%i*y,1+%i)-H(x+%i*y,1-%i)-H(x+%i*y,-1+%i))=i/10,
18071                                x,-3,3,
18072                                y,-3,3
18073                            )
18074                        ],
18075                        i,1,25
18076                    )
18077                )$
18078     (Figure draw_color3)
18079
18080          (%i1) draw2d(
18081                  "figures/draw_color4",
18082                  makelist(
18083                      [
18084                          color=i,
18085                          key=sconcat("color =",i),
18086                          explicit(sin(i*x),x,0,1)
18087                      ],
18088                      i,0,17
18089                  )
18090              )$
18091     (Figure draw_color4)
18092
18093     See also 'fill_color'.
18094
18095 -- Graphic option: colorbox
18096     Default value: 'true'
18097
18098     If 'colorbox' is 'true', a color scale without label is drawn
18099     together with 'image' 2D objects, or coloured 3d objects.  If
18100     'colorbox' is 'false', no color scale is shown.  If 'colorbox' is a
18101     string, a color scale with label is drawn.
18102
18103     Since this is a global graphics option, its position in the scene
18104     description does not matter.
18105
18106     Example:
18107
18108     Color scale and images.
18109
18110          (%i1) im: apply('matrix,
18111                           makelist(makelist(random(200),i,1,30),i,1,30))$
18112          (%i2) draw(
18113                    gr2d(image(im,0,0,30,30)),
18114                    gr2d(colorbox = false, image(im,0,0,30,30))
18115                )$
18116     (Figure draw_colorbox) Color scale and 3D coloured object.
18117
18118          (%i1) draw3d(
18119                  colorbox   = "Magnitude",
18120                  enhanced3d = true,
18121                  explicit(x^2+y^2,x,-1,1,y,-1,1))$
18122     (Figure draw_colorbox2)
18123
18124     See also 'palette_draw'.
18125
18126 -- Graphic option: columns
18127     Default value: 1
18128
18129     'columns' is the number of columns in multiple plots.
18130
18131     Since this is a global graphics option, its position in the scene
18132     description does not matter.  It can be also used as an argument of
18133     function 'draw'.
18134
18135     Example:
18136
18137          (%i1) scene1: gr2d(title="Ellipse",
18138                             nticks=30,
18139                             parametric(2*cos(t),5*sin(t),t,0,2*%pi))$
18140          (%i2) scene2: gr2d(title="Triangle",
18141                             polygon([4,5,7],[6,4,2]))$
18142          (%i3) draw(scene1, scene2, columns = 2)$
18143     (Figure draw_columns)
18144
18145 -- Graphic option: contour
18146     Default value: 'none'
18147
18148     Option 'contour' enables the user to select where to plot contour
18149     lines.  Possible values are:
18150
18151        * 'none': no contour lines are plotted.
18152
18153        * 'base': contour lines are projected on the xy plane.
18154
18155        * 'surface': contour lines are plotted on the surface.
18156
18157        * 'both': two contour lines are plotted: on the xy plane and on
18158          the surface.
18159
18160        * 'map': contour lines are projected on the xy plane, and the
18161          view point is set just in the vertical.
18162
18163     Since this is a global graphics option, its position in the scene
18164     description does not matter.
18165
18166     Example:
18167
18168          (%i1) draw3d(explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
18169                       contour_levels = 15,
18170                       contour        = both,
18171                       surface_hide   = true) $
18172     (Figure draw_contour)
18173
18174          (%i1) draw3d(explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
18175                       contour_levels = 15,
18176                       contour        = map
18177                ) $
18178     (Figure draw_contour2)
18179
18180 -- Graphic option: contour_levels
18181     Default value: 5
18182
18183     This graphic option controls the way contours are drawn.
18184     'contour_levels' can be set to a positive integer number, a list of
18185     three numbers or an arbitrary set of numbers:
18186
18187        * When option 'contour_levels' is bounded to positive integer
18188          <n>, <n> contour lines will be drawn at equal intervals.  By
18189          default, five equally spaced contours are plotted.
18190
18191        * When option 'contour_levels' is bounded to a list of length
18192          three of the form '[lowest,s,highest]', contour lines are
18193          plotted from 'lowest' to 'highest' in steps of 's'.
18194
18195        * When option 'contour_levels' is bounded to a set of numbers of
18196          the form '{n1, n2, ...}', contour lines are plotted at values
18197          'n1', 'n2', ...
18198
18199     Since this is a global graphics option, its position in the scene
18200     description does not matter.
18201
18202     Examples:
18203
18204     Ten equally spaced contour lines.  The actual number of levels can
18205     be adjusted to give simple labels.
18206          (%i1) draw3d(color = green,
18207                       explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
18208                       contour_levels = 10,
18209                       contour        = both,
18210                       surface_hide   = true) $
18211
18212     From -8 to 8 in steps of 4.
18213          (%i1) draw3d(color = green,
18214                       explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
18215                       contour_levels = [-8,4,8],
18216                       contour        = both,
18217                       surface_hide   = true) $
18218
18219     Isolines at levels -7, -6, 0.8 and 5.
18220          (%i1) draw3d(color = green,
18221                       explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
18222                       contour_levels = {-7, -6, 0.8, 5},
18223                       contour        = both,
18224                       surface_hide   = true) $
18225
18226     See also 'contour'.
18227
18228 -- Graphic option: data_file_name
18229     Default value: '"data.gnuplot"'
18230
18231     This is the name of the file with the numeric data needed by
18232     Gnuplot to build the requested plot.
18233
18234     Since this is a global graphics option, its position in the scene
18235     description does not matter.  It can be also used as an argument of
18236     function 'draw'.
18237
18238     See example in 'gnuplot_file_name'.
18239
18240 -- Graphic option: delay
18241     Default value: 5
18242
18243     This is the delay in 1/100 seconds of frames in animated gif files.
18244
18245     Since this is a global graphics option, its position in the scene
18246     description does not matter.  It can be also used as an argument of
18247     function 'draw'.
18248
18249     Example:
18250
18251          (%i1) draw(
18252                  delay     = 100,
18253                  file_name = "zzz",
18254                  terminal  = 'animated_gif,
18255                  gr2d(explicit(x^2,x,-1,1)),
18256                  gr2d(explicit(x^3,x,-1,1)),
18257                  gr2d(explicit(x^4,x,-1,1)));
18258          End of animation sequence
18259          (%o2)          [gr2d(explicit), gr2d(explicit), gr2d(explicit)]
18260
18261     Option 'delay' is only active in animated gif's; it is ignored in
18262     any other case.
18263
18264     See also 'terminal', and 'dimensions'.
18265
18266 -- Graphic option: dimensions
18267     Default value: '[600,500]'
18268
18269     Dimensions of the output terminal.  Its value is a list formed by
18270     the width and the height.  The meaning of the two numbers depends
18271     on the terminal you are working with.
18272
18273     With terminals 'gif', 'animated_gif', 'png', 'jpg', 'svg',
18274     'screen', 'wxt', and 'aquaterm', the integers represent the number
18275     of points in each direction.  If they are not intergers, they are
18276     rounded.
18277
18278     With terminals 'eps', 'eps_color', 'pdf', and 'pdfcairo', both
18279     numbers represent hundredths of cm, which means that, by default,
18280     pictures in these formats are 6 cm in width and 5 cm in height.
18281
18282     Since this is a global graphics option, its position in the scene
18283     description does not matter.  It can be also used as an argument of
18284     function 'draw'.
18285
18286     Examples:
18287
18288     Option 'dimensions' applied to file output and to wxt canvas.
18289
18290          (%i1) draw2d(
18291                  dimensions = [300,300],
18292                  terminal   = 'png,
18293                  explicit(x^4,x,-1,1)) $
18294          (%i2) draw2d(
18295                  dimensions = [300,300],
18296                  terminal   = 'wxt,
18297                  explicit(x^4,x,-1,1)) $
18298
18299     Option 'dimensions' applied to eps output.  We want an eps file
18300     with A4 portrait dimensions.
18301
18302          (%i1) A4portrait: 100*[21, 29.7]$
18303          (%i2) draw3d(
18304                  dimensions = A4portrait,
18305                  terminal   = 'eps,
18306                  explicit(x^2-y^2,x,-2,2,y,-2,2)) $
18307
18308 -- Graphic option: draw_realpart
18309     Default value: 'true'
18310
18311     When 'true', functions to be drawn are considered as complex
18312     functions whose real part value should be plotted; when 'false',
18313     nothing will be plotted when the function does not give a real
18314     value.
18315
18316     This option affects objects 'explicit' and 'parametric' in 2D and
18317     3D, and 'parametric_surface'.
18318
18319     Example:
18320          (%i1) draw2d(
18321                  draw_realpart = false,
18322                  explicit(sqrt(x^2  - 4*x) - x, x, -1, 5),
18323                  color         = red,
18324                  draw_realpart = true,
18325                  parametric(x,sqrt(x^2  - 4*x) - x + 1, x, -1, 5) );
18326
18327 -- Graphic option: enhanced3d
18328     Default value: 'none'
18329
18330     If 'enhanced3d' is 'none', surfaces are not colored in 3D plots.
18331     In order to get a colored surface, a list must be assigned to
18332     option 'enhanced3d', where the first element is an expression and
18333     the rest are the names of the variables or parameters used in that
18334     expression.  A list such '[f(x,y,z), x, y, z]' means that point
18335     '[x,y,z]' of the surface is assigned number 'f(x,y,z)', which will
18336     be colored according to the actual 'palette'.  For those 3D graphic
18337     objects defined in terms of parameters, it is possible to define
18338     the color number in terms of the parameters, as in '[f(u), u]', as
18339     in objects 'parametric' and 'tube', or '[f(u,v), u, v]', as in
18340     object 'parametric_surface'.  While all 3D objects admit the model
18341     based on absolute coordinates, '[f(x,y,z), x, y, z]', only two of
18342     them, namely 'explicit' and 'elevation_grid', accept also models
18343     defined on the '[x,y]' coordinates, '[f(x,y), x, y]'.  3D graphic
18344     object 'implicit' accepts only the '[f(x,y,z), x, y, z]' model.
18345     Object 'points' accepts also the '[f(x,y,z), x, y, z]' model, but
18346     when points have a chronological nature, model '[f(k), k]' is also
18347     valid, being 'k' an ordering parameter.
18348
18349     When 'enhanced3d' is assigned something different to 'none',
18350     options 'color' and 'surface_hide' are ignored.
18351
18352     The names of the variables defined in the lists may be different to
18353     those used in the definitions of the graphic objects.
18354
18355     In order to maintain back compatibility, 'enhanced3d = false' is
18356     equivalent to 'enhanced3d = none', and 'enhanced3d = true' is
18357     equivalent to 'enhanced3d = [z, x, y, z]'.  If an expression is
18358     given to 'enhanced3d', its variables must be the same used in the
18359     surface definition.  This is not necessary when using lists.
18360
18361     See option 'palette' to learn how palettes are specified.
18362
18363     Examples:
18364
18365     'explicit' object with coloring defined by the '[f(x,y,z), x, y,
18366     z]' model.
18367
18368          (%i1) draw3d(
18369                   enhanced3d = [x-z/10,x,y,z],
18370                   palette    = gray,
18371                   explicit(20*exp(-x^2-y^2)-10,x,-3,3,y,-3,3))$
18372     (Figure draw_enhanced3d)
18373
18374     'explicit' object with coloring defined by the '[f(x,y), x, y]'
18375     model.  The names of the variables defined in the lists may be
18376     different to those used in the definitions of the graphic objects;
18377     in this case, 'r' corresponds to 'x', and 's' to 'y'.
18378
18379          (%i1) draw3d(
18380                   enhanced3d = [sin(r*s),r,s],
18381                   explicit(20*exp(-x^2-y^2)-10,x,-3,3,y,-3,3))$
18382     (Figure draw_enhanced3d2)
18383
18384     'parametric' object with coloring defined by the '[f(x,y,z), x, y,
18385     z]' model.
18386
18387          (%i1) draw3d(
18388                   nticks = 100,
18389                   line_width = 2,
18390                   enhanced3d = [if y>= 0 then 1 else 0, x, y, z],
18391                   parametric(sin(u)^2,cos(u),u,u,0,4*%pi)) $
18392     (Figure draw_enhanced3d3)
18393
18394     'parametric' object with coloring defined by the '[f(u), u]' model.
18395     In this case, '(u-1)^2' is a shortcut for '[(u-1)^2,u]'.
18396
18397          (%i1) draw3d(
18398                   nticks = 60,
18399                   line_width = 3,
18400                   enhanced3d = (u-1)^2,
18401                   parametric(cos(5*u)^2,sin(7*u),u-2,u,0,2))$
18402     (Figure draw_enhanced3d4)
18403
18404     'elevation_grid' object with coloring defined by the '[f(x,y), x,
18405     y]' model.
18406
18407          (%i1) m: apply(
18408                     matrix,
18409                     makelist(makelist(cos(i^2/80-k/30),k,1,30),i,1,20)) $
18410          (%i2) draw3d(
18411                   enhanced3d = [cos(x*y*10),x,y],
18412                   elevation_grid(m,-1,-1,2,2),
18413                   xlabel = "x",
18414                   ylabel = "y");
18415     (Figure draw_enhanced3d5)
18416
18417     'tube' object with coloring defined by the '[f(x,y,z), x, y, z]'
18418     model.
18419
18420          (%i1) draw3d(
18421                   enhanced3d = [cos(x-y),x,y,z],
18422                   palette = gray,
18423                   xu_grid = 50,
18424                   tube(cos(a), a, 0, 1, a, 0, 4*%pi) )$
18425     (Figure draw_enhanced3d6)
18426
18427     'tube' object with coloring defined by the '[f(u), u]' model.
18428     Here, 'enhanced3d = -a' would be the shortcut for 'enhanced3d =
18429     [-foo,foo]'.
18430
18431          (%i1) draw3d(
18432                   capping = [true, false],
18433                   palette = [26,15,-2],
18434                   enhanced3d = [-foo, foo],
18435                   tube(a, a, a^2, 1, a, -2, 2) )$
18436     (Figure draw_enhanced3d7)
18437
18438     'implicit' and 'points' objects with coloring defined by the
18439     '[f(x,y,z), x, y, z]' model.
18440
18441          (%i1) draw3d(
18442                   enhanced3d = [x-y,x,y,z],
18443                   implicit((x^2+y^2+z^2-1)*(x^2+(y-1.5)^2+z^2-0.5)=0.015,
18444                            x,-1,1,y,-1.2,2.3,z,-1,1)) $
18445          (%i2) m: makelist([random(1.0),random(1.0),random(1.0)],k,1,2000)$
18446     (Figure draw_enhanced3d9)
18447          (%i3) draw3d(
18448                   point_type = filled_circle,
18449                   point_size = 2,
18450                   enhanced3d = [u+v-w,u,v,w],
18451                   points(m) ) $
18452     (Figure draw_enhanced3d10)
18453
18454     When points have a chronological nature, model '[f(k), k]' is also
18455     valid, being 'k' an ordering parameter.
18456
18457          (%i1) m:makelist([random(1.0), random(1.0), random(1.0)],k,1,5)$
18458          (%i2) draw3d(
18459                   enhanced3d = [sin(j), j],
18460                   point_size = 3,
18461                   point_type = filled_circle,
18462                   points_joined = true,
18463                   points(m)) $
18464     (Figure draw_enhanced3d11)
18465
18466 -- Graphic option: error_type
18467     Default value: 'y'
18468
18469     Depending on its value, which can be 'x', 'y', or 'xy', graphic
18470     object 'errors' will draw points with horizontal, vertical, or
18471     both, error bars.  When 'error_type=boxes', boxes will be drawn
18472     instead of crosses.
18473
18474     See also 'errors'.
18475
18476 -- Graphic option: file_name
18477     Default value: '"maxima_out"'
18478
18479     This is the name of the file where terminals 'png', 'jpg', 'gif',
18480     'eps', 'eps_color', 'pdf', 'pdfcairo' and 'svg' will save the
18481     graphic.
18482
18483     Since this is a global graphics option, its position in the scene
18484     description does not matter.  It can be also used as an argument of
18485     function 'draw'.
18486
18487     Example:
18488
18489          (%i1) draw2d(file_name = "myfile",
18490                       explicit(x^2,x,-1,1),
18491                       terminal  = 'png)$
18492
18493     See also 'terminal', 'dimensions_draw'.
18494
18495 -- Graphic option: fill_color
18496     Default value: '"red"'
18497
18498     'fill_color' specifies the color for filling polygons and 2d
18499     'explicit' functions.
18500
18501     See 'color' to learn how colors are specified.
18502
18503 -- Graphic option: fill_density
18504     Default value: 0
18505
18506     'fill_density' is a number between 0 and 1 that specifies the
18507     intensity of the 'fill_color' in 'bars' objects.
18508
18509     See 'bars' for examples.
18510
18511 -- Graphic option: filled_func
18512     Default value: 'false'
18513
18514     Option 'filled_func' controls how regions limited by functions
18515     should be filled.  When 'filled_func' is 'true', the region bounded
18516     by the function defined with object 'explicit' and the bottom of
18517     the graphic window is filled with 'fill_color'.  When 'filled_func'
18518     contains a function expression, then the region bounded by this
18519     function and the function defined with object 'explicit' will be
18520     filled.  By default, explicit functions are not filled.
18521
18522     A useful special case is 'filled_func=0', which generates the
18523     region bond by the horizontal axis and the explicit function.
18524
18525     This option affects only the 2d graphic object 'explicit'.
18526
18527     Example:
18528
18529     Region bounded by an 'explicit' object and the bottom of the
18530     graphic window.
18531          (%i1) draw2d(fill_color  = red,
18532                       filled_func = true,
18533                       explicit(sin(x),x,0,10) )$
18534     (Figure draw_filledfunc)
18535
18536     Region bounded by an 'explicit' object and the function defined by
18537     option 'filled_func'.  Note that the variable in 'filled_func' must
18538     be the same as that used in 'explicit'.
18539          (%i1) draw2d(fill_color  = grey,
18540                       filled_func = sin(x),
18541                       explicit(-sin(x),x,0,%pi));
18542     (Figure draw_filledfunc2) See also 'fill_color' and 'explicit'.
18543
18544 -- Graphic option: font
18545     Default value: '""' (empty string)
18546
18547     This option can be used to set the font face to be used by the
18548     terminal.  Only one font face and size can be used throughout the
18549     plot.
18550
18551     Since this is a global graphics option, its position in the scene
18552     description does not matter.
18553
18554     See also 'font_size'.
18555
18556     Gnuplot doesn't handle fonts by itself, it leaves this task to the
18557     support libraries of the different terminals, each one with its own
18558     philosophy about it.  A brief summary follows:
18559
18560        * x11: Uses the normal x11 font server mechanism.
18561
18562          Example:
18563               (%i1) draw2d(font      = "Arial",
18564                            font_size = 20,
18565                            label(["Arial font, size 20",1,1]))$
18566
18567        * windows: The windows terminal doesn't support changing of
18568          fonts from inside the plot.  Once the plot has been generated,
18569          the font can be changed right-clicking on the menu of the
18570          graph window.
18571
18572        * png, jpeg, gif: The libgd library uses the font path stored in
18573          the environment variable 'GDFONTPATH'; in this case, it is
18574          only necessary to set option 'font' to the font's name.  It is
18575          also possible to give the complete path to the font file.
18576
18577          Examples:
18578
18579          Option 'font' can be given the complete path to the font file:
18580               (%i1) path: "/usr/share/fonts/truetype/freefont/" $
18581               (%i2) file: "FreeSerifBoldItalic.ttf" $
18582               (%i3) draw2d(
18583                       font      = concat(path, file),
18584                       font_size = 20,
18585                       color     = red,
18586                       label(["FreeSerifBoldItalic font, size 20",1,1]),
18587                       terminal  = png)$
18588
18589          If environment variable 'GDFONTPATH' is set to the path where
18590          font files are allocated, it is possible to set graphic option
18591          'font' to the name of the font.
18592               (%i1) draw2d(
18593                       font      = "FreeSerifBoldItalic",
18594                       font_size = 20,
18595                       color     = red,
18596                       label(["FreeSerifBoldItalic font, size 20",1,1]),
18597                       terminal  = png)$
18598
18599        * Postscript: Standard Postscript fonts are:
18600          '"Times-Roman"', '"Times-Italic"', '"Times-Bold"',
18601          '"Times-BoldItalic"',
18602          '"Helvetica"', '"Helvetica-Oblique"', '"Helvetica-Bold"',
18603          '"Helvetic-BoldOblique"', '"Courier"', '"Courier-Oblique"',
18604          '"Courier-Bold"',
18605          and '"Courier-BoldOblique"'.
18606
18607          Example:
18608               (%i1) draw2d(
18609                       font      = "Courier-Oblique",
18610                       font_size = 15,
18611                       label(["Courier-Oblique font, size 15",1,1]),
18612                       terminal = eps)$
18613
18614        * pdf: Uses same fonts as Postscript.
18615
18616        * pdfcairo: Uses same fonts as wxt.
18617
18618        * wxt: The pango library finds fonts via the 'fontconfig'
18619          utility.
18620
18621        * aqua: Default is '"Times-Roman"'.
18622
18623     The gnuplot documentation is an important source of information
18624     about terminals and fonts.
18625
18626 -- Graphic option: font_size
18627     Default value: 10
18628
18629     This option can be used to set the font size to be used by the
18630     terminal.  Only one font face and size can be used throughout the
18631     plot.  'font_size' is active only when option 'font' is not equal
18632     to the empty string.
18633
18634     Since this is a global graphics option, its position in the scene
18635     description does not matter.
18636
18637     See also 'font'.
18638
18639 -- Graphic option: gnuplot_file_name
18640     Default value: '"maxout_xxx.gnuplot"' with '"xxx"' being a number
18641     that is unique to each concurrently-running maxima process.
18642
18643     This is the name of the file with the necessary commands to be
18644     processed by Gnuplot.
18645
18646     Since this is a global graphics option, its position in the scene
18647     description does not matter.  It can be also used as an argument of
18648     function 'draw'.
18649
18650     Example:
18651
18652          (%i1) draw2d(
18653                 file_name = "my_file",
18654                 gnuplot_file_name = "my_commands_for_gnuplot",
18655                 data_file_name    = "my_data_for_gnuplot",
18656                 terminal          = png,
18657                 explicit(x^2,x,-1,1)) $
18658
18659     See also 'data_file_name'.
18660
18661 -- Graphic option: grid
18662     Default value: 'false'
18663
18664     If 'grid' is 'not false', a grid will be drawn on the <xy> plane.
18665     If 'grid' is assigned true, one grid line per tick of each axis is
18666     drawn.  If 'grid' is assigned a list 'nx,ny' with '[nx,ny] > [0,0]'
18667     instead 'nx' lines per tick of the x axis and 'ny' lines per tick
18668     of the y axis are drawn.
18669
18670     Since this is a global graphics option, its position in the scene
18671     description does not matter.
18672
18673     Example:
18674
18675          (%i1) draw2d(grid = true,
18676                       explicit(exp(u),u,-2,2))$
18677     (Figure draw_grid)
18678
18679          (%i1) draw2d(grid = [2,2],
18680                       explicit(sin(x),x,0,2*%pi))$
18681     (Figure draw_grid2)
18682
18683 -- Graphic option: head_angle
18684     Default value: 45
18685
18686     'head_angle' indicates the angle, in degrees, between the arrow
18687     heads and the segment.
18688
18689     This option is relevant only for 'vector' objects.
18690
18691     Example:
18692
18693          (%i1) draw2d(xrange      = [0,10],
18694                       yrange      = [0,9],
18695                       head_length = 0.7,
18696                       head_angle  = 10,
18697                       vector([1,1],[0,6]),
18698                       head_angle  = 20,
18699                       vector([2,1],[0,6]),
18700                       head_angle  = 30,
18701                       vector([3,1],[0,6]),
18702                       head_angle  = 40,
18703                       vector([4,1],[0,6]),
18704                       head_angle  = 60,
18705                       vector([5,1],[0,6]),
18706                       head_angle  = 90,
18707                       vector([6,1],[0,6]),
18708                       head_angle  = 120,
18709                       vector([7,1],[0,6]),
18710                       head_angle  = 160,
18711                       vector([8,1],[0,6]),
18712                       head_angle  = 180,
18713                       vector([9,1],[0,6]) )$
18714     (Figure draw_head_angle)
18715
18716     See also 'head_both', 'head_length', and 'head_type'.
18717
18718 -- Graphic option: head_both
18719     Default value: 'false'
18720
18721     If 'head_both' is 'true', vectors are plotted with two arrow heads.
18722     If 'false', only one arrow is plotted.
18723
18724     This option is relevant only for 'vector' objects.
18725
18726     Example:
18727
18728          (%i1) draw2d(xrange      = [0,8],
18729                       yrange      = [0,8],
18730                       head_length = 0.7,
18731                       vector([1,1],[6,0]),
18732                       head_both   = true,
18733                       vector([1,7],[6,0]) )$
18734     (Figure draw_head_both)
18735
18736     See also 'head_length', 'head_angle', and 'head_type'.
18737
18738 -- Graphic option: head_length
18739     Default value: 2
18740
18741     'head_length' indicates, in <x>-axis units, the length of arrow
18742     heads.
18743
18744     This option is relevant only for 'vector' objects.
18745
18746     Example:
18747
18748          (%i1) draw2d(xrange      = [0,12],
18749                       yrange      = [0,8],
18750                       vector([0,1],[5,5]),
18751                       head_length = 1,
18752                       vector([2,1],[5,5]),
18753                       head_length = 0.5,
18754                       vector([4,1],[5,5]),
18755                       head_length = 0.25,
18756                       vector([6,1],[5,5]))$
18757     (Figure draw_head_length)
18758
18759     See also 'head_both', 'head_angle', and 'head_type'.
18760
18761 -- Graphic option: head_type
18762     Default value: 'filled'
18763
18764     'head_type' is used to specify how arrow heads are plotted.
18765     Possible values are: 'filled' (closed and filled arrow heads),
18766     'empty' (closed but not filled arrow heads), and 'nofilled' (open
18767     arrow heads).
18768
18769     This option is relevant only for 'vector' objects.
18770
18771     Example:
18772
18773          (%i1) draw2d(xrange      = [0,12],
18774                       yrange      = [0,10],
18775                       head_length = 1,
18776                       vector([0,1],[5,5]), /* default type */
18777                       head_type = 'empty,
18778                       vector([3,1],[5,5]),
18779                       head_type = 'nofilled,
18780                       vector([6,1],[5,5]))$
18781     (Figure draw_head_type)
18782
18783     See also 'head_both', 'head_angle', and 'head_length'.
18784
18785 -- Graphic option: interpolate_color
18786     Default value: 'false'
18787
18788     This option is relevant only when 'enhanced3d' is not 'false'.
18789
18790     When 'interpolate_color' is 'false', surfaces are colored with
18791     homogeneous quadrangles.  When 'true', color transitions are
18792     smoothed by interpolation.
18793
18794     'interpolate_color' also accepts a list of two numbers, '[m,n]'.
18795     For positive <m> and <n>, each quadrangle or triangle is
18796     interpolated <m> times and <n> times in the respective direction.
18797     For negative <m> and <n>, the interpolation frequency is chosen so
18798     that there will be at least <|m|> and <|n|> points drawn; you can
18799     consider this as a special gridding function.  Zeros, i.e.
18800     'interpolate_color=[0,0]', will automatically choose an optimal
18801     number of interpolated surface points.
18802
18803     Also, 'interpolate_color=true' is equivalent to
18804     'interpolate_color=[0,0]'.
18805
18806     Examples:
18807
18808     Color interpolation with explicit functions.
18809
18810          (%i1) draw3d(
18811                  enhanced3d   = sin(x*y),
18812                  explicit(20*exp(-x^2-y^2)-10, x ,-3, 3, y, -3, 3)) $
18813     (Figure draw_interpolate_color)
18814          (%i2) draw3d(
18815                  interpolate_color = true,
18816                  enhanced3d   = sin(x*y),
18817                  explicit(20*exp(-x^2-y^2)-10, x ,-3, 3, y, -3, 3)) $
18818     (Figure draw_interpolate_color2)
18819          (%i3) draw3d(
18820                  interpolate_color = [-10,0],
18821                  enhanced3d   = sin(x*y),
18822                  explicit(20*exp(-x^2-y^2)-10, x ,-3, 3, y, -3, 3)) $
18823     (Figure draw_interpolate_color3)
18824
18825     Color interpolation with the 'mesh' graphic object.
18826
18827     Interpolating colors in parametric surfaces can give unexpected
18828     results.
18829
18830          (%i1) draw3d(
18831                  enhanced3d = true,
18832                  mesh([[1,1,3],   [7,3,1],[12,-2,4],[15,0,5]],
18833                       [[2,7,8],   [4,3,1],[10,5,8], [12,7,1]],
18834                       [[-2,11,10],[6,9,5],[6,15,1], [20,15,2]])) $
18835     (Figure draw_interpolate_color4)
18836          (%i2) draw3d(
18837                  enhanced3d        = true,
18838                  interpolate_color = true,
18839                  mesh([[1,1,3],   [7,3,1],[12,-2,4],[15,0,5]],
18840                       [[2,7,8],   [4,3,1],[10,5,8], [12,7,1]],
18841                       [[-2,11,10],[6,9,5],[6,15,1], [20,15,2]])) $
18842     (Figure draw_interpolate_color5)
18843          (%i3) draw3d(
18844                  enhanced3d        = true,
18845                  interpolate_color = true,
18846                  view=map,
18847                  mesh([[1,1,3],   [7,3,1],[12,-2,4],[15,0,5]],
18848                       [[2,7,8],   [4,3,1],[10,5,8], [12,7,1]],
18849                       [[-2,11,10],[6,9,5],[6,15,1], [20,15,2]])) $
18850     (Figure draw_interpolate_color6)
18851
18852     See also 'enhanced3d'.
18853
18854 -- Graphic option: ip_grid
18855     Default value: '[50, 50]'
18856
18857     'ip_grid' sets the grid for the first sampling in implicit plots.
18858
18859     This option is relevant only for 'implicit' objects.
18860
18861 -- Graphic option: ip_grid_in
18862     Default value: '[5, 5]'
18863
18864     'ip_grid_in' sets the grid for the second sampling in implicit
18865     plots.
18866
18867     This option is relevant only for 'implicit' objects.
18868
18869 -- Graphic option: key
18870     Default value: '""' (empty string)
18871
18872     'key' is the name of a function in the legend.  If 'key' is an
18873     empty string, no key is assigned to the function.
18874
18875     This option affects the following graphic objects:
18876        * 'gr2d': 'points', 'polygon', 'rectangle', 'ellipse', 'vector',
18877          'explicit', 'implicit', 'parametric' and 'polar'.
18878
18879        * 'gr3d': 'points', 'explicit', 'parametric' and
18880          'parametric_surface'.
18881
18882     Example:
18883
18884          (%i1) draw2d(key   = "Sinus",
18885                       explicit(sin(x),x,0,10),
18886                       key   = "Cosinus",
18887                       color = red,
18888                       explicit(cos(x),x,0,10) )$
18889     (Figure draw_key)
18890
18891 -- Graphic option: key_pos
18892     Default value: '""' (empty string)
18893
18894     'key_pos' defines at which position the legend will be drawn.  If
18895     'key' is an empty string, '"top_right"' is used.  Available
18896     position specifiers are: 'top_left', 'top_center', 'top_right',
18897     'center_left', 'center', 'center_right', 'bottom_left',
18898     'bottom_center', and 'bottom_right'.
18899
18900     Since this is a global graphics option, its position in the scene
18901     description does not matter.
18902
18903     Example:
18904
18905          (%i1) draw2d(
18906                  key_pos = top_left,
18907                  key   = "x",
18908                  explicit(x,  x,0,10),
18909                  color= red,
18910                  key   = "x squared",
18911                  explicit(x^2,x,0,10))$
18912          (%i3) draw3d(
18913                  key_pos = center,
18914                  key   = "x",
18915                  explicit(x+y,x,0,10,y,0,10),
18916                  color= red,
18917                  key   = "x squared",
18918                  explicit(x^2+y^2,x,0,10,y,0,10))$
18919     (Figure draw_key_pos)
18920
18921 -- Graphic option: label_alignment
18922     Default value: 'center'
18923
18924     'label_alignment' is used to specify where to write labels with
18925     respect to the given coordinates.  Possible values are: 'center',
18926     'left', and 'right'.
18927
18928     This option is relevant only for 'label' objects.
18929
18930     Example:
18931
18932          (%i1) draw2d(xrange          = [0,10],
18933                       yrange          = [0,10],
18934                       points_joined   = true,
18935                       points([[5,0],[5,10]]),
18936                       color           = blue,
18937                       label(["Centered alignment (default)",5,2]),
18938                       label_alignment = 'left,
18939                       label(["Left alignment",5,5]),
18940                       label_alignment = 'right,
18941                       label(["Right alignment",5,8]))$
18942     (Figure draw_label_alignment)
18943
18944     See also 'label_orientation', and 'color'
18945
18946 -- Graphic option: label_orientation
18947     Default value: 'horizontal'
18948
18949     'label_orientation' is used to specify orientation of labels.
18950     Possible values are: 'horizontal', and 'vertical'.
18951
18952     This option is relevant only for 'label' objects.
18953
18954     Example:
18955
18956     In this example, a dummy point is added to get an image.  Package
18957     'draw' needs always data to draw an scene.
18958          (%i1) draw2d(xrange     = [0,10],
18959                       yrange     = [0,10],
18960                       point_size = 0,
18961                       points([[5,5]]),
18962                       color      = navy,
18963                       label(["Horizontal orientation (default)",5,2]),
18964                       label_orientation = 'vertical,
18965                       color             = "#654321",
18966                       label(["Vertical orientation",1,5]))$
18967     (Figure draw_label_orientation)
18968
18969     See also 'label_alignment' and 'color'
18970
18971 -- Graphic option: line_type
18972     Default value: 'solid'
18973
18974     'line_type' indicates how lines are displayed; possible values are
18975     'solid' and 'dots', both available in all terminals, and 'dashes',
18976     'short_dashes', 'short_long_dashes', 'short_short_long_dashes', and
18977     'dot_dash', which are not available in 'png', 'jpg', and 'gif'
18978     terminals.
18979
18980     This option affects the following graphic objects:
18981        * 'gr2d': 'points', 'polygon', 'rectangle', 'ellipse', 'vector',
18982          'explicit', 'implicit', 'parametric' and 'polar'.
18983
18984        * 'gr3d': 'points', 'explicit', 'parametric' and
18985          'parametric_surface'.
18986
18987     Example:
18988
18989          (%i1) draw2d(line_type = dots,
18990                       explicit(1 + x^2,x,-1,1),
18991                       line_type = solid, /* default */
18992                       explicit(2 + x^2,x,-1,1))$
18993     (Figure draw_line_type)
18994
18995     See also 'line_width'.
18996
18997 -- Graphic option: line_width
18998     Default value: 1
18999
19000     'line_width' is the width of plotted lines.  Its value must be a
19001     positive number.
19002
19003     This option affects the following graphic objects:
19004        * 'gr2d': 'points', 'polygon', 'rectangle', 'ellipse', 'vector',
19005          'explicit', 'implicit', 'parametric' and 'polar'.
19006
19007        * 'gr3d': 'points' and 'parametric'.
19008
19009     Example:
19010
19011          (%i1) draw2d(explicit(x^2,x,-1,1), /* default width */
19012                       line_width = 5.5,
19013                       explicit(1 + x^2,x,-1,1),
19014                       line_width = 10,
19015                       explicit(2 + x^2,x,-1,1))$
19016     (Figure draw_line_width)
19017
19018     See also 'line_type'.
19019
19020 -- Graphic option: logcb
19021     Default value: 'false'
19022
19023     If 'logcb' is 'true', the tics in the colorbox will be drawn in the
19024     logarithmic scale.
19025
19026     When 'enhanced3d' or 'colorbox' is 'false', option 'logcb' has no
19027     effect.
19028
19029     Since this is a global graphics option, its position in the scene
19030     description does not matter.
19031
19032     Example:
19033
19034          (%i1) draw3d (
19035                  enhanced3d = true,
19036                  color      = green,
19037                  logcb = true,
19038                  logz  = true,
19039                  palette = [-15,24,-9],
19040                  explicit(exp(x^2-y^2), x,-2,2,y,-2,2)) $
19041     (Figure draw_logcb)
19042
19043     See also 'enhanced3d', 'colorbox' and 'cbrange'.
19044
19045 -- Graphic option: logx
19046     Default value: 'false'
19047
19048     If 'logx' is 'true', the <x> axis will be drawn in the logarithmic
19049     scale.
19050
19051     Since this is a global graphics option, its position in the scene
19052     description does not matter, with the exception that it should be
19053     written before any 2D 'explicit' object, so that 'draw' can produce
19054     a better plot.
19055
19056     Example:
19057
19058          (%i1) draw2d(logx = true,
19059                       explicit(log(x),x,0.01,5))$
19060
19061     See also 'logy', 'logx_secondary', 'logy_secondary', and 'logz'.
19062
19063 -- Graphic option: logx_secondary
19064     Default value: 'false'
19065
19066     If 'logx_secondary' is 'true', the secondary <x> axis will be drawn
19067     in the logarithmic scale.
19068
19069     This option is relevant only for 2d scenes.
19070
19071     Since this is a global graphics option, its position in the scene
19072     description does not matter.
19073
19074     Example:
19075
19076          (%i1) draw2d(
19077                  grid = true,
19078                  key="x^2, linear scale",
19079                  color=red,
19080                  explicit(x^2,x,1,100),
19081                  xaxis_secondary = true,
19082                  xtics_secondary = true,
19083                  logx_secondary  = true,
19084                  key = "x^2, logarithmic x scale",
19085                  color = blue,
19086                  explicit(x^2,x,1,100) )$
19087     (Figure draw_logx_secondary)
19088
19089     See also 'logx_draw', 'logy_draw', 'logy_secondary', and 'logz'.
19090
19091 -- Graphic option: logy
19092     Default value: 'false'
19093
19094     If 'logy' is 'true', the <y> axis will be drawn in the logarithmic
19095     scale.
19096
19097     Since this is a global graphics option, its position in the scene
19098     description does not matter.
19099
19100     Example:
19101
19102          (%i1) draw2d(logy = true,
19103                       explicit(exp(x),x,0,5))$
19104
19105     See also 'logx_draw', 'logx_secondary', 'logy_secondary', and
19106     'logz'.
19107
19108 -- Graphic option: logy_secondary
19109     Default value: 'false'
19110
19111     If 'logy_secondary' is 'true', the secondary <y> axis will be drawn
19112     in the logarithmic scale.
19113
19114     This option is relevant only for 2d scenes.
19115
19116     Since this is a global graphics option, its position in the scene
19117     description does not matter.
19118
19119     Example:
19120
19121          (%i1) draw2d(
19122                  grid = true,
19123                  key="x^2, linear scale",
19124                  color=red,
19125                  explicit(x^2,x,1,100),
19126                  yaxis_secondary = true,
19127                  ytics_secondary = true,
19128                  logy_secondary  = true,
19129                  key = "x^2, logarithmic y scale",
19130                  color = blue,
19131                  explicit(x^2,x,1,100) )$
19132
19133     See also 'logx_draw', 'logy_draw', 'logx_secondary', and 'logz'.
19134
19135 -- Graphic option: logz
19136     Default value: 'false'
19137
19138     If 'logz' is 'true', the <z> axis will be drawn in the logarithmic
19139     scale.
19140
19141     Since this is a global graphics option, its position in the scene
19142     description does not matter.
19143
19144     Example:
19145
19146          (%i1) draw3d(logz = true,
19147                       explicit(exp(u^2+v^2),u,-2,2,v,-2,2))$
19148
19149     See also 'logx_draw' and 'logy_draw'.
19150
19151 -- Graphic option: nticks
19152     Default value: 29
19153
19154     In 2d, 'nticks' gives the initial number of points used by the
19155     adaptive plotting routine for explicit objects.  It is also the
19156     number of points that will be shown in parametric and polar curves.
19157
19158     This option affects the following graphic objects:
19159        * 'gr2d': 'ellipse', 'explicit', 'parametric' and 'polar'.
19160
19161        * 'gr3d': 'parametric'.
19162
19163     See also 'adapt_depth'
19164
19165     Example:
19166
19167          (%i1) draw2d(transparent = true,
19168                       ellipse(0,0,4,2,0,180),
19169                       nticks = 5,
19170                       ellipse(0,0,4,2,180,180) )$
19171     (Figure draw_nticks)
19172
19173 -- Graphic option: palette
19174     Default value: 'color'
19175
19176     'palette' indicates how to map gray levels onto color components.
19177     It works together with option 'enhanced3d' in 3D graphics, who
19178     associates every point of a surfaces to a real number or gray
19179     level.  It also works with gray images.  With 'palette', levels are
19180     transformed into colors.
19181
19182     There are two ways for defining these transformations.
19183
19184     First, 'palette' can be a vector of length three with components
19185     ranging from -36 to +36; each value is an index for a formula
19186     mapping the levels onto red, green and blue colors, respectively:
19187           0: 0               1: 0.5           2: 1
19188           3: x               4: x^2           5: x^3
19189           6: x^4             7: sqrt(x)       8: sqrt(sqrt(x))
19190           9: sin(90x)       10: cos(90x)     11: |x-0.5|
19191          12: (2x-1)^2       13: sin(180x)    14: |cos(180x)|
19192          15: sin(360x)      16: cos(360x)    17: |sin(360x)|
19193          18: |cos(360x)|    19: |sin(720x)|  20: |cos(720x)|
19194          21: 3x             22: 3x-1         23: 3x-2
19195          24: |3x-1|         25: |3x-2|       26: (3x-1)/2
19196          27: (3x-2)/2       28: |(3x-1)/2|   29: |(3x-2)/2|
19197          30: x/0.32-0.78125 31: 2*x-0.84     32: 4x;1;-2x+1.84;x/0.08-11.5
19198          33: |2*x - 0.5|    34: 2*x          35: 2*x - 0.5
19199          36: 2*x - 1
19200     negative numbers mean negative colour component.  'palette = gray'
19201     and 'palette = color' are short cuts for 'palette = [3,3,3]' and
19202     'palette = [7,5,15]', respectively.
19203
19204     Second, 'palette' can be a user defined lookup table.  In this
19205     case, the format for building a lookup table of length 'n' is
19206     'palette=[color_1, color_2, ..., color_n]', where 'color_i' is a
19207     well formed color (see option 'color') such that 'color_1' is
19208     assigned to the lowest gray level and 'color_n' to the highest.
19209     The rest of colors are interpolated.
19210
19211     Since this is a global graphics option, its position in the scene
19212     description does not matter.
19213
19214     Examples:
19215
19216     It works together with option 'enhanced3d' in 3D graphics.
19217
19218          (%i1) draw3d(
19219                  enhanced3d = [z-x+2*y,x,y,z],
19220                  palette = [32, -8, 17],
19221                  explicit(20*exp(-x^2-y^2)-10,x,-3,3,y,-3,3))$
19222     (Figure draw_palette)
19223
19224     It also works with gray images.
19225
19226          (%i1) im: apply(
19227                     'matrix,
19228                      makelist(makelist(random(200),i,1,30),i,1,30))$
19229          (%i2) /* palette = color, default */
19230                draw2d(image(im,0,0,30,30))$
19231          (%i3) draw2d(palette = gray, image(im,0,0,30,30))$
19232          (%i4) draw2d(palette = [15,20,-4],
19233                       colorbox=false,
19234                       image(im,0,0,30,30))$
19235     (Figure draw_palette2)
19236
19237     'palette' can be a user defined lookup table.  In this example, low
19238     values of 'x' are colored in red, and higher values in yellow.
19239
19240          (%i1) draw3d(
19241                   palette = [red, blue, yellow],
19242                   enhanced3d = x,
19243                   explicit(x^2+y^2,x,-1,1,y,-1,1)) $
19244     (Figure draw_palette3)
19245
19246     See also 'colorbox' and 'enhanced3d'.
19247
19248 -- Graphic option: point_size
19249     Default value: 1
19250
19251     'point_size' sets the size for plotted points.  It must be a non
19252     negative number.
19253
19254     This option has no effect when graphic option 'point_type' is set
19255     to 'dot'.
19256
19257     This option affects the following graphic objects:
19258        * 'gr2d': 'points'.
19259
19260        * 'gr3d': 'points'.
19261
19262     Example:
19263
19264          (%i1) draw2d(points(makelist([random(20),random(50)],k,1,10)),
19265                  point_size = 5,
19266                  points(makelist(k,k,1,20),makelist(random(30),k,1,20)))$
19267     (Figure draw_point_size)
19268
19269 -- Graphic option: point_type
19270     Default value: 1
19271
19272     'point_type' indicates how isolated points are displayed; the value
19273     of this option can be any integer index greater or equal than -1,
19274     or the name of a point style: '$none' (-1), 'dot' (0), 'plus' (1),
19275     'multiply' (2), 'asterisk' (3), 'square' (4), 'filled_square' (5),
19276     'circle' (6), 'filled_circle' (7), 'up_triangle' (8),
19277     'filled_up_triangle' (9), 'down_triangle' (10),
19278     'filled_down_triangle' (11), 'diamant' (12) and 'filled_diamant'
19279     (13).
19280
19281     This option affects the following graphic objects:
19282        * 'gr2d': 'points'.
19283
19284        * 'gr3d': 'points'.
19285
19286     Example:
19287
19288          (%i1) draw2d(xrange = [0,10],
19289                       yrange = [0,10],
19290                       point_size = 3,
19291                       point_type = diamant,
19292                       points([[1,1],[5,1],[9,1]]),
19293                       point_type = filled_down_triangle,
19294                       points([[1,2],[5,2],[9,2]]),
19295                       point_type = asterisk,
19296                       points([[1,3],[5,3],[9,3]]),
19297                       point_type = filled_diamant,
19298                       points([[1,4],[5,4],[9,4]]),
19299                       point_type = 5,
19300                       points([[1,5],[5,5],[9,5]]),
19301                       point_type = 6,
19302                       points([[1,6],[5,6],[9,6]]),
19303                       point_type = filled_circle,
19304                       points([[1,7],[5,7],[9,7]]),
19305                       point_type = 8,
19306                       points([[1,8],[5,8],[9,8]]),
19307                       point_type = filled_diamant,
19308                       points([[1,9],[5,9],[9,9]]) )$
19309     (Figure draw_point_type)
19310
19311 -- Graphic option: points_joined
19312     Default value: 'false'
19313
19314     When 'points_joined' is 'true', points are joined by lines; when
19315     'false', isolated points are drawn.  A third possible value for
19316     this graphic option is 'impulses'; in such case, vertical segments
19317     are drawn from points to the x-axis (2D) or to the xy-plane (3D).
19318
19319     This option affects the following graphic objects:
19320        * 'gr2d': 'points'.
19321
19322        * 'gr3d': 'points'.
19323
19324     Example:
19325
19326          (%i1) draw2d(xrange        = [0,10],
19327                       yrange        = [0,4],
19328                       point_size    = 3,
19329                       point_type    = up_triangle,
19330                       color         = blue,
19331                       points([[1,1],[5,1],[9,1]]),
19332                       points_joined = true,
19333                       point_type    = square,
19334                       line_type     = dots,
19335                       points([[1,2],[5,2],[9,2]]),
19336                       point_type    = circle,
19337                       color         = red,
19338                       line_width    = 7,
19339                       points([[1,3],[5,3],[9,3]]) )$
19340     (Figure draw_points_joined)
19341
19342 -- Graphic option: proportional_axes
19343     Default value: 'none'
19344
19345     When 'proportional_axes' is equal to 'xy' or 'xyz', the aspect
19346     ratio of the axis units will be set to 1:1 resulting in a 2D or 3D
19347     scene that will be drawn with axes proportional to their relative
19348     lengths.
19349
19350     Since this is a global graphics option, its position in the scene
19351     description does not matter.
19352
19353     This option works with Gnuplot version 4.2.6 or greater.
19354
19355     Examples:
19356
19357     Single 2D plot.
19358
19359          (%i1) draw2d(
19360                  ellipse(0,0,1,1,0,360),
19361                  transparent=true,
19362                  color = blue,
19363                  line_width = 4,
19364                  ellipse(0,0,2,1/2,0,360),
19365                  proportional_axes = 'xy) $
19366     (Figure draw_proportional_axis)
19367
19368     Multiplot.
19369
19370          (%i1) draw(
19371                  terminal = wxt,
19372                  gr2d(proportional_axes = 'xy,
19373                       explicit(x^2,x,0,1)),
19374                  gr2d(explicit(x^2,x,0,1),
19375                       xrange = [0,1],
19376                       yrange = [0,2],
19377                       proportional_axes='xy),
19378                  gr2d(explicit(x^2,x,0,1)))$
19379     (Figure draw_proportional_axis2)
19380
19381 -- Graphic option: surface_hide
19382     Default value: 'false'
19383
19384     If 'surface_hide' is 'true', hidden parts are not plotted in 3d
19385     surfaces.
19386
19387     Since this is a global graphics option, its position in the scene
19388     description does not matter.
19389
19390     Example:
19391
19392          (%i1) draw(columns=2,
19393                     gr3d(explicit(exp(sin(x)+cos(x^2)),x,-3,3,y,-3,3)),
19394                     gr3d(surface_hide = true,
19395                          explicit(exp(sin(x)+cos(x^2)),x,-3,3,y,-3,3)) )$
19396     (Figure draw_surface_hide)
19397
19398 -- Graphic option: terminal
19399     Default value: 'screen'
19400
19401     Selects the terminal to be used by Gnuplot; possible values are:
19402     'screen' (default), 'png', 'pngcairo', 'jpg', 'gif', 'eps',
19403     'eps_color', 'epslatex', 'epslatex_standalone', 'svg', 'canvas',
19404     'dumb', 'dumb_file', 'pdf', 'pdfcairo', 'wxt', 'animated_gif',
19405     'multipage_pdfcairo', 'multipage_pdf', 'multipage_eps',
19406     'multipage_eps_color', and 'aquaterm'.
19407
19408     Terminals 'screen', 'wxt', 'windows' and 'aquaterm' can be also
19409     defined as a list with two elements: the name of the terminal
19410     itself and a non negative integer number.  In this form, multiple
19411     windows can be opened at the same time, each with its corresponding
19412     number.  This feature does not work in Windows platforms.
19413
19414     Since this is a global graphics option, its position in the scene
19415     description does not matter.  It can be also used as an argument of
19416     function 'draw'.
19417
19418     N.B. pdfcairo requires Gnuplot 4.3 or newer.  'pdf' requires
19419     Gnuplot to be compiled with the option '--enable-pdf' and libpdf
19420     must be installed.  The pdf library is available from:
19421     <http://www.pdflib.com/en/download/pdflib-family/pdflib-lite/>
19422
19423     Examples:
19424
19425          (%i1) /* screen terminal (default) */
19426                draw2d(explicit(x^2,x,-1,1))$
19427          (%i2) /* png file */
19428                draw2d(terminal  = 'png,
19429                       explicit(x^2,x,-1,1))$
19430          (%i3) /* jpg file */
19431                draw2d(terminal   = 'jpg,
19432                       dimensions = [300,300],
19433                       explicit(x^2,x,-1,1))$
19434          (%i4) /* eps file */
19435                draw2d(file_name = "myfile",
19436                       explicit(x^2,x,-1,1),
19437                       terminal  = 'eps)$
19438          (%i5) /* pdf file */
19439                draw2d(file_name = "mypdf",
19440                       dimensions = 100*[12.0,8.0],
19441                       explicit(x^2,x,-1,1),
19442                       terminal  = 'pdf)$
19443          (%i6) /* wxwidgets window */
19444                draw2d(explicit(x^2,x,-1,1),
19445                       terminal  = 'wxt)$
19446
19447     Multiple windows.
19448          (%i1) draw2d(explicit(x^5,x,-2,2), terminal=[screen, 3])$
19449          (%i2) draw2d(explicit(x^2,x,-2,2), terminal=[screen, 0])$
19450
19451     An animated gif file.
19452          (%i1) draw(
19453                  delay     = 100,
19454                  file_name = "zzz",
19455                  terminal  = 'animated_gif,
19456                  gr2d(explicit(x^2,x,-1,1)),
19457                  gr2d(explicit(x^3,x,-1,1)),
19458                  gr2d(explicit(x^4,x,-1,1)));
19459          End of animation sequence
19460          (%o1)          [gr2d(explicit), gr2d(explicit), gr2d(explicit)]
19461
19462     Option 'delay' is only active in animated gif's; it is ignored in
19463     any other case.
19464
19465     Multipage output in eps format.
19466          (%i1) draw(
19467                  file_name = "parabol",
19468                  terminal  = multipage_eps,
19469                  dimensions = 100*[10,10],
19470                  gr2d(explicit(x^2,x,-1,1)),
19471                  gr3d(explicit(x^2+y^2,x,-1,1,y,-1,1))) $
19472
19473     See also 'file_name', 'dimensions_draw' and 'delay'.
19474
19475 -- Graphic option: title
19476     Default value: '""' (empty string)
19477
19478     Option 'title', a string, is the main title for the scene.  By
19479     default, no title is written.
19480
19481     Since this is a global graphics option, its position in the scene
19482     description does not matter.
19483
19484     Example:
19485
19486          (%i1) draw2d(explicit(exp(u),u,-2,2),
19487                       title = "Exponential function")$
19488     (Figure draw_title)
19489
19490 -- Graphic option: transform
19491     Default value: 'none'
19492
19493     If 'transform' is 'none', the space is not transformed and graphic
19494     objects are drawn as defined.  When a space transformation is
19495     desired, a list must be assigned to option 'transform'.  In case of
19496     a 2D scene, the list takes the form '[f1(x,y), f2(x,y), x, y]'.  In
19497     case of a 3D scene, the list is of the form '[f1(x,y,z), f2(x,y,z),
19498     f3(x,y,z), x, y, z]'.
19499
19500     The names of the variables defined in the lists may be different to
19501     those used in the definitions of the graphic objects.
19502
19503     Examples:
19504
19505     Rotation in 2D.
19506
19507          (%i1) th : %pi / 4$
19508          (%i2) draw2d(
19509                  color = "#e245f0",
19510                  proportional_axes = 'xy,
19511                  line_width = 8,
19512                  triangle([3,2],[7,2],[5,5]),
19513                  border     = false,
19514                  fill_color = yellow,
19515                  transform  = [cos(th)*x - sin(th)*y,
19516                                sin(th)*x + cos(th)*y, x, y],
19517                  triangle([3,2],[7,2],[5,5]) )$
19518     (Figure draw_transform)
19519
19520     Translation in 3D.
19521
19522          (%i1) draw3d(
19523                  color     = "#a02c00",
19524                  explicit(20*exp(-x^2-y^2)-10,x,-3,3,y,-3,3),
19525                  transform = [x+10,y+10,z+10,x,y,z],
19526                  color     = blue,
19527                  explicit(20*exp(-x^2-y^2)-10,x,-3,3,y,-3,3) )$
19528
19529 -- Graphic option: transparent
19530     Default value: 'false'
19531
19532     If 'transparent' is 'false', interior regions of polygons are
19533     filled according to 'fill_color'.
19534
19535     This option affects the following graphic objects:
19536        * 'gr2d': 'polygon', 'rectangle' and 'ellipse'.
19537
19538     Example:
19539
19540          (%i1) draw2d(polygon([[3,2],[7,2],[5,5]]),
19541                       transparent = true,
19542                       color       = blue,
19543                       polygon([[5,2],[9,2],[7,5]]) )$
19544     (Figure draw_transparent)
19545
19546 -- Graphic option: unit_vectors
19547     Default value: 'false'
19548
19549     If 'unit_vectors' is 'true', vectors are plotted with module 1.
19550     This is useful for plotting vector fields.  If 'unit_vectors' is
19551     'false', vectors are plotted with its original length.
19552
19553     This option is relevant only for 'vector' objects.
19554
19555     Example:
19556
19557          (%i1) draw2d(xrange      = [-1,6],
19558                       yrange      = [-1,6],
19559                       head_length = 0.1,
19560                       vector([0,0],[5,2]),
19561                       unit_vectors = true,
19562                       color        = red,
19563                       vector([0,3],[5,2]))$
19564     (Figure draw_unit_vectors)
19565
19566 -- Graphic option: user_preamble
19567     Default value: '""' (empty string)
19568
19569     Expert Gnuplot users can make use of this option to fine tune
19570     Gnuplot's behaviour by writing settings to be sent before the
19571     'plot' or 'splot' command.
19572
19573     The value of this option must be a string or a list of strings (one
19574     per line).
19575
19576     Since this is a global graphics option, its position in the scene
19577     description does not matter.
19578
19579     Example:
19580
19581     Tell Gnuplot to draw axes and grid on top of graphics objects,
19582          (%i1) draw2d(
19583                  xaxis =true, xaxis_type=solid,
19584                  yaxis =true, yaxis_type=solid,
19585                  user_preamble="set grid front",
19586                  region(x^2+y^2<1 ,x,-1.5,1.5,y,-1.5,1.5))$
19587     (Figure draw_user_preamble)
19588
19589     Tell gnuplot to draw all contour lines in black
19590
19591          (%i1) draw3d(
19592                    contour=both,
19593                    surface_hide=true,enhanced3d=true,wired_surface=true,
19594                    contour_levels=10,
19595                    user_preamble="set for [i=1:8] linetype i dashtype i linecolor 0",
19596                    explicit(sin(x)*cos(y),x,1,10,y,1,10)
19597                );
19598     (Figure draw_user_preamble2)
19599
19600 -- Graphic option: view
19601     Default value: '[60,30]'
19602
19603     A pair of angles, measured in degrees, indicating the view
19604     direction in a 3D scene.  The first angle is the vertical rotation
19605     around the <x> axis, in the range [0, 360].  The second one is the
19606     horizontal rotation around the <z> axis, in the range [0, 360].
19607
19608     If option 'view' is given the value 'map', the view direction is
19609     set to be perpendicular to the xy-plane.
19610
19611     Since this is a global graphics option, its position in the scene
19612     description does not matter.
19613
19614     Example:
19615
19616          (%i1) draw3d(view = [170, 50],
19617                       enhanced3d = true,
19618                       explicit(sin(x^2+y^2),x,-2,2,y,-2,2) )$
19619     (Figure draw_view)
19620          (%i2) draw3d(view = map,
19621                       enhanced3d = true,
19622                       explicit(sin(x^2+y^2),x,-2,2,y,-2,2) )$
19623     (Figure draw_view2)
19624
19625 -- Graphic option: wired_surface
19626     Default value: 'false'
19627
19628     Indicates whether 3D surfaces in 'enhanced3d' mode show the grid
19629     joinning the points or not.
19630
19631     Since this is a global graphics option, its position in the scene
19632     description does not matter.
19633
19634     Example:
19635
19636          (%i1) draw3d(
19637                  enhanced3d    = [sin(x),x,y],
19638                  wired_surface = true,
19639                  explicit(x^2+y^2,x,-1,1,y,-1,1)) $
19640     (Figure draw_wired_surface)
19641
19642 -- Graphic option: x_voxel
19643     Default value: 10
19644
19645     'x_voxel' is the number of voxels in the x direction to be used by
19646     the marching cubes algorithm implemented by the 3d 'implicit'
19647     object.  It is also used by graphic object 'region'.
19648
19649 -- Graphic option: xaxis
19650     Default value: 'false'
19651
19652     If 'xaxis' is 'true', the <x> axis is drawn.
19653
19654     Since this is a global graphics option, its position in the scene
19655     description does not matter.
19656
19657     Example:
19658
19659          (%i1) draw2d(explicit(x^3,x,-1,1),
19660                       xaxis       = true,
19661                       xaxis_color = blue)$
19662     (Figure draw_xaxis)
19663
19664     See also 'xaxis_width', 'xaxis_type' and 'xaxis_color'.
19665
19666 -- Graphic option: xaxis_color
19667     Default value: '"black"'
19668
19669     'xaxis_color' specifies the color for the <x> axis.  See 'color' to
19670     know how colors are defined.
19671
19672     Since this is a global graphics option, its position in the scene
19673     description does not matter.
19674
19675     Example:
19676
19677          (%i1) draw2d(explicit(x^3,x,-1,1),
19678                       xaxis       = true,
19679                       xaxis_color = red)$
19680
19681     See also 'xaxis', 'xaxis_width' and 'xaxis_type'.
19682
19683 -- Graphic option: xaxis_secondary
19684     Default value: 'false'
19685
19686     If 'xaxis_secondary' is 'true', function values can be plotted with
19687     respect to the second <x> axis, which will be drawn on top of the
19688     scene.
19689
19690     Note that this is a local graphics option which only affects to 2d
19691     plots.
19692
19693     Example:
19694
19695          (%i1) draw2d(
19696                   key   = "Bottom x-axis",
19697                   explicit(x+1,x,1,2),
19698                   color = red,
19699                   key   = "Above x-axis",
19700                   xtics_secondary = true,
19701                   xaxis_secondary = true,
19702                   explicit(x^2,x,-1,1)) $
19703     (Figure draw_xaxis_secondary)
19704
19705     See also 'xrange_secondary', 'xtics_secondary',
19706     'xtics_rotate_secondary', 'xtics_axis_secondary' and
19707     'xaxis_secondary'.
19708
19709 -- Graphic option: xaxis_type
19710     Default value: 'dots'
19711
19712     'xaxis_type' indicates how the <x> axis is displayed; possible
19713     values are 'solid' and 'dots'
19714
19715     Since this is a global graphics option, its position in the scene
19716     description does not matter.
19717
19718     Example:
19719
19720          (%i1) draw2d(explicit(x^3,x,-1,1),
19721                       xaxis       = true,
19722                       xaxis_type  = solid)$
19723
19724     See also 'xaxis', 'xaxis_width' and 'xaxis_color'.
19725
19726 -- Graphic option: xaxis_width
19727     Default value: 1
19728
19729     'xaxis_width' is the width of the <x> axis.  Its value must be a
19730     positive number.
19731
19732     Since this is a global graphics option, its position in the scene
19733     description does not matter.
19734
19735     Example:
19736
19737          (%i1) draw2d(explicit(x^3,x,-1,1),
19738                       xaxis       = true,
19739                       xaxis_width = 3)$
19740
19741     See also 'xaxis', 'xaxis_type' and 'xaxis_color'.
19742
19743 -- Graphic option: xlabel
19744     Default value: '""'
19745
19746     Option 'xlabel', a string, is the label for the <x> axis.  By
19747     default, the axis is labeled with string '"x"'.
19748
19749     Since this is a global graphics option, its position in the scene
19750     description does not matter.
19751
19752     Example:
19753
19754          (%i1) draw2d(xlabel = "Time",
19755                       explicit(exp(u),u,-2,2),
19756                       ylabel = "Population")$
19757
19758     See also 'xlabel_secondary', 'ylabel', 'ylabel_secondary' and
19759     'zlabel_draw'.
19760
19761 -- Graphic option: xlabel_secondary
19762     Default value: '""' (empty string)
19763
19764     Option 'xlabel_secondary', a string, is the label for the secondary
19765     <x> axis.  By default, no label is written.
19766
19767     Since this is a global graphics option, its position in the scene
19768     description does not matter.
19769
19770     Example:
19771
19772          (%i1) draw2d(
19773                   xaxis_secondary=true,yaxis_secondary=true,
19774                   xtics_secondary=true,ytics_secondary=true,
19775                   xlabel_secondary="t[s]",
19776                   ylabel_secondary="U[V]",
19777                   explicit(sin(t),t,0,10) )$
19778     (Figure draw_ylabel_secondary)
19779
19780     See also 'xlabel_draw', 'ylabel_draw', 'ylabel_secondary' and
19781     'zlabel_draw'.
19782
19783 -- Graphic option: xrange
19784     Default value: 'auto'
19785
19786     If 'xrange' is 'auto', the range for the <x> coordinate is computed
19787     automatically.
19788
19789     If the user wants a specific interval for <x>, it must be given as
19790     a Maxima list, as in 'xrange=[-2, 3]'.
19791
19792     Since this is a global graphics option, its position in the scene
19793     description does not matter.
19794
19795     Example:
19796
19797          (%i1) draw2d(xrange = [-3,5],
19798                       explicit(x^2,x,-1,1))$
19799
19800     See also 'yrange' and 'zrange'.
19801
19802 -- Graphic option: xrange_secondary
19803     Default value: 'auto'
19804
19805     If 'xrange_secondary' is 'auto', the range for the second <x> axis
19806     is computed automatically.
19807
19808     If the user wants a specific interval for the second <x> axis, it
19809     must be given as a Maxima list, as in 'xrange_secondary=[-2, 3]'.
19810
19811     Since this is a global graphics option, its position in the scene
19812     description does not matter.
19813
19814     See also 'xrange', 'yrange', 'zrange' and 'yrange_secondary'.
19815
19816 -- Graphic option: xtics
19817     Default value: 'true'
19818
19819     This graphic option controls the way tic marks are drawn on the <x>
19820     axis.
19821
19822        * When option 'xtics' is bounded to symbol <true>, tic marks are
19823          drawn automatically.
19824
19825        * When option 'xtics' is bounded to symbol <false>, tic marks
19826          are not drawn.
19827
19828        * When option 'xtics' is bounded to a positive number, this is
19829          the distance between two consecutive tic marks.
19830
19831        * When option 'xtics' is bounded to a list of length three of
19832          the form '[start,incr,end]', tic marks are plotted from
19833          'start' to 'end' at intervals of length 'incr'.
19834
19835        * When option 'xtics' is bounded to a set of numbers of the form
19836          '{n1, n2, ...}', tic marks are plotted at values 'n1', 'n2',
19837          ...
19838
19839        * When option 'xtics' is bounded to a set of pairs of the form
19840          '{["label1", n1], ["label2", n2], ...}', tic marks
19841          corresponding to values 'n1', 'n2', ...  are labeled with
19842          '"label1"', '"label2"', ..., respectively.
19843
19844     Since this is a global graphics option, its position in the scene
19845     description does not matter.
19846
19847     Examples:
19848
19849     Disable tics.
19850          (%i1) draw2d(xtics = 'false,
19851                       explicit(x^3,x,-1,1)  )$
19852
19853     Tics every 1/4 units.
19854          (%i1) draw2d(xtics = 1/4,
19855                       explicit(x^3,x,-1,1)  )$
19856
19857     Tics from -3/4 to 3/4 in steps of 1/8.
19858          (%i1) draw2d(xtics = [-3/4,1/8,3/4],
19859                       explicit(x^3,x,-1,1)  )$
19860
19861     Tics at points -1/2, -1/4 and 3/4.
19862          (%i1) draw2d(xtics = {-1/2,-1/4,3/4},
19863                       explicit(x^3,x,-1,1)  )$
19864
19865     Labeled tics.
19866          (%i1) draw2d(xtics = {["High",0.75],["Medium",0],["Low",-0.75]},
19867                       explicit(x^3,x,-1,1)  )$
19868
19869     See also 'ytics', and 'ztics'.
19870
19871 -- Graphic option: xtics_axis
19872     Default value: 'false'
19873
19874     If 'xtics_axis' is 'true', tic marks and their labels are plotted
19875     just along the <x> axis, if it is 'false' tics are plotted on the
19876     border.
19877
19878     Since this is a global graphics option, its position in the scene
19879     description does not matter.
19880
19881 -- Graphic option: xtics_rotate
19882     Default value: 'false'
19883
19884     If 'xtics_rotate' is 'true', tic marks on the <x> axis are rotated
19885     90 degrees.
19886
19887     Since this is a global graphics option, its position in the scene
19888     description does not matter.
19889
19890 -- Graphic option: xtics_rotate_secondary
19891     Default value: 'false'
19892
19893     If 'xtics_rotate_secondary' is 'true', tic marks on the secondary
19894     <x> axis are rotated 90 degrees.
19895
19896     Since this is a global graphics option, its position in the scene
19897     description does not matter.
19898
19899 -- Graphic option: xtics_secondary
19900     Default value: 'auto'
19901
19902     This graphic option controls the way tic marks are drawn on the
19903     second <x> axis.
19904
19905     See 'xtics' for a complete description.
19906
19907 -- Graphic option: xtics_secondary_axis
19908     Default value: 'false'
19909
19910     If 'xtics_secondary_axis' is 'true', tic marks and their labels are
19911     plotted just along the secondary <x> axis, if it is 'false' tics
19912     are plotted on the border.
19913
19914     Since this is a global graphics option, its position in the scene
19915     description does not matter.
19916
19917 -- Graphic option: xu_grid
19918     Default value: 30
19919
19920     'xu_grid' is the number of coordinates of the first variable ('x'
19921     in explicit and 'u' in parametric 3d surfaces) to build the grid of
19922     sample points.
19923
19924     This option affects the following graphic objects:
19925        * 'gr3d': 'explicit' and 'parametric_surface'.
19926
19927     Example:
19928
19929          (%i1) draw3d(xu_grid = 10,
19930                       yv_grid = 50,
19931                       explicit(x^2+y^2,x,-3,3,y,-3,3) )$
19932
19933     See also 'yv_grid'.
19934
19935 -- Graphic option: xy_file
19936     Default value: '""' (empty string)
19937
19938     'xy_file' is the name of the file where the coordinates will be
19939     saved after clicking with the mouse button and hitting the 'x' key.
19940     By default, no coordinates are saved.
19941
19942     Since this is a global graphics option, its position in the scene
19943     description does not matter.
19944
19945 -- Graphic option: xyplane
19946     Default value: 'false'
19947
19948     Allocates the xy-plane in 3D scenes.  When 'xyplane' is 'false',
19949     the xy-plane is placed automatically; when it is a real number, the
19950     xy-plane intersects the z-axis at this level.  This option has no
19951     effect in 2D scenes.
19952
19953     Since this is a global graphics option, its position in the scene
19954     description does not matter.
19955
19956     Example:
19957
19958          (%i1) draw3d(xyplane = %e-2,
19959                       explicit(x^2+y^2,x,-1,1,y,-1,1))$
19960
19961 -- Graphic option: y_voxel
19962     Default value: 10
19963
19964     'y_voxel' is the number of voxels in the y direction to be used by
19965     the marching cubes algorithm implemented by the 3d 'implicit'
19966     object.  It is also used by graphic object 'region'.
19967
19968 -- Graphic option: yaxis
19969     Default value: 'false'
19970
19971     If 'yaxis' is 'true', the <y> axis is drawn.
19972
19973     Since this is a global graphics option, its position in the scene
19974     description does not matter.
19975
19976     Example:
19977
19978          (%i1) draw2d(explicit(x^3,x,-1,1),
19979                       yaxis       = true,
19980                       yaxis_color = blue)$
19981
19982     See also 'yaxis_width', 'yaxis_type' and 'yaxis_color'.
19983
19984 -- Graphic option: yaxis_color
19985     Default value: '"black"'
19986
19987     'yaxis_color' specifies the color for the <y> axis.  See 'color' to
19988     know how colors are defined.
19989
19990     Since this is a global graphics option, its position in the scene
19991     description does not matter.
19992
19993     Example:
19994
19995          (%i1) draw2d(explicit(x^3,x,-1,1),
19996                       yaxis       = true,
19997                       yaxis_color = red)$
19998
19999     See also 'yaxis', 'yaxis_width' and 'yaxis_type'.
20000
20001 -- Graphic option: yaxis_secondary
20002     Default value: 'false'
20003
20004     If 'yaxis_secondary' is 'true', function values can be plotted with
20005     respect to the second <y> axis, which will be drawn on the right
20006     side of the scene.
20007
20008     Note that this is a local graphics option which only affects to 2d
20009     plots.
20010
20011     Example:
20012
20013          (%i1) draw2d(
20014                   explicit(sin(x),x,0,10),
20015                   yaxis_secondary = true,
20016                   ytics_secondary = true,
20017                   color = blue,
20018                   explicit(100*sin(x+0.1)+2,x,0,10));
20019
20020     See also 'yrange_secondary', 'ytics_secondary',
20021     'ytics_rotate_secondary' and 'ytics_axis_secondary'
20022
20023 -- Graphic option: yaxis_type
20024     Default value: 'dots'
20025
20026     'yaxis_type' indicates how the <y> axis is displayed; possible
20027     values are 'solid' and 'dots'.
20028
20029     Since this is a global graphics option, its position in the scene
20030     description does not matter.
20031
20032     Example:
20033
20034          (%i1) draw2d(explicit(x^3,x,-1,1),
20035                       yaxis       = true,
20036                       yaxis_type  = solid)$
20037
20038     See also 'yaxis', 'yaxis_width' and 'yaxis_color'.
20039
20040 -- Graphic option: yaxis_width
20041     Default value: 1
20042
20043     'yaxis_width' is the width of the <y> axis.  Its value must be a
20044     positive number.
20045
20046     Since this is a global graphics option, its position in the scene
20047     description does not matter.
20048
20049     Example:
20050
20051          (%i1) draw2d(explicit(x^3,x,-1,1),
20052                       yaxis       = true,
20053                       yaxis_width = 3)$
20054
20055     See also 'yaxis', 'yaxis_type' and 'yaxis_color'.
20056
20057 -- Graphic option: ylabel
20058     Default value: '""'
20059
20060     Option 'ylabel', a string, is the label for the <y> axis.  By
20061     default, the axis is labeled with string '"y"'.
20062
20063     Since this is a global graphics option, its position in the scene
20064     description does not matter.
20065
20066     Example:
20067
20068          (%i1) draw2d(xlabel = "Time",
20069                       ylabel = "Population",
20070                       explicit(exp(u),u,-2,2) )$
20071
20072     See also 'xlabel_draw', 'xlabel_secondary', 'ylabel_secondary', and
20073     'zlabel_draw'.
20074
20075 -- Graphic option: ylabel_secondary
20076     Default value: '""' (empty string)
20077
20078     Option 'ylabel_secondary', a string, is the label for the secondary
20079     <y> axis.  By default, no label is written.
20080
20081     Since this is a global graphics option, its position in the scene
20082     description does not matter.
20083
20084     Example:
20085
20086          (%i1) draw2d(
20087                  key_pos=bottom_right,
20088                  key="current",
20089                  xlabel="t[s]",
20090                  ylabel="I[A]",ylabel_secondary="P[W]",
20091                  explicit(sin(t),t,0,10),
20092                  yaxis_secondary=true,
20093                  ytics_secondary=true,
20094                  color=red,key="Power",
20095                  explicit((sin(t))^2,t,0,10)
20096              )$
20097
20098     See also 'xlabel_draw', 'xlabel_secondary', 'ylabel_draw' and
20099     'zlabel_draw'.
20100
20101 -- Graphic option: yrange
20102     Default value: 'auto'
20103
20104     If 'yrange' is 'auto', the range for the <y> coordinate is computed
20105     automatically.
20106
20107     If the user wants a specific interval for <y>, it must be given as
20108     a Maxima list, as in 'yrange=[-2, 3]'.
20109
20110     Since this is a global graphics option, its position in the scene
20111     description does not matter.
20112
20113     Example:
20114
20115          (%i1) draw2d(yrange = [-2,3],
20116                       explicit(x^2,x,-1,1),
20117                       xrange = [-3,3])$
20118
20119     See also 'xrange', 'yrange_secondary' and 'zrange'.
20120
20121 -- Graphic option: yrange_secondary
20122     Default value: 'auto'
20123
20124     If 'yrange_secondary' is 'auto', the range for the second <y> axis
20125     is computed automatically.
20126
20127     If the user wants a specific interval for the second <y> axis, it
20128     must be given as a Maxima list, as in 'yrange_secondary=[-2, 3]'.
20129
20130     Since this is a global graphics option, its position in the scene
20131     description does not matter.
20132
20133     Example:
20134
20135          (%i1) draw2d(
20136                   explicit(sin(x),x,0,10),
20137                   yaxis_secondary = true,
20138                   ytics_secondary = true,
20139                   yrange = [-3, 3],
20140                   yrange_secondary = [-20, 20],
20141                   color = blue,
20142                   explicit(100*sin(x+0.1)+2,x,0,10)) $
20143
20144     See also 'xrange', 'yrange' and 'zrange'.
20145
20146 -- Graphic option: ytics
20147     Default value: 'true'
20148
20149     This graphic option controls the way tic marks are drawn on the <y>
20150     axis.
20151
20152     See 'xtics' for a complete description.
20153
20154 -- Graphic option: ytics_axis
20155     Default value: 'false'
20156
20157     If 'ytics_axis' is 'true', tic marks and their labels are plotted
20158     just along the <y> axis, if it is 'false' tics are plotted on the
20159     border.
20160
20161     Since this is a global graphics option, its position in the scene
20162     description does not matter.
20163
20164 -- Graphic option: ytics_rotate
20165     Default value: 'false'
20166
20167     If 'ytics_rotate' is 'true', tic marks on the <y> axis are rotated
20168     90 degrees.
20169
20170     Since this is a global graphics option, its position in the scene
20171     description does not matter.
20172
20173 -- Graphic option: ytics_rotate_secondary
20174     Default value: 'false'
20175
20176     If 'ytics_rotate_secondary' is 'true', tic marks on the secondary
20177     <y> axis are rotated 90 degrees.
20178
20179     Since this is a global graphics option, its position in the scene
20180     description does not matter.
20181
20182 -- Graphic option: ytics_secondary
20183     Default value: 'auto'
20184
20185     This graphic option controls the way tic marks are drawn on the
20186     second <y> axis.
20187
20188     See 'xtics' for a complete description.
20189
20190 -- Graphic option: ytics_secondary_axis
20191     Default value: 'false'
20192
20193     If 'ytics_secondary_axis' is 'true', tic marks and their labels are
20194     plotted just along the secondary <y> axis, if it is 'false' tics
20195     are plotted on the border.
20196
20197     Since this is a global graphics option, its position in the scene
20198     description does not matter.
20199
20200 -- Graphic option: yv_grid
20201     Default value: 30
20202
20203     'yv_grid' is the number of coordinates of the second variable ('y'
20204     in explicit and 'v' in parametric 3d surfaces) to build the grid of
20205     sample points.
20206
20207     This option affects the following graphic objects:
20208        * 'gr3d': 'explicit' and 'parametric_surface'.
20209
20210     Example:
20211
20212          (%i1) draw3d(xu_grid = 10,
20213                       yv_grid = 50,
20214                       explicit(x^2+y^2,x,-3,3,y,-3,3) )$
20215     (Figure draw_xugrid)
20216
20217     See also 'xu_grid'.
20218
20219 -- Graphic option: z_voxel
20220     Default value: 10
20221
20222     'z_voxel' is the number of voxels in the z direction to be used by
20223     the marching cubes algorithm implemented by the 3d 'implicit'
20224     object.
20225
20226 -- Graphic option: zaxis
20227     Default value: 'false'
20228
20229     If 'zaxis' is 'true', the <z> axis is drawn in 3D plots.  This
20230     option has no effect in 2D scenes.
20231
20232     Since this is a global graphics option, its position in the scene
20233     description does not matter.
20234
20235     Example:
20236
20237          (%i1) draw3d(explicit(x^2+y^2,x,-1,1,y,-1,1),
20238                       zaxis       = true,
20239                       zaxis_type  = solid,
20240                       zaxis_color = blue)$
20241
20242     See also 'zaxis_width', 'zaxis_type' and 'zaxis_color'.
20243
20244 -- Graphic option: zaxis_color
20245     Default value: '"black"'
20246
20247     'zaxis_color' specifies the color for the <z> axis.  See 'color' to
20248     know how colors are defined.  This option has no effect in 2D
20249     scenes.
20250
20251     Since this is a global graphics option, its position in the scene
20252     description does not matter.
20253
20254     Example:
20255
20256          (%i1) draw3d(explicit(x^2+y^2,x,-1,1,y,-1,1),
20257                       zaxis       = true,
20258                       zaxis_type  = solid,
20259                       zaxis_color = red)$
20260
20261     See also 'zaxis', 'zaxis_width' and 'zaxis_type'.
20262
20263 -- Graphic option: zaxis_type
20264     Default value: 'dots'
20265
20266     'zaxis_type' indicates how the <z> axis is displayed; possible
20267     values are 'solid' and 'dots'.  This option has no effect in 2D
20268     scenes.
20269
20270     Since this is a global graphics option, its position in the scene
20271     description does not matter.
20272
20273     Example:
20274
20275          (%i1) draw3d(explicit(x^2+y^2,x,-1,1,y,-1,1),
20276                       zaxis       = true,
20277                       zaxis_type  = solid)$
20278
20279     See also 'zaxis', 'zaxis_width' and 'zaxis_color'.
20280
20281 -- Graphic option: zaxis_width
20282     Default value: 1
20283
20284     'zaxis_width' is the width of the <z> axis.  Its value must be a
20285     positive number.  This option has no effect in 2D scenes.
20286
20287     Since this is a global graphics option, its position in the scene
20288     description does not matter.
20289
20290     Example:
20291
20292          (%i1) draw3d(explicit(x^2+y^2,x,-1,1,y,-1,1),
20293                       zaxis       = true,
20294                       zaxis_type  = solid,
20295                       zaxis_width = 3)$
20296
20297     See also 'zaxis', 'zaxis_type' and 'zaxis_color'.
20298
20299 -- Graphic option: zlabel
20300     Default value: '""'
20301
20302     Option 'zlabel', a string, is the label for the <z> axis.  By
20303     default, the axis is labeled with string '"z"'.
20304
20305     Since this is a global graphics option, its position in the scene
20306     description does not matter.
20307
20308     Example:
20309
20310          (%i1) draw3d(zlabel = "Z variable",
20311                       ylabel = "Y variable",
20312                       explicit(sin(x^2+y^2),x,-2,2,y,-2,2),
20313                       xlabel = "X variable" )$
20314
20315     See also 'xlabel_draw', 'ylabel_draw', and 'zlabel_rotate'.
20316
20317 -- Graphic option: zlabel_rotate
20318     Default value: '"auto"'
20319
20320     This graphics option allows to choose if the z axis label of 3d
20321     plots is drawn horizontal ('false'), vertical ('true') or if maxima
20322     automatically chooses an orientation based on the length of the
20323     label ('auto').
20324
20325     Since this is a global graphics option, its position in the scene
20326     description does not matter.
20327
20328     Example:
20329
20330          (%i1) draw3d(
20331                    explicit(sin(x)*sin(y),x,0,10,y,0,10),
20332                    zlabel_rotate=false
20333                )$
20334
20335     See also 'zlabel_draw'.
20336
20337 -- Graphic option: zrange
20338     Default value: 'auto'
20339
20340     If 'zrange' is 'auto', the range for the <z> coordinate is computed
20341     automatically.
20342
20343     If the user wants a specific interval for <z>, it must be given as
20344     a Maxima list, as in 'zrange=[-2, 3]'.
20345
20346     Since this is a global graphics option, its position in the scene
20347     description does not matter.
20348
20349     Example:
20350
20351          (%i1) draw3d(yrange = [-3,3],
20352                       zrange = [-2,5],
20353                       explicit(x^2+y^2,x,-1,1,y,-1,1),
20354                       xrange = [-3,3])$
20355
20356     See also 'xrange' and 'yrange'.
20357
20358 -- Graphic option: ztics
20359     Default value: 'true'
20360
20361     This graphic option controls the way tic marks are drawn on the <z>
20362     axis.
20363
20364     See 'xtics' for a complete description.
20365
20366 -- Graphic option: ztics_axis
20367     Default value: 'false'
20368
20369     If 'ztics_axis' is 'true', tic marks and their labels are plotted
20370     just along the <z> axis, if it is 'false' tics are plotted on the
20371     border.
20372
20373     Since this is a global graphics option, its position in the scene
20374     description does not matter.
20375
20376 -- Graphic option: ztics_rotate
20377     Default value: 'false'
20378
20379     If 'ztics_rotate' is 'true', tic marks on the <z> axis are rotated
20380     90 degrees.
20381
20382     Since this is a global graphics option, its position in the scene
20383     description does not matter.
20384
2038553.2.4 Graphics objects
20386-----------------------
20387
20388 -- Graphic object: bars ([<x1>,<h1>,<w1>], [<x2>,<h2>,<w2>, ...])
20389     Draws vertical bars in 2D.
20390
20391     2D
20392
20393     'bars ([<x1>,<h1>,<w1>], [<x2>,<h2>,<w2>, ...])' draws bars
20394     centered at values <x1>, <x2>, ...  with heights <h1>, <h2>, ...
20395     and widths <w1>, <w2>, ...
20396
20397     This object is affected by the following graphic options: 'key',
20398     'fill_color', 'fill_density' and 'line_width'.
20399
20400     Example:
20401
20402          (%i1) draw2d(
20403                 key          = "Group A",
20404                 fill_color   = blue,
20405                 fill_density = 0.2,
20406                 bars([0.8,5,0.4],[1.8,7,0.4],[2.8,-4,0.4]),
20407                 key          = "Group B",
20408                 fill_color   = red,
20409                 fill_density = 0.6,
20410                 line_width   = 4,
20411                 bars([1.2,4,0.4],[2.2,-2,0.4],[3.2,5,0.4]),
20412                 xaxis = true);
20413     (Figure draw_bars)
20414
20415 -- Graphic object: cylindrical (<radius>, <z>, <minz>, <maxz>, <azi>,
20416          <minazi>, <maxazi>)
20417     Draws 3D functions defined in cylindrical coordinates.
20418
20419     3D
20420
20421     'cylindrical(<radius>, <z>, <minz>, <maxz>, <azi>, <minazi>,
20422     <maxazi>)' plots the function '<radius>(<z>, <azi>)' defined in
20423     cylindrical coordinates, with variable <z> taking values from
20424     <minz> to <maxz> and azimuth <azi> taking values from <minazi> to
20425     <maxazi>.
20426
20427     This object is affected by the following graphic options:
20428     'xu_grid', 'yv_grid', 'line_type', 'key', 'wired_surface',
20429     'enhanced3d' and 'color'
20430
20431     Example:
20432
20433          (%i1) draw3d(cylindrical(1,z,-2,2,az,0,2*%pi))$
20434     (Figure draw_cylindrical)
20435
20436 -- Graphic object: elevation_grid (<mat>,<x0>,<y0>,<width>,<height>)
20437     Draws matrix <mat> in 3D space.  <z> values are taken from <mat>,
20438     the abscissas range from <x0> to <x0> + <width> and ordinates from
20439     <y0> to <y0> + <height>.  Element a(1,1) is projected on point
20440     (x0,y0+height), a(1,n) on (x0+width,y0+height), a(m,1) on (x0,y0),
20441     and a(m,n) on (x0+width,y0).
20442
20443     This object is affected by the following graphic options:
20444     'line_type',, 'line_width' 'key', 'wired_surface', 'enhanced3d' and
20445     'color'
20446
20447     In older versions of Maxima, 'elevation_grid' was called 'mesh'.
20448     See also 'mesh'.
20449
20450     Example:
20451
20452          (%i1) m: apply(
20453                      matrix,
20454                      makelist(makelist(random(10.0),k,1,30),i,1,20)) $
20455          (%i2) draw3d(
20456                   color = blue,
20457                   elevation_grid(m,0,0,3,2),
20458                   xlabel = "x",
20459                   ylabel = "y",
20460                   surface_hide = true);
20461     (Figure draw_elevation_grid)
20462
20463 -- Graphic object: ellipse (<xc>, <yc>, <a>, <b>, <ang1>, <ang2>)
20464     Draws ellipses and circles in 2D.
20465
20466     2D
20467
20468     'ellipse (<xc>, <yc>, <a>, <b>, <ang1>, <ang2>)' plots an ellipse
20469     centered at '[<xc>, <yc>]' with horizontal and vertical semi axis
20470     <a> and <b>, respectively, starting at angle <ang1> with an
20471     amplitude equal to angle <ang2>.
20472
20473     This object is affected by the following graphic options: 'nticks',
20474     'transparent', 'fill_color', 'border', 'line_width', 'line_type',
20475     'key' and 'color'
20476
20477     Example:
20478
20479          (%i1) draw2d(transparent = false,
20480                       fill_color  = red,
20481                       color       = gray30,
20482                       transparent = false,
20483                       line_width  = 5,
20484                       ellipse(0,6,3,2,270,-270),
20485                       /* center (x,y), a, b, start & end in degrees */
20486                       transparent = true,
20487                       color       = blue,
20488                       line_width  = 3,
20489                       ellipse(2.5,6,2,3,30,-90),
20490                       xrange      = [-3,6],
20491                       yrange      = [2,9] )$
20492     (Figure draw_ellipse)
20493
20494 -- Graphic object: errors ([<x1>, <x2>, ...], [<y1>, <y2>, ...])
20495     Draws points with error bars, horizontally, vertically or both,
20496     depending on the value of option 'error_type'.
20497
20498     2D
20499
20500     If 'error_type = x', arguments to 'errors' must be of the form '[x,
20501     y, xdelta]' or '[x, y, xlow, xhigh]'.  If 'error_type = y',
20502     arguments must be of the form '[x, y, ydelta]' or '[x, y, ylow,
20503     yhigh]'.  If 'error_type = xy' or 'error_type = boxes', arguments
20504     to 'errors' must be of the form '[x, y, xdelta, ydelta]' or '[x, y,
20505     xlow, xhigh, ylow, yhigh]'.
20506
20507     See also 'error_type'.
20508
20509     This object is affected by the following graphic options:
20510     'error_type', 'points_joined', 'line_width', 'key', 'line_type',
20511     'color' 'fill_density', 'xaxis_secondary' and 'yaxis_secondary'.
20512
20513     Option 'fill_density' is only relevant when 'error_type=boxes'.
20514
20515     Examples:
20516
20517     Horizontal error bars.
20518
20519          (%i1) draw2d(
20520                  error_type = 'y,
20521                  errors([[1,2,1], [3,5,3], [10,3,1], [17,6,2]]))$
20522     (Figure draw_errors)
20523
20524     Vertical and horizontal error bars.
20525
20526          (%i1) draw2d(
20527                  error_type = 'xy,
20528                  points_joined = true,
20529                  color = blue,
20530                  errors([[1,2,1,2], [3,5,2,1], [10,3,1,1], [17,6,1/2,2]]));
20531     (Figure draw_errors2)
20532
20533 -- Graphic object: explicit
20534          explicit (<expr>,<var>,<minval>,<maxval>)
20535          explicit (<fcn>,<var>,<minval>,<maxval>)
20536          explicit
20537          (<expr>,<var1>,<minval1>,<maxval1>,<var2>,<minval2>,<maxval2>)
20538
20539          explicit
20540          (<fcn>,<var1>,<minval1>,<maxval1>,<var2>,<minval2>,<maxval2>)
20541
20542     Draws explicit functions in 2D and 3D.
20543
20544     2D
20545
20546     'explicit(<fcn>,<var>,<minval>,<maxval>)' plots explicit function
20547     <fcn>, with variable <var> taking values from <minval> to <maxval>.
20548
20549     This object is affected by the following graphic options: 'nticks',
20550     'adapt_depth', 'draw_realpart', 'line_width', 'line_type', 'key',
20551     'filled_func', 'fill_color' and 'color'
20552
20553     Example:
20554
20555          (%i1) draw2d(line_width = 3,
20556                       color      = blue,
20557                       explicit(x^2,x,-3,3) )$
20558     (Figure draw_explicit)
20559          (%i2) draw2d(fill_color  = brown,
20560                       filled_func = true,
20561                       explicit(x^2,x,-3,3) )$
20562     (Figure draw_explicit2)
20563
20564     3D
20565
20566     'explicit(<fcn>, <var1>, <minval1>, <maxval1>, <var2>, <minval2>,
20567     <maxval2>)' plots the explicit function <fcn>, with variable <var1>
20568     taking values from <minval1> to <maxval1> and variable <var2>
20569     taking values from <minval2> to <maxval2>.
20570
20571     This object is affected by the following graphic options:
20572     'draw_realpart', 'xu_grid', 'yv_grid', 'line_type', 'line_width',
20573     'key', 'wired_surface', 'enhanced3d' and 'color'.
20574
20575     Example:
20576
20577          (%i1) draw3d(key   = "Gauss",
20578                       color = "#a02c00",
20579                       explicit(20*exp(-x^2-y^2)-10,x,-3,3,y,-3,3),
20580                       yv_grid     = 10,
20581                       color = blue,
20582                       key   = "Plane",
20583                       explicit(x+y,x,-5,5,y,-5,5),
20584                       surface_hide = true)$
20585     (Figure draw_explicit3)
20586
20587     See also 'filled_func' for filled functions.
20588
20589 -- Graphic object: image (<im>,<x0>,<y0>,<width>,<height>)
20590     Renders images in 2D.
20591
20592     2D
20593
20594     'image (<im>,<x0>,<y0>,<width>,<height>)' plots image <im> in the
20595     rectangular region from vertex '(<x0>,<y0>)' to
20596     '(x0+<width>,y0+<height>)' on the real plane.  Argument <im> must
20597     be a matrix of real numbers, a matrix of vectors of length three or
20598     a <picture> object.
20599
20600     If <im> is a matrix of real numbers or a <levels picture> object,
20601     pixel values are interpreted according to graphic option 'palette',
20602     which is a vector of length three with components ranging from -36
20603     to +36; each value is an index for a formula mapping the levels
20604     onto red, green and blue colors, respectively:
20605           0: 0               1: 0.5           2: 1
20606           3: x               4: x^2           5: x^3
20607           6: x^4             7: sqrt(x)       8: sqrt(sqrt(x))
20608           9: sin(90x)       10: cos(90x)     11: |x-0.5|
20609          12: (2x-1)^2       13: sin(180x)    14: |cos(180x)|
20610          15: sin(360x)      16: cos(360x)    17: |sin(360x)|
20611          18: |cos(360x)|    19: |sin(720x)|  20: |cos(720x)|
20612          21: 3x             22: 3x-1         23: 3x-2
20613          24: |3x-1|         25: |3x-2|       26: (3x-1)/2
20614          27: (3x-2)/2       28: |(3x-1)/2|   29: |(3x-2)/2|
20615          30: x/0.32-0.78125                  31: 2*x-0.84
20616          32: 4x;1;-2x+1.84;x/0.08-11.5
20617          33: |2*x - 0.5|    34: 2*x          35: 2*x - 0.5
20618          36: 2*x - 1
20619     negative numbers mean negative colour component.
20620
20621     'palette = gray' and 'palette = color' are short cuts for 'palette
20622     = [3,3,3]' and 'palette = [7,5,15]', respectively.
20623
20624     If <im> is a matrix of vectors of length three or an <rgb picture>
20625     object, they are interpreted as red, green and blue color
20626     components.
20627
20628     Examples:
20629
20630     If <im> is a matrix of real numbers, pixel values are interpreted
20631     according to graphic option 'palette'.
20632          (%i1) im: apply(
20633                     'matrix,
20634                      makelist(makelist(random(200),i,1,30),i,1,30))$
20635          (%i2) /* palette = color, default */
20636                draw2d(image(im,0,0,30,30))$
20637     (Figure draw_image)
20638          (%i3) draw2d(palette = gray, image(im,0,0,30,30))$
20639     (Figure draw_image2)
20640          (%i4) draw2d(palette = [15,20,-4],
20641                       colorbox=false,
20642                       image(im,0,0,30,30))$
20643     (Figure draw_image3)
20644
20645     See also 'colorbox'.
20646
20647     If <im> is a matrix of vectors of length three, they are
20648     interpreted as red, green and blue color components.
20649          (%i1) im: apply(
20650                      'matrix,
20651                       makelist(
20652                         makelist([random(300),
20653                                   random(300),
20654                                   random(300)],i,1,30),i,1,30))$
20655          (%i2) draw2d(image(im,0,0,30,30))$
20656     (Figure draw_image4)
20657
20658     Package 'draw' automatically loads package 'picture'.  In this
20659     example, a level picture object is built by hand and then rendered.
20660          (%i1) im: make_level_picture([45,87,2,134,204,16],3,2);
20661          (%o1)       picture(level, 3, 2, {Array:  #(45 87 2 134 204 16)})
20662          (%i2) /* default color palette */
20663                draw2d(image(im,0,0,30,30))$
20664     (Figure draw_image5)
20665          (%i3) /* gray palette */
20666                draw2d(palette = gray,
20667                       image(im,0,0,30,30))$
20668     (Figure draw_image6)
20669
20670     An xpm file is read and then rendered.
20671          (%i1) im: read_xpm("myfile.xpm")$
20672          (%i2) draw2d(image(im,0,0,10,7))$
20673
20674     See also 'make_level_picture', 'make_rgb_picture' and 'read_xpm'.
20675
20676     <http://www.telefonica.net/web2/biomates/maxima/gpdraw/image>
20677     contains more elaborated examples.
20678
20679 -- Graphic object: implicit
20680          implicit (<fcn>,<x>,<xmin>,<xmax>,<y>,<ymin>,<ymax>)
20681          implicit
20682          (<fcn>,<x>,<xmin>,<xmax>,<y>,<ymin>,<ymax>,<z>,<zmin>,<zmax>)
20683
20684     Draws implicit functions in 2D and 3D.
20685
20686     2D
20687
20688     'implicit(<fcn>,<x>,<xmin>,<xmax>,<y>,<ymin>,<ymax>)' plots the
20689     implicit function defined by <fcn>, with variable <x> taking values
20690     from <xmin> to <xmax>, and variable <y> taking values from <ymin>
20691     to <ymax>.
20692
20693     This object is affected by the following graphic options:
20694     'ip_grid', 'ip_grid_in', 'line_width', 'line_type', 'key' and
20695     'color'.
20696
20697     Example:
20698
20699          (%i1) draw2d(grid      = true,
20700                       line_type = solid,
20701                       key       = "y^2=x^3-2*x+1",
20702                       implicit(y^2=x^3-2*x+1, x, -4,4, y, -4,4),
20703                       line_type = dots,
20704                       key       = "x^3+y^3 = 3*x*y^2-x-1",
20705                       implicit(x^3+y^3 = 3*x*y^2-x-1, x,-4,4, y,-4,4),
20706                       title     = "Two implicit functions" )$
20707     (Figure draw_implicit)
20708
20709     3D
20710
20711     'implicit (<fcn>,<x>,<xmin>,<xmax>, <y>,<ymin>,<ymax>,
20712     <z>,<zmin>,<zmax>)' plots the implicit surface defined by <fcn>,
20713     with variable <x> taking values from <xmin> to <xmax>, variable <y>
20714     taking values from <ymin> to <ymax> and variable <z> taking values
20715     from <zmin> to <zmax>.  This object implements the marching cubes
20716     algorithm.
20717
20718     This object is affected by the following graphic options:
20719     'x_voxel', 'y_voxel', 'z_voxel', 'line_width', 'line_type', 'key',
20720     'wired_surface', 'enhanced3d' and 'color'.
20721
20722     Example:
20723
20724          (%i1) draw3d(
20725                  color=blue,
20726                  implicit((x^2+y^2+z^2-1)*(x^2+(y-1.5)^2+z^2-0.5)=0.015,
20727                           x,-1,1,y,-1.2,2.3,z,-1,1),
20728                  surface_hide=true);
20729     (Figure draw_implicit2)
20730
20731 -- Graphic object: label
20732          label ([<string>,<x>,<y>],...)
20733          label ([<string>,<x>,<y>,<z>],...)
20734
20735     Writes labels in 2D and 3D.
20736
20737     Colored labels work only with Gnuplot 4.3 and up.
20738
20739     This object is affected by the following graphic options:
20740     'label_alignment', 'label_orientation' and 'color'.
20741
20742     2D
20743
20744     'label([<string>,<x>,<y>])' writes the <string> at point
20745     '[<x>,<y>]'.
20746
20747     Example:
20748
20749          (%i1) draw2d(yrange = [0.1,1.4],
20750                       color = red,
20751                       label(["Label in red",0,0.3]),
20752                       color = "#0000ff",
20753                       label(["Label in blue",0,0.6]),
20754                       color = light_blue,
20755                       label(["Label in light-blue",0,0.9],
20756                             ["Another light-blue",0,1.2])  )$
20757     (Figure draw_label)
20758
20759     3D
20760
20761     'label([<string>,<x>,<y>,<z>])' writes the <string> at point
20762     '[<x>,<y>,<z>]'.
20763
20764     Example:
20765
20766          (%i1) draw3d(explicit(exp(sin(x)+cos(x^2)),x,-3,3,y,-3,3),
20767                       color = red,
20768                       label(["UP 1",-2,0,3], ["UP 2",1.5,0,4]),
20769                       color = blue,
20770                       label(["DOWN 1",2,0,-3]) )$
20771     (Figure draw_label2)
20772
20773 -- Graphic object: mesh (<row_1>,<row_2>,...)
20774     Draws a quadrangular mesh in 3D.
20775
20776     3D
20777
20778     Argument <row_i> is a list of <n> 3D points of the form
20779     '[[x_i1,y_i1,z_i1], ...,[x_in,y_in,z_in]]', and all rows are of
20780     equal length.  All these points define an arbitrary surface in 3D
20781     and in some sense it's a generalization of the 'elevation_grid'
20782     object.
20783
20784     This object is affected by the following graphic options:
20785     'line_type', 'line_width', 'color', 'key', 'wired_surface',
20786     'enhanced3d' and 'transform'.
20787
20788     Examples:
20789
20790     A simple example.
20791
20792          (%i1) draw3d(
20793                   mesh([[1,1,3],   [7,3,1],[12,-2,4],[15,0,5]],
20794                        [[2,7,8],   [4,3,1],[10,5,8], [12,7,1]],
20795                        [[-2,11,10],[6,9,5],[6,15,1], [20,15,2]])) $
20796     (Figure draw_mesh)
20797
20798     Plotting a triangle in 3D.
20799
20800          (%i1) draw3d(
20801                  line_width = 2,
20802                  mesh([[1,0,0],[0,1,0]],
20803                       [[0,0,1],[0,0,1]])) $
20804     (Figure draw_mesh2)
20805
20806     Two quadrilaterals.
20807
20808          (%i1) draw3d(
20809                  surface_hide = true,
20810                  line_width   = 3,
20811                  color = red,
20812                  mesh([[0,0,0], [0,1,0]],
20813                       [[2,0,2], [2,2,2]]),
20814                  color = blue,
20815                  mesh([[0,0,2], [0,1,2]],
20816                       [[2,0,4], [2,2,4]])) $
20817     (Figure draw_mesh3)
20818
20819 -- Graphic object: parametric
20820          parametric (<xfun>,<yfun>,<par>,<parmin>,<parmax>)
20821          parametric (<xfun>,<yfun>,<zfun>,<par>,<parmin>,<parmax>)
20822
20823     Draws parametric functions in 2D and 3D.
20824
20825     This object is affected by the following graphic options: 'nticks',
20826     'line_width', 'line_type', 'key', 'color' and 'enhanced3d'.
20827
20828     2D
20829
20830     The command 'parametric(<xfun>, <yfun>, <par>, <parmin>, <parmax>)'
20831     plots the parametric function '[<xfun>, <yfun>]', with parameter
20832     <par> taking values from <parmin> to <parmax>.
20833
20834     Example:
20835
20836          (%i1) draw2d(explicit(exp(x),x,-1,3),
20837                       color = red,
20838                       key   = "This is the parametric one!!",
20839                       parametric(2*cos(rrr),rrr^2,rrr,0,2*%pi))$
20840     (Figure draw_parametric)
20841
20842     3D
20843
20844     'parametric(<xfun>, <yfun>, <zfun>, <par>, <parmin>, <parmax>)'
20845     plots the parametric curve '[<xfun>, <yfun>, <zfun>]', with
20846     parameter <par> taking values from <parmin> to <parmax>.
20847
20848     Example:
20849
20850          (%i1) draw3d(explicit(exp(sin(x)+cos(x^2)),x,-3,3,y,-3,3),
20851                       color = royalblue,
20852                       parametric(cos(5*u)^2,sin(7*u),u-2,u,0,2),
20853                       color      = turquoise,
20854                       line_width = 2,
20855                       parametric(t^2,sin(t),2+t,t,0,2),
20856                       surface_hide = true,
20857                       title = "Surface & curves" )$
20858     (Figure draw_parametric2)
20859
20860 -- Graphic object: parametric_surface (<xfun>, <yfun>, <zfun>, <par1>,
20861          <par1min>, <par1max>, <par2>, <par2min>, <par2max>)
20862     Draws parametric surfaces in 3D.
20863
20864     3D
20865
20866     The command 'parametric_surface(<xfun>, <yfun>, <zfun>, <par1>,
20867     <par1min>, <par1max>, <par2>, <par2min>, <par2max>)' plots the
20868     parametric surface '[<xfun>, <yfun>, <zfun>]', with parameter
20869     <par1> taking values from <par1min> to <par1max> and parameter
20870     <par2> taking values from <par2min> to <par2max>.
20871
20872     This object is affected by the following graphic options:
20873     'draw_realpart', 'xu_grid', 'yv_grid', 'line_type', 'line_width',
20874     'key', 'wired_surface', 'enhanced3d' and 'color'.
20875
20876     Example:
20877
20878          (%i1) draw3d(title          = "Sea shell",
20879                       xu_grid        = 100,
20880                       yv_grid        = 25,
20881                       view           = [100,20],
20882                       surface_hide   = true,
20883                       parametric_surface(0.5*u*cos(u)*(cos(v)+1),
20884                                     0.5*u*sin(u)*(cos(v)+1),
20885                                     u*sin(v) - ((u+3)/8*%pi)^2 - 20,
20886                                     u, 0, 13*%pi, v, -%pi, %pi) )$
20887     (Figure draw_parametric3)
20888
20889 -- Graphic object: points
20890          points ([[<x1>,<y1>], [<x2>,<y2>],...])
20891          points ([<x1>,<x2>,...], [<y1>,<y2>,...])
20892          points ([<y1>,<y2>,...])
20893          points ([[<x1>,<y1>,<z1>], [<x2>,<y2>,<z2>],...])
20894          points ([<x1>,<x2>,...], [<y1>,<y2>,...], [<z1>,<z2>,...])
20895          points (<matrix>)
20896          points (<1d_y_array>)
20897          points (<1d_x_array>, <1d_y_array>)
20898          points (<1d_x_array>, <1d_y_array>, <1d_z_array>)
20899          points (<2d_xy_array>)
20900          points (<2d_xyz_array>)
20901
20902     Draws points in 2D and 3D.
20903
20904     This object is affected by the following graphic options:
20905     'point_size', 'point_type', 'points_joined', 'line_width', 'key',
20906     'line_type' and 'color'.  In 3D mode, it is also affected by
20907     'enhanced3d'
20908
20909     2D
20910
20911     'points ([[<x1>,<y1>], [<x2>,<y2>],...])' or 'points
20912     ([<x1>,<x2>,...], [<y1>,<y2>,...])' plots points '[x1,y1]',
20913     '[x2,y2]', etc.  If abscissas are not given, they are set to
20914     consecutive positive integers, so that 'points ([<y1>,<y2>,...])'
20915     draws points '[1,<y1>]', '[2,<y2>]', etc.  If <matrix> is a
20916     two-column or two-row matrix, 'points (<matrix>)' draws the
20917     associated points.  If <matrix> is a one-column or one-row matrix,
20918     abscissas are assigned automatically.
20919
20920     If <1d_y_array> is a 1D lisp array of numbers, 'points
20921     (<1d_y_array>)' plots them setting abscissas to consecutive
20922     positive integers.  'points (<1d_x_array>, <1d_y_array>)' plots
20923     points with their coordinates taken from the two arrays passed as
20924     arguments.  If <2d_xy_array> is a 2D array with two columns, or
20925     with two rows, 'points (<2d_xy_array>)' plots the corresponding
20926     points on the plane.
20927
20928     Examples:
20929
20930     Two types of arguments for 'points', a list of pairs and two lists
20931     of separate coordinates.
20932          (%i1) draw2d(
20933                  key = "Small points",
20934                  points(makelist([random(20),random(50)],k,1,10)),
20935                  point_type    = circle,
20936                  point_size    = 3,
20937                  points_joined = true,
20938                  key           = "Great points",
20939                  points(makelist(k,k,1,20),makelist(random(30),k,1,20)),
20940                  point_type    = filled_down_triangle,
20941                  key           = "Automatic abscissas",
20942                  color         = red,
20943                  points([2,12,8]))$
20944     (Figure draw_points)
20945
20946     Drawing impulses.
20947          (%i1) draw2d(
20948                  points_joined = impulses,
20949                  line_width    = 2,
20950                  color         = red,
20951                  points(makelist([random(20),random(50)],k,1,10)))$
20952     (Figure draw_points2)
20953
20954     Array with ordinates.
20955          (%i1) a: make_array (flonum, 100) $
20956          (%i2) for i:0 thru 99 do a[i]: random(1.0) $
20957          (%i3) draw2d(points(a)) $
20958     (Figure draw_points3)
20959
20960     Two arrays with separate coordinates.
20961          (%i1) x: make_array (flonum, 100) $
20962          (%i2) y: make_array (fixnum, 100) $
20963          (%i3) for i:0 thru 99 do (
20964                  x[i]: float(i/100),
20965                  y[i]: random(10) ) $
20966          (%i4) draw2d(points(x, y)) $
20967     (Figure draw_points4)
20968
20969     A two-column 2D array.
20970          (%i1) xy: make_array(flonum, 100, 2) $
20971          (%i2) for i:0 thru 99 do (
20972                  xy[i, 0]: float(i/100),
20973                  xy[i, 1]: random(10) ) $
20974          (%i3) draw2d(points(xy)) $
20975     (Figure draw_points5)
20976
20977     Drawing an array filled with function 'read_array'.
20978          (%i1) a: make_array(flonum,100) $
20979          (%i2) read_array (file_search ("pidigits.data"), a) $
20980          (%i3) draw2d(points(a)) $
20981
20982     3D
20983
20984     'points([[<x1>, <y1>, <z1>], [<x2>, <y2>, <z2>], ...])' or
20985     'points([<x1>, <x2>, ...], [<y1>, <y2>, ...], [<z1>, <z2>,...])'
20986     plots points '[<x1>, <y1>, <z1>]', '[<x2>, <y2>, <z2>]', etc.  If
20987     <matrix> is a three-column or three-row matrix, 'points (<matrix>)'
20988     draws the associated points.
20989
20990     When arguments are lisp arrays, 'points (<1d_x_array>,
20991     <1d_y_array>, <1d_z_array>)' takes coordinates from the three 1D
20992     arrays.  If <2d_xyz_array> is a 2D array with three columns, or
20993     with three rows, 'points (<2d_xyz_array>)' plots the corresponding
20994     points.
20995
20996     Examples:
20997
20998     One tridimensional sample,
20999          (%i1) load ("numericalio")$
21000          (%i2) s2 : read_matrix (file_search ("wind.data"))$
21001          (%i3) draw3d(title = "Daily average wind speeds",
21002                       point_size = 2,
21003                       points(args(submatrix (s2, 4, 5))) )$
21004
21005     Two tridimensional samples,
21006          (%i1) load ("numericalio")$
21007          (%i2) s2 : read_matrix (file_search ("wind.data"))$
21008          (%i3) draw3d(
21009                   title = "Daily average wind speeds. Two data sets",
21010                   point_size = 2,
21011                   key        = "Sample from stations 1, 2 and 3",
21012                   points(args(submatrix (s2, 4, 5))),
21013                   point_type = 4,
21014                   key        = "Sample from stations 1, 4 and 5",
21015                   points(args(submatrix (s2, 2, 3))) )$
21016
21017     Unidimensional arrays,
21018          (%i1) x: make_array (fixnum, 10) $
21019          (%i2) y: make_array (fixnum, 10) $
21020          (%i3) z: make_array (fixnum, 10) $
21021          (%i4) for i:0 thru 9 do (
21022                  x[i]: random(10),
21023                  y[i]: random(10),
21024                  z[i]: random(10) ) $
21025          (%i5) draw3d(points(x,y,z)) $
21026     (Figure draw_points6)
21027
21028     Bidimensional colored array,
21029          (%i1) xyz: make_array(fixnum, 10, 3) $
21030          (%i2) for i:0 thru 9 do (
21031                  xyz[i, 0]: random(10),
21032                  xyz[i, 1]: random(10),
21033                  xyz[i, 2]: random(10) ) $
21034          (%i3) draw3d(
21035                   enhanced3d = true,
21036                   points_joined = true,
21037                   points(xyz)) $
21038     (Figure draw_points7)
21039
21040     Color numbers explicitly specified by the user.
21041          (%i1) pts: makelist([t,t^2,cos(t)], t, 0, 15)$
21042          (%i2) col_num: makelist(k, k, 1, length(pts))$
21043          (%i3) draw3d(
21044                  enhanced3d = ['part(col_num,k),k],
21045                  point_size = 3,
21046                  point_type = filled_circle,
21047                  points(pts))$
21048     (Figure draw_points8)
21049
21050 -- Graphic object: polar (<radius>,<ang>,<minang>,<maxang>)
21051     Draws 2D functions defined in polar coordinates.
21052
21053     2D
21054
21055     'polar (<radius>,<ang>,<minang>,<maxang>)' plots function
21056     '<radius>(<ang>)' defined in polar coordinates, with variable <ang>
21057     taking values from <minang> to <maxang>.
21058
21059     This object is affected by the following graphic options: 'nticks',
21060     'line_width', 'line_type', 'key' and 'color'.
21061
21062     Example:
21063
21064          (%i1) draw2d(user_preamble = "set grid polar",
21065                       nticks        = 200,
21066                       xrange        = [-5,5],
21067                       yrange        = [-5,5],
21068                       color         = blue,
21069                       line_width    = 3,
21070                       title         = "Hyperbolic Spiral",
21071                       polar(10/theta,theta,1,10*%pi) )$
21072     (Figure draw_polar)
21073
21074 -- Graphic object: polygon
21075          polygon ([[<x1>, <y1>], [<x2>, <y2>], ...])
21076          polygon ([<x1>, <x2>, ...], [<y1>, <y2>, ...])
21077
21078     Draws polygons in 2D.
21079
21080     2D
21081
21082     The commands 'polygon([[<x1>, <y1>], [<x2>, <y2>], ...])' or
21083     'polygon([<x1>, <x2>, ...], [<y1>, <y2>, ...])' plot on the plane a
21084     polygon with vertices '[<x1>, <y1>]', '[<x2>, <y2>]', etc.
21085
21086     This object is affected by the following graphic options:
21087     'transparent', 'fill_color', 'border', 'line_width', 'key',
21088     'line_type' and 'color'.
21089
21090     Example:
21091
21092          (%i1) draw2d(color      = "#e245f0",
21093                       line_width = 8,
21094                       polygon([[3,2],[7,2],[5,5]]),
21095                       border      = false,
21096                       fill_color  = yellow,
21097                       polygon([[5,2],[9,2],[7,5]]) )$
21098     (Figure draw_polygon)
21099
21100 -- Graphic object: quadrilateral (<point_1>, <point_2>, <point_3>,
21101          <point_4>)
21102     Draws a quadrilateral.
21103
21104     2D
21105
21106     'quadrilateral([<x1>, <y1>], [<x2>, <y2>], [<x3>, <y3>], [<x4>,
21107     <y4>])' draws a quadrilateral with vertices '[<x1>, <y1>]', '[<x2>,
21108     <y2>]', '[<x3>, <y3>]', and '[<x4>, <y4>]'.
21109
21110     This object is affected by the following graphic options:
21111     'transparent', 'fill_color', 'border', 'line_width', 'key',
21112     'xaxis_secondary', 'yaxis_secondary', 'line_type', 'transform' and
21113     'color'.
21114
21115     Example:
21116
21117          (%i1) draw2d(
21118                  quadrilateral([1,1],[2,2],[3,-1],[2,-2]))$
21119     (Figure draw_quadrilateral)
21120
21121     3D
21122
21123     'quadrilateral([<x1>, <y1>, <z1>], [<x2>, <y2>, <z2>], [<x3>, <y3>,
21124     <z3>], [<x4>, <y4>, <z4>])' draws a quadrilateral with vertices
21125     '[<x1>, <y1>, <z1>]', '[<x2>, <y2>, <z2>]', '[<x3>, <y3>, <z3>]',
21126     and '[<x4>, <y4>, <z4>]'.
21127
21128     This object is affected by the following graphic options:
21129     'line_type', 'line_width', 'color', 'key', 'enhanced3d' and
21130     'transform'.
21131
21132 -- Graphic object: rectangle ([<x1>,<y1>], [<x2>,<y2>])
21133     Draws rectangles in 2D.
21134
21135     2D
21136
21137     'rectangle ([<x1>,<y1>], [<x2>,<y2>])' draws a rectangle with
21138     opposite vertices '[<x1>,<y1>]' and '[<x2>,<y2>]'.
21139
21140     This object is affected by the following graphic options:
21141     'transparent', 'fill_color', 'border', 'line_width', 'key',
21142     'line_type' and 'color'.
21143
21144     Example:
21145
21146          (%i1) draw2d(fill_color  = red,
21147                       line_width  = 6,
21148                       line_type   = dots,
21149                       transparent = false,
21150                       fill_color  = blue,
21151                       rectangle([-2,-2],[8,-1]), /* opposite vertices */
21152                       transparent = true,
21153                       line_type   = solid,
21154                       line_width  = 1,
21155                       rectangle([9,4],[2,-1.5]),
21156                       xrange      = [-3,10],
21157                       yrange      = [-3,4.5] )$
21158     (Figure draw_rectangle)
21159
21160 -- Graphic object: region
21161          (<expr>,<var1>,<minval1>,<maxval1>,<var2>,<minval2>,<maxval2>)
21162     Plots a region on the plane defined by inequalities.
21163
21164     2D <expr> is an expression formed by inequalities and boolean
21165     operators 'and', 'or', and 'not'.  The region is bounded by the
21166     rectangle defined by [<minval1>, <maxval1>] and [<minval2>,
21167     <maxval2>].
21168
21169     This object is affected by the following graphic options:
21170     'fill_color', 'key', 'x_voxel' and 'y_voxel'.
21171
21172     Example:
21173
21174          (%i1) draw2d(
21175                  x_voxel = 30,
21176                  y_voxel = 30,
21177                  region(x^2+y^2<1 and x^2+y^2 > 1/2,
21178                         x, -1.5, 1.5, y, -1.5, 1.5));
21179   (Figure draw_region)
21180
21181 -- Graphic object: spherical (<radius>, <azi>, <minazi>, <maxazi>,
21182          <zen>, <minzen>, <maxzen>)
21183     Draws 3D functions defined in spherical coordinates.
21184
21185     3D
21186
21187     'spherical(<radius>, <azi>, <minazi>, <maxazi>, <zen>, <minzen>,
21188     <maxzen>)' plots the function '<radius>(<azi>, <zen>)' defined in
21189     spherical coordinates, with azimuth <azi> taking values from
21190     <minazi> to <maxazi> and zenith <zen> taking values from <minzen>
21191     to <maxzen>.
21192
21193     This object is affected by the following graphic options:
21194     'xu_grid', 'yv_grid', 'line_type', 'key', 'wired_surface',
21195     'enhanced3d' and 'color'.
21196
21197     Example:
21198
21199          (%i1) draw3d(spherical(1,a,0,2*%pi,z,0,%pi))$
21200     (Figure draw_spherical)
21201
21202 -- Graphic object: triangle (<point_1>, <point_2>, <point_3>)
21203     Draws a triangle.
21204
21205     2D
21206
21207     'triangle ([<x1>,<y1>], [<x2>,<y2>], [<x3>,<y3>])' draws a triangle
21208     with vertices '[<x1>,<y1>]', '[<x2>,<y2>]', and '[<x3>,<y3>]'.
21209
21210     This object is affected by the following graphic options:
21211     'transparent', 'fill_color', 'border', 'line_width', 'key',
21212     'xaxis_secondary', 'yaxis_secondary', 'line_type', 'transform' and
21213     'color'.
21214
21215     Example:
21216
21217          (%i1) draw2d(
21218                  triangle([1,1],[2,2],[3,-1]))$
21219     (Figure draw_triangle)
21220
21221     3D
21222
21223     'triangle ([<x1>,<y1>,<z1>], [<x2>,<y2>,<z2>], [<x3>,<y3>,<z3>])'
21224     draws a triangle with vertices '[<x1>,<y1>,<z1>]',
21225     '[<x2>,<y2>,<z2>]', and '[<x3>,<y3>,<z3>]'.
21226
21227     This object is affected by the following graphic options:
21228     'line_type', 'line_width', 'color', 'key', 'enhanced3d' and
21229     'transform'.
21230
21231 -- Graphic object: tube (<xfun>,<yfun>,<zfun>,<rfun>,<p>,<pmin>,<pmax>)
21232     Draws a tube in 3D with varying diameter.
21233
21234     3D
21235
21236     '[<xfun>,<yfun>,<zfun>]' is the parametric curve with parameter <p>
21237     taking values from <pmin> to <pmax>.  Circles of radius <rfun> are
21238     placed with their centers on the parametric curve and perpendicular
21239     to it.
21240
21241     This object is affected by the following graphic options:
21242     'xu_grid', 'yv_grid', 'line_type', 'line_width', 'key',
21243     'wired_surface', 'enhanced3d', 'color' and 'capping'.
21244
21245     Example:
21246
21247          (%i1) draw3d(
21248                  enhanced3d = true,
21249                  xu_grid = 50,
21250                  tube(cos(a), a, 0, cos(a/10)^2,
21251                       a, 0, 4*%pi) )$
21252     (Figure draw_tube)
21253
21254 -- Graphic object: vector
21255          vector ([<x>,<y>], [<dx>,<dy>])
21256          vector ([<x>,<y>,<z>], [<dx>,<dy>,<dz>])
21257
21258     Draws vectors in 2D and 3D.
21259
21260     This object is affected by the following graphic options:
21261     'head_both', 'head_length', 'head_angle', 'head_type',
21262     'line_width', 'line_type', 'key' and 'color'.
21263
21264     2D
21265
21266     'vector([<x>,<y>], [<dx>,<dy>])' plots vector '[<dx>,<dy>]' with
21267     origin in '[<x>,<y>]'.
21268
21269     Example:
21270
21271          (%i1) draw2d(xrange      = [0,12],
21272                       yrange      = [0,10],
21273                       head_length = 1,
21274                       vector([0,1],[5,5]), /* default type */
21275                       head_type = 'empty,
21276                       vector([3,1],[5,5]),
21277                       head_both = true,
21278                       head_type = 'nofilled,
21279                       line_type = dots,
21280                       vector([6,1],[5,5]))$
21281     (Figure draw_vector)
21282
21283     3D
21284
21285     'vector([<x>,<y>,<z>], [<dx>,<dy>,<dz>])' plots vector
21286     '[<dx>,<dy>,<dz>]' with origin in '[<x>,<y>,<z>]'.
21287
21288     Example:
21289
21290          (%i1) draw3d(color = cyan,
21291                       vector([0,0,0],[1,1,1]/sqrt(3)),
21292                       vector([0,0,0],[1,-1,0]/sqrt(2)),
21293                       vector([0,0,0],[1,1,-2]/sqrt(6)) )$
21294     (Figure draw_vector2)
21295
21296
21297File: maxima.info,  Node: Functions and Variables for pictures,  Next: Functions and Variables for worldmap,  Prev: Functions and Variables for draw,  Up: draw-pkg
21298
2129953.3 Functions and Variables for pictures
21300=========================================
21301
21302 -- Function: get_pixel (<pic>,<x>,<y>)
21303     Returns pixel from picture.  Coordinates <x> and <y> range from 0
21304     to 'width-1' and 'height-1', respectively.
21305
21306 -- Function: make_level_picture
21307          make_level_picture (<data>)
21308          make_level_picture (<data>,<width>,<height>)
21309
21310     Returns a levels <picture> object.  'make_level_picture (<data>)'
21311     builds the <picture> object from matrix <data>.
21312     'make_level_picture (<data>,<width>,<height>)' builds the object
21313     from a list of numbers; in this case, both the <width> and the
21314     <height> must be given.
21315
21316     The returned <picture> object contains the following four parts:
21317
21318       1. symbol 'level'
21319       2. image width
21320       3. image height
21321       4. an integer array with pixel data ranging from 0 to 255.
21322          Argument <data> must contain only numbers ranged from 0 to
21323          255; negative numbers are substituted by 0, and those which
21324          are greater than 255 are set to 255.
21325
21326     Example:
21327
21328     Level picture from matrix.
21329          (%i1) make_level_picture(matrix([3,2,5],[7,-9,3000]));
21330          (%o1)         picture(level, 3, 2, {Array:  #(3 2 5 7 0 255)})
21331
21332     Level picture from numeric list.
21333          (%i1) make_level_picture([-2,0,54,%pi],2,2);
21334          (%o1)            picture(level, 2, 2, {Array:  #(0 0 54 3)})
21335
21336 -- Function: make_rgb_picture (<redlevel>,<greenlevel>,<bluelevel>)
21337     Returns an rgb-coloured <picture> object.  All three arguments must
21338     be levels picture; with red, green and blue levels.
21339
21340     The returned <picture> object contains the following four parts:
21341
21342       1. symbol 'rgb'
21343       2. image width
21344       3. image height
21345       4. an integer array of length <3*width*height> with pixel data
21346          ranging from 0 to 255.  Each pixel is represented by three
21347          consecutive numbers (red, green, blue).
21348
21349     Example:
21350
21351          (%i1) red: make_level_picture(matrix([3,2],[7,260]));
21352          (%o1)           picture(level, 2, 2, {Array:  #(3 2 7 255)})
21353          (%i2) green: make_level_picture(matrix([54,23],[73,-9]));
21354          (%o2)           picture(level, 2, 2, {Array:  #(54 23 73 0)})
21355          (%i3) blue: make_level_picture(matrix([123,82],[45,32.5698]));
21356          (%o3)          picture(level, 2, 2, {Array:  #(123 82 45 33)})
21357          (%i4) make_rgb_picture(red,green,blue);
21358          (%o4) picture(rgb, 2, 2,
21359                        {Array:  #(3 54 123 2 23 82 7 73 45 255 0 33)})
21360
21361 -- Function: negative_picture (<pic>)
21362     Returns the negative of a (<level> or <rgb>) picture.
21363
21364 -- Function: picture_equalp (<x>,<y>)
21365     Returns 'true' in case of equal pictures, and 'false' otherwise.
21366
21367 -- Function: picturep (<x>)
21368     Returns 'true' if the argument is a well formed image, and 'false'
21369     otherwise.
21370
21371 -- Function: read_xpm (<xpm_file>)
21372     Reads a file in xpm and returns a picture object.
21373
21374 -- Function: rgb2level (<pic>)
21375     Transforms an <rgb> picture into a <level> one by averaging the
21376     red, green and blue channels.
21377
21378 -- Function: take_channel (<im>,<color>)
21379     If argument <color> is 'red', 'green' or 'blue', function
21380     'take_channel' returns the corresponding color channel of picture
21381     <im>.  Example:
21382
21383          (%i1) red: make_level_picture(matrix([3,2],[7,260]));
21384          (%o1)           picture(level, 2, 2, {Array:  #(3 2 7 255)})
21385          (%i2) green: make_level_picture(matrix([54,23],[73,-9]));
21386          (%o2)           picture(level, 2, 2, {Array:  #(54 23 73 0)})
21387          (%i3) blue: make_level_picture(matrix([123,82],[45,32.5698]));
21388          (%o3)          picture(level, 2, 2, {Array:  #(123 82 45 33)})
21389          (%i4) make_rgb_picture(red,green,blue);
21390          (%o4) picture(rgb, 2, 2,
21391                        {Array:  #(3 54 123 2 23 82 7 73 45 255 0 33)})
21392          (%i5) take_channel(%,'green);  /* simple quote!!! */
21393          (%o5)           picture(level, 2, 2, {Array:  #(54 23 73 0)})
21394
21395
21396File: maxima.info,  Node: Functions and Variables for worldmap,  Prev: Functions and Variables for pictures,  Up: draw-pkg
21397
2139853.4 Functions and Variables for worldmap
21399=========================================
21400
2140153.4.1 Variables and Functions
21402------------------------------
21403
21404 -- Global variable: boundaries_array
21405     Default value: 'false'
21406
21407     'boundaries_array' is where the graphic object 'geomap' looks for
21408     boundaries coordinates.
21409
21410     Each component of 'boundaries_array' is an array of floating point
21411     quantities, the coordinates of a polygonal segment or map boundary.
21412
21413     See also 'geomap'.
21414
21415 -- Function: numbered_boundaries (<nlist>)
21416     Draws a list of polygonal segments (boundaries), labeled by its
21417     numbers ('boundaries_array' coordinates).  This is of great help
21418     when building new geographical entities.
21419
21420     Example:
21421
21422     Map of Europe labeling borders with their component number in
21423     'boundaries_array'.
21424          (%i1) load(worldmap)$
21425          (%i2) european_borders:
21426                     region_boundaries(-31.81,74.92,49.84,32.06)$
21427          (%i3) numbered_boundaries(european_borders)$
21428
21429 -- Function: make_poly_continent
21430          make_poly_continent (<continent_name>)
21431          make_poly_continent (<country_list>)
21432
21433     Makes the necessary polygons to draw a colored continent or a list
21434     of countries.
21435
21436     Example:
21437
21438          (%i1) load(worldmap)$
21439          (%i2) /* A continent */
21440                make_poly_continent(Africa)$
21441          (%i3) apply(draw2d, %)$
21442     (Figure worldmap_make_poly_continent)
21443          (%i4) /* A list of countries */
21444                make_poly_continent([Germany,Denmark,Poland])$
21445          (%i5) apply(draw2d, %)$
21446     (Figure worldmap_make_poly_continent2)
21447
21448 -- Function: make_poly_country (<country_name>)
21449     Makes the necessary polygons to draw a colored country.  If islands
21450     exist, one country can be defined with more than just one polygon.
21451
21452     Example:
21453
21454          (%i1) load(worldmap)$
21455          (%i2) make_poly_country(India)$
21456          (%i3) apply(draw2d, %)$
21457     (Figure worldmap_make_poly_country)
21458
21459 -- Function: make_polygon (<nlist>)
21460     Returns a 'polygon' object from boundary indices.  Argument <nlist>
21461     is a list of components of 'boundaries_array'.
21462
21463     Example:
21464
21465     Bhutan is defined by boundary numbers 171, 173 and 1143, so that
21466     'make_polygon([171,173,1143])' appends arrays of coordinates
21467     'boundaries_array[171]', 'boundaries_array[173]' and
21468     'boundaries_array[1143]' and returns a 'polygon' object suited to
21469     be plotted by 'draw'.  To avoid an error message, arrays must be
21470     compatible in the sense that any two consecutive arrays have two
21471     coordinates in the extremes in common.  In this example, the two
21472     first components of 'boundaries_array[171]' are equal to the last
21473     two coordinates of 'boundaries_array[173]', and the two first of
21474     'boundaries_array[173]' are equal to the two first of
21475     'boundaries_array[1143]'; in conclussion, boundary numbers 171, 173
21476     and 1143 (in this order) are compatible and the colored polygon can
21477     be drawn.
21478          (%i1) load(worldmap)$
21479          (%i2) Bhutan;
21480          (%o2)                        [[171, 173, 1143]]
21481          (%i3) boundaries_array[171];
21482          (%o3) {Array:
21483                 #(88.750549 27.14727 88.806351 27.25305 88.901367 27.282221
21484                   88.917877 27.321039)}
21485          (%i4) boundaries_array[173];
21486          (%o4) {Array:
21487                 #(91.659554 27.76511 91.6008 27.66666 91.598022 27.62499
21488                   91.631348 27.536381 91.765533 27.45694 91.775253 27.4161
21489                   92.007751 27.471939 92.11441 27.28583 92.015259 27.168051
21490                   92.015533 27.08083 92.083313 27.02277 92.112183 26.920271
21491                   92.069977 26.86194 91.997192 26.85194 91.915253 26.893881
21492                   91.916924 26.85416 91.8358 26.863331 91.712479 26.799999
21493                   91.542191 26.80444 91.492188 26.87472 91.418854 26.873329
21494                   91.371353 26.800831 91.307457 26.778049 90.682457 26.77417
21495                   90.392197 26.903601 90.344131 26.894159 90.143044 26.75333
21496                   89.98996 26.73583 89.841919 26.70138 89.618301 26.72694
21497                   89.636093 26.771111 89.360786 26.859989 89.22081 26.81472
21498                   89.110237 26.829161 88.921631 26.98777 88.873016 26.95499
21499                   88.867737 27.080549 88.843307 27.108601 88.750549
21500                   27.14727)}
21501          (%i5) boundaries_array[1143];
21502          (%o5) {Array:
21503                 #(91.659554 27.76511 91.666924 27.88888 91.65831 27.94805
21504                   91.338028 28.05249 91.314972 28.096661 91.108856 27.971109
21505                   91.015808 27.97777 90.896927 28.05055 90.382462 28.07972
21506                   90.396088 28.23555 90.366074 28.257771 89.996353 28.32333
21507                   89.83165 28.24888 89.58609 28.139999 89.35997 27.87166
21508                   89.225517 27.795 89.125793 27.56749 88.971077 27.47361
21509                   88.917877 27.321039)}
21510          (%i6) Bhutan_polygon: make_polygon([171,173,1143])$
21511          (%i7) draw2d(Bhutan_polygon)$
21512     (Figure worldmap_make_polygon)
21513
21514 -- Function: region_boundaries (<x1>,<y1>,<x2>,<y2>)
21515     Detects polygonal segments of global variable 'boundaries_array'
21516     fully contained in the rectangle with vertices (<x1>,<y1>) -upper
21517     left- and (<x2>,<y2>) -bottom right-.
21518
21519     Example:
21520
21521     Returns segment numbers for plotting southern Italy.
21522          (%i1) load(worldmap)$
21523          (%i2) region_boundaries(10.4,41.5,20.7,35.4);
21524          (%o2)                [1846, 1863, 1864, 1881, 1888, 1894]
21525          (%i3) draw2d(geomap(%))$
21526     (Figure worldmap_region_boundaries)
21527
21528 -- Function: region_boundaries_plus (<x1>,<y1>,<x2>,<y2>)
21529     Detects polygonal segments of global variable 'boundaries_array'
21530     containing at least one vertex in the rectangle defined by vertices
21531     (<x1>,<y1>) -upper left- and (<x2>,<y2>) -bottom right-.
21532
21533     Example:
21534
21535          (%i1) load(worldmap)$
21536          (%i2) region_boundaries_plus(10.4,41.5,20.7,35.4);
21537          (%o2) [1060, 1062, 1076, 1835, 1839, 1844, 1846, 1858,
21538                 1861, 1863, 1864, 1871, 1881, 1888, 1894, 1897]
21539          (%i3) draw2d(geomap(%))$
21540     (Figure worldmap_region_boundaries_plus)
21541
2154253.4.2 Graphic objects
21543----------------------
21544
21545 -- Graphic object: geomap
21546          geomap (<numlist>)
21547          geomap (<numlist>,<3Dprojection>)
21548
21549     Draws cartographic maps in 2D and 3D.
21550
21551     2D
21552
21553     This function works together with global variable
21554     'boundaries_array'.
21555
21556     Argument <numlist> is a list containing numbers or lists of
21557     numbers.  All these numbers must be integers greater or equal than
21558     zero, representing the components of global array
21559     'boundaries_array'.
21560
21561     Each component of 'boundaries_array' is an array of floating point
21562     quantities, the coordinates of a polygonal segment or map boundary.
21563
21564     'geomap (<numlist>)' flattens its arguments and draws the
21565     associated boundaries in 'boundaries_array'.
21566
21567     This object is affected by the following graphic options:
21568     'line_width', 'line_type' and 'color'.
21569
21570     Examples:
21571
21572     A simple map defined by hand:
21573          (%i1) load(worldmap)$
21574          (%i2) /* Vertices of boundary #0: {(1,1),(2,5),(4,3)} */
21575             ( bnd0: make_array(flonum,6),
21576               bnd0[0]:1.0, bnd0[1]:1.0, bnd0[2]:2.0,
21577               bnd0[3]:5.0, bnd0[4]:4.0, bnd0[5]:3.0 )$
21578          (%i3) /* Vertices of boundary #1: {(4,3),(5,4),(6,4),(5,1)} */
21579             ( bnd1: make_array(flonum,8),
21580               bnd1[0]:4.0, bnd1[1]:3.0, bnd1[2]:5.0, bnd1[3]:4.0,
21581               bnd1[4]:6.0, bnd1[5]:4.0, bnd1[6]:5.0, bnd1[7]:1.0)$
21582          (%i4) /* Vertices of boundary #2: {(5,1), (3,0), (1,1)} */
21583             ( bnd2: make_array(flonum,6),
21584               bnd2[0]:5.0, bnd2[1]:1.0, bnd2[2]:3.0,
21585               bnd2[3]:0.0, bnd2[4]:1.0, bnd2[5]:1.0 )$
21586          (%i5) /* Vertices of boundary #3: {(1,1), (4,3)} */
21587             ( bnd3: make_array(flonum,4),
21588               bnd3[0]:1.0, bnd3[1]:1.0, bnd3[2]:4.0, bnd3[3]:3.0)$
21589          (%i6) /* Vertices of boundary #4: {(4,3), (5,1)} */
21590             ( bnd4: make_array(flonum,4),
21591               bnd4[0]:4.0, bnd4[1]:3.0, bnd4[2]:5.0, bnd4[3]:1.0)$
21592          (%i7) /* Pack all together in boundaries_array */
21593             ( boundaries_array: make_array(any,5),
21594               boundaries_array[0]: bnd0, boundaries_array[1]: bnd1,
21595               boundaries_array[2]: bnd2, boundaries_array[3]: bnd3,
21596               boundaries_array[4]: bnd4 )$
21597          (%i8) draw2d(geomap([0,1,2,3,4]))$
21598     (Figure worldmap_geomap)
21599
21600     The auxiliary package 'worldmap' sets the global variable
21601     'boundaries_array' to real world boundaries in (longitude,
21602     latitude) coordinates.  These data are in the public domain and
21603     come from
21604     <https://web.archive.org/web/20100310124019/http://www-cger.nies.go.jp/grid-e/gridtxt/grid19.html>.
21605     Package 'worldmap' defines also boundaries for countries,
21606     continents and coastlines as lists with the necessary components of
21607     'boundaries_array' (see file 'share/draw/worldmap.mac' for more
21608     information).  Package 'worldmap' automatically loads package
21609     'worldmap'.
21610          (%i1) load(worldmap)$
21611          (%i2) c1: gr2d(geomap([Canada,United_States,
21612                                 Mexico,Cuba]))$
21613          (%i3) c2: gr2d(geomap(Africa))$
21614          (%i4) c3: gr2d(geomap([Oceania,China,Japan]))$
21615          (%i5) c4: gr2d(geomap([France,Portugal,Spain,
21616                                 Morocco,Western_Sahara]))$
21617          (%i6) draw(columns  = 2,
21618                     c1,c2,c3,c4)$
21619     (Figure worldmap_geomap2)
21620
21621     Package 'worldmap' is also useful for plotting countries as
21622     polygons.  In this case, graphic object 'geomap' is no longer
21623     necessary and the 'polygon' object is used instead.  Since lists
21624     are now used and not arrays, maps rendering will be slower.  See
21625     also 'make_poly_country' and 'make_poly_continent' to understand
21626     the following code.
21627          (%i1) load(worldmap)$
21628          (%i2) mymap: append(
21629             [color      = white],  /* borders are white */
21630             [fill_color = red],             make_poly_country(Bolivia),
21631             [fill_color = cyan],            make_poly_country(Paraguay),
21632             [fill_color = green],           make_poly_country(Colombia),
21633             [fill_color = blue],            make_poly_country(Chile),
21634             [fill_color = "#23ab0f"],       make_poly_country(Brazil),
21635             [fill_color = goldenrod],       make_poly_country(Argentina),
21636             [fill_color = "midnight-blue"], make_poly_country(Uruguay))$
21637          (%i3) apply(draw2d, mymap)$
21638     (Figure worldmap_geomap3)
21639
21640     3D
21641
21642     'geomap (<numlist>)' projects map boundaries on the sphere of
21643     radius 1 centered at (0,0,0).  It is possible to change the sphere
21644     or the projection type by using 'geomap
21645     (<numlist>,<3Dprojection>)'.
21646
21647     Available 3D projections:
21648
21649        * '[spherical_projection,<x>,<y>,<z>,<r>]': projects map
21650          boundaries on the sphere of radius <r> centered at
21651          (<x>,<y>,<z>).
21652               (%i1) load(worldmap)$
21653               (%i2) draw3d(geomap(Australia), /* default projection */
21654                            geomap(Australia,
21655                                   [spherical_projection,2,2,2,3]))$
21656          (Figure worldmap_geomap4)
21657
21658        * '[cylindrical_projection,<x>,<y>,<z>,<r>,<rc>]': re-projects
21659          spherical map boundaries on the cylinder of radius <rc> and
21660          axis passing through the poles of the globe of radius <r>
21661          centered at (<x>,<y>,<z>).
21662               (%i1) load(worldmap)$
21663               (%i2) draw3d(geomap([America_coastlines,Eurasia_coastlines],
21664                                   [cylindrical_projection,2,2,2,3,4]))$
21665          (Figure worldmap_geomap5)
21666
21667        * '[conic_projection,<x>,<y>,<z>,<r>,<alpha>]': re-projects
21668          spherical map boundaries on the cones of angle <alpha>, with
21669          axis passing through the poles of the globe of radius <r>
21670          centered at (<x>,<y>,<z>).  Both the northern and southern
21671          cones are tangent to sphere.
21672               (%i1) load(worldmap)$
21673               (%i2) draw3d(geomap(World_coastlines,
21674                                   [conic_projection,0,0,0,1,90]))$
21675     (Figure worldmap_geomap6)
21676
21677     See also <http://riotorto.users.sf.net/gnuplot/geomap> for more
21678     elaborated examples.
21679
21680
21681File: maxima.info,  Node: drawdf-pkg,  Next: dynamics-pkg,  Prev: draw-pkg,  Up: Top
21682
2168354 drawdf
21684*********
21685
21686* Menu:
21687
21688* Introduction to drawdf::
21689* Functions and Variables for drawdf::
21690
21691
21692File: maxima.info,  Node: Introduction to drawdf,  Next: Functions and Variables for drawdf,  Prev: drawdf-pkg,  Up: drawdf-pkg
21693
2169454.1 Introduction to drawdf
21695===========================
21696
21697The function 'drawdf' draws the direction field of a first-order
21698Ordinary Differential Equation (ODE) or a system of two autonomous
21699first-order ODE's.
21700
21701   Since this is an additional package, in order to use it you must
21702first load it with 'load("drawdf")'.  Drawdf is built upon the 'draw'
21703package, which requires Gnuplot 4.2.
21704
21705   To plot the direction field of a single ODE, the ODE must be written
21706in the form:
21707            dy
21708            -- = F(x,y)
21709            dx
21710
21711   and the function <F> should be given as the argument for 'drawdf'.
21712If the independent and dependent variables are not <x>, and <y>, as in
21713the equation above, then those two variables should be named explicitly
21714in a list given as an argument to the drawdf command (see the examples).
21715
21716   To plot the direction field of a set of two autonomous ODE's, they
21717must be written in the form
21718            dx             dy
21719            -- = G(x,y)    -- = F(x,y)
21720            dt             dt
21721
21722   and the argument for 'drawdf' should be a list with the two functions
21723<G> and <F>, in that order; namely, the first expression in the list
21724will be taken to be the time derivative of the variable represented on
21725the horizontal axis, and the second expression will be the time
21726derivative of the variable represented on the vertical axis.  Those two
21727variables do not have to be <x> and <y>, but if they are not, then the
21728second argument given to drawdf must be another list naming the two
21729variables, first the one on the horizontal axis and then the one on the
21730vertical axis.
21731
21732   If only one ODE is given, 'drawdf' will implicitly admit 'x=t', and
21733'G(x,y)=1', transforming the non-autonomous equation into a system of
21734two autonomous equations.
21735
21736
21737File: maxima.info,  Node: Functions and Variables for drawdf,  Prev: Introduction to drawdf,  Up: drawdf-pkg
21738
2173954.2 Functions and Variables for drawdf
21740=======================================
21741
2174254.2.1 Functions
21743----------------
21744
21745 -- Function: drawdf
21746          drawdf (<dydx>, ...options and objects...)
21747          drawdf (<dvdu>, [<u>,<v>], ...options and objects...)
21748          drawdf (<dvdu>, [<u>,<umin>,<umax>], [<v>,<vmin>,<vmax>],
21749          ...options and objects...)
21750          drawdf ([<dxdt>,<dydt>], ...options and objects...)
21751          drawdf ([<dudt>,<dvdt>], [<u>,<v>], ...options and objects...)
21752
21753          drawdf ([<dudt>,<dvdt>], [<u>,<umin>,<umax>],
21754          [<v>,<vmin>,<vmax>], ...options and objects...)
21755
21756     Function 'drawdf' draws a 2D direction field with optional solution
21757     curves and other graphics using the 'draw' package.
21758
21759     The first argument specifies the derivative(s), and must be either
21760     an expression or a list of two expressions.  <dydx>, <dxdt> and
21761     <dydt> are expressions that depend on <x> and <y>.  <dvdu>, <dudt>
21762     and <dvdt> are expressions that depend on <u> and <v>.
21763
21764     If the independent and dependent variables are not <x> and <y>,
21765     then their names must be specified immediately following the
21766     derivative(s), either as a list of two names '['<u>,<v>']', or as
21767     two lists of the form '['<u>,<umin>,<umax>']' and
21768     '['<v>,<vmin>,<vmax>']'.
21769
21770     The remaining arguments are graphic options, graphic objects, or
21771     lists containing graphic options and objects, nested to arbitrary
21772     depth.  The set of graphic options and objects supported by
21773     'drawdf' is a superset of those supported by 'draw2d' and 'gr2d'
21774     from the 'draw' package.
21775
21776     The arguments are interpreted sequentially: graphic options affect
21777     all following graphic objects.  Furthermore, graphic objects are
21778     drawn on the canvas in order specified, and may obscure graphics
21779     drawn earlier.  Some graphic options affect the global appearance
21780     of the scene.
21781
21782     The additional graphic objects supported by 'drawdf' include:
21783     'solns_at', 'points_at', 'saddles_at', 'soln_at', 'point_at', and
21784     'saddle_at'.
21785
21786     The additional graphic options supported by 'drawdf' include:
21787     'field_degree', 'soln_arrows', 'field_arrows', 'field_grid',
21788     'field_color', 'show_field', 'tstep', 'nsteps', 'duration',
21789     'direction', 'field_tstep', 'field_nsteps', and 'field_duration'.
21790
21791     Commonly used graphic objects inherited from the 'draw' package
21792     include: 'explicit', 'implicit', 'parametric', 'polygon', 'points',
21793     'vector', 'label', and all others supported by 'draw2d' and 'gr2d'.
21794
21795     Commonly used graphic options inherited from the 'draw' package
21796     include:
21797     'points_joined', 'color', 'point_type', 'point_size', 'line_width',
21798     'line_type', 'key', 'title', 'xlabel', 'ylabel', 'user_preamble',
21799     'terminal', 'dimensions', 'file_name', and all others supported by
21800     'draw2d' and 'gr2d'.
21801
21802     See also 'draw2d'.
21803
21804     Users of wxMaxima or Imaxima may optionally use 'wxdrawdf', which
21805     is identical to 'drawdf' except that the graphics are drawn within
21806     the notebook using 'wxdraw'.
21807
21808     To make use of this function, write first 'load("drawdf")'.
21809
21810     Examples:
21811
21812          (%i1) load("drawdf")$
21813          (%i2) drawdf(exp(-x)+y)$        /* default vars: x,y */
21814          (%i3) drawdf(exp(-t)+y, [t,y])$ /* default range: [-10,10] */
21815          (%i4) drawdf([y,-9*sin(x)-y/5], [x,1,5], [y,-2,2])$
21816
21817     For backward compatibility, 'drawdf' accepts most of the parameters
21818     supported by plotdf.
21819
21820          (%i5) drawdf(2*cos(t)-1+y, [t,y], [t,-5,10], [y,-4,9],
21821                       [trajectory_at,0,0])$
21822
21823     'soln_at' and 'solns_at' draw solution curves passing through the
21824     specified points, using a slightly enhanced 4th-order Runge Kutta
21825     numerical integrator.
21826
21827          (%i6) drawdf(2*cos(t)-1+y, [t,-5,10], [y,-4,9],
21828                       solns_at([0,0.1],[0,-0.1]),
21829                       color=blue, soln_at(0,0))$
21830
21831     'field_degree=2' causes the field to be composed of quadratic
21832     splines, based on the first and second derivatives at each grid
21833     point.  'field_grid=['<COLS>,<ROWS>']' specifies the number of
21834     columns and rows in the grid.
21835
21836          (%i7) drawdf(2*cos(t)-1+y, [t,-5,10], [y,-4,9],
21837                       field_degree=2, field_grid=[20,15],
21838                       solns_at([0,0.1],[0,-0.1]),
21839                       color=blue, soln_at(0,0))$
21840
21841     'soln_arrows=true' adds arrows to the solution curves, and (by
21842     default) removes them from the direction field.  It also changes
21843     the default colors to emphasize the solution curves.
21844
21845          (%i8) drawdf(2*cos(t)-1+y, [t,-5,10], [y,-4,9],
21846                       soln_arrows=true,
21847                       solns_at([0,0.1],[0,-0.1],[0,0]))$
21848
21849     'duration=40' specifies the time duration of numerical integration
21850     (default 10).  Integration will also stop automatically if the
21851     solution moves too far away from the plotted region, or if the
21852     derivative becomes complex or infinite.  Here we also specify
21853     'field_degree=2' to plot quadratic splines.  The equations below
21854     model a predator-prey system.
21855
21856          (%i9) drawdf([x*(1-x-y), y*(3/4-y-x/2)], [x,0,1.1], [y,0,1],
21857                       field_degree=2, duration=40,
21858                       soln_arrows=true, point_at(1/2,1/2),
21859                       solns_at([0.1,0.2], [0.2,0.1], [1,0.8], [0.8,1],
21860                                [0.1,0.1], [0.6,0.05], [0.05,0.4],
21861                                [1,0.01], [0.01,0.75]))$
21862
21863     'field_degree='solns' causes the field to be composed of many small
21864     solution curves computed by 4th-order Runge Kutta, with better
21865     results in this case.
21866
21867          (%i10) drawdf([x*(1-x-y), y*(3/4-y-x/2)], [x,0,1.1], [y,0,1],
21868                        field_degree='solns, duration=40,
21869                        soln_arrows=true, point_at(1/2,1/2),
21870                        solns_at([0.1,0.2], [0.2,0.1], [1,0.8],
21871                                 [0.8,1], [0.1,0.1], [0.6,0.05],
21872                                 [0.05,0.4], [1,0.01], [0.01,0.75]))$
21873
21874     'saddles_at' attempts to automatically linearize the equation at
21875     each saddle, and to plot a numerical solution corresponding to each
21876     eigenvector, including the separatrices.  'tstep=0.05' specifies
21877     the maximum time step for the numerical integrator (the default is
21878     0.1).  Note that smaller time steps will sometimes be used in order
21879     to keep the x and y steps small.  The equations below model a
21880     damped pendulum.
21881
21882          (%i11) drawdf([y,-9*sin(x)-y/5], tstep=0.05,
21883                        soln_arrows=true, point_size=0.5,
21884                        points_at([0,0], [2*%pi,0], [-2*%pi,0]),
21885                        field_degree='solns,
21886                        saddles_at([%pi,0], [-%pi,0]))$
21887
21888     'show_field=false' suppresses the field entirely.
21889
21890          (%i12) drawdf([y,-9*sin(x)-y/5], tstep=0.05,
21891                        show_field=false, soln_arrows=true,
21892                        point_size=0.5,
21893                        points_at([0,0], [2*%pi,0], [-2*%pi,0]),
21894                        saddles_at([3*%pi,0], [-3*%pi,0],
21895                                   [%pi,0], [-%pi,0]))$
21896
21897     'drawdf' passes all unrecognized parameters to 'draw2d' or 'gr2d',
21898     allowing you to combine the full power of the 'draw' package with
21899     'drawdf'.
21900
21901          (%i13) drawdf(x^2+y^2, [x,-2,2], [y,-2,2], field_color=gray,
21902                        key="soln 1", color=black, soln_at(0,0),
21903                        key="soln 2", color=red, soln_at(0,1),
21904                        key="isocline", color=green, line_width=2,
21905                        nticks=100, parametric(cos(t),sin(t),t,0,2*%pi))$
21906
21907     'drawdf' accepts nested lists of graphic options and objects,
21908     allowing convenient use of makelist and other function calls to
21909     generate graphics.
21910
21911          (%i14) colors : ['red,'blue,'purple,'orange,'green]$
21912          (%i15) drawdf([x-x*y/2, (x*y - 3*y)/4],
21913                        [x,2.5,3.5], [y,1.5,2.5],
21914                        field_color = gray,
21915                        makelist([ key   = concat("soln",k),
21916                                   color = colors[k],
21917                                   soln_at(3, 2 + k/20) ],
21918                                 k,1,5))$
21919
21920
21921File: maxima.info,  Node: dynamics-pkg,  Next: engineering-format-pkg,  Prev: drawdf-pkg,  Up: Top
21922
2192355 dynamics
21924***********
21925
21926* Menu:
21927
21928* The dynamics package::
21929* Graphical analysis of discrete dynamical systems::
21930* Visualization with VTK::
21931
21932
21933File: maxima.info,  Node: The dynamics package,  Next: Graphical analysis of discrete dynamical systems,  Prev: dynamics-pkg,  Up: dynamics-pkg
21934
2193555.1 The dynamics package
21936=========================
21937
21938Package 'dynamics' includes functions for 3D visualization, animations,
21939graphical analysis of differential and difference equations and
21940numerical solution of differential equations.  The functions for
21941differential equations are described in the section on 'Numerical
21942Methods' and the functions to plot the Mandelbrot and Julia sets are
21943described in the section on 'Plotting'.
21944
21945   All the functions in this package will be loaded automatically the
21946first time they are used.
21947
21948
21949File: maxima.info,  Node: Graphical analysis of discrete dynamical systems,  Next: Visualization with VTK,  Prev: The dynamics package,  Up: dynamics-pkg
21950
2195155.2 Graphical analysis of discrete dynamical systems
21952=====================================================
21953
21954 -- Function: chaosgame ([[<x1>, <y1>]...[<xm>, <ym>]], [<x0>, <y0>],
21955          <b>, <n>, <options>, ...);
21956
21957     Implements the so-called chaos game: the initial point (<x0>, <y0>)
21958     is plotted and then one of the <m> points [<x1>, <y1>]...<xm>,
21959     <ym>] will be selected at random.  The next point plotted will be
21960     on the segment from the previous point plotted to the point chosen
21961     randomly, at a distance from the random point which will be <b>
21962     times that segment's length.  The procedure is repeated <n> times.
21963     The options are the same as for 'plot2d'.
21964
21965     *Example*.  A plot of Sierpinsky's triangle:
21966
21967          (%i1) chaosgame([[0, 0], [1, 0], [0.5, sqrt(3)/2]], [0.1, 0.1], 1/2,
21968                           30000, [style, dots]);
21969
21970 -- Function: evolution (<F>, <y0>, <n>, ..., <options>, ...);
21971
21972     Draws <n+1> points in a two-dimensional graph, where the horizontal
21973     coordinates of the points are the integers 0, 1, 2, ..., <n>, and
21974     the vertical coordinates are the corresponding values <y(n)> of the
21975     sequence defined by the recurrence relation
21976                  y(n+1) = F(y(n))
21977
21978     With initial value <y(0)> equal to <y0>.  <F> must be an expression
21979     that depends only on one variable (in the example, it depend on
21980     <y>, but any other variable can be used), <y0> must be a real
21981     number and <n> must be a positive integer.  This function accepts
21982     the same options as 'plot2d'.
21983
21984     *Example*.
21985
21986          (%i1) evolution(cos(y), 2, 11);
21987
21988 -- Function: evolution2d ([<F>, <G>], [<u>, <v>], [<u0>, <y0>], <n>,
21989          <options>, ...);
21990
21991     Shows, in a two-dimensional plot, the first <n+1> points in the
21992     sequence of points defined by the two-dimensional discrete
21993     dynamical system with recurrence relations
21994                  u(n+1) = F(u(n), v(n))    v(n+1) = G(u(n), v(n))
21995
21996     With initial values <u0> and <v0>.  <F> and <G> must be two
21997     expressions that depend only on two variables, <u> and <v>, which
21998     must be named explicitly in a list.  The options are the same as
21999     for 'plot2d'.
22000
22001     *Example*.  Evolution of a two-dimensional discrete dynamical
22002     system:
22003
22004          (%i1) f: 0.6*x*(1+2*x)+0.8*y*(x-1)-y^2-0.9$
22005          (%i2) g: 0.1*x*(1-6*x+4*y)+0.1*y*(1+9*y)-0.4$
22006          (%i3) evolution2d([f,g], [x,y], [-0.5,0], 50000, [style,dots]);
22007
22008     And an enlargement of a small region in that fractal:
22009
22010          (%i9) evolution2d([f,g], [x,y], [-0.5,0], 300000, [x,-0.8,-0.6],
22011                            [y,-0.4,-0.2], [style, dots]);
22012
22013 -- Function: ifs ([<r1>, ..., <rm>], [<A1>,..., <Am>], [[<x1>, <y1>],
22014          ..., [<xm>, <ym>]], [<x0>, <y0>], <n>, <options>, ...);
22015
22016     Implements the Iterated Function System method.  This method is
22017     similar to the method described in the function 'chaosgame'.  but
22018     instead of shrinking the segment from the current point to the
22019     randomly chosen point, the 2 components of that segment will be
22020     multiplied by the 2 by 2 matrix <Ai> that corresponds to the point
22021     chosen randomly.
22022
22023     The random choice of one of the <m> attractive points can be made
22024     with a non-uniform probability distribution defined by the weights
22025     <r1>,...,<rm>.  Those weights are given in cumulative form; for
22026     instance if there are 3 points with probabilities 0.2, 0.5 and 0.3,
22027     the weights <r1>, <r2> and <r3> could be 2, 7 and 10.  The options
22028     are the same as for 'plot2d'.
22029
22030     *Example*.  Barnsley's fern, obtained with 4 matrices and 4 points:
22031
22032          (%i1) a1: matrix([0.85,0.04],[-0.04,0.85])$
22033          (%i2) a2: matrix([0.2,-0.26],[0.23,0.22])$
22034          (%i3) a3: matrix([-0.15,0.28],[0.26,0.24])$
22035          (%i4) a4: matrix([0,0],[0,0.16])$
22036          (%i5) p1: [0,1.6]$
22037          (%i6) p2: [0,1.6]$
22038          (%i7) p3: [0,0.44]$
22039          (%i8) p4: [0,0]$
22040          (%i9) w: [85,92,99,100]$
22041          (%i10) ifs(w, [a1,a2,a3,a4], [p1,p2,p3,p4], [5,0], 50000, [style,dots]);
22042
22043 -- Function: orbits (<F>, <y0>, <n1>, <n2>, [<x>, <x0>, <xf>, <xstep>],
22044          <options>, ...);
22045
22046     Draws the orbits diagram for a family of one-dimensional discrete
22047     dynamical systems, with one parameter <x>; that kind of diagram is
22048     used to study the bifurcations of a one-dimensional discrete
22049     system.
22050
22051     The function <F(y)> defines a sequence with a starting value of
22052     <y0>, as in the case of the function 'evolution', but in this case
22053     that function will also depend on a parameter <x> that will take
22054     values in the interval from <x0> to <xf> with increments of
22055     <xstep>.  Each value used for the parameter <x> is shown on the
22056     horizontal axis.  The vertical axis will show the <n2> values of
22057     the sequence <y(n1+1)>,..., <y(n1+n2+1)> obtained after letting the
22058     sequence evolve <n1> iterations.  In addition to the options
22059     accepted by 'plot2d', it accepts an option <pixels> that sets up
22060     the maximum number of different points that will be represented in
22061     the vertical direction.
22062
22063     *Example*.  Orbits diagram of the quadratic map, with a parameter
22064     <a>:
22065
22066          (%i1) orbits(x^2+a, 0, 50, 200, [a, -2, 0.25], [style, dots]);
22067
22068     To enlarge the region around the lower bifurcation near x '=' -1.25
22069     use:
22070          (%i2) orbits(x^2+a, 0, 100, 400, [a,-1,-1.53], [x,-1.6,-0.8],
22071                       [nticks, 400], [style,dots]);
22072
22073 -- Function: staircase (<F>, <y0>, <n>,<options>,...);
22074
22075     Draws a staircase diagram for the sequence defined by the
22076     recurrence relation
22077                  y(n+1) = F(y(n))
22078
22079     The interpretation and allowed values of the input parameters is
22080     the same as for the function 'evolution'.  A staircase diagram
22081     consists of a plot of the function <F(y)>, together with the line
22082     <G(y)> '=' <y>.  A vertical segment is drawn from the point (<y0>,
22083     <y0>) on that line until the point where it intersects the function
22084     <F>.  From that point a horizontal segment is drawn until it
22085     reaches the point (<y1>, <y1>) on the line, and the procedure is
22086     repeated <n> times until the point (<yn>, <yn>) is reached.  The
22087     options are the same as for 'plot2d'.
22088
22089     *Example*.
22090
22091          (%i1) staircase(cos(y), 1, 11, [y, 0, 1.2]);
22092
22093
22094File: maxima.info,  Node: Visualization with VTK,  Prev: Graphical analysis of discrete dynamical systems,  Up: dynamics-pkg
22095
2209655.3 Visualization with VTK
22097===========================
22098
22099Function scene creates 3D images and animations using the _Visualization
22100ToolKit_ (VTK) software.  In order to use that function, Xmaxima and VTK
22101should be installed in your system (including the TCL bindings of VTK,
22102which in some system might come in a separate package).
22103
22104 -- Function: scene (<objects>, ..., <options>, ...);
22105
22106     Accepts an empty list or a list of several 'objects' and 'options'.
22107     The program launches Xmaxima, which opens an external window
22108     representing the given objects in a 3-dimensional space and
22109     applying the options given.  Each object must belong to one of the
22110     following 4 classes: sphere, cube, cylinder or cone (see 'Scene
22111     objects').  Objects are identified by giving their name or by a
22112     list in which the first element is the class name and the following
22113     elements are options for that object.
22114
22115     *Example*.  A hexagonal pyramid with a blue background:
22116          (%i1) scene(cone, [background,"#9980e5"])$
22117
22118     By holding down the left button of the mouse while it is moved on
22119     the graphics window, the camera can be rotated showing different
22120     views of the pyramid.  The two plot options 'elevation' and
22121     'azimuth' can also be used to change the initial orientation of the
22122     viewing camera.  The camera can be moved by holding the middle
22123     mouse button while moving it and holding the right-side mouse
22124     button while moving it up or down will zoom in or out.
22125
22126     Each object option should be a list starting with the option name,
22127     followed by its value.  The list of allowed options can be found in
22128     the 'Scene object's options' section.
22129
22130     *Example*.  This will show a sphere falling to the ground and
22131     bouncing off without losing any energy.  To start or pause the
22132     animation, press the play/pause button.
22133
22134          (%i1) p: makelist ([0,0,2.1- 9.8*t^2/2], t, 0, 0.64, 0.01)$
22135
22136          (%i2) p: append (p, reverse(p))$
22137
22138          (%i3) ball: [sphere, [radius,0.1], [thetaresolution,20],
22139            [phiresolution,20], [position,0,0,2.1], [color,red],
22140            [animate,position,p]]$
22141
22142          (%i4) ground: [cube, [xlength,2], [ylength,2], [zlength,0.2],
22143            [position,0,0,-0.1],[color,violet]]$
22144
22145          (%i5) scene (ball, ground, restart)$
22146
22147     The <restart> option was used to make the animation restart
22148     automatically every time the last point in the position list is
22149     reached.  The accepted values for the colors are the same as for
22150     the 'color' option of plot2d.
22151
2215255.3.1 Scene options
22153--------------------
22154
22155 -- Scene option: azimuth [azimuth, <angle>]
22156     Default value: '135'
22157
22158     The rotation of the camera on the horizontal (x, y) plane.  <angle>
22159     must be a real number; an angle of 0 means that the camera points
22160     in the direction of the y axis and the x axis will appear on the
22161     right.
22162
22163 -- Scene option: background [background, <color>]
22164     Default value: 'black'
22165
22166     The color of the graphics window's background.  It accepts color
22167     names or hexadecimal red-green-blue strings (see the 'color' option
22168     of plot2d).
22169
22170 -- Scene option: elevation [elevation, <angle>]
22171     Default value: '30'
22172
22173     The vertical rotation of the camera.  The <angle> must be a real
22174     number; an angle of 0 means that the camera points on the
22175     horizontal, and the default angle of 30 means that the camera is
22176     pointing 30 degrees down from the horizontal.
22177
22178 -- Scene option: height [height, <pixels>]
22179     Default value: '500'
22180
22181     The height, in pixels, of the graphics window.  <pixels> must be a
22182     positive integer number.
22183
22184 -- Scene option: restart [restart, <value>]
22185     Default value: 'false'
22186
22187     A true value means that animations will restart automatically when
22188     the end of the list is reached.  Writing just "restart" is
22189     equivalent to [restart, <true>].
22190
22191 -- Scene option: tstep [tstep, <time>]
22192     Default value: '10'
22193
22194     The amount of time, in mili-seconds, between iterations among
22195     consecutive animation frames.  <time> must be a real number.
22196
22197 -- Scene option: width [width, <pixels>]
22198     Default value: '500'
22199
22200     The width, in pixels, of the graphics window.  <pixels> must be a
22201     positive integer number.
22202
22203 -- Scene option: windowname [windowtitle, <name>]
22204     Default value: '.scene'
22205
22206     <name> must be a string that can be used as the name of the Tk
22207     window created by Xmaxima for the 'scene' graphics.  The default
22208     value '.scene' implies that a new top level window will be created.
22209
22210 -- Scene option: windowtitle [windowtitle, <name>]
22211     Default value: 'Xmaxima: scene'
22212
22213     <name> must be a string that will be written in the title of the
22214     window created by 'scene'.
22215
2221655.3.2 Scene objects
22217--------------------
22218
22219 -- Scene object: cone [cone, <options>]
22220
22221     Creates a regular pyramid with height equal to 1 and a hexagonal
22222     base with vertices 0.5 units away from the axis.  Options 'height'
22223     and 'radius' can be used to change those defaults and option
22224     'resolution' can be used to change the number of edges of the base;
22225     higher values will make it look like a cone.  By default, the axis
22226     will be along the x axis, the middle point of the axis will be at
22227     the origin and the vertex on the positive side of the x axis; use
22228     options 'orientation' and 'center' to change those defaults.
22229
22230     *Example*.  This shows a pyramid that starts rotating around the z
22231     axis when the play button is pressed.
22232
22233          (%i1) scene([cone, [orientation,0,30,0], [tstep,100],
22234             [animate,orientation,makelist([0,30,i],i,5,360,5)]], restart)$
22235
22236 -- Scene object: cube [cube, <options>]
22237
22238     A cube with edges of 1 unit and faces parallel to the xy, xz and yz
22239     planes.  The lengths of the three edges can be changed with options
22240     'xlength', 'ylength' and 'zlength', turning it into a rectangular
22241     box and the faces can be rotated with option 'orientation'.
22242
22243 -- Scene object: cylinder [cylinder, <options>]
22244
22245     Creates a regular prism with height equal to 1 and a hexagonal base
22246     with vertices 0.5 units away from the axis.  Options 'height' and
22247     'radius' can be used to change those defaults and option
22248     'resolution' can be used to change the number of edges of the base;
22249     higher values will make it look like a cylinder.  The default
22250     height can be changed with the option 'height'.  By default, the
22251     axis will be along the x axis and the middle point of the axis will
22252     be at the origin; use options 'orientation' and 'center' to change
22253     those defaults.
22254
22255 -- Scene object: sphere [sphere, <options>]
22256
22257     A sphere with default radius of 0.5 units and center at the origin.
22258
2225955.3.3 Scene object's options
22260-----------------------------
22261
22262 -- Object option: animation [animation, <property>, <positions>]
22263
22264     <property> should be one of the following 4 object's properties:
22265     'origin', 'scale', 'position' or 'orientation' and <positions>
22266     should be a list of points.  When the play button is pressed, the
22267     object property will be changed sequentially through all the values
22268     in the list, at intervals of time given by the option 'tstep'.  The
22269     rewind button can be used to point at the start of the sequence
22270     making the animation restart after the play button is pressed
22271     again.
22272
22273     See also 'track'.
22274
22275 -- Object option: capping [capping, <number>]
22276     Default value: '1'
22277
22278     In a cone or a cylinder, it defines whether the base (or bases)
22279     will be shown.  A value of 1 for <number> makes the base visible
22280     and a value of 0 makes it invisible.
22281
22282 -- Object option: center [center, <point>]
22283     Default value: '[0, 0, 0]'
22284
22285     The coordinates of the object's geometric center, with respect to
22286     its 'position'.  <point> can be a list with 3 real numbers, or 3
22287     real numbers separated by commas.  In a cylinder, cone or cube it
22288     will be at half its height and in a sphere at its center.
22289
22290 -- Object option: color [color, <colorname>]
22291     Default value: 'white'
22292
22293     The color of the object.  It accepts color names or hexadecimal
22294     red-green-blue strings (see the 'color' option of plot2d).
22295
22296 -- Object option: endphi [endphi, <angle>]
22297     Default value: '180'
22298
22299     In a sphere phi is the angle on the vertical plane that passes
22300     through the z axis, measured from the positive part of the z axis.
22301     <angle> must be a number between 0 and 180 that sets the final
22302     value of phi at which the surface will end.  A value smaller than
22303     180 will eliminate a part of the sphere's surface.
22304
22305     See also 'startphi' and 'phiresolution'.
22306
22307 -- Object option: endtheta [endtheta, <angle>]
22308     Default value: '360'
22309
22310     In a sphere theta is the angle on the horizontal plane (longitude),
22311     measured from the positive part of the x axis.  <angle> must be a
22312     number between 0 and 360 that sets the final value of theta at
22313     which the surface will end.  A value smaller than 360 will
22314     eliminate a part of the sphere's surface.
22315
22316     See also 'starttheta' and 'thetaresolution'.
22317
22318 -- Object option: height [height, <value>]
22319     Default value: '1'
22320
22321     <value> must be a positive number which sets the height of a cone
22322     or a cylinder.
22323
22324 -- Object option: linewidth [linewidth, <value>]
22325     Default value: '1'
22326
22327     The width of the lines, when option 'wireframe' is used.  <value>
22328     must be a positive number.
22329
22330 -- Object option: opacity [opacity, <value>]
22331     Default value: '1'
22332
22333     <value> must be a number between 0 and 1.  The lower the number,
22334     the more transparent the object will become.  The default value of
22335     1 means a completely opaque object.
22336
22337 -- Object option: orientation [orientation, <angles>]
22338     Default value: '[0, 0, 0]'
22339
22340     Three angles by which the object will be rotated with respect to
22341     the three axis.  <angles> can be a list with 3 real numbers, or 3
22342     real numbers separated by commas.  *Example*: '[0, 0, 90]' rotates
22343     the x axis of the object to the y axis of the reference frame.
22344
22345 -- Object option: origin [origin, <point>]
22346     Default value: '[0, 0, 0]'
22347
22348     The coordinates of the object's origin, with respect to which its
22349     other dimensions are defined.  <point> can be a list with 3 real
22350     numbers, or 3 real numbers separated by commas.
22351
22352 -- Object option: phiresolution [phiresolution, <num>]
22353     Default value: ''
22354
22355     The number of sub-intervals into which the phi angle interval from
22356     'startphi' to 'endphi' will be divided.  <num> must be a positive
22357     integer.
22358
22359     See also 'startphi' and 'endphi'.
22360
22361 -- Object option: points [points]
22362
22363     Only the vertices of the triangulation used to render the surface
22364     will be shown.  *Example*: '[sphere, [points]]'
22365
22366     See also 'surface' and 'wireframe'.
22367
22368 -- Object option: pointsize [pointsize, <value>]
22369     Default value: '1'
22370
22371     The size of the points, when option 'points' is used.  <value> must
22372     be a positive number.
22373
22374 -- Object option: position [position, <point>]
22375     Default value: '[0, 0, 0]'
22376
22377     The coordinates of the object's position.  <point> can be a list
22378     with 3 real numbers, or 3 real numbers separated by commas.
22379
22380 -- Object option: radius [radius, <value>]
22381     Default value: '0.5'
22382
22383     The radius or a sphere or the distance from the axis to the base's
22384     vertices in a cylinder or a cone.  <value> must be a positive
22385     number.
22386
22387 -- Object option: resolution [resolution, <number>]
22388     Default value: '6'
22389
22390     <number> must be a integer greater than 2 that sets the number of
22391     edges in the base of a cone or a cylinder.
22392
22393 -- Object option: scale [scale, <factors>]
22394     Default value: '[1, 1, 1]'
22395
22396     Three numbers by which the object will be scaled with respect to
22397     the three axis.  <factors> can be a list with 3 real numbers, or 3
22398     real numbers separated by commas.  *Example*: '[2, 0.5, 1]'
22399     enlarges the object to twice its size in the x direction, reduces
22400     the dimensions in the y direction to half and leaves the z
22401     dimensions unchanged.
22402
22403 -- Object option: startphi [startphi, <angle>]
22404     Default value: '0'
22405
22406     In a sphere phi is the angle on the vertical plane that passes
22407     through the z axis, measured from the positive part of the z axis.
22408     <angle> must be a number between 0 and 180 that sets the initial
22409     value of phi at which the surface will start.  A value bigger than
22410     0 will eliminate a part of the sphere's surface.
22411
22412     See also 'endphi' and 'phiresolution'.
22413
22414 -- Object option: starttheta [starttheta, <angle>]
22415     Default value: '0'
22416
22417     In a sphere theta is the angle on the horizontal plane (longitude),
22418     measured from the positive part of the x axis.  <angle> must be a
22419     number between 0 and 360 that sets the initial value of theta at
22420     which the surface will start.  A value bigger than 0 will eliminate
22421     a part of the sphere's surface.
22422
22423     See also 'endtheta' and 'thetaresolution'.
22424
22425 -- Object option: surface [surface]
22426
22427     The surfaces of the object will be rendered and the lines and
22428     points of the triangulation used to build the surface will not be
22429     shown.  This is the default behavior, which can be changed using
22430     either the option 'points' or 'wireframe'.
22431
22432 -- Object option: thetaresolution [thetaresolution, <num>]
22433     Default value: ''
22434
22435     The number of sub-intervals into which the theta angle interval
22436     from 'starttheta' to 'endtheta' will be divided.  <num> must be a
22437     positive integer.
22438
22439     See also 'starttheta' and 'endtheta'.
22440
22441 -- Object option: track [track, <positions>]
22442
22443     <positions> should be a list of points.  When the play button is
22444     pressed, the object position will be changed sequentially through
22445     all the points in the list, at intervals of time given by the
22446     option 'tstep', leaving behind a track of the object's trajectory.
22447     The rewind button can be used to point at the start of the sequence
22448     making the animation restart after the play button is pressed
22449     again.
22450
22451     *Example*.  This will show the trajectory of a ball thrown with
22452     speed of 5 m/s, at an angle of 45 degrees, when the air resistance
22453     can be neglected:
22454
22455          (%i1) p: makelist ([0,4*t,4*t- 9.8*t^2/2], t, 0, 0.82, 0.01)$
22456
22457          (%i2) ball: [sphere, [radius,0.1], [color,red], [track,p]]$
22458
22459          (%i3) ground: [cube, [xlength,2], [ylength,4], [zlength,0.2],
22460                [position,0,1.5,-0.2],[color,green]]$
22461
22462          (%i4) scene (ball, ground)$
22463
22464     See also 'animation'.
22465
22466 -- Object option: xlength [xlength, <length>]
22467     Default value: '1'
22468
22469     The height of a cube in the x direction.  <length> must be a
22470     positive number.  See also 'ylength' and 'zlength'.
22471
22472 -- Object option: ylength [ylength, <length>]
22473     Default value: '1'
22474
22475     The height of a cube in the y direction.  <length> must be a
22476     positive number.  See also 'xlength' and 'zlength'.
22477
22478 -- Object option: zlength [zlength, <length>]
22479     Default value: '1'
22480
22481     The height of a cube in z the direction.  <length> must be a
22482     positive number.  See also 'xlength' and 'ylength'.
22483
22484 -- Object option: wireframe [wireframe]
22485
22486     Only the edges of the triangulation used to render the surface will
22487     be shown.  *Example*: '[cube, [wireframe]]'
22488
22489     See also 'surface' and 'points'.
22490
22491
22492File: maxima.info,  Node: engineering-format-pkg,  Next: ezunits-pkg,  Prev: dynamics-pkg,  Up: Top
22493
2249456 engineering-format
22495*********************
22496
22497Engineering-format changes the way maxima outputs floating-point numbers
22498to the notation engineers are used to: 'a*10^b' with 'b' dividable by
22499three.
22500* Menu:
22501
22502* Functions and Variables for engineering-format::
22503* Known bugs in engineering-format::
22504
22505
22506File: maxima.info,  Node: Functions and Variables for engineering-format,  Next: Known bugs in engineering-format,  Prev: engineering-format-pkg,  Up: engineering-format-pkg
22507
2250856.1 Functions and Variables for engineering-format
22509===================================================
22510
22511 -- Option variable: engineering_format_floats
22512     Default value: 'true'
22513
22514     This variable allows to temporarily switch off engineering-format.
22515          (%i1) load("engineering-format");
22516          (%o1) /home/gunter/src/maxima-code/share/contrib/engineering-for\
22517          mat.lisp
22518          (%i2) float(sin(10)/10000);
22519          (%o2)                - 54.40211108893698e-6
22520          (%i3) engineering_format_floats:false$
22521          (%i4) float(sin(10)/10000);
22522          (%o4)                - 5.440211108893698e-5
22523
22524     See also 'fpprintprec' and 'float'.
22525
22526 -- Option variable: engineering_format_min
22527     Default value: '0.0'
22528
22529     The minimum absolute value that isn't automatically converted to
22530     the engineering format.  See also 'engineering_format_max' and
22531     'engineering_format_floats'.
22532
22533          (%i1) lst: float([.05,.5,5,500,5000,500000]);
22534          (%o1)       [0.05, 0.5, 5.0, 500.0, 5000.0, 500000.0]
22535          (%i2) load("engineering-format");
22536          (%o2) /home/gunter/src/maxima-code/share/contrib/engineering-for\
22537          mat.lisp
22538          (%i3) lst;
22539          (%o3) [50.0e-3, 500.0e-3, 5.0e+0, 500.0e+0, 5.0e+3, 500.0e+3]
22540          (%i4) engineering_format_min:.1$
22541          (%i5) engineering_format_max:1000$
22542          (%i6) lst;
22543          (%o6)     [50.0e-3, 0.5, 5.0, 500.0, 5.0e+3, 500.0e+3]
22544
22545 -- Option variable: engineering_format_max
22546     Default value: '0.0'
22547
22548     The maximum absolute value that isn't automatically converted to
22549     the engineering format.  See also 'engineering_format_min' and
22550     'engineering_format_floats'.
22551
22552
22553File: maxima.info,  Node: Known bugs in engineering-format,  Prev: Functions and Variables for engineering-format,  Up: engineering-format-pkg
22554
2255556.2 Known Bugs
22556===============
22557
22558The output routine of SBCL 1.3.0 has a bug that sometimes causes the
22559exponent not to be dividable by three.  The value of the displayed
22560number is still valid in this case.
22561
22562
22563File: maxima.info,  Node: ezunits-pkg,  Next: f90-pkg,  Prev: engineering-format-pkg,  Up: Top
22564
2256557 ezunits
22566**********
22567
22568* Menu:
22569
22570* Introduction to ezunits::
22571* Introduction to physical_constants::
22572* Functions and Variables for ezunits::
22573
22574
22575File: maxima.info,  Node: Introduction to ezunits,  Next: Introduction to physical_constants,  Prev: ezunits-pkg,  Up: ezunits-pkg
22576
2257757.1 Introduction to ezunits
22578============================
22579
22580'ezunits' is a package for working with dimensional quantities,
22581including some functions for dimensional analysis.  'ezunits' can carry
22582out arithmetic operations on dimensional quantities and unit
22583conversions.  The built-in units include Systeme Internationale (SI) and
22584US customary units, and other units can be declared.  See also
22585'physical_constants', a collection of physical constants.
22586
22587   'load("ezunits")' loads this package.  'demo("ezunits")' displays
22588several examples.  The convenience function 'known_units' returns a list
22589of the built-in and user-declared units, while
22590'display_known_unit_conversions' displays the set of known conversions
22591in an easy-to-read format.
22592
22593   An expression a ` b represents a dimensional quantity, with 'a'
22594indicating a nondimensional quantity and 'b' indicating the dimensional
22595units.  A symbol can be used as a unit without declaring it as such;
22596unit symbols need not have any special properties.  The quantity and
22597unit of an expression a ` b can be extracted by the 'qty' and 'units'
22598functions, respectively.
22599
22600   A symbol may be declared to be a dimensional quantity, with specified
22601quantity or specified units or both.
22602
22603   An expression a ` b `` c converts from unit 'b' to unit 'c'.
22604'ezunits' has built-in conversions for SI base units, SI derived units,
22605and some non-SI units.  Unit conversions not already known to 'ezunits'
22606can be declared.  The unit conversions known to 'ezunits' are specified
22607by the global variable 'known_unit_conversions', which comprises
22608built-in and user-defined conversions.  Conversions for products,
22609quotients, and powers of units are derived from the set of known unit
22610conversions.
22611
22612   As Maxima generally prefers exact numbers (integers or rationals) to
22613inexact (float or bigfloat), so 'ezunits' preserves exact numbers when
22614they appear in dimensional quantities.  All built-in unit conversions
22615are expressed in terms of exact numbers; inexact numbers in declared
22616conversions are coerced to exact.
22617
22618   There is no preferred system for display of units; input units are
22619not converted to other units unless conversion is explicitly indicated.
22620'ezunits' recognizes the prefixes m-, k-, M, and G- (for milli-, kilo-,
22621mega-, and giga-) as applied to SI base units and SI derived units, but
22622such prefixes are applied only when indicated by an explicit conversion.
22623
22624   Arithmetic operations on dimensional quantities are carried out by
22625conventional rules for such operations.
22626
22627   * (x ` a) * (y ` b) is equal to (x * y) ` (a * b).
22628   * (x ` a) + (y ` a) is equal to (x + y) ` a.
22629   * (x ` a)^y is equal to x^y ` a^y when 'y' is nondimensional.
22630
22631   'ezunits' does not require that units in a sum have the same
22632dimensions; such terms are not added together, and no error is reported.
22633
22634   'ezunits' includes functions for elementary dimensional analysis,
22635namely the fundamental dimensions and fundamental units of a dimensional
22636quantity, and computation of dimensionless quantities and natural units.
22637The functions for dimensional analysis were adapted from similar
22638functions in another package, written by Barton Willis.
22639
22640   For the purpose of dimensional analysis, a list of fundamental
22641dimensions and an associated list of fundamental units are maintained;
22642by default the fundamental dimensions are length, mass, time, charge,
22643temperature, and quantity, and the fundamental units are the associated
22644SI units, but other fundamental dimensions and units can be declared.
22645
22646
22647File: maxima.info,  Node: Introduction to physical_constants,  Next: Functions and Variables for ezunits,  Prev: Introduction to ezunits,  Up: ezunits-pkg
22648
2264957.2 Introduction to physical_constants
22650=======================================
22651
22652'physical_constants' is a collection of physical constants, copied from
22653CODATA 2006 recommended values (<http://physics.nist.gov/constants>).
22654'load ("physical_constants")' loads this package, and loads 'ezunits'
22655also, if it is not already loaded.
22656
22657   A physical constant is represented as a symbol which has a property
22658which is the constant value.  The constant value is a dimensional
22659quantity, as represented by 'ezunits'.  The function 'constvalue'
22660fetches the constant value; the constant value is not the ordinary value
22661of the symbol, so symbols of physical constants persist in evaluated
22662expressions until their values are fetched by 'constvalue'.
22663
22664   'physical_constants' includes some auxiliary information, namely, a
22665description string for each constant, an estimate of the error of its
22666numerical value, and a property for TeX display.  To identify physical
22667constants, each symbol has the 'physical_constant' property;
22668'propvars(physical_constant)' therefore shows the list of all such
22669symbols.
22670
22671   'physical_constants' comprises the following constants.
22672
22673'%c'
22674     speed of light in vacuum
22675'%mu_0'
22676     magnetic constant
22677'%e_0'
22678     electric constant
22679'%Z_0'
22680     characteristic impedance of vacuum
22681'%G'
22682     Newtonian constant of gravitation
22683'%h'
22684     Planck constant
22685'%h_bar'
22686     Planck constant
22687'%m_P'
22688     Planck mass
22689'%T_P'
22690     Planck temperature
22691'%l_P'
22692     Planck length
22693'%t_P'
22694     Planck time
22695'%%e'
22696     elementary charge
22697'%Phi_0'
22698     magnetic flux quantum
22699'%G_0'
22700     conductance quantum
22701'%K_J'
22702     Josephson constant
22703'%R_K'
22704     von Klitzing constant
22705'%mu_B'
22706     Bohr magneton
22707'%mu_N'
22708     nuclear magneton
22709'%alpha'
22710     fine-structure constant
22711'%R_inf'
22712     Rydberg constant
22713'%a_0'
22714     Bohr radius
22715'%E_h'
22716     Hartree energy
22717'%ratio_h_me'
22718     quantum of circulation
22719'%m_e'
22720     electron mass
22721'%N_A'
22722     Avogadro constant
22723'%m_u'
22724     atomic mass constant
22725'%F'
22726     Faraday constant
22727'%R'
22728     molar gas constant
22729'%%k'
22730     Boltzmann constant
22731'%V_m'
22732     molar volume of ideal gas
22733'%n_0'
22734     Loschmidt constant
22735'%ratio_S0_R'
22736     Sackur-Tetrode constant (absolute entropy constant)
22737'%sigma'
22738     Stefan-Boltzmann constant
22739'%c_1'
22740     first radiation constant
22741'%c_1L'
22742     first radiation constant for spectral radiance
22743'%c_2'
22744     second radiation constant
22745'%b'
22746     Wien displacement law constant
22747'%b_prime'
22748     Wien displacement law constant
22749
22750   Reference: <http://physics.nist.gov/constants>
22751
22752   Examples:
22753
22754   The list of all symbols which have the 'physical_constant' property.
22755
22756     (%i1) load ("physical_constants")$
22757     (%i2) propvars (physical_constant);
22758     (%o2) [%c, %mu_0, %e_0, %Z_0, %G, %h, %h_bar, %m_P, %T_P, %l_P,
22759     %t_P, %%e, %Phi_0, %G_0, %K_J, %R_K, %mu_B, %mu_N, %alpha,
22760     %R_inf, %a_0, %E_h, %ratio_h_me, %m_e, %N_A, %m_u, %F, %R, %%k,
22761     %V_m, %n_0, %ratio_S0_R, %sigma, %c_1, %c_1L, %c_2, %b, %b_prime]
22762
22763   Properties of the physical constant '%c'.
22764
22765     (%i1) load ("physical_constants")$
22766     (%i2) constantp (%c);
22767     (%o2)                         true
22768     (%i3) get (%c, description);
22769     (%o3)               speed of light in vacuum
22770     (%i4) constvalue (%c);
22771                                           m
22772     (%o4)                     299792458 ` -
22773                                           s
22774     (%i5) get (%c, RSU);
22775     (%o5)                           0
22776     (%i6) tex (%c);
22777     $$c$$
22778     (%o6)                         false
22779
22780   The energy equivalent of 1 pound-mass.  The symbol '%c' persists
22781until its value is fetched by 'constvalue'.
22782
22783     (%i1) load ("physical_constants")$
22784     (%i2) m * %c^2;
22785                                     2
22786     (%o2)                         %c  m
22787     (%i3) %, m = 1 ` lbm;
22788                                   2
22789     (%o3)                       %c  ` lbm
22790     (%i4) constvalue (%);
22791                                                 2
22792                                            lbm m
22793     (%o4)              89875517873681764 ` ------
22794                                               2
22795                                              s
22796     (%i5) E : % `` J;
22797     Computing conversions to base units; may take a moment.
22798                          366838848464007200
22799     (%o5)                ------------------ ` J
22800                                  9
22801     (%i6) E `` GJ;
22802                           458548560580009
22803     (%o6)                 --------------- ` GJ
22804                              11250000
22805     (%i7) float (%);
22806     (%o7)              4.0759872051556356e+7 ` GJ
22807
22808
22809File: maxima.info,  Node: Functions and Variables for ezunits,  Prev: Introduction to physical_constants,  Up: ezunits-pkg
22810
2281157.3 Functions and Variables for ezunits
22812========================================
22813
22814 -- Operator: `
22815
22816     The dimensional quantity operator.  An expression a ` b represents
22817     a dimensional quantity, with 'a' indicating a nondimensional
22818     quantity and 'b' indicating the dimensional units.  A symbol can be
22819     used as a unit without declaring it as such; unit symbols need not
22820     have any special properties.  The quantity and unit of an
22821     expression a ` b can be extracted by the 'qty' and 'units'
22822     functions, respectively.
22823
22824     Arithmetic operations on dimensional quantities are carried out by
22825     conventional rules for such operations.
22826
22827        * (x ` a) * (y ` b) is equal to (x * y) ` (a * b).
22828        * (x ` a) + (y ` a) is equal to (x + y) ` a.
22829        * (x ` a)^y is equal to x^y ` a^y when 'y' is nondimensional.
22830
22831     'ezunits' does not require that units in a sum have the same
22832     dimensions; such terms are not added together, and no error is
22833     reported.
22834
22835     'load ("ezunits")' enables this operator.
22836
22837     Examples:
22838
22839     SI (Systeme Internationale) units.
22840
22841          (%i1) load ("ezunits")$
22842          (%i2) foo : 10 ` m;
22843          (%o2)                        10 ` m
22844          (%i3) qty (foo);
22845          (%o3)                          10
22846          (%i4) units (foo);
22847          (%o4)                           m
22848          (%i5) dimensions (foo);
22849          (%o5)                        length
22850
22851     "Customary" units.
22852
22853          (%i1) load ("ezunits")$
22854          (%i2) bar : x ` acre;
22855          (%o2)                       x ` acre
22856          (%i3) dimensions (bar);
22857                                             2
22858          (%o3)                        length
22859          (%i4) fundamental_units (bar);
22860                                          2
22861          (%o4)                          m
22862
22863     Units ad hoc.
22864
22865          (%i1) load ("ezunits")$
22866          (%i2) baz : 3 ` sheep + 8 ` goat + 1 ` horse;
22867          (%o2)           8 ` goat + 3 ` sheep + 1 ` horse
22868          (%i3) subst ([sheep = 3*goat, horse = 10*goat], baz);
22869          (%o3)                       27 ` goat
22870          (%i4) baz2 : 1000`gallon/fortnight;
22871                                          gallon
22872          (%o4)                   1000 ` ---------
22873                                         fortnight
22874          (%i5) subst (fortnight = 14*day, baz2);
22875                                    500   gallon
22876          (%o5)                     --- ` ------
22877                                     7     day
22878
22879     Arithmetic operations on dimensional quantities.
22880
22881          (%i1) load ("ezunits")$
22882          (%i2) 100 ` kg + 200 ` kg;
22883          (%o2)                       300 ` kg
22884          (%i3) 100 ` m^3 - 100 ` m^3;
22885                                            3
22886          (%o3)                        0 ` m
22887          (%i4) (10 ` kg) * (17 ` m/s^2);
22888                                           kg m
22889          (%o4)                      170 ` ----
22890                                             2
22891                                            s
22892          (%i5) (x ` m) / (y ` s);
22893                                        x   m
22894          (%o5)                         - ` -
22895                                        y   s
22896          (%i6) (a ` m)^2;
22897                                        2    2
22898          (%o6)                        a  ` m
22899
22900 -- Operator: ``
22901
22902     The unit conversion operator.  An expression a ` b `` c converts
22903     from unit 'b' to unit 'c'.  'ezunits' has built-in conversions for
22904     SI base units, SI derived units, and some non-SI units.  Unit
22905     conversions not already known to 'ezunits' can be declared.  The
22906     unit conversions known to 'ezunits' are specified by the global
22907     variable 'known_unit_conversions', which comprises built-in and
22908     user-defined conversions.  Conversions for products, quotients, and
22909     powers of units are derived from the set of known unit conversions.
22910
22911     There is no preferred system for display of units; input units are
22912     not converted to other units unless conversion is explicitly
22913     indicated.  'ezunits' does not attempt to simplify units by
22914     prefixes (milli-, centi-, deci-, etc) unless such conversion is
22915     explicitly indicated.
22916
22917     'load ("ezunits")' enables this operator.
22918
22919     Examples:
22920
22921     The set of known unit conversions.
22922
22923          (%i1) load ("ezunits")$
22924          (%i2) display2d : false$
22925          (%i3) known_unit_conversions;
22926          (%o3) {acre = 4840*yard^2,Btu = 1055*J,cfm = feet^3/minute,
22927                 cm = m/100,day = 86400*s,feet = 381*m/1250,ft = feet,
22928                 g = kg/1000,gallon = 757*l/200,GHz = 1000000000*Hz,
22929                 GOhm = 1000000000*Ohm,GPa = 1000000000*Pa,
22930                 GWb = 1000000000*Wb,Gg = 1000000*kg,Gm = 1000000000*m,
22931                 Gmol = 1000000*mol,Gs = 1000000000*s,ha = hectare,
22932                 hectare = 100*m^2,hour = 3600*s,Hz = 1/s,inch = feet/12,
22933                 km = 1000*m,kmol = 1000*mol,ks = 1000*s,l = liter,
22934                 lbf = pound_force,lbm = pound_mass,liter = m^3/1000,
22935                 metric_ton = Mg,mg = kg/1000000,MHz = 1000000*Hz,
22936                 microgram = kg/1000000000,micrometer = m/1000000,
22937                 micron = micrometer,microsecond = s/1000000,
22938                 mile = 5280*feet,minute = 60*s,mm = m/1000,
22939                 mmol = mol/1000,month = 2629800*s,MOhm = 1000000*Ohm,
22940                 MPa = 1000000*Pa,ms = s/1000,MWb = 1000000*Wb,
22941                 Mg = 1000*kg,Mm = 1000000*m,Mmol = 1000000000*mol,
22942                 Ms = 1000000*s,ns = s/1000000000,ounce = pound_mass/16,
22943                 oz = ounce,Ohm = s*J/C^2,
22944                 pound_force = 32*ft*pound_mass/s^2,
22945                 pound_mass = 200*kg/441,psi = pound_force/inch^2,
22946                 Pa = N/m^2,week = 604800*s,Wb = J/A,yard = 3*feet,
22947                 year = 31557600*s,C = s*A,F = C^2/J,GA = 1000000000*A,
22948                 GC = 1000000000*C,GF = 1000000000*F,GH = 1000000000*H,
22949                 GJ = 1000000000*J,GK = 1000000000*K,GN = 1000000000*N,
22950                 GS = 1000000000*S,GT = 1000000000*T,GV = 1000000000*V,
22951                 GW = 1000000000*W,H = J/A^2,J = m*N,kA = 1000*A,
22952                 kC = 1000*C,kF = 1000*F,kH = 1000*H,kHz = 1000*Hz,
22953                 kJ = 1000*J,kK = 1000*K,kN = 1000*N,kOhm = 1000*Ohm,
22954                 kPa = 1000*Pa,kS = 1000*S,kT = 1000*T,kV = 1000*V,
22955                 kW = 1000*W,kWb = 1000*Wb,mA = A/1000,mC = C/1000,
22956                 mF = F/1000,mH = H/1000,mHz = Hz/1000,mJ = J/1000,
22957                 mK = K/1000,mN = N/1000,mOhm = Ohm/1000,mPa = Pa/1000,
22958                 mS = S/1000,mT = T/1000,mV = V/1000,mW = W/1000,
22959                 mWb = Wb/1000,MA = 1000000*A,MC = 1000000*C,
22960                 MF = 1000000*F,MH = 1000000*H,MJ = 1000000*J,
22961                 MK = 1000000*K,MN = 1000000*N,MS = 1000000*S,
22962                 MT = 1000000*T,MV = 1000000*V,MW = 1000000*W,
22963                 N = kg*m/s^2,R = 5*K/9,S = 1/Ohm,T = J/(m^2*A),V = J/C,
22964                 W = J/s}
22965
22966     Elementary unit conversions.
22967
22968          (%i1) load ("ezunits")$
22969          (%i2) 1 ` ft `` m;
22970          Computing conversions to base units; may take a moment.
22971                                      381
22972          (%o2)                       ---- ` m
22973                                      1250
22974          (%i3) %, numer;
22975          (%o3)                      0.3048 ` m
22976          (%i4) 1 ` kg `` lbm;
22977                                      441
22978          (%o4)                       --- ` lbm
22979                                      200
22980          (%i5) %, numer;
22981          (%o5)                      2.205 ` lbm
22982          (%i6) 1 ` W `` Btu/hour;
22983                                     720   Btu
22984          (%o6)                      --- ` ----
22985                                     211   hour
22986          (%i7) %, numer;
22987                                                  Btu
22988          (%o7)               3.412322274881517 ` ----
22989                                                  hour
22990          (%i8) 100 ` degC `` degF;
22991          (%o8)                      212 ` degF
22992          (%i9) -40 ` degF `` degC;
22993          (%o9)                     (- 40) ` degC
22994          (%i10) 1 ` acre*ft `` m^3;
22995                                  60228605349    3
22996          (%o10)                  ----------- ` m
22997                                   48828125
22998          (%i11) %, numer;
22999                                                    3
23000          (%o11)                1233.48183754752 ` m
23001
23002     Coercing quantities in feet and meters to one or the other.
23003
23004          (%i1) load ("ezunits")$
23005          (%i2) 100 ` m + 100 ` ft;
23006          (%o2)                  100 ` m + 100 ` ft
23007          (%i3) (100 ` m + 100 ` ft) `` ft;
23008          Computing conversions to base units; may take a moment.
23009                                     163100
23010          (%o3)                      ------ ` ft
23011                                      381
23012          (%i4) %, numer;
23013          (%o4)                428.0839895013123 ` ft
23014          (%i5) (100 ` m + 100 ` ft) `` m;
23015                                      3262
23016          (%o5)                       ---- ` m
23017                                       25
23018          (%i6) %, numer;
23019          (%o6)                      130.48 ` m
23020
23021     Dimensional analysis to find fundamental dimensions and fundamental
23022     units.
23023
23024          (%i1) load ("ezunits")$
23025          (%i2) foo : 1 ` acre * ft;
23026          (%o2)                      1 ` acre ft
23027          (%i3) dimensions (foo);
23028                                             3
23029          (%o3)                        length
23030          (%i4) fundamental_units (foo);
23031                                          3
23032          (%o4)                          m
23033          (%i5) foo `` m^3;
23034          Computing conversions to base units; may take a moment.
23035                                  60228605349    3
23036          (%o5)                   ----------- ` m
23037                                   48828125
23038          (%i6) %, numer;
23039                                                    3
23040          (%o6)                 1233.48183754752 ` m
23041
23042     Declared unit conversions.
23043
23044          (%i1) load ("ezunits")$
23045          (%i2) declare_unit_conversion (MMBtu = 10^6*Btu, kW = 1000*W);
23046          (%o2)                         done
23047          (%i3) declare_unit_conversion (kWh = kW*hour, MWh = 1000*kWh,
23048                                         bell = 1800*s);
23049          (%o3)                         done
23050          (%i4) 1 ` kW*s `` MWh;
23051          Computing conversions to base units; may take a moment.
23052                                       1
23053          (%o4)                     ------- ` MWh
23054                                    3600000
23055          (%i5) 1 ` kW/m^2 `` MMBtu/bell/ft^2;
23056                                 1306449      MMBtu
23057          (%o5)                 ---------- ` --------
23058                                8242187500          2
23059                                             bell ft
23060
23061 -- Function: constvalue (<x>)
23062
23063     Shows the value and the units of one of the constants declared by
23064     package 'physical_constants', which includes a list of physical
23065     constants, or of a new constant declared in package 'ezunits' (see
23066     'declare_constvalue').
23067
23068     Note that constant values as recognized by 'constvalue' are
23069     separate from values declared by 'numerval' and recognized by
23070     'constantp'.
23071
23072     Example:
23073
23074          (%i1) load ("physical_constants")$
23075          (%i2) constvalue (%G);
23076                                               3
23077                                              m
23078          (%o2)                    6.67428 ` -----
23079                                                 2
23080                                             kg s
23081          (%i3) get ('%G, 'description);
23082          (%o3)           Newtonian constant of gravitation
23083
23084 -- Function: declare_constvalue (<a>, <x>)
23085
23086     Declares the value of a constant to be used in package 'ezunits'.
23087     This function should be loaded with 'load ("ezunits")'.
23088
23089     Example:
23090
23091          (%i1) load ("ezunits")$
23092          (%i2) declare_constvalue (FOO, 100 ` lbm / acre);
23093                                           lbm
23094          (%o2)                      100 ` ----
23095                                           acre
23096          (%i3) FOO * (50 ` acre);
23097          (%o3)                     50 FOO ` acre
23098          (%i4) constvalue (%);
23099          (%o4)                      5000 ` lbm
23100
23101 -- Function: remove_constvalue (<a>)
23102
23103     Reverts the effect of 'declare_constvalue'.  This function should
23104     be loaded with 'load ("ezunits")'.
23105
23106 -- Function: units (<x>)
23107
23108     Returns the units of a dimensional quantity <x>, or returns 1 if
23109     <x> is nondimensional.
23110
23111     <x> may be a literal dimensional expression a ` b, a symbol with
23112     declared units via 'declare_units', or an expression containing
23113     either or both of those.
23114
23115     This function should be loaded with 'load ("ezunits")'.
23116
23117     Example:
23118
23119          (%i1) load ("ezunits")$
23120          (%i2) foo : 100 ` kg;
23121          (%o2)                       100 ` kg
23122          (%i3) bar : x ` m/s;
23123                                            m
23124          (%o3)                         x ` -
23125                                            s
23126          (%i4) units (foo);
23127          (%o4)                          kg
23128          (%i5) units (bar);
23129                                          m
23130          (%o5)                           -
23131                                          s
23132          (%i6) units (foo * bar);
23133                                        kg m
23134          (%o6)                         ----
23135                                         s
23136          (%i7) units (foo / bar);
23137                                        kg s
23138          (%o7)                         ----
23139                                         m
23140          (%i8) units (foo^2);
23141                                           2
23142          (%o8)                          kg
23143
23144 -- Function: declare_units (<a>, <u>)
23145
23146     Declares that 'units' should return units <u> for <a>, where <u> is
23147     an expression.  This function should be loaded with 'load
23148     ("ezunits")'.
23149
23150     Example:
23151
23152          (%i1) load ("ezunits")$
23153          (%i2) units (aa);
23154          (%o2)                           1
23155          (%i3) declare_units (aa, J);
23156          (%o3)                           J
23157          (%i4) units (aa);
23158          (%o4)                           J
23159          (%i5) units (aa^2);
23160                                          2
23161          (%o5)                          J
23162          (%i6) foo : 100 ` kg;
23163          (%o6)                       100 ` kg
23164          (%i7) units (aa * foo);
23165          (%o7)                         kg J
23166
23167 -- Function: qty (<x>)
23168
23169     Returns the nondimensional part of a dimensional quantity <x>, or
23170     returns <x> if <x> is nondimensional.  <x> may be a literal
23171     dimensional expression a ` b, a symbol with declared quantity, or
23172     an expression containing either or both of those.
23173
23174     This function should be loaded with 'load ("ezunits")'.
23175
23176     Example:
23177
23178          (%i1) load ("ezunits")$
23179          (%i2) foo : 100 ` kg;
23180          (%o2)                       100 ` kg
23181          (%i3) qty (foo);
23182          (%o3)                          100
23183          (%i4) bar : v ` m/s;
23184                                            m
23185          (%o4)                         v ` -
23186                                            s
23187          (%i5) foo * bar;
23188                                            kg m
23189          (%o5)                     100 v ` ----
23190                                             s
23191          (%i6) qty (foo * bar);
23192          (%o6)                         100 v
23193
23194 -- Function: declare_qty (<a>, <x>)
23195
23196     Declares that 'qty' should return <x> for symbol <a>, where <x> is
23197     a nondimensional quantity.  This function should be loaded with
23198     'load ("ezunits")'.
23199
23200     Example:
23201
23202          (%i1) load ("ezunits")$
23203          (%i2) declare_qty (aa, xx);
23204          (%o2)                          xx
23205          (%i3) qty (aa);
23206          (%o3)                          xx
23207          (%i4) qty (aa^2);
23208                                           2
23209          (%o4)                          xx
23210          (%i5) foo : 100 ` kg;
23211          (%o5)                       100 ` kg
23212          (%i6) qty (aa * foo);
23213          (%o6)                        100 xx
23214
23215 -- Function: unitp (<x>)
23216
23217     Returns 'true' if <x> is a literal dimensional expression, a symbol
23218     declared dimensional, or an expression in which the main operator
23219     is declared dimensional.  'unitp' returns 'false' otherwise.
23220
23221     'load ("ezunits")' loads this function.
23222
23223     Examples:
23224
23225     'unitp' applied to a literal dimensional expression.
23226
23227          (%i1) load ("ezunits")$
23228          (%i2) unitp (100 ` kg);
23229          (%o2)                         true
23230
23231     'unitp' applied to a symbol declared dimensional.
23232
23233          (%i1) load ("ezunits")$
23234          (%i2) unitp (foo);
23235          (%o2)                         false
23236          (%i3) declare (foo, dimensional);
23237          (%o3)                         done
23238          (%i4) unitp (foo);
23239          (%o4)                         true
23240
23241     'unitp' applied to an expression in which the main operator is
23242     declared dimensional.
23243
23244          (%i1) load ("ezunits")$
23245          (%i2) unitp (bar (x, y, z));
23246          (%o2)                         false
23247          (%i3) declare (bar, dimensional);
23248          (%o3)                         done
23249          (%i4) unitp (bar (x, y, z));
23250          (%o4)                         true
23251
23252 -- Function: declare_unit_conversion (<u> = <v>, ...)
23253
23254     Appends equations <u> = <v>, ...  to the list of unit conversions
23255     known to the unit conversion operator ``.  <u> and <v> are both
23256     multiplicative terms, in which any variables are units, or both
23257     literal dimensional expressions.
23258
23259     At present, it is necessary to express conversions such that the
23260     left-hand side of each equation is a simple unit (not a
23261     multiplicative expression) or a literal dimensional expression with
23262     the quantity equal to 1 and the unit being a simple unit.  This
23263     limitation might be relaxed in future versions.
23264
23265     'known_unit_conversions' is the list of known unit conversions.
23266
23267     This function should be loaded with 'load ("ezunits")'.
23268
23269     Examples:
23270
23271     Unit conversions expressed by equations of multiplicative terms.
23272
23273          (%i1) load ("ezunits")$
23274          (%i2) declare_unit_conversion (nautical_mile = 1852 * m,
23275                                         fortnight = 14 * day);
23276          (%o2)                         done
23277          (%i3) 100 ` nautical_mile / fortnight `` m/s;
23278          Computing conversions to base units; may take a moment.
23279                                      463    m
23280          (%o3)                       ---- ` -
23281                                      3024   s
23282
23283     Unit conversions expressed by equations of literal dimensional
23284     expressions.
23285
23286          (%i1) load ("ezunits")$
23287          (%i2) declare_unit_conversion (1 ` fluid_ounce = 2 ` tablespoon);
23288          (%o2)                         done
23289          (%i3) declare_unit_conversion (1 ` tablespoon = 3 ` teaspoon);
23290          (%o3)                         done
23291          (%i4) 15 ` fluid_ounce `` teaspoon;
23292          Computing conversions to base units; may take a moment.
23293          (%o4)                     90 ` teaspoon
23294
23295 -- Function: declare_dimensions (<a_1>, <d_1>, ..., <a_n>, <d_n>)
23296
23297     Declares <a_1>, ..., <a_n> to have dimensions <d_1>, ..., <d_n>,
23298     respectively.
23299
23300     Each <a_k> is a symbol or a list of symbols.  If it is a list, then
23301     every symbol in <a_k> is declared to have dimension <d_k>.
23302
23303     'load ("ezunits")' loads these functions.
23304
23305     Examples:
23306
23307          (%i1) load ("ezunits") $
23308          (%i2) declare_dimensions ([x, y, z], length, [t, u], time);
23309          (%o2)                         done
23310          (%i3) dimensions (y^2/u);
23311                                             2
23312                                       length
23313          (%o3)                        -------
23314                                        time
23315          (%i4) fundamental_units (y^2/u);
23316          0 errors, 0 warnings
23317                                          2
23318                                         m
23319          (%o4)                          --
23320                                         s
23321
23322 -- Function: remove_dimensions (<a_1>, ..., <a_n>)
23323
23324     Reverts the effect of 'declare_dimensions'.  This function should
23325     be loaded with 'load ("ezunits")'.
23326
23327 -- Function: declare_fundamental_dimensions (<d_1>, <d_2>, <d_3>, ...)
23328 -- Function: remove_fundamental_dimensions (<d_1>, <d_2>, <d_3>, ...)
23329 -- Global variable: fundamental_dimensions
23330
23331     'declare_fundamental_dimensions' declares fundamental dimensions.
23332     Symbols <d_1>, <d_2>, <d_3>, ...  are appended to the list of
23333     fundamental dimensions, if they are not already on the list.
23334
23335     'remove_fundamental_dimensions' reverts the effect of
23336     'declare_fundamental_dimensions'.
23337
23338     'fundamental_dimensions' is the list of fundamental dimensions.  By
23339     default, the list comprises several physical dimensions.
23340
23341     'load ("ezunits")' loads these functions.
23342
23343     Examples:
23344
23345          (%i1) load ("ezunits") $
23346          (%i2) fundamental_dimensions;
23347          (%o2) [length, mass, time, current, temperature, quantity]
23348          (%i3) declare_fundamental_dimensions (money, cattle, happiness);
23349          (%o3)                         done
23350          (%i4) fundamental_dimensions;
23351          (%o4) [length, mass, time, current, temperature, quantity,
23352                                                  money, cattle, happiness]
23353          (%i5) remove_fundamental_dimensions (cattle, happiness);
23354          (%o5)                         done
23355          (%i6) fundamental_dimensions;
23356          (%o6) [length, mass, time, current, temperature, quantity, money]
23357
23358 -- Function: declare_fundamental_units (<u_1>, <d_1>, ..., <u_n>,
23359          <d_n>)
23360 -- Function: remove_fundamental_units (<u_1>, ..., <u_n>)
23361
23362     'declare_fundamental_units' declares <u_1>, ..., <u_n> to have
23363     dimensions <d_1>, ..., <d_n>, respectively.  All arguments must be
23364     symbols.
23365
23366     After calling 'declare_fundamental_units', 'dimensions(<u_k>)'
23367     returns <d_k> for each argument <u_1>, ..., <u_n>, and
23368     'fundamental_units(<d_k>)' returns <u_k> for each argument <d_1>,
23369     ..., <d_n>.
23370
23371     'remove_fundamental_units' reverts the effect of
23372     'declare_fundamental_units'.
23373
23374     'load ("ezunits")' loads these functions.
23375
23376     Examples:
23377
23378          (%i1) load ("ezunits") $
23379          (%i2) declare_fundamental_dimensions (money, cattle, happiness);
23380          (%o2)                         done
23381          (%i3) declare_fundamental_units (dollar, money, goat, cattle,
23382                                           smile, happiness);
23383          (%o3)                 [dollar, goat, smile]
23384          (%i4) dimensions (100 ` dollar/goat/km^2);
23385                                       money
23386          (%o4)                    --------------
23387                                                2
23388                                   cattle length
23389          (%i5) dimensions (x ` smile/kg);
23390                                      happiness
23391          (%o5)                       ---------
23392                                        mass
23393          (%i6) fundamental_units (money*cattle/happiness);
23394          0 errors, 0 warnings
23395                                     dollar goat
23396          (%o6)                      -----------
23397                                        smile
23398
23399 -- Function: dimensions (<x>)
23400 -- Function: dimensions_as_list (<x>)
23401
23402     'dimensions' returns the dimensions of the dimensional quantity <x>
23403     as an expression comprising products and powers of base dimensions.
23404
23405     'dimensions_as_list' returns the dimensions of the dimensional
23406     quantity <x> as a list, in which each element is an integer which
23407     indicates the power of the corresponding base dimension in the
23408     dimensions of <x>.
23409
23410     'load ("ezunits")' loads these functions.
23411
23412     Examples:
23413
23414          (%i1) load ("ezunits")$
23415          (%i2) dimensions (1000 ` kg*m^2/s^3);
23416                                          2
23417                                    length  mass
23418          (%o2)                     ------------
23419                                           3
23420                                       time
23421          (%i3) declare_units (foo, acre*ft/hour);
23422                                       acre ft
23423          (%o3)                        -------
23424                                        hour
23425          (%i4) dimensions (foo);
23426                                             3
23427                                       length
23428          (%o4)                        -------
23429                                        time
23430
23431          (%i1) load ("ezunits")$
23432          (%i2) fundamental_dimensions;
23433          (%o2)  [length, mass, time, charge, temperature, quantity]
23434          (%i3) dimensions_as_list (1000 ` kg*m^2/s^3);
23435          (%o3)                 [2, 1, - 3, 0, 0, 0]
23436          (%i4) declare_units (foo, acre*ft/hour);
23437                                       acre ft
23438          (%o4)                        -------
23439                                        hour
23440          (%i5) dimensions_as_list (foo);
23441          (%o5)                 [3, 0, - 1, 0, 0, 0]
23442
23443 -- Function: fundamental_units
23444          fundamental_units (<x>)
23445          fundamental_units ()
23446
23447     'fundamental_units(<x>)' returns the units associated with the
23448     fundamental dimensions of <x>.  as determined by 'dimensions(<x>)'.
23449
23450     <x> may be a literal dimensional expression a ` b, a symbol with
23451     declared units via 'declare_units', or an expression containing
23452     either or both of those.
23453
23454     'fundamental_units()' returns the list of all known fundamental
23455     units, as declared by 'declare_fundamental_units'.
23456
23457     'load ("ezunits")' loads this function.
23458
23459     Examples:
23460
23461          (%i1) load ("ezunits")$
23462          (%i2) fundamental_units ();
23463          (%o2)                 [m, kg, s, A, K, mol]
23464          (%i3) fundamental_units (100 ` mile/hour);
23465                                          m
23466          (%o3)                           -
23467                                          s
23468          (%i4) declare_units (aa, g/foot^2);
23469                                          g
23470          (%o4)                         -----
23471                                            2
23472                                        foot
23473          (%i5) fundamental_units (aa);
23474                                         kg
23475          (%o5)                          --
23476                                          2
23477                                         m
23478
23479 -- Function: dimensionless (<L>)
23480
23481     Returns a basis for the dimensionless quantities which can be
23482     formed from a list <L> of dimensional quantities.
23483
23484     'load ("ezunits")' loads this function.
23485
23486     Examples:
23487
23488          (%i1) load ("ezunits") $
23489          (%i2) dimensionless ([x ` m, y ` m/s, z ` s]);
23490          0 errors, 0 warnings
23491          0 errors, 0 warnings
23492                                         y z
23493          (%o2)                         [---]
23494                                          x
23495
23496     Dimensionless quantities derived from fundamental physical
23497     quantities.  Note that the first element on the list is
23498     proportional to the fine-structure constant.
23499
23500          (%i1) load ("ezunits") $
23501          (%i2) load ("physical_constants") $
23502          (%i3) dimensionless([%h_bar, %m_e, %m_P, %%e, %c, %e_0]);
23503          0 errors, 0 warnings
23504          0 errors, 0 warnings
23505                                        2
23506                                     %%e        %m_e
23507          (%o3)                [--------------, ----]
23508                                %c %e_0 %h_bar  %m_P
23509
23510 -- Function: natural_unit (<expr>, [<v_1>, ..., <v_n>])
23511
23512     Finds exponents <e_1>, ..., <e_n> such that 'dimension(<expr>) =
23513     dimension(<v_1>^<e_1> ... <v_n>^<e_n>)'.
23514
23515     'load ("ezunits")' loads this function.
23516
23517     Examples:
23518
23519
23520
23521File: maxima.info,  Node: f90-pkg,  Next: finance-pkg,  Prev: ezunits-pkg,  Up: Top
23522
2352358 f90
23524******
23525
23526* Menu:
23527
23528* Package f90::
23529
23530
23531File: maxima.info,  Node: Package f90,  Prev: f90-pkg,  Up: f90-pkg
23532
2353358.1 Package f90
23534================
23535
23536 -- Option variable: f90_output_line_length_max
23537     Default value: 65
23538
23539     'f90_output_line_length_max' is the maximum number of characters of
23540     Fortran code which are output by 'f90' per line.  Longer lines of
23541     code are divided, and printed with an ampersand '&' at the end of
23542     an output line and an ampersand at the beginning of the following
23543     line.
23544
23545     'f90_output_line_length_max' must be a positive integer.
23546
23547     Example:
23548
23549          (%i1) load ("f90")$
23550          (%i2) foo : expand ((xxx + yyy + 7)^4);
23551                   4            3         3        2    2             2
23552          (%o2) yyy  + 4 xxx yyy  + 28 yyy  + 6 xxx  yyy  + 84 xxx yyy
23553                    2        3             2
23554           + 294 yyy  + 4 xxx  yyy + 84 xxx  yyy + 588 xxx yyy + 1372 yyy
23555                4         3          2
23556           + xxx  + 28 xxx  + 294 xxx  + 1372 xxx + 2401
23557          (%i3) f90_output_line_length_max;
23558          (%o3)                          65
23559          (%i4) f90 ('foo = foo);
23560          foo = yyy**4+4*xxx*yyy**3+28*yyy**3+6*xxx**2*yyy**2+84*xxx*yyy**2&
23561          &+294*yyy**2+4*xxx**3*yyy+84*xxx**2*yyy+588*xxx*yyy+1372*yyy+xxx**&
23562          &4+28*xxx**3+294*xxx**2+1372*xxx+2401
23563          (%o4)                         false
23564          (%i5) f90_output_line_length_max : 40 $
23565          (%i6) f90 ('foo = foo);
23566          foo = yyy**4+4*xxx*yyy**3+28*yyy**3+6*xx&
23567          &x**2*yyy**2+84*xxx*yyy**2+294*yyy**2+4*x&
23568          &xx**3*yyy+84*xxx**2*yyy+588*xxx*yyy+1372&
23569          &*yyy+xxx**4+28*xxx**3+294*xxx**2+1372*xx&
23570          &x+2401
23571          (%o6)                         false
23572
23573 -- Function: f90 (<expr_1>, ..., <expr_n>)
23574
23575     Prints one or more expressions <expr_1>, ..., <expr_n> as a Fortran
23576     90 program.  Output is printed to the standard output.
23577
23578     'f90' prints output in the so-called "free form" input format for
23579     Fortran 90: there is no special attention to column positions.
23580     Long lines are split at a fixed width with the ampersand '&'
23581     continuation character; the number of output characters per line,
23582     not including ampersands, is specified by
23583     'f90_output_line_length_max'.  'f90' outputs an ampersand at the
23584     end of a split line and another at the beginning of the next line.
23585
23586     'load("f90")' loads this function.  See also the function
23587     'fortran'.
23588
23589     Examples:
23590
23591          (%i1) load ("f90")$
23592          (%i2) foo : expand ((xxx + yyy + 7)^4);
23593                   4            3         3        2    2             2
23594          (%o2) yyy  + 4 xxx yyy  + 28 yyy  + 6 xxx  yyy  + 84 xxx yyy
23595                    2        3             2
23596           + 294 yyy  + 4 xxx  yyy + 84 xxx  yyy + 588 xxx yyy + 1372 yyy
23597                4         3          2
23598           + xxx  + 28 xxx  + 294 xxx  + 1372 xxx + 2401
23599          (%i3) f90 ('foo = foo);
23600          foo = yyy**4+4*xxx*yyy**3+28*yyy**3+6*xxx**2*yyy**2+84*xxx*yyy**2&
23601          &+294*yyy**2+4*xxx**3*yyy+84*xxx**2*yyy+588*xxx*yyy+1372*yyy+xxx**&
23602          &4+28*xxx**3+294*xxx**2+1372*xxx+2401
23603          (%o3)                         false
23604
23605     Multiple expressions.  Capture standard output into a file via the
23606     'with_stdout' function.
23607
23608          (%i1) load ("f90")$
23609          (%i2) foo : sin (3*x + 1) - cos (7*x - 2);
23610          (%o2)              sin(3 x + 1) - cos(7 x - 2)
23611          (%i3) with_stdout ("foo.f90",
23612                             f90 (x=0.25, y=0.625, 'foo=foo, 'stop, 'end));
23613          (%o3)                         false
23614          (%i4) printfile ("foo.f90");
23615          x = 0.25
23616          y = 0.625
23617          foo = sin(3*x+1)-cos(7*x-2)
23618          stop
23619          end
23620          (%o4)                        foo.f90
23621
23622
23623File: maxima.info,  Node: finance-pkg,  Next: fractals-pkg,  Prev: f90-pkg,  Up: Top
23624
2362559 finance
23626**********
23627
23628* Menu:
23629
23630* Introduction to finance::
23631* Functions and Variables for finance::
23632
23633
23634File: maxima.info,  Node: Introduction to finance,  Next: Functions and Variables for finance,  Prev: finance-pkg,  Up: finance-pkg
23635
2363659.1 Introduction to finance
23637============================
23638
23639This is the Finance Package (Ver 0.1).
23640
23641   In all the functions, <rate> is the compound interest rate, <num> is
23642the number of periods and must be positive and <flow> refers to cash
23643flow so if you have an Output the flow is negative and positive for
23644Inputs.
23645
23646   Note that before using the functions defined in this package, you
23647have to load it writing 'load(finance)$'.
23648
23649   Author: Nicolas Guarin Zapata.
23650
23651
23652File: maxima.info,  Node: Functions and Variables for finance,  Prev: Introduction to finance,  Up: finance-pkg
23653
2365459.2 Functions and Variables for finance
23655========================================
23656
23657 -- Function: days360 (<year1>,<month1>,<day1>,<year2>,<month2>,<day2>)
23658
23659     Calculates the distance between 2 dates, assuming 360 days years,
23660     30 days months.
23661
23662     Example:
23663
23664          (%i1) load("finance")$
23665          (%i2) days360(2008,12,16,2007,3,25);
23666          (%o2)                      - 621
23667
23668 -- Function: fv (<rate>,<PV>,<num>)
23669
23670     We can calculate the future value of a Present one given a certain
23671     interest rate.  <rate> is the interest rate, <PV> is the present
23672     value and <num> is the number of periods.
23673
23674     Example:
23675
23676          (%i1) load("finance")$
23677          (%i2) fv(0.12,1000,3);
23678          (%o2)                     1404.928
23679
23680 -- Function: pv (<rate>,<FV>,<num>)
23681
23682     We can calculate the present value of a Future one given a certain
23683     interest rate.  <rate> is the interest rate, <FV> is the future
23684     value and <num> is the number of periods.
23685
23686     Example:
23687
23688          (%i1) load("finance")$
23689          (%i2) pv(0.12,1000,3);
23690          (%o2)                711.7802478134108
23691
23692 -- Function: graph_flow (<val>)
23693
23694     Plots the money flow in a time line, the positive values are in
23695     blue and upside; the negative ones are in red and downside.  The
23696     direction of the flow is given by the sign of the value.  <val> is
23697     a list of flow values.
23698
23699     Example:
23700
23701          (%i1) load("finance")$
23702          (%i2) graph_flow([-5000,-3000,800,1300,1500,2000])$
23703
23704 -- Function: annuity_pv (<rate>,<PV>,<num>)
23705
23706     We can calculate the annuity knowing the present value (like an
23707     amount), it is a constant and periodic payment.  <rate> is the
23708     interest rate, <PV> is the present value and <num> is the number of
23709     periods.
23710
23711     Example:
23712
23713          (%i1) load("finance")$
23714          (%i2) annuity_pv(0.12,5000,10);
23715          (%o2)                884.9208207992202
23716
23717 -- Function: annuity_fv (<rate>,<FV>,<num>)
23718
23719     We can calculate the annuity knowing the desired value (future
23720     value), it is a constant and periodic payment.  <rate> is the
23721     interest rate, <FV> is the future value and <num> is the number of
23722     periods.
23723
23724     Example:
23725
23726          (%i1) load("finance")$
23727          (%i2) annuity_fv(0.12,65000,10);
23728          (%o2)                3703.970670389863
23729
23730 -- Function: geo_annuity_pv (<rate>,<growing_rate>,<PV>,<num>)
23731
23732     We can calculate the annuity knowing the present value (like an
23733     amount), in a growing periodic payment.  <rate> is the interest
23734     rate, <growing_rate> is the growing rate, <PV> is the present value
23735     and <num> is the number of periods.
23736
23737     Example:
23738
23739          (%i1) load("finance")$
23740          (%i2) geo_annuity_pv(0.14,0.05,5000,10);
23741          (%o2)                802.6888176505123
23742
23743 -- Function: geo_annuity_fv (<rate>,<growing_rate>,<FV>,<num>)
23744
23745     We can calculate the annuity knowing the desired value (future
23746     value), in a growing periodic payment.  <rate> is the interest
23747     rate, <growing_rate> is the growing rate, <FV> is the future value
23748     and <num> is the number of periods.
23749
23750     Example:
23751
23752          (%i1) load("finance")$
23753          (%i2) geo_annuity_fv(0.14,0.05,5000,10);
23754          (%o2)                216.5203395312695
23755
23756 -- Function: amortization (<rate>,<amount>,<num>)
23757
23758     Amortization table determined by a specific rate.  <rate> is the
23759     interest rate, <amount> is the amount value, and <num> is the
23760     number of periods.
23761
23762     Example:
23763
23764          (%i1) load("finance")$
23765          (%i2) amortization(0.05,56000,12)$
23766                "n"    "Balance"     "Interest"   "Amortization"  "Payment"
23767               0.000     56000.000         0.000         0.000         0.000
23768               1.000     52481.777      2800.000      3518.223      6318.223
23769               2.000     48787.643      2624.089      3694.134      6318.223
23770               3.000     44908.802      2439.382      3878.841      6318.223
23771               4.000     40836.019      2245.440      4072.783      6318.223
23772               5.000     36559.597      2041.801      4276.422      6318.223
23773               6.000     32069.354      1827.980      4490.243      6318.223
23774               7.000     27354.599      1603.468      4714.755      6318.223
23775               8.000     22404.106      1367.730      4950.493      6318.223
23776               9.000     17206.088      1120.205      5198.018      6318.223
23777              10.000     11748.170       860.304      5457.919      6318.223
23778              11.000      6017.355       587.408      5730.814      6318.223
23779              12.000         0.000       300.868      6017.355      6318.223
23780
23781 -- Function: arit_amortization (<rate>,<increment>,<amount>,<num>)
23782
23783     The amortization table determined by a specific rate and with
23784     growing payment can be claculated by 'arit_amortization'.  Notice
23785     that the payment is not constant, it presents an arithmetic
23786     growing, increment is then the difference between two consecutive
23787     rows in the "Payment" column.  <rate> is the interest rate,
23788     <increment> is the increment, <amount> is the amount value, and
23789     <num> is the number of periods.
23790
23791     Example:
23792
23793          (%i1) load("finance")$
23794          (%i2) arit_amortization(0.05,1000,56000,12)$
23795                "n"    "Balance"     "Interest"   "Amortization"  "Payment"
23796               0.000     56000.000         0.000         0.000         0.000
23797               1.000     57403.679      2800.000     -1403.679      1396.321
23798               2.000     57877.541      2870.184      -473.863      2396.321
23799               3.000     57375.097      2893.877       502.444      3396.321
23800               4.000     55847.530      2868.755      1527.567      4396.321
23801               5.000     53243.586      2792.377      2603.945      5396.321
23802               6.000     49509.443      2662.179      3734.142      6396.321
23803               7.000     44588.594      2475.472      4920.849      7396.321
23804               8.000     38421.703      2229.430      6166.892      8396.321
23805               9.000     30946.466      1921.085      7475.236      9396.321
23806              10.000     22097.468      1547.323      8848.998     10396.321
23807              11.000     11806.020      1104.873     10291.448     11396.321
23808              12.000        -0.000       590.301     11806.020     12396.321
23809
23810 -- Function: geo_amortization (<rate>,<growing_rate>,<amount>,<num>)
23811
23812     The amortization table determined by rate, amount, and number of
23813     periods can be found by 'geo_amortization'.  Notice that the
23814     payment is not constant, it presents a geometric growing,
23815     <growing_rate> is then the quotient between two consecutive rows in
23816     the "Payment" column.  <rate> is the interest rate, <amount> is the
23817     amount value, and <num> is the number of periods.
23818
23819     Example:
23820
23821          (%i1) load("finance")$
23822          (%i2) geo_amortization(0.05,0.03,56000,12)$
23823                "n"    "Balance"     "Interest"   "Amortization"  "Payment"
23824               0.000     56000.000         0.000         0.000         0.000
23825               1.000     53365.296      2800.000      2634.704      5434.704
23826               2.000     50435.816      2668.265      2929.480      5597.745
23827               3.000     47191.930      2521.791      3243.886      5765.677
23828               4.000     43612.879      2359.596      3579.051      5938.648
23829               5.000     39676.716      2180.644      3936.163      6116.807
23830               6.000     35360.240      1983.836      4316.475      6300.311
23831               7.000     30638.932      1768.012      4721.309      6489.321
23832               8.000     25486.878      1531.947      5152.054      6684.000
23833               9.000     19876.702      1274.344      5610.176      6884.520
23834              10.000     13779.481       993.835      6097.221      7091.056
23835              11.000      7164.668       688.974      6614.813      7303.787
23836              12.000         0.000       358.233      7164.668      7522.901
23837
23838 -- Function: saving (<rate>,<amount>,<num>)
23839
23840     The table that represents the values in a constant and periodic
23841     saving can be found by 'saving'.  <amount> represents the desired
23842     quantity and num the number of periods to save.
23843
23844     Example:
23845
23846          (%i1) load("finance")$
23847          (%i2) saving(0.15,12000,15)$
23848                "n"    "Balance"     "Interest"   "Payment"
23849               0.000         0.000         0.000         0.000
23850               1.000       252.205         0.000       252.205
23851               2.000       542.240        37.831       252.205
23852               3.000       875.781        81.336       252.205
23853               4.000      1259.352       131.367       252.205
23854               5.000      1700.460       188.903       252.205
23855               6.000      2207.733       255.069       252.205
23856               7.000      2791.098       331.160       252.205
23857               8.000      3461.967       418.665       252.205
23858               9.000      4233.467       519.295       252.205
23859              10.000      5120.692       635.020       252.205
23860              11.000      6141.000       768.104       252.205
23861              12.000      7314.355       921.150       252.205
23862              13.000      8663.713      1097.153       252.205
23863              14.000     10215.474      1299.557       252.205
23864              15.000     12000.000      1532.321       252.205
23865
23866 -- Function: npv (<rate>,<val>)
23867
23868     Calculates the present value of a value series to evaluate the
23869     viability in a project.  <val> is a list of varying cash flows.
23870
23871     Example:
23872
23873          (%i1) load("finance")$
23874          (%i2) npv(0.25,[100,500,323,124,300]);
23875          (%o2)                714.4703999999999
23876
23877 -- Function: irr (<val>,<IO>)
23878
23879     IRR (Internal Rate of Return) is the value of rate which makes Net
23880     Present Value zero.  <flowValues> is a list of varying cash flows,
23881     <I0> is the initial investment.
23882
23883     Example:
23884
23885          (%i1) load("finance")$
23886          (%i2) res:irr([-5000,0,800,1300,1500,2000],0)$
23887          (%i3) rhs(res[1][1]);
23888          (%o3)                .03009250374237132
23889
23890 -- Function: benefit_cost (<rate>,<input>,<output>)
23891
23892     Calculates the ratio Benefit/Cost.  Benefit is the Net Present
23893     Value (NPV) of the inputs, and Cost is the Net Present Value (NPV)
23894     of the outputs.  Notice that if there is not an input or output
23895     value in a specific period, the input/output would be a zero for
23896     that period.  <rate> is the interest rate, <input> is a list of
23897     input values, and <output> is a list of output values.
23898
23899     Example:
23900
23901          (%i1) load("finance")$
23902          (%i2) benefit_cost(0.24,[0,300,500,150],[100,320,0,180]);
23903          (%o2)               1.427249324905784
23904
23905
23906File: maxima.info,  Node: fractals-pkg,  Next: ggf-pkg,  Prev: finance-pkg,  Up: Top
23907
2390860 fractals
23909***********
23910
23911* Menu:
23912
23913* Introduction to fractals::
23914* Definitions for IFS fractals::
23915* Definitions for complex fractals::
23916* Definitions for Koch snowflakes::
23917* Definitions for Peano maps::
23918
23919
23920File: maxima.info,  Node: Introduction to fractals,  Next: Definitions for IFS fractals,  Prev: fractals-pkg,  Up: fractals-pkg
23921
2392260.1 Introduction to fractals
23923=============================
23924
23925This package defines some well known fractals:
23926
23927   - with random IFS (Iterated Function System): the Sierpinsky
23928triangle, a Tree and a Fern
23929
23930   - Complex Fractals: the Mandelbrot and Julia Sets
23931
23932   - the Koch snowflake sets
23933
23934   - Peano maps: the Sierpinski and Hilbert maps
23935
23936   Author: Jose' Rami'rez Labrador.
23937
23938   For questions, suggestions and bugs, please feel free to contact me
23939at
23940
23941   pepe DOT ramirez AAATTT uca DOT es
23942
23943
23944File: maxima.info,  Node: Definitions for IFS fractals,  Next: Definitions for complex fractals,  Prev: Introduction to fractals,  Up: fractals-pkg
23945
2394660.2 Definitions for IFS fractals
23947=================================
23948
23949Some fractals can be generated by iterative applications of contractive
23950affine transformations in a random way; see
23951
23952   Hoggar S. G., "Mathematics for computer graphics", Cambridge
23953University Press 1994.
23954
23955   We define a list with several contractive affine transformations, and
23956we randomly select the transformation in a recursive way.  The
23957probability of the choice of a transformation must be related with the
23958contraction ratio.
23959
23960   You can change the transformations and find another fractal
23961
23962 -- Function: sierpinskiale (<n>)
23963
23964     Sierpinski Triangle: 3 contractive maps; .5 contraction constant
23965     and translations; all maps have the same contraction ratio.
23966     Argument <n> must be great enougth, 10000 or greater.
23967
23968     Example:
23969
23970          (%i1) load("fractals")$
23971          (%i2) n: 10000$
23972          (%i3) plot2d([discrete,sierpinskiale(n)], [style,dots])$
23973
23974 -- Function: treefale (<n>)
23975
23976     3 contractive maps all with the same contraction ratio.  Argument
23977     <n> must be great enougth, 10000 or greater.
23978
23979     Example:
23980
23981          (%i1) load("fractals")$
23982          (%i2) n: 10000$
23983          (%i3) plot2d([discrete,treefale(n)], [style,dots])$
23984
23985 -- Function: fernfale (<n>)
23986
23987     4 contractive maps, the probability to choice a transformation must
23988     be related with the contraction ratio.  Argument <n> must be great
23989     enougth, 10000 or greater.
23990
23991     Example:
23992
23993          (%i1) load("fractals")$
23994          (%i2) n: 10000$
23995          (%i3) plot2d([discrete,fernfale(n)], [style,dots])$
23996
23997
23998File: maxima.info,  Node: Definitions for complex fractals,  Next: Definitions for Koch snowflakes,  Prev: Definitions for IFS fractals,  Up: Top
23999
2400060.3 Definitions for complex fractals
24001=====================================
24002
24003 -- Function: mandelbrot_set (<x>, <y>)
24004
24005     Mandelbrot set.
24006
24007     Example:
24008
24009     This program is time consuming because it must make a lot of
24010     operations; the computing time is also related with the number of
24011     grid points.
24012
24013          (%i1) load("fractals")$
24014          (%i2) plot3d (mandelbrot_set, [x, -2.5, 1], [y, -1.5, 1.5],
24015                          [gnuplot_preamble, "set view map"],
24016                          [gnuplot_pm3d, true],
24017                          [grid, 150, 150])$
24018
24019 -- Function: julia_set (<x>, <y>)
24020
24021     Julia sets.
24022
24023     This program is time consuming because it must make a lot of
24024     operations; the computing time is also related with the number of
24025     grid points.
24026
24027     Example:
24028
24029          (%i1) load("fractals")$
24030          (%i2) plot3d (julia_set, [x, -2, 1], [y, -1.5, 1.5],
24031                          [gnuplot_preamble, "set view map"],
24032                          [gnuplot_pm3d, true],
24033                          [grid, 150, 150])$
24034
24035     See also 'julia_parameter'.
24036
24037 -- Optional variable: julia_parameter
24038     Default value: '%i'
24039
24040     Complex parameter for Julia fractals.  Its default value is '%i';
24041     we suggest the values '-.745+%i*.113002', '-.39054-%i*.58679',
24042     '-.15652+%i*1.03225', '-.194+%i*.6557' and '.011031-%i*.67037'.
24043
24044 -- Function: julia_sin (<x>, <y>)
24045
24046     While function 'julia_set' implements the transformation
24047     'julia_parameter+z^2', function 'julia_sin' implements
24048     'julia_parameter*sin(z)'.  See source code for more details.
24049
24050     This program runs slowly because it calculates a lot of sines.
24051
24052     Example:
24053
24054     This program is time consuming because it must make a lot of
24055     operations; the computing time is also related with the number of
24056     grid points.
24057
24058          (%i1) load("fractals")$
24059          (%i2) julia_parameter:1+.1*%i$
24060          (%i3) plot3d (julia_sin, [x, -2, 2], [y, -3, 3],
24061                          [gnuplot_preamble, "set view map"],
24062                          [gnuplot_pm3d, true],
24063                          [grid, 150, 150])$
24064
24065     See also 'julia_parameter'.
24066
24067
24068File: maxima.info,  Node: Definitions for Koch snowflakes,  Next: Definitions for Peano maps,  Prev: Definitions for complex fractals,  Up: Top
24069
2407060.4 Definitions for Koch snowflakes
24071====================================
24072
24073 -- Function: snowmap (<ent>, <nn>)
24074
24075     Koch snowflake sets.  Function 'snowmap' plots the snow Koch map
24076     over the vertex of an initial closed polygonal, in the complex
24077     plane.  Here the orientation of the polygon is important.  Argument
24078     <nn> is the number of recursive applications of Koch
24079     transformation; <nn> must be small (5 or 6).
24080
24081     Examples:
24082
24083          (%i1) load("fractals")$
24084          (%i2) plot2d([discrete,
24085                        snowmap([1,exp(%i*%pi*2/3),exp(-%i*%pi*2/3),1],4)])$
24086          (%i3) plot2d([discrete,
24087                        snowmap([1,exp(-%i*%pi*2/3),exp(%i*%pi*2/3),1],4)])$
24088          (%i4) plot2d([discrete, snowmap([0,1,1+%i,%i,0],4)])$
24089          (%i5) plot2d([discrete, snowmap([0,%i,1+%i,1,0],4)])$
24090
24091
24092File: maxima.info,  Node: Definitions for Peano maps,  Prev: Definitions for Koch snowflakes,  Up: fractals-pkg
24093
2409460.5 Definitions for Peano maps
24095===============================
24096
24097Continuous curves that cover an area.  Warning: the number of points
24098exponentially grows with <n>.
24099
24100 -- Function: hilbertmap (<nn>)
24101
24102     Hilbert map.  Argument <nn> must be small (5, for example).  Maxima
24103     can crash if <nn> is 7 or greater.
24104
24105     Example:
24106
24107          (%i1) load("fractals")$
24108          (%i2) plot2d([discrete,hilbertmap(6)])$
24109
24110 -- Function: sierpinskimap (<nn>)
24111
24112     Sierpinski map.  Argument <nn> must be small (5, for example).
24113     Maxima can crash if <nn> is 7 or greater.
24114
24115     Example:
24116
24117          (%i1) load("fractals")$
24118          (%i2) plot2d([discrete,sierpinskimap(6)])$
24119
24120
24121File: maxima.info,  Node: ggf-pkg,  Next: graphs-pkg,  Prev: fractals-pkg,  Up: Top
24122
2412361 ggf
24124******
24125
24126* Menu:
24127
24128* Functions and Variables for ggf::
24129
24130
24131File: maxima.info,  Node: Functions and Variables for ggf,  Prev: ggf-pkg,  Up: ggf-pkg
24132
2413361.1 Functions and Variables for ggf
24134====================================
24135
24136 -- Option variable: GGFINFINITY
24137     Default value: 3
24138
24139     This is an option variable for function 'ggf'.
24140
24141     When computing the continued fraction of the generating function, a
24142     partial quotient having a degree (strictly) greater than
24143     <GGFINFINITY> will be discarded and the current convergent will be
24144     considered as the exact value of the generating function; most
24145     often the degree of all partial quotients will be 0 or 1; if you
24146     use a greater value, then you should give enough terms in order to
24147     make the computation accurate enough.
24148
24149     See also 'ggf'.
24150
24151 -- Option variable: GGFCFMAX
24152     Default value: 3
24153
24154     This is an option variable for function 'ggf'.
24155
24156     When computing the continued fraction of the generating function,
24157     if no good result has been found (see the <GGFINFINITY> flag) after
24158     having computed <GGFCFMAX> partial quotients, the generating
24159     function will be considered as not being a fraction of two
24160     polynomials and the function will exit.  Put freely a greater value
24161     for more complicated generating functions.
24162
24163     See also 'ggf'.
24164
24165 -- Function: ggf (<l>)
24166     Compute the generating function (if it is a fraction of two
24167     polynomials) of a sequence, its first terms being given.  <l> is a
24168     list of numbers.
24169
24170     The solution is returned as a fraction of two polynomials.  If no
24171     solution has been found, it returns with 'done'.
24172
24173     This function is controlled by global variables <GGFINFINITY> and
24174     <GGFCFMAX>.  See also <GGFINFINITY> and <GGFCFMAX>.
24175
24176     To use this function write first 'load("ggf")'.
24177
24178
24179File: maxima.info,  Node: graphs-pkg,  Next: grobner-pkg,  Prev: ggf-pkg,  Up: Top
24180
2418162 graphs
24182*********
24183
24184* Menu:
24185
24186* Introduction to graphs::
24187* Functions and Variables for graphs::
24188
24189
24190File: maxima.info,  Node: Introduction to graphs,  Next: Functions and Variables for graphs,  Prev: graphs-pkg,  Up: graphs-pkg
24191
2419262.1 Introduction to graphs
24193===========================
24194
24195The 'graphs' package provides graph and digraph data structure for
24196Maxima.  Graphs and digraphs are simple (have no multiple edges nor
24197loops), although digraphs can have a directed edge from <u> to <v> and a
24198directed edge from <v> to <u>.
24199
24200   Internally graphs are represented by adjacency lists and implemented
24201as a lisp structures.  Vertices are identified by their ids (an id is an
24202integer).  Edges/arcs are represented by lists of length 2.  Labels can
24203be assigned to vertices of graphs/digraphs and weights can be assigned
24204to edges/arcs of graphs/digraphs.
24205
24206   There is a 'draw_graph' function for drawing graphs.  Graphs are
24207drawn using a force based vertex positioning algorithm.  'draw_graph'
24208can also use graphviz programs available from <http://www.graphviz.org>.
24209'draw_graph' is based on the maxima 'draw' package.
24210
24211   To use the 'graphs' package, first load it with 'load("graphs")'.
24212
24213
24214File: maxima.info,  Node: Functions and Variables for graphs,  Prev: Introduction to graphs,  Up: graphs-pkg
24215
2421662.2 Functions and Variables for graphs
24217=======================================
24218
2421962.2.1 Building graphs
24220----------------------
24221
24222 -- Function: create_graph
24223          create_graph (<v_list>, <e_list>)
24224          create_graph (<n>, <e_list>)
24225          create_graph (<v_list>, <e_list>, <directed>)
24226
24227     Creates a new graph on the set of vertices <v_list> and with edges
24228     <e_list>.
24229
24230     <v_list> is a list of vertices ('[v1, v2,..., vn]') or a list of
24231     vertices together with vertex labels ('[[v1,l1], [v2,l2],...,
24232     [vn,ln]]').
24233
24234     <n> is the number of vertices.  Vertices will be identified by
24235     integers from 0 to n-1.
24236
24237     <e_list> is a list of edges ('[e1, e2,..., em]') or a list of edges
24238     together with edge-weights ('[[e1, w1], ..., [em, wm]]').
24239
24240     If <directed> is not 'false', a directed graph will be returned.
24241
24242     Example 1: create a cycle on 3 vertices:
24243          (%i1) load ("graphs")$
24244          (%i2) g : create_graph([1,2,3], [[1,2], [2,3], [1,3]])$
24245          (%i3) print_graph(g)$
24246          Graph on 3 vertices with 3 edges.
24247          Adjacencies:
24248            3 :  1  2
24249            2 :  3  1
24250            1 :  3  2
24251
24252     Example 2: create a cycle on 3 vertices with edge weights:
24253          (%i1) load ("graphs")$
24254          (%i2) g : create_graph([1,2,3], [[[1,2], 1.0], [[2,3], 2.0],
24255                                    [[1,3], 3.0]])$
24256          (%i3) print_graph(g)$
24257          Graph on 3 vertices with 3 edges.
24258          Adjacencies:
24259            3 :  1  2
24260            2 :  3  1
24261            1 :  3  2
24262
24263     Example 3: create a directed graph:
24264          (%i1) load ("graphs")$
24265          (%i2) d : create_graph(
24266                  [1,2,3,4],
24267                  [
24268                   [1,3], [1,4],
24269                   [2,3], [2,4]
24270                  ],
24271                  'directed = true)$
24272          (%i3) print_graph(d)$
24273          Digraph on 4 vertices with 4 arcs.
24274          Adjacencies:
24275            4 :
24276            3 :
24277            2 :  4  3
24278            1 :  4  3
24279
24280 -- Function: copy_graph (<g>)
24281     Returns a copy of the graph <g>.
24282
24283 -- Function: circulant_graph (<n>, <d>)
24284     Returns the circulant graph with parameters <n> and <d>.
24285
24286     Example:
24287          (%i1) load ("graphs")$
24288          (%i2) g : circulant_graph(10, [1,3])$
24289          (%i3) print_graph(g)$
24290          Graph on 10 vertices with 20 edges.
24291          Adjacencies:
24292            9 :  2  6  0  8
24293            8 :  1  5  9  7
24294            7 :  0  4  8  6
24295            6 :  9  3  7  5
24296            5 :  8  2  6  4
24297            4 :  7  1  5  3
24298            3 :  6  0  4  2
24299            2 :  9  5  3  1
24300            1 :  8  4  2  0
24301            0 :  7  3  9  1
24302
24303 -- Function: clebsch_graph ()
24304     Returns the Clebsch graph.
24305
24306 -- Function: complement_graph (<g>)
24307     Returns the complement of the graph <g>.
24308
24309 -- Function: complete_bipartite_graph (<n>, <m>)
24310     Returns the complete bipartite graph on <n+m> vertices.
24311
24312 -- Function: complete_graph (<n>)
24313     Returns the complete graph on <n> vertices.
24314
24315 -- Function: cycle_digraph (<n>)
24316     Returns the directed cycle on <n> vertices.
24317
24318 -- Function: cycle_graph (<n>)
24319     Returns the cycle on <n> vertices.
24320
24321 -- Function: cuboctahedron_graph (<n>)
24322     Returns the cuboctahedron graph.
24323
24324 -- Function: cube_graph (<n>)
24325     Returns the <n>-dimensional cube.
24326
24327 -- Function: dodecahedron_graph ()
24328     Returns the dodecahedron graph.
24329
24330 -- Function: empty_graph (<n>)
24331     Returns the empty graph on <n> vertices.
24332
24333 -- Function: flower_snark (<n>)
24334     Returns the flower graph on <4n> vertices.
24335
24336     Example:
24337          (%i1) load ("graphs")$
24338          (%i2) f5 : flower_snark(5)$
24339          (%i3) chromatic_index(f5);
24340          (%o3)                           4
24341
24342 -- Function: from_adjacency_matrix (<A>)
24343     Returns the graph represented by its adjacency matrix <A>.
24344
24345 -- Function: frucht_graph ()
24346     Returns the Frucht graph.
24347
24348 -- Function: graph_product (<g1>, <g1>)
24349     Returns the direct product of graphs <g1> and <g2>.
24350
24351     Example:
24352          (%i1) load ("graphs")$
24353          (%i2) grid : graph_product(path_graph(3), path_graph(4))$
24354          (%i3) draw_graph(grid)$
24355
24356 -- Function: graph_union (<g1>, <g1>)
24357     Returns the union (sum) of graphs <g1> and <g2>.
24358
24359 -- Function: grid_graph (<n>, <m>)
24360     Returns the <n x m> grid.
24361
24362 -- Function: great_rhombicosidodecahedron_graph ()
24363     Returns the great rhombicosidodecahedron graph.
24364
24365 -- Function: great_rhombicuboctahedron_graph ()
24366     Returns the great rhombicuboctahedron graph.
24367
24368 -- Function: grotzch_graph ()
24369     Returns the Grotzch graph.
24370
24371 -- Function: heawood_graph ()
24372     Returns the Heawood graph.
24373
24374 -- Function: icosahedron_graph ()
24375     Returns the icosahedron graph.
24376
24377 -- Function: icosidodecahedron_graph ()
24378     Returns the icosidodecahedron graph.
24379
24380 -- Function: induced_subgraph (<V>, <g>)
24381     Returns the graph induced on the subset <V> of vertices of the
24382     graph <g>.
24383
24384     Example:
24385          (%i1) load ("graphs")$
24386          (%i2) p : petersen_graph()$
24387          (%i3) V : [0,1,2,3,4]$
24388          (%i4) g : induced_subgraph(V, p)$
24389          (%i5) print_graph(g)$
24390          Graph on 5 vertices with 5 edges.
24391          Adjacencies:
24392            4 :  3  0
24393            3 :  2  4
24394            2 :  1  3
24395            1 :  0  2
24396            0 :  1  4
24397
24398 -- Function: line_graph (<g>)
24399     Returns the line graph of the graph <g>.
24400
24401 -- Function: make_graph
24402          make_graph (<vrt>, <f>)
24403          make_graph (<vrt>, <f>, <oriented>)
24404
24405     Creates a graph using a predicate function <f>.
24406
24407     <vrt> is a list/set of vertices or an integer.  If <vrt> is an
24408     integer, then vertices of the graph will be integers from 1 to
24409     <vrt>.
24410
24411     <f> is a predicate function.  Two vertices <a> and <b> will be
24412     connected if 'f(a,b)=true'.
24413
24414     If <directed> is not <false>, then the graph will be directed.
24415
24416     Example 1:
24417          (%i1) load("graphs")$
24418          (%i2) g : make_graph(powerset({1,2,3,4,5}, 2), disjointp)$
24419          (%i3) is_isomorphic(g, petersen_graph());
24420          (%o3)                         true
24421          (%i4) get_vertex_label(1, g);
24422          (%o4)                        {1, 2}
24423
24424     Example 2:
24425          (%i1) load("graphs")$
24426          (%i2) f(i, j) := is (mod(j, i)=0)$
24427          (%i3) g : make_graph(20, f, directed=true)$
24428          (%i4) out_neighbors(4, g);
24429          (%o4)                    [8, 12, 16, 20]
24430          (%i5) in_neighbors(18, g);
24431          (%o5)                    [1, 2, 3, 6, 9]
24432
24433 -- Function: mycielski_graph (<g>)
24434     Returns the mycielskian graph of the graph <g>.
24435
24436 -- Function: new_graph ()
24437     Returns the graph with no vertices and no edges.
24438
24439 -- Function: path_digraph (<n>)
24440     Returns the directed path on <n> vertices.
24441
24442 -- Function: path_graph (<n>)
24443     Returns the path on <n> vertices.
24444
24445 -- Function: petersen_graph
24446          petersen_graph ()
24447          petersen_graph (<n>, <d>)
24448
24449     Returns the petersen graph <P_{n,d}>.  The default values for <n>
24450     and <d> are 'n=5' and 'd=2'.
24451
24452 -- Function: random_bipartite_graph (<a>, <b>, <p>)
24453     Returns a random bipartite graph on 'a+b' vertices.  Each edge is
24454     present with probability <p>.
24455
24456 -- Function: random_digraph (<n>, <p>)
24457     Returns a random directed graph on <n> vertices.  Each arc is
24458     present with probability <p>.
24459
24460 -- Function: random_regular_graph
24461          random_regular_graph (<n>)
24462          random_regular_graph (<n>, <d>)
24463
24464     Returns a random <d>-regular graph on <n> vertices.  The default
24465     value for <d> is 'd=3'.
24466
24467 -- Function: random_graph (<n>, <p>)
24468     Returns a random graph on <n> vertices.  Each edge is present with
24469     probability <p>.
24470
24471 -- Function: random_graph1 (<n>, <m>)
24472     Returns a random graph on <n> vertices and random <m> edges.
24473
24474 -- Function: random_network (<n>, <p>, <w>)
24475     Returns a random network on <n> vertices.  Each arc is present with
24476     probability <p> and has a weight in the range '[0,w]'.  The
24477     function returns a list '[network, source, sink]'.
24478
24479     Example:
24480          (%i1) load ("graphs")$
24481          (%i2) [net, s, t] : random_network(50, 0.2, 10.0);
24482          (%o2)                   [DIGRAPH, 50, 51]
24483          (%i3) max_flow(net, s, t)$
24484          (%i4) first(%);
24485          (%o4)                   27.65981397932507
24486
24487 -- Function: random_tournament (<n>)
24488     Returns a random tournament on <n> vertices.
24489
24490 -- Function: random_tree (<n>)
24491     Returns a random tree on <n> vertices.
24492
24493 -- Function: small_rhombicosidodecahedron_graph ()
24494     Returns the small rhombicosidodecahedron graph.
24495
24496 -- Function: small_rhombicuboctahedron_graph ()
24497     Returns the small rhombicuboctahedron graph.
24498
24499 -- Function: snub_cube_graph ()
24500     Returns the snub cube graph.
24501
24502 -- Function: snub_dodecahedron_graph ()
24503     Returns the snub dodecahedron graph.
24504
24505 -- Function: truncated_cube_graph ()
24506     Returns the truncated cube graph.
24507
24508 -- Function: truncated_dodecahedron_graph ()
24509     Returns the truncated dodecahedron graph.
24510
24511 -- Function: truncated_icosahedron_graph ()
24512     Returns the truncated icosahedron graph.
24513
24514 -- Function: truncated_tetrahedron_graph ()
24515     Returns the truncated tetrahedron graph.
24516
24517 -- Function: tutte_graph ()
24518     Returns the Tutte graph.
24519
24520 -- Function: underlying_graph (<g>)
24521     Returns the underlying graph of the directed graph <g>.
24522
24523 -- Function: wheel_graph (<n>)
24524     Returns the wheel graph on <n+1> vertices.
24525
2452662.2.2 Graph properties
24527-----------------------
24528
24529 -- Function: adjacency_matrix (<gr>)
24530     Returns the adjacency matrix of the graph <gr>.
24531
24532     Example:
24533          (%i1) load ("graphs")$
24534          (%i2) c5 : cycle_graph(4)$
24535          (%i3) adjacency_matrix(c5);
24536                                   [ 0  1  0  1 ]
24537                                   [            ]
24538                                   [ 1  0  1  0 ]
24539          (%o3)                    [            ]
24540                                   [ 0  1  0  1 ]
24541                                   [            ]
24542                                   [ 1  0  1  0 ]
24543
24544 -- Function: average_degree (<gr>)
24545     Returns the average degree of vertices in the graph <gr>.
24546
24547     Example:
24548          (%i1) load ("graphs")$
24549          (%i2) average_degree(grotzch_graph());
24550                                         40
24551          (%o2)                          --
24552                                         11
24553
24554 -- Function: biconnected_components (<gr>)
24555     Returns the (vertex sets of) 2-connected components of the graph
24556     <gr>.
24557
24558     Example:
24559          (%i1) load ("graphs")$
24560          (%i2) g : create_graph(
24561                      [1,2,3,4,5,6,7],
24562                      [
24563                       [1,2],[2,3],[2,4],[3,4],
24564                       [4,5],[5,6],[4,6],[6,7]
24565                      ])$
24566          (%i3) biconnected_components(g);
24567          (%o3)        [[6, 7], [4, 5, 6], [1, 2], [2, 3, 4]]
24568
24569 -- Function: bipartition (<gr>)
24570     Returns a bipartition of the vertices of the graph <gr> or an empty
24571     list if <gr> is not bipartite.
24572
24573     Example:
24574
24575          (%i1) load ("graphs")$
24576          (%i2) h : heawood_graph()$
24577          (%i3) [A,B]:bipartition(h);
24578          (%o3)  [[8, 12, 6, 10, 0, 2, 4], [13, 5, 11, 7, 9, 1, 3]]
24579          (%i4) draw_graph(h, show_vertices=A, program=circular)$
24580
24581 -- Function: chromatic_index (<gr>)
24582     Returns the chromatic index of the graph <gr>.
24583
24584     Example:
24585          (%i1) load ("graphs")$
24586          (%i2) p : petersen_graph()$
24587          (%i3) chromatic_index(p);
24588          (%o3)                           4
24589
24590 -- Function: chromatic_number (<gr>)
24591     Returns the chromatic number of the graph <gr>.
24592
24593     Example:
24594          (%i1) load ("graphs")$
24595          (%i2) chromatic_number(cycle_graph(5));
24596          (%o2)                           3
24597          (%i3) chromatic_number(cycle_graph(6));
24598          (%o3)                           2
24599
24600 -- Function: clear_edge_weight (<e>, <gr>)
24601     Removes the weight of the edge <e> in the graph <gr>.
24602
24603     Example:
24604
24605          (%i1) load ("graphs")$
24606          (%i2) g : create_graph(3, [[[0,1], 1.5], [[1,2], 1.3]])$
24607          (%i3) get_edge_weight([0,1], g);
24608          (%o3)                          1.5
24609          (%i4) clear_edge_weight([0,1], g)$
24610          (%i5) get_edge_weight([0,1], g);
24611          (%o5)                           1
24612
24613 -- Function: clear_vertex_label (<v>, <gr>)
24614     Removes the label of the vertex <v> in the graph <gr>.
24615
24616     Example:
24617          (%i1) load ("graphs")$
24618          (%i2) g : create_graph([[0,"Zero"], [1, "One"]], [[0,1]])$
24619          (%i3) get_vertex_label(0, g);
24620          (%o3)                         Zero
24621          (%i4) clear_vertex_label(0, g);
24622          (%o4)                         done
24623          (%i5) get_vertex_label(0, g);
24624          (%o5)                         false
24625
24626 -- Function: connected_components (<gr>)
24627     Returns the (vertex sets of) connected components of the graph
24628     <gr>.
24629
24630     Example:
24631          (%i1) load ("graphs")$
24632          (%i2) g: graph_union(cycle_graph(5), path_graph(4))$
24633          (%i3) connected_components(g);
24634          (%o3)            [[1, 2, 3, 4, 0], [8, 7, 6, 5]]
24635
24636 -- Function: diameter (<gr>)
24637     Returns the diameter of the graph <gr>.
24638
24639     Example:
24640          (%i1) load ("graphs")$
24641          (%i2) diameter(dodecahedron_graph());
24642          (%o2)                           5
24643
24644 -- Function: edge_coloring (<gr>)
24645     Returns an optimal coloring of the edges of the graph <gr>.
24646
24647     The function returns the chromatic index and a list representing
24648     the coloring of the edges of <gr>.
24649
24650     Example:
24651          (%i1) load ("graphs")$
24652          (%i2) p : petersen_graph()$
24653          (%i3) [ch_index, col] : edge_coloring(p);
24654          (%o3) [4, [[[0, 5], 3], [[5, 7], 1], [[0, 1], 1], [[1, 6], 2],
24655          [[6, 8], 1], [[1, 2], 3], [[2, 7], 4], [[7, 9], 2], [[2, 3], 2],
24656          [[3, 8], 3], [[5, 8], 2], [[3, 4], 1], [[4, 9], 4], [[6, 9], 3],
24657          [[0, 4], 2]]]
24658          (%i4) assoc([0,1], col);
24659          (%o4)                           1
24660          (%i5) assoc([0,5], col);
24661          (%o5)                           3
24662
24663 -- Function: degree_sequence (<gr>)
24664     Returns the list of vertex degrees of the graph <gr>.
24665
24666     Example:
24667          (%i1) load ("graphs")$
24668          (%i2) degree_sequence(random_graph(10, 0.4));
24669          (%o2)            [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]
24670
24671 -- Function: edge_connectivity (<gr>)
24672     Returns the edge-connectivity of the graph <gr>.
24673
24674     See also 'min_edge_cut'.
24675
24676 -- Function: edges (<gr>)
24677     Returns the list of edges (arcs) in a (directed) graph <gr>.
24678
24679     Example:
24680          (%i1) load ("graphs")$
24681          (%i2) edges(complete_graph(4));
24682          (%o2)   [[2, 3], [1, 3], [1, 2], [0, 3], [0, 2], [0, 1]]
24683
24684 -- Function: get_edge_weight
24685          get_edge_weight (<e>, <gr>)
24686          get_edge_weight (<e>, <gr>, <ifnot>)
24687
24688     Returns the weight of the edge <e> in the graph <gr>.
24689
24690     If there is no weight assigned to the edge, the function returns 1.
24691     If the edge is not present in the graph, the function signals an
24692     error or returns the optional argument <ifnot>.
24693
24694     Example:
24695          (%i1) load ("graphs")$
24696          (%i2) c5 : cycle_graph(5)$
24697          (%i3) get_edge_weight([1,2], c5);
24698          (%o3)                           1
24699          (%i4) set_edge_weight([1,2], 2.0, c5);
24700          (%o4)                         done
24701          (%i5) get_edge_weight([1,2], c5);
24702          (%o5)                          2.0
24703
24704 -- Function: get_vertex_label (<v>, <gr>)
24705     Returns the label of the vertex <v> in the graph <gr>.
24706
24707     Example:
24708          (%i1) load ("graphs")$
24709          (%i2) g : create_graph([[0,"Zero"], [1, "One"]], [[0,1]])$
24710          (%i3) get_vertex_label(0, g);
24711          (%o3)                         Zero
24712
24713 -- Function: graph_charpoly (<gr>, <x>)
24714     Returns the characteristic polynomial (in variable <x>) of the
24715     graph <gr>.
24716
24717     Example:
24718          (%i1) load ("graphs")$
24719          (%i2) p : petersen_graph()$
24720          (%i3) graph_charpoly(p, x), factor;
24721                                             5        4
24722          (%o3)               (x - 3) (x - 1)  (x + 2)
24723
24724 -- Function: graph_center (<gr>)
24725     Returns the center of the graph <gr>.
24726
24727     Example:
24728          (%i1) load ("graphs")$
24729          (%i2) g : grid_graph(5,5)$
24730          (%i3) graph_center(g);
24731          (%o3)                         [12]
24732
24733 -- Function: graph_eigenvalues (<gr>)
24734     Returns the eigenvalues of the graph <gr>.  The function returns
24735     eigenvalues in the same format as maxima 'eigenvalues' function.
24736
24737     Example:
24738          (%i1) load ("graphs")$
24739          (%i2) p : petersen_graph()$
24740          (%i3) graph_eigenvalues(p);
24741          (%o3)               [[3, - 2, 1], [1, 4, 5]]
24742
24743 -- Function: graph_periphery (<gr>)
24744     Returns the periphery of the graph <gr>.
24745
24746     Example:
24747          (%i1) load ("graphs")$
24748          (%i2) g : grid_graph(5,5)$
24749          (%i3) graph_periphery(g);
24750          (%o3)                    [24, 20, 4, 0]
24751
24752 -- Function: graph_size (<gr>)
24753     Returns the number of edges in the graph <gr>.
24754
24755     Example:
24756          (%i1) load ("graphs")$
24757          (%i2) p : petersen_graph()$
24758          (%i3) graph_size(p);
24759          (%o3)                          15
24760
24761 -- Function: graph_order (<gr>)
24762     Returns the number of vertices in the graph <gr>.
24763
24764     Example:
24765          (%i1) load ("graphs")$
24766          (%i2) p : petersen_graph()$
24767          (%i3) graph_order(p);
24768          (%o3)                          10
24769
24770 -- Function: girth (<gr>)
24771     Returns the length of the shortest cycle in <gr>.
24772
24773     Example:
24774          (%i1) load ("graphs")$
24775          (%i2) g : heawood_graph()$
24776          (%i3) girth(g);
24777          (%o3)                           6
24778
24779 -- Function: hamilton_cycle (<gr>)
24780     Returns the Hamilton cycle of the graph <gr> or an empty list if
24781     <gr> is not hamiltonian.
24782
24783     Example:
24784          (%i1) load ("graphs")$
24785          (%i2) c : cube_graph(3)$
24786          (%i3) hc : hamilton_cycle(c);
24787          (%o3)              [7, 3, 2, 6, 4, 0, 1, 5, 7]
24788          (%i4) draw_graph(c, show_edges=vertices_to_cycle(hc))$
24789
24790 -- Function: hamilton_path (<gr>)
24791     Returns the Hamilton path of the graph <gr> or an empty list if
24792     <gr> does not have a Hamilton path.
24793
24794     Example:
24795          (%i1) load ("graphs")$
24796          (%i2) p : petersen_graph()$
24797          (%i3) hp : hamilton_path(p);
24798          (%o3)            [0, 5, 7, 2, 1, 6, 8, 3, 4, 9]
24799          (%i4) draw_graph(p, show_edges=vertices_to_path(hp))$
24800
24801 -- Function: isomorphism (<gr1>, <gr2>)
24802
24803     Returns a an isomorphism between graphs/digraphs <gr1> and <gr2>.
24804     If <gr1> and <gr2> are not isomorphic, it returns an empty list.
24805
24806     Example:
24807          (%i1) load ("graphs")$
24808          (%i2) clk5:complement_graph(line_graph(complete_graph(5)))$
24809          (%i3) isomorphism(clk5, petersen_graph());
24810          (%o3) [9 -> 0, 2 -> 1, 6 -> 2, 5 -> 3, 0 -> 4, 1 -> 5, 3 -> 6,
24811                                                    4 -> 7, 7 -> 8, 8 -> 9]
24812
24813 -- Function: in_neighbors (<v>, <gr>)
24814     Returns the list of in-neighbors of the vertex <v> in the directed
24815     graph <gr>.
24816
24817     Example:
24818          (%i1) load ("graphs")$
24819          (%i2) p : path_digraph(3)$
24820          (%i3) in_neighbors(2, p);
24821          (%o3)                          [1]
24822          (%i4) out_neighbors(2, p);
24823          (%o4)                          []
24824
24825 -- Function: is_biconnected (<gr>)
24826     Returns 'true' if <gr> is 2-connected and 'false' otherwise.
24827
24828     Example:
24829          (%i1) load ("graphs")$
24830          (%i2) is_biconnected(cycle_graph(5));
24831          (%o2)                         true
24832          (%i3) is_biconnected(path_graph(5));
24833          (%o3)                         false
24834
24835 -- Function: is_bipartite (<gr>)
24836     Returns 'true' if <gr> is bipartite (2-colorable) and 'false'
24837     otherwise.
24838
24839     Example:
24840          (%i1) load ("graphs")$
24841          (%i2) is_bipartite(petersen_graph());
24842          (%o2)                         false
24843          (%i3) is_bipartite(heawood_graph());
24844          (%o3)                         true
24845
24846 -- Function: is_connected (<gr>)
24847     Returns 'true' if the graph <gr> is connected and 'false'
24848     otherwise.
24849
24850     Example:
24851          (%i1) load ("graphs")$
24852          (%i2) is_connected(graph_union(cycle_graph(4), path_graph(3)));
24853          (%o2)                         false
24854
24855 -- Function: is_digraph (<gr>)
24856     Returns 'true' if <gr> is a directed graph and 'false' otherwise.
24857
24858     Example:
24859          (%i1) load ("graphs")$
24860          (%i2) is_digraph(path_graph(5));
24861          (%o2)                         false
24862          (%i3) is_digraph(path_digraph(5));
24863          (%o3)                         true
24864
24865 -- Function: is_edge_in_graph (<e>, <gr>)
24866     Returns 'true' if <e> is an edge (arc) in the (directed) graph <g>
24867     and 'false' otherwise.
24868
24869     Example:
24870          (%i1) load ("graphs")$
24871          (%i2) c4 : cycle_graph(4)$
24872          (%i3) is_edge_in_graph([2,3], c4);
24873          (%o3)                         true
24874          (%i4) is_edge_in_graph([3,2], c4);
24875          (%o4)                         true
24876          (%i5) is_edge_in_graph([2,4], c4);
24877          (%o5)                         false
24878          (%i6) is_edge_in_graph([3,2], cycle_digraph(4));
24879          (%o6)                         false
24880
24881 -- Function: is_graph (<gr>)
24882     Returns 'true' if <gr> is a graph and 'false' otherwise.
24883
24884     Example:
24885          (%i1) load ("graphs")$
24886          (%i2) is_graph(path_graph(5));
24887          (%o2)                         true
24888          (%i3) is_graph(path_digraph(5));
24889          (%o3)                         false
24890
24891 -- Function: is_graph_or_digraph (<gr>)
24892     Returns 'true' if <gr> is a graph or a directed graph and 'false'
24893     otherwise.
24894
24895     Example:
24896          (%i1) load ("graphs")$
24897          (%i2) is_graph_or_digraph(path_graph(5));
24898          (%o2)                         true
24899          (%i3) is_graph_or_digraph(path_digraph(5));
24900          (%o3)                         true
24901
24902 -- Function: is_isomorphic (<gr1>, <gr2>)
24903
24904     Returns 'true' if graphs/digraphs <gr1> and <gr2> are isomorphic
24905     and 'false' otherwise.
24906
24907     See also 'isomorphism'.
24908
24909     Example:
24910          (%i1) load ("graphs")$
24911          (%i2) clk5:complement_graph(line_graph(complete_graph(5)))$
24912          (%i3) is_isomorphic(clk5, petersen_graph());
24913          (%o3)                         true
24914
24915 -- Function: is_planar (<gr>)
24916
24917     Returns 'true' if <gr> is a planar graph and 'false' otherwise.
24918
24919     The algorithm used is the Demoucron's algorithm, which is a
24920     quadratic time algorithm.
24921
24922     Example:
24923          (%i1) load ("graphs")$
24924          (%i2) is_planar(dodecahedron_graph());
24925          (%o2)                         true
24926          (%i3) is_planar(petersen_graph());
24927          (%o3)                         false
24928          (%i4) is_planar(petersen_graph(10,2));
24929          (%o4)                         true
24930
24931 -- Function: is_sconnected (<gr>)
24932     Returns 'true' if the directed graph <gr> is strongly connected and
24933     'false' otherwise.
24934
24935     Example:
24936          (%i1) load ("graphs")$
24937          (%i2) is_sconnected(cycle_digraph(5));
24938          (%o2)                         true
24939          (%i3) is_sconnected(path_digraph(5));
24940          (%o3)                         false
24941
24942 -- Function: is_vertex_in_graph (<v>, <gr>)
24943     Returns 'true' if <v> is a vertex in the graph <g> and 'false'
24944     otherwise.
24945
24946     Example:
24947          (%i1) load ("graphs")$
24948          (%i2) c4 : cycle_graph(4)$
24949          (%i3) is_vertex_in_graph(0, c4);
24950          (%o3)                         true
24951          (%i4) is_vertex_in_graph(6, c4);
24952          (%o4)                         false
24953
24954 -- Function: is_tree (<gr>)
24955     Returns 'true' if <gr> is a tree and 'false' otherwise.
24956
24957     Example:
24958          (%i1) load ("graphs")$
24959          (%i2) is_tree(random_tree(4));
24960          (%o2)                         true
24961          (%i3) is_tree(graph_union(random_tree(4), random_tree(5)));
24962          (%o3)                         false
24963
24964 -- Function: laplacian_matrix (<gr>)
24965     Returns the laplacian matrix of the graph <gr>.
24966
24967     Example:
24968          (%i1) load ("graphs")$
24969          (%i2) laplacian_matrix(cycle_graph(5));
24970                             [  2   - 1   0    0   - 1 ]
24971                             [                         ]
24972                             [ - 1   2   - 1   0    0  ]
24973                             [                         ]
24974          (%o2)              [  0   - 1   2   - 1   0  ]
24975                             [                         ]
24976                             [  0    0   - 1   2   - 1 ]
24977                             [                         ]
24978                             [ - 1   0    0   - 1   2  ]
24979
24980 -- Function: max_clique (<gr>)
24981     Returns a maximum clique of the graph <gr>.
24982
24983     Example:
24984          (%i1) load ("graphs")$
24985          (%i2) g : random_graph(100, 0.5)$
24986          (%i3) max_clique(g);
24987          (%o3)          [6, 12, 31, 36, 52, 59, 62, 63, 80]
24988
24989 -- Function: max_degree (<gr>)
24990     Returns the maximal degree of vertices of the graph <gr> and a
24991     vertex of maximal degree.
24992
24993     Example:
24994          (%i1) load ("graphs")$
24995          (%i2) g : random_graph(100, 0.02)$
24996          (%i3) max_degree(g);
24997          (%o3)                        [6, 79]
24998          (%i4) vertex_degree(95, g);
24999          (%o4)                           2
25000
25001 -- Function: max_flow (<net>, <s>, <t>)
25002     Returns a maximum flow through the network <net> with the source
25003     <s> and the sink <t>.
25004
25005     The function returns the value of the maximal flow and a list
25006     representing the weights of the arcs in the optimal flow.
25007
25008     Example:
25009          (%i1) load ("graphs")$
25010          (%i2) net : create_graph(
25011            [1,2,3,4,5,6],
25012            [[[1,2], 1.0],
25013             [[1,3], 0.3],
25014             [[2,4], 0.2],
25015             [[2,5], 0.3],
25016             [[3,4], 0.1],
25017             [[3,5], 0.1],
25018             [[4,6], 1.0],
25019             [[5,6], 1.0]],
25020            directed=true)$
25021          (%i3) [flow_value, flow] : max_flow(net, 1, 6);
25022          (%o3) [0.7, [[[1, 2], 0.5], [[1, 3], 0.2], [[2, 4], 0.2],
25023          [[2, 5], 0.3], [[3, 4], 0.1], [[3, 5], 0.1], [[4, 6], 0.3],
25024          [[5, 6], 0.4]]]
25025          (%i4) fl : 0$
25026          (%i5) for u in out_neighbors(1, net)
25027               do fl : fl + assoc([1, u], flow)$
25028          (%i6) fl;
25029          (%o6)                          0.7
25030
25031 -- Function: max_independent_set (<gr>)
25032     Returns a maximum independent set of the graph <gr>.
25033
25034     Example:
25035          (%i1) load ("graphs")$
25036          (%i2) d : dodecahedron_graph()$
25037          (%i3) mi : max_independent_set(d);
25038          (%o3)             [0, 3, 5, 9, 10, 11, 18, 19]
25039          (%i4) draw_graph(d, show_vertices=mi)$
25040
25041 -- Function: max_matching (<gr>)
25042     Returns a maximum matching of the graph <gr>.
25043
25044     Example:
25045          (%i1) load ("graphs")$
25046          (%i2) d : dodecahedron_graph()$
25047          (%i3) m : max_matching(d);
25048          (%o3) [[5, 7], [8, 9], [6, 10], [14, 19], [13, 18], [12, 17],
25049                                         [11, 16], [0, 15], [3, 4], [1, 2]]
25050          (%i4) draw_graph(d, show_edges=m)$
25051
25052 -- Function: min_degree (<gr>)
25053     Returns the minimum degree of vertices of the graph <gr> and a
25054     vertex of minimum degree.
25055
25056     Example:
25057          (%i1) load ("graphs")$
25058          (%i2) g : random_graph(100, 0.1)$
25059          (%i3) min_degree(g);
25060          (%o3)                        [3, 49]
25061          (%i4) vertex_degree(21, g);
25062          (%o4)                           9
25063
25064 -- Function: min_edge_cut (<gr>)
25065     Returns the minimum edge cut in the graph <gr>.
25066
25067     See also 'edge_connectivity'.
25068
25069 -- Function: min_vertex_cover (<gr>)
25070     Returns the minimum vertex cover of the graph <gr>.
25071
25072 -- Function: min_vertex_cut (<gr>)
25073     Returns the minimum vertex cut in the graph <gr>.
25074
25075     See also 'vertex_connectivity'.
25076
25077 -- Function: minimum_spanning_tree (<gr>)
25078     Returns the minimum spanning tree of the graph <gr>.
25079
25080     Example:
25081          (%i1) load ("graphs")$
25082          (%i2) g : graph_product(path_graph(10), path_graph(10))$
25083          (%i3) t : minimum_spanning_tree(g)$
25084          (%i4) draw_graph(g, show_edges=edges(t))$
25085
25086 -- Function: neighbors (<v>, <gr>)
25087     Returns the list of neighbors of the vertex <v> in the graph <gr>.
25088
25089     Example:
25090          (%i1) load ("graphs")$
25091          (%i2) p : petersen_graph()$
25092          (%i3) neighbors(3, p);
25093          (%o3)                       [4, 8, 2]
25094
25095 -- Function: odd_girth (<gr>)
25096     Returns the length of the shortest odd cycle in the graph <gr>.
25097
25098     Example:
25099          (%i1) load ("graphs")$
25100          (%i2) g : graph_product(cycle_graph(4), cycle_graph(7))$
25101          (%i3) girth(g);
25102          (%o3)                           4
25103          (%i4) odd_girth(g);
25104          (%o4)                           7
25105
25106 -- Function: out_neighbors (<v>, <gr>)
25107     Returns the list of out-neighbors of the vertex <v> in the directed
25108     graph <gr>.
25109
25110     Example:
25111          (%i1) load ("graphs")$
25112          (%i2) p : path_digraph(3)$
25113          (%i3) in_neighbors(2, p);
25114          (%o3)                          [1]
25115          (%i4) out_neighbors(2, p);
25116          (%o4)                          []
25117
25118 -- Function: planar_embedding (<gr>)
25119
25120     Returns the list of facial walks in a planar embedding of <gr> and
25121     'false' if <gr> is not a planar graph.
25122
25123     The graph <gr> must be biconnected.
25124
25125     The algorithm used is the Demoucron's algorithm, which is a
25126     quadratic time algorithm.
25127
25128     Example:
25129          (%i1) load ("graphs")$
25130          (%i2) planar_embedding(grid_graph(3,3));
25131          (%o2) [[3, 6, 7, 8, 5, 2, 1, 0], [4, 3, 0, 1], [3, 4, 7, 6],
25132                                                [8, 7, 4, 5], [1, 2, 5, 4]]
25133
25134 -- Function: print_graph (<gr>)
25135     Prints some information about the graph <gr>.
25136
25137     Example:
25138          (%i1) load ("graphs")$
25139          (%i2) c5 : cycle_graph(5)$
25140          (%i3) print_graph(c5)$
25141          Graph on 5 vertices with 5 edges.
25142          Adjacencies:
25143            4 :  0  3
25144            3 :  4  2
25145            2 :  3  1
25146            1 :  2  0
25147            0 :  4  1
25148          (%i4) dc5 : cycle_digraph(5)$
25149          (%i5) print_graph(dc5)$
25150          Digraph on 5 vertices with 5 arcs.
25151          Adjacencies:
25152            4 :  0
25153            3 :  4
25154            2 :  3
25155            1 :  2
25156            0 :  1
25157          (%i6) out_neighbors(0, dc5);
25158          (%o6)                          [1]
25159
25160 -- Function: radius (<gr>)
25161     Returns the radius of the graph <gr>.
25162
25163     Example:
25164          (%i1) load ("graphs")$
25165          (%i2) radius(dodecahedron_graph());
25166          (%o2)                           5
25167
25168 -- Function: set_edge_weight (<e>, <w>, <gr>)
25169     Assigns the weight <w> to the edge <e> in the graph <gr>.
25170
25171     Example:
25172          (%i1) load ("graphs")$
25173          (%i2) g : create_graph([1, 2], [[[1,2], 1.2]])$
25174          (%i3) get_edge_weight([1,2], g);
25175          (%o3)                          1.2
25176          (%i4) set_edge_weight([1,2], 2.1, g);
25177          (%o4)                         done
25178          (%i5) get_edge_weight([1,2], g);
25179          (%o5)                          2.1
25180
25181 -- Function: set_vertex_label (<v>, <l>, <gr>)
25182     Assigns the label <l> to the vertex <v> in the graph <gr>.
25183
25184     Example:
25185          (%i1) load ("graphs")$
25186          (%i2) g : create_graph([[1, "One"], [2, "Two"]], [[1,2]])$
25187          (%i3) get_vertex_label(1, g);
25188          (%o3)                          One
25189          (%i4) set_vertex_label(1, "oNE", g);
25190          (%o4)                         done
25191          (%i5) get_vertex_label(1, g);
25192          (%o5)                          oNE
25193
25194 -- Function: shortest_path (<u>, <v>, <gr>)
25195     Returns the shortest path from <u> to <v> in the graph <gr>.
25196
25197     Example:
25198          (%i1) load ("graphs")$
25199          (%i2) d : dodecahedron_graph()$
25200          (%i3) path : shortest_path(0, 7, d);
25201          (%o3)                   [0, 1, 19, 13, 7]
25202          (%i4) draw_graph(d, show_edges=vertices_to_path(path))$
25203
25204 -- Function: shortest_weighted_path (<u>, <v>, <gr>)
25205     Returns the length of the shortest weighted path and the shortest
25206     weighted path from <u> to <v> in the graph <gr>.
25207
25208     The length of a weighted path is the sum of edge weights of edges
25209     in the path.  If an edge has no weight, then it has a default
25210     weight 1.
25211
25212     Example:
25213
25214          (%i1) load ("graphs")$
25215          (%i2) g: petersen_graph(20, 2)$
25216          (%i3) for e in edges(g) do set_edge_weight(e, random(1.0), g)$
25217          (%i4) shortest_weighted_path(0, 10, g);
25218          (%o4) [2.575143920268482, [0, 20, 38, 36, 34, 32, 30, 10]]
25219
25220 -- Function: strong_components (<gr>)
25221     Returns the strong components of a directed graph <gr>.
25222
25223     Example:
25224          (%i1) load ("graphs")$
25225          (%i2) t : random_tournament(4)$
25226          (%i3) strong_components(t);
25227          (%o3)                 [[1], [0], [2], [3]]
25228          (%i4) vertex_out_degree(3, t);
25229          (%o4)                           3
25230
25231 -- Function: topological_sort (<dag>)
25232
25233     Returns a topological sorting of the vertices of a directed graph
25234     <dag> or an empty list if <dag> is not a directed acyclic graph.
25235
25236     Example:
25237          (%i1) load ("graphs")$
25238          (%i2) g:create_graph(
25239                   [1,2,3,4,5],
25240                   [
25241                    [1,2], [2,5], [5,3],
25242                    [5,4], [3,4], [1,3]
25243                   ],
25244                   directed=true)$
25245          (%i3) topological_sort(g);
25246          (%o3)                    [1, 2, 5, 3, 4]
25247
25248 -- Function: vertex_connectivity (<g>)
25249     Returns the vertex connectivity of the graph <g>.
25250
25251     See also 'min_vertex_cut'.
25252
25253 -- Function: vertex_degree (<v>, <gr>)
25254     Returns the degree of the vertex <v> in the graph <gr>.
25255
25256 -- Function: vertex_distance (<u>, <v>, <gr>)
25257     Returns the length of the shortest path between <u> and <v> in the
25258     (directed) graph <gr>.
25259
25260     Example:
25261          (%i1) load ("graphs")$
25262          (%i2) d : dodecahedron_graph()$
25263          (%i3) vertex_distance(0, 7, d);
25264          (%o3)                           4
25265          (%i4) shortest_path(0, 7, d);
25266          (%o4)                   [0, 1, 19, 13, 7]
25267
25268 -- Function: vertex_eccentricity (<v>, <gr>)
25269
25270     Returns the eccentricity of the vertex <v> in the graph <gr>.
25271
25272     Example:
25273          (%i1) load ("graphs")$
25274          (%i2) g:cycle_graph(7)$
25275          (%i3) vertex_eccentricity(0, g);
25276          (%o3)                           3
25277
25278 -- Function: vertex_in_degree (<v>, <gr>)
25279     Returns the in-degree of the vertex <v> in the directed graph <gr>.
25280
25281     Example:
25282          (%i1) load ("graphs")$
25283          (%i2) p5 : path_digraph(5)$
25284          (%i3) print_graph(p5)$
25285          Digraph on 5 vertices with 4 arcs.
25286          Adjacencies:
25287            4 :
25288            3 :  4
25289            2 :  3
25290            1 :  2
25291            0 :  1
25292          (%i4) vertex_in_degree(4, p5);
25293          (%o4)                           1
25294          (%i5) in_neighbors(4, p5);
25295          (%o5)                          [3]
25296
25297 -- Function: vertex_out_degree (<v>, <gr>)
25298     Returns the out-degree of the vertex <v> in the directed graph
25299     <gr>.
25300
25301     Example:
25302          (%i1) load ("graphs")$
25303          (%i2) t : random_tournament(10)$
25304          (%i3) vertex_out_degree(0, t);
25305          (%o3)                           2
25306          (%i4) out_neighbors(0, t);
25307          (%o4)                        [7, 1]
25308
25309 -- Function: vertices (<gr>)
25310     Returns the list of vertices in the graph <gr>.
25311
25312     Example:
25313          (%i1) load ("graphs")$
25314          (%i2) vertices(complete_graph(4));
25315          (%o2)                     [3, 2, 1, 0]
25316
25317 -- Function: vertex_coloring (<gr>)
25318     Returns an optimal coloring of the vertices of the graph <gr>.
25319
25320     The function returns the chromatic number and a list representing
25321     the coloring of the vertices of <gr>.
25322
25323     Example:
25324          (%i1) load ("graphs")$
25325          (%i2) p:petersen_graph()$
25326          (%i3) vertex_coloring(p);
25327          (%o3) [3, [[0, 2], [1, 3], [2, 2], [3, 3], [4, 1], [5, 3],
25328                                           [6, 1], [7, 1], [8, 2], [9, 2]]]
25329
25330 -- Function: wiener_index (<gr>)
25331     Returns the Wiener index of the graph <gr>.
25332
25333     Example:
25334          (%i2) wiener_index(dodecahedron_graph());
25335          (%o2)                          500
25336
2533762.2.3 Modifying graphs
25338-----------------------
25339
25340 -- Function: add_edge (<e>, <gr>)
25341     Adds the edge <e> to the graph <gr>.
25342
25343     Example:
25344          (%i1) load ("graphs")$
25345          (%i2) p : path_graph(4)$
25346          (%i3) neighbors(0, p);
25347          (%o3)                          [1]
25348          (%i4) add_edge([0,3], p);
25349          (%o4)                         done
25350          (%i5) neighbors(0, p);
25351          (%o5)                        [3, 1]
25352
25353 -- Function: add_edges (<e_list>, <gr>)
25354     Adds all edges in the list <e_list> to the graph <gr>.
25355
25356     Example:
25357          (%i1) load ("graphs")$
25358          (%i2) g : empty_graph(3)$
25359          (%i3) add_edges([[0,1],[1,2]], g)$
25360          (%i4) print_graph(g)$
25361          Graph on 3 vertices with 2 edges.
25362          Adjacencies:
25363            2 :  1
25364            1 :  2  0
25365            0 :  1
25366
25367 -- Function: add_vertex (<v>, <gr>)
25368     Adds the vertex <v> to the graph <gr>.
25369
25370     Example:
25371          (%i1) load ("graphs")$
25372          (%i2) g : path_graph(2)$
25373          (%i3) add_vertex(2, g)$
25374          (%i4) print_graph(g)$
25375          Graph on 3 vertices with 1 edges.
25376          Adjacencies:
25377            2 :
25378            1 :  0
25379            0 :  1
25380
25381 -- Function: add_vertices (<v_list>, <gr>)
25382     Adds all vertices in the list <v_list> to the graph <gr>.
25383
25384 -- Function: connect_vertices (<v_list>, <u_list>, <gr>)
25385     Connects all vertices from the list <v_list> with the vertices in
25386     the list <u_list> in the graph <gr>.
25387
25388     <v_list> and <u_list> can be single vertices or lists of vertices.
25389
25390     Example:
25391          (%i1) load ("graphs")$
25392          (%i2) g : empty_graph(4)$
25393          (%i3) connect_vertices(0, [1,2,3], g)$
25394          (%i4) print_graph(g)$
25395          Graph on 4 vertices with 3 edges.
25396          Adjacencies:
25397            3 :  0
25398            2 :  0
25399            1 :  0
25400            0 :  3  2  1
25401
25402 -- Function: contract_edge (<e>, <gr>)
25403     Contracts the edge <e> in the graph <gr>.
25404
25405     Example:
25406          (%i1) load ("graphs")$
25407          (%i2) g: create_graph(
25408                8, [[0,3],[1,3],[2,3],[3,4],[4,5],[4,6],[4,7]])$
25409          (%i3) print_graph(g)$
25410          Graph on 8 vertices with 7 edges.
25411          Adjacencies:
25412            7 :  4
25413            6 :  4
25414            5 :  4
25415            4 :  7  6  5  3
25416            3 :  4  2  1  0
25417            2 :  3
25418            1 :  3
25419            0 :  3
25420          (%i4) contract_edge([3,4], g)$
25421          (%i5) print_graph(g)$
25422          Graph on 7 vertices with 6 edges.
25423          Adjacencies:
25424            7 :  3
25425            6 :  3
25426            5 :  3
25427            3 :  5  6  7  2  1  0
25428            2 :  3
25429            1 :  3
25430            0 :  3
25431
25432 -- Function: remove_edge (<e>, <gr>)
25433     Removes the edge <e> from the graph <gr>.
25434
25435     Example:
25436          (%i1) load ("graphs")$
25437          (%i2) c3 : cycle_graph(3)$
25438          (%i3) remove_edge([0,1], c3)$
25439          (%i4) print_graph(c3)$
25440          Graph on 3 vertices with 2 edges.
25441          Adjacencies:
25442            2 :  0  1
25443            1 :  2
25444            0 :  2
25445
25446 -- Function: remove_vertex (<v>, <gr>)
25447     Removes the vertex <v> from the graph <gr>.
25448
2544962.2.4 Reading and writing to files
25450-----------------------------------
25451
25452 -- Function: dimacs_export
25453          dimacs_export (<gr>, <fl>)
25454          dimacs_export (<gr>, <fl>, <comment1>, ..., <commentn>)
25455
25456     Exports the graph into the file <fl> in the DIMACS format.
25457     Optional comments will be added to the top of the file.
25458
25459 -- Function: dimacs_import (<fl>)
25460
25461     Returns the graph from file <fl> in the DIMACS format.
25462
25463 -- Function: graph6_decode (<str>)
25464
25465     Returns the graph encoded in the graph6 format in the string <str>.
25466
25467 -- Function: graph6_encode (<gr>)
25468
25469     Returns a string which encodes the graph <gr> in the graph6 format.
25470
25471 -- Function: graph6_export (<gr_list>, <fl>)
25472
25473     Exports graphs in the list <gr_list> to the file <fl> in the graph6
25474     format.
25475
25476 -- Function: graph6_import (<fl>)
25477
25478     Returns a list of graphs from the file <fl> in the graph6 format.
25479
25480 -- Function: sparse6_decode (<str>)
25481
25482     Returns the graph encoded in the sparse6 format in the string
25483     <str>.
25484
25485 -- Function: sparse6_encode (<gr>)
25486
25487     Returns a string which encodes the graph <gr> in the sparse6
25488     format.
25489
25490 -- Function: sparse6_export (<gr_list>, <fl>)
25491
25492     Exports graphs in the list <gr_list> to the file <fl> in the
25493     sparse6 format.
25494
25495 -- Function: sparse6_import (<fl>)
25496
25497     Returns a list of graphs from the file <fl> in the sparse6 format.
25498
2549962.2.5 Visualization
25500--------------------
25501
25502 -- Function: draw_graph
25503          draw_graph (<graph>)
25504          draw_graph (<graph>, <option1>, ..., <optionk>)
25505
25506     Draws the graph using the *note draw-pkg:: package.
25507
25508     The algorithm used to position vertices is specified by the
25509     optional argument <program>.  The default value is
25510     'program=spring_embedding'.  <draw_graph> can also use the graphviz
25511     programs for positioning vertices, but graphviz must be installed
25512     separately.
25513
25514     Example 1:
25515
25516          (%i1) load ("graphs")$
25517          (%i2) g:grid_graph(10,10)$
25518          (%i3) m:max_matching(g)$
25519          (%i4) draw_graph(g,
25520             spring_embedding_depth=100,
25521             show_edges=m, edge_type=dots,
25522             vertex_size=0)$
25523
25524     Example 2:
25525
25526          (%i1) load ("graphs")$
25527          (%i2) g:create_graph(16,
25528              [
25529               [0,1],[1,3],[2,3],[0,2],[3,4],[2,4],
25530               [5,6],[6,4],[4,7],[6,7],[7,8],[7,10],[7,11],
25531               [8,10],[11,10],[8,9],[11,12],[9,15],[12,13],
25532               [10,14],[15,14],[13,14]
25533              ])$
25534          (%i3) t:minimum_spanning_tree(g)$
25535          (%i4) draw_graph(
25536              g,
25537              show_edges=edges(t),
25538              show_edge_width=4,
25539              show_edge_color=green,
25540              vertex_type=filled_square,
25541              vertex_size=2
25542              )$
25543
25544     Example 3:
25545
25546          (%i1) load ("graphs")$
25547          (%i2) g:create_graph(16,
25548              [
25549               [0,1],[1,3],[2,3],[0,2],[3,4],[2,4],
25550               [5,6],[6,4],[4,7],[6,7],[7,8],[7,10],[7,11],
25551               [8,10],[11,10],[8,9],[11,12],[9,15],[12,13],
25552               [10,14],[15,14],[13,14]
25553              ])$
25554          (%i3) mi : max_independent_set(g)$
25555          (%i4) draw_graph(
25556              g,
25557              show_vertices=mi,
25558              show_vertex_type=filled_up_triangle,
25559              show_vertex_size=2,
25560              edge_color=cyan,
25561              edge_width=3,
25562              show_id=true,
25563              text_color=brown
25564              )$
25565
25566     Example 4:
25567
25568          (%i1) load ("graphs")$
25569          (%i2) net : create_graph(
25570              [0,1,2,3,4,5],
25571              [
25572               [[0,1], 3], [[0,2], 2],
25573               [[1,3], 1], [[1,4], 3],
25574               [[2,3], 2], [[2,4], 2],
25575               [[4,5], 2], [[3,5], 2]
25576              ],
25577              directed=true
25578              )$
25579          (%i3) draw_graph(
25580              net,
25581              show_weight=true,
25582              vertex_size=0,
25583              show_vertices=[0,5],
25584              show_vertex_type=filled_square,
25585              head_length=0.2,
25586              head_angle=10,
25587              edge_color="dark-green",
25588              text_color=blue
25589              )$
25590
25591     Example 5:
25592
25593          (%i1) load("graphs")$
25594          (%i2) g: petersen_graph(20, 2);
25595          (%o2)                         GRAPH
25596          (%i3) draw_graph(g, redraw=true, program=planar_embedding);
25597          (%o3)                         done
25598
25599     Example 6:
25600
25601          (%i1) load("graphs")$
25602          (%i2) t: tutte_graph();
25603          (%o2)                         GRAPH
25604          (%i3) draw_graph(t, redraw=true,
25605                              fixed_vertices=[1,2,3,4,5,6,7,8,9]);
25606          (%o3)                         done
25607
25608 -- Option variable: draw_graph_program
25609     Default value: <spring_embedding>
25610
25611     The default value for the program used to position vertices in
25612     'draw_graph' program.
25613
25614 -- draw_graph option: show_id
25615     Default value: <false>
25616
25617     If <true> then ids of the vertices are displayed.
25618
25619 -- draw_graph option: show_label
25620     Default value: <false>
25621
25622     If <true> then labels of the vertices are displayed.
25623
25624 -- draw_graph option: label_alignment
25625     Default value: <center>
25626
25627     Determines how to align the labels/ids of the vertices.  Can be
25628     'left', 'center' or 'right'.
25629
25630 -- draw_graph option: show_weight
25631     Default value: <false>
25632
25633     If <true> then weights of the edges are displayed.
25634
25635 -- draw_graph option: vertex_type
25636     Default value: <circle>
25637
25638     Defines how vertices are displayed.  See the <point_type> option
25639     for the 'draw' package for possible values.
25640
25641 -- draw_graph option: vertex_size
25642     The size of vertices.
25643
25644 -- draw_graph option: vertex_color
25645     The color used for displaying vertices.
25646
25647 -- draw_graph option: show_vertices
25648     Default value: []
25649
25650     Display selected vertices in the using a different color.
25651
25652 -- draw_graph option: show_vertex_type
25653     Defines how vertices specified in <show_vertices> are displayed.
25654     See the <point_type> option for the 'draw' package for possible
25655     values.
25656
25657 -- draw_graph option: show_vertex_size
25658     The size of vertices in <show_vertices>.
25659
25660 -- draw_graph option: show_vertex_color
25661     The color used for displaying vertices in the <show_vertices> list.
25662
25663 -- draw_graph option: vertex_partition
25664     Default value: []
25665
25666     A partition '[[v1,v2,...],...,[vk,...,vn]]' of the vertices of the
25667     graph.  The vertices of each list in the partition will be drawn in
25668     a different color.
25669
25670 -- draw_graph option: vertex_coloring
25671     Specifies coloring of the vertices.  The coloring <col> must be
25672     specified in the format as returned by <vertex_coloring>.
25673
25674 -- draw_graph option: edge_color
25675     The color used for displaying edges.
25676
25677 -- draw_graph option: edge_width
25678     The width of edges.
25679
25680 -- draw_graph option: edge_type
25681     Defines how edges are displayed.  See the <line_type> option for
25682     the 'draw' package.
25683
25684 -- draw_graph option: show_edges
25685     Display edges specified in the list <e_list> using a different
25686     color.
25687
25688 -- draw_graph option: show_edge_color
25689     The color used for displaying edges in the <show_edges> list.
25690
25691 -- draw_graph option: show_edge_width
25692     The width of edges in <show_edges>.
25693
25694 -- draw_graph option: show_edge_type
25695     Defines how edges in <show_edges> are displayed.  See the
25696     <line_type> option for the 'draw' package.
25697
25698 -- draw_graph option: edge_partition
25699     A partition '[[e1,e2,...],...,[ek,...,em]]' of edges of the graph.
25700     The edges of each list in the partition will be drawn using a
25701     different color.
25702
25703 -- draw_graph option: edge_coloring
25704     The coloring of edges.  The coloring must be specified in the
25705     format as returned by the function <edge_coloring>.
25706
25707 -- draw_graph option: redraw
25708     Default value: <false>
25709
25710     If 'true', vertex positions are recomputed even if the positions
25711     have been saved from a previous drawing of the graph.
25712
25713 -- draw_graph option: head_angle
25714     Default value: 15
25715
25716     The angle for the arrows displayed on arcs (in directed graphs).
25717
25718 -- draw_graph option: head_length
25719     Default value: 0.1
25720
25721     The length for the arrows displayed on arcs (in directed graphs).
25722
25723 -- draw_graph option: spring_embedding_depth
25724     Default value: 50
25725
25726     The number of iterations in the spring embedding graph drawing
25727     algorithm.
25728
25729 -- draw_graph option: terminal
25730     The terminal used for drawing (see the <terminal> option in the
25731     'draw' package).
25732
25733 -- draw_graph option: file_name
25734     The filename of the drawing if terminal is not screen.
25735
25736 -- draw_graph option: program
25737     Defines the program used for positioning vertices of the graph.
25738     Can be one of the graphviz programs (dot, neato, twopi, circ, fdp),
25739     <circular>, <spring_embedding> or <planar_embedding>.
25740     <planar_embedding> is only available for 2-connected planar graphs.
25741     When 'program=spring_embedding', a set of vertices with fixed
25742     position can be specified with the <fixed_vertices> option.
25743
25744 -- draw_graph option: fixed_vertices
25745     Specifies a list of vertices which will have positions fixed along
25746     a regular polygon.  Can be used when 'program=spring_embedding'.
25747
25748 -- Function: vertices_to_path (<v_list>)
25749     Converts a list <v_list> of vertices to a list of edges of the path
25750     defined by <v_list>.
25751
25752 -- Function: vertices_to_cycle (<v_list>)
25753     Converts a list <v_list> of vertices to a list of edges of the
25754     cycle defined by <v_list>.
25755
25756