Correctness of the multiple polynomial quadratic sieve full
This proof shows: correctness, termination.
Throughout, N≥3 is odd and not a perfect square, and F is the factor base of line L1: −1, 2, and the odd primes p≤B with (N/p)=1, each with tp2≡N(modp).
Lemma 1 (enough primes q). There are infinitely many primes q with (N/q)=1. So the search of line L3 always stops.
Proof. First, infinitely many primes divide some value x2−N with x an integer. If not, let p1,…,pk be all of them and P=p1⋯pk. Then (NP)2−N=N(NP2−1), and NP2−1≥N−1≥2 is coprime to P, so it has a prime factor that is not among the pi but divides the value at x=NP, a contradiction. Now take such a prime q with q∤2N; all but finitely many qualify. Then x2≡N≡0(modq) for some x, so N is a nonzero square modulo the odd prime q, that is, (N/q)=1. □
Lemma 2 (the polynomial). Let q be an odd prime with (N/q)=1, a=q2, and b0 with b02≡N(modq), 0<b0<q. Let k=qN−b02⋅(2b0)−1modq and b=b0+kq, replaced by a−b if 2b>a. Then b2≡N(moda), 0<b≤a/2, c=(b2−N)/a is an integer, b2−ac=N, and for every integer x
af(x)=(ax+b)2−N=0,f(x)=ax2+2bx+c. Proof. Since (N/q)=1, q∤N, so q∤b0, and q is odd, so 2b0 is invertible modulo q and k is defined. The quotient (N−b02)/q is an integer as q∣N−b02. Then
b2=b02+2b0kq+k2q2≡b02+2b0kq(modq2), and 2b0k≡(N−b02)/q(modq) gives 2b0kq≡N−b02(modq2), so b2≡N(modq2). Also (a−b)2=a2−2ab+b2≡b2(moda), so the replacement keeps the congruence. Before it, 1≤b0≤b≤(q−1)+(q−1)q<a, so 0<b<a, and after it 0<b≤a/2. The congruence makes c an integer, and ac=b2−N is b2−ac=N. Expanding, (ax+b)2−N=a2x2+2abx+b2−N=a2x2+2abx+ac=af(x). This is not 0, since N is not a perfect square. □
Lemma 3 (the root classes). Let f be as in Lemma 2 with q>B. For an odd p∈F, the two classes x≡(±tp−b)a−1(modp) are distinct, and p∣f(x) if and only if x is in one of them. Also 2∣f(x) if and only if x≡c(mod2).
Proof. Let p∈F be odd. Then p≤B<q, so p∤a=q2 and a−1modp exists. Also (N/p)=1 gives p∤N, so tp≡−tp(modp), since otherwise p∣2tp, so p∣tp and p∣tp2, and then tp2≡N gives p∣N; so the two classes are distinct. As p∤a, p∣f(x) if and only if p∣af(x)=(ax+b)2−N, which is (ax+b)2≡tp2, that is, (ax+b−tp)(ax+b+tp)≡0(modp). Since p is prime, this holds if and only if ax+b≡±tp, that is, x≡(±tp−b)a−1(modp). For p=2: a is odd and x2≡x(mod2), so f(x)=ax2+2bx+c≡x+c(mod2). □
Lemma 4 (the sieve). After line L5, for every x∈[−M,M), S[x] is the sum of logp over the distinct primes p∈F, p>0, that divide f(x).
Proof. Line L5 starts with S[x]=0 and adds logp once for each root class of p that contains x. By Lemma 3, an odd p has two distinct classes and x lies in one of them exactly when p∣f(x), so logp is added once if p∣f(x) and never otherwise. For p=2 the single class x≡c gives the same. □
Lemma 5 (relations). Every relation (r,v) appended at line L6 satisfies r2≡∏p∈Fpvp(modN), with p=−1 included.
Proof. Line L6 appends (r,v) only when trial division shows f(x)=∏p∈Fpvp, with v−1=1 exactly when f(x)<0. Here r≡(ax+b)q−1(modN), where q−1 exists because q∤N. By Lemma 2, (ax+b)2=N+af(x)≡q2f(x)(modN), so r2≡q2f(x)q−2=f(x)(modN). □
Lemma 6 (the elimination). Let v1,…,vm be the exponent vectors mod 2, as bit masks over the ∣F∣ coordinates of F. Gaussian elimination that records, for each reduced row, the set h of original rows added into it, produces for each row that reduces to 0 a nonempty set h with ⨁l∈hvl=0. If m>∣F∣, at least m−∣F∣ such sets are found.
Proof. Row j starts with u=vj and h={j}. Each reduction adds a stored pivot pair (u′,h′) with u′=⨁l∈h′vl to (u,h) by ⊕ in both parts, so u=⨁l∈hvl stays true. The stored pairs come from earlier rows, so j∈/h′ and j stays in h, which is therefore nonempty. Each reduction clears the leading bit of u and changes only lower bits, so the row either reduces to 0 or becomes a pivot with a new leading bit. There are ∣F∣ coordinates, so at most ∣F∣ pivots, and at least m−∣F∣ rows reduce to 0. □
Theorem. MPQS stops, and it returns 1 or a proper factor g of N. Each subset T tried at line L7 satisfies X2≡Y2(modN). If the loop ends with ∣R∣≥∣F∣+E, at least E subsets are tried.
Proof. Termination. Each pass of the loop of line L2 uses one more polynomial, and the loop stops after at most P of them. In each pass, line L3 stops by Lemma 1, lines L4 and L5 do finitely many steps for the finitely many primes of F on an interval of 2M values, and trial division of the nonzero integer f(x) (Lemma 2) by primes stops. Line L7 runs over finitely many subsets.
Congruence of squares. Let T be a subset from Lemma 6 and e=∑(r,v)∈Tv over the integers. Every ep is even, including e−1. By Lemma 5,
X2≡(r,v)∈T∏r2≡p∈F∏pep=(−1)e−1p>0∏(pep/2)2≡Y2(modN), since (−1)e−1=1. The relations of T may come from different polynomials, since each satisfies Lemma 5 over the same F. The count of subsets is Lemma 6 with m=∣R∣.
Correctness. The only return other than line L8 is in line L7, which returns g=gcd(X−Y,N) only if 1<g<N. A gcd with N divides N, so g is a proper factor. A prime N has none, so for a prime N the output is 1. The threshold τ of line L6 decides only which values are tried by trial division, and keeping only one relation for each value of ±r only removes relations, so neither affects these statements. ■