38
The Integers & Division

The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Embed Size (px)

Citation preview

Page 1: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

The Integers & Division

Page 2: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

• a divides b if• a is not zero• there is a m such that a.m = b

• “a is a factor of b”• “b is a multiple of a”• a|b

ba |

Division

ba |

ZcZbZacabcbaba

,,)).(|(0

Page 3: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

• If a|b and a|c then a|(b+c)• “If a divides b and a divides c then a divides b plus c”

• a|b a.x = b• a|c a.y = c• b+c = a.x + a.y• = a(x + y)• and that is divisible by a

)(||| cbacaba

Division

Page 4: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

• a|b a.m = b• b.c = a.m.c• which is divisible by a

).||( cbabacba

Division

Page 5: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

• a|b a.x = b• b|c b.y = c• c = a.x.y• and that is divisible by a

cacbba |||

Division

Page 6: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Division

cacbba

cbaba

cbacaba

|||

.||

)(||

Theorem 1 (page 202, 6th ed, page 154, 5th ed)

Page 7: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Primes

• p > 1 is prime if the only positive factors are 1 and p• if p is not prime it is composite

The Fundamental Theorem of Arithmetic

Every positive integer can be expressed as a unique product of primes

k

i

eiipn

1

My name is Euclid

Page 8: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Primes

5.3.25.3.2.260 2

There is no other factoring!

22 5.25.5.2.2100

Page 9: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Euclid of Alexandria

325BC to 265BC

Page 10: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Primes

Euclid’s words

“if a number be the least that is measured by prime numbers, it will not be measured by any other prime except those originally measuring it “

Where “measuring” is “dividing”

The Elements

Page 11: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division
Page 12: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Proof of Fundamental Theorem of Arithmetic

• Well Ordering Principle (WOP)• every non-empty set of positive integers has a least element

RTP: Every integer n > 1 can be written as a product of primes

• If n is prime we are done• n is composite and has a positive divisor 1 < p < n

• let p1 be the smallest of these divisors• p1 must be prime otherwise

• there is an integer k, 1 < k < p1, and k divides p1

• consequently n = n1 times p1 (i.e. n1 = n p1)• where p1 is prime and n1 < n

• repeat the argument with n1

• If n1 is prime we are done• otherwise n1 = n2 times p2

• where p2 is prime and n2 < n1 and p2 p1

• … this process terminates due to the WOP

Page 13: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

PRIMES

a.bn n)composite(

The dumb way to test if n is prime

• if n is divisible by 2 return(“composite”)• if n is divisible by 3 return(“composite”)• if n is divisible by 4 return(“composite”)• …• if n is divisible by n-1 return(“composite”)• return(“prime”)

Question: is n (n > 2) ever divisible by n-1?

Page 14: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

PRIMES

n divisor prime a has n composite is n If

a.bn n)composite(

nb na

n divisor prime a hasn then composite isn if

Therefore, the divisor a or b is either prime or due to the

fundamental theorem of arithmetic, can be expressed as a

product of primes

) nb n(a

Put another way

(p 211 6th ed, p 155 5th ed)

Page 15: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

PRIMES

n divisor prime a hasn then composite isn if

We now have a test for primality

If a number is not composite it is prime

If a number is prime then it does NOT have a prime divisorless than or equal to n

Therefore we can test if n is divisible by primes in the range2 to n

If none are found n must be prime

Page 16: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Primes

Prove that 41 is prime

To be prime, 41 must not be composite

If composite 41 has a divisor less than or equal to square root of 41

6 41

The only primes not exceeding 6 are 2, 3, and 5

None of these divides 41

Therefore 41 is not composite, it is prime

Remember: floor(x) x the largest integer smaller than x

Page 17: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Primes for the class!

Prove that 67 is prime

To be prime, 67 must not be composite

If composite 67 has a divisor less than or equal to square root of 67

8 67

The only primes not exceeding 8 are 2, 3, 5, and 7

None of these divides 67

Therefore 67 is not composite, it is prime

Page 18: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Is 51 prime?

751

Consider prime divisors 2, 3, 5, 7 only

17351

Page 19: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Primes Compute the prime factorisation of n

The Fundamental Theorem of Arithmetic

Every positive integer can be expressed as a unique product of primes

k

i

eiipn

1

Revisited

Page 20: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Primes Compute the prime factorisation of n

• assume nextPrime(i) delivers next prime number greater than i• nextPrime(7) = 11 and nextPrime(nextPrime(7)) = 13

• floor(sqrt(n)) delivers largest integer square root of n• floor(sqrt(97)) = 9

p := 2; // the 1st primerootN := floor(sqrt(N)) // where we stopwhile p <= rootNdo begin if p|n then begin print(p); // p is a prime divisor n := n/p; rootN := floor(sqrt(n)); end else p := nextPrime(p); end print(p);

Page 21: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Primes

N p rootN 7007 2 83 7007 3 83 7007 5 83 7007 7 83print 7 1001 7 31print 7 143 7 11 143 11 11print 11 13 11 3print 13

7007 = 7.7.11.13

p := 2; // the 1st primerootN := floor(sqrt(N)) // where we stopwhile p <= rootNdo begin if p|n then begin print(p); // p is a prime divisor n := n/p; rootN := floor(sqrt(n)); end else p := nextPrime(p); end print(p);

Page 22: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

The Division Algorithm (aint no algorithm)

• a is an integer and d is a positive integer• there exists unique integers q and r,• 0 r d• a = d.q. + r

d)r0rd.qr(a!q!Zd Za

a divided by d = q remainder r

dividenddivisor

quotient

remainder

NOTE: remainder r is positive and divisor d is positive

Page 23: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Division

• a = d.q + r and 0 <= r < d• a = -11 and d = 3 and 0 <= r < 3

• -11 = 3q + r• q = -4 and r = 1

• a = d.q + r and 0 <= r < d• a = -63 and d = 20 and 0 <= r <= 20

• -63 = 20q + r• q = -4 and r = 17

• a = d.q + r and 0 <= r < d• a = -25 and d = 15 and 0 <= r < 15

• -25 = 15.q + r• q = -2 and r = 10

dr

rqda

0

.

Page 24: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Division

• a = d.q + r and 0 <= r < d• a = -11 and d = 3 and 0 <= r < 3

• -11 = 3q + r• q = -4 and r = 1

Troubled by this?Did you expect q = -3 and r = -2?What if 3 of you went to a café and got a bill for £11?Would you each put £3 down and then leg it?Or £4 each and leave £1 tip?

Page 25: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Greatest common divisor gcd(a,b) and Least common multiple

• gcd(a,b) is largest d such that d|a and d|b• if gcd(a,b) = 1 then a and b are relative prime• lcm(a,b) is the smallest/least x such that a|x and b|x

•3 Naïve algorithms for gcd(a,b)• start with x at 1 up to min(a,b) testing if x | a and x |b

• remember the last (largest) successful value• start with x at min(a,b) and count down to 1 testing if x|a and x|b

• stop when the first value of x is found• compute the prime factorisation of a and of b

• and then see below

),min(),min(2

),min(1 ...),gcd( 2211 nn ba

nbaba pppba

Page 26: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Greatest common divisor gcd(a,b)

),min(),min(2

),min(1 ...),gcd( 2211 nn ba

nbaba pppba

• gcd(120,500)• prime factorisation of 120 is 2.2.2.3.5• prime factorisation of 500 is 2.2.5.5.5

)3,1min()0,1min()2,3min( 532)500,120gcd(

20… but there is a better algorithm (wots an algorithm?)

Page 27: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division
Page 28: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Lowest/least common multiple lcm(a,b) = smallest x divisible by a and by b

),max(),max(2

),max(1 ...),( 2211 nn ba

nbaba pppbalcm

• lcm(95256,432)• prime factorisation of 95256 is 2.2.2.3.3.3.3.3.7.7• prime factorisation of 432 is 2.2.2.2.3.3.3

)0,2max()0,0max()3,5max()4,3max( 7532)432,95256( lcm

190512

Page 29: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

mod arithmetic

• a mod m is the remainder of a divided by m• a mod m is the integer r such that

• a = qm + r and 0 <= r < m • again, r is positive

•Examples

• 17 mod 3 = 2• 17 mod 12 = 5 (5 o’clock)•-17 mod 3 = 1

Page 30: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

mod arithmetic

a is congruent to b modulo m if m divides a - b

b)m|(am)b(a mod

congruences

Page 31: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

mod arithmetic a is congruent to b modulo m if m divides a - b

b)m|(am)b(a mod

)5(mod27

)}3(mod2205|{ xxNxx}17,14,11,8,5{

)}3(mod2205|{

xxNxx

Page 32: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

mod arithmetic a is congruent to b modulo m if m divides a - b

b)m|(am)b(a mod

mbmamba modmod)(mod

congruence ofDefn

mod ofDefn

mod ofDefn

modmod)(mod

3

22

11

mqba

rmqb

rmqa

mbmamba

)()(

congruence ofDefn

mod ofDefn

mod ofDefn

modmod)(mod

2121

2121

3

22

11

rrmqq

rrmqmqba

mqba

rmqb

rmqa

mbmamba

21

21

2121

2121

3

22

11

r

zero bemust

)(|But

)()(

congruence ofDefn

mod ofDefn

mod ofDefn

modmod)(mod

r

rr

bam

rrmqq

rrmqmqba

mqba

rmqb

rmqa

mbmamba

Page 33: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

mod arithmetic a is congruent to b modulo m if m divides a - b

b)m|(am)b(a mod

)(mod)(mod)(mod mdbcamdcmba

)(|)(mod

)(|)(mod

dcmmdc

bammba

tydivisibili From))()((|

)(|)(mod

)(|)(mod

dcbam

dcmmdc

bammba

))()((|

tydivisibili From))()((|

)(|)(mod

)(|)(mod

dbcam

dcbam

dcmmdc

bammba

congruence ofDefn ))(mod(

))()((|

tydivisibili From))()((|

)(|)(mod

)(|)(mod

mdbca

dbcam

dcbam

dcmmdc

bammba

Page 34: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

mod arithmetic a is congruent to b modulo m if m divides a - b

b)m|(am)b(a mod)(mod)(mod)(mod mbdacmdcmba

congruence ofDefn 2

1

mqdc

mqba

)(

)(

2121

2121

2

1

mqqbqdqmbdac

mqqbqdqmbdac

mqdc

mqba

)(mod

)(|

)(

)(

2121

2121

2

1

mbdac

bdacm

mqqbqdqmbdac

mqqbqdqmbdac

mqdc

mqba

Page 35: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Mod arithmetic

• -133 mod 9 = 2 (but in Claire?)• list 5 numbers that are congruent to 4 modulo 12• hash function h(k) = k mod 101

• h(104578690)• h(432222187)• h(372201919)• h(501338753)

examples

Page 36: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

What have we done? (summary)

• divisibility a | b• FTA

• proof of FTA• test for primality• computation of prime factorisation• gcd and lcm

• Division algorithm• aint no algorithm

• Mod arithmetic• congruences

Page 37: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division

Division and multiplication

That’s all for now folks

Page 38: The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division