Prime Numbers

Prime Numbers Prime Numbers

thales.doa.fmph.uniba.sk
from thales.doa.fmph.uniba.sk More from this publisher
10.12.2012 Views

3.2 Sieving 123 this number’s entry is also 3. Dividing by 3 again, we get 1337, whose entry is 7. Dividing by 7, we get 191, whose entry is 1. Thus 191 is prime and we have the prime factorization 12033 = 3 2 · 7 · 191. Factor tables predate, by far, the computer era. Extensive hand-computed factor tables were indispensable to researchers doing numerical work in number theory for many decades prior to the advent of electronic calculating engines. 3.2.4 Sieving to construct complete factorizations Again, at the cost of somewhat more space, but very little more time, one may adapt the sieve of Eratosthenes so that next to entry m is the complete prime factorization of m. One does this by appending the prime p to lists at locations p, 2p, 3p,..., p⌊N/p⌋. One also needs to sieve with the powers pa of primes p ≤ √ N,wherethepowerpadoes not exceed N. At each multiple of pa another copy of the prime p is appended. To avoid sieving with the primes √N,N in the interval , one can divide to complete the factorization. For example, say N = 20000; let us follow what happens to the entry m = 12033. Sieving by 3, we change the 1 at location 12033 to 3. Sieving by 9, we change the 3 at location 12033 to 3, 3. Sieving by 7, we change the entry to 3, 3, 7. At the end of sieving (which includes sieving with all primes up to 139 and higher powers of these primes up to 20000), we return to each location in the sieve and multiply the list there. At the location 12033, we multiply 3 · 3 · 7, getting 63. Dividing 63 into 12033, the quotient is 191, which is also put on the list. So the final list for 12033 is 3, 3, 7, 191, giving the complete prime factorization of 12033. 3.2.5 Sieving to recognize smooth numbers Using the sieve of Eratosthenes to get complete factorizations may be simplified and turned into a device to recognize all of the B-smooth numbers (see Definition 1.4.8) in [2,N]. We suppose that 2 ≤ B ≤ √ N. Perform the factorization sieve as in the above subsection, but with two simplifications: (1) Do not sieve with any p a where p exceeds B, and (2) if the product of the list at a location is not equal to that location number, then do not bother dividing to get the quotient. The B-smooth numbers are precisely those at locations that are equal to the product of the primes in the list at that location. To simplify slightly, we might multiply a running product at each location by p whenever p a hits there. There is no need to keep the lists around if we are interested only in picking out the B-smooth numbers. At the end of the sieve, those locations whose location numbers are equal to the entry in the location are the B-smooth numbers. For example, say B =10andN = 20000. The entry corresponding to 12033 starts as 1, and gets changed sequentially to 3, to 9, and finally to

124 Chapter 3 RECOGNIZING PRIMES AND COMPOSITES 63. Thus 12033 is not 10-smooth. However, the entry at 12000 gets changed sequentially to 2, 4, 8, 16, 32, 96, 480, 2400, and finally 12000. Thus 12000 is 10-smooth. One important way of speeding this sieve is to do the arithmetic at each location in the sieve with logarithms. Doing exact arithmetic with logarithms involves infinite precision, but there is no need to be exact. For example, say we use the closest integer to the base-2 logarithm. For 12000 this is 14. We also use the approximations lg 2 ≈ 1 (this one being exact), lg 3 ≈ 2, lg 5 ≈ 2, lg 7 ≈ 3. The entry now at location 12000 gets changed sequentially to 1, 2, 3, 4, 5, 7, 9, 11, 13. This is close enough to the target 14 for us to recognize that 12000 is smooth. In general, if we are searching for B-smooth numbers, then an error smaller than lg B is of no consequence. One should see the great advantage of working with approximate logarithms, as above. First, the numbers one deals with are very small. Second, the arithmetic necessary is addition, an operation that is much faster to perform on most computers than multiplication or division. Also note that the logarithm function moves very slowly for large arguments, so that all nearby locations in the sieve have essentially the same target. For example, above we had 14 the target for 12000. This same number is used as the target for all locations between 2 13.5 and 2 14.5 , namely, all integers between 11586 and 23170. We shall find later an important application for this kind of sieve in factorization algorithms. And, as discussed in Section 6.4, sieving for smooth numbers is also crucial in some discrete logarithm algorithms. In these settings we are not so concerned with doing a perfect job sieving, but rather just recognizing most B-smooth numbers without falsely reporting too many numbers that are not B-smooth. This is a liberating thought that allows further speed-ups in sieving. The time spent sieving with a prime p in the sieve is proportional to the product of the length of the sieve and 1/p. In particular, small primes are the most time-consuming. But their logarithms contribute very little to the sum, and so one might agree to forgo sieving with these small primes, allowing a little more error in the sieve. In the above example, say we forgo sieving with the moduli 2, 3, 4, 5. We will sieve by higher powers of 2, 3, and 5, as well as all powers of 7, to recognize our 10smooth numbers. Then the running sum in location 12000 is 3, 4, 5, 9, 11. This total is close enough to 14 to cause a report, and the number 12000 is not overlooked. But we were able to avoid the most costly part of the sieve to find it. 3.2.6 Sieving a polynomial Suppose f(x) is a polynomial with integer coefficients. Consider the numbers f(1),f(2),...,f(N). Say we wish to find the prime numbers in this list, or to prepare a factor table for the list, or to find the B-smooth numbers in this list. All of these tasks can easily be accomplished with a sieve. In fact, we have already seen a special case of this for the polynomial f(x) =2x +1, when we

3.2 Sieving 123<br />

this number’s entry is also 3. Dividing by 3 again, we get 1337, whose entry<br />

is 7. Dividing by 7, we get 191, whose entry is 1. Thus 191 is prime and we<br />

have the prime factorization<br />

12033 = 3 2 · 7 · 191.<br />

Factor tables predate, by far, the computer era. Extensive hand-computed<br />

factor tables were indispensable to researchers doing numerical work in<br />

number theory for many decades prior to the advent of electronic calculating<br />

engines.<br />

3.2.4 Sieving to construct complete factorizations<br />

Again, at the cost of somewhat more space, but very little more time, one<br />

may adapt the sieve of Eratosthenes so that next to entry m is the complete<br />

prime factorization of m. One does this by appending the prime p to lists at<br />

locations p, 2p, 3p,..., p⌊N/p⌋. One also needs to sieve with the powers pa of<br />

primes p ≤ √ N,wherethepowerpadoes not exceed N. At each multiple of<br />

pa another copy of the prime p is appended. To avoid sieving with the primes<br />

√N,N<br />

in the interval , one can divide to complete the factorization.<br />

For example, say N = 20000; let us follow what happens to the entry<br />

m = 12033. Sieving by 3, we change the 1 at location 12033 to 3. Sieving by<br />

9, we change the 3 at location 12033 to 3, 3. Sieving by 7, we change the entry<br />

to 3, 3, 7. At the end of sieving (which includes sieving with all primes up to<br />

139 and higher powers of these primes up to 20000), we return to each location<br />

in the sieve and multiply the list there. At the location 12033, we multiply<br />

3 · 3 · 7, getting 63. Dividing 63 into 12033, the quotient is 191, which is also<br />

put on the list. So the final list for 12033 is 3, 3, 7, 191, giving the complete<br />

prime factorization of 12033.<br />

3.2.5 Sieving to recognize smooth numbers<br />

Using the sieve of Eratosthenes to get complete factorizations may be<br />

simplified and turned into a device to recognize all of the B-smooth numbers<br />

(see Definition 1.4.8) in [2,N]. We suppose that 2 ≤ B ≤ √ N. Perform the<br />

factorization sieve as in the above subsection, but with two simplifications: (1)<br />

Do not sieve with any p a where p exceeds B, and (2) if the product of the list<br />

at a location is not equal to that location number, then do not bother dividing<br />

to get the quotient. The B-smooth numbers are precisely those at locations<br />

that are equal to the product of the primes in the list at that location.<br />

To simplify slightly, we might multiply a running product at each location<br />

by p whenever p a hits there. There is no need to keep the lists around if we<br />

are interested only in picking out the B-smooth numbers. At the end of the<br />

sieve, those locations whose location numbers are equal to the entry in the<br />

location are the B-smooth numbers.<br />

For example, say B =10andN = 20000. The entry corresponding to<br />

12033 starts as 1, and gets changed sequentially to 3, to 9, and finally to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!