Proofs: Pocklington primality test
These are the human proofs of Pocklington primality test, at full length.
Correctness of the Pocklington primality test full
This proof shows: correctness, termination, error.
We prove that POCKLINGTON returns PRIME only for primes, returns COMPOSITE only for composites, always stops, and returns UNKNOWN on a prime with probability at most . The input is an odd , a divisor of with and the distinct primes, and the number of tries for each prime.
Lemma 1 (order of a prime power). Let be a prime, a prime, , and an integer with and . Then the multiplicative order of modulo is , and .
Proof. Since , and the order of divides , so for some . If , then and , which is false. So . By Fermat's little theorem , so .
Lemma 2 (Pocklington). Suppose that for each there is a base with and . Then every prime factor of satisfies , and is prime.
Proof. Fix a prime and an index . Put , an integer power because . Then , since . Also . If this were , then would divide both and , against the gcd condition. So Lemma 1 gives . The prime powers are pairwise coprime, so their product divides . Hence .
If were composite, it would have a prime factor , which contradicts . So is prime.
Correctness of PRIME. Line L12 is reached only after the loop of line L4 has finished for every prime . The loop for ends without a return only by the break of line L10, so a base was recorded for which line L7 did not return, that is , and line L8 gave , that is . Line L3 has checked and . Lemma 2 applies, so is prime. For , line L1 returns PRIME only for and , which are prime.
Correctness of COMPOSITE. Line L1 returns COMPOSITE for (and for negative ), none of which is prime. Line L2 returns it for an even , which has the factor . Line L7 returns it when for some . If were prime, then and Fermat's little theorem would give ; so is composite. Line L9 returns it with and ; then is a proper divisor of , so is composite.
Termination. Line L4 runs over primes and line L5 does at most tries for each, and every step of a try (two modular powers and a gcd) stops. So the call stops after at most tries.
Error: UNKNOWN on a prime. Let be prime. Then lines L7 and L9 never return: by Fermat's little theorem, and with is or , because is prime and . Moreover exactly when . The group is cyclic of order , and , so the map has kernel of size exactly (the kernel of the power map in a cyclic group of order with exponent has size ). The base lies in and is not in , so at most of the bases in are bad. Since and ,
The bases for are independent and uniform, so the loop for fails all tries with probability at most . By the union bound over the primes of , the call returns UNKNOWN with probability at most , and otherwise it returns PRIME.
Error: composites. For a composite , the call never returns PRIME, by the correctness of PRIME. It returns COMPOSITE or UNKNOWN; UNKNOWN is not a wrong answer, only a missing one. So all errors are of one kind: a prime may receive UNKNOWN, with the probability bounded above, and no input ever receives a wrong verdict.