Factoring Strategies
This is Lab 8 from Clint by Hugh Montgomery, edited by Codex and Elad Zelingher. All rights reserved to Hugh Montgomery.
We know that trial division yields a rigorous proof of the factorization of in at most steps. This is slow when is large, so we now consider methods that are faster for large . Our object here is not to present state-of-the-art factoring, but only to drive home the point that it is possible to construct factoring strategies that are much faster than trial division.
Problem 1
Trial division takes steps if is prime or if is the product of two primes, with . However these are the worst cases, and trial division is much quicker for many numbers. To see why this is so, suppose that is composite and that are the distinct primes dividing . Explain why only trial divisions are required to factor . Trial division is unlikely to yield the complete factorization of a large in a reasonable amount of time, but nevertheless one should always try divisors through 100000 or so, when asked to factor a number of unknown multiplicative structure.
Problem 2
Although alternative factoring strategies can be traced as far back as Fermat and Gauss, we begin with a simple method of comparatively recent origin, namely Pollard's Rho Method, proposed in 1975 by J. M. Pollard. (Why it should be called “Rho” is explained on p. 81 of NZM.) Suppose that a prime number has been chosen. Let , and for let the numbers be determined by the relations , . Here is some constant. We usually start with , but other values of are sometimes handy, as will become clear later. The sequence may have a non-periodic initial segment, but once a value is repeated (as must eventually happen), the sequence becomes periodic. The program RhoDem will assist you in determining when this first repetition occurs. Use RhoDem, and in response to the query “Use cycle-detecting algorithm?” respond by selecting “List the sequence only.” Enter , and set . In the sequence of displayed, you will see that , but that . Thus the first repeat is at , and the period of the repetitions is 14. In general, let be the least index such that the value repeats a value found previously, and let denote the least period of the repetitions. Thus and . Repeat this calculation for the prime , and thus determine the values of and .
By the pigeon-hole principle we see that , but the “Birthday Paradox” leads us to expect that for most primes, and for most choices of . (See Lemma 2.21 in NZM, and the discussion following.)
Problem 3
In the examples above it is easy to spot the first repetition visually, but this task becomes rapidly more difficult when is a little larger. Repeat the steps above with . Scroll down through the table, and as you go, note the following four values:
| 130 | 2185 |
| 131 | 2212 |
| 147 | 1278 |
| 148 | 2212 |
Thus and . Since it is quite tedious (and time-consuming!) to compare each value with all the previous ones, we need a quick way to spot repetitions. This is provided by the following Cycle Detection Algorithm: Watch for an index at which . Let denote the least such . The advantages of this approach are that only one comparison need be made, and that only the values and . Thus we have no need to store the values of the . If then we use the recurrence once to compute , and twice more to compute . The old values , are discarded, and we continue with the two new values. The disadvantage of this approach is that it is slightly inefficient, in the sense that the recurrence must be used times, which is somewhat larger than , which would be optimal. Using RhoDem, complete the following table (the first row of which has been thoughtfully provided). Use RhoDem with no cycle-detecting first, to determine the values of and . By inspecting the values , try to determine the value of . Check your work by applying RhoDem a second time with cycle-detecting.
| 37 | 6 | 5 | 1 |
| 41 | |||
| 43 | |||
| 47 | |||
| 53 |
Problem 4
When we apply the Rho method to factor a number , we compute the sequence modulo . Suppose that . We can't construct the sequence (mod ), because the prime is unknown. However, the computed are congruent (mod ) to those we would have obtained if we had worked (mod ) (recall Theorem 2.1(5) of NZM). Hence when . Let denote the least index such that . Then
Moreover, for this index we have unless for all . Take where the are selected from the above table in such a way that . Apply RhoDem to this , with cycle-detecting, and note the point at which a divisor is found. Repeat this, with the selected so that . Note that the gcd jumps from 1 to , but that RhoDem does not give up. What does RhoDem do, instead? Finally, choose two so that but , and note that the prime factor found by RhoDem is not the least prime factor of .
The Pollard Rho Method should only be applied to numbers that are already known to be composite (as the result of a strong pseudoprime test, for example). If it were applied to a large prime number , it would run endlessly, switching to ever larger values of .
Problem 5
Apply RhoDem to . What is the least for which ? The program Rho will attempt to factor a given number by means of the Pollard rho algorithm. Apply Rho to 11111111111111111. Is this much faster than using the program Factor? What do you expect the running time of Rho to be, on average, as a function of the size of the least prime factor of ?
Problem 6
What inequalities can be established between the three quantities , , ? Explore.
Problem 7
In general you should avoid taking or in the rho method. Experiment with these values of , using RhoDem, and try to explain why these values of are bad. (Hint: For , note that if and then .)
Problem 8
For the programmer. Richard Brent has observed that the cycle-detecting algorithm can be made about 24% more efficient, as follows: Suppose that you have calculated and , and that you have tried for pairs with the difference running from to . Starting from , apply the iteration times, to evaluate . Next compute , , , . Here the differences between the subscripts range from to . If you start this with , then runs through powers of . To speed things up further, do not calculate the gcd separately for each term indicated above. Instead, form a product of these numbers, keeping track of the number of factors in the product. When the number of factors reaches , compute the gcd of the product with . The product, like everything else, is computed modulo .
Problem 9
We now turn to a second method proposed by Pollard, the “ Method.” Suppose that is a number to be factored, that , and that , so that whenever , which is to say that . Thus we use the powering algorithm to calculate a number , , so that , and then we use the Euclidean algorithm to evaluate in the hope that this will disclose a proper factor of . If this gcd is still 1 then we try a larger ; if it is then we switch to a different value of . This method is rather erratic: It is remarkably fast for some numbers, but for other numbers it is no faster than trial division. Apply the program P–1Dem to several numbers, and note how the calculation proceeds. The program P–1 is ridiculously fast when applied to . Use P–1 to break into factors, use Factor to verify that the factors are indeed prime, say . Apply Factor to and to , and thus demonstrate why P–1 is so quick for this number. At the opposite extreme, the program P–1 will take an uncomfortably long time to factor the comparatively small number . Find the prime factors of this , and also the factorization of for each such , to explain why the method is so slow in this case. Finally, apply the program P–1 to our old favorite, .
Problem 10
For the programmer. The Pollard method, as explained above, is slightly inefficient because the power of 2 dividing is much larger than is likely to be needed. Try using instead of , where denotes the least common multiple of the integers . Show that where if is a power of , otherwise. Note that unless is a primepower. Thus it is necessary to compute only when is a primepower. Does this lead to a more efficient method?
It is notable that we have no proof that the Pollard Rho Method is efficient, although we believe that on average it will yield a proper divisor of in steps, where is the smallest prime factor of . Although the method is erratic, the idea behind the method is used in other methods, notably the Elliptic Curve Method (ECM), devised by Lenstra in 1987. (See §5.8 of NZM.) In 1982, Carl Pomerance invented the Quadratic Sieve method (QS) of factoring, which has been further developed to become the Multiple Polynomial Quadratic Sieve (MPQS). These methods have largely usurped an older method, CFRAC, based on properties of continued fractions. A new method, the Number Field Sieve, (NFS) is currently being developed, and has already achieved some notable successes.
For more information concerning factoring, consult the following sources.
- D. M. Bressoud, Factorization and primality testing, Springer-Verlag, New York, 1989.
- D. V. Chudnovsky and G. V. Chudnovsky, “Sequences of numbers generated by addition in formal groups and new primality and factorization tests,” Adv. Appl. Math. 7 (1986), 385–434.
- D. Coppersmith, “Modifications to the number field sieve,” J. Cryptology 6 (1993), 169–180.
- J. D. Dixon, “Factorization and primality tests,” Amer. Math. Monthly 91 (1984), 333–352.
- R. K. Guy, “How to factor a number,” Proc. Fifth Conf. Numerical Math., Utilitas, Winnipeg, 1975, pp. 49–89.
- P. L. Montgomery, “Speeding the Pollard and elliptic methods of factorization,” Math. Comp. 48 (1987), 243–264.
- C. Pomerance, Lecture Notes on Primality Testing and Factoring, MAA Notes 4, Math. Assoc. of America, Washington, 1984.
- H. Riesel, Prime Numbers and Computer Methods for Factorization, Birkhäuser, Boston, 1985, 464 pp.
- H. C. Williams, “Factoring on a computer,” Math. Intell. 6 (1984), 29–36.
- M. C. Wunderlich, “Computational methods for factoring large integers,” Abacus 5 (1988), 19–33.