Algorithm Search⌘K

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 t 2−kt \, 2^{-k}. The input is an odd n≥5n \ge 5, a divisor F=∏j=1tqjejF = \prod_{j=1}^{t} q_j^{e_j} of n−1n - 1 with F2>nF^2 > n and the qjq_j distinct primes, and the number k≥1k \ge 1 of tries for each prime.

Lemma 1 (order of a prime power). Let pp be a prime, qq a prime, e≥1e \ge 1, and bb an integer with bqe≡1(modp)b^{q^e} \equiv 1 \pmod p and bqe−1≢1(modp)b^{q^{e-1}} \not\equiv 1 \pmod p. Then the multiplicative order of bb modulo pp is qeq^e, and qe∣p−1q^e \mid p - 1.

Proof. Since bqe≡1b^{q^e} \equiv 1, p∤bp \nmid b and the order dd of bb divides qeq^e, so d=qid = q^i for some 0≤i≤e0 \le i \le e. If i<ei < e, then d∣qe−1d \mid q^{e-1} and bqe−1≡1b^{q^{e-1}} \equiv 1, which is false. So d=qed = q^e. By Fermat's little theorem bp−1≡1b^{p-1} \equiv 1, so d∣p−1d \mid p - 1. □\square

Lemma 2 (Pocklington). Suppose that for each jj there is a base aja_j with ajn−1≡1(modn)a_j^{n-1} \equiv 1 \pmod n and gcd⁡(aj(n−1)/qj−1,n)=1\gcd(a_j^{(n-1)/q_j} - 1, n) = 1. Then every prime factor pp of nn satisfies p≡1(modF)p \equiv 1 \pmod F, and nn is prime.

Proof. Fix a prime p∣np \mid n and an index jj. Put b=aj(n−1)/qjejb = a_j^{(n-1)/q_j^{e_j}}, an integer power because qjej∣F∣n−1q_j^{e_j} \mid F \mid n - 1. Then bqjej=ajn−1≡1(modp)b^{q_j^{e_j}} = a_j^{n-1} \equiv 1 \pmod p, since p∣np \mid n. Also bqjej−1=aj(n−1)/qjb^{q_j^{e_j - 1}} = a_j^{(n-1)/q_j}. If this were ≡1(modp)\equiv 1 \pmod p, then pp would divide both aj(n−1)/qj−1a_j^{(n-1)/q_j} - 1 and nn, against the gcd condition. So Lemma 1 gives qjej∣p−1q_j^{e_j} \mid p - 1. The prime powers qjejq_j^{e_j} are pairwise coprime, so their product FF divides p−1p - 1. Hence p≥F+1>np \ge F + 1 > \sqrt n.

If nn were composite, it would have a prime factor p≤np \le \sqrt n, which contradicts p>np > \sqrt n. So nn is prime. □\square

Correctness of PRIME. Line L12 is reached only after the loop of line L4 has finished for every prime qjq_j. The loop for qjq_j ends without a return only by the break of line L10, so a base aj=aqja_j = a_{q_j} was recorded for which line L7 did not return, that is ajn−1 mod n=1a_j^{n-1} \bmod n = 1, and line L8 gave g=1g = 1, that is gcd⁡(aj(n−1)/qj−1,n)=1\gcd(a_j^{(n-1)/q_j} - 1, n) = 1. Line L3 has checked F∣n−1F \mid n - 1 and F2>nF^2 > n. Lemma 2 applies, so nn is prime. For n<5n < 5, line L1 returns PRIME only for 22 and 33, which are prime.

Correctness of COMPOSITE. Line L1 returns COMPOSITE for n∈{0,1,4}n \in \{0, 1, 4\} (and for negative nn), none of which is prime. Line L2 returns it for an even n≥6n \ge 6, which has the factor 22. Line L7 returns it when an−1≢1(modn)a^{n-1} \not\equiv 1 \pmod n for some a∈[2,n−2]a \in [2, n-2]. If nn were prime, then n∤an \nmid a and Fermat's little theorem would give an−1≡1a^{n-1} \equiv 1; so nn is composite. Line L9 returns it with g=gcd⁡(⋅,n)g = \gcd(\cdot, n) and 1<g<n1 < g < n; then gg is a proper divisor of nn, so nn is composite.

Termination. Line L4 runs over tt primes and line L5 does at most kk tries for each, and every step of a try (two modular powers and a gcd) stops. So the call stops after at most ktk t tries.

Error: UNKNOWN on a prime. Let nn be prime. Then lines L7 and L9 never return: an−1≡1a^{n-1} \equiv 1 by Fermat's little theorem, and g=gcd⁡(c−1,n)g = \gcd(c - 1, n) with c=a(n−1)/q mod nc = a^{(n-1)/q} \bmod n is 11 or nn, because nn is prime and c−1∈[−1,n−2]c - 1 \in [-1, n - 2]. Moreover g=ng = n exactly when c=1c = 1. The group Zn∗\mathbb{Z}_n^* is cyclic of order n−1n - 1, and q∣n−1q \mid n - 1, so the map x↦x(n−1)/qx \mapsto x^{(n-1)/q} has kernel KqK_q of size exactly (n−1)/q(n-1)/q (the kernel of the power map in a cyclic group of order mm with exponent d∣md \mid m has size dd). The base 11 lies in KqK_q and is not in [2,n−2][2, n-2], so at most (n−1)/q−1(n-1)/q - 1 of the n−3n - 3 bases in [2,n−2][2, n-2] are bad. Since q≥2q \ge 2 and n≥5n \ge 5,

(n−1)/q−1n−3≤(n−1)/2−1n−3=12.\frac{(n-1)/q - 1}{n - 3} \le \frac{(n-1)/2 - 1}{n - 3} = \frac{1}{2}.

The kk bases for qq are independent and uniform, so the loop for qq fails all kk tries with probability at most 2−k2^{-k}. By the union bound over the tt primes of FF, the call returns UNKNOWN with probability at most t 2−kt \, 2^{-k}, and otherwise it returns PRIME.

Error: composites. For a composite nn, 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. ■\blacksquare

Back to Pocklington primality test