~ubuntu-branches/debian/squeeze/maxima/squeeze

« back to all changes in this revision

Viewing changes to doc/info/pt/maxima.info-6

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-10-18 14:52:42 UTC
  • mto: (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061018145242-vzyrm5hmxr8kiosf
ImportĀ upstreamĀ versionĀ 5.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
This is maxima.info, produced by makeinfo version 4.7 from maxima.texi.
 
2
 
 
3
   Esse ļæ½ um Manual do Maxima no formato Texinfo
 
4
 
 
5
   Copyright 1994,2001 William F. Schelter
 
6
 
 
7
START-INFO-DIR-ENTRY
 
8
* Maxima: (maxima).     Um sistema de ļæ½lgebra computacional.
 
9
END-INFO-DIR-ENTRY
 
10
 
 
11
 
 
12
File: maxima.info,  Node: Definitions for simplex,  Prev: Introduction to simplex,  Up: simplex
 
13
 
 
14
63.2 Definitions for simplex
 
15
============================
 
16
 
 
17
 -- Option variable: epsilon_sx
 
18
     Default value: `10^-8'
 
19
 
 
20
     Epsilon used for numerical computations in `linear_program'.
 
21
 
 
22
     See also: `linear_program'.
 
23
 
 
24
 
 
25
 -- Function: linear_program (<A>, <b>, <c>)
 
26
     `linear_program' is an implementation of the simplex algorithm.
 
27
     `linear_program(A, b, c)' computes a vector <x> for which `c.x' is
 
28
     minimum possible among vectors for which `A.x = b' and `x >= 0'.
 
29
     Argument <A> is a matrix and arguments <b> and <c> are lists.
 
30
 
 
31
     `linear_program' returns a list which contains the minimizing
 
32
     vector <x> and the minimum value `c.x'. If the problem is not
 
33
     bounded, it returns "Problem not bounded!" and if the problem is
 
34
     not feasible, it returns "Problem not feasible!".
 
35
 
 
36
     To use this function first load the `simplex' package with
 
37
     `load(simplex);'.
 
38
 
 
39
     Example:
 
40
 
 
41
          (%i2) A: matrix([1,1,-1,0], [2,-3,0,-1], [4,-5,0,0])$
 
42
          (%i3) b: [1,1,6]$
 
43
          (%i4) c: [1,-2,0,0]$
 
44
          (%i5) linear_program(A, b, c);
 
45
                             13     19        3
 
46
          (%o5)            [[--, 4, --, 0], - -]
 
47
                             2      2         2
 
48
 
 
49
     See also: `minimize_sx', `scale_sx', and `epsilon_sx'.
 
50
 
 
51
 
 
52
 -- Function: maximize_sx (<obj>, <cond>, [<pos>])
 
53
     Maximizes linear objective function <obj> subject to some linear
 
54
     constraints <cond>. See `minimize_sx' for detailed description of
 
55
     arguments and return value.
 
56
 
 
57
     See also: `minimize_sx'.
 
58
 
 
59
 
 
60
 -- Function: minimize_sx (<obj>, <cond>, [<pos>])
 
61
     Minimizes a linear objective function <obj> subject to some linear
 
62
     constraints <cond>. <cond> a list of linear equations or
 
63
     inequalities. In strict inequalities `>' is replaced by `>=' and
 
64
     `<' by `<='. The optional argument <pos> is a list of decision
 
65
     variables which are assumed to be positive.
 
66
 
 
67
     If the minimum exists, `minimize_sx' returns a list which contains
 
68
     the minimum value of the objective function and a list of decision
 
69
     variable values for which the minimum is attained. If the problem
 
70
     is not bounded, `minimize_sx' returns "Problem not bounded!" and
 
71
     if the problem is not feasible, it returns "Ploblem not feasible!".
 
72
 
 
73
     The decision variables are not assumed to be nonegative by
 
74
     default. If all decision variables are nonegative, set
 
75
     `nonegative_sx' to `true'.  If only some of decision variables are
 
76
     positive, list them in the optional argument <pos> (note that this
 
77
     is more efficient than adding constraints).
 
78
 
 
79
     `minimize_sx' uses the simplex algorithm which is implemented in
 
80
     maxima `linear_program' function.
 
81
 
 
82
     To use this function first load the `simplex' package with
 
83
     `load(simplex);'.
 
84
 
 
85
     Examples:
 
86
 
 
87
          (%i1) minimize_sx(x+y, [3*x+y=0, x+2*y>2]);
 
88
                                4       6        2
 
89
          (%o1)                [-, [y = -, x = - -]]
 
90
                                5       5        5
 
91
          (%i2) minimize_sx(x+y, [3*x+y>0, x+2*y>2]), nonegative_sx=true;
 
92
          (%o2)                [1, [y = 1, x = 0]]
 
93
          (%i3) minimize_sx(x+y, [3*x+y=0, x+2*y>2]), nonegative_sx=true;
 
94
          (%o3)                Problem not feasible!
 
95
          (%i4) minimize_sx(x+y, [3*x+y>0]);
 
96
          (%o4)                Problem not bounded!
 
97
 
 
98
     See also: `maximize_sx', `nonegative_sx', `epsilon_sx'.
 
99
 
 
100
 
 
101
 -- Option variable: nonegative_sx
 
102
     Default value: `false'
 
103
 
 
104
     If `nonegative_sx' is true all decision variables to `minimize_sx'
 
105
     and `maximize_sx' are assumed to be positive.
 
106
 
 
107
     See also: `minimize_sx'.
 
108
 
 
109
 
 
110
 
 
111
File: maxima.info,  Node: simplification,  Next: solve_rec,  Prev: simplex,  Up: Top
 
112
 
 
113
64 simplification
 
114
*****************
 
115
 
 
116
* Menu:
 
117
 
 
118
* Introduction to simplification::
 
119
* Definitions for simplification::
 
120
 
 
121
 
 
122
File: maxima.info,  Node: Introduction to simplification,  Next: Definitions for simplification,  Prev: simplification,  Up: simplification
 
123
 
 
124
64.1 Introduction to simplification
 
125
===================================
 
126
 
 
127
The directory `maxima/share/simplification' contains several scripts
 
128
which implement simplification rules and functions, and also some
 
129
functions not related to simplification.
 
130
 
 
131
 
 
132
File: maxima.info,  Node: Definitions for simplification,  Prev: Introduction to simplification,  Up: simplification
 
133
 
 
134
64.2 Definitions for simplification
 
135
===================================
 
136
 
 
137
64.2.1 Package absimp
 
138
---------------------
 
139
 
 
140
The `absimp' package contains pattern-matching rules that extend the
 
141
built-in simplification rules for the `abs' and `signum' functions.
 
142
`absimp' respects relations established with the built-in `assume'
 
143
function and by declarations such as  `modedeclare (m, even, n, odd)'
 
144
for even or odd integers.
 
145
 
 
146
   `absimp' defines `unitramp' and `unitstep' functions in terms of
 
147
`abs' and `signum'.
 
148
 
 
149
   `load (absimp)' loads this package.  `demo (absimp)' shows a
 
150
demonstration of this package.
 
151
 
 
152
   Examples:
 
153
 
 
154
     (%i1) load (absimp)$
 
155
     (%i2) (abs (x))^2;
 
156
                                            2
 
157
     (%o2)                                 x
 
158
     (%i3) diff (abs (x), x);
 
159
                                           x
 
160
     (%o3)                               ------
 
161
                                         abs(x)
 
162
     (%i4) cosh (abs (x));
 
163
     (%o4)                               cosh(x)
 
164
 
 
165
64.2.2 Package facexp
 
166
---------------------
 
167
 
 
168
The `facexp' package contains several related  functions that provide
 
169
the user with the ability to structure expressions by controlled
 
170
expansion.   This capability  is especially  useful when  the expression
 
171
contains variables that have physical meaning, because it is  often true
 
172
that the most economical form  of such an expression can be  obtained by
 
173
fully expanding the expression with respect to those variables, and then
 
174
factoring their coefficients.  While it is  true that this  procedure is
 
175
not difficult to carry out using standard Maxima  functions, additional
 
176
fine-tuning may also  be desirable, and  these finishing touches  can be
 
177
more  difficult to  apply.
 
178
 
 
179
   The  function `facsum'  and its  related forms provide a convenient
 
180
means for controlling the structure  of expressions in this way.
 
181
Another function, `collectterms', can be used to add  two or more
 
182
expressions that have already been simplified to this form, without
 
183
resimplifying the whole expression again.  This function may be useful
 
184
when the expressions are very large.
 
185
 
 
186
   `load (facexp)' loads this package.  `demo (facexp)' shows a
 
187
demonstration of this package.
 
188
 
 
189
 -- Function: facsum (<expr>, <arg_1>, ..., <arg_n>)
 
190
     Returns  a form  of <expr>  which depends  on the arguments
 
191
     <arg_1>, ..., <arg_n>.  The arguments can be any form suitable for
 
192
     `ratvars', or they can be lists  of such  forms.  If  the
 
193
     arguments  are not  lists, then  the form returned is  fully
 
194
     expanded with respect  to the arguments,  and the coefficients of
 
195
     the arguments are factored.  These  coefficients are free of the
 
196
     arguments, except perhaps in a non-rational sense.
 
197
 
 
198
     If any of the arguments are  lists, then all such lists are
 
199
     combined into  a  single  list,   and  instead  of  calling
 
200
     `factor'   on  the coefficients  of  the  arguments,  `facsum'
 
201
     calls  itself   on  these coefficients, using  this newly
 
202
     constructed  single list as  the new argument list  for this
 
203
     recursive  call.  This  process can  be  repeated to arbitrary
 
204
     depth by nesting the desired elements in lists.
 
205
 
 
206
     It is possible that one may wish to `facsum' with respect  to more
 
207
     complicated subexpressions,  such as  `log (x + y)'.  Such
 
208
     arguments are also  permissible.   With  no  variable
 
209
     specification,  for example `facsum (<expr>)', the  result
 
210
     returned  is the same  as that  returned by `ratsimp (<expr>)'.
 
211
 
 
212
     Occasionally the user may wish to obtain any of the  above forms
 
213
     for expressions which are specified only by their leading
 
214
     operators.  For example, one may wish  to `facsum' with respect to
 
215
     all  `log''s.  In this situation, one may  include among the
 
216
     arguments either  the specific `log''s which are to be treated in
 
217
     this way, or  alternatively, either the expression  `operator
 
218
     (log)' or `'operator (log)'.   If one  wished to `facsum' the
 
219
     expression <expr> with respect to the operators <op_1>, ...,
 
220
     <op_n>, one   would  evaluate  `facsum (<expr>, operator (<op_1>,
 
221
     ..., <op_n>))'.  The `operator' form may also appear inside list
 
222
     arguments.
 
223
 
 
224
     In  addition,  the  setting  of  the  switches   `facsum_combine'
 
225
     and `nextlayerfactor' may affect the result of `facsum'.
 
226
 
 
227
 -- Global variable: nextlayerfactor
 
228
     Default value: `false'
 
229
 
 
230
     When `nextlayerfactor' is `true', recursive calls  of `facsum' are
 
231
     applied  to  the  factors  of  the  factored  form   of  the
 
232
     coefficients of the arguments.
 
233
 
 
234
     When  `false', `facsum' is applied to each coefficient as a whole
 
235
     whenever recusive calls to  `facsum' occur.
 
236
 
 
237
     Inclusion   of   the  atom `nextlayerfactor' in  the argument
 
238
     list of `facsum'  has the  effect of `nextlayerfactor: true', but
 
239
     for the next level of the expression only.  Since
 
240
     `nextlayerfactor' is  always bound to  either `true' or  `false',
 
241
     it must be presented single-quoted whenever it appears in the
 
242
     argument list of `facsum'.
 
243
 
 
244
 -- Global variable: facsum_combine
 
245
     Default value: `true'
 
246
 
 
247
     `facsum_combine' controls the form  of the final result  returned
 
248
     by `facsum'  when  its  argument  is  a  quotient  of
 
249
     polynomials.   If `facsum_combine' is `false'  then the form will
 
250
     be returned as  a fully expanded  sum  as described  above,  but
 
251
     if  `true',  then  the expression returned is a ratio of
 
252
     polynomials, with each polynomial in the form described above.
 
253
 
 
254
     The `true' setting of this switch is useful when one wants to
 
255
     `facsum' both  the numerator and  denominator of  a rational
 
256
     expression,  but  does not  want  the denominator  to  be
 
257
     multiplied through the terms of the numerator.
 
258
 
 
259
 -- Function: factorfacsum (<expr>, <arg_1>, ... <arg_n>)
 
260
     Returns a  form of <expr>  which is obtained by calling  `facsum'
 
261
     on the factors  of <expr> with <arg_1>, ... <arg_n> as arguments.
 
262
     If any of the factors of <expr> is raised to a  power, both the
 
263
     factor and the exponent will be processed in this way.
 
264
 
 
265
 -- Function: collectterms (<arg_1>, ..., <arg_n>)
 
266
     If several  expressions  have been simplified  with  `facsum',
 
267
     `factorfacsum',  `factenexpand',  `facexpten' or
 
268
     `factorfacexpten',  and  they are  to  be added  together,  it
 
269
     may be desirable   to  combine   them  using   the   function
 
270
     `collecterms'.  `collecterms' can take as arguments  all of the
 
271
     arguments that  can be given  to these  other associated
 
272
     functions with  the  exception of `nextlayerfactor', which has no
 
273
     effect on `collectterms'.  The advantage of `collectterms'  is
 
274
     that it  returns a form  similar to  `facsum', but since it is
 
275
     adding forms that have already been processed by `facsum', it
 
276
     does  not  need  to  repeat  that  effort.   This  capability is
 
277
     especially useful when the expressions to be summed are very large.
 
278
 
 
279
64.2.3 Package functs
 
280
---------------------
 
281
 
 
282
 -- Function: rempart (<expr>, <n>)
 
283
     Removes part <n> from the expression <expr>.
 
284
 
 
285
     If <n> is a list of the form `[<l>, <m>]' then parts <l> thru <m>
 
286
     are removed.
 
287
 
 
288
     To use this function write first `load(functs)'.
 
289
 
 
290
 -- Function: wronskian ([<f_1>, ..., <f_n>], <x>)
 
291
     Returns the Wronskian matrix of the functions <f_1>, ..., <f_n> in
 
292
     the variable <x>.
 
293
 
 
294
     <f_1>, ..., <f_n> may be the names of user-defined functions, or
 
295
     expressions in the variable <x>.
 
296
 
 
297
     The determinant of the Wronskian matrix is the Wronskian
 
298
     determinant of the set of functions.  The functions are linearly
 
299
     dependent if this determinant is zero.
 
300
 
 
301
     To use this function write first `load(functs)'.
 
302
 
 
303
 -- Function: tracematrix (<M>)
 
304
     Returns the trace (sum of the diagonal elements) of matrix <M>.
 
305
 
 
306
     To use this function write first `load(functs)'.
 
307
 
 
308
 -- Function: rational (`z')
 
309
     Multiplies numerator and denominator of <z> by the complex
 
310
     conjugate of denominator, thus rationalizing the denominator.
 
311
     Returns canonical rational expression (CRE) form if given one,
 
312
     else returns general form.
 
313
 
 
314
     To use this function write first `load(functs)'.
 
315
 
 
316
 -- Function: logand (`x',`y')
 
317
     Returns logical (bit-wise) "and" of arguments x and y.
 
318
 
 
319
     To use this function write first `load(functs)'.
 
320
 
 
321
 -- Function: logor (`x',`y')
 
322
     Returns logical (bit-wise) "or" of arguments x and y.
 
323
 
 
324
     To use this function write first `load(functs)'.
 
325
 
 
326
 -- Function: logxor (`x',`y')
 
327
     Returns logical (bit-wise) exclusive-or of arguments x and y.
 
328
 
 
329
     To use this function write first `load(functs)'.
 
330
 
 
331
 -- Function: nonzeroandfreeof (<x>, <expr>)
 
332
     Returns `true' if <expr> is nonzero and `freeof (<x>, <expr>)'
 
333
     returns `true'.  Returns `false' otherwise.
 
334
 
 
335
     To use this function write first `load(functs)'.
 
336
 
 
337
 -- Function: linear (<expr>, <x>)
 
338
     When <expr> is an expression linear in variable <x>, `linear'
 
339
     returns `<a>*<x> + <b>' where <a> is nonzero, and <a> and <b> are
 
340
     free of <x>.  Otherwise, `linear' returns <expr>.
 
341
 
 
342
     To use this function write first `load(functs)'.
 
343
 
 
344
 -- Function: gcdivide (<p>, <q>)
 
345
     When `takegcd' is `true', `gcdivide' divides the polynomials <p>
 
346
     and <q> by their greatest common divisor and returns the ratio of
 
347
     the results.
 
348
 
 
349
     When `takegcd' is `false', `gcdivide' returns the ratio `<p>/<q>'.
 
350
 
 
351
     To use this function write first `load(functs)'.
 
352
 
 
353
 -- Function: arithmetic (<a>, <d>, <n>)
 
354
     Returns the <n>-th term of the arithmetic series `<a>, <a> + <d>,
 
355
     <a> + 2*<d>, ..., <a> + (<n> - 1)*<d>'.
 
356
 
 
357
     To use this function write first `load(functs)'.
 
358
 
 
359
 -- Function: geometric (<a>, <r>, <n>)
 
360
     Returns the <n>-th term of the geometric series `<a>, <a>*<r>,
 
361
     <a>*<r>^2, ..., <a>*<r>^(<n> - 1)'.
 
362
 
 
363
     To use this function write first `load(functs)'.
 
364
 
 
365
 -- Function: harmonic (<a>, <b>, <c>, <n>)
 
366
     Returns the <n>-th term of the harmonic series `<a>/<b>, <a>/(<b>
 
367
     + <c>), <a>/(<b> + 2*<c>), ..., <a>/(<b> + (<n> - 1)*<c>)'.
 
368
 
 
369
     To use this function write first `load(functs)'.
 
370
 
 
371
 -- Function: arithsum (<a>, <d>, <n>)
 
372
     Returns the sum of the arithmetic series from 1 to <n>.
 
373
 
 
374
     To use this function write first `load(functs)'.
 
375
 
 
376
 -- Function: geosum (<a>, <r>, <n>)
 
377
     Returns the sum of the geometric series from 1 to <n>.  If <n> is
 
378
     infinity (`inf') then a sum is finite only if the absolute value
 
379
     of <r> is less than 1.
 
380
 
 
381
     To use this function write first `load(functs)'.
 
382
 
 
383
 -- Function: gaussprob (<x>)
 
384
     Returns the Gaussian probability function `%e^(-<x>^2/2) /
 
385
     sqrt(2*%pi)'.
 
386
 
 
387
     To use this function write first `load(functs)'.
 
388
 
 
389
 -- Function: gd (<x>)
 
390
     Returns the Gudermannian function `2 * atan(%e^<x> - %pi/2)'.
 
391
 
 
392
     To use this function write first `load(functs)'.
 
393
 
 
394
 -- Function: agd (<x>)
 
395
     Returns the inverse Gudermannian function `log (tan (%pi/4 +
 
396
     x/2)))'.
 
397
 
 
398
     To use this function write first `load(functs)'.
 
399
 
 
400
 -- Function: vers (<x>)
 
401
     Returns the versed sine `1 - cos (x)'.
 
402
 
 
403
     To use this function write first `load(functs)'.
 
404
 
 
405
 -- Function: covers (<x>)
 
406
     Returns the coversed sine `1 - sin (<x>)'.
 
407
 
 
408
     To use this function write first `load(functs)'.
 
409
 
 
410
 -- Function: exsec (<x>)
 
411
     Returns the exsecant `sec (<x>) - 1'.
 
412
 
 
413
     To use this function write first `load(functs)'.
 
414
 
 
415
 -- Function: hav (<x>)
 
416
     Returns the haversine `(1 - cos(x))/2'.
 
417
 
 
418
     To use this function write first `load(functs)'.
 
419
 
 
420
 -- Function: combination (<n>, <r>)
 
421
     Returns the number of combinations of <n> objects taken <r> at a
 
422
     time.
 
423
 
 
424
     To use this function write first `load(functs)'.
 
425
 
 
426
 -- Function: permutation (<n>, <r>)
 
427
     Returns the number of permutations of <r> objects selected from a
 
428
     set of <n> objects.
 
429
 
 
430
     To use this function write first `load(functs)'.
 
431
 
 
432
64.2.4 Package ineq
 
433
-------------------
 
434
 
 
435
The `ineq' package contains simplification rules for inequalities.
 
436
 
 
437
   Example session:
 
438
 
 
439
     (%i1) load(ineq)$
 
440
     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
 
441
     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
 
442
     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
 
443
     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
 
444
     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
 
445
     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
 
446
     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
 
447
     Warning: Putting rules on '+' or '*' is inefficient, and may not work.
 
448
     (%i2) a>=4;  /* a sample inequality */
 
449
     (%o2)                               a >= 4
 
450
     (%i3) (b>c)+%; /* add a second, strict inequality */
 
451
     (%o3)                            b + a > c + 4
 
452
     (%i4) 7*(x<y); /* multiply by a positive number */
 
453
     (%o4)                              7 x < 7 y
 
454
     (%i5) -2*(x>=3*z); /* multiply by a negative number */
 
455
     (%o5)                           - 2 x <= - 6 z
 
456
     (%i6) (1+a^2)*(1/(1+a^2)<=1); /* Maxima knows that 1+a^2 > 0 */
 
457
                                             2
 
458
     (%o6)                             1 <= a  + 1
 
459
     (%i7) assume(x>0)$ x*(2<3); /* assuming x>0 */
 
460
     (%o7)                              2 x < 3 x
 
461
     (%i8) a>=b; /* another inequality */
 
462
     (%o8)                               a >= b
 
463
     (%i9) 3+%; /* add something */
 
464
     (%o9)                           a + 3 >= b + 3
 
465
     (%i10) %-3; /* subtract it out */
 
466
     (%o10)                              a >= b
 
467
     (%i11) a>=c-b; /* yet another inequality */
 
468
     (%o11)                            a >= c - b
 
469
     (%i12) b+%; /* add b to both sides */
 
470
     (%o12)                            b + a >= c
 
471
     (%i13) %-c; /* subtract c from both sides */
 
472
     (%o13)                         - c + b + a >= 0
 
473
     (%i14) -%;  /* multiply by -1 */
 
474
     (%o14)                          c - b - a <= 0
 
475
     (%i15) (z-1)^2>-2*z; /* determining truth of assertion */
 
476
                                           2
 
477
     (%o15)                         (z - 1)  > - 2 z
 
478
     (%i16) expand(%)+2*z; /* expand this and add 2*z to both sides */
 
479
                                        2
 
480
     (%o16)                            z  + 1 > 0
 
481
     (%i17) %,pred;
 
482
     (%o17)                               true
 
483
 
 
484
   Be careful about using parentheses around the inequalities: when the
 
485
user types in `(A > B) + (C = 5)' the result is `A + C > B + 5', but `A
 
486
> B + C = 5' is a syntax error, and `(A > B + C) = 5' is something else
 
487
entirely.
 
488
 
 
489
   Do `disprule (all)' to see a complete listing of the rule
 
490
definitions.
 
491
 
 
492
   The user will be queried if Maxima is unable to decide the sign of a
 
493
quantity multiplying an inequality.
 
494
 
 
495
   The most common mis-feature is illustrated by:
 
496
 
 
497
     eq: a > b;
 
498
     2*eq;
 
499
     % - eq;
 
500
 
 
501
   Another problem is 0 times an inequality; the default to have this
 
502
turn into 0 has been left alone. However, if you type
 
503
`X*<some_inequality>' and Maxima asks about the sign of `X' and you
 
504
respond `zero' (or `z'), the program returns `X*<some_inequality>' and
 
505
not use the information that `X' is 0. You should do `ev (%, x: 0)' in
 
506
such a case, as the database will only be used for comparison purposes
 
507
in decisions, and not for the purpose of evaluating `X'.
 
508
 
 
509
   The user may note a slower response when this package is loaded, as
 
510
the simplifier is forced to examine more rules than without the
 
511
package, so you might wish to remove the rules after making use of
 
512
them. Do `kill (rules)' to eliminate all of the rules (including any
 
513
that you might have defined); or you may be more selective by killing
 
514
only some of them; or use `remrule' on a specific rule.
 
515
 
 
516
   Note that if you load this package after defining your own rules you
 
517
will clobber your rules that have the same name. The rules in this
 
518
package are: `*rule1', ..., `*rule8', `+rule1', ..., `+rule18', and you
 
519
must enclose the rulename in quotes to refer to it, as in `remrule
 
520
("+", "+rule1")' to specifically remove the first rule on `"+"' or
 
521
`disprule ("*rule2")' to display the definition of the second
 
522
multiplicative rule.
 
523
 
 
524
64.2.5 Package rducon
 
525
---------------------
 
526
 
 
527
 -- Function: reduce_consts (<expr>)
 
528
     Replaces constant subexpressions of <expr> with constructed
 
529
     constant atoms, saving the definition of all these constructed
 
530
     constants in the list of equations `const_eqns', and returning the
 
531
     modified <expr>.  Those parts of <expr> are constant which return
 
532
     `true' when operated on by the function `constantp'.  Hence,
 
533
     before invoking `reduce_consts', one should do
 
534
 
 
535
          declare ([<objects to be given the constant property>], constant)$
 
536
 
 
537
     to set up a database of the constant quantities occurring in your
 
538
     expressions.
 
539
 
 
540
     If you are planning to generate Fortran output after these symbolic
 
541
     calculations, one of the first code sections should be the
 
542
     calculation of all constants.  To generate this code segment, do
 
543
 
 
544
          map ('fortran, const_eqns)$
 
545
 
 
546
     Variables besides `const_eqns' which affect `reduce_consts' are:
 
547
 
 
548
     `const_prefix' (default value: `xx') is the string of characters
 
549
     used to prefix all symbols generated by `reduce_consts' to
 
550
     represent constant subexpressions.
 
551
 
 
552
     `const_counter' (default value: 1) is the integer index used to
 
553
     generate unique symbols to represent each constant subexpression
 
554
     found by `reduce_consts'.
 
555
 
 
556
     `load (rducon)' loads this function.  `demo (rducon)' shows a
 
557
     demonstration of this function.
 
558
 
 
559
64.2.6 Package scifac
 
560
---------------------
 
561
 
 
562
 -- Function: gcfac (<expr>)
 
563
     `gcfac' is a factoring function that attempts to apply the same
 
564
     heuristics which scientists apply in trying to make expressions
 
565
     simpler.  `gcfac' is limited to monomial-type factoring.  For a
 
566
     sum, `gcfac' does the following:
 
567
 
 
568
       1. Factors over the integers.
 
569
 
 
570
       2. Factors out the largest powers of terms occurring as
 
571
          coefficients, regardless of the complexity of the terms.
 
572
 
 
573
       3. Uses (1) and (2) in factoring adjacent pairs of terms.
 
574
 
 
575
       4. Repeatedly and recursively applies these techniques until the
 
576
          expression no longer changes.
 
577
 
 
578
     Item (3) does not necessarily do an optimal job of pairwise
 
579
     factoring because of the combinatorially-difficult nature of
 
580
     finding which of all possible rearrangements of the pairs yields
 
581
     the most compact pair-factored result.
 
582
 
 
583
     `load (scifac)' loads this function.  `demo (scifac)' shows a
 
584
     demonstration of this function.
 
585
 
 
586
64.2.7 Package sqdnst
 
587
---------------------
 
588
 
 
589
 -- Function: sqrtdenest (<expr>)
 
590
     Denests `sqrt' of simple, numerical, binomial surds, where
 
591
     possible.  E.g.
 
592
 
 
593
          (%i1) load (sqdnst)$
 
594
          (%i2) sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
 
595
                                              sqrt(3)
 
596
                                         sqrt(------- + 1)
 
597
                                                 2
 
598
          (%o2)                        ---------------------
 
599
                                       sqrt(11 sqrt(2) - 12)
 
600
          (%i3) sqrtdenest(%);
 
601
                                            sqrt(3)   1
 
602
                                            ------- + -
 
603
                                               2      2
 
604
          (%o3)                            -------------
 
605
                                              1/4    3/4
 
606
                                           3 2    - 2
 
607
 
 
608
     Sometimes it helps to apply `sqrtdenest' more than once, on such as
 
609
     `(19601-13860 sqrt(2))^(7/4)'.
 
610
 
 
611
     `load (sqdnst)' loads this function.
 
612
 
 
613
 
 
614
File: maxima.info,  Node: solve_rec,  Next: stirling,  Prev: simplification,  Up: Top
 
615
 
 
616
65 solve_rec
 
617
************
 
618
 
 
619
* Menu:
 
620
 
 
621
* Introduction to solve_rec::
 
622
* Definitions for solve_rec::
 
623
 
 
624
 
 
625
File: maxima.info,  Node: Introduction to solve_rec,  Next: Definitions for solve_rec,  Prev: solve_rec,  Up: solve_rec
 
626
 
 
627
65.1 Introduction to solve_rec
 
628
==============================
 
629
 
 
630
`solve_rec' is a package for solving linear recurrences with polynomial
 
631
coefficients.
 
632
 
 
633
   A demo is available with `demo(solve_rec);'.
 
634
 
 
635
   Example:
 
636
 
 
637
     (%i1) load("solve_rec")$
 
638
     (%i2) solve_rec((n+4)*s[n+2] + s[n+1] - (n+1)*s[n], s[n]);
 
639
                                         n
 
640
                      %k  (2 n + 3) (- 1)          %k
 
641
                        1                            2
 
642
     (%o2)       s  = -------------------- + ---------------
 
643
                  n     (n + 1) (n + 2)      (n + 1) (n + 2)
 
644
 
 
645
 
 
646
File: maxima.info,  Node: Definitions for solve_rec,  Prev: Introduction to solve_rec,  Up: solve_rec
 
647
 
 
648
65.2 Definitions for solve_rec
 
649
==============================
 
650
 
 
651
 -- Function: closed_form (<expr>)
 
652
     Tries to simplify all sums appearing in <expr> to a closed form.
 
653
 
 
654
     `closed_form' uses Gosper and Zeilberger algorithms to simplify
 
655
     sums.
 
656
 
 
657
     To use this function first load the `closed_form' package with
 
658
     `load(closed_form)'.
 
659
 
 
660
     Example:
 
661
 
 
662
          (%i1) load("closed_form")$
 
663
          (%i2) sum(binom(n+k,k)/2^k, k, 0, n) + sum(binom(2*n, 2*k), k, 0, n);
 
664
                   n                            n
 
665
                  ====                         ====
 
666
                  \      binomial(n + k, k)    \
 
667
          (%o2)    >     ------------------ +   >    binomial(2 n, 2 k)
 
668
                  /               k            /
 
669
                  ====           2             ====
 
670
                  k = 0                        k = 0
 
671
          (%i3) closed_form(%);
 
672
                                         n
 
673
                                        4     n
 
674
          (%o3)                         -- + 2
 
675
                                        2
 
676
 
 
677
 
 
678
 -- Function: reduce_order (<rec>, <sol>, <var>)
 
679
     Reduces the order of linear recurrence <rec> when a particular
 
680
     solution <sol> is known. The reduced reccurence can be used to get
 
681
     other solutions.
 
682
 
 
683
     Example:
 
684
 
 
685
          (%i3) rec: x[n+2] = x[n+1] + x[n]/n;
 
686
                                                x
 
687
                                                 n
 
688
          (%o3)               x      = x      + --
 
689
                               n + 2    n + 1   n
 
690
          (%i4) solve_rec(rec, x[n]);
 
691
          WARNING: found some hypergeometrical solutions!
 
692
          (%o4)                    x  = %k  n
 
693
                                    n     1
 
694
          (%i5) reduce_order(rec, n, x[n]);
 
695
          (%t5)                    x  = n %z
 
696
                                    n       n
 
697
 
 
698
                                     n - 1
 
699
                                     ====
 
700
                                     \
 
701
          (%t6)                %z  =  >     %u
 
702
                                 n   /        %j
 
703
                                     ====
 
704
                                     %j = 0
 
705
 
 
706
          (%o6)             (- n - 2) %u     - %u
 
707
                                        n + 1     n
 
708
          (%i6) solve_rec((n+2)*%u[n+1] + %u[n], %u[n]);
 
709
                                               n
 
710
                                      %k  (- 1)
 
711
                                        1
 
712
          (%o6)                 %u  = ----------
 
713
                                  n    (n + 1)!
 
714
 
 
715
          So the general solution is
 
716
 
 
717
                       n - 1
 
718
                       ====        n
 
719
                       \      (- 1)
 
720
                 %k  n  >    -------- + %k  n
 
721
                   2   /     (n + 1)!     1
 
722
                       ====
 
723
                       n = 0
 
724
 
 
725
 
 
726
 -- Option variable: simplify_products
 
727
     Default value: `true'
 
728
 
 
729
     If `simplify_products' is `true', `solve_rec' will try to simplify
 
730
     products in result.
 
731
 
 
732
     See also: `solve_rec'.
 
733
 
 
734
 
 
735
 -- Function: solve_rec (<eqn>, <var>, [<init>])
 
736
     Solves for hypergeometrical solutions to linear recurrence <eqn>
 
737
     with polynomials coefficient in variable <var>. Optional arguments
 
738
     <init> are initial conditions.
 
739
 
 
740
     `solve_rec' can solve linear recurrences with constant
 
741
     coefficients, finds hypergeometrical solutions to homogeneous
 
742
     linear recurrences with polynomial coefficients, rational
 
743
     solutions to linear recurrences with polynomial coefficients and
 
744
     can solve Ricatti type recurrences.
 
745
 
 
746
     Note that the running time of the algorithm used to find
 
747
     hypergeometrical solutions is exponential in the degree of the
 
748
     leading and trailing coefficient.
 
749
 
 
750
     To use this function first load the `solve_rec' package with
 
751
     `load(solve_rec);'.
 
752
 
 
753
     Example of linear recurrence with constant coefficients:
 
754
 
 
755
          (%i2) solve_rec(a[n]=a[n-1]+a[n-2]+n/2^n, a[n]);
 
756
                                  n          n
 
757
                     (sqrt(5) - 1)  %k  (- 1)
 
758
                                      1           n
 
759
          (%o2) a  = ------------------------- - ----
 
760
                 n               n                  n
 
761
                                2                5 2
 
762
                                                          n
 
763
                                             (sqrt(5) + 1)  %k
 
764
                                                              2    2
 
765
                                           + ------------------ - ----
 
766
                                                      n              n
 
767
                                                     2            5 2
 
768
 
 
769
     Example of linear recurrence with polynomial coefficients:
 
770
 
 
771
          (%i7) 2*x*(x+1)*y[x] - (x^2+3*x-2)*y[x+1] + (x-1)*y[x+2];
 
772
                                   2
 
773
          (%o7) (x - 1) y      - (x  + 3 x - 2) y      + 2 x (x + 1) y
 
774
                         x + 2                   x + 1                x
 
775
          (%i8) solve_rec(%, y[x], y[1]=1, y[3]=3);
 
776
                                        x
 
777
                                     3 2    x!
 
778
          (%o9)                 y  = ---- - --
 
779
                                 x    4     2
 
780
 
 
781
     Example of Ricatti type recurrence:
 
782
 
 
783
          (%i2) x*y[x+1]*y[x] - y[x+1]/(x+2) + y[x]/(x-1) = 0;
 
784
                                      y         y
 
785
                                       x + 1     x
 
786
          (%o2)         x y  y      - ------ + ----- = 0
 
787
                           x  x + 1   x + 2    x - 1
 
788
          (%i3) solve_rec(%, y[x], y[3]=5)$
 
789
          (%i4) ratsimp(minfactorial(factcomb(%)));
 
790
                                             3
 
791
                                         30 x  - 30 x
 
792
          (%o4) y  = - -------------------------------------------------
 
793
                 x        6      5       4       3       2
 
794
                       5 x  - 3 x  - 25 x  + 15 x  + 20 x  - 12 x - 1584
 
795
 
 
796
     See also: `solve_rec_rat', `simplify_products', and
 
797
     `product_use_gamma'.
 
798
 
 
799
 
 
800
 -- Function: solve_rec_rat (<eqn>, <var>, [<init>])
 
801
     Solves for rational solutions to linear recurrences. See solve_rec
 
802
     for description of arguments.
 
803
 
 
804
     To use this function first load the `solve_rec' package with
 
805
     `load(solve_rec);'.
 
806
 
 
807
     Example:
 
808
 
 
809
          (%i1) (x+4)*a[x+3] + (x+3)*a[x+2] - x*a[x+1] + (x^2-1)*a[x];
 
810
          (%o1)  (x + 4) a      + (x + 3) a      - x a
 
811
                          x + 3            x + 2      x + 1
 
812
                                                             2
 
813
                                                         + (x  - 1) a
 
814
                                                                      x
 
815
          (%i2) solve_rec_rat(% = (x+2)/(x+1), a[x]);
 
816
                                 1
 
817
          (%o2)      a  = ---------------
 
818
                      x   (x - 1) (x + 1)
 
819
 
 
820
     See also: `solve_rec'.
 
821
 
 
822
 
 
823
 -- Option variable: product_use_gamma
 
824
     Default value: `true'
 
825
 
 
826
     When simplifying products, `solve_rec' introduces gamma function
 
827
     into the expression if `product_use_gamma' is `true'.
 
828
 
 
829
     See also: `simplify_products', `solve_rec'.
 
830
 
 
831
 
 
832
 -- Function: summand_to_rec (<summand>, <k>, <n>)
 
833
 -- Function: summand_to_rec (<summand>, [<k>, <lo>, <hi>], <n>)
 
834
     Returns the recurrence sattisfied by the sum
 
835
 
 
836
               hi
 
837
              ====
 
838
              \
 
839
               >     summand
 
840
              /
 
841
              ====
 
842
            k = lo
 
843
 
 
844
     where summand is hypergeometrical in <k> and <n>. If <lo> and <hi>
 
845
     are omited, they are assumed to be `lo = -inf' and `hi = inf'.
 
846
 
 
847
     To use this function first load the `closed_form' package with
 
848
     `load(closed_form)'.
 
849
 
 
850
     Example:
 
851
 
 
852
          (%i1) load("closed_form")$
 
853
          (%i2) summand: binom(n,k);
 
854
          (%o2)                           binomial(n, k)
 
855
          (%i3) summand_to_rec(summand,k,n);
 
856
          (%o3)                      2 sm  - sm      = 0
 
857
                                         n     n + 1
 
858
          (%i7) summand: binom(n, k)/(k+1);
 
859
                                          binomial(n, k)
 
860
          (%o7)                           --------------
 
861
                                              k + 1
 
862
          (%i8) summand_to_rec(summand, [k, 0, n], n);
 
863
          (%o8)               2 (n + 1) sm  - (n + 2) sm      = - 1
 
864
                                          n             n + 1
 
865
 
 
866
 
 
867
 
 
868
File: maxima.info,  Node: stirling,  Next: stringproc,  Prev: solve_rec,  Up: Top
 
869
 
 
870
66 stirling
 
871
***********
 
872
 
 
873
* Menu:
 
874
 
 
875
* Definiļæ½ļæ½es para stirling::
 
876
 
 
877
 
 
878
File: maxima.info,  Node: Definiļæ½ļæ½es para stirling,  Prev: stirling,  Up: stirling
 
879
 
 
880
66.1 Definiļæ½ļæ½es para stirling
 
881
=============================
 
882
 
 
883
 -- Funļæ½ļæ½o: stirling (<z>,<n>)
 
884
     Substitui `gamma(x)' pela fļæ½rmula de Stirling O(1/x^(2n-1)).
 
885
     Quando <n> for um inteiro estritamente negativo, sinaliza um erro.
 
886
 
 
887
     Referļæ½ncia: Abramowitz & Stegun, " Handbook of mathematical
 
888
     functions", 6.1.40.
 
889
 
 
890
     Exemplos:
 
891
          (%i1) load (stirling)$
 
892
 
 
893
          (%i2) stirling(gamma(%alpha+x)/gamma(x),1);
 
894
                 1/2 - x             x + %alpha - 1/2
 
895
          (%o2) x        (x + %alpha)
 
896
                                             1           1
 
897
                                      --------------- - ---- - %alpha
 
898
                                      12 (x + %alpha)   12 x
 
899
                                    %e
 
900
          (%i3) taylor(%,x,inf,1);
 
901
                              %alpha       2    %alpha
 
902
                    %alpha   x       %alpha  - x       %alpha
 
903
          (%o3)/T/ x       + -------------------------------- + . . .
 
904
                                           2 x
 
905
          (%i4) map('factor,%);
 
906
                                                 %alpha - 1
 
907
                   %alpha   (%alpha - 1) %alpha x
 
908
          (%o4)   x       + -------------------------------
 
909
                                            2
 
910
 
 
911
     A funļæ½ļæ½o `stirling' conhece a diferenļæ½a entre a variļæ½vel <gamma> e
 
912
     a funļæ½ļæ½o `gamma':
 
913
 
 
914
          (%i5) stirling(gamma + gamma(x),0);
 
915
                                              x - 1/2   - x
 
916
          (%o5)    gamma + sqrt(2) sqrt(%pi) x        %e
 
917
          (%i6) stirling(gamma(y) + gamma(x),0);
 
918
                                   y - 1/2   - y
 
919
          (%o6) sqrt(2) sqrt(%pi) y        %e
 
920
                                                        x - 1/2   - x
 
921
                                   + sqrt(2) sqrt(%pi) x        %e
 
922
 
 
923
     Para usar essa funļæ½ļæ½o escreva primeiro `load("stirling")'.
 
924
 
 
925
 
 
926
File: maxima.info,  Node: stringproc,  Next: unit,  Prev: stirling,  Up: Top
 
927
 
 
928
67 stringproc
 
929
*************
 
930
 
 
931
* Menu:
 
932
 
 
933
* Introduction to string processing::
 
934
* Definitions for input and output::
 
935
* Definitions for characters::
 
936
* Definitions for strings::
 
937
 
 
938
 
 
939
File: maxima.info,  Node: Introduction to string processing,  Next: Definitions for input and output,  Prev: stringproc,  Up: stringproc
 
940
 
 
941
67.1 Introduction to string processing
 
942
======================================
 
943
 
 
944
`stringproc.lisp' enlarges Maximas capabilities of working with strings.
 
945
 
 
946
   Please note that for Maxima Version 5.9.1 you need a different file.
 
947
For questions and bugs mail to van.nek at arcor.de .
 
948
 
 
949
   Load `stringproc.lisp' by typing `load("stringproc");'.
 
950
 
 
951
   In Maxima a string is easily constructed by typing "text".  Note
 
952
that Maxima-strings are no Lisp-strings and vice versa.  Tests can be
 
953
done with `stringp' respectively `lstringp'.  If for some reasons you
 
954
have a value, that is a Lisp-string, maybe when using Maxima-function
 
955
sconcat, you can convert via `sunlisp'.
 
956
 
 
957
     (%i1) load("stringproc")$
 
958
     (%i2) m: "text";
 
959
     (%o2)                         text
 
960
     (%i3) [stringp(m),lstringp(m)];
 
961
     (%o3)                     [true, false]
 
962
     (%i4) l: sconcat("text");
 
963
     (%o4)                         text
 
964
     (%i5) [stringp(l),lstringp(l)];
 
965
     (%o5)                     [false, true]
 
966
     (%i6) stringp( sunlisp(l) );
 
967
     (%o6)                         true
 
968
 
 
969
   All functions in `stringproc.lisp', that return strings, return
 
970
Maxima-strings.
 
971
 
 
972
   Characters are introduced as Maxima-strings of length 1.  Of course,
 
973
these are no Lisp-characters.  Tests can be done with `charp'
 
974
(respectively `lcharp' and conversion from Lisp to Maxima with
 
975
`cunlisp').
 
976
 
 
977
     (%i1) load("stringproc")$
 
978
     (%i2) c: "e";
 
979
     (%o2)                           e
 
980
     (%i3) [charp(c),lcharp(c)];
 
981
     (%o3)                     [true, false]
 
982
     (%i4) supcase(c);
 
983
     (%o4)                           E
 
984
     (%i5) charp(%);
 
985
     (%o5)                         true
 
986
 
 
987
   Again, all functions in `stringproc.lisp', that return characters,
 
988
return Maxima-characters.  Due to the fact, that the introduced
 
989
characters are strings of length 1, you can use a lot of string
 
990
functions also for characters.  As seen, `supcase' is one example.
 
991
 
 
992
   It is important to know, that the first character in a Maxima-string
 
993
is at position 1.  This is designed due to the fact that the first
 
994
element in a Maxima-list is at position 1 too.  See definitions of
 
995
charat and charlist for examples.
 
996
 
 
997
   In applications string-functions are often used when working with
 
998
files.  You will find some useful stream- and print-functions in
 
999
`stringproc.lisp'.  The following example shows some of the here
 
1000
introduced functions at work.
 
1001
 
 
1002
   Example:
 
1003
 
 
1004
   Let file contain Maxima console I/O, saved with 'Save Console to
 
1005
File' or with copy and paste.  `extracti' then extracts the values of
 
1006
all input labels to a batchable file, which path is the return value.
 
1007
The batch process can directly be started with `batch(%)'.  Note that
 
1008
`extracti' fails if at least one label is damaged, maybe due to erasing
 
1009
the `).' Or if there are input lines from a batch process.  In this
 
1010
case terminators are missing.  It fails too, if there are some
 
1011
characters behind the terminators, maybe due to comment.
 
1012
 
 
1013
     extracti(file):= block(
 
1014
        [ s1: openr(file), ifile: sconc(file,".in"), line, nl: false ],
 
1015
        s2: openw(ifile),
 
1016
 
 
1017
        while ( stringp(line: readline(s1)) ) do (
 
1018
           if ssearch( sconc("(",inchar),line ) = 1 then (
 
1019
              line: strim(" ",substring( line,ssearch(")",line)+1 )),
 
1020
              printf( s2,"~a~%",line ),
 
1021
              checklast(line) )
 
1022
           else if nl then (
 
1023
              line: strimr(" ",line),
 
1024
              printf( s2,"~a~%",line ),
 
1025
              checklast(line) )),
 
1026
 
 
1027
        close(s1), close(s2),
 
1028
        ifile)$
 
1029
 
 
1030
     checklast(line):= block(
 
1031
        [ last: charat( line,slength(line) ) ],
 
1032
        if cequal(last,";") or cequal(last,"$") then
 
1033
           nl:false else nl:true )$
 
1034
 
 
1035
   File 'C:\home\maxima\test.out':
 
1036
 
 
1037
     (%i1) f(x):= sin(x)$
 
1038
     (%i2) diff(f(x),x);
 
1039
     (%o2)                               cos(x)
 
1040
     (%i3) df(x):= ''%;
 
1041
     (%o3)                           df(x) := cos(x)
 
1042
     (%i4) df(0);
 
1043
     (%o4)                                  1
 
1044
 
 
1045
   Maxima:
 
1046
 
 
1047
     (%i11) extracti("C:\\home\\maxima\\test.out");
 
1048
     (%o11)             C:\home\maxima\test.out.in
 
1049
     (%i12) batch(%);
 
1050
 
 
1051
     batching #pC:/home/maxima/test.out.in
 
1052
     (%i13)                          f(x) := sin(x)
 
1053
     (%i14)                           diff(f(x), x)
 
1054
     (%o14)                              cos(x)
 
1055
     (%i15)                          df(x) := cos(x)
 
1056
     (%o15)                          df(x) := cos(x)
 
1057
     (%i16)                               df(0)
 
1058
     (%o16)                                 1
 
1059
 
 
1060
 
 
1061
File: maxima.info,  Node: Definitions for input and output,  Next: Definitions for characters,  Prev: Introduction to string processing,  Up: stringproc
 
1062
 
 
1063
67.2 Definitions for input and output
 
1064
=====================================
 
1065
 
 
1066
Example:
 
1067
 
 
1068
     (%i1) s: openw("C:\\home\\file.txt");
 
1069
     (%o1)                 #<output stream C:\home\file.txt>
 
1070
     (%i2) control: "~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2tand an integer: ~20t~d~%"$
 
1071
     (%i3) printf( s,control, 'true,[1,2,3],42 )$
 
1072
     (%o3)                                false
 
1073
     (%i4) close(s);
 
1074
     (%o4)                                true
 
1075
     (%i5) s: openr("C:\\home\\file.txt");
 
1076
     (%o5)                 #<input stream C:\home\file.txt>
 
1077
     (%i6) while stringp( tmp:readline(s) ) do print(tmp)$
 
1078
       An atom:          true
 
1079
       and a list:       one two three
 
1080
       and an integer:   42
 
1081
     (%i7) close(s)$
 
1082
 
 
1083
 -- Function: close (<stream>)
 
1084
     Closes <stream> and returns `true' if <stream> had been open.
 
1085
 
 
1086
 
 
1087
 -- Function: flength (<stream>)
 
1088
     Returns the number of elements in <stream>.
 
1089
 
 
1090
 
 
1091
 -- Function: fposition (<stream>)
 
1092
 -- Function: fposition (<stream>, <pos>)
 
1093
     Returns the current position in <stream>, if <pos> is not used.
 
1094
     If <pos> is used, `fposition' sets the position in <stream>.
 
1095
     <pos> has to be a positive number, the first element in <stream>
 
1096
     is in position 1.
 
1097
 
 
1098
 
 
1099
 -- Function: freshline ()
 
1100
 -- Function: freshline (<stream>)
 
1101
     Writes a new line to <stream>, if the position is not at the
 
1102
     beginning of a line.  `freshline' does not work properly with the
 
1103
     streams `true' and `false'.
 
1104
 
 
1105
 
 
1106
 -- Function: newline ()
 
1107
 -- Function: newline (<stream>)
 
1108
     Writes a new line to <stream>.  `newline' does not work properly
 
1109
     with the streams `true' and `false'.  See `sprint' for an example
 
1110
     of using `newline'.
 
1111
 
 
1112
 
 
1113
 -- Function: opena (<file>)
 
1114
     Returns an output stream to <file>.  If an existing file is
 
1115
     opened, `opena' appends elements at the end of file.
 
1116
 
 
1117
 
 
1118
 -- Function: openr (<file>)
 
1119
     Returns an input stream to <file>.  If <file> does not exist, it
 
1120
     will be created.
 
1121
 
 
1122
 
 
1123
 -- Function: openw (<file>)
 
1124
     Returns an output stream to <file>.  If <file> does not exist, it
 
1125
     will be created.  If an existing file is opened, `openw'
 
1126
     destructively modifies <file>.
 
1127
 
 
1128
 
 
1129
 -- Function: printf (<dest>, <string>)
 
1130
 -- Function: printf (<dest>, <string>, <expr_1>, ..., <expr_n>)
 
1131
     `printf' is like FORMAT in Common Lisp.  (From gcl.info: "format
 
1132
     produces formatted output by outputting the characters of
 
1133
     control-string string and observing that a tilde introduces a
 
1134
     directive.  The character after the tilde, possibly preceded by
 
1135
     prefix parameters and modifiers, specifies what kind of formatting
 
1136
     is desired.  Most directives use one or more elements of args to
 
1137
     create their output.")
 
1138
 
 
1139
     The following description and the examples may give an idea of
 
1140
     using `printf'.  See Lisp reference for more information.  Note
 
1141
     that there are some directives, which do not work in Maxima.  For
 
1142
     example, `~:[' fails.  `printf' is designed with the intention,
 
1143
     that `~s' is read as `~a'.  Also note that the selection directive
 
1144
     `~[' is zero-indexed.
 
1145
 
 
1146
             ~%       new line
 
1147
             ~&       fresh line
 
1148
             ~t       tab
 
1149
             ~$       monetary
 
1150
             ~d       decimal integer
 
1151
             ~b       binary integer
 
1152
             ~o       octal integer
 
1153
             ~x       hexadecimal integer
 
1154
             ~br      base-b integer
 
1155
             ~r       spell an integer
 
1156
             ~p       plural
 
1157
             ~f       floating point
 
1158
             ~e       scientific notation
 
1159
             ~g       ~f or ~e, depending upon magnitude
 
1160
             ~a       as printed by Maxima function print
 
1161
             ~s       like ~a
 
1162
             ~~       ~
 
1163
             ~<       justification, ~> terminates
 
1164
             ~(       case conversion, ~) terminates
 
1165
             ~[       selection, ~] terminates
 
1166
             ~{       iteration, ~} terminates
 
1167
 
 
1168
          (%i1) printf( false, "~s ~a ~4f ~a ~@r",
 
1169
          "String",sym,bound,sqrt(8),144), bound = 1.234;
 
1170
          (%o1)                 String sym 1.23 2*sqrt(2) CXLIV
 
1171
          (%i2) printf( false,"~{~a ~}",["one",2,"THREE"] );
 
1172
          (%o2)                          one 2 THREE
 
1173
          (%i3) printf( true,"~{~{~9,1f ~}~%~}",mat ),
 
1174
          mat = args( matrix([1.1,2,3.33],[4,5,6],[7,8.88,9]) )$
 
1175
                1.1       2.0       3.3
 
1176
                4.0       5.0       6.0
 
1177
                7.0       8.9       9.0
 
1178
          (%i4) control: "~:(~r~) bird~p ~[is~;are~] singing."$
 
1179
          (%i5) printf( false,control, n,n,if n=1 then 0 else 1 ), n=2;
 
1180
          (%o5)                    Two birds are singing.
 
1181
 
 
1182
     If <dest> is a stream or `true', then `printf' returns `false'.
 
1183
     Otherwise, `printf' returns a string containing the output.
 
1184
 
 
1185
 
 
1186
 -- Function: readline (<stream>)
 
1187
     Returns a string containing the characters from the current
 
1188
     position in <stream> up to the end of the line or <false> if the
 
1189
     end of the file is encountered.
 
1190
 
 
1191
 
 
1192
 -- Function: sprint (<expr_1>, ..., <expr_n>)
 
1193
     Evaluates and displays its arguments one after the other `on a
 
1194
     line' starting at the leftmost position.  The numbers are printed
 
1195
     with the '-' right next to the number, and it disregards line
 
1196
     length.
 
1197
 
 
1198
          (%i1) for n:0 thru 16 do sprint( fib(n) )$
 
1199
          0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
 
1200
 
 
1201
     In xmaxima you might wish to add `,newline()', if you prefer line
 
1202
     breaking prior to printing.  See `ascii' for an example.
 
1203
 
 
1204
 
 
1205
 
 
1206
File: maxima.info,  Node: Definitions for characters,  Next: Definitions for strings,  Prev: Definitions for input and output,  Up: stringproc
 
1207
 
 
1208
67.3 Definitions for characters
 
1209
===============================
 
1210
 
 
1211
 -- Function: alphacharp (<char>)
 
1212
     Returns `true' if <char> is an alphabetic character.
 
1213
 
 
1214
 
 
1215
 -- Function: alphanumericp (<char>)
 
1216
     Returns `true' if <char> is an alphabetic character or a digit.
 
1217
 
 
1218
 
 
1219
 -- Function: ascii (<int>)
 
1220
     Returns the character corresponding to the ASCII number <int>.  (
 
1221
     -1 < int < 256 )
 
1222
 
 
1223
          (%i1) for n from 0 thru 255 do ( tmp: ascii(n),
 
1224
          if alphacharp(tmp) then sprint(tmp) ), newline()$
 
1225
          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 a b c d e f g
 
1226
          h i j k l m n o p q r s t u v w x y z
 
1227
 
 
1228
 
 
1229
 -- Function: cequal (<char_1>, <char_2>)
 
1230
     Returns `true' if <char_1> and <char_2> are the same.
 
1231
 
 
1232
 
 
1233
 -- Function: cequalignore (<char_1>, <char_2>)
 
1234
     Like `cequal' but ignores case.
 
1235
 
 
1236
 
 
1237
 -- Function: cgreaterp (<char_1>, <char_2>)
 
1238
     Returns `true' if the ASCII number of <char_1> is greater than the
 
1239
     number of <char_2>.
 
1240
 
 
1241
 
 
1242
 -- Function: cgreaterpignore (<char_1>, <char_2>)
 
1243
     Like `cgreaterp' but ignores case.
 
1244
 
 
1245
 
 
1246
 -- Function: charp (<obj>)
 
1247
     Returns `true' if <obj> is a Maxima-character.  See introduction
 
1248
     for example.
 
1249
 
 
1250
 
 
1251
 -- Function: cint (<char>)
 
1252
     Returns the ASCII number of <char>.
 
1253
 
 
1254
 
 
1255
 -- Function: clessp (<char_1>, <char_2>)
 
1256
     Returns `true' if the ASCII number of <char_1> is less than the
 
1257
     number of <char_2>.
 
1258
 
 
1259
 
 
1260
 -- Function: clesspignore (<char_1>, <char_2>)
 
1261
     Like `clessp' but ignores case.
 
1262
 
 
1263
 
 
1264
 -- Function: constituent (<char>)
 
1265
     Returns `true' if <char> is a graphic character and not the space
 
1266
     character.  A graphic character is a character one can see, plus
 
1267
     the space character.  (`constituent' is defined by Paul Graham,
 
1268
     ANSI Common Lisp, 1996, page 67.)
 
1269
 
 
1270
          (%i1) for n from 0 thru 255 do ( tmp: ascii(n),
 
1271
          if constituent(tmp) then sprint(tmp) ), newline()$
 
1272
          ! " #  %  ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B
 
1273
          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
 
1274
          d e f g h i j k l m n o p q r s t u v w x y z { | } ~
 
1275
 
 
1276
 
 
1277
 -- Function: cunlisp (<lisp_char>)
 
1278
     Converts a Lisp-character into a Maxima-character.  (You wont need
 
1279
     it.)
 
1280
 
 
1281
 
 
1282
 -- Function: digitcharp (<char>)
 
1283
     Returns `true' if <char> is a digit.
 
1284
 
 
1285
 
 
1286
 -- Function: lcharp (<obj>)
 
1287
     Returns `true' if <obj> is a Lisp-character.  (You wont need it.)
 
1288
 
 
1289
 
 
1290
 -- Function: lowercasep (<char>)
 
1291
     Returns `true' if <char> is a lowercase character.
 
1292
 
 
1293
 
 
1294
 -- Variable: newline
 
1295
     The character newline.
 
1296
 
 
1297
 
 
1298
 -- Variable: space
 
1299
     The character space.
 
1300
 
 
1301
 
 
1302
 -- Variable: tab
 
1303
     The character tab.
 
1304
 
 
1305
 
 
1306
 -- Function: uppercasep (<char>)
 
1307
     Returns `true' if <char> is an uppercase character.
 
1308
 
 
1309
 
 
1310
 
 
1311
File: maxima.info,  Node: Definitions for strings,  Prev: Definitions for characters,  Up: stringproc
 
1312
 
 
1313
67.4 Definitions for strings
 
1314
============================
 
1315
 
 
1316
 -- Function: sunlisp (<lisp_string>)
 
1317
     Converts a Lisp-string into a Maxima-string.  (In general you wont
 
1318
     need it.)
 
1319
 
 
1320
 
 
1321
 -- Function: lstringp (<obj>)
 
1322
     Returns `true' if <obj> is a Lisp-string.  (In general you wont
 
1323
     need it.)
 
1324
 
 
1325
 
 
1326
 -- Function: stringp (<obj>)
 
1327
     Returns `true' if <obj> is a Maxima-string.  See introduction for
 
1328
     example.
 
1329
 
 
1330
 
 
1331
 -- Function: charat (<string>, <n>)
 
1332
     Returns the <n>-th character of <string>.  The first character in
 
1333
     <string> is returned with <n> = 1.
 
1334
 
 
1335
          (%i1) load("stringproc")$
 
1336
          (%i2) charat("Lisp",1);
 
1337
          (%o2)                           L
 
1338
 
 
1339
 
 
1340
 -- Function: charlist (<string>)
 
1341
     Returns the list of all characters in <string>.
 
1342
 
 
1343
          (%i1) load("stringproc")$
 
1344
          (%i2) charlist("Lisp");
 
1345
          (%o2)                     [L, i, s, p]
 
1346
          (%i3) %[1];
 
1347
          (%o3)                           L
 
1348
 
 
1349
 
 
1350
 -- Function: parsetoken (<string>)
 
1351
     `parsetoken' converts the first token in <string> to the
 
1352
     corresponding number or returns `false' if the number cannot be
 
1353
     determined .  The delimiter set for tokenizing is `{space, comma,
 
1354
     semicolon, tab, newline}'.
 
1355
 
 
1356
          (%i1) load("stringproc")$
 
1357
          (%i2) 2*parsetoken("1.234 5.678");
 
1358
          (%o2)                         2.468
 
1359
 
 
1360
     For parsing you can also use function parse_string.  See
 
1361
     description in file 'share\contrib\eval_string.lisp'.
 
1362
 
 
1363
 
 
1364
 -- Function: sconc (<expr_1>, ..., <expr_n>)
 
1365
     Evaluates its arguments and concatenates them into a string.
 
1366
     `sconc' is like `sconcat' but returns a Maxima string.
 
1367
 
 
1368
          (%i1) load("stringproc")$
 
1369
          (%i2) sconc("xx[",3,"]:",expand((x+y)^3));
 
1370
          (%o2)             xx[3]:y^3+3*x*y^2+3*x^2*y+x^3
 
1371
          (%i3) stringp(%);
 
1372
          (%o3)                         true
 
1373
 
 
1374
 
 
1375
 -- Function: scopy (<string>)
 
1376
     Returns a copy of <string> as a new string.
 
1377
 
 
1378
 
 
1379
 -- Function: sdowncase (<string>)
 
1380
 -- Function: sdowncase (<string>, <start>)
 
1381
 -- Function: sdowncase (<string>, <start>, <end>)
 
1382
     Like `supcase', but uppercase characters are converted to
 
1383
     lowercase.
 
1384
 
 
1385
 
 
1386
 -- Function: sequal (<string_1>, <string_2>)
 
1387
     Returns `true' if <string_1> and <string_2> are the same length
 
1388
     and contain the same characters.
 
1389
 
 
1390
 
 
1391
 -- Function: sequalignore (<string_1>, <string_2>)
 
1392
     Like `sequal' but ignores case.
 
1393
 
 
1394
 
 
1395
 -- Function: sexplode (<string>)
 
1396
     `sexplode' is an alias for function `charlist'.
 
1397
 
 
1398
 
 
1399
 -- Function: simplode (<list>)
 
1400
 -- Function: simplode (<list>, <delim>)
 
1401
     `simplode' takes a list of expressions and concatenates them into
 
1402
     a string.  If no delimiter <delim> is used, `simplode' is like
 
1403
     `sconc' and uses no delimiter.  <delim> can be any string.
 
1404
 
 
1405
          (%i1) load("stringproc")$
 
1406
          (%i2) simplode(["xx[",3,"]:",expand((x+y)^3)]);
 
1407
          (%o2)             xx[3]:y^3+3*x*y^2+3*x^2*y+x^3
 
1408
          (%i3) simplode( sexplode("stars")," * " );
 
1409
          (%o3)                   s * t * a * r * s
 
1410
          (%i4) simplode( ["One","more","coffee."]," " );
 
1411
          (%o4)                   One more coffee.
 
1412
 
 
1413
 
 
1414
 -- Function: sinsert (<seq>, <string>, <pos>)
 
1415
     Returns a string that is a concatenation of `substring (<string>,
 
1416
     1, <pos> - 1)', the string <seq> and `substring (<string>, <pos>)'.
 
1417
     Note that the first character in <string> is in position 1.
 
1418
 
 
1419
          (%i1) load("stringproc")$
 
1420
          (%i2) s: "A submarine."$
 
1421
          (%i3) sconc( substring(s,1,3),"yellow ",substring(s,3) );
 
1422
          (%o3)                  A yellow submarine.
 
1423
          (%i4) sinsert("hollow ",s,3);
 
1424
          (%o4)                  A hollow submarine.
 
1425
 
 
1426
 
 
1427
 -- Function: sinvertcase (<string>)
 
1428
 -- Function: sinvertcase (<string>, <start>)
 
1429
 -- Function: sinvertcase (<string>, <start>, <end>)
 
1430
     Returns <string> except that each character from position <start>
 
1431
     to <end> is inverted.  If <end> is not given, all characters from
 
1432
     start to the <end> of <string> are replaced.
 
1433
 
 
1434
          (%i1) load("stringproc")$
 
1435
          (%i2) sinvertcase("sInvertCase");
 
1436
          (%o2)                      SiNVERTcASE
 
1437
 
 
1438
 
 
1439
 -- Function: slength (<string>)
 
1440
     Returns the number of characters in <string>.
 
1441
 
 
1442
 
 
1443
 -- Function: smake (<num>, <char>)
 
1444
     Returns a new string with a number of <num> characters <char>.
 
1445
 
 
1446
          (%i1) load("stringproc")$
 
1447
          (%i2) smake(3,"w");
 
1448
          (%o2)                          www
 
1449
 
 
1450
 
 
1451
 -- Function: smismatch (<string_1>, <string_2>)
 
1452
 -- Function: smismatch (<string_1>, <string_2>, <test>)
 
1453
     Returns the position of the first character of <string_1> at which
 
1454
     <string_1> and <string_2> differ or `false'.  Default test
 
1455
     function for matching is `sequal'.  If `smismatch' should ignore
 
1456
     case, use `sequalignore' as test.
 
1457
 
 
1458
          (%i1) load("stringproc")$
 
1459
          (%i2) smismatch("seven","seventh");
 
1460
          (%o2)                           6
 
1461
 
 
1462
 
 
1463
 -- Function: split (<string>)
 
1464
 -- Function: split (<string>, <delim>)
 
1465
 -- Function: split (<string>, <delim>, <multiple>)
 
1466
     Returns the list of all tokens in <string>.  Each token is an
 
1467
     unparsed string.  `split' uses <delim> as delimiter.  If <delim>
 
1468
     is not given, the space character is the default delimiter.
 
1469
     <multiple> is a boolean variable with `true' by default.  Multiple
 
1470
     delimiters are read as one.  This is useful if tabs are saved as
 
1471
     multiple space characters.  If <multiple> is set to `false', each
 
1472
     delimiter is noted.
 
1473
 
 
1474
          (%i1) load("stringproc")$
 
1475
          (%i2) split("1.2   2.3   3.4   4.5");
 
1476
          (%o2)                 [1.2, 2.3, 3.4, 4.5]
 
1477
          (%i3) split("first;;third;fourth",";",false);
 
1478
          (%o3)               [first, , third, fourth]
 
1479
 
 
1480
 
 
1481
 -- Function: sposition (<char>, <string>)
 
1482
     Returns the position of the first character in <string> which
 
1483
     matches <char>.  The first character in <string> is in position 1.
 
1484
     For matching characters ignoring case see `ssearch'.
 
1485
 
 
1486
 
 
1487
 -- Function: sremove (<seq>, <string>)
 
1488
 -- Function: sremove (<seq>, <string>, <test>)
 
1489
 -- Function: sremove (<seq>, <string>, <test>, <start>)
 
1490
 -- Function: sremove (<seq>, <string>, <test>, <start>, <end>)
 
1491
     Returns a string like <string> but without all substrings matching
 
1492
     <seq>.  Default test function for matching is `sequal'.  If
 
1493
     `sremove' should ignore case while searching for <seq>, use
 
1494
     `sequalignore' as test.  Use <start> and <end> to limit searching.
 
1495
     Note that the first character in <string> is in position 1.
 
1496
 
 
1497
          (%i1) load("stringproc")$
 
1498
          (%i2) sremove("n't","I don't like coffee.");
 
1499
          (%o2)                   I do like coffee.
 
1500
          (%i3) sremove ("DO ",%,'sequalignore);
 
1501
          (%o3)                    I like coffee.
 
1502
 
 
1503
 
 
1504
 -- Function: sremovefirst (<seq>, <string>)
 
1505
 -- Function: sremovefirst (<seq>, <string>, <test>)
 
1506
 -- Function: sremovefirst (<seq>, <string>, <test>, <start>)
 
1507
 -- Function: sremovefirst (<seq>, <string>, <test>, <start>, <end>)
 
1508
     Like `sremove' except that only the first substring that matches
 
1509
     `seq' is removed.
 
1510
 
 
1511
 
 
1512
 -- Function: sreverse (<string>)
 
1513
     Returns a string with all the characters of <string> in reverse
 
1514
     order.
 
1515
 
 
1516
 
 
1517
 -- Function: ssearch (<seq>, <string>)
 
1518
 -- Function: ssearch (<seq>, <string>, <test>)
 
1519
 -- Function: ssearch (<seq>, <string>, <test>, <start>)
 
1520
 -- Function: ssearch (<seq>, <string>, <test>, <start>, <end>)
 
1521
     Returns the position of the first substring of <string> that
 
1522
     matches the string <seq>.  Default test function for matching is
 
1523
     `sequal'.  If `ssearch' should ignore case, use `sequalignore' as
 
1524
     test.  Use <start> and <end> to limit searching.  Note that the
 
1525
     first character in <string> is in position 1.
 
1526
 
 
1527
          (%i1) ssearch("~s","~{~S ~}~%",'sequalignore);
 
1528
          (%o1)                                  4
 
1529
 
 
1530
 
 
1531
 -- Function: ssort (<string>)
 
1532
 -- Function: ssort (<string>, <test>)
 
1533
     Returns a string that contains all characters from <string> in an
 
1534
     order such there are no two successive characters <c> and <d> such
 
1535
     that `test (<c>, <d>)' is `false' and `test (<d>, <c>)' is `true'.
 
1536
     Default test function for sorting is <clessp>.  The set of test
 
1537
     functions is `{clessp, clesspignore, cgreaterp, cgreaterpignore,
 
1538
     cequal, cequalignore}'.
 
1539
 
 
1540
          (%i1) load("stringproc")$
 
1541
          (%i2) ssort("I don't like Mondays.");
 
1542
          (%o2)                    '.IMaddeiklnnoosty
 
1543
          (%i3) ssort("I don't like Mondays.",'cgreaterpignore);
 
1544
          (%o3)                 ytsoonnMlkIiedda.'
 
1545
 
 
1546
 
 
1547
 -- Function: ssubst (<new>, <old>, <string>)
 
1548
 -- Function: ssubst (<new>, <old>, <string>, <test>)
 
1549
 -- Function: ssubst (<new>, <old>, <string>, <test>, <start>)
 
1550
 -- Function: ssubst (<new>, <old>, <string>, <test>, <start>, <end>)
 
1551
     Returns a string like <string> except that all substrings matching
 
1552
     <old> are replaced by <new>.  <old> and <new> need not to be of
 
1553
     the same length.  Default test function for matching is `sequal'.
 
1554
     If `ssubst' should ignore case while searching for old, use
 
1555
     `sequalignore' as test.  Use <start> and <end> to limit searching.
 
1556
     Note that the first character in <string> is in position 1.
 
1557
 
 
1558
          (%i1) load("stringproc")$
 
1559
          (%i2) ssubst("like","hate","I hate Thai food. I hate green tea.");
 
1560
          (%o2)          I like Thai food. I like green tea.
 
1561
          (%i3) ssubst("Indian","thai",%,'sequalignore,8,12);
 
1562
          (%o3)         I like Indian food. I like green tea.
 
1563
 
 
1564
 
 
1565
 -- Function: ssubstfirst (<new>, <old>, <string>)
 
1566
 -- Function: ssubstfirst (<new>, <old>, <string>, <test>)
 
1567
 -- Function: ssubstfirst (<new>, <old>, <string>, <test>, <start>)
 
1568
 -- Function: ssubstfirst (<new>, <old>, <string>, <test>, <start>,
 
1569
          <end>)
 
1570
     Like `subst' except that only the first substring that matches
 
1571
     <old> is replaced.
 
1572
 
 
1573
 
 
1574
 -- Function: strim (<seq>,<string>)
 
1575
     Returns a string like <string>, but with all characters that
 
1576
     appear in <seq> removed from both ends.
 
1577
 
 
1578
          (%i1) load("stringproc")$
 
1579
          (%i2) "/* comment */"$
 
1580
          (%i3) strim(" /*",%);
 
1581
          (%o3)                        comment
 
1582
          (%i4) slength(%);
 
1583
          (%o4)                           7
 
1584
 
 
1585
 
 
1586
 -- Function: striml (<seq>, <string>)
 
1587
     Like `strim' except that only the left end of <string> is trimmed.
 
1588
 
 
1589
 
 
1590
 -- Function: strimr (<seq>, <string>)
 
1591
     Like `strim' except that only the right end of string is trimmed.
 
1592
 
 
1593
 
 
1594
 -- Function: substring (<string>, <start>)
 
1595
 -- Function: substring (<string>, <start>, <end>)
 
1596
     Returns the substring of <string> beginning at position <start>
 
1597
     and ending at position <end>.  The character at position <end> is
 
1598
     not included.  If <end> is not given, the substring contains the
 
1599
     rest of the string.  Note that the first character in <string> is
 
1600
     in position 1.
 
1601
 
 
1602
          (%i1) load("stringproc")$
 
1603
          (%i2) substring("substring",4);
 
1604
          (%o2)                        string
 
1605
          (%i3) substring(%,4,6);
 
1606
          (%o3)                          in
 
1607
 
 
1608
 
 
1609
 -- Function: supcase (<string>)
 
1610
 -- Function: supcase (<string>, <start>)
 
1611
 -- Function: supcase (<string>, <start>, <end>)
 
1612
     Returns <string> except that lowercase characters from position
 
1613
     <start> to <end> are replaced by the corresponding uppercase ones.
 
1614
     If <end> is not given, all lowercase characters from <start> to
 
1615
     the end of <string> are replaced.
 
1616
 
 
1617
          (%i1) load("stringproc")$
 
1618
          (%i2) supcase("english",1,2);
 
1619
          (%o2)                        English
 
1620
 
 
1621
 
 
1622
 -- Function: tokens (<string>)
 
1623
 -- Function: tokens (<string>, <test>)
 
1624
     Returns a list of tokens, which have been extracted from <string>.
 
1625
     The tokens are substrings whose characters satisfy a certain test
 
1626
     function.  If test is not given, <constituent> is used as the
 
1627
     default test.  `{constituent, alphacharp, digitcharp, lowercasep,
 
1628
     uppercasep, charp, characterp, alphanumericp}' is the set of test
 
1629
     functions.  (The Lisp-version of `tokens' is written by Paul
 
1630
     Graham. ANSI Common Lisp, 1996, page 67.)
 
1631
 
 
1632
          (%i1) load("stringproc")$
 
1633
          (%i2) tokens("24 October 2005");
 
1634
          (%o2)                  [24, October, 2005]
 
1635
          (%i3) tokens("05-10-24",'digitcharp);
 
1636
          (%o3)                     [05, 10, 24]
 
1637
          (%i4) map(parsetoken,%);
 
1638
          (%o4)                      [5, 10, 24]
 
1639
 
 
1640
 
 
1641
 
 
1642
File: maxima.info,  Node: unit,  Next: zeilberger,  Prev: stringproc,  Up: Top
 
1643
 
 
1644
68 unit
 
1645
*******
 
1646
 
 
1647
* Menu:
 
1648
 
 
1649
* Introduction to Units::
 
1650
* Definitions for Units::
 
1651
 
 
1652
 
 
1653
File: maxima.info,  Node: Introduction to Units,  Next: Definitions for Units,  Prev: unit,  Up: unit
 
1654
 
 
1655
68.1 Introduction to Units
 
1656
==========================
 
1657
 
 
1658
The _unit_ package enables the user to convert between arbitrary units
 
1659
and work with dimensions in equations. The functioning of this package
 
1660
is radically different from the original Maxima units package - whereas
 
1661
the original was a basic list of definitions, this package uses
 
1662
rulesets to allow the user to chose, on a per dimension basis, what
 
1663
unit final answers should be rendered in.  It will separate units
 
1664
instead of intermixing them in the display, allowing the user to
 
1665
readily identify the units associated with a particular answer.  It
 
1666
will allow a user to simplify an expression to its fundamental Base
 
1667
Units, as well as providing fine control over simplifying to derived
 
1668
units.  Dimensional analysis is possible, and a variety of tools are
 
1669
available to manage conversion and simplification options. In addition
 
1670
to customizable automatic conversion, _units_ also provides a
 
1671
traditional manual conversion option.
 
1672
 
 
1673
   Note - when unit conversions are inexact Maxima will make
 
1674
approximations resulting in fractions. This is a consequence of the
 
1675
techniques used to simplify units.  The messages warning of this type
 
1676
of substitution are disabled by default in the case of units (normally
 
1677
they are on) since this situation occurs frequently and the warnings
 
1678
clutter the output.  (The existing state of ratprint is restored after
 
1679
unit conversions, so user changes to that setting will be preserved
 
1680
otherwise.)  If  the user needs this information for units, they can set
 
1681
_unitverbose:on_ to reactivate the printing of warnings from the unit
 
1682
conversion process.
 
1683
 
 
1684
   _unit_ is included in Maxima in the share/contrib/unit directory. It
 
1685
obeys normal Maxima package loading conventions:
 
1686
 
 
1687
     (%i1) load("unit")$
 
1688
     *******************************************************************
 
1689
     *                       Units version 0.50                        *
 
1690
     *          Definitions based on the NIST Reference on             *
 
1691
     *              Constants, Units, and Uncertainty                  *
 
1692
     *       Conversion factors from various sources including         *
 
1693
     *                   NIST and the GNU units package                *
 
1694
     *******************************************************************
 
1695
 
 
1696
     Redefining necessary functions...
 
1697
     WARNING: DEFUN/DEFMACRO: redefining function TOPLEVEL-MACSYMA-EVAL ...
 
1698
     WARNING: DEFUN/DEFMACRO: redefining function MSETCHK ...
 
1699
     WARNING: DEFUN/DEFMACRO: redefining function KILL1 ...
 
1700
     WARNING: DEFUN/DEFMACRO: redefining function NFORMAT ...
 
1701
     Initializing unit arrays...
 
1702
     Done.
 
1703
 
 
1704
   The WARNING messages are expected and not a cause for concern - they
 
1705
indicate the _unit_ package is redefining functions already defined in
 
1706
Maxima proper.  This is necessary in order to properly handle units.
 
1707
The user should be aware that if other changes have been made to these
 
1708
functions by other packages those changes will be overwritten by this
 
1709
loading process.
 
1710
 
 
1711
   The _unit.mac_ file also loads a lisp file _unit-functions.lisp_
 
1712
which contains the lisp functions needed for the package.
 
1713
 
 
1714
   Clifford Yapp is the primary author.  He has received valuable
 
1715
assistance from Barton Willis of the University of Nebraska at Kearney
 
1716
(UNK), Robert Dodier, and other intrepid folk of the Maxima mailing
 
1717
list.
 
1718
 
 
1719
   There are probably lots of bugs.  Let me know.  `float' and `numer'
 
1720
don't do what is expected.
 
1721
 
 
1722
   TODO : dimension functionality, handling of temperature, showabbr
 
1723
and friends.  Show examples with addition of quantities containing
 
1724
units.
 
1725
 
 
1726
 
 
1727
File: maxima.info,  Node: Definitions for Units,  Prev: Introduction to Units,  Up: unit
 
1728
 
 
1729
68.2 Definitions for Units
 
1730
==========================
 
1731
 
 
1732
 -- Function: setunits (<list>)
 
1733
     By default, the _unit_ package does not use any derived
 
1734
     dimensions, but will convert all units to the seven fundamental
 
1735
     dimensions using MKS units.
 
1736
          (%i2) N;
 
1737
                                               kg m
 
1738
          (%o2)                                ----
 
1739
                                                 2
 
1740
                                                s
 
1741
          (%i3) dyn;
 
1742
                                             1      kg m
 
1743
          (%o3)                           (------) (----)
 
1744
                                           100000     2
 
1745
                                                     s
 
1746
          (%i4) g;
 
1747
                                              1
 
1748
          (%o4)                             (----) (kg)
 
1749
                                             1000
 
1750
          (%i5) centigram*inch/minutes^2;
 
1751
                                            127        kg m
 
1752
          (%o5)                       (-------------) (----)
 
1753
                                       1800000000000     2
 
1754
                                                        s
 
1755
 
 
1756
     In some cases this is the desired behavior.  If the user wishes to
 
1757
     use other units, this is achieved with the `setunits' command:
 
1758
          (%i6) setunits([centigram,inch,minute]);
 
1759
          (%o6)                                done
 
1760
          (%i7) N;
 
1761
                                      1800000000000   %in cg
 
1762
          (%o7)                      (-------------) (------)
 
1763
                                           127            2
 
1764
                                                      %min
 
1765
          (%i8) dyn;
 
1766
                                         18000000   %in cg
 
1767
          (%o8)                         (--------) (------)
 
1768
                                           127          2
 
1769
                                                    %min
 
1770
          (%i9) g;
 
1771
          (%o9)                             (100) (cg)
 
1772
          (%i10) centigram*inch/minutes^2;
 
1773
                                              %in cg
 
1774
          (%o10)                              ------
 
1775
                                                  2
 
1776
                                              %min
 
1777
 
 
1778
     The setting of units is quite flexible.  For example, if we want to
 
1779
     get back to kilograms, meters, and seconds as defaults for those
 
1780
     dimensions we can do:
 
1781
          (%i11) setunits([kg,m,s]);
 
1782
          (%o11)                               done
 
1783
          (%i12) centigram*inch/minutes^2;
 
1784
                                            127        kg m
 
1785
          (%o12)                      (-------------) (----)
 
1786
                                       1800000000000     2
 
1787
                                                        s
 
1788
 
 
1789
     Derived units are also handled by this command:
 
1790
          (%i17) setunits(N);
 
1791
          (%o17)                               done
 
1792
          (%i18) N;
 
1793
          (%o18)                                 N
 
1794
          (%i19) dyn;
 
1795
                                              1
 
1796
          (%o19)                           (------) (N)
 
1797
                                            100000
 
1798
          (%i20) kg*m/s^2;
 
1799
          (%o20)                                 N
 
1800
          (%i21) centigram*inch/minutes^2;
 
1801
                                              127
 
1802
          (%o21)                        (-------------) (N)
 
1803
                                         1800000000000
 
1804
 
 
1805
     Notice that the _unit_ package recognized the non MKS combination
 
1806
     of mass, length, and inverse time squared as a force, and
 
1807
     converted it to Newtons.  This is how Maxima works in general.
 
1808
     If, for example, we prefer dyne to Newtons, we simply do the
 
1809
     following:
 
1810
          (%i22) setunits(dyn);
 
1811
          (%o22)                               done
 
1812
          (%i23) kg*m/s^2;
 
1813
          (%o23)                          (100000) (dyn)
 
1814
          (%i24) centigram*inch/minutes^2;
 
1815
                                            127
 
1816
          (%o24)                         (--------) (dyn)
 
1817
                                          18000000
 
1818
 
 
1819
     To discontinue simplifying to any force, we use the uforget
 
1820
     command:
 
1821
          (%i26) uforget(dyn);
 
1822
          (%o26)                               false
 
1823
          (%i27) kg*m/s^2;
 
1824
                                               kg m
 
1825
          (%o27)                               ----
 
1826
                                                 2
 
1827
                                                s
 
1828
          (%i28) centigram*inch/minutes^2;
 
1829
                                            127        kg m
 
1830
          (%o28)                      (-------------) (----)
 
1831
                                       1800000000000     2
 
1832
                                                        s
 
1833
     This would have worked equally well with `uforget(N)' or
 
1834
     `uforget(%force)'.
 
1835
 
 
1836
     See also `uforget'. To use this function write first
 
1837
     `load("unit")'.
 
1838
 
 
1839
 -- Function: uforget (<list>)
 
1840
     By default, the _unit_ package converts all units to the seven
 
1841
     fundamental dimensions using MKS units. This behavior can be
 
1842
     changed with the `setunits' command. After that, the user can
 
1843
     restore the default behavior for a particular dimension by means
 
1844
     of the `uforget' command:
 
1845
          (%i13) setunits([centigram,inch,minute]);
 
1846
          (%o13)                               done
 
1847
          (%i14) centigram*inch/minutes^2;
 
1848
                                              %in cg
 
1849
          (%o14)                              ------
 
1850
                                                  2
 
1851
                                              %min
 
1852
          (%i15) uforget([cg,%in,%min]);
 
1853
          (%o15)                      [false, false, false]
 
1854
          (%i16) centigram*inch/minutes^2;
 
1855
                                            127        kg m
 
1856
          (%o16)                      (-------------) (----)
 
1857
                                       1800000000000     2
 
1858
                                                        s
 
1859
 
 
1860
     `uforget' operates on dimensions, not units, so any unit of a
 
1861
     particular dimension will work.  The dimension itself is also a
 
1862
     legal argument.
 
1863
 
 
1864
     See also `setunits'. To use this function write first
 
1865
     `load("unit")'.
 
1866
 
 
1867
 -- Function: convert (<expr>, <list>)
 
1868
     When resetting the global environment is overkill, there is the
 
1869
     `convert' command, which allows one time conversions.  It can
 
1870
     accept either a single argument or a list of units to use in
 
1871
     conversion.  When a convert operation is done, the normal global
 
1872
     evaluation system is bypassed, in order to avoid the desired
 
1873
     result being converted again.  As a consequence, for inexact
 
1874
     calculations "rat" warnings will be visible if the global
 
1875
     environment controlling this behavior (`ratprint') is true.  This
 
1876
     is also useful for spot-checking the accuracy of a global
 
1877
     conversion.  Another feature is `convert' will allow a user to do
 
1878
     Base Dimension conversions even if the global environment is set to
 
1879
     simplify to a Derived Dimension.
 
1880
 
 
1881
          (%i2) kg*m/s^2;
 
1882
                                               kg m
 
1883
          (%o2)                                ----
 
1884
                                                 2
 
1885
                                                s
 
1886
          (%i3) convert(kg*m/s^2,[g,km,s]);
 
1887
                                               g km
 
1888
          (%o3)                                ----
 
1889
                                                 2
 
1890
                                                s
 
1891
          (%i4) convert(kg*m/s^2,[g,inch,minute]);
 
1892
 
 
1893
          `rat' replaced 39.37007874015748 by 5000//127 = 39.37007874015748
 
1894
                                        18000000000   %in g
 
1895
          (%o4)                        (-----------) (-----)
 
1896
                                            127           2
 
1897
                                                      %min
 
1898
          (%i5) convert(kg*m/s^2,[N]);
 
1899
          (%o5)                                  N
 
1900
          (%i6) convert(kg*m^2/s^2,[N]);
 
1901
          (%o6)                                 m N
 
1902
          (%i7) setunits([N,J]);
 
1903
          (%o7)                                done
 
1904
          (%i8) convert(kg*m^2/s^2,[N]);
 
1905
          (%o8)                                 m N
 
1906
          (%i9) convert(kg*m^2/s^2,[N,inch]);
 
1907
 
 
1908
          `rat' replaced 39.37007874015748 by 5000//127 = 39.37007874015748
 
1909
                                           5000
 
1910
          (%o9)                           (----) (%in N)
 
1911
                                           127
 
1912
          (%i10) convert(kg*m^2/s^2,[J]);
 
1913
          (%o10)                                 J
 
1914
          (%i11) kg*m^2/s^2;
 
1915
          (%o11)                                 J
 
1916
          (%i12) setunits([g,inch,s]);
 
1917
          (%o12)                               done
 
1918
          (%i13) kg*m/s^2;
 
1919
          (%o13)                                 N
 
1920
          (%i14) uforget(N);
 
1921
          (%o14)                               false
 
1922
          (%i15) kg*m/s^2;
 
1923
                                          5000000   %in g
 
1924
          (%o15)                         (-------) (-----)
 
1925
                                            127       2
 
1926
                                                     s
 
1927
          (%i16) convert(kg*m/s^2,[g,inch,s]);
 
1928
 
 
1929
          `rat' replaced 39.37007874015748 by 5000//127 = 39.37007874015748
 
1930
                                          5000000   %in g
 
1931
          (%o16)                         (-------) (-----)
 
1932
                                            127       2
 
1933
                                                     s
 
1934
 
 
1935
     See also `setunits' and `uforget'. To use this function write
 
1936
     first `load("unit")'.
 
1937
 
 
1938
 -- Optional variable: usersetunits
 
1939
     Default value: none
 
1940
 
 
1941
     If a user wishes to have a default unit behavior other than that
 
1942
     described, they can make use of _maxima-init.mac_ and the
 
1943
     _usersetunits_ variable.  The _unit_ package will check on startup
 
1944
     to see if this variable has been assigned a list.  If it has, it
 
1945
     will use setunits on that list and take the units from that list
 
1946
     to be defaults.  `uforget' will revert to the behavior defined by
 
1947
     usersetunits over its own defaults.  For example, if we have a
 
1948
     _maxima-init.mac_ file containing:
 
1949
          usersetunits : [N,J];
 
1950
     we would see the following behavior:
 
1951
          (%i1) load("unit")$
 
1952
          *******************************************************************
 
1953
          *                       Units version 0.50                        *
 
1954
          *          Definitions based on the NIST Reference on             *
 
1955
          *              Constants, Units, and Uncertainty                  *
 
1956
          *       Conversion factors from various sources including         *
 
1957
          *                   NIST and the GNU units package                *
 
1958
          *******************************************************************
 
1959
 
 
1960
          Redefining necessary functions...
 
1961
          WARNING: DEFUN/DEFMACRO: redefining function TOPLEVEL-MACSYMA-EVAL ...
 
1962
          WARNING: DEFUN/DEFMACRO: redefining function MSETCHK ...
 
1963
          WARNING: DEFUN/DEFMACRO: redefining function KILL1 ...
 
1964
          WARNING: DEFUN/DEFMACRO: redefining function NFORMAT ...
 
1965
          Initializing unit arrays...
 
1966
          Done.
 
1967
          User defaults found...
 
1968
          User defaults initialized.
 
1969
          (%i2) kg*m/s^2;
 
1970
          (%o2)                                  N
 
1971
          (%i3) kg*m^2/s^2;
 
1972
          (%o3)                                  J
 
1973
          (%i4) kg*m^3/s^2;
 
1974
          (%o4)                                 J m
 
1975
          (%i5) kg*m*km/s^2;
 
1976
          (%o5)                             (1000) (J)
 
1977
          (%i6) setunits([dyn,eV]);
 
1978
          (%o6)                                done
 
1979
          (%i7) kg*m/s^2;
 
1980
          (%o7)                           (100000) (dyn)
 
1981
          (%i8) kg*m^2/s^2;
 
1982
          (%o8)                     (6241509596477042688) (eV)
 
1983
          (%i9) kg*m^3/s^2;
 
1984
          (%o9)                    (6241509596477042688) (eV m)
 
1985
          (%i10) kg*m*km/s^2;
 
1986
          (%o10)                   (6241509596477042688000) (eV)
 
1987
          (%i11) uforget([dyn,eV]);
 
1988
          (%o11)                           [false, false]
 
1989
          (%i12) kg*m/s^2;
 
1990
          (%o12)                                 N
 
1991
          (%i13) kg*m^2/s^2;
 
1992
          (%o13)                                 J
 
1993
          (%i14) kg*m^3/s^2;
 
1994
          (%o14)                                J m
 
1995
          (%i15) kg*m*km/s^2;
 
1996
          (%o15)                            (1000) (J)
 
1997
     Without `usersetunits', the initial inputs would have been
 
1998
     converted to MKS, and uforget would have resulted in a return to
 
1999
     MKS rules.  Instead, the user preferences are respected in both
 
2000
     cases.  Notice these can still be overridden if desired.  To
 
2001
     completely eliminate this simplification - i.e.  to have the user
 
2002
     defaults reset to factory defaults - the `dontusedimension'
 
2003
     command can be used.  `uforget' can restore user settings again,
 
2004
     but only if `usedimension' frees it for use.  Alternately,
 
2005
     `kill(usersetunits)' will completely remove all knowledge of the
 
2006
     user defaults from the session.  Here are some examples of how
 
2007
     these various options work.
 
2008
          (%i2) kg*m/s^2;
 
2009
          (%o2)                                  N
 
2010
          (%i3) kg*m^2/s^2;
 
2011
          (%o3)                                  J
 
2012
          (%i4) setunits([dyn,eV]);
 
2013
          (%o4)                                done
 
2014
          (%i5) kg*m/s^2;
 
2015
          (%o5)                           (100000) (dyn)
 
2016
          (%i6) kg*m^2/s^2;
 
2017
          (%o6)                     (6241509596477042688) (eV)
 
2018
          (%i7) uforget([dyn,eV]);
 
2019
          (%o7)                          [false, false]
 
2020
          (%i8) kg*m/s^2;
 
2021
          (%o8)                                  N
 
2022
          (%i9) kg*m^2/s^2;
 
2023
          (%o9)                                  J
 
2024
          (%i10) dontusedimension(N);
 
2025
          (%o10)                             [%force]
 
2026
          (%i11) dontusedimension(J);
 
2027
          (%o11)                         [%energy, %force]
 
2028
          (%i12) kg*m/s^2;
 
2029
                                               kg m
 
2030
          (%o12)                               ----
 
2031
                                                 2
 
2032
                                                s
 
2033
          (%i13) kg*m^2/s^2;
 
2034
                                                   2
 
2035
                                               kg m
 
2036
          (%o13)                               -----
 
2037
                                                 2
 
2038
                                                s
 
2039
          (%i14) setunits([dyn,eV]);
 
2040
          (%o14)                               done
 
2041
          (%i15) kg*m/s^2;
 
2042
                                               kg m
 
2043
          (%o15)                               ----
 
2044
                                                 2
 
2045
                                                s
 
2046
          (%i16) kg*m^2/s^2;
 
2047
                                                   2
 
2048
                                               kg m
 
2049
          (%o16)                               -----
 
2050
                                                 2
 
2051
                                                s
 
2052
          (%i17) uforget([dyn,eV]);
 
2053
          (%o17)                         [false, false]
 
2054
          (%i18) kg*m/s^2;
 
2055
                                               kg m
 
2056
          (%o18)                               ----
 
2057
                                                 2
 
2058
                                                s
 
2059
          (%i19) kg*m^2/s^2;
 
2060
                                                   2
 
2061
                                               kg m
 
2062
          (%o19)                               -----
 
2063
                                                 2
 
2064
                                                s
 
2065
          (%i20) usedimension(N);
 
2066
          Done.  To have Maxima simplify to this dimension, use setunits([unit])
 
2067
          to select a unit.
 
2068
          (%o20)                               true
 
2069
          (%i21) usedimension(J);
 
2070
          Done.  To have Maxima simplify to this dimension, use setunits([unit])
 
2071
          to select a unit.
 
2072
          (%o21)                               true
 
2073
          (%i22) kg*m/s^2;
 
2074
                                               kg m
 
2075
          (%o22)                               ----
 
2076
                                                 2
 
2077
                                                s
 
2078
          (%i23) kg*m^2/s^2;
 
2079
                                                   2
 
2080
                                               kg m
 
2081
          (%o23)                               -----
 
2082
                                                 2
 
2083
                                                s
 
2084
          (%i24) setunits([dyn,eV]);
 
2085
          (%o24)                               done
 
2086
          (%i25) kg*m/s^2;
 
2087
          (%o25)                          (100000) (dyn)
 
2088
          (%i26) kg*m^2/s^2;
 
2089
          (%o26)                    (6241509596477042688) (eV)
 
2090
          (%i27) uforget([dyn,eV]);
 
2091
          (%o27)                           [false, false]
 
2092
          (%i28) kg*m/s^2;
 
2093
          (%o28)                                 N
 
2094
          (%i29) kg*m^2/s^2;
 
2095
          (%o29)                                 J
 
2096
          (%i30) kill(usersetunits);
 
2097
          (%o30)                               done
 
2098
          (%i31) uforget([dyn,eV]);
 
2099
          (%o31)                          [false, false]
 
2100
          (%i32) kg*m/s^2;
 
2101
                                               kg m
 
2102
          (%o32)                               ----
 
2103
                                                 2
 
2104
                                                s
 
2105
          (%i33) kg*m^2/s^2;
 
2106
                                                   2
 
2107
                                               kg m
 
2108
          (%o33)                               -----
 
2109
                                                 2
 
2110
                                                s
 
2111
     Unfortunately this wide variety of options is a little confusing
 
2112
     at first, but once the user grows used to them they should find
 
2113
     they have very full control over their working environment.
 
2114
 
 
2115
 
 
2116
 -- Function: metricexpandall (<x>)
 
2117
     Rebuilds global unit lists automatically creating all desired
 
2118
     metric units.  <x> is a numerical argument which is used to
 
2119
     specify how many metric prefixes the user wishes defined.  The
 
2120
     arguments are as follows, with each higher number defining all
 
2121
     lower numbers' units:
 
2122
                     0 - none. Only base units
 
2123
                     1 - kilo, centi, milli
 
2124
          (default)  2 - giga, mega, kilo, hecto, deka, deci, centi, milli,
 
2125
                         micro, nano
 
2126
                     3 - peta, tera, giga, mega, kilo, hecto, deka, deci,
 
2127
                         centi, milli, micro, nano, pico, femto
 
2128
                     4 - all
 
2129
     Normally, Maxima will not define the full expansion since this
 
2130
     results in a very large number of units, but `metricexpandall' can
 
2131
     be used to rebuild the list in a more or less complete fashion.
 
2132
     The relevant variable in the _unit.mac_ file is <%unitexpand>.
 
2133
 
 
2134
 -- Variable: %unitexpand
 
2135
     Default value: `2'
 
2136
 
 
2137
     This is the value supplied to `metricexpandall' during the initial
 
2138
     loading of _unit_.
 
2139
 
 
2140
 
 
2141
 
 
2142
File: maxima.info,  Node: zeilberger,  Next: ļæ½ndice de Funļæ½ļæ½es e Variļæ½veis,  Prev: unit,  Up: Top
 
2143
 
 
2144
69 zeilberger
 
2145
*************
 
2146
 
 
2147
* Menu:
 
2148
 
 
2149
* Introduction to zeilberger::
 
2150
* Definitions for zeilberger::
 
2151
 
 
2152
 
 
2153
File: maxima.info,  Node: Introduction to zeilberger,  Next: Definitions for zeilberger,  Prev: zeilberger,  Up: zeilberger
 
2154
 
 
2155
69.1 Introduction to zeilberger
 
2156
===============================
 
2157
 
 
2158
`zeilberger' is a implementation of Zeilberger's algorithm for definite
 
2159
hypergeometric summation, and also Gosper's algorithm for indefinite
 
2160
hypergeometric summation.
 
2161
 
 
2162
   `zeilberger' makes use of the "filtering" optimization method
 
2163
developed by Axel Riese.
 
2164
 
 
2165
   `zeilberger' was developed by Fabrizio Caruso.
 
2166
 
 
2167
   `load (zeilberger)' loads this package.
 
2168
 
 
2169
69.1.0.1 The indefinite summation problem
 
2170
.........................................
 
2171
 
 
2172
`zeilberger' implements Gosper's algorithm for indefinite
 
2173
hypergeometric summation.  Given a hypergeometric term F_k in k we want
 
2174
to find its hypergeometric anti-difference, that is, a hypergeometric
 
2175
term f_k such that F_k = f_(k+1) - f_k.
 
2176
 
 
2177
69.1.0.2 The definite summation problem
 
2178
.......................................
 
2179
 
 
2180
`zeilberger' implements Zeilberger's algorithm for definite
 
2181
hypergeometric summation.  Given a proper hypergeometric term (in n and
 
2182
k) F_(n,k) and a positive integer d we want to find a d-th order linear
 
2183
recurrence with polynomial coefficients (in n) for F_(n,k) and a
 
2184
rational function R in n and k such that
 
2185
 
 
2186
   a_0 F_(n,k) + ... + a_d F_(n+d),k = Delta_K(R(n,k) F_(n,k))
 
2187
 
 
2188
   where Delta_k is the k-forward difference operator, i.e.,
 
2189
Delta_k(t_k) := t_(k+1) - t_k.
 
2190
 
 
2191
69.1.1 Verbosity levels
 
2192
-----------------------
 
2193
 
 
2194
There are also verbose versions of the commands which are called by
 
2195
adding one of the following prefixes:
 
2196
 
 
2197
`Summary'
 
2198
     Just a summary at the end is shown
 
2199
 
 
2200
`Verbose'
 
2201
     Some information in the intermidiate steps
 
2202
 
 
2203
`VeryVerbose'
 
2204
     More information
 
2205
 
 
2206
`Extra'
 
2207
     Even more information including information on the linear system
 
2208
     in Zeilberger's algorithm
 
2209
 
 
2210
   For example: `GosperVerbose', `parGosperVeryVerbose',
 
2211
`ZeilbergerExtra', `AntiDifferenceSummary'.
 
2212
 
 
2213
 
 
2214
File: maxima.info,  Node: Definitions for zeilberger,  Prev: Introduction to zeilberger,  Up: zeilberger
 
2215
 
 
2216
69.2 Definitions for zeilberger
 
2217
===============================
 
2218
 
 
2219
 -- Function: AntiDifference (<F_k>, <k>)
 
2220
     Returns the hypergeometric anti-difference of <F_k>, if it exists.
 
2221
     Otherwise `AntiDifference' returns `no_hyp_antidifference'.
 
2222
 
 
2223
 -- Function: Gosper (<F_k>, <k>)
 
2224
     Returns the rational certificate <R(k)> for <F_k>, that is, a
 
2225
     rational function such that
 
2226
 
 
2227
     F_k = R(k+1) F_(k+1) - R(k) F_k
 
2228
 
 
2229
     if it exists.  Otherwise, `Gosper' returns `no_hyp_sol'.
 
2230
 
 
2231
 -- Function: GosperSum (<F_k>, <k>, <a>, <b>)
 
2232
     Returns the summmation of <F_k> from <k> = <a> to <k> = <b> if
 
2233
     <F_k> has a hypergeometric anti-difference.  Otherwise,
 
2234
     `GosperSum' returns `nongosper_summable'.
 
2235
 
 
2236
     Examples:
 
2237
 
 
2238
          (%i1) load (zeilberger);
 
2239
          (%o1)  /usr/share/maxima/share/contrib/Zeilberger/zeilberger.mac
 
2240
          (%i2) GosperSum ((-1)^k*k / (4*k^2 - 1), k, 1, n);
 
2241
 
 
2242
          Dependent equations eliminated:  (1)
 
2243
                                     3       n + 1
 
2244
                                (n + -) (- 1)
 
2245
                                     2               1
 
2246
          (%o2)               - ------------------ - -
 
2247
                                            2        4
 
2248
                                2 (4 (n + 1)  - 1)
 
2249
          (%i3) GosperSum (1 / (4*k^2 - 1), k, 1, n);
 
2250
                                          3
 
2251
                                    - n - -
 
2252
                                          2       1
 
2253
          (%o3)                  -------------- + -
 
2254
                                          2       2
 
2255
                                 4 (n + 1)  - 1
 
2256
          (%i4) GosperSum (x^k, k, 1, n);
 
2257
                                    n + 1
 
2258
                                   x          x
 
2259
          (%o4)                    ------ - -----
 
2260
                                   x - 1    x - 1
 
2261
          (%i5) GosperSum ((-1)^k*a! / (k!*(a - k)!), k, 1, n);
 
2262
                                          n + 1
 
2263
                          a! (n + 1) (- 1)              a!
 
2264
          (%o5)       - ------------------------- - ----------
 
2265
                        a (- n + a - 1)! (n + 1)!   a (a - 1)!
 
2266
          (%i6) GosperSum (k*k!, k, 1, n);
 
2267
 
 
2268
          Dependent equations eliminated:  (1)
 
2269
          (%o6)                     (n + 1)! - 1
 
2270
          (%i7) GosperSum ((k + 1)*k! / (k + 1)!, k, 1, n);
 
2271
                            (n + 1) (n + 2) (n + 1)!
 
2272
          (%o7)             ------------------------ - 1
 
2273
                                    (n + 2)!
 
2274
          (%i8) GosperSum (1 / ((a - k)!*k!), k, 1, n);
 
2275
          (%o8)                  nonGosper_summable
 
2276
 
 
2277
 -- Function: parGosper (<F_{n,k}>, <k>, <n>, <d>)
 
2278
     Attempts to find a a <d>-th order recurrence for <F_{n,k}>.
 
2279
 
 
2280
     The algorithm yields a sequence [s_1, s_2, ..., s_m] of solutions.
 
2281
     Each solution has the form
 
2282
 
 
2283
     [R(n, k), [a_0, a_1, ..., a_d]]
 
2284
 
 
2285
     `parGosper' returns `[]' if it fails to find a recurrence.
 
2286
 
 
2287
 -- Function: Zeilberger (<F_{n,k}>, <k>, <n>)
 
2288
     Attempts to compute the indefinite hypergeometric summation of
 
2289
     <F_{n,k}>.
 
2290
 
 
2291
     `Zeilberger' first invokes `Gosper', and if that fails to find a
 
2292
     solution, then invokes `parGosper' with order 1, 2, 3, ..., up to
 
2293
     `MAX_ORD'.  If Zeilberger finds a solution before reaching
 
2294
     `MAX_ORD', it stops and returns the solution.
 
2295
 
 
2296
     The algorithms yields a sequence [s_1, s_2, ..., s_m] of solutions.
 
2297
     Each solution has the form
 
2298
 
 
2299
     [R(n,k), [a_0, a_1, ..., a_d]]
 
2300
 
 
2301
     `Zeilberger' returns `[]' if it fails to find a solution.
 
2302
 
 
2303
     `Zeilberger' invokes `Gosper' only if `gosper_in_zeilberger' is
 
2304
     `true'.
 
2305
 
 
2306
69.3 General global variables
 
2307
=============================
 
2308
 
 
2309
 -- Global variable: MAX_ORD
 
2310
     Default value: 5
 
2311
 
 
2312
     `MAX_ORD' is the maximum recurrence order attempted by
 
2313
     `Zeilberger'.
 
2314
 
 
2315
 -- Global variable: simplified_output
 
2316
     Default value: `false'
 
2317
 
 
2318
     When `simplified_output' is `true', functions in the `zeilberger'
 
2319
     package attempt further simplification of the solution.
 
2320
 
 
2321
 -- Global variable: linear_solver
 
2322
     Default value: `linsolve'
 
2323
 
 
2324
     `linear_solver' names the solver which is used to solve the system
 
2325
     of equations in Zeilberger's algorithm.
 
2326
 
 
2327
 -- Global variable: warnings
 
2328
     Default value: `true'
 
2329
 
 
2330
     When `warnings' is `true', functions in the `zeilberger' package
 
2331
     print warning messages during execution.
 
2332
 
 
2333
 -- Global variable: gosper_in_zeilberger
 
2334
     Default value: `true'
 
2335
 
 
2336
     When `gosper_in_zeilberger' is `true', the `Zeilberger' function
 
2337
     calls `Gosper' before calling `parGosper'.  Otherwise,
 
2338
     `Zeilberger' goes immediately to `parGosper'.
 
2339
 
 
2340
 -- Global variable: trivial_solutions
 
2341
     Default value: `true'
 
2342
 
 
2343
     When `trivial_solutions' is `true', `Zeilberger' returns solutions
 
2344
     which have certificate equal to zero, or all coefficients equal to
 
2345
     zero.
 
2346
 
 
2347
69.4 Variables related to the modular test
 
2348
==========================================
 
2349
 
 
2350
 -- Global variable: mod_test
 
2351
     Default value: `false'
 
2352
 
 
2353
     When `mod_test' is `true', `parGosper' executes a modular test for
 
2354
     discarding systems with no solutions.
 
2355
 
 
2356
 -- Global variable: modular_linear_solver
 
2357
     Default value: `linsolve'
 
2358
 
 
2359
     `modular_linear_solver' names the linear solver used by the
 
2360
     modular test in `parGosper'.
 
2361
 
 
2362
 -- Global variable: ev_point
 
2363
     Default value: `big_primes[10]'
 
2364
 
 
2365
     `ev_point' is the value at which the variable <n> is evaluated
 
2366
     when executing the modular test in `parGosper'.
 
2367
 
 
2368
 -- Global variable: mod_big_prime
 
2369
     Default value: `big_primes[1]'
 
2370
 
 
2371
     `mod_big_prime' is the modulus used by the modular test in
 
2372
     `parGosper'.
 
2373
 
 
2374
 -- Global variable: mod_threshold
 
2375
     Default value: 4
 
2376
 
 
2377
     `mod_threshold' is the greatest order for which the modular test
 
2378
     in `parGosper' is attempted.
 
2379
 
 
2380
 
 
2381
 
 
2382
Local Variables:
 
2383
coding: iso-8859-1
 
2384
End: