Università Degli Studi Di Trento Dipartimento Di Matematica
Total Page:16
File Type:pdf, Size:1020Kb
1 Università degli studi di Trento Dipartimento di Matematica Corso di laurea in Matematica AKS, the proof of "PRIMES is in P" Correctness and time complexity analysis, along with Java implementation Supervisore: Candidato: Prof.ssa Pellegrini Stefano Alessandra Bernardi Matricola: 174856 Anno accademico 2016/2017 CONTENTS 2 Abstract We present the algorithm described in M. Agrawal, N. Kajal, N. Saxena "PRIMES is in P" paper. The first Section provides the historical context in which the algorithm took place, while the second introduces the reader to the notation and preliminary results used. In Sections 3 and 4 there are the correctness and time complexity analyses. Finally, Java implementation occupies Section 5. Contents 1 Historical introduction on primality testing 4 1.1 Some historically relevant primality tests . .5 2 Notation and preliminary results 7 3 The algorithm and its correctness 10 4 Time complexity analysis 15 5 Java implementation 16 CONTENTS 3 Acknowledgements I would like to thank some people without whom, for various reasons, this work wouldn’t have been possible. First and foremost I am grateful to Prof. Alessandra Bernardi for her endless patience and continuous encouragements. I would also like to thank Prof. Alberto Montrsor for his precious help with the Java implementation and all my family for always supporting me. 1 HISTORICAL INTRODUCTION ON PRIMALITY TESTING 4 "Il mondo dei numeri è pieno di sorprese, e scoprirle è uno dei piaceri dello studio della matematica." Philip J. Davis, Il mondo dei grandi numeri, 1961 1 Historical introduction on primality testing Prime numbers have ever played a key role throughout the history of arithmetic, since the works of the great ancient Greek mathematicians. At first sight, though, there is nothing special for a number in having exactly two natural divisors; there is no evident reason for 421 for being somehow more significant than 403. Why are they considered so important, then? Why have they stolen so much time and energies from academics as Euler, Gauss or Fermat? And the interest has not lowered in these years: the Electronic Frontier Foun- dation offers a prize of 150 thousand dollars to whom will find a prime greater than the highest currently known (277;232;917 − 1, a number with 23,249,425 digits). Definition 1.1. A natural number n is called "prime" if for every couple of naturals a;b such that n = a · b then n either divides a or b. Definition 1.2. A natural number is called "irreducible" if it has exactly two distinct divi- sors: 1 and himself. Theorem 1.3. A natural number is prime if and only if it is irreducible. This is a classical result which follows by the fact that N is a unique factorisation domain1. Since they are equivalent, we shall use the notions of prime and irreducible in- differently. Most of the relevance of the set of primes is given by the following two properties: Theorem 1.4. There is no greatest prime number. The fact that primes are infinite was proven by Euclid in its "Elements", composed during the 4th century before Christ, giving an elegant "by absurd" demonstration which we shortly present: Proof. Suppose that the set of all primes is finite and let this be P = fp1;:::; png. Consider n ! p := p1 · ::: · pn + 1 = ∏ pi + 1 i=1 Then p 2= P is not divisible for any of the pi 2 P since pi divides p − 1 = p1 · ::: · pn. We have therefore found another prime number, showing a contradiction in the starting hypothesis 1A unique factorisation domain is a commutative ring in which zero-product property and the fundamen- tal Theorem of arithmetics for irreducibles (1.5) are valid 1 HISTORICAL INTRODUCTION ON PRIMALITY TESTING 5 Theorem 1.5 (Fundamental theorem of arithmetic). Each natural number can be written as the product of a unique set of primes. The proof of this theorem was stated for the first time by Carl Gauss in the "Disquisi- tiones arithmeticae"[1], which was published in 1801. Theorem 1.5 leads prime numbers to be seen as the multiplicative "building blocks" of all naturals, in the sense that every number, except from 0 and 1, can be built by multi- plying some primes; factorization is somehow the signature of each integer. What can be surprising is that this set of "building blocks" is infinite, as stated by Theorem 1.4, while for example we can construct additively the whole set of naturals using only the unity (1;2 = 1 + 1;3 = 1 + 1 + 1;:::). One may now be wondering if prime numbers form a logical sequence, in the sense that if we possess the first n numbers the (n + 1)-th can be easily found. Mathematicians have been searching for an answer for centuries without success and even if several achieve- ments were reached, finding prime numbers is still a hard task and, surprisingly, this reveals to be the main reason of their contemporary practical use. In fact, most of the information security systems that almost everyone uses nowadays, such as internet pass- words, online payments and ATMs, are based on cryptographic systems that rely on prime numbers. As an example, if Alice chooses two big primes and sends their product to Bob, he can send her a message that requires knowing the two starting numbers to be decrypted. Eve, that wants to read their conversation, has to factorize that product; if it is large enough, this work is going to take some million years, causing her to fail in her evil attempt. Luckily or not, despite the great effort spent by the mathematical community, no deter- ministic structure could be found in the primes succession, which means that the only way to produce a prime number is to choose a random one and to test if it is prime2. Primal- ity tests are then a central issue in number theory and since a simple - but slow - test is straightforward from the definition, the efficiency of a test is a feature of basic importance. 1.1 Some historically relevant primality tests The Sieve of Erathostenes, invented in the 4-th century b.C. by the famous Greek mathe- matician that estimated Earth’s diameter in a quite precise way, is not a proper primality test. It can produce all the prime numbers up to a given integer by cutting out, at each step, all the proper multiples of the smaller "not sieved" number, which is surely prime. For example, to find out the primes up to 20, we take 2 as the first prime number and we sieve out all its proper multiples. Now the smallest number that we have not yet consid- ered is 3, which is our next prime and we cut out all of his multiples. The next one is 5 and we continue this way. This algorithm can be implemented quite easily and allowed the production of the first prime tables, however it is not really efficient when treating with really large numbers. The increasing need of efficiency led to the development of a series of tests based on sev- 2Quite surprisingly, this is the main reason why they are currently used in cryptography: if the prime distribution will be found most of digital security systems would quickly become useless. 1 HISTORICAL INTRODUCTION ON PRIMALITY TESTING 6 eral number-theoretic properties, such as the so called "Fermat little Theorem"3. Some of them are probabilistic, in the sense that they can give an upper bound for a number to the probability of being prime. The greatest advantage of such tests is indeed the time complexity, which makes them the most used in practice, but since they cannot give a certain response they have little theoretical value. The simplest of this kind is Fermat primality test, which checks whether p divides ap−1 −1;4 if this is false we are certain that p is composite, otherwise nothing can be said. Repeating this operation for n values of a 1 bounds the probability for p being composite to 2n ; for example if we prove that p divides ap−1 − 1 for 10 distinct values of a then p is composite with probability < 0;001. Several more sophisticated variants of this test, such as Miller-Rabin[2] and Solovay-Strassen[3], can improve its efficiency. There is also a class of primality tests that currently have neither a demonstration nor a counterexample and are hence called heuristic, for example the "Baillie-PSW" test[4]. No composite number below 264 passes this test and there are not known greater counterex- amples, although they are conjectured to be infinitely many. As for deterministic tests, the ones that give a certain output, several results have been achieved, too. Some of them only focus on treating numbers in a particular form, obtaining significant results in efficiency, making them the most suitable in searching for really big primes. Pepin’s test[5], for instance, works on Fermat numbers, namely naturals in the form 2n Fn−1 2 + 1. In this case it suffices to verify whether Fn divides 3 2 + 1 to decide about the primality of the n-th Fermat number Fn. Although this computation can be done in a very rapid way, Fermat numbers grow so rapidly that it is possible to test only few of them in a reasonable amount of time. The test that provided most of the greatest known primes, such as 277;232;917 − 1 that was mentioned above, was developed in 1870 by the French mathematician Edouard Lukas p and optimized by Derrick Normann Lehmer in 1930[6].