Proofs: Dixon's random squares algorithm
These are the human proofs of Dixon's random squares algorithm, at full length.
Correctness of Dixon's random squares algorithm full
This proof shows: correctness, termination.
Write for the group of units modulo , that is, the residues in prime to , and for the exponent vector of over when it exists.
Lemma 1 (the elimination). Let be the exponent vectors mod 2, as bit masks. When row reduces to , the subset it carries is nonempty and , where is the sum mod 2. If , at least subsets are found.
Proof. Row starts with and . Each reduction adds a stored pivot pair with to by in both parts, so stays true. The stored pairs come from rows , so and stays in ; thus . Each reduction clears the leading bit of and changes only lower bits, so a row either reduces to or becomes a pivot with a leading bit that no other pivot has. There are bit positions, so at most pivots, and at least rows reduce to .
Lemma 2 (the congruence). For every subset tried at line L7, .
Proof. Each relation has by line L5. Let . By Lemma 1 every is even, so .
Lemma 3 (square roots). Let be odd with exactly distinct prime factors, and let be . Each nonempty fiber is a coset of the kernel , and . For units with , is a proper factor of if and only if .
Proof. is a homomorphism of the abelian group , so its fibers are the cosets of its kernel . By the Chinese remainder theorem, is the product of the groups over the prime powers . For odd , the group of units modulo is cyclic of even order, so it has exactly two elements with square , namely . Hence .
For the second claim, . If , the gcd is . If , then is a unit because is odd, so the gcd is . Conversely, if the gcd is then . If the gcd is , then , so . In all other cases .
Theorem. The algorithm stops and returns or a proper factor of . Suppose is odd with distinct prime factors. Then, conditioned on the event that the run reaches line L6, each subset that line L6 produces gives a proper factor at line L8 with probability at least .
Proof. Termination. The loop of lines L2 to L5 makes at most draws. Each smoothness test divides a positive integer by primes, so it stops. Line L6 runs Lemma 1 on finitely many rows, and lines L7 and L8 run once per subset.
Correctness. At line L4, , so , and is tested; so is a proper factor. Line L8 returns only if . Otherwise line L9 returns . So the output is always or a proper factor. A prime has no proper factor, so the output is .
Probability. The run reaches line L6 exactly when no draw had . Conditioned on this, the draws are independent and uniform on . Condition further on the values . By Lemma 3, each is then uniform on the coset , and the stay independent, because the fibers of all have size and the draws were independent. Every choice of the algorithm before line L8 depends only on the values : the number of draws, the smoothness test, the vectors, the subsets of Lemma 1 and the value . So, given the , the subset and are fixed. Also is a unit: if a prime divides , it does not divide , because with , so .
Pick one relation and write , where is the product of the other in modulo and is independent of . Given , is uniform on the coset , which has elements. By Lemma 2, , so lie in this coset too, and they are two distinct elements since is odd and is a unit. So has probability . By Lemma 3, line L8 finds a proper factor in every other case. Since this holds for every value of the conditions, it holds after removing them.