Proving Primality
This is Lab 13 from Clint by Hugh Montgomery, edited by Codex and Elad Zelingher. All rights reserved to Hugh Montgomery.
We have seen that a composite number can be proved to be composite very quickly by means of the strong pseudoprime test. Finding the complete factorization of a composite number takes longer, but for large we have methods that are much faster than trial division. To complete the picture we need a fast method for proving the primality of a large prime number . In this direction, we show that proving the primality of is no harder than factoring . Suppose that , and that for every prime factor of . Then has order modulo , and hence must be prime. In general, if is prime then such a is not hard to find; thus we have a means of proving that is prime provided that we can factor .
Problem 1
Apply PrimRoot to 8675309. The machine quickly responds with a primitive root, because 8675308 is easily factored. Thus the primality of 8675309 has been rigorously established. (David Farmer proposes that this is the largest prime number ever mentioned in a popular song.)
The simple idea used above can be strengthened in several ways. First, suppose that is a prime factor of , say . Let denote an arbitrary prime factor of . Presumably the only such is , but this remains to be proved. Suppose that we can find a number such that but such that . Then but . (Note that we can deduce this without knowing the value of .) Hence divides the order of modulo , and consequently . That is, every prime factor of is . Suppose we repeat this for several different prime factors of . (The value of that works is allowed to depend on .) Let denote the product of the primepowers for which this calculation has succeeded. Then we can assert that every prime factor of is . Since the product of two or more such primes must be , we see that if then must be prime. Hence we can establish the primality of , based only on an incomplete factorization of , provided that we can factor , , and . (This analysis is related to Problems 38, 39 at the end of §2.8 of NZM.)
Problem 2
It is easy to confirm that . Use the program ProveP to demonstrate that this second factor is prime. That is, apply ProveP to 16692759230113, and note the results.
Problem 3
If, as the factorization of proceeds, a point is reached at which the factored portion of is so large that testing for divisors , will take less time than the time already spent trying to factor , then the program ProveP automatically switches to the latter approach. To witness an instance of this, apply ProveP to the number .
The method of proving primality being employed here can be made still more efficient. Suppose that as prime factors of are being found, we reach a point at which . Then either is prime or is the product of two primes, , say. Write and , so that . With a little care with inequalities, it can be shown that and that . Thus the representation of that we have given here in terms of powers of coincides with the expansion of in base . That is, by the division algorithm we may write with , and , . To determine whether such and exist, we have only to test whether is a perfect square. This embellishment is due to H. C. Williams.
Problem 4
Apply the program ProveP to demonstrate that the number is prime. Also that is prime. If the program GetNextP is given an argument for which , then the number returned is the least integer that is a strong pseudoprime to bases 2, 3, 5, 7 and 11. It is incredibly likely that is prime, but to obtain a rigorous proof one should use the program ProveP. In this manner, find the least prime greater than 12345678987654321.
Problem 5
In most cases the method used by ProveP is reasonably quick. However, it can happen that where is prime. In such a case, attention is focused on . After a brief attempt to factor it by trial division fails, one should apply a strong pseudoprime test. If passes the test, then a rigorous proof that is prime may be obtained by applying the program ProveP to . In attempting to factor one may encounter the same problem as with . Nevertheless, by systematically employing the programs ProveP, SPsP, Factor and Rho, the needed factorizations can be rigorously established. For example, suppose that we apply the program ProveP to show that the number is prime. The machine quickly finds that is divisible by 2 and by 3, but then there is a pause. Touch any key to interrupt the program, and you find that it is trying to factor 164548830721543. Type q to quit, and then apply the program SPsP to this factor. In this way we discover that we are dealing with a composite number, so we apply the program Rho, which discloses that the factor may be written as . We apply the program Factor to the first of these numbers, to confirm that it is prime. Then we again apply ProveP to the original number . Again the machine finds 2 and 3, but when it pauses, we interrupt it, type s to indicate that we wish to supply a prime factor, and enter 5378033. This time the program reaches a successful resolution without further intervention, and it is proved that is indeed prime. Show that is prime. What intermediate numbers need to be factored? Give an account of the programs used, and the findings. (By applying GetNextP to this number you may confirm that this is the largest prime not exceeding . Similarly, show that is prime. Indicate what numbers are encountered, and how they are dealt with.
Problem 6
Show that and are both prime.
Problem 7
What is the first composite number in the sequence 31, 331, 3331, 33331, ? Apply ProveP until the first composite element is encountered. Here the -th term is . Show that for every , the least prime factor dividing is . Show that precisely when lies in a certain residue class (mod 16). (Suggestion: Use the program PowerTab to display for appropriate .)
Problem 8
For the programmer. When attempting to prove that is prime, we factor . After removing the factor 2, this leaves to be factored—but this may be prime. In such a case we would confirm that is prime by applying ProveP. However, it may happen that with prime. Perhaps also with prime. It is in such a case that our procedure for establishing primality will require the most work. How long can a chain of primes be, with ? Construct a program to explore this. Apply the SPSP test to odd integers until a probable prime is found. Then apply SPSP to , and so on, until a chain of probable primes has been constructed. If this chain is of record-breaking length, print out and , so that the program ProveP can be applied to the members of the chain. The first chain you will find is , ; the next one is , , , . Show that if begins a chain of length at least 4, with , then necessarily . For more on such chains, see D. H. Lehmer, On certain chains of primes, Proc. London Math. Soc. (3) 14a (1965), 183–186.
By the method of primality proof employed here, we see that proving that is prime is no harder than factoring . Other methods of proving primality have been proposed, and some of these are significantly more efficient than our best factoring algorithms. Thus a prime of 1000 digits can be proved to be prime, but the record for factoring hard composite numbers stands below 200 digits. One of the methods currently in wide use is that of Adleman, Pomerance and Rumely (the APR method); it depends on Gauss sums. A method depending on elliptic curves, devised by Atkin and Morain, has achieved some striking successes lately. For more information concerning proofs of primality, consult the following papers.
L. M. Adleman, C. Pomerance, and R. S. Rumely, On distinguishing prime numbers from composite numbers, Ann. of Math. (2) 117 (1983), 173–206.
A. O. L. Atkin and F. Morain, Elliptic curves and primality proving, Math. Comp. 61 (1993), 29–68.
J. D. Dixon, Factorization and primality tests, Amer. Math. Monthly. 91 (1984), 333–352.