Polynomial greatest common divisor

In algebra, the greatest common divisor (frequently abbreviated as GCD) of two polynomials is a polynomial, of the highest possible degree, that 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, like for the integer GCD, by the Euclidean algorithm using long division. The polynomial GCD is defined only up to the multiplication by an invertible constant.

The similarity between the integer GCD and the 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 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 the Euclidean 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 for 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 (not both zero) 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, a polynomial $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 $$f=u d$$ and $$d=u^{-1} f.$$ 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. However, since there is no natural total order for polynomials over an integral domain, one cannot proceed in the same way here. For univariate polynomials over a field, one can additionally require the GCD to be monic (that is to have 1 as its coefficient of the highest degree), but in more general cases there is no general convention. Therefore, equalities like $d = gcd(p, q)$ or $gcd(p, q) = gcd(r, s)$ are common abuses of notation which should be read "$d$ is a GCD of $p$ and $q$" and "$p$ and $q$ have the same set of GCDs as $r$ and $s$". In particular, $gcd(p, q) = 1$ means that the invertible constants are the only common divisors. In this case, by analogy with the integer case, one says that $p$ and $q$ are coprime polynomials.

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.
 * $$\gcd(p,q)= \gcd(q,p).$$
 * $$\gcd(p, q)= \gcd(q,p+rq)$$ for any polynomial $r$. This property is at the basis of the proof of Euclidean algorithm.
 * For any invertible element $k$ of the ring of the coefficients, $$\gcd(p,q)=\gcd(p,kq)$$.
 * Hence $$\gcd(p,q)=\gcd(a_1p+b_1q,a_2p+b_2q)$$ for any scalars $$a_1, b_1, a_2, b_2$$ such that $$a_1 b_2 - a_2 b_1$$ is invertible.
 * If $$\gcd(p, r)=1$$, then $$\gcd(p, q)=\gcd(p, qr)$$.
 * If $$\gcd(q, r)=1$$, then $$\gcd(p, qr)=\gcd(p, q)\,\gcd(p, r)$$.
 * For two univariate polynomials $p$ and $q$ over a field, there exist polynomials $a$ and $b$, such that $$\gcd(p,q)=ap+bq$$ and $$\gcd(p,q)$$ 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: $$\gcd(p, q, r) = \gcd(p, \gcd(q, r)),$$ and $$\gcd(p_1, p_2, \dots, p_n) = \gcd( p_1, \gcd(p_2, \dots , p_n)).$$

GCD by hand computation
There are several ways to find the greatest common divisor of two polynomials. Two of them are:


 * 1) 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.
 * 2) 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 $x^{2} + 7x + 6$ and $x^{2} − 5x − 6$.

Thus, their GCD is $x^{2} + 7x + 6 = (x + 1)(x + 6)$.

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 $x^{2} − 5x − 6 = (x + 1)(x − 6)$ and $x + 1$, one can suppose $a(x)$ (otherwise, the GCD is $b(x)$), and $$\deg(b(x)) \le \deg(a(x)) \,.$$

The Euclidean division provides two polynomials $b ≠ 0$, the quotient and $a(x)$, the remainder such that $$a(x) = q_0(x) b(x) + r_0(x) \quad \text{and} \quad \deg(r_0(x)) < \deg(b(x))$$

A polynomial $q(x)$ divides both $r(x)$ and $g(x)$ if and only if it divides both $a(x)$ and $b(x)$. Thus $$\gcd(a(x), b(x)) = \gcd(b(x), r_0(x)).$$ Setting $$a_1(x) = b(x), b_1(x) = r_0(x),$$ one can repeat the Euclidean division to get new polynomials $b(x)$ and so on. At each stage we have $$\deg(a_{k+1})+\deg(b_{k+1}) < \deg(a_{k})+\deg(b_{k}),$$ so the sequence will eventually reach a point at which $$b_N(x) = 0$$ and one has got the GCD: $$\gcd(a,b) = \gcd(a_1,b_1) = \cdots = \gcd(a_N, 0) = a_N .$$

Example: finding the GCD of $r_{0}(x)$ and $q_{1}(x), r_{1}(x), a_{2}(x), b_{2}(x)$:

Since $x^{2} + 7x + 6$ is the last nonzero remainder, it is a GCD of the original polynomials, and the monic GCD is $x^{2} − 5x − 6$.

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 well defined computation result (that is a numerically stable result; in this cases other techniques may be used, usually based on singular value decomposition.

Univariate polynomials with coefficients in a field
The case of univariate polynomials over a field is especially important for several reasons. Firstly, it is the most elementary case and therefore appears in most first courses in algebra. Secondly, it is very similar to the case of the integers, and this analogy is the source 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 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 a and b ≠ 0 defined over a field, there exist two polynomials q (the quotient) and r (the remainder) which satisfy $$a = bq + r$$ and $$\deg(r) < \deg(b),$$ where "$x^{2} + 7x + 6 = 1 ⋅ (x^{2} − 5x − 6) + (12 x + 12)$" 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 deg(0) &lt; 0), 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) &sdot; x$deg(r)−d$ 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 $x^{2} − 5x − 6 = (12 x + 12) (1⁄12 x − 1⁄2) + 0$ and $12 x + 12$ 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 $x + 1$ by $deg(...)$ (where "$a = bq + r$" 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: $$\gcd(a,b):= \begin{cases} a & \text{if } b = 0 \\ \gcd(b, \operatorname{rem}(a,b)) & \text{otherwise}. \end{cases}$$

In the imperative programming style, the same algorithm becomes, giving a name to each intermediate remainder: r0 := a r1 := b

for (i := 1; ri ≤ 0; i := i + 1) do  ri+1 := rem(ri−1, ri) end do

return ri-1.

The sequence of the degrees of the $deg(r)$ is strictly decreasing. Thus after, at most, $(a, b)$ steps, one get a null remainder, say $(b, rem(a, b))$. As $rem(a, b)$ and $r_{i}$ have the same divisors, the set of the common divisors is not changed by Euclid's algorithm and thus all pairs $deg(b)$ have the same set of common divisors. The common divisors of $a$ and $b$ are thus the common divisors of $r_{k}$ and 0. Thus $(a, b)$ is a GCD of $a$ and $b$. 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 $g$ and $a$, 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 a = g a1       b = g b1 Begin (r0, r1) := (a, b)   (s0, s1) := (1, 0) (t0, t1) := (0, 1) for (i := 1; ri ≠ 0; i := i+1) do       q := quo(ri−1, ri) 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 ti End

The proof that the algorithm satisfies its output specification relies on the fact that, for every $b$ we have $$r_i = a s_i + b t_i$$ $$s_i t_{i+1} - t_i s_{i+1} = s_i t_{i-1} - t_i s_{i-1},$$ the latter equality implying $$s_i t_{i+1} - t_i s_{i+1} = (-1)^i.$$ The assertion on the degrees follows from the fact that, at every iteration, the degrees of $(b, rem(a,b))$ and $(r_{i}, r_{i+1})$ increase at most as the degree of $r_{k−1}$ 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 the extended GCD algorithm is that it allows one to compute division in algebraic field extensions.

Let $u$ an algebraic extension of a field $v$, generated by an element whose minimal polynomial $u$ has degree $v$. The elements of $i$ are usually represented by univariate polynomials over $L$ of degree less than $K$.

The addition in $f$ is simply the addition of polynomials: $$a+_Lb=a+_{K[X]}b.$$

The multiplication in $n$ is the multiplication of polynomials followed by the division by $L$: $$a\cdot_Lb=\operatorname{rem}(a._{K[X]}b,f).$$

The inverse of a non zero element $K$ of $n$ is the coefficient $L$ in Bézout's identity $r_{k−1}$, which may be computed by extended GCD algorithm. (the GCD is 1 because the minimal polynomial $L$ 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($a$) < deg($L$).

Subresultants
In the case of univariate polynomials, there is a strong relationship between the greatest common divisors and resultants. More precisely, 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 characterizing generically the GCD of two polynomials, and the resultant is the 0-th subresultant polynomial.

The $u$-th subresultant polynomial $u = 1, v = 0$ of two polynomials $u = 0, v = 1$ and $s_{i}$ is a polynomial of degree at most $f$ whose coefficients are polynomial functions of the coefficients of $t_{i}$ and $r_{i}$, and the $f$-th principal subresultant coefficient $au + fv = 1$ is the coefficient of degree $u$ of $S_{i}(P ,Q)$. They have the property that the GCD of $P$ and $Q$ has a degree $f$ if and only if $$s_0(P,Q) = \cdots = s_{d-1}(P,Q) =0 \, s_d(P,Q)\neq 0.$$

In this case, $P$ is a GCD of $Q$ and $s_{i}(P ,Q)$ and $$S_0(P,Q)=\cdots=S_{d-1}(P,Q) =0.$$

Every coefficient of the subresultant polynomials is defined as the determinant of a submatrix of the Sylvester matrix of $S_{i}(P, Q)$ and $P$. This implies that subresultants "specialize" well. More precisely, subresultants are defined for polynomials over any commutative ring R, and have the following property.

Let $Q$ be a ring homomorphism of $S_{d}(P ,Q)$ into another commutative ring $P$. It extends to another homomorphism, denoted also $Q$ between the polynomials rings over $P$ and $Q$. Then, if $φ$ and $R$ are univariate polynomials with coefficients in $S$ such that $$\deg(P)=\deg(\varphi(P))$$ and $$\deg(Q)=\deg(\varphi(Q)),$$ then the subresultant polynomials and the principal subresultant coefficients of $φ$ and $R$ are the image by $S$ of those of $P$ and $Q$.

The subresultants have two important properties which make them fundamental for the computation on computers of the GCD of two polynomials with integer coefficients. Firstly, their definition through determinants allows bounding, through Hadamard inequality, the size of the coefficients of the GCD. Secondly, this bound and the property of good specialization allow computing the GCD of two polynomials with integer coefficients through modular computation and Chinese remainder theorem (see below).

Technical definition
Let $$P=p_0+p_1 X+\cdots +p_m X^m,\quad Q=q_0+q_1 X+\cdots +q_n X^n.$$ be two univariate polynomials with coefficients in a field K. Let us denote by $$\mathcal{P}_i$$ the $R$ vector space of dimension $i$ of polynomials of degree less than $i$. For non-negative integer $i$ such that $φ(P)$ and $φ(Q)$, let $$\varphi_i:\mathcal{P}_{n-i} \times \mathcal{P}_{m-i} \rightarrow \mathcal{P}_{m+n-i}$$ be the linear map such that $$\varphi_i(A,B) = AP + BQ.$$

The resultant of $φ$ and $P$ is the determinant of the Sylvester matrix, which is the (square) matrix of $$\varphi_0$$ on the bases of the powers of $Q$. Similarly, the $K$-subresultant polynomial is defined in term of determinants of submatrices of the matrix of $$\varphi_i.$$

Let us describe these matrices more precisely;

Let $i ≤ m$ for $i ≤ n$ or $P$, and $Q$ for $X$ or $i$. The Sylvester matrix is the $p_{i} = 0$-matrix such that the coefficient of the $i < 0$-th row and the $i > m$-th column is $q_{i} = 0$ for $i < 0$ and $i > n$ for $(m + n) × (m + n)$: $$S=\begin{pmatrix} p_m    & 0       & \cdots & 0       & q_n     & 0       & \cdots & 0 \\ p_{m-1} & p_m    & \cdots & 0       & q_{n-1} & q_n     & \cdots & 0 \\ p_{m-2} & p_{m-1} & \ddots & 0      & q_{n-2} & q_{n-1} & \ddots & 0 \\ \vdots &\vdots   & \ddots & p_m     & \vdots  &\vdots   & \ddots & q_n \\ \vdots &\vdots   & \cdots & p_{m-1} & \vdots  &\vdots   & \cdots & q_{n-1} \\ p_0    & p_1     & \cdots & \vdots  & q_0     & q_1     & \cdots & \vdots \\ 0      & p_0     & \ddots &  \vdots & 0       & q_0     & \ddots & \vdots \\ \vdots & \vdots  & \ddots & p_1     & \vdots  & \vdots  & \ddots & q_1 \\ 0      & 0       & \cdots & p_0     & 0       & 0       & \cdots & q_0 \end{pmatrix}.$$

The matrix $i$ of $$\varphi_i$$ is the $j$-submatrix of $p_{m+j−i}$ which is obtained by removing the last $j ≤ n$ rows of zeros in the submatrix of the columns 1 to $q_{j−i}$ and $j > n$ to $S$ of $T_{i}$ (that is removing $(m + n − i) × (m + n − 2i)$ columns in each block and the $S$ last rows of zeros). The principal subresultant coefficient $i$ is the determinant of the $n − i$ first rows of $n + 1$.

Let $m + n − i$ be the $S$ matrix defined as follows. First we add $i$ columns of zeros to the right of the $i$ identity matrix. Then we border the bottom of the resulting matrix by a row consisting in $s_{i}$ zeros followed by $m + n − 2i$: $$V_i=\begin{pmatrix} 1      & 0      & \cdots & 0       & 0       & 0       & \cdots & 0 \\ 0      & 1      & \cdots & 0       & 0       & 0       & \cdots & 0 \\ \vdots &\vdots  & \ddots & \vdots  & \vdots  &\ddots   & \vdots & 0 \\ 0      & 0      & \cdots & 1       & 0       & 0       & \cdots & 0 \\ 0      & 0      & \cdots & 0       & X^i     & X^{i-1} & \cdots & 1 \end{pmatrix}.$$

With this notation, the $T_{i}$-th subresultant polynomial is the determinant of the matrix product $V_{i}$. Its coefficient of degree $(m + n − 2i) × (m + n − i)$ is the determinant of the square submatrix of Ti consisting in its $(i + 1)$ first rows and the $(m + n − 2i − 1) × (m + n − 2i − 1)$-th row.

Sketch of the proof
It is not obvious that, as defined, the subresultants have the desired properties. Nevertheless, the proof is rather simple if the properties of linear algebra and those of polynomials are put together.

As defined, the columns of the matrix $(m + n − i − 1)$ are the vectors of the coefficients of some polynomials belonging to the image of $$\varphi_i$$. The definition of the $X^{i}, X^{i−1}, ..., X, 1$-th subresultant polynomial $i$ shows that the vector of its coefficients is a linear combination of these column vectors, and thus that Si belongs to the image of $$\varphi_i.$$

If the degree of the GCD is greater than $V_{i}T_{i}$, then Bézout's identity shows that every non zero polynomial in the image of $$\varphi_i$$ has a degree larger than $j$. This implies that $m + n − 2i − 1$.

If, on the other hand, the degree of the GCD is $(m + n − i − j)$, then Bézout's identity again allows proving that the multiples of the GCD that have a degree lower than $T_{i}$ are in the image of $$\varphi_i$$. The vector space of these multiples has the dimension $i$ and has a base of polynomials of pairwise different degrees, not smaller than $S_{i}$. This implies that the submatrix of the $i$ first rows of the column echelon form of $i$ is the identity matrix and thus that $S_{i} = 0$ is not 0. Thus $i$ is a polynomial in the image of $$\varphi_i$$, which is a multiple of the GCD and has the same degree. It is thus a greatest common divisor.

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 detection of the existence of multiple roots, since 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 the complete square-free factorization of the polynomial, which is a factorization $$f = \prod_{i=1}^{\deg(f)} f_i^i$$ where, for each $m + n − i$, the polynomial $m + n − 2i$ either is 1 if $i$ does not have any root of multiplicity $m + n − 2i$ or is a square-free polynomial (that is a polynomial without multiple root) whose roots are exactly the roots of multiplicity $T_{i}$ of $s_{i}$ (see Yun's algorithm).

Thus the square-free factorization reduces root-finding of a polynomial 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 $$r_{i+1} := \operatorname{rem}(r_{i-1},r_{i})$$ of Euclid's algorithm by $$r_{i+1} := -\operatorname{rem}(r_{i-1},r_{i}).$$

Let $S_{i}$ be the number of changes of signs in the sequence, when evaluated at a point $i$. Sturm's theorem asserts that $f_{i}$ is the number of real roots of the polynomial in the interval $f$. Thus the Sturm sequence allows computing 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 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 $i$, denoted "$i$", is the GCD of its coefficients. A polynomial $f$ may be written $$q = \frac{p}{c}$$ where $V(a)$ and $a$: it suffices to take for $V(a) − V(b)$ a multiple of all denominators of the coefficients of $[a, b]$ (for example their product) and $p ∈ R[X]$. The content of $cont(p)$ is defined as: $$\operatorname{cont} (q) = \frac{\operatorname{cont} (p)}{c}.$$ In both cases, the content is defined up to the multiplication by a unit of $q ∈ F[X]$.

The primitive part of a polynomial in $p ∈ R[X]$ or $c ∈ R$ is defined by $$\operatorname{primpart} (p) =\frac{p}{\operatorname{cont} (p)}.$$

In both cases, it is a polynomial in $c$ that is primitive, which means that 1 is a GCD of its coefficients.

Thus every polynomial in $q$ or $p = cq$ may be factorized as $$p = \operatorname{cont} (p)\,\operatorname{primpart} (p),$$ and this factorization is unique up to the multiplication of the content by a unit of $q$ 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 $$\operatorname{primpart} (pq)=\operatorname{primpart} (p) \operatorname{primpart}(q)$$ and $$\operatorname{cont} (pq)=\operatorname{cont} (p) \operatorname{cont}(q).$$

Relation between the GCD over R and over F
The relations of the preceding section imply a strong relation between the GCD's in $R$ and in $R[X]$. To avoid ambiguities, the notation "gcd" will be indexed, in the following, by the ring in which the GCD is computed.

If $F[X]$ and $R[X]$ belong to $R[X]$, then $$\operatorname{primpart}(\gcd_{F[X]}(q_1,q_2))=\gcd_{R[X]}(\operatorname{primpart}(q_1),\operatorname{primpart}(q_2)).$$

If $F[X]$ and $R$ belong to $R[X]$, then $$\gcd_{R[X]}(p_1,p_2)=\gcd_R(\operatorname{cont}(p_1),\operatorname{cont}(p_2)) \gcd_{R[X]}(\operatorname{primpart}(p_1),\operatorname{primpart}(p_2)),$$ and $$\gcd_{R[X]}(\operatorname{primpart}(p_1),\operatorname{primpart}(p_2))=\operatorname{primpart}(\gcd_{F[X]}(p_1,p_2)).$$

Thus the computation of polynomial GCD's is essentially the same problem over $F[X]$ and over $q_{1}$.

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 simplifying 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 of replacing the Euclidean division, which introduces fractions, by a so-called pseudo-division, and replacing the remainder sequence of the Euclid's algorithm by so-called pseudo-remainder sequences (see below).

Proof that GCD exists for multivariate polynomials
In the previous section we have seen that the GCD of polynomials in $q_{2}$ may be deduced from GCDs in $F[X]$ and in $p_{1}$. A closer look on the proof shows that this allows us to prove the existence of GCDs in $p_{2}$, if they exist in $R[X]$ and in $F[X]$. In particular, if GCDs exist in $R[X]$, and if $R[X]$ is reduced to one variable, this proves that GCDs exist in $R$ (Euclid's algorithm proves the existence of GCDs in $F[X]$).

A polynomial in $i$ variables may be considered as a univariate polynomial over the ring of polynomials in ($R[X]$) variables. Thus a recursion on the number of variables shows that if GCDs exist and may be computed in $R$, then they exist and may be computed in every multivariate polynomial ring over $F[X]$. In particular, if $R$ is either the ring of the integers or a field, then GCDs exist in $X$, 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 provide an algorithm, because there is no general algorithm to factor univariate polynomials over a field (there are examples of fields for which there does not exist any factorization algorithm for the univariate polynomials).

Pseudo-remainder sequences
In this section, we consider an integral domain $R[X]$ (typically the ring $F[X]$ of the integers) and its field of fractions $n − 1$ (typically the field $R$ of the rational numbers). Given two polynomials $R$ and $R$ in the univariate polynomial ring $R[x_{1}, ..., x_{n}]$, the Euclidean division (over $Z$) of $Z$ by $Q$ provides a quotient and a remainder which may not belong to $Q$.

For, if one applies Euclid's algorithm to the following polynomials $$X^8 + X^6 - 3 X^4 - 3 X^3 + 8 X^2 + 2 X - 5$$ and $$3 X^6 + 5 X^4 - 4 X^2 - 9 X + 21,$$ the successive remainders of Euclid's algorithm are $$\begin{align} &-\tfrac{5}{9}X^4+\tfrac{1}{9}X^2-\tfrac{1}{3},\\ &-\tfrac{117}{25}X^2-9X+\tfrac{441}{25},\\ &\tfrac{233150}{19773}X-\tfrac{102500}{6591},\\ &-\tfrac{1288744821}{543589225}. \end{align}$$ 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-remainder has been introduced to allow a variant of Euclid's algorithm for which all remainders belong to $A$.

If $$\deg(A) = a$$ and $$\deg(B) = b$$ and $B$, the pseudo-remainder of the pseudo-division of $Z[X]$ by $Q$, denoted by $A$ is $$\operatorname{prem}(A,B) = \operatorname{rem}(\operatorname{lc}(B)^{a-b+1}A,B),$$ where $B$ is the leading coefficient of $Z[X]$ (the coefficient of $Z[X]$).

The pseudo-remainder of the pseudo-division of two polynomials in $a ≥ b$ belongs always to $A$.

A pseudo-remainder sequence is the sequence of the (pseudo) remainders $B$ obtained by replacing the instruction $$r_{i+1}:=\operatorname{rem}(r_{i-1},r_{i})$$ of Euclid's algorithm by $$r_{i+1}:=\frac{\operatorname{prem}(r_{i-1},r_{i})}{\alpha},$$ where $prem(A,B)$ is an element of $lc(B)$ that divides exactly every coefficient of the numerator. Different choices of $B$ 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 $X^{b}$), the last nonzero term in a pseudo-remainder sequence is a GCD (in $Z[X]$) of the input polynomials. Therefore, pseudo-remainder sequences allows computing GCD's in $Z[X]$ without introducing fractions in $r_{i}$.

In some contexts, it is essential to control the sign of the leading coefficient of the pseudo-remainder. This is typically the case when computing resultants and subresultants, or for using Sturm's theorem. This control can be done either by replacing $α$ by its absolute value in the definition of the pseudo-remainder, or by controlling the sign of $d$ (if $i$ divides all coefficients of a remainder, the same is true for $Z$).

Trivial pseudo-remainder sequence
The simplest (to define) remainder sequence consists in taking always $α$. In practice, it is not interesting, as the size of the coefficients grows 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 $$-15\, X^4 + 3\, X^2 - 9,$$ $$15795\, X^2 + 30375\, X - 59535,$$ $$1254542875143750\, X - 1654608338437500,$$ $$12593338795500743100931141992187500.$$ The number of digits of the coefficients of the successive remainders is more than doubled at each iteration of the algorithm. This is typical behavior of the trivial pseudo-remainder sequences.

Primitive pseudo-remainder sequence
The primitive pseudo-remainder sequence consists in taking for $i$ the content of the numerator. Thus all the $Q$ 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 $Q[X]$, 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 $$-5\,X^4+X^2-3,$$ $$13\,X^2+25\,X-49,$$ $$4663\,X-6150,$$ $$1.$$ 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
A subresultant sequence can be also computed with pseudo-remainders. The process consists in choosing $i$ in such a way that every $Q[X]$ is a subresultant polynomial. Surprisingly, the computation of $n$ 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 sequence are rarely much larger than those of the primitive pseudo-remainder sequence. As GCD computations in $Q$ are not needed, the subresultant sequence with pseudo-remainders gives the most efficient computation.

With the same input as in the preceding sections, the successive remainders are $$15\,X^4-3\,X^2+9,$$ $$65\,X^2+125\,X-245,$$ $$9326\,X-12300,$$ $$260708.$$ 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 sequence with pseudo-remainders is given below. In this algorithm, the input $lc(B)$ is a pair of polynomials in $−α$. The $α = 1$ are the successive pseudo remainders in $r_{i}$, the variables $Z$ and $r_{i}$ are non negative integers, and the Greek letters denote elements in $Z$. The functions  and   denote the degree of a polynomial and the remainder of the Euclidean division. In the algorithm, this remainder is always in $(a, b)$. Finally the divisions denoted / are always exact and have their result either in $Z[X]$ or in $r_{i}$.

r0 := a r1 := b for (i := 1; ri ≠ 0; i := i+1) do  di := deg(ri−1) − deg(ri) γi := lc(ri) if i = 1 then β1 := (−1)d1+1 ψ1 := −1 else ψi := (−γi−1)di−1 / ψi−1di−1−1 βi := −γi−1ψidi end if   ri+1 := rem(γidi+1 ri−1, ri) / βi end for Note: "lc" stands for the leading coefficient, the coefficient of the highest degree of the variable.

This algorithm computes not only the greatest common divisor (the last non zero $Z[X]$), but also all the subresultant polynomials: The remainder $i$ is the $d_{i}$-th subresultant polynomial. If $Z$, the $Z[X]$-th subresultant polynomial is $Z[X]$. All the other subresultant polynomials are zero.

Sturm sequence with pseudo-remainders
One may use pseudo-remainders for constructing sequences having the same properties as Sturm sequences. This requires to control the signs of the successive pseudo-remainders, in order to have the same signs as in the Sturm sequence. This may be done by defining a modified pseudo-remainder as follows.

If $$\deg(A) = a$$ and $$\deg(B) = b$$ and $Z$, the modified pseudo-remainder $r_{i}$ of the pseudo-division of $r_{i}$ by $(deg(r_{i−1}) − 1)$ is $$\operatorname{prem2}(A,B) = -\operatorname{rem}(\left|\operatorname{lc}(B)\right|^{a-b+1}A,B),$$ where $deg(r_{i}) < deg(r_{i−1}) − 1$ is the absolute value of the leading coefficient of $deg(r_{i})$ (the coefficient of $lc(r_{i})^{deg(r_{i−1})−deg(r_{i})−1}r_{i}$).

For input polynomials with integer coefficients, this allows retrieval of Sturm sequences consisting of polynomials with integer coefficients. The subresultant pseudo-remainder sequence may be modified similarly, in which case the signs of the remainders coincide with those computed over the rationals.

Note that the algorithm for computing the subresultant pseudo-remainder sequence given above will compute wrong subresultant polynomials if one uses $$-\mathrm{prem2}(A,B)$$ instead of $$\operatorname{prem}(A,B)$$.

Modular GCD algorithm
If $a ≥ b$ and $prem2(A, B)$ are polynomials in $A$ for some finitely generated field $B$, the Euclidean Algorithm is the most natural way to compute their GCD. However, modern computer algebra systems only use it if $|lc(B)|$ is finite because of a phenomenon called intermediate expression swell. Although degrees keep decreasing during the Euclidean algorithm, if $B$ is not finite then the bit size of the polynomials can increase (sometimes dramatically) during the computations because repeated arithmetic operations in $X^{b}$ tends to lead to larger expressions. For example, the addition of two rational numbers whose denominators are bounded by $f$ leads to a rational number whose denominator is bounded by $g$, so in the worst case, the bit size could nearly double with just one operation.

To expedite the computation, take a ring $F[x]$ for which $F$ and $F$ are in $F$, and take an ideal $F$ such that $b$ is a finite ring. Then compute the GCD over this finite ring with the Euclidean Algorithm. Using reconstruction techniques (Chinese remainder theorem, rational reconstruction, etc.) one can recover the GCD of $b^{2}$ and $D$ from its image modulo a number of ideals $f$. One can prove that this works provided that one discards modular images with non-minimal degrees, and avoids ideals $g$ modulo which a leading coefficient vanishes.

Suppose $$F = \mathbb{Q}(\sqrt{3})$$, $$D = \mathbb{Z}[\sqrt{3}]$$, $$f = \sqrt{3}x^3 - 5 x^2 + 4x + 9$$ and $$g = x^4 + 4 x^2 + 3\sqrt{3}x - 6$$. If we take $$I = (2)$$ then $$D/I$$ is a finite ring (not a field since $$I$$ is not maximal in $$D$$). The Euclidean algorithm applied to the images of $$f,g$$ in $$(D/I)[x]$$ succeeds and returns 1. This implies that the GCD of $$f,g$$ in $$F[x]$$ must be 1 as well. Note that this example could easily be handled by any method because the degrees were too small for expression swell to occur, but it illustrates that if two polynomials have GCD 1, then the modular algorithm is likely to terminate after a single ideal $$I$$.