Algebraic Operations on Polynomials
For many kinds of practical calculations, the only operations you will need to perform on polynomials are essentially the structural ones discussed in the preceding sections.
If you do more advanced algebra with polynomials, however, you will have to use the algebraic operations discussed in this section.
You should realize that most of the operations discussed in this section work only on ordinary polynomials, with integer exponents and rational-number coefficients for each term.
| PolynomialQuotient[poly1,poly2,x] | find the result of dividing the polynomial poly1 in x by poly2, dropping any remainder term |
| PolynomialRemainder[poly1,poly2,x] | find the remainder from dividing the polynomial poly1 in x by poly2 |
| PolynomialQuotientRemainder[poly1,poly2,x] |
| give the quotient and remainder in a list |
| PolynomialMod[poly,m] | reduce the polynomial poly modulo m |
| PolynomialGCD[poly1,poly2] | find the greatest common divisor of two polynomials |
| PolynomialLCM[poly1,poly2] | find the least common multiple of two polynomials |
| PolynomialExtendedGCD[poly1,poly2] | find the extended greatest common divisor of two polynomials |
| Resultant[poly1,poly2,x] | find the resultant of two polynomials |
| Subresultants[poly1,poly2,x] | find the principal subresultant coefficients of two polynomials |
| Discriminant[poly,x] | find the discriminant of the polynomial poly |
| GroebnerBasis[{poly1,poly2,...},{x1,x2,...}] |
| find the Gröbner basis for the polynomials polyi |
| GroebnerBasis[{poly1,poly2,...},{x1,x2,...},{y1,y2,...}] |
| find the Gröbner basis eliminating the yi |
| PolynomialReduce[poly,{poly1,poly2,...},{x1,x2,...}] |
| find a minimal representation of poly in terms of the polyi |
Reduction of polynomials.
Given two polynomials
p (x) and
q (x), one can always uniquely write

, where the degree of
b (x) is less than the degree of
q (x).
PolynomialQuotient gives the quotient
a (x), and
PolynomialRemainder gives the remainder
b (x).
This gives the remainder from dividing x2 by 1+x.
| Out[1]= |  |
|
Here is the quotient of x2 and x+1, with the remainder dropped.
| Out[2]= |  |
|
This gives back the original expression.
| Out[3]= |  |
|
Here the result depends on whether the polynomials are considered to be in x or y.
| Out[4]= |  |
|
PolynomialMod is essentially the analog for polynomials of the function
Mod for integers. When the modulus
m is an integer,
PolynomialMod[poly, m] simply reduces each coefficient in
poly modulo the integer
m. If
m is a polynomial, then
PolynomialMod[poly, m] effectively tries to get a polynomial with as low a degree as possible by subtracting from
poly appropriate multiples
q m of
m. The multiplier
q can itself be a polynomial, but its degree is always less than the degree of
poly.
PolynomialMod yields a final polynomial whose degree and leading coefficient are both as small as possible.
This reduces x2 modulo x+1. The result is simply the remainder from dividing the polynomials.
| Out[5]= |  |
|
| Out[6]= |  |
|
The main difference between
PolynomialMod and
PolynomialRemainder is that while the former works simply by multiplying and subtracting polynomials, the latter uses division in getting its results. In addition,
PolynomialMod allows reduction by several moduli at the same time. A typical case is reduction modulo both a polynomial and an integer.
This reduces the polynomial x2+1 modulo both x+1 and 2.
| Out[7]= |  |
|
PolynomialGCD[poly1, poly2] finds the highest degree polynomial that divides the
polyi exactly. It gives the analog for polynomials of the integer function
GCD.
PolynomialGCD gives the greatest common divisor of the two polynomials.
| Out[8]= |  |
|
| Out[9]= |  |
|
The returned polynomials r and s can be used to represent the GCD in terms of the original polynomials.
| Out[10]= |  |
|
The function
Resultant[poly1, poly2, x] is used in a number of classical algebraic algorithms. The resultant of two polynomials
a and
b, both with leading coefficient one, is given by the product of all the differences
ai-bj between the roots of the polynomials. It turns out that for any pair of polynomials, the resultant is always a polynomial in their coefficients. By looking at when the resultant is zero, you can tell for what values of their parameters two polynomials have a common root. Two polynomials with leading coefficient one have
k common roots if exactly the first
k elements in the list
Subresultants[poly1, poly2, x] are zero.
Here is the resultant with respect to y of two polynomials in x and y. The original polynomials have a common root in y only for values of x at which the resultant vanishes.
| Out[11]= |  |
|
The function
Discriminant[poly, x] is the product of the squares of the differences of its roots. It can be used to determine whether the polynomial has any repeated roots. The discriminant is equal to the resultant of the polynomial and its derivative, up to a factor independent of the variable.
This polynomial has a repeated root, so its discriminant vanishes.
| Out[12]= |  |
|
This polynomial has distinct roots, so its discriminant is nonzero.
| Out[13]= |  |
|
Gröbner bases appear in many modern algebraic algorithms and applications. The function
GroebnerBasis[{poly1, poly2, ...}, {x1, x2, ...}] takes a set of polynomials, and reduces this set to a canonical form from which many properties can conveniently be deduced. An important feature is that the set of polynomials obtained from
GroebnerBasis always has exactly the same collection of common roots as the original set.
The (x+y)2 is effectively redundant, and so does not appear in the Gröbner basis.
| Out[14]= |  |
|
The polynomial 1 has no roots, showing that the original polynomials have no common roots.
| Out[15]= |  |
|
The polynomials are effectively unwound here, and can now be seen to have exactly five common roots.
| Out[16]= |  |
|
PolynomialReduce[poly, {p1, p2, ...}, {x1, x2, ...}] yields a list
{{a1, a2, ...}, b} of polynomials with the property that
b is minimal and
a1p1+a2p2+...+b is exactly
poly.
This writes x2+y2 in terms of x-y and y+a, leaving a remainder that depends only on a.
| Out[17]= |  |
|
Functions for factoring polynomials.
Factor,
FactorTerms and
FactorSquareFree perform various degrees of factoring on polynomials.
Factor does full factoring over the integers.
FactorTerms extracts the "content" of the polynomial.
FactorSquareFree pulls out any multiple factors that appear.
Here is a polynomial, in expanded form.
| Out[18]= |  |
|
FactorTerms pulls out only the factor of 2 that does not depend on x.
| Out[19]= |  |
|
FactorSquareFree factors out the 2 and the term (1+x)^2, but leaves the rest unfactored.
| Out[20]= |  |
|
Factor does full factoring, recovering the original form.
| Out[21]= |  |
|
Particularly when you write programs that work with polynomials, you will often find it convenient to pick out pieces of polynomials in a standard form. The function
FactorList gives a list of all the factors of a polynomial, together with their exponents. The first element of the list is always the overall numerical factor for the polynomial.
The form that
FactorList returns is the analog for polynomials of the form produced by
FactorInteger for integers.
Here is a list of the factors of the polynomial in the previous set of examples. Each element of the list gives the factor, together with its exponent.
| Out[22]= |  |
|
Factoring polynomials with complex coefficients.
Factor and related functions usually handle only polynomials with ordinary integer or rational-number coefficients. If you set the option
GaussianIntegers->True, however, then
Factor will allow polynomials with coefficients that are complex numbers with rational real and imaginary parts. This often allows more extensive factorization to be performed.
This polynomial is irreducible when only ordinary integers are allowed.
| Out[23]= |  |
|
When Gaussian integer coefficients are allowed, the polynomial factors.
| Out[24]= |  |
|
| Cyclotomic[n,x] | give the cyclotomic polynomial of order n in x |
Cyclotomic polynomials.
Cyclotomic polynomials arise as "elementary polynomials" in various algebraic algorithms. The cyclotomic polynomials are defined by

, where
k runs over all positive integers less than
n that are relatively prime to
n.
This is the cyclotomic polynomial C6 (x).
| Out[25]= |  |
|
C6 (x) appears in the factors of x6-1.
| Out[26]= |  |
|
| Decompose[poly,x] | decompose poly, if possible, into a composition of a list of simpler polynomials |
Decomposing polynomials.
Factorization is one important way of breaking down polynomials into simpler parts. Another, quite different, way is
decomposition. When you factor a polynomial
P (x), you write it as a product
p1 (x)p2 (x)... of polynomials
pi (x). Decomposing a polynomial
Q (x) consists of writing it as a
composition of polynomials of the form
q1 (q2 (... (x)...)).
Here is a simple example of Decompose. The original polynomial x4+x2+1 can be written as the polynomial  , where  is the polynomial x2.
| Out[27]= |  |
|
Here are two polynomial functions. |
This gives the composition of the two functions.
| Out[29]= |  |
|
| Out[30]= |  |
|
Decompose[poly, x] is set up to give a list of polynomials in
x, which, if composed, reproduce the original polynomial. The original polynomial can contain variables other than
x, but the sequence of polynomials that
Decompose produces are all intended to be considered as functions of
x.
Unlike factoring, the decomposition of polynomials is not completely unique. For example, the two sets of polynomials
pi and
qi, related by
q1 (x)=p1 (x-a) and
q2 (x)=p2 (x)+a give the same result on composition, so that
p1 (p2 (x))=q1 (q2 (x)).
Mathematica follows the convention of absorbing any constant terms into the first polynomial in the list produced by
Decompose.
Generating interpolating polynomials.
This yields a quadratic polynomial which goes through the specified three points.
| Out[31]= |  |
|
When x is 0, the polynomial has value 2.
| Out[32]= |  |
|