Algorithm Search⌘K

Proofs: Pollard's rho algorithm

These are the human proofs of Pollard's rho algorithm, at full length.

Correctness of Pollard's rho algorithm full

This proof shows: correctness, termination.

Let N≥2N \ge 2, cc an integer and 0≤s<N0 \le s < N. Let f(x)=(x2+c) mod Nf(x) = (x^2 + c) \bmod N and xi=f(i)(s)x_i = f^{(i)}(s), so x0=sx_0 = s.

Lemma 1 (the passes). After ii passes of the loop of lines L2 to L5, x=xix = x_i and y=x2iy = x_{2i}.

Proof. Line L1 gives x=y=s=x0x = y = s = x_0. If x=xix = x_i and y=x2iy = x_{2i} before a pass, then line L3 gives x=f(xi)=xi+1x = f(x_i) = x_{i+1} and line L4 gives y=f(f(x2i))=x2i+2y = f(f(x_{2i})) = x_{2i + 2}. □\square

Lemma 2 (reduction). For each divisor m≥1m \ge 1 of NN, the residues ui=xi mod mu_i = x_i \bmod m satisfy ui+1=(ui2+c) mod mu_{i+1} = (u_i^2 + c) \bmod m. So uiu_i is the orbit of u0u_0 under the map h(u)=(u2+c) mod mh(u) = (u^2 + c) \bmod m on the finite set {0,…,m−1}\{0, \dots, m - 1\}.

Proof. xi+1=xi2+c−kNx_{i+1} = x_i^2 + c - kN for some integer kk, and m∣Nm \mid N, so xi+1≡xi2+c≡ui2+c(modm)x_{i+1} \equiv x_i^2 + c \equiv u_i^2 + c \pmod m. □\square

Lemma 3 (Floyd). Let u0,u1,…u_0, u_1, \dots be the orbit of a map hh on a finite set of size mm. There are integers μ≥0\mu \ge 0 and λ≥1\lambda \ge 1 with μ+λ≤m\mu + \lambda \le m such that u0,…,uμ+λ−1u_0, \dots, u_{\mu + \lambda - 1} are distinct and ui+λ=uiu_{i + \lambda} = u_i for all i≥μi \ge \mu. For i≥1i \ge 1, ui=u2iu_i = u_{2i} holds if and only if i≥μi \ge \mu and λ∣i\lambda \mid i. The least such i≥1i \ge 1 is at most μ+λ≤m\mu + \lambda \le m.

Proof. Among u0,…,umu_0, \dots, u_m there are m+1m + 1 values in a set of size mm, so some value repeats. Let jj be the least index such that uj=uku_j = u_k for some k<jk < j, and let μ=k\mu = k, λ=j−k\lambda = j - k. Then u0,…,uj−1u_0, \dots, u_{j - 1} are distinct, j=μ+λ≤mj = \mu + \lambda \le m, and uμ+λ=uμu_{\mu + \lambda} = u_\mu. Applying hh repeatedly gives ui+λ=uiu_{i + \lambda} = u_i for every i≥μi \ge \mu, and so ui+tλ=uiu_{i + t\lambda} = u_i for t≥0t \ge 0.

If i≥μi \ge \mu and λ∣i\lambda \mid i, write i=tλi = t\lambda; then u2i=ui+tλ=uiu_{2i} = u_{i + t\lambda} = u_i. Conversely, let ui=u2iu_i = u_{2i} with i≥1i \ge 1. If i<μi < \mu, then the value uiu_i lies on the tail, but every uku_k with k≥μk \ge \mu is on the cycle {uμ,…,uμ+λ−1}\{u_\mu, \dots, u_{\mu+\lambda-1}\}, which is disjoint from the tail since u0,…,uμ+λ−1u_0, \dots, u_{\mu+\lambda-1} are distinct; and if 2i<μ2i < \mu then uiu_i and u2iu_{2i} are two distinct tail values. Either way ui≠u2iu_i \ne u_{2i}, a contradiction, so i≥μi \ge \mu. Then u2i=uiu_{2i} = u_i with both indices at least μ\mu, and on the cycle uk=ulu_k = u_l for k,l≥μk, l \ge \mu holds only if λ∣k−l\lambda \mid k - l, because uμ,…,uμ+λ−1u_\mu, \dots, u_{\mu+\lambda-1} are distinct. So λ∣i\lambda \mid i. Among μ,μ+1,…,μ+λ−1\mu, \mu + 1, \dots, \mu + \lambda - 1 there is a multiple of λ\lambda, and if μ=0\mu = 0 then λ\lambda itself works; so the least i≥1i \ge 1 with ui=u2iu_i = u_{2i} is at most μ+λ\mu + \lambda. □\square

Termination. Apply Lemmas 2 and 3 with m=Nm = N. There is an i∗≤Ni^* \le N with xi∗=x2i∗x_{i^*} = x_{2i^*}. If the loop has not stopped before pass i∗i^*, then at pass i∗i^*, by Lemma 1, line L5 computes gcd⁡(0,N)=N≠1\gcd(0, N) = N \ne 1, and the loop stops. So the loop runs at most NN passes.

Correctness. The loop stops only when g≠1g \ne 1, and gg is a gcd with N≥2N \ge 2, so the returned gg is a divisor of NN with g>1g > 1.

When it succeeds. Let the loop stop at pass ii. For each prime power rk∥Nr^k \parallel N, rk∣gr^k \mid g if and only if xi≡x2i(modrk)x_i \equiv x_{2i} \pmod{r^k}. So g<Ng < N exactly when some prime power part of NN has not yet closed its cycle in the sense of Lemma 3 at pass ii, and g>1g > 1 shows that some prime r∣Nr \mid N has xi≡x2i(modr)x_i \equiv x_{2i} \pmod r. In particular, if a prime p∣Np \mid N has its first i≥1i \ge 1 with xi≡x2i(modp)x_i \equiv x_{2i} \pmod p strictly smaller than the first such ii for NN, then the algorithm returns a proper factor of NN that is a multiple of pp. ■\blacksquare

Back to Pollard's rho algorithm