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_0is the identity function: for allb,gcd_0(b)=b; -
for nonzero
a,gcd_ais defined on the inputbin terms of the remainder on division bya(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)
-
gcd(a,b)is always positive, unless both inputsa,bare zero (in which case it's zero). -
gcd(a,b)divides bothaandb. -
If
xis any number which dividesaandb, then it also dividesgcd(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).
-
If
a=0thengcd(a,b)=b, which is positive unlessbis also zero.Otherwise
gcd(a,b)=gcd(r_a(b),a), which is positive by the inductive hypothesis (sinceais nonzero). -
If
a=0thengcd(a,b)=b, which is a factor of both0andb.Otherwise
gcd(a,b)=gcd(r_a(b),a), which by the inductive hypothesis is a factor of bothaandr_a(b). By Proposition 28(2), the remainderr_a(b)satisfiesb=aq+r_a(b)for some natural numberq(the "quotient"). Sincegcd(a,b)is a factor of bothaandr_a(b), it must also be a factor ofb. -
If
a=0thengcd(a,b)=b, sox, being a factor ofb, is a factor ofgcd(a,b).Otherwise, by Proposition 28(2),
b=aq+r_a(b)for some natural numberq. Sincexis a factor of bothaandb, by Theorem 23 it is also a factor ofr_a(b). By the inductive hypothesis it follows thatxis a factor ofgcd(r_a(b),a), which is equal togcd(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.