130 likes | 365 Views
Detecting Primes. Adam Brooks COT4810 February 12, 2008. Quick Number Theory Review. Prime number A natural number > 1 which has exactly two divisors – 1 and itself Composite number A non-prime number… a natural number that has a positive factor other than 1 and itself.
E N D
Detecting Primes Adam Brooks COT4810 February 12, 2008
Quick Number Theory Review • Prime number • A natural number > 1 which has exactly two divisors – 1 and itself • Composite number • A non-prime number… a natural number that has a positive factor other than 1 and itself
Application of Primes • Computer Science applies prime numbers in: • Cryptography • Hashing schemes • Sorting schemes • Random number generation
Algorithms • Numerous algorithms exist for detecting if a given number is prime or composite. • Finding primes vs. testing if a number is prime • Deterministic tests vs. Probabilistic (Monte-Carlo) tests
Sieve of Eratosthenes • Ancient Greek algorithm for identifying primes from 2..n • Steps: • Start with 2 and strike-out all multiples in the list • The first remaining number (3) is prime, strike-out it’s multiples and repeat the process
Fermat’s Theorem • Probabilistic test to determine if a number n is prime. • Repeated k times for randomly selected integers in the range [1, n) • If the equality an-1 mod n = 1 fails, then a is said to be a witness for the compositeness of n.
Rabin-Miller Test • Probabilistic (normally) method similar to Fermat’s where “witnesses” to a number’s compositeness are identified • A witness would be any integer w satisfying the following two conditions: 1. wn-1 = 1 mod n, or 2. For some integer k, and 1 < gcd(wn – 1, n) < n
Rabin-Miller Test (cont.) • A simple algorithm can be outlined: • Input prime candidate n • Select m integers w1, w2, …, wm at random from the set {2, 3, …, n – 1} • For i = 1, 2, …, m, test whether wi is a witness • If none of the m integers are witnesses output yes, else, output no.
Rabin-Miller Test (cont.) • How accurate is it? • Rabin theorized that if n is composite, more than half the numbers in the set {2, 3, …, n – 1} are witnesses to the compositeness of n. • The probability of n being prime if the algorithm returns yes is: • Where m is the number of random integers selected to test as witnesses.
Special Primes • Probabilistic algorithms are useful in the search for primes due to the large numbers of computations required to find them… • GIMPS (Great Internet Mersenne Prime Search) is a Distributed Computing project supporting the search for Mersenne primes – of the form 2p – 1. • The largest known prime is traditionally a Mersenne prime.
Mersenne Primes • The current largest prime (found in Sept. 2006) is the 44th known Mersenne prime, 232,582,657– 1 and is 9,808,358 digits long. • mersenne.org and the EFF currently offer prizes for finding the largest primes ($100,000 for the first 10,000,000 digit prime) • The bad news: • Testing a single 10,000,000+ digit number takes two months on a 2GHz P4
Homework Questions • What form do Mersenne primes take? • Give two uses for prime numbers in computer science applications.
References • Dewdney, A.K. The New Turing Omnibus. pp 335-338. • Rabin, Michael O. “Probabilistic algorithm for testing primality.” Journal of Number Theory, volume 12, issue 1. February, 1980. pp 128-138. • GIMPS – The Great Internet Mersenne Prime Search. http://www.mersenne.org • Bernstein, D.J. Distinguishing prime numbers from composite numbers: the state of the art in 2004. http://cr.yp.to/primetests.html • Prime Numbers. http://en.wikipedia.org/wiki/Prime_numbers