This lecture discusses one of the earliest and most important mathematical algorithms. The Euclidean algorithm computes the greatest common divisor of two integers (it can be extended to other domains such as polynomials). This algorithm, not commonly taught when gcds are introduced in High School mathematics, is a much more efficient way to compute the gcd than using integer factorization.

The algorithm can be stated in a few lines, using recursion, yet it has many fascinating properties, and its complete analysis was a major undertaking.

An immediate generalization of the Euclidean algorithm, called the extended Euclidean algorithm computes integers x and y such that x*a + y*b = gcd(a,b). This relationship, called Bezout's identity, can be used to prove Theorem 1.1 from lecture 1. We will see later in the course, that it has many other important applications.

- Euclidean division (division with remainder). a = q*b + r, where 0 <= r < b. The quotient q and remainder r are unique.
- Definition. g = gcd(a,b) iff g|a and g|b (m|n iff n = q*m for some q) and if e|a and e|b then e|g.
- Factorization into primes (every integer can be written uniquely (upto order) as a product of prime numbers. This is called the fundamental theorem of arithmetic. See lecture 1 on Unique Factorization.

- Chapter sections 1.3-1.4 of the text.

- Definition of greatest common divisors
- Existence proof of Bezout's identity and a proof of Theorem 1.1.
- Euclidean algorithm

gcd(a,b)- if b = 0 then return a;
- else return gcd(b,a mod b)

- Proof of correctness
- The extended Euclidean algorithm (recursive version)
- Iterative version of the algorithm and remainder sequences
- Fibonacci numbers and an upper bound on the number of divisions
- The Fibonacci numbers are defined by F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2} for n > 1.
- F_n = 1/sqrt(5)*(phi^n - phihat^n), where phi = (1 + sqrt(5))/2 and phihat = (1 - sqrt(5))/2 are the roots of x^2-x-1=0. F_n is the nearest integer to 1/sqrt(5)*phi^n.
- Let 0 <= b < a <= N and n = the maximum number of division steps required to compute gcd(a,b) using the Euclidean algorithm. Then n <= 2lg(N). This constant in this bound is not tight.
- Let 0 <= b < a <= N. The maximum number of division steps occurs when when a = F_{n+2} and b = F_{n+1}. From this it follows that the n <= log[phi](N) + log[phi](sqrt(5)/phi). log[phi](N) is approximately 1.44*lg(N).

- The probability that two random integers are relatively prime.

- euclid.mw - Maple worksheet on the Euclidean algorithm.

- Use Maple's
**igcd**command to find gcd(1239,168). - Use Maple's
**igcdex**command to find integers x and y such that 1239*x + 168*y = gcd(1239,168). - Exercise 1.19 from the text.
- Exercise 1.22 from the text.
- Experiment with Maple's
**cfrac**command from the**numtheory**package. Review how to load a package with**with**.