Algorithm Search⌘K

Proofs: General number field sieve

These are the human proofs of General number field sieve, at full length.

Correctness of the general number field sieve full

This proof shows: correctness, termination.

Let N≥3N \ge 3 be an odd integer, and let f=xd+cd−1xd−1+⋯+c0∈Z[x]f = x^d + c_{d-1}x^{d-1} + \dots + c_0 \in \mathbb{Z}[x] be the monic polynomial and mm the integer of line L1, with f(m)=Nf(m) = N. Write Z[α]=Z[x]/(f)\mathbb{Z}[\alpha] = \mathbb{Z}[x]/(f), and represent each element by its coefficients on 1,α,…,αd−11, \alpha, \dots, \alpha^{d-1}. We prove three things. The output is always 11 or a proper factor of NN. Every subset that reaches line L9 gives a congruence of squares. The algorithm stops. We do not prove that a proper factor is found; that part is a heuristic. At the end we prove that the driver factorize returns the prime factorization.

Lemma 1 (the homomorphism). There is a ring homomorphism φ ⁣:Z[α]→Z/NZ\varphi\colon \mathbb{Z}[\alpha] \to \mathbb{Z}/N\mathbb{Z} with φ(α)=m mod N\varphi(\alpha) = m \bmod N, and φ(u)=u(m) mod N\varphi(u) = u(m) \bmod N for every uu of degree below dd.

Proof. Evaluation at mm followed by reduction modulo NN is a ring homomorphism ψ ⁣:Z[x]→Z/NZ\psi\colon \mathbb{Z}[x] \to \mathbb{Z}/N\mathbb{Z}. It maps ff to f(m) mod N=N mod N=0f(m) \bmod N = N \bmod N = 0, so it maps the ideal (f)(f) to 00, and it factors through Z[x]/(f)\mathbb{Z}[x]/(f). The value on the class of uu is ψ(u)=u(m) mod N\psi(u) = u(m) \bmod N. □\square

The proof does not need ff to be irreducible: Lemma 1 holds for any monic ff with f(m)=Nf(m) = N.

Lemma 2 (exact products). The functions mulmod with no modulus and product_in_order compute products in Z[α]\mathbb{Z}[\alpha] exactly.

Proof. mulmod forms the product ww of the two polynomials in Z[x]\mathbb{Z}[x], of degree at most 2d−22d - 2. For k=2d−2k = 2d - 2 down to dd it subtracts wkxk−dfw_k x^{k-d} f, which does not change the class modulo ff. Since ff is monic, this sets the coefficient of xkx^k to 00 and changes only lower coefficients. After the loop the degree is below dd, so the result is the representative of uvuv. product_in_order multiplies pairs level by level; multiplication in a commutative ring is associative and commutative, so the result is the product of all the elements. □\square

Lemma 3 (the rational square). Let TT be a set of relations whose vectors of line L5 add to 00 modulo 22, and let epe_p be the sum over TT of the exponents of pp in a−bma - bm. Then ∏T(a−bm)=v2\prod_T (a - bm) = v^2 with v=∏p∈Ppep/2v = \prod_{p \in P} p^{e_p/2}, and the value xx of line L7 satisfies x≡f′(m)v(modN)x \equiv f'(m) v \pmod N.

Proof. Each relation has ∣a−bm∣=∏p∈Ppep(a,b)|a - bm| = \prod_{p \in P} p^{e_p(a, b)}, which line L4 checks by trial division. The product over TT of the signs is (−1)s(-1)^s, where ss is the number of negative a−bma - bm; bit 00 of the vectors is the sign, so ss is even and the product is positive. Bits for the rational primes are the exponents modulo 22, so every epe_p is even. Hence ∏T(a−bm)=∏T∣a−bm∣=∏ppep=v2\prod_T (a - bm) = \prod_T |a - bm| = \prod_p p^{e_p} = v^2. Line L7 computes f′(m)f'(m) times ∏pep/2\prod p^{e_p/2} modulo NN. □\square

Lemma 4 (the algebraic square). If line L8 returns δ\delta, then δ2=γ\delta^2 = \gamma in Z[α]\mathbb{Z}[\alpha], where γ=f′(α)2∏T(a−bα)\gamma = f'(\alpha)^2 \prod_T (a - b\alpha).

Proof. The implementation computes γ\gamma exactly by Lemma 2, and algebraic_sqrt returns a candidate only after the test mulmod(delta, delta, f) == gamma, an exact product by Lemma 2. Otherwise it returns None, and line L8 goes on to the next subset. □\square

Lemma 5 (the congruence of squares). If a subset TT reaches line L9, then x2≡y2(modN)x^2 \equiv y^2 \pmod N.

Proof. By Lemma 3, x2≡f′(m)2∏T(a−bm)(modN)x^2 \equiv f'(m)^2 \prod_T (a - bm) \pmod N. By Lemma 1, φ(a−bα)=a−bm\varphi(a - b\alpha) = a - bm and φ(f′(α))=f′(m)\varphi(f'(\alpha)) = f'(m), since f′f' has degree d−1<dd - 1 < d. By Lemma 4 and Lemma 1, y2=φ(δ)2=φ(δ2)=φ(γ)=f′(m)2∏T(a−bm)y^2 = \varphi(\delta)^2 = \varphi(\delta^2) = \varphi(\gamma) = f'(m)^2 \prod_T (a - bm) in Z/NZ\mathbb{Z}/N\mathbb{Z}. So x2≡y2x^2 \equiv y^2. □\square

Lemma 6 (the output). gnfs returns 11 or an integer gg with 1<g<N1 < g < N and g∣Ng \mid N.

Proof. There are four return points with a value other than 11. The trial division returns a prime pp with p∣Np \mid N only if p<Np < N, and returns 11 otherwise. Line L1 returns gcd⁡(f′(m),N)\gcd(f'(m), N) only if it lies strictly between 11 and NN. Line L9 returns gcd⁡(x−y,N)\gcd(x - y, N) only if it lies strictly between 11 and NN. A gcd with NN divides NN. Every other exit returns 11. □\square

When gg comes from line L9, Lemma 5 explains why it is a factor: N∣(x−y)(x+y)N \mid (x - y)(x + y), and gg is proper exactly when x≢±yx \not\equiv \pm y modulo some but not all prime power factors of NN.

Lemma 7 (inert primes and the square root modulo pp). Let pp be an odd prime with p≡3(mod4)p \equiv 3 \pmod 4 such that is_inert(f, p) is true, where dd is an odd prime. Then ff is irreducible modulo pp, K=Fp[x]/(f)K = \mathbb{F}_p[x]/(f) is a field with q=pdq = p^d elements, and q≡3(mod4)q \equiv 3 \pmod 4. For γ∈K∗\gamma \in K^*, r0=γ(3q−5)/4r_0 = \gamma^{(3q-5)/4} satisfies r02γ=1r_0^2\gamma = 1 if and only if γ\gamma is a square in K∗K^*.

Proof. The test says that ff has no root modulo pp and xpd≡x(modf,p)x^{p^d} \equiv x \pmod{f, p}. The second condition means that ff divides xpd−xx^{p^d} - x in Fp[x]\mathbb{F}_p[x]. That polynomial is the product of all monic irreducible polynomials over Fp\mathbb{F}_p of degree dividing dd, each once. So every irreducible factor of ff has degree 11 or dd, since dd is prime. There is no root, so no factor of degree 11, and ff is irreducible of degree dd. Hence KK is a field with q=pdq = p^d elements. Since p≡3(mod4)p \equiv 3 \pmod 4 and dd is odd, q≡3d≡3(mod4)q \equiv 3^d \equiv 3 \pmod 4, so (3q−5)/4(3q - 5)/4 is an integer.

K∗K^* is cyclic of order q−1q - 1, so γ\gamma is a square if and only if γ(q−1)/2=1\gamma^{(q-1)/2} = 1. Now r02γ=γ(3q−5)/2+1=γ3(q−1)/2=(γ(q−1)/2)3r_0^2\gamma = \gamma^{(3q-5)/2 + 1} = \gamma^{3(q-1)/2} = (\gamma^{(q-1)/2})^3. The value γ(q−1)/2\gamma^{(q-1)/2} is 11 or −1-1, and its cube is the same value. So r02γ=1r_0^2\gamma = 1 exactly when γ\gamma is a square. □\square

Lemma 7 explains why line L8 finds the square root when it exists and the precision is high enough. Correctness does not depend on it, since Lemma 4 checks the result.

Lemma 8 (Newton's step). Let MM be an odd modulus, and let r,γr, \gamma in (Z/M2)[x]/(f)(\mathbb{Z}/M^2)[x]/(f) satisfy γr2≡1(modM)\gamma r^2 \equiv 1 \pmod M. Then r′=r(3−γr2)/2r' = r(3 - \gamma r^2)/2 satisfies γr′2≡1(modM2)\gamma r'^2 \equiv 1 \pmod{M^2}.

Proof. Write γr2=1−e\gamma r^2 = 1 - e with e≡0(modM)e \equiv 0 \pmod M. Then r′=r(2+e)/2r' = r(2 + e)/2, where 22 is invertible since MM is odd, and

γr′2=(1−e)(2+e)24=4−3e2−e34=1−3e2+e34.\gamma r'^2 = \frac{(1 - e)(2 + e)^2}{4} = \frac{4 - 3e^2 - e^3}{4} = 1 - \frac{3e^2 + e^3}{4}.

Both e2e^2 and e3e^3 are 00 modulo M2M^2. □\square

Lemma 9 (the vector of a relation is defined). For a relation (a,b)(a, b) and a prime p∈Pp \in P that divides F(a,b)F(a, b), p∤bp \nmid b, and the pair (p,ab−1 mod p)(p, ab^{-1} \bmod p) is in the algebraic factor base.

Proof. Modulo bb, F(a,b)=∑ciaibd−i≡adF(a, b) = \sum c_i a^i b^{d-i} \equiv a^d, since cd=1c_d = 1. If p∣bp \mid b and p∣F(a,b)p \mid F(a, b), then p∣adp \mid a^d, so p∣ap \mid a, against gcd⁡(a,b)=1\gcd(a, b) = 1. So p∤bp \nmid b, and with r=ab−1 mod pr = ab^{-1} \bmod p, 0≡F(a,b)=bdf(a/b)≡bdf(r)(modp)0 \equiv F(a, b) = b^d f(a/b) \equiv b^d f(r) \pmod p, so f(r)≡0(modp)f(r) \equiv 0 \pmod p and (p,r)(p, r) is one of the pairs of line L2. □\square

So relation_vector never takes the inverse of 00 modulo pp and never looks up a missing pair.

Lemma 10 (termination). gnfs stops on every input.

Proof. Polynomial selection tries at most 6464 values of mm. The trial division and the search for an inert prime run over finite ranges (at most 20002000 candidates for the inert prime). If an inert prime pp is found, then ff is irreducible modulo pp by Lemma 7, so it is irreducible over Q\mathbb{Q} (a factorization over Q\mathbb{Q} gives one over Z\mathbb{Z} with monic factors, by Gauss's lemma, and it reduces to a factorization modulo pp). Then the loop of line L2 for the characters stops. Its discriminant Δ\Delta is not 00, since an irreducible polynomial over Q\mathbb{Q} has distinct roots. By Schur's theorem, infinitely many primes qq divide some value f(s)f(s) with s∈Zs \in \mathbb{Z}; for such q∤Δq \nmid \Delta, s mod qs \bmod q is a simple root, so f′(s)≢0(modq)f'(s) \not\equiv 0 \pmod q. So enough characters exist, and the search reaches them. The sieve runs over YY lines of 2A+12A + 1 points. Trial division of a nonzero integer by finitely many primes stops. The elimination is a loop over the rows, and each inner loop clears the top bit of vv or stops, so it runs at most as many times as vv has bits. The dependency loop is finite. In algebraic_sqrt, the modulus is squared at each step and the loop stops when it passes a fixed bound. □\square

Theorem. gnfs stops and returns either 11 or a proper factor of NN. When it returns a proper factor from line L9, it has found xx and yy with x2≡y2(modN)x^2 \equiv y^2 \pmod N.

Proof. Lemmas 10, 6 and 5. □\square

The driver. factorize(n) returns the prime factors of n≥1n \ge 1 with multiplicity, in order, provided that is_probable_prime is correct on the numbers it sees. That holds for all numbers below 33170440646798873859619813317044064679887385961981, where the strong test to the 1313 prime bases up to 4141 is a proof of primality.

Proof. The trial division divides out the primes below 10001000 in increasing order. If it stops because p2>np^2 > n for the remaining nn, then nn has no prime factor below pp, so nn is 11 or a prime. Otherwise nn has no prime factor below 10001000. The invariant of the stack is this: the product of the output and of the stack equals the input, every output entry is prime, and every stack entry has no prime factor below 10001000. It holds at the start. A popped mm that is 11 is dropped. A popped m>1m > 1 with m<106m < 10^6 is prime, because a composite with no prime factor below 10001000 is at least 10092>1061009^2 > 10^6. A popped m≥106m \ge 10^6 that passes is_probable_prime is prime by the assumption. Otherwise mm is composite, and _split(m) returns a proper factor gg: a perfect power rer^e with e≥2e \ge 2 gives 1<r<m1 < r < m; gnfs gives a proper factor by the Theorem; and the last resort finds the least odd t≥1001t \ge 1001 with t∣mt \mid m, which exists and is below mm because mm is odd and composite with no prime factor below 10001000. Then gg and m/gm/g both divide mm, so they have no prime factor below 10001000, and their product is mm. The invariant holds after each step. Each split replaces mm by two numbers greater than 11 whose product is mm, so the total number of prime factors counted with multiplicity bounds the number of splits, and the loop stops. When the stack is empty, the output is a list of primes whose product is the input, and sorting puts it in order. ■\blacksquare

Back to General number field sieve