Polynomial greatest common divisor
This article needs additional citations for verification. (September 2012) |
In algebra, the greatest common divisor (frequently abbreviated as GCD) of two polynomials is a notion which is very similar to the greatest common divisor of two integers.
In the important case of univariate polynomials over a field the polynomial GCD may be computed, like for the integer GCD, by Euclid's algorithm using long division. The main difference lies in the fact that there is no natural total order on the polynomials. Therefore, "greatest" is meant for the relation of divisibility. As this relation is only a preorder, the polynomial GCD is defined only up to the multiplication by an invertible constant.
The similarity between integer and polynomial GCD allows to extend to univariate polynomials all the properties that may be deduced from Euclid's algorithm and Euclidean division. Moreover, the polynomial GCD has specific properties that make it a fundamental notion in various areas of algebra. Typically, the roots of the GCD of two polynomials are the common roots of the two polynomials, and this allows to get information on the roots without computing them. For example the multiple roots of a polynomial are the roots of its GCD with its derivative, and further GCD computations allow to compute the square-free factorization of the polynomial.
The greatest common divisor may be defined and exists, more generally, for multivariate polynomials over a field or the ring of integers, and also over a unique factorization domain. There exist algorithms to compute them as soon as one has a GCD algorithm in the ring of coefficients. These algorithms proceed by a recursion on the number of variables to reduce the problem to a variant of Euclid's algorithm. They are a fundamental tool in computer algebra, because computer algebra systems use them systematically to simplify fractions. Conversely, most of the modern theory of polynomial GCD has been developed to satisfy the need of efficiency of computer algebra systems.
General definition
Let p and q be polynomials with coefficients in an integral domain F, typically a field or the integers. A greatest common divisor of p and q is a polynomial d that divides p and q and such that every common divisor of p and q also divides d. Every pair of polynomials has a GCD if and only if F is a unique factorization domain.
If F is a field and p and q are not both zero, d is a greatest common divisor if and only if it divides both p and q and it has the greatest degree among the polynomials having this property. If p = q = 0, the GCD is 0. However, some authors consider that it is not defined in this case?
The greatest common divisor of p and q is usually denoted "gcd(p, q)".
The greatest common divisor is not unique: if d is a GCD of p and q, then the polynomial f is another GCD if and only if there is an invertible element u of F such that
and
- .
In other words, the GCD is unique up to the multiplication by an invertible constant.
In the case of the integers, this indetermination has been settled by choosing, as the GCD, the unique one which is positive (there is another one, which is its opposite). With this convention, the GCD of two integers is also the greatest (for the usual ordering) common divisor. When one want to settle this indetermination in the polynomial case, one lacks of a natural total order. Therefore, one chooses once for all a particular GCD that is then called the greatest common divisor. For univariate polynomials over a field, this is usually the unique GCD which is monic (that is has 1 as coefficient of the highest degree). In more general cases, there is no general convention and above indetermination is usually kept. Therefore equalities like d = gcd(p, q) or gcd(p, q) = gcd(r, s) are usual abuses of notation which should be read "d is a GCD of p and q" and "p, q has the same set of GCD as r, s". In particular, gcd(p, q) = 1 means that the invertible constants are the only common divisors, and thus that p and q are coprime.
Properties
- As stated above, the GCD of two polynomials exists if the coefficients belong either to a field, the ring of the integers or more generally to a unique factorization domain.
- If c is any common divisor of p and q, then c divides their GCD.
- for any polynomial r. This property is at the basis of the proof of Euclid's algorithm.
- For any invertible element k of the ring of the coefficients, .
- Hence for any scalars such that is invertible.
- If , then .
- If , then .
- For two univariate polynomials p and q over a field, there exist polynomials a and b, such that and divides every such linear combination of p and q (Bézout's identity).
- The greatest common divisor of three or more polynomials may be defined similarly as for two polynomials. It may be computed recursively from GCD's of two polynomials by the identities:
- and
GCD by hand writing computation
There are several ways to find the greatest common divisor of two polynomials. Two of them are:
- Factorization, in which one finds the factors of each expression, then selects the set of common factors held by all from within each set of factors. This method may be useful only in very simple cases, as, like for the integers, factoring is usually much more difficult than computing the greatest common divisor. Moreover, there are fields of coefficient for which there is no factorization algorithm, while Euclidean algorithm always exists.
- The Euclidean algorithm, which can be used to find the GCD of two polynomials in the same manner as for two numbers.
Factoring
To find the GCD of two polynomials using factoring, simply factor the two polynomials completely. Then, take the product of all common factors. At this stage, we do not necessarily have a monic polynomial, so finally multiply this by a constant to make it a monic polynomial. This will be the GCD of the two polynomials as it includes all common divisors and is monic.
Example one: Find the GCD of x2 + 7x + 6 and x2 − 5x − 6.
x2 + 7x + 6 = (x + 1)(x + 6)
x2 − 5x − 6 = (x + 1)(x − 6)
Thus, their GCD is x + 1.
Euclidean algorithm
Factoring polynomials can be difficult, especially if the polynomials have large degree. The Euclidean algorithm is a method which works for any pair of polynomials. It makes repeated use of polynomial long division or synthetic division. When using this algorithm on two numbers, the size of the numbers decreases at each stage. With polynomials, the degree of the polynomials decreases at each stage. The last nonzero remainder, made monic if necessary, is the GCD of the two polynomials.
More specifically, assume we wish to find the gcd of two polynomials a(x) and b(x), where we can suppose
We can find two polynomials q(x) and r(x) which satisfy (see Polynomial long division)
The polynomial q0(x) is called the quotient and r0(x) is the remainder. Notice that a polynomial g(x) divides a(x) and b(x) if and only if it divides b(x) and r0(x). We deduce
- .
Then set
Repeat the Polynomial long division to get new polynomials q1(x), r1(x), a2(x), b2(x) and so on. At each stage we have
so the sequence will eventually reach a point at which
and we will have found our GCD:
Example: Find the GCD of x2 + 7x + 6 and x2 − 5x − 6.
- x2 + 7x + 6 = (x2 − 5x − 6)(1) + (x + 1)(12)
- x2 − 5x − 6 = (x + 1)(x − 6) + 0
Since x + 1 is the last nonzero remainder, the GCD of these polynomials is x + 1.
This method works only if one may test the equality to zero of the elements of the field of the coefficients. Thus, in practice, it works only for polynomials with coefficients in the field of rational numbers, in a finite field or a number field or in the field of rational functions over one of the previous fields.
This induces a new difficulty: For all these fields except the finite ones, the coefficients are fractions. If the fractions are not simplified during the computation, the size of the coefficients grows exponentially during the computation, which makes it impossible except for very small degrees. On the other hand, it is highly time consuming to simplify the fractions immediately. Therefore two different alternative methods have been introduced (see below):
- Pseudo-remainder sequences, especially subresultant sequences.
- Modular GCD algorithm using modular arithmetic
Univariate polynomials with coefficients in a field
The case of univariate polynomials over a field is specially important for several reasons. Firstly, it is the most elementary case and therefore appear in most first courses in algebra. Secondly, it is very similar to the case of the integers, and this analogy is the source of of the notion of Euclidean domain. A third reason is that the theory and the algorithms for the multivariate case and for coefficients in a unique factorization domain are strongly based on this particular case. Last but not least, polynomial GCD and derived algorithms allow to get useful information on the roots of a polynomial, without computing them.
Euclidean division
Euclidean division of polynomials is very similar to Euclidean division of integers. It existence consists in the following theorem: Given two univariate polynomials a and b ≠ 0 defined over a field, there exist two polynomials q, the quotient and r the remainder which satisfy
and
where "deg(...)" denotes the degree and the degree of 0 is defined as negative. Moreover q and r are uniquely defined by these relations.
The difference with Euclidean division of the integers is that, for the integers, the degree is replaced by the absolute value, and that for having the uniqueness one has to suppose that r is non negative. The rings for which such a theorem exists are called Euclidean domains.
Like for the integers, the Euclidean division of the polynomials may be computed by the long division algorithm. This algorithm is usually presented for paper and pencil computation, but it works well on computers, when formalized as follows (note that the names of the variables correspond exactly to the regions of the paper sheet in a pencil and paper computation of long division). In the following computation "deg" stands for the degree of its argument and "lc" stands for the leading coefficient, the coefficient of the highest degree of the variable.
Euclidean division
Input: a and b ≠ 0 two polynomials in the variable x;
Output: q, the quotient and r, the remainder;
Begin
while do
end do;
return (q, r);
end.
The proof of this algorithm relies on the fact that during the whole "while" loop, we have a = bq + r and deg(r) is a non negative integer that decreases at each iteration. Thus the proof of the algorithm proves also the existence of Euclidean division.
Euclid's algorithm
As for the integers, the Euclidean division allows to define Euclid's algorithm for computing GCD's.
Starting from two polynomials a and b, Euclid's algorithm consists in recursively replacing the pair (a, b) by (b, rem(a, b)) (where "rem(a, b)" denotes the remainder of the Euclidean division, computed by the algorithm of the preceding section), until b = 0. The GCD is the last non zero remainder.
Euclid's algorithm may be formalized in the recursive programming style as:
.
In the imperative programming style, the same algorithm becomes, giving a name to each intermediate remainder:
while do
end do;
return
The sequence of the degrees of the ri is strictly decreasing. Thus after, at most, deg(b) steps, one get a null remainder, say rk. As (a, b) and (b, rem(a,b)) have the same divisors, the set of the common divisors is not changed by Euclid's algorithm and thus all pairs (ri, ri + 1) have the same set of common divisors. The common divisors of aand bare thus the common divisors of rk − 1 and 0. Thus rk − 1 is a GCD of aand b. This not only proves that Euclid's algorithm computes GCD's, but proves also that GCD's exists.
Bézout's identity and extended GCD algorithm
Bézout's identity is a GCD related theorem, initially proved for the integers, which is valid for every principal ideal domain. In the case of the univariate polynomials over a field, it may be stated as follows.
If g is the greatest common divisor of two polynomials a and b, then there are two polynomials u and v such that
and
The interest of this result in the case of the polynomials is that there is an efficient algorithm to compute the polynomials u and v, This algorithm differs from Euclid's algorithm by a few more computation done at each iteration of the loop. It is therefore called extended GCD algorithm. Another difference with Euclid's algorithm is that it uses the quotient, denoted "quo", of the Euclidean division instead of the remainder. This algorithm works as follows.
Extended GCD algorithm
Input: a, b,univariate polynomials
Output:
- g,the GCD of a and b
- u, v, such that
- a1, b1, such that
Begin
- while ri ≠ 0 do
- end do;
end.
The proof that the algorithm satisfies its output specification relies on the fact that, for every i we have
the latter equality implying
The assertion on the degrees follows from the fact that, at every iteration, the degrees of si and ti increase at most as the degree of ri decreases.
An interesting feature of this algorithm is that, when the coefficients of Bezout's identity are needed, one gets for free the quotient of the input polynomials by their GCD.
Arithmetic of algebraic extensions
An important application of extended GCD algorithm is that it allows to compute division in algebraic field extensions.
Let L an algebraic extension of a field K, generated by an element whhose minimal polynomial f has degree n. The elements of L are usually represented by univariate polynomials over K of degree less than n.
The addition in L is simply the addition of polynomials:
The multiplication in L is the multiplication of polynomials followed by the division by f:
The inverse of a non zero element a of L is the coefficient u in Bézout's identity au + fv = 1, which may be computed by extended GCD algorithm. (the GCD is 1 because the minimal polynomial f is irreducible). The degrees inequality in the specification of extended GCD algorithm shows that a further division by f is not needed to get deg(u) < deg(f).
Subresultants
In the case of univariate polynomials, there is a strong relationship between greatest common divisors and resultants. In fact the resultant of two polynomials P, Q is a polynomial function of the coefficients of P and Q which has the value zero if and only if the GCD of P and Q is not constant.
The subresultants theory is a generalization of this property that allows to characterize generically the GCD of two polynomials, and the resultant is the 0-th subresultant polynomial.
The i-th subresultant polynomial Si(P ,Q) of two polynomials P and Q is a polynomial of degree at most i whose coefficients are polynomial functions of the coefficients of P and Q, and the i-th principal subresultant coefficient si(P ,Q) is the coefficient of degree i of Si(P, Q). They have the property that the GCD of P and Q has a degree d if and only if
- .
In this case, Sd(P ,Q) is a GCD of P and Q and
Every coefficient of the subresultant polynomials is defined as the determinant of a submatrix of the Sylvester matrix of P and Q. This implies that that subresultants "specialize" well. More precisely, subresultants are defined for polynomials over any commutative ring R, and have the following property.
Let φ be a ring homomorphism of R into another commutative ring S. It extends to another homomorphism, denoted also φ between the polynomials rings over R and S. Then, if P and Q are univariate polynomials with coefficients in R such that
and
then the subresultant polynomials and the principal subresultant coefficients of φ(P) and φ(Q) are the image by φ of those of P and Q.
The subresultants have two important properties whch make them fundamental for the computation on computers of the GCD of two polynomials with integer coefficients. Firstly, their definition through determinants allows to bound, through Hadamard inequality, the size of the coefficients of the GCD. Secondly, this bound and the property of good specialization allow to compute the GCD of two polynomials with integer coefficients through modular computation and Chinese remainder theorem (see below).
Technical definition
Let
be two univariate polynomials with coefficients in a field K. Let us denote by the K vector space of dimension i the polynomials of degree less than i. For non negative integer i such that i≤m and i≤n, let
be the linear map such that
The resultant of P and Q is the determinant of the Sylvester matrix, which is the (square) matrix of on the bases of the powers of X. Similarly, the i-subresultant polynomial is defined in term of determinants of submatrices of the matrix of
Let us describe these matrices more precisely;
Let pi = 0 for i < 0 or i > m, and qi = 0 for i < 0 or i > n. The Sylvester matrix is the (m + n) × (m + n)-matrix such that the coefficient of the i-th row and the j-th column is pm + j - i for j ≤ n and qj - i for j > n:[1]
The matrix Ti of is the (m + n − i) × (m + n − 2i)-submatrix of S which is obtained by removing the last i rows of zeros in the submatrix of the columns 1 to n-i and n+1 to m+n-i of S (that is removing i columns in each block and the i last rows of zeros). The principal subresultant coefficient sij is the determinant of the m + n - 2i first rows of Ti.
Let Vi be the (m + n − 2i) × (m + n − i) matrix defined as follows. First we add (i + 1) columns of zeros to the right of the (m + n - i - 1) × (m + n - i - 1) identity matrix. Then we border the bottom of the resulting matrix by a row consisting in (m + n - i - 1) zeros followed by Xi, Xi − 1, ..., X, 1:
With this notation, the i-th subresultant polynomial is the determinant of the matrix product ViTi. Its coefficient of degree j is the determinant of the square submatrix of Vi consisting in its m + n - 2i - 1 first rows and the (m + n - i - j)-th row.
GCD and root finding
Square-free factorization
Most root-finding algorithms behave badly with polynomials that have multiple roots. It is therefore useful to detect and remove them before calling a root-finding algorithm. A GCD computation allows to detect the existence of multiple roots, because the multiple roots of a polynomial are the roots of the GCD of the polynomial and its derivative.
After computing the GCD of the polynomial and its derivative, further GCD computations provide provide the complete square-free factorization of the polynomial, which is a factorization
where, for each i, the polynomial fi either is 1 if f does not have any root of multiplicity i or is a square-free polynomial (that is a polynomial without multiple root) whose roots are exactly the roots of multiplicity i of f (see Yun's algorithm).
Thus the square-free factorization reduces root finding of a polynomials with multiple roots to root finding of several square-free polynomials of lower degree. The square-free factorization is also the first step in most polynomial factorization algorithms.
Sturm sequence
The Sturm sequence of a polynomial with real coefficients is the sequence of the remainders provided by a variant of Euclid's algorithm applied to the polynomial and its derivative. For getting the Sturm sequence, one simply replaces the instruction
of Euclid's algorithm by
Let V(a) be the number of changes of signs in the sequence, when evaluated at a point a. Sturm's theorem asserts that V(a)-V(b) is the number of real roots of the polynomial in the interval [a,b]. Thus the Sturm sequence allows to compute the number of real roots in a given interval. By subdividing the interval until every subinterval contains at most one root, this provides an algorithm that locates the real roots in intervals of arbitrary small length.
GCD over a ring and over its field of fractions
In this section, we consider polynomials over a unique factorization domain R, typically the ring of the integers, and over its field of fractions F, typically the field of the rational numbers, and we denote R[X] and F[X] the rings of polynomials in a set of variables over these rings.
Primitive part–content factorization
The content of a polynomial p ∈ R[X], denoted "cont(p)", is the GCD of its coefficients. A polynomial q ∈ F[X] may be written
where p ∈ R[X] and c ∈ R: it suffices to take for c a multiple of all denominators of the coefficients of q (for example their product) and p = cq. The content of q is defined as:
In both cases, the content is defined up to the multiplication by a unit of R.
The primitive part of a polynomial in R[X] or F[X] is defined by
In both cases, it is a polynomial in R[X] that is primitive, which means that 1 is a GCD of its coefficients.
Thus every polynomial in R[X] or F[X] may be factorized as
and this factorization is unique up to the multiplication of the content by a unit of R and of the primitive part by the inverse of this unit.
Gauss's lemma implies that the product of two primitive polynomials is primitive. It follows that
and
Relation between the GCD over R and over F
The relations of the preceding section implies a strong relation between the GCD's in R[X] and in F[X]. In order to avoid ambiguities, the notation "gcd" will be indexed, in the following, by the ring in which the GCD is computed.
If q1 and q2 belong to F[X], then
If p1 and p2 belong to R[X], then
and
Thus the computation of polynomial GCD's is essentially the same problem over F[X] and over R[X].
For univariate polynomials over the rational numbers one may think that Euclid's algorithm is a convenient method for computing the GCD. However, it involves to simplify a large number of fractions of integers, and the resulting algorithm is not efficient. For this reason, methods have been designed to modify Euclid's algorithm for working only with polynomials over the integers. They consist in replacing Euclidean division, which introduces fractions, by a so-called pseudo-division, and replacing the remainder sequence of Euclid's algorithm by so-called pseudo-remainder sequences (see below).
Proof that GCD exist for multivariate polynomials
In the previous section we have seen that the GCD of polynomials in R[X] may be deduced from GCD's in R and in F[X]. A closer look on the proof shows that this allows to prove the existence of GCD's in R[X], if they exist in R and in F[X]. In particular, if GCD's exist in R, and if X is reduced to one variable, this proves that GCD's exist in R[X] (Euclid's algorithm proves the existence of GCD's in F[X]).
A polynomial in n variables may be considered as a univariate polynomial over the ring of polynomials in (n − 1) variables. Thus a recursion on the number of variables shows that if GCD's exists and may be computed in R, then they exist and may be computed in every multivariate polynomial rings over R. In particular, if R is either the ring of the integers or a field, then GCD's exist in R[x1,..., xn], and what precedes provides an algorithm to compute them.
The proof that a polynomial ring over a unique factorization domain is also a unique factorization domain is similar, but it does not provides an algorithm, because there is no general algorithm to factorize univariate polynomials over a field (there are examples of fields for which it does not exist any factorization algorithm for the univariate polynomials).
Pseudo-remainder sequences
In this section, we consider an integral domain Z (typically the ring Z of the integers) and its field of fractions Q (typically the field Q of the rational numbers). Given two polynomials A and B in the univariate polynomial ring Z[X], the Euclidean division (over Q) of A by B provides a quotient and a remainder which may not belong to Z[X].
For, if one applies Euclid's algorithm to
and
the successive remainders of Euclid's algorithm are
One sees that, despite the small degree and the small size of the coefficients of the input polynomials, one has to manipulate and simplify integer fractions of rather large size.
The pseudo-division has been introduced to allow a variant of Euclid's algorithm for which all remainders belong to Z[X].
If and and a≥b, the pseudo-remainder of the pseudo-division of A by B, denoted by prem(A,B) is
where lc(B) is the leading coefficient of A (the coefficient of Xb).
The pseudo-remainder of the pseudo-division of two polynomials in Z[X] belongs always to Z[X].
A pseudo-remainder sequence is the sequence of the (pseudo) remainders ri obtained by replacing the instruction
of Euclid's algorithm by
where α is an element of Z that divides exactly every coefficient of the numerator. Different choices of α give different pseudo-remainder sequences, which are described in the next subsections.
As the common divisors of two polynomials are not changed if the polynomials are multiplied by invertible constants (in Q), the last non zero term in a pseudo-remainder sequence is a GCD (in Q[X]) of the input polynomials. Therefore pseudo-remainder sequences allows to compute GCD's in Q[X] without introducing fractions in Q.
Trivial pseudo-remainder sequence
The simplest (to define) remainder sequence consists in taking always α=1. In practice, it is not interesting, as the size of the coefficients grow exponentially with the degree of the input polynomials. This appears clearly on the example of the preceding section, for which the successive pseudo-remainders are
The number of digits of the coefficients of the successive remainders is more than doubled at each iteration of the algorithm. This is a typical behavior of the trivial pseudo-remainder sequences.
Primitive pseudo-remainder sequence
The primitive pseudo-remainder sequence consists in taking for α the content of the numerator. Thus all the ri are primitive polynomials.
The primitive pseudo-remainder sequence is the pseudo-remainder sequence, which generates the smallest coefficients. However it requires to compute a number of GCD's in Z, and therefore is not sufficiently efficient to be used in practice, especially when Z is itself a polynomial ring.
With the same input as in the preceding sections, the successive remainders, after division by their content are
The small size of the coefficients hides the fact that a number of integers GCD and divisions by the GCD have been computed.
Subresultant pseudo-remainder sequence
The subresultant pseudo-remainder sequence consists in choosing α is such a way that every ri is a subresultant polynomial. Surprisingly, the computation of α is very easy (see below). On the other hand the proof of correctness of the algorithm is difficult, because it should take into account all the possibilities for the difference of degrees of two consecutive remainders.
The coefficients in the subresultant pseudo-remainder sequence are rarely much larger than those of the primitive pseudo-remainder sequence. As GCD computations in Z are not needed, the subresultant pseudo-remainder sequence is the pseudo-remainder sequence which gives the most efficient computation.
With the same input as in the preceding sections, the successive remainders are
The coefficients have a reasonable size. They are obtained without any GCD computation, only exact divisions. This makes this algorithm more efficient than that of primitive pseudo-remainder sequences.
The algorithm computing the subresultant pseudo-remainder sequence is given below. In this algorithm, the input (a, b) is a pair of polynomials in Z[X]. The ri are the successive pseudo remainders in Z[X], the variables i and di are non negative integers, and the Greek letters denote elements in Z. The functions deg() and rem() denote the degree of a polynomial and the remainder of the Euclidean division. In the algorithm, this remainder is always in Z[X]. Finally the divisions denoted / are always exact and have their result either in Z[X] or in Z.
while do
end do.
This algorithm computes not only the greatest common divisor (the last non zero ri), but also all the subresultant polynomials: The remainder ri is the (deg(ri-1)-1)-th subresultant polynomial. If deg(ri)<deg(ri-1)-1, the deg(ri)-th subresultant polynomial is lc(ri)deg(ri-1)-deg(ri)-1ri. All the other subresultant polynomials are null.
Modular GCD algorithm
This section needs expansion. You can help by adding to it. (August 2012) |
See also
References
This section needs expansion. You can help by adding to it. (September 2012) |
- ^ Many author define the Sylvester matrix as the transpose of S. This breaks the usual convention for writing the matrix of a linear map.