Primality Testing a Survey of Techniques
Total Page:16
File Type:pdf, Size:1020Kb
Primality Testing A survey of techniques Harish G. Rohan Ramanath Department of Computer Science & Engineering Department of Computer Science & Engineering R.V. College of Engineering R.V. College of Engineering Bangalore, India. Bangalore, India. [email protected] [email protected] Abstract — This expository paper briefly surveys the history where s has to be regarded as a complex variable and the of testing whether a number is prime. The recently discovered product is taken over all primes. The series, and so the deterministic polynomial time primality test due to Agrawal, product, converges absolutely for real( s) > 1. The identity Kayal and Saxena is presented and some improvements are between the series and the product is the analytic version of briefly discussed. the unique factorization of integers, and provides another Keywords— primality tests, polynomial time, P, NP proof for the existence of infinitely many prime numbers which is due to Euler: assuming that there are only finitely I. INTRODUCTION many primes, the product converges throughout the complex plane, contradicting the fact that the series reduces for s = 1 to Prime numbers are studied in number theory but they the divergent harmonic series. occur in many other subfields of mathematics. In the last few The Riemann hypothesis claims that the complex zeros of decades, prime numbers entered the real world in many (s) all lie on the so-called critical line Re s = 1/2 in the applications, e.g. as generator for keys in modern complex plane. This famous conjecture was stated by cryptographic algorithms. Riemann in 1859 and is still unproved. If the Riemann An integer n > 1 is called prime if it has no other positive hypothesis is true, the error term in the prime number theorem divisors than 1 and itself (within the set of integers); otherwise 1/2 n is said to be composite . is as small as possible, namely ~ x log x, and so the prime Every integer has a unique factorization into powers of numbers are distributed as uniformly as possible [7]. distinct prime numbers. Euclid was the first who proved that II. BACKGROUND there are infinitely many primes. His proof is that if p1, p2, …, It is easy to check that 97 is prime and 99 is not, but it pm are prime, then the number seems much harder to answer the same question for the q = p 1 × … × pm + 1 numbers 10 000 000 000 097 and 10 000 000 000 099, at least is not divisible by any of the p js. Thus q has a prime divisor in the same time. Indeed, a fundamental problem in number different from p 1, …, pm (one of which can be q itself). This construction of a new prime number out of an arbitrary finite theory is the decision problem collection of given primes implies the infinitude of prime Primes: given a positive integer n, decide whether n is numbers. Other proofs of this basic fact are in Ribbenboim [7]. prime or not! The celebrated prime number theorem gives information This problem became very important by developments in on how the primes are distributed. On the first view the prime cryptography in the late 1970s. It is easy to multiply two large numbers seem to appear in the sequence of positive integers prime numbers but it is much harder to factor a given large without any visible rule. However, as conjectured by Gauss integer; at least there are no factoring algorithms of satisfying and first proved by Hadamard and de la Vallée-Poussin speed known so far. This simple observation led to so-called (independently) on the base of outstanding contributions due public key cryptosystems where the key, a large integer N of to Riemann, they satisfy a distribution law. Roughly speaking, about two hundred digits, is public knowledge (as the the number π(x) of primes less than or equal to x is: telephone number) but its prime factorization is the secret of 3 0 its owner. This idea is attackable if N splits into small primes, (1) but if N is the product of two (carefully chosen) primes with ʚͬʛ = Ȅͦ ΚΝΕ 0 + error term The appearing logarithmic integral is asymptotically about hundred digits, the factorization of N is a nearly equal to x/ log x, where log x is the natural logarithm. The error unsolvable task with present day computers [4]. For term in the prime number theorem is small in comparison with generating such keys one needs to find large prime numbers x/ log x and is closely related to the zero distribution of the or, in other words, one needs to have a fast primality test, Riemann zeta-function. where fast means that the running time depending on the size of the number to be tested is small . Notice that a factoring ͥ ͥ ͯͥ Ϧ (2) algorithm and a primality test are different things: a number n ζʚͧʛ = ∑)Ͱͥ )Ħ = ∏+ ʠ1 − +Ħʡ 1 can fail a primality test and the test does not tell us any of its expectation value for the number of Mersenne primes M p with divisors, whereas a factoring algorithm gives the complete p ≤ x is factorization of n. 1 1 1 log log ͬ One of the first ideas for testing a given number n of being ȕ ∼ ȕ ∼ log ʚ2+ − 1ʛ log 2 ͤ log 2 prime might be trial division, i.e., to try all positive integers ≤ +3 +3 which tends with x to infinity; the last asymptotic identity whether they divide n or not. Obviously, if there is no √n relies on taking the logarithm in Equation (2). Note that this divisor of n among them, then n is prime. This strategy is not fits pretty well to the number of detected Mersenne primes. very useful if n is large. For example, it would take about 10 50 10 arithmetic operations to test an integer with 100 digits. If 10 III. DESIRED CHARACTERISTICS OF PRIMALITY TESTS operations can be performed by a computer within one second, then this test would take about 10 40 seconds, which is still A. Generality much more than 12 billion years, the estimated age of the There are many fast primality tests but they work for Universe. However, hypothetical quantum computers that are numbers with only certain properties. For example, the Lucas– computers which compute with quantum states, if once Lehmer test for Mersenne numbers can only be applied for realized, would solve this factorization problem within a Mersenne numbers. Pépin's test works only for Fermat fraction of a second. The simple idea of trial division leads to numbers. We would like an algorithm that can be used to test the sieve of Eratosthenes (due to the ancient Greek any general number for primality. Eratosthenes who was the first to measure approximately the circumference of the Earth 250 B.C.). If one deletes out of a B. Polynomial time in input size list of integers 1 < n ≤ x all multiples n of the primes p ≤ , √ͬ The maximum running time of the algorithm can be then only the prime numbers in between and x remain. This √x expressed as a polynomial over the number of digits in the gives a list of all primes under a given magnitude. Moreover, target number. Certain algorithms can deterministically we obtain the factorizations of all integers in the list. For a determine whether a given number is prime or not, but their primality test, this is a lot of superfluous information and we running time is not polynomial for all inputs. Algorithms like might ask for faster algorithms for detecting primes. ECPP (Elliptic Curve Primality Proving) and APR (Adleman- For some special numbers, primality tests of satisfying Pomerance-Rumely) deterministically prove primality, but speed are known for quite a long time. For instance, the they do not have polynomial running time for all inputs. We Mersenne numbers, invented by the monk Mersenne in 1644, would like an algorithm that runs in polynomial time for all p are defined by M p = 2 − 1, where p ≥ 3 is prime. It is easily possible inputs. seen that composite exponents cannot produce primes of this form. In 1750, Euler corrected Mersenne’s erroneous list of C. Deterministic Mersenne prime numbers by use of the following criterion: if The algorithm guarantees to deterministically distinguish p is a prime number of the form p = 4k + 3, then q = 2p + 1 is whether the target number is prime or composite. There are a divisor of M p if and only if q is prime; primes of the form certain randomized algorithms like Solovay-Strassen and 2p+1 for prime p are called Sophie Germain-primes. For Miller-Rabin, that can test any given number for primality in example, M 11 = 2047 = 23 × 89 is not prime as it was stated by polynomial time, but they may produce some false positives Mersenne. In 1878, Lucas found a simple and fast primality also. We would like an algorithm that can “prove” or test for Mersenne numbers (but only in 1935 Lehmer gave the “disprove” primality with certainty. first proof of the underlying mathematical theorem). His algorithm makes use of the congruence calculus and the test D. Unconditional (called Lucas-Lehmer test) can be described as follows: The Miller test for primality is fully deterministic and runs ≥ Input: a prime p 3. Output: Mp is prime or composite. in polynomial time over all inputs, but its correctness depends 1. Put s = 4. 2 on the truth of the yet-unproven generalized Riemann 2. For j from 3 to p do s := s − 2 mod M p.