copyright © 2014 - curt hill divisibility and modular arithmetic a topic in number theory

23
Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Upload: simon-norman

Post on 13-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Copyright © 2014 - Curt Hill

Divisibility and Modular Arithmetic

A Topic in Number Theory

Page 2: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Copyright © 2014 - Curt Hill

Number Theory• Study of integers and their

properties– Originally known as arithmetic

• Operations and algorithms • Prime numbers and factorization • Among other things

Page 3: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Divisibility• When we divide an integer by a

non-zero integer we get two integers:– Quotient– Remainder

• 153 produces quotient 5 and remainder 0

• 152 produces quotient 7 and remainder 1– We could also consider the result 7.5– However, this is not an integer

Copyright © 2014 - Curt Hill

Page 4: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Definitions• If AB produces a zero remainder

we say that B divides A– We also say that B is a factor or

divisor of A– We also say that A is a multiple of B

• Notation B|A means B is a factor of A– BA means that B is not a factor of A

• If B|A then

Copyright © 2014 - Curt Hill

Page 5: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Theorems• A,B,C are integers and A is not zero• If A|B and A|C then A|(B+C)• If A|B then A|BC• If A|B and B|C then A|C

Copyright © 2014 - Curt Hill

Page 6: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Proof 1• Prove that if A|B and A|C then A|

(B+C)• A|B means that B=AI for some

integer I• A|C means that C=AJ for some

integer J• B+C = AI + AJ• B+C = A(I+J)• Thus A|(B+C)

Copyright © 2014 - Curt Hill

Page 7: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Division ‘Algorithm’• If A is an integer and D a positive

integer• There are unique integers Q and R

where 0R<D, such that A =DQ+R• D is divisor• A is dividend• Q is quotient• R is remainder• This is a restatement of AD gives

quotient Q and remainder RCopyright © 2014 - Curt Hill

Page 8: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Div and Mod• Rosen’s flavor of pseudo-code is

definitely Pascal based• Pascal used / for real division and

div and mod for integer division• Thus:

– 17 div 3 gives the quotient which is 5– 17 mod 3 gives remainder, 2

• The two, div and mod, will be used like operators

Copyright © 2014 - Curt Hill

Page 9: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Examples• -19 and 4

– -19 div 4 = -4– -19 mod 4 = -3– -19 = 4-4 + -3

• 26 and 4– 26 div 5 = 5– 26 mod 5 = 1– 26 = 55 + 1

Copyright © 2014 - Curt Hill

Page 10: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Clock Arithmetic• When we add 8 hours to 6 o’clock

we do not get 14:00– Rather we get 2:00

• Clock arithmetic is a bit odd – 12 and 0 are the same– No negatives

• You do arithmetic and then mod it by 12 – If the result is 0, make it 12

• We now move towards modular arithmetic Copyright © 2014 - Curt Hill

Page 11: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Military Time• Military time uses a 24 hour clock

and it works without the exceptions of clock arithmetic

• 0 is midnight• 12 is noon• 16 is 4PM• 23:59 is the highest time• All arithmetic operations are

modded by 24

Copyright © 2014 - Curt Hill

Page 12: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Modular Arithmetic• If we take a time and add 24 hours

we have not changed it all• Moreover if we take a time and add

4 fours or 28 hours or 52 hours it all ends with the same time of day

• This is the notion of congruence in modular arithmetic

• Two numbers are congruent if they are equal after being modded by a particular integer

Copyright © 2014 - Curt Hill

Page 13: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Congruence More Formally• Suppose that a and be are integers

and m is some positive integer• We say that a is congruent to b

modulo m if a mod m = b mod m– The notation is a b (mod m)

• If a b (mod m) then m|(a-b)– The negation of congruence uses the

symbol • In congruence we refer to m as the

modulus (plural is moduli)

Copyright © 2014 - Curt Hill

Page 14: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Two Mods• a b (mod m) expresses a relation• a mod m is a function• What is the difference?

Copyright © 2014 - Curt Hill

Page 15: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Another Theorem• a b (mod m) iff there is an integer

k such that a=b+km• Proof:

– From a=b+km we get a-b = km– Then (a-b)/m = k which we know to

be an integer– We know that if a b (mod m) then m|

(a-b) which simply means that m divides a-b evenly

Copyright © 2014 - Curt Hill

Page 16: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Congruence Class• An set of integers congruent with

an integer mod m• This is the set of integers b where

a b (mod m) • The evens are a congruence class

mod 2 as are the odds– 16 20 (mod 2) and any even could

be substituted for either 16 or 20– 17 31 (mod 2) and any odd could be

substituted for either 17 or 31• What are four elements of the

congruence class of 26 mod 5?Copyright © 2014 - Curt Hill

Page 17: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Arithmetic and Congruence Classes

• If a b (mod m) and c d (mod m)• Then a+c b+d (mod m)• Also ac bd (mod m)• How would such a proof be done?• The corollary is

(a+b) mod m = ((a mod m)+(b mod m))mod m

• Andab mod m = ((a mod m)(b mod m))mod m

Copyright © 2014 - Curt Hill

Page 18: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

a+c b+d (mod m)• a b (mod m)

then a mod m = b mod m• Thus a mod m = b mod m = i for

some i• Also c mod m = d mod m = j for

some j• Thus i+j = i+j• Can you do the other one?

Copyright © 2014 - Curt Hill

Page 19: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Modulo m Arithmetic• Suppose we take the first m

integers:{0, 1, 2, … m-1}

• We may now define arithmetic on this set +m and m

• Addition a +m b = (a+b) mod m

• Multiplication a m b = (ab) mod m

Copyright © 2014 - Curt Hill

Page 20: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Example 15• Our set of numbers is {0, 1, …13,

14}• 8 +15 12 = 20 mod 15 = 5

• 8 +15 4 = 12 mod 15 = 12

• 13 +15 12 = 25 mod 15 = 10

• 6 15 12 = 72 mod 15 = 12

• 6 15 11 = 66 mod 15 = 6

• 6 15 10 = 60 mod 15 = 0

Copyright © 2014 - Curt Hill

Page 21: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Modulo m Arithmetic• Has several properties• Closure

– a +m b and a m b will be in the set {0..m-1} provided a and b in the set

• Associativity– (a m b) m c = a m (b m c)

– (a +m b) +m c = a +m (b +m c)

• Commutativity– a m b = b m a

– a +m b = b +m aCopyright © 2014 - Curt Hill

Page 22: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

More Properties• Identity elements– 0 is identity for addition and 1 for

multiplication– Sometimes called the unit– a m 1 = a

– a +m 0 = a

• Additive inverse– If a 0 is a member of the set then m-

a is the additive inverse– a +m (m-a) = 0

• Distributivity– a m (b +m c) = a m b +m a m c

Copyright © 2014 - Curt Hill

Page 23: Copyright © 2014 - Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory

Exercises• 4.1

– 3, 7, 13, 23, 29, 33

Copyright © 2014 - Curt Hill