Algorithm Search⌘K

Proofs: Polynomial Euclidean algorithm

These are the human proofs of Polynomial Euclidean algorithm, at full length.

The Euclidean algorithm returns the monic gcd full

This proof shows: correctness.

Let FF be a field and f,g∈F[x]f, g \in F[x]. For a,b∈F[x]a, b \in F[x] let D(a,b)D(a, b) be the set of common divisors of aa and bb in F[x]F[x].

Lemma. If b≠0b \ne 0 and a=qb+ca = q b + c, then D(a,b)=D(b,c)D(a, b) = D(b, c).

Proof. If d∣ad \mid a and d∣bd \mid b, then d∣a−qb=cd \mid a - q b = c. If d∣bd \mid b and d∣cd \mid c, then d∣qb+c=ad \mid q b + c = a. □\square

Invariant. Before each test of line L2, D(r0,r1)=D(f,g)D(r_0, r_1) = D(f, g).

Initialization. Line L1 only strips zero coefficients, which does not change the polynomials, so r0=fr_0 = f and r1=gr_1 = g.

Maintenance. Line L3 runs only when r1≠0r_1 \ne 0. Over a field, lc⁡(r1)\operatorname{lc}(r_1) is a unit, so long division gives r0=qr1+cr_0 = q r_1 + c with c=r0rem⁡r1c = r_0 \operatorname{rem} r_1 and deg⁡c<deg⁡r1\deg c < \deg r_1 (see the proof for long division). By the lemma, D(r1,c)=D(r0,r1)=D(f,g)D(r_1, c) = D(r_0, r_1) = D(f, g), and the new pair is (r1,c)(r_1, c).

Termination. Let dtd_t be deg⁡r1\deg r_1 before the tt-th test of line L2, with deg⁡0=−∞\deg 0 = -\infty. While the loop runs, r1≠0r_1 \ne 0, so dt≥0d_t \ge 0, and line L3 gives dt+1=deg⁡(r0rem⁡r1)<dtd_{t+1} = \deg(r_0 \operatorname{rem} r_1) < d_t. A strictly decreasing sequence of integers that are at least 00 has at most d1+1d_1 + 1 terms, so after at most deg⁡g+1\deg g + 1 passes the new remainder is 00 and the loop stops. If g=0g = 0, it stops at once.

Result. When the loop stops, r1=0r_1 = 0 and D(f,g)=D(r0,0)D(f, g) = D(r_0, 0), the set of divisors of r0r_0.

  • If r0=0r_0 = 0, every polynomial is in D(f,g)D(f, g), so f=g=0f = g = 0, and line L4 returns 0=gcd⁡(0,0)0 = \gcd(0, 0).
  • If r0≠0r_0 \ne 0, then r0r_0 divides itself, so r0∈D(f,g)r_0 \in D(f, g), and every d∈D(f,g)d \in D(f, g) divides r0r_0. So r0r_0 is a gcd of ff and gg. Lines L5 and L6 multiply it by the unit u=lc⁡(r0)−1u = \operatorname{lc}(r_0)^{-1}, which does not change the set of its divisors or of its multiples, and give a gcd with leading coefficient ulc⁡(r0)=1u \operatorname{lc}(r_0) = 1. The monic gcd is unique, since two gcds divide each other and so differ by a unit factor, and only one unit multiple is monic.

So EUCLID(f,g)(f, g) returns the monic gcd⁡(f,g)\gcd(f, g).

Cost. Let m=deg⁡f≥n=deg⁡g≥0m = \deg f \ge n = \deg g \ge 0 and let n1=n>n2>⋯>nℓ≥0n_1 = n > n_2 > \cdots > n_\ell \ge 0 be the degrees of the nonzero remainders r1=g,r2,…,rℓr_1 = g, r_2, \ldots, r_\ell, with n0=mn_0 = m. The pass that divides ri−1r_{i-1} by rir_i costs at most (2ni+1)(ni−1−ni+1)(2 n_i + 1)(n_{i-1} - n_i + 1) field operations and one inversion, by the count for long division. Since 2ni+1≤2n+12 n_i + 1 \le 2n + 1 and ∑i=1ℓ(ni−1−ni+1)=n0−nℓ+ℓ\sum_{i=1}^{\ell} (n_{i-1} - n_i + 1) = n_0 - n_\ell + \ell, the passes cost at most (2n+1)(m−nℓ+ℓ)(2n + 1)(m - n_\ell + \ell). The degrees n1,…,nℓn_1, \ldots, n_\ell are distinct integers in [0,n][0, n], so ℓ≤n+1\ell \le n + 1, and nℓ≥0n_\ell \ge 0. This gives at most (2n+1)(m+n+1)(2n + 1)(m + n + 1) operations and n+1n + 1 inversions for the loop. Lines L5 and L6 add one inversion and nℓ+1≤n+1n_\ell + 1 \le n + 1 multiplications. ■\blacksquare

Back to Polynomial Euclidean algorithm