Algorithm Search⌘K

Proofs: Quadratic sieve

These are the human proofs of Quadratic sieve, at full length.

Correctness of the quadratic sieve full

This proof shows: correctness, termination.

Let s=⌊N⌋s = \lfloor \sqrt N \rfloor and f(t)=(s+t)2−Nf(t) = (s + t)^2 - N. Since NN is not a perfect square, f(t)≠0f(t) \ne 0 for every integer tt, so log⁡∣f(t)∣\log |f(t)| at line L5 is defined.

Lemma 1 (the root classes). Let pp be an odd prime with p∤Np \nmid N and (N/p)=1(N/p) = 1, and let rp2≡N(modp)r_p^2 \equiv N \pmod p. Then rp≢−rp(modp)r_p \not\equiv -r_p \pmod p, and for every integer xx, p∣x2−Np \mid x^2 - N if and only if x≡rpx \equiv r_p or x≡−rp(modp)x \equiv -r_p \pmod p. Also 2∣x2−N2 \mid x^2 - N if and only if xx is odd.

Proof. If rp≡−rpr_p \equiv -r_p, then p∣2rpp \mid 2r_p, so p∣rpp \mid r_p and p∣Np \mid N, which is excluded. Next, x2−N≡x2−rp2=(x−rp)(x+rp)(modp)x^2 - N \equiv x^2 - r_p^2 = (x - r_p)(x + r_p) \pmod p, and since pp is prime, pp divides the product if and only if it divides one factor. For p=2p = 2: NN is odd, so x2−Nx^2 - N is even if and only if x2x^2 is odd, that is, xx is odd. □\square

Lemma 2 (the sieve). After line L4 runs on a block WW, for each t∈Wt \in W, S[t]=∑log⁡pS[t] = \sum \log p over the distinct primes p∈Fp \in F, p>0p > 0, that divide f(t)f(t).

Proof. Line L4 sets S[t]=0S[t] = 0 and then, for each prime pp of FF and each of its root classes cc, adds log⁡p\log p to exactly the entries t∈Wt \in W with s+t≡c(modp)s + t \equiv c \pmod p. By Lemma 1, the root classes of an odd pp are two distinct classes, and p∣f(t)p \mid f(t) exactly when s+ts + t lies in one of them; so log⁡p\log p is added once if p∣f(t)p \mid f(t) and never otherwise. For p=2p = 2 the one class c=1c = 1 gives the same. Every odd p∈Fp \in F has (N/p)=1(N/p) = 1, which implies p∤Np \nmid N, so Lemma 1 applies to it. □\square

Lemma 3 (relations). Every relation (x,v)(x, v) in RR satisfies x2≡∏p∈Fpvp(modN)x^2 \equiv \prod_{p \in F} p^{v_p} \pmod N, with p=−1p = -1 included. No two relations have the same xx.

Proof. Line L6 appends (s+t,v)(s + t, v) only when trial division shows f(t)=∏p∈Fpvpf(t) = \prod_{p \in F} p^{v_p}, with v−1=1v_{-1} = 1 exactly when f(t)<0f(t) < 0. Then x2=(s+t)2=N+f(t)≡f(t)(modN)x^2 = (s + t)^2 = N + f(t) \equiv f(t) \pmod N. The blocks of line L3 are disjoint intervals of tt: the right blocks [jM,(j+1)M)[jM, (j + 1)M) cover t≥0t \ge 0 and the left blocks [−(j+1)M,−jM)[-(j + 1)M, -jM) cover t<0t < 0, each cut to s+t≥1s + t \ge 1. So each tt, hence each x=s+tx = s + t, is looked at once. □\square

Lemma 4 (the elimination). Let v1,…,vmv_1, \dots, v_m be the exponent vectors mod 2, as bit masks over the K+1K + 1 coordinates of FF. Gaussian elimination that records, for each reduced row, the set hh of original rows added into it, produces for each row that reduces to 00 a nonempty set hh with ⨁l∈hvl=0\bigoplus_{l \in h} v_l = 0. If m>∣F∣m > |F|, at least m−∣F∣m - |F| such sets are found.

Proof. Row jj starts with u=vju = v_j and h={j}h = \{j\}. Each reduction adds a stored pivot pair (u′,h′)(u', h') with u′=⨁l∈h′vlu' = \bigoplus_{l \in h'} v_l to (u,h)(u, h) by ⊕\oplus in both parts, so u=⨁l∈hvlu = \bigoplus_{l \in h} v_l stays true. The stored pairs come from earlier rows, so j∉h′j \notin h', and jj stays in hh. Each reduction clears the leading bit of uu and changes only lower bits, so the row either reduces to 00 or becomes a pivot with a new leading bit. There are ∣F∣|F| coordinates, so at most ∣F∣|F| pivots, and at least m−∣F∣m - |F| rows reduce to 00. □\square

Theorem. QS stops, and it returns 11 or a proper factor gg of NN. Each subset TT tried at line L8 satisfies X2≡Y2(modN)X^2 \equiv Y^2 \pmod N. If the loop ends with ∣R∣≥∣F∣+E|R| \ge |F| + E, at least EE subsets are tried.

Proof. Termination. Each pass of the loop of line L2 increases jj at line L7, and the loop stops when j≥Jj \ge J. Each pass sieves two blocks of at most MM values with finitely many primes, and trial division of a nonzero integer by primes stops. Line L8 runs over finitely many subsets.

Congruence of squares. Let TT be a subset from Lemma 4 and e=∑(x,v)∈Tve = \sum_{(x, v) \in T} v over the integers. Every epe_p is even, including e−1e_{-1}. By Lemma 3, X2≡∏(x,v)∈Tx2≡∏p∈Fpep=(−1)e−1∏p>0(pep/2)2≡Y2(modN)X^2 \equiv \prod_{(x, v) \in T} x^2 \equiv \prod_{p \in F} p^{e_p} = (-1)^{e_{-1}} \prod_{p > 0} \big(p^{e_p/2}\big)^2 \equiv Y^2 \pmod N, since (−1)e−1=1(-1)^{e_{-1}} = 1. The count of subsets is Lemma 4 with m=∣R∣m = |R|.

Correctness. The only return other than line L9 is in line L8, which returns g=gcd⁡(X−Y,N)g = \gcd(X - Y, N) only if 1<g<N1 < g < N. A gcd with NN divides NN, so gg is a proper factor. A prime NN has none, so for a prime the output is 11. The threshold of line L5 decides only which values are tried by trial division, so it does not affect any of these statements. ■\blacksquare

Back to Quadratic sieve