Donald Knuth
[The Euclidean algorithm is] the granddaddy of all algorithms, because it is the oldest nontrivial algorithm that has survived to the present day.
— The Art of Computer Programming, Vol. 2
We are back at another historical journey of mathematics, with this installment being one of the oldest algorithms we still use today. That’s right: the Euclidean Algorithm, and all of the small discoveries that led to it.
The semi-forgotten history of Reciprocal Subtraction
Suppose you were in the shoes of a Greek mathematician, and you were tasked with finding the circumference of a circle that has the radius of 1 unit. You can empirically measure it and obtain a rough decimal approximation, but what if you wanted to find a close fractional form? We know that the circumference of a circle is: . But how can we construct a fraction close to it? Let’s focus in on the decimal part, so we can subtract , so we can reduce the problem to: “What is the closest fraction we can get for “.
The process I will call ‘reciprocal subtraction’ has a long history in mathematics and is closely connected to rational approximation. Variations of the process appear in Euclid’s Elements, but Euclid did not provide a numerical worked example in the modern sense.
Reciprocal Subtraction
Let be the number you want to approximate. I will denote the ceiling function as . Let . Define the remaining ‘s in the following way:
Now we can build our continued fraction as:
Example
Awesome Coincidence
- If we were to do the following: We can stumble upon a pretty famous approximation for that dates back to the fifth century by mathematician Zu Chongzhi. Unfortunately, his exact method of how he obtained that approximation has been lost to history, but many historians suggest that continued fractions could have been how he did it!
Question
- Couldn’t you come up with a rational by adding up all the parts of the decimal?
Yes, but...
- I don’t know about you, but is a much nicer fraction than . Using it for various calculations would be considerably much easier, even if it’s an over-approximation, it still agrees with to ten decimal places
Here is my favorite computation I've discovered!
Using this process, we obtain a finite continued fraction representation for , one of the most famous approximations for pi!
The Division Algorithm
Before we talk about the Euclidean Algorithm, it would be helpful to jump a bit into the future to gain some familiarity of Euclid’s Concepts with our more modern way of viewing division.
The Division Algorithm
- Given integers and , with , there exists unique integers and satisfying
- where is usually denoted as the quotient and is the remainder in the division of and
Proof
- In order to prove the division algorithm for the integers, we will need to prove the existence and uniqueness of such solutions
Existence
- We will prove by induction on a
Induction Step
Suppose that given a fixed positive integer , then for every integer with there exists a with Lets consider , then
Case 1:
If , then we are done as we can see that
Case 2:
If , then
- Hence, we are able to construct , where and
Uniqueness
Suppose that
Without Loss of generality, assume that , then and . Since and , then
However, since is a positive integer, lets call it , however, we run into a problem as there are no positive integers that satisfies the inequality . Leaving us at a contradiction. Therefore, or , therefore
Euclid’s Elements
Unsurprisingly, many elements of the Euclidean Algorithm can be traced back to Euclid’s Elements. The main book we will focus on is Book 7 as Euclid has laid out the foundation to many elements of the Euclidean Algorithm that we currently use.
Good Old Euclid
Book 7, Prop 1
When two unequal numbers are set out, and the less is continually subtracted in turn from the greater, if the number which is left never measures the one before it until a unit is left, then the original numbers are relatively prime.
Modern Interpretation
For positive integers , apply the division algorithm in the following way:
and , then
Book 7, Prop 2
Book 7 lays the actual procedure using an example, it is quite long and tedious, so instead I’ll provide a worded example! You can read a translation here if you are really interested!
So . But if you were to slightly adjust the way the operations are done, it will look familiar!
It looks just like reciprocal subtraction! But maybe this realization will blow your mind. We can distill the problem to just:
What initially appeared as three different abstract mathematical concepts can all be related by underlying process! Isn’t that awesome!
Why does the Euclidean Algorithm give us the greatest common divisor?
Before we tackle the question, let us generalize the Euclidean Algorithm using notion we are familiar with:
Modern Interpretation
For positive integers , apply the division algorithm in the following way:
Producing a strictly decreasing sequence of positive integers ,where the algorithm terminates with as the last non-zero remainder and
Useful Divisibility Properties that will be useful for our proofs
Let
Proof
The Euclidean Algorithm terminates after at most b steps
Proof
- At every step of the Euclidean Algorithm, the remainders are positive integers strictly smaller than the preceding remainder: Since there are only positive integers smaller than , there can be at most nonzero remainders. Therefore, after finitely many steps, the next remainder must be 0, and the algorithm terminates.
The Euclidean Algorithm generates a number that divides both and
Proof
Giving us and
The Euclidean Algorithm generates the greatest common divisor
Proof
- Suppose , hence and and
- Clean Conclusion: Since and is positive, . However since divides both and and is their greatest common divisor, , thus , or is our greatest common divisor!
One Final observation and recap
The final proof lays out quite a very important corollary in number theory!
Book 7, Prop 2 Corollary
If a number measures two numbers, then it also measures their greatest common measure.
Modern Interpretation
- If and , then
Proof
- This proof follows the exact same procedure as the last proof. You will end off with !
And with that, you now know how to find the greatest common divisors of any two integers and, along the way, a process to find rational approximations of irrational numbers. Now go on with your day and tackle even more math questions!