+ All Categories
Home > Documents > CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

Date post: 14-Dec-2015
Category:
Upload: bennett-fowler
View: 232 times
Download: 2 times
Share this document with a friend
Popular Tags:
21
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Transcript
Page 1: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

CSE 20: Discrete Mathematics for Computer Science

Prof. Shachar Lovett

Page 2: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

2

Today’s Topics:1. Prime factorization2. Primality testing

Page 3: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

3

1. Prime factorizationsPrimes are the atoms of integers

Page 4: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

4

Primes Natural numbers: positive integers N={1,2,3,…}

Definition: is prime if the only natural numbers that divide it are 1,n

By definition, 1 is not prime.

Page 5: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

5

Primes Which of the following is prime?

A. 1B. 6C. 7D. 21

Page 6: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

6

Prime factorization Basic theorem of number theory: any

integer can be factored as a product of primes (we will prove this soon)

Moreover, this factorization is unique

Example: 36=2*2*3*3

Page 7: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

7

Existence of prime factorization Theorem: For any integer there exist

primes such that

Proof: strong induction Try and prove it by yourself first.

Page 8: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

8

Existence of prime factorization Theorem: For any integer there exist primes such that

Proof: strong induction Base case: n=2. 2 is prime. We are done.

Inductive case: let . There are two cases: Case I: n is prime. We are done.

Case II: n is not prime. So there is some such that a|n. So where 1<a,b<n. By strong induction, both a,b have a prime factorization: a= for some primes b= for some primes

So n= is a prime factorization of n.

Page 9: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

9

How to find the prime factorization? What is the prime factorization of 100?

A. 2*5B. 2*2*5C. 10*10D. 2*2*5*5E. Other

Page 10: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

10

How to find the prime factorization? What is the prime factorization of

82768328638217?

Page 11: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

11

How to find the prime factorization? What is the prime factorization of 82768328638217?

Not so easy anymore…

The security of RSA (which for example, protects your bank accounts) is based on the assumption that it is hard to factor numbers

We cannot prove it.

In fact, maybe somebody knows how to factor numbers fast (lets wait for more Snowden revelations…)

Page 12: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

12

2. Primality testing

Page 13: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

13

Primality testing If it’s hard to factor numbers into

primes, lets focus on an easier problem

Test if a given integer is prime

How can you do it? Try and come up with the best algorithm you can

Page 14: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

14

Primality testing Algorithm 1:

isPrime(n):1. For i=2..n-1

1.1 If n MOD i=0: return False

2. Return True

Page 15: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

15

Primality testing Algorithm 1:

isPrime(n):1. For i=2..n-1

1.1 If n MOD i=0: return False

2. Return True

How many steps?

A. ~nB. ~n2

C. ~log(n)D. Doesn’t depend on nE. Other

Page 16: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

16

Better primality testing? The primality testing algorithm uses n calls to the MOD

function

Even if we assume that MOD can be computed very efficiently (and it can), there are many call

Observation: if n is not prime, then it has a factor of size

Proof: If then .

We can use it to design a faster algorithm.

Page 17: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

17

Primality testing Algorithm 1:

isPrime(n):1. For i=2..n-1

1.1 If n MOD i=0: return False

2. Return True

Page 18: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

18

Primality testing (II) Algorithm 2:

isPrime(n):1. For i=2..

1.1 If n MOD i=0: return False

2. Return True

Page 19: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

19

Primality testing (II) Algorithm 2:

isPrime(n):1. For i=2..

1.1 If n MOD i=0: return False

2. Return True

How many steps?

A. ~nB. ~n2

C. ~log(n)D. Doesn’t depend on nE. Other

Page 20: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

20

An even faster algorithm? The prime numbers used in RSA are

very big, with 100s of digits

These algorithms will take forever

There are much faster algorithms, which run in time ~log(n); they are randomized algorithm (e.g. Miller-Rabin)

Page 21: CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.

21

Log vs poly time Assume n=10100

Then n or are very big (>>atoms in universe)

But log(n)<1000 !

Algorithms running in log-time are very efficient!!!


Recommended