Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design and Analysis of Prime Number Sieves

Similar presentations


Presentation on theme: "Design and Analysis of Prime Number Sieves"— Presentation transcript:

1 Design and Analysis of Prime Number Sieves
Seth Futrell, Matthew Ritchie, Dakota Perryman, Mark Thompson (Tag’s Tots)

2 Background History Prime numbers have fascinated the human race for millennia with solutions to finding primes predating the times of euclid. Primes continue to amaze mathematicians and theoretical thinkers daily. Research of these fascinating numbers continues in present day with the continuing growth of the field of number theory and encryption protocols .

3 Why Do Prime Numbers Matter?
The most relevant reasons to use prime numbers in today’s society are for modern encryption algorithms. Rivest-Shamir-Adlerman ( RSA Encryption) uses multiple prime numbers to calculate encryption keys. Primes also relate to modern blockchain technology used in cryptocurrencies and cloud computing. Creating sets of prime numbers is essential to analyze patterns such as: Twin Primes (Brun’s Theorem) Ulam Spirals Generation Hash Keys Not to mention, every integer is a product of a set of unique prime numbers. N = 24 Prime Factorization: 2 * 2 * 2 * 3

4 Prime Facts The set of prime numbers is infinite.
This has been proven many times, but most famously by Euclid’s proof which was published in “Euclid’s Elements” around 300 B.C. Theorem: There are infinitely many primes. Proof. Suppose that p1=2 < p2 = 3 < ... < pr are all of the primes. Let P = p1p2...pr+1 and let p be a prime dividing P; then p can not be any of p1, p2, ..., pr, otherwise p would divide the difference P-p1p2...pr=1, which is impossible. So this prime p is still another prime, and p1, p2, ..., pr would not be all of the primes. 1 is not defined as a prime number according to the formal statement of a prime number.

5 Problem Statement in natural terms
Common language: Given any counting number N greater than 1, construct a set of all prime numbers that are less than N.

6 Formal Constructs Define set S as:
Given a counting number n define set S as all counting number < n. Define a prime number as : Informally: A prime number (or prime integer, often simply called a “prime” for short) is a positive integer p>1 that has no positive integer divisors other than 1 and p itself. More concisely, a prime number P is a positive integer having exactly one positive divisor other than 1, meaning it is a number that cannot be factored. Formally: p∈N, ∀k∈N,((k∣p)⇒(k=1)∨(k=p)) Define set P as: A set of positive integers where each element is prime. Define formal problem statement as: ∀n∈S, IFF((p∈N, ∀k∈N,((k∣p)⇒(k=1)∨(k=p)) : (P← P U {n})

7 Limitations Limitations we set for ourselves: 32 bit Integers
Using a 32 bit system we could only use 3.5 gb of RAM. Time of computation

8 Brute Force (Control/Benchmark)
Using the brute force method to calculate all prime numbers less than N, we used this algorithm to set a standard to compare our other algorithms. The while loop, does n iterates through all values n which equivalates to O(n). O(n*sqrt(n)) The for loop in the isPrime function only does sqrt(n) iterations which is a sqrt(n) operation.

9 Hour Algorithm (Original Implementation)
Unlike brute force, we initialize a list of primes with 2 being the only element. Because all multiples of 2 are even, and therefore not prime, we can safely skip them. Looping through all odd numbers, we begin doing modulus division of every element in the prime set. Since we know that all integers are constructed of prime factors, if an Integer n is not divisible by any number in the prime set, then it must be prime. It is then added to the list of prime numbers and can be used as a divisor for larger numbers.

10 Hour Algorithm (Original Implementation)
Time Complexity: O(n log(n)) Since this while loop will run until i is equivalent to n this is an O(n) loop. While loop iterates up until the sqrt(i) therefore O(log(n)).

11 Sieve of Eratosthenes •Create a boolean array with n entries set to true •For each entry from 2 to the sqrt of n: if the entry is true, set the entries for multiples of that index to false •Only prime numbers remain after counter reaches the sqrt of n

12 Sieve of Eratosthenes Time Complexity: O(nlog(log(n)))
For loop iterates from i*i to n in increments of i, therefore O(log(n)) For loop iterates to square root of n, therefore O(log(n)) O(n)

13 Sieve of Sundaram •Set k to (n – 2)/2
•Create a boolean array with k entries •The outer loop (i) counts from 1 to k, the inner loop (j) starts from the outer loop value and increments while i + j + (2 * i * j) < k •integers are eliminated by i + j + 2 * i * j •After loops complete, primes are found by multiplying the indices of the true entries by 2 and adding 1

14 Sieve of Sundaram Code Time Complexity: O(nlog(n))
While loop is O(log(n)) For loop is O(n) For loop is O(n)

15 Sieve of Atkin Create an boolean array with n entries set to false
Outer loop increments x from 1 to sqrt(n) Inner loop increments y from 1 to sqrt(n) Three different values (z) are calculated from 3 quadratic equations for each x and y value, then subjected to remainder division by 60 Case 1: z = 4 * x^2 + y^2 If z mod 60 is 1, 13, 17, 29, 37, 41, 49, or 53, flip the entry in the sieve list for z. For each entry in the sieve list marked true, square the number and mark all multiples of the square as non-prime.

16 Sieve of Atkin code Time Complexity: O(nlog(log(n))) O(log(n))

17 Data Analysis - Python vs C (Brute and Hour)

18 Data Analysis - Python vs C (SOE,SOS,SOA)

19 Continued Analysis of C code
Eratosthenes Sundaram Atkin Hour Brute Force 0.0716 0.0540 0.0932 6.4122 2.3250 1.1584 1.6416 1.3502 Sieve of Eratosthenes proved to be the most efficient algorithm for very large values of n, followed by Atkin and Sundaram, respectively. This was in line with our expectations, given that Eratosthenes and Atkin have the same time complexity, but with Atkin doing more calculations and memory references per iteration. However, there are values of n for which Sundaram is more efficient.

20 Space Complexity Sieving methods use an array of O(n) to generate primes. What is the size of the resulting array of primes? For any Integer n: n / ln n ≤ π(n) ≤ * n / ln n Brute Force & Hour Algorithm: O(n / log n) Sieve Algorithms: O(n + n / log n)

21 Direct Comparison of Python and C

22 Questions What is the big O when we are doing brute force to find the number of primes when we are only doing modulus division of sqrt(n)? n*sqrt(n) What is the standard big O of sieve of eratosthenes? n*log(log(n)) What is an ulam spiral? A graphical depiction of the set of all prime numbers. How would you construct 24 as multiple of prime factors? 3*2*2*2 What causes our implementations to be run much faster in C rather than in python? Python is an interpreted language compared to C which is compiled directly by the CPU.

23 The Future of Computing Primes
With the increasing importance of prime numbers in relation to encryption, within the next decade, quantum computing will be a large scale player in prime factorization. Quantum computing is the area of study focused on developing computer technology based on the principles of quantum theory, which explains the nature and behavior of energy and matter on the quantum (atomic and subatomic) level. (Solves TSP for 22 cities in roughly one minute Using a permutation of Shor’s algorithm, modern encryption will be decimated, considering we will be able to find all prime factors in minutes, if not seconds. “The Quantum Sieve of Eranthoses ”

24 Sources


Download ppt "Design and Analysis of Prime Number Sieves"

Similar presentations


Ads by Google