Pocklington primality test

In mathematics, the Pocklington n−1 primality test (or Pocklington–Lehmer primality test) is a primality test devised by Henry Cabourn Pocklington and Derrick Henry Lehmer. The test uses a partial factorization of N−1 to prove that an integer N is prime.

It produces a primality certificate to be found with less effort than the Lucas primality test, which requires the full factorization of N−1.

Pocklington criterion

The basic version of the test relies on the Pocklington theorem (or Pocklington criterion) which is formulated as follows:

Theorem—Let N>1 be an integer, and suppose there exist natural numbers a and p such that

Then N is prime.

Here i≡j(modk) means that after finding the remainder of division by k, i and j are equal; i|j means that i is a divisor for j; and gcd is the greatest common divisor.

Note: Equation (1) is simply a Fermat primality test. If we find any value of a, not divisible by N, such that equation (1) is false, we may immediately conclude that N is not prime. (This divisibility condition is not explicitly stated because it is implied by equation (3).) For example, let N=35. With a=2, we find that aN−1≡9(modN). This is enough to prove that N is not prime.

Proof

Suppose N is not prime. This means there must be a prime q, where q≤N that divides N.

Since p>N−1≥q−1, p>q−1, and since p is prime, gcd⁡(p,q−1)=1.

Thus there must exist an integer u, a multiplicative inverse of p modulo q−1, with the property that

and therefore, by Fermat's little theorem

This implies

1≡aN−1(modq),     by (1) since q|N
≡(aN−1)u≡au(N−1)≡aup((N−1)/p)≡(aup)(N−1)/p(modq),
≡a(N−1)/p(modq),     by (5)

This shows that q divides the gcd⁡() in (3), and therefore this gcd⁡()≠1; a contradiction.

Given N, if p and a can be found which satisfy the conditions of the theorem, then N is prime. Moreover, the pair (p, a) constitute a primality certificate which can be quickly verified to satisfy the conditions of the theorem, confirming N as prime.

The main difficulty is finding a value of p which satisfies (2). First, it is usually difficult to find a large prime factor of a large number. Second, for many primes N, such a p does not exist. For example, N=17 has no suitable p because N−1=24, and p=2<N−1, which violates the inequality in (2); other examples include N=19,37,41,61,71,73, and 97.

Given p, finding a is not nearly as difficult. If N is prime, then by Fermat's little theorem, any a in the interval 1≤a≤N−1 will satisfy (1) (however, the cases a=1 and a=N−1 are trivial and will not satisfy (3)). This a will satisfy (3) as long as ord(a) does not divide (N−1)/p. Thus a randomly chosen a in the interval 2≤a≤N−2 has a good chance of working. If a is a generator mod N, its order is ⁠N−1⁠ and so the method is guaranteed to work for this choice.

Generalized Pocklington test

The above version of Pocklington's theorem is sometimes impossible to apply because some primes N are such that there is no prime p dividing N−1 where p>N−1. The following generalized version of Pocklington's theorem is more widely applicable.: Corollary 1 

Theorem—Factor N − 1 as N − 1 = AB, where A and B are relatively prime, A>N, the prime factorization of A is known, but the factorization of B is not necessarily known.

If for each prime factor p of A there exists an integer ap so that

then N is prime.

Proof

Let p be a prime dividing A and let pe be the maximum power of p dividing A. Let q be a prime factor of N. For the ap from the corollary set b≡ap(N−1)/pe(modq). This means bpe≡apN−1≡1(modq) and because of gcd⁡(ap(N−1)/p−1,N)=1 also bpe−1≡ap(N−1)/p≢1(modq).

This means that the order of b(modq) is pe

Thus, pe|(q−1). The same observation holds for each prime power factor pe of A, which implies A|(q−1).

Specifically, this means q>A≥N.

If N were composite, it would necessarily have a prime factor which is less than or equal to N. It has been shown that there is no such factor, which proves that N is prime.

Comments

The Pocklington–Lehmer primality test follows directly from this corollary. To use this corollary, first find enough factors of N − 1 so the product of those factors exceeds N. Call this product A. Then let B = (N − 1)/A be the remaining, unfactored portion of N − 1. It does not matter whether B is prime. We merely need to verify that no prime that divides A also divides B, that is, that A and B are relatively prime. Then, for every prime factor p of A, find an ap which fulfills conditions (6) and (7) of the corollary. If such aps can be found, the Corollary implies that N is prime.

According to Koblitz, ap = 2 often works.

Example

Determine whether

N=27457

is prime.

First, search for small prime factors of N−1. We quickly find that

N−1=26⋅3⋅B=192⋅B.

We must determine whether A=192 and B=(N−1)/A=143 meet the conditions of the Corollary. A2=36864>N, so A>N. Therefore, we have factored enough of N−1 to apply the Corollary. We must also verify that gcd⁡(A,B)=1.

It does not matter whether B is prime (in fact, it is not).

Finally, for each prime factor p of A, use trial and error to find an ap that satisfies (6) and (7).

For p=2, try a2=2. Raising a2 to this high power can be done efficiently using binary exponentiation:

a2N−1≡227456≡1(mod27457)
gcd⁡(a2(N−1)/2−1,N)=gcd⁡(213728−1,27457)=27457.

So, a2=2 satisfies (6) but not (7). As we are allowed a different ap for each p, try a2=5 instead:

a2N−1≡527456≡1(mod27457)
gcd⁡(a2(N−1)/2−1,N)=gcd⁡(513728−1,27457)=1.

So a2=5 satisfies both (6) and (7).

For p=3, the second prime factor of A, try a3=2:

a3N−1≡227456≡1(mod27457).
gcd⁡(a3(N−1)/3−1,N)=gcd⁡(29152−1,27457)=1.

a3=2 satisfies both (6) and (7).

This completes the proof that N=27457 is prime. The certificate of primality for N=27457 would consist of the two (p,ap) pairs (2, 5) and (3, 2).

We have chosen small numbers for this example, but in practice when we start factoring A we may get factors that are themselves so large their primality is not obvious. We cannot prove N is prime without proving that the factors of A are prime as well. In such a case we use the same test recursively on the large factors of A, until all of the primes are below a reasonable threshold.

In our example, we can say with certainty that 2 and 3 are prime, and thus we have proved our result. The primality certificate is the list of (p,ap)pairs, which can be quickly checked in the corollary.

If our example had included large prime factors, the certificate would be more complicated. It would first consist of our initial round of aps which correspond to the 'prime' factors of A; Next, for each factor of A where primality was uncertain, we would have more ap, and so on for factors of these factors until we reach factors of which primality is certain. This can continue for many layers if the initial prime is large, but the important point is that a certificate can be produced, containing at each level the prime to be tested, and the corresponding aps, which can easily be verified.

Morrison n + 1 primality test

Morrison n + 1 primality test, which uses a partial factorization of N+1 instead of N−1 to prove that an integer N is prime. Large primes of the form k⋅bn+1 are proven primes by the Pocklington n − 1 primality test, while large primes of the form k⋅bn−1 are proven primes by the Morrison n + 1 primality test.

Brillhart–Lehmer–Selfridge primality test

The 1975 paper by Brillhart, Lehmer, and Selfridge gives a proof for what is shown above as the "generalized Pocklington theorem" as Theorem 4 on page 623, called Brillhart–Lehmer–Selfridge primality test (BLS primality test). Additional theorems are shown which allow less factoring. This includes their Theorem 3 (a strengthening of an 1878 theorem of Proth):

Let N−1=mp where p is an odd prime such that 2p+1>N. If there exists an a for which a(N−1)/2≡−1(modN), but am/2≢−1(modN), then N is prime.

If N is large, it is often difficult to factor enough of N−1 to apply the above corollary. Theorem 5 of the Brillhart, Lehmer, and Selfridge paper allows a primality proof when the factored part has reached only (N/2)1/3, i.e. if the factored part of N−1 is larger than the cube root of N/2, then N can be proven to be prime. Many additional such theorems are presented that allow one to prove the primality of N based on the partial factorization of N−1, N+1, N2+1, and N2±N+1. Because they are cyclotomic polynomials evluated at N, this test is called cyclotomy primality test. If a prime p has none of N−1, N+1, N2+1, and N2±N+1 factor enough to make the number easily provable using the Brillhart–Lehmer–Selfridge primality test, then p is called an ordinary prime.

If the factored part has not reached (N/2)1/3 but reached (N/2)1/4, then Konyagin–Pomerance primality test (KP primality test) or Coppersmith–Howgrave–Graham primality test (CHG primality test) can be used. However, Konyagin–Pomerance test and Coppersmith–Howgrave–Graham test are like elliptic curve primality test (unlike Brillhart–Lehmer–Selfridge primality test), these two tests cannot be used for arbitrarily large numbers.