This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
Wolfram Research, Inc.

Structural Operations on Rational ExpressionsPolynomials Modulo Primes

3.3.4 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.

Reduction of polynomials.

Given two polynomials and , one can always uniquely write , where the degree of is less than the degree of . PolynomialQuotient gives the quotient , and PolynomialRemainder gives the remainder .

This gives the remainder from dividing by .

In[1]:= PolynomialRemainder[x^2, x+1, x]


Here is the quotient of and , with the remainder dropped.

In[2]:= PolynomialQuotient[x^2, x+1, x]


This gives back the original expression.

In[3]:= Simplify[ (x+1) % + %% ]


Here the result depends on whether the polynomials are considered to be in x or y.

In[4]:= {PolynomialRemainder[x+y, x-y, x],

PolynomialRemainder[x+y, x-y, y]}


PolynomialGCD[, ] finds the highest degree polynomial that divides the exactly. It gives the analog for polynomials of the integer function GCD.

PolynomialGCD gives the greatest common divisor of the two polynomials.

In[5]:= PolynomialGCD[ (1-x)^2 (1+x) (2+x), (1-x) (2+x) (3+x) ]


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 as low degree a polynomial 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 modulo . The result is simply the remainder from dividing the polynomials.

In[6]:= PolynomialMod[x^2, x+1]


In this case, PolynomialMod and PolynomialRemainder do not give the same result.

In[7]:= {PolynomialMod[x^2, 2x+1],

PolynomialRemainder[x^2, 2x+1, x]}


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 modulo both and .

In[8]:= PolynomialMod[x^2 + 1, {x + 1, 2}]


The function Resultant[, , x] is used in a number of classical algebraic algorithms. The resultant of two polynomials and , both with leading coefficient one, is given by the product of all the differences 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, one can tell for what values of their parameters two polynomials have a common root. Two polynomials with leading coefficient one have common roots if exactly the first elements in the list Subresultants[, , x] are zero.

Here is the resultant with respect to of two polynomials in and . The original polynomials have a common root in only for values of at which the resultant vanishes.

In[9]:= Resultant[(x-y)^2-2, y^2-3, y]


Gröbner bases appear in many modern algebraic algorithms and applications. The function GroebnerBasis[, , ... , , , ... ] 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 is effectively redundant, and so does not appear in the Gröbner basis.

In[10]:= GroebnerBasis[{(x+y), (x+y)^2}, {x, y}]


The polynomial 1 has no roots, showing that the original polynomials have no common roots.

In[11]:= GroebnerBasis[{x+y,x^2-1,y^2-2x}, {x, y}]


The polynomials are effectively unwound here, and can now be seen to have exactly five common roots.

In[12]:= GroebnerBasis[{x y^2+2 x y+x^2+1, x y+y^2+1}, {x, y}]


PolynomialReduce[poly, , , ... , , , ... ] yields a list , , ... , b of polynomials with the property that b is minimal and + + ... + b is exactly poly.

This writes in terms of and , leaving a remainder that depends only on .

In[13]:= PolynomialReduce[x^2 + y^2, {x - y, y + a}, {x, y}]


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.

In[14]:= t = Expand[ 2 (1 + x)^2 (2 + x) (3 + x) ]


FactorTerms pulls out only the factor of 2 that does not depend on x.

In[15]:= FactorTerms[t, x]


FactorSquareFree factors out the 2 and the term (1 + x)^2, but leaves the rest unfactored.

In[16]:= FactorSquareFree[t]


Factor does full factoring, recovering the original form.

In[17]:= Factor[t]


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.

In[18]:= FactorList[t]


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.

In[19]:= Factor[1 + x^2]


When Gaussian integer coefficients are allowed, the polynomial factors.

In[20]:= Factor[1 + x^2, GaussianIntegers -> True]


Cyclotomic polynomials.

Cyclotomic polynomials arise as "elementary polynomials" in various algebraic algorithms. The cyclotomic polynomials are defined by , where runs over all positive integers less than that are relatively prime to .

This is the cyclotomic polynomial .

In[21]:= Cyclotomic[6, x]


appears in the factors of .

In[22]:= Factor[x^6 - 1]


Decomposing polynomials.

Factorization is one important way of breaking down polynomials into simpler parts. Another, quite different, way is decomposition. When one factors a polynomial , one writes it as a product of polynomials . Decomposing a polynomial consists of writing it as a composition of polynomials of the form .

Here is a simple example of Decompose. The original polynomial can be written as the polynomial , where is the polynomial .

In[23]:= Decompose[x^4 + x^2 + 1, x]


Here are two polynomial functions.

In[24]:= ( q1[x_] = 1 - 2x + x^4 ;

q2[x_] = 5x + x^3 ; )

This gives the composition of the two functions.

In[25]:= Expand[ q1[ q2[ x ] ] ]


Decompose recovers the original functions.

In[26]:= Decompose[%, x]


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 and , related by and give the same result on composition, so that . 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.

In[27]:= InterpolatingPolynomial[{{-1, 4}, {0, 2}, {1, 6}}, x]


When x is 0, the polynomial has value 2.

In[28]:= % /. x -> 0


Structural Operations on Rational ExpressionsPolynomials Modulo Primes