Powering Algorithms and Primality Testing
This is Lab 7 from Clint by Hugh Montgomery, edited by Elad Zelingher. All rights reserved to Hugh Montgomery.
The number can be determined by multiplications of residue classes, but this is slow if is large. There is a much faster way: The values of , can be determined, by repeated squaring, in only multiplications. The binary expansion of provides a representation of as a sum of powers of 2 , and hence is a product of an appropriate collection of the numbers . For example, , and hence . The exact number of multiplications required by this method varies irregularly with , but it never exceeds . The binary expansion of can be built from the bottom up, or from the top down. The former of these two methods is discussed on pages 76, 77 of §2.4 of NZM.
Problem 1
Apply the program PwrDem using its three different algorithm types to several values of until the process is clear to you. Apply the Left-to-Right and the Right-to-Left binary methods to the same . How do the number of multiplications compare?
Problem 2
If has binary expansion with , then our powering algorithm requires multiplications to calculate . In particular, it takes 6 multiplications to calculate . Show that can be obtained with only 5 multiplications.
Problem 3
The program Power evaluates . Use the program Power to evaluate where 11111111111111111. Assuming Fermat's congruence, (Theorem 2.7 of NZM), this provides a quick (but indirect) proof that 11111111111111111 is composite. Apply the program Factor to 11111111111111111, and note how long it runs. With large numbers (of hundreds of digits), it is often the case that a quick proof that is composite can be given, even though we know of no way to obtain the factors of within a reasonable amount of time.
Problem 4
Is 91 prime? Evaluate . Is 341 prime? Evaluate . Now evaluate (mod 341). What do you conclude?
Problem 5
We have no quick method to find akin to our quick method for calculating powers. There are a few special cases (such as ), but in general the fastest method known involves simply performing the multiplications. If a quick method could be found, then it would have important applications (to factoring, for example). Suppose that you are in possession of a quick method for calculating .
Explain how this could be used to provide a quick method for calculating . Suppose you have a quick method for calculating . Explain how this could be used to provide a quick method for factoring .
Discussion
If and then is composite. Since it is easy to calculate powers modulo , this provides a quick proof that is composite-when it works. Unfortunately, the converse is false, but the counterexamples seem to be rare, so we call a probable prime base if is odd and . If is a probable prime base but is nevertheless composite, then we call a pseudoprime base , or, briefly, is a . If is found to be a probable prime base 2 , then we might try base 3, and so on, but there exist composite that are probable primes to every base for which . To see how this might happen, suppose that is a composite squarefree number with the peculiar property that for every prime number dividing . (The least such is 561 .) Suppose that . If then , and hence . Since , it follows that . Since this congruence holds for every dividing , it holds modulo the product of all the primes dividing . But we have assumed that is squarefree; hence . An odd composite number such that whenever is called an absolute pseudoprime, or Carmichael number. The least Carmichael number is 561 ; indeed, it can be shown that if is a Carmichael number then is of the form we considered: is squarefree and whenever . (This is called Korselt's criterion; see Problems 25-27 at the end of of NZM.) It is not hard to show that there exist infinitely many pseudoprimes to any given base (see Problem 19 at the end of of NZM), and it is easy to construct numerical examples of Carmichael numbers and to give arguments that suggest that Carmichael numbers form a fairly rich subset of the integers (by methods akin to the construction of Problem 20 of of NZM). In particular, P. Erdős (On pseudoprimes and Carmichael numbers, Publ. Math. Debrecen 4 (1956), 201-206) formulated a heuristic argument that suggests that the number of Carmichael numbers not exceeding is larger than for all sufficiently large . Although Erdős's conjecture is presumably true, it seems that the tends to 0 slowly, since numerical studies have revealed that , and that . Nevertheless, it was finally proved that there do indeed exist infinitely many Carmichael numbers. W. R. Alford, A. Granville, and C. Pomerance, (There are infinitely many Carmichael numbers, Ann. of Math. (2) 139 (1994), 703-722) showed that for all sufficiently large .
Since the pseudoprime test fails to establish the compositeness of some composite numbers, we consider a slightly more elaborate test, which, however, involves no more calculation than before. If is odd, we repeatedly divide 2 into , until we obtain a representation with odd. Suppose that . Compute . Next, repeatedly square, forming the sequence . Let denote this last residue class computed. If then , and hence is composite, by Fermat's congruence. Suppose now that . If then is composite by virtue of Lemma 2.10 of NZM. More generally, if in the sequence of powers computed we find an entry followed by an entry 1 , then , and hence is composite. This test is more stringent than the previous one; if it is inconclusive then we call a strong probable prime base . If in addition is composite then we call a strong pseudoprime base , or is an . In practice, we abandon the repeated squaring if a value is encountered, since the conclusion is already clear. The exact sequence of steps performed is exhibited on p. 78 of NZM. It is known that if is composite then there are at least bases such that the compositeness of is demonstrated by applying this strong pseudoprime test base . Thus if survives this test for several values of , we can be reasonably confident that is prime - such an might be called an "industrial grade prime".
Problem 6
By means of lengthy calculation (see C. Pomerance, J. L. Selfridge, and S. S. Wagstaff Jr., The pseudoprimes to , Math. Comp. 35 (1980), 1003-1026), it has been found that there are only 13 odd integers that are for , and . Of these, only one, namely is also a . Apply the strong pseudoprime test to this with bases , and 11. For example, try using the program SPsPDem with input , .
Problem 7
By appropriate use of the program Power, show that 4369 and 4371 are both probable primes base 2. Are either of these numbers strong probable primes base 2? Are either of these numbers prime? (Use the program SPsP to answer this question, not Factor.) Are either of these numbers Carmichael numbers?
Problem 8
Factor 561 using Factor, verify that 561 is squarefree, and that for every prime dividing 561. Hence deduce that 561 is a Carmichael number.
Problem 9
If is a but not a then the strong pseudoprime test locates a number such that , but . In such a situation not only is it established that is composite, but also a proper divisor of can be exhibited, namely . Apply the program SPsPDem to with .
Problem 10
Numerical evidence suggests that most pseudoprimes are squarefree. To explain this, show that if is a , and if is a prime such that , then
(Hint: , and hence . But divides .) Conversely, show that if is a prime such that (1) holds then is a . Only a few primes have been found for which , although it is believed that infinitely many exist. The least such prime is 1093 . Use the program Factor to verify that 1093 is prime, and the program Power to verify that . Is 1093 a ?
For an extensive account of primality testing see H. C. Williams, Primality testing on a computer, Ars Comb. 5 (1978), 127-185.