Extended Euclidean Algorithm: Proof and Examples, Lecture notes of Grammar and Composition

The proof of the Extended Euclidean Algorithm and examples of finding integers x and y that satisfy the equation gcd(a, b) = ax + by. The algorithm is explained through theorems and a contradiction proof.

Typology: Lecture notes

2021/2022

Uploaded on 07/04/2022

dirk88
dirk88 ๐Ÿ‡ง๐Ÿ‡ช

4.4

(222)

3.1K documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Extended'Euclidean'Algorithm
Yan$Huang
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Extended Euclidean Algorithm: Proof and Examples and more Lecture notes Grammar and Composition in PDF only on Docsity!

Extended Euclidean Algorithm

Yan Huang

Can you sell exactly 4 gallons of gasoline?

3 Gallon 8 Gallon

Can you sell 1 gallon of gasoline with

containers of these two sizes?

3 Gallon 8 Gallon

  1. Pour 8*2 gallons of gasoline the tank.
  2. Fill the 3-gallon container with gasoline in the tank, 5 times.
  3. Sell the remaining 1 gallon gasoline in the tank.

Theorem : gcd(๐‘Ž, ๐‘) = ๐‘‘ if and only if ๐‘‘ is the least positive integer that can be expressed as ๐‘Ž๐‘ฅ + ๐‘๐‘ฆ where ๐‘ฅ, ๐‘ฆ โˆˆ โ„ค.

Theorem : gcd(๐‘Ž, ๐‘) = ๐‘‘ if and only if ๐‘‘ is the least positive integer that can be expressed as ๐‘Ž๐‘ฅ + ๐‘๐‘ฆ where ๐‘ฅ, ๐‘ฆ โˆˆ โ„ค.

Proof (by contradiction ): Consider the set of integers S = ๐‘Ž๐‘ฅ + ๐‘๐‘ฆ ๐‘ฅ, ๐‘ฆ โˆˆ โ„ค} and ๐‘‘ = min ๐‘†. Assume (for the sake of contradiction) that ๐‘‘ โˆค ๐‘Ž. Then ๐‘Ž = ๐‘‘๐‘ž + ๐‘Ÿ where 0 โ‰ค ๐‘Ÿ < ๐‘‘. Therefore, ๐‘Ÿ = ๐‘‘ โˆ’ ๐‘Ž๐‘ž = ๐‘Ž๐‘ฅ + ๐‘๐‘ฆ โˆ’ ๐‘Ž๐‘ž = ๐‘Ž ๐‘ฅ โˆ’ ๐‘ž + ๐‘๐‘ฆ โˆˆ ๐‘†, which contradicts to the fact that ๐‘‘ = min ๐‘† since ๐‘Ÿ โˆˆ ๐‘† and ๐‘Ÿ < ๐‘‘. Thus, the assumption was wrong and ๐‘‘|๐‘Ž. Theorem : gcd(๐‘Ž, ๐‘) = ๐‘‘ if and only if ๐‘‘ is the least positive integer that can be expressed as ๐‘Ž๐‘ฅ + ๐‘๐‘ฆ where ๐‘ฅ, ๐‘ฆ โˆˆ โ„ค.

Examples

  • ๐‘Ž = 6 and ๐‘ = 8

Examples

  • ๐‘Ž = 3 and ๐‘ = 8

Examples

  • Find x, y such that 12x + 8y = gcd(12, 8) egcd (12, 8) egcd :: Int - > Int - > (Int, Int, Int) egcd a 1 = (0, 1, 1) egcd a 0 = (1, 0, a) egcd a b | a < b = let (x, y, d) = egcd b a in (y, x, d) | otherwise = let (x, y, d) = egcd b (a mod b) q = a div b in (y, x-y*q, d)

Exercise

  • Find integer x, y such that 27x + 42y = gcd(27, 42) egcd (27, 42)