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 , , , , and . Let and be the tail and cycle lengths of the sequence : are distinct, and for . They exist because the sequence takes values in a set of elements (as in the proof for Pollard's rho). Then for , if and only if .
Lemma 1 (the indices). At the start of the block with length (the first is , then doubles), . In that block, line L3 sets , and the comparisons of line L7 are for in order, up to if the block is not cut short. If the block runs to the end, at its end.
Proof. For , line L1 gives . Suppose at the start of a block. Line L3 saves and applies times, so . The loop of lines L5 to L8 applies once before each comparison, so the comparisons use , and the batches together contain steps at most, in all, ending at . Since , the claim holds for the next block.
Lemma 2 (the product). At each gcd of line L8, , the product over all comparisons made so far (in all blocks, each with the saved value of its own block).
Proof. starts at and each comparison multiplies it by the new difference modulo .
Termination of the main loop. Let be the least power of two with . Suppose the loop reaches the block with . Its saved index is . Its comparison indices run over , so runs over the consecutive integers ; since , one of them is a multiple of . For that , , the difference is , and by Lemma 2 at the next gcd, which gives . So the loop of line L2 ends at the latest in this block, after evaluations of . All inner loops are finite.
The backtrack. Suppose that after the main loop . Consider the last batch, the one whose gcd gave , and let () be its differences. The previous gcd (or the start, with ) gave , so the product before this batch is coprime to . Let be any prime factor of . Since and , divides , and , so for some . Line L6 saved at the start of this batch, and is unchanged, so the loop of line L11 recomputes equal to in order. At the first with , which exists by the argument above and has , the loop stops.
Correctness. The algorithm returns only when , either from the main loop (where ) or from line L11 (where ). In both cases is a gcd with , so is a divisor of with . If some prime divides a difference before every prime power part of does, the gcd at that batch, or the backtrack, returns a proper divisor of that is a multiple of .