comp 170 l2 page 1 l05: inverses and gcds l objective: n when does have an inverse? n how to compute...

67
COMP 170 L2 Page 1 L05: Inverses and GCDs Objective: When does have an inverse? How to compute the inverse? Need: Greatest common dividers (GCDs) Results will be used in L06.

Upload: bertina-kelley

Post on 26-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 1

L05: Inverses and GCDs

Objective: When does have an inverse? How to compute the inverse?

Need: Greatest common dividers (GCDs) Results will be used in L06.

Page 2: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 2

Inverses and GCDs

Greatest Common Divisors (GCDs)

Definitions

Euclid’s Division Theorem

The GCD Algorithm

Multiplicative Inverses

Definition and Properties

Link to GCD

The extended GCD algorithm.

Computing inverses

Page 3: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 3

Divisors of an Integer

Page 4: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 4

Prime Numbers

Page 5: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 5

Common Divisors

Page 6: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 6

Relatively Prime

Page 7: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 7

How to Find GCD?

How to calculate gcd(m, n)?

Need Euclid’s division theorem

Page 8: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 8

Inverses and GCDs

Greatest Common Divisors (GCDs)

Definitions

Euclid’s Division Theorem

The GCD Algorithm

Multiplicative Inverses

Definition and Properties

Link to GCD

The extended GCD algorithm.

Computing inverses

Page 9: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 9

Euclid’s Division Theorem

Page 10: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 10

Euclid’s Division Theorem

Page 11: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 11

Page 12: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 12

Page 13: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 13

Page 14: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 14

Proof by Smallest Counter Example

Page 15: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 15

Page 16: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 16

Inverses and GCDs

Greatest Common Divisors (GCDs)

Definitions

Euclid’s Division Theorem

The GCD Algorithm

Multiplicative Inverses

Definition and Properties

Link to GCD

The extended GCD algorithm.

Computing inverses .

Page 17: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 17

A Lemma

This lemma gives us a way to calculate GCDs.

Example

10 = 4 * 2 + 2

gcd(10, 4) = 2 = gcd(4, 2)

Page 18: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 18

Page 19: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 19

Page 20: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 20

Euclid’s GCD algorithm

The 2nd argument is nonnegative

Decreases in each recursive call

Becomes 0 in a finite number of steps

Page 21: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 21

Euclid’s GCD algorithm

Page 22: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 22

Euclid’s GCD algorithm

Page 23: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 23

Inverses and GCDs

Greatest Common Divisors (GCDs)

Definitions

Euclid’s Division Theorem

The GCD Algorithm

Multiplicative Inverses

Definition and Properties

Link to GCD

The extended GCD algorithm.

Computing inverses

Page 24: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 24

Multiplicative Inverse mod n

Page 25: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 25

Determine Inverses from Multiplication Table

Which nonzero elements of have multiplicative inverses?

Page 26: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 26

Determine Inverses from Multiplication Table

Which nonzero elements of have multiplicative inverses?

Page 27: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 27

It seems determining inverses is simple

Just scan multiplication tables

But do you see a problem with this method?

Yes, too complex…

For e-commerce, we need to determine inverse of integers of

more 200 or 300 digits…

Computationally .

Next:

Show a way to prove inverse does not exist.

Develop efficient way to calculate inverses if they exist.

Determine Inverses from Multiplication Table

Page 28: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 28

Multiplicative Inverse mod n

Page 29: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 29

Multiplicative Inverse mod n

Page 30: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 30

Proving Inverse does not Exist

Gives us a way to prove that inverse does not exist

Page 31: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 31

Proving Inverse does not Exist

Page 32: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 32

Proving Inverse does not Exist

Page 33: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 33

Proving Inverse does not Exist

Page 34: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 34

Inverses and GCDs

Greatest Common Divisors (GCDs)

Definitions

Euclid’s Division Theorem

The GCD Algorithm

Multiplicative Inverses

Definition and Properties

Link to GCD

The extended GCD algorithm.

Computing inverses

Page 35: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 35

Link to GCD

Objective:

Show the following two important results

Page 36: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 36

Modular Equations and Normal Equations

Page 37: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 37

Page 38: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 38

Inverse and Normal Equations

Page 39: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 39

Clue on Finding Inverse Second part of the proof of Lemma 2.8:

Does this give us a way to find the inverse of a?

Yes,

Page 40: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 40

Clue on Finding Inverse

So, given a and n, if we can find x and y, such that

a x + ny =1 (*)

Then, we find inverse of a, i.e., x mod n

Given a and n, how do we find x and y, to satisfy (*)?

Link to GCD

Page 41: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 41

Link to GCD

Page 42: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 42

Link to GCD/Summary

Page 43: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 43

Inverses and GCDs

Greatest Common Divisors (GCDs)

Definitions

Euclid’s Division Theorem

The GCD Algorithm

Multiplicative Inverses

Definition and Properties

Link to GCD

The extended GCD algorithm.

Computing inverses

Page 44: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 44

The GCD algorithm Revisited

Computes GCD, but does not give x and y such thata x + ny =1

Page 45: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 45

Page 46: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 46

The Extended GCD Algorithm/Base Case

Base case: k=jq

gcd(k, j) = j

j * 1 + k * 0 = gcd(k, j), x=1, y=0

Page 47: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 47

The Extended GCD Algorithm/Induction

Induction: k \= jq

Page 48: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 48

Page 49: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 49

The Extended GCD Algorithm

Page 50: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 50Page 50

The Extended GCD Algorithm/Example

Page 51: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

Easy Manual Way to Find x and y

Without remembering:

Page 51

Page 52: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

The Extended GCD AlgorithmPage 52

Proved by induction already.

Page 53: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

Related Results

Together, those two imply:

Page 53

Page 54: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

Related ResultsPage 54

Together, those two imply:

Page 55: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

Page 56: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2Page 56

Inverses and GCDs

Greatest Common Divisors (GCDs)

Definitions

Euclid’s Division Theorem

The GCD Algorithm

Multiplicative Inverses

Definition and Properties

Link to GCD

The extended GCD algorithm.

Computing inverses

Page 57: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

Extend GCD Algo and InversesPage 57Page 57

Together, those two imply:

Page 58: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

Finding Inverse/Example

Find the

Page 58

Page 59: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

Manual Way to Find InversePage 59

Page 60: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

Page 61: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

02-03-2010: Recap

Proved:

Page 61

Proof technique

Proof by contradiction

Proof by smallest counter example

Page 62: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

02-03-2010: RecapPage 62

Page 63: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

02-03-2010: Today

Greatest Common Divisors (GCDs)

Definitions

Euclid’s Division Theorem

The GCD Algorithm

Multiplicative Inverses

Definition and Properties

Link to GCD (only results, proofs later)

The extended GCD algorithm.

Computing inverses

Page 63

Page 64: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

04-03-2010: RecapPage 64

a has multiplicative inverse in Zn iff gcd(a, n) =1

In that case, inverse of a = x mod n.

Today: prove correctness

Page 65: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

A Note on an Old Exam QuestionPage 65

Question: Should I first try to run extended GCD or try to show

equation with no solution? How to figure “3” in second case?

Page 66: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

A Note on an Old Exam Question

Answer: Factorize the numbers into product of primes

Page 66

53 cannot be divided by 2, 3, 5, 7, 11, 13, 17, 23, 29

So, it is a prime number.

Inverse exist. Run extended GCD.

Page 67: COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)

COMP 170 L2

A Note on an Old Exam QuestionPage 67

Answer: Factorize the numbers into product of primes

12 = 3 * 4

147 = 3 * 49

= 3 * 7 * 7

12 and 147 have common divisor 3

Left divisible by 3, but not right.

Write proof