Next: , Previous:   [Contents][Index]

14 Polynomials


14.1 Introduction to Polynomials

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.

Categories: Polynomials · Rational expressions ·

14.2 Functions and Variables for Polynomials

Option variable: algebraic

Default value: false

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

Option variable: 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.

Categories: Polynomials ·
Function: bezout (p1, p2, x)

an alternative to the resultant command. It returns a matrix. determinant of this matrix is the desired resultant.

Examples:

(%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
Categories: Polynomials ·
Function: 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.

Example:

(%i1) islinear (expr, x) := block ([c],
        c: bothcoef (rat (expr, x), x),
        is (freeof (x, c) and c[1] # 0))$
(%i2) islinear ((r^2 - (x - r)^2)/x, x);
(%o2)                         true
Categories: Polynomials ·
Function: coeff
    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.

Examples:

coeff returns the coefficient x^n in expr.

(%i1) coeff (b^3*a^3 + b^2*a^2 + b*a + 1, a^3);
                                3
(%o1)                          b

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

(%i1) coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z, 3);
(%o1)                         - c
                                 3
(%i2) coeff (c[4]*z^4 - c[3]*z^3 - c[2]*z^2 + c[1]*z, z^3);
(%o2)                         - c
                                 3

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

(%i1) coeff (a*u + b^2*u^2 + c^3*u^3, b, 0);
                            3  3
(%o1)                      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.

(%i1) coeff (h^4 - 2*%pi*h^2 + 1, h, 2);
(%o1)                        - 2 %pi
(%i2) coeff (v[1]^4 - 2*%pi*v[1]^2 + 1, v[1], 2);
(%o2)                        - 2 %pi
(%i3) coeff (sin(1+x)*sin(x) + sin(1+x)^3*sin(x)^3, sin(1+x)^3);
                                3
(%o3)                        sin (x)
(%i4) coeff ((d - a)^2*(b + c)^3 + (a + b)^4*(c - d), a + b, 4);
(%o4)                         c - d

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

(%i1) coeff (c*(a + b)^3, a);
(%o1)                           0
(%i2) expand (c*(a + b)^3);
                 3          2        2        3
(%o2)           b  c + 3 a b  c + 3 a  b c + a  c
(%i3) coeff (%, a);
                                2
(%o3)                        3 b  c
(%i4) coeff (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c, (a + b)^3);
(%o4)                           0
(%i5) factor (b^3*c + 3*a*b^2*c + 3*a^2*b*c + a^3*c);
                                  3
(%o5)                      (b + a)  c
(%i6) coeff (%, (a + b)^3);
(%o6)                           c

coeff distributes over lists, matrices, and equations.

(%i1) coeff ([4*a, -3*a, 2*a], a);
(%o1)                      [4, - 3, 2]
(%i2) coeff (matrix ([a*x, b*x], [-c*x, -d*x]), x);
                          [  a    b  ]
(%o2)                     [          ]
                          [ - c  - d ]
(%i3) coeff (a*u - b*v = 7*u + 3*v, u);
(%o3)                         a = 7
Categories: Polynomials ·
Function: 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.

Examples:

(%i1) content (2*x*y + 4*x^2*y^2, y);
                                   2
(%o1)                   [2 x, 2 x y  + y]
Categories: Polynomials ·
Function: denom (expr)

Returns the denominator of the rational expression expr.

See also num

(%i1) g1:(x+2)*(x+1)/((x+3)^2);
                         (x + 1) (x + 2)
(%o1)                    ---------------
                                   2
                            (x + 3)
(%i2) denom(g1);
                                   2
(%o2)                       (x + 3)
(%i3) g2:sin(x)/10*cos(x)/y;
                          cos(x) sin(x)
(%o3)                     -------------
                              10 y
(%i4) denom(g2);
(%o4)                         10 y
Categories: Expressions ·
Function: 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.

Examples:

(%i1) divide (x + y, x - y, x);
(%o1)                       [1, 2 y]
(%i2) divide (x + y, x - y);
(%o2)                      [- 1, 2 x]

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

Categories: Polynomials ·
Function: 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.

Example:

(%i1) expr1: 2*x^2 + y*x + z;
                                      2
(%o1)                    z + x y + 2 x
(%i2) expr2: 3*x + 5*y - z - 1;
(%o2)                  - z + 5 y + 3 x - 1
(%i3) expr3: z^2 + x - y^2 + 5;
                          2    2
(%o3)                    z  - y  + x + 5
(%i4) eliminate ([expr3, expr2, expr1], [y, z]);
             8         7         6          5          4
(%o4) [7425 x  - 1170 x  + 1299 x  + 12076 x  + 22887 x

                                    3         2
                            - 5154 x  - 1291 x  + 7688 x + 15376]
Categories: Polynomials · Algebraic equations ·
Function: 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.

Examples:

The three polynomials have the greatest common divisor 2*x-3. The gcd is first calculated with the function gcd and then with the function ezgcd.

(%i1) p1 : 6*x^3-17*x^2+14*x-3;
                        3       2
(%o1)                6 x  - 17 x  + 14 x - 3
(%i2) p2 : 4*x^4-14*x^3+12*x^2+2*x-3;
                    4       3       2
(%o2)            4 x  - 14 x  + 12 x  + 2 x - 3
(%i3) p3 : -8*x^3+14*x^2-x-3;
                          3       2
(%o3)                - 8 x  + 14 x  - x - 3

(%i4) gcd(p1, gcd(p2, p3));
(%o4)                        2 x - 3

(%i5) ezgcd(p1, p2, p3);
                   2               3      2           2
(%o5) [2 x - 3, 3 x  - 4 x + 1, 2 x  - 4 x  + 1, - 4 x  + x + 1]
Categories: Polynomials ·
Option variable: facexpand

Default value: true

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

Categories: Polynomials ·
Function: factor
    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.

factor_max_degree if set to a positive integer n will prevent certain polynomials from being factored if their degree in any variable exceeds n.

See also collectterms and sqfr

Examples:

(%i1) factor (2^63 - 1);
                    2
(%o1)              7  73 127 337 92737 649657
(%i2) factor (-8*y - 4*x + z^2*(2*y + x));
(%o2)               (2 y + x) (z - 2) (z + 2)
(%i3) -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2;
                2  2        2    2    2
(%o3)          x  y  + 2 x y  + y  - x  - 2 x - 1
(%i4) block ([dontfactor: [x]], factor (%/36/(1 + 2*y + y^2)));
                       2
                     (x  + 2 x + 1) (y - 1)
(%o4)                ----------------------
                           36 (y + 1)
(%i5) factor (1 + %e^(3*x));
                      x         2 x     x
(%o5)              (%e  + 1) (%e    - %e  + 1)
(%i6) factor (1 + x^4, a^2 - 2);
                    2              2
(%o6)             (x  - a x + 1) (x  + a x + 1)
(%i7) factor (-y^2*z^2 - x*z^2 + x^2*y^2 + x^3);
                       2
(%o7)              - (y  + x) (z - x) (z + x)
(%i8) (2 + x)/(3 + x)/(b + x)/(c + x)^2;
                             x + 2
(%o8)               ------------------------
                                           2
                    (x + 3) (x + b) (x + c)
(%i9) ratsimp (%);
                4                  3
(%o9) (x + 2)/(x  + (2 c + b + 3) x

     2                       2             2                   2
 + (c  + (2 b + 6) c + 3 b) x  + ((b + 3) c  + 6 b c) x + 3 b c )
(%i10) partfrac (%, x);
           2                   4                3
(%o10) - (c  - 4 c - b + 6)/((c  + (- 2 b - 6) c

     2              2         2                2
 + (b  + 12 b + 9) c  + (- 6 b  - 18 b) c + 9 b ) (x + c))

                 c - 2
 - ---------------------------------
     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)
(%i11) map ('factor, %);
              2
             c  - 4 c - b + 6                 c - 2
(%o11) - ------------------------- - ------------------------
                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)
(%i12) ratsimp ((x^5 - 1)/(x - 1));
                       4    3    2
(%o12)                x  + x  + x  + x + 1
(%i13) subst (a, x, %);
                       4    3    2
(%o13)                a  + a  + a  + a + 1
(%i14) factor (%th(2), %);
                       2        3        3    2
(%o14)   (x - a) (x - a ) (x - a ) (x + a  + a  + a + 1)
(%i15) factor (1 + x^12);
                       4        8    4
(%o15)               (x  + 1) (x  - x  + 1)
(%i16) factor (1 + x^99);
                 2            6    3
(%o16) (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
 (x   + x   - x   - x   + x   + x   - x   - x   - x  + x  + x

    4    3            60    57    51    48    42    39    33
 - x  - x  + x + 1) (x   + x   - x   - x   + x   + x   - x

    30    27    21    18    12    9    3
 - x   - x   + x   + x   - x   - x  + x  + 1)
Categories: Polynomials ·
Option variable: factor_max_degree

Default value: 1000

When factor_max_degree is set to a positive integer n, it will prevent Maxima from attempting to factor certain polynomials whose degree in any variable exceeds n. If factor_max_degree_print_warning is true, a warning message will be printed. factor_max_degree can be used to prevent excessive memory usage and/or computation time and stack overflows. Note that "obvious" factoring of polynomials such as x^2000+x^2001 to x^2000*(x+1) will still take place. To disable this behavior, set factor_max_degree to 0.

Example:

(%i1) factor_max_degree : 100$
(%i2) factor(x^100-1);
                        2        4    3    2
(%o2) (x - 1) (x + 1) (x  + 1) (x  - x  + x  - x + 1)
   4    3    2            8    6    4    2
 (x  + x  + x  + x + 1) (x  - x  + x  - x  + 1)
   20    15    10    5        20    15    10    5
 (x   - x   + x   - x  + 1) (x   + x   + x   + x  + 1)
   40    30    20    10
 (x   - x   + x   - x   + 1)
(%i3) factor(x^101-1);
                               101
Refusing to factor polynomial x    - 1
               because its degree exceeds factor_max_degree (100)
                             101
(%o3)                       x    - 1

See also: factor_max_degree_print_warning

Categories: Polynomials ·
Option variable: factor_max_degree_print_warning

Default value: true

When factor_max_degree_print_warning is true, then Maxima will print a warning message when the factoring of a polynomial is prevented because its degree exceeds the value of factor_max_degree.

See also: factor_max_degree

Categories: Polynomials ·
Option variable: factorflag

Default value: false

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

Categories: Polynomials ·
Function: 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.

Example:

(%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)
Categories: Expressions ·
Function: 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.

Example:

(%i1) expand ((x + 1)*((u + v)^2 + a*(w + z)^2));
           2      2                            2      2
(%o1) a x z  + a z  + 2 a w x z + 2 a w z + a w  x + v  x

                                     2        2    2            2
                        + 2 u v x + u  x + a w  + v  + 2 u v + u
(%i2) factorsum (%);
                                   2          2
(%o2)            (x + 1) (a (z + w)  + (v + u) )
Categories: Expressions ·
Function: 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.

Categories: Polynomials ·
Function: 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.

Example:

(%i1) expr: (x^(a/2) + 1)^2*(x^(a/2) - 1)^2/(x^a - 1);
                       a/2     2   a/2     2
                     (x    - 1)  (x    + 1)
(%o1)                -----------------------
                              a
                             x  - 1
(%i2) ratsimp (expr);
                          2 a      a
                         x    - 2 x  + 1
(%o2)                    ---------------
                              a
                             x  - 1
(%i3) fullratsimp (expr);
                              a
(%o3)                        x  - 1
(%i4) rat (expr);
                       a/2 4       a/2 2
                     (x   )  - 2 (x   )  + 1
(%o4)/R/             -----------------------
                              a
                             x  - 1
Function: fullratsubst (new, old, expr)
    fullratsubst (old = new, expr)
    fullratsubst ([ old_1 = new_1, …, old_n = new_n ], expr)

fullratsubst applies lratsubst repeatedly until expr stops changing (or lrats_max_iter is reached). This function is useful when the replacement expression and the replaced expression have one or more variables in common.

fullratsubst accepts its arguments in the format of ratsubst or lratsubst.

Examples:

  • subst can carry out multiple substitutions. lratsubst is analogous to subst.
(%i2) subst ([a = b, c = d], a + c);
(%o2)                         d + b
(%i3) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
(%o3)                (d + a c) e + a d + b c
  • If only one substitution is desired, then a single equation may be given as first argument.
(%i4) lratsubst (a^2 = b, a^3);
(%o4)                          a b
  • fullratsubst is equivalent to ratsubst except that it recurses until its result stops changing.
(%i5) ratsubst (b*a, a^2, a^3);
                               2
(%o5)                         a  b
(%i6) fullratsubst (b*a, a^2, a^3);
                                 2
(%o6)                         a b
  • fullratsubst also accepts a list of equations or a single equation as first argument.
(%i7) fullratsubst ([a^2 = b, b^2 = c, c^2 = a], a^3*b*c);
(%o7)                           b
(%i8) fullratsubst (a^2 = b*a, a^3);
                                 2
(%o8)                         a b
(%i9) fullratsubst (b*a^2, a^2, a^3), lrats_max_iter=15;
Warning: fullratsubst1(substexpr,forexpr,expr): reached maximum iterations of 15 . Increase `lrats_max_iter' to increase this limit.
                                     3  15
(%o7)                               a  b

See also lrats_max_iter and fullratsubstflag.

Categories: Rational expressions ·
Option variable: fullratsubstflag

Default value: false

An option variable that is set to true in fullratsubst.

Categories: Polynomials · Rational expressions ·
Function: 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.

Example:

(%i1) p1:6*x^3+19*x^2+19*x+6; 
                        3       2
(%o1)                6 x  + 19 x  + 19 x + 6
(%i2) p2:6*x^5+13*x^4+12*x^3+13*x^2+6*x;
                  5       4       3       2
(%o2)          6 x  + 13 x  + 12 x  + 13 x  + 6 x
(%i3) gcd(p1, p2);
                            2
(%o3)                    6 x  + 13 x + 6
(%i4) p1/gcd(p1, p2), ratsimp;
(%o4)                         x + 1
(%i5) p2/gcd(p1, p2), ratsimp;
                              3
(%o5)                        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.

(%i6) ezgcd(p1, p2);
                    2                     3
(%o6)           [6 x  + 13 x + 6, x + 1, x  + x]
Categories: Polynomials · Rational expressions ·
Function: gcdex
    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.

Examples:

(%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].

(%i1) gcdex (x*(y + 1), y^2 - 1, x);
                               1
(%o1)/R/                 [0, ------, 1]
                              2
                             y  - 1
Categories: Polynomials · Rational expressions ·
Function: 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.

Categories: Integers ·
Function: gfactor (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.

Example:

(%i1) gfactor (x^4 - 1);
(%o1)           (x - 1) (x + 1) (x - %i) (x + %i)
Categories: Polynomials ·
Function: gfactorsum (expr)

is similar to factorsum but applies gfactor instead of factor.

Categories: Expressions ·
Function: 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.

Examples:

(%i1) hipow (y^3 * x^2 + x * y^4, x);
(%o1)                           2
(%i2) hipow ((x + y)^5, x);
(%o2)                           1
(%i3) hipow (expand ((x + y)^5), x);
(%o3)                           5
(%i4) hipow ((x + y)^5, x + y);
(%o4)                           5
(%i5) hipow (expand ((x + y)^5), x + y);
(%o5)                           0
Categories: Expressions ·
Option variable: 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.

Categories: Integers ·
Option variable: 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.

Examples:

(%i1) rat(x/2.0);

rat: replaced 0.5 by 1/2 = 0.5
                                x
(%o1)/R/                        -
                                2
(%i2) rat(x/2.0), keepfloat;
(%o2)/R/                      0.5 x

solve ignores keepfloat:

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

rat: replaced 1.0 by 1/1 = 1.0
(%o1)                        [x = 1]
Categories: Numerical evaluation ·
Function: lopow (expr, x)

Returns the lowest exponent of x which explicitly appears in expr. Thus

(%i1) lopow ((x+y)^2 + (x+y)^a, x+y);
(%o1)                       min(a, 2)
Categories: Expressions ·
Function: lratsubst (new, old, expr)
    lratsubst (old = new, expr)
    lratsubst ([ old_1 = new_1, …, old_n = new_n ], expr)

lratsubst is analogous to subst except that it uses ratsubst to perform substitutions.

The first argument of lratsubst is an equation, a list of equations or a list of unit length whose first element is a list of equations (that is, the first argument is 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.

Examples:

  • subst can carry out multiple substitutions. lratsubst is analogous to subst.
(%i2) lratsubst ([a = b, c = d], a + c);
(%o2)                         d + b
(%i3) lratsubst ([a^2 = b, c^2 = d], (a + e)*c*(a + c));
(%o3)                (d + a c) e + a d + b c
  • If only one substitution is desired, then a single equation may be given as first argument.
(%i4) lratsubst (a^2 = b, a^3);
(%o4)                          a b
  • A nested list of substitutions can be used–but it must contain only one list.
(%i5) lratsubst ([[a^2=b*a, b=c]], a^3);

                                      2
(%o5)                               a  c
(%i6) lratsubst ([[a^2=b*a, b=c],[a=b]], a^3);


                                 2
lratsubst: improper argument: [[a  = a b, b = c], [a = b]]
#0: lratsubst(listofeqns=[[a^2 = a*b,b = c],[a = b]],expr=a^3)
 -- an error. To debug this try: debugmode(true);

See also fullratsubst.

Categories: Polynomials · Rational expressions ·
Option variable: lrats_max_iter

Default value: 100000

The upper limit on the number of iterations that fullratsubst and lratsubst may perform. It must be set to a positive integer. See the example for fullratsubst.

Categories: Polynomials · Rational expressions ·
Option variable: modulus

Default value: false

When modulus is a positive number p, operations on canonical rational expressions (CREs, 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.

Examples:

(%i1) modulus:7;
(%o1)                           7
(%i2) polymod([0,1,2,3,4,5,6,7]);
(%o2)            [0, 1, 2, 3, - 3, - 2, - 1, 0]
(%i3) modulus:false;
(%o3)                         false
(%i4) poly:x^6+x^2+1;
                            6    2
(%o4)                      x  + x  + 1
(%i5) factor(poly);
                            6    2
(%o5)                      x  + x  + 1
(%i6) modulus:13;
(%o6)                          13
(%i7) factor(poly);
                      2        4      2
(%o7)               (x  + 6) (x  - 6 x  - 2)
(%i8) polymod(%);
                            6    2
(%o8)                      x  + x  + 1
Categories: Integers ·
Function: num (expr)

Returns the numerator of expr if it is a ratio. If expr is not a ratio, expr is returned.

num evaluates its argument.

See also denom

(%i1) g1:(x+2)*(x+1)/((x+3)^2);
                         (x + 1) (x + 2)
(%o1)                    ---------------
                                   2
                            (x + 3)
(%i2) num(g1);
(%o2)                    (x + 1) (x + 2)
(%i3) g2:sin(x)/10*cos(x)/y;
                          cos(x) sin(x)
(%o3)                     -------------
                              10 y
(%i4) num(g2);
(%o4)                     cos(x) sin(x)
Categories: Expressions ·
Function: polydecomp (p, x)

Decomposes the polynomial p in the variable x into the functional composition of polynomials in x. polydecomp returns a list [p_1, ..., p_n] such that

lambda ([x], p_1) (lambda ([x], p_2) (... (lambda ([x], p_n) (x))
  ...))

is equal to p. The degree of p_i is greater than 1 for i less than n.

Such a decomposition is not unique.

Examples:

(%i1) polydecomp (x^210, x);
                          7   5   3   2
(%o1)                   [x , x , x , x ]
(%i2) p : expand (subst (x^3 - x - 1, x, x^2 - a));
                6      4      3    2
(%o2)          x  - 2 x  - 2 x  + x  + 2 x - a + 1
(%i3) polydecomp (p, x);
                        2       3
(%o3)                 [x  - a, x  - x - 1]

The following function composes L = [e_1, ..., e_n] as functions in x; it is the inverse of polydecomp:

(%i1) compose (L, x) :=
  block ([r : x], for e in L do r : subst (e, x, r), r) $

Re-express above example using compose:

(%i1) polydecomp (compose ([x^2 - a, x^3 - x - 1], x), x);
                          2       3
(%o1)          [compose([x  - a, x  - x - 1], x)]

Note that though compose (polydecomp (p, x), x) always returns p (unexpanded), polydecomp (compose ([p_1, ..., p_n], x), x) does not necessarily return [p_1, ..., p_n]:

(%i1) polydecomp (compose ([x^2 + 2*x + 3, x^2], x), x);
                           2             2
(%o1)           [compose([x  + 2 x + 3, x ], x)]
(%i2) polydecomp (compose ([x^2 + x + 1, x^2 + x + 1], x), x);
                        2           2
(%o2)        [compose([x  + x + 1, x  + x + 1], x)]
Categories: Polynomials ·
Function: polymod
    polymod (p)
    polymod (p, m)

Converts the polynomial p to a modular representation with respect to the current modulus which is the value of the variable modulus.

polymod (p, m) specifies a modulus m to be used instead of the current value of modulus.

See modulus.

Categories: Polynomials ·
Function: polynomialp
    polynomialp (p, L, coeffp, exponp)
    polynomialp (p, L, coeffp)
    polynomialp (p, L)

Return true if p is a polynomial in the variables in the list L. The predicate coeffp must evaluate to true for each coefficient, and the predicate exponp must evaluate to true for all exponents of the variables in L. If you want to use a non-default value for exponp, you must supply coeffp with a value even if you want to use the default for coeffp.

The command polynomialp (p, L, coeffp) is equivalent to polynomialp (p, L, coeffp, 'nonnegintegerp) and the command polynomialp (p, L) is equivalent to polynomialp (p, L, 'constantp, 'nonnegintegerp).

The polynomial needn’t be expanded:

(%i1) polynomialp ((x + 1)*(x + 2), [x]);
(%o1)                         true
(%i2) polynomialp ((x + 1)*(x + 2)^a, [x]);
(%o2)                         false

An example using non-default values for coeffp and exponp:

(%i1) polynomialp ((x + 1)*(x + 2)^(3/2), [x], numberp, numberp);
(%o1)                         true
(%i2) polynomialp ((x^(1/2) + 1)*(x + 2)^(3/2), [x], numberp,
                                                        numberp);
(%o2)                         true

Polynomials with two variables:

(%i1) polynomialp (x^2 + 5*x*y + y^2, [x]);
(%o1)                         false
(%i2) polynomialp (x^2 + 5*x*y + y^2, [x, y]);
(%o2)                         true

Polynomial in one variable and accepting any expression free of x as a coefficient.

(%i1) polynomialp (a*x^2 + b*x + c, [x]);
(%o1)                         false
(%i2) polynomialp (a*x^2 + b*x + c, [x], lambda([ex], freeof(x, ex)));
(%o2)                         true
Categories: Predicate functions · Polynomials ·
Function: quotient
    quotient (p_1, p_2)
    quotient (p_1, p_2, x_1, …, x_n)

Returns the polynomial p_1 divided by the polynomial p_2. The arguments x_1, …, x_n are interpreted as in ratvars.

quotient returns the first element of the two-element list returned by divide.

Categories: Polynomials ·
Function: rat
    rat (expr)
    rat (expr, x_1, …, x_n)

Converts expr to canonical rational expression (CRE) form by expanding and combining all terms over a common denominator and cancelling out the greatest common divisor of the numerator and denominator, as well as converting floating point numbers to rational numbers within a tolerance of ratepsilon. The variables are ordered according to the x_1, …, x_n, if specified, as in ratvars.

rat does not generally simplify functions other than addition +, subtraction -, multiplication *, division /, and exponentiation to an integer power, whereas ratsimp does handle those cases. Note that atoms (numbers and variables) in CRE form are not the same as they are in the general form. For example, rat(x)- x yields rat(0) which has a different internal representation than 0.

When ratfac is true, rat yields a partially factored form for CRE. During rational operations the expression is maintained as fully factored as possible without an actual call to the factor package. This should always save space and may save some time in some computations. The numerator and denominator are still made relatively prime (e.g., rat((x^2 - 1)^4/(x + 1)^2) yields (x - 1)^4 (x + 1)^2 when ratfac is true), but the factors within each part may not be relatively prime.

ratprint if false suppresses the printout of the message informing the user of the conversion of floating point numbers to rational numbers.

keepfloat if true prevents floating point numbers from being converted to rational numbers.

See also ratexpand and ratsimp.

Examples:

(%i1) ((x - 2*y)^4/(x^2 - 4*y^2)^2 + 1)*(y + a)*(2*y + x) /
      (4*y^2 + x^2);
                                           4
                                  (x - 2 y)
              (y + a) (2 y + x) (------------ + 1)
                                   2      2 2
                                 (x  - 4 y )
(%o1)         ------------------------------------
                              2    2
                           4 y  + x
(%i2) rat (%, y, a, x);
                            2 a + 2 y
(%o2)/R/                    ---------
                             x + 2 y
Categories: Rational expressions ·
Option variable: ratalgdenom

Default value: true

When ratalgdenom is true, allows rationalization of denominators with respect to radicals to take effect. ratalgdenom has an effect only when canonical rational expressions (CRE) are used in algebraic mode.

Function: ratcoef
    ratcoef (expr, x, n)
    ratcoef (expr, x)

Returns the coefficient of the expression x^n in the expression expr. If omitted, n is assumed to be 1.

The return value is free (except possibly in a non-rational sense) of the variables in x. If no coefficient of this type exists, 0 is returned.

ratcoef expands and rationally simplifies its first argument and thus it may produce answers different from those of coeff which is purely syntactic. Thus ratcoef ((x + 1)/y + x, x) returns (y + 1)/y whereas coeff returns 1.

ratcoef (expr, x, 0), viewing expr as a sum, returns a sum of those terms which do not contain x. Therefore if x occurs to any negative powers, ratcoef should not be used.

Since expr is rationally simplified before it is examined, coefficients may not appear quite the way they were envisioned.

Example:

(%i1) s: a*x + b*x + 5$
(%i2) ratcoef (s, a + b);
(%o2)                           x
Categories: Polynomials · Rational expressions ·
Function: ratdenom (expr)

Returns the denominator of expr, after coercing expr to a canonical rational expression (CRE). The return value is a CRE.

expr is coerced to a CRE by rat if it is not already a CRE. This conversion may change the form of expr by putting all terms over a common denominator.

denom is similar, but returns an ordinary expression instead of a CRE. Also, denom does not attempt to place all terms over a common denominator, and thus some expressions which are considered ratios by ratdenom are not considered ratios by denom.

Categories: Rational expressions ·
Option variable: ratdenomdivide

Default value: true

When ratdenomdivide is true, ratexpand expands a ratio in which the numerator is a sum into a sum of ratios, all having a common denominator. Otherwise, ratexpand collapses a sum of ratios into a single ratio, the numerator of which is the sum of the numerators of each ratio.

Examples:

(%i1) expr: (x^2 + x + 1)/(y^2 + 7);
                            2
                           x  + x + 1
(%o1)                      ----------
                              2
                             y  + 7
(%i2) ratdenomdivide: true$
(%i3) ratexpand (expr);
                       2
                      x        x        1
(%o3)               ------ + ------ + ------
                     2        2        2
                    y  + 7   y  + 7   y  + 7
(%i4) ratdenomdivide: false$
(%i5) ratexpand (expr);
                            2
                           x  + x + 1
(%o5)                      ----------
                              2
                             y  + 7
(%i6) expr2: a^2/(b^2 + 3) + b/(b^2 + 3);
                                     2
                           b        a
(%o6)                    ------ + ------
                          2        2
                         b  + 3   b  + 3
(%i7) ratexpand (expr2);
                                  2
                             b + a
(%o7)                        ------
                              2
                             b  + 3
Function: ratdiff (expr, x)

Differentiates the rational expression expr with respect to x. expr must be a ratio of polynomials or a polynomial in x. The argument x may be a variable or a subexpression of expr.

The result is equivalent to diff, although perhaps in a different form. ratdiff may be faster than diff, for rational expressions.

ratdiff returns a canonical rational expression (CRE) if expr is a CRE. Otherwise, ratdiff returns a general expression.

ratdiff considers only the dependence of expr on x, and ignores any dependencies established by depends.

Example:

(%i1) expr: (4*x^3 + 10*x - 11)/(x^5 + 5);
                           3
                        4 x  + 10 x - 11
(%o1)                   ----------------
                              5
                             x  + 5
(%i2) ratdiff (expr, x);
                    7       5       4       2
                 8 x  + 40 x  - 55 x  - 60 x  - 50
(%o2)          - ---------------------------------
                          10       5
                         x   + 10 x  + 25
(%i3) expr: f(x)^3 - f(x)^2 + 7;
                         3       2
(%o3)                   f (x) - f (x) + 7
(%i4) ratdiff (expr, f(x));
                           2
(%o4)                   3 f (x) - 2 f(x)
(%i5) expr: (a + b)^3 + (a + b)^2;
                              3          2
(%o5)                  (b + a)  + (b + a)
(%i6) ratdiff (expr, a + b);
                    2                    2
(%o6)            3 b  + (6 a + 2) b + 3 a  + 2 a
Categories: Rational expressions ·
Function: ratdisrep (expr)

Returns its argument as a general expression. If expr is a general expression, it is returned unchanged.

Typically ratdisrep is called to convert a canonical rational expression (CRE) into a general expression. This is sometimes convenient if one wishes to stop the "contagion", or use rational functions in non-rational contexts.

See also totaldisrep.

Categories: Rational expressions ·
Function: ratexpand (expr)
Option variable: ratexpand

Expands expr by multiplying out products of sums and exponentiated sums, combining fractions over a common denominator, cancelling the greatest common divisor of the numerator and denominator, then splitting the numerator (if a sum) into its respective terms divided by the denominator.

The return value of ratexpand is a general expression, even if expr is a canonical rational expression (CRE).

The switch ratexpand if true will cause CRE expressions to be fully expanded when they are converted back to general form or displayed, while if it is false then they will be put into a recursive form. See also ratsimp.

When ratdenomdivide is true, ratexpand expands a ratio in which the numerator is a sum into a sum of ratios, all having a common denominator. Otherwise, ratexpand collapses a sum of ratios into a single ratio, the numerator of which is the sum of the numerators of each ratio.

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

Examples:

(%i1) ratexpand ((2*x - 3*y)^3);
                     3         2       2        3
(%o1)          - 27 y  + 54 x y  - 36 x  y + 8 x
(%i2) expr: (x - 1)/(x + 1)^2 + 1/(x - 1);
                         x - 1       1
(%o2)                   -------- + -----
                               2   x - 1
                        (x + 1)
(%i3) expand (expr);
                    x              1           1
(%o3)          ------------ - ------------ + -----
                2              2             x - 1
               x  + 2 x + 1   x  + 2 x + 1
(%i4) ratexpand (expr);
                        2
                     2 x                 2
(%o4)           --------------- + ---------------
                 3    2            3    2
                x  + x  - x - 1   x  + x  - x - 1
Categories: Rational expressions ·
Option variable: ratfac

Default value: false

When ratfac is true, canonical rational expressions (CRE) are manipulated in a partially factored form.

During rational operations the expression is maintained as fully factored as possible without calling factor. This should always save space and may save time in some computations. The numerator and denominator are made relatively prime, for example factor ((x^2 - 1)^4/(x + 1)^2) yields (x - 1)^4 (x + 1)^2, but the factors within each part may not be relatively prime.

In the ctensor (Component Tensor Manipulation) package, Ricci, Einstein, Riemann, and Weyl tensors and the scalar curvature are factored automatically when ratfac is true. ratfac should only be set for cases where the tensorial components are known to consist of few terms.

The ratfac and ratweight schemes are incompatible and may not both be used at the same time.

Categories: Rational expressions ·
Function: ratnumer (expr)

Returns the numerator of expr, after coercing expr to a canonical rational expression (CRE). The return value is a CRE.

expr is coerced to a CRE by rat if it is not already a CRE. This conversion may change the form of expr by putting all terms over a common denominator.

num is similar, but returns an ordinary expression instead of a CRE. Also, num does not attempt to place all terms over a common denominator, and thus some expressions which are considered ratios by ratnumer are not considered ratios by num.

Categories: Rational expressions ·
Function: ratp (expr)

Returns true if expr is a canonical rational expression (CRE) or extended CRE, otherwise false.

CRE are created by rat and related functions. Extended CRE are created by taylor and related functions.

Option variable: ratprint

Default value: true

When ratprint is true, a message informing the user of the conversion of floating point numbers to rational numbers is displayed.

Function: ratsimp (expr)
Function: ratsimp (expr, x_1, …, x_n)

Simplifies the expression expr and all of its subexpressions, including the arguments to non-rational functions. The result is returned as the quotient of two polynomials in a recursive form, that is, the coefficients of the main variable are polynomials in the other variables. Variables may include non-rational functions (e.g., sin (x^2 + 1)) and the arguments to any such functions are also rationally simplified.

ratsimp (expr, x_1, ..., x_n) enables rational simplification with the specification of variable ordering as in ratvars.

When ratsimpexpons is true, ratsimp is applied to the exponents of expressions during simplification.

See also ratexpand. Note that ratsimp is affected by some of the flags which affect ratexpand.

Examples:

(%i1) sin (x/(x^2 + x)) = exp ((log(x) + 1)^2 - log(x)^2);
                                         2      2
                   x         (log(x) + 1)  - log (x)
(%o1)        sin(------) = %e
                  2
                 x  + x
(%i2) ratsimp (%);
                             1          2
(%o2)                  sin(-----) = %e x
                           x + 1
(%i3) ((x - 1)^(3/2) - (x + 1)*sqrt(x - 1))/sqrt((x - 1)*(x + 1));
                       3/2
                (x - 1)    - sqrt(x - 1) (x + 1)
(%o3)           --------------------------------
                     sqrt((x - 1) (x + 1))
(%i4) ratsimp (%);
                           2 sqrt(x - 1)
(%o4)                    - -------------
                                 2
                           sqrt(x  - 1)
(%i5) x^(a + 1/a), ratsimpexpons: true;
                               2
                              a  + 1
                              ------
                                a
(%o5)                        x
Option variable: ratsimpexpons

Default value: false

When ratsimpexpons is true, ratsimp is applied to the exponents of expressions during simplification.

Option variable: radsubstflag

Default value: false

radsubstflag, if true, permits ratsubst to make substitutions such as u for sqrt (x) in x.

Function: ratsubst (a, b, c)

Substitutes a for b in c and returns the resulting expression. b may be a sum, product, power, etc.

ratsubst knows something of the meaning of expressions whereas subst does a purely syntactic substitution. Thus subst (a, x + y, x + y + z) returns x + y + z whereas ratsubst returns z + a.

When radsubstflag is true, ratsubst makes substitutions for radicals in expressions which don’t explicitly contain them.

ratsubst ignores the value true of the option variables keepfloat, float, and numer.

Examples:

(%i1) ratsubst (a, x*y^2, x^4*y^3 + x^4*y^8);
                              3      4
(%o1)                      a x  y + a
(%i2) cos(x)^4 + cos(x)^3 + cos(x)^2 + cos(x) + 1;
               4         3         2
(%o2)       cos (x) + cos (x) + cos (x) + cos(x) + 1
(%i3) ratsubst (1 - sin(x)^2, cos(x)^2, %);
            4           2                     2
(%o3)    sin (x) - 3 sin (x) + cos(x) (2 - sin (x)) + 3
(%i4) ratsubst (1 - cos(x)^2, sin(x)^2, sin(x)^4);
                        4           2
(%o4)                cos (x) - 2 cos (x) + 1
(%i5) radsubstflag: false$
(%i6) ratsubst (u, sqrt(x), x);
(%o6)                           x
(%i7) radsubstflag: true$
(%i8) ratsubst (u, sqrt(x), x);
                                2
(%o8)                          u
Categories: Rational expressions ·
Function: ratvars (x_1, …, x_n)
Function: ratvars ()
System variable: ratvars

Declares main variables x_1, …, x_n for rational expressions. x_n, if present in a rational expression, is considered the main variable. Otherwise, x_[n-1] is considered the main variable if present, and so on through the preceding variables to x_1, which is considered the main variable only if none of the succeeding variables are present.

If a variable in a rational expression is not present in the ratvars list, it is given a lower priority than x_1.

The arguments to ratvars can be either variables or non-rational functions such as sin(x).

The variable ratvars is a list of the arguments of the function ratvars when it was called most recently. Each call to the function ratvars resets the list. ratvars () clears the list.

Categories: Rational expressions ·
Option variable: ratvarswitch

Default value: true

Maxima keeps an internal list in the Lisp variable VARLIST of the main variables for rational expressions. If ratvarswitch is true, every evaluation starts with a fresh list VARLIST. This is the default behavior. Otherwise, the main variables from previous evaluations are not removed from the internal list VARLIST.

The main variables, which are declared with the function ratvars are not affected by the option variable ratvarswitch.

Examples:

If ratvarswitch is true, every evaluation starts with a fresh list VARLIST.

(%i1) ratvarswitch:true$

(%i2) rat(2*x+y^2);
                             2
(%o2)/R/                    y  + 2 x
(%i3) :lisp varlist
($X $Y)

(%i3) rat(2*a+b^2);
                             2
(%o3)/R/                    b  + 2 a

(%i4) :lisp varlist
($A $B)

If ratvarswitch is false, the main variables from the last evaluation are still present.

(%i4) ratvarswitch:false$

(%i5) rat(2*x+y^2);
                             2
(%o5)/R/                    y  + 2 x
(%i6) :lisp varlist
($X $Y)

(%i6) rat(2*a+b^2);
                             2
(%o6)/R/                    b  + 2 a

(%i7) :lisp varlist
($A $B $X $Y)
Function: ratweight
    ratweight (x_1, w_1, …, x_n, w_n)
    ratweight ()

Assigns a weight w_i to the variable x_i. This causes a term to be replaced by 0 if its weight exceeds the value of the variable ratwtlvl (default yields no truncation). The weight of a term is the sum of the products of the weight of a variable in the term times its power. For example, the weight of 3 x_1^2 x_2 is 2 w_1 + w_2. Truncation according to ratwtlvl is carried out only when multiplying or exponentiating canonical rational expressions (CRE).

ratweight () returns the cumulative list of weight assignments.

Note: The ratfac and ratweight schemes are incompatible and may not both be used at the same time.

Examples:

(%i1) ratweight (a, 1, b, 1);
(%o1)                     [a, 1, b, 1]
(%i2) expr1: rat(a + b + 1)$
(%i3) expr1^2;
                  2                  2
(%o3)/R/         b  + (2 a + 2) b + a  + 2 a + 1
(%i4) ratwtlvl: 1$
(%i5) expr1^2;
(%o5)/R/                  2 b + 2 a + 1
Categories: Rational expressions ·
System variable: ratweights

Default value: []

ratweights is the list of weights assigned by ratweight. The list is cumulative: each call to ratweight places additional items in the list.

kill (ratweights) and save (ratweights) both work as expected.

Categories: Rational expressions ·
Option variable: ratwtlvl

Default value: false

ratwtlvl is used in combination with the ratweight function to control the truncation of canonical rational expressions (CRE). For the default value of false, no truncation occurs.

Categories: Rational expressions ·
Function: remainder
    remainder (p_1, p_2)
    remainder (p_1, p_2, x_1, …, x_n)

Returns the remainder of the polynomial p_1 divided by the polynomial p_2. The arguments x_1, …, x_n are interpreted as in ratvars.

remainder returns the second element of the two-element list returned by divide.

Categories: Polynomials ·
Function: resultant (p_1, p_2, x)

The function resultant computes the resultant of the two polynomials p_1 and p_2, eliminating the variable x. The resultant is a determinant of the coefficients of x in p_1 and p_2, which equals zero if and only if p_1 and p_2 have a non-constant factor in common.

If p_1 or p_2 can be factored, it may be desirable to call factor before calling resultant.

The option variable resultant controls which algorithm will be used to compute the resultant. See the option variable resultant.

The function bezout takes the same arguments as resultant and returns a matrix. The determinant of the return value is the desired resultant.

Examples:

(%i1) resultant(2*x^2+3*x+1, 2*x^2+x+1, x);
(%o1)                           8
(%i2) resultant(x+1, x+1, x);
(%o2)                           0
(%i3) resultant((x+1)*x, (x+1), x);
(%o3)                           0
(%i4) resultant(a*x^2+b*x+1, c*x + 2, x);
                         2
(%o4)                   c  - 2 b c + 4 a

(%i5) bezout(a*x^2+b*x+1, c*x+2, x);
                        [ 2 a  2 b - c ]
(%o5)                   [              ]
                        [  c      2    ]
(%i6) determinant(%);
(%o6)                   4 a - (2 b - c) c
Categories: Polynomials ·
Option variable: resultant

Default value: subres

The option variable resultant controls which algorithm will be used to compute the resultant with the function resultant. The possible values are:

subres

for the subresultant polynomial remainder sequence (PRS) algorithm,

mod

(not enabled) for the modular resultant algorithm, and

red

for the reduced polynomial remainder sequence (PRS) algorithm.

On most problems the default value subres should be best.

Categories: Polynomials ·
Option variable: savefactors

Default value: false

When savefactors is 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.

Categories: Polynomials ·
Function: showratvars (expr)

Returns a list of the canonical rational expression (CRE) variables in expression expr.

See also ratvars.

Function: sqfr (expr)

is similar to factor except that the polynomial factors are "square-free." That is, they have factors only of degree one. This algorithm, which is also used by the first stage of factor, utilizes the fact that a polynomial has in common with its n’th derivative all its factors of degree greater than n. Thus by taking greatest common divisors with the polynomial of the derivatives with respect to each variable in the polynomial, all factors of degree greater than 1 can be found.

Example:

(%i1) sqfr (4*x^4 + 4*x^3 - 3*x^2 - 4*x - 1);
                                2   2
(%o1)                  (2 x + 1)  (x  - 1)
Categories: Polynomials ·
Function: tellrat
    tellrat (p_1, …, p_n)
    tellrat ()

Adds to the ring of algebraic integers known to Maxima the elements which are the solutions of the polynomials p_1, …, p_n. Each argument p_i is a polynomial with integer coefficients.

tellrat (x) effectively means substitute 0 for x in rational functions.

tellrat () returns a list of the current substitutions.

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

Maxima initially knows about the imaginary unit %i and all roots of integers.

There is a command untellrat which takes kernels and removes tellrat properties.

When tellrat’ing a multivariate polynomial, e.g., tellrat (x^2 - y^2), there would be an ambiguity as to whether to substitute y^2 for x^2 or vice versa. Maxima picks a particular ordering, but if the user wants to specify which, e.g. tellrat (y^2 = x^2) provides a syntax which says replace y^2 by x^2.

Examples:

(%i1) 10*(%i + 1)/(%i + 3^(1/3));
                           10 (%i + 1)
(%o1)                      -----------
                                  1/3
                            %i + 3
(%i2) ev (ratdisrep (rat(%)), algebraic);
             2/3      1/3              2/3      1/3
(%o2)    (4 3    - 2 3    - 4) %i + 2 3    + 4 3    - 2
(%i3) tellrat (1 + a + a^2);
                            2
(%o3)                     [a  + a + 1]
(%i4) 1/(a*sqrt(2) - 1) + a/(sqrt(3) + sqrt(2));
                      1                 a
(%o4)           ------------- + -----------------
                sqrt(2) a - 1   sqrt(3) + sqrt(2)
(%i5) ev (ratdisrep (rat(%)), algebraic);
         (7 sqrt(3) - 10 sqrt(2) + 2) a - 2 sqrt(2) - 1
(%o5)    ----------------------------------------------
                               7
(%i6) tellrat (y^2 = x^2);
                        2    2   2
(%o6)                 [y  - x , a  + a + 1]
Categories: Polynomials · Rational expressions ·
Function: totaldisrep (expr)

Converts every subexpression of expr from canonical rational expressions (CRE) to general form and returns the result. If expr is itself in CRE form then totaldisrep is identical to ratdisrep.

totaldisrep may be useful for ratdisrepping expressions such as equations, lists, matrices, etc., which have some subexpressions in CRE form.

Categories: Rational expressions ·
Function: untellrat (x_1, …, x_n)

Removes tellrat properties from x_1, …, x_n.

Categories: Polynomials · Rational expressions ·

14.3 Introduction to algebraic extensions

We assume here that the fields are of characteristic 0 so that irreductible polynomials have simple roots (are separable, thus square free). The base fields K of interest are the field Q of rational numbers, for algebraic numbers, and the fields of rational functions on the real numbers R or the complex numbers C, that is R(t) or C(t), when considering algebraic functions. An extension of degree n is defined by an irreducible degree n polynomial p(x) with coefficients in the base field, and consists of the quotient of the ring K[x] of polynomials by the multiples of p(x). So if p(x) = x^n + p_0 x^{n - 1} + ... + p_n, each time one encounters x^n one substitutes -(p_0 x^{n - 1} + ... + p_n). This is a field because of Bezout’s identity, and a vector space of dimension n over K spanned by 1, x, ..., x^{n - 1}. When K = C(t), this field can be identified with the field of algebraic functions on the algebraic curve of equation p(x, t) = 0.

In Maxima the process of taking rationals modulo p is obtained by the function tellrat when algebraic is true. The best way to ensure, in particular when considering the case where p depends on other variables that this simplification property is attached to x is to write (note the polynomial must be monic): tellrat(x^n = -(p_0*x^(n - 1) + ... + p_n)) where the p_i may depend on other variables. When one wants to remove this tellrat property one then has to write untellrat(x).

In the field K[x] one may do all sorts of algebraic computations, taking quotients, GCD of two elements, etc. by the same algorithms as in the usual case. In particular one can do factorization of polynomials on an extension, using the function algfac below. Moreover multiplication by an element f is a linear operation of the vector space K[x] over K and as such has a trace and a determinant. These are called algtrace and algnorm below. One can see that the trace of an element f(x) in K[x] is the sum of the values f(a) when a runs over roots of p and the norm is the product of the f(a). Both are symmetric in the roots of p and thus belong to K.

The field K[x] is also called the field obtained by adjoining a root a of p(x) to K. One can similarly adjoin a second root b of another polynomial obtaining a new extension K[a,b]. In fact there is a “prime element” c in K[a, b] such that K[a, b] = K[c]. This is obtained by function primeelmt below. Recursively one can thus adjoin any number of elements. In particular adjoining all the roots of p(x) to K one gets the splitting field of p, which is the smallest extension in which p completely splits in linear functions. The function splitfield constructs a primitive element of the splitting field, which in general is of very high degree.

The relevant concepts are explained in a concise and self-contained way in the small books edited by Dover: “Algebraic theory of numbers,” by Pierre Samuel, “Algebraic curves,” by Robert Walker, and the methods presented here are described in the article “Algebraic factoring and rational function integration” by B. Trager, Proceedings of the 1976 AMS Symposium on Symbolic and Algebraic Computation.


14.4 Functions and Variables for algebraic extensions

Function: algfac (f, p)

Returns the factorization of f in the field K[a]. Does the same as factor(f, p) which in fact calls algfac. One can also specify the variable a as in algfac(f, p, a).

Examples:

(%i1) algfac(x^4 + 1, a^2 - 2);
                           2              2
(%o1)                    (x  - a x + 1) (x  + a x + 1)
(%i2) algfac(x^4 - t*x^2 + 1, a^2 - t - 2, a);
                           2              2
(%o2)                    (x  - a x + 1) (x  + a x + 1)

In the second example note that a = sqrt(2 + t).

Function: algnorm (f, p, a)

Returns the norm of the polynomial f(a) in the extension obtained by a root a of polynomial p. The coefficients of f may depend on other variables.

Examples:

(%i1) algnorm(x*a^2 + y*a + z,a^2 - 2, a);
                            2              2      2
(%o1)/R/                   z  + 4 x z - 2 y  + 4 x

The norm is also the resultant of polynomials f and p, and the product of the differences of the roots of f and p.

Function: algtrace (f, p, a)

Returns the trace of the polynomial f(a) in the extension obtained by a root a of polynomial p. The coefficients of f may depend on other variables which remain “inert”.

Example:

(%i1) algtrace(x*a^5 + y*a^3 + z + 1, a^2 + a + 1, a);
(%o1)/R/                       2 z + 2 y - x + 2
Function: bdiscr (args)

Computes the discriminant of a basis x_i in K[a] as the determinant of the matrix of elements trace(x_i*x_j). The args are the elements of the basis followed by the minimal polynomial.

Example:

(%i1) bdiscr(1, x, x^2, x^3 - 2);
(%o1)/R/                             - 108
(%i2) poly_discriminant(x^3 - 2, x);
(%o2)                                - 108

A standard base in an extension of degree n is 1, x, ..., x^{n - 1}. In this case it is known that the discriminant of this base is the discriminant of the minimal polynomial. This is checked in (%o2) above.

Function: primelmt (f_b, p_a, c)

Computes a prime element for the extension of K[a] by a root b of a polynomial f_b(b) whose coefficients may depend on a. One assumes that f_b is square free. The function returns an irreducible polynomial, a root of which generates K[a, b], and the expression of this primitive element in terms of a and b.

Examples:

(%i1) primelmt(b^2 - a*b - 1, a^2 - 2, c);
                              4       2
(%o1)                       [c  - 12 c  + 9, b + a]
(%i2) solve(b^2 - sqrt(2)*b - 1)[1];
                                  sqrt(6) - sqrt(2)
(%o2)                       b = - -----------------
                                          2
(%i3) primelmt(b^2 - 3, a^2 - 2, c);
                              4       2
(%o3)                       [c  - 10 c  + 1, b + a]
(%i4) factor(c^4 - 12*c^2 + 9, a^4 - 10*a^2 + 1);
                 3    2                       3    2
(%o4) ((4 c - 3 a  - a  + 27 a + 5) (4 c - 3 a  + a  + 27 a - 5)
                           3    2                       3    2
                 (4 c + 3 a  - a  - 27 a + 5) (4 c + 3 a  + a  - 27 a - 5))/256
(%i5) primelmt(b^3 - 3, a^2 - 2, c);
                   6      4      3       2
(%o5)            [c  - 6 c  - 6 c  + 12 c  - 36 c + 1, b + a]
(%i6) factor(b^3 - 3, %[1]);
            5       4        3        2
(%o6) ((48 c  + 27 c  - 320 c  - 468 c  + 124 c + 755 b - 1092)
           5        5         4       4          3        3          2        2
 ((- 48 b c ) - 54 c  - 27 b c  + 64 c  + 320 b c  + 360 c  + 468 b c  + 149 c
                           2
 - 124 b c - 1272 c + 755 b  + 1092 b + 1606))/570025

In (%o1), f_b depends on a. Using solve, the solution depends on sqrt(2) and sqrt(3). In (%o3), K[sqrt(2), sqrt(3)] is computed, and we see that the the primitive polynomial in (%o1) factorizes completely here. In (%i5), we compute K[sqrt(2), 3^{1/3}], and we see that b^3 - 3 gets one factor in this extension. If we assume this extension is real, the two other factors are complex.

Function: splitfield (p, x)

Computes the splitting field of the polynomial p(x). In the generic case it is of degree n! in terms of the degree n of p, but may be of lower order if the Galois group of p is a strict subgroup of the group of permutations of n elements. The function returns a primitive polynomial for this extension and the expressions of the roots of p as polynomials of a root of this primitive polynomial. The polynomial f may be irreducible or factorizable.

Examples:

(%i1) splitfield(x^3 + x + 1, x);
                                              4         2
              6         4         2       alg1  + 5 alg1  - 9 alg1 + 4
(%o1)/R/ [alg1  + 6 alg1  + 9 alg1  + 31, ----------------------------, 
                                                       18
                                 4         2          4         2
                             alg1  + 5 alg1  + 4  alg1  + 5 alg1  + 9 alg1 + 4
                           - -------------------, ----------------------------]
                                      9                        18
(%i2) splitfield(x^4 + 10*x^2 - 96*x - 71, x)[1];
             8           6           5            4             3
(%o2)/R/ alg2  + 148 alg2  - 576 alg2  + 9814 alg2  - 42624 alg2
                                                    2
                                       + 502260 alg2  + 1109952 alg2 + 18860337

In the first case we have the primitive polynomial of degree 6 and the 3 roots of the third degree equations in terms of a variable alg1 produced by the system. In the second case the primitive polynomial is of degree 8 instead of 24, because the Galois group of the equation is reduced to D8 since there are relations between the roots.


Next: , Previous:   [Contents][Index]