Algorithm Search⌘K

Proofs: Brown's modular GCD algorithm

These are the human proofs of Brown's modular GCD algorithm, at full length.

BROWN-GCD returns gcd(f, g) and stops after finitely many primes full

This proof shows: correctness.

Let f,g∈Z[x]f, g \in \mathbb{Z}[x] be nonzero and not constant after line L1, so that ff and gg are primitive with positive leading coefficients. (If one input is zero or a constant, the implementation answers directly, and the answer is the gcd by definition.) Let G=gcd⁡(f,g)G = \gcd(f, g) in Z[x]\mathbb{Z}[x], primitive with lc(G)>0\mathrm{lc}(G) > 0, and b=gcd⁡(lcf,lcg)b = \gcd(\mathrm{lc} f, \mathrm{lc} g). For a∈Z[x]a \in \mathbb{Z}[x], ∥a∥1\|a\|_1 and ∥a∥∞\|a\|_\infty are the sum and the largest absolute value of the coefficients. The primes come from a list of distinct primes, and only primes p∤bp \nmid b reach line L4.

Lemma 1 (contents). gcd⁡(f0,g0)=gcd⁡(contf0,contg0)⋅gcd⁡(ppf0,ppg0)\gcd(f_0, g_0) = \gcd(\mathrm{cont} f_0, \mathrm{cont} g_0) \cdot \gcd(\mathrm{pp} f_0, \mathrm{pp} g_0) for the original inputs f0,g0f_0, g_0.

Proof. This is a consequence of Gauss's lemma: the product of primitive polynomials is primitive, so contents and primitive parts of common divisors split independently. □\square

So it is enough to show that line L10 returns c⋅Gc \cdot G with c=gcd⁡(contf0,contg0)c = \gcd(\mathrm{cont} f_0, \mathrm{cont} g_0).

Lemma 2 (images). Let p∤bp \nmid b and let vpv_p be the monic gcd of f mod pf \bmod p and g mod pg \bmod p. Then deg⁡vp≥deg⁡G\deg v_p \ge \deg G, and if equality holds, b vp≡(b/lc G) G(modp)b\, v_p \equiv (b/\mathrm{lc}\, G)\, G \pmod p.

Proof. lc(G)\mathrm{lc}(G) divides lc(f)\mathrm{lc}(f) and lc(g)\mathrm{lc}(g), so it divides bb, and p∤lc(G)p \nmid \mathrm{lc}(G). Hence G mod pG \bmod p has degree deg⁡G\deg G. It divides f mod pf \bmod p and g mod pg \bmod p, so it divides vpv_p in (Z/pZ)[x](\mathbb{Z}/p\mathbb{Z})[x], and deg⁡vp≥deg⁡G\deg v_p \ge \deg G. If the degrees are equal, vp=G⋅lc(G)−1 mod pv_p = G \cdot \mathrm{lc}(G)^{-1} \bmod p, since both are monic and one divides the other. Multiplying by bb gives the claim, and b/lc(G)b/\mathrm{lc}(G) is an integer. □\square

Call pp lucky if deg⁡vp=deg⁡G\deg v_p = \deg G. Let H∘=(b/lc G) GH^\circ = (b/\mathrm{lc}\, G)\, G, U∘=lc(G) f/GU^\circ = \mathrm{lc}(G)\, f/G and W∘=lc(G) g/GW^\circ = \mathrm{lc}(G)\, g/G. These are in Z[x]\mathbb{Z}[x], and bf=H∘U∘b f = H^\circ U^\circ, bg=H∘W∘b g = H^\circ W^\circ.

Invariant. After line L8, dd is the smallest degree deg⁡vp\deg v_p seen so far, mm is the product of the primes pp seen so far with deg⁡vp=d\deg v_p = d since the last restart, and H,U,WH, U, W have coefficients in the symmetric range modulo mm with

H≡b vp,U≡f/vp,W≡g/vp(modp)for each such p,bf≡HU,bg≡HW(modm),H \equiv b\, v_p,\quad U \equiv f / v_p,\quad W \equiv g / v_p \pmod p \quad \text{for each such } p, \qquad b f \equiv H U,\quad b g \equiv H W \pmod m,

and the coefficient of xdx^d in HH is ≡b≢0(modp)\equiv b \not\equiv 0 \pmod p for every p∣mp \mid m, so deg⁡H=d\deg H = d.

Proof. Line L5 discards primes of larger degree, line L6 restarts with one prime when the degree drops or at the first prime, and line L7 combines a new image of the same degree, so the first part follows by induction, using that the Chinese remainder theorem gives the unique residue modulo mpm p with the given residues modulo mm and pp. For each p∣mp \mid m, bf≡b vp⋅(f/vp)≡HU(modp)b f \equiv b\, v_p \cdot (f/v_p) \equiv H U \pmod p, and the same holds for gg; the primes are distinct, so the congruences hold modulo mm. Finally vpv_p is monic of degree dd, so the coefficient of xdx^d in HH is ≡b(modp)\equiv b \pmod p, and higher coefficients are 00. □\square

Lemma 3 (the test is sound). If the test at line L9 passes, then pp(H)=G\mathrm{pp}(H) = G.

Proof. Every coefficient of HUH U has absolute value at most ∥H∥1∥U∥1<m/2\|H\|_1 \|U\|_1 < m/2, and every coefficient of bfb f has absolute value less than m/2m/2. Two integers in (−m/2,m/2)(-m/2, m/2) that are congruent modulo mm are equal, so bf=HUb f = H U in Z[x]\mathbb{Z}[x], and in the same way bg=HWb g = H W. So HH divides bfb f and bgb g, and so does pp(H)\mathrm{pp}(H). As pp(H)\mathrm{pp}(H) is primitive, Gauss's lemma gives pp(H)∣f\mathrm{pp}(H) \mid f and pp(H)∣g\mathrm{pp}(H) \mid g, so pp(H)\mathrm{pp}(H) divides GG. By Lemma 2, every image has degree at least deg⁡G\deg G, so deg⁡pp(H)=d≥deg⁡G\deg \mathrm{pp}(H) = d \ge \deg G. A divisor of GG of degree at least deg⁡G\deg G is ±G\pm G, and both have positive leading coefficients, so pp(H)=G\mathrm{pp}(H) = G. □\square

With Lemma 1, the returned value c⋅pp(H)c \cdot \mathrm{pp}(H) is gcd⁡(f0,g0)\gcd(f_0, g_0).

Lemma 4 (unlucky primes are finite). If p∤bp \nmid b is unlucky, then pp divides the resultant r=res(f/G,g/G)r = \mathrm{res}(f/G, g/G), which is a nonzero integer.

Proof. f/Gf/G and g/Gg/G are coprime in Q[x]\mathbb{Q}[x], so r≠0r \ne 0. Since p∤bp \nmid b, pp does not divide both leading coefficients, say p∤lc(f)p \nmid \mathrm{lc}(f), hence p∤lc(f/G)p \nmid \mathrm{lc}(f/G). Then r mod pr \bmod p equals, up to a power of lc(f/G)\mathrm{lc}(f/G) and a sign, the resultant of the reductions, and it is zero if the reductions have a common factor of positive degree. If pp is unlucky, vpv_p has degree greater than deg⁡G\deg G, so vp/(G mod p)v_p / (G \bmod p) is a common factor of (f/G) mod p(f/G) \bmod p and (g/G) mod p(g/G) \bmod p of positive degree, and p∣rp \mid r. □\square

Termination. Only finitely many primes are unlucky by Lemma 4, and each is either discarded at line L5 or causes a restart at line L6 that a later lucky prime undoes, since a lucky prime has the smallest possible degree deg⁡G\deg G. After the last unlucky prime in the list, every prime p∤bp \nmid b is lucky, d=deg⁡Gd = \deg G, and by Lemma 2 and the invariant, H≡H∘H \equiv H^\circ, U≡U∘U \equiv U^\circ, W≡W∘(modm)W \equiv W^\circ \pmod m. Once m>2max⁡(∥H∘∥1∥U∘∥1,∥H∘∥1∥W∘∥1,∥H∘∥∞,∥U∘∥∞,∥W∘∥∞,∥bf∥∞,∥bg∥∞)m > 2 \max(\|H^\circ\|_1 \|U^\circ\|_1, \|H^\circ\|_1 \|W^\circ\|_1, \|H^\circ\|_\infty, \|U^\circ\|_\infty, \|W^\circ\|_\infty, \|b f\|_\infty, \|b g\|_\infty), the symmetric residues at line L8 are H∘,U∘,W∘H^\circ, U^\circ, W^\circ themselves, and the test at line L9 passes. The list must contain enough primes; the implementation raises an error otherwise. ■\blacksquare

Back to Brown's modular GCD algorithm