Algorithm Search⌘K

Proofs: Brent's variant of Pollard's rho

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

Correctness of Brent's variant of Pollard's rho full

This proof shows: correctness, termination.

Let N≥2N \ge 2, 0≤s<N0 \le s < N, m≥1m \ge 1, f(x)=(x2+c) mod Nf(x) = (x^2 + c) \bmod N, x0=sx_0 = s and xi+1=f(xi)x_{i+1} = f(x_i). Let μ≥0\mu \ge 0 and λ≥1\lambda \ge 1 be the tail and cycle lengths of the sequence (xi)(x_i): x0,…,xμ+λ−1x_0, \dots, x_{\mu+\lambda-1} are distinct, and xi+λ=xix_{i+\lambda} = x_i for i≥μi \ge \mu. They exist because the sequence takes values in a set of NN elements (as in the proof for Pollard's rho). Then for j>i≥μj > i \ge \mu, xj=xix_j = x_i if and only if λ∣j−i\lambda \mid j - i.

Lemma 1 (the indices). At the start of the block with length rr (the first is r=1r = 1, then rr doubles), y=x2r−2y = x_{2r-2}. In that block, line L3 sets x=x2r−2x = x_{2r-2}, and the comparisons of line L7 are ∣x−xj∣|x - x_j| for j=3r−1,3r,…j = 3r - 1, 3r, \dots in order, up to 4r−24r - 2 if the block is not cut short. If the block runs to the end, y=x4r−2=x2(2r)−2y = x_{4r - 2} = x_{2(2r) - 2} at its end.

Proof. For r=1r = 1, line L1 gives y=x0y = x_0. Suppose y=x2r−2y = x_{2r-2} at the start of a block. Line L3 saves x=x2r−2x = x_{2r-2} and applies ff rr times, so y=x3r−2y = x_{3r-2}. The loop of lines L5 to L8 applies ff once before each comparison, so the comparisons use x3r−1,x3r,…x_{3r-1}, x_{3r}, \dots, and the batches together contain r−kr - k steps at most, rr in all, ending at x4r−2x_{4r-2}. Since 4r−2=2(2r)−24r - 2 = 2(2r) - 2, the claim holds for the next block. □\square

Lemma 2 (the product). At each gcd of line L8, q≡∏∣x−xj∣(modN)q \equiv \prod |x - x_j| \pmod N, the product over all comparisons made so far (in all blocks, each with the saved value of its own block).

Proof. qq starts at 11 and each comparison multiplies it by the new difference modulo NN. □\square

Termination of the main loop. Let r∗r^* be the least power of two with r∗≥max⁡(λ,μ,2)r^* \ge \max(\lambda, \mu, 2). Suppose the loop reaches the block with r=r∗r = r^*. Its saved index is 2r−2≥r≥μ2r - 2 \ge r \ge \mu. Its comparison indices jj run over 3r−1,…,4r−23r - 1, \dots, 4r - 2, so j−(2r−2)j - (2r - 2) runs over the rr consecutive integers r+1,…,2rr + 1, \dots, 2r; since r≥λr \ge \lambda, one of them is a multiple of λ\lambda. For that jj, xj=x2r−2x_j = x_{2r-2}, the difference is 00, and by Lemma 2 q≡0(modN)q \equiv 0 \pmod N at the next gcd, which gives g=gcd⁡(0,N)=N≠1g = \gcd(0, N) = N \ne 1. So the loop of line L2 ends at the latest in this block, after O(r∗)=O(N)O(r^*) = O(N) evaluations of ff. All inner loops are finite.

The backtrack. Suppose that after the main loop g=Ng = N. Consider the last batch, the one whose gcd gave NN, and let t1,…,tℓt_1, \dots, t_\ell (ℓ≤m\ell \le m) be its differences. The previous gcd (or the start, with q=1q = 1) gave 11, so the product q′q' before this batch is coprime to NN. Let pp be any prime factor of NN. Since p∣N=gcd⁡(q,N)p \mid N = \gcd(q, N) and q≡q′t1⋯tℓ(modN)q \equiv q' t_1 \cdots t_\ell \pmod N, pp divides q′t1⋯tℓq' t_1 \cdots t_\ell, and p∤q′p \nmid q', so p∣tip \mid t_i for some ii. Line L6 saved ys=yy_s = y at the start of this batch, and xx is unchanged, so the loop of line L11 recomputes ∣x−ys∣|x - y_s| equal to t1,t2,…t_1, t_2, \dots in order. At the first ii with gcd⁡(ti,N)>1\gcd(t_i, N) > 1, which exists by the argument above and has i≤ℓ≤mi \le \ell \le m, the loop stops.

Correctness. The algorithm returns gg only when g>1g > 1, either from the main loop (where g≠1g \ne 1) or from line L11 (where g>1g > 1). In both cases gg is a gcd with NN, so gg is a divisor of NN with g>1g > 1. If some prime p∣Np \mid N divides a difference before every prime power part of NN does, the gcd at that batch, or the backtrack, returns a proper divisor of NN that is a multiple of pp. ■\blacksquare

Back to Brent's variant of Pollard's rho