Archivi Categorie: maxima

Maxima – 90- Polinomi – funzioni e variabili – 4

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.276.

gcdex (f, g)
gcdex (f, g, x)
Returns a list [a, b, u] where u is the greatest common divisor (gcd) of f and g, and u is equal to a f + b g. The arguments f and g should be univariate polynomials, or else polynomials in x a supplied main variable since we need to be in a principal ideal domain for this to work. The gcd means the gcd regarding f and g as univariate polynomials with coefficients being rational functions in the other variables.

gcdex implements the Euclidean algorithm, where we have a sequence of L[i]: [a[i], b[i], r[i]] which are all perpendicular to [f, g, -1] and the next one is built as if q = quotient(r[i]/r[i+1]) then L[i+2]: L[i] - q L[i+1], and it terminates at L[i+1] when the remainder r[i+2] is zero.

The arguments f and g can be integers. For this case the function igcdex is called by gcdex.

See also ezgcd, gcd, gcdivide, and poly_gcd.

(%i1) gcdex (x^2 + 1, x^3 + 4);
                              2
                             x  + 4 x - 1  x + 4
(%o1)/R/                  [- ------------, -----, 1]
                                  17        17
(%i2) % . [x^2 + 1, x^3 + 4, -1];
(%o2)/R/                               0

Note that the gcd in the following is 1 since we work in k(y)[x], not the y+1 we would expect in k[y, x].

(%i3) gcdex (x*(y + 1), y^2 - 1, x);
                                      1
(%o3)/R/                        [0, ------, 1]
                                     2
                                    y  - 1

gcfactor (n)
Factors the Gaussian integer n over the Gaussian integers, i.e., numbers of the form a + b %i where a and b are rational integers (i.e., ordinary integers). Factors are normalized by making a and b non-negative.

gcfactor (expr)
Factors the polynomial expr over the Gaussian integers (that is, the integers with the imaginary unit %i adjoined). This is like factor(expr, a^2+1) where a is %i.

(%i4) gfactor (x^4 - 1);
(%o4)                  (x - 1) (x + 1) (x - %i) (x + %i)

gfactorsum (expr)
is similar to factorsum but applies gfactor instead of factor.

hipow (expr, x)
Returns the highest explicit exponent of x in expr. x may be a variable or a general expression. If x does not appear in expr, hipow returns 0.

hipow does not consider expressions equivalent to expr. In particular, hipow does not expand expr, so hipow(expr, x) and hipow(expand(expr, x)) may yield different results.

(%i5) hipow (y^3 * x^2 + x * y^4, x);
(%o5)                                  2
(%i6) hipow ((x + y)^5, x);
(%o6)                                  1
(%i7) hipow (expand ((x + y)^5), x);
(%o7)                                  5
(%i8) hipow (expand ((x + y)^5), x + y);
(%o8)                                  0

intfaclim
Default value: true.

If true, maxima will give up factorization of integers if no factor is found after trial divisions and Pollard’s rho method and factorization will not be complete.

When intfaclim is false (this is the case when the user calls factor explicitly), complete factorization will be attempted. intfaclim is set to false when factors are computed in divisors, divsum and totient.

Internal calls to factor respect the user-specified value of intfaclim. Setting intfaclim to true may reduce the time spent factoring large integers.

keepfloat
Default value: false.

When keepfloat is true, prevents floating point numbers from being rationalized when expressions which contain them are converted to canonical rational expression (CRE) form.

Note that the function solve and those functions calling it (eigenvalues, for example) currently ignore this flag, converting floating point numbers anyway.

(%i9) rat(x/2.0);

rat: replaced 0.5 by 1/2 = 0.5
                                       x
(%o9)/R/                               -
                                       2
(%i10) rat(x/2.0), keepfloat;
(%o10)/R/                            0.5 x

solve ignores keepfloat:

(%i11) solve(1.0-x,x), keepfloat;

rat: replaced 1.0 by 1/1 = 1.0
(%o11)                              [x = 1]

lopow (expr, x)
Returns the lowest exponent of x which explicitly appears in expr.

(%i12) lopow ((x+y)^2 + (x+y)^a, x+y);
(%o12)                             min(2, a)

lratsubst (L, expr)
is analogous to subst(L, expr) except that it uses ratsubst instead of subst.

The first argument of lratsubst is an equation or a list of equations identical in format to that accepted by subst. The substitutions are made in the order given by the list of equations, that is, from left to right.

load("lrats") loads fullratsubst and lratsubst.

(%i13) load ("lrats")$

subst can carry out multiple substitutions. lratsubst is analogous to subst.

(%i14) subst ([a = b, c = d], a + c);
(%o14)                               d + b
(%i15) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
(%o15)                      (d + a c) e + a d + b c

If only one substitution is desired, then a single equation may be given as first argument.

(%i16) lratsubst (a^2 = b, a^3);
(%o16)                                a b

modulus
Default value: false.

When modulus is a positive number p, operations on rational numbers (as returned by rat and related functions) are carried out modulo p, using the so-called “balanced” modulus system in which n modulo p is defined as an integer k in [-(p-1)/2, ..., 0, ..., (p-1)/2] when p is odd, or [-(p/2 - 1), ..., 0, ...., p/2] when p is even, such that a p + k equals n for some integer a.

If expr is already in canonical rational expression (CRE) form when modulus is reset, then you may need to re-rat expr, e.g., expr: rat (ratdisrep (expr)), in order to get correct results.

Typically modulus is set to a prime number. If modulus is set to a positive non-prime integer, this setting is accepted, but a warning message is displayed. Maxima signals an error, when zero or a negative integer is assigned to modulus.

(%i17) modulus:7;
(%o17)                                 7
(%i18) polymod([0,1,2,3,4,5,6,7]);
(%o18)                  [0, 1, 2, 3, - 3, - 2, - 1, 0]
(%i19) modulus:false;
(%o19)                               false
(%i20) poly:x^6+x^2+1;
                                   6    2
(%o20)                            x  + x  + 1
(%i21) factor(poly);
                                   6    2
(%o21)                            x  + x  + 1
(%i22) modulus:13;
(%o22)                                13
(%i23) factor(poly);
                             2        4      2
(%o23)                     (x  + 6) (x  - 6 x  - 2)
(%i24) polymod(%);
                                   6    2
(%o24)                            x  + x  + 1

Maxima – 89- Polinomi – funzioni e variabili – 3

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.272.

factorflag
Default value: false.

When factorflag is false, suppresses the factoring of integer factors of rational expressions.

factorout (expr, x_1, x_2, ...)
Rearranges the sum expr into a sum of terms of the form f(x_1, x_2, ...)*g where g is a product of expressions not containing any x_i and f is factored. Note that the option variable keepfloat is ignored by factorout.

(%i1) expand (a*(x+1)*(x-1)*(u+1)^2);
                    2  2          2      2      2
(%o1)            a u  x  + 2 a u x  + a x  - a u  - 2 a u - a
(%i2) factorout(%,x);
          2
(%o2)  a u  (x - 1) (x + 1) + 2 a u (x - 1) (x + 1) + a (x - 1) (x + 1)

factorsum (expr)
Tries to group terms in factors of expr which are sums into groups of terms such that their sum is factorable. factorsum can recover the result of expand((x + y)^2 + (z + w)^2) but it can’t recover expand((x + 1)^2 + (x + y)^2) because the terms have variables in common.

(%i3) expand ((x + 1)*((u + v)^2 + a*(w + z)^2));
           2      2                            2      2                2
(%o3) a x z  + a z  + 2 a w x z + 2 a w z + a w  x + v  x + 2 u v x + u  x
                                                            2    2            2
                                                       + a w  + v  + 2 u v + u
(%i4) factorsum (%);
                                          2          2
(%o4)                   (x + 1) (a (z + w)  + (v + u) )

fasttimes (p_1, p_2)
Returns the product of the polynomials p_1 and p_2 by using a special algorithm for multiplication of polynomials. p_1 and p_2 should be multivariate, dense, and nearly the same size. Classical multiplication is of order n_1 n_2 where n_1 is the degree of p_1 and n_2 is the degree of p_2. fasttimes is of order max(n_1, n_2)^1.585.

fullratsimp (expr)
fullratsimp repeatedly applies ratsimp followed by non-rational simplification to an expression until no further change occurs, and returns the result.

When non-rational expressions are involved, one call to ratsimp followed as is usual by non-rational (“general”) simplification may not be sufficient to return a simplified result. Sometimes, more than one such call may be necessary. fullratsimp makes this process convenient.

fullratsimp(expr, x_1, ..., x_n) takes one or more arguments similar to ratsimp and rat.

(%i5) expr: (x^(a/2) + 1)^2*(x^(a/2) - 1)^2/(x^a - 1);
                              a/2     2   a/2     2
                            (x    - 1)  (x    + 1)
(%o5)                       -----------------------
                                     a
                                    x  - 1
(%i6) ratsimp (expr);
                                 2 a      a
                                x    - 2 x  + 1
(%o6)                           ---------------
                                     a
                                    x  - 1
(%i7) fullratsimp (expr);
                                     a
(%o7)                               x  - 1
(%i8) rat (expr);
                              a/2 4       a/2 2
                            (x   )  - 2 (x   )  + 1
(%o8)/R/                    -----------------------
                                     a
                                    x  - 1

fullratsubst (a, b, c)
is the same as ratsubst except that it calls itself recursively on its result until that result stops changing. This function is useful when the replacement expression and the replaced expression have one or more variables in common.

fullratsubst will also accept its arguments in the format of lratsubst. That is, the first argument may be a single substitution equation or a list of such equations, while the second argument is the expression being processed.

load ("lrats") loads fullratsubst and lratsubst.

(%i9) load ("lrats")$

subst can carry out multiple substitutions. lratsubst is analogous to subst

(%i10) subst ([a = b, c = d], a + c);
(%o10)                               d + b
(%i11) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
(%o11)                      (d + a c) e + a d + b c

If only one substitution is desired, then a single equation may be given as first argument.

(%i12) lratsubst (a^2 = b, a^3);
(%o12)                                a b

fullratsubst is equivalent to ratsubst except that it recurses until its result stops changing.

(%i13) ratsubst (b*a, a^2, a^3);
                                      2
(%o13)                               a  b
(%i14) fullratsubst (b*a, a^2, a^3);
                                        2
(%o14)                               a b

fullratsubst also accepts a list of equations or a single equation as first argument.

(%i15) fullratsubst ([a^2 = b, b^2 = c, c^2 = a], a^3*b*c);
(%o15)                                 b
(%i16) fullratsubst (a^2 = b*a, a^3);
                                        2
(%o16)                               a b

fullratsubst may cause an indefinite recursion.

(%i17) errcatch (fullratsubst (b*a^2, a^2, a^3));
(%o17)                                []

gcd (p_1, p_2, x_1, ...)
Returns the greatest common divisor of p_1 and p_2. The flag gcd determines which algorithm is employed. Setting gcd to ez, subres, red, or spmod selects the ezgcd, subresultant prs, reduced, or modular algorithm, respectively. If gcd false then gcd(p_1, p_2, x) always returns 1 for all x. Many functions (e.g. ratsimp, factor, etc.) cause gcd’s to be taken implicitly. For homogeneous polynomials it is recommended that gcd equal to subres be used. To take the gcd when an algebraic is present, e.g., gcd(x^2 - 2*sqrt(2)* x + 2, x - sqrt(2)), the option variable algebraic must be true and gcd must not be ez.

The gcd flag, default: spmod, if false will also prevent the greatest common divisor from being taken when expressions are converted to canonical rational expression (CRE) form. This will sometimes speed the calculation if gcds are not required.

See also ezgcd, gcdex, gcdivide, and poly_gcd.

(%i18) p1: 6*x^3+19*x^2+19*x+6;
                               3       2
(%o18)                      6 x  + 19 x  + 19 x + 6
(%i19) p2: 6*x^5+13*x^4+12*x^3+13*x^2+6*x;
                         5       4       3       2
(%o19)                6 x  + 13 x  + 12 x  + 13 x  + 6 x
(%i20) gcd(p1, p2);
                                   2
(%o20)                          6 x  + 13 x + 6
(%i21) p1/gcd(p1, p2), ratsimp;
(%o21)                               x + 1
(%i22) p2/gcd(p1, p2), ratsimp;
                                     3
(%o22)                              x  + x

ezgcd returns a list whose first element is the greatest common divisor of the polynomials p_1 and p_2, and whose remaining elements are the polynomials divided by the greatest common divisor.

(%i23) ezgcd(p1, p2);
                           2                     3
(%o23)                 [6 x  + 13 x + 6, x + 1, x  + x]

Maxima – 88- Polinomi – funzioni e variabili – 2

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.268.

content (p_1, x_1, ..., x_n)
Returns a list whose first element is the greatest common divisor of the coefficients of the terms of the polynomial p_1 in the variable x_n (this is the content) and whose second element is the polynomial p_1 divided by the content.

(%i1) content (2*x*y + 4*x^2*y^2, y);
                                          2
(%o1)                          [2 x, 2 x y  + y]

denom (expr)
Returns the denominator of the rational expression expr. See also num.

(%i2) g1:(x+2)*(x+1)/((x+3)^2);
                                (x + 1) (x + 2)
(%o2)                           ---------------
                                          2
                                   (x + 3)
(%i3) denom(g1);
                                          2
(%o3)                              (x + 3)
(%i4) g2:sin(x)/10*cos(x)/y;
                                 cos(x) sin(x)
(%o4)                            -------------
                                     10 y
(%i5) denom(g2);
(%o5)                                10 y

divide (p_1, p_2, x_1, ..., x_n)
computes the quotient and remainder of the polynomial p_1 divided by the polynomial p_2, in a main polynomial variable, x_n. The other variables are as in the ratvars function. The result is a list whose first element is the quotient and whose second element is the remainder.

(%i6) divide (x + y, x - y, x);
(%o6)                              [1, 2 y]
(%i7) divide (x + y, x - y);
(%o7)                             [- 1, 2 x]

Note that y is the main variable in the second example.

eliminate ([eqn_1, ..., eqn_n], [x_1, ..., x_k])
Eliminates variables from equations (or expressions assumed equal to zero) by taking successive resultants. This returns a list of n - k expressions with the k variables x_1, ..., x_k eliminated. First x_1 is eliminated yielding n - 1 expressions, then x_2 is eliminated, etc. If k = n then a single expression in a list is returned free of the variables x_1, ..., x_k. In this case solve is called to solve the last resultant for the last variable.

(%i8) expr1: 2*x^2 + y*x + z;
                                             2
(%o8)                           z + x y + 2 x
(%i9) expr2: 3*x + 5*y - z - 1;
(%o9)                        (- z) + 5 y + 3 x - 1
(%i10) expr3: z^2 + x - y^2 + 5;
                                 2    2
(%o10)                          z  - y  + x + 5
(%i11) eliminate ([expr3, expr2, expr1], [y, z]);
              8         7         6          5          4         3         2
(%o11) [7425 x  - 1170 x  + 1299 x  + 12076 x  + 22887 x  - 5154 x  - 1291 x
                                                              + 7688 x + 15376]

ezgcd (p_1, p_2, p_3, ...)
Returns a list whose first element is the greatest common divisor of the polynomials p_1, p_2, p_3, ... and whose remaining elements are the polynomials divided by the greatest common divisor. This always uses the ezgcd algorithm.

See also gcd, gcdex, gcdivide, and poly_gcd.

(%i12) p1 : 6*x^3-17*x^2+14*x-3;
                               3       2
(%o12)                      6 x  - 17 x  + 14 x - 3
(%i13) p2 : 4*x^4-14*x^3+12*x^2+2*x-3;
                           4       3       2
(%o13)                  4 x  - 14 x  + 12 x  + 2 x - 3
(%i14) p3 : -8*x^3+14*x^2-x-3;
                                 3        2
(%o14)                     (- 8 x ) + 14 x  - x - 3
(%i15) gcd(p1, gcd(p2, p3));
(%o15)                              2 x - 3
(%i16) ezgcd(p1, p2, p3);
                      2               3      2            2
(%o16)   [2 x - 3, 3 x  - 4 x + 1, 2 x  - 4 x  + 1, (- 4 x ) + x + 1]

facexpand
Default value: true.

facexpand controls whether the irreducible factors returned by factor are in expanded (the default) or recursive (normal CRE) form.

factor (expr)
factor (expr, p)
Factors the expression expr, containing any number of variables or functions, into factors irreducible over the integers. factor(expr, p) factors expr over the field of rationals with an element adjoined whose minimum polynomial is p.

factor uses ifactors function for factoring integers.

factorflag if false suppresses the factoring of integer factors of rational expressions.

dontfactor may be set to a list of variables with respect to which factoring is not to occur. (It is initially empty). Factoring also will not take place with respect to any variables which are less important (using the variable ordering assumed for CRE form) than those on the dontfactor list.

savefactors if true causes the factors of an expression which is a product of factors to be saved by certain functions in order to speed up later factorizations of expressions containing some of the same factors.

berlefact if false then the Kronecker factoring algorithm will be used otherwise the Berlekamp algorithm, which is the default, will be used.

intfaclim if true Maxima will give up factorization of integers if no factor is found after trial divisions and Pollard’s rho method. If set to false (this is the case when the user calls factor explicitly), complete factorization of the integer will be attempted.

The user’s setting of intfaclim is used for internal calls to factor. Thus, intfaclim may be reset to prevent Maxima from taking an inordinately long time factoring large integers.

See also collectterms.

(%i17) factor (2^63 - 1);
                           2
(%o17)                    7  73 127 337 92737 649657
(%i18) factor (-8*y - 4*x + z^2*(2*y + x));
(%o18)                     (2 y + x) (z - 2) (z + 2)
(%i19) -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2;
                       2  2        2    2    2
(%o19)                x  y  + 2 x y  + y  - x  - 2 x - 1
(%i20) block ([dontfactor: [x]], factor (%/36/(1 + 2*y + y^2)));
                              2
                            (x  + 2 x + 1) (y - 1)
(%o20)                      ----------------------
                                  36 (y + 1)
(%i21) factor (1 + %e^(3*x));
                             x         2 x     x
(%o21)                    (%e  + 1) (%e    - %e  + 1)
(%i22) factor (1 + x^4, a^2 - 2);
                           2              2
(%o22)                   (x  - a x + 1) (x  + a x + 1)
(%i23) factor (-y^2*z^2 - x*z^2 + x^2*y^2 + x^3);
                              2
(%o23)                    - (y  + x) (z - x) (z + x)
(%i24) (2 + x)/(3 + x)/(b + x)/(c + x)^2;
                                    x + 2
(%o24)                     ------------------------
                                                  2
                           (x + 3) (x + b) (x + c)
(%i25) ratsimp (%);
                 4                  3     2                       2
(%o25) (x + 2)/(x  + (2 c + b + 3) x  + (c  + (2 b + 6) c + 3 b) x
                                                         2                   2
                                             + ((b + 3) c  + 6 b c) x + 3 b c )
(%i26) partfrac (%, x);
            2                   4                  3     2              2
(%o26) (- (c  - 4 c - b + 6)/((c  + ((- 2 b) - 6) c  + (b  + 12 b + 9) c
          2                 2                             c - 2
 + ((- 6 b ) - 18 b) c + 9 b ) (x + c))) - -----------------------------------
                                             2                               2
                                           (c  + ((- b) - 3) c + 3 b) (x + c)
                         b - 2
 + -------------------------------------------------
             2             2       3      2
   ((b - 3) c  + (6 b - 2 b ) c + b  - 3 b ) (x + b)
                         1
 - ----------------------------------------------
             2
   ((b - 3) c  + (18 - 6 b) c + 9 b - 27) (x + 3)
(%i27) map ('factor, %);
               2
              c  - 4 c - b + 6                  c - 2
(%o27) (- -------------------------) - ------------------------
                 2        2                                   2
          (c - 3)  (c - b)  (x + c)    (c - 3) (c - b) (x + c)
                                     b - 2                        1
                          + ------------------------ - ------------------------
                                           2                          2
                            (b - 3) (c - b)  (x + b)   (b - 3) (c - 3)  (x + 3)
(%i28) ratsimp ((x^5 - 1)/(x - 1));
                              4    3    2
(%o28)                       x  + x  + x  + x + 1
(%i29) subst (a, x, %);
                              4    3    2
(%o29)                       a  + a  + a  + a + 1
(%i30) factor (%th(2), %);
                              2        3        3    2
(%o30)          (x - a) (x - a ) (x - a ) (x + a  + a  + a + 1)
(%i31) factor (1 + x^12);
                              4        8    4
(%o31)                      (x  + 1) (x  - x  + 1)
(%i32) factor (1 + x^99);
                 2            6    3
(%o32) (x + 1) (x  - x + 1) (x  - x  + 1)
   10    9    8    7    6    5    4    3    2
 (x   - x  + x  - x  + x  - x  + x  - x  + x  - x + 1)
   20    19    17    16    14    13    11    10    9    7    6    4    3
 (x   + x   - x   - x   + x   + x   - x   - x   - x  + x  + x  - x  - x  + x
        60    57    51    48    42    39    33    30    27    21    18    12
 + 1) (x   + x   - x   - x   + x   + x   - x   - x   - x   + x   + x   - x
    9    3
 - x  + x  + 1)

Maxima – 87- Polinomi – funzioni e variabili – 1

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.265.

algebraic
Default value: false.

algebraic must be set to true in order for the simplification of algebraic integers to take effect.

berlefact
Default value: true.

When berlefact is false then the Kronecker factoring algorithm will be used otherwise the Berlekamp algorithm, which is the default, will be used.

bezout (p1, p2, x)
an alternative to the resultant command. It returns a matrix. determinant of this matrix is the desired resultant.

(%i1) bezout(a*x+b, c*x^2+d, x);
                                [ b c  - a d ]
(%o1)                           [            ]
                                [  a     b   ]
(%i2) determinant(%);
                                   2      2
(%o2)                             a  d + b  c
(%i3) resultant(a*x+b, c*x^2+d, x);
                                   2      2
(%o3)                             a  d + b  c

bothcoef (expr, x)
Returns a list whose first member is the coefficient of x in expr (as found by ratcoef if expr is in CRE form otherwise by coeff) and whose second member is the remaining part of expr. That is, [A, B] where expr = A*x + B.

(%i4) islinear (expr, x) := block ([c],
                           c: bothcoef (rat (expr, x), x),
                           is (freeof (x, c) and c[1] # 0))$

(%i5) islinear ((r^2 - (x - r)^2)/x, x);
(%o5)                                true

coeff (expr, x, n)
coeff (expr, x)
Returns the coefficient of x^n in expr, where expr is a polynomial or a monomial term in x. Other than ratcoef coeff is a strictly syntactical operation and will only find literal instances of x^n in the internal representation of expr.

coeff(expr, x^n) is equivalent to coeff(expr, x, n). coeff(expr, x, 0) returns the remainder of expr which is free of x. If omitted, n is assumed to be 1.

x may be a simple variable or a subscripted variable, or a subexpression of expr which comprises an operator and all of its arguments.

It may be possible to compute coefficients of expressions which are equivalent to expr by applying expand or factor. coeff itself does not apply expand or factor or any other function.

coeff distributes over lists, matrices, and equations.

See also ratcoef.

coeff returns the coefficient x^n in expr.

(%i6) coeff (b^3*a^3 + b^2*a^2 + b*a + 1, a^3);
                                       3
(%o6)                                 b

coeff(expr, x^n) is equivalent to coeff(expr, x, n).

(%i7) coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z, 3);
(%o7)                                - c
                                        3
(%i8) coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z^3);
(%o8)                                - c
                                        3

coeff(expr, x, 0) returns the remainder of expr which is free of x.

(%i9) coeff (a*u + b^2*u^2 + c^3*u^3, b, 0);
                                   3  3
(%o9)                             c  u  + a u

x may be a simple variable or a subscripted variable, or a subexpression of expr which comprises an operator and all of its arguments.

(%i10) coeff (h^4 - 2*%pi*h^2 + 1, h, 2);
(%o10)                              - 2 %pi
(%i11) coeff (v[1]^4 - 2*%pi*v[1]^2 + 1, v[1], 2);
(%o11)                              - 2 %pi
(%i12) coeff (sin(1+x)*sin(x) + sin(1+x)^3*sin(x)^3, sin(1+x)^3);
                                       3
(%o12)                              sin (x)
(%i13) coeff ((d - a)^2*(b + c)^3 + (a + b)^4*(c - d), a + b, 4);
(%o13)                               c - d

coeff itself does not apply expand or factor or any other function.

(%i14) coeff (c*(a + b)^3, a);
(%o14)                                 0
(%i15) expand (c*(a + b)^3);
                        3          2        2        3
(%o15)                 b  c + 3 a b  c + 3 a  b c + a  c
(%i16) coeff (%, a);
                                       2
(%o16)                              3 b  c
(%i17) coeff (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c, (a + b)^3);
(%o17)                                 0
(%i18) factor (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c);
                                         3
(%o18)                            (b + a)  c
(%i19) coeff (%, (a + b)^3);
(%o19)                                 c

coeff distributes over lists, matrices, and equations.

(%i20) coeff ([4*a, -3*a, 2*a], a);
(%o20)                            [4, - 3, 2]
(%i21) coeff (matrix ([a*x, b*x], [-c*x, -d*x]), x);
                                 [  a    b  ]
(%o21)                           [          ]
                                 [ - c  - d ]
(%i22) coeff (a*u - b*v = 7*u + 3*v, u);
(%o22)                               a = 7

Maxima – 86- Polinomi – introduzione

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.265.

Polynomials are stored in Maxima either in General Form or as Canonical Rational Expressions (CRE) form. The latter is a standard form, and is used internally by operations such as factor, ratsimp, and so on.

Canonical Rational Expressions constitute a kind of representation which is especially suitable for expanded polynomials and rational functions (as well as for partially factored polynomials and rational functions when RATFAC is set to true).

In this CRE form an ordering of variables (from most to least main) is assumed for each expression. Polynomials are represented recursively by a list consisting of the main variable followed by a series of pairs of expressions, one for each term of the polynomial. The first member of each pair is the exponent of the main variable in that term and the second member is the coefficient of that term which could be a number or a polynomial in another variable again represented in this form. Thus the principal part of the CRE form of 3*X^2-1 is (X 2 3 0 -1) and that of 2*X*Y+X-3 is (Y 1 (X 1 2) 0 (X 1 1 0 -3)) assuming Y is the main variable, and is (X 1 (Y 1 2 0 1) 0 -3) assuming X is the main variable.

“Main”-ness is usually determined by reverse alphabetical order. The “variables” of a CRE expression needn’t be atomic. In fact any subexpression whose main operator is not §§+ – * / or ^ with integer power will be considered a “variable” of the expression (in CRE form) in which it occurs. For example the CRE variables of the expression X+SIN(X+1)+2*SQRT(X)+1 are X, SQRT(X), and SIN(X+1). If the user does not specify an ordering of variables by using the RATVARS function Maxima will choose an alphabetic one. In general, CRE’s represent rational expressions, that is, ratios of polynomials, where the numerator and denominator have no common factors, and the denominator is positive.

The internal form is essentially a pair of polynomials (the numerator and denominator) preceded by the variable ordering list. If an expression to be displayed is in CRE form or if it contains any subexpressions in CRE form, the symbol /R/ will follow the line label. See the RAT function for converting an expression to CRE form. An extended CRE form is used for the representation of Taylor series. The notion of a rational expression is extended so that the exponents of the variables can be positive or negative rational numbers rather than just positive integers and the coefficients can themselves be rational expressions as described above rather than just polynomials. These are represented internally by a recursive polynomial form which is similar to and is a generalization of CRE form, but carries additional information such as the degree of truncation. As with CRE form, the symbol /T/ follows the line label of such expressions.

Maxima – 85- Files di input e output – funzioni e variabili per l’output del Fortran

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.262.

fortindent
Default value: 0.
fortindent controls the left margin indentation of expressions printed out by the fortran command. 0 gives normal printout (i.e., 6 spaces), and positive values will causes the expressions to be printed farther to the right.

fortran (expr)
Prints expr as a Fortran statement. The output line is indented with spaces. If the line is too long, fortran prints continuation lines. fortran prints the exponentiation operator ^ as **, and prints a complex number a + b %i in the form (a,b).

expr may be an equation. If so, fortran prints an assignment statement, assigning the right-hand side of the equation to the left-hand side. In particular, if the right-hand side of expr is the name of a matrix, then fortran prints an assignment statement for each element of the matrix.

If expr is not something recognized by fortran, the expression is printed in grind format without complaint. fortran does not know about lists, arrays, or functions.

fortindent controls the left margin of the printed lines. 0 is the normal margin (i.e., indented 6 spaces). Increasing fortindent causes expressions to be printed further to the right.

When fortspaces is true, fortran fills out each printed line with spaces to 80 columns.

fortran evaluates its arguments; quoting an argument defeats evaluation. fortran always returns done.

See also the function f90, for printing one or more expressions as a Fortran 90 program.

(%i1) expr: (a + b)^12$

(%i2) fortran (expr);
      (b+a)**12
(%o2)                                done
(%i3) fortran ('x=expand (expr));
      x = b**12+12*a*b**11+66*a**2*b**10+220*a**3*b**9+495*a**4*b**8+792
     1   *a**5*b**7+924*a**6*b**6+792*a**7*b**5+495*a**8*b**4+220*a**9*b
     2   **3+66*a**10*b**2+12*a**11*b+a**12
(%o3)                                done
(%i4) fortran ('x=7+5*%i);
      x = (7,5)
(%o4)                                done
(%i5) fortran ('x=[1,2,3,4]);
      x(1) = 1
      x(2) = 2
      x(3) = 3
      x(4) = 4
(%o5)                                done
(%i6) f(x) := x^2$

(%i7) fortran (f);
      f
(%o7)                                done

fortspaces
Default value: false.

When fortspaces is true, fortran fills out each printed line with spaces to 80 columns.

Averlo avuto 30+ anni orsono! Per esempio ho un integrale di quelli non banali mi faccio calcolare l’espressione pronta per copiarla e inserirla nel mio programma. Oggi nessuno conosce più il Fortran, tranne me (io) 😐

Maxima – 84 – Files di input e output – funzioni e variabili per l’output di TeX

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.257.

Nota urgente per me: devo verificare se TeX e LaTeX sono compatibili o quali sono le differenze. Confido nella compatibilità ma chissà… 🤔

Note that the built-in TeX output functionality of wxMaxima makes no use of the functions described here but uses its own implementation instead.

tex (expr)
tex (expr, destination)
tex (expr, false)
tex (label)
tex (label, destination)
tex (label, false)
Prints a representation of an expression suitable for the TeX document preparation system. The result is a fragment of a document, which can be copied into a larger document but not processed by itself.

tex(expr) prints a TeX representation of expr on the console.

tex(label) prints a TeX representation of the expression named by label and assigns it an equation label (to be displayed to the left of the expression). The TeX equation label is the same as the Maxima label.

destination may be an output stream or file name. When destination is a file name, tex appends its output to the file. The functions openw and opena create output streams.

tex(expr, false) and tex(label, false) return their TeX output as a string.

tex evaluates its first argument after testing it to see if it is a label. Quote-quote '' forces evaluation of the argument, thereby defeating the test and preventing the label. See also texput.

(%i1) integrate (1/(1+x^3), x);
                                          2 x - 1
                       2             atan(-------)
                  log(x  - x + 1)         sqrt(3)    log(x + 1)
(%o1)          (- ---------------) + ------------- + ----------
                         6              sqrt(3)          3
(%i2) tex (%o1);
$$-{{\log \left(x^2-x+1\right)}\over{6}}+{{\arctan \left({{2\,x-1
 }\over{\sqrt{3}}}\right)}\over{\sqrt{3}}}+{{\log \left(x+1\right)
 }\over{3}}\leqno{\tt (\%o1)}$$
(%o2)                               (\%o1)
(%i3) tex (integrate (sin(x), x));
$$-\cos x$$
(%o3)                                false
(%i4) tex (%o1, "foo.tex");
(%o4)                               (\%o1)

Sì, compatibile

tex(expr, false) returns its TeX output as a string.

(%i5) S : tex (x * y * z, false);
(%o5) $$x\,y\,z$$
(%i6) S;
(%o6) $$x\,y\,z$$

tex1 (e)
Returns a string which represents the TeX output for the expressions e. The TeX output is not enclosed in delimiters for an equation or any other environment.

(%i7) tex1 (sin(x) + cos(x));
(%o7)                            \sin x+\cos x

texput (a, s)
texput (a, f)
texput (a, s, operator_type)
texput (a, [s_1, s_2], matchfix)
texput (a, [s_1, s_2, s_3], matchfix)
Assign the TeX output for the atom a, which can be a symbol or the name of an operator.

texput(a, s) causes the tex function to interpolate the string s into the TeX output in place of a.

texput(a, f) causes the tex function to call the function f to generate TeX output. f must accept one argument, which is an expression which has operator a, and must return a string (the TeX output). f may call tex1 to generate TeX output for the arguments of the input expression.

texput(a, s, operator_type), where operator_type is prefix, infix, postfix, nary, or nofix, causes the tex function to interpolate s into the TeX output in place of a, and to place the interpolated text in the appropriate position.

texput(a, [s_1, s_2], matchfix) causes the tex function to interpolate s_1 and s_2 into the TeX output on either side of the arguments of a. The arguments (if more than one) are separated by commas.

texput(a, [s_1, s_2, s_3], matchfix) causes the tex function to interpolate s_1 and s_2 into the TeX output on either side of the arguments of a, with s_3 separating the arguments.

Assign TeX output for a variable.

(%i8) texput (me,"\\mu_e");
(%o8)                                \mu_e
(%i9) tex (me);
$$\mu_e$$
(%o9)                                false

Assign TeX output for an ordinary function (not an operator).

(%i10) texput (lcm, "\\mathrm{lcm}");
(%o10)                           \mathrm{lcm}
(%i11) tex (lcm (a, b));
$$\mathrm{lcm}\left(a , b\right)$$
(%o11)                               false

Call a function to generate TeX output.

(%i12) texfoo (e) := block ([a, b], [a, b] : args (e),
          concat("\\left[\\stackrel{",tex1(b),"}{",tex1(a),"}\\right]"))$

(%i13) texput (foo, texfoo);
(%o13)                              texfoo
(%i14) tex (foo (2^x, %pi));
$$\left[\stackrel{\pi}{2^{x}}\right]$$
(%o14)                               false

Assign TeX output for a prefix operator.

(%i15) prefix ("grad");
(%o15)                               grad
(%i16) texput ("grad", " \\nabla ", prefix);
(%o16)                              \nabla
(%i17) tex (grad f);
$$ \nabla f$$
(%o17)                               false

Assign TeX output for an infix operator.

(%i18) infix ("~");
(%o18)                                 ~
(%i19) texput ("~", " \\times ", infix);
(%o19)                              \times
(%i20) tex (a ~ b);
$$a \times b$$
(%o20)                               false

Assign TeX output for a postfix operator.

(%i21) postfix ("##");
(%o21)                                ##
(%i22) texput ("##", "!!", postfix);
(%o22)                                !!
(%i23) tex (x ##);
$$x!!$$
(%o23)                               false

Assign TeX output for a nary operator.

(%i24) nary ("@@");
(%o24)                                @@
(%i25) texput ("@@", " \\circ ", nary);
(%o25)                               \circ
(%i26) tex (a @@ b @@ c @@ d);
$$a \circ b \circ c \circ d$$
(%o26)                               false

Assign TeX output for a nofix operator.

(%i27) nofix ("foo");
(%o27)                                foo
(%i28) texput ("foo", "\\mathsc{foo}", nofix);
(%o28)                           \mathsc{foo}
(%i29) tex (foo);
$$\mathsc{foo}$$
(%o29)                               false

Assign TeX output for a matchfix operator.

(%i30) matchfix ("<<", ">>");
(%o30)                                <<
(%i31) texput ("<<", [" \\langle ", " \\rangle "], matchfix);
(%o31)                      [ \langle ,  \rangle ]
(%i32) tex (<>);
$$ \langle a \rangle $$
(%o32)                               false
(%i33) tex (<<a, b>>);
$$ \langle a , b \rangle $$
(%o33)                               false
(%i34) texput ("<<", [" \\langle ", " \\rangle ", " \\, | \\,"], matchfix);
(%o34)                 [ \langle ,  \rangle ,  \, | \,]
(%i35) tex (<>);
$$ \langle a \rangle $$
(%o35)                               false
(%i36) tex (<<a, b>>);
$$ \langle a \, | \,b \rangle $$
(%o36)                               false

get_tex_environment (op)
set_tex_environment (op, before, after)
Customize the TeX environment output by tex. As maintained by these functions, the TeX environment comprises two strings: one is printed before any other TeX output, and the other is printed after.

Only the TeX environment of the top-level operator in an expression is output; TeX environments associated with other operators are ignored.

get_tex_environment returns the TeX environment which is applied to the operator op; returns the default if no other environment has been assigned.

set_tex_environment assigns the TeX environment for the operator op.

(%i37) get_tex_environment (":=");
(%o37) [
\begin{verbatim}
, ;
\end{verbatim}
]
(%i38) tex (f (x) := 1 - x);

\begin{verbatim}
f(x):=1-x;
\end{verbatim}

(%o38)                               false
(%i39) set_tex_environment (":=", "$$", "$$");
(%o39)                             [$$, $$]
(%i40) tex (f (x) := 1 - x);
$$f(x):=1-x$$
(%o40)                               false

get_tex_environment_default ()
get_tex_environment_default (before, after)
Customize the TeX environment output by tex. As maintained by these functions, the TeX environment comprises two strings: one is printed before any other TeX output, and the other is printed after.

get_tex_environment_default returns the TeX environment which is applied to expressions for which the top-level operator has no specific TeX environment (as assigned by set_tex_environment).

set_tex_environment_default assigns the default TeX environment.

(%i41) get_tex_environment_default ();
(%o41)                             [$$, $$]
(%i42) tex (f(x) + g(x));
$$g\left(x\right)-x+1$$
(%o42)                               false
(%i43) set_tex_environment_default ("\\begin{equation}
", "
\\end{equation}");
(%o43) [\begin{equation}
,
\end{equation}]
(%i44) tex (f(x) + g(x));
\begin{equation}
g\left(x\right)-x+1
\end{equation}
(%o44)                               false

Maxima – 83 – Files di input e output – funzioni e variabili – 3

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.255.

save (filename, name_1, name_2, name_3, ...)
save (filename, values, functions, labels, ...)
save (filename, [m, n])
save (filename, name_1=expr_1, ...)
save (filename, all)
save (filename, name_1=expr_1, name_2=expr_2, ...)
Stores the current values of name_1, name_2, name_3, ..., in filename. The arguments are the names of variables, functions, or other objects. If a name has no value or function associated with it, it is ignored. save returns filename.

save stores data in the form of Lisp expressions. If filename ends in .lisp the data stored by save may be recovered by load(filename). See load.

The global flag file_output_append governs whether save appends or truncates the output file. When file_output_append is true, save appends to the output file. Otherwise, save truncates the output file. In either case, save creates the file if it does not yet exist.

The special form save(filename, values, functions, labels, ...) stores the items named by values, functions, labels, etc. The names may be any specified by the variable infolists. values comprises all user-defined variables.

The special form save(filename, [m, n]) stores the values of input and output labels m through n. Note that m and n must be literal integers. Input and output labels may also be stored one by one, e.g., save("foo.1", %i42, %o42). save(filename, labels) stores all input and output labels. When the stored labels are recovered, they clobber existing labels.

The special form save(filename, name_1=expr_1, name_2=expr_2, ...) stores the values of expr_1, expr_2, ..., with names name_1, name_2, …. It is useful to apply this form to input and output labels, e.g., save("foo.1", aa=%o88). The right-hand side of the equality in this form may be any expression, which is evaluated. This form does not introduce the new names into the current Maxima environment, but only stores them in filename.

These special forms and the general form of save may be mixed at will. For example, save(filename, aa, bb, cc=42, functions, [11, 17]).

The special form save(filename, all) stores the current state of Maxima. This includes all user-defined variables, functions, arrays, etc., as well as some automatically defined items. The saved items include system variables, such as file_search_maxima or showtime, if they have been assigned new values by the user; see myoptions.

save evaluates filename and quotes all other arguments.

stringout (filename, expr_1, expr_2, expr_3, ...)
stringout (filename, [m, n])
stringout (filename, input)
stringout (filename, functions)
stringout (filename, values)
stringout writes expressions to a file in the same form the expressions would be typed for input. The file can then be used as input for the batch or demo commands, and it may be edited for any purpose. stringout can be executed while writefile is in progress.

The global flag file_output_append governs whether stringout appends or truncates the output file. When file_output_append is true, stringout appends to the output file. Otherwise, stringout truncates the output file. In either case, stringout creates the file if it does not yet exist.

The general form of stringout writes the values of one or more expressions to the output file. Note that if an expression is a variable, only the value of the variable is written and not the name of the variable. As a useful special case, the expressions may be input labels (%i1, %i2, %i3, ...) or output labels (%o1, %o2, %o3, ...).

If grind is true, stringout formats the output using the grind format. Otherwise the string format is used. See grind and string.

The special form stringout(filename, [m, n]) writes the values of input labels m through n, inclusive.

The special form stringout(filename, input) writes all input labels to the file.

The special form stringout(filename, functions) writes all user-defined functions (named by the global list functions) to the file.

The special form stringout(filename, values) writes all user-assigned variables (named by the global list values) to the file. Each variable is printed as an assignment statement, with the name of the variable, a colon, and its value. Note that the general form of stringout does not print variables as assignment statements.

with_stdout (f, expr_1, expr_2, expr_3, ...)
with_stdout (s, expr_1, expr_2, expr_3, ...)
Evaluates expr_1, expr_2, expr_3, ... and writes any output thus generated to a file f or output stream s. The evaluated expressions are not written to the output. Output may be generated by print, display, grind, among other functions.

The global flag file_output_append governs whether with_stdout appends or truncates the output file f. When file_output_append is true, with_stdout appends to the output file. Otherwise, with_stdout truncates the output file. In either case, with_stdout creates the file if it does not yet exist.

with_stdout returns the value of its final argument.

See also writefile.

(%i1) with_stdout ("tmp.out", for i:5 thru 10 do
                   print (i, "! yields", i!))$

(%i2) printfile ("tmp.out")$
5 ! yields 120
6 ! yields 720
7 ! yields 5040
8 ! yields 40320
9 ! yields 362880
10 ! yields 3628800

writefile (filename)
Begins writing a transcript of the Maxima session to filename. All interaction between the user and Maxima is then recorded in this file, just as it appears on the console.

As the transcript is printed in the console output format, it cannot be reloaded into Maxima. To make a file containing expressions which can be reloaded, see save and stringout. save stores expressions in Lisp form, while stringout stores expressions in Maxima form.

The effect of executing writefile when filename already exists depends on the underlying Lisp implementation; the transcript file may be clobbered, or the file may be appended. appendfile always appends to the transcript file.

It may be convenient to execute playback after writefile to save the display of previous interactions. As playback displays only the input and output variables (%i1, %o1, etc.), any output generated by a print statement in a function (as opposed to a return value) is not displayed by playback.

closefile closes the transcript file opened by writefile or appendfile.

Maxima – 82 – Files di input e output – funzioni e variabili – 2

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.252.

file_search_maxima
file_search_lisp
file_search_demo
file_search_usage
file_search_tests
These variables specify lists of directories to be searched by load, demo, and some other Maxima functions. The default values of these variables name various directories in the Maxima installation.

The user can modify these variables, either to replace the default values or to append additional directories. For example,
file_search_maxima: ["/usr/local/foo/###.mac", "/usr/local/bar/###.mac"]$
replaces the default value of file_search_maxima, while
file_search_maxima: append (file_search_maxima, ["/usr/local/foo/###.mac", "/usr/local/bar/###.mac"])$ appends two additional directories. It may be convenient to put such an expression in the file maxima-init.mac so that the file search path is assigned automatically when Maxima starts. See also Introduction for Runtime Environment.

Multiple filename extensions and multiple paths can be specified by special “wildcard” constructions. The string ### expands into the sought-after name, while a comma separated list enclosed in curly braces {foo,bar,baz} expands into multiple strings.

For example, supposing the sought-after name is neumann, "/home/{wfs,gcj}/###.{lisp,mac}" expands into /home/wfs/neumann.lisp, /home/gcj/neumann.lisp, /home/wfs/neumann.mac, and /home/gcj/neumann.mac.

file_type (filename)
Returns a guess about the content of filename, based on the filename extension.

filename need not refer to an actual file; no attempt is made to open the file and inspect the content.

The return value is a symbol, either object, lisp, or maxima. If the extension is matches one of the values in file_type_maxima, file_type returns maxima. If the extension matches one of the values in file_type_lisp, file_type returns lisp. If none of the above, file_type returns object.

See also pathname_type. See file_type_maxima and file_type_lisp for the default values.

(%i1) map('file_type, ["test.lisp", "test.mac", "test.dem", "test.txt"]);
(%o1)                   [lisp, maxima, maxima, object]

file_type_lisp
Default value: [l, lsp, lisp].

file_type_lisp is a list of file extensions that maxima recognizes as denoting a Lisp source file. See also file_type.

file_type_maxima
Default value: [mac, mc, demo, dem, dm1, dm2, dm3, dmt, wxm].

file_type_maxima is a list of file extensions that maxima recognizes as denoting a Maxima source file. See also file_type.

load (filename)
Evaluates expressions in filename, thus bringing variables, functions, and other objects into Maxima. The binding of any existing object is clobbered by the binding recovered from filename. To find the file, load calls file_search with file_search_maxima and file_search_lisp as the search directories. If load succeeds, it returns the name of the file. Otherwise load prints an error message.

load works equally well for Lisp code and Maxima code. Files created by save, translate_file, and compile_file, which create Lisp code, and stringout, which creates Maxima code, can all be processed by load. load calls loadfile to load Lisp files and batchload to load Maxima files.

load does not recognize :lisp constructs in Maxima files, and while processing filename, the global variables _, __, %, and %th have whatever bindings they had when load was called.

It is also to note that structures will only be read back as structures if they have been defined by defstruct before the load command is called.

See also loadfile, batch, batchload, and demo. loadfile processes Lisp files; batch, batchload, and demo process Maxima files.

See file_search for more detail about the file search mechanism.

load evaluates its argument.

load_pathname
Default value: false.

When a file is loaded with the functions load, loadfile or batchload the system variable load_pathname is bound to the pathname of the file which is processed.

The variable load_pathname can be accessed from the file during the loading. Example: Suppose we have a batchfile test.mac in the directory "/home/dieter/workspace/mymaxima/temp/" with the following commands:
print("The value of load_pathname is: ", load_pathname)$
print("End of batchfile")$
then we get the following output:
(%i1) load("/home/dieter/workspace/mymaxima/temp/test.mac")$
The value of load_pathname is:
/home/dieter/workspace/mymaxima/temp/test.mac
End of batchfile

loadfile (filename)
Evaluates Lisp expressions in filename. loadfile does not invoke file_search, so filename must include the file extension and as much of the path as needed to find the file.

loadfile can process files created by save, translate_file, and compile_file.

The user may find it more convenient to use load instead of loadfile.

loadprint
Default value: true.

loadprint tells whether to print a message when a file is loaded.

  • When loadprint is true, always print a message.
  • When loadprint is 'loadfile, print a message only if a file is loaded by the function loadfile.
  • When loadprint is 'autoload, print a message only if a file is automatically loaded. See setup_autoload.
  • When loadprint is false, never print a message.

directory (path)
Returns a list of the files and directories found in path in the file system. path may contain wildcard characters (i.e., characters which represent unspecified parts of the path), which include at least the asterisk on most systems, and possibly other characters, depending on the system.

directory relies on the Lisp function DIRECTORY, which may have implementation-specific behavior.

pathname_directory (pathname)
pathname_name (pathname)
pathname_type (pathname)
These functions return the components of pathname.

(%i2) pathname_directory("/home/dieter/maxima/changelog.txt");
(%o2)                        /home/dieter/maxima/
(%i3) pathname_name("/home/dieter/maxima/changelog.txt");
(%o3)                              changelog
(%i4) pathname_type("/home/dieter/maxima/changelog.txt");
(%o4)                                 txt

printfile (path)
Prints the file named by path to the console. path may be a string or a symbol; if it is a symbol, it is converted to a string.

If path names a file which is accessible from the current working directory, that file is printed to the console. Otherwise, printfile attempts to locate the file by appending path to each of the elements of file_search_usage via filename_merge.

printfile returns path if it names an existing file, or otherwise the result of a successful filename merge.

Maxima – 81 – Files di input e output – funzioni e variabili – 1

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.250.

appendfile (filename)
Appends a console transcript to filename. appendfile is the same as writefile, except that the transcript file, if it exists, is always appended.

closefile closes the transcript file opened by appendfile or writefile.

(%i1) 6 * 7;
(%o1)                                 42
(%i2) appendfile("prova");

/* Starts dribbling to prova (2018/10/12, 07:40:09).*/
(%o2)                                done
(%i3) 8 * 9;
(%o3)                                 72
(%i4) closefile();

/*Finished dribbling to prova.*/
(%o4)                                done

ecco il file prova

/* Starts dribbling to prova (2018/10/12, 07:40:09).*/
(%o2)                                done
(%i3)
8 * 9;(%o3)                                 72
(%i4)
closefile();
/*Finished dribbling to prova.*/

batch (filename)
batch (filename, option)
batch(filename) reads Maxima expressions from filename and evaluates them. batch searches for filename in the list file_search_maxima. See also file_search.

batch(filename, demo) is like demo(filename). In this case batch searches for filename in the list file_search_demo. See demo.

batch(filename, test) is like run_testsuite with the option display_all=true. For this case batch searches filename in the list file_search_maxima and not in the list file_search_tests like run_testsuite. Furthermore, run_testsuite runs tests which are in the list testsuite_files. With batch it is possible to run any file in a test mode, which can be found in the list file_search_maxima. This is useful, when writing a test file.

filename comprises a sequence of Maxima expressions, each terminated with ; or $. The special variable % and the function %th refer to previous results within the file.

The file may include :lisp constructs. Spaces, tabs, and newlines in the file are ignored. A suitable input file may be created by a text editor or by the stringout function.

batch reads each input expression from filename, displays the input to the console, computes the corresponding output expression, and displays the output expression.

Input labels are assigned to the input expressions and output labels are assigned to the output expressions. batch evaluates every input expression in the file unless there is an error. If user input is requested (by asksign or askinteger, for example) batch pauses to collect the requisite input and then continue.

It may be possible to halt batch by typing control-C at the console. The effect of control-C depends on the underlying Lisp implementation.

batch has several uses, such as to provide a reservoir for working command lines, to give error-free demonstrations, or to help organize one’s thinking in solving complex problems.

batch evaluates its argument. batch returns the path of filename as a string, when called with no second argument or with the option demo. When called with the option test, the return value is a an empty list [] or a list with filename and the numbers of the tests which have failed.

See also load, batchload, and demo.

batchload (filename)
Reads Maxima expressions from filename and evaluates them, without displaying the input or output expressions and without assigning labels to output expressions. Printed output (such as produced by print or describe)) is displayed, however.

The special variable % and the function %th refer to previous results from the interactive interpreter, not results within the file. The file cannot include :lisp constructs.

batchload returns the path of filename, as a string. batchload evaluates its argument.

See also batch, and load.

closefile ()
Closes the transcript file opened by writefile or appendfile.

file_output_append
Default value: false.

file_output_append governs whether file output functions append or truncate their output file. When file_output_append is true, such functions append to their output file. Otherwise, the output file is truncated.

save, stringout, and with_stdout respect file_output_append. Other functions which write output files do not respect file_output_append. In particular, plotting and translation functions always truncate their output file, and tex and appendfile always append.

filename_merge (path, filename)
Constructs a modified path from path and filename. If the final component of path is of the form ###.something, the component is replaced with filename.something. Otherwise, the final component is simply replaced by filename.

The result is a Lisp pathname object.

file_search (filename)
file_search (filename, pathlist)
file_search searches for the file filename and returns the path to the file (as a string) if it can be found; otherwise file_search returns false. file_search (filename) searches in the default search directories, which are specified by the file_search_maxima, file_search_lisp, and file_search_demo variables.

file_search first checks if the actual name passed exists, before attempting to match it to “wildcard” file search patterns. See file_search_maxima concerning file search patterns.

The argument filename can be a path and file name, or just a file name, or, if a file search directory includes a file search pattern, just the base of the file name (without an extension). For example,
file_search ("/home/wfs/special/zeta.mac");
file_search ("zeta.mac");
file_search ("zeta");
all find the same file, assuming the file exists and /home/wfs/special/###.mac is in file_search_maxima.

file_search (filename, pathlist) searches only in the directories specified by pathlist, which is a list of strings. The argument pathlist supersedes the default search directories, so if the path list is given, file_search searches only the ones specified, and not any of the default search directories. Even if there is only one directory in pathlist, it must still be given as a one-element list.

The user may modify the default search directories. See file_search_maxima.

file_search is invoked by load with file_search_maxima and file_search_lisp as the search directories.