1. Introduction
The Euclidean greatest common divisor (
) algorithm is one of the most successful algorithms in Mathematics. Its improvements, like Lehmer’s
algorithm [1], are currently being used in cryptography protocols to factorize large composite numbers [2]. Examples of
’s application in Number Theory are: the Diophantine equations [3], the Chinese remainder theorem [4], and continued fractions [5]. The
algorithm also inspired Gabriel Lamé in the creation of the computational complexity theory [6]. Euclid gave expression to the
algorithm in the propositions of Book Seven of Euclid’s Elements [7]. He used concepts about divisibility and relatively prime numbers that may have taken the focus away from the case when the numbers are not integers. However, it is known that the algorithm works with real numbers, even though there are not many current references on this topic. But in fact, the concept of
has historically also used the name “greatest common measure’’ [7], indicating the measurement of real magnitudes.
In this paper, we present an algorithm that finds inspiration in Euclid’s
algorithm and Eudoxus’ proportion theory [8]. The impeccable theory of proportions of Eudoxus dates some decades before Euclid and uses the simple idea of fitting integer multiples of two real numbers with the intention of defining their ratio. In the next paragraphs, we provide some preliminary definitions and review useful background for later reference.
Let
and
be positive real numbers. Considering the fraction
, we distinguish two cases, the case where
is a rational, and the case where
is an irrational. If
is a rational, we denote
as the unique simplified fraction
, with
and
natural numbers and
, such that
(1)
The positive real number
is a divisor of
whenever there exists a natural number
fulfilling
. Each time the set of common divisors of
and
is not empty, the greatest common divisor of
and
,
is the maximum
that is a divisor of
and is also a divisor of
. In the case that the set of common divisors of
and
is empty, we say that
and
are incommensurable.
The relation between the previous definitions of
and
, is that when
is the greatest common divisor of
and
, and
,
, we have that
. Consequently,
(2)
and
(3)
The veracity of (3) is a consequence of the simple fact that if
and
, then the
would be equal to
instead of
.
The previous definition of
for
and
reals is not new. Indeed, the original version of the Euclidean algorithm works with quantities represented by segments. Its inspiration was to measure one segment with another. The algorithm that we present in Section 2 recovers this original meaning, which can be insightful even for children in elementary school.
The extended Euclidean algorithm, described in [9], has many applications in the solution of Diophantine equations [10] [11]. Improving its performance is a frequent subject in publications [12]. In all the rediscoveries and improvements that we can find since the 5th-6th century to our days, the Euclid’s way to find
is the cornerstone. The algorithm we present in Section 2 is not only a way to get the solution of the Diophantine equation,
(4)
but it also provides a complete arithmetic in
, the ring of the residue classes modulo
. The “steady walk” algorithm (
) described in this paper does not use the Euclidean algorithm for
. The proof we give in Section 2 is interesting by itself and uses the following not common formula of
as a function of
, when
and
,
(5)
The formula (5) can be proven by mathematical induction, using the tangent of the sum of two angles. The integers
and
are the floor function values on
and
respectively. Let
(6)
Consequently, in the case that
, the formula (5) implies that
(7)
The rest of this article is organized in the following way. Section 2 explains the
and presents its formal description with the necessary proof. In Section 3, the implementation of the algorithm provides interesting resulting examples. And finally, we present a concluding section.
2. The Algorithm
Let
and
be positive real numbers, with
. The
consists in marking, between two “walls”, consecutive steps, with step length equal to
. The walls are at 0 and at
of the real line. The first step begins at the 0 wall. If a step has not finished when it meets a wall, it rebounds off the wall in order to complete the step length. The walk only changes direction when the steps meet and rebound off the walls.
Formalizing the previous description, we write,
defined by:
and
(8)
Then the mark of the
-step is
.
Theorem 1. If the set
(9)
is not empty and we call
, then the following statements are true:
1) The set
is an array of equidistant points.
2) The distance between contiguous points is the
.
3) The distance between the maximum of
and
is equal to
or
.
4) If
is the number of points that are less than the first step, then
. Additionally,
, in correspondence to the disjunction in item 3, respectively.
5)
, in correspondence to the above disjunction respectively.
6) If the point id of the array, corresponds to the
-step, then,
in correspondence to the above disjunction respectively.
Proof. Let us visualize the algorithm in the following way:
Construct a circle of radius equal to
. In this way the semicircle has a length equal to
, and the quarter circle is
long. The steps will go from the point of zero angle, counterclockwise and each step has length
on the circle. If
is the
-step, the angle in radians of this point is
. We denote the before angle as
. There is only one angle,
in the first quadrant fulfilling,
(10)
Simple observation shows that the steps
map on the steps
under the natural bijection between the segment
and the first quarter circle. In the case that there exists
,
, with
, we have that
and consequently,
(11)
(12)
(13)
The last equality (13) is a consequence of
. Hence, we can suppose that there exist
and
, fulfilling
(14)
The case
is equivalent to
(15)
Similarly, we conclude that there exist
and
, fulfilling,
(16)
From (16), we obtain
(17)
Let
. It is easy to verify that,
1)
2)
and,
(18)
The set of equalities (18) can be written as
(19)
Dividing each equation by
, we get
(20)
Denoting
, we have,
(21)
We can interpret the set of equalities (21) as a system of linear equations with unknown variables
. This is a system where the number of variables exceeds by one the number of equations.
We now observe that, if for some
we have
(22)
and
(23)
we also have
(24)
Then, we would have the square system,
(25)
(26)
whose determinant is equal to a non-null Vandermonde determinant. This is a contradiction due to the existence of the non-null solution
.
Let us examine what is failing. Checking (22),
(27)
The last equality in (27) implies that
divides
. This is impossible because
. Hence, the only possibility is that (23) fails. In other words, for each
, there exist
fulfilling,
(28)
Also, it is easy to check that the values
are different,
(29)
From (29), we have that
, which clearly implies
. Therefore, by the Pigeonhole Principle, there exists a bijective function
such that
(30)
is defined by the property,
(31)
Now, we observe that,
(32)
and
, so the first five points of the theorem are straightforward. Recapitulating,
1) The set
corresponds to the set of steps in the first quadrant
, and this last set corresponds to the angles
.
2)
is the arc length between contiguous points of the array. Furthermore,
(33)
3) When
is even, the maximum of the array of steps is
(34)
And when
is odd, the maximum is
(35)
4) The equality
is a consequence of item 2. Additionally, when
is even,
(36)
and
. When
is odd,
(37)
and
.
5) In the case
is even,
(38)
And when
is odd,
(39)
Finally, let us prove item 6,
(40)
(41)
(42)
(43)
The previous sequence of implications (40)-(43) finishes the proof of the theorem. □
Note that the equality (43) is equivalent to
(44)
and this last equality (44) justifies that the
provides a complete arithmetic in
, as stated in the introduction.
3. Implementation and Examples
In this section, we show the process of the algorithm described in Section 2 as a pseudocode. The examples and figures were implemented using the python programming language. In the figures, we mark the steps corresponding to each complete path of
on different segments of a polygonal curve. See Figures 1-3. The geometrical behavior displayed in the plots change with the two numbers, x and y, in the Algorithm 1 and with the number of iterations
.
Algorithm 1. Steady walk algorithm.
Example 1: The steady walk algorithm (
) for two integers,
and
, with
iterations. As seen in Figure 1, the algorithm stops at the iteration (847/2)/11. In this case the Euclidean algorithm for
only needs two divisions and the
obtains two footprints, 286 and 275, with difference equal to the
after two sums and two differences.
Figure 1. Output of
for
and
. The plot shows the steps
vs. the iteration number
. The table lists the numerical values of all points.
Figure 1. Output of
for
and
. The plot shows the steps
vs. the iteration number
. The table lists the numerical values of all points.
Example 2: The
for the numbers
and the irrational
, with
iterations. These two numbers
and
are incommensurable. We choose this particular number of iterations
so that it shows interesting regular patterns (see Figure 2).
Figure 2. Output of
for
and
. The plot shows the steps
vs. the iteration number
. The table lists the numerical values of all points.
Example 3: Figure 3 shows the
for two irrational numbers,
and
, with
iterations.
Figure 3. Output of
for
and
. The plot shows the steps
vs. the iteration number n.
4. Conclusion
The full Euclidean algorithm that we present in this paper has advantages in several aspects. As a result of its graphical output, it can be a very useful tool in the mathematical explanations about incommensurability, irrationality, great common divisor, solution of the Diophantine Equation (4) and arithmetic in the ring
, of residue classes modulo
. Another advantage is the improvement of the extended Euclidean algorithm. The process can be expedited since the difference between any two footprints is a new candidate to redirect the algorithm toward a shorter path. In fact, to begin with
, instead of
, is already a clear improvement. The last aspect we would like to mention is the study of irrationality. The distribution of footprints in
, when the number of steps increases, is a promising tool in the understanding of different kinds and grades of irrationality, and the Diophantine approximation. Some related results can be found in [13]. Finally,
is conceptually easier than the extended and classic Euclidean algorithms, allowing many shortcuts that improve its efficiency.