We have seen what the greatest common divisor is and one of its uses, namely it allows us observe under what conditions linear equations are soluble in the integers. In this post we will see one way to compute the greatest common divsior, the Extended Euclidean Algorithm. Before we get to the Extended Euclidean Algorithm we will start with the standard Euclidean Algorithm. It is named after Euclid a greek mathematician who is often called the “father of geometry” who described this algorithm as early as 300 BC. The essence of the Euclidean Algorithm is to apply Theorem 2.1 over and over until we get a remainder of zero, then we can extract the greatest common divisor.
Notation: means x does not divide y.
Definition 3.1: Linear Combination
A linear combination of integers is any expression of the form
where a and b are constants. (for our purposes a and b will always be integers).
This next theorem may look intimidating but once we go through an example and put numbers to the letters it will become clearer.
Theorem 3.1: (The Euclidean Algorithm) Let with
and
. Let
and apply Theorem 2.1 repeatedly to obtain a sequence of remainders
defined as follows:
where
where
…
where
where
Then
Proof:
Consider the sequence of remainders, the $r_{i}$ are strictly decreasing non-negative integers and so at some stage . We have that for any
we have gcd(x,y)=gcd(x+zy,y). So in terms of our remainders this is
. Applying this over and over yields;
where the last equality is because
.
QED
Remember Bezout’s Identity from the last post? well we can find such that
(i.e. we can express the gcd of a and b as a linear combination of a and b) by ‘working backwards’. We can do this because each remainder can be expressed as a linear combination of the two previous remainders, so can the remainders before those and eventually it can be expressed in terms of a and b as we will see in the following example;
Example 3.1: Calculate the Greatest Common divisor of 720 and 333 and express it as a linear combination of 720 and 333.
therefore gcd(720,333)=9. (Try and compare this example to the previous theorem and see where the numbers fit the ). Now lets work backwards to express 9 as a linear combination of 720 and 333.
and so
collecting like terms yields .
So we have now seen how and why the Euclidean Algorithm works, now for the Extended Euclidean Algorithm. The Extended Euclidean Algorithm essentially combines the ‘working backwards’ step we did in the previous example while we compute the gcd, and so it computes the gcd as a linear combination of the two integers.
The sequences of quotients, , and remainders,
, defined in the Euclidean Algorithm, we now define the sequence of integers
, such that
. Remember that we define
to be the last non zero remainder and that
. Therefore we have
and so we set
. Let us now explicitly define
and
. So from Theorem 3.1
and
and so clearly
and
and so we set
and
. Now for
we recursively define by
which will become clear with an example.
Example 3.2: Let calculate gcd(720,333) again but this time using the Extended Euclidean Algorithm;
| 0 | 720 | 1 | 0 | |||
| 1 | 333 | 0 | 1 | |||
| 2 | 720 | 333 | 2 | 54 | 1 | -2 |
| 3 | 333 | 54 | 6 | 9 | -6 | 13 |
| 4 | 54 | 9 | 6 | 0 |
Compare this with example 3.1 to help you understand where everything is coming from. A useful exercise is to compute the gcd of any two integers and then check your answer at this website https://planetcalc.com/3298/ .