Element Operations

Contents

Arithmetic Operators

The usual unary and binary ring operations are available for multivariate polynomials.

For polynomial rings over fields division by elements of the coefficient field are allowed (with the result in the original polynomial ring). The operator div has slightly different semantics from the univariate case: if b divides a, that is, if there exists a polynomial q∈P such that a = b.q∈P then q will be the result of a div b, but if such polynomial does not exist an error results.

+ a : RngMPolElt -> RngMPolElt
- a : RngMPolElt -> RngMPolElt
a + b : RngMPolElt, RngMPolElt -> RngMPolElt
a - b : RngMPolElt, RngMPolElt -> RngMPolElt
a * b : RngMPolElt, RngMPolElt -> RngMPolElt
a ^ k : RngMPolElt, RngIntElt -> RngMPolElt
a / b : RngMPolElt, RngMPolElt -> FldFunMElt
a div b : RngMPolElt, RngMPolElt -> RngMPolElt
a +:= b : RngMPolElt, RngMPolElt -> RngMPolElt
a -:= b : RngMPolElt, RngMPolElt -> RngMPolElt
a *:= b : RngMPolElt, RngMPolElt -> RngMPolElt
a div:= b : RngMPolElt, RngMPolElt -> RngMPolElt

Equality and Membership

a eq b : RngMPolElt, RngMPolElt -> BoolElt
a ne b : RngMPolElt, RngMPolElt -> BoolElt
a in R : RngMPolElt, Rng -> BoolElt
a notin R : RngMPolElt, Rng -> BoolElt

Predicates on Ring Elements

The list belows contains the general ring element predicates. Also, the IsDivisibleBy function allows a divisibility test, and the IsAlgebraicallyDependent function determines if a set of ring elements is algebraically dependent. Note that not all functions are available for every coefficient ring.

IsZero(f) : RngMPolElt -> BoolElt
IsOne(f) : RngMPolElt -> BoolElt
IsMinusOne(f) : RngMPolElt -> BoolElt
IsNilpotent(f) : RngMPolElt -> BoolElt
IsIdempotent(f) : RngMPolElt -> BoolElt
IsUnit(f) : RngMPolElt -> BoolElt
IsZeroDivisor(f) : RngMPolElt -> BoolElt
IsRegular(f) : RngMPolElt -> BoolElt
IsIrreducible(f) : RngMPolElt -> BoolElt
IsPrime(f) : RngMPolElt -> BoolElt
IsDivisibleBy(a, b) : RngMPolElt, RngMPolElt -> BoolElt, RngMPolElt
Given elements a, b in a multivariate polynomial ring P, this function returns whether the polynomial a is divisible by b in P, that is, if and only if there exists q∈P such that a=q.b. If true is returned, the quotient polynomial q is also returned.
IsAlgebraicallyDependent(S) : RngMPolElt -> BoolElt
Returns true iff the set S of multivariate polynomials is algebraically dependent.

Coefficients, Monomials and Terms

Many of the functions in this subsection come in three different forms: one in which no variable is specified, which usually returns values in the coefficient ring, and two in which a particular variable is referred, either by name or by number, and these usually return values in the polynomial ring itself.

Coefficients(f) : RngMPolElt -> [ RngElt ]
Given a multivariate polynomial f with coefficients in R, this function returns a sequence of `base' coefficients, that is, a sequence of elements of R occurring as coefficients of the monomials in f. Note that the monomials are ordered, and that the sequence of coefficients corresponds exactly to the sequence of monomials returned by Monomials(f).
Coefficients(f, i) : RngMPolElt, RngIntElt -> [ RngElt ]
Coefficients(f, v) : RngMPolElt, RngMPolElt -> [ RngElt ]
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns a sequence of coefficients with respect to a given variable v=xi, that is, the function returns a sequence of elements of P that form the coefficients of the powers of v (in ascending order) when f is regarded as a polynomial ∑j cj xij; note that the variable xi itself will not occur in the coefficients. There are two ways to indicate with respect to which variable the coefficients are to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
Coefficient(f, i, k) : RngMPolElt, RngIntElt, RngIntElt -> RngElt
Coefficient(f, v, k) : RngMPolElt, RngMPolElt, RngIntElt -> RngElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the coefficient of vk=xik, that is, the function returns the element of P that forms the coefficient of the k-th power of xi, when f is regarded as a polynomial ∑j cj xij; note that the variable xi itself will not occur in the coefficient. There are two ways to indicate with respect to which variable the coefficient is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
LeadingCoefficient(f) : RngMPolElt -> RngElt
Given a multivariate polynomial f with coefficients in R, this function returns the leading coefficient of f as an element of R; this is the coefficient of the leading monomial of f, that is, the first among the monomials occurring in f with respect to the ordering of monomials used in P.
LeadingCoefficient(f, i) : RngMPolElt, RngIntElt -> RngElt
LeadingCoefficient(f, v) : RngMPolElt, RngMPolElt -> RngElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the element of P that forms the coefficient of the largest power of v=xi that occurs with non-zero coefficient in f, when f is regarded as a polynomial ∑j cj xij; note that the variable xi itself will not occur in the coefficient. There are two ways to indicate with respect to which variable the leading coefficient is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
Length(f) : RngMPolElt -> RngIntElt
Given a multivariate polynomial f, return the length of f, i.e., the number of terms of f.
TrailingCoefficient(f) : RngMPolElt -> RngElt
Given a multivariate polynomial f with coefficients in R, this function returns the trailing coefficient of f as an element of R; this is the coefficient of the trailing monomial of f, that is, the last among the monomials occurring in f with respect to the ordering of monomials used in P.
TrailingCoefficient(f, i) : RngMPolElt, RngIntElt -> RngElt
TrailingCoefficient(f, v) : RngMPolElt, RngMPolElt -> RngElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the element of P that forms the coefficient of the least power of v=xi that occurs with non-zero coefficient in f, when f is regarded as a polynomial ∑j cj xij; note that the variable xi itself will not occur in the coefficient. There are two ways to indicate with respect to which variable the leading coefficient is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
CoefficientDenominator(f) : RngMPolElt -> RngElt
CoefficientNumerator(f) : RngMPolElt -> RngElt
Given a multivariate polynomial f with coefficients in Q, a rational function field or a field of fractions of an order of a number or function field, return the LCM of the denominators of the coefficients of f (CoefficientDenominator) or the product of that LCM with f itself (CoefficientNumerator).
MonomialCoefficient(f, m) : RngMPolElt, RngMPolElt -> RngElt
Given a multivariate polynomial f and a monomial m, both in P∈R[x1, ..., xn], this function returns the coefficient with which m occurs in f as an element of R.
Monomials(f) : RngMPolElt -> [ RngMPolElt ]
Given a multivariate polynomial f∈P, this function returns a sequence of monomials, that is, a sequence of monomial elements of P occurring in f. Note that the monomials in P are ordered, and that the sequence of monomials corresponds exactly to the sequence of coefficients returned by Coefficients(f).
CoefficientsAndMonomials(f) : RngMPolElt -> [ RngElt ], [ RngMPolElt ]
Given a multivariate polynomial f∈P, this function returns parallel sequences C and M of the coefficients and monomials, respectively, of f. Thus this function is equivalent to calling Coefficients and Monomials separately, but is more efficient (particularly for large polynomials) since only one scan of the polynomial needs to be done.
LeadingMonomial(f) : RngMPolElt -> RngMPolElt
Given a multivariate polynomial f∈P this function returns the leading monomial of f, that is, the first monomial element of P that occurs in f, with respect to the ordering of monomials used in P.
Terms(f) : RngMPolElt -> [ RngMPolElt ]
Given a multivariate polynomial f∈P, this function returns the sequence of (non-zero) terms of f as elements of P. The terms are ordered according to the ordering on the monomials in P. Consequently the i-th element of this sequence of terms will be equal to the product of the i-th element of the sequence of coefficients and the i-th element of the sequence of monomials.
Terms(f, i) : RngMPolElt, RngIntElt -> [ RngMPolElt ]
Terms(f, v) : RngMPolElt, RngMPolElt -> [ RngMPolElt ]
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns a sequence of terms with respect to a given variable v=xi, that is, the function returns a sequence of elements of P that form the terms (ascending order) of f regarded as a polynomial ∑j cj xij. There are two ways to indicate with respect to which variable the terms are to be ordered: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
Term(f, i, k) : RngMPolElt, RngIntElt, RngIntElt -> RngMPolElt
Term(f, v, k) : RngMPolElt, RngMPolElt, RngIntElt -> RngMPolElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the k-th term of f (with k≥0), that is, the function returns the term of f involving the k-th power of xi, when f is regarded as a polynomial ∑j cj xij. There are two ways to indicate with respect to which variable the term is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
LeadingTerm(f) : RngMPolElt -> RngMPolElt
Given a multivariate polynomial f∈P, this function returns the leading term of f as an element of P; this is the product of the leading monomial and the leading coefficient that is, the first among the monomial terms occurring in f with respect to the ordering of monomials used in P.
LeadingTerm(f, i) : RngMPolElt, RngIntElt -> RngMPolElt
LeadingTerm(f, v) : RngMPolElt, RngMPolElt -> RngMPolElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the element of P that forms the leading term of f when f is regarded as a polynomial ∑j cj xij. Thus it is the term involving the largest power of xi that occurs with non-zero coefficient. There are two ways to indicate with respect to which variable the leading coefficient is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
TrailingTerm(f) : RngMPolElt -> RngElt
Given a multivariate polynomial f∈P, this function returns the trailing term of f as an element of P; this is the last among the monomial terms occurring in f with respect to the ordering of monomials used in P.
TrailingTerm(f, i) : RngMPolElt, RngIntElt -> RngElt
TrailingTerm(f, v) : RngMPolElt, RngMPolElt -> RngElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the element of P that forms the trailing term of f when f is regarded as a polynomial ∑j cj xij. Thus it is the term involving the least power of xi that occurs with non-zero coefficient. There are two ways to indicate with respect to which variable the leading coefficient is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
Exponents(f) : RngMPolElt -> [ RngIntElt ]
Given a single term f (a polynomial having exactly one term) in a polynomial ring of rank n, return the exponents of the monomial of f, as a sequence of length n of integers. (The coefficient of f is ignored; it need not be 1.)
Monomial(P, E) : RngMPol, [ RngIntElt ] -> RngMPolElt
Given a multivariate polynomial ring P = R[x1, ..., xn], and a sequence E of non-negative integers, return the monomial (x1)E[1] ... (xn)E[n] in P. This function is a semi-inverse of Exponents.
Polynomial(C, M) : [RngElt], [RngMPolElt] -> RngMPolElt
Given a length-k sequence C of coefficients in a ring R and a length-k sequence M of monomials of a polynomial ring R, return the multivariate polynomial f∈R whose coefficients are C and monomials are M. (Thus for any f∈R, Polynomial(Coefficients(f), Monomials(f)) equals f.)

Example RngMPol_Coefficients (H25E4)

In this and the next example we illustrate the coefficient and term functions, using the polynomial in three variables x, y, z over the rational field that is given by f=(2x + y)z3 + 11xyz + x2y2.
> R<x, y, z> := PolynomialAlgebra(RationalField(), 3);
> f := (2*x+y)*z^3+11*x*y*z+x^2*y^2;
> f;
x^2*y^2 + 11*x*y*z + 2*x*z^3 + y*z^3
> Coefficients(f);
[ 1, 11, 2, 1 ]
> Monomials(f);
[
   x^2*y^2,
   x*y*z,
   x*z^3,
   y*z^3
]
> CoefficientsAndMonomials(f);
[ 1, 11, 2, 1 ]
[
    x^2*y^2,
    x*y*z,
    x*z^3,
    y*z^3
]
> Terms(f);
[
   x^2*y^2,
   11*x*y*z,
   2*x*z^3,
   y*z^3
]
> Coefficients(f, y);
[
   2*x*z^3,
   11*x*z + z^3,
   x^2
]
> Terms(f, 2);
[
   2*x*z^3,
   11*x*y*z + y*z^3,
   x^2*y^2
]
> MonomialCoefficient(f, x*y*z);
11
> LeadingTerm(f);
x^2*y^2
> LeadingTerm(f, z);
2*x*z^3 + y*z^3
> LeadingCoefficient(f, z);
2*x + y
> Polynomial([1, 2, 3], [x*y, y, z^2]);
x*y + 2*y + 3*z^2

Degrees

Degree(f, i) : RngMPolElt, RngIntElt -> RngIntElt
Degree(f, v) : RngMPolElt, RngMPolElt -> RngIntElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the degree of f in vk=xik, that is, the function returns the degree of f when it is regarded as a polynomial ∑j cj xij. The resulting integer is thus the largest power of xi occurring in any monomial of f. There are two ways to indicate with respect to which variable the degree is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P). If f is the zero polynomial, the return value is always -1.
TotalDegree(f) : RngMPolElt -> RngIntElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the total degree of f, which is the maximum of the total degrees of all monomials that occur in f. The total degree of a monomial m is the sum of the exponents of the indeterminates that make up m. Note that this ignores the weights on the variables if there are any (see the section on graded polynomial rings below). If f is the zero polynomial, the return value is -1.
LeadingTotalDegree(f) : RngMPolElt -> RngIntElt
Given a multivariate polynomial f∈P = R[x1, ..., xn], this function returns the leading total degree of f, which is the total degree of the leading monomial of f. If f is the zero polynomial, the return value is -1.

Univariate Polynomials

IsUnivariate(f) : RngMPolElt -> BoolElt, RngUPolElt, RngIntElt
Given a multivariate polynomial f∈R[x1, ..., xn], this function returns whether f is in fact a univariate polynomial in one of its indeterminates x1, ..., xn. If true is returned, then the function also returns a univariate version u of f and (the first) i such that f is univariate in xi. Note that there will only be ambiguity about i if f is a constant polynomial. The univariate polynomial u will be an element of R[x] with the same coefficients as f.
IsUnivariate(f, i) : RngMPolElt, RngIntElt -> BoolElt, RngUPolElt
IsUnivariate(f, v) : RngMPolElt, RngMPolElt -> BoolElt, RngUPolElt
Given a multivariate polynomial f∈R[x1, ..., xn], this function returns whether f is in fact a univariate polynomial in xi. If true is returned, then the function also returns a univariate version u of f, which will be an element of the univariate polynomial ring R[x] with the same coefficients as f. The indeterminate xi should either be specified as a (polynomial) argument v or as an integer i.
UnivariatePolynomial(f) : RngMPolElt -> RngUPolElt
Given a multivariate polynomial f∈R[x1, ..., xn], which is known to be a univariate polynomial in xi for some i with 1≤i≤n, return a univariate version u of f, which will be an element of the univariate polynomial ring R[x] with the same coefficients as f.

Example RngMPol_UnivariatePolynomial (H25E5)

Suppose we have two bivariate polynomials f and g over some ring.
> P<x,y> := PolynomialRing(GF(5), 2);
> f := x^2 - y + 3;
> g := y^3 - x*y + x;
If we compute the resultant in either variable of the two polynomials, then we can apply UnivariatePolynomial to this to obtain a univariate version of it, from which we can compute the roots.
> ry := Resultant(f, g, y);
> ry;
4*x^6 + x^4 + x^3 + 3*x^2 + 2*x + 3
> Roots(UnivariatePolynomial(ry));
[ <3, 1> ]
> Evaluate(f, x, 3);
4*y + 2
> Evaluate(g, x, 3);
y^3 + 2*y + 3
> GCD($1, $2);
y + 3
> rx := Resultant(f, g, x);
> rx;
y^6 + 4*y^3 + 3*y + 3
> Roots(UnivariatePolynomial(rx));
[ <2, 1> ]
> Evaluate(f, y, 2);
x^2 + 1
> Evaluate(g, y, 2);
4*x + 3
> GCD($1, $2);
x + 2

Derivative, Integral

Derivative(f, i) : RngMPolElt, RngIntElt -> RngMPolElt
Derivative(f, v) : RngMPolElt, RngMPolElt -> RngMPolElt
Given a multivariate polynomial f∈P, return the derivative of f with respect to the variable v=xi, as an element of P. There are two ways to indicate with respect to which variable the derivative is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
Derivative(f, k, i) : RngMPolElt, RngIntElt -> RngMPolElt
Derivative(f, k, v) : RngMPolElt, RngMPolElt -> RngMPolElt
Given a multivariate polynomial f∈P and an integer k > 0, return the k-th derivative of f with respect to the variable v=xi, as an element of P. There are two ways to indicate with respect to which variable the derivative is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
Integral(f, i) : RngMPolElt, RngIntElt -> RngMPolElt
Integral(f, v) : RngMPolElt, RngMPolElt -> RngMPolElt
Given a multivariate polynomial f∈P over a field of characteristic zero, return the formal integral of f with respect to v=xi as an element of P. There are two ways to indicate with respect to which variable the integral is to be taken: either one specifies i, the integer 1≤i≤n that is the number of the variable (upon creation of P, corresponding to P.i) or the variable v itself (as an element of P).
JacobianMatrix( [ f ] ) : [ RngMPolElt ] -> RngMPol
Creates the matrix with (i, j)'th entry the partial derivative of the i'th polynomial in the list with the j'th indeterminate of its parent ring.

Evaluation, Interpolation

Evaluate(f, s) : RngMPolElt, [ RngElt ] -> RngElt
Evaluate(f, s) : RngMPolElt, < RngElt, ..., RngElt > -> RngElt
Given an element f of a polynomial ring P=R[x1, ..., xn] and a sequence or tuple s of ring elements of length n, return the value of f at s, that is, obtained by substituting xi=s[i]. If the elements of s can be lifted into the coefficient ring R, then the result will be an element of R. If the elements of s cannot be lifted to the coefficient ring, then an attempt is made to do a generic evaluation of f at s. In this case, the result will be of the same type as the elements of s.
Evaluate(f, i, r) : RngMPolElt, RngMPolElt, RngElt -> RngMPolElt
Evaluate(f, v, r) : RngMPolElt, RngMPolElt, RngElt -> RngMPolElt
Given an element f of a multivariate polynomial ring P and a ring element r return the value of f when the variable v=xi is evaluated at r. If r can be coerced into the coefficient ring of P, the result will be an element in P again. Otherwise the other variables of P must be coercible into the parent of r, and the result will have the same parent as r.
Interpolation(I, V, i) : [ RngElt ], [ RngMPolElt ], RngIntElt -> RngMPolElt
Interpolation(I, V, v) : [ RngElt ], [ RngMPolElt ], RngIntElt -> RngMPolElt
Let K be a field, and P=K[x1, ..., xn] a multivariate polynomial ring over K; let v=xi be the i-th indeterminate of P. Given a sequence I of elements of K (the interpolation points) and a sequence V of elements of P (the interpolation values), both sequences of length k>0, return the unique polynomial f∈P of degree less than k in the variable xi such that f(I[j]) = V[j], for j=1, ..., k. The variable xi may not occur anywhere in the values V. There are two ways to indicate with respect to which variable to interpolate: either one specifies i, the integer 1≤i≤n that is the number of the variable or the variable v itself (as a polynomial).

Example RngMPol_Interpolate (H25E6)

We define P=Q[x, y, z], and give an example of interpolation. We find a polynomial which, when evaluated in the first variable x in the rational points 1, 2, 3, yields y, z, y + z respectively. We check the result by evaluating.
> Q := RationalField();
> P<x, y, z> := PolynomialRing(Q, 3);
> f := Interpolation([Q | 1, 2, 3], [y, z, y + z], 1);
> f;
x^2*y - 1/2*x^2*z - 4*x*y + 5/2*x*z + 4*y - 2*z
> [ Evaluate(f, 1, v) : v in [1, 2, 3] ];
[
   y,
   z,
   y + z
]

Quotient and Reductum

f div g : RngMPolElt, RngMPolElt -> RngMPolElt
ExactQuotient(f, g) : RngMPolElt, RngMPolElt -> RngMPolElt
The quotient of the multivariate polynomial f by g in R[x1, ..., xn], provided the result lies in P again. Here R must be a domain. If a polynomial q in P exists such that f=q.g then it will be returned, but if does not exist an error results.
Reductum(f) : RngMPolElt -> RngMPolElt
The reductum of a polynomial f, which is the polynomial obtained by removing the leading term of f.
Reductum(f, i) : RngMPolElt, RngIntElt -> RngMPolElt
Reductum(f, v) : RngMPolElt, RngMPolElt -> RngMPolElt
The reductum of a multivariate polynomial f∈R[x1, ..., xn] obtained by removing the leading term with respect to the variable v=xi. Here either v must be specified as a polynomial, or xi must be specified by providing the integer i, with 1≤i≤n.

Diagonalizing a Polynomial of Degree 2

We provide two basic tools that deal with polynomial diagonalization.

SymmetricBilinearForm(f) : RngMPolElt -> ModMatRngElt
The symmetric bilinear form (as a matrix) of a multivariate polynomial of degree 2.
DiagonalForm(f) : RngMPolElt -> RngMPolElt, ModMatRngElt
The diagonal form of the multivariate polynomial of degree 2. Also returns the transformation matrix.

Example RngMPol_Sym_Bi_Linear (H25E7)

> Q := RationalField();
> PR<x, y, z> := PolynomialRing(Q, 3);
> g := 119/44*x^2 - 93759/41440*x*y + 390935/91427*x*z
>      + 212/243*x - 3/17*y^2 + 52808/172227*y*z
>      - 287/227*y + 537/934*z^2 - 127/422*z;
> SymmetricBilinearForm(g);
[       119/44  -93759/82880 390935/182854       106/243]
[ -93759/82880         -3/17  26404/172227      -287/454]
[390935/182854  26404/172227       537/934      -127/844]
[      106/243      -287/454      -127/844             0]
> DiagonalForm(g);
119/44*x^2 - 15798558582429/4*y^2 +
34932799628335074761085292707227419544217/934*z^2 -
176588732861018934524371210556883645619275217398116147234837710457404146371/2
>
> bl := SymmetricBilinearForm(g);
> NBL := Matrix(PR, bl);
> D, T := OrthogonalizeGram(bl);
> NT := Matrix(PR, T);
> C := Matrix(PR, [[x,y,z,1]]);
> NC := C * NT;
> NCT := Transpose(NC);
> (NC * NBL * NCT)[1][1] eq DiagonalForm(g);
true
The last few statements demonstrate how the polynomial's diagonal form is obtained from its symmetric bilinear form. Note also that since the polynomial g is not homogeneous its symmetric bilinear form is given on four variables, the fourth variable being a homogenizing variable.
V2.28, 13 July 2023