Algorithm Search⌘K

Proofs: Heuristic GCD

These are the human proofs of Heuristic GCD, at full length.

A candidate that divides both inputs is the gcd full

This proof shows: correctness, termination.

Let f,g∈Z[x]f, g \in \mathbb{Z}[x] be nonzero and primitive, as after line L1. Let G=gcd⁡(f,g)G = \gcd(f, g), primitive with a positive leading coefficient. Fix an integer ξ≥2min⁡(∣f∣∞,∣g∣∞)+2\xi \ge 2 \min(|f|_\infty, |g|_\infty) + 2, and say a∈{f,g}a \in \{f, g\} is the input with ∣a∣∞=min⁡(∣f∣∞,∣g∣∞)|a|_\infty = \min(|f|_\infty, |g|_\infty). Every point used by the algorithm satisfies this bound: line L2 sets ξ\xi to it, and line L8 never makes ξ\xi smaller, because ⌊ξ⋅73794/27011⌋≥ξ\lfloor \xi \cdot 73794 / 27011 \rfloor \ge \xi for ξ≥1\xi \ge 1.

Fact 1 (Cauchy bound). If p∈Z[x]p \in \mathbb{Z}[x] divides aa and α∈C\alpha \in \mathbb{C} is a root of pp, then ∣α∣<1+∣a∣∞≤ξ/2|\alpha| < 1 + |a|_\infty \le \xi / 2.

Proof. α\alpha is a root of a=∑i=0maixia = \sum_{i=0}^{m} a_i x^i with am≠0a_m \ne 0. If ∣α∣≤1|\alpha| \le 1 the claim holds since ∣a∣∞≥1|a|_\infty \ge 1. Otherwise amαm=−∑i<maiαia_m \alpha^m = -\sum_{i < m} a_i \alpha^i gives

∣α∣m≤∣am∣∣α∣m≤∣a∣∞∑i<m∣α∣i=∣a∣∞∣α∣m−1∣α∣−1<∣a∣∞∣α∣m∣α∣−1,|\alpha|^m \le |a_m| |\alpha|^m \le |a|_\infty \sum_{i < m} |\alpha|^i = |a|_\infty \frac{|\alpha|^m - 1}{|\alpha| - 1} < |a|_\infty \frac{|\alpha|^m}{|\alpha| - 1},

so ∣α∣−1<∣a∣∞|\alpha| - 1 < |a|_\infty. Finally 1+∣a∣∞≤ξ/21 + |a|_\infty \le \xi / 2 is the bound on ξ\xi. □\square

Fact 2. If p∈Z[x]p \in \mathbb{Z}[x] divides aa and deg⁡p=e≥1\deg p = e \ge 1, then ∣p(ξ)∣>(ξ/2)e≥ξ/2|p(\xi)| > (\xi / 2)^e \ge \xi / 2. If pp divides aa and p≠0p \ne 0, then p(ξ)≠0p(\xi) \ne 0.

Proof. Write p=lc⁡(p)∏j=1e(x−αj)p = \operatorname{lc}(p) \prod_{j=1}^{e} (x - \alpha_j). By Fact 1, ∣ξ−αj∣≥ξ−∣αj∣>ξ−ξ/2=ξ/2|\xi - \alpha_j| \ge \xi - |\alpha_j| > \xi - \xi/2 = \xi/2, and ∣lc⁡(p)∣≥1|\operatorname{lc}(p)| \ge 1. So ∣p(ξ)∣>(ξ/2)e|p(\xi)| > (\xi/2)^e, which is at least ξ/2\xi/2 because ξ/2≥1\xi / 2 \ge 1. For e=0e = 0, pp is a nonzero constant. □\square

Fact 3. For γ≠0\gamma \ne 0, h~=genpoly⁡(γ,ξ)\tilde h = \operatorname{genpoly}(\gamma, \xi) is nonzero, satisfies h~(ξ)=γ\tilde h(\xi) = \gamma, and every coefficient lies in (−ξ/2,ξ/2](-\xi/2, \xi/2]. Hence ∣cont⁡(h~)∣≤ξ/2|\operatorname{cont}(\tilde h)| \le \xi / 2.

Proof. The expansion loop keeps γorig=∑j<ihjξj+γiξi\gamma_{\text{orig}} = \sum_{j < i} h_j \xi^j + \gamma_i \xi^i, where γi\gamma_i is the value of γ\gamma after ii steps, and it stops when γi=0\gamma_i = 0. It does stop: if ∣γi∣≥1|\gamma_i| \ge 1 then ∣γi+1∣≤(∣γi∣+ξ/2)/ξ<∣γi∣|\gamma_{i+1}| \le (|\gamma_i| + \xi/2)/\xi < |\gamma_i|, because ξ≥2\xi \ge 2. Each digit is chosen in (−ξ/2,ξ/2](-\xi/2, \xi/2]. The content divides each nonzero coefficient, so it is at most ξ/2\xi/2 in absolute value, and there is a nonzero coefficient since γ≠0\gamma \ne 0. □\square

Theorem. At any try, let γ=gcd⁡(f(ξ),g(ξ))\gamma = \gcd(f(\xi), g(\xi)), h~=genpoly⁡(γ,ξ)\tilde h = \operatorname{genpoly}(\gamma, \xi) and h=pp⁡(h~)h = \operatorname{pp}(\tilde h). If hh divides ff and gg in Z[x]\mathbb{Z}[x], then h=Gh = G.

Proof. By Fact 2 with p=ap = a, a(ξ)≠0a(\xi) \ne 0, so γ≠0\gamma \ne 0 and Fact 3 applies. Write h~=c h\tilde h = c\, h with c=±cont⁡(h~)c = \pm \operatorname{cont}(\tilde h), so 0<∣c∣≤ξ/20 < |c| \le \xi/2.

Since hh is primitive and divides ff and gg, it divides GG (in Z[x]\mathbb{Z}[x], a common divisor divides the gcd). Write G=hkG = h k with k∈Z[x]k \in \mathbb{Z}[x]. Since GG divides ff and gg, the integer G(ξ)G(\xi) divides f(ξ)f(\xi) and g(ξ)g(\xi), hence divides γ\gamma: γ=m G(ξ)\gamma = m\, G(\xi) for a nonzero integer mm. Now

c h(ξ)=h~(ξ)=γ=m G(ξ)=m h(ξ) k(ξ).c\, h(\xi) = \tilde h(\xi) = \gamma = m\, G(\xi) = m\, h(\xi)\, k(\xi).

The polynomial hh divides aa and is nonzero, so h(ξ)≠0h(\xi) \ne 0 by Fact 2, and therefore c=m k(ξ)c = m\, k(\xi). So ∣k(ξ)∣≤∣c∣≤ξ/2|k(\xi)| \le |c| \le \xi / 2.

The polynomial kk divides GG, which divides aa. If deg⁡k≥1\deg k \ge 1, Fact 2 gives ∣k(ξ)∣>ξ/2|k(\xi)| > \xi / 2, a contradiction. So kk is a nonzero integer constant. Both GG and hh are primitive, so k=±1k = \pm 1, and both have positive leading coefficients, so k=1k = 1 and h=Gh = G. ■\blacksquare

Correctness of the output. If line L7 returns, the theorem gives h=gcd⁡(pp⁡f,pp⁡g)h = \gcd(\operatorname{pp} f, \operatorname{pp} g), and by Gauss's lemma c⋅h=gcd⁡(f,g)c \cdot h = \gcd(f, g) for c=gcd⁡(cont⁡f,cont⁡g)c = \gcd(\operatorname{cont} f, \operatorname{cont} g). Otherwise the algorithm returns FAIL, which makes no claim.

Termination. Each try does finitely many integer operations: an evaluation, an integer gcd, a terminating expansion (Fact 3), and two trial divisions, each of which lowers the degree of the remainder at every step. The loop of line L3 runs at most TT times. ■\blacksquare

Back to Heuristic GCD