Back
 AM  Vol.12 No.4 , April 2021
Full Euclidean Algorithm by Means of a Steady Walk
Abstract: Let x and y be two positive real numbers with x < y. Consider a traveler, on the interval [0, y/2], departing from 0 and taking steps of length equal to x. Every time a step reaches an endpoint of the interval, the traveler rebounds off the endpoint in order to complete the step length. We show that the footprints of the traveler are the output of a full Euclidean algorithm for x and y, whenever y/x is a rational number. In the case that y/x is irrational, the algorithm is, theoretically, not finite; however, it is a new tool for the study of its irrationality.

1. Introduction

The Euclidean greatest common divisor ( g c d ) algorithm is one of the most successful algorithms in Mathematics. Its improvements, like Lehmer’s g c d algorithm [1], are currently being used in cryptography protocols to factorize large composite numbers [2]. Examples of g c d ’s application in Number Theory are: the Diophantine equations [3], the Chinese remainder theorem [4], and continued fractions [5]. The g c d algorithm also inspired Gabriel Lamé in the creation of the computational complexity theory [6]. Euclid gave expression to the g c d 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 g c d 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 g c d 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 x and y be positive real numbers. Considering the fraction y / x , we distinguish two cases, the case where y / x is a rational, and the case where y / x is an irrational. If y / x is a rational, we denote S F ( y / x ) as the unique simplified fraction a / b , with a and b natural numbers and g c d ( a , b ) = 1 , such that

y x = S F ( y / x ) . (1)

The positive real number z is a divisor of x whenever there exists a natural number k fulfilling k z = x . Each time the set of common divisors of x and y is not empty, the greatest common divisor of x and y , g c d ( x , y ) is the maximum z that is a divisor of x and is also a divisor of y . In the case that the set of common divisors of x and y is empty, we say that x and y are incommensurable.

The relation between the previous definitions of S F and g c d , is that when z is the greatest common divisor of x and y , and k z = x , m z = y , we have that m k z = m x , k m z = k y . Consequently,

( m k x = y ) ( k m y = x ) , (2)

and

( m k = S F ( y x ) ) ( k m = S F ( x y ) ) . (3)

The veracity of (3) is a consequence of the simple fact that if g c d ( k , m ) = d and d > 1 , then the g c d ( x , y ) would be equal to z d instead of z .

The previous definition of g c d ( x , y ) for x and y 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 g c d is the cornerstone. The algorithm we present in Section 2 is not only a way to get the solution of the Diophantine equation,

m x + n y = g c d ( x , y ) , (4)

but it also provides a complete arithmetic in x / y , the ring of the residue classes modulo y . The “steady walk” algorithm ( s w a ) described in this paper does not use the Euclidean algorithm for g c d . The proof we give in Section 2 is interesting by itself and uses the following not common formula of tan ( n θ ) as a function of tan ( θ ) , when tan ( θ ) and n 1 ,

tan ( n θ ) = k = 0 ( n 1 ) / 2 ( 1 ) k ( n 2 k + 1 ) tan 2 k + 1 ( θ ) k = 0 n / 2 ( 1 ) k ( n 2 k ) tan 2 k ( θ ) . (5)

The formula (5) can be proven by mathematical induction, using the tangent of the sum of two angles. The integers ( n 1 ) / 2 and n / 2 are the floor function values on ( n 1 ) / 2 and n / 2 respectively. Let

P n ( x ) = k = 0 ( n 1 ) / 2 ( 1 ) k ( n 2 k + 1 ) x 2 k + 1 . (6)

Consequently, in the case that tan ( x ) , the formula (5) implies that

tan ( n x ) = 0 P n ( tan ( x ) ) = 0. (7)

The rest of this article is organized in the following way. Section 2 explains the s w a 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 x and y be positive real numbers, with x < y . The s w a consists in marking, between two “walls”, consecutive steps, with step length equal to x . The walls are at 0 and at y / 2 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,

f : [ 0 , + [ \ { ( k y / 2 ) : k , k > 0 } [ 0 , y / 2 ] ,

defined by: f ( 0 ) = 0 and

f ( t ) = ( t n y / 2 , t ( n y 2 , ( n + 1 ) y 2 ) n is even ( n + 1 ) y / 2 t , t ( n y 2 , ( n + 1 ) y 2 ) n is odd . (8)

Then the mark of the m -step is f ( m x ) .

Theorem 1. If the set

F = { s : ( t , t < s , f ( s x ) = f ( t x ) ) ( f ( s x ) = y / 2 ) } (9)

is not empty and we call k + 1 = min ( F ) , then the following statements are true:

1) The set { f ( m x ) : m [ 0, k ] } is an array of equidistant points.

2) The distance between contiguous points is the g c d ( x , y ) = d .

3) The distance between the maximum of { f ( m x ) : m [ 0, k ] } and y / 2 is equal to d or d / 2 .

4) If b is the number of points that are less than the first step, then b d = x . Additionally, y = ( 2 k + 2 ) d y = ( 2 k + 1 ) d , in correspondence to the disjunction in item 3, respectively.

5) ( 2 k + 2 ) / b = S F ( y / x ) ( 2 k + 1 ) / b = S F ( y / x ) , in correspondence to the above disjunction respectively.

6) If the point id of the array, corresponds to the m i -step, then,

m i b ± i ( mod ( 2 k + 2 ) ) m i b ± i ( mod ( 2 k + 1 ) ) ,

in correspondence to the above disjunction respectively.

Proof. Let us visualize the algorithm in the following way:

Construct a circle of radius equal to y / π . In this way the semicircle has a length equal to y , and the quarter circle is y / 2 long. The steps will go from the point of zero angle, counterclockwise and each step has length x on the circle. If m x is the m -step, the angle in radians of this point is m x π / y . We denote the before angle as x m . There is only one angle, x ˜ m in the first quadrant fulfilling,

tan 2 ( x m ) = tan 2 ( x ˜ m ) . (10)

Simple observation shows that the steps x ˜ m map on the steps f ( m x ) under the natural bijection between the segment [ 0 , y / 2 ] and the first quarter circle. In the case that there exists t , t < s , with f ( s x ) = f ( t x ) , we have that x ˜ s = x ˜ t and consequently,

( s x π / y = ± t x π / y + m π , m ) (11)

( s x = ± t x + m y , m ) (12)

( s t m x = y , m ) . (13)

The last equality (13) is a consequence of ( s t 0 m 0 ) . Hence, we can suppose that there exist a and b , fulfilling

a b x = y , with a , b and g c d ( a , b ) = 1. (14)

The case f ( s x ) = y / 2 is equivalent to

s x = 2 k y + y / 2 , k . (15)

Similarly, we conclude that there exist a and b , fulfilling,

a b x = y , with a , b and g c d ( a , b ) = 1. (16)

From (16), we obtain

tan ( a n x b ) = tan ( a n x b ) = tan ( n π ) = 0, n . (17)

Let A = { 1,2, , ( a 1 ) / 2 } . It is easy to verify that,

1) n A ( tan ( ( n x / b ) ) 0 tan ( ( n x / b ) ) ) ,

2) ( n , m A n m ) tan 2 ( ( n x / b ) ) tan 2 ( ( m x / b ) ) ,

and,

P a ( tan ( ( n x / b ) ) ) = 0, n A . (18)

The set of equalities (18) can be written as

k = 0 ( a 1 ) / 2 ( 1 ) k ( a 2 k + 1 ) ( tan ( ( n x / b ) ) ) 2 k + 1 = 0 , n A . (19)

Dividing each equation by tan ( ( n x / b ) ) 0 , we get

k = 0 ( a 1 ) / 2 ( 1 ) k ( a 2 k + 1 ) ( tan 2 ( ( n x / b ) ) ) k = 0. (20)

Denoting x k = ( 1 ) k ( a 2 k + 1 ) , we have,

k = 0 ( a 1 ) / 2 ( tan 2 ( ( n x / b ) ) ) k x k = 0 , n A . (21)

We can interpret the set of equalities (21) as a system of linear equations with unknown variables { x k } . This is a system where the number of variables exceeds by one the number of equations.

We now observe that, if for some m A we have

tan ( ( m x ) ) 0 tan ( ( m x ) ) (22)

and

tan 2 ( ( m x ) ) tan 2 ( ( n x / b ) ) , for all n A , (23)

we also have

P a ( tan ( m x ) ) = tan ( a ( m x ) ) = tan ( ( a m x ) ) = tan ( b m π ) = 0. (24)

Then, we would have the square system,

k = 0 ( a 1 ) / 2 ( tan 2 ( ( n x / b ) ) ) k x k = 0 , n A , (25)

k = 0 ( a 1 ) / 2 ( tan 2 ( ( m x ) ) ) k x k = 0 , (26)

whose determinant is equal to a non-null Vandermonde determinant. This is a contradiction due to the existence of the non-null solution { x k } .

Let us examine what is failing. Checking (22),

( tan ( ( m x ) ) = 0 tan ( ( m x ) ) = ) m x = k y / 2 , k (27)

2 m b = k a , k .

The last equality in (27) implies that a divides 2 m . This is impossible because m A . Hence, the only possibility is that (23) fails. In other words, for each m A , there exist n A fulfilling,

tan 2 ( ( m x ) ) = tan 2 ( ( n x / b ) ) . (28)

Also, it is easy to check that the values { tan 2 ( ( m x ) ) / m A } are different,

tan 2 ( ( m x ) ) = tan 2 ( ( m 1 x ) ) m x = ± m 1 x + k y (29)

b ( m m 1 ) = k a .

From (29), we have that m m 1 = 0 , which clearly implies m = m 1 . Therefore, by the Pigeonhole Principle, there exists a bijective function f such that

f : A A (30)

n m n ,

is defined by the property,

tan 2 ( ( m n x ) ) = tan 2 ( ( n x / b ) ) . (31)

Now, we observe that,

k = Cardinality ( A ) = a 1 2 = ( ( a 2 ) / 2 with a even ( a 1 ) / 2 with a odd , (32)

and d = x / b , so the first five points of the theorem are straightforward. Recapitulating,

1) The set { f ( m x ) : m [ 0, k ] } corresponds to the set of steps in the first quadrant { x ˜ m } , and this last set corresponds to the angles { ( n x / b ) : n A } .

2) d = x / b is the arc length between contiguous points of the array. Furthermore,

a ( x b ) = y b ( x b ) = x . (33)

3) When a is even, the maximum of the array of steps is

( a 2 2 ) ( x b ) = ( 1 2 ) ( a b ) x d = ( y 2 ) d . (34)

And when a is odd, the maximum is

( a 1 2 ) ( x b ) = ( 1 2 ) ( a b ) x d 2 = ( y 2 ) d 2 . (35)

4) The equality b d = x is a consequence of item 2. Additionally, when a is even,

( a 2 2 ) = k , (36)

and y = a d = ( 2 k + 2 ) d . When a is odd,

( a 1 2 ) = k , (37)

and y = a d = ( 2 k + 1 ) d .

5) In the case a is even,

a b = 2 k + 2 b = S F ( y / x ) . (38)

And when a is odd,

a b = 2 k + 1 b = S F ( y / x ) . (39)

Finally, let us prove item 6,

tan 2 ( ( m i x ) ) = tan 2 ( ( i x / b ) ) (40)

m i x = ± ( i x / b ) + m y , m (41)

m i b y a i y a = m y , m (42)

m i b i = m a , m . (43)

The previous sequence of implications (40)-(43) finishes the proof of the theorem. □

Note that the equality (43) is equivalent to

m i x i x b = m y , m , (44)

and this last equality (44) justifies that the s w a provides a complete arithmetic in x / y , 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 [ 0 , y / 2 ] 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 N .

Algorithm 1. Steady walk algorithm.

Example 1: The steady walk algorithm ( s w a ) for two integers, x = 143 and y = 847 , with N = 200 iterations. As seen in Figure 1, the algorithm stops at the iteration (847/2)/11. In this case the Euclidean algorithm for g c d only needs two divisions and the s w a obtains two footprints, 286 and 275, with difference equal to the g c d after two sums and two differences.

Figure 1. Output of s w a for x = 143 and y = 847 . The plot shows the steps P [ n ] vs. the iteration number n . The table lists the numerical values of all points.

Figure 1. Output of s w a for x = 143 and y = 847 . The plot shows the steps P [ n ] vs. the iteration number n . The table lists the numerical values of all points.

Example 2: The s w a for the numbers x = 1 and the irrational y = π , with N = 55 iterations. These two numbers x and y are incommensurable. We choose this particular number of iterations N so that it shows interesting regular patterns (see Figure 2).

Figure 2. Output of s w a for x = 1 and y = π . The plot shows the steps P [ n ] vs. the iteration number n . The table lists the numerical values of all points.

Example 3: Figure 3 shows the s w a for two irrational numbers, x = 2 and y = e , with N = 200 iterations.

Figure 3. Output of s w a for x = 2 and y = e . The plot shows the steps P [ n ] 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 a , of residue classes modulo a . 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 y / 2 , instead of y , is already a clear improvement. The last aspect we would like to mention is the study of irrationality. The distribution of footprints in [ 0 , y / 2 ] , 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, s w a is conceptually easier than the extended and classic Euclidean algorithms, allowing many shortcuts that improve its efficiency.

Cite this paper: Rodriguez, C. , Cruz, M. and Falcon, C. (2021) Full Euclidean Algorithm by Means of a Steady Walk. Applied Mathematics, 12, 269-279. doi: 10.4236/am.2021.124018.
References

[1]   Lehmer, D.H. (1938) Euclid’s Algorithm for Large Numbers. The American Mathematical Monthly, 45, 227-233.
https://doi.org/10.1080/00029890.1938.11990797

[2]   Durand, A. (1998) Efficient Ways to Implement Elliptic Curve Exponentiation on a Smart Card. International Conference on Smart Card Research and Advanced Applications, Springer, Berlin, 357-365.
https://doi.org/10.1007/10721064_33

[3]   Mordell, L.J. (1969) Diophantine Equations. Academic Press, London, New York.

[4]   Childs, L.N. (2009) A Concrete Introduction to Higher Algebra. ch. The Chinese Remainder Theorem. Springer-Verlag, New York, 253-281.
https://doi.org/10.1007/978-0-387-74725-5

[5]   Khinchin, A.Y. (1997) Continued Fractions, Russian ed. Dover Publications, New York.

[6]   Lamé, G. (1844) Note sur la limite du nombre des divisions dans la recherche du plus grand commun diviseur entre deux nombres entiers. Comptes Rendus Acad. Sci., Paris.

[7]   Heiberg, J.L. (2007) Euclid’s Elements. Richard Fitzpatrick, TX, USA.

[8]   Nikolic, M. (1974) The Relation between Eudoxus’ Theory of Proportions and Dedekind’s Theory of Cuts. In: Cohen, R.S., Stachel, J.J. and Wartofsky, M.W., Eds., For Dirk Struik, Springer, Dordrecht, 225-243.
https://doi.org/10.1007/978-94-010-2115-9_19

[9]   Knuth, D.E. (2014) Art of Computer Programming, Volume 2: Seminumerical Algorithms. Addison-Wesley Professional, Boston.

[10]   Ramachandran, P. (2006) Use of Extended Euclidean Algorithm in Solving a System of Linear Diophantine Equations with Bounded Variables. In: Hess, F., Pauli, S. and Pohst, M., Eds., Algorithmic Number Theory. ANTS 2006. Lecture Notes in Computer Science, Vol 4076. Springer, Berlin, Heidelberg, 182-192.
https://doi.org/10.1007/11792086_14

[11]   Rankin, S. (2013) The Euclidean Algorithm and the Linear Diophantine Equation ax + by = gcd (a,b). The American Mathematical Monthly, 120, 562-564.
https://doi.org/10.4169/amer.math.monthly.120.06.562

[12]   Iliev, A. and Kyurkchiev, N. (2018) The Faster Euclidean Algorithm. Collection of Scientific Works from Conference, Pamporovo, Bulgaria, 28-30.

[13]   Niven, I. (1956) Irrational Numbers. (Carus Mathematical Monographs, Series Number 11). John Wiley and Sons, Inc., New York.
https://doi.org/10.5948/9781614440116

 
 
Top