These are the human proofs of Lehman's factorization method, at full length.
Correctness of Lehman's factorization method full
This proof shows: correctness, termination.
Let N≥22, and write t=N1/3, a real number with t>2.8.
Termination. Line L1 is a finite loop. For each k, the value a2−4kN grows with a without bound, so the loop of line L4 ends; the loop of line L2 has ⌊t⌋+1 passes. So the algorithm stops.
Lemma 1 (a returned gcd is a proper factor). Suppose line L5 returns for some k≤t+1 and some a with a2−4kN=b2, b≥0, and (a2−4kN)3<N2. Then d=gcd(a+b,N) satisfies 1<d<N.
Proof. From b6<N2 we get b<t. From a2=4kN+b2<4(t+1)t3+t2=t2(2t+1)2, we get a<t(2t+1). So a+b<2t2+2t. The inequality 2t2+2t<t3 is t2−2t−2>0, which holds for t>1+3≈2.73, so for N>20.4. Hence a+b<N. Also a2−b2=4kN>0 with a,b≥0, so a>b and a−b≥1.
N divides 4kN=(a+b)(a−b). If d=N, then N∣a+b with 0<a+b<N, which is impossible. If d=1, then N∣a−b, and 0<a−b<a+b<N, which is impossible. So 1<d<N. □
Lemma 2 (Dirichlet). Let ξ be a real number and B>1 a real number. There are integers u and v with 1≤v≤B and ∣vξ−u∣<1/B.
Proof. Let M=⌊B⌋≥1. The M+2 numbers 0,1 and {jξ}=jξ−⌊jξ⌋ for j=1,…,M lie in [0,1]. Split [0,1] into the M+1 closed intervals [i/(M+1),(i+1)/(M+1)]. Two of the M+2 numbers lie in the same interval, so they differ by at most 1/(M+1). Each of the numbers has the form jξ−uj with 0≤j≤M (with 0=0ξ−0 and 1=0ξ+1), and the two chosen numbers cannot both have j=0, because 0 and 1 differ by 1>1/(M+1). Their difference is vξ−u with 1≤∣v∣≤M; replacing (v,u) by (−v,−u) if needed, 1≤v≤M≤B, and ∣vξ−u∣≤1/(M+1)<1/B since M+1>B. □
Lemma 3 (a good multiplier exists). Let N=pq with primes t<p≤q. Then there are integers u,v≥1 such that k=uv satisfies 1≤k<t+1, and a=uq+vp, b=∣uq−vp∣ satisfy a2−b2=4kN, a≥4kN and b<t.
Proof. Let B=N1/6q/p. Since q≥p and N>1, B>1. Apply Lemma 2 with ξ=p/q: there are u,v with 1≤v≤B and ∣vp/q−u∣<1/B. Multiply by q: ∣vp−uq∣<q/B=pq/N1/6=N1/2−1/6=t. So b<t.
If u≤0, then ∣vp−uq∣≥vp≥p>t, a contradiction; so u≥1. Next, u<vp/q+1/B, so k=uv<v2p/q+v/B≤B2p/q+1=N1/3+1=t+1, using v≤B.
Finally, a2−b2=(uq+vp)2−(uq−vp)2=4uvpq=4kN, and by the inequality of the means a=uq+vp≥2uq⋅vp=2kN. □
Theorem. LEHMAN(N) returns a divisor d of N with 1<d<N if N is composite, and returns N if N is prime.
Proof. If line L1 returns d, then 2≤d≤t<N and d∣N. If line L5 returns, then Lemma 1 applies, since the loop of line L2 only uses k≤⌊t⌋+1≤t+1 and line L4 checks (a2−4kN)3<N2. So every value returned on lines L1 or L5 is a proper divisor; in particular, for prime N neither line returns, and line L7 returns N.
Let N be composite, and suppose line L1 returns nothing. Then N has no prime factor at most t. If N had three prime factors (with multiplicity), their product would exceed t3=N. So N=pq with primes t<p≤q. Take u,v,k,a,b from Lemma 3. Since k is an integer with 1≤k<t+1, it satisfies k≤⌊t⌋+1, so the loop of line L2 reaches k unless it returned earlier. For this k, line L3 starts at ⌈4kN⌉≤a, and a2−4kN=b2 with b6<t6=N2. The value a′2−4kN increases with a′, so every a′ from ⌈4kN⌉ to a passes the test of line L4, and the loop reaches a unless line L5 returned earlier. At a, line L5 finds the square b2 and returns. So for composite N the algorithm always returns on line L1 or L5, never on line L7. ■