Lecture 3.7: The Euclidean algorithm Matthew Macauley Department of - - PowerPoint PPT Presentation

lecture 3 7 the euclidean algorithm
SMART_READER_LITE
LIVE PREVIEW

Lecture 3.7: The Euclidean algorithm Matthew Macauley Department of - - PowerPoint PPT Presentation

Lecture 3.7: The Euclidean algorithm Matthew Macauley Department of Mathematical Sciences Clemson University http://www.math.clemson.edu/~macaule/ Math 4190, Discrete Mathematical Structures M. Macauley (Clemson) Lecture 3.7: The Euclidean


slide-1
SLIDE 1

Lecture 3.7: The Euclidean algorithm

Matthew Macauley Department of Mathematical Sciences Clemson University http://www.math.clemson.edu/~macaule/ Math 4190, Discrete Mathematical Structures

  • M. Macauley (Clemson)

Lecture 3.7: The Euclidean algorithm Discrete Mathematical Structures 1 / 6

slide-2
SLIDE 2

Greatest common divisor

Definition

Let a, b ∈ Z be nonzero. The greatest common divisor of a and b, denote gcd(a, b), is the positive integer d satisfying:

  • 1. d is a common divisor of a and b, i.e.,

d | a and d | b.

  • 2. If c also divides a and b, then c ≤ d. In other words,

∀c ∈ N, if c | a and c | b, then c ≤ d.

Examples

Compute the following:

  • 1. gcd(72, 63) =
  • 2. gcd(1012, 618) =
  • 3. gcd(5, 0) =
  • 4. gcd(0, 0) =
  • M. Macauley (Clemson)

Lecture 3.7: The Euclidean algorithm Discrete Mathematical Structures 2 / 6

slide-3
SLIDE 3

Greatest common divisor

Lemma

If a, b ∈ Z are not both zero, and q, r ∈ Z satisfy a = bq + r, then gcd(a, b) = gcd(b, r).

Proof

We’ll show:

  • 1. gcd(a, b) ≤ gcd(b, r).
  • 2. gcd(b, r) ≤ gcd(a, b).
  • M. Macauley (Clemson)

Lecture 3.7: The Euclidean algorithm Discrete Mathematical Structures 3 / 6

slide-4
SLIDE 4

The Euclidean algorithm

Around 300 B.C., Euclid wrote his famous book, the Elements, in which he described what is now known as the Euclidean algorithm:

Proposition VII.2 (Euclid’s Elements)

Given two numbers not prime to one another, to find their greatest common measure. The algorithm works due to two key observations: If a | b, then gcd(a, b) = a; If a = bq + r, then gcd(a, b) = gcd(b, r). This is best seen by an example: Let a = 654 and b = 360. 654 = 360 · 1 + 294 gcd(654, 360) = gcd(360, 294) 360 = 294 · 1 + 66 gcd(360, 294) = gcd(294, 66) 294 = 66 · 4 + 30 gcd(294, 66) = gcd(66, 30) 66 = 30 · 2 + 6 gcd(66, 30) = gcd(30, 6) 30 = 6 · 5 gcd(30, 6) = 6. We conclude that gcd(654, 360) = 6.

  • M. Macauley (Clemson)

Lecture 3.7: The Euclidean algorithm Discrete Mathematical Structures 4 / 6

slide-5
SLIDE 5

The Euclidean algorithm (modernized)

Input: Integers A, B ∈ Z with A > B ≥ 0.

  • Initalize. a := A, b := B, r := B.

while (b = 0) r := a mod b a := b b := r end while gcd := a return gcd;

  • M. Macauley (Clemson)

Lecture 3.7: The Euclidean algorithm Discrete Mathematical Structures 5 / 6

slide-6
SLIDE 6

The extended Euclidean algorithm

It can be useful to keep track of extra information when doing the Euclidean algorithm. The following is an example of the extended Euclidean algorithm, for a = 654 and b = 360. 654 360 654 = 1 · 654 + 0 · 360 1 360 = 0 · 654 + 1 · 360 1 654 = 360 · 1 + 294 294 = 1 · 654 − 1 · 360 1 −1 360 = 294 · 1 + 66 66 = 1 · 360 − 1 · 294 −1 2 294 = 66 · 4 + 30 30 = 1 · 294 − 4 · 66 5 −9 66 = 30 · 2 + 6 6 = 1 · 66 − 2 · 30 −11 20 30 = 6 · 5 We conclude that: gcd(654, 360) = 6 = 654(−11) + 360(20). Note that this allows us to solve equations of the form 654x ≡ 6 mod 360, = ⇒ x = −11 ≡ 349 (mod 360) and 360x ≡ 6 mod 654, = ⇒ x = 20 (mod 654).

  • M. Macauley (Clemson)

Lecture 3.7: The Euclidean algorithm Discrete Mathematical Structures 6 / 6