comp 170 l2 page 1 l05: inverses and gcds l objective: n when does have an inverse? n how to compute...
TRANSCRIPT
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.
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
COMP 170 L2Page 3
Divisors of an Integer
COMP 170 L2Page 4
Prime Numbers
COMP 170 L2Page 5
Common Divisors
COMP 170 L2Page 6
Relatively Prime
COMP 170 L2Page 7
How to Find GCD?
How to calculate gcd(m, n)?
Need Euclid’s division theorem
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
COMP 170 L2Page 9
Euclid’s Division Theorem
COMP 170 L2Page 10
Euclid’s Division Theorem
COMP 170 L2Page 11
COMP 170 L2Page 12
COMP 170 L2Page 13
COMP 170 L2Page 14
Proof by Smallest Counter Example
COMP 170 L2Page 15
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 .
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)
COMP 170 L2Page 18
COMP 170 L2Page 19
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
COMP 170 L2Page 21
Euclid’s GCD algorithm
COMP 170 L2Page 22
Euclid’s GCD algorithm
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
COMP 170 L2Page 24
Multiplicative Inverse mod n
COMP 170 L2Page 25
Determine Inverses from Multiplication Table
Which nonzero elements of have multiplicative inverses?
COMP 170 L2Page 26
Determine Inverses from Multiplication Table
Which nonzero elements of have multiplicative inverses?
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
COMP 170 L2Page 28
Multiplicative Inverse mod n
COMP 170 L2Page 29
Multiplicative Inverse mod n
COMP 170 L2Page 30
Proving Inverse does not Exist
Gives us a way to prove that inverse does not exist
COMP 170 L2Page 31
Proving Inverse does not Exist
COMP 170 L2Page 32
Proving Inverse does not Exist
COMP 170 L2Page 33
Proving Inverse does not Exist
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
COMP 170 L2Page 35
Link to GCD
Objective:
Show the following two important results
COMP 170 L2Page 36
Modular Equations and Normal Equations
COMP 170 L2Page 37
COMP 170 L2Page 38
Inverse and Normal Equations
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,
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
COMP 170 L2Page 41
Link to GCD
COMP 170 L2Page 42
Link to GCD/Summary
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
COMP 170 L2Page 44
The GCD algorithm Revisited
Computes GCD, but does not give x and y such thata x + ny =1
COMP 170 L2Page 45
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
COMP 170 L2Page 47
The Extended GCD Algorithm/Induction
Induction: k \= jq
COMP 170 L2Page 48
COMP 170 L2Page 49
The Extended GCD Algorithm
COMP 170 L2Page 50Page 50
The Extended GCD Algorithm/Example
COMP 170 L2
Easy Manual Way to Find x and y
Without remembering:
Page 51
COMP 170 L2
The Extended GCD AlgorithmPage 52
Proved by induction already.
COMP 170 L2
Related Results
Together, those two imply:
Page 53
COMP 170 L2
Related ResultsPage 54
Together, those two imply:
COMP 170 L2
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
COMP 170 L2
Extend GCD Algo and InversesPage 57Page 57
Together, those two imply:
COMP 170 L2
Finding Inverse/Example
Find the
Page 58
COMP 170 L2
Manual Way to Find InversePage 59
COMP 170 L2
COMP 170 L2
02-03-2010: Recap
Proved:
Page 61
Proof technique
Proof by contradiction
Proof by smallest counter example
COMP 170 L2
02-03-2010: RecapPage 62
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
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
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?
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.
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