Docsity

Extended Euclidean Algorithm and Multiplicative Inverses for Solving Modular Equations, Study notes of Mathematics for Computing

Partial preview of the text

Download Extended Euclidean Algorithm and Multiplicative Inverses for Solving Modular Equations and more Study notes Mathematics for Computing in PDF only on Docsity!

CSE 311 Lecture 14: EuclideanCSE 311 Lecture 14: Euclidean

Algorithm and ModularAlgorithm and Modular

EquationsEquations

Emina Torlak andSami Davies

TopicsTopics

Primes and GCD

A quick review of.

Extended Euclidean algorithm

Bézout’s theorem and the extended Euclidean algorithm.

Modular equations

Solving modular equations with the extended Euclidean algorithm.

Lecture 13

Primes and composites: definitions and theoremsPrimes and composites: definitions and theorems

Prime number

An integer p > 1 is called prime if its only positive factors are 1 and p.

Composite number

An integer c > 1 is called composite if it is not prime.

Fundamental theorem of arithmetic

Every positive integer greater than 1 has a unique prime factorization.

Euclid’s theorem

There are infinitely many primes.

Greatest common divisor (GCD): definitionGreatest common divisor (GCD): definition

Greatest common divisor (GCD)

The greatest common divisor of integers a and b , written as GCD( a , b ), is the

largest integer d such that d | a and d | b.

We can compute GCDs efficiently using the

Euclidean algorithm. Invented in 300 BC!

Extended Euclidean algorithmExtended Euclidean algorithm

Bézout’s theorem and the extended Euclidean algorithm.

Bézout’s theorem about GCDsBézout’s theorem about GCDs

Bézout’s theorem

If a and b are positive integers, then there exist integers s and t such that

GCD( a , b ) = sa + tb.

Extended Euclidean algorithmExtended Euclidean algorithm

1. Compute GCD and keep the tableau. GCD(35, 27) = 35 s + 27 t.

Extended Euclidean algorithmExtended Euclidean algorithm

1. Compute GCD and keep the tableau.

a = q ∗ b + r 35 = 1 ∗ 27 + 8 27 = 3 ∗ 8 + 3 8 = 2 ∗ 3 + 2 3 = 1 ∗ 2 + 1

GCD( a , b ) GCD( b , a mod b ) r = a mod b GCD(35, 27) = GCD(27, 35 mod 27) = GCD(27, 8) = GCD(8, 27 mod 8) = GCD(8, 3) = GCD(3, 8 mod 3) = GCD(3, 2) = GCD(2, 3 mod 2) = GCD(2, 1) = GCD(1, 2 mod 1) = GCD(1, 0)

GCD(35, 27) = 35 s + 27 t.

Extended Euclidean algorithmExtended Euclidean algorithm

1. Compute GCD and keep the tableau.

2. Solve the equations for r in the tableau.

3. Back substitute the equations for r.

r = a − q ∗ b 8 = 35 − 1 ∗ 27 3 = 27 − 3 ∗ 8 2 = 8 − 2 ∗ 3 1 = 3 − 1 ∗ 2

GCD(35, 27) = 35 s + 27 t.

Extended Euclidean algorithmExtended Euclidean algorithm

1. Compute GCD and keep the tableau.

2. Solve the equations for r in the tableau.

3. Back substitute the equations for r.

r = a − q ∗ b 8 = 35 − 1 ∗ 27 3 = 27 − 3 ∗ 8 2 = 8 − 2 ∗ 3 1 = 3 − 1 ∗ 2

GCD(35, 27) = 35 s + 27 t.

ri = ri − 2 − qi ∗ ri − 1 r 0 = a = 35 r 1 = b = 27 r 2 = r 0 − q 2 ∗ r 1 = 8 r 3 = r 1 − q 3 ∗ r 2 = 3 r 4 = r 2 − q 4 ∗ r 3 = 2 r 5 = r 3 − q 5 ∗ r 4 = 1

Extended Euclidean algorithmExtended Euclidean algorithm

1. Compute GCD and keep the tableau.

2. Solve the equations for r in the tableau.

3. Back substitute the equations for r.

r = a − q ∗ b 8 = 35 − 1 ∗ 27 3 = 27 − 3 ∗ 8 2 = 8 − 2 ∗ 3 1 = 3 − 1 ∗ 2

1 = 3 − 1 ∗ 2 r 5 =^ r 3 −^ q 5 ∗^ r 4. = 3 − 1 ∗ (8 − 2 ∗ 3) Plug in^ r 4 =^ r 2 −^ q 4 ∗^ r 3.

GCD(35, 27) = 35 s + 27 t.

ri = ri − 2 − qi ∗ ri − 1 r 0 = a = 35 r 1 = b = 27 r 2 = r 0 − q 2 ∗ r 1 = 8 r 3 = r 1 − q 3 ∗ r 2 = 3 r 4 = r 2 − q 4 ∗ r 3 = 2 r 5 = r 3 − q 5 ∗ r 4 = 1

Extended Euclidean algorithmExtended Euclidean algorithm

1. Compute GCD and keep the tableau.

2. Solve the equations for r in the tableau.

3. Back substitute the equations for r.

r = a − q ∗ b 8 = 35 − 1 ∗ 27 3 = 27 − 3 ∗ 8 2 = 8 − 2 ∗ 3 1 = 3 − 1 ∗ 2

1 = 3 − 1 ∗ 2 r 5 =^ r 3 −^ q 5 ∗^ r 4. = 3 − 1 ∗ (8 − 2 ∗ 3) Plug in^ r 4 =^ r 2 −^ q 4 ∗^ r 3. = ( − 1) ∗ 8 + 3 ∗ 3 Combine^ r 2 ,^ r 3 terms.

GCD(35, 27) = 35 s + 27 t.

ri = ri − 2 − qi ∗ ri − 1 r 0 = a = 35 r 1 = b = 27 r 2 = r 0 − q 2 ∗ r 1 = 8 r 3 = r 1 − q 3 ∗ r 2 = 3 r 4 = r 2 − q 4 ∗ r 3 = 2 r 5 = r 3 − q 5 ∗ r 4 = 1

Extended Euclidean algorithmExtended Euclidean algorithm

1. Compute GCD and keep the tableau.

2. Solve the equations for r in the tableau.

3. Back substitute the equations for r.

r = a − q ∗ b 8 = 35 − 1 ∗ 27 3 = 27 − 3 ∗ 8 2 = 8 − 2 ∗ 3 1 = 3 − 1 ∗ 2

1 = 3 − 1 ∗ 2 r 5 =^ r 3 −^ q 5 ∗^ r 4. = 3 − 1 ∗ (8 − 2 ∗ 3) Plug in^ r 4 =^ r 2 −^ q 4 ∗^ r 3. = ( − 1) ∗ 8 + 3 ∗ 3 Combine^ r 2 ,^ r 3 terms. = ( − 1) ∗ 8 + 3 ∗ (27 − 3 ∗ 8) Plug in^ r 3 =^ r 1 −^ q 3 ∗^ r 2. = 3 ∗ 27 + ( − 10) ∗ 8 Combine^ r 1 ,^ r 2 terms.

GCD(35, 27) = 35 s + 27 t.

ri = ri − 2 − qi ∗ ri − 1 r 0 = a = 35 r 1 = b = 27 r 2 = r 0 − q 2 ∗ r 1 = 8 r 3 = r 1 − q 3 ∗ r 2 = 3 r 4 = r 2 − q 4 ∗ r 3 = 2 r 5 = r 3 − q 5 ∗ r 4 = 1

Extended Euclidean algorithmExtended Euclidean algorithm

1. Compute GCD and keep the tableau.

2. Solve the equations for r in the tableau.

3. Back substitute the equations for r.

r = a − q ∗ b 8 = 35 − 1 ∗ 27 3 = 27 − 3 ∗ 8 2 = 8 − 2 ∗ 3 1 = 3 − 1 ∗ 2

1 = 3 − 1 ∗ 2 r 5 =^ r 3 −^ q 5 ∗^ r 4. = 3 − 1 ∗ (8 − 2 ∗ 3) Plug in^ r 4 =^ r 2 −^ q 4 ∗^ r 3. = ( − 1) ∗ 8 + 3 ∗ 3 Combine^ r 2 ,^ r 3 terms. = ( − 1) ∗ 8 + 3 ∗ (27 − 3 ∗ 8) Plug in^ r 3 =^ r 1 −^ q 3 ∗^ r 2. = 3 ∗ 27 + ( − 10) ∗ 8 Combine^ r 1 ,^ r 2 terms. = 3 ∗ 27 + ( − 10) ∗ (35 − 1 ∗ 27) Plug in^ r 2 =^ r 0 −^ q 2 ∗^ r 1.

GCD(35, 27) = 35 s + 27 t.

ri = ri − 2 − qi ∗ ri − 1 r 0 = a = 35 r 1 = b = 27 r 2 = r 0 − q 2 ∗ r 1 = 8 r 3 = r 1 − q 3 ∗ r 2 = 3 r 4 = r 2 − q 4 ∗ r 3 = 2 r 5 = r 3 − q 5 ∗ r 4 = 1