In algebra, the greatest common divisor (frequently abbreviated GCD or gcd) of two polynomials is a polynomial, of the highest possible degree, which is a factor of both the two original polynomials. This concept is analogous to the greatest common divisor of two integers.

In the important case of univariate polynomials over a field, the polynomial GCD may be computed as for the integer GCD, with the Euclidean algorithm using long division. The polynomial GCD is defined only up to the multiplication by an invertible constant.

The similarity between integer GCD and polynomial GCD allows extending to univariate polynomials all the properties that may be deduced from the Euclidean 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 provides information on the roots without computing them. For example, the multiple roots of a polynomial are the roots of the GCD of the polynomial and its derivative, and further GCD computations allow computing the square-free factorization of the polynomial, which provides polynomials whose roots are the roots of a given multiplicity of the original polynomial.

The greatest common divisor may be defined and exists, more generally, for multivariate polynomials over a field, over the ring of integers, and over any 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 the Euclidean algorithm. They are a fundamental tool in computer algebra, because computer algebra systems use them systematically to simplify fractions: this was the motivation for much of the modern theory of polynomial GCD.

General definition Let and be polynomials with coefficients in an integral domain , typically a field or the integers. A greatest common divisor of and is a polynomial that divides and , and such that every common divisor of and also divides . Every pair of polynomials (not both zero) has a GCD if and only if is a unique factorization domain.

If is a field and and are not both zero, a polynomial is a greatest common divisor if and only if it divides both and , and it has the greatest degree among the polynomials having this property. If , the GCD is 0; however some authors consider that it is not defined in this case.

The greatest common divisor of and is usually denoted .

The greatest common divisor is unique only up to multiplication by an invertible constant. That is, if is a GCD of and , then the polynomial is another GCD if and only if there is an invertible element of such that In the case of the integers, this ambiguity may be removed by choosing the unique positive GCD, rather than its negative. For univariate polynomials over a field, one can instead choose the standard GCD to be the unique monic choice (having leading coefficient 1), but over more general coefficient rings there is no standard choice. Therefore, equalities like or should be understood to mean " is a GCD of and " and " and have the same set of GCDs as and ". In particular, means that the invertible constants are the only common divisors: in this case, by analogy with the ring of integers, one says that and are .

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 is any common divisor of and , then divides their GCD.

for any polynomial . This property is at the basis of the proof of Euclidean algorithm. For any invertible element of the ring of the coefficients, . Hence for any scalars such that is invertible. If , then . If , then . For two univariate polynomials and over a field, there exist polynomials and , such that and divides every such linear combination of and (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 computation There are several ways to find the greatest common divisor of two polynomials. Two of them are:

Factorization of polynomials, 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 simple cases, as factoring is usually more difficult than computing the greatest common divisor. 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 and .

Thus, their GCD is .

Euclidean algorithm Factoring polynomials can be difficult, especially if the polynomials have a large degree. The Euclidean algorithm is a method that works for any pair of polynomials. It makes repeated use of Euclidean 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, for finding the gcd of two polynomials and , one can suppose (otherwise, the GCD is ), and

The Euclidean division provides two polynomials , the quotient and , the remainder such that

A polynomial divides both and if and only if it divides both and . Thus

Setting

one can repeat the Euclidean division to get new polynomials and so on. At each stage we have

so the sequence will eventually reach a point at which

and one has got the GCD:

Example: finding the GCD of and :

Since is the last nonzero remainder, it is a GCD of the original polynomials, and the monic GCD is .

In this example, it is not difficult to avoid introducing denominators by factoring out 12 before the second step. This can always be done by using pseudo-remainder sequences, but, without care, this may introduce very large integers during the computation. Therefore, for computer computation, other algorithms are used, that are described below.

This method works only if one can test the equality to zero of the coefficients that occur during the computation. So, in practice, the coefficients must be integers, rational numbers, elements of a finite field, or must belong to some finitely generated field extension of one of the preceding fields. If the coefficients are floating-point numbers that represent real numbers that are known only approximately, then one must know the degree of the GCD for having a numerically stable result; in this case other techniques may be used, usually based on singular value decomposition.

Univariate polynomials with coefficients in a field

The basic case of univariate polynomials over a field is especially important. It is the simplest example beyond the ring of integers, and this analogy is the source of the notion of Euclidean domain. The theory and algorithms for the multivariate case and for coefficients in a unique factorization domain depend heavily on the basic case. Polynomial GCD algorithms and derived algorithms allow one to get useful information on the roots of a polynomial, without computing them.

Euclidean division Euclidean division of polynomials, which is used in Euclid's algorithm for computing GCDs, is very similar to Euclidean division of integers. Its existence is based on the following theorem: Given two univariate polynomials and defined over a field, there exist two polynomials (the quotient) and (the remainder) which satisfy

and

where "" denotes the degree and the degree of the zero polynomial is defined as being negative. Moreover, q and r are uniquely defined by these relations.

The difference from Euclidean division of the integers is that, for the integers, the degree is replaced by the absolute value, and that to have 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 (with the convention ), 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 q := 0 r := a d := deg(b) c := lc(b) while deg(r) ≥ d do s := (lc(r)/c) ⋅ x q := q + s r := r − sb end do return (q, r) end

The proof of the validity of this algorithm relies on the fact that during the whole "while" loop, we have and is a non-negative integer that decreases at each iteration. Thus the proof of the validity of this algorithm also proves the validity of the Euclidean division.

Euclid's algorithm As for the integers, the Euclidean division allows us to define Euclid's algorithm for computing GCDs.

Starting from two polynomials a and b, Euclid's algorithm consists of recursively replacing the pair by (where "" 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:

end do

The sequence of the degrees of the is strictly decreasing. Thus after, at most, steps, one get a null remainder, say . As and have the same divisors, the set of the common divisors is not changed by Euclid's algorithm and thus all pairs have the same set of common divisors. The common divisors of and are thus the common divisors of and 0. Thus is a GCD of and . This not only proves that Euclid's algorithm computes GCDs but also proves that GCDs exist.

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.

The interest of this result in the case of the polynomials is that there is an efficient algorithm to compute the polynomials and . This algorithm differs from Euclid's algorithm by a few more computations done at each iteration of the loop. It is therefore called extended GCD algorithm. Another difference with Euclid's algorithm is that it also uses the quotient, denoted "quo", of the Euclidean division instead of only 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, as in above statement a1, b1, such that

Begin (r0, r1) := (a, b) (s0, s1) := (1, 0) (t0, t1) := (0, 1)

for (i := 1; ri ≠ 0; i := i+1) do

ri+1 := ri−1 − qri si+1 := si−1 − qsi ti+1 := ti−1 − qti end do g := ri−1 u := si−1 v := ti−1 a1 := (−1)i−1 ti b1 := (−1)i si End

The proof that the algorithm satisfies its output specification relies on the fact that, for every we have