1This is maxima.info, produced by makeinfo version 6.6 from maxima.texi.
2
3Das ist ein Texinfo Maxima Manual
4
5   Copyright 1994,2001 William F. Schelter
6
7START-INFO-DIR-ENTRY
8* Maxima: (maxima).     Ein Computer Algebra System.
9END-INFO-DIR-ENTRY
10
11
12File: maxima.info,  Node: lbfgs,  Next: lindstedt,  Prev: lapack,  Up: Top
13
1456 lbfgs
15********
16
17* Menu:
18
19* Introduction to lbfgs::
20* Functions and Variables for lbfgs::
21
22
23File: maxima.info,  Node: Introduction to lbfgs,  Next: Functions and Variables for lbfgs,  Prev: Top,  Up: Top
24
2556.1 Introduction to lbfgs
26==========================
27
28'lbfgs' is an implementation of the L-BFGS algorithm [1] to solve
29unconstrained minimization problems via a limited-memory quasi-Newton
30(BFGS) algorithm.  It is called a limited-memory method because a
31low-rank approximation of the Hessian matrix inverse is stored instead
32of the entire Hessian inverse.  The program was originally written in
33Fortran [2] by Jorge Nocedal, incorporating some functions originally
34written by Jorge J. Moré and David J. Thuente, and translated into Lisp
35automatically via the program 'f2cl'.  The Maxima package 'lbfgs'
36comprises the translated code plus an interface function which manages
37some details.
38
39References:
40
41[1] D. Liu and J. Nocedal.  "On the limited memory BFGS method for large
42scale optimization".  Mathematical Programming B 45:503-528 (1989)
43
44[2] <http://netlib.org/opt/lbfgs_um.shar>
45
46
47File: maxima.info,  Node: Functions and Variables for lbfgs,  Prev: Introduction to lbfgs,  Up: Top
48
4956.2 Functions and Variables for lbfgs
50======================================
51
52 -- Function: lbfgs (<FOM>, <X>, <X0>, <epsilon>, <iprint>)
53 -- Function: lbfgs ([<FOM>, <grad>] <X>, <X0>, <epsilon>, <iprint>)
54
55     Finds an approximate solution of the unconstrained minimization of
56     the figure of merit <FOM> over the list of variables <X>, starting
57     from initial estimates <X0>, such that norm(grad(FOM)) <
58     epsilon*max(1, norm(X)).
59
60     <grad>, if present, is the gradient of <FOM> with respect to the
61     variables <X>.  <grad> is a list, with one element for each element
62     of <X>.  If not present, the gradient is computed automatically by
63     symbolic differentiation.
64
65     The algorithm applied is a limited-memory quasi-Newton (BFGS)
66     algorithm [1].  It is called a limited-memory method because a
67     low-rank approximation of the Hessian matrix inverse is stored
68     instead of the entire Hessian inverse.  Each iteration of the
69     algorithm is a line search, that is, a search along a ray in the
70     variables <X>, with the search direction computed from the
71     approximate Hessian inverse.  The FOM is always decreased by a
72     successful line search.  Usually (but not always) the norm of the
73     gradient of FOM also decreases.
74
75     <iprint> controls progress messages printed by 'lbfgs'.
76
77     'iprint[1]'
78          '<iprint>[1]' controls the frequency of progress messages.
79          'iprint[1] < 0'
80               No progress messages.
81          'iprint[1] = 0'
82               Messages at the first and last iterations.
83          'iprint[1] > 0'
84               Print a message every '<iprint>[1]' iterations.
85     'iprint[2]'
86          '<iprint>[2]' controls the verbosity of progress messages.
87          'iprint[2] = 0'
88               Print out iteration count, number of evaluations of
89               <FOM>, value of <FOM>, norm of the gradient of <FOM>, and
90               step length.
91          'iprint[2] = 1'
92               Same as '<iprint>[2] = 0', plus <X0> and the gradient of
93               <FOM> evaluated at <X0>.
94          'iprint[2] = 2'
95               Same as '<iprint>[2] = 1', plus values of <X> at each
96               iteration.
97          'iprint[2] = 3'
98               Same as '<iprint>[2] = 2', plus the gradient of <FOM> at
99               each iteration.
100
101     The columns printed by 'lbfgs' are the following.
102
103     'I'
104          Number of iterations.  It is incremented for each line search.
105     'NFN'
106          Number of evaluations of the figure of merit.
107     'FUNC'
108          Value of the figure of merit at the end of the most recent
109          line search.
110     'GNORM'
111          Norm of the gradient of the figure of merit at the end of the
112          most recent line search.
113     'STEPLENGTH'
114          An internal parameter of the search algorithm.
115
116     Additional information concerning details of the algorithm are
117     found in the comments of the original Fortran code [2].
118
119     See also 'lbfgs_nfeval_max' and 'lbfgs_ncorrections'.
120
121     References:
122
123     [1] D. Liu and J. Nocedal.  "On the limited memory BFGS method for
124     large scale optimization".  Mathematical Programming B 45:503-528
125     (1989)
126
127     [2] <http://netlib.org/opt/lbfgs_um.shar>
128
129     Examples:
130
131     The same FOM as computed by FGCOMPUTE in the program sdrive.f in
132     the LBFGS package from Netlib.  Note that the variables in question
133     are subscripted variables.  The FOM has an exact minimum equal to
134     zero at u[k] = 1 for k = 1, ..., 8.
135
136          (%i1) load (lbfgs);
137          (%o1)   /usr/share/maxima/5.10.0cvs/share/lbfgs/lbfgs.mac
138          (%i2) t1[j] := 1 - u[j];
139          (%o2)                     t1  := 1 - u
140                                      j         j
141          (%i3) t2[j] := 10*(u[j + 1] - u[j]^2);
142                                                    2
143          (%o3)                t2  := 10 (u      - u )
144                                 j         j + 1    j
145          (%i4) n : 8;
146          (%o4)                           8
147          (%i5) FOM : sum (t1[2*j - 1]^2 + t2[2*j - 1]^2, j, 1, n/2);
148                           2 2           2              2 2           2
149          (%o5) 100 (u  - u )  + (1 - u )  + 100 (u  - u )  + (1 - u )
150                      8    7           7           6    5           5
151                               2 2           2              2 2           2
152                  + 100 (u  - u )  + (1 - u )  + 100 (u  - u )  + (1 - u )
153                          4    3           3           2    1           1
154          (%i6) lbfgs (FOM, '[u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8]],
155                 [-1.2, 1, -1.2, 1, -1.2, 1, -1.2, 1], 1e-3, [1, 0]);
156          *************************************************
157            N=    8   NUMBER OF CORRECTIONS=25
158                 INITIAL VALUES
159           F=  9.680000000000000D+01   GNORM=  4.657353755084532D+02
160          *************************************************
161           I NFN   FUNC                    GNORM                   STEPLENGTH
162
163           1   3   1.651479526340304D+01   4.324359291335977D+00   7.926153934390631D-04
164           2   4   1.650209316638371D+01   3.575788161060007D+00   1.000000000000000D+00
165           3   5   1.645461701312851D+01   6.230869903601577D+00   1.000000000000000D+00
166           4   6   1.636867301275588D+01   1.177589920974980D+01   1.000000000000000D+00
167           5   7   1.612153014409201D+01   2.292797147151288D+01   1.000000000000000D+00
168           6   8   1.569118407390628D+01   3.687447158775571D+01   1.000000000000000D+00
169           7   9   1.510361958398942D+01   4.501931728123680D+01   1.000000000000000D+00
170           8  10   1.391077875774294D+01   4.526061463810632D+01   1.000000000000000D+00
171           9  11   1.165625686278198D+01   2.748348965356917D+01   1.000000000000000D+00
172          10  12   9.859422687859137D+00   2.111494974231644D+01   1.000000000000000D+00
173          11  13   7.815442521732281D+00   6.110762325766556D+00   1.000000000000000D+00
174          12  15   7.346380905773160D+00   2.165281166714631D+01   1.285316401779533D-01
175          13  16   6.330460634066370D+00   1.401220851762050D+01   1.000000000000000D+00
176          14  17   5.238763939851439D+00   1.702473787613255D+01   1.000000000000000D+00
177          15  18   3.754016790406701D+00   7.981845727704576D+00   1.000000000000000D+00
178          16  20   3.001238402309352D+00   3.925482944716691D+00   2.333129631296807D-01
179          17  22   2.794390709718290D+00   8.243329982546473D+00   2.503577283782332D-01
180          18  23   2.563783562918759D+00   1.035413426521790D+01   1.000000000000000D+00
181          19  24   2.019429976377856D+00   1.065187312346769D+01   1.000000000000000D+00
182          20  25   1.428003167670903D+00   2.475962450826961D+00   1.000000000000000D+00
183          21  27   1.197874264861340D+00   8.441707983493810D+00   4.303451060808756D-01
184          22  28   9.023848941942773D-01   1.113189216635162D+01   1.000000000000000D+00
185          23  29   5.508226405863770D-01   2.380830600326308D+00   1.000000000000000D+00
186          24  31   3.902893258815567D-01   5.625595816584421D+00   4.834988416524465D-01
187          25  32   3.207542206990315D-01   1.149444645416472D+01   1.000000000000000D+00
188          26  33   1.874468266362791D-01   3.632482152880997D+00   1.000000000000000D+00
189          27  34   9.575763380706598D-02   4.816497446154354D+00   1.000000000000000D+00
190          28  35   4.085145107543406D-02   2.087009350166495D+00   1.000000000000000D+00
191          29  36   1.931106001379290D-02   3.886818608498966D+00   1.000000000000000D+00
192          30  37   6.894000721499670D-03   3.198505796342214D+00   1.000000000000000D+00
193          31  38   1.443296033051864D-03   1.590265471025043D+00   1.000000000000000D+00
194          32  39   1.571766603154336D-04   3.098257063980634D-01   1.000000000000000D+00
195          33  40   1.288011776581970D-05   1.207784183577257D-02   1.000000000000000D+00
196          34  41   1.806140173752971D-06   4.587890233385193D-02   1.000000000000000D+00
197          35  42   1.769004645459358D-07   1.790537375052208D-02   1.000000000000000D+00
198          36  43   3.312164100763217D-10   6.782068426119681D-04   1.000000000000000D+00
199
200           THE MINIMIZATION TERMINATED WITHOUT DETECTING ERRORS.
201           IFLAG = 0
202          (%o6) [u  = 1.000005339815974, u  = 1.000009942839805,
203                  1                       2
204          u  = 1.000005339815974, u  = 1.000009942839805,
205           3                       4
206          u  = 1.000005339815974, u  = 1.000009942839805,
207           5                       6
208          u  = 1.000005339815974, u  = 1.000009942839805]
209           7                       8
210
211     A regression problem.  The FOM is the mean square difference
212     between the predicted value F(X[i]) and the observed value Y[i].
213     The function F is a bounded monotone function (a so-called
214     "sigmoidal" function).  In this example, 'lbfgs' computes
215     approximate values for the parameters of F and 'plot2d' displays a
216     comparison of F with the observed data.
217
218          (%i1) load (lbfgs);
219          (%o1)   /usr/share/maxima/5.10.0cvs/share/lbfgs/lbfgs.mac
220          (%i2) FOM : '((1/length(X))*sum((F(X[i]) - Y[i])^2, i, 1,
221                                                          length(X)));
222                                         2
223                         sum((F(X ) - Y ) , i, 1, length(X))
224                                 i     i
225          (%o2)          -----------------------------------
226                                      length(X)
227          (%i3) X : [1, 2, 3, 4, 5];
228          (%o3)                    [1, 2, 3, 4, 5]
229          (%i4) Y : [0, 0.5, 1, 1.25, 1.5];
230          (%o4)                [0, 0.5, 1, 1.25, 1.5]
231          (%i5) F(x) := A/(1 + exp(-B*(x - C)));
232                                             A
233          (%o5)            F(x) := ----------------------
234                                   1 + exp((- B) (x - C))
235          (%i6) ''FOM;
236                          A               2            A                2
237          (%o6) ((----------------- - 1.5)  + (----------------- - 1.25)
238                    - B (5 - C)                  - B (4 - C)
239                  %e            + 1            %e            + 1
240                      A             2            A               2
241           + (----------------- - 1)  + (----------------- - 0.5)
242                - B (3 - C)                - B (2 - C)
243              %e            + 1          %e            + 1
244                       2
245                      A
246           + --------------------)/5
247                - B (1 - C)     2
248             (%e            + 1)
249          (%i7) estimates : lbfgs (FOM, '[A, B, C], [1, 1, 1], 1e-4, [1, 0]);
250          *************************************************
251            N=    3   NUMBER OF CORRECTIONS=25
252                 INITIAL VALUES
253           F=  1.348738534246918D-01   GNORM=  2.000215531936760D-01
254          *************************************************
255
256          I  NFN  FUNC                    GNORM                   STEPLENGTH
257          1    3  1.177820636622582D-01   9.893138394953992D-02   8.554435968992371D-01
258          2    6  2.302653892214013D-02   1.180098521565904D-01   2.100000000000000D+01
259          3    8  1.496348495303005D-02   9.611201567691633D-02   5.257340567840707D-01
260          4    9  7.900460841091139D-03   1.325041647391314D-02   1.000000000000000D+00
261          5   10  7.314495451266917D-03   1.510670810312237D-02   1.000000000000000D+00
262          6   11  6.750147275936680D-03   1.914964958023047D-02   1.000000000000000D+00
263          7   12  5.850716021108205D-03   1.028089194579363D-02   1.000000000000000D+00
264          8   13  5.778664230657791D-03   3.676866074530332D-04   1.000000000000000D+00
265          9   14  5.777818823650782D-03   3.010740179797255D-04   1.000000000000000D+00
266
267           THE MINIMIZATION TERMINATED WITHOUT DETECTING ERRORS.
268           IFLAG = 0
269          (%o7) [A = 1.461933911464101, B = 1.601593973254802,
270                                                     C = 2.528933072164854]
271          (%i8) plot2d ([F(x), [discrete, X, Y]], [x, -1, 6]), ''estimates;
272          (%o8)
273
274     Gradient of FOM is specified (instead of computing it
275     automatically).
276
277          (%i1) load (lbfgs)$
278          (%i2) F(a, b, c) := (a - 5)^2 + (b - 3)^4 + (c - 2)^6;
279                                         2          4          6
280          (%o2)     F(a, b, c) := (a - 5)  + (b - 3)  + (c - 2)
281          (%i3) F_grad : map (lambda ([x], diff (F(a, b, c), x)), [a, b, c]);
282                                              3           5
283          (%o3)          [2 (a - 5), 4 (b - 3) , 6 (c - 2) ]
284          (%i4) estimates : lbfgs ([F(a, b, c), F_grad],
285                                   [a, b, c], [0, 0, 0], 1e-4, [1, 0]);
286          *************************************************
287            N=    3   NUMBER OF CORRECTIONS=25
288                 INITIAL VALUES
289           F=  1.700000000000000D+02   GNORM=  2.205175729958953D+02
290          *************************************************
291
292             I  NFN     FUNC                    GNORM                   STEPLENGTH
293
294             1    2     6.632967565917638D+01   6.498411132518770D+01   4.534785987412505D-03
295             2    3     4.368890936228036D+01   3.784147651974131D+01   1.000000000000000D+00
296             3    4     2.685298972775190D+01   1.640262125898521D+01   1.000000000000000D+00
297             4    5     1.909064767659852D+01   9.733664001790506D+00   1.000000000000000D+00
298             5    6     1.006493272061515D+01   6.344808151880209D+00   1.000000000000000D+00
299             6    7     1.215263596054294D+00   2.204727876126879D+00   1.000000000000000D+00
300             7    8     1.080252896385334D-02   1.431637116951849D-01   1.000000000000000D+00
301             8    9     8.407195124830908D-03   1.126344579730013D-01   1.000000000000000D+00
302             9   10     5.022091686198527D-03   7.750731829225274D-02   1.000000000000000D+00
303            10   11     2.277152808939775D-03   5.032810859286795D-02   1.000000000000000D+00
304            11   12     6.489384688303218D-04   1.932007150271008D-02   1.000000000000000D+00
305            12   13     2.075791943844548D-04   6.964319310814364D-03   1.000000000000000D+00
306            13   14     7.349472666162257D-05   4.017449067849554D-03   1.000000000000000D+00
307            14   15     2.293617477985237D-05   1.334590390856715D-03   1.000000000000000D+00
308            15   16     7.683645404048675D-06   6.011057038099201D-04   1.000000000000000D+00
309
310           THE MINIMIZATION TERMINATED WITHOUT DETECTING ERRORS.
311           IFLAG = 0
312          (%o4) [a = 5.000086823042934, b = 3.05239542970518,
313                                                     c = 1.927980629919583]
314
315 -- Variable: lbfgs_nfeval_max
316     Default value: 100
317
318     'lbfgs_nfeval_max' is the maximum number of evaluations of the
319     figure of merit (FOM) in 'lbfgs'.  When 'lbfgs_nfeval_max' is
320     reached, 'lbfgs' returns the result of the last successful line
321     search.
322
323 -- Variable: lbfgs_ncorrections
324     Default value: 25
325
326     'lbfgs_ncorrections' is the number of corrections applied to the
327     approximate inverse Hessian matrix which is maintained by 'lbfgs'.
328
329
330File: maxima.info,  Node: lindstedt,  Next: linearalgebra,  Prev: lbfgs,  Up: Top
331
33257 lindstedt
333************
334
335* Menu:
336
337* Functions and Variables for lindstedt::
338
339
340File: maxima.info,  Node: Functions and Variables for lindstedt,  Prev: lindstedt,  Up: lindstedt
341
34257.1 Functions and Variables for lindstedt
343==========================================
344
345 -- Function: Lindstedt (<eq>,<pvar>,<torder>,<ic>)
346
347     This is a first pass at a Lindstedt code.  It can solve problems
348     with initial conditions entered, which can be arbitrary constants,
349     (just not <%k1> and <%k2>) where the initial conditions on the
350     perturbation equations are z[i]=0, z'[i]=0 for i>0.  <ic> is the
351     list of initial conditions.
352
353     Problems occur when initial conditions are not given, as the
354     constants in the perturbation equations are the same as the zero
355     order equation solution.  Also, problems occur when the initial
356     conditions for the perturbation equations are not z[i]=0, z'[i]=0
357     for i>0, such as the Van der Pol equation.
358
359     Example:
360
361          (%i1) load("makeOrders")$
362
363          (%i2) load("lindstedt")$
364
365          (%i3) Lindstedt('diff(x,t,2)+x-(e*x^3)/6,e,2,[1,0]);
366                    2
367                   e  (cos(5 T) - 24 cos(3 T) + 23 cos(T))
368          (%o3) [[[---------------------------------------
369                                    36864
370             e (cos(3 T) - cos(T))
371           - --------------------- + cos(T)],
372                      192
373                    2
374                 7 e    e
375          T = (- ---- - -- + 1) t]]
376                 3072   16
377
378     To use this function write first 'load("makeOrders")' and
379     'load("lindstedt")'.
380
381
382File: maxima.info,  Node: linearalgebra,  Next: lsquares,  Prev: lindstedt,  Up: Top
383
38458 linearalgebra
385****************
386
387* Menu:
388
389* Introduction to linearalgebra::
390* Functions and Variables for linearalgebra::
391
392
393File: maxima.info,  Node: Introduction to linearalgebra,  Next: Functions and Variables for linearalgebra,  Prev: linearalgebra,  Up: linearalgebra
394
39558.1 Introduction to linearalgebra
396==================================
397
398'linearalgebra' is a collection of functions for linear algebra.
399
400Example:
401
402     (%i1) M : matrix ([1, 2], [1, 2]);
403                                 [ 1  2 ]
404     (%o1)                       [      ]
405                                 [ 1  2 ]
406     (%i2) nullspace (M);
407                                    [  1  ]
408                                    [     ]
409     (%o2)                     span([   1 ])
410                                    [ - - ]
411                                    [   2 ]
412     (%i3) columnspace (M);
413                                     [ 1 ]
414     (%o3)                      span([   ])
415                                     [ 1 ]
416     (%i4) ptriangularize (M - z*ident(2), z);
417                              [ 1   2 - z   ]
418     (%o4)                    [             ]
419                              [           2 ]
420                              [ 0  3 z - z  ]
421     (%i5) M : matrix ([1, 2, 3], [4, 5, 6], [7, 8, 9]) - z*ident(3);
422                          [ 1 - z    2      3   ]
423                          [                     ]
424     (%o5)                [   4    5 - z    6   ]
425                          [                     ]
426                          [   7      8    9 - z ]
427     (%i6) MM : ptriangularize (M, z);
428                   [ 4  5 - z            6            ]
429                   [                                  ]
430                   [                2                 ]
431                   [     66        z    102 z   132   ]
432                   [ 0   --      - -- + ----- + ---   ]
433     (%o6)         [     49        7     49     49    ]
434                   [                                  ]
435                   [               3        2         ]
436                   [           49 z    245 z    147 z ]
437                   [ 0    0    ----- - ------ - ----- ]
438                   [            264      88      44   ]
439     (%i7) algebraic : true;
440     (%o7)                         true
441     (%i8) tellrat (MM [3, 3]);
442                              3       2
443     (%o8)                  [z  - 15 z  - 18 z]
444     (%i9) MM : ratsimp (MM);
445                    [ 4  5 - z           6           ]
446                    [                                ]
447                    [                2               ]
448     (%o9)          [     66      7 z  - 102 z - 132 ]
449                    [ 0   --    - ------------------ ]
450                    [     49              49         ]
451                    [                                ]
452                    [ 0    0             0           ]
453     (%i10) nullspace (MM);
454                             [        1         ]
455                             [                  ]
456                             [   2              ]
457                             [  z  - 14 z - 16  ]
458                             [  --------------  ]
459     (%o10)             span([        8         ])
460                             [                  ]
461                             [    2             ]
462                             [   z  - 18 z - 12 ]
463                             [ - -------------- ]
464                             [         12       ]
465     (%i11) M : matrix ([1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
466                        [13, 14, 15, 16]);
467                            [ 1   2   3   4  ]
468                            [                ]
469                            [ 5   6   7   8  ]
470     (%o11)                 [                ]
471                            [ 9   10  11  12 ]
472                            [                ]
473                            [ 13  14  15  16 ]
474     (%i12) columnspace (M);
475                                [ 1  ]  [ 2  ]
476                                [    ]  [    ]
477                                [ 5  ]  [ 6  ]
478     (%o12)                span([    ], [    ])
479                                [ 9  ]  [ 10 ]
480                                [    ]  [    ]
481                                [ 13 ]  [ 14 ]
482     (%i13) apply ('orthogonal_complement, args (nullspace (transpose (M))));
483                                [ 0 ]  [  1  ]
484                                [   ]  [     ]
485                                [ 1 ]  [  0  ]
486     (%o13)                span([   ], [     ])
487                                [ 2 ]  [ - 1 ]
488                                [   ]  [     ]
489                                [ 3 ]  [ - 2 ]
490
491
492File: maxima.info,  Node: Functions and Variables for linearalgebra,  Prev: Introduction to linearalgebra,  Up: linearalgebra
493
49458.2 Functions and Variables for linearalgebra
495==============================================
496
497 -- Function: addmatrices (<f>, <M_1>, ..., <M_n>)
498
499     Using the function <f> as the addition function, return the sum of
500     the matrices <M_1>, ..., <M_n>.  The function <f> must accept any
501     number of arguments (a Maxima nary function).
502
503     Examples:
504
505          (%i1) m1 : matrix([1,2],[3,4])$
506          (%i2) m2 : matrix([7,8],[9,10])$
507          (%i3) addmatrices('max,m1,m2);
508          (%o3) matrix([7,8],[9,10])
509          (%i4) addmatrices('max,m1,m2,5*m1);
510          (%o4) matrix([7,10],[15,20])
511
512 -- Function: blockmatrixp (<M>)
513
514     Return true if and only if <M> is a matrix and every entry of <M>
515     is a matrix.
516
517 -- Function: columnop (<M>, <i>, <j>, <theta>)
518
519     If <M> is a matrix, return the matrix that results from doing the
520     column operation 'C_i <- C_i - <theta> * C_j'.  If <M> doesn't have
521     a row <i> or <j>, signal an error.
522
523 -- Function: columnswap (<M>, <i>, <j>)
524
525     If <M> is a matrix, swap columns <i> and <j>.  If <M> doesn't have
526     a column <i> or <j>, signal an error.
527
528 -- Function: columnspace (<M>)
529
530     If <M> is a matrix, return 'span (v_1, ..., v_n)', where the set
531     '{v_1, ..., v_n}' is a basis for the column space of <M>.  The span
532     of the empty set is '{0}'.  Thus, when the column space has only
533     one member, return 'span ()'.
534
535 -- Function: copy (<e>)
536
537     Return a copy of the Maxima expression <e>.  Although <e> can be
538     any Maxima expression, the copy function is the most useful when
539     <e> is either a list or a matrix; consider:
540
541          (%i1) m : [1,[2,3]]$
542          (%i2) mm : m$
543          (%i3) mm[2][1] : x$
544          (%i4) m;
545          (%o4)                      [1,[x,3]]
546          (%i5) mm;
547          (%o5)                      [1,[x,3]]
548
549     Let's try the same experiment, but this time let <mm> be a copy of
550     <m>
551
552          (%i6) m : [1,[2,3]]$
553          (%i7) mm : copy(m)$
554          (%i8) mm[2][1] : x$
555          (%i9) m;
556          (%o9)                     [1,[2,3]]
557          (%i10) mm;
558          (%o10)                    [1,[x,3]]
559     This time, the assignment to <mm> does not change the value of <m>.
560
561 -- Function: cholesky (<M>)
562 -- Function: cholesky (<M>, <field>)
563
564     Return the Cholesky factorization of the matrix selfadjoint (or
565     hermitian) matrix <M>.  The second argument defaults to
566     'generalring.'  For a description of the possible values for
567     <field>, see 'lu_factor'.
568
569 -- Function: ctranspose (<M>)
570
571     Return the complex conjugate transpose of the matrix <M>.  The
572     function 'ctranspose' uses 'matrix_element_transpose' to transpose
573     each matrix element.
574
575 -- Function: diag_matrix (<d_1>, <d_2>,...,<d_n>)
576
577     Return a diagonal matrix with diagonal entries <d_1>, <d_2>, ...,
578     <d_n>.  When the diagonal entries are matrices, the zero entries of
579     the returned matrix are zero matrices of the appropriate size; for
580     example:
581
582          (%i1) diag_matrix(diag_matrix(1,2),diag_matrix(3,4));
583
584                                      [ [ 1  0 ]  [ 0  0 ] ]
585                                      [ [      ]  [      ] ]
586                                      [ [ 0  2 ]  [ 0  0 ] ]
587          (%o1)                       [                    ]
588                                      [ [ 0  0 ]  [ 3  0 ] ]
589                                      [ [      ]  [      ] ]
590                                      [ [ 0  0 ]  [ 0  4 ] ]
591          (%i2) diag_matrix(p,q);
592
593                                             [ p  0 ]
594          (%o2)                              [      ]
595                                             [ 0  q ]
596
597 -- Function: dotproduct (<u>, <v>)
598
599     Return the dotproduct of vectors <u> and <v>.  This is the same as
600     'conjugate (transpose (<u>)) . <v>'.  The arguments <u> and <v>
601     must be column vectors.
602
603 -- Function: eigens_by_jacobi (<A>)
604 -- Function: eigens_by_jacobi (<A>, <field_type>)
605
606     Computes the eigenvalues and eigenvectors of <A> by the method of
607     Jacobi rotations.  <A> must be a symmetric matrix (but it need not
608     be positive definite nor positive semidefinite).  <field_type>
609     indicates the computational field, either 'floatfield' or
610     'bigfloatfield'.  If <field_type> is not specified, it defaults to
611     'floatfield'.
612
613     The elements of <A> must be numbers or expressions which evaluate
614     to numbers via 'float' or 'bfloat' (depending on <field_type>).
615
616     Examples:
617
618          (%i1) S: matrix([1/sqrt(2), 1/sqrt(2)],[-1/sqrt(2), 1/sqrt(2)]);
619                               [     1         1    ]
620                               [  -------   ------- ]
621                               [  sqrt(2)   sqrt(2) ]
622          (%o1)                [                    ]
623                               [      1        1    ]
624                               [ - -------  ------- ]
625                               [   sqrt(2)  sqrt(2) ]
626          (%i2) L : matrix ([sqrt(3), 0], [0, sqrt(5)]);
627                                [ sqrt(3)     0    ]
628          (%o2)                 [                  ]
629                                [    0     sqrt(5) ]
630          (%i3) M : S . L . transpose (S);
631                      [ sqrt(5)   sqrt(3)  sqrt(5)   sqrt(3) ]
632                      [ ------- + -------  ------- - ------- ]
633                      [    2         2        2         2    ]
634          (%o3)       [                                      ]
635                      [ sqrt(5)   sqrt(3)  sqrt(5)   sqrt(3) ]
636                      [ ------- - -------  ------- + ------- ]
637                      [    2         2        2         2    ]
638          (%i4) eigens_by_jacobi (M);
639          The largest percent change was 0.1454972243679
640          The largest percent change was 0.0
641          number of sweeps: 2
642          number of rotations: 1
643          (%o4) [[1.732050807568877, 2.23606797749979],
644                                  [  0.70710678118655   0.70710678118655 ]
645                                  [                                      ]]
646                                  [ - 0.70710678118655  0.70710678118655 ]
647          (%i5) float ([[sqrt(3), sqrt(5)], S]);
648          (%o5) [[1.732050807568877, 2.23606797749979],
649                                  [  0.70710678118655   0.70710678118655 ]
650                                  [                                      ]]
651                                  [ - 0.70710678118655  0.70710678118655 ]
652          (%i6) eigens_by_jacobi (M, bigfloatfield);
653          The largest percent change was 1.454972243679028b-1
654          The largest percent change was 0.0b0
655          number of sweeps: 2
656          number of rotations: 1
657          (%o6) [[1.732050807568877b0, 2.23606797749979b0],
658                          [  7.071067811865475b-1   7.071067811865475b-1 ]
659                          [                                              ]]
660                          [ - 7.071067811865475b-1  7.071067811865475b-1 ]
661
662 -- Function: get_lu_factors (<x>)
663
664     When '<x> = lu_factor (<A>)', then 'get_lu_factors' returns a list
665     of the form '[P, L, U]', where <P> is a permutation matrix, <L> is
666     lower triangular with ones on the diagonal, and <U> is upper
667     triangular, and '<A> = <P> <L> <U>'.
668
669 -- Function: hankel (<col>)
670 -- Function: hankel (<col>, <row>)
671
672     Return a Hankel matrix <H>.  The first column of <H> is <col>;
673     except for the first entry, the last row of <H> is <row>.  The
674     default for <row> is the zero vector with the same length as <col>.
675
676 -- Function: hessian (<f>, <x>)
677
678     Returns the Hessian matrix of <f> with respect to the list of
679     variables <x>.  The '(i, j)'-th element of the Hessian matrix is
680     'diff(<f>, <x>[i], 1, <x>[j], 1)'.
681
682     Examples:
683
684          (%i1) hessian (x * sin (y), [x, y]);
685                               [   0       cos(y)   ]
686          (%o1)                [                    ]
687                               [ cos(y)  - x sin(y) ]
688          (%i2) depends (F, [a, b]);
689          (%o2)                       [F(a, b)]
690          (%i3) hessian (F, [a, b]);
691                                  [   2      2   ]
692                                  [  d F    d F  ]
693                                  [  ---   ----- ]
694                                  [    2   da db ]
695                                  [  da          ]
696          (%o3)                   [              ]
697                                  [   2      2   ]
698                                  [  d F    d F  ]
699                                  [ -----   ---  ]
700                                  [ da db     2  ]
701                                  [         db   ]
702
703 -- Function: hilbert_matrix (<n>)
704
705     Return the <n> by <n> Hilbert matrix.  When <n> isn't a positive
706     integer, signal an error.
707
708 -- Function: identfor (<M>)
709 -- Function: identfor (<M>, <fld>)
710
711     Return an identity matrix that has the same shape as the matrix
712     <M>.  The diagonal entries of the identity matrix are the
713     multiplicative identity of the field <fld>; the default for <fld>
714     is <generalring>.
715
716     The first argument <M> should be a square matrix or a non-matrix.
717     When <M> is a matrix, each entry of <M> can be a square matrix -
718     thus <M> can be a blocked Maxima matrix.  The matrix can be blocked
719     to any (finite) depth.
720
721     See also 'zerofor'
722
723 -- Function: invert_by_lu (<M>, <(rng generalring)>)
724
725     Invert a matrix <M> by using the LU factorization.  The LU
726     factorization is done using the ring <rng>.
727
728 -- Function: jacobian (<f>, <x>)
729
730     Returns the Jacobian matrix of the list of functions <f> with
731     respect to the list of variables <x>.  The '(i, j)'-th element of
732     the Jacobian matrix is 'diff(<f>[i], <x>[j])'.
733
734     Examples:
735
736          (%i1) jacobian ([sin (u - v), sin (u * v)], [u, v]);
737                            [ cos(v - u)  - cos(v - u) ]
738          (%o1)             [                          ]
739                            [ v cos(u v)   u cos(u v)  ]
740          (%i2) depends ([F, G], [y, z]);
741          (%o2)                  [F(y, z), G(y, z)]
742          (%i3) jacobian ([F, G], [y, z]);
743                                     [ dF  dF ]
744                                     [ --  -- ]
745                                     [ dy  dz ]
746          (%o3)                      [        ]
747                                     [ dG  dG ]
748                                     [ --  -- ]
749                                     [ dy  dz ]
750
751 -- Function: kronecker_product (<A>, <B>)
752
753     Return the Kronecker product of the matrices <A> and <B>.
754
755 -- Function: listp (<e>, <p>)
756 -- Function: listp (<e>)
757
758     Given an optional argument <p>, return 'true' if <e> is a Maxima
759     list and <p> evaluates to 'true' for every list element.  When
760     'listp' is not given the optional argument, return 'true' if <e> is
761     a Maxima list.  In all other cases, return 'false'.
762
763 -- Function: locate_matrix_entry (<M>, <r_1>, <c_1>, <r_2>, <c_2>, <f>,
764          <rel>)
765
766     The first argument must be a matrix; the arguments <r_1> through
767     <c_2> determine a sub-matrix of <M> that consists of rows <r_1>
768     through <r_2> and columns <c_1> through <c_2>.
769
770     Find a entry in the sub-matrix <M> that satisfies some property.
771     Three cases:
772
773     (1) '<rel> = 'bool' and <f> a predicate:
774
775     Scan the sub-matrix from left to right then top to bottom, and
776     return the index of the first entry that satisfies the predicate
777     <f>.  If no matrix entry satisfies <f>, return 'false'.
778
779     (2) '<rel> = 'max' and <f> real-valued:
780
781     Scan the sub-matrix looking for an entry that maximizes <f>.
782     Return the index of a maximizing entry.
783
784     (3) '<rel> = 'min' and <f> real-valued:
785
786     Scan the sub-matrix looking for an entry that minimizes <f>.
787     Return the index of a minimizing entry.
788
789 -- Function: lu_backsub (<M>, <b>)
790
791     When '<M> = lu_factor (<A>, <field>)', then 'lu_backsub (<M>, <b>)'
792     solves the linear system '<A> <x> = <b>'.
793
794 -- Function: lu_factor (<M>, <field>)
795
796     Return a list of the form '[<LU>, <perm>, <fld>]', or '[<LU>,
797     <perm>, <fld>, <lower-cnd> <upper-cnd>]', where
798
799     (1) The matrix <LU> contains the factorization of <M> in a packed
800     form.  Packed form means three things: First, the rows of <LU> are
801     permuted according to the list <perm>.  If, for example, <perm> is
802     the list '[3,2,1]', the actual first row of the <LU> factorization
803     is the third row of the matrix <LU>.  Second, the lower triangular
804     factor of m is the lower triangular part of <LU> with the diagonal
805     entries replaced by all ones.  Third, the upper triangular factor
806     of <M> is the upper triangular part of <LU>.
807
808     (2) When the field is either 'floatfield' or 'complexfield', the
809     numbers <lower-cnd> and <upper-cnd> are lower and upper bounds for
810     the infinity norm condition number of <M>.  For all fields, the
811     condition number might not be estimated; for such fields,
812     'lu_factor' returns a two item list.  Both the lower and upper
813     bounds can differ from their true values by arbitrarily large
814     factors.  (See also 'mat_cond'.)
815
816     The argument <M> must be a square matrix.
817
818     The optional argument <fld> must be a symbol that determines a ring
819     or field.  The pre-defined fields and rings are:
820
821     (a) 'generalring' - the ring of Maxima expressions, (b)
822     'floatfield' - the field of floating point numbers of the type
823     double, (c) 'complexfield' - the field of complex floating point
824     numbers of the type double, (d) 'crering' - the ring of Maxima CRE
825     expressions, (e) 'rationalfield' - the field of rational numbers,
826     (f) 'runningerror' - track the all floating point rounding errors,
827     (g) 'noncommutingring' - the ring of Maxima expressions where
828     multiplication is the non-commutative dot operator.
829
830     When the field is 'floatfield', 'complexfield', or 'runningerror',
831     the algorithm uses partial pivoting; for all other fields, rows are
832     switched only when needed to avoid a zero pivot.
833
834     Floating point addition arithmetic isn't associative, so the
835     meaning of 'field' differs from the mathematical definition.
836
837     A member of the field 'runningerror' is a two member Maxima list of
838     the form '[x,n]',where <x> is a floating point number and 'n' is an
839     integer.  The relative difference between the 'true' value of 'x'
840     and 'x' is approximately bounded by the machine epsilon times 'n'.
841     The running error bound drops some terms that of the order the
842     square of the machine epsilon.
843
844     There is no user-interface for defining a new field.  A user that
845     is familiar with Common Lisp should be able to define a new field.
846     To do this, a user must define functions for the arithmetic
847     operations and functions for converting from the field
848     representation to Maxima and back.  Additionally, for ordered
849     fields (where partial pivoting will be used), a user must define
850     functions for the magnitude and for comparing field members.  After
851     that all that remains is to define a Common Lisp structure 'mring'.
852     The file 'mring' has many examples.
853
854     To compute the factorization, the first task is to convert each
855     matrix entry to a member of the indicated field.  When conversion
856     isn't possible, the factorization halts with an error message.
857     Members of the field needn't be Maxima expressions.  Members of the
858     'complexfield', for example, are Common Lisp complex numbers.  Thus
859     after computing the factorization, the matrix entries must be
860     converted to Maxima expressions.
861
862     See also 'get_lu_factors'.
863
864     Examples:
865
866          (%i1) w[i,j] := random (1.0) + %i * random (1.0);
867          (%o1)          w     := random(1.) + %i random(1.)
868                          i, j
869          (%i2) showtime : true$
870          Evaluation took 0.00 seconds (0.00 elapsed)
871          (%i3) M : genmatrix (w, 100, 100)$
872          Evaluation took 7.40 seconds (8.23 elapsed)
873          (%i4) lu_factor (M, complexfield)$
874          Evaluation took 28.71 seconds (35.00 elapsed)
875          (%i5) lu_factor (M, generalring)$
876          Evaluation took 109.24 seconds (152.10 elapsed)
877          (%i6) showtime : false$
878
879          (%i7) M : matrix ([1 - z, 3], [3, 8 - z]);
880                                  [ 1 - z    3   ]
881          (%o7)                   [              ]
882                                  [   3    8 - z ]
883          (%i8) lu_factor (M, generalring);
884                    [ 1 - z         3        ]
885                    [                        ]
886          (%o8)    [[   3            9       ], [1, 2], generalring]
887                    [ -----  - z - ----- + 8 ]
888                    [ 1 - z        1 - z     ]
889          (%i9) get_lu_factors (%);
890                            [   1    0 ]  [ 1 - z         3        ]
891                  [ 1  0 ]  [          ]  [                        ]
892          (%o9)  [[      ], [   3      ], [                9       ]]
893                  [ 0  1 ]  [ -----  1 ]  [   0    - z - ----- + 8 ]
894                            [ 1 - z    ]  [              1 - z     ]
895          (%i10) %[1] . %[2] . %[3];
896                                  [ 1 - z    3   ]
897          (%o10)                  [              ]
898                                  [   3    8 - z ]
899
900 -- Function: mat_cond (<M>, 1)
901 -- Function: mat_cond (<M>, inf)
902
903     Return the <p>-norm matrix condition number of the matrix <m>.  The
904     allowed values for <p> are 1 and <inf>.  This function uses the LU
905     factorization to invert the matrix <m>.  Thus the running time for
906     'mat_cond' is proportional to the cube of the matrix size;
907     'lu_factor' determines lower and upper bounds for the infinity norm
908     condition number in time proportional to the square of the matrix
909     size.
910
911 -- Function: mat_norm (<M>, 1)
912 -- Function: mat_norm (<M>, inf)
913 -- Function: mat_norm (<M>, frobenius)
914
915     Return the matrix <p>-norm of the matrix <M>.  The allowed values
916     for <p> are 1, 'inf', and 'frobenius' (the Frobenius matrix norm).
917     The matrix <M> should be an unblocked matrix.
918
919 -- Function: matrixp (<e>, <p>)
920 -- Function: matrixp (<e>)
921
922     Given an optional argument <p>, return 'true' if <e> is a matrix
923     and <p> evaluates to 'true' for every matrix element.  When
924     'matrixp' is not given an optional argument, return 'true' if 'e'
925     is a matrix.  In all other cases, return 'false'.
926
927     See also 'blockmatrixp'
928
929 -- Function: matrix_size (<M>)
930
931     Return a two member list that gives the number of rows and columns,
932     respectively of the matrix <M>.
933
934 -- Function: mat_fullunblocker (<M>)
935
936     If <M> is a block matrix, unblock the matrix to all levels.  If <M>
937     is a matrix, return <M>; otherwise, signal an error.
938
939 -- Function: mat_trace (<M>)
940
941     Return the trace of the matrix <M>.  If <M> isn't a matrix, return
942     a noun form.  When <M> is a block matrix, 'mat_trace(M)' returns
943     the same value as does 'mat_trace(mat_unblocker(m))'.
944
945 -- Function: mat_unblocker (<M>)
946
947     If <M> is a block matrix, unblock <M> one level.  If <M> is a
948     matrix, 'mat_unblocker (M)' returns <M>; otherwise, signal an
949     error.
950
951     Thus if each entry of <M> is matrix, 'mat_unblocker (M)' returns an
952     unblocked matrix, but if each entry of <M> is a block matrix,
953     'mat_unblocker (M)' returns a block matrix with one less level of
954     blocking.
955
956     If you use block matrices, most likely you'll want to set
957     'matrix_element_mult' to '"."' and 'matrix_element_transpose' to
958     ''transpose'.  See also 'mat_fullunblocker'.
959
960     Example:
961
962          (%i1) A : matrix ([1, 2], [3, 4]);
963                                      [ 1  2 ]
964          (%o1)                       [      ]
965                                      [ 3  4 ]
966          (%i2) B : matrix ([7, 8], [9, 10]);
967                                      [ 7  8  ]
968          (%o2)                       [       ]
969                                      [ 9  10 ]
970          (%i3) matrix ([A, B]);
971                               [ [ 1  2 ]  [ 7  8  ] ]
972          (%o3)                [ [      ]  [       ] ]
973                               [ [ 3  4 ]  [ 9  10 ] ]
974          (%i4) mat_unblocker (%);
975                                   [ 1  2  7  8  ]
976          (%o4)                    [             ]
977                                   [ 3  4  9  10 ]
978
979 -- Function: nullspace (<M>)
980
981     If <M> is a matrix, return 'span (v_1, ..., v_n)', where the set
982     '{v_1, ..., v_n}' is a basis for the nullspace of <M>.  The span of
983     the empty set is '{0}'.  Thus, when the nullspace has only one
984     member, return 'span ()'.
985
986 -- Function: nullity (<M>)
987
988     If <M> is a matrix, return the dimension of the nullspace of <M>.
989
990 -- Function: orthogonal_complement (<v_1>, ..., <v_n>)
991
992     Return 'span (u_1, ..., u_m)', where the set '{u_1, ..., u_m}' is a
993     basis for the orthogonal complement of the set '(v_1, ..., v_n)'.
994
995     Each vector <v_1> through <v_n> must be a column vector.
996
997 -- Function: polynomialp (<p>, <L>, <coeffp>, <exponp>)
998 -- Function: polynomialp (<p>, <L>, <coeffp>)
999 -- Function: polynomialp (<p>, <L>)
1000
1001     Return 'true' if <p> is a polynomial in the variables in the list
1002     <L>.  The predicate <coeffp> must evaluate to 'true' for each
1003     coefficient, and the predicate <exponp> must evaluate to 'true' for
1004     all exponents of the variables in <L>.  If you want to use a
1005     non-default value for <exponp>, you must supply <coeffp> with a
1006     value even if you want to use the default for <coeffp>.
1007
1008     The command 'polynomialp (<p>, <L>, <coeffp>)' is equivalent to
1009     'polynomialp (<p>, <L>, <coeffp>, 'nonnegintegerp)' and
1010     'polynomialp (<p>, <L>)' is equivalent to 'polynomialp (<p>, L<,>
1011     'constantp, 'nonnegintegerp)'.
1012
1013     The polynomial needn't be expanded:
1014
1015          (%i1) polynomialp ((x + 1)*(x + 2), [x]);
1016          (%o1)                         true
1017          (%i2) polynomialp ((x + 1)*(x + 2)^a, [x]);
1018          (%o2)                         false
1019
1020     An example using non-default values for coeffp and exponp:
1021
1022          (%i1) polynomialp ((x + 1)*(x + 2)^(3/2), [x], numberp, numberp);
1023          (%o1)                         true
1024          (%i2) polynomialp ((x^(1/2) + 1)*(x + 2)^(3/2), [x], numberp,
1025                                                                  numberp);
1026          (%o2)                         true
1027
1028     Polynomials with two variables:
1029
1030          (%i1) polynomialp (x^2 + 5*x*y + y^2, [x]);
1031          (%o1)                         false
1032          (%i2) polynomialp (x^2 + 5*x*y + y^2, [x, y]);
1033          (%o2)                         true
1034
1035 -- Function: polytocompanion (<p>, <x>)
1036
1037     If <p> is a polynomial in <x>, return the companion matrix of <p>.
1038     For a monic polynomial <p> of degree <n>, we have '<p> = (-1)^<n>
1039     charpoly (polytocompanion (<p>, <x>))'.
1040
1041     When <p> isn't a polynomial in <x>, signal an error.
1042
1043 -- Function: ptriangularize (<M>, <v>)
1044
1045     If <M> is a matrix with each entry a polynomial in <v>, return a
1046     matrix <M2> such that
1047
1048     (1) <M2> is upper triangular,
1049
1050     (2) '<M2> = <E_n> ... <E_1> <M>', where <E_1> through <E_n> are
1051     elementary matrices whose entries are polynomials in <v>,
1052
1053     (3) '|det (<M>)| = |det (<M2>)|',
1054
1055     Note: This function doesn't check that every entry is a polynomial
1056     in <v>.
1057
1058 -- Function: rowop (<M>, <i>, <j>, <theta>)
1059
1060     If <M> is a matrix, return the matrix that results from doing the
1061     row operation 'R_i <- R_i - theta * R_j'.  If <M> doesn't have a
1062     row <i> or <j>, signal an error.
1063
1064 -- Function: rank (<M>)
1065
1066     Return the rank of that matrix <M>.  The rank is the dimension of
1067     the column space.
1068
1069     Example:
1070
1071          (%i1) rank(matrix([1,2],[2,4]));
1072          (%o1)                                  1
1073          (%i2) rank(matrix([1,b],[c,d]));
1074          Proviso:  {d - b c # 0}
1075          (%o2)                                  2
1076
1077 -- Function: rowswap (<M>, <i>, <j>)
1078
1079     If <M> is a matrix, swap rows <i> and <j>.  If <M> doesn't have a
1080     row <i> or <j>, signal an error.
1081
1082 -- Function: toeplitz (<col>)
1083 -- Function: toeplitz (<col>, <row>)
1084
1085     Return a Toeplitz matrix <T>.  The first first column of <T> is
1086     <col>; except for the first entry, the first row of <T> is <row>.
1087     The default for <row> is complex conjugate of <col>.
1088
1089     Example:
1090
1091          (%i1)  toeplitz([1,2,3],[x,y,z]);
1092
1093                                            [ 1  y  z ]
1094                                            [         ]
1095          (%o1)                             [ 2  1  y ]
1096                                            [         ]
1097                                            [ 3  2  1 ]
1098          (%i2)  toeplitz([1,1+%i]);
1099
1100                                        [   1     1 - %I ]
1101          (%o2)                         [                ]
1102                                        [ %I + 1    1    ]
1103
1104 -- Function: vandermonde_matrix ([<x_1>, ..., <x_n>])
1105
1106     Return a <n> by <n> matrix whose <i>-th row is '[1, <x_i>, <x_i>^2,
1107     ... <x_i>^(<n>-1)]'.
1108
1109 -- Function: zerofor (<M>)
1110 -- Function: zerofor (<M>, <fld>)
1111
1112     Return a zero matrix that has the same shape as the matrix <M>.
1113     Every entry of the zero matrix is the additive identity of the
1114     field <fld>; the default for <fld> is <generalring>.
1115
1116     The first argument <M> should be a square matrix or a non-matrix.
1117     When <M> is a matrix, each entry of <M> can be a square matrix -
1118     thus <M> can be a blocked Maxima matrix.  The matrix can be blocked
1119     to any (finite) depth.
1120
1121     See also 'identfor'
1122
1123 -- Function: zeromatrixp (<M>)
1124
1125     If <M> is not a block matrix, return 'true' if 'is (equal (<e>,
1126     0))' is true for each element <e> of the matrix <M>.  If <M> is a
1127     block matrix, return 'true' if 'zeromatrixp' evaluates to 'true'
1128     for each element of <e>.
1129
1130
1131File: maxima.info,  Node: lsquares,  Next: makeOrders,  Prev: linearalgebra,  Up: Top
1132
113359 lsquares
1134***********
1135
1136* Menu:
1137
1138* Introduction to lsquares::
1139* Functions and Variables for lsquares::
1140
1141
1142File: maxima.info,  Node: Introduction to lsquares,  Next: Functions and Variables for lsquares,  Prev: lsquares,  Up: lsquares
1143
114459.1 Introduction to lsquares
1145=============================
1146
1147'lsquares' is a collection of functions to implement the method of least
1148squares to estimate parameters for a model from numerical data.
1149
1150
1151File: maxima.info,  Node: Functions and Variables for lsquares,  Prev: Introduction to lsquares,  Up: lsquares
1152
115359.2 Functions and Variables for lsquares
1154=========================================
1155
1156 -- Function: lsquares_estimates (<D>, <x>, <e>, <a>)
1157 -- Function: lsquares_estimates (<D>, <x>, <e>, <a>, initial = <L>, tol
1158          = <t>)
1159
1160     Estimate parameters <a> to best fit the equation <e> in the
1161     variables <x> and <a> to the data <D>, as determined by the method
1162     of least squares.  'lsquares_estimates' first seeks an exact
1163     solution, and if that fails, then seeks an approximate solution.
1164
1165     The return value is a list of lists of equations of the form '[a =
1166     ..., b = ..., c = ...]'.  Each element of the list is a distinct,
1167     equivalent minimum of the mean square error.
1168
1169     The data <D> must be a matrix.  Each row is one datum (which may be
1170     called a 'record' or 'case' in some contexts), and each column
1171     contains the values of one variable across all data.  The list of
1172     variables <x> gives a name for each column of <D>, even the columns
1173     which do not enter the analysis.  The list of parameters <a> gives
1174     the names of the parameters for which estimates are sought.  The
1175     equation <e> is an expression or equation in the variables <x> and
1176     <a>; if <e> is not an equation, it is treated the same as '<e> =
1177     0'.
1178
1179     Additional arguments to 'lsquares_estimates' are specified as
1180     equations and passed on verbatim to the function 'lbfgs' which is
1181     called to find estimates by a numerical method when an exact result
1182     is not found.
1183
1184     If some exact solution can be found (via 'solve'), the data <D> may
1185     contain non-numeric values.  However, if no exact solution is
1186     found, each element of <D> must have a numeric value.  This
1187     includes numeric constants such as '%pi' and '%e' as well as
1188     literal numbers (integers, rationals, ordinary floats, and
1189     bigfloats).  Numerical calculations are carried out with ordinary
1190     floating-point arithmetic, so all other kinds of numbers are
1191     converted to ordinary floats for calculations.
1192
1193     'load(lsquares)' loads this function.
1194
1195     See also
1196     'lsquares_estimates_exact', 'lsquares_estimates_approximate',
1197     'lsquares_mse', 'lsquares_residuals', and 'lsquares_residual_mse'.
1198
1199     Examples:
1200
1201     A problem for which an exact solution is found.
1202
1203          (%i1) load (lsquares)$
1204          (%i2) M : matrix (
1205                  [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
1206                                            [ 1  1  1 ]
1207                                            [         ]
1208                                            [ 3       ]
1209                                            [ -  1  2 ]
1210                                            [ 2       ]
1211                                            [         ]
1212          (%o2)                             [ 9       ]
1213                                            [ -  2  1 ]
1214                                            [ 4       ]
1215                                            [         ]
1216                                            [ 3  2  2 ]
1217                                            [         ]
1218                                            [ 2  2  1 ]
1219          (%i3) lsquares_estimates (
1220                   M, [z,x,y], (z+D)^2 = A*x+B*y+C, [A,B,C,D]);
1221                                   59        27      10921        107
1222          (%o3)            [[A = - --, B = - --, C = -----, D = - ---]]
1223                                   16        16      1024         32
1224
1225     A problem for which no exact solution is found, so
1226     'lsquares_estimates' resorts to numerical approximation.
1227
1228          (%i1) load (lsquares)$
1229          (%i2) M : matrix ([1, 1], [2, 7/4], [3, 11/4], [4, 13/4]);
1230                                             [ 1  1  ]
1231                                             [       ]
1232                                             [    7  ]
1233                                             [ 2  -  ]
1234                                             [    4  ]
1235                                             [       ]
1236          (%o2)                              [    11 ]
1237                                             [ 3  -- ]
1238                                             [    4  ]
1239                                             [       ]
1240                                             [    13 ]
1241                                             [ 4  -- ]
1242                                             [    4  ]
1243          (%i3) lsquares_estimates (
1244            M, [x,y], y=a*x^b+c, [a,b,c], initial=[3,3,3], iprint=[-1,0]);
1245          (%o3) [[a = 1.387365874920637, b = .7110956639593767,
1246                                                  c = - .4142705622439105]]
1247
1248 -- Function: lsquares_estimates_exact (<MSE>, <a>)
1249
1250     Estimate parameters <a> to minimize the mean square error <MSE>, by
1251     constructing a system of equations and attempting to solve them
1252     symbolically via 'solve'.  The mean square error is an expression
1253     in the parameters <a>, such as that returned by 'lsquares_mse'.
1254
1255     The return value is a list of lists of equations of the form '[a =
1256     ..., b = ..., c = ...]'.  The return value may contain zero, one,
1257     or two or more elements.  If two or more elements are returned,
1258     each represents a distinct, equivalent minimum of the mean square
1259     error.
1260
1261     See also 'lsquares_estimates', 'lsquares_estimates_approximate',
1262     'lsquares_mse', 'lsquares_residuals', and 'lsquares_residual_mse'.
1263
1264     Example:
1265
1266          (%i1) load (lsquares)$
1267          (%i2) M : matrix (
1268                   [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
1269                                     [ 1  1  1 ]
1270                                     [         ]
1271                                     [ 3       ]
1272                                     [ -  1  2 ]
1273                                     [ 2       ]
1274                                     [         ]
1275          (%o2)                      [ 9       ]
1276                                     [ -  2  1 ]
1277                                     [ 4       ]
1278                                     [         ]
1279                                     [ 3  2  2 ]
1280                                     [         ]
1281                                     [ 2  2  1 ]
1282          (%i3) mse : lsquares_mse (M, [z, x, y], (z + D)^2 = A*x + B*y + C);
1283                     5
1284                    ====
1285                    \                 2                         2
1286                     >    ((D + M    )  - C - M     B - M     A)
1287                    /            i, 1          i, 3      i, 2
1288                    ====
1289                    i = 1
1290          (%o3)     ---------------------------------------------
1291                                          5
1292          (%i4) lsquares_estimates_exact (mse, [A, B, C, D]);
1293                            59        27      10921        107
1294          (%o4)     [[A = - --, B = - --, C = -----, D = - ---]]
1295                            16        16      1024         32
1296
1297 -- Function: lsquares_estimates_approximate (<MSE>, <a>, initial = <L>,
1298          tol = <t>)
1299
1300     Estimate parameters <a> to minimize the mean square error <MSE>,
1301     via the numerical minimization function 'lbfgs'.  The mean square
1302     error is an expression in the parameters <a>, such as that returned
1303     by 'lsquares_mse'.
1304
1305     The solution returned by 'lsquares_estimates_approximate' is a
1306     local (perhaps global) minimum of the mean square error.  For
1307     consistency with 'lsquares_estimates_exact', the return value is a
1308     nested list which contains one element, namely a list of equations
1309     of the form '[a = ..., b = ..., c = ...]'.
1310
1311     Additional arguments to 'lsquares_estimates_approximate' are
1312     specified as equations and passed on verbatim to the function
1313     'lbfgs'.
1314
1315     <MSE> must evaluate to a number when the parameters are assigned
1316     numeric values.  This requires that the data from which <MSE> was
1317     constructed comprise only numeric constants such as '%pi' and '%e'
1318     and literal numbers (integers, rationals, ordinary floats, and
1319     bigfloats).  Numerical calculations are carried out with ordinary
1320     floating-point arithmetic, so all other kinds of numbers are
1321     converted to ordinary floats for calculations.
1322
1323     'load(lsquares)' loads this function.
1324
1325     See also
1326     'lsquares_estimates', 'lsquares_estimates_exact',
1327     'lsquares_mse', 'lsquares_residuals', and 'lsquares_residual_mse'.
1328
1329     Example:
1330
1331          (%i1) load (lsquares)$
1332          (%i2) M : matrix (
1333                   [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
1334                                     [ 1  1  1 ]
1335                                     [         ]
1336                                     [ 3       ]
1337                                     [ -  1  2 ]
1338                                     [ 2       ]
1339                                     [         ]
1340          (%o2)                      [ 9       ]
1341                                     [ -  2  1 ]
1342                                     [ 4       ]
1343                                     [         ]
1344                                     [ 3  2  2 ]
1345                                     [         ]
1346                                     [ 2  2  1 ]
1347          (%i3) mse : lsquares_mse (M, [z, x, y], (z + D)^2 = A*x + B*y + C);
1348                     5
1349                    ====
1350                    \                 2                         2
1351                     >    ((D + M    )  - C - M     B - M     A)
1352                    /            i, 1          i, 3      i, 2
1353                    ====
1354                    i = 1
1355          (%o3)     ---------------------------------------------
1356                                          5
1357          (%i4) lsquares_estimates_approximate (
1358                        mse, [A, B, C, D], iprint = [-1, 0]);
1359          (%o4) [[A = - 3.67850494740174, B = - 1.683070351177813,
1360                           C = 10.63469950148635, D = - 3.340357993175206]]
1361
1362 -- Function: lsquares_mse (<D>, <x>, <e>)
1363
1364     Returns the mean square error (MSE), a summation expression, for
1365     the equation <e> in the variables <x>, with data <D>.
1366
1367     The MSE is defined as:
1368
1369                              n
1370                             ====
1371                         1   \                        2
1372                         -    >    (lhs(e ) - rhs(e ))
1373                         n   /           i         i
1374                             ====
1375                             i = 1
1376
1377     where <n> is the number of data and '<e>[i]' is the equation <e>
1378     evaluated with the variables in <x> assigned values from the 'i'-th
1379     datum, '<D>[i]'.
1380
1381     'load(lsquares)' loads this function.
1382
1383     Example:
1384
1385          (%i1) load (lsquares)$
1386          (%i2) M : matrix (
1387                   [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
1388                                     [ 1  1  1 ]
1389                                     [         ]
1390                                     [ 3       ]
1391                                     [ -  1  2 ]
1392                                     [ 2       ]
1393                                     [         ]
1394          (%o2)                      [ 9       ]
1395                                     [ -  2  1 ]
1396                                     [ 4       ]
1397                                     [         ]
1398                                     [ 3  2  2 ]
1399                                     [         ]
1400                                     [ 2  2  1 ]
1401          (%i3) mse : lsquares_mse (M, [z, x, y], (z + D)^2 = A*x + B*y + C);
1402                     5
1403                    ====
1404                    \                 2                         2
1405                     >    ((D + M    )  - C - M     B - M     A)
1406                    /            i, 1          i, 3      i, 2
1407                    ====
1408                    i = 1
1409          (%o3)     ---------------------------------------------
1410                                          5
1411          (%i4) diff (mse, D);
1412                   5
1413                  ====
1414                  \                             2
1415                4  >    (D + M    ) ((D + M    )  - C - M     B - M     A)
1416                  /           i, 1         i, 1          i, 3      i, 2
1417                  ====
1418                  i = 1
1419          (%o4) ----------------------------------------------------------
1420                                            5
1421          (%i5) ''mse, nouns;
1422                         2                 2         9 2               2
1423          (%o5) (((D + 3)  - C - 2 B - 2 A)  + ((D + -)  - C - B - 2 A)
1424                                                     4
1425                     2               2         3 2               2
1426           + ((D + 2)  - C - B - 2 A)  + ((D + -)  - C - 2 B - A)
1427                                               2
1428                     2             2
1429           + ((D + 1)  - C - B - A) )/5
1430
1431 -- Function: lsquares_residuals (<D>, <x>, <e>, <a>)
1432
1433     Returns the residuals for the equation <e> with specified
1434     parameters <a> and data <D>.
1435
1436     <D> is a matrix, <x> is a list of variables, <e> is an equation or
1437     general expression; if not an equation, <e> is treated as if it
1438     were '<e> = 0'.  <a> is a list of equations which specify values
1439     for any free parameters in <e> aside from <x>.
1440
1441     The residuals are defined as:
1442
1443                                  lhs(e ) - rhs(e )
1444                                       i         i
1445
1446     where '<e>[i]' is the equation <e> evaluated with the variables in
1447     <x> assigned values from the 'i'-th datum, '<D>[i]', and assigning
1448     any remaining free variables from <a>.
1449
1450     'load(lsquares)' loads this function.
1451
1452     Example:
1453
1454          (%i1) load (lsquares)$
1455          (%i2) M : matrix (
1456                   [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
1457                                            [ 1  1  1 ]
1458                                            [         ]
1459                                            [ 3       ]
1460                                            [ -  1  2 ]
1461                                            [ 2       ]
1462                                            [         ]
1463          (%o2)                             [ 9       ]
1464                                            [ -  2  1 ]
1465                                            [ 4       ]
1466                                            [         ]
1467                                            [ 3  2  2 ]
1468                                            [         ]
1469                                            [ 2  2  1 ]
1470          (%i3) a : lsquares_estimates (
1471                    M, [z,x,y], (z+D)^2 = A*x+B*y+C, [A,B,C,D]);
1472                                   59        27      10921        107
1473          (%o3)            [[A = - --, B = - --, C = -----, D = - ---]]
1474                                   16        16      1024         32
1475          (%i4) lsquares_residuals (
1476                    M, [z,x,y], (z+D)^2 = A*x+B*y+C, first(a));
1477                                      13    13    13  13  13
1478          (%o4)                      [--, - --, - --, --, --]
1479                                      64    64    32  64  64
1480
1481 -- Function: lsquares_residual_mse (<D>, <x>, <e>, <a>)
1482
1483     Returns the residual mean square error (MSE) for the equation <e>
1484     with specified parameters <a> and data <D>.
1485
1486     The residual MSE is defined as:
1487
1488                              n
1489                             ====
1490                         1   \                        2
1491                         -    >    (lhs(e ) - rhs(e ))
1492                         n   /           i         i
1493                             ====
1494                             i = 1
1495
1496     where '<e>[i]' is the equation <e> evaluated with the variables in
1497     <x> assigned values from the 'i'-th datum, '<D>[i]', and assigning
1498     any remaining free variables from <a>.
1499
1500     'load(lsquares)' loads this function.
1501
1502     Example:
1503
1504          (%i1) load (lsquares)$
1505          (%i2) M : matrix (
1506                   [1,1,1], [3/2,1,2], [9/4,2,1], [3,2,2], [2,2,1]);
1507                                     [ 1  1  1 ]
1508                                     [         ]
1509                                     [ 3       ]
1510                                     [ -  1  2 ]
1511                                     [ 2       ]
1512                                     [         ]
1513          (%o2)                      [ 9       ]
1514                                     [ -  2  1 ]
1515                                     [ 4       ]
1516                                     [         ]
1517                                     [ 3  2  2 ]
1518                                     [         ]
1519                                     [ 2  2  1 ]
1520          (%i3) a : lsquares_estimates (
1521                       M, [z,x,y], (z+D)^2 = A*x+B*y+C, [A,B,C,D]);
1522
1523                            59        27      10921        107
1524          (%o3)     [[A = - --, B = - --, C = -----, D = - ---]]
1525                            16        16      1024         32
1526          (%i4) lsquares_residual_mse (
1527                       M, [z,x,y], (z + D)^2 = A*x + B*y + C, first (a));
1528                                        169
1529          (%o4)                         ----
1530                                        2560
1531
1532 -- Function: plsquares (<Mat>,<VarList>,<depvars>)
1533 -- Function: plsquares (<Mat>,<VarList>,<depvars>,<maxexpon>)
1534 -- Function: plsquares
1535          (<Mat>,<VarList>,<depvars>,<maxexpon>,<maxdegree>)
1536     Multivariable polynomial adjustment of a data table by the "least
1537     squares" method.  <Mat> is a matrix containing the data, <VarList>
1538     is a list of variable names (one for each Mat column, but use "-"
1539     instead of varnames to ignore Mat columns), <depvars> is the name
1540     of a dependent variable or a list with one or more names of
1541     dependent variables (which names should be in <VarList>),
1542     <maxexpon> is the optional maximum exponent for each independent
1543     variable (1 by default), and <maxdegree> is the optional maximum
1544     polynomial degree (<maxexpon> by default); note that the sum of
1545     exponents of each term must be equal or smaller than <maxdegree>,
1546     and if 'maxdgree = 0' then no limit is applied.
1547
1548     If <depvars> is the name of a dependent variable (not in a list),
1549     'plsquares' returns the adjusted polynomial.  If <depvars> is a
1550     list of one or more dependent variables, 'plsquares' returns a list
1551     with the adjusted polynomial(s).  The Coefficients of Determination
1552     are displayed in order to inform about the goodness of fit, which
1553     ranges from 0 (no correlation) to 1 (exact correlation).  These
1554     values are also stored in the global variable <DETCOEF> (a list if
1555     <depvars> is a list).
1556
1557     A simple example of multivariable linear adjustment:
1558          (%i1) load("plsquares")$
1559
1560          (%i2) plsquares(matrix([1,2,0],[3,5,4],[4,7,9],[5,8,10]),
1561                          [x,y,z],z);
1562               Determination Coefficient for z = .9897039897039897
1563                                 11 y - 9 x - 14
1564          (%o2)              z = ---------------
1565                                        3
1566
1567     The same example without degree restrictions:
1568          (%i3) plsquares(matrix([1,2,0],[3,5,4],[4,7,9],[5,8,10]),
1569                          [x,y,z],z,1,0);
1570               Determination Coefficient for z = 1.0
1571                              x y + 23 y - 29 x - 19
1572          (%o3)           z = ----------------------
1573                                        6
1574
1575     How many diagonals does a N-sides polygon have?  What polynomial
1576     degree should be used?
1577          (%i4) plsquares(matrix([3,0],[4,2],[5,5],[6,9],[7,14],[8,20]),
1578                          [N,diagonals],diagonals,5);
1579               Determination Coefficient for diagonals = 1.0
1580                                          2
1581                                         N  - 3 N
1582          (%o4)              diagonals = --------
1583                                            2
1584          (%i5) ev(%, N=9);   /* Testing for a 9 sides polygon */
1585          (%o5)                 diagonals = 27
1586
1587     How many ways do we have to put two queens without they are
1588     threatened into a n x n chessboard?
1589          (%i6) plsquares(matrix([0,0],[1,0],[2,0],[3,8],[4,44]),
1590                          [n,positions],[positions],4);
1591               Determination Coefficient for [positions] = [1.0]
1592                                   4       3      2
1593                                3 n  - 10 n  + 9 n  - 2 n
1594          (%o6)    [positions = -------------------------]
1595                                            6
1596          (%i7) ev(%[1], n=8); /* Testing for a (8 x 8) chessboard */
1597          (%o7)                positions = 1288
1598
1599     An example with six dependent variables:
1600          (%i8) mtrx:matrix([0,0,0,0,0,1,1,1],[0,1,0,1,1,1,0,0],
1601                            [1,0,0,1,1,1,0,0],[1,1,1,1,0,0,0,1])$
1602          (%i8) plsquares(mtrx,[a,b,_And,_Or,_Xor,_Nand,_Nor,_Nxor],
1603                               [_And,_Or,_Xor,_Nand,_Nor,_Nxor],1,0);
1604                Determination Coefficient for
1605          [_And, _Or, _Xor, _Nand, _Nor, _Nxor] =
1606          [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
1607          (%o2) [_And = a b, _Or = - a b + b + a,
1608          _Xor = - 2 a b + b + a, _Nand = 1 - a b,
1609          _Nor = a b - b - a + 1, _Nxor = 2 a b - b - a + 1]
1610
1611     To use this function write first 'load("lsquares")'.
1612
1613
1614File: maxima.info,  Node: makeOrders,  Next: minpack,  Prev: lsquares,  Up: Top
1615
161660 makeOrders
1617*************
1618
1619* Menu:
1620
1621* Functions and Variables for makeOrders::
1622
1623
1624File: maxima.info,  Node: Functions and Variables for makeOrders,  Prev: makeOrders,  Up: makeOrders
1625
162660.1 Functions and Variables for makeOrders
1627===========================================
1628
1629 -- Function: makeOrders (<indvarlist>, <orderlist>)
1630
1631     Returns a list of all powers for a polynomial up to and including
1632     the arguments.
1633
1634          (%i1) load("makeOrders")$
1635
1636          (%i2) makeOrders([a,b],[2,3]);
1637          (%o2) [[0, 0], [0, 1], [0, 2], [0, 3], [1, 0], [1, 1],
1638                      [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3]]
1639          (%i3) expand((1+a+a^2)*(1+b+b^2+b^3));
1640                 2  3      3    3    2  2      2    2    2
1641          (%o3) a  b  + a b  + b  + a  b  + a b  + b  + a  b + a b
1642                                                            2
1643                                                     + b + a  + a + 1
1644
1645     where '[0, 1]' is associated with the term b and '[2, 3]' with a^2
1646     b^3.
1647
1648     To use this function write first 'load("makeOrders")'.
1649
1650
1651File: maxima.info,  Node: minpack,  Next: mnewton,  Prev: makeOrders,  Up: Top
1652
165361 minpack
1654**********
1655
1656* Menu:
1657
1658* Introduction to minpack::
1659* Functions and Variables for minpack::
1660
1661
1662File: maxima.info,  Node: Introduction to minpack
1663
166461.1 Introduction to minpack
1665============================
1666
1667'Minpack' is a Common Lisp translation (via 'f2cl') of the Fortran
1668library MINPACK, as obtained from Netlib.
1669
1670
1671File: maxima.info,  Node: Functions and Variables for minpack
1672
167361.2 Functions and Variables for minpack
1674========================================
1675
1676 -- Function: minpack_lsquares (<flist>, <varlist>, <guess> [,
1677          <tolerance>, <jacobian>])
1678
1679     Compute the point that minimizes the sum of the squares of the
1680     functions in the list <flist>.  The variables are in the list
1681     <varlist>.  An initial guess of the optimum point must be provided
1682     in <guess>.
1683
1684     The optional keyword arguments, <tolerance> and <jacobian> provide
1685     some control over the algorithm.  <tolerance> is the estimated
1686     relative error desired in the sum of squares.  <jacobian> can be
1687     used to specify the Jacobian.  If <jacobian> is not given or is
1688     'true' (the default), the Jacobian is computed from <flist>.  If
1689     <jacobian> is 'false', a numerical approximation is used.
1690
1691     'minpack_lsquares' returns a list.  The first item is the estimated
1692     solution; the second is the sum of squares, and the third indicates
1693     the success of the algorithm.  The possible values are
1694
1695     '0'
1696          improper input parameters.
1697     '1'
1698          algorithm estimates that the relative error in the sum of
1699          squares is at most 'tolerance'.
1700     '2'
1701          algorithm estimates that the relative error between x and the
1702          solution is at most 'tolerance'.
1703     '3'
1704          conditions for info = 1 and info = 2 both hold.
1705     '4'
1706          fvec is orthogonal to the columns of the jacobian to machine
1707          precision.
1708     '5'
1709          number of calls to fcn with iflag = 1 has reached 100*(n+1).
1710     '6'
1711          tol is too small.  no further reduction in the sum of squares
1712          is possible.
1713     '7'
1714          tol is too small.  no further improvement in the approximate
1715          solution x is possible.
1716
1717          /* Problem 6: Powell singular function */
1718          (%i1) powell(x1,x2,x3,x4) :=
1719                   [x1+10*x2, sqrt(5)*(x3-x4), (x2-2*x3)^2,
1720                        sqrt(10)*(x1-x4)^2]$
1721          (%i2) minpack_lsquares(powell(x1,x2,x3,x4), [x1,x2,x3,x4],
1722                                 [3,-1,0,1]);
1723          (%o2) [[1.652117596168394e-17, - 1.652117596168393e-18,
1724                  2.643388153869468e-18, 2.643388153869468e-18],
1725                 6.109327859207777e-34, 4]
1726
1727          /* Same problem but use numerical approximation to Jacobian */
1728          (%i3) minpack_lsquares(powell(x1,x2,x3,x4), [x1,x2,x3,x4],
1729                                 [3,-1,0,1], jacobian = false);
1730          (%o3) [[5.060282149485331e-11, - 5.060282149491206e-12,
1731                  2.179447843547218e-11, 2.179447843547218e-11],
1732                 3.534491794847031e-21, 5]
1733
1734 -- Function: minpack_solve (<flist>, <varlist>, <guess> [, <tolerance>,
1735          <jacobian>])
1736
1737     Solve a system of 'n' equations in 'n' unknowns.  The 'n' equations
1738     are given in the list <flist>, and the unknowns are in <varlist>.
1739     An initial guess of the solution must be provided in <guess>.
1740
1741     The optional keyword arguments, <tolerance> and <jacobian> provide
1742     some control over the algorithm.  <tolerance> is the estimated
1743     relative error desired in the sum of squares.  <jacobian> can be
1744     used to specify the Jacobian.  If <jacobian> is not given or is
1745     'true' (the default), the Jacobian is computed from <flist>.  If
1746     <jacobian> is 'false', a numerical approximation is used.
1747
1748     'minpack_solve' returns a list.  The first item is the estimated
1749     solution; the second is the sum of squares, and the third indicates
1750     the success of the algorithm.  The possible values are
1751
1752     '0'
1753          improper input parameters.
1754     '1'
1755          algorithm estimates that the relative error in the solution is
1756          at most 'tolerance'.
1757     '2'
1758          number of calls to fcn with iflag = 1 has reached 100*(n+1).
1759     '3'
1760          tol is too small.  no further reduction in the sum of squares
1761          is possible.
1762     '4'
1763          Iteration is not making good progress.
1764
1765
1766
1767File: maxima.info,  Node: mnewton,  Next: numericalio,  Prev: minpack,  Up: Top
1768
176962 mnewton
1770**********
1771
1772* Menu:
1773
1774* Einführung in mnewton::
1775* Funktionen und Variablen für mnewton::
1776
1777
1778File: maxima.info,  Node: Einführung in mnewton,  Next: Funktionen und Variablen für mnewton,  Prev: mnewton,  Up: mnewton
1779
178062.1 Einführung in mnewton
1781==========================
1782
1783Das Paket mnewton implementiert das Newton-Verfahren mit der Funktion
1784'mnewton' für das numerische Lösen nichtlinear Gleichungen in einer oder
1785mehrerer Variablen.  Die Funktion 'newton' ist eine weitere
1786Implementierung, die im Paket newton1 enthalten ist.
1787
1788
1789File: maxima.info,  Node: Funktionen und Variablen für mnewton,  Prev: Einführung in mnewton,  Up: mnewton
1790
179162.2 Funktionen und Variablen für mnewton
1792=========================================
1793
1794 -- Optionsvariable: newtonepsilon
1795     Standardwert: '1.0e-8'
1796
1797     Genauigkeit mit der getestet wird, wie gut die Funktion 'mnewton'
1798     sich der Lösung angenähert hat.  Unterschreitet die Änderung der
1799     Approximation den Wert 'newtonepsilon', bricht der Algorithmus ab
1800     und gibt das Ergebnis zurück.
1801
1802 -- Optionsvariable: newtonmaxiter
1803     Standardwert: '50'
1804
1805     Obere Grenze für die Anzahl an Iterationen, falls die Funktion
1806     'mnewton' nicht oder sehr langsam konvergiert.
1807
1808 -- Funktion: mnewton (<FuncList>, <VarList>, <GuessList>)
1809
1810     Implementation des Newton-Verfahrens für das numerische Lösen von
1811     Gleichungen in mehreren Variablen.  Das Argument <FuncList> ist die
1812     Liste der Gleichungen, für die eine numerische Lösung gesucht wird.
1813     Das Argument <VarList> ist eine Liste der Variablen und das
1814     Argument <GuessList> ist eine Liste mit den Startwerten des
1815     Newton-Verfahrens.
1816
1817     Die Lösungen werden als eine Liste zurückgegeben.  Kann keine
1818     Lösung gefunden werden, ist die Rückgabe eine leere Liste '[]'.
1819
1820     'mnewton' wird von den Funktionen 'newtonepsilon' und
1821     'newtonmaxiter' kontrolliert.
1822
1823     Die Funktion wird mit dem Kommando 'load(mnewton)' geladen.  Siehe
1824     die Funktion 'newton' für eine alternative Implementierung des
1825     Newton-Verfahrens.
1826
1827     Beispiele:
1828
1829          (%i1) load(mnewton)$
1830
1831          (%i2) mnewton([x1+3*log(x1)-x2^2, 2*x1^2-x1*x2-5*x1+1],
1832                        [x1, x2], [5, 5]);
1833          (%o2) [[x1 = 3.756834008012769, x2 = 2.779849592817897]]
1834          (%i3) mnewton([2*a^a-5],[a],[1]);
1835          (%o3)             [[a = 1.70927556786144]]
1836          (%i4) mnewton([2*3^u-v/u-5, u+2^v-4], [u, v], [2, 2]);
1837          (%o4) [[u = 1.066618389595407, v = 1.552564766841786]]
1838
1839     Die Optionsvariable 'newtonepsilon' kontrolliert die Genauigkeit
1840     der Approximation.  Weiterhin kontrolliert die Optionsvariable, ob
1841     die Berechnung mit Gleitkommazahlen in doppelter oder großer
1842     Genauigkeit durchgeführt wird.
1843
1844          (%i1) load(mnewton)$
1845
1846          (%i2) (fpprec : 25, newtonepsilon : bfloat(10^(-fpprec+5)))$
1847
1848          (%i3) mnewton([2*3^u-v/u-5, u+2^v-4], [u, v], [2, 2]);
1849          (%o3) [[u = 1.066618389595406772591173b0,
1850                                         v = 1.552564766841786450100418b0]]
1851
1852 -- Funktion: newton (<expr>, <x>, <x_0>, <eps>)
1853
1854     Die Funktion 'newton' gibt eine Näherungslösung der Gleichung
1855     '<expr> = 0' zurück, die mit dem Newton-Verfahren berechnet wird.
1856     Der Ausdruck <expr> ist eine Funktion einer Variablen <x>.  Der
1857     Anfangswert ist ' <x> = <x_0>'.  Der Algorithmus bricht ab, wenn
1858     'abs(<expr>) < <eps>', wobei der Ausdruck <expr> für den aktuellen
1859     Näherungswert <x> ausgewertet wird.
1860
1861     'newton' erlaubt symbolische Variablen im Ausdruck <expr>, wenn der
1862     Ausdruck 'abs(<expr>) < <eps>' zu 'true' oder 'false' ausgewertet
1863     werden kann.  Daher ist es nicht notwendig, dass der Ausdruck
1864     <expr> zu einer Zahl ausgewertet werden kann.
1865
1866     Das Kommando 'load(newton1)' lädt die Funktion.
1867
1868     Siehe auch die Funktionen 'realroots', 'allroots' und 'find_root',
1869     um numerische Lösungen von Gleichungen zu finden.  Das Paket
1870     mnewton enthält mit der Funktion 'mnewton' eine weitere
1871     Implementation des Newton-Verfahrens.
1872
1873     Achtung: Auch mit 'load(newton)' wird eine Funktion mit dem Namen
1874     'newton' geladen, die sich jedoch in ihrer Syntax von der hier
1875     beschriebenen Funktion unterscheidet und auch nicht dokumentiert
1876     ist.
1877
1878     Beispiele:
1879
1880          (%i1) load (newton1);
1881          (%o1) /usr/share/maxima/5.10.0cvs/share/numeric/newton1.mac
1882          (%i2) newton (cos (u), u, 1, 1/100);
1883          (%o2)                   1.570675277161251
1884          (%i3) ev (cos (u), u = %);
1885          (%o3)                 1.2104963335033528E-4
1886          (%i4) assume (a > 0);
1887          (%o4)                        [a > 0]
1888          (%i5) newton (x^2 - a^2, x, a/2, a^2/100);
1889          (%o5)                  1.00030487804878 a
1890          (%i6) ev (x^2 - a^2, x = %);
1891                                                     2
1892          (%o6)                6.098490481853958E-4 a
1893
1894
1895File: maxima.info,  Node: numericalio,  Next: opsubst,  Prev: mnewton,  Up: Top
1896
189763 numericalio
1898**************
1899
1900* Menu:
1901
1902* Introduction to numericalio::
1903* Functions and Variables for plain-text input and output::
1904* Functions and Variables for binary input and output::
1905
1906
1907File: maxima.info,  Node: Introduction to numericalio,  Next: Functions and Variables for plain-text input and output,  Prev: numericalio,  Up: numericalio
1908
190963.1 Introduction to numericalio
1910================================
1911
1912'numericalio' is a collection of functions to read and write files and
1913streams.  Functions for plain-text input and output can read and write
1914numbers (integer, float, or bigfloat), symbols, and strings.  Functions
1915for binary input and output can read and write only floating-point
1916numbers.
1917
1918If there already exists a list, matrix, or array object to store input
1919data, 'numericalio' input functions can write data into that object.
1920Otherwise, 'numericalio' can guess, to some degree, the structure of an
1921object to store the data, and return that object.
1922
192363.1.1 Plain-text input and output
1924----------------------------------
1925
1926In plain-text input and output, it is assumed that each item to read or
1927write is an atom: an integer, float, bigfloat, string, or symbol, and
1928not a rational or complex number or any other kind of nonatomic
1929expression.  The 'numericalio' functions may attempt to do something
1930sensible faced with nonatomic expressions, but the results are not
1931specified here and subject to change.
1932
1933Atoms in both input and output files have the same format as in Maxima
1934batch files or the interactive console.  In particular, strings are
1935enclosed in double quotes, backslash '\' prevents any special
1936interpretation of the next character, and the question mark '?' is
1937recognized at the beginning of a symbol to mean a Lisp symbol (as
1938opposed to a Maxima symbol).  No continuation character (to join broken
1939lines) is recognized.
1940
194163.1.2 Separator flag values for input
1942--------------------------------------
1943
1944The functions for plain-text input and output take an optional argument,
1945<separator_flag>, that tells what character separates data.
1946
1947For plain-text input, these values of <separator_flag> are recognized:
1948'comma' for comma separated values, 'pipe' for values separated by the
1949vertical bar character '|', 'semicolon' for values separated by
1950semicolon ';', and 'space' for values separated by space or tab
1951characters.  If the file name ends in '.csv' and <separator_flag> is not
1952specified, 'comma' is assumed.  If the file name ends in something other
1953than '.csv' and 'separator_flag' is not specified, 'space' is assumed.
1954
1955In plain-text input, multiple successive space and tab characters count
1956as a single separator.  However, multiple comma, pipe, or semicolon
1957characters are significant.  Successive comma, pipe, or semicolon
1958characters (with or without intervening spaces or tabs) are considered
1959to have 'false' between the separators.  For example, '1234,,Foo' is
1960treated the same as '1234,false,Foo'.
1961
196263.1.3 Separator flag values for output
1963---------------------------------------
1964
1965For plain-text output, 'tab', for values separated by the tab character,
1966is recognized as a value of <separator_flag>, as well as 'comma',
1967'pipe', 'semicolon', and 'space'.
1968
1969In plain-text output, 'false' atoms are written as such; a list '[1234,
1970false, Foo]' is written '1234,false,Foo', and there is no attempt to
1971collapse the output to '1234,,Foo'.
1972
197363.1.4 Binary floating-point input and output
1974---------------------------------------------
1975
1976'numericalio' functions can read and write 8-byte IEEE 754
1977floating-point numbers.  These numbers can be stored either least
1978significant byte first or most significant byte first, according to the
1979global flag set by 'assume_external_byte_order'.  If not specified,
1980'numericalio' assumes the external byte order is most-significant byte
1981first.
1982
1983Other kinds of numbers are coerced to 8-byte floats; 'numericalio'
1984cannot read or write binary non-numeric data.
1985
1986Some Lisp implementations do not recognize IEEE 754 special values
1987(positive and negative infinity, not-a-number values, denormalized
1988values).  The effect of reading such values with 'numericalio' is
1989undefined.
1990
1991'numericalio' includes functions to open a stream for reading or writing
1992a stream of bytes.
1993
1994
1995File: maxima.info,  Node: Functions and Variables for plain-text input and output,  Next: Functions and Variables for binary input and output,  Prev: Introduction to numericalio,  Up: numericalio
1996
199763.2 Functions and Variables for plain-text input and output
1998============================================================
1999
2000 -- Function: read_matrix (<S>)
2001 -- Function: read_matrix (<S>, <M>)
2002 -- Function: read_matrix (<S>, <separator_flag>)
2003 -- Function: read_matrix (<S>, <M>, <separator_flag>)
2004
2005     'read_matrix(<S>)' reads the source <S> and returns its entire
2006     content as a matrix.  The size of the matrix is inferred from the
2007     input data; each line of the file becomes one row of the matrix.
2008     If some lines have different lengths, 'read_matrix' complains.
2009
2010     'read_matrix(<S>, <M>)' read the source <S> into the matrix <M>,
2011     until <M> is full or the source is exhausted.  Input data are read
2012     into the matrix in row-major order; the input need not have the
2013     same number of rows and columns as <M>.
2014
2015     The source <S> may be a file name or a stream.
2016
2017     The recognized values of <separator_flag> are 'comma', 'pipe',
2018     'semicolon', and 'space'.  If <separator_flag> is not specified,
2019     the file is assumed space-delimited.
2020
2021 -- Function: read_array (<S>, <A>)
2022 -- Function: read_array (<S>, <A>, <separator_flag>)
2023
2024     Reads the source <S> into the array <A>, until <A> is full or the
2025     source is exhausted.  Input data are read into the array in
2026     row-major order; the input need not conform to the dimensions of
2027     <A>.
2028
2029     The source <S> may be a file name or a stream.
2030
2031     The recognized values of <separator_flag> are 'comma', 'pipe',
2032     'semicolon', and 'space'.  If <separator_flag> is not specified,
2033     the file is assumed space-delimited.
2034
2035 -- Function: read_hashed_array (<S>, <A>)
2036 -- Function: read_hashed_array (<S>, <A>, <separator_flag>)
2037
2038     Reads the source <S> and returns its entire content as a hashed
2039     array.  The source <S> may be a file name or a stream.
2040
2041     'read_hashed_array' treats the first item on each line as a hash
2042     key, and associates the remainder of the line (as a list) with the
2043     key.  For example, the line '567 12 17 32 55' is equivalent to
2044     'A[567]: [12, 17, 32, 55]$'.  Lines need not have the same numbers
2045     of elements.
2046
2047     The recognized values of <separator_flag> are 'comma', 'pipe',
2048     'semicolon', and 'space'.  If <separator_flag> is not specified,
2049     the file is assumed space-delimited.
2050
2051 -- Function: read_nested_list (<S>)
2052 -- Function: read_nested_list (<S>, <separator_flag>)
2053
2054     Reads the source <S> and returns its entire content as a nested
2055     list.  The source <S> may be a file name or a stream.
2056
2057     'read_nested_list' returns a list which has a sublist for each line
2058     of input.  Lines need not have the same numbers of elements.  Empty
2059     lines are not ignored: an empty line yields an empty sublist.
2060
2061     The recognized values of <separator_flag> are 'comma', 'pipe',
2062     'semicolon', and 'space'.  If <separator_flag> is not specified,
2063     the file is assumed space-delimited.
2064
2065 -- Function: read_list (<S>)
2066 -- Function: read_list (<S>, <L>)
2067 -- Function: read_list (<S>, <separator_flag>)
2068 -- Function: read_list (<S>, <L>, <separator_flag>)
2069
2070     'read_list(<S>)' reads the source <S> and returns its entire
2071     content as a flat list.
2072
2073     'read_list(<S>, <L>)' reads the source <S> into the list <L>, until
2074     <L> is full or the source is exhausted.
2075
2076     The source <S> may be a file name or a stream.
2077
2078     The recognized values of <separator_flag> are 'comma', 'pipe',
2079     'semicolon', and 'space'.  If <separator_flag> is not specified,
2080     the file is assumed space-delimited.
2081
2082 -- Function: write_data (<X>, <D>)
2083 -- Function: write_data (<X>, <D>, <separator_flag>)
2084
2085     Writes the object <X> to the destination <D>.
2086
2087     'write_data' writes a matrix in row-major order, with one line per
2088     row.
2089
2090     'write_data' writes an array created by 'array' or 'make_array' in
2091     row-major order, with a new line at the end of every slab.
2092     Higher-dimensional slabs are separated by additional new lines.
2093
2094     'write_data' writes a hashed array with each key followed by its
2095     associated list on one line.
2096
2097     'write_data' writes a nested list with each sublist on one line.
2098
2099     'write_data' writes a flat list all on one line.
2100
2101     The destination <D> may be a file name or a stream.  When the
2102     destination is a file name, the global variable
2103     'file_output_append' governs whether the output file is appended or
2104     truncated.  When the destination is a stream, no special action is
2105     taken by 'write_data' after all the data are written; in
2106     particular, the stream remains open.
2107
2108     The recognized values of <separator_flag> are 'comma', 'pipe',
2109     'semicolon', 'space', and 'tab'.  If <separator_flag> is not
2110     specified, the file is assumed space-delimited.
2111
2112
2113File: maxima.info,  Node: Functions and Variables for binary input and output,  Prev: Functions and Variables for plain-text input and output,  Up: numericalio
2114
211563.3 Functions and Variables for binary input and output
2116========================================================
2117
2118 -- Function: assume_external_byte_order (<byte_order_flag>)
2119     Tells 'numericalio' the byte order for reading and writing binary
2120     data.  Two values of <byte_order_flag> are recognized: 'lsb' which
2121     indicates least-significant byte first, also called little-endian
2122     byte order; and 'msb' which indicates most-significant byte first,
2123     also called big-endian byte order.
2124
2125     If not specified, 'numericalio' assumes the external byte order is
2126     most-significant byte first.
2127
2128 -- Function: openr_binary (<file_name>)
2129     Returns an input stream of 8-bit unsigned bytes to read the file
2130     named by <file_name>.
2131
2132 -- Function: openw_binary (<file_name>)
2133     Returns an output stream of 8-bit unsigned bytes to write the file
2134     named by <file_name>.
2135
2136 -- Function: opena_binary (<file_name>)
2137     Returns an output stream of 8-bit unsigned bytes to append the file
2138     named by <file_name>.
2139
2140 -- Function: read_binary_matrix (<S>, <M>)
2141     Reads binary 8-byte floating point numbers from the source <S> into
2142     the matrix <M> until <M> is full, or the source is exhausted.
2143     Elements of <M> are read in row-major order.
2144
2145     The source <S> may be a file name or a stream.
2146
2147     The byte order in elements of the source is specified by
2148     'assume_external_byte_order'.
2149
2150 -- Function: read_binary_array (<S>, <A>)
2151     Reads binary 8-byte floating point numbers from the source <S> into
2152     the array <A> until <A> is full, or the source is exhausted.  <A>
2153     must be an array created by 'array' or 'make_array'.  Elements of
2154     <A> are read in row-major order.
2155
2156     The source <S> may be a file name or a stream.
2157
2158     The byte order in elements of the source is specified by
2159     'assume_external_byte_order'.
2160
2161 -- Function: read_binary_list (<S>)
2162 -- Function: read_binary_list (<S>, <L>)
2163     'read_binary_list(<S>)' reads the entire content of the source <S>
2164     as a sequence of binary 8-byte floating point numbers, and returns
2165     it as a list.  The source <S> may be a file name or a stream.
2166
2167     'read_binary_list(<S>, <L>)' reads 8-byte binary floating point
2168     numbers from the source <S> until the list <L> is full, or the
2169     source is exhausted.
2170
2171     The byte order in elements of the source is specified by
2172     'assume_external_byte_order'.
2173
2174 -- Function: write_binary_data (<X>, <D>)
2175
2176     Writes the object <X>, comprising binary 8-byte IEEE 754
2177     floating-point numbers, to the destination <D>.  Other kinds of
2178     numbers are coerced to 8-byte floats.  'write_binary_data' cannot
2179     write non-numeric data.
2180
2181     The object <X> may be a list, a nested list, a matrix, or an array
2182     created by 'array' or 'make_array'; <X> cannot be an undeclared
2183     array or any other type of object.  'write_binary_data' writes
2184     nested lists, matrices, and arrays in row-major order.
2185
2186     The destination <D> may be a file name or a stream.  When the
2187     destination is a file name, the global variable
2188     'file_output_append' governs whether the output file is appended or
2189     truncated.  When the destination is a stream, no special action is
2190     taken by 'write_binary_data' after all the data are written; in
2191     particular, the stream remains open.
2192
2193     The byte order in elements of the destination is specified by
2194     'assume_external_byte_order'.
2195
2196
2197File: maxima.info,  Node: opsubst,  Next: orthopoly,  Prev: numericalio,  Up: Top
2198
219964 opsubst
2200**********
2201
2202* Menu:
2203
2204* Functions and Variables for opsubst::
2205
2206
2207File: maxima.info,  Node: Functions and Variables for opsubst,  Prev: opsubst,  Up: opsubst
2208
220964.1 Functions and Variables for opsubst
2210========================================
2211
2212 -- Function: opsubst (<f>, <g>, <e>)
2213 -- Function: opsubst (<g> = <f>, <e>)
2214 -- Function: opsubst ([<g1> = <f1>, <g2> = <f2>, ..., <gn> = <fn>],
2215          <e>)
2216
2217     The function 'opsubst' is similar to the function 'subst', except
2218     that 'opsubst' only makes substitutions for the operators in an
2219     expression.  In general, when <f> is an operator in the expression
2220     <e>, substitute <g> for <f> in the expression <e>.
2221
2222     To determine the operator, 'opsubst' sets 'inflag' to true.  This
2223     means 'opsubst' substitutes for the internal, not the displayed,
2224     operator in the expression.
2225
2226     To use this function write first 'load("opsubst")'.
2227
2228     Examples:
2229
2230          (%i1) load("opsubst")$
2231
2232          (%i2) opsubst(f, g, g(g(x)));
2233          (%o2)                     f(f(x))
2234          (%i3) opsubst(f, g, g(g));
2235          (%o3)                       f(g)
2236          (%i4) opsubst(f, g[x], g[x](z));
2237          (%o4)                       f(z)
2238          (%i5) opsubst(g[x], f, f(z));
2239          (%o5)                      g (z)
2240                                      x
2241          (%i6) opsubst(tan, sin, sin(sin));
2242          (%o6)                     tan(sin)
2243          (%i7) opsubst([f=g, g=h], f(x));
2244          (%o7)                       h(x)
2245
2246     Internally, Maxima does not use the unary negation, division, or
2247     the subtraction operators; thus:
2248
2249          (%i8) opsubst("+", "-", a-b);
2250          (%o8)                     a - b
2251          (%i9) opsubst("f", "-", -a);
2252          (%o9)                      - a
2253          (%i10) opsubst("^^", "/", a/b);
2254                                       a
2255          (%o10)                       -
2256                                       b
2257
2258     The internal representation of '-a*b' is '*(-1,a,b)'; thus
2259
2260          (%i11) opsubst("[", "*", -a*b);
2261          (%o11)                  [- 1, a, b]
2262
2263     When either operator isn't a Maxima symbol, generally some other
2264     function will signal an error:
2265
2266          (%i12) opsubst(a+b, f, f(x));
2267
2268          Improper name or value in functional position:
2269          b + a
2270           -- an error.  Quitting.  To debug this try debugmode(true);
2271
2272     However, subscripted operators are allowed:
2273
2274          (%i13) opsubst(g[5], f, f(x));
2275          (%o13)                     g (x)
2276                                      5
2277
2278
2279File: maxima.info,  Node: orthopoly,  Next: plotdf,  Prev: opsubst,  Up: Top
2280
228165 orthopoly
2282************
2283
2284* Menu:
2285
2286* Introduction to orthogonal polynomials::
2287* Functions and Variables for orthogonal polynomials::
2288
2289
2290File: maxima.info,  Node: Introduction to orthogonal polynomials,  Next: Functions and Variables for orthogonal polynomials,  Prev: orthopoly,  Up: orthopoly
2291
229265.1 Introduction to orthogonal polynomials
2293===========================================
2294
2295'orthopoly' is a package for symbolic and numerical evaluation of
2296several kinds of orthogonal polynomials, including Chebyshev, Laguerre,
2297Hermite, Jacobi, Legendre, and ultraspherical (Gegenbauer) polynomials.
2298Additionally, 'orthopoly' includes support for the spherical Bessel,
2299spherical Hankel, and spherical harmonic functions.
2300
2301For the most part, 'orthopoly' follows the conventions of Abramowitz and
2302Stegun Handbook of Mathematical Functions, Chapter 22 (10th printing,
2303December 1972); additionally, we use Gradshteyn and Ryzhik, Table of
2304Integrals, Series, and Products (1980 corrected and enlarged edition),
2305and Eugen Merzbacher Quantum Mechanics (2nd edition, 1970).
2306
2307Barton Willis of the University of Nebraska at Kearney (UNK) wrote the
2308'orthopoly' package and its documentation.  The package is released
2309under the GNU General Public License (GPL).
2310
231165.1.1 Getting Started with orthopoly
2312-------------------------------------
2313
2314'load (orthopoly)' loads the 'orthopoly' package.
2315
2316To find the third-order Legendre polynomial,
2317
2318     (%i1) legendre_p (3, x);
2319                           3             2
2320                  5 (1 - x)    15 (1 - x)
2321     (%o1)      - ---------- + ----------- - 6 (1 - x) + 1
2322                      2             2
2323
2324To express this as a sum of powers of <x>, apply 'ratsimp' or 'rat' to
2325the result.
2326
2327     (%i2) [ratsimp (%), rat (%)];
2328                             3           3
2329                          5 x  - 3 x  5 x  - 3 x
2330     (%o2)/R/            [----------, ----------]
2331                              2           2
2332
2333Alternatively, make the second argument to 'legendre_p' (its "main"
2334variable) a canonical rational expression (CRE).
2335
2336     (%i1) legendre_p (3, rat (x));
2337                                   3
2338                                5 x  - 3 x
2339     (%o1)/R/                   ----------
2340                                    2
2341
2342For floating point evaluation, 'orthopoly' uses a running error analysis
2343to estimate an upper bound for the error.  For example,
2344
2345     (%i1) jacobi_p (150, 2, 3, 0.2);
2346     (%o1) interval(- 0.062017037936715, 1.533267919277521E-11)
2347
2348Intervals have the form 'interval (<c>, <r>)', where <c> is the center
2349and <r> is the radius of the interval.  Since Maxima does not support
2350arithmetic on intervals, in some situations, such as graphics, you want
2351to suppress the error and output only the center of the interval.  To do
2352this, set the option variable 'orthopoly_returns_intervals' to 'false'.
2353
2354     (%i1) orthopoly_returns_intervals : false;
2355     (%o1)                         false
2356     (%i2) jacobi_p (150, 2, 3, 0.2);
2357     (%o2)                  - 0.062017037936715
2358
2359Refer to the section *note Floating point Evaluation:: for more
2360information.
2361
2362Most functions in 'orthopoly' have a 'gradef' property; thus
2363
2364     (%i1) diff (hermite (n, x), x);
2365     (%o1)                     2 n H     (x)
2366                                    n - 1
2367     (%i2) diff (gen_laguerre (n, a, x), x);
2368                   (a)               (a)
2369                n L   (x) - (n + a) L     (x) unit_step(n)
2370                   n                 n - 1
2371     (%o2)      ------------------------------------------
2372                                    x
2373
2374The unit step function in the second example prevents an error that
2375would otherwise arise by evaluating with <n> equal to 0.
2376
2377     (%i3) ev (%, n = 0);
2378     (%o3)                           0
2379
2380The 'gradef' property only applies to the "main" variable; derivatives
2381with respect other arguments usually result in an error message; for
2382example
2383
2384     (%i1) diff (hermite (n, x), x);
2385     (%o1)                     2 n H     (x)
2386                                    n - 1
2387     (%i2) diff (hermite (n, x), n);
2388
2389     Maxima doesn't know the derivative of hermite with respect the first
2390     argument
2391      -- an error.  Quitting.  To debug this try debugmode(true);
2392
2393Generally, functions in 'orthopoly' map over lists and matrices.  For
2394the mapping to fully evaluate, the option variables 'doallmxops' and
2395'listarith' must both be 'true' (the defaults).  To illustrate the
2396mapping over matrices, consider
2397
2398     (%i1) hermite (2, x);
2399                                          2
2400     (%o1)                    - 2 (1 - 2 x )
2401     (%i2) m : matrix ([0, x], [y, 0]);
2402                                 [ 0  x ]
2403     (%o2)                       [      ]
2404                                 [ y  0 ]
2405     (%i3) hermite (2, m);
2406                    [                             2  ]
2407                    [      - 2        - 2 (1 - 2 x ) ]
2408     (%o3)          [                                ]
2409                    [             2                  ]
2410                    [ - 2 (1 - 2 y )       - 2       ]
2411
2412In the second example, the 'i, j' element of the value is 'hermite (2,
2413m[i,j])'; this is not the same as computing '-2 + 4 m . m', as seen in
2414the next example.
2415
2416     (%i4) -2 * matrix ([1, 0], [0, 1]) + 4 * m . m;
2417                         [ 4 x y - 2      0     ]
2418     (%o4)               [                      ]
2419                         [     0      4 x y - 2 ]
2420
2421If you evaluate a function at a point outside its domain, generally
2422'orthopoly' returns the function unevaluated.  For example,
2423
2424     (%i1) legendre_p (2/3, x);
2425     (%o1)                        P   (x)
2426                                   2/3
2427
2428'orthopoly' supports translation into TeX; it also does two-dimensional
2429output on a terminal.
2430
2431     (%i1) spherical_harmonic (l, m, theta, phi);
2432                               m
2433     (%o1)                    Y (theta, phi)
2434                               l
2435     (%i2) tex (%);
2436     $$Y_{l}^{m}\left(\vartheta,\varphi\right)$$
2437     (%o2)                         false
2438     (%i3) jacobi_p (n, a, a - b, x/2);
2439                               (a, a - b) x
2440     (%o3)                    P          (-)
2441                               n          2
2442     (%i4) tex (%);
2443     $$P_{n}^{\left(a,a-b\right)}\left({{x}\over{2}}\right)$$
2444     (%o4)                         false
2445
244665.1.2 Limitations
2447------------------
2448
2449When an expression involves several orthogonal polynomials with symbolic
2450orders, it's possible that the expression actually vanishes, yet Maxima
2451is unable to simplify it to zero.  If you divide by such a quantity,
2452you'll be in trouble.  For example, the following expression vanishes
2453for integers <n> greater than 1, yet Maxima is unable to simplify it to
2454zero.
2455
2456     (%i1) (2*n - 1) * legendre_p (n - 1, x) * x - n * legendre_p (n, x)
2457           + (1 - n) * legendre_p (n - 2, x);
2458     (%o1)  (2 n - 1) P     (x) x - n P (x) + (1 - n) P     (x)
2459                       n - 1           n               n - 2
2460
2461For a specific <n>, we can reduce the expression to zero.
2462
2463     (%i2) ev (% ,n = 10, ratsimp);
2464     (%o2)                           0
2465
2466Generally, the polynomial form of an orthogonal polynomial is ill-suited
2467for floating point evaluation.  Here's an example.
2468
2469     (%i1) p : jacobi_p (100, 2, 3, x)$
2470
2471     (%i2) subst (0.2, x, p);
2472     (%o2)                3.4442767023833592E+35
2473     (%i3) jacobi_p (100, 2, 3, 0.2);
2474     (%o3)  interval(0.18413609135169, 6.8990300925815987E-12)
2475     (%i4) float(jacobi_p (100, 2, 3, 2/10));
2476     (%o4)                   0.18413609135169
2477
2478The true value is about 0.184; this calculation suffers from extreme
2479subtractive cancellation error.  Expanding the polynomial and then
2480evaluating, gives a better result.
2481
2482     (%i5) p : expand(p)$
2483     (%i6) subst (0.2, x, p);
2484     (%o6) 0.18413609766122982
2485
2486This isn't a general rule; expanding the polynomial does not always
2487result in an expression that is better suited for numerical evaluation.
2488By far, the best way to do numerical evaluation is to make one or more
2489of the function arguments floating point numbers.  By doing that,
2490specialized floating point algorithms are used for evaluation.
2491
2492Maxima's 'float' function is somewhat indiscriminate; if you apply
2493'float' to an expression involving an orthogonal polynomial with a
2494symbolic degree or order parameter, these parameters may be converted
2495into floats; after that, the expression will not evaluate fully.
2496Consider
2497
2498     (%i1) assoc_legendre_p (n, 1, x);
2499                                    1
2500     (%o1)                         P (x)
2501                                    n
2502     (%i2) float (%);
2503                                   1.0
2504     (%o2)                        P   (x)
2505                                   n
2506     (%i3) ev (%, n=2, x=0.9);
2507                                  1.0
2508     (%o3)                       P   (0.9)
2509                                  2
2510
2511The expression in (%o3) will not evaluate to a float; 'orthopoly'
2512doesn't recognize floating point values where it requires an integer.
2513Similarly, numerical evaluation of the 'pochhammer' function for orders
2514that exceed 'pochhammer_max_index' can be troublesome; consider
2515
2516     (%i1) x :  pochhammer (1, 10), pochhammer_max_index : 5;
2517     (%o1)                         (1)
2518                                      10
2519
2520Applying 'float' doesn't evaluate <x> to a float
2521
2522     (%i2) float (x);
2523     (%o2)                       (1.0)
2524                                      10.0
2525
2526To evaluate <x> to a float, you'll need to bind 'pochhammer_max_index'
2527to 11 or greater and apply 'float' to <x>.
2528
2529     (%i3) float (x), pochhammer_max_index : 11;
2530     (%o3)                       3628800.0
2531
2532The default value of 'pochhammer_max_index' is 100; change its value
2533after loading 'orthopoly'.
2534
2535Finally, be aware that reference books vary on the definitions of the
2536orthogonal polynomials; we've generally used the conventions of
2537conventions of Abramowitz and Stegun.
2538
2539Before you suspect a bug in orthopoly, check some special cases to
2540determine if your definitions match those used by 'orthopoly'.
2541Definitions often differ by a normalization; occasionally, authors use
2542"shifted" versions of the functions that makes the family orthogonal on
2543an interval other than (-1, 1).  To define, for example, a Legendre
2544polynomial that is orthogonal on (0, 1), define
2545
2546     (%i1) shifted_legendre_p (n, x) := legendre_p (n, 2*x - 1)$
2547
2548     (%i2) shifted_legendre_p (2, rat (x));
2549                                 2
2550     (%o2)/R/                 6 x  - 6 x + 1
2551     (%i3) legendre_p (2, rat (x));
2552                                    2
2553                                 3 x  - 1
2554     (%o3)/R/                    --------
2555                                    2
2556
255765.1.3 Floating point Evaluation
2558--------------------------------
2559
2560Most functions in 'orthopoly' use a running error analysis to estimate
2561the error in floating point evaluation; the exceptions are the spherical
2562Bessel functions and the associated Legendre polynomials of the second
2563kind.  For numerical evaluation, the spherical Bessel functions call
2564SLATEC functions.  No specialized method is used for numerical
2565evaluation of the associated Legendre polynomials of the second kind.
2566
2567The running error analysis ignores errors that are second or higher
2568order in the machine epsilon (also known as unit roundoff).  It also
2569ignores a few other errors.  It's possible (although unlikely) that the
2570actual error exceeds the estimate.
2571
2572Intervals have the form 'interval (<c>, <r>)', where <c> is the center
2573of the interval and <r> is its radius.  The center of an interval can be
2574a complex number, and the radius is always a positive real number.
2575
2576Here is an example.
2577
2578     (%i1) fpprec : 50$
2579
2580     (%i2) y0 : jacobi_p (100, 2, 3, 0.2);
2581     (%o2) interval(0.1841360913516871, 6.8990300925815987E-12)
2582     (%i3) y1 : bfloat (jacobi_p (100, 2, 3, 1/5));
2583     (%o3) 1.8413609135168563091370224958913493690868904463668b-1
2584
2585Let's test that the actual error is smaller than the error estimate
2586
2587     (%i4) is (abs (part (y0, 1) - y1) < part (y0, 2));
2588     (%o4)                         true
2589
2590Indeed, for this example the error estimate is an upper bound for the
2591true error.
2592
2593Maxima does not support arithmetic on intervals.
2594
2595     (%i1) legendre_p (7, 0.1) + legendre_p (8, 0.1);
2596     (%o1) interval(0.18032072148437508, 3.1477135311021797E-15)
2597             + interval(- 0.19949294375000004, 3.3769353084291579E-15)
2598
2599A user could define arithmetic operators that do interval math.  To
2600define interval addition, we can define
2601
2602     (%i1) infix ("@+")$
2603
2604     (%i2) "@+"(x,y) := interval (part (x, 1) + part (y, 1), part (x, 2)
2605           + part (y, 2))$
2606
2607     (%i3) legendre_p (7, 0.1) @+ legendre_p (8, 0.1);
2608     (%o3) interval(- 0.019172222265624955, 6.5246488395313372E-15)
2609
2610The special floating point routines get called when the arguments are
2611complex.  For example,
2612
2613     (%i1) legendre_p (10, 2 + 3.0*%i);
2614     (%o1) interval(- 3.876378825E+7 %i - 6.0787748E+7,
2615                                                1.2089173052721777E-6)
2616
2617Let's compare this to the true value.
2618
2619     (%i1) float (expand (legendre_p (10, 2 + 3*%i)));
2620     (%o1)          - 3.876378825E+7 %i - 6.0787748E+7
2621
2622Additionally, when the arguments are big floats, the special floating
2623point routines get called; however, the big floats are converted into
2624double floats and the final result is a double.
2625
2626     (%i1) ultraspherical (150, 0.5b0, 0.9b0);
2627     (%o1) interval(- 0.043009481257265, 3.3750051301228864E-14)
2628
262965.1.4 Graphics and 'orthopoly'
2630-------------------------------
2631
2632To plot expressions that involve the orthogonal polynomials, you must do
2633two things:
2634  1. Set the option variable 'orthopoly_returns_intervals' to 'false',
2635  2. Quote any calls to 'orthopoly' functions.
2636
2637If function calls aren't quoted, Maxima evaluates them to polynomials
2638before plotting; consequently, the specialized floating point code
2639doesn't get called.  Here is an example of how to plot an expression
2640that involves a Legendre polynomial.
2641
2642     (%i1) plot2d ('(legendre_p (5, x)), [x, 0, 1]),
2643                             orthopoly_returns_intervals : false;
2644     (%o1)
2645
2646The entire expression 'legendre_p (5, x)' is quoted; this is different
2647than just quoting the function name using ''legendre_p (5, <x>)'.
2648
264965.1.5 Miscellaneous Functions
2650------------------------------
2651
2652The 'orthopoly' package defines the Pochhammer symbol and a unit step
2653function.  'orthopoly' uses the Kronecker delta function and the unit
2654step function in 'gradef' statements.
2655
2656To convert Pochhammer symbols into quotients of gamma functions, use
2657'makegamma'.
2658
2659     (%i1) makegamma (pochhammer (x, n));
2660                               gamma(x + n)
2661     (%o1)                     ------------
2662                                 gamma(x)
2663     (%i2) makegamma (pochhammer (1/2, 1/2));
2664                                     1
2665     (%o2)                       ---------
2666                                 sqrt(%pi)
2667
2668Derivatives of the Pochhammer symbol are given in terms of the 'psi'
2669function.
2670
2671     (%i1) diff (pochhammer (x, n), x);
2672     (%o1)             (x)  (psi (x + n) - psi (x))
2673                          n     0             0
2674     (%i2) diff (pochhammer (x, n), n);
2675     (%o2)                   (x)  psi (x + n)
2676                                n    0
2677
2678You need to be careful with the expression in (%o1); the difference of
2679the 'psi' functions has polynomials when '<x> = -1, -2, .., -<n>'.
2680These polynomials cancel with factors in 'pochhammer (<x>, <n>)' making
2681the derivative a degree '<n> - 1' polynomial when <n> is a positive
2682integer.
2683
2684The Pochhammer symbol is defined for negative orders through its
2685representation as a quotient of gamma functions.  Consider
2686
2687     (%i1) q : makegamma (pochhammer (x, n));
2688                               gamma(x + n)
2689     (%o1)                     ------------
2690                                 gamma(x)
2691     (%i2) sublis ([x=11/3, n= -6], q);
2692                                    729
2693     (%o2)                        - ----
2694                                    2240
2695
2696Alternatively, we can get this result directly.
2697
2698     (%i1) pochhammer (11/3, -6);
2699                                    729
2700     (%o1)                        - ----
2701                                    2240
2702
2703The unit step function is left-continuous; thus
2704
2705     (%i1) [unit_step (-1/10), unit_step (0), unit_step (1/10)];
2706     (%o1)                       [0, 0, 1]
2707
2708If you need a unit step function that is neither left or right
2709continuous at zero, define your own using 'signum', for example,
2710
2711     (%i1) xunit_step (x) := (1 + signum (x))/2$
2712
2713     (%i2) [xunit_step (-1/10), xunit_step (0), xunit_step (1/10)];
2714                                     1
2715     (%o2)                       [0, -, 1]
2716                                     2
2717
2718Do not redefine 'unit_step' itself; some code in 'orthopoly' requires
2719that the unit step function be left-continuous.
2720
272165.1.6 Algorithms
2722-----------------
2723
2724Generally, 'orthopoly' does symbolic evaluation by using a hypergeometic
2725representation of the orthogonal polynomials.  The hypergeometic
2726functions are evaluated using the (undocumented) functions 'hypergeo11'
2727and 'hypergeo21'.  The exceptions are the half-integer Bessel functions
2728and the associated Legendre function of the second kind.  The
2729half-integer Bessel functions are evaluated using an explicit
2730representation, and the associated Legendre function of the second kind
2731is evaluated using recursion.
2732
2733For floating point evaluation, we again convert most functions into a
2734hypergeometic form; we evaluate the hypergeometic functions using
2735forward recursion.  Again, the exceptions are the half-integer Bessel
2736functions and the associated Legendre function of the second kind.
2737Numerically, the half-integer Bessel functions are evaluated using the
2738SLATEC code.
2739
2740
2741File: maxima.info,  Node: Functions and Variables for orthogonal polynomials,  Prev: Introduction to orthogonal polynomials,  Up: orthopoly
2742
274365.2 Functions and Variables for orthogonal polynomials
2744=======================================================
2745
2746 -- Function: assoc_legendre_p (<n>, <m>, <x>)
2747
2748     The associated Legendre function of the first kind of degree <n>
2749     and order <m>.
2750
2751     Reference: Abramowitz and Stegun, equations 22.5.37, page 779,
2752     8.6.6 (second equation), page 334, and 8.2.5, page 333.
2753
2754 -- Function: assoc_legendre_q (<n>, <m>, <x>)
2755
2756     The associated Legendre function of the second kind of degree <n>
2757     and order <m>.
2758
2759     Reference: Abramowitz and Stegun, equation 8.5.3 and 8.1.8.
2760
2761 -- Function: chebyshev_t (<n>, <x>)
2762
2763     The Chebyshev function of the first kind.
2764
2765     Reference: Abramowitz and Stegun, equation 22.5.47, page 779.
2766
2767 -- Function: chebyshev_u (<n>, <x>)
2768
2769     The Chebyshev function of the second kind.
2770
2771     Reference: Abramowitz and Stegun, equation 22.5.48, page 779.
2772
2773 -- Function: gen_laguerre (<n>, <a>, <x>)
2774
2775     The generalized Laguerre polynomial of degree <n>.
2776
2777     Reference: Abramowitz and Stegun, equation 22.5.54, page 780.
2778
2779 -- Function: hermite (<n>, <x>)
2780
2781     The Hermite polynomial.
2782
2783     Reference: Abramowitz and Stegun, equation 22.5.55, page 780.
2784
2785 -- Function: intervalp (<e>)
2786
2787     Return 'true' if the input is an interval and return false if it
2788     isn't.
2789
2790 -- Function: jacobi_p (<n>, <a>, <b>, <x>)
2791
2792     The Jacobi polynomial.
2793
2794     The Jacobi polynomials are actually defined for all <a> and <b>;
2795     however, the Jacobi polynomial weight '(1 - <x>)^<a> (1 + <x>)^<b>'
2796     isn't integrable for '<a> <= -1' or '<b> <= -1'.
2797
2798     Reference: Abramowitz and Stegun, equation 22.5.42, page 779.
2799
2800 -- Function: laguerre (<n>, <x>)
2801
2802     The Laguerre polynomial.
2803
2804     Reference: Abramowitz and Stegun, equations 22.5.16 and 22.5.54,
2805     page 780.
2806
2807 -- Function: legendre_p (<n>, <x>)
2808
2809     The Legendre polynomial of the first kind.
2810
2811     Reference: Abramowitz and Stegun, equations 22.5.50 and 22.5.51,
2812     page 779.
2813
2814 -- Function: legendre_q (<n>, <x>)
2815
2816     The Legendre polynomial of the first kind.
2817
2818     Reference: Abramowitz and Stegun, equations 8.5.3 and 8.1.8.
2819
2820 -- Function: orthopoly_recur (<f>, <args>)
2821
2822     Returns a recursion relation for the orthogonal function family <f>
2823     with arguments <args>.  The recursion is with respect to the
2824     polynomial degree.
2825
2826          (%i1) orthopoly_recur (legendre_p, [n, x]);
2827                          (2 n - 1) P     (x) x + (1 - n) P     (x)
2828                                     n - 1                 n - 2
2829          (%o1)   P (x) = -----------------------------------------
2830                   n                          n
2831
2832     The second argument to 'orthopoly_recur' must be a list with the
2833     correct number of arguments for the function <f>; if it isn't,
2834     Maxima signals an error.
2835
2836          (%i1) orthopoly_recur (jacobi_p, [n, x]);
2837
2838          Function jacobi_p needs 4 arguments, instead it received 2
2839           -- an error.  Quitting.  To debug this try debugmode(true);
2840
2841     Additionally, when <f> isn't the name of one of the families of
2842     orthogonal polynomials, an error is signalled.
2843
2844          (%i1) orthopoly_recur (foo, [n, x]);
2845
2846          A recursion relation for foo isn't known to Maxima
2847           -- an error.  Quitting.  To debug this try debugmode(true);
2848
2849 -- Variable: orthopoly_returns_intervals
2850     Default value: 'true'
2851
2852     When 'orthopoly_returns_intervals' is 'true', floating point
2853     results are returned in the form 'interval (<c>, <r>)', where <c>
2854     is the center of an interval and <r> is its radius.  The center can
2855     be a complex number; in that case, the interval is a disk in the
2856     complex plane.
2857
2858 -- Function: orthopoly_weight (<f>, <args>)
2859
2860     Returns a three element list; the first element is the formula of
2861     the weight for the orthogonal polynomial family <f> with arguments
2862     given by the list <args>; the second and third elements give the
2863     lower and upper endpoints of the interval of orthogonality.  For
2864     example,
2865
2866          (%i1) w : orthopoly_weight (hermite, [n, x]);
2867                                      2
2868                                   - x
2869          (%o1)                 [%e    , - inf, inf]
2870          (%i2) integrate(w[1]*hermite(3, x)*hermite(2, x), x, w[2], w[3]);
2871          (%o2)                           0
2872
2873     The main variable of <f> must be a symbol; if it isn't, Maxima
2874     signals an error.
2875
2876 -- Function: pochhammer (<n>, <x>)
2877
2878     The Pochhammer symbol.  For nonnegative integers <n> with '<n> <=
2879     pochhammer_max_index', the expression 'pochhammer (<x>, <n>)'
2880     evaluates to the product '<x> (<x> + 1) (<x> + 2) ... (<x> + n -
2881     1)' when '<n> > 0' and to 1 when '<n> = 0'.  For negative <n>,
2882     'pochhammer (<x>, <n>)' is defined as '(-1)^<n> / pochhammer (1 -
2883     <x>, -<n>)'.  Thus
2884
2885          (%i1) pochhammer (x, 3);
2886          (%o1)                   x (x + 1) (x + 2)
2887          (%i2) pochhammer (x, -3);
2888                                           1
2889          (%o2)               - -----------------------
2890                                (1 - x) (2 - x) (3 - x)
2891
2892     To convert a Pochhammer symbol into a quotient of gamma functions,
2893     (see Abramowitz and Stegun, equation 6.1.22) use 'makegamma', for
2894     example
2895
2896          (%i1) makegamma (pochhammer (x, n));
2897                                    gamma(x + n)
2898          (%o1)                     ------------
2899                                      gamma(x)
2900
2901     When <n> exceeds 'pochhammer_max_index' or when <n> is symbolic,
2902     'pochhammer' returns a noun form.
2903
2904          (%i1) pochhammer (x, n);
2905          (%o1)                         (x)
2906                                           n
2907
2908 -- Variable: pochhammer_max_index
2909     Default value: 100
2910
2911     'pochhammer (<n>, <x>)' expands to a product if and only if '<n> <=
2912     pochhammer_max_index'.
2913
2914     Examples:
2915
2916          (%i1) pochhammer (x, 3), pochhammer_max_index : 3;
2917          (%o1)                   x (x + 1) (x + 2)
2918          (%i2) pochhammer (x, 4), pochhammer_max_index : 3;
2919          (%o2)                         (x)
2920                                           4
2921
2922     Reference: Abramowitz and Stegun, equation 6.1.16, page 256.
2923
2924 -- Function: spherical_bessel_j (<n>, <x>)
2925
2926     The spherical Bessel function of the first kind.
2927
2928     Reference: Abramowitz and Stegun, equations 10.1.8, page 437 and
2929     10.1.15, page 439.
2930
2931 -- Function: spherical_bessel_y (<n>, <x>)
2932
2933     The spherical Bessel function of the second kind.
2934
2935     Reference: Abramowitz and Stegun, equations 10.1.9, page 437 and
2936     10.1.15, page 439.
2937
2938 -- Function: spherical_hankel1 (<n>, <x>)
2939
2940     The spherical Hankel function of the first kind.
2941
2942     Reference: Abramowitz and Stegun, equation 10.1.36, page 439.
2943
2944 -- Function: spherical_hankel2 (<n>, <x>)
2945
2946     The spherical Hankel function of the second kind.
2947
2948     Reference: Abramowitz and Stegun, equation 10.1.17, page 439.
2949
2950 -- Function: spherical_harmonic (<n>, <m>, <x>, <y>)
2951
2952     The spherical harmonic function.
2953
2954     Reference: Merzbacher 9.64.
2955
2956 -- Function: unit_step (<x>)
2957
2958     The left-continuous unit step function; thus 'unit_step (<x>)'
2959     vanishes for '<x> <= 0' and equals 1 for '<x> > 0'.
2960
2961     If you want a unit step function that takes on the value 1/2 at
2962     zero, use '(1 + signum (<x>))/2'.
2963
2964 -- Function: ultraspherical (<n>, <a>, <x>)
2965
2966     The ultraspherical polynomial (also known as the Gegenbauer
2967     polynomial).
2968
2969     Reference: Abramowitz and Stegun, equation 22.5.46, page 779.
2970
2971
2972File: maxima.info,  Node: plotdf,  Next: romberg,  Prev: orthopoly,  Up: Top
2973
297466 plotdf
2975*********
2976
2977* Menu:
2978
2979* Introduction to plotdf::
2980* Functions and Variables for plotdf::
2981
2982
2983File: maxima.info,  Node: Introduction to plotdf,  Next: Functions and Variables for plotdf,  Prev: plotdf,  Up: plotdf
2984
298566.1 Introduction to plotdf
2986===========================
2987
2988The function 'plotdf' creates a plot of the direction field (also called
2989slope field) for a first-order Ordinary Differential Equation (ODE) or a
2990system of two autonomous first-order ODE's.
2991
2992Plotdf requires Xmaxima.  It can be used from the console or any other
2993interface to Maxima, but the resulting file will be sent to Xmaxima for
2994plotting.  Please make sure you have installed Xmaxima before trying to
2995use plotdf.
2996
2997To plot the direction field of a single ODE, the ODE must be written in
2998the form:
2999
3000            dy
3001            -- = F(x,y)
3002            dx
3003
3004and the function <F> should be given as the argument for 'plotdf'.  If
3005the independent and dependent variables are not <x>, and <y>, as in the
3006equation above, then those two variables should be named explicitly in a
3007list given as an argument to the plotdf command (see the examples).
3008
3009To plot the direction field of a set of two autonomous ODE's, they must
3010be written in the form
3011
3012            dx             dy
3013            -- = G(x,y)    -- = F(x,y)
3014            dt             dt
3015
3016and the argument for 'plotdf' should be a list with the two functions
3017<G> and <F>, in that order; namely, the first expression in the list
3018will be taken to be the time derivative of the variable represented on
3019the horizontal axis, and the second expression will be the time
3020derivative of the variable represented on the vertical axis.  Those two
3021variables do not have to be <x> and <y>, but if they are not, then the
3022second argument given to plotdf must be another list naming the two
3023variables, first the one on the horizontal axis and then the one on the
3024vertical axis.
3025
3026If only one ODE is given, 'plotdf' will implicitly admit 'x=t', and
3027'G(x,y)=1', transforming the non-autonomous equation into a system of
3028two autonomous equations.
3029
3030
3031File: maxima.info,  Node: Functions and Variables for plotdf,  Prev: Introduction to plotdf,  Up: plotdf
3032
303366.2 Functions and Variables for plotdf
3034=======================================
3035
3036 -- Function: plotdf (<dydx>, ... options ...)
3037 -- Function: plotdf (<dvdu>, '['<u>,<v>']', ... options ...)
3038 -- Function: plotdf ('['<dxdt>, <dydt>']', ... options ...)
3039 -- Function: plotdf ('['<dudt>, <dvdt>']', '['<u>, <v>']', ... options
3040          ...)
3041
3042     Displays a direction field in two dimensions <x> and <y>.
3043
3044     <dydx>, <dxdt> and <dydt> are expressions that depend on <x> and
3045     <y>.  <dvdu>, <dudt> and <dvdt> are expressions that depend on <u>
3046     and <v>.  In addition to those two variables, the expressions can
3047     also depend on a set of parameters, with numerical values given
3048     with the 'parameters' option (the option syntax is given below), or
3049     with a range of allowed values specified by a <sliders> option.
3050
3051     Several other options can be given within the command, or selected
3052     in the menu.  Integral curves can be obtained by clicking on the
3053     plot, or with the option 'trajectory_at'.  The direction of the
3054     integration can be controlled with the 'direction' option, which
3055     can have values of _forward_, _backward_ or _both_.  The number of
3056     integration steps is given by 'nsteps' and the time interval
3057     between them is set up with the 'tstep' option.  The Adams Moulton
3058     method is used for the integration; it is also possible to switch
3059     to an adaptive Runge-Kutta 4th order method.
3060
3061     Plot window menu:
3062
3063     The menu in the plot window has the following options: _Zoom_, will
3064     change the behavior of the mouse so that it will allow you to zoom
3065     in on a region of the plot by clicking with the left button.  Each
3066     click near a point magnifies the plot, keeping the center at the
3067     point where you clicked.  Holding the <Shift> key while clicking,
3068     zooms out to the previous magnification.  To resume computing
3069     trajectories when you click on a point, select _Integrate_ from the
3070     menu.
3071
3072     The option _Config_ in the menu can be used to change the ODE(s) in
3073     use and various other settings.  After configuration changes are
3074     made, the menu option _Replot_ should be selected, to activate the
3075     new settings.  If a pair of coordinates are entered in the field
3076     _Trajectory at_ in the _Config_ dialog menu, and the <enter> key is
3077     pressed, a new integral curve will be shown, in addition to the
3078     ones already shown.  When _Replot_ is selected, only the last
3079     integral curve entered will be shown.
3080
3081     Holding the right mouse button down while the cursor is moved, can
3082     be used to drag the plot sideways or up and down.  Additional
3083     parameters such as the number of steps, the initial value of <t>
3084     and the x and y centers and radii, may be set in the Config menu.
3085
3086     A copy of the plot can be saved as a postscript file, using the
3087     menu option _Save_.
3088
3089     Plot options:
3090
3091     The 'plotdf' command may include several commands, each command is
3092     a list of two or more items.  The first item is the name of the
3093     option, and the remainder comprises the value or values assigned to
3094     the option.
3095
3096     The options which are recognized by 'plotdf' are the following:
3097
3098        * "tstep" defines the length of the increments on the
3099          independent variable <t>, used to compute an integral curve.
3100          If only one expression <dydx> is given to 'plotdf', the <x>
3101          variable will be directly proportional to <t>.  The default
3102          value is 0.1.
3103
3104        * "nsteps" defines the number of steps of length 'tstep' that
3105          will be used for the independent variable, to compute an
3106          integral curve.  The default value is 100.
3107
3108        * "direction" defines the direction of the independent variable
3109          that will be followed to compute an integral curve.  Possible
3110          values are 'forward', to make the independent variable
3111          increase 'nsteps' times, with increments 'tstep', 'backward',
3112          to make the independent variable decrease, or 'both' that will
3113          lead to an integral curve that extends 'nsteps' forward, and
3114          'nsteps' backward.  The keywords 'right' and 'left' can be
3115          used as synonyms for 'forward' and 'backward'.  The default
3116          value is 'both'.
3117
3118        * "tinitial" defines the initial value of variable <t> used to
3119          compute integral curves.  Since the differential equations are
3120          autonomous, that setting will only appear in the plot of the
3121          curves as functions of <t>.  The default value is 0.
3122
3123        * "versus_t" is used to create a second plot window, with a plot
3124          of an integral curve, as two functions <x>, <y>, of the
3125          independent variable <t>.  If 'versus_t' is given any value
3126          different from 0, the second plot window will be displayed.
3127          The second plot window includes another menu, similar to the
3128          menu of the main plot window.  The default value is 0.
3129
3130        * "trajectory_at" defines the coordinates <xinitial> and
3131          <yinitial> for the starting point of an integral curve.  The
3132          option is empty by default.
3133
3134        * "parameters" defines a list of parameters, and their numerical
3135          values, used in the definition of the differential equations.
3136          The name and values of the parameters must be given in a
3137          string with a comma-separated sequence of pairs 'name=value'.
3138
3139        * "sliders" defines a list of parameters that will be changed
3140          interactively using slider buttons, and the range of variation
3141          of those parameters.  The names and ranges of the parameters
3142          must be given in a string with a comma-separated sequence of
3143          elements 'name=min:max'
3144
3145        * "xfun" defines a string with semi-colon-separated sequence of
3146          functions of <x> to be displayed, on top of the direction
3147          field.  Those functions will be parsed by Tcl and not by
3148          Maxima.
3149
3150        * "x" should be followed by two numbers, which will set up the
3151          minimum and maximum values shown on the horizontal axis.  If
3152          the variable on the horizontal axis is not <x>, then this
3153          option should have the name of the variable on the horizontal
3154          axis.  The default horizontal range is from -10 to 10.
3155
3156        * "y" should be followed by two numbers, which will set up the
3157          minimum and maximum values shown on the vertical axis.  If the
3158          variable on the vertical axis is not <y>, then this option
3159          should have the name of the variable on the vertical axis.
3160          The default vertical range is from -10 to 10.
3161
3162     Examples:
3163
3164        * To show the direction field of the differential equation y' =
3165          exp(-x) + y and the solution that goes through (2, -0.1):
3166
3167               (%i1) plotdf(exp(-x)+y,[trajectory_at,2,-0.1])$
3168
3169        * To obtain the direction field for the equation diff(y,x) = x -
3170          y^2 and the solution with initial condition y(-1) = 3, we can
3171          use the command:
3172
3173               (%i1) plotdf(x-y^2,[xfun,"sqrt(x);-sqrt(x)"],
3174                        [trajectory_at,-1,3], [direction,forward],
3175                        [y,-5,5], [x,-4,16])$
3176
3177          The graph also shows the function y = sqrt(x).
3178
3179        * The following example shows the direction field of a harmonic
3180          oscillator, defined by the two equations dz/dt = v and dv/dt =
3181          -k*z/m, and the integral curve through (z,v) = (6,0), with a
3182          slider that will allow you to change the value of m
3183          interactively (k is fixed at 2):
3184
3185               (%i1) plotdf([v,-k*z/m], [z,v], [parameters,"m=2,k=2"],
3186                          [sliders,"m=1:5"], [trajectory_at,6,0])$
3187
3188        * To plot the direction field of the Duffing equation,
3189          m*x''+c*x'+k*x+b*x^3 = 0, we introduce the variable y=x' and
3190          use:
3191
3192               (%i1) plotdf([y,-(k*x + c*y + b*x^3)/m],
3193                            [parameters,"k=-1,m=1.0,c=0,b=1"],
3194                            [sliders,"k=-2:2,m=-1:1"],[tstep,0.1])$
3195
3196        * The direction field for a damped pendulum, including the
3197          solution for the given initial conditions, with a slider that
3198          can be used to change the value of the mass m, and with a plot
3199          of the two state variables as a function of time:
3200
3201               (%i1) plotdf([w,-g*sin(a)/l - b*w/m/l], [a,w],
3202                       [parameters,"g=9.8,l=0.5,m=0.3,b=0.05"],
3203                       [trajectory_at,1.05,-9],[tstep,0.01],
3204                       [a,-10,2], [w,-14,14], [direction,forward],
3205                       [nsteps,300], [sliders,"m=0.1:1"], [versus_t,1])$
3206
3207
3208File: maxima.info,  Node: romberg,  Next: simplex,  Prev: plotdf,  Up: Top
3209
321067 romberg
3211**********
3212
3213* Menu:
3214
3215* Functions and Variables for romberg::
3216
3217
3218File: maxima.info,  Node: Functions and Variables for romberg,  Prev: Top,  Up: Top
3219
322067.1 Functions and Variables for romberg
3221========================================
3222
3223 -- Function: romberg (<expr>, <x>, <a>, <b>)
3224 -- Function: romberg (<F>, <a>, <b>)
3225
3226     Computes a numerical integration by Romberg's method.
3227
3228     'romberg(<expr>, <x>, <a>, <b>)' returns an estimate of the
3229     integral 'integrate(<expr>, <x>, <a>, <b>)'.  <expr> must be an
3230     expression which evaluates to a floating point value when <x> is
3231     bound to a floating point value.
3232
3233     'romberg(<F>, <a>, <b>)' returns an estimate of the integral
3234     'integrate(<F>(x), x, <a>, <b>)' where 'x' represents the unnamed,
3235     sole argument of <F>; the actual argument is not named 'x'.  <F>
3236     must be a Maxima or Lisp function which returns a floating point
3237     value when the argument is a floating point value.  <F> may name a
3238     translated or compiled Maxima function.
3239
3240     The accuracy of 'romberg' is governed by the global variables
3241     'rombergabs' and 'rombergtol'.  'romberg' terminates successfully
3242     when the absolute difference between successive approximations is
3243     less than 'rombergabs', or the relative difference in successive
3244     approximations is less than 'rombergtol'.  Thus when 'rombergabs'
3245     is '0.0' (the default) only the relative error test has any effect
3246     on 'romberg'.
3247
3248     'romberg' halves the stepsize at most 'rombergit' times before it
3249     gives up; the maximum number of function evaluations is therefore
3250     '2^rombergit'.  If the error criterion established by 'rombergabs'
3251     and 'rombergtol' is not satisfied, 'romberg' prints an error
3252     message.  'romberg' always makes at least 'rombergmin' iterations;
3253     this is a heuristic intended to prevent spurious termination when
3254     the integrand is oscillatory.
3255
3256     'romberg' repeatedly evaluates the integrand after binding the
3257     variable of integration to a specific value (and not before).  This
3258     evaluation policy makes it possible to nest calls to 'romberg', to
3259     compute multidimensional integrals.  However, the error
3260     calculations do not take the errors of nested integrations into
3261     account, so errors may be underestimated.  Also, methods devised
3262     especially for multidimensional problems may yield the same
3263     accuracy with fewer function evaluations.
3264
3265     'load(romberg)' loads this function.
3266
3267     See also *note Einführung in QUADPACK::, a collection of numerical
3268     integration functions.
3269
3270     Examples:
3271
3272     A 1-dimensional integration.
3273
3274          (%i1) load (romberg);
3275          (%o1)    /usr/share/maxima/5.11.0/share/numeric/romberg.lisp
3276          (%i2) f(x) := 1/((x - 1)^2 + 1/100) + 1/((x - 2)^2 + 1/1000)
3277                        + 1/((x - 3)^2 + 1/200);
3278                              1                 1                1
3279          (%o2) f(x) := -------------- + --------------- + --------------
3280                               2    1           2    1            2    1
3281                        (x - 1)  + ---   (x - 2)  + ----   (x - 3)  + ---
3282                                   100              1000              200
3283          (%i3) rombergtol : 1e-6;
3284          (%o3)                 9.9999999999999995E-7
3285          (%i4) rombergit : 15;
3286          (%o4)                          15
3287          (%i5) estimate : romberg (f(x), x, -5, 5);
3288          (%o5)                   173.6730736617464
3289          (%i6) exact : integrate (f(x), x, -5, 5);
3290          (%o6) 10 sqrt(10) atan(70 sqrt(10))
3291           + 10 sqrt(10) atan(30 sqrt(10)) + 10 sqrt(2) atan(80 sqrt(2))
3292           + 10 sqrt(2) atan(20 sqrt(2)) + 10 atan(60) + 10 atan(40)
3293          (%i7) abs (estimate - exact) / exact, numer;
3294          (%o7)                7.5527060865060088E-11
3295
3296     A 2-dimensional integration, implemented by nested calls to
3297     'romberg'.
3298
3299          (%i1) load (romberg);
3300          (%o1)    /usr/share/maxima/5.11.0/share/numeric/romberg.lisp
3301          (%i2) g(x, y) := x*y / (x + y);
3302                                              x y
3303          (%o2)                   g(x, y) := -----
3304                                             x + y
3305          (%i3) rombergtol : 1e-6;
3306          (%o3)                 9.9999999999999995E-7
3307          (%i4) estimate : romberg (romberg (g(x, y), y, 0, x/2), x, 1, 3);
3308          (%o4)                   0.81930239628356
3309          (%i5) assume (x > 0);
3310          (%o5)                        [x > 0]
3311          (%i6) integrate (integrate (g(x, y), y, 0, x/2), x, 1, 3);
3312                                                    3
3313                                              2 log(-) - 1
3314                              9                     2        9
3315          (%o6)       - 9 log(-) + 9 log(3) + ------------ + -
3316                              2                    6         2
3317          (%i7) exact : radcan (%);
3318                              26 log(3) - 26 log(2) - 13
3319          (%o7)             - --------------------------
3320                                          3
3321          (%i8) abs (estimate - exact) / exact, numer;
3322          (%o8)                1.3711979871851024E-10
3323
3324 -- Option variable: rombergabs
3325     Default value: '0.0'
3326
3327     The accuracy of 'romberg' is governed by the global variables
3328     'rombergabs' and 'rombergtol'.  'romberg' terminates successfully
3329     when the absolute difference between successive approximations is
3330     less than 'rombergabs', or the relative difference in successive
3331     approximations is less than 'rombergtol'.  Thus when 'rombergabs'
3332     is '0.0' (the default) only the relative error test has any effect
3333     on 'romberg'.
3334
3335     See also 'rombergit' and 'rombergmin'.
3336
3337 -- Option variable: rombergit
3338     Default value: '11'
3339
3340     'romberg' halves the stepsize at most 'rombergit' times before it
3341     gives up; the maximum number of function evaluations is therefore
3342     '2^rombergit'.  'romberg' always makes at least 'rombergmin'
3343     iterations; this is a heuristic intended to prevent spurious
3344     termination when the integrand is oscillatory.
3345
3346     See also 'rombergabs' and 'rombergtol'.
3347
3348 -- Option variable: rombergmin
3349     Default value: '0'
3350
3351     'romberg' always makes at least 'rombergmin' iterations; this is a
3352     heuristic intended to prevent spurious termination when the
3353     integrand is oscillatory.
3354
3355     See also 'rombergit', 'rombergabs', and 'rombergtol'.
3356
3357 -- Option variable: rombergtol
3358     Default value: '1e-4'
3359
3360     The accuracy of 'romberg' is governed by the global variables
3361     'rombergabs' and 'rombergtol'.  'romberg' terminates successfully
3362     when the absolute difference between successive approximations is
3363     less than 'rombergabs', or the relative difference in successive
3364     approximations is less than 'rombergtol'.  Thus when 'rombergabs'
3365     is '0.0' (the default) only the relative error test has any effect
3366     on 'romberg'.
3367
3368     See also 'rombergit' and 'rombergmin'.
3369
3370
3371File: maxima.info,  Node: simplex,  Next: simplification,  Prev: romberg,  Up: Top
3372
337368 simplex
3374**********
3375
3376* Menu:
3377
3378* Introduction to simplex::
3379* Functions and Variables for simplex::
3380
3381
3382File: maxima.info,  Node: Introduction to simplex,  Next: Functions and Variables for simplex,  Prev: simplex,  Up: simplex
3383
338468.1 Introduction to simplex
3385============================
3386
3387'simplex' is a package for linear optimization using the simplex
3388algorithm.
3389
3390Example:
3391
3392     (%i1) load("simplex")$
3393     (%i2) minimize_lp(x+y, [3*x+2*y>2, x+4*y>3]);
3394                       9        7       1
3395     (%o2)            [--, [y = --, x = -]]
3396                       10       10      5
3397
3398
3399File: maxima.info,  Node: Functions and Variables for simplex,  Prev: Introduction to simplex,  Up: simplex
3400
340168.2 Functions and Variables for simplex
3402========================================
3403
3404 -- Option variable: epsilon_lp
3405     Default value: '10^-8'
3406
3407     Epsilon used for numerical computations in 'linear_program'.
3408
3409     See also: 'linear_program'.
3410
3411 -- Function: linear_program (<A>, <b>, <c>)
3412
3413     'linear_program' is an implementation of the simplex algorithm.
3414     'linear_program(A, b, c)' computes a vector <x> for which 'c.x' is
3415     minimum possible among vectors for which 'A.x = b' and 'x >= 0'.
3416     Argument <A> is a matrix and arguments <b> and <c> are lists.
3417
3418     'linear_program' returns a list which contains the minimizing
3419     vector <x> and the minimum value 'c.x'.  If the problem is not
3420     bounded, it returns "Problem not bounded!"  and if the problem is
3421     not feasible, it returns "Problem not feasible!".
3422
3423     To use this function first load the 'simplex' package with
3424     'load(simplex);'.
3425
3426     Example:
3427
3428          (%i2) A: matrix([1,1,-1,0], [2,-3,0,-1], [4,-5,0,0])$
3429          (%i3) b: [1,1,6]$
3430          (%i4) c: [1,-2,0,0]$
3431          (%i5) linear_program(A, b, c);
3432                             13     19        3
3433          (%o5)            [[--, 4, --, 0], - -]
3434                             2      2         2
3435
3436     See also: 'minimize_lp', 'scale_lp', and 'epsilon_lp'.
3437
3438 -- Function: maximize_lp (<obj>, <cond>, [<pos>])
3439
3440     Maximizes linear objective function <obj> subject to some linear
3441     constraints <cond>.  See 'minimize_lp' for detailed description of
3442     arguments and return value.
3443
3444     See also: 'minimize_lp'.
3445
3446 -- Function: minimize_lp (<obj>, <cond>, [<pos>])
3447
3448     Minimizes a linear objective function <obj> subject to some linear
3449     constraints <cond>.  <cond> a list of linear equations or
3450     inequalities.  In strict inequalities '>' is replaced by '>=' and
3451     '<' by '<='.  The optional argument <pos> is a list of decision
3452     variables which are assumed to be positive.
3453
3454     If the minimum exists, 'minimize_lp' returns a list which contains
3455     the minimum value of the objective function and a list of decision
3456     variable values for which the minimum is attained.  If the problem
3457     is not bounded, 'minimize_lp' returns "Problem not bounded!"  and
3458     if the problem is not feasible, it returns "Ploblem not feasible!".
3459
3460     The decision variables are not assumed to be nonegative by default.
3461     If all decision variables are nonegative, set 'nonegative_lp' to
3462     'true'.  If only some of decision variables are positive, list them
3463     in the optional argument <pos> (note that this is more efficient
3464     than adding constraints).
3465
3466     'minimize_lp' uses the simplex algorithm which is implemented in
3467     maxima 'linear_program' function.
3468
3469     To use this function first load the 'simplex' package with
3470     'load(simplex);'.
3471
3472     Examples:
3473
3474          (%i1) minimize_lp(x+y, [3*x+y=0, x+2*y>2]);
3475                                4       6        2
3476          (%o1)                [-, [y = -, x = - -]]
3477                                5       5        5
3478          (%i2) minimize_lp(x+y, [3*x+y>0, x+2*y>2]), nonegative_lp=true;
3479          (%o2)                [1, [y = 1, x = 0]]
3480          (%i3) minimize_lp(x+y, [3*x+y=0, x+2*y>2]), nonegative_lp=true;
3481          (%o3)                Problem not feasible!
3482          (%i4) minimize_lp(x+y, [3*x+y>0]);
3483          (%o4)                Problem not bounded!
3484
3485     See also: 'maximize_lp', 'nonegative_lp', 'epsilon_lp'.
3486
3487 -- Option variable: nonegative_lp
3488     Default value: 'false'
3489
3490     If 'nonegative_lp' is true all decision variables to 'minimize_lp'
3491     and 'maximize_lp' are assumed to be positive.
3492
3493     See also: 'minimize_lp'.
3494
3495
3496File: maxima.info,  Node: simplification,  Next: solve_rec,  Prev: simplex,  Up: Top
3497
349869 simplification
3499*****************
3500
3501* Menu:
3502
3503* Introduction to simplification::
3504* Package absimp::
3505* Package facexp::
3506* Package functs::
3507* Package ineq::
3508* Package rducon::
3509* Package scifac::
3510* Package sqdnst::
3511
3512
3513File: maxima.info,  Node: Introduction to simplification,  Next: Package absimp,  Prev: simplification,  Up: simplification
3514
351569.1 Introduction to simplification
3516===================================
3517
3518The directory 'maxima/share/simplification' contains several scripts
3519which implement simplification rules and functions, and also some
3520functions not related to simplification.
3521
3522
3523File: maxima.info,  Node: Package absimp,  Next: Package facexp,  Prev: Introduction to simplification,  Up: simplification
3524
352569.2 Package absimp
3526===================
3527
3528The 'absimp' package contains pattern-matching rules that extend the
3529built-in simplification rules for the 'abs' and 'signum' functions.
3530'absimp' respects relations established with the built-in 'assume'
3531function and by declarations such as 'modedeclare (m, even, n, odd)' for
3532even or odd integers.
3533
3534'absimp' defines 'unitramp' and 'unitstep' functions in terms of 'abs'
3535and 'signum'.
3536
3537'load(absimp)' loads this package.  'demo(absimp)' shows a demonstration
3538of this package.
3539
3540Examples:
3541
3542     (%i1) load (absimp)$
3543     (%i2) (abs (x))^2;
3544                                            2
3545     (%o2)                                 x
3546     (%i3) diff (abs (x), x);
3547                                           x
3548     (%o3)                               ------
3549                                         abs(x)
3550     (%i4) cosh (abs (x));
3551     (%o4)                               cosh(x)
3552
3553
3554File: maxima.info,  Node: Package facexp,  Next: Package functs,  Prev: Package absimp,  Up: simplification
3555
355669.3 Package facexp
3557===================
3558
3559The 'facexp' package contains several related functions that provide the
3560user with the ability to structure expressions by controlled expansion.
3561This capability is especially useful when the expression contains
3562variables that have physical meaning, because it is often true that the
3563most economical form of such an expression can be obtained by fully
3564expanding the expression with respect to those variables, and then
3565factoring their coefficients.  While it is true that this procedure is
3566not difficult to carry out using standard Maxima functions, additional
3567fine-tuning may also be desirable, and these finishing touches can be
3568more difficult to apply.
3569
3570The function 'facsum' and its related forms provide a convenient means
3571for controlling the structure of expressions in this way.  Another
3572function, 'collectterms', can be used to add two or more expressions
3573that have already been simplified to this form, without resimplifying
3574the whole expression again.  This function may be useful when the
3575expressions are very large.
3576
3577'load(facexp)' loads this package.  'demo(facexp)' shows a demonstration
3578of this package.
3579
3580 -- Function: facsum (<expr>, <arg_1>, ..., <arg_n>)
3581
3582     Returns a form of <expr> which depends on the arguments <arg_1>,
3583     ..., <arg_n>.  The arguments can be any form suitable for
3584     'ratvars', or they can be lists of such forms.  If the arguments
3585     are not lists, then the form returned is fully expanded with
3586     respect to the arguments, and the coefficients of the arguments are
3587     factored.  These coefficients are free of the arguments, except
3588     perhaps in a non-rational sense.
3589
3590     If any of the arguments are lists, then all such lists are combined
3591     into a single list, and instead of calling 'factor' on the
3592     coefficients of the arguments, 'facsum' calls itself on these
3593     coefficients, using this newly constructed single list as the new
3594     argument list for this recursive call.  This process can be
3595     repeated to arbitrary depth by nesting the desired elements in
3596     lists.
3597
3598     It is possible that one may wish to 'facsum' with respect to more
3599     complicated subexpressions, such as 'log(x + y)'.  Such arguments
3600     are also permissible.
3601
3602     Occasionally the user may wish to obtain any of the above forms for
3603     expressions which are specified only by their leading operators.
3604     For example, one may wish to 'facsum' with respect to all 'log''s.
3605     In this situation, one may include among the arguments either the
3606     specific 'log''s which are to be treated in this way, or
3607     alternatively, either the expression 'operator (log)' or ''operator
3608     (log)'.  If one wished to 'facsum' the expression <expr> with
3609     respect to the operators <op_1>, ..., <op_n>, one would evaluate
3610     'facsum (<expr>, operator (<op_1>, ..., <op_n>))'.  The 'operator'
3611     form may also appear inside list arguments.
3612
3613     In addition, the setting of the switches 'facsum_combine' and
3614     'nextlayerfactor' may affect the result of 'facsum'.
3615
3616 -- Global variable: nextlayerfactor
3617     Default value: 'false'
3618
3619     When 'nextlayerfactor' is 'true', recursive calls of 'facsum' are
3620     applied to the factors of the factored form of the coefficients of
3621     the arguments.
3622
3623     When 'false', 'facsum' is applied to each coefficient as a whole
3624     whenever recusive calls to 'facsum' occur.
3625
3626     Inclusion of the atom 'nextlayerfactor' in the argument list of
3627     'facsum' has the effect of 'nextlayerfactor: true', but for the
3628     next level of the expression only.  Since 'nextlayerfactor' is
3629     always bound to either 'true' or 'false', it must be presented
3630     single-quoted whenever it appears in the argument list of 'facsum'.
3631
3632 -- Global variable: facsum_combine
3633     Default value: 'true'
3634
3635     'facsum_combine' controls the form of the final result returned by
3636     'facsum' when its argument is a quotient of polynomials.  If
3637     'facsum_combine' is 'false' then the form will be returned as a
3638     fully expanded sum as described above, but if 'true', then the
3639     expression returned is a ratio of polynomials, with each polynomial
3640     in the form described above.
3641
3642     The 'true' setting of this switch is useful when one wants to
3643     'facsum' both the numerator and denominator of a rational
3644     expression, but does not want the denominator to be multiplied
3645     through the terms of the numerator.
3646
3647 -- Function: factorfacsum (<expr>, <arg_1>, ... <arg_n>)
3648
3649     Returns a form of <expr> which is obtained by calling 'facsum' on
3650     the factors of <expr> with <arg_1>, ... <arg_n> as arguments.  If
3651     any of the factors of <expr> is raised to a power, both the factor
3652     and the exponent will be processed in this way.
3653
3654 -- Function: collectterms (<expr>, <arg_1>, ..., <arg_n>)
3655
3656     If several expressions have been simplified with the following
3657     functions: 'facsum', 'factorfacsum', 'factenexpand', 'facexpten' or
3658     'factorfacexpten', and they are to be added together, it may be
3659     desirable to combine them using the function 'collecterms'.
3660     'collecterms' can take as arguments all of the arguments that can
3661     be given to these other associated functions with the exception of
3662     'nextlayerfactor', which has no effect on 'collectterms'.  The
3663     advantage of 'collectterms' is that it returns a form similar to
3664     'facsum', but since it is adding forms that have already been
3665     processed by 'facsum', it does not need to repeat that effort.
3666     This capability is especially useful when the expressions to be
3667     summed are very large.
3668
3669
3670File: maxima.info,  Node: Package functs,  Next: Package ineq,  Prev: Package facexp,  Up: simplification
3671
367269.4 Package functs
3673===================
3674
3675 -- Function: rempart (<expr>, <n>)
3676
3677     Removes part <n> from the expression <expr>.
3678
3679     If <n> is a list of the form '[<l>, <m>]' then parts <l> thru <m>
3680     are removed.
3681
3682     To use this function write first 'load(functs)'.
3683
3684 -- Function: wronskian ([<f_1>, ..., <f_n>], <x>)
3685
3686     Returns the Wronskian matrix of the list of expressions [<f_1>,
3687     ..., <f_n>] in the variable <x>.  The determinant of the Wronskian
3688     matrix is the Wronskian determinant of the list of expressions.
3689
3690     To use 'wronskian', first 'load(functs)'.  Example:
3691
3692          (%i1) load(functs)$
3693          (%i2) wronskian([f(x), g(x)],x);
3694          (%o2) matrix([f(x),g(x)],['diff(f(x),x,1),'diff(g(x),x,1)])
3695
3696 -- Function: tracematrix (<M>)
3697
3698     Returns the trace (sum of the diagonal elements) of matrix <M>.
3699
3700     To use this function write first 'load(functs)'.
3701
3702 -- Function: rational ('z')
3703
3704     Multiplies numerator and denominator of <z> by the complex
3705     conjugate of denominator, thus rationalizing the denominator.
3706     Returns canonical rational expression (CRE) form if given one, else
3707     returns general form.
3708
3709     To use this function write first 'load(functs)'.
3710
3711 -- Function: nonzeroandfreeof (<x>, <expr>)
3712
3713     Returns 'true' if <expr> is nonzero and 'freeof (<x>, <expr>)'
3714     returns 'true'.  Returns 'false' otherwise.
3715
3716     To use this function write first 'load(functs)'.
3717
3718 -- Function: linear (<expr>, <x>)
3719
3720     When <expr> is an expression linear in variable <x>, 'linear'
3721     returns '<a>*<x> + <b>' where <a> is nonzero, and <a> and <b> are
3722     free of <x>.  Otherwise, 'linear' returns <expr>.
3723
3724     To use this function write first 'load(functs)'.
3725
3726 -- Function: gcdivide (<p>, <q>)
3727
3728     When the option variable 'takegcd' is 'true' which is the default,
3729     'gcdivide' divides the polynomials <p> and <q> by their greatest
3730     common divisor and returns the ratio of the results.  'gcdivde'
3731     calls the function 'ezgcd' to divide the polynomials by the
3732     greatest common divisor.
3733
3734     When 'takegcd' is 'false', 'gcdivide' returns the ratio '<p>/<q>'.
3735
3736     To use this function write first 'load(functs)'.
3737
3738     See also 'ezgcd', 'gcd', 'gcdex', and 'poly_gcd'.
3739
3740     Example:
3741
3742          (%i1) load(functs)$
3743
3744          (%i2) p1:6*x^3+19*x^2+19*x+6;
3745                                  3       2
3746          (%o2)                6 x  + 19 x  + 19 x + 6
3747          (%i3) p2:6*x^5+13*x^4+12*x^3+13*x^2+6*x;
3748                            5       4       3       2
3749          (%o3)          6 x  + 13 x  + 12 x  + 13 x  + 6 x
3750          (%i4) gcdivide(p1, p2);
3751                                       x + 1
3752          (%o4)                        ------
3753                                        3
3754                                       x  + x
3755          (%i5) takegcd:false;
3756          (%o5)                         false
3757          (%i6) gcdivide(p1, p2);
3758                                 3       2
3759                              6 x  + 19 x  + 19 x + 6
3760          (%o6)          ----------------------------------
3761                            5       4       3       2
3762                         6 x  + 13 x  + 12 x  + 13 x  + 6 x
3763          (%i7) ratsimp(%);
3764                                       x + 1
3765          (%o7)                        ------
3766                                        3
3767                                       x  + x
3768
3769 -- Function: arithmetic (<a>, <d>, <n>)
3770
3771     Returns the <n>-th term of the arithmetic series '<a>, <a> + <d>,
3772     <a> + 2*<d>, ..., <a> + (<n> - 1)*<d>'.
3773
3774     To use this function write first 'load(functs)'.
3775
3776 -- Function: geometric (<a>, <r>, <n>)
3777
3778     Returns the <n>-th term of the geometric series '<a>, <a>*<r>,
3779     <a>*<r>^2, ..., <a>*<r>^(<n> - 1)'.
3780
3781     To use this function write first 'load(functs)'.
3782
3783 -- Function: harmonic (<a>, <b>, <c>, <n>)
3784
3785     Returns the <n>-th term of the harmonic series '<a>/<b>, <a>/(<b> +
3786     <c>), <a>/(<b> + 2*<c>), ..., <a>/(<b> + (<n> - 1)*<c>)'.
3787
3788     To use this function write first 'load(functs)'.
3789
3790 -- Function: arithsum (<a>, <d>, <n>)
3791
3792     Returns the sum of the arithmetic series from 1 to <n>.
3793
3794     To use this function write first 'load(functs)'.
3795
3796 -- Function: geosum (<a>, <r>, <n>)
3797
3798     Returns the sum of the geometric series from 1 to <n>.  If <n> is
3799     infinity ('inf') then a sum is finite only if the absolute value of
3800     <r> is less than 1.
3801
3802     To use this function write first 'load(functs)'.
3803
3804 -- Function: gaussprob (<x>)
3805
3806     Returns the Gaussian probability function '%e^(-<x>^2/2) /
3807     sqrt(2*%pi)'.
3808
3809     To use this function write first 'load(functs)'.
3810
3811 -- Function: gd (<x>)
3812
3813     Returns the Gudermannian function '2*atan(%e^x)-%pi/2'.
3814
3815     To use this function write first 'load(functs)'.
3816
3817 -- Function: agd (<x>)
3818
3819     Returns the inverse Gudermannian function 'log (tan (%pi/4 +
3820     x/2)))'.
3821
3822     To use this function write first 'load(functs)'.
3823
3824 -- Function: vers (<x>)
3825
3826     Returns the versed sine '1 - cos (x)'.
3827
3828     To use this function write first 'load(functs)'.
3829
3830 -- Function: covers (<x>)
3831
3832     Returns the coversed sine '1 - sin (<x>)'.
3833
3834     To use this function write first 'load(functs)'.
3835
3836 -- Function: exsec (<x>)
3837
3838     Returns the exsecant 'sec (<x>) - 1'.
3839
3840     To use this function write first 'load(functs)'.
3841
3842 -- Function: hav (<x>)
3843
3844     Returns the haversine '(1 - cos(x))/2'.
3845
3846     To use this function write first 'load(functs)'.
3847
3848 -- Function: combination (<n>, <r>)
3849
3850     Returns the number of combinations of <n> objects taken <r> at a
3851     time.
3852
3853     To use this function write first 'load(functs)'.
3854
3855 -- Function: permutation (<n>, <r>)
3856
3857     Returns the number of permutations of <r> objects selected from a
3858     set of <n> objects.
3859
3860     To use this function write first 'load(functs)'.
3861
3862
3863File: maxima.info,  Node: Package ineq,  Next: Package rducon,  Prev: Package functs,  Up: simplification
3864
386569.5 Package ineq
3866=================
3867
3868The 'ineq' package contains simplification rules for inequalities.
3869
3870Example session:
3871
3872     (%i1) load(ineq)$
3873     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
3874     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
3875     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
3876     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
3877     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
3878     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
3879     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
3880     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
3881     (%i2) a>=4;  /* a sample inequality */
3882     (%o2)                               a >= 4
3883     (%i3) (b>c)+%; /* add a second, strict inequality */
3884     (%o3)                            b + a > c + 4
3885     (%i4) 7*(x<y); /* multiply by a positive number */
3886     (%o4)                              7 x < 7 y
3887     (%i5) -2*(x>=3*z); /* multiply by a negative number */
3888     (%o5)                           - 2 x <= - 6 z
3889     (%i6) (1+a^2)*(1/(1+a^2)<=1); /* Maxima knows that 1+a^2 > 0 */
3890                                             2
3891     (%o6)                             1 <= a  + 1
3892     (%i7) assume(x>0)$ x*(2<3); /* assuming x>0 */
3893     (%o7)                              2 x < 3 x
3894     (%i8) a>=b; /* another inequality */
3895     (%o8)                               a >= b
3896     (%i9) 3+%; /* add something */
3897     (%o9)                           a + 3 >= b + 3
3898     (%i10) %-3; /* subtract it out */
3899     (%o10)                              a >= b
3900     (%i11) a>=c-b; /* yet another inequality */
3901     (%o11)                            a >= c - b
3902     (%i12) b+%; /* add b to both sides */
3903     (%o12)                            b + a >= c
3904     (%i13) %-c; /* subtract c from both sides */
3905     (%o13)                         - c + b + a >= 0
3906     (%i14) -%;  /* multiply by -1 */
3907     (%o14)                          c - b - a <= 0
3908     (%i15) (z-1)^2>-2*z; /* determining truth of assertion */
3909                                           2
3910     (%o15)                         (z - 1)  > - 2 z
3911     (%i16) expand(%)+2*z; /* expand this and add 2*z to both sides */
3912                                        2
3913     (%o16)                            z  + 1 > 0
3914     (%i17) %,pred;
3915     (%o17)                               true
3916
3917Be careful about using parentheses around the inequalities: when the
3918user types in '(A > B) + (C = 5)' the result is 'A + C > B + 5', but 'A
3919> B + C = 5' is a syntax error, and '(A > B + C) = 5' is something else
3920entirely.
3921
3922Do 'disprule (all)' to see a complete listing of the rule definitions.
3923
3924The user will be queried if Maxima is unable to decide the sign of a
3925quantity multiplying an inequality.
3926
3927The most common mis-feature is illustrated by:
3928
3929     (%i1) eq: a > b;
3930     (%o1)                              a > b
3931     (%i2) 2*eq;
3932     (%o2)                            2 (a > b)
3933     (%i3) % - eq;
3934     (%o3)                              a > b
3935
3936Another problem is 0 times an inequality; the default to have this turn
3937into 0 has been left alone.  However, if you type 'X*<some_inequality>'
3938and Maxima asks about the sign of 'X' and you respond 'zero' (or 'z'),
3939the program returns 'X*<some_inequality>' and not use the information
3940that 'X' is 0.  You should do 'ev (%, x: 0)' in such a case, as the
3941database will only be used for comparison purposes in decisions, and not
3942for the purpose of evaluating 'X'.
3943
3944The user may note a slower response when this package is loaded, as the
3945simplifier is forced to examine more rules than without the package, so
3946you might wish to remove the rules after making use of them.  Do 'kill
3947(rules)' to eliminate all of the rules (including any that you might
3948have defined); or you may be more selective by killing only some of
3949them; or use 'remrule' on a specific rule.
3950
3951Note that if you load this package after defining your own rules you
3952will clobber your rules that have the same name.  The rules in this
3953package are: '*rule1', ..., '*rule8', '+rule1', ..., '+rule18', and you
3954must enclose the rulename in quotes to refer to it, as in 'remrule ("+",
3955"+rule1")' to specifically remove the first rule on '"+"' or 'disprule
3956("*rule2")' to display the definition of the second multiplicative rule.
3957
3958
3959File: maxima.info,  Node: Package rducon,  Next: Package scifac,  Prev: Package ineq,  Up: simplification
3960
396169.6 Package rducon
3962===================
3963
3964 -- Function: reduce_consts (<expr>)
3965
3966     Replaces constant subexpressions of <expr> with constructed
3967     constant atoms, saving the definition of all these constructed
3968     constants in the list of equations 'const_eqns', and returning the
3969     modified <expr>.  Those parts of <expr> are constant which return
3970     'true' when operated on by the function 'constantp'.  Hence, before
3971     invoking 'reduce_consts', one should do
3972
3973          declare ([<objects to be given the constant property>], constant)$
3974
3975     to set up a database of the constant quantities occurring in your
3976     expressions.
3977
3978     If you are planning to generate Fortran output after these symbolic
3979     calculations, one of the first code sections should be the
3980     calculation of all constants.  To generate this code segment, do
3981
3982          map ('fortran, const_eqns)$
3983
3984     Variables besides 'const_eqns' which affect 'reduce_consts' are:
3985
3986     'const_prefix' (default value: 'xx') is the string of characters
3987     used to prefix all symbols generated by 'reduce_consts' to
3988     represent constant subexpressions.
3989
3990     'const_counter' (default value: 1) is the integer index used to
3991     generate unique symbols to represent each constant subexpression
3992     found by 'reduce_consts'.
3993
3994     'load(rducon)' loads this function.  'demo(rducon)' shows a
3995     demonstration of this function.
3996
3997
3998File: maxima.info,  Node: Package scifac,  Next: Package sqdnst,  Prev: Package rducon,  Up: simplification
3999
400069.7 Package scifac
4001===================
4002
4003 -- Function: gcfac (<expr>)
4004
4005     'gcfac' is a factoring function that attempts to apply the same
4006     heuristics which scientists apply in trying to make expressions
4007     simpler.  'gcfac' is limited to monomial-type factoring.  For a
4008     sum, 'gcfac' does the following:
4009
4010       1. Factors over the integers.
4011       2. Factors out the largest powers of terms occurring as
4012          coefficients, regardless of the complexity of the terms.
4013       3. Uses (1) and (2) in factoring adjacent pairs of terms.
4014       4. Repeatedly and recursively applies these techniques until the
4015          expression no longer changes.
4016
4017     Item (3) does not necessarily do an optimal job of pairwise
4018     factoring because of the combinatorially-difficult nature of
4019     finding which of all possible rearrangements of the pairs yields
4020     the most compact pair-factored result.
4021
4022     'load(scifac)' loads this function.  'demo(scifac)' shows a
4023     demonstration of this function.
4024
4025
4026File: maxima.info,  Node: Package sqdnst,  Prev: Package scifac,  Up: simplification
4027
402869.8 Package sqdnst
4029===================
4030
4031 -- Function: sqrtdenest (<expr>)
4032
4033     Denests 'sqrt' of simple, numerical, binomial surds, where
4034     possible.  E.g.
4035
4036          (%i1) load (sqdnst)$
4037          (%i2) sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
4038                                              sqrt(3)
4039                                         sqrt(------- + 1)
4040                                                 2
4041          (%o2)                        ---------------------
4042                                       sqrt(11 sqrt(2) - 12)
4043          (%i3) sqrtdenest(%);
4044                                            sqrt(3)   1
4045                                            ------- + -
4046                                               2      2
4047          (%o3)                            -------------
4048                                              1/4    3/4
4049                                           3 2    - 2
4050
4051     Sometimes it helps to apply 'sqrtdenest' more than once, on such as
4052     '(19601-13860 sqrt(2))^(7/4)'.
4053
4054     'load(sqdnst)' loads this function.
4055
4056
4057File: maxima.info,  Node: solve_rec,  Next: stats,  Prev: simplification,  Up: Top
4058
405970 solve_rec
4060************
4061
4062* Menu:
4063
4064* Introduction to solve_rec::
4065* Functions and Variables for solve_rec::
4066
4067
4068File: maxima.info,  Node: Introduction to solve_rec,  Next: Functions and Variables for solve_rec,  Prev: solve_rec,  Up: solve_rec
4069
407070.1 Introduction to solve_rec
4071==============================
4072
4073'solve_rec' is a package for solving linear recurrences with polynomial
4074coefficients.
4075
4076A demo is available with 'demo(solve_rec)'.
4077
4078Example:
4079
4080     (%i1) load("solve_rec")$
4081     (%i2) solve_rec((n+4)*s[n+2] + s[n+1] - (n+1)*s[n], s[n]);
4082                                         n
4083                      %k  (2 n + 3) (- 1)          %k
4084                        1                            2
4085     (%o2)       s  = -------------------- + ---------------
4086                  n     (n + 1) (n + 2)      (n + 1) (n + 2)
4087
4088
4089File: maxima.info,  Node: Functions and Variables for solve_rec,  Prev: Introduction to solve_rec,  Up: solve_rec
4090
409170.2 Functions and Variables for solve_rec
4092==========================================
4093
4094 -- Function: reduce_order (<rec>, <sol>, <var>)
4095
4096     Reduces the order of linear recurrence <rec> when a particular
4097     solution <sol> is known.  The reduced reccurence can be used to get
4098     other solutions.
4099
4100     Example:
4101
4102          (%i3) rec: x[n+2] = x[n+1] + x[n]/n;
4103                                                x
4104                                                 n
4105          (%o3)               x      = x      + --
4106                               n + 2    n + 1   n
4107          (%i4) solve_rec(rec, x[n]);
4108          WARNING: found some hypergeometrical solutions!
4109          (%o4)                    x  = %k  n
4110                                    n     1
4111          (%i5) reduce_order(rec, n, x[n]);
4112          (%t5)                    x  = n %z
4113                                    n       n
4114
4115                                     n - 1
4116                                     ====
4117                                     \
4118          (%t6)                %z  =  >     %u
4119                                 n   /        %j
4120                                     ====
4121                                     %j = 0
4122
4123          (%o6)             (- n - 2) %u     - %u
4124                                        n + 1     n
4125          (%i6) solve_rec((n+2)*%u[n+1] + %u[n], %u[n]);
4126                                               n
4127                                      %k  (- 1)
4128                                        1
4129          (%o6)                 %u  = ----------
4130                                  n    (n + 1)!
4131
4132          So the general solution is
4133
4134                       n - 1
4135                       ====        j
4136                       \      (- 1)
4137                 %k  n  >    -------- + %k  n
4138                   2   /     (j + 1)!     1
4139                       ====
4140                       j = 0
4141
4142 -- Option variable: simplify_products
4143     Default value: 'true'
4144
4145     If 'simplify_products' is 'true', 'solve_rec' will try to simplify
4146     products in result.
4147
4148     See also: 'solve_rec'.
4149
4150 -- Function: simplify_sum (<expr>)
4151
4152     Tries to simplify all sums appearing in <expr> to a closed form.
4153
4154     To use this function first load the 'simplify_sum' package with
4155     'load(simplify_sum)'.
4156
4157     Example:
4158
4159          (%i1) load("simplify_sum")$
4160          (%i2) sum(binom(n+k,k)/2^k, k, 0, n)
4161                                       + sum(binom(2*n, 2*k), k, 0, n);
4162                   n                            n
4163                  ====                         ====
4164                  \      binomial(n + k, k)    \
4165          (%o2)    >     ------------------ +   >    binomial(2 n, 2 k)
4166                  /               k            /
4167                  ====           2             ====
4168                  k = 0                        k = 0
4169          (%i3) simplify_sum(%);
4170                                         n
4171                                        4     n
4172          (%o3)                         -- + 2
4173                                        2
4174
4175 -- Function: solve_rec (<eqn>, <var>, [<init>])
4176
4177     Solves for hypergeometrical solutions to linear recurrence <eqn>
4178     with polynomials coefficient in variable <var>.  Optional arguments
4179     <init> are initial conditions.
4180
4181     'solve_rec' can solve linear recurrences with constant
4182     coefficients, finds hypergeometrical solutions to homogeneous
4183     linear recurrences with polynomial coefficients, rational solutions
4184     to linear recurrences with polynomial coefficients and can solve
4185     Ricatti type recurrences.
4186
4187     Note that the running time of the algorithm used to find
4188     hypergeometrical solutions is exponential in the degree of the
4189     leading and trailing coefficient.
4190
4191     To use this function first load the 'solve_rec' package with
4192     'load(solve_rec);'.
4193
4194     Example of linear recurrence with constant coefficients:
4195
4196          (%i2) solve_rec(a[n]=a[n-1]+a[n-2]+n/2^n, a[n]);
4197                                  n          n
4198                     (sqrt(5) - 1)  %k  (- 1)
4199                                      1           n
4200          (%o2) a  = ------------------------- - ----
4201                 n               n                  n
4202                                2                5 2
4203                                                          n
4204                                             (sqrt(5) + 1)  %k
4205                                                              2    2
4206                                           + ------------------ - ----
4207                                                      n              n
4208                                                     2            5 2
4209
4210     Example of linear recurrence with polynomial coefficients:
4211
4212          (%i7) 2*x*(x+1)*y[x] - (x^2+3*x-2)*y[x+1] + (x-1)*y[x+2];
4213                                   2
4214          (%o7) (x - 1) y      - (x  + 3 x - 2) y      + 2 x (x + 1) y
4215                         x + 2                   x + 1                x
4216          (%i8) solve_rec(%, y[x], y[1]=1, y[3]=3);
4217                                        x
4218                                     3 2    x!
4219          (%o9)                 y  = ---- - --
4220                                 x    4     2
4221
4222     Example of Ricatti type recurrence:
4223
4224          (%i2) x*y[x+1]*y[x] - y[x+1]/(x+2) + y[x]/(x-1) = 0;
4225                                      y         y
4226                                       x + 1     x
4227          (%o2)         x y  y      - ------ + ----- = 0
4228                           x  x + 1   x + 2    x - 1
4229          (%i3) solve_rec(%, y[x], y[3]=5)$
4230          (%i4) ratsimp(minfactorial(factcomb(%)));
4231                                             3
4232                                         30 x  - 30 x
4233          (%o4) y  = - -------------------------------------------------
4234                 x        6      5       4       3       2
4235                       5 x  - 3 x  - 25 x  + 15 x  + 20 x  - 12 x - 1584
4236
4237     See also: 'solve_rec_rat', 'simplify_products', and
4238     'product_use_gamma'.
4239
4240 -- Function: solve_rec_rat (<eqn>, <var>, [<init>])
4241
4242     Solves for rational solutions to linear recurrences.  See solve_rec
4243     for description of arguments.
4244
4245     To use this function first load the 'solve_rec' package with
4246     'load(solve_rec);'.
4247
4248     Example:
4249
4250          (%i1) (x+4)*a[x+3] + (x+3)*a[x+2] - x*a[x+1] + (x^2-1)*a[x];
4251          (%o1)  (x + 4) a      + (x + 3) a      - x a
4252                          x + 3            x + 2      x + 1
4253                                                             2
4254                                                         + (x  - 1) a
4255                                                                      x
4256          (%i2) solve_rec_rat(% = (x+2)/(x+1), a[x]);
4257                                 1
4258          (%o2)      a  = ---------------
4259                      x   (x - 1) (x + 1)
4260
4261     See also: 'solve_rec'.
4262
4263 -- Option variable: product_use_gamma
4264     Default value: 'true'
4265
4266     When simplifying products, 'solve_rec' introduces gamma function
4267     into the expression if 'product_use_gamma' is 'true'.
4268
4269     See also: 'simplify_products', 'solve_rec'.
4270
4271 -- Function: summand_to_rec (<summand>, <k>, <n>)
4272 -- Function: summand_to_rec (<summand>, [<k>, <lo>, <hi>], <n>)
4273
4274     Returns the recurrence sattisfied by the sum
4275
4276               hi
4277              ====
4278              \
4279               >     summand
4280              /
4281              ====
4282            k = lo
4283
4284     where summand is hypergeometrical in <k> and <n>.  If <lo> and <hi>
4285     are omited, they are assumed to be 'lo = -inf' and 'hi = inf'.
4286
4287     To use this function first load the 'simplify_sum' package with
4288     'load(simplify_sum)'.
4289
4290     Example:
4291
4292          (%i1) load("simplify_sum")$
4293          (%i2) summand: binom(n,k);
4294          (%o2)                           binomial(n, k)
4295          (%i3) summand_to_rec(summand,k,n);
4296          (%o3)                      2 sm  - sm      = 0
4297                                         n     n + 1
4298          (%i7) summand: binom(n, k)/(k+1);
4299                                          binomial(n, k)
4300          (%o7)                           --------------
4301                                              k + 1
4302          (%i8) summand_to_rec(summand, [k, 0, n], n);
4303          (%o8)               2 (n + 1) sm  - (n + 2) sm      = - 1
4304                                          n             n + 1
4305
4306
4307File: maxima.info,  Node: stats,  Next: stirling,  Prev: solve_rec,  Up: Top
4308
430971 stats
4310********
4311
4312* Menu:
4313
4314* Introduction to stats::
4315* Functions and Variables for inference_result::
4316* Functions and Variables for stats::
4317* Functions and Variables for special distributions::
4318
4319
4320File: maxima.info,  Node: Introduction to stats,  Next: Functions and Variables for inference_result,  Prev: Top,  Up: Top
4321
432271.1 Introduction to stats
4323==========================
4324
4325Package 'stats' contains a set of classical statistical inference and
4326hypothesis testing procedures.
4327
4328All these functions return an 'inference_result' Maxima object which
4329contains the necessary results for population inferences and decision
4330making.
4331
4332Global variable 'stats_numer' controls whether results are given in
4333floating point or symbolic and rational format; its default value is
4334'true' and results are returned in floating point format.
4335
4336Package 'descriptive' contains some utilities to manipulate data
4337structures (lists and matrices); for example, to extract subsamples.  It
4338also contains some examples on how to use package 'numericalio' to read
4339data from plain text files.  See 'descriptive' and 'numericalio' for
4340more details.
4341
4342Package 'stats' loads packages 'descriptive', 'distrib' and
4343'inference_result'.
4344
4345For comments, bugs or suggestions, please contact the author at
4346
4347<'mario AT edu DOT xunta DOT es'>.
4348
4349
4350File: maxima.info,  Node: Functions and Variables for inference_result,  Next: Functions and Variables for stats,  Prev: Introduction to stats,  Up: Top
4351
435271.2 Functions and Variables for inference_result
4353=================================================
4354
4355 -- Function: inference_result (<title>, <values>, <numbers>)
4356
4357     Constructs an 'inference_result' object of the type returned by the
4358     stats functions.  Argument <title> is a string with the name of the
4359     procedure; <values> is a list with elements of the form 'symbol =
4360     value' and <numbers> is a list with positive integer numbers
4361     ranging from one to 'length(<values>)', indicating which values
4362     will be shown by default.
4363
4364     Example:
4365
4366     This is a simple example showing results concerning a rectangle.
4367     The title of this object is the string '"Rectangle"', it stores
4368     five results, named ''base', ''height', ''diagonal', ''area', and
4369     ''perimeter', but only the first, second, fifth, and fourth will be
4370     displayed.  The ''diagonal' is stored in this object, but it is not
4371     displayed; to access its value, make use of function
4372     'take_inference'.
4373
4374          (%i1) load(inference_result)$
4375          (%i2) b: 3$ h: 2$
4376          (%i3) inference_result("Rectangle",
4377                                  ['base=b,
4378                                   'height=h,
4379                                   'diagonal=sqrt(b^2+h^2),
4380                                   'area=b*h,
4381                                   'perimeter=2*(b+h)],
4382                                  [1,2,5,4] );
4383                                  |   Rectangle
4384                                  |
4385                                  |    base = 3
4386                                  |
4387          (%o3)                   |   height = 2
4388                                  |
4389                                  | perimeter = 10
4390                                  |
4391                                  |    area = 6
4392          (%i4) take_inference('diagonal,%);
4393          (%o4)                        sqrt(13)
4394
4395     See also 'take_inference'.
4396
4397 -- Function: inferencep (<obj>)
4398
4399     Returns 'true' or 'false', depending on whether <obj> is an
4400     'inference_result' object or not.
4401
4402 -- Function: items_inference (<obj>)
4403
4404     Returns a list with the names of the items stored in <obj>, which
4405     must be an 'inference_result' object.
4406
4407     Example:
4408
4409     The 'inference_result' object stores two values, named ''pi' and
4410     ''e', but only the second is displayed.  The 'items_inference'
4411     function returns the names of all items, no matter they are
4412     displayed or not.
4413
4414          (%i1) load(inference_result)$
4415          (%i2) inference_result("Hi", ['pi=%pi,'e=%e],[2]);
4416                                      |   Hi
4417          (%o2)                       |
4418                                      | e = %e
4419          (%i3) items_inference(%);
4420          (%o3)                        [pi, e]
4421
4422 -- Function: take_inference (<n>, <obj>)
4423 -- Function: take_inference (<name>, <obj>)
4424 -- Function: take_inference (<list>, <obj>)
4425
4426     Returns the <n>-th value stored in <obj> if <n> is a positive
4427     integer, or the item named <name> if this is the name of an item.
4428     If the first argument is a list of numbers and/or symbols, function
4429     'take_inference' returns a list with the corresponding results.
4430
4431     Example:
4432
4433     Given an 'inference_result' object, function 'take_inference' is
4434     called in order to extract some information stored in it.
4435
4436          (%i1) load(inference_result)$
4437          (%i2) b: 3$ h: 2$
4438          (%i3) sol: inference_result("Rectangle",
4439                                      ['base=b,
4440                                       'height=h,
4441                                       'diagonal=sqrt(b^2+h^2),
4442                                       'area=b*h,
4443                                       'perimeter=2*(b+h)],
4444                                      [1,2,5,4] );
4445                                  |   Rectangle
4446                                  |
4447                                  |    base = 3
4448                                  |
4449          (%o3)                   |   height = 2
4450                                  |
4451                                  | perimeter = 10
4452                                  |
4453                                  |    area = 6
4454          (%i4) take_inference('base,sol);
4455          (%o4)                           3
4456          (%i5) take_inference(5,sol);
4457          (%o5)                          10
4458          (%i6) take_inference([1,'diagonal],sol);
4459          (%o6)                     [3, sqrt(13)]
4460          (%i7) take_inference(items_inference(sol),sol);
4461          (%o7)                [3, 2, sqrt(13), 6, 10]
4462
4463     See also 'inference_result' and 'take_inference'.
4464
4465
4466File: maxima.info,  Node: Functions and Variables for stats,  Next: Functions and Variables for special distributions,  Prev: Functions and Variables for inference_result,  Up: Top
4467
446871.3 Functions and Variables for stats
4469======================================
4470
4471 -- Option variable: stats_numer
4472     Default value: 'true'
4473
4474     If 'stats_numer' is 'true', inference statistical functions return
4475     their results in floating point numbers.  If it is 'false', results
4476     are given in symbolic and rational format.
4477
4478 -- Function: test_mean (<x>)
4479 -- Function: test_mean (<x>, <options> ...)
4480
4481     This is the mean <t>-test.  Argument <x> is a list or a column
4482     matrix containing a one dimensional sample.  It also performs an
4483     asymptotic test based on the Central Limit Theorem if option
4484     ''asymptotic' is 'true'.
4485
4486     Options:
4487
4488        * ''mean', default '0', is the mean value to be checked.
4489
4490        * ''alternative', default ''twosided', is the alternative
4491          hypothesis; valid values are: ''twosided', ''greater' and
4492          ''less'.
4493
4494        * ''dev', default ''unknown', this is the value of the standard
4495          deviation when it is known; valid values are: ''unknown' or a
4496          positive expression.
4497
4498        * ''conflevel', default '95/100', confidence level for the
4499          confidence interval; it must be an expression which takes a
4500          value in (0,1).
4501
4502        * ''asymptotic', default 'false', indicates whether it performs
4503          an exact <t>-test or an asymptotic one based on the Central
4504          Limit Theorem; valid values are 'true' and 'false'.
4505
4506     The output of function 'test_mean' is an 'inference_result' Maxima
4507     object showing the following results:
4508
4509       1. ''mean_estimate': the sample mean.
4510
4511       2. ''conf_level': confidence level selected by the user.
4512
4513       3. ''conf_interval': confidence interval for the population mean.
4514
4515       4. ''method': inference procedure.
4516
4517       5. ''hypotheses': null and alternative hypotheses to be tested.
4518
4519       6. ''statistic': value of the sample statistic used for testing
4520          the null hypothesis.
4521
4522       7. ''distribution': distribution of the sample statistic,
4523          together with its parameter(s).
4524
4525       8. ''p_value': p-value of the test.
4526
4527     Examples:
4528
4529     Performs an exact <t>-test with unknown variance.  The null
4530     hypothesis is H_0: mean=50 against the one sided alternative H_1:
4531     mean<50; according to the results, the p-value is too great, there
4532     are no evidence for rejecting H_0.
4533
4534          (%i1) load("stats")$
4535          (%i2) data: [78,64,35,45,45,75,43,74,42,42]$
4536          (%i3) test_mean(data,'conflevel=0.9,'alternative='less,'mean=50);
4537                    |                 MEAN TEST
4538                    |
4539                    |            mean_estimate = 54.3
4540                    |
4541                    |              conf_level = 0.9
4542                    |
4543                    | conf_interval = [minf, 61.51314273502712]
4544                    |
4545          (%o3)     |  method = Exact t-test. Unknown variance.
4546                    |
4547                    | hypotheses = H0: mean = 50 , H1: mean < 50
4548                    |
4549                    |       statistic = .8244705235071678
4550                    |
4551                    |       distribution = [student_t, 9]
4552                    |
4553                    |        p_value = .7845100411786889
4554
4555     This time Maxima performs an asymptotic test, based on the Central
4556     Limit Theorem.  The null hypothesis is H_0: equal(mean, 50) against
4557     the two sided alternative H_1: not equal(mean, 50); according to
4558     the results, the p-value is very small, H_0 should be rejected in
4559     favor of the alternative H_1.  Note that, as indicated by the
4560     'Method' component, this procedure should be applied to large
4561     samples.
4562
4563          (%i1) load("stats")$
4564          (%i2) test_mean([36,118,52,87,35,256,56,178,57,57,89,34,25,98,35,
4565                        98,41,45,198,54,79,63,35,45,44,75,42,75,45,45,
4566                        45,51,123,54,151],
4567                        'asymptotic=true,'mean=50);
4568                    |                       MEAN TEST
4569                    |
4570                    |           mean_estimate = 74.88571428571429
4571                    |
4572                    |                   conf_level = 0.95
4573                    |
4574                    | conf_interval = [57.72848600856194, 92.04294256286663]
4575                    |
4576          (%o2)     |    method = Large sample z-test. Unknown variance.
4577                    |
4578                    |       hypotheses = H0: mean = 50 , H1: mean # 50
4579                    |
4580                    |             statistic = 2.842831192874313
4581                    |
4582                    |             distribution = [normal, 0, 1]
4583                    |
4584                    |             p_value = .004471474652002261
4585
4586 -- Function: test_means_difference (<x1>, <x2>)
4587 -- Function: test_means_difference (<x1>, <x2>, <options> ...)
4588
4589     This is the difference of means <t>-test for two samples.
4590     Arguments <x1> and <x2> are lists or column matrices containing two
4591     independent samples.  In case of different unknown variances (see
4592     options ''dev1', ''dev2' and ''varequal' bellow), the degrees of
4593     freedom are computed by means of the Welch approximation.  It also
4594     performs an asymptotic test based on the Central Limit Theorem if
4595     option ''asymptotic' is set to 'true'.
4596
4597     Options:
4598
4599        *
4600        * ''alternative', default ''twosided', is the alternative
4601          hypothesis; valid values are: ''twosided', ''greater' and
4602          ''less'.
4603
4604        * ''dev1', default ''unknown', this is the value of the standard
4605          deviation of the <x1> sample when it is known; valid values
4606          are: ''unknown' or a positive expression.
4607
4608        * ''dev2', default ''unknown', this is the value of the standard
4609          deviation of the <x2> sample when it is known; valid values
4610          are: ''unknown' or a positive expression.
4611
4612        * ''varequal', default 'false', whether variances should be
4613          considered to be equal or not; this option takes effect only
4614          when ''dev1' and/or ''dev2' are ''unknown'.
4615
4616        * ''conflevel', default '95/100', confidence level for the
4617          confidence interval; it must be an expression which takes a
4618          value in (0,1).
4619
4620        * ''asymptotic', default 'false', indicates whether it performs
4621          an exact <t>-test or an asymptotic one based on the Central
4622          Limit Theorem; valid values are 'true' and 'false'.
4623
4624     The output of function 'test_means_difference' is an
4625     'inference_result' Maxima object showing the following results:
4626
4627       1. ''diff_estimate': the difference of means estimate.
4628
4629       2. ''conf_level': confidence level selected by the user.
4630
4631       3. ''conf_interval': confidence interval for the difference of
4632          means.
4633
4634       4. ''method': inference procedure.
4635
4636       5. ''hypotheses': null and alternative hypotheses to be tested.
4637
4638       6. ''statistic': value of the sample statistic used for testing
4639          the null hypothesis.
4640
4641       7. ''distribution': distribution of the sample statistic,
4642          together with its parameter(s).
4643
4644       8. ''p_value': p-value of the test.
4645
4646     Examples:
4647
4648     The equality of means is tested with two small samples <x> and <y>,
4649     against the alternative H_1: m_1>m_2, being m_1 and m_2 the
4650     populations means; variances are unknown and supposed to be
4651     different.
4652
4653          (%i1) load("stats")$
4654          (%i2) x: [20.4,62.5,61.3,44.2,11.1,23.7]$
4655          (%i3) y: [1.2,6.9,38.7,20.4,17.2]$
4656          (%i4) test_means_difference(x,y,'alternative='greater);
4657                      |              DIFFERENCE OF MEANS TEST
4658                      |
4659                      |         diff_estimate = 20.31999999999999
4660                      |
4661                      |                 conf_level = 0.95
4662                      |
4663                      |    conf_interval = [- .04597417812882298, inf]
4664                      |
4665          (%o4)       |        method = Exact t-test. Welch approx.
4666                      |
4667                      | hypotheses = H0: mean1 = mean2 , H1: mean1 > mean2
4668                      |
4669                      |           statistic = 1.838004300728477
4670                      |
4671                      |    distribution = [student_t, 8.62758740184604]
4672                      |
4673                      |            p_value = .05032746527991905
4674
4675     The same test as before, but now variances are supposed to be
4676     equal.
4677
4678          (%i1) load("stats")$
4679          (%i2) x: [20.4,62.5,61.3,44.2,11.1,23.7]$
4680          (%i3) y: matrix([1.2],[6.9],[38.7],[20.4],[17.2])$
4681          (%i4) test_means_difference(x,y,'alternative='greater,
4682                                                           'varequal=true);
4683                      |              DIFFERENCE OF MEANS TEST
4684                      |
4685                      |         diff_estimate = 20.31999999999999
4686                      |
4687                      |                 conf_level = 0.95
4688                      |
4689                      |     conf_interval = [- .7722627696897568, inf]
4690                      |
4691          (%o4)       |   method = Exact t-test. Unknown equal variances
4692                      |
4693                      | hypotheses = H0: mean1 = mean2 , H1: mean1 > mean2
4694                      |
4695                      |           statistic = 1.765996124515009
4696                      |
4697                      |           distribution = [student_t, 9]
4698                      |
4699                      |            p_value = .05560320992529344
4700
4701 -- Function: test_variance (<x>)
4702 -- Function: test_variance (<x>, <options>, ...)
4703
4704     This is the variance <chi^2>-test.  Argument <x> is a list or a
4705     column matrix containing a one dimensional sample taken from a
4706     normal population.
4707
4708     Options:
4709
4710        * ''mean', default ''unknown', is the population's mean, when it
4711          is known.
4712
4713        * ''alternative', default ''twosided', is the alternative
4714          hypothesis; valid values are: ''twosided', ''greater' and
4715          ''less'.
4716
4717        * ''variance', default '1', this is the variance value
4718          (positive) to be checked.
4719
4720        * ''conflevel', default '95/100', confidence level for the
4721          confidence interval; it must be an expression which takes a
4722          value in (0,1).
4723
4724     The output of function 'test_variance' is an 'inference_result'
4725     Maxima object showing the following results:
4726
4727       1. ''var_estimate': the sample variance.
4728
4729       2. ''conf_level': confidence level selected by the user.
4730
4731       3. ''conf_interval': confidence interval for the population
4732          variance.
4733
4734       4. ''method': inference procedure.
4735
4736       5. ''hypotheses': null and alternative hypotheses to be tested.
4737
4738       6. ''statistic': value of the sample statistic used for testing
4739          the null hypothesis.
4740
4741       7. ''distribution': distribution of the sample statistic,
4742          together with its parameter.
4743
4744       8. ''p_value': p-value of the test.
4745
4746     Examples:
4747
4748     It is tested whether the variance of a population with unknown mean
4749     is equal to or greater than 200.
4750
4751          (%i1) load("stats")$
4752          (%i2) x: [203,229,215,220,223,233,208,228,209]$
4753          (%i3) test_variance(x,'alternative='greater,'variance=200);
4754                       |                  VARIANCE TEST
4755                       |
4756                       |              var_estimate = 110.75
4757                       |
4758                       |                conf_level = 0.95
4759                       |
4760                       |     conf_interval = [57.13433376937479, inf]
4761                       |
4762          (%o3)        | method = Variance Chi-square test. Unknown mean.
4763                       |
4764                       |    hypotheses = H0: var = 200 , H1: var > 200
4765                       |
4766                       |                 statistic = 4.43
4767                       |
4768                       |             distribution = [chi2, 8]
4769                       |
4770                       |           p_value = .8163948512777689
4771
4772 -- Function: test_variance_ratio (<x1>, <x2>)
4773 -- Function: test_variance_ratio (<x1>, <x2>, <options> ...)
4774
4775     This is the variance ratio <F>-test for two normal populations.
4776     Arguments <x1> and <x2> are lists or column matrices containing two
4777     independent samples.
4778
4779     Options:
4780
4781        * ''alternative', default ''twosided', is the alternative
4782          hypothesis; valid values are: ''twosided', ''greater' and
4783          ''less'.
4784
4785        * ''mean1', default ''unknown', when it is known, this is the
4786          mean of the population from which <x1> was taken.
4787
4788        * ''mean2', default ''unknown', when it is known, this is the
4789          mean of the population from which <x2> was taken.
4790
4791        * ''conflevel', default '95/100', confidence level for the
4792          confidence interval of the ratio; it must be an expression
4793          which takes a value in (0,1).
4794
4795     The output of function 'test_variance_ratio' is an
4796     'inference_result' Maxima object showing the following results:
4797
4798       1. ''ratio_estimate': the sample variance ratio.
4799
4800       2. ''conf_level': confidence level selected by the user.
4801
4802       3. ''conf_interval': confidence interval for the variance ratio.
4803
4804       4. ''method': inference procedure.
4805
4806       5. ''hypotheses': null and alternative hypotheses to be tested.
4807
4808       6. ''statistic': value of the sample statistic used for testing
4809          the null hypothesis.
4810
4811       7. ''distribution': distribution of the sample statistic,
4812          together with its parameters.
4813
4814       8. ''p_value': p-value of the test.
4815
4816     Examples:
4817
4818     The equality of the variances of two normal populations is checked
4819     against the alternative that the first is greater than the second.
4820
4821          (%i1) load("stats")$
4822          (%i2) x: [20.4,62.5,61.3,44.2,11.1,23.7]$
4823          (%i3) y: [1.2,6.9,38.7,20.4,17.2]$
4824          (%i4) test_variance_ratio(x,y,'alternative='greater);
4825                        |              VARIANCE RATIO TEST
4826                        |
4827                        |       ratio_estimate = 2.316933391522034
4828                        |
4829                        |               conf_level = 0.95
4830                        |
4831                        |    conf_interval = [.3703504689507268, inf]
4832                        |
4833          (%o4)         | method = Variance ratio F-test. Unknown means.
4834                        |
4835                        | hypotheses = H0: var1 = var2 , H1: var1 > var2
4836                        |
4837                        |         statistic = 2.316933391522034
4838                        |
4839                        |            distribution = [f, 5, 4]
4840                        |
4841                        |          p_value = .2179269692254457
4842
4843 -- Function: test_proportion (<x>, <n>)
4844 -- Function: test_proportion (<x>, <n>, <options> ...)
4845
4846     Inferences on a proportion.  Argument <x> is the number of
4847     successes in <n> trials in a Bernoulli experiment with unknown
4848     probability.
4849
4850     Options:
4851
4852        * ''proportion', default '1/2', is the value of the proportion
4853          to be checked.
4854
4855        * ''alternative', default ''twosided', is the alternative
4856          hypothesis; valid values are: ''twosided', ''greater' and
4857          ''less'.
4858
4859        * ''conflevel', default '95/100', confidence level for the
4860          confidence interval; it must be an expression which takes a
4861          value in (0,1).
4862
4863        * ''asymptotic', default 'false', indicates whether it performs
4864          an exact test based on the binomial distribution, or an
4865          asymptotic one based on the Central Limit Theorem; valid
4866          values are 'true' and 'false'.
4867
4868        * ''correct', default 'true', indicates whether Yates correction
4869          is applied or not.
4870
4871     The output of function 'test_proportion' is an 'inference_result'
4872     Maxima object showing the following results:
4873
4874       1. ''sample_proportion': the sample proportion.
4875
4876       2. ''conf_level': confidence level selected by the user.
4877
4878       3. ''conf_interval': Wilson confidence interval for the
4879          proportion.
4880
4881       4. ''method': inference procedure.
4882
4883       5. ''hypotheses': null and alternative hypotheses to be tested.
4884
4885       6. ''statistic': value of the sample statistic used for testing
4886          the null hypothesis.
4887
4888       7. ''distribution': distribution of the sample statistic,
4889          together with its parameters.
4890
4891       8. ''p_value': p-value of the test.
4892
4893     Examples:
4894
4895     Performs an exact test.  The null hypothesis is H_0: p=1/2 against
4896     the one sided alternative H_1: p<1/2.
4897
4898          (%i1) load("stats")$
4899          (%i2) test_proportion(45, 103, alternative = less);
4900                   |            PROPORTION TEST
4901                   |
4902                   | sample_proportion = .4368932038834951
4903                   |
4904                   |           conf_level = 0.95
4905                   |
4906                   | conf_interval = [0, 0.522714149150231]
4907                   |
4908          (%o2)    |     method = Exact binomial test.
4909                   |
4910                   | hypotheses = H0: p = 0.5 , H1: p < 0.5
4911                   |
4912                   |             statistic = 45
4913                   |
4914                   |  distribution = [binomial, 103, 0.5]
4915                   |
4916                   |      p_value = .1184509388901454
4917
4918     A two sided asymptotic test.  Confidence level is 99/100.
4919
4920          (%i1) load("stats")$
4921          (%i2) fpprintprec:7$
4922          (%i3) test_proportion(45, 103,
4923                            conflevel = 99/100, asymptotic=true);
4924                |                 PROPORTION TEST
4925                |
4926                |           sample_proportion = .43689
4927                |
4928                |                conf_level = 0.99
4929                |
4930                |        conf_interval = [.31422, .56749]
4931                |
4932          (%o3) | method = Asympthotic test with Yates correction.
4933                |
4934                |     hypotheses = H0: p = 0.5 , H1: p # 0.5
4935                |
4936                |               statistic = .43689
4937                |
4938                |      distribution = [normal, 0.5, .048872]
4939                |
4940                |                p_value = .19662
4941
4942 -- Function: test_proportions_difference (<x1>, <n1>, <x2>, <n2>)
4943 -- Function: test_proportions_difference (<x1>, <n1>, <x2>, <n2>,
4944          <options> ...)
4945
4946     Inferences on the difference of two proportions.  Argument <x1> is
4947     the number of successes in <n1> trials in a Bernoulli experiment in
4948     the first population, and <x2> and <n2> are the corresponding
4949     values in the second population.  Samples are independent and the
4950     test is asymptotic.
4951
4952     Options:
4953
4954        * ''alternative', default ''twosided', is the alternative
4955          hypothesis; valid values are: ''twosided' ('p1 # p2'),
4956          ''greater' ('p1 > p2') and ''less' ('p1 < p2').
4957
4958        * ''conflevel', default '95/100', confidence level for the
4959          confidence interval; it must be an expression which takes a
4960          value in (0,1).
4961
4962        * ''correct', default 'true', indicates whether Yates correction
4963          is applied or not.
4964
4965     The output of function 'test_proportions_difference' is an
4966     'inference_result' Maxima object showing the following results:
4967
4968       1. ''proportions': list with the two sample proportions.
4969
4970       2. ''conf_level': confidence level selected by the user.
4971
4972       3. ''conf_interval': Confidence interval for the difference of
4973          proportions 'p1 - p2'.
4974
4975       4. ''method': inference procedure and warning message in case of
4976          any of the samples sizes is less than 10.
4977
4978       5. ''hypotheses': null and alternative hypotheses to be tested.
4979
4980       6. ''statistic': value of the sample statistic used for testing
4981          the null hypothesis.
4982
4983       7. ''distribution': distribution of the sample statistic,
4984          together with its parameters.
4985
4986       8. ''p_value': p-value of the test.
4987
4988     Examples:
4989
4990     A machine produced 10 defective articles in a batch of 250.  After
4991     some maintenance work, it produces 4 defective in a batch of 150.
4992     In order to know if the machine has improved, we test the null
4993     hypothesis 'H0:p1=p2', against the alternative 'H0:p1>p2', where
4994     'p1' and 'p2' are the probabilities for one produced article to be
4995     defective before and after maintenance.  According to the p value,
4996     there is not enough evidence to accept the alternative.
4997
4998          (%i1) load("stats")$
4999          (%i2) fpprintprec:7$
5000          (%i3) test_proportions_difference(10, 250, 4, 150,
5001                                          alternative = greater);
5002                |       DIFFERENCE OF PROPORTIONS TEST
5003                |
5004                |       proportions = [0.04, .02666667]
5005                |
5006                |              conf_level = 0.95
5007                |
5008                |      conf_interval = [- .02172761, 1]
5009                |
5010          (%o3) | method = Asymptotic test. Yates correction.
5011                |
5012                |   hypotheses = H0: p1 = p2 , H1: p1 > p2
5013                |
5014                |            statistic = .01333333
5015                |
5016                |    distribution = [normal, 0, .01898069]
5017                |
5018                |             p_value = .2411936
5019
5020     Exact standard deviation of the asymptotic normal distribution when
5021     the data are unknown.
5022
5023          (%i1) load("stats")$
5024          (%i2) stats_numer: false$
5025          (%i3) sol: test_proportions_difference(x1,n1,x2,n2)$
5026          (%i4) last(take_inference('distribution,sol));
5027                         1    1                  x2 + x1
5028                        (-- + --) (x2 + x1) (1 - -------)
5029                         n2   n1                 n2 + n1
5030          (%o4)    sqrt(---------------------------------)
5031                                     n2 + n1
5032
5033 -- Function: test_sign (<x>)
5034 -- Function: test_sign (<x>, <options> ...)
5035
5036     This is the non parametric sign test for the median of a continuous
5037     population.  Argument <x> is a list or a column matrix containing a
5038     one dimensional sample.
5039
5040     Options:
5041
5042        * ''alternative', default ''twosided', is the alternative
5043          hypothesis; valid values are: ''twosided', ''greater' and
5044          ''less'.
5045
5046        * ''median', default '0', is the median value to be checked.
5047
5048     The output of function 'test_sign' is an 'inference_result' Maxima
5049     object showing the following results:
5050
5051       1. ''med_estimate': the sample median.
5052
5053       2. ''method': inference procedure.
5054
5055       3. ''hypotheses': null and alternative hypotheses to be tested.
5056
5057       4. ''statistic': value of the sample statistic used for testing
5058          the null hypothesis.
5059
5060       5. ''distribution': distribution of the sample statistic,
5061          together with its parameter(s).
5062
5063       6. ''p_value': p-value of the test.
5064
5065     Examples:
5066
5067     Checks whether the population from which the sample was taken has
5068     median 6, against the alternative H_1: median > 6.
5069
5070          (%i1) load("stats")$
5071          (%i2) x: [2,0.1,7,1.8,4,2.3,5.6,7.4,5.1,6.1,6]$
5072          (%i3) test_sign(x,'median=6,'alternative='greater);
5073                         |                  SIGN TEST
5074                         |
5075                         |              med_estimate = 5.1
5076                         |
5077                         |      method = Non parametric sign test.
5078                         |
5079          (%o3)          | hypotheses = H0: median = 6 , H1: median > 6
5080                         |
5081                         |                statistic = 7
5082                         |
5083                         |      distribution = [binomial, 10, 0.5]
5084                         |
5085                         |         p_value = .05468749999999989
5086
5087 -- Function: test_signed_rank (<x>)
5088 -- Function: test_signed_rank (<x>, <options> ...)
5089
5090     This is the Wilcoxon signed rank test to make inferences about the
5091     median of a continuous population.  Argument <x> is a list or a
5092     column matrix containing a one dimensional sample.  Performs normal
5093     approximation if the sample size is greater than 20, or if there
5094     are zeroes or ties.
5095
5096     See also 'pdf_rank_test' and 'cdf_rank_test'.
5097
5098     Options:
5099
5100        * ''median', default '0', is the median value to be checked.
5101
5102        * ''alternative', default ''twosided', is the alternative
5103          hypothesis; valid values are: ''twosided', ''greater' and
5104          ''less'.
5105
5106     The output of function 'test_signed_rank' is an 'inference_result'
5107     Maxima object with the following results:
5108
5109       1. ''med_estimate': the sample median.
5110
5111       2. ''method': inference procedure.
5112
5113       3. ''hypotheses': null and alternative hypotheses to be tested.
5114
5115       4. ''statistic': value of the sample statistic used for testing
5116          the null hypothesis.
5117
5118       5. ''distribution': distribution of the sample statistic,
5119          together with its parameter(s).
5120
5121       6. ''p_value': p-value of the test.
5122
5123     Examples:
5124
5125     Checks the null hypothesis H_0: median = 15 against the alternative
5126     H_1: median > 15.  This is an exact test, since there are no ties.
5127
5128          (%i1) load("stats")$
5129          (%i2) x: [17.1,15.9,13.7,13.4,15.5,17.6]$
5130          (%i3) test_signed_rank(x,median=15,alternative=greater);
5131                           |             SIGNED RANK TEST
5132                           |
5133                           |           med_estimate = 15.7
5134                           |
5135                           |           method = Exact test
5136                           |
5137          (%o3)            | hypotheses = H0: med = 15 , H1: med > 15
5138                           |
5139                           |              statistic = 14
5140                           |
5141                           |     distribution = [signed_rank, 6]
5142                           |
5143                           |            p_value = 0.28125
5144
5145     Checks the null hypothesis H_0: equal(median, 2.5) against the
5146     alternative H_1: not equal(median, 2.5).  This is an approximated
5147     test, since there are ties.
5148
5149          (%i1) load("stats")$
5150          (%i2) y:[1.9,2.3,2.6,1.9,1.6,3.3,4.2,4,2.4,2.9,1.5,3,2.9,4.2,3.1]$
5151          (%i3) test_signed_rank(y,median=2.5);
5152                       |                 SIGNED RANK TEST
5153                       |
5154                       |                med_estimate = 2.9
5155                       |
5156                       |          method = Asymptotic test. Ties
5157                       |
5158          (%o3)        |    hypotheses = H0: med = 2.5 , H1: med # 2.5
5159                       |
5160                       |                 statistic = 76.5
5161                       |
5162                       | distribution = [normal, 60.5, 17.58195097251724]
5163                       |
5164                       |           p_value = .3628097734643669
5165
5166 -- Function: test_rank_sum (<x1>, <x2>)
5167 -- Function: test_rank_sum (<x1>, <x2>, <option>)
5168
5169     This is the Wilcoxon-Mann-Whitney test for comparing the medians of
5170     two continuous populations.  The first two arguments <x1> and <x2>
5171     are lists or column matrices with the data of two independent
5172     samples.  Performs normal approximation if any of the sample sizes
5173     is greater than 10, or if there are ties.
5174
5175     Option:
5176
5177        * ''alternative', default ''twosided', is the alternative
5178          hypothesis; valid values are: ''twosided', ''greater' and
5179          ''less'.
5180
5181     The output of function 'test_rank_sum' is an 'inference_result'
5182     Maxima object with the following results:
5183
5184       1. ''method': inference procedure.
5185
5186       2. ''hypotheses': null and alternative hypotheses to be tested.
5187
5188       3. ''statistic': value of the sample statistic used for testing
5189          the null hypothesis.
5190
5191       4. ''distribution': distribution of the sample statistic,
5192          together with its parameters.
5193
5194       5. ''p_value': p-value of the test.
5195
5196     Examples:
5197
5198     Checks whether populations have similar medians.  Samples sizes are
5199     small and an exact test is made.
5200
5201          (%i1) load("stats")$
5202          (%i2) x:[12,15,17,38,42,10,23,35,28]$
5203          (%i3) y:[21,18,25,14,52,65,40,43]$
5204          (%i4) test_rank_sum(x,y);
5205                        |                 RANK SUM TEST
5206                        |
5207                        |              method = Exact test
5208                        |
5209                        | hypotheses = H0: med1 = med2 , H1: med1 # med2
5210          (%o4)         |
5211                        |                 statistic = 22
5212                        |
5213                        |        distribution = [rank_sum, 9, 8]
5214                        |
5215                        |          p_value = .1995886466474702
5216
5217     Now, with greater samples and ties, the procedure makes normal
5218     approximation.  The alternative hypothesis is H_1: median1 <
5219     median2.
5220
5221          (%i1) load("stats")$
5222          (%i2) x: [39,42,35,13,10,23,15,20,17,27]$
5223          (%i3) y: [20,52,66,19,41,32,44,25,14,39,43,35,19,56,27,15]$
5224          (%i4) test_rank_sum(x,y,'alternative='less);
5225                       |                  RANK SUM TEST
5226                       |
5227                       |          method = Asymptotic test. Ties
5228                       |
5229                       |  hypotheses = H0: med1 = med2 , H1: med1 < med2
5230          (%o4)        |
5231                       |                 statistic = 48.5
5232                       |
5233                       | distribution = [normal, 79.5, 18.95419580097078]
5234                       |
5235                       |           p_value = .05096985666598441
5236
5237 -- Function: test_normality (<x>)
5238
5239     Shapiro-Wilk test for normality.  Argument <x> is a list of
5240     numbers, and sample size must be greater than 2 and less or equal
5241     than 5000, otherwise, function 'test_normality' signals an error
5242     message.
5243
5244     Reference:
5245
5246     [1] Algorithm AS R94, Applied Statistics (1995), vol.44, no.4,
5247     547-551
5248
5249     The output of function 'test_normality' is an 'inference_result'
5250     Maxima object with the following results:
5251
5252       1. ''statistic': value of the <W> statistic.
5253
5254       2. ''p_value': p-value under normal assumption.
5255
5256     Examples:
5257
5258     Checks for the normality of a population, based on a sample of size
5259     9.
5260
5261          (%i1) load("stats")$
5262          (%i2) x:[12,15,17,38,42,10,23,35,28]$
5263          (%i3) test_normality(x);
5264                                 |      SHAPIRO - WILK TEST
5265                                 |
5266          (%o3)                  | statistic = .9251055695162436
5267                                 |
5268                                 |  p_value = .4361763918860381
5269
5270 -- Function: simple_linear_regression (<x>)
5271 -- Function: simple_linear_regression (<x> <option>)
5272
5273     Simple linear regression, y_i=a+b x_i+e_i, where e_i are N(0,sigma)
5274     independent random variables.  Argument <x> must be a two column
5275     matrix or a list of pairs.
5276
5277     Options:
5278
5279        * ''conflevel', default '95/100', confidence level for the
5280          confidence interval; it must be an expression which takes a
5281          value in (0,1).
5282
5283        * ''regressor', default ''x', name of the independent variable.
5284
5285     The output of function 'simple_linear_regression' is an
5286     'inference_result' Maxima object with the following results:
5287
5288       1. ''model': the fitted equation.  Useful to make new
5289          predictions.  See examples bellow.
5290
5291       2. ''means': bivariate mean.
5292
5293       3. ''variances': variances of both variables.
5294
5295       4. ''correlation': correlation coefficient.
5296
5297       5. ''adc': adjusted determination coefficient.
5298
5299       6. ''a_estimation': estimation of parameter <a>.
5300
5301       7. ''a_conf_int': confidence interval of parameter <a>.
5302
5303       8. ''b_estimation': estimation of parameter <b>.
5304
5305       9. ''b_conf_int': confidence interval of parameter <b>.
5306
5307       10. ''hypotheses': null and alternative hypotheses about
5308          parameter <b>.
5309
5310       11. ''statistic': value of the sample statistic used for testing
5311          the null hypothesis.
5312
5313       12. ''distribution': distribution of the sample statistic,
5314          together with its parameter.
5315
5316       13. ''p_value': p-value of the test about <b>.
5317
5318       14. ''v_estimation': unbiased variance estimation, or residual
5319          variance.
5320
5321       15. ''v_conf_int': variance confidence interval.
5322
5323       16. ''cond_mean_conf_int': confidence interval for the
5324          conditioned mean.  See examples bellow.
5325
5326       17. ''new_pred_conf_int': confidence interval for a new
5327          prediction.  See examples bellow.
5328
5329       18. ''residuals': list of pairs (prediction, residual), ordered
5330          with respect to predictions.  This is useful for goodness of
5331          fit analysis.  See examples bellow.
5332
5333     Only items 1, 4, 14, 9, 10, 11, 12, and 13 above, in this order,
5334     are shown by default.  The rest remain hidden until the user makes
5335     use of functions 'items_inference' and 'take_inference'.
5336
5337     Example:
5338
5339     Fitting a linear model to a bivariate sample.  Input '%i4' plots
5340     the sample together with the regression line; input '%i5' computes
5341     'y' given 'x=113'; the means and the confidence interval for a new
5342     prediction when 'x=113' are also calculated.
5343
5344          (%i1) load("stats")$
5345          (%i2) s:[[125,140.7], [130,155.1], [135,160.3], [140,167.2],
5346                                                          [145,169.8]]$
5347          (%i3) z:simple_linear_regression(s,conflevel=0.99);
5348                     |               SIMPLE LINEAR REGRESSION
5349                     |
5350                     |   model = 1.405999999999985 x - 31.18999999999804
5351                     |
5352                     |           correlation = .9611685255255155
5353                     |
5354                     |           v_estimation = 13.57966666666665
5355                     |
5356          (%o3)      | b_conf_int = [.04469633662525263, 2.767303663374718]
5357                     |
5358                     |          hypotheses = H0: b = 0 ,H1: b # 0
5359                     |
5360                     |            statistic = 6.032686683658114
5361                     |
5362                     |            distribution = [student_t, 3]
5363                     |
5364                     |             p_value = 0.0038059549413203
5365          (%i4) plot2d([[discrete, s], take_inference(model,z)],
5366                  [x,120,150],
5367                  [gnuplot_curve_styles, ["with points","with lines"]] )$
5368          (%i5) take_inference(model,z), x=133;
5369          (%o5)                         155.808
5370          (%i6) take_inference(means,z);
5371          (%o6)                     [135.0, 158.62]
5372          (%i7) take_inference(new_pred_conf_int,z), x=133;
5373          (%o7)              [132.0728595995113, 179.5431404004887]
5374
5375
5376File: maxima.info,  Node: Functions and Variables for special distributions,  Prev: Functions and Variables for stats,  Up: Top
5377
537871.4 Functions and Variables for special distributions
5379======================================================
5380
5381 -- Function: pdf_signed_rank (<x>, <n>)
5382     Probability density function of the exact distribution of the
5383     signed rank statistic.  Argument <x> is a real number and <n> a
5384     positive integer.
5385
5386     See also 'test_signed_rank'.
5387
5388 -- Function: cdf_signed_rank (<x>, <n>)
5389     Cumulative density function of the exact distribution of the signed
5390     rank statistic.  Argument <x> is a real number and <n> a positive
5391     integer.
5392
5393     See also 'test_signed_rank'.
5394
5395 -- Function: pdf_rank_sum (<x>, <n>, <m>)
5396     Probability density function of the exact distribution of the rank
5397     sum statistic.  Argument <x> is a real number and <n> and <m> are
5398     both positive integers.
5399
5400     See also 'test_rank_sum'.
5401
5402 -- Function: cdf_rank_sum (<x>, <n>, <m>)
5403     Cumulative density function of the exact distribution of the rank
5404     sum statistic.  Argument <x> is a real number and <n> and <m> are
5405     both positive integers.
5406
5407     See also 'test_rank_sum'.
5408
5409
5410File: maxima.info,  Node: stirling,  Next: stringproc,  Prev: stats,  Up: Top
5411
541272 stirling
5413***********
5414
5415* Menu:
5416
5417* Functions and Variables for stirling::
5418
5419
5420File: maxima.info,  Node: Functions and Variables for stirling,  Prev: stirling,  Up: stirling
5421
542272.1 Functions and Variables for stirling
5423=========================================
5424
5425 -- Function: stirling (<z>, <n>)
5426 -- Function: stirling (<z>, <n>, <pred>)
5427
5428     Replace 'gamma(x)' with the O(1/x^(2n-1)) Stirling formula.  When
5429     <n> isn't a nonnegative integer, signal an error.  With the
5430     optional third argument 'pred', the Stirling formula is applied
5431     only when 'pred' is true.
5432
5433     To use this function write first 'load(stirling)'.
5434
5435     Reference: Abramowitz & Stegun, "Handbook of mathematical
5436     functions", 6.1.40.
5437
5438     Examples:
5439
5440          (%i1) load (stirling)$
5441
5442          (%i2) stirling(gamma(%alpha+x)/gamma(x),1);
5443                 1/2 - x             x + %alpha - 1/2
5444          (%o2) x        (x + %alpha)
5445                                             1           1
5446                                      --------------- - ---- - %alpha
5447                                      12 (x + %alpha)   12 x
5448                                    %e
5449          (%i3) taylor(%,x,inf,1);
5450                              %alpha       2    %alpha
5451                    %alpha   x       %alpha  - x       %alpha
5452          (%o3)/T/ x       + -------------------------------- + . . .
5453                                           2 x
5454          (%i4) map('factor,%);
5455                                                 %alpha - 1
5456                   %alpha   (%alpha - 1) %alpha x
5457          (%o4)   x       + -------------------------------
5458                                            2
5459
5460     The function 'stirling' knows the difference between the variable
5461     'gamma' and the function gamma:
5462
5463          (%i5) stirling(gamma + gamma(x),0);
5464                                              x - 1/2   - x
5465          (%o5)    gamma + sqrt(2) sqrt(%pi) x        %e
5466          (%i6) stirling(gamma(y) + gamma(x),0);
5467                                   y - 1/2   - y
5468          (%o6) sqrt(2) sqrt(%pi) y        %e
5469                                                        x - 1/2   - x
5470                                   + sqrt(2) sqrt(%pi) x        %e
5471
5472     To apply the Stirling formula only to terms that involve the
5473     variable 'k', use an optional third argument; for example
5474
5475          (%i7) makegamma(pochhammer(a,k)/pochhammer(b,k));
5476                                gamma(b) gamma(k + a)
5477          (%o7)                 ---------------------
5478                                gamma(a) gamma(k + b)
5479
5480          (%i8) stirling(%,1, lambda([s], not(freeof(k,s))));
5481                  b - a                 k + a - 1/2        - k - b + 1/2
5482                %e      gamma(b) (k + a)            (k + b)
5483          (%o8) --------------------------------------------------------
5484                                        gamma(a)
5485
5486     The terms 'gamma(a)' and 'gamma(b)' are free of 'k', so the
5487     Stirling formula was not applied to these two terms.
5488
5489
5490File: maxima.info,  Node: stringproc,  Next: symmetries,  Prev: stirling,  Up: Top
5491
549273 stringproc
5493*************
5494
5495* Menu:
5496
5497* Einführung in die Verarbeitung von Zeichenketten::
5498* Ein- und Ausgabe::
5499* Schriftzeichen::
5500* Verarbeitung von Zeichenketten::
5501* Oktette und Werkzeuge für die Kryptographie::
5502
5503
5504File: maxima.info,  Node: Einführung in die Verarbeitung von Zeichenketten,  Next: Ein- und Ausgabe,  Prev: stringproc,  Up: stringproc
5505
550673.1 Einführung in die Verarbeitung von Zeichenketten
5507=====================================================
5508
5509Das Paket 'stringproc' enthält Funktionen für die Verarbeitung von
5510Zeichen und Zeichenketten, was Formatierung, Zeichenkodierung und die
5511Behandlung von Datenströmen mit einschließt.  Abgerundet wird dieses
5512Paket durch Werkzeuge für die Kryptographie, wie z.B. Base64 und
5513Hashfunktionen.
5514
5515Das Paket kann explizit durch 'load(stringproc)' geladen werden oder
5516automatisch durch die Verwendung einer der enthaltenden Funktionen.
5517
5518Fragen und Fehlerberichte senden Sie bitte direkt an den Autor, dessen
5519e-Mail-Adresse durch den folgenden Befehl ausgegeben wird.
5520
5521'printf(true, "~{~a~}@gmail.com", split(sdowncase("Volker van Nek")))$'
5522
5523Eine Zeichenkette wird durch die Eingabe von z.B. '"Text"' erzeugt.  Ist
5524die Optionsvariable 'stringdisp' auf 'false' gesetzt, was standardmäßig
5525der Fall ist, werden die (doppelten) Anführungszeichen nicht mit
5526ausgegeben.  *note stringp:: ist ein Test, ob ein Objekt eine
5527Zeichenkette ist.
5528
5529     (%i1) str: "Text";
5530     (%o1)                         Text
5531     (%i2) stringp(str);
5532     (%o2)                         true
5533
5534Schriftzeichen werden in Maxima durch Zeichenketten der Länge 1
5535dargestellt.  *note charp:: ist hier der entsprechende Test.
5536
5537     (%i1) char: "e";
5538     (%o1)                           e
5539     (%i2) charp(char);
5540     (%o2)                         true
5541
5542Positionsindizes in Zeichenketten sind in Maxima genau so wie in Listen
55431-indiziert, wodurch die folgende Übereinstimmung entsteht.
5544
5545     (%i1) is(charat("Lisp",1) = charlist("Lisp")[1]);
5546     (%o1)                         true
5547
5548Eine Zeichenkette kann Ausdrücke enthalten, die Maxima versteht.  Diese
5549können mit *note parse_string:: heraus gelöst werden.
5550
5551     (%i1) map(parse_string, ["42" ,"sqrt(2)", "%pi"]);
5552     (%o1)                   [42, sqrt(2), %pi]
5553     (%i2) map('float, %);
5554     (%o2)        [42.0, 1.414213562373095, 3.141592653589793]
5555
5556Zeichenketten können als Schriftzeichen und binär als Oktette
5557verarbeitet werden.  *note string_to_octets:: bzw.  *note
5558octets_to_string:: dienen hierbei zur Umrechnung.  Die verwendbaren
5559Kodierungen sind dabei von der Plattform, der Anwendung und vom unter
5560Maxima liegenden Lisp abhängig.  (Folgend Maxima in GNU/Linux,
5561kompiliert mit SBCL.)
5562
5563     (%i1) obase: 16.$
5564     (%i2) string_to_octets("$£Euro", "cp1252");
5565     (%o2)                     [24, 0A3, 80]
5566     (%i3) string_to_octets("$£Euro", "utf-8");
5567     (%o3)               [24, 0C2, 0A3, 0E2, 82, 0AC]
5568
5569Dem entsprechend können Zeichenketten an Datenströme für Schriftzeichen
5570und als Oktette an binäre Ströme weiter gegeben werden.  Das folgende
5571Beispiel zeigt das Schreiben und Lesen von Schriftzeichen in bzw.  aus
5572einer Datei.
5573
5574*note openw:: gibt dabei einen Ausgabestrom in eine Datei zurück, mit
5575*note printf:: wird formatiert in diesen Strom geschrieben und mit z.B.
5576*note close:: werden die im Strom enthaltenden Zeichen in die Datei
5577geschrieben.
5578
5579     (%i1) s: openw("file.txt");
5580     (%o1)                #<output stream file.txt>
5581     (%i2) printf(s, "~%~d ~f ~a ~a ~f ~e ~a~%",
5582     42, 1.234, sqrt(2), %pi, 1.0e-2, 1.0e-2, 1.0b-2)$
5583     (%i3) close(s)$
5584
5585*note openr:: gibt folgend einen Eingabestrom aus der obigen Datei
5586zurück und *note readline:: die gelesene Zeile als Zeichenkette.  Mit
5587z.B. *note split:: oder *note tokens:: kann die Zeichenkette
5588anschließend in seine Bestandteile zerlegt werden.  *note parse_string::
5589verwandelt diese dann in auswertbare Ausdrücke.
5590
5591     (%i4) s: openr("file.txt");
5592     (%o4)                 #<input stream file.txt>
5593     (%i5) readline(s);
5594     (%o5)          42 1.234 sqrt(2) %pi 0.01 1.0E-2 1.0b-2
5595     (%i6) map(parse_string, split(%));
5596     (%o6)       [42, 1.234, sqrt(2), %pi, 0.01, 0.01, 1.0b-2]
5597     (%i7) close(s)$
5598
5599
5600File: maxima.info,  Node: Ein- und Ausgabe,  Next: Schriftzeichen,  Prev: Einführung in die Verarbeitung von Zeichenketten,  Up: stringproc
5601
560273.2 Ein- und Ausgabe
5603=====================
5604
5605Beispiel: Formatiertes Schreiben in eine Datei mit anschließendem Lesen.
5606
5607     (%i1) s: openw("file.txt");
5608     (%o1)                      #<output stream file.txt>
5609     (%i2) control:
5610     "~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2t\
5611     and an integer: ~20t~d~%"$
5612     (%i3) printf(s, control, 'true,[1,2,3],42)$
5613     (%o3)                                false
5614     (%i4) close(s);
5615     (%o4)                                true
5616     (%i5) s: openr("file.txt");
5617     (%o5)                      #<input stream file.txt>
5618     (%i6) while stringp(tmp:readline(s)) do print(tmp)$
5619       An atom:          true
5620       and a list:       one two three
5621       and an integer:   42
5622     (%i7) close(s)$
5623
5624Beispiel: Lesen aus einer binären Datei.  Siehe *note readbyte::.
5625
5626 -- Funktion: close (<stream>)
5627
5628     Schließt den Datenstrom <stream> und gibt 'true' zurück, wenn
5629     <stream> noch geöffnet war.
5630
5631 -- Funktion: flength (<stream>)
5632
5633     <stream> muss ein geöffneter Datenstrom in eine oder aus einer
5634     Datei sein.  'flength' gibt dann die Anzahl der Bytes zurück, die
5635     sich momentan in dieser Datei befinden.
5636
5637     Beispiel: Siehe *note writebyte:: .
5638
5639 -- Funktion: flush_output (<stream>)
5640
5641     Leert den Inhalt des Dateiausgabestroms <stream> in die Datei.
5642
5643     Beispiel: Siehe *note writebyte:: .
5644
5645 -- Function: fposition (<stream>)
5646 -- Function: fposition (<stream>, <pos>)
5647
5648     Ohne das optionale Argument <pos> gibt 'fposition' die aktuelle
5649     Position in dem Datenstrom <stream> zurück.  Wird <pos> verwendet,
5650     legt 'fposition' diesen Wert als aktuelle Position in <stream>
5651     fest.  <pos> muss eine positive Zahl sein.
5652
5653     Die Positionen in Datenströmen sind wie in Zeichenketten und Listen
5654     1-indiziert, d.h.  das erste Element in <stream> hat die Position
5655     1.
5656
5657 -- Function: freshline ()
5658 -- Function: freshline (<stream>)
5659
5660     Schreibt einen Zeilenumbruch in den Standardausgabestrom, falls die
5661     aktuelle Ausgabeposition nicht gerade der Anfang einer Zeile ist
5662     und gibt 'true' zurück.  Bei der Verwendung des optionalen
5663     Arguments <stream> wird der Umbruch in diesen Datenstrom
5664     geschrieben.
5665
5666     Es gibt Situationen, in denen 'freshline()' nicht wie erwartet
5667     funktioniert.
5668
5669     Siehe auch *note newline::.
5670
5671 -- Funktion: get_output_stream_string (<stream>)
5672
5673     Gibt Schriftzeichen, die aktuell in dem geöffneten Datenstrom
5674     <stream> enthalten sind, in einer Zeichenkette zurück.  Die zurück
5675     gegebenen Zeichen werden dabei aus dem Datenstrom entfernt.
5676     <stream> muss durch 'make_string_output_stream' erzeugt worden
5677     sein.
5678
5679     Beispiel: Siehe *note make_string_output_stream:: .
5680
5681 -- Funktion: make_string_input_stream (<string>)
5682 -- Funktion: make_string_input_stream (<string>, <start>)
5683 -- Funktion: make_string_input_stream (<string>, <start>, <end>)
5684
5685     Gibt einen Datenstrom zurück, der Teile der Zeichenkette <string>
5686     und ein Dateiende enthält.  Ohne optionale Argumente enthält der
5687     Strom die gesamte Zeichenkette und ist vor dem ersten Zeichen
5688     positioniert.  Mit den optionalen Argumenten <start> und <end>
5689     lässt sich der Abschnitt der Zeichenkette festlegen, den der
5690     Datenstrom enthält.  Das erste Zeichen befindet sich dabei an der
5691     Position 1.
5692
5693          (%i1) istream : make_string_input_stream("text", 1, 4);
5694          (%o1)              #<string-input stream from "text">
5695          (%i2) (while (c : readchar(istream)) # false do sprint(c), newline())$
5696          t e x
5697          (%i3) close(istream)$
5698
5699 -- Funktion: make_string_output_stream ()
5700
5701     Gibt einen Datenstrom zurück, der Schriftzeichen aufnehmen kann.
5702     Die aktuell im Strom enthaltenden Zeichen können mit *note
5703     get_output_stream_string:: entnommen werden.
5704
5705          (%i1) ostream : make_string_output_stream();
5706          (%o1)               #<string-output stream 09622ea0>
5707          (%i2) printf(ostream, "foo")$
5708
5709          (%i3) printf(ostream, "bar")$
5710
5711          (%i4) string : get_output_stream_string(ostream);
5712          (%o4)                            foobar
5713          (%i5) printf(ostream, "baz")$
5714
5715          (%i6) string : get_output_stream_string(ostream);
5716          (%o6)                              baz
5717          (%i7) close(ostream)$
5718
5719 -- Funktion: newline ()
5720 -- Funktion: newline (<stream>)
5721
5722     Schreibt einen Zeilenumbruch in den Standardausgabestrom und gibt
5723     'false' zurück.  Bei der Verwendung des optionalen Arguments
5724     <stream> wird der Umbruch in diesen Datenstrom geschrieben.  Es
5725     gibt Situationen, in denen 'newline()' nicht wie erwartet
5726     funktioniert.
5727
5728     Beispiel: Siehe *note sprint::.
5729
5730 -- Funktion: opena (<file>)
5731
5732     Gibt einen Dateiausgabestrom für Schriftzeichen zurück.  Sollte die
5733     Textdatei <file> nicht existieren, wird sie erzeugt.  Wird eine
5734     bereits vorhandene Datei geöffnet, werden alle Ausgaben in die
5735     Datei am Ende hinzugefügt.
5736
5737     *note opena_binary: Functions and Variables for binary input and
5738     output. ist die entsprechende Funktion für die Ausgabe in eine
5739     Binärdatei.
5740
5741 -- Funktion: openr (<file>)
5742
5743     Gibt einen Dateieingabestrom für Schriftzeichen aus einer Textdatei
5744     zurück.  Voraussetzung ist, dass die Datei <file> bereits
5745     existiert.
5746
5747     *note openr_binary: Functions and Variables for binary input and
5748     output. ist die entsprechende Funktion für die Eingabe aus einer
5749     Binärdatei.
5750
5751 -- Funktion: openw (<file>)
5752
5753     Gibt einen Dateiausgabestrom für Schriftzeichen zurück.  Sollte die
5754     Textdatei <file> nicht existieren, wird sie erzeugt.  Wird eine
5755     bereits vorhandene Datei geöffnet, wird sie destruktiv verändert.
5756
5757     *note openw_binary: Functions and Variables for binary input and
5758     output. ist die entsprechende Funktion für die Ausgabe in eine
5759     Binärdatei.
5760
5761 -- Function: printf (<dest>, <string>)
5762 -- Function: printf (<dest>, <string>, <expr_1>, ..., <expr_n>)
5763
5764     Erzeugt eine formatierte Ausgabe.  Der Zielparameter <dest> gibt
5765     an, wo die Ausgabe erfolgen soll.  Möglich sind hier ein
5766     Ausgabestrom oder die globalen Variablen 'true' und 'false'.
5767     'true' bewirkt eine Ausgabe im Terminal.  Der Rückgabewert von
5768     'printf' ist in diesem Fall 'false'.  'false' als Zielparameter
5769     bewirkt die Ausgabe im Rückgabewert.
5770
5771     Die Zeichen des Kontrollparameters <string> werden der Reihe nach
5772     ausgegeben, wobei jedoch eine Tilde eine Direktive einleitet.  Die
5773     Direktiven verwenden dann im Allgemeinen die nachstehenden
5774     Parameter <expr_1>, ..., <expr_n>, um die Ausgabe zu erzeugen.  Das
5775     Zeichen nach der Tilde gibt dabei an, welche Art der Formatierung
5776     gewünscht ist.
5777
5778     'printf' stellt die Common Lisp Funktion 'format' in Maxima zur
5779     Verfügung.  Das folgende Beispiel zeigt die grundsätzliche
5780     Beziehung zwischen diesen beiden Funktionen.
5781
5782          (%i1) printf(true, "R~dD~d~%", 2, 2);
5783          R2D2
5784          (%o1)                                false
5785          (%i2) :lisp (format t "R~dD~d~%" 2 2)
5786          R2D2
5787          NIL
5788
5789     Die folgende Beschreibung und die Beispiele beschränken sich auf
5790     eine grobe Skizze der Verwendungsmöglichkeiten von 'printf'.  Die
5791     Lisp Funktion 'format' ist in vielen Referenzbüchern ausführlich
5792     beschrieben.  Eine hilfreiche Quelle ist z.B. das frei verfügbare
5793     Online-Manual "Common Lisp the Language" von Guy L. Steele.  Siehe
5794     dort das Kapitel 22.3.3.
5795
5796             ~%       new line
5797             ~&       fresh line
5798             ~t       tab
5799             ~$       monetary
5800             ~d       decimal integer
5801             ~b       binary integer
5802             ~o       octal integer
5803             ~x       hexadecimal integer
5804             ~br      base-b integer
5805             ~r       spell an integer
5806             ~p       plural
5807             ~f       floating point
5808             ~e       scientific notation
5809             ~g       ~f or ~e, depending upon magnitude
5810             ~h       bigfloat
5811             ~a       uses Maxima function string
5812             ~s       like ~a, but output enclosed in "double quotes"
5813             ~~       ~
5814             ~<       justification, ~> terminates
5815             ~(       case conversion, ~) terminates
5816             ~[       selection, ~] terminates
5817             ~{       iteration, ~} terminates
5818
5819     Die Direktive ~h für Gleitkommazahlen mit beliebiger Genauigkeit
5820     entspricht nicht dem Lisp-Standard und wird daher unten näher
5821     beschrieben.
5822
5823     Die Direktive ~* wird nicht unterstützt.
5824
5825     Ist <dest> ein Datenstrom oder 'true', gibt 'printf' 'false'
5826     zurück.  Andernfalls ist der Rückgabewert eine Zeichenkette.
5827
5828          (%i1) printf( false, "~a ~a ~4f ~a ~@r",
5829                        "String",sym,bound,sqrt(12),144), bound = 1.234;
5830          (%o1)                 String sym 1.23 2*sqrt(3) CXLIV
5831          (%i2) printf( false,"~{~a ~}",["one",2,"THREE"] );
5832          (%o2)                          one 2 THREE
5833          (%i3) printf( true,"~{~{~9,1f ~}~%~}",mat ),
5834                    mat = args(matrix([1.1,2,3.33],[4,5,6],[7,8.88,9]))$
5835                1.1       2.0       3.3
5836                4.0       5.0       6.0
5837                7.0       8.9       9.0
5838          (%i4) control: "~:(~r~) bird~p ~[is~;are~] singing."$
5839          (%i5) printf( false, control, n,n, if n = 1 then 1 else 2 ), n = 2;
5840          (%o5)                    Two birds are singing.
5841
5842     Die Direktive ~h wurde für Gleitkommazahlen mit beliebiger
5843     Genauigkeit eingeführt.
5844
5845          ~w,d,e,x,o,p@H
5846           w : width
5847           d : decimal digits behind floating point
5848           e : minimal exponent digits
5849           x : preferred exponent
5850           o : overflow character
5851           p : padding character
5852           @ : display sign for positive numbers
5853
5854          (%i1) fpprec : 1000$
5855          (%i2) printf(true, "|~h|~%", 2.b0^-64)$
5856          |0.0000000000000000000542101086242752217003726400434970855712890625|
5857          (%i3) fpprec : 26$
5858          (%i4) printf(true, "|~h|~%", sqrt(2))$
5859          |1.4142135623730950488016887|
5860          (%i5) fpprec : 24$
5861          (%i6) printf(true, "|~h|~%", sqrt(2))$
5862          |1.41421356237309504880169|
5863          (%i7) printf(true, "|~28h|~%", sqrt(2))$
5864          |   1.41421356237309504880169|
5865          (%i8) printf(true, "|~28,,,,,'*h|~%", sqrt(2))$
5866          |***1.41421356237309504880169|
5867          (%i9) printf(true, "|~,18h|~%", sqrt(2))$
5868          |1.414213562373095049|
5869          (%i10) printf(true, "|~,,,-3h|~%", sqrt(2))$
5870          |1414.21356237309504880169b-3|
5871          (%i11) printf(true, "|~,,2,-3h|~%", sqrt(2))$
5872          |1414.21356237309504880169b-03|
5873          (%i12) printf(true, "|~20h|~%", sqrt(2))$
5874          |1.41421356237309504880169|
5875          (%i13) printf(true, "|~20,,,,'+h|~%", sqrt(2))$
5876          |++++++++++++++++++++|
5877
5878 -- Funktion: readbyte (<stream>)
5879
5880     Entfernt das erste Byte aus dem binären Eingabestrom <stream> und
5881     gibt es zurück.  Ist das Ende der Datei (EOF) erreicht, wird
5882     'false' zurück gegeben.
5883
5884     Beispiel: Die ersten 16 Byte aus einer mit AES in OpenSSL
5885     verschlüsselten Datei werden gelesen und ausgewertet.
5886
5887          (%i1) ibase: obase: 16.$
5888
5889          (%i2) in: openr_binary("msg.bin");
5890          (%o2)                       #<input stream msg.bin>
5891          (%i3) (L:[],  thru 16. do push(readbyte(in), L),  L:reverse(L));
5892          (%o3) [53, 61, 6C, 74, 65, 64, 5F, 5F, 88, 56, 0DE, 8A, 74, 0FD, 0AD, 0F0]
5893          (%i4) close(in);
5894          (%o4)                                true
5895          (%i5) map(ascii, rest(L,-8));
5896          (%o5)                      [S, a, l, t, e, d, _, _]
5897          (%i6) salt: octets_to_number(rest(L,8));
5898          (%o6)                          8856de8a74fdadf0
5899
5900 -- Funktion: readchar (<stream>)
5901
5902     Entfernt und gibt das erste Schriftzeichen in <stream> zurück.
5903     Falls das Ende des Streams erreicht sein sollte, gibt 'readchar'
5904     'false' zurück.
5905
5906     Beispiel: Siehe *note make_string_input_stream::.
5907
5908 -- Function: readline (<stream>)
5909
5910     Gibt die Zeichenkette zurück, die sämtliche Zeichen von der
5911     aktuellen Position in <stream> bis zum Ende der Zeile enthält oder
5912     'false', falls das Ende der Datei erreicht wurde.
5913
5914 -- Funktion: sprint (<expr_1>, ..., <expr_n>)
5915
5916     Wertet ihre Argumente der Reihe nach von links nach rechts aus und
5917     gibt sie dann auf einer Linie aus.  Zeilenbegrenzungen werden dabei
5918     außer Acht gelassen.  An die ausgegebenen Ausdrücke wird jeweils
5919     rechts ein Leerzeichen angefügt.
5920
5921     Beispiel: Sequentielle Ausgabe mit 'sprint'.  Zeilenumbrüche werden
5922     hier mit 'newline()' erzeugt.
5923
5924          (%i1) for n:0 thru 19 do sprint(fib(n))$
5925          0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
5926          (%i2) for n:0 thru 22 do (
5927                   sprint(fib(n)),
5928                   if mod(n,10) = 9 then newline() )$
5929          0 1 1 2 3 5 8 13 21 34
5930          55 89 144 233 377 610 987 1597 2584 4181
5931          6765 10946 17711
5932
5933 -- Funktion: writebyte (<byte>, <stream>)
5934
5935     Schreibt das Byte <byte> in den binären Ausgabestrom <stream>.
5936     'writebyte' gibt 'byte' zurück.
5937
5938     Beispiel: Es werden Bytes in eine Binärdatei geschrieben.  In
5939     diesem Beispiel entsprechen sämtliche Bytes druckbaren Zeichen, die
5940     mit Hilfe von 'printfile' ausgegeben werden können.  Die Bytes
5941     verbleiben so lange im Datenstrom, bis die Funktionen
5942     'flush_output' oder 'close' aufgerufen werden.
5943
5944          (%i1) ibase: obase: 16.$
5945
5946          (%i2) bytes: string_to_octets("GNU/Linux");
5947          (%o2)                [47, 4E, 55, 2F, 4C, 69, 6E, 75, 78]
5948          (%i3) out: openw_binary("test.bin");
5949          (%o3)                      #<output stream test.bin>
5950          (%i4) for i thru 3 do writebyte(bytes[i], out);
5951          (%o4)                                done
5952          (%i5) printfile("test.bin")$
5953
5954          (%i6) flength(out);
5955          (%o6)                                  0
5956          (%i7) flush_output(out);
5957          (%o7)                                true
5958          (%i8) flength(out);
5959          (%o8)                                  3
5960          (%i9) printfile("test.bin")$
5961          GNU
5962          (%i0A) for b in rest(bytes,3) do writebyte(b, out);
5963          (%o0A)                               done
5964          (%i0B) close(out);
5965          (%o0B)                               true
5966          (%i0C) printfile("test.bin")$
5967          GNU/Linux
5968
5969
5970File: maxima.info,  Node: Schriftzeichen,  Next: Verarbeitung von Zeichenketten,  Prev: Ein- und Ausgabe,  Up: stringproc
5971
597273.3 Schriftzeichen
5973===================
5974
5975In Maxima sind Schriftzeichen Zeichenketten der Länge 1.
5976
5977 -- Function: adjust_external_format ()
5978
5979     Gibt Informationen zum aktuellen externen Format des Lisp Lesers
5980     aus und in dem Fall, dass die Kodierung des externen Formats nicht
5981     mit der Kodierung der Anwendung, in der Maxima läuft,
5982     übereinstimmt, versucht 'adjust_external_format', die Kodierung
5983     anzupassen oder gibt entsprechende Hilfen oder Anleitungen aus.
5984     'adjust_external_format' gibt 'true' zurück, wenn das externe
5985     Format geändert wurde und 'false', wenn nicht.
5986
5987     Funktionen wie *note cint::, *note unicode::, *note
5988     octets_to_string:: und *note string_to_octets:: benötigen UTF-8 als
5989     das externe Format des Lisp Lesers, um über dem vollständigen
5990     Bereich der Unicode-Zeichen korrekt arbeiten zu können.
5991
5992     Beispiele (Maxima in Windows, März 2016): Die Verwendung von
5993     'adjust_external_format' in dem Fall, dass das externe Format nicht
5994     mit der Kodierung der Anwendung, in der Maxima läuft,
5995     übereinstimmt.
5996
5997     1.  Maxima in der Kommandozeile
5998
5999     Für die Sitzung in einem Terminal wird empfohlen, ein mit SBCL
6000     kompiliertes Maxima zu verwenden.  Unicode wird hier standardmäßig
6001     unterstützt und ein Aufruf von 'adjust_external_format' ist nicht
6002     notwendig.
6003
6004     Falls Maxima mit CLISP oder GCL kompiliert wurde, wird empfohlen,
6005     die Kodierung des Terminals von CP850 in CP1252 abzuändern.
6006     'adjust_external_format' gibt eine entsprechende Hilfe aus.
6007
6008     CCL liest UTF-8, obwohl der Input vom Terminal standardmäßig in
6009     CP850 kodiert ist.  CP1252 wird jedoch von CCL nicht unterstützt.
6010     'adjust_external_format' gibt deshalb eine Anleitung aus, wie die
6011     Kodierung des Terminals und die des externen Formats beide auf
6012     ISO-8859-1 abgeändert werden können.
6013
6014     2.  wxMaxima
6015
6016     In wxMaxima liest SBCL standardmäßig CP1252.  Der Input von der
6017     Anwendung (wxMaxima) ist jedoch UTF-8-kodiert.  Hier ist eine
6018     Anpassung erforderlich.
6019
6020     Ein Aufruf von 'adjust_external_format' und ein Neustart von Maxima
6021     ändern das standardmäßige externe Format auf UTF-8.
6022
6023          (%i1)adjust_external_format();
6024          The line
6025          (setf sb-impl::*default-external-format* :utf-8)
6026          has been appended to the init file
6027          C:/Users/Username/.sbclrc
6028          Please restart Maxima to set the external format to UTF-8.
6029          (%i1) false
6030
6031     Maxima wird neu gestartet.
6032
6033          (%i1) adjust_external_format();
6034          The external format is currently UTF-8
6035          and has not been changed.
6036          (%i1) false
6037
6038 -- Function: alphacharp (<char>)
6039
6040     Gibt 'true' zurück, falls <char> ein Buchstabe eines Alphabets ist.
6041
6042     Um ein Nicht-US-ASCII-Zeichen als Buchstaben eines Alphabets
6043     erkennen zu können, muss das unter Maxima liegende Lisp Unicode
6044     voll unterstützen.  So wird z.B. ein Umlaut mit SBCL in GNU/Linux
6045     als Buchstabe erkannt, mit GCL jedoch nicht.  (In Windows muss ein
6046     mit SBCL kompiliertes Maxima auf UTF-8 umgestellt worden sein.
6047     Siehe hierzu *note adjust_external_format::.)
6048
6049     Beispiele:
6050
6051     Das unter Maxima liegende Lisp (SBCL, GNU/Linux) kann das
6052     eingegebene Zeichen in ein Lisp-Schriftzeichen umwandeln und
6053     untersuchen.
6054
6055          (%i1) alphacharp("ü");
6056          (%o1)                          true
6057
6058     Mit GCL ist dies nicht möglich.  Es kommt zu einem Fehlerabbruch.
6059
6060          (%i1) alphacharp("u");
6061          (%o1)                          true
6062          (%i2) alphacharp("ü");
6063
6064          package stringproc: ü cannot be converted into a Lisp character.
6065           -- an error.
6066
6067 -- Function: alphanumericp (<char>)
6068
6069     Gibt 'true' zurück, falls <char> ein Buchstabe eines Alphabets oder
6070     ein Zahlzeichen ist (als Zahlzeichen werden hier nur entprechende
6071     US-ASCII-Zeichen betrachtet).
6072
6073     Hinweis: Siehe Bemerkungen zu *note alphacharp::.
6074
6075 -- Funktion: ascii (<int>)
6076
6077     Gibt das US-ASCII-Zeichen zurück, das der Ganzzahl <int>
6078     entspricht.  <int> muss dabei kleiner als '128' sein.
6079
6080     Siehe *note unicode:: für die Umwandlung von Codepunkten größer
6081     '127'.
6082
6083     Beispiele:
6084
6085          (%i1) for n from 0 thru 127 do (
6086                  ch: ascii(n),
6087                  if alphacharp(ch) then sprint(ch),
6088                  if n = 96 then newline() )$
6089          A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
6090          a b c d e f g h i j k l m n o p q r s t u v w x y z
6091
6092 -- Function: cequal (<char_1>, <char_2>)
6093
6094     Gibt 'true' zurück, falls <char_1> und <char_2> ein und das selbe
6095     Schriftzeichen sind.
6096
6097 -- Function: cequalignore (<char_1>, <char_2>)
6098
6099     Arbeitet wie *note cequal::, ignoriert jedoch die Groß- und
6100     Kleinschreibung, was für Nicht-US-ASCII-Zeichen nur möglich ist,
6101     wenn das unter Maxima liegende Lisp einen Buchstaben auch als
6102     Buchstaben eines Alphabets erkennen kann.  Siehe hierzu die
6103     Bemerkungen zu *note alphacharp::.
6104
6105 -- Function: cgreaterp (<char_1>, <char_2>)
6106
6107     Gibt 'true' zurück, wenn der Codepunkt des Zeichens <char_1> größer
6108     ist als der des Zeichens <char_2>.
6109
6110 -- Funktion: cgreaterpignore (<char_1>, <char_2>)
6111
6112     Arbeitet wie *note cgreaterp::, ignoriert jedoch die Groß- und
6113     Kleinschreibung, was für Nicht-US-ASCII-Zeichen nur möglich ist,
6114     wenn das unter Maxima liegende Lisp einen Buchstaben auch als
6115     Buchstaben eines Alphabets erkennen kann.  Siehe hierzu die
6116     Bemerkungen zu *note alphacharp::.
6117
6118 -- Funktion: charp (<obj>)
6119
6120     Gibt 'true' zurück, wenn <obj> ein Schriftzeichen ist.
6121
6122     Beispiel: Siehe Einführung.
6123
6124 -- Funktion: cint (<char>)
6125
6126     Gibt den Unicode Codepunkt des Arguments <char> zurück, das ein
6127     Schriftzeichen sein muss, d.h.  eine Zeichenkette der Länge '1'.
6128
6129     Beispiele: Der hexadedimale Codepunkt von Schriftzeichen (Maxima
6130     kompiliert mit SBCL in GNU/Linux).
6131
6132          (%i1) obase: 16.$
6133          (%i2) map(cint, ["$","£","Euro"]);
6134          (%o2)                           [24, 0A3, 20AC]
6135
6136     Warnung: In Windows ist es nicht möglich, Schriftzeichen, die
6137     Codepunkten größer 16 Bit entsprechen, in wxMaxima einzugeben, wenn
6138     Maxima mit SBCL kompiliert wurde und das aktuelle externe Format
6139     nicht UTF-8 ist.  Siehe *note adjust_external_format:: für weitere
6140     Informationen.
6141
6142     CMUCL verarbeitet solche Zeichen nicht als ein einziges Zeichen und
6143     'cint' gibt dann 'false' zurück.  Als Ausweg kann hier die
6144     Umwandlung von Schriftzeichen in Codepunkte über UTF-8-Oktette
6145     dienen:
6146     'utf8_to_unicode(string_to_octets(character));'
6147
6148     Siehe *note utf8_to_unicode::, *note string_to_octets::.
6149
6150 -- Function: clessp (<char_1>, <char_2>)
6151
6152     Gibt 'true' zurück, wenn der Codepunkt des Zeichens <char_1>
6153     kleiner ist als der des Zeichens <char_2>.
6154
6155 -- Funktion: clesspignore (<char_1>, <char_2>)
6156
6157     Arbeitet wie *note clessp::, ignoriert jedoch die Groß- und
6158     Kleinschreibung, was für Nicht-US-ASCII-Zeichen nur möglich ist,
6159     wenn das unter Maxima liegende Lisp einen Buchstaben auch als
6160     Buchstaben eines Alphabets erkennen kann.  Siehe hierzu die
6161     Bemerkungen zu *note alphacharp::.
6162
6163 -- Funktion: constituent (<char>)
6164
6165     Gibt 'true' zurück, wenn <char> ein graphisches Schriftzeichen,
6166     aber kein Leerzeichen ist.  Ein graphisches Schriftzeichen ist ein
6167     Leerzeichen oder ein Zeichen, das man sehen kann.  ('constituent'
6168     wurde definiert von Paul Graham.  Siehe Paul Graham, ANSI Common
6169     Lisp, 1996, Seite 67.)
6170
6171     Beispiel:
6172
6173          (%i1) for n from 0 thru 255 do (
6174          tmp: ascii(n), if constituent(tmp) then sprint(tmp) )$
6175          ! " #  %  ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B
6176          C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c
6177          d e f g h i j k l m n o p q r s t u v w x y z { | } ~
6178
6179     Hinweis: Siehe Bemerkungen zu *note alphacharp::.
6180
6181 -- Funktion: digitcharp (<char>)
6182
6183     Gibt 'true' zurück, wenn <char> ein Zahlzeichen ist, wobei als
6184     Zahlzeichen hier nur entsprechende US-ASCII-Zeichen betrachtet
6185     werden.
6186
6187 -- Funktion: lowercasep (<char>)
6188
6189     Gibt 'true' zurück, wenn <char> ein Kleinbuchstabe ist.
6190
6191     Hinweis: Siehe Bemerkungen zu *note alphacharp::.
6192
6193 -- Variable: newline
6194
6195     Das Steuerzeichen für den Zeilenvorschub (ASCII-Zeichen 10).
6196
6197 -- Variable: space
6198
6199     Das Leerzeichen.
6200
6201 -- Variable: tab
6202
6203     Das Tabulatorzeichen.
6204
6205 -- Funktion: unicode (<arg>)
6206
6207     Gibt das durch <arg> definierte Schriftzeichen zurück.  <arg> kann
6208     ein Unicode Codepunkt oder auch eine Zeichenkette mit einem Namen
6209     sein, falls das unter Maxima liegende Lisp Unicode vollständig
6210     unterstützt.
6211
6212     Beispiel: Durch hexadezimale Codepunkte definierte Schriftzeichen
6213     (Maxima kompiliert mit SBCL in GNU/Linux).
6214
6215          (%i1) ibase: 16.$
6216          (%i2) map(unicode, [24, 0A3, 20AC]);
6217          (%o2)                            [$, £, Euro]
6218
6219     Warnung: In wxMaxima in Windows ist es nicht möglich, Codepunkte
6220     größer 16 Bit in Schriftzeichen umzuwandeln, wenn Maxima mit SBCL
6221     kompiliert wurde und das aktuelle externe Format nicht UTF-8 ist.
6222     Siehe *note adjust_external_format:: für weitere Informationen.
6223
6224     CMUCL verarbeitet keine Codepunkte größer 16 Bit.  'unicode' gibt
6225     dann 'false' zurück.  Als Ausweg kann hier die Umwandlung der
6226     Codepunkte in Schriftzeichen über UTF-8-Oktette dienen:
6227
6228     'octets_to_string(unicode_to_utf8(code_point));'
6229
6230     Siehe *note octets_to_string::, *note unicode_to_utf8::.
6231
6232     Falls das unter Maxima liegende Lisp Unicode vollständig
6233     unterstützt, kann ein Schriftzeichen durch seinen Namen angegeben
6234     werden.
6235
6236     Das folgende Beispiel ist mit ECL, CLISP und SBCL möglich, wobei
6237     mit SBCL in wxMaxima in Windows das externe Format auf UTF-8
6238     gesetzt werden muss.  'unicode(name)' wird auch von CMUCL
6239     unterstützt, jedoch wieder beschränkt auf 16-Bit-Zeichen.
6240
6241     Die Zeichenkette als Argument für 'unicode' muss prinzipiell die
6242     sein, die 'printf' mit der Spezifikation "~@c" zurück gibt, jedoch,
6243     wie unten gezeigt, ohne den Präfix "#\".  Unterstriche können durch
6244     Leerzeichen und Groß- durch Kleinbuchstaben ersetzt werden.
6245
6246     Beispiel (fortgesetzt): Ein Schriftzeichen ist durch seinen Namen
6247     gegeben (Maxima kompiliert mit SBCL in GNU/Linux).
6248
6249          (%i3) printf(false, "~@c", unicode(0DF));
6250          (%o3)                    #\LATIN_SMALL_LETTER_SHARP_S
6251          (%i4) unicode("LATIN_SMALL_LETTER_SHARP_S");
6252          (%o4)                                  ß
6253          (%i5) unicode("Latin small letter sharp S");
6254          (%o5)                                  ß
6255
6256 -- Funktion: unicode_to_utf8 (<code_point>)
6257
6258     Gibt eine Liste mit UTF-8-Code zurück, der dem Unicode <code_point>
6259     entspricht.
6260
6261     Beispiel: Umwandlung von Unicode Codepunkten in UTF-8 und
6262     umgekehrt.
6263
6264          (%i1) ibase: obase: 16.$
6265          (%i2) map(cint, ["$","£","Euro"]);
6266          (%o2)                           [24, 0A3, 20AC]
6267          (%i3) map(unicode_to_utf8, %);
6268          (%o3)                 [[24], [0C2, 0A3], [0E2, 82, 0AC]]
6269          (%i4) map(utf8_to_unicode, %);
6270          (%o4)                           [24, 0A3, 20AC]
6271
6272 -- Funktion: uppercasep (<char>)
6273
6274     Gibt 'true' zurück, wenn <char> ein Großbuchstabe ist.
6275
6276     Hinweis: Siehe Bemerkungen zu *note alphacharp::.
6277
6278 -- Variable: us_ascii_only
6279
6280     Diese Optionsvariable beeinflusst Maxima, wenn die Zeichenkodierung
6281     der Anwendung, in der Maxima läuft, UTF-8 ist, das externe Format
6282     des Lisp Readers jedoch nicht.
6283
6284     In GNU/Linux trifft dies zu, wenn Maxima mit GCL kompiliert wurde
6285     und in Windows in wxMaxima in GCL- und SBCL-Versionen.  Es wird
6286     empfohlen, in der SBCL-Version das externe Format in UTF-8
6287     abzuändern.  Eine Festlegung von 'us_ascii_only' wird damit
6288     unnötig.  Siehe *note adjust_external_format:: für Details.
6289
6290     'us_ascii_only' ist standardmäßig 'false'.  Maxima analysiert dann
6291     (d.h.  in der oben beschriebenen Situation) selbst die
6292     UTF-8-Kodierung.
6293
6294     Wurde 'us_ascii_only' auf 'true' gesetzt, wird angenommen, dass
6295     alle Zeichenketten, die als Argumente für Funktionen des Pakets
6296     'stringproc' verwendet werden, nur ausschließlich US-ASCII-Zeichen
6297     enthalten.  Durch diese Vereinbarung wird die UTF-8-Analyse des
6298     Inputs überflüssig und Zeichenketten können effizienter verarbeitet
6299     werden.
6300
6301 -- Function: utf8_to_unicode (<list>)
6302
6303     Gibt den Unicode Codepunkt zurück, der der Liste <list> entspricht,
6304     die die UTF-8-Kodierung eines einzelnen Schriftzeichens enthalten
6305     muss.
6306
6307     Beispiel: Siehe *note unicode_to_utf8::.
6308
6309
6310File: maxima.info,  Node: Verarbeitung von Zeichenketten,  Next: Oktette und Werkzeuge für die Kryptographie,  Prev: Schriftzeichen,  Up: stringproc
6311
631273.4 Verarbeitung von Zeichenketten
6313===================================
6314
6315Positionsindizes in Strings sind in Maxima genau so wie Listen
63161-indiziert.  Siehe hierzu das Beispiel in *note charat::.
6317
6318 -- Funktion: charat (<string>, <n>)
6319
6320     Gibt das <n>-te Schriftzeichen in <string> zurück.  Das erste
6321     Zeichen in <string> erhält man mit <n> = 1.
6322
6323     Beispiel:
6324
6325          (%i1) charat("Lisp",1);
6326          (%o1)                           L
6327          (%i2) charlist("Lisp")[1];
6328          (%o2)                           L
6329
6330 -- Funktion: charlist (<string>)
6331
6332     Gibt eine Liste mit allen Schriftzeichen in <string> zurück.
6333
6334     Beispiel:
6335
6336          (%i1) charlist("Lisp");
6337          (%o1)                     [L, i, s, p]
6338
6339 -- Function: eval_string (<str>)
6340
6341     Parse the string <str> as a Maxima expression and evaluate it.  The
6342     string <str> may or may not have a terminator (dollar sign '$' or
6343     semicolon ';').  Only the first expression is parsed and evaluated,
6344     if there is more than one.
6345
6346     Complain if <str> is not a string.
6347
6348     See also *note parse_string::.
6349
6350     Examples:
6351
6352          (%i1) eval_string ("foo: 42; bar: foo^2 + baz");
6353          (%o1)                       42
6354          (%i2) eval_string ("(foo: 42, bar: foo^2 + baz)");
6355          (%o2)                   baz + 1764
6356
6357 -- Function: parse_string (<str>)
6358
6359     Parse the string <str> as a Maxima expression (do not evaluate it).
6360     The string <str> may or may not have a terminator (dollar sign '$'
6361     or semicolon ';').  Only the first expression is parsed, if there
6362     is more than one.
6363
6364     Complain if <str> is not a string.
6365
6366     See also *note eval_string::.
6367
6368     Examples:
6369
6370          (%i1) parse_string ("foo: 42; bar: foo^2 + baz");
6371          (%o1)                    foo : 42
6372          (%i2) parse_string ("(foo: 42, bar: foo^2 + baz)");
6373                                             2
6374          (%o2)          (foo : 42, bar : foo  + baz)
6375
6376 -- Funktion: scopy (<string>)
6377
6378     Gibt eine Kopie der Zeichenkette <string> als neue Zeichenkette
6379     zurück.
6380
6381 -- Funktion: sdowncase (<string>)
6382 -- Funktion: sdowncase (<string>, <start>)
6383 -- Funktion: sdowncase (<string>, <start>, <end>)
6384
6385     Arbeitet wie *note supcase::, jedoch werden Groß- in
6386     Kleinbuchstaben umgewandelt.
6387
6388 -- Funktion: sequal (<string_1>, <string_2>)
6389
6390     Gibt 'true' zurück, wenn <string_1> und <string_2> die selbe
6391     Zeichensequenz enthalten.
6392
6393 -- Funktion: sequalignore (<string_1>, <string_2>)
6394
6395     Arbeitet wie *note sequal::, ignoriert jedoch die Groß- und
6396     Kleinschreibung, was für Nicht-US-ASCII-Zeichen nur möglich ist,
6397     wenn das unter Maxima liegende Lisp einen Buchstaben auch als
6398     Buchstaben eines Alphabets erkennen kann.  Siehe hierzu die
6399     Bemerkungen zu *note alphacharp::.
6400
6401 -- Funktion: sexplode (<string>)
6402
6403     'sexplode' ist ein Alias für die Funktion *note charlist::.
6404
6405 -- Function: simplode (<list>)
6406 -- Function: simplode (<list>, <delim>)
6407
6408     'simplode' takes a list of expressions and concatenates them into a
6409     string.  If no delimiter <delim> is specified, 'simplode' uses no
6410     delimiter.  <delim> can be any string.
6411
6412     Examples:
6413
6414          (%i1) simplode(["xx[",3,"]:",expand((x+y)^3)]);
6415          (%o1)             xx[3]:y^3+3*x*y^2+3*x^2*y+x^3
6416          (%i2) simplode( sexplode("stars")," * " );
6417          (%o2)                   s * t * a * r * s
6418          (%i3) simplode( ["One","more","coffee."]," " );
6419          (%o3)                   One more coffee.
6420
6421 -- Function: sinsert (<seq>, <string>, <pos>)
6422
6423     Returns a string that is a concatenation of 'substring (<string>,
6424     1, <pos> - 1)', the string <seq> and 'substring (<string>, <pos>)'.
6425     Note that the first character in <string> is in position 1.
6426
6427     Examples:
6428
6429          (%i1) s: "A submarine."$
6430          (%i2) concat( substring(s,1,3),"yellow ",substring(s,3) );
6431          (%o2)                  A yellow submarine.
6432          (%i3) sinsert("hollow ",s,3);
6433          (%o3)                  A hollow submarine.
6434
6435 -- Function: sinvertcase (<string>)
6436 -- Function: sinvertcase (<string>, <start>)
6437 -- Function: sinvertcase (<string>, <start>, <end>)
6438
6439     Returns <string> except that each character from position <start>
6440     to <end> is inverted.  If <end> is not given, all characters from
6441     <start> to the end of <string> are replaced.
6442
6443     Examples:
6444
6445          (%i1) sinvertcase("sInvertCase");
6446          (%o1)                      SiNVERTcASE
6447
6448 -- Funktion: slength (<string>)
6449
6450     Gibt die Anzahl der Zeichen in der Zeichenkette <string> zurück.
6451
6452 -- Funktion: smake (<num>, <char>)
6453
6454     Gibt eine neue Zeichenkette mit <num> Zeichen <char> zurück.
6455
6456     Beispiel:
6457
6458          (%i1) smake(3,"w");
6459          (%o1)                          www
6460
6461 -- Function: smismatch (<string_1>, <string_2>)
6462 -- Function: smismatch (<string_1>, <string_2>, <test>)
6463
6464     Returns the position of the first character of <string_1> at which
6465     <string_1> and <string_2> differ or 'false'.  Default test function
6466     for matching is *note sequal::.  If 'smismatch' should ignore case,
6467     use *note sequalignore:: as test.
6468
6469     Example:
6470
6471          (%i1) smismatch("seven","seventh");
6472          (%o1)                           6
6473
6474 -- Function: split (<string>)
6475 -- Function: split (<string>, <delim>)
6476 -- Function: split (<string>, <delim>, <multiple>)
6477
6478     Returns the list of all tokens in <string>.  Each token is an
6479     unparsed string.  'split' uses <delim> as delimiter.  If <delim> is
6480     not given, the space character is the default delimiter.
6481     <multiple> is a boolean variable with 'true' by default.  Multiple
6482     delimiters are read as one.  This is useful if tabs are saved as
6483     multiple space characters.  If <multiple> is set to 'false', each
6484     delimiter is noted.
6485
6486     Examples:
6487
6488          (%i1) split("1.2   2.3   3.4   4.5");
6489          (%o1)                 [1.2, 2.3, 3.4, 4.5]
6490          (%i2) split("first;;third;fourth",";",false);
6491          (%o2)               [first, , third, fourth]
6492
6493 -- Function: sposition (<char>, <string>)
6494
6495     Returns the position of the first character in <string> which
6496     matches <char>.  The first character in <string> is in position 1.
6497     For matching characters ignoring case see *note ssearch::.
6498
6499 -- Function: sremove (<seq>, <string>)
6500 -- Function: sremove (<seq>, <string>, <test>)
6501 -- Function: sremove (<seq>, <string>, <test>, <start>)
6502 -- Function: sremove (<seq>, <string>, <test>, <start>, <end>)
6503
6504     Returns a string like <string> but without all substrings matching
6505     <seq>.  Default test function for matching is *note sequal::.  If
6506     'sremove' should ignore case while searching for <seq>, use *note
6507     sequalignore:: as test.  Use <start> and <end> to limit searching.
6508     Note that the first character in <string> is in position 1.
6509
6510     Examples:
6511
6512          (%i1) sremove("n't","I don't like coffee.");
6513          (%o1)                   I do like coffee.
6514          (%i2) sremove ("DO ",%,'sequalignore);
6515          (%o2)                    I like coffee.
6516
6517 -- Function: sremovefirst (<seq>, <string>)
6518 -- Function: sremovefirst (<seq>, <string>, <test>)
6519 -- Function: sremovefirst (<seq>, <string>, <test>, <start>)
6520 -- Function: sremovefirst (<seq>, <string>, <test>, <start>, <end>)
6521
6522     Like 'sremove' except that only the first substring that matches
6523     'seq' is removed.
6524
6525 -- Funktion: sreverse (<string>)
6526
6527     Gibt eine Zeichenkette mit allen Zeichen von <string> in
6528     umgekehrter Reihenfolge zurück.
6529
6530 -- Function: ssearch (<seq>, <string>)
6531 -- Function: ssearch (<seq>, <string>, <test>)
6532 -- Function: ssearch (<seq>, <string>, <test>, <start>)
6533 -- Function: ssearch (<seq>, <string>, <test>, <start>, <end>)
6534
6535     Returns the position of the first substring of <string> that
6536     matches the string <seq>.  Default test function for matching is
6537     *note sequal::.  If 'ssearch' should ignore case, use *note
6538     sequalignore:: as test.  Use <start> and <end> to limit searching.
6539     Note that the first character in <string> is in position 1.
6540
6541          (%i1) ssearch("~s","~{~S ~}~%",'sequalignore);
6542          (%o1)                                  4
6543
6544 -- Function: ssort (<string>)
6545 -- Function: ssort (<string>, <test>)
6546
6547     Returns a string that contains all characters from <string> in an
6548     order such there are no two successive characters <c> and <d> such
6549     that 'test (<c>, <d>)' is 'false' and 'test (<d>, <c>)' is 'true'.
6550     Default test function for sorting is *note clessp::.  The set of
6551     test functions is '{*note clessp::, *note clesspignore::, *note
6552     cgreaterp::, *note cgreaterpignore::, *note cequal::, *note
6553     cequalignore::}'.
6554
6555          (%i1) ssort("I don't like Mondays.");
6556          (%o1)                    '.IMaddeiklnnoosty
6557          (%i2) ssort("I don't like Mondays.",'cgreaterpignore);
6558          (%o2)                 ytsoonnMlkIiedda.'
6559
6560 -- Function: ssubst (<new>, <old>, <string>)
6561 -- Function: ssubst (<new>, <old>, <string>, <test>)
6562 -- Function: ssubst (<new>, <old>, <string>, <test>, <start>)
6563 -- Function: ssubst (<new>, <old>, <string>, <test>, <start>, <end>)
6564
6565     Returns a string like <string> except that all substrings matching
6566     <old> are replaced by <new>.  <old> and <new> need not to be of the
6567     same length.  Default test function for matching is *note sequal::.
6568     If 'ssubst' should ignore case while searching for old, use *note
6569     sequalignore:: as test.  Use <start> and <end> to limit searching.
6570     Note that the first character in <string> is in position 1.
6571
6572          (%i1) ssubst("like","hate","I hate Thai food. I hate green tea.");
6573          (%o1)          I like Thai food. I like green tea.
6574          (%i2) ssubst("Indian","thai",%,'sequalignore,8,12);
6575          (%o2)         I like Indian food. I like green tea.
6576
6577 -- Function: ssubstfirst (<new>, <old>, <string>)
6578 -- Function: ssubstfirst (<new>, <old>, <string>, <test>)
6579 -- Function: ssubstfirst (<new>, <old>, <string>, <test>, <start>)
6580 -- Function: ssubstfirst (<new>, <old>, <string>, <test>, <start>,
6581          <end>)
6582
6583     Like *note subst:: except that only the first substring that
6584     matches <old> is replaced.
6585
6586 -- Function: strim (<seq>,<string>)
6587
6588     Returns a string like <string>, but with all characters that appear
6589     in <seq> removed from both ends.
6590
6591          (%i1) "/* comment */"$
6592          (%i2) strim(" /*",%);
6593          (%o2)                        comment
6594          (%i3) slength(%);
6595          (%o3)                           7
6596
6597 -- Function: striml (<seq>, <string>)
6598
6599     Like *note strim:: except that only the left end of <string> is
6600     trimmed.
6601
6602 -- Function: strimr (<seq>, <string>)
6603
6604     Like *note strim:: except that only the right end of string is
6605     trimmed.
6606
6607 -- Funktion: stringp (<obj>)
6608
6609     Gibt 'true' zurück, wenn <obj> eine Zeichenkette ist.
6610
6611     Beispiel: Siehe Einführung.
6612
6613 -- Function: substring (<string>, <start>)
6614 -- Function: substring (<string>, <start>, <end>)
6615
6616     Returns the substring of <string> beginning at position <start> and
6617     ending at position <end>.  The character at position <end> is not
6618     included.  If <end> is not given, the substring contains the rest
6619     of the string.  Note that the first character in <string> is in
6620     position 1.
6621
6622          (%i1) substring("substring",4);
6623          (%o1)                        string
6624          (%i2) substring(%,4,6);
6625          (%o2)                          in
6626
6627 -- Function: supcase (<string>)
6628 -- Function: supcase (<string>, <start>)
6629 -- Function: supcase (<string>, <start>, <end>)
6630
6631     Returns <string> except that lowercase characters from position
6632     <start> to <end> are replaced by the corresponding uppercase ones.
6633     If <end> is not given, all lowercase characters from <start> to the
6634     end of <string> are replaced.
6635
6636          (%i1) supcase("english",1,2);
6637          (%o1)                        English
6638
6639 -- Function: tokens (<string>)
6640 -- Function: tokens (<string>, <test>)
6641
6642     Returns a list of tokens, which have been extracted from <string>.
6643     The tokens are substrings whose characters satisfy a certain test
6644     function.  If <test> is not given, <constituent> is used as the
6645     default test.  '{constituent, alphacharp, digitcharp, lowercasep,
6646     uppercasep, charp, characterp, alphanumericp}' is the set of test
6647     functions.  (The Lisp-version of 'tokens' is written by Paul
6648     Graham.  ANSI Common Lisp, 1996, page 67.)
6649
6650          (%i1) tokens("24 October 2005");
6651          (%o1)                  [24, October, 2005]
6652          (%i2) tokens("05-10-24",'digitcharp);
6653          (%o2)                     [05, 10, 24]
6654          (%i3) map(parse_string,%);
6655          (%o3)                      [5, 10, 24]
6656
6657
6658File: maxima.info,  Node: Oktette und Werkzeuge für die Kryptographie,  Prev: Verarbeitung von Zeichenketten,  Up: stringproc
6659
666073.5 Oktette und Werkzeuge für die Kryptographie
6661================================================
6662
6663 -- Funktion: base64 (<arg>)
6664
6665     Gibt eine Base64-Darstellung von <arg> zurück.  Das Argument <arg>
6666     kann eine Zeichenkette, eine nicht-negative Ganzzahl oder eine
6667     Liste von Oktetten sein.
6668
6669     Beispiel:
6670
6671          (%i1) base64: base64("foo bar baz");
6672          (%o1)                          Zm9vIGJhciBiYXo=
6673          (%i2) string: base64_decode(base64);
6674          (%o2)                            foo bar baz
6675          (%i3) obase: 16.$
6676          (%i4) integer: base64_decode(base64, 'number);
6677          (%o4)                       666f6f206261722062617a
6678          (%i5) octets: base64_decode(base64, 'list);
6679          (%o5)            [66, 6F, 6F, 20, 62, 61, 72, 20, 62, 61, 7A]
6680          (%i6) ibase: 16.$
6681          (%i7) base64(octets);
6682          (%o7)                          Zm9vIGJhciBiYXo=
6683
6684     Sind in <arg> Umlaute oder Eszett enthalten (bzw.  Oktette größer
6685     als 127), ist das Ergebnis von der verwendeten Plattform abhängig.
6686     Es wird aber durch eine Anwendung von *note base64_decode:: in
6687     jedem Fall wieder in die ursprüngliche Zeichenkette zurück
6688     verwandelt.
6689
6690 -- Funktion: base64_decode (<base64-string>)
6691 -- Funktion: base64_decode (<base64-string>, <return-type>)
6692
6693     Dekodiert die Base64-kodierte Zeichenkette <base64-string>
6694     standardmäßig wieder zurück in die ursprüngliche Zeichenkette.
6695
6696     Das optionale Argument <return-type> erlaubt es 'base64_decode',
6697     alternativ hierzu auch die entsprechende Ganzzahl oder Liste von
6698     Oktetten zurück zu geben.  <return-type> kann 'string', 'number'
6699     oder 'list' sein.
6700
6701     Beispiel: Siehe *note base64::.
6702
6703 -- Funktion: crc24sum (<octets>)
6704 -- Funktion: crc24sum (<octets>, <return-type>)
6705
6706     Gibt standardmäßig die 'CRC24'-Prüfsumme einer Oktett-Liste als
6707     Zeichenkette zurück.
6708
6709     Das optionale Argument <return-type> erlaubt es 'crc24sum',
6710     alternativ hierzu auch die entsprechende Ganzzahl oder Liste von
6711     Oktetten zurück zu geben.  <return-type> kann 'string', 'number'
6712     oder 'list' sein.
6713
6714     Beispiel:
6715          -----BEGIN PGP SIGNATURE-----
6716          Version: GnuPG v2.0.22 (GNU/Linux)
6717
6718          iQEcBAEBAgAGBQJVdCTzAAoJEG/1Mgf2DWAqCSYH/AhVFwhu1D89C3/QFcgVvZTM
6719          wnOYzBUURJAL/cT+IngkLEpp3hEbREcugWp+Tm6aw3R4CdJ7G3FLxExBH/5KnDHi
6720          rBQu+I7+3ySK2hpryQ6Wx5J9uZSa4YmfsNteR8up0zGkaulJeWkS4pjiRM+auWVe
6721          vajlKZCIK52P080DG7Q2dpshh4fgTeNwqCuCiBhQ73t8g1IaLdhDN6EzJVjGIzam
6722          /spqT/sTo6sw8yDOJjvU+Qvn6/mSMjC/YxjhRMaQt9EMrR1AZ4ukBF5uG1S7mXOH
6723          WdiwkSPZ3gnIBhM9SuC076gLWZUNs6NqTeE3UzMjDAFhH3jYk1T7mysCvdtIkms=
6724          =WmeC
6725          -----END PGP SIGNATURE-----
6726
6727          (%i1) ibase : obase : 16.$
6728          (%i2) sig64 : sconcat(
6729           "iQEcBAEBAgAGBQJVdCTzAAoJEG/1Mgf2DWAqCSYH/AhVFwhu1D89C3/QFcgVvZTM",
6730           "wnOYzBUURJAL/cT+IngkLEpp3hEbREcugWp+Tm6aw3R4CdJ7G3FLxExBH/5KnDHi",
6731           "rBQu+I7+3ySK2hpryQ6Wx5J9uZSa4YmfsNteR8up0zGkaulJeWkS4pjiRM+auWVe",
6732           "vajlKZCIK52P080DG7Q2dpshh4fgTeNwqCuCiBhQ73t8g1IaLdhDN6EzJVjGIzam",
6733           "/spqT/sTo6sw8yDOJjvU+Qvn6/mSMjC/YxjhRMaQt9EMrR1AZ4ukBF5uG1S7mXOH",
6734           "WdiwkSPZ3gnIBhM9SuC076gLWZUNs6NqTeE3UzMjDAFhH3jYk1T7mysCvdtIkms=" )$
6735          (%i3) octets: base64_decode(sig64, 'list)$
6736          (%i4) crc24: crc24sum(octets, 'list);
6737          (%o4)                          [5A, 67, 82]
6738          (%i5) base64(crc24);
6739          (%o5)                              WmeC
6740
6741 -- Funktion: md5sum (<arg>)
6742 -- Funktion: md5sum (<arg>, <return-type>)
6743
6744     Gibt die 'md5'-Prüfsumme einer Zeichenkette, einer nicht-negativen
6745     Ganzzahl oder einer Liste von Oktetten zurück.  Der standardmäßige
6746     Rückgabewert ist eine Zeichenkette mit 32 hexadezimalen Zeichen.
6747
6748     Das optionale Argument <return-type> erlaubt es 'md5sum',
6749     alternativ hierzu auch die entsprechende Ganzzahl oder Liste von
6750     Oktetten zurück zu geben.  <return-type> kann 'string', 'number'
6751     oder 'list' sein.
6752
6753     Beispiel:
6754
6755          (%i1) ibase: obase: 16.$
6756          (%i2) msg: "foo bar baz"$
6757          (%i3) string: md5sum(msg);
6758          (%o3)                  ab07acbb1e496801937adfa772424bf7
6759          (%i4) integer: md5sum(msg, 'number);
6760          (%o4)                 0ab07acbb1e496801937adfa772424bf7
6761          (%i5) octets: md5sum(msg, 'list);
6762          (%o5)        [0AB,7,0AC,0BB,1E,49,68,1,93,7A,0DF,0A7,72,42,4B,0F7]
6763          (%i6) sdowncase( printf(false, "~{~2,'0x~^:~}", octets) );
6764          (%o6)           ab:07:ac:bb:1e:49:68:01:93:7a:df:a7:72:42:4b:f7
6765
6766     Sind in <arg> Umlaute oder andere Nicht-US-ASCII-Zeichen enthalten
6767     (bzw.  Oktette größer als 127), ist das Ergebnis von der
6768     verwendeten Plattform abhängig.
6769
6770 -- Funktion: mgf1_sha1 (<seed>, <len>)
6771 -- Funktion: mgf1_sha1 (<seed>, <len>, <return-type>)
6772
6773     Gibt eine Pseudozufallszahl variabler Länge zurück.  Standardmäßig
6774     ist dies eine Zahl mit einer Länge von <len> Oktetten.
6775
6776     Das optionale Argument <return-type> erlaubt es 'mgf1_sha1',
6777     alternativ hierzu die Liste mit den <len> entsprechenden Oktetten
6778     zurück zu geben.  <return-type> kann 'number' oder 'list' sein.
6779
6780     Die Berechnung des Rückgabewerts wird in der 'RFC 3447' im Anhang
6781     'B.2.1 MGF1' beschrieben.  Verwendet wird dabei 'SHA1' als
6782     Hashfunktion, d.h.  die Zufälligkeit der berechneten Zahl beruht
6783     auf der Zufälligkeit von 'SHA1'-Hashwerten.
6784
6785     Beispiel:
6786
6787          (%i1) ibase: obase: 16.$
6788          (%i2) number: mgf1_sha1(4711., 8);
6789          (%o2)                        0e0252e5a2a42fea1
6790          (%i3) octets: mgf1_sha1(4711., 8, 'list);
6791          (%o3)                  [0E0,25,2E,5A,2A,42,0FE,0A1]
6792
6793 -- Funktion: number_to_octets (<number>)
6794
6795     Gibt eine Oktett-Darstellung der nicht-negativen Ganzzahl <number>
6796     in Form einer Liste zurück.
6797
6798     Beispiel:
6799
6800          (%i1) ibase : obase : 16.$
6801          (%i2) octets: [0ca,0fe,0ba,0be]$
6802          (%i3) number: octets_to_number(octets);
6803          (%o3)                            0cafebabe
6804          (%i4) number_to_octets(number);
6805          (%o4)                      [0CA, 0FE, 0BA, 0BE]
6806
6807 -- Funktion: octets_to_number (<octets>)
6808
6809     Fügt die in der Liste <octets> enthaltenden Oktette zu einer Zahl
6810     zusammen und gibt diese zurück.
6811
6812     Beispiel: Siehe *note number_to_octets::.
6813
6814 -- Funktion: octets_to_oid (<octets>)
6815
6816     Berechnet eine Objektkennung (OID) aus einer Liste von Oktetten.
6817
6818     Beispiel: RSA encryption OID
6819
6820          (%i1) ibase : obase : 16.$
6821          (%i2) oid: octets_to_oid([2A,86,48,86,0F7,0D,1,1,1]);
6822          (%o2)                      1.2.840.113549.1.1.1
6823          (%i3) oid_to_octets(oid);
6824          (%o3)               [2A, 86, 48, 86, 0F7, 0D, 1, 1, 1]
6825
6826 -- Funktion: octets_to_string (<octets>)
6827 -- Funktion: octets_to_string (<octets>, <encoding>)
6828
6829     Dekodiert den aktuellen Systemstandards entsprechend die Liste
6830     <octets> in eine Zeichenkette.  Bei der Dekodierung von Oktetten,
6831     die nicht ausschließlich US-ASCII-Zeichen entsprechen, ist das
6832     Ergebnis abhängig von der Plattform, der Anwendung und vom unter
6833     Maxima liegenden Lisp.
6834
6835     Beispiel: Die Verwendung des Systemstandards (Maxima kompiliert mit
6836     GCL, das keine Format-Definition verwendet und die vom GNU/Linux
6837     Terminal kodierten UTF-8-Oktette ungeändert an Maxima weitergibt).
6838
6839          (%i1) octets: string_to_octets("abc");
6840          (%o1)                            [61, 62, 63]
6841          (%i2) octets_to_string(octets);
6842          (%o2)                                 abc
6843          (%i3) ibase: obase: 16.$
6844          (%i4) unicode(20AC);
6845          (%o4)                                  Euro
6846          (%i5) octets: string_to_octets(%);
6847          (%o5)                           [0E2, 82, 0AC]
6848          (%i6) octets_to_string(octets);
6849          (%o6)                                  Euro
6850          (%i7) utf8_to_unicode(octets);
6851          (%o7)                                20AC
6852
6853     In dem Fall, dass UTF-8 das externe Format des Lisp Readers ist,
6854     kann das optionale Argument <encoding> genutzt werden, um für die
6855     Oktett-String-Umwandlung eine gewünschte Kodierung auszuwählen.
6856     Siehe *note adjust_external_format::, falls es notwendig sein
6857     sollte, hierfür das externe Format zu ändern.
6858
6859     Die Namen einiger unterstützter Kodierungen (weitere siehe das
6860     entsprechende Lisp Manual):
6861     CCL, CLISP, SBCL: 'utf-8, ucs-2be, ucs-4be, iso-8859-1, cp1252,
6862     cp850'
6863     CMUCL: 'utf-8, utf-16-be, utf-32-be, iso8859-1, cp1252'
6864     ECL: 'utf-8, ucs-2be, ucs-4be, iso-8859-1, windows-cp1252,
6865     dos-cp850'
6866
6867     Beispiel (fortgesetzt): Die Verwendung des optionalen Arguments
6868     (Maxima kompiliert mit SBCL, GNU/Linux Terminal).
6869
6870          (%i8) string_to_octets("Euro", "ucs-2be");
6871          (%o8)                              [20, 0AC]
6872
6873 -- Funktion: oid_to_octets (<oid-string>)
6874
6875     Verwandelt eine Objektkennung (OID) in eine Liste von Oktetten.
6876
6877     Beispiel: Siehe *note octets_to_oid::.
6878
6879 -- Funktion: sha1sum (<arg>)
6880 -- Funktion: sha1sum (<arg>, <return-type>)
6881
6882     Gibt den 'SHA1'-Fingerabdruck einer Zeichenkette, einer
6883     nicht-negativen Ganzzahl oder einer Liste von Oktetten zurück.  Der
6884     standardmäßige Rückgabewert ist eine Zeichenkette mit 40
6885     hexadezimalen Zeichen.
6886
6887     Das optionale Argument <return-type> erlaubt es 'sha1sum',
6888     alternativ hierzu auch die entsprechende Ganzzahl oder Liste von
6889     Oktetten zurück zu geben.  <return-type> kann 'string', 'number'
6890     oder 'list' sein.
6891
6892     Beispiel:
6893
6894          (%i1) ibase: obase: 16.$
6895          (%i2) msg: "foo bar baz"$
6896          (%i3) string: sha1sum(msg);
6897          (%o3)              c7567e8b39e2428e38bf9c9226ac68de4c67dc39
6898          (%i4) integer: sha1sum(msg, 'number);
6899          (%o4)             0c7567e8b39e2428e38bf9c9226ac68de4c67dc39
6900          (%i5) octets: sha1sum(msg, 'list);
6901          (%o5)  [0C7,56,7E,8B,39,0E2,42,8E,38,0BF,9C,92,26,0AC,68,0DE,4C,67,0DC,39]
6902          (%i6) sdowncase( printf(false, "~{~2,'0x~^:~}", octets) );
6903          (%o6)     c7:56:7e:8b:39:e2:42:8e:38:bf:9c:92:26:ac:68:de:4c:67:dc:39
6904
6905     Sind in <arg> Umlaute oder andere Nicht-US-ASCII-Zeichen enthalten
6906     (bzw.  Oktette größer als 127), ist der 'SHA1'-Fingerabdruck von
6907     der verwendeten Plattform abhängig.
6908
6909 -- Funktion: sha256sum (<arg>)
6910 -- Funktion: sha256sum (<arg>, <return-type>)
6911
6912     Gibt den 'SHA256'-Fingerabdruck einer Zeichenkette, einer
6913     nicht-negativen Ganzzahl oder einer Liste von Oktetten zurück.  Der
6914     standardmäßige Rückgabewert ist eine Zeichenkette mit 64
6915     hexadezimalen Zeichen.
6916
6917     Das optionale Argument <return-type> erlaubt es 'sha256sum',
6918     alternativ hierzu auch die entsprechende Ganzzahl oder Liste von
6919     Oktetten zurück zu geben (siehe *note sha1sum::).
6920
6921     Beispiel:
6922
6923          (%i1) string: sha256sum("foo bar baz");
6924          (%o1)  dbd318c1c462aee872f41109a4dfd3048871a03dedd0fe0e757ced57dad6f2d7
6925
6926     Sind in <arg> Umlaute oder andere Nicht-US-ASCII-Zeichen enthalten
6927     (bzw.  Oktette größer als 127), ist der 'SHA256'-Fingerabdruck von
6928     der verwendeten Plattform abhängig.
6929
6930 -- Funktion: string_to_octets (<string>)
6931 -- Funktion: string_to_octets (<string>, <encoding>)
6932
6933     Kodiert den aktuellen Systemstandards entsprechend die Zeichenkette
6934     <string> in eine Liste von Oktetten.  Bei der Kodierung von
6935     Zeichenketten, die nicht ausschließlich US-ASCII-Zeichen enthalten,
6936     ist das Ergebnis abhängig von der Plattform, der Anwendung und vom
6937     unter Maxima liegenden Lisp.
6938
6939     In dem Fall, dass UTF-8 das externe Format des Lisp Readers ist,
6940     kann das optionale Argument <encoding> genutzt werden, um für die
6941     String-Oktett-Umwandlung eine gewünschte Kodierung auszuwählen.
6942     Siehe *note adjust_external_format::, falls es notwendig sein
6943     sollte, hierfür das externe Format zu ändern.
6944
6945     Siehe *note octets_to_string:: für Beispiele und zusätzliche
6946     Informationen.
6947
6948
6949File: maxima.info,  Node: symmetries,  Next: to_poly_solve,  Prev: stringproc,  Up: Top
6950
695174 symmetries
6952*************
6953
6954* Menu:
6955
6956* Introduction to Symmetries::
6957* Functions and Variables for Symmetries::
6958
6959
6960File: maxima.info,  Node: Introduction to Symmetries,  Next: Functions and Variables for Symmetries,  Prev: symmetries,  Up: symmetries
6961
696274.1 Introduction to Symmetries
6963===============================
6964
6965'sym' is a package for working with symmetric groups of polynomials.
6966
6967It was written for Macsyma-Symbolics by Annick Valibouze
6968(<http://www-calfor.lip6.fr/~avb/>).  The algorithms are described in
6969the following papers:
6970
6971  1. Fonctions symétriques et changements de bases.  Annick Valibouze.
6972     EUROCAL'87 (Leipzig, 1987), 323-332, Lecture Notes in Comput.  Sci
6973     378.  Springer, Berlin, 1989.
6974     <http://www.stix.polytechnique.fr/publications/1984-1994.html>
6975
6976  2. Résolvantes et fonctions symétriques.  Annick Valibouze.
6977     Proceedings of the ACM-SIGSAM 1989 International Symposium on
6978     Symbolic and Algebraic Computation, ISSAC'89 (Portland, Oregon).
6979     ACM Press, 390-399, 1989.
6980     <http://www-calfor.lip6.fr/~avb/DonneesTelechargeables/MesArticles/issac89ACMValibouze.pdf>
6981
6982  3. Symbolic computation with symmetric polynomials, an extension to
6983     Macsyma.  Annick Valibouze.  Computers and Mathematics (MIT, USA,
6984     June 13-17, 1989), Springer-Verlag, New York Berlin, 308-320, 1989.
6985     <http://www.stix.polytechnique.fr/publications/1984-1994.html>
6986
6987  4. Théorie de Galois Constructive.  Annick Valibouze.  Mémoire
6988     d'habilitation à diriger les recherches (HDR), Université P. et M.
6989     Curie (Paris VI), 1994.
6990
6991
6992File: maxima.info,  Node: Functions and Variables for Symmetries,  Prev: Introduction to Symmetries,  Up: symmetries
6993
699474.2 Functions and Variables for Symmetries
6995===========================================
6996
699774.2.1 Changing bases
6998---------------------
6999
7000 -- Function: comp2pui (<n>, <L>)
7001
7002     implements passing from the complete symmetric functions given in
7003     the list <L> to the elementary symmetric functions from 0 to <n>.
7004     If the list <L> contains fewer than <n+1> elements, it will be
7005     completed with formal values of the type <h1>, <h2>, etc.  If the
7006     first element of the list <L> exists, it specifies the size of the
7007     alphabet, otherwise the size is set to <n>.
7008
7009          (%i1) comp2pui (3, [4, g]);
7010                                  2                    2
7011          (%o1)    [4, g, 2 h2 - g , 3 h3 - g h2 + g (g  - 2 h2)]
7012
7013 -- Function: ele2pui (<m>, <L>)
7014
7015     goes from the elementary symmetric functions to the complete
7016     functions.  Similar to 'comp2ele' and 'comp2pui'.
7017
7018     Other functions for changing bases: 'comp2ele'.
7019
7020 -- Function: ele2comp (<m>, <L>)
7021
7022     Goes from the elementary symmetric functions to the compete
7023     functions.  Similar to 'comp2ele' and 'comp2pui'.
7024
7025     Other functions for changing bases: 'comp2ele'.
7026
7027 -- Function: elem (<ele>, <sym>, <lvar>)
7028
7029     decomposes the symmetric polynomial <sym>, in the variables
7030     contained in the list <lvar>, in terms of the elementary symmetric
7031     functions given in the list <ele>.  If the first element of <ele>
7032     is given, it will be the size of the alphabet, otherwise the size
7033     will be the degree of the polynomial <sym>.  If values are missing
7034     in the list <ele>, formal values of the type <e1>, <e2>, etc.  will
7035     be added.  The polynomial <sym> may be given in three different
7036     forms: contracted ('elem' should then be 1, its default value),
7037     partitioned ('elem' should be 3), or extended (i.e.  the entire
7038     polynomial, and 'elem' should then be 2).  The function 'pui' is
7039     used in the same way.
7040
7041     On an alphabet of size 3 with <e1>, the first elementary symmetric
7042     function, with value 7, the symmetric polynomial in 3 variables
7043     whose contracted form (which here depends on only two of its
7044     variables) is <x^4-2*x*y> decomposes as follows in elementary
7045     symmetric functions:
7046
7047          (%i1) elem ([3, 7], x^4 - 2*x*y, [x, y]);
7048          (%o1) 7 (e3 - 7 e2 + 7 (49 - e2)) + 21 e3
7049
7050                                                   + (- 2 (49 - e2) - 2) e2
7051          (%i2) ratsimp (%);
7052                                        2
7053          (%o2)             28 e3 + 2 e2  - 198 e2 + 2401
7054
7055     Other functions for changing bases: 'comp2ele'.
7056
7057 -- Function: mon2schur (<L>)
7058
7059     The list <L> represents the Schur function S_L: we have L = [i_1,
7060     i_2, ..., i_q], with i_1 <= i_2 <= ... <= i_q.  The Schur function
7061     S_[i_1, i_2, ..., i_q] is the minor of the infinite matrix h_[i-j],
7062     i <= 1, j <= 1, consisting of the q first rows and the columns 1 +
7063     i_1, 2 + i_2, ..., q + i_q.
7064
7065     This Schur function can be written in terms of monomials by using
7066     'treinat' and 'kostka'.  The form returned is a symmetric
7067     polynomial in a contracted representation in the variables
7068     x_1,x_2,...
7069
7070          (%i1) mon2schur ([1, 1, 1]);
7071          (%o1)                       x1 x2 x3
7072          (%i2) mon2schur ([3]);
7073                                            2        3
7074          (%o2)                x1 x2 x3 + x1  x2 + x1
7075          (%i3) mon2schur ([1, 2]);
7076                                                2
7077          (%o3)                  2 x1 x2 x3 + x1  x2
7078
7079     which means that for 3 variables this gives:
7080
7081             2 x1 x2 x3 + x1^2 x2 + x2^2 x1 + x1^2 x3 + x3^2 x1
7082              + x2^2 x3 + x3^2 x2
7083     Other functions for changing bases: 'comp2ele'.
7084
7085 -- Function: multi_elem (<l_elem>, <multi_pc>, <l_var>)
7086
7087     decomposes a multi-symmetric polynomial in the multi-contracted
7088     form <multi_pc> in the groups of variables contained in the list of
7089     lists <l_var> in terms of the elementary symmetric functions
7090     contained in <l_elem>.
7091
7092          (%i1) multi_elem ([[2, e1, e2], [2, f1, f2]], a*x + a^2 + x^3,
7093                [[x, y], [a, b]]);
7094                                                            3
7095          (%o1)         - 2 f2 + f1 (f1 + e1) - 3 e1 e2 + e1
7096          (%i2) ratsimp (%);
7097                                   2                       3
7098          (%o2)         - 2 f2 + f1  + e1 f1 - 3 e1 e2 + e1
7099
7100     Other functions for changing bases: 'comp2ele'.
7101
7102 -- Function: multi_pui
7103
7104     is to the function 'pui' what the function 'multi_elem' is to the
7105     function 'elem'.
7106
7107          (%i1) multi_pui ([[2, p1, p2], [2, t1, t2]], a*x + a^2 + x^3,
7108                [[x, y], [a, b]]);
7109                                                      3
7110                                          3 p1 p2   p1
7111          (%o1)              t2 + p1 t1 + ------- - ---
7112                                             2       2
7113
7114 -- Function: pui (<L>, <sym>, <lvar>)
7115
7116     decomposes the symmetric polynomial <sym>, in the variables in the
7117     list <lvar>, in terms of the power functions in the list <L>.  If
7118     the first element of <L> is given, it will be the size of the
7119     alphabet, otherwise the size will be the degree of the polynomial
7120     <sym>.  If values are missing in the list <L>, formal values of the
7121     type <p1>, <p2> , etc.  will be added.  The polynomial <sym> may be
7122     given in three different forms: contracted ('elem' should then be
7123     1, its default value), partitioned ('elem' should be 3), or
7124     extended (i.e.  the entire polynomial, and 'elem' should then be
7125     2).  The function 'pui' is used in the same way.
7126
7127          (%i1) pui;
7128          (%o1)                           1
7129          (%i2) pui ([3, a, b], u*x*y*z, [x, y, z]);
7130                                 2
7131                             a (a  - b) u   (a b - p3) u
7132          (%o2)              ------------ - ------------
7133                                  6              3
7134          (%i3) ratsimp (%);
7135                                                 3
7136                                (2 p3 - 3 a b + a ) u
7137          (%o3)                 ---------------------
7138                                          6
7139     Other functions for changing bases: 'comp2ele'.
7140
7141 -- Function: pui2comp (<n>, <lpui>)
7142
7143     renders the list of the first <n> complete functions (with the
7144     length first) in terms of the power functions given in the list
7145     <lpui>.  If the list <lpui> is empty, the cardinal is <n>,
7146     otherwise it is its first element (as in 'comp2ele' and
7147     'comp2pui').
7148
7149          (%i1) pui2comp (2, []);
7150                                                 2
7151                                          p2 + p1
7152          (%o1)                   [2, p1, --------]
7153                                             2
7154          (%i2) pui2comp (3, [2, a1]);
7155                                                      2
7156                                           a1 (p2 + a1 )
7157                                   2  p3 + ------------- + a1 p2
7158                            p2 + a1              2
7159          (%o2)     [2, a1, --------, --------------------------]
7160                               2                  3
7161          (%i3) ratsimp (%);
7162                                      2                     3
7163                               p2 + a1   2 p3 + 3 a1 p2 + a1
7164          (%o3)        [2, a1, --------, --------------------]
7165                                  2               6
7166     Other functions for changing bases: 'comp2ele'.
7167
7168 -- Function: pui2ele (<n>, <lpui>)
7169
7170     effects the passage from power functions to the elementary
7171     symmetric functions.  If the flag 'pui2ele' is 'girard', it will
7172     return the list of elementary symmetric functions from 1 to <n>,
7173     and if the flag is 'close', it will return the <n>-th elementary
7174     symmetric function.
7175
7176     Other functions for changing bases: 'comp2ele'.
7177
7178 -- Function: puireduc (<n>, <lpui>)
7179
7180     <lpui> is a list whose first element is an integer <m>.  'puireduc'
7181     gives the first <n> power functions in terms of the first <m>.
7182
7183          (%i1) puireduc (3, [2]);
7184                                                   2
7185                                             p1 (p1  - p2)
7186          (%o1)          [2, p1, p2, p1 p2 - -------------]
7187                                                   2
7188          (%i2) ratsimp (%);
7189                                                     3
7190                                         3 p1 p2 - p1
7191          (%o2)              [2, p1, p2, -------------]
7192                                               2
7193
7194 -- Function: schur2comp (<P>, <l_var>)
7195
7196     <P> is a polynomial in the variables of the list <l_var>.  Each of
7197     these variables represents a complete symmetric function.  In
7198     <l_var> the <i>-th complete symmetric function is represented by
7199     the concatenation of the letter 'h' and the integer <i>: 'h<i>'.
7200     This function expresses <P> in terms of Schur functions.
7201
7202          (%i1) schur2comp (h1*h2 - h3, [h1, h2, h3]);
7203          (%o1)                         s
7204                                         1, 2
7205          (%i2) schur2comp (a*h3, [h3]);
7206          (%o2)                         s  a
7207                                         3
7208
720974.2.2 Changing representations
7210-------------------------------
7211
7212 -- Function: cont2part (<pc>, <lvar>)
7213
7214     returns the partitioned polynomial associated to the contracted
7215     form <pc> whose variables are in <lvar>.
7216
7217          (%i1) pc: 2*a^3*b*x^4*y + x^5;
7218                                     3    4      5
7219          (%o1)                   2 a  b x  y + x
7220          (%i2) cont2part (pc, [x, y]);
7221                                             3
7222          (%o2)              [[1, 5, 0], [2 a  b, 4, 1]]
7223
7224 -- Function: contract (<psym>, <lvar>)
7225
7226     returns a contracted form (i.e.  a monomial orbit under the action
7227     of the symmetric group) of the polynomial <psym> in the variables
7228     contained in the list <lvar>.  The function 'explose' performs the
7229     inverse operation.  The function 'tcontract' tests the symmetry of
7230     the polynomial.
7231
7232          (%i1) psym: explose (2*a^3*b*x^4*y, [x, y, z]);
7233                   3      4      3      4      3    4        3    4
7234          (%o1) 2 a  b y z  + 2 a  b x z  + 2 a  b y  z + 2 a  b x  z
7235
7236                                                     3      4      3    4
7237                                                + 2 a  b x y  + 2 a  b x  y
7238          (%i2) contract (psym, [x, y, z]);
7239                                        3    4
7240          (%o2)                      2 a  b x  y
7241
7242 -- Function: explose (<pc>, <lvar>)
7243
7244     returns the symmetric polynomial associated with the contracted
7245     form <pc>.  The list <lvar> contains the variables.
7246
7247          (%i1) explose (a*x + 1, [x, y, z]);
7248          (%o1)                  a z + a y + a x + 1
7249
7250 -- Function: part2cont (<ppart>, <lvar>)
7251
7252     goes from the partitioned form to the contracted form of a
7253     symmetric polynomial.  The contracted form is rendered with the
7254     variables in <lvar>.
7255
7256          (%i1) part2cont ([[2*a^3*b, 4, 1]], [x, y]);
7257                                        3    4
7258          (%o1)                      2 a  b x  y
7259
7260 -- Function: partpol (<psym>, <lvar>)
7261
7262     <psym> is a symmetric polynomial in the variables of the list
7263     <lvar>.  This function retturns its partitioned representation.
7264
7265          (%i1) partpol (-a*(x + y) + 3*x*y, [x, y]);
7266          (%o1)               [[3, 1, 1], [- a, 1, 0]]
7267
7268 -- Function: tcontract (<pol>, <lvar>)
7269
7270     tests if the polynomial <pol> is symmetric in the variables of the
7271     list <lvar>.  If so, it returns a contracted representation like
7272     the function 'contract'.
7273
7274 -- Function: tpartpol (<pol>, <lvar>)
7275
7276     tests if the polynomial <pol> is symmetric in the variables of the
7277     list <lvar>.  If so, it returns its partitioned representation like
7278     the function 'partpol'.
7279
728074.2.3 Groups and orbits
7281------------------------
7282
7283 -- Function: direct ([<p_1>, ..., <p_n>], <y>, <f>, [<lvar_1>, ...,
7284          <lvar_n>])
7285     calculates the direct image (see M. Giusti, D. Lazard et A.
7286     Valibouze, ISSAC 1988, Rome) associated to the function <f>, in the
7287     lists of variables <lvar_1>, ..., <lvar_n>, and in the polynomials
7288     <p_1>, ..., <p_n> in a variable <y>.  The arity of the function <f>
7289     is important for the calulation.  Thus, if the expression for <f>
7290     does not depend on some variable, it is useless to include this
7291     variable, and not including it will also considerably reduce the
7292     amount of computation.
7293
7294          (%i1) direct ([z^2  - e1* z + e2, z^2  - f1* z + f2],
7295                        z, b*v + a*u, [[u, v], [a, b]]);
7296                 2
7297          (%o1) y  - e1 f1 y
7298
7299                                           2            2             2   2
7300                            - 4 e2 f2 - (e1  - 2 e2) (f1  - 2 f2) + e1  f1
7301                          + -----------------------------------------------
7302                                                   2
7303          (%i2) ratsimp (%);
7304                        2                2                   2
7305          (%o2)        y  - e1 f1 y + (e1  - 4 e2) f2 + e2 f1
7306          (%i3) ratsimp (direct ([z^3-e1*z^2+e2*z-e3,z^2  - f1* z + f2],
7307                        z, b*v + a*u, [[u, v], [a, b]]));
7308                 6            5         2                        2    2   4
7309          (%o3) y  - 2 e1 f1 y  + ((2 e1  - 6 e2) f2 + (2 e2 + e1 ) f1 ) y
7310
7311                                    3                               3   3
7312           + ((9 e3 + 5 e1 e2 - 2 e1 ) f1 f2 + (- 2 e3 - 2 e1 e2) f1 ) y
7313
7314                   2       2        4    2
7315           + ((9 e2  - 6 e1  e2 + e1 ) f2
7316
7317                              2       2       2                   2    4
7318           + (- 9 e1 e3 - 6 e2  + 3 e1  e2) f1  f2 + (2 e1 e3 + e2 ) f1 )
7319
7320            2          2                      2     3          2
7321           y  + (((9 e1  - 27 e2) e3 + 3 e1 e2  - e1  e2) f1 f2
7322
7323                           2            2    3                5
7324           + ((15 e2 - 2 e1 ) e3 - e1 e2 ) f1  f2 - 2 e2 e3 f1 ) y
7325
7326                     2                   3           3     2   2    3
7327           + (- 27 e3  + (18 e1 e2 - 4 e1 ) e3 - 4 e2  + e1  e2 ) f2
7328
7329                   2      3                   3    2   2
7330           + (27 e3  + (e1  - 9 e1 e2) e3 + e2 ) f1  f2
7331
7332                             2    4        2   6
7333           + (e1 e2 e3 - 9 e3 ) f1  f2 + e3  f1
7334
7335     Finding the polynomial whose roots are the sums a+u where a is a
7336     root of z^2 - e_1 z + e_2 and u is a root of z^2 - f_1 z + f_2.
7337
7338          (%i1) ratsimp (direct ([z^2 - e1* z + e2, z^2 - f1* z + f2],
7339                                    z, a + u, [[u], [a]]));
7340                 4                    3             2
7341          (%o1) y  + (- 2 f1 - 2 e1) y  + (2 f2 + f1  + 3 e1 f1 + 2 e2
7342
7343               2   2                              2               2
7344           + e1 ) y  + ((- 2 f1 - 2 e1) f2 - e1 f1  + (- 2 e2 - e1 ) f1
7345
7346                            2                     2            2
7347           - 2 e1 e2) y + f2  + (e1 f1 - 2 e2 + e1 ) f2 + e2 f1  + e1 e2 f1
7348
7349               2
7350           + e2
7351
7352     'direct' accepts two flags: 'elementaires' and 'puissances'
7353     (default) which allow decomposing the symmetric polynomials
7354     appearing in the calculation into elementary symmetric functions,
7355     or power functions, respectively.
7356
7357     Functions of 'sym' used in this function:
7358
7359     'multi_orbit' (so 'orbit'), 'pui_direct', 'multi_elem' (so 'elem'),
7360     'multi_pui' (so 'pui'), 'pui2ele', 'ele2pui' (if the flag 'direct'
7361     is in 'puissances').
7362
7363 -- Function: multi_orbit (<P>, [<lvar_1>, <lvar_2>,..., <lvar_p>])
7364
7365     <P> is a polynomial in the set of variables contained in the lists
7366     <lvar_1>, <lvar_2>, ..., <lvar_p>.  This function returns the orbit
7367     of the polynomial <P> under the action of the product of the
7368     symmetric groups of the sets of variables represented in these <p>
7369     lists.
7370
7371          (%i1) multi_orbit (a*x + b*y, [[x, y], [a, b]]);
7372          (%o1)                [b y + a x, a y + b x]
7373          (%i2) multi_orbit (x + y + 2*a, [[x, y], [a, b, c]]);
7374          (%o2)        [y + x + 2 c, y + x + 2 b, y + x + 2 a]
7375     Also see: 'orbit' for the action of a single symmetric group.
7376
7377 -- Function: multsym (<ppart_1>, <ppart_2>, <n>)
7378
7379     returns the product of the two symmetric polynomials in <n>
7380     variables by working only modulo the action of the symmetric group
7381     of order <n>.  The polynomials are in their partitioned form.
7382
7383     Given the 2 symmetric polynomials in <x>, <y>: '3*(x + y) + 2*x*y'
7384     and '5*(x^2 + y^2)' whose partitioned forms are '[[3, 1], [2, 1,
7385     1]]' and '[[5, 2]]', their product will be
7386
7387          (%i1) multsym ([[3, 1], [2, 1, 1]], [[5, 2]], 2);
7388          (%o1)         [[10, 3, 1], [15, 3, 0], [15, 2, 1]]
7389     that is '10*(x^3*y + y^3*x) + 15*(x^2*y + y^2*x) + 15*(x^3 + y^3)'.
7390
7391     Functions for changing the representations of a symmetric
7392     polynomial:
7393
7394     'contract', 'cont2part', 'explose', 'part2cont', 'partpol',
7395     'tcontract', 'tpartpol'.
7396
7397 -- Function: orbit (<P>, <lvar>)
7398
7399     computes the orbit of the polynomial <P> in the variables in the
7400     list <lvar> under the action of the symmetric group of the set of
7401     variables in the list <lvar>.
7402
7403          (%i1) orbit (a*x + b*y, [x, y]);
7404          (%o1)                [a y + b x, b y + a x]
7405          (%i2) orbit (2*x + x^2, [x, y]);
7406                                  2         2
7407          (%o2)                 [y  + 2 y, x  + 2 x]
7408     See also 'multi_orbit' for the action of a product of symmetric
7409     groups on a polynomial.
7410
7411 -- Function: pui_direct (<orbite>, [<lvar_1>, ..., <lvar_n>], [<d_1>,
7412          <d_2>, ..., <d_n>])
7413
7414     Let <f> be a polynomial in <n> blocks of variables <lvar_1>, ...,
7415     <lvar_n>.  Let <c_i> be the number of variables in <lvar_i>, and
7416     <SC> be the product of <n> symmetric groups of degree <c_1>, ...,
7417     <c_n>.  This group acts naturally on <f>.  The list <orbite> is the
7418     orbit, denoted '<SC>(<f>)', of the function <f> under the action of
7419     <SC>.  (This list may be obtained by the function 'multi_orbit'.)
7420     The <di> are integers s.t.  c_1 <= d_1, c_2 <= d_2, ..., c_n <=
7421     d_n.
7422
7423     Let <SD> be the product of the symmetric groups S_[d_1] x S_[d_2] x
7424     ... x S_[d_n].  The function 'pui_direct' returns the first <n>
7425     power functions of '<SD>(<f>)' deduced from the power functions of
7426     '<SC>(<f>)', where <n> is the size of '<SD>(<f>)'.
7427
7428     The result is in multi-contracted form w.r.t.  <SD>, i.e.  only one
7429     element is kept per orbit, under the action of <SD>.
7430
7431          (%i1) l: [[x, y], [a, b]];
7432          (%o1)                   [[x, y], [a, b]]
7433          (%i2) pui_direct (multi_orbit (a*x + b*y, l), l, [2, 2]);
7434                                                 2  2
7435          (%o2)               [a x, 4 a b x y + a  x ]
7436          (%i3) pui_direct (multi_orbit (a*x + b*y, l), l, [3, 2]);
7437                                       2  2     2    2        3  3
7438          (%o3) [2 a x, 4 a b x y + 2 a  x , 3 a  b x  y + 2 a  x ,
7439
7440              2  2  2  2      3    3        4  4
7441          12 a  b  x  y  + 4 a  b x  y + 2 a  x ,
7442
7443              3  2  3  2      4    4        5  5
7444          10 a  b  x  y  + 5 a  b x  y + 2 a  x ,
7445
7446              3  3  3  3       4  2  4  2      5    5        6  6
7447          40 a  b  x  y  + 15 a  b  x  y  + 6 a  b x  y + 2 a  x ]
7448          (%i4) pui_direct ([y + x + 2*c, y + x + 2*b, y + x + 2*a],
7449                [[x, y], [a, b, c]], [2, 3]);
7450                                       2              2
7451          (%o4) [3 x + 2 a, 6 x y + 3 x  + 4 a x + 4 a ,
7452
7453                           2                   3        2       2        3
7454                        9 x  y + 12 a x y + 3 x  + 6 a x  + 12 a  x + 8 a ]
7455
745674.2.4 Partitions
7457-----------------
7458
7459 -- Function: kostka (<part_1>, <part_2>)
7460
7461     written by P. Esperet, calculates the Kostka number of the
7462     partition <part_1> and <part_2>.
7463
7464          (%i1) kostka ([3, 3, 3], [2, 2, 2, 1, 1, 1]);
7465          (%o1)                           6
7466
7467 -- Function: lgtreillis (<n>, <m>)
7468
7469     returns the list of partitions of weight <n> and length <m>.
7470
7471          (%i1) lgtreillis (4, 2);
7472          (%o1)                   [[3, 1], [2, 2]]
7473     Also see: 'ltreillis', 'treillis' and 'treinat'.
7474
7475 -- Function: ltreillis (<n>, <m>)
7476
7477     returns the list of partitions of weight <n> and length less than
7478     or equal to <m>.
7479
7480          (%i1) ltreillis (4, 2);
7481          (%o1)               [[4, 0], [3, 1], [2, 2]]
7482     Also see: 'lgtreillis', 'treillis' and 'treinat'.
7483
7484 -- Function: treillis (<n>)
7485
7486     returns all partitions of weight <n>.
7487
7488          (%i1) treillis (4);
7489          (%o1)    [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
7490
7491     See also: 'lgtreillis', 'ltreillis' and 'treinat'.
7492
7493 -- Function: treinat (<part>)
7494
7495     retruns the list of partitions inferior to the partition <part>
7496     w.r.t.  the natural order.
7497
7498          (%i1) treinat ([5]);
7499          (%o1)                         [[5]]
7500          (%i2) treinat ([1, 1, 1, 1, 1]);
7501          (%o2) [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1],
7502
7503                                                           [1, 1, 1, 1, 1]]
7504          (%i3) treinat ([3, 2]);
7505          (%o3)                 [[5], [4, 1], [3, 2]]
7506
7507     See also: 'lgtreillis', 'ltreillis' and 'treillis'.
7508
750974.2.5 Polynomials and their roots
7510----------------------------------
7511
7512 -- Function: ele2polynome (<L>, <z>)
7513
7514     returns the polynomial in <z> s.t.  the elementary symmetric
7515     functions of its roots are in the list '<L> = [<n>, <e_1>, ...,
7516     <e_n>]', where <n> is the degree of the polynomial and <e_i> the
7517     <i>-th elementary symmetric function.
7518
7519          (%i1) ele2polynome ([2, e1, e2], z);
7520                                    2
7521          (%o1)                    z  - e1 z + e2
7522          (%i2) polynome2ele (x^7 - 14*x^5 + 56*x^3  - 56*x + 22, x);
7523          (%o2)          [7, 0, - 14, 0, 56, 0, - 56, - 22]
7524          (%i3) ele2polynome ([7, 0, -14, 0, 56, 0, -56, -22], x);
7525                            7       5       3
7526          (%o3)            x  - 14 x  + 56 x  - 56 x + 22
7527     The inverse: 'polynome2ele (<P>, <z>)'.
7528
7529     Also see: 'polynome2ele', 'pui2polynome'.
7530
7531 -- Function: polynome2ele (<P>, <x>)
7532
7533     gives the list '<l> = [<n>, <e_1>, ..., <e_n>]' where <n> is the
7534     degree of the polynomial <P> in the variable <x> and <e_i> is the
7535     <i>-the elementary symmetric function of the roots of <P>.
7536
7537          (%i1) polynome2ele (x^7 - 14*x^5 + 56*x^3 - 56*x + 22, x);
7538          (%o1)          [7, 0, - 14, 0, 56, 0, - 56, - 22]
7539          (%i2) ele2polynome ([7, 0, -14, 0, 56, 0, -56, -22], x);
7540                            7       5       3
7541          (%o2)            x  - 14 x  + 56 x  - 56 x + 22
7542     The inverse: 'ele2polynome (<l>, <x>)'
7543
7544 -- Function: prodrac (<L>, <k>)
7545
7546     <L> is a list containing the elementary symmetric functions on a
7547     set <A>.  'prodrac' returns the polynomial whose roots are the <k>
7548     by <k> products of the elements of <A>.
7549
7550     Also see 'somrac'.
7551
7552 -- Function: pui2polynome (<x>, <lpui>)
7553
7554     calculates the polynomial in <x> whose power functions of the roots
7555     are given in the list <lpui>.
7556
7557          (%i1) pui;
7558          (%o1)                           1
7559          (%i2) kill(labels);
7560          (%o0)                         done
7561          (%i1) polynome2ele (x^3 - 4*x^2 + 5*x - 1, x);
7562          (%o1)                     [3, 4, 5, 1]
7563          (%i2) ele2pui (3, %);
7564          (%o2)                     [3, 4, 6, 7]
7565          (%i3) pui2polynome (x, %);
7566                                  3      2
7567          (%o3)                  x  - 4 x  + 5 x - 1
7568     See also: 'polynome2ele', 'ele2polynome'.
7569
7570 -- Function: somrac (<L>, <k>)
7571
7572     The list <L> contains elementary symmetric functions of a
7573     polynomial <P> .  The function computes the polynomial whose roots
7574     are the <k> by <k> distinct sums of the roots of <P>.
7575
7576     Also see 'prodrac'.
7577
757874.2.6 Resolvents
7579-----------------
7580
7581 -- Function: resolvante (<P>, <x>, <f>, [<x_1>,..., <x_d>])
7582
7583     calculates the resolvent of the polynomial <P> in <x> of degree <n>
7584     >= <d> by the function <f> expressed in the variables <x_1>, ...,
7585     <x_d>.  For efficiency of computation it is important to not
7586     include in the list '[<x_1>, ..., <x_d>]' variables which do not
7587     appear in the transformation function <f>.
7588
7589     To increase the efficiency of the computation one may set flags in
7590     'resolvante' so as to use appropriate algorithms:
7591
7592     If the function <f> is unitary:
7593        * A polynomial in a single variable,
7594        * linear,
7595        * alternating,
7596        * a sum,
7597        * symmetric,
7598        * a product,
7599        * the function of the Cayley resolvent (usable up to degree 5)
7600
7601               (x1*x2 + x2*x3 + x3*x4 + x4*x5 + x5*x1 -
7602                    (x1*x3 + x3*x5 + x5*x2 + x2*x4 + x4*x1))^2
7603
7604          general,
7605     the flag of 'resolvante' may be, respectively:
7606        * unitaire,
7607        * lineaire,
7608        * alternee,
7609        * somme,
7610        * produit,
7611        * cayley,
7612        * generale.
7613
7614          (%i1) resolvante: unitaire$
7615          (%i2) resolvante (x^7 - 14*x^5 + 56*x^3 - 56*x + 22, x, x^3 - 1,
7616                [x]);
7617
7618          " resolvante unitaire " [7, 0, 28, 0, 168, 0, 1120, - 154, 7840,
7619                                   - 2772, 56448, - 33880,
7620
7621          413952, - 352352, 3076668, - 3363360, 23114112, - 30494464,
7622
7623          175230832, - 267412992, 1338886528, - 2292126760]
7624            3       6      3       9      6      3
7625          [x  - 1, x  - 2 x  + 1, x  - 3 x  + 3 x  - 1,
7626
7627           12      9      6      3       15      12       9       6      3
7628          x   - 4 x  + 6 x  - 4 x  + 1, x   - 5 x   + 10 x  - 10 x  + 5 x
7629
7630                 18      15       12       9       6      3
7631           - 1, x   - 6 x   + 15 x   - 20 x  + 15 x  - 6 x  + 1,
7632
7633           21      18       15       12       9       6      3
7634          x   - 7 x   + 21 x   - 35 x   + 35 x  - 21 x  + 7 x  - 1]
7635          [- 7, 1127, - 6139, 431767, - 5472047, 201692519, - 3603982011]
7636                 7      6        5         4          3           2
7637          (%o2) y  + 7 y  - 539 y  - 1841 y  + 51443 y  + 315133 y
7638
7639                                                        + 376999 y + 125253
7640          (%i3) resolvante: lineaire$
7641          (%i4) resolvante (x^4 - 1, x, x1 + 2*x2 + 3*x3, [x1, x2, x3]);
7642
7643          " resolvante lineaire "
7644                 24       20         16            12             8
7645          (%o4) y   + 80 y   + 7520 y   + 1107200 y   + 49475840 y
7646
7647                                                              4
7648                                                 + 344489984 y  + 655360000
7649          (%i5) resolvante: general$
7650          (%i6) resolvante (x^4 - 1, x, x1 + 2*x2 + 3*x3, [x1, x2, x3]);
7651
7652          " resolvante generale "
7653                 24       20         16            12             8
7654          (%o6) y   + 80 y   + 7520 y   + 1107200 y   + 49475840 y
7655
7656                                                              4
7657                                                 + 344489984 y  + 655360000
7658          (%i7) resolvante (x^4 - 1, x, x1 + 2*x2 + 3*x3, [x1, x2, x3, x4]);
7659
7660          " resolvante generale "
7661                 24       20         16            12             8
7662          (%o7) y   + 80 y   + 7520 y   + 1107200 y   + 49475840 y
7663
7664                                                              4
7665                                                 + 344489984 y  + 655360000
7666          (%i8) direct ([x^4 - 1], x, x1 + 2*x2 + 3*x3, [[x1, x2, x3]]);
7667                 24       20         16            12             8
7668          (%o8) y   + 80 y   + 7520 y   + 1107200 y   + 49475840 y
7669
7670                                                              4
7671                                                 + 344489984 y  + 655360000
7672          (%i9) resolvante :lineaire$
7673          (%i10) resolvante (x^4 - 1, x, x1 + x2 + x3, [x1, x2, x3]);
7674
7675          " resolvante lineaire "
7676                                        4
7677          (%o10)                       y  - 1
7678          (%i11) resolvante: symetrique$
7679          (%i12) resolvante (x^4 - 1, x, x1 + x2 + x3, [x1, x2, x3]);
7680
7681          " resolvante symetrique "
7682                                        4
7683          (%o12)                       y  - 1
7684          (%i13) resolvante (x^4 + x + 1, x, x1 - x2, [x1, x2]);
7685
7686          " resolvante symetrique "
7687                                     6      2
7688          (%o13)                    y  - 4 y  - 1
7689          (%i14) resolvante: alternee$
7690          (%i15) resolvante (x^4 + x + 1, x, x1 - x2, [x1, x2]);
7691
7692          " resolvante alternee "
7693                      12      8       6        4        2
7694          (%o15)     y   + 8 y  + 26 y  - 112 y  + 216 y  + 229
7695          (%i16) resolvante: produit$
7696          (%i17) resolvante (x^7 - 7*x + 3, x, x1*x2*x3, [x1, x2, x3]);
7697
7698          " resolvante produit "
7699                  35      33         29        28         27        26
7700          (%o17) y   - 7 y   - 1029 y   + 135 y   + 7203 y   - 756 y
7701
7702                   24           23          22            21           20
7703           + 1323 y   + 352947 y   - 46305 y   - 2463339 y   + 324135 y
7704
7705                    19           18             17              15
7706           - 30618 y   - 453789 y   - 40246444 y   + 282225202 y
7707
7708                       14              12             11            10
7709           - 44274492 y   + 155098503 y   + 12252303 y   + 2893401 y
7710
7711                        9            8            7             6
7712           - 171532242 y  + 6751269 y  + 2657205 y  - 94517766 y
7713
7714                      5             3
7715           - 3720087 y  + 26040609 y  + 14348907
7716          (%i18) resolvante: symetrique$
7717          (%i19) resolvante (x^7 - 7*x + 3, x, x1*x2*x3, [x1, x2, x3]);
7718
7719          " resolvante symetrique "
7720                  35      33         29        28         27        26
7721          (%o19) y   - 7 y   - 1029 y   + 135 y   + 7203 y   - 756 y
7722
7723                   24           23          22            21           20
7724           + 1323 y   + 352947 y   - 46305 y   - 2463339 y   + 324135 y
7725
7726                    19           18             17              15
7727           - 30618 y   - 453789 y   - 40246444 y   + 282225202 y
7728
7729                       14              12             11            10
7730           - 44274492 y   + 155098503 y   + 12252303 y   + 2893401 y
7731
7732                        9            8            7             6
7733           - 171532242 y  + 6751269 y  + 2657205 y  - 94517766 y
7734
7735                      5             3
7736           - 3720087 y  + 26040609 y  + 14348907
7737          (%i20) resolvante: cayley$
7738          (%i21) resolvante (x^5 - 4*x^2 + x + 1, x, a, []);
7739
7740          " resolvante de Cayley "
7741                  6       5         4          3            2
7742          (%o21) x  - 40 x  + 4080 x  - 92928 x  + 3772160 x  + 37880832 x
7743
7744                                                                 + 93392896
7745
7746     For the Cayley resolvent, the 2 last arguments are neutral and the
7747     input polynomial must necessarily be of degree 5.
7748
7749     See also:
7750     'resolvante_bipartite', 'resolvante_produit_sym',
7751     'resolvante_unitaire', 'resolvante_alternee1', 'resolvante_klein',
7752     'resolvante_klein3', 'resolvante_vierer', 'resolvante_diedrale'.
7753
7754 -- Function: resolvante_alternee1 (<P>, <x>)
7755
7756     calculates the transformation '<P>(<x>)' of degree <n> by the
7757     function product(x_i - x_j, 1 <= i < j <= n - 1).
7758
7759     See also:
7760     'resolvante_produit_sym', 'resolvante_unitaire',
7761     'resolvante' , 'resolvante_klein', 'resolvante_klein3',
7762     'resolvante_vierer', 'resolvante_diedrale', 'resolvante_bipartite'.
7763
7764 -- Function: resolvante_bipartite (<P>, <x>)
7765
7766     calculates the transformation of '<P>(<x>)' of even degree <n> by
7767     the function x_1 x_2 ... x_[n/2] + x_[n/2 + 1] ... x_n.
7768
7769     See also:
7770     'resolvante_produit_sym', 'resolvante_unitaire',
7771     'resolvante' , 'resolvante_klein', 'resolvante_klein3',
7772     'resolvante_vierer', 'resolvante_diedrale', 'resolvante_alternee1'.
7773
7774          (%i1) resolvante_bipartite (x^6 + 108, x);
7775                        10        8           6             4
7776          (%o1)        y   - 972 y  + 314928 y  - 34012224 y
7777
7778     See also:
7779     'resolvante_produit_sym', 'resolvante_unitaire',
7780     'resolvante', 'resolvante_klein', 'resolvante_klein3',
7781     'resolvante_vierer', 'resolvante_diedrale',
7782     'resolvante_alternee1'.
7783
7784 -- Function: resolvante_diedrale (<P>, <x>)
7785
7786     calculates the transformation of '<P>(<x>)' by the function '<x_1>
7787     <x_2> + <x_3> <x_4>'.
7788
7789          (%i1) resolvante_diedrale (x^5 - 3*x^4 + 1, x);
7790                 15       12       11       10        9         8         7
7791          (%o1) x   - 21 x   - 81 x   - 21 x   + 207 x  + 1134 x  + 2331 x
7792
7793                  6         5          4          3          2
7794           - 945 x  - 4970 x  - 18333 x  - 29079 x  - 20745 x  - 25326 x
7795
7796           - 697
7797
7798     See also:
7799     'resolvante_produit_sym', 'resolvante_unitaire',
7800     'resolvante_alternee1', 'resolvante_klein', 'resolvante_klein3',
7801     'resolvante_vierer', 'resolvante'.
7802
7803 -- Function: resolvante_klein (<P>, <x>)
7804
7805     calculates the transformation of '<P>(<x>)' by the function '<x_1>
7806     <x_2> <x_4> + <x_4>'.
7807
7808     See also:
7809     'resolvante_produit_sym', 'resolvante_unitaire',
7810     'resolvante_alternee1', 'resolvante', 'resolvante_klein3',
7811     'resolvante_vierer', 'resolvante_diedrale'.
7812
7813 -- Function: resolvante_klein3 (<P>, <x>)
7814
7815     calculates the transformation of '<P>(<x>)' by the function '<x_1>
7816     <x_2> <x_4> + <x_4>'.
7817
7818     See also:
7819     'resolvante_produit_sym', 'resolvante_unitaire',
7820     'resolvante_alternee1', 'resolvante_klein', 'resolvante',
7821     'resolvante_vierer', 'resolvante_diedrale'.
7822
7823 -- Function: resolvante_produit_sym (<P>, <x>)
7824
7825     calculates the list of all product resolvents of the polynomial
7826     '<P>(<x>)'.
7827
7828          (%i1) resolvante_produit_sym (x^5 + 3*x^4 + 2*x - 1, x);
7829                  5      4             10      8       7       6       5
7830          (%o1) [y  + 3 y  + 2 y - 1, y   - 2 y  - 21 y  - 31 y  - 14 y
7831
7832              4       3      2       10      8       7    6       5       4
7833           - y  + 14 y  + 3 y  + 1, y   + 3 y  + 14 y  - y  - 14 y  - 31 y
7834
7835                 3      2       5      4
7836           - 21 y  - 2 y  + 1, y  - 2 y  - 3 y - 1, y - 1]
7837          (%i2) resolvante: produit$
7838          (%i3) resolvante (x^5 + 3*x^4 + 2*x - 1, x, a*b*c, [a, b, c]);
7839
7840          " resolvante produit "
7841                 10      8       7    6        5       4       3     2
7842          (%o3) y   + 3 y  + 14 y  - y  - 14 y  - 31 y  - 21 y  - 2 y  + 1
7843
7844     See also:
7845     'resolvante', 'resolvante_unitaire',
7846     'resolvante_alternee1', 'resolvante_klein',
7847     'resolvante_klein3', 'resolvante_vierer',
7848     'resolvante_diedrale'.
7849
7850 -- Function: resolvante_unitaire (<P>, <Q>, <x>)
7851
7852     computes the resolvent of the polynomial '<P>(<x>)' by the
7853     polynomial '<Q>(<x>)'.
7854
7855     See also:
7856     'resolvante_produit_sym', 'resolvante',
7857     'resolvante_alternee1', 'resolvante_klein', 'resolvante_klein3',
7858     'resolvante_vierer', 'resolvante_diedrale'.
7859
7860 -- Function: resolvante_vierer (<P>, <x>)
7861
7862     computes the transformation of '<P>(<x>)' by the function '<x_1>
7863     <x_2> - <x_3> <x_4>'.
7864
7865     See also:
7866     'resolvante_produit_sym', 'resolvante_unitaire',
7867     'resolvante_alternee1', 'resolvante_klein', 'resolvante_klein3',
7868     'resolvante', 'resolvante_diedrale'.
7869
787074.2.7 Miscellaneous
7871--------------------
7872
7873 -- Function: multinomial (<r>, <part>)
7874
7875     where <r> is the weight of the partition <part>.  This function
7876     returns the associate multinomial coefficient: if the parts of
7877     <part> are <i_1>, <i_2>, ..., <i_k>, the result is '<r>!/(<i_1>!
7878     <i_2>! ... <i_k>!)'.
7879
7880 -- Function: permut (<L>)
7881
7882     returns the list of permutations of the list <L>.
7883
7884