1
This is maxima.info, produced by makeinfo version 4.7 from maxima.texi.
3
Esse ļæ½ um Manual do Maxima no formato Texinfo
5
Copyright 1994,2001 William F. Schelter
8
* Maxima: (maxima). Um sistema de ļæ½lgebra computacional.
12
File: maxima.info, Node: Definitions for simplex, Prev: Introduction to simplex, Up: simplex
14
63.2 Definitions for simplex
15
============================
17
-- Option variable: epsilon_sx
18
Default value: `10^-8'
20
Epsilon used for numerical computations in `linear_program'.
22
See also: `linear_program'.
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.
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!".
36
To use this function first load the `simplex' package with
41
(%i2) A: matrix([1,1,-1,0], [2,-3,0,-1], [4,-5,0,0])$
44
(%i5) linear_program(A, b, c);
46
(%o5) [[--, 4, --, 0], - -]
49
See also: `minimize_sx', `scale_sx', and `epsilon_sx'.
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.
57
See also: `minimize_sx'.
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.
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!".
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).
79
`minimize_sx' uses the simplex algorithm which is implemented in
80
maxima `linear_program' function.
82
To use this function first load the `simplex' package with
87
(%i1) minimize_sx(x+y, [3*x+y=0, x+2*y>2]);
89
(%o1) [-, [y = -, x = - -]]
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!
98
See also: `maximize_sx', `nonegative_sx', `epsilon_sx'.
101
-- Option variable: nonegative_sx
102
Default value: `false'
104
If `nonegative_sx' is true all decision variables to `minimize_sx'
105
and `maximize_sx' are assumed to be positive.
107
See also: `minimize_sx'.
111
File: maxima.info, Node: simplification, Next: solve_rec, Prev: simplex, Up: Top
118
* Introduction to simplification::
119
* Definitions for simplification::
122
File: maxima.info, Node: Introduction to simplification, Next: Definitions for simplification, Prev: simplification, Up: simplification
124
64.1 Introduction to simplification
125
===================================
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.
132
File: maxima.info, Node: Definitions for simplification, Prev: Introduction to simplification, Up: simplification
134
64.2 Definitions for simplification
135
===================================
137
64.2.1 Package absimp
138
---------------------
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.
146
`absimp' defines `unitramp' and `unitstep' functions in terms of
149
`load (absimp)' loads this package. `demo (absimp)' shows a
150
demonstration of this package.
158
(%i3) diff (abs (x), x);
162
(%i4) cosh (abs (x));
165
64.2.2 Package facexp
166
---------------------
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.
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.
186
`load (facexp)' loads this package. `demo (facexp)' shows a
187
demonstration of this package.
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.
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.
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>)'.
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
224
In addition, the setting of the switches `facsum_combine'
225
and `nextlayerfactor' may affect the result of `facsum'.
227
-- Global variable: nextlayerfactor
228
Default value: `false'
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.
234
When `false', `facsum' is applied to each coefficient as a whole
235
whenever recusive calls to `facsum' occur.
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'.
244
-- Global variable: facsum_combine
245
Default value: `true'
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.
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.
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.
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.
279
64.2.3 Package functs
280
---------------------
282
-- Function: rempart (<expr>, <n>)
283
Removes part <n> from the expression <expr>.
285
If <n> is a list of the form `[<l>, <m>]' then parts <l> thru <m>
288
To use this function write first `load(functs)'.
290
-- Function: wronskian ([<f_1>, ..., <f_n>], <x>)
291
Returns the Wronskian matrix of the functions <f_1>, ..., <f_n> in
294
<f_1>, ..., <f_n> may be the names of user-defined functions, or
295
expressions in the variable <x>.
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.
301
To use this function write first `load(functs)'.
303
-- Function: tracematrix (<M>)
304
Returns the trace (sum of the diagonal elements) of matrix <M>.
306
To use this function write first `load(functs)'.
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.
314
To use this function write first `load(functs)'.
316
-- Function: logand (`x',`y')
317
Returns logical (bit-wise) "and" of arguments x and y.
319
To use this function write first `load(functs)'.
321
-- Function: logor (`x',`y')
322
Returns logical (bit-wise) "or" of arguments x and y.
324
To use this function write first `load(functs)'.
326
-- Function: logxor (`x',`y')
327
Returns logical (bit-wise) exclusive-or of arguments x and y.
329
To use this function write first `load(functs)'.
331
-- Function: nonzeroandfreeof (<x>, <expr>)
332
Returns `true' if <expr> is nonzero and `freeof (<x>, <expr>)'
333
returns `true'. Returns `false' otherwise.
335
To use this function write first `load(functs)'.
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>.
342
To use this function write first `load(functs)'.
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
349
When `takegcd' is `false', `gcdivide' returns the ratio `<p>/<q>'.
351
To use this function write first `load(functs)'.
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>'.
357
To use this function write first `load(functs)'.
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)'.
363
To use this function write first `load(functs)'.
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>)'.
369
To use this function write first `load(functs)'.
371
-- Function: arithsum (<a>, <d>, <n>)
372
Returns the sum of the arithmetic series from 1 to <n>.
374
To use this function write first `load(functs)'.
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.
381
To use this function write first `load(functs)'.
383
-- Function: gaussprob (<x>)
384
Returns the Gaussian probability function `%e^(-<x>^2/2) /
387
To use this function write first `load(functs)'.
389
-- Function: gd (<x>)
390
Returns the Gudermannian function `2 * atan(%e^<x> - %pi/2)'.
392
To use this function write first `load(functs)'.
394
-- Function: agd (<x>)
395
Returns the inverse Gudermannian function `log (tan (%pi/4 +
398
To use this function write first `load(functs)'.
400
-- Function: vers (<x>)
401
Returns the versed sine `1 - cos (x)'.
403
To use this function write first `load(functs)'.
405
-- Function: covers (<x>)
406
Returns the coversed sine `1 - sin (<x>)'.
408
To use this function write first `load(functs)'.
410
-- Function: exsec (<x>)
411
Returns the exsecant `sec (<x>) - 1'.
413
To use this function write first `load(functs)'.
415
-- Function: hav (<x>)
416
Returns the haversine `(1 - cos(x))/2'.
418
To use this function write first `load(functs)'.
420
-- Function: combination (<n>, <r>)
421
Returns the number of combinations of <n> objects taken <r> at a
424
To use this function write first `load(functs)'.
426
-- Function: permutation (<n>, <r>)
427
Returns the number of permutations of <r> objects selected from a
430
To use this function write first `load(functs)'.
435
The `ineq' package contains simplification rules for inequalities.
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 */
450
(%i3) (b>c)+%; /* add a second, strict inequality */
452
(%i4) 7*(x<y); /* multiply by a positive number */
454
(%i5) -2*(x>=3*z); /* multiply by a negative number */
456
(%i6) (1+a^2)*(1/(1+a^2)<=1); /* Maxima knows that 1+a^2 > 0 */
459
(%i7) assume(x>0)$ x*(2<3); /* assuming x>0 */
461
(%i8) a>=b; /* another inequality */
463
(%i9) 3+%; /* add something */
465
(%i10) %-3; /* subtract it out */
467
(%i11) a>=c-b; /* yet another inequality */
469
(%i12) b+%; /* add b to both sides */
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 */
477
(%o15) (z - 1) > - 2 z
478
(%i16) expand(%)+2*z; /* expand this and add 2*z to both sides */
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
489
Do `disprule (all)' to see a complete listing of the rule
492
The user will be queried if Maxima is unable to decide the sign of a
493
quantity multiplying an inequality.
495
The most common mis-feature is illustrated by:
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'.
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.
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
524
64.2.5 Package rducon
525
---------------------
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
535
declare ([<objects to be given the constant property>], constant)$
537
to set up a database of the constant quantities occurring in your
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
544
map ('fortran, const_eqns)$
546
Variables besides `const_eqns' which affect `reduce_consts' are:
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.
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'.
556
`load (rducon)' loads this function. `demo (rducon)' shows a
557
demonstration of this function.
559
64.2.6 Package scifac
560
---------------------
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:
568
1. Factors over the integers.
570
2. Factors out the largest powers of terms occurring as
571
coefficients, regardless of the complexity of the terms.
573
3. Uses (1) and (2) in factoring adjacent pairs of terms.
575
4. Repeatedly and recursively applies these techniques until the
576
expression no longer changes.
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.
583
`load (scifac)' loads this function. `demo (scifac)' shows a
584
demonstration of this function.
586
64.2.7 Package sqdnst
587
---------------------
589
-- Function: sqrtdenest (<expr>)
590
Denests `sqrt' of simple, numerical, binomial surds, where
594
(%i2) sqrt(sqrt(3)/2+1)/sqrt(11*sqrt(2)-12);
598
(%o2) ---------------------
599
sqrt(11 sqrt(2) - 12)
608
Sometimes it helps to apply `sqrtdenest' more than once, on such as
609
`(19601-13860 sqrt(2))^(7/4)'.
611
`load (sqdnst)' loads this function.
614
File: maxima.info, Node: solve_rec, Next: stirling, Prev: simplification, Up: Top
621
* Introduction to solve_rec::
622
* Definitions for solve_rec::
625
File: maxima.info, Node: Introduction to solve_rec, Next: Definitions for solve_rec, Prev: solve_rec, Up: solve_rec
627
65.1 Introduction to solve_rec
628
==============================
630
`solve_rec' is a package for solving linear recurrences with polynomial
633
A demo is available with `demo(solve_rec);'.
637
(%i1) load("solve_rec")$
638
(%i2) solve_rec((n+4)*s[n+2] + s[n+1] - (n+1)*s[n], s[n]);
640
%k (2 n + 3) (- 1) %k
642
(%o2) s = -------------------- + ---------------
643
n (n + 1) (n + 2) (n + 1) (n + 2)
646
File: maxima.info, Node: Definitions for solve_rec, Prev: Introduction to solve_rec, Up: solve_rec
648
65.2 Definitions for solve_rec
649
==============================
651
-- Function: closed_form (<expr>)
652
Tries to simplify all sums appearing in <expr> to a closed form.
654
`closed_form' uses Gosper and Zeilberger algorithms to simplify
657
To use this function first load the `closed_form' package with
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);
666
\ binomial(n + k, k) \
667
(%o2) > ------------------ + > binomial(2 n, 2 k)
671
(%i3) closed_form(%);
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
685
(%i3) rec: x[n+2] = x[n+1] + x[n]/n;
690
(%i4) solve_rec(rec, x[n]);
691
WARNING: found some hypergeometrical solutions!
694
(%i5) reduce_order(rec, n, x[n]);
706
(%o6) (- n - 2) %u - %u
708
(%i6) solve_rec((n+2)*%u[n+1] + %u[n], %u[n]);
712
(%o6) %u = ----------
715
So the general solution is
720
%k n > -------- + %k n
726
-- Option variable: simplify_products
727
Default value: `true'
729
If `simplify_products' is `true', `solve_rec' will try to simplify
732
See also: `solve_rec'.
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.
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.
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.
750
To use this function first load the `solve_rec' package with
753
Example of linear recurrence with constant coefficients:
755
(%i2) solve_rec(a[n]=a[n-1]+a[n-2]+n/2^n, a[n]);
757
(sqrt(5) - 1) %k (- 1)
759
(%o2) a = ------------------------- - ----
765
+ ------------------ - ----
769
Example of linear recurrence with polynomial coefficients:
771
(%i7) 2*x*(x+1)*y[x] - (x^2+3*x-2)*y[x+1] + (x-1)*y[x+2];
773
(%o7) (x - 1) y - (x + 3 x - 2) y + 2 x (x + 1) y
775
(%i8) solve_rec(%, y[x], y[1]=1, y[3]=3);
781
Example of Ricatti type recurrence:
783
(%i2) x*y[x+1]*y[x] - y[x+1]/(x+2) + y[x]/(x-1) = 0;
786
(%o2) x y y - ------ + ----- = 0
788
(%i3) solve_rec(%, y[x], y[3]=5)$
789
(%i4) ratsimp(minfactorial(factcomb(%)));
792
(%o4) y = - -------------------------------------------------
794
5 x - 3 x - 25 x + 15 x + 20 x - 12 x - 1584
796
See also: `solve_rec_rat', `simplify_products', and
800
-- Function: solve_rec_rat (<eqn>, <var>, [<init>])
801
Solves for rational solutions to linear recurrences. See solve_rec
802
for description of arguments.
804
To use this function first load the `solve_rec' package with
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
815
(%i2) solve_rec_rat(% = (x+2)/(x+1), a[x]);
817
(%o2) a = ---------------
820
See also: `solve_rec'.
823
-- Option variable: product_use_gamma
824
Default value: `true'
826
When simplifying products, `solve_rec' introduces gamma function
827
into the expression if `product_use_gamma' is `true'.
829
See also: `simplify_products', `solve_rec'.
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
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'.
847
To use this function first load the `closed_form' package with
852
(%i1) load("closed_form")$
853
(%i2) summand: binom(n,k);
855
(%i3) summand_to_rec(summand,k,n);
858
(%i7) summand: binom(n, k)/(k+1);
862
(%i8) summand_to_rec(summand, [k, 0, n], n);
863
(%o8) 2 (n + 1) sm - (n + 2) sm = - 1
868
File: maxima.info, Node: stirling, Next: stringproc, Prev: solve_rec, Up: Top
875
* Definiļæ½ļæ½es para stirling::
878
File: maxima.info, Node: Definiļæ½ļæ½es para stirling, Prev: stirling, Up: stirling
880
66.1 Definiļæ½ļæ½es para stirling
881
=============================
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.
887
Referļæ½ncia: Abramowitz & Stegun, " Handbook of mathematical
891
(%i1) load (stirling)$
893
(%i2) stirling(gamma(%alpha+x)/gamma(x),1);
894
1/2 - x x + %alpha - 1/2
897
--------------- - ---- - %alpha
900
(%i3) taylor(%,x,inf,1);
902
%alpha x %alpha - x %alpha
903
(%o3)/T/ x + -------------------------------- + . . .
905
(%i4) map('factor,%);
907
%alpha (%alpha - 1) %alpha x
908
(%o4) x + -------------------------------
911
A funļæ½ļæ½o `stirling' conhece a diferenļæ½a entre a variļæ½vel <gamma> e
912
a funļæ½ļæ½o `gamma':
914
(%i5) stirling(gamma + gamma(x),0);
916
(%o5) gamma + sqrt(2) sqrt(%pi) x %e
917
(%i6) stirling(gamma(y) + gamma(x),0);
919
(%o6) sqrt(2) sqrt(%pi) y %e
921
+ sqrt(2) sqrt(%pi) x %e
923
Para usar essa funļæ½ļæ½o escreva primeiro `load("stirling")'.
926
File: maxima.info, Node: stringproc, Next: unit, Prev: stirling, Up: Top
933
* Introduction to string processing::
934
* Definitions for input and output::
935
* Definitions for characters::
936
* Definitions for strings::
939
File: maxima.info, Node: Introduction to string processing, Next: Definitions for input and output, Prev: stringproc, Up: stringproc
941
67.1 Introduction to string processing
942
======================================
944
`stringproc.lisp' enlarges Maximas capabilities of working with strings.
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 .
949
Load `stringproc.lisp' by typing `load("stringproc");'.
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'.
957
(%i1) load("stringproc")$
960
(%i3) [stringp(m),lstringp(m)];
962
(%i4) l: sconcat("text");
964
(%i5) [stringp(l),lstringp(l)];
966
(%i6) stringp( sunlisp(l) );
969
All functions in `stringproc.lisp', that return strings, return
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
977
(%i1) load("stringproc")$
980
(%i3) [charp(c),lcharp(c)];
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.
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.
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.
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.
1013
extracti(file):= block(
1014
[ s1: openr(file), ifile: sconc(file,".in"), line, nl: false ],
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 ),
1023
line: strimr(" ",line),
1024
printf( s2,"~a~%",line ),
1027
close(s1), close(s2),
1030
checklast(line):= block(
1031
[ last: charat( line,slength(line) ) ],
1032
if cequal(last,";") or cequal(last,"$") then
1033
nl:false else nl:true )$
1035
File 'C:\home\maxima\test.out':
1037
(%i1) f(x):= sin(x)$
1041
(%o3) df(x) := cos(x)
1047
(%i11) extracti("C:\\home\\maxima\\test.out");
1048
(%o11) C:\home\maxima\test.out.in
1051
batching #pC:/home/maxima/test.out.in
1052
(%i13) f(x) := sin(x)
1053
(%i14) diff(f(x), x)
1055
(%i15) df(x) := cos(x)
1056
(%o15) df(x) := cos(x)
1061
File: maxima.info, Node: Definitions for input and output, Next: Definitions for characters, Prev: Introduction to string processing, Up: stringproc
1063
67.2 Definitions for input and output
1064
=====================================
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 )$
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)$
1079
and a list: one two three
1083
-- Function: close (<stream>)
1084
Closes <stream> and returns `true' if <stream> had been open.
1087
-- Function: flength (<stream>)
1088
Returns the number of elements in <stream>.
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>
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'.
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
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.
1118
-- Function: openr (<file>)
1119
Returns an input stream to <file>. If <file> does not exist, it
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>.
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.")
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.
1153
~x hexadecimal integer
1158
~e scientific notation
1159
~g ~f or ~e, depending upon magnitude
1160
~a as printed by Maxima function print
1163
~< justification, ~> terminates
1164
~( case conversion, ~) terminates
1165
~[ selection, ~] terminates
1166
~{ iteration, ~} terminates
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"] );
1173
(%i3) printf( true,"~{~{~9,1f ~}~%~}",mat ),
1174
mat = args( matrix([1.1,2,3.33],[4,5,6],[7,8.88,9]) )$
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.
1182
If <dest> is a stream or `true', then `printf' returns `false'.
1183
Otherwise, `printf' returns a string containing the output.
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.
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
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
1201
In xmaxima you might wish to add `,newline()', if you prefer line
1202
breaking prior to printing. See `ascii' for an example.
1206
File: maxima.info, Node: Definitions for characters, Next: Definitions for strings, Prev: Definitions for input and output, Up: stringproc
1208
67.3 Definitions for characters
1209
===============================
1211
-- Function: alphacharp (<char>)
1212
Returns `true' if <char> is an alphabetic character.
1215
-- Function: alphanumericp (<char>)
1216
Returns `true' if <char> is an alphabetic character or a digit.
1219
-- Function: ascii (<int>)
1220
Returns the character corresponding to the ASCII number <int>. (
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
1229
-- Function: cequal (<char_1>, <char_2>)
1230
Returns `true' if <char_1> and <char_2> are the same.
1233
-- Function: cequalignore (<char_1>, <char_2>)
1234
Like `cequal' but ignores case.
1237
-- Function: cgreaterp (<char_1>, <char_2>)
1238
Returns `true' if the ASCII number of <char_1> is greater than the
1242
-- Function: cgreaterpignore (<char_1>, <char_2>)
1243
Like `cgreaterp' but ignores case.
1246
-- Function: charp (<obj>)
1247
Returns `true' if <obj> is a Maxima-character. See introduction
1251
-- Function: cint (<char>)
1252
Returns the ASCII number of <char>.
1255
-- Function: clessp (<char_1>, <char_2>)
1256
Returns `true' if the ASCII number of <char_1> is less than the
1260
-- Function: clesspignore (<char_1>, <char_2>)
1261
Like `clessp' but ignores case.
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.)
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 { | } ~
1277
-- Function: cunlisp (<lisp_char>)
1278
Converts a Lisp-character into a Maxima-character. (You wont need
1282
-- Function: digitcharp (<char>)
1283
Returns `true' if <char> is a digit.
1286
-- Function: lcharp (<obj>)
1287
Returns `true' if <obj> is a Lisp-character. (You wont need it.)
1290
-- Function: lowercasep (<char>)
1291
Returns `true' if <char> is a lowercase character.
1294
-- Variable: newline
1295
The character newline.
1299
The character space.
1306
-- Function: uppercasep (<char>)
1307
Returns `true' if <char> is an uppercase character.
1311
File: maxima.info, Node: Definitions for strings, Prev: Definitions for characters, Up: stringproc
1313
67.4 Definitions for strings
1314
============================
1316
-- Function: sunlisp (<lisp_string>)
1317
Converts a Lisp-string into a Maxima-string. (In general you wont
1321
-- Function: lstringp (<obj>)
1322
Returns `true' if <obj> is a Lisp-string. (In general you wont
1326
-- Function: stringp (<obj>)
1327
Returns `true' if <obj> is a Maxima-string. See introduction for
1331
-- Function: charat (<string>, <n>)
1332
Returns the <n>-th character of <string>. The first character in
1333
<string> is returned with <n> = 1.
1335
(%i1) load("stringproc")$
1336
(%i2) charat("Lisp",1);
1340
-- Function: charlist (<string>)
1341
Returns the list of all characters in <string>.
1343
(%i1) load("stringproc")$
1344
(%i2) charlist("Lisp");
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}'.
1356
(%i1) load("stringproc")$
1357
(%i2) 2*parsetoken("1.234 5.678");
1360
For parsing you can also use function parse_string. See
1361
description in file 'share\contrib\eval_string.lisp'.
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.
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
1375
-- Function: scopy (<string>)
1376
Returns a copy of <string> as a new string.
1379
-- Function: sdowncase (<string>)
1380
-- Function: sdowncase (<string>, <start>)
1381
-- Function: sdowncase (<string>, <start>, <end>)
1382
Like `supcase', but uppercase characters are converted to
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.
1391
-- Function: sequalignore (<string_1>, <string_2>)
1392
Like `sequal' but ignores case.
1395
-- Function: sexplode (<string>)
1396
`sexplode' is an alias for function `charlist'.
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.
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.
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.
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.
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.
1434
(%i1) load("stringproc")$
1435
(%i2) sinvertcase("sInvertCase");
1439
-- Function: slength (<string>)
1440
Returns the number of characters in <string>.
1443
-- Function: smake (<num>, <char>)
1444
Returns a new string with a number of <num> characters <char>.
1446
(%i1) load("stringproc")$
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.
1458
(%i1) load("stringproc")$
1459
(%i2) smismatch("seven","seventh");
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
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]
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'.
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.
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.
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
1512
-- Function: sreverse (<string>)
1513
Returns a string with all the characters of <string> in reverse
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.
1527
(%i1) ssearch("~s","~{~S ~}~%",'sequalignore);
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}'.
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.'
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.
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.
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>,
1570
Like `subst' except that only the first substring that matches
1574
-- Function: strim (<seq>,<string>)
1575
Returns a string like <string>, but with all characters that
1576
appear in <seq> removed from both ends.
1578
(%i1) load("stringproc")$
1579
(%i2) "/* comment */"$
1580
(%i3) strim(" /*",%);
1586
-- Function: striml (<seq>, <string>)
1587
Like `strim' except that only the left end of <string> is trimmed.
1590
-- Function: strimr (<seq>, <string>)
1591
Like `strim' except that only the right end of string is trimmed.
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
1602
(%i1) load("stringproc")$
1603
(%i2) substring("substring",4);
1605
(%i3) substring(%,4,6);
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.
1617
(%i1) load("stringproc")$
1618
(%i2) supcase("english",1,2);
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.)
1632
(%i1) load("stringproc")$
1633
(%i2) tokens("24 October 2005");
1634
(%o2) [24, October, 2005]
1635
(%i3) tokens("05-10-24",'digitcharp);
1637
(%i4) map(parsetoken,%);
1642
File: maxima.info, Node: unit, Next: zeilberger, Prev: stringproc, Up: Top
1649
* Introduction to Units::
1650
* Definitions for Units::
1653
File: maxima.info, Node: Introduction to Units, Next: Definitions for Units, Prev: unit, Up: unit
1655
68.1 Introduction to Units
1656
==========================
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.
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
1684
_unit_ is included in Maxima in the share/contrib/unit directory. It
1685
obeys normal Maxima package loading conventions:
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
*******************************************************************
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...
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
1711
The _unit.mac_ file also loads a lisp file _unit-functions.lisp_
1712
which contains the lisp functions needed for the package.
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
1719
There are probably lots of bugs. Let me know. `float' and `numer'
1720
don't do what is expected.
1722
TODO : dimension functionality, handling of temperature, showabbr
1723
and friends. Show examples with addition of quantities containing
1727
File: maxima.info, Node: Definitions for Units, Prev: Introduction to Units, Up: unit
1729
68.2 Definitions for Units
1730
==========================
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.
1743
(%o3) (------) (----)
1750
(%i5) centigram*inch/minutes^2;
1752
(%o5) (-------------) (----)
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]);
1761
1800000000000 %in cg
1762
(%o7) (-------------) (------)
1767
(%o8) (--------) (------)
1772
(%i10) centigram*inch/minutes^2;
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]);
1783
(%i12) centigram*inch/minutes^2;
1785
(%o12) (-------------) (----)
1789
Derived units are also handled by this command:
1800
(%i21) centigram*inch/minutes^2;
1802
(%o21) (-------------) (N)
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
1810
(%i22) setunits(dyn);
1813
(%o23) (100000) (dyn)
1814
(%i24) centigram*inch/minutes^2;
1816
(%o24) (--------) (dyn)
1819
To discontinue simplifying to any force, we use the uforget
1821
(%i26) uforget(dyn);
1828
(%i28) centigram*inch/minutes^2;
1830
(%o28) (-------------) (----)
1833
This would have worked equally well with `uforget(N)' or
1836
See also `uforget'. To use this function write first
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]);
1847
(%i14) centigram*inch/minutes^2;
1852
(%i15) uforget([cg,%in,%min]);
1853
(%o15) [false, false, false]
1854
(%i16) centigram*inch/minutes^2;
1856
(%o16) (-------------) (----)
1860
`uforget' operates on dimensions, not units, so any unit of a
1861
particular dimension will work. The dimension itself is also a
1864
See also `setunits'. To use this function write first
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.
1886
(%i3) convert(kg*m/s^2,[g,km,s]);
1891
(%i4) convert(kg*m/s^2,[g,inch,minute]);
1893
`rat' replaced 39.37007874015748 by 5000//127 = 39.37007874015748
1895
(%o4) (-----------) (-----)
1898
(%i5) convert(kg*m/s^2,[N]);
1900
(%i6) convert(kg*m^2/s^2,[N]);
1902
(%i7) setunits([N,J]);
1904
(%i8) convert(kg*m^2/s^2,[N]);
1906
(%i9) convert(kg*m^2/s^2,[N,inch]);
1908
`rat' replaced 39.37007874015748 by 5000//127 = 39.37007874015748
1910
(%o9) (----) (%in N)
1912
(%i10) convert(kg*m^2/s^2,[J]);
1916
(%i12) setunits([g,inch,s]);
1924
(%o15) (-------) (-----)
1927
(%i16) convert(kg*m/s^2,[g,inch,s]);
1929
`rat' replaced 39.37007874015748 by 5000//127 = 39.37007874015748
1931
(%o16) (-------) (-----)
1935
See also `setunits' and `uforget'. To use this function write
1936
first `load("unit")'.
1938
-- Optional variable: usersetunits
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:
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
*******************************************************************
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...
1967
User defaults found...
1968
User defaults initialized.
1977
(%i6) setunits([dyn,eV]);
1980
(%o7) (100000) (dyn)
1982
(%o8) (6241509596477042688) (eV)
1984
(%o9) (6241509596477042688) (eV m)
1986
(%o10) (6241509596477042688000) (eV)
1987
(%i11) uforget([dyn,eV]);
1988
(%o11) [false, false]
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.
2012
(%i4) setunits([dyn,eV]);
2015
(%o5) (100000) (dyn)
2017
(%o6) (6241509596477042688) (eV)
2018
(%i7) uforget([dyn,eV]);
2019
(%o7) [false, false]
2024
(%i10) dontusedimension(N);
2026
(%i11) dontusedimension(J);
2027
(%o11) [%energy, %force]
2039
(%i14) setunits([dyn,eV]);
2052
(%i17) uforget([dyn,eV]);
2053
(%o17) [false, false]
2065
(%i20) usedimension(N);
2066
Done. To have Maxima simplify to this dimension, use setunits([unit])
2069
(%i21) usedimension(J);
2070
Done. To have Maxima simplify to this dimension, use setunits([unit])
2084
(%i24) setunits([dyn,eV]);
2087
(%o25) (100000) (dyn)
2089
(%o26) (6241509596477042688) (eV)
2090
(%i27) uforget([dyn,eV]);
2091
(%o27) [false, false]
2096
(%i30) kill(usersetunits);
2098
(%i31) uforget([dyn,eV]);
2099
(%o31) [false, false]
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.
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,
2126
3 - peta, tera, giga, mega, kilo, hecto, deka, deci,
2127
centi, milli, micro, nano, pico, femto
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>.
2134
-- Variable: %unitexpand
2137
This is the value supplied to `metricexpandall' during the initial
2142
File: maxima.info, Node: zeilberger, Next: ļæ½ndice de Funļæ½ļæ½es e Variļæ½veis, Prev: unit, Up: Top
2149
* Introduction to zeilberger::
2150
* Definitions for zeilberger::
2153
File: maxima.info, Node: Introduction to zeilberger, Next: Definitions for zeilberger, Prev: zeilberger, Up: zeilberger
2155
69.1 Introduction to zeilberger
2156
===============================
2158
`zeilberger' is a implementation of Zeilberger's algorithm for definite
2159
hypergeometric summation, and also Gosper's algorithm for indefinite
2160
hypergeometric summation.
2162
`zeilberger' makes use of the "filtering" optimization method
2163
developed by Axel Riese.
2165
`zeilberger' was developed by Fabrizio Caruso.
2167
`load (zeilberger)' loads this package.
2169
69.1.0.1 The indefinite summation problem
2170
.........................................
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.
2177
69.1.0.2 The definite summation problem
2178
.......................................
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
2186
a_0 F_(n,k) + ... + a_d F_(n+d),k = Delta_K(R(n,k) F_(n,k))
2188
where Delta_k is the k-forward difference operator, i.e.,
2189
Delta_k(t_k) := t_(k+1) - t_k.
2191
69.1.1 Verbosity levels
2192
-----------------------
2194
There are also verbose versions of the commands which are called by
2195
adding one of the following prefixes:
2198
Just a summary at the end is shown
2201
Some information in the intermidiate steps
2207
Even more information including information on the linear system
2208
in Zeilberger's algorithm
2210
For example: `GosperVerbose', `parGosperVeryVerbose',
2211
`ZeilbergerExtra', `AntiDifferenceSummary'.
2214
File: maxima.info, Node: Definitions for zeilberger, Prev: Introduction to zeilberger, Up: zeilberger
2216
69.2 Definitions for zeilberger
2217
===============================
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'.
2223
-- Function: Gosper (<F_k>, <k>)
2224
Returns the rational certificate <R(k)> for <F_k>, that is, a
2225
rational function such that
2227
F_k = R(k+1) F_(k+1) - R(k) F_k
2229
if it exists. Otherwise, `Gosper' returns `no_hyp_sol'.
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'.
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);
2242
Dependent equations eliminated: (1)
2246
(%o2) - ------------------ - -
2249
(%i3) GosperSum (1 / (4*k^2 - 1), k, 1, n);
2253
(%o3) -------------- + -
2256
(%i4) GosperSum (x^k, k, 1, n);
2259
(%o4) ------ - -----
2261
(%i5) GosperSum ((-1)^k*a! / (k!*(a - k)!), k, 1, n);
2264
(%o5) - ------------------------- - ----------
2265
a (- n + a - 1)! (n + 1)! a (a - 1)!
2266
(%i6) GosperSum (k*k!, k, 1, n);
2268
Dependent equations eliminated: (1)
2270
(%i7) GosperSum ((k + 1)*k! / (k + 1)!, k, 1, n);
2271
(n + 1) (n + 2) (n + 1)!
2272
(%o7) ------------------------ - 1
2274
(%i8) GosperSum (1 / ((a - k)!*k!), k, 1, n);
2275
(%o8) nonGosper_summable
2277
-- Function: parGosper (<F_{n,k}>, <k>, <n>, <d>)
2278
Attempts to find a a <d>-th order recurrence for <F_{n,k}>.
2280
The algorithm yields a sequence [s_1, s_2, ..., s_m] of solutions.
2281
Each solution has the form
2283
[R(n, k), [a_0, a_1, ..., a_d]]
2285
`parGosper' returns `[]' if it fails to find a recurrence.
2287
-- Function: Zeilberger (<F_{n,k}>, <k>, <n>)
2288
Attempts to compute the indefinite hypergeometric summation of
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.
2296
The algorithms yields a sequence [s_1, s_2, ..., s_m] of solutions.
2297
Each solution has the form
2299
[R(n,k), [a_0, a_1, ..., a_d]]
2301
`Zeilberger' returns `[]' if it fails to find a solution.
2303
`Zeilberger' invokes `Gosper' only if `gosper_in_zeilberger' is
2306
69.3 General global variables
2307
=============================
2309
-- Global variable: MAX_ORD
2312
`MAX_ORD' is the maximum recurrence order attempted by
2315
-- Global variable: simplified_output
2316
Default value: `false'
2318
When `simplified_output' is `true', functions in the `zeilberger'
2319
package attempt further simplification of the solution.
2321
-- Global variable: linear_solver
2322
Default value: `linsolve'
2324
`linear_solver' names the solver which is used to solve the system
2325
of equations in Zeilberger's algorithm.
2327
-- Global variable: warnings
2328
Default value: `true'
2330
When `warnings' is `true', functions in the `zeilberger' package
2331
print warning messages during execution.
2333
-- Global variable: gosper_in_zeilberger
2334
Default value: `true'
2336
When `gosper_in_zeilberger' is `true', the `Zeilberger' function
2337
calls `Gosper' before calling `parGosper'. Otherwise,
2338
`Zeilberger' goes immediately to `parGosper'.
2340
-- Global variable: trivial_solutions
2341
Default value: `true'
2343
When `trivial_solutions' is `true', `Zeilberger' returns solutions
2344
which have certificate equal to zero, or all coefficients equal to
2347
69.4 Variables related to the modular test
2348
==========================================
2350
-- Global variable: mod_test
2351
Default value: `false'
2353
When `mod_test' is `true', `parGosper' executes a modular test for
2354
discarding systems with no solutions.
2356
-- Global variable: modular_linear_solver
2357
Default value: `linsolve'
2359
`modular_linear_solver' names the linear solver used by the
2360
modular test in `parGosper'.
2362
-- Global variable: ev_point
2363
Default value: `big_primes[10]'
2365
`ev_point' is the value at which the variable <n> is evaluated
2366
when executing the modular test in `parGosper'.
2368
-- Global variable: mod_big_prime
2369
Default value: `big_primes[1]'
2371
`mod_big_prime' is the modulus used by the modular test in
2374
-- Global variable: mod_threshold
2377
`mod_threshold' is the greatest order for which the modular test
2378
in `parGosper' is attempted.