IUM lectures on Numbers

2.13. Euclid's algorithm

Say we have two natural numbers a and b. Here is a complicated function of a and b. It's called Euclid's algorithm.

Definition 34 (Euclid's Algorithm)

Define a sequence of functions gcd_a:\N \to \N as follows:

  • gcd_0 is the identity function: for all b, gcd_0(b)=b;

  • for nonzero a, gcd_a is defined on the input b in terms of the remainder on division by a (see Definition 27): gcd_a(b)=gcd_{r_a(b)}(a).

Notation: sometimes we write gcd(a,b) rather than gcd_a(b); with this notation gcd is being thought of as a function from \N\times\N to \N.

This definition is another example of strong recursion (Definition 25). The set X is \N \to \N, the set of functions from the natural numbers to themselves: For each natural number a we define a function gcd_a :\N \to \N. The function gcd_a is defined in terms in terms of prior, not necessarily immediately-prior, functions gcd_t, namely functions gcd_{r_a(b)}, where r_a(b) are the remainders on dividing various natural numbers by a, which are all smaller than a itself by Proposition 28(1).

Let's see an example. Let's start with a=20 and b=28. We take the remainder of 28 when dividing by 20; this gives 8. Next we take the remainder of 20 when dividing by 8; this gives 4. We continue: \begin{align*} gcd(20,28)&=gcd(8,20)\\ &=gcd(4,8)\\ &=gcd(0,4)\\ &=4.\end{align*} Eventually the remainder is zero, and at that point we return the most recent previous remainder, which was 4.

Let's prove some facts about this function gcd.

Proposition 35 (Results about Euclid's algorithm)

  1. gcd(a,b) is always positive, unless both inputs a, b are zero (in which case it's zero).

  2. gcd(a,b) divides both a and b.

  3. If x is any number which divides a and b, then it also divides gcd(a,b).

Proof

We prove all these facts by strong induction. Let a be a natural number, and suppose these facts are known for gcd(t,s), for all t<a. Now let b be a natural number and consider gcd(a,b).

  1. If a=0 then gcd(a,b)=b, which is positive unless b is also zero.

    Otherwise gcd(a,b)=gcd(r_a(b),a), which is positive by the inductive hypothesis (since a is nonzero).

  2. If a=0 then gcd(a,b)=b, which is a factor of both 0 and b.

    Otherwise gcd(a,b)=gcd(r_a(b),a), which by the inductive hypothesis is a factor of both a and r_a(b). By Proposition 28(2), the remainder r_a(b) satisfies b=aq+r_a(b) for some natural number q (the "quotient"). Since gcd(a,b) is a factor of both a and r_a(b), it must also be a factor of b.

  3. If a=0 then gcd(a,b)=b, so x, being a factor of b, is a factor of gcd(a,b).

    Otherwise, by Proposition 28(2), b=aq+r_a(b) for some natural number q. Since x is a factor of both a and b, by Theorem 23 it is also a factor of r_a(b). By the inductive hypothesis it follows that x is a factor of gcd(r_a(b),a), which is equal to gcd(a,b) by definition.

We have just shown this:

Theorem 36 (Greatest common divisor facts)

If at least one of a and b is positive, then gcd(a,b) is the greatest of the common divisors of a and b, and it is even a multiple of all common divisors of a and b.

This is why we chose the notation gcd -- it stands for greatest common divisor (we will also use that terminology).

In the case a=b=0, the number 0=gcd(a,b) still does have the property that any divisor of a and b divides 0, because everything divides 0. In this case 0=gcd(a,b) is not the greatest common divisor because 37>0 and 37 divides 0. However it is still the divisor that all the other divisors divide.

Note that computing the greatest common divisor of two numbers via Euclid's algorithm is much more efficient than factoring both sides, the moment the numbers involved are bigger than 200 or so.

Developing the theory of prime numbers and divisors any further is pretty annoying without a theory of subtraction, and developing a theory of subtraction is pretty annoying without having access to negative numbers. So we stop our development of naturals here, and move on to an explanation of the integers.