Algorithm Search⌘K

Proofs: Extended Euclidean algorithm for polynomials

These are the human proofs of Extended Euclidean algorithm for polynomials, at full length.

The extended Euclidean algorithm returns the gcd and small Bézout coefficients full

This proof shows: correctness.

Let FF be a field and f,g∈F[x]f, g \in F[x]. We number the values of the loop as in the page: r0=fr_0 = f, r1=gr_1 = g, s0=1s_0 = 1, s1=0s_1 = 0, t0=0t_0 = 0, t1=1t_1 = 1, and the pass of line L4 for i=1,2,…i = 1, 2, \ldots computes ri−1=qiri+ri+1r_{i-1} = q_i r_i + r_{i+1} with deg⁡ri+1<deg⁡ri\deg r_{i+1} < \deg r_i, si+1=si−1−qisis_{i+1} = s_{i-1} - q_i s_i and ti+1=ti−1−qitit_{i+1} = t_{i-1} - q_i t_i. The loop stops after the pass with rℓ+1=0r_{\ell+1} = 0, and then the variables (r0,s0,t0)(r_0, s_0, t_0) of the algorithm hold (rℓ,sℓ,tℓ)(r_\ell, s_\ell, t_\ell).

Invariant. sif+tig=ris_i f + t_i g = r_i for every ii that the algorithm computes.

Proof. For i=0i = 0 and i=1i = 1 this is 1⋅f+0⋅g=f1 \cdot f + 0 \cdot g = f and 0⋅f+1⋅g=g0 \cdot f + 1 \cdot g = g. If it holds for i−1i - 1 and ii, then

si+1f+ti+1g=(si−1f+ti−1g)−qi(sif+tig)=ri−1−qiri=ri+1.□s_{i+1} f + t_{i+1} g = (s_{i-1} f + t_{i-1} g) - q_i (s_i f + t_i g) = r_{i-1} - q_i r_i = r_{i+1}. \qquad \square

The gcd. The values rir_i are those of the Euclidean algorithm, so by its proof the loop stops, and rℓr_\ell is a gcd of ff and gg when (f,g)≠(0,0)(f, g) \ne (0, 0). If f=g=0f = g = 0, the loop does not run, line L5 returns (0,1,0)(0, 1, 0), and 1⋅0+0⋅0=0=gcd⁡(0,0)1 \cdot 0 + 0 \cdot 0 = 0 = \gcd(0, 0). Otherwise rℓ≠0r_\ell \ne 0, u=lc⁡(rℓ)−1u = \operatorname{lc}(r_\ell)^{-1}, and multiplying the invariant for i=ℓi = \ell by uu gives (usℓ)f+(utℓ)g=urℓ(u s_\ell) f + (u t_\ell) g = u r_\ell, the monic gcd hh.

Degree formulas. Assume m=deg⁡f≥n=deg⁡g≥0m = \deg f \ge n = \deg g \ge 0, and write ni=deg⁡rin_i = \deg r_i, so n0=m≥n1=n>n2>⋯>nℓ≥0n_0 = m \ge n_1 = n > n_2 > \cdots > n_\ell \ge 0 and deg⁡qi=ni−1−ni\deg q_i = n_{i-1} - n_i for 1≤i≤ℓ1 \le i \le \ell (rule 3 of degree of a polynomial). We show, for 2≤i≤ℓ+12 \le i \le \ell + 1,

deg⁡si=n1−ni−1,deg⁡ti=n0−ni−1.\deg s_i = n_1 - n_{i-1}, \qquad \deg t_i = n_0 - n_{i-1}.

For i=2i = 2: s2=1−q1⋅0=1s_2 = 1 - q_1 \cdot 0 = 1, of degree 0=n1−n10 = n_1 - n_1, and t2=0−q1⋅1=−q1t_2 = 0 - q_1 \cdot 1 = -q_1, of degree n0−n1n_0 - n_1.

For i=3i = 3: s3=0−q2⋅1s_3 = 0 - q_2 \cdot 1, of degree n1−n2n_1 - n_2, and t3=1−q2t2t_3 = 1 - q_2 t_2. Here deg⁡(q2t2)=(n1−n2)+(n0−n1)=n0−n2≥1>0=deg⁡1\deg(q_2 t_2) = (n_1 - n_2) + (n_0 - n_1) = n_0 - n_2 \ge 1 > 0 = \deg 1, so deg⁡t3=n0−n2\deg t_3 = n_0 - n_2.

For 4≤i+1≤ℓ+14 \le i + 1 \le \ell + 1, assume the formulas for i−1i - 1 and ii, with i≥3i \ge 3. Then

deg⁡(qisi)=(ni−1−ni)+(n1−ni−1)=n1−ni>n1−ni−2=deg⁡si−1,\deg(q_i s_i) = (n_{i-1} - n_i) + (n_1 - n_{i-1}) = n_1 - n_i > n_1 - n_{i-2} = \deg s_{i-1},

because ni<ni−2n_i < n_{i-2}. By rule 1 of degree, deg⁡si+1=deg⁡(si−1−qisi)=n1−ni\deg s_{i+1} = \deg(s_{i-1} - q_i s_i) = n_1 - n_i. In the same way deg⁡(qiti)=n0−ni>n0−ni−2=deg⁡ti−1\deg(q_i t_i) = n_0 - n_i > n_0 - n_{i-2} = \deg t_{i-1}, so deg⁡ti+1=n0−ni\deg t_{i+1} = n_0 - n_i. □\square

Degree bounds of the output. Assume f,g≠0f, g \ne 0 and that hh is neither the monic ff nor the monic gg. If m<nm < n, the first pass gives q1=0q_1 = 0, r2=fr_2 = f, s2=1s_2 = 1, t2=0t_2 = 0, so from then on the algorithm runs as XGCD(g,f)(g, f) with the roles of ss and tt exchanged; so it suffices to treat m≥nm \ge n. Then g∤fg \nmid f, since otherwise hh would be the monic gg; so r2≠0r_2 \ne 0 and ℓ≥2\ell \ge 2. The formulas with i=ℓi = \ell give

deg⁡s=deg⁡sℓ=n1−nℓ−1<n1−nℓ=deg⁡g−deg⁡h,deg⁡t=deg⁡tℓ=n0−nℓ−1<n0−nℓ=deg⁡f−deg⁡h,\deg s = \deg s_\ell = n_1 - n_{\ell-1} < n_1 - n_\ell = \deg g - \deg h, \qquad \deg t = \deg t_\ell = n_0 - n_{\ell-1} < n_0 - n_\ell = \deg f - \deg h,

since nℓ−1>nℓ=deg⁡hn_{\ell-1} > n_\ell = \deg h. Scaling by uu does not change degrees. ■\blacksquare

Back to Extended Euclidean algorithm for polynomials