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

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

The Euclidean Algorithm terminates after at most b steps

The Euclidean Algorithm generates a number that divides both and

The Euclidean Algorithm generates the 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

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!

Resources