Euclidean algorithm explained

In mathematics, the Euclidean algorithm,[1] or Euclid's algorithm, is an efficient method for computing the greatest common divisor (GCD) of two integers (numbers), the largest number that divides them both without a remainder. It is named after the ancient Greek mathematician Euclid, who first described it in his Elements .It is an example of an algorithm, a step-by-step procedure for performing a calculation according to well-defined rules,and is one of the oldest algorithms in common use. It can be used to reduce fractions to their simplest form, and is a part of many other number-theoretic and cryptographic calculations.

The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. For example, 21 is the GCD of 252 and 105 (as and, and the same number 21 is also the GCD of 105 and . Since this replacement reduces the larger of the two numbers, repeating this process gives successively smaller pairs of numbers until the two numbers become equal. When that occurs, that number is the GCD of the original two numbers. By reversing the steps or using the extended Euclidean algorithm, the GCD can be expressed as a linear combination of the two original numbers, that is the sum of the two numbers, each multiplied by an integer (for example,). The fact that the GCD can always be expressed in this way is known as Bézout's identity.

The version of the Euclidean algorithm described above—which follows Euclid's original presentation—can take many subtraction steps to find the GCD when one of the given numbers is much bigger than the other. A more efficient version of the algorithm shortcuts these steps, instead replacing the larger of the two numbers by its remainder when divided by the smaller of the two (with this version, the algorithm stops when reaching a zero remainder). With this improvement, the algorithm never requires more steps than five times the number of digits (base 10) of the smaller integer. This was proven by Gabriel Lamé in 1844 (Lamé's Theorem),[2] [3] and marks the beginning of computational complexity theory. Additional methods for improving the algorithm's efficiency were developed in the 20th century.

The Euclidean algorithm has many theoretical and practical applications. It is used for reducing fractions to their simplest form and for performing division in modular arithmetic. Computations using this algorithm form part of the cryptographic protocols that are used to secure internet communications, and in methods for breaking these cryptosystems by factoring large composite numbers. The Euclidean algorithm may be used to solve Diophantine equations, such as finding numbers that satisfy multiple congruences according to the Chinese remainder theorem, to construct continued fractions, and to find accurate rational approximations to real numbers. Finally, it can be used as a basic tool for proving theorems in number theory such as Lagrange's four-square theorem and the uniqueness of prime factorizations.

The original algorithm was described only for natural numbers and geometric lengths (real numbers), but the algorithm was generalized in the 19th century to other types of numbers, such as Gaussian integers and polynomials of one variable. This led to modern abstract algebraic notions such as Euclidean domains.

Background: greatest common divisor

See main article: Greatest common divisor.

The Euclidean algorithm calculates the greatest common divisor (GCD) of two natural numbers and . The greatest common divisor is the largest natural number that divides both and without leaving a remainder. Synonyms for GCD include greatest common factor (GCF), highest common factor (HCF), highest common divisor (HCD), and greatest common measure (GCM). The greatest common divisor is often written as or, more simply, as, although the latter notation is ambiguous, also used for concepts such as an ideal in the ring of integers, which is closely related to GCD.

If, then and are said to be coprime (or relatively prime). This property does not imply that or are themselves prime numbers. For example, 6 and 35 factor as 6 = 2 × 3 and 35 = 5 × 7, so they are not prime, but their prime factors are different, so 6 and 35 are coprime, with no common factors other than 1.

Let . Since and are both multiples of, they can be written and, and there is no larger number for which this is true. The natural numbers and must be coprime, since any common factor could be factored out of and to make greater. Thus, any other number that divides both and must also divide . The greatest common divisor of and is the unique (positive) common divisor of and that is divisible by any other common divisor .

The greatest common divisor can be visualized as follows.[4] Consider a rectangular area by, and any common divisor that divides both and exactly. The sides of the rectangle can be divided into segments of length, which divides the rectangle into a grid of squares of side length . The GCD is the largest value of for which this is possible. For illustration, a rectangular area can be divided into a grid of: squares, squares, squares, squares, squares or squares. Therefore, is the GCD of and . A rectangular area can be divided into a grid of squares, with two squares along one edge and five squares along the other .

The greatest common divisor of two numbers and is the product of the prime factors shared by the two numbers, where each prime factor can be repeated as many times as it divides both and . For example, since can be factored into, and can be factored into, the GCD of and equals, the product of their shared prime factors (with 3 repeated since divides both). If two numbers have no common prime factors, their GCD is (obtained here as an instance of the empty product); in other words, they are coprime. A key advantage of the Euclidean algorithm is that it can find the GCD efficiently without having to compute the prime factors.[5] Factorization of large integers is believed to be a computationally very difficult problem, and the security of many widely used cryptographic protocols is based upon its infeasibility.

Another definition of the GCD is helpful in advanced mathematics, particularly ring theory. The greatest common divisor of two nonzero numbers and is also their smallest positive integral linear combination, that is, the smallest positive number of the form where and are integers. The set of all integral linear combinations of and is actually the same as the set of all multiples of (where is an integer). In modern mathematical language, the ideal generated by and is the ideal generated by  alone (an ideal generated by a single element is called a principal ideal, and all ideals of the integers are principal ideals). Some properties of the GCD are in fact easier to see with this description, for instance the fact that any common divisor of and also divides the GCD (it divides both terms of). The equivalence of this GCD definition with the other definitions is described below.

The GCD of three or more numbers equals the product of the prime factors common to all the numbers, but it can also be calculated by repeatedly taking the GCDs of pairs of numbers. For example,

Thus, Euclid's algorithm, which computes the GCD of two integers, suffices to calculate the GCD of arbitrarily many integers.

Description

Procedure

The Euclidean algorithm can be thought of as constructing a sequence of non-negative integers that begins with the two given integers

r-2=a

and

r-1=b

and will eventually terminate with the integer zero:

\{r-2=a,r-1=b,r0,r1,  … ,rn-1,rn=0\}

with

rk+1<rk

. The integer

rn-1

will then be the GCD and we can state

gcd(a,b)=rn-1

. The algorithm indicates how to construct the intermediate remainders

rk

via division-with-remainder on the preceding pair

(rk-2,rk-1)

by finding an integer quotient

qk

so that:

rk-2=qkrk-1+rk,withrk-1>rk\geq0.

Because the sequence of non-negative integers

\{rk\}

is strictly decreasing, it eventually must terminate. In other words, since

rk\ge0

for every

k

, and each

rk

is an integer that is strictly smaller than the preceding

rk-1

, there eventually cannot be a non-negative integer smaller than zero, and hence the algorithm must terminate. In fact, the algorithm will always terminate at the n-th step with

rn

equal to zero.

To illustrate, suppose the GCD of 1071 and 462 is requested. The sequence is initially

\{r-2=1071,r-1=462\}

and in order to find

r0

, we need to find integers

q0

and

r0<r-1

such that:

1071=q0462+r0

.

This is the quotient

q0=2

since

1071=2462+147

. This determines

r0=147

and so the sequence is now

\{1071, 462,r0=147\}

. The next step is to continue the sequence to find

r1

by finding integers

q1

and

r1<r0

such that:

462=q1147+r1

.

This is the quotient

q1=3

since

462=3147+21

. This determines

r1=21

and so the sequence is now

\{1071, 462, 147,r1=21\}

. The next step is to continue the sequence to find

r2

by finding integers

q2

and

r2<r1

such that:

147=q221+r2

.

This is the quotient

q2=7

since

147=721+0

. This determines

r2=0

and so the sequence is completed as

\{1071, 462, 147, 21,r2=0\}

as no further non-negative integer smaller than

0

can be found. The penultimate remainder

21

is therefore the requested GCD:

gcd(1071, 462)=21.

We can generalize slightly by dropping any ordering requirement on the initial two values

a

and

b

. If

a=b

, the algorithm may continue and trivially find that

gcd(a,a)=a

as the sequence of remainders will be

\{a,a, 0\}

. If

a<b

, then we can also continue since

a\equiv0b+a

, suggesting the next remainder should be

a

itself, and the sequence is

\{a,b,a,  … \}

. Normally, this would be invalid because it breaks the requirement

r0<r-1

but now we have

a<b

by construction, so the requirement is automatically satisfied and the Euclidean algorithm can continue as normal. Therefore, dropping any ordering between the first two integers does not affect the conclusion that the sequence must eventually terminate because the next remainder will always satisfy

r0<b

and everything continues as above. The only modifications that need to be made are that

rk<rk-1

only for

k\ge0

, and that the sub-sequence of non-negative integers

\{rk-1\}

for

k\ge0

is strictly decreasing, therefore excluding

a=r-2

from both statements.

Proof of validity

The validity of the Euclidean algorithm can be proven by a two-step argument. In the first step, the final nonzero remainder rN−1 is shown to divide both a and b. Since it is a common divisor, it must be less than or equal to the greatest common divisor g. In the second step, it is shown that any common divisor of a and b, including g, must divide rN−1; therefore, g must be less than or equal to rN−1. These two opposite inequalities imply rN−1 = g.

To demonstrate that rN−1 divides both a and b (the first step), rN−1 divides its predecessor rN−2

since the final remainder rN is zero. rN−1 also divides its next predecessor rN−3

because it divides both terms on the right-hand side of the equation. Iterating the same argument, rN−1 divides all the preceding remainders, including a and b. None of the preceding remainders rN−2, rN−3, etc. divide a and b, since they leave a remainder. Since rN−1 is a common divisor of a and b, rN−1 ≤ g.

In the second step, any natural number c that divides both a and b (in other words, any common divisor of a and b) divides the remainders rk. By definition, a and b can be written as multiples of c : a = mc and b = nc, where m and n are natural numbers. Therefore, c divides the initial remainder r0, since r0 = a − q0b = mc − q0nc = (m − q0n)c. An analogous argument shows that c also divides the subsequent remainders r1, r2, etc. Therefore, the greatest common divisor g must divide rN−1, which implies that g ≤ rN−1. Since the first part of the argument showed the reverse (rN−1 ≤ g), it follows that g = rN−1. Thus, g is the greatest common divisor of all the succeeding pairs:[6]

Worked example

For illustration, the Euclidean algorithm can be used to find the greatest common divisor of a = 1071 and b = 462. To begin, multiples of 462 are subtracted from 1071 until the remainder is less than 462. Two such multiples can be subtracted (q0 = 2), leaving a remainder of 147:

Then multiples of 147 are subtracted from 462 until the remainder is less than 147. Three multiples can be subtracted (q1 = 3), leaving a remainder of 21:

Then multiples of 21 are subtracted from 147 until the remainder is less than 21. Seven multiples can be subtracted (q2 = 7), leaving no remainder:

Since the last remainder is zero, the algorithm ends with 21 as the greatest common divisor of 1071 and 462. This agrees with the gcd(1071, 462) found by prime factorization above. In tabular form, the steps are:

Step kEquationQuotient and remainder
0 and
1 and
2 and ; algorithm ends

Visualization

The Euclidean algorithm can be visualized in terms of the tiling analogy given above for the greatest common divisor.[7] Assume that we wish to cover an a×b rectangle with square tiles exactly, where a is the larger of the two numbers. We first attempt to tile the rectangle using b×b square tiles; however, this leaves an r0×b residual rectangle untiled, where r0 < b. We then attempt to tile the residual rectangle with r0×r0 square tiles. This leaves a second residual rectangle r1×r0, which we attempt to tile using r1×r1 square tiles, and so on. The sequence ends when there is no residual rectangle, i.e., when the square tiles cover the previous residual rectangle exactly. The length of the sides of the smallest square tile is the GCD of the dimensions of the original rectangle. For example, the smallest square tile in the adjacent figure is 21×21 (shown in red), and 21 is the GCD of 1071 and 462, the dimensions of the original rectangle (shown in green).

Euclidean division

See main article: Euclidean division.

At every step k, the Euclidean algorithm computes a quotient qk and remainder rk from two numbers rk−1 and rk−2

where the rk is non-negative and is strictly less than the absolute value of rk−1. The theorem which underlies the definition of the Euclidean division ensures that such a quotient and remainder always exist and are unique.[8]

In Euclid's original version of the algorithm, the quotient and remainder are found by repeated subtraction; that is, rk−1 is subtracted from rk−2 repeatedly until the remainder rk is smaller than rk−1. After that rk and rk−1 are exchanged and the process is iterated. Euclidean division reduces all the steps between two exchanges into a single step, which is thus more efficient. Moreover, the quotients are not needed, thus one may replace Euclidean division by the modulo operation, which gives only the remainder. Thus the iteration of the Euclidean algorithm becomes simply

Implementations

Implementations of the algorithm may be expressed in pseudocode. For example, the division-based version may be programmed as

function gcd(a, b) while b ≠ 0 t := b b := a mod b a := t return a

At the beginning of the kth iteration, the variable b holds the latest remainder rk−1, whereas the variable a holds its predecessor, rk−2. The step b := a mod b is equivalent to the above recursion formula rkrk−2 mod rk−1. The temporary variable t holds the value of rk−1 while the next remainder rk is being calculated. At the end of the loop iteration, the variable b holds the remainder rk, whereas the variable a holds its predecessor, rk−1.

(If negative inputs are allowed, or if the mod function may return negative values, the last line must be changed into return abs(a).)

In the subtraction-based version, which was Euclid's original version, the remainder calculation (b&nbsp;:=&nbsp;a '''mod''' b) is replaced by repeated subtraction. Contrary to the division-based version, which works with arbitrary integers as input, the subtraction-based version supposes that the input consists of positive integers and stops when a = b:

function gcd(a, b) while a ≠ b if a > b a := a − b else b := b − a return a

The variables a and b alternate holding the previous remainders rk−1 and rk−2. Assume that a is larger than b at the beginning of an iteration; then a equals rk−2, since rk−2 > rk−1. During the loop iteration, a is reduced by multiples of the previous remainder b until a is smaller than b. Then a is the next remainder rk. Then b is reduced by multiples of a until it is again smaller than a, giving the next remainder rk+1, and so on.

The recursive version is based on the equality of the GCDs of successive remainders and the stopping condition gcd(rN−1, 0) = rN−1.

function gcd(a, b) if b = 0 return a else return gcd(b, a mod b)

(As above, if negative inputs are allowed, or if the mod function may return negative values, the instruction "return a" must be changed into "return max(a, −a)".)

For illustration, the gcd(1071, 462) is calculated from the equivalent gcd(462, 1071 mod 462) = gcd(462, 147). The latter GCD is calculated from the gcd(147, 462 mod 147) = gcd(147, 21), which in turn is calculated from the gcd(21, 147 mod 21) = gcd(21, 0) = 21.

Method of least absolute remainders

In another version of Euclid's algorithm, the quotient at each step is increased by one if the resulting negative remainder is smaller in magnitude than the typical positive remainder.[9] Previously, the equation

assumed that . However, an alternative negative remainder can be computed:

if or

if .

If is replaced by when, then one gets a variant of Euclidean algorithm such that

at each step.

Leopold Kronecker has shown that this version requires the fewest steps of any version of Euclid's algorithm. More generally, it has been proven that, for every input numbers a and b, the number of steps is minimal if and only if is chosen in order that

\left|

rk+1
rk

\right|<

1
\varphi

\sim0.618,

where

\varphi

is the golden ratio.[10]

Historical development

The Euclidean algorithm is one of the oldest algorithms in common use.[11] It appears in Euclid's Elements (c. 300 BC), specifically in Book 7 (Propositions 1–2) and Book 10 (Propositions 2–3). In Book 7, the algorithm is formulated for integers, whereas in Book 10, it is formulated for lengths of line segments. (In modern usage, one would say it was formulated there for real numbers. But lengths, areas, and volumes, represented as real numbers in modern usage, are not measured in the same units and there is no natural unit of length, area, or volume; the concept of real numbers was unknown at that time.) The latter algorithm is geometrical. The GCD of two lengths a and b corresponds to the greatest length g that measures a and b evenly; in other words, the lengths a and b are both integer multiples of the length g.

The algorithm was probably not discovered by Euclid, who compiled results from earlier mathematicians in his Elements.[12] [13] The mathematician and historian B. L. van der Waerden suggests that Book VII derives from a textbook on number theory written by mathematicians in the school of Pythagoras.[14] The algorithm was probably known by Eudoxus of Cnidus (about 375 BC).[11] [15] The algorithm may even pre-date Eudoxus,[16] [17] judging from the use of the technical term ἀνθυφαίρεσις (anthyphairesis, reciprocal subtraction) in works by Euclid and Aristotle.[18]

Centuries later, Euclid's algorithm was discovered independently both in India and in China, primarily to solve Diophantine equations that arose in astronomy and making accurate calendars. In the late 5th century, the Indian mathematician and astronomer Aryabhata described the algorithm as the "pulverizer", perhaps because of its effectiveness in solving Diophantine equations. Although a special case of the Chinese remainder theorem had already been described in the Chinese book Sunzi Suanjing, the general solution was published by Qin Jiushao in his 1247 book Shushu Jiuzhang (數書九章 Mathematical Treatise in Nine Sections). The Euclidean algorithm was first described numerically and popularized in Europe in the second edition of Bachet's Problèmes plaisants et délectables (Pleasant and enjoyable problems, 1624). In Europe, it was likewise used to solve Diophantine equations and in developing continued fractions. The extended Euclidean algorithm was published by the English mathematician Nicholas Saunderson,[19] who attributed it to Roger Cotes as a method for computing continued fractions efficiently.

In the 19th century, the Euclidean algorithm led to the development of new number systems, such as Gaussian integers and Eisenstein integers. In 1815, Carl Gauss used the Euclidean algorithm to demonstrate unique factorization of Gaussian integers, although his work was first published in 1832. Gauss mentioned the algorithm in his Disquisitiones Arithmeticae (published 1801), but only as a method for continued fractions. Peter Gustav Lejeune Dirichlet seems to have been the first to describe the Euclidean algorithm as the basis for much of number theory. Lejeune Dirichlet noted that many results of number theory, such as unique factorization, would hold true for any other system of numbers to which the Euclidean algorithm could be applied. Lejeune Dirichlet's lectures on number theory were edited and extended by Richard Dedekind, who used Euclid's algorithm to study algebraic integers, a new general type of number. For example, Dedekind was the first to prove Fermat's two-square theorem using the unique factorization of Gaussian integers.[20] Dedekind also defined the concept of a Euclidean domain, a number system in which a generalized version of the Euclidean algorithm can be defined (as described below). In the closing decades of the 19th century, the Euclidean algorithm gradually became eclipsed by Dedekind's more general theory of ideals.

"[The Euclidean algorithm] is the granddaddy of all algorithms, because it is the oldest nontrivial algorithm that has survived to the present day."
Donald Knuth, The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 2nd edition (1981), p. 318.

Other applications of Euclid's algorithm were developed in the 19th century. In 1829, Charles Sturm showed that the algorithm was useful in the Sturm chain method for counting the real roots of polynomials in any given interval.[21]

The Euclidean algorithm was the first integer relation algorithm, which is a method for finding integer relations between commensurate real numbers. Several novel integer relation algorithms have been developed, such as the algorithm of Helaman Ferguson and R.W. Forcade (1979)[22] and the LLL algorithm.[23] [24]

In 1969, Cole and Davie developed a two-player game based on the Euclidean algorithm, called The Game of Euclid,[25] which has an optimal strategy.[26] The players begin with two piles of a and b stones. The players take turns removing m multiples of the smaller pile from the larger. Thus, if the two piles consist of x and y stones, where x is larger than y, the next player can reduce the larger pile from x stones to xmy stones, as long as the latter is a nonnegative integer. The winner is the first player to reduce one pile to zero stones.[27]

Mathematical applications

Bézout's identity

See main article: Bézout's identity. Bézout's identity states that the greatest common divisor g of two integers a and b can be represented as a linear sum of the original two numbers a and b.[28] In other words, it is always possible to find integers s and t such that g = sa + tb.

The integers s and t can be calculated from the quotients q0, q1, etc. by reversing the order of equations in Euclid's algorithm. Beginning with the next-to-last equation, g can be expressed in terms of the quotient qN−1 and the two preceding remainders, rN−2 and rN−3:

Those two remainders can be likewise expressed in terms of their quotients and preceding remainders,

and

Substituting these formulae for rN−2 and rN−3 into the first equation yields g as a linear sum of the remainders rN−4 and rN−5. The process of substituting remainders by formulae involving their predecessors can be continued until the original numbers a and b are reached:

After all the remainders r0, r1, etc. have been substituted, the final equation expresses g as a linear sum of a and b, so that g = sa + tb.

The Euclidean algorithm, and thus Bezout's identity, can be generalized to the context of Euclidean domains.

Principal ideals and related problems

Bézout's identity provides yet another definition of the greatest common divisor g of two numbers a and b. Consider the set of all numbers ua + vb, where u and v are any two integers. Since a and b are both divisible by g, every number in the set is divisible by g. In other words, every number of the set is an integer multiple of g. This is true for every common divisor of a and b. However, unlike other common divisors, the greatest common divisor is a member of the set; by Bézout's identity, choosing u = s and v = t gives g. A smaller common divisor cannot be a member of the set, since every member of the set must be divisible by g. Conversely, any multiple m of g can be obtained by choosing u = ms and v = mt, where s and t are the integers of Bézout's identity. This may be seen by multiplying Bézout's identity by m,

Therefore, the set of all numbers ua + vb is equivalent to the set of multiples m of g. In other words, the set of all possible sums of integer multiples of two numbers (a and b) is equivalent to the set of multiples of gcd(a, b). The GCD is said to be the generator of the ideal of a and b. This GCD definition led to the modern abstract algebraic concepts of a principal ideal (an ideal generated by a single element) and a principal ideal domain (a domain in which every ideal is a principal ideal).

Certain problems can be solved using this result. For example, consider two measuring cups of volume a and b. By adding/subtracting u multiples of the first cup and v multiples of the second cup, any volume ua + vb can be measured out. These volumes are all multiples of g = gcd(ab).

Extended Euclidean algorithm

See main article: Extended Euclidean algorithm.

The integers s and t of Bézout's identity can be computed efficiently using the extended Euclidean algorithm. This extension adds two recursive equations to Euclid's algorithm

with the starting values

Using this recursion, Bézout's integers s and t are given by s = sN and t = tN, where N+1 is the step on which the algorithm terminates with rN+1 = 0.

The validity of this approach can be shown by induction. Assume that the recursion formula is correct up to step k − 1 of the algorithm; in other words, assume that

for all j less than k. The kth step of the algorithm gives the equation

Since the recursion formula has been assumed to be correct for rk−2 and rk−1, they may be expressed in terms of the corresponding s and t variables

Rearranging this equation yields the recursion formula for step k, as required

Matrix method

The integers s and t can also be found using an equivalent matrix method.[29] The sequence of equations of Euclid's algorithm

\begin{align} a&=q0b+r0\\ b&=q1r0+r1\\ &\vdots\\ rN-2&=qNrN-1+0 \end{align}

can be written as a product of 2×2 quotient matrices multiplying a two-dimensional remainder vector

\begin{pmatrix}a\b\end{pmatrix}= \begin{pmatrix}q0&1\ 1&0\end{pmatrix}\begin{pmatrix}b\r0\end{pmatrix}= \begin{pmatrix}q0&1\ 1&0\end{pmatrix}\begin{pmatrix}q1&1\ 1&0\end{pmatrix}\begin{pmatrix}r0\r1\end{pmatrix}=

N
= \prod
i=0

\begin{pmatrix}qi&1\ 1&0\end{pmatrix}\begin{pmatrix}rN-1\ 0\end{pmatrix}.

Let M represent the product of all the quotient matrices

M=\begin{pmatrix}m11&m12\m21&m22\end{pmatrix}

N
= \prod
i=0

\begin{pmatrix}qi&1\ 1&0\end{pmatrix}= \begin{pmatrix}q0&1\ 1&0\end{pmatrix}\begin{pmatrix}q1&1\ 1&0\end{pmatrix}\begin{pmatrix}qN&1\ 1&0\end{pmatrix}.

This simplifies the Euclidean algorithm to the form

\begin{pmatrix}a\b\end{pmatrix}= M\begin{pmatrix}rN-1\ 0\end{pmatrix}= M\begin{pmatrix}g\ 0\end{pmatrix}.

To express g as a linear sum of a and b, both sides of this equation can be multiplied by the inverse of the matrix M.[30] The determinant of M equals (−1)N+1, since it equals the product of the determinants of the quotient matrices, each of which is negative one. Since the determinant of M is never zero, the vector of the final remainders can be solved using the inverse of M

\begin{pmatrix}g\ 0\end{pmatrix}= M-1\begin{pmatrix}a\b\end{pmatrix}= (-1)N+1\begin{pmatrix}m22&-m12\ -m21&m11\end{pmatrix}\begin{pmatrix}a\b\end{pmatrix}.

Since the top equation gives

the two integers of Bézout's identity are s = (−1)N+1m22 and t = (−1)Nm12. The matrix method is as efficient as the equivalent recursion, with two multiplications and two additions per step of the Euclidean algorithm.

Euclid's lemma and unique factorization

Bézout's identity is essential to many applications of Euclid's algorithm, such as demonstrating the unique factorization of numbers into prime factors. To illustrate this, suppose that a number L can be written as a product of two factors u and v, that is, L = uv. If another number w also divides L but is coprime with u, then w must divide v, by the following argument: If the greatest common divisor of u and w is 1, then integers s and t can be found such that

by Bézout's identity. Multiplying both sides by v gives the relation:

Since w divides both terms on the right-hand side, it must also divide the left-hand side, v. This result is known as Euclid's lemma. Specifically, if a prime number divides L, then it must divide at least one factor of L. Conversely, if a number w is coprime to each of a series of numbers a1, a2, ..., an, then w is also coprime to their product, a1 × a2 × ... × an.

Euclid's lemma suffices to prove that every number has a unique factorization into prime numbers. To see this, assume the contrary, that there are two independent factorizations of L into m and n prime factors, respectively

Since each prime p divides L by assumption, it must also divide one of the q factors; since each q is prime as well, it must be that p = q. Iteratively dividing by the p factors shows that each p has an equal counterpart q; the two prime factorizations are identical except for their order. The unique factorization of numbers into primes has many applications in mathematical proofs, as shown below.

Linear Diophantine equations

Diophantine equations are equations in which the solutions are restricted to integers; they are named after the 3rd-century Alexandrian mathematician Diophantus. A typical linear Diophantine equation seeks integers x and y such that

where a, b and c are given integers. This can be written as an equation for x in modular arithmetic:

Let g be the greatest common divisor of a and b. Both terms in ax + by are divisible by g; therefore, c must also be divisible by g, or the equation has no solutions. By dividing both sides by c/g, the equation can be reduced to Bezout's identity

where s and t can be found by the extended Euclidean algorithm. This provides one solution to the Diophantine equation, x1 = s (c/g) and y1 = t (c/g).

In general, a linear Diophantine equation has no solutions, or an infinite number of solutions. To find the latter, consider two solutions, (x1y1) and (x2y2), where

or equivalently

Therefore, the smallest difference between two x solutions is b/g, whereas the smallest difference between two y solutions is a/g. Thus, the solutions may be expressed as

.

By allowing u to vary over all possible integers, an infinite family of solutions can be generated from a single solution (x1y1). If the solutions are required to be positive integers (x > 0, y > 0), only a finite number of solutions may be possible. This restriction on the acceptable solutions allows some systems of Diophantine equations with more unknowns than equations to have a finite number of solutions; this is impossible for a system of linear equations when the solutions can be any real number (see Underdetermined system).

Multiplicative inverses and the RSA algorithm

A finite field is a set of numbers with four generalized operations. The operations are called addition, subtraction, multiplication and division and have their usual properties, such as commutativity, associativity and distributivity. An example of a finite field is the set of 13 numbers using modular arithmetic. In this field, the results of any mathematical operation (addition, subtraction, multiplication, or division) is reduced modulo 13; that is, multiples of 13 are added or subtracted until the result is brought within the range 0–12. For example, the result of 5 × 7 = 35 mod 13 = 9. Such finite fields can be defined for any prime p; using more sophisticated definitions, they can also be defined for any power m of a prime p m. Finite fields are often called Galois fields, and are abbreviated as GF(p) or GF(p m).

In such a field with m numbers, every nonzero element a has a unique modular multiplicative inverse, a−1 such that This inverse can be found by solving the congruence equation ax ≡ 1 mod m, or the equivalent linear Diophantine equation

This equation can be solved by the Euclidean algorithm, as described above. Finding multiplicative inverses is an essential step in the RSA algorithm, which is widely used in electronic commerce; specifically, the equation determines the integer used to decrypt the message. Although the RSA algorithm uses rings rather than fields, the Euclidean algorithm can still be used to find a multiplicative inverse where one exists. The Euclidean algorithm also has other applications in error-correcting codes; for example, it can be used as an alternative to the Berlekamp–Massey algorithm for decoding BCH and Reed–Solomon codes, which are based on Galois fields.[31]

Chinese remainder theorem

Euclid's algorithm can also be used to solve multiple linear Diophantine equations. Such equations arise in the Chinese remainder theorem, which describes a novel method to represent an integer x. Instead of representing an integer by its digits, it may be represented by its remainders xi modulo a set of N coprime numbers mi:

\begin{align} x1&\equivx\pmod{m1}\\ x2&\equivx\pmod{m2}\\ &\vdots\\ xN&\equivx\pmod{mN}. \end{align}

The goal is to determine x from its N remainders xi. The solution is to combine the multiple equations into a single linear Diophantine equation with a much larger modulus M that is the product of all the individual moduli mi, and define Mi as

Mi=

M
mi

.

Thus, each Mi is the product of all the moduli except mi. The solution depends on finding N new numbers hi such that

Mihi\equiv1\pmod{mi}.

With these numbers hi, any integer x can be reconstructed from its remainders xi by the equation

x\equiv(x1M1h1+x2M2h2++xNMNhN)\pmodM.

Since these numbers hi are the multiplicative inverses of the Mi, they may be found using Euclid's algorithm as described in the previous subsection.

Stern–Brocot tree

See main article: Stern–Brocot tree. The Euclidean algorithm can be used to arrange the set of all positive rational numbers into an infinite binary search tree, called the Stern–Brocot tree.The number 1 (expressed as a fraction 1/1) is placed at the root of the tree, and the location of any other number a/b can be found by computing gcd(a,b) using the original form of the Euclidean algorithm, in which each step replaces the larger of the two given numbers by its difference with the smaller number (not its remainder), stopping when two equal numbers are reached. A step of the Euclidean algorithm that replaces the first of the two numbers corresponds to a step in the tree from a node to its right child, and a step that replaces the second of the two numbers corresponds to a step in the tree from a node to its left child. The sequence of steps constructed in this way does not depend on whether a/b is given in lowest terms, and forms a path from the root to a node containing the number a/b.[32] This fact can be used to prove that each positive rational number appears exactly once in this tree.

For example, 3/4 can be found by starting at the root, going to the left once, then to the right twice:

\begin{align} &\gcd(3,4)&\leftarrow\\ ={}&\gcd(3,1)&\\ ={}&\gcd(2,1)&\\ ={}&\gcd(1,1). \end{align}

The Euclidean algorithm has almost the same relationship to another binary tree on the rational numbers called the Calkin–Wilf tree. The difference is that the path is reversed: instead of producing a path from the root of the tree to a target, it produces a path from the target to the root.

Continued fractions

The Euclidean algorithm has a close relationship with continued fractions.[33] The sequence of equations can be written in the form

\begin{align} a
b

&=q0+

r0\\
b
b
r0

&=q1+

r1\\
r0
r0
r1

&=q2+

r2
r1

\\ &\vdots\\

rk-2
rk-1

&=qk+

rk
rk-1

\\ &\vdots\\

rN-2
rN-1

&=qN. \end{align}

The last term on the right-hand side always equals the inverse of the left-hand side of the next equation. Thus, the first two equations may be combined to form

a
b

=q0+\cfrac1{q1+\cfrac{r1}{r0}}.

The third equation may be used to substitute the denominator term r1/r0, yielding

a
b

=q0+\cfrac1{q1+\cfrac1{q2+\cfrac{r2}{r1}}}.

The final ratio of remainders rk/rk−1 can always be replaced using the next equation in the series, up to the final equation. The result is a continued fraction

a
b

=q0+\cfrac1{q1+\cfrac1{q2+\cfrac{1}{\ddots+\cfrac1{qN}}}}=[q0;q1,q2,\ldots,qN].

In the worked example above, the gcd(1071, 462) was calculated, and the quotients qk were 2, 3 and 7, respectively. Therefore, the fraction 1071/462 may be written

1071
462

=2+\cfrac1{3+\cfrac17}=[2;3,7]

as can be confirmed by calculation.

Factorization algorithms

Calculating a greatest common divisor is an essential step in several integer factorization algorithms,[34] such as Pollard's rho algorithm,[35] Shor's algorithm,[36] Dixon's factorization method[37] and the Lenstra elliptic curve factorization.[38] The Euclidean algorithm may be used to find this GCD efficiently. Continued fraction factorization uses continued fractions, which are determined using Euclid's algorithm.[39]

Algorithmic efficiency

The computational efficiency of Euclid's algorithm has been studied thoroughly.[40] This efficiency can be described by the number of division steps the algorithm requires, multiplied by the computational expense of each step. The first known analysis of Euclid's algorithm is due to A. A. L. Reynaud in 1811,[41] who showed that the number of division steps on input (u, v) is bounded by v; later he improved this to v/2  + 2. Later, in 1841, P. J. E. Finck showed[42] that the number of division steps is at most 2 log2 v + 1, and hence Euclid's algorithm runs in time polynomial in the size of the input. Émile Léger, in 1837, studied the worst case, which is when the inputs are consecutive Fibonacci numbers. Finck's analysis was refined by Gabriel Lamé in 1844,[43] who showed that the number of steps required for completion is never more than five times the number h of base-10 digits of the smaller number b.[44] [45]

In the uniform cost model (suitable for analyzing the complexity of gcd calculation on numbers that fit into a single machine word), each step of the algorithm takes constant time, and Lamé's analysis implies that the total running time is also O(h). However, in a model of computation suitable for computation with larger numbers, the computational expense of a single remainder computation in the algorithm can be as large as O(h2). In this case the total time for all of the steps of the algorithm can be analyzed using a telescoping series, showing that it is also O(h2). Modern algorithmic techniques based on the Schönhage–Strassen algorithm for fast integer multiplication can be used to speed this up, leading to quasilinear algorithms for the GCD.

Number of steps

The number of steps to calculate the GCD of two natural numbers, a and b, may be denoted by T(ab).[46] If g is the GCD of a and b, then a = mg and b = ng for two coprime numbers m and n. Then

as may be seen by dividing all the steps in the Euclidean algorithm by g. By the same argument, the number of steps remains the same if a and b are multiplied by a common factor w: T(a, b) = T(wa, wb). Therefore, the number of steps T may vary dramatically between neighboring pairs of numbers, such as T(a, b) and T(ab + 1), depending on the size of the two GCDs.

The recursive nature of the Euclidean algorithm gives another equation

where T(x, 0) = 0 by assumption.[46]

Worst-case

If the Euclidean algorithm requires N steps for a pair of natural numbers a > b > 0, the smallest values of a and b for which this is true are the Fibonacci numbers FN+2 and FN+1, respectively.[47] More precisely, if the Euclidean algorithm requires N steps for the pair a > b, then one has a ≥ FN+2 and b ≥ FN+1. This can be shown by induction. If N = 1, b divides a with no remainder; the smallest natural numbers for which this is true is b = 1 and a = 2, which are F2 and F3, respectively. Now assume that the result holds for all values of N up to M − 1. The first step of the M-step algorithm is a = q0b + r0, and the Euclidean algorithm requires M − 1 steps for the pair b > r0. By induction hypothesis, one has b ≥ FM+1 and r0 ≥ FM. Therefore, a = q0b + r0 ≥ b + r0 ≥ FM+1 + FM = FM+2,which is the desired inequality.This proof, published by Gabriel Lamé in 1844, represents the beginning of computational complexity theory, and also the first practical application of the Fibonacci numbers.[47]

This result suffices to show that the number of steps in Euclid's algorithm can never be more than five times the number of its digits (base 10). For if the algorithm requires N steps, then b is greater than or equal to FN+1 which in turn is greater than or equal to φN-1, where φ is the golden ratio. Since b ≥ φN-1, then N - 1 ≤ logφb. Since log10φ > 1/5, (N - 1)/5 < log10φ logφb = log10b. Thus, N ≤ 5 log10b. Thus, the Euclidean algorithm always needs less than O(h) divisions, where h is the number of digits in the smaller number b.

Average

The average number of steps taken by the Euclidean algorithm has been defined in three different ways. The first definition is the average time T(a) required to calculate the GCD of a given number a and a smaller natural number b chosen with equal probability from the integers 0 to a − 1[46]

T(a)=

1
a

\sum0T(a,b).

However, since T(ab) fluctuates dramatically with the GCD of the two numbers, the averaged function T(a) is likewise "noisy".[48]

To reduce this noise, a second average τ(a) is taken over all numbers coprime with a

\tau(a)=

1
\varphi(a)

\sum\begin{smallmatrix0\leqb<a\\gcd(a,b)=1\end{smallmatrix}}T(a,b).

There are φ(a) coprime integers less than a, where φ is Euler's totient function. This tau average grows smoothly with a[49] [50]

\tau(a)=

12
\pi2

ln2lna+C+O(a-1/6-\varepsilon)

with the residual error being of order a−(1/6) + ε, where ε is infinitesimal. The constant C in this formula is called Porter's constant[51] and equals

C=-

1
2

+

6ln2
\pi2

\left(4\gamma-

24
\pi2

\zeta'(2)+3ln2-2\right)1.467

where γ is the Euler–Mascheroni constant and ζ' is the derivative of the Riemann zeta function.[52] [53] The leading coefficient (12/π2) ln 2 was determined by two independent methods.[54] [55]

Since the first average can be calculated from the tau average by summing over the divisors d of a[56]

T(a)=

1
a

\sumd\varphi(d)\tau(d)

it can be approximated by the formula[57]

T(a)C+

12
\pi2

ln2\left(lna-\sumd

Λ(d)
d\right)

where Λ(d) is the Mangoldt function.[58]

A third average Y(n) is defined as the mean number of steps required when both a and b are chosen randomly (with uniform distribution) from 1 to n

Y(n)=

1
n2
n
\sum
a=1
n
\sum
b=1

T(a,b)=

1
n
n
\sum
a=1

T(a).

Substituting the approximate formula for T(a) into this equation yields an estimate for Y(n)[59]

Y(n)

12
\pi2

ln2lnn+0.06.

Computational expense per step

In each step k of the Euclidean algorithm, the quotient qk and remainder rk are computed for a given pair of integers rk−2 and rk−1

The computational expense per step is associated chiefly with finding qk, since the remainder rk can be calculated quickly from rk−2, rk−1, and qk

The computational expense of dividing h-bit numbers scales as, where is the length of the quotient.[60]

For comparison, Euclid's original subtraction-based algorithm can be much slower. A single integer division is equivalent to the quotient q number of subtractions. If the ratio of a and b is very large, the quotient is large and many subtractions will be required. On the other hand, it has been shown that the quotients are very likely to be small integers. The probability of a given quotient q is approximately where .[61] For illustration, the probability of a quotient of 1, 2, 3, or 4 is roughly 41.5%, 17.0%, 9.3%, and 5.9%, respectively. Since the operation of subtraction is faster than division, particularly for large numbers,[62] the subtraction-based Euclid's algorithm is competitive with the division-based version. This is exploited in the binary version of Euclid's algorithm.

Combining the estimated number of steps with the estimated computational expense per step shows that the Euclid's algorithm grows quadratically (h2) with the average number of digits h in the initial two numbers a and b. Let represent the number of digits in the successive remainders . Since the number of steps N grows linearly with h, the running time is bounded by

O(\sumi<Nhi(hi-hi+1+2))\subseteqO(h\sumi<N(hi-hi+1+2))\subseteqO(h(h0+2N))\subseteqO(h2).

Alternative methods

Euclid's algorithm is widely used in practice, especially for small numbers, due to its simplicity.[63] For comparison, the efficiency of alternatives to Euclid's algorithm may be determined.

One inefficient approach to finding the GCD of two natural numbers a and b is to calculate all their common divisors; the GCD is then the largest common divisor. The common divisors can be found by dividing both numbers by successive integers from 2 to the smaller number b. The number of steps of this approach grows linearly with b, or exponentially in the number of digits. Another inefficient approach is to find the prime factors of one or both numbers. As noted above, the GCD equals the product of the prime factors shared by the two numbers a and b. Present methods for prime factorization are also inefficient; many modern cryptography systems even rely on that inefficiency.

The binary GCD algorithm is an efficient alternative that substitutes division with faster operations by exploiting the binary representation used by computers.[64] [65] However, this alternative also scales like O(h²). It is generally faster than the Euclidean algorithm on real computers, even though it scales in the same way.[66] Additional efficiency can be gleaned by examining only the leading digits of the two numbers a and b.[67] [68] The binary algorithm can be extended to other bases (k-ary algorithms),[69] with up to fivefold increases in speed.[70] Lehmer's GCD algorithm uses the same general principle as the binary algorithm to speed up GCD computations in arbitrary bases.

A recursive approach for very large integers (with more than 25,000 digits) leads to quasilinear integer GCD algorithms,[71] such as those of Schönhage,[72] [73] and Stehlé and Zimmermann.[74] These algorithms exploit the 2×2 matrix form of the Euclidean algorithm given above. These quasilinear methods generally scale as [75]

Generalizations

Although the Euclidean algorithm is used to find the greatest common divisor of two natural numbers (positive integers), it may be generalized to the real numbers, and to other mathematical objects, such as polynomials, quadratic integers and Hurwitz quaternions. In the latter cases, the Euclidean algorithm is used to demonstrate the crucial property of unique factorization, i.e., that such numbers can be factored uniquely into irreducible elements, the counterparts of prime numbers. Unique factorization is essential to many proofs of number theory.

Rational and real numbers

Euclid's algorithm can be applied to real numbers, as described by Euclid in Book 10 of his Elements. The goal of the algorithm is to identify a real number such that two given real numbers, and, are integer multiples of it: and, where and are integers. This identification is equivalent to finding an integer relation among the real numbers and ; that is, it determines integers and such that . If such an equation is possible, a and b are called commensurable lengths, otherwise they are incommensurable lengths.[76] [77]

The real-number Euclidean algorithm differs from its integer counterpart in two respects. First, the remainders are real numbers, although the quotients are integers as before. Second, the algorithm is not guaranteed to end in a finite number of steps. If it does, the fraction is a rational number, i.e., the ratio of two integers

a
b

=

mg
ng

=

m
n

,

and can be written as a finite continued fraction . If the algorithm does not stop, the fraction is an irrational number and can be described by an infinite continued fraction .[78] Examples of infinite continued fractions are the golden ratio and the square root of two, .[79] The algorithm is unlikely to stop, since almost all ratios of two real numbers are irrational.[80]

An infinite continued fraction may be truncated at a step to yield an approximation to that improves as is increased. The approximation is described by convergents ; the numerator and denominators are coprime and obey the recurrence relation

\begin{align} mk&=qkmk-1+mk-2\\ nk&=qknk-1+nk-2, \end{align}

where and are the initial values of the recursion. The convergent is the best rational number approximation to with denominator :[81]

\left|a
b

-

mk
nk

\right|<

1
2
n
k

.

Polynomials

See main article: Polynomial greatest common divisor. Polynomials in a single variable x can be added, multiplied and factored into irreducible polynomials, which are the analogs of the prime numbers for integers. The greatest common divisor polynomial of two polynomials and is defined as the product of their shared irreducible polynomials, which can be identified using the Euclidean algorithm.[82] The basic procedure is similar to that for integers. At each step, a quotient polynomial and a remainder polynomial are identified to satisfy the recursive equation

rk-2(x)=qk(x)rk-1(x)+rk(x),

where and . Each quotient polynomial is chosen such that each remainder is either zero or has a degree that is smaller than the degree of its predecessor: . Since the degree is a nonnegative integer, and since it decreases with every step, the Euclidean algorithm concludes in a finite number of steps. The last nonzero remainder is the greatest common divisor of the original two polynomials, and .

For example, consider the following two quartic polynomials, which each factor into two quadratic polynomials

\begin{align} a(x)&=x4-4x3+4x2-3x+14=(x2-5x+7)(x2+x+2)    and\\ b(x)&=x4+8x3+12x2+17x+6=(x2+7x+3)(x2+x+2). \end{align}

Dividing by yields a remainder . In the next step, is divided by yielding a remainder . Finally, dividing by yields a zero remainder, indicating that is the greatest common divisor polynomial of and, consistent with their factorization.

Many of the applications described above for integers carry over to polynomials. The Euclidean algorithm can be used to solve linear Diophantine equations and Chinese remainder problems for polynomials; continued fractions of polynomials can also be defined.

The polynomial Euclidean algorithm has other applications, such as Sturm chains, a method for counting the zeros of a polynomial that lie inside a given real interval.[83] This in turn has applications in several areas, such as the Routh–Hurwitz stability criterion in control theory.[84]

Finally, the coefficients of the polynomials need not be drawn from integers, real numbers or even the complex numbers. For example, the coefficients may be drawn from a general field, such as the finite fields described above. The corresponding conclusions about the Euclidean algorithm and its applications hold even for such polynomials.[82]

Gaussian integers

The Gaussian integers are complex numbers of the form, where and are ordinary integers[85] and is the square root of negative one. By defining an analog of the Euclidean algorithm, Gaussian integers can be shown to be uniquely factorizable, by the argument above.[86] This unique factorization is helpful in many applications, such as deriving all Pythagorean triples or proving Fermat's theorem on sums of two squares. In general, the Euclidean algorithm is convenient in such applications, but not essential; for example, the theorems can often be proven by other arguments.

The Euclidean algorithm developed for two Gaussian integers and is nearly the same as that for ordinary integers,[87] but differs in two respects. As before, we set and, and the task at each step is to identify a quotient and a remainder such that

rk=rk-2-qkrk-1,

where every remainder is strictly smaller than its predecessor: . The first difference is that the quotients and remainders are themselves Gaussian integers, and thus are complex numbers. The quotients are generally found by rounding the real and complex parts of the exact ratio (such as the complex number) to the nearest integers.[87] The second difference lies in the necessity of defining how one complex remainder can be "smaller" than another. To do this, a norm function is defined, which converts every Gaussian integer into an ordinary integer. After each step of the Euclidean algorithm, the norm of the remainder is smaller than the norm of the preceding remainder, . Since the norm is a nonnegative integer and decreases with every step, the Euclidean algorithm for Gaussian integers ends in a finite number of steps.[88] The final nonzero remainder is, the Gaussian integer of largest norm that divides both and ; it is unique up to multiplication by a unit, or .[89]

Many of the other applications of the Euclidean algorithm carry over to Gaussian integers. For example, it can be used to solve linear Diophantine equations and Chinese remainder problems for Gaussian integers;[90] continued fractions of Gaussian integers can also be defined.[87]

Euclidean domains

A set of elements under two binary operations, denoted as addition and multiplication, is called a Euclidean domain if it forms a commutative ring and, roughly speaking, if a generalized Euclidean algorithm can be performed on them. The two operations of such a ring need not be the addition and multiplication of ordinary arithmetic; rather, they can be more general, such as the operations of a mathematical group or monoid. Nevertheless, these general operations should respect many of the laws governing ordinary arithmetic, such as commutativity, associativity and distributivity.

The generalized Euclidean algorithm requires a Euclidean function, i.e., a mapping from into the set of nonnegative integers such that, for any two nonzero elements and in, there exist and in such that and .[91] Examples of such mappings are the absolute value for integers, the degree for univariate polynomials, and the norm for Gaussian integers above.[92] [93] The basic principle is that each step of the algorithm reduces f inexorably; hence, if can be reduced only a finite number of times, the algorithm must stop in a finite number of steps. This principle relies on the well-ordering property of the non-negative integers, which asserts that every non-empty set of non-negative integers has a smallest member.[94]

The fundamental theorem of arithmetic applies to any Euclidean domain: Any number from a Euclidean domain can be factored uniquely into irreducible elements. Any Euclidean domain is a unique factorization domain (UFD), although the converse is not true.[94] The Euclidean domains and the UFD's are subclasses of the GCD domains, domains in which a greatest common divisor of two numbers always exists.[95] In other words, a greatest common divisor may exist (for all pairs of elements in a domain), although it may not be possible to find it using a Euclidean algorithm. A Euclidean domain is always a principal ideal domain (PID), an integral domain in which every ideal is a principal ideal.[96] Again, the converse is not true: not every PID is a Euclidean domain.

The unique factorization of Euclidean domains is useful in many applications. For example, the unique factorization of the Gaussian integers is convenient in deriving formulae for all Pythagorean triples and in proving Fermat's theorem on sums of two squares. Unique factorization was also a key element in an attempted proof of Fermat's Last Theorem published in 1847 by Gabriel Lamé, the same mathematician who analyzed the efficiency of Euclid's algorithm, based on a suggestion of Joseph Liouville.[97] Lamé's approach required the unique factorization of numbers of the form, where and are integers, and is an th root of 1, that is, . Although this approach succeeds for some values of (such as, the Eisenstein integers), in general such numbers do factor uniquely. This failure of unique factorization in some cyclotomic fields led Ernst Kummer to the concept of ideal numbers and, later, Richard Dedekind to ideals.[98]

Unique factorization of quadratic integers

The quadratic integer rings are helpful to illustrate Euclidean domains. Quadratic integers are generalizations of the Gaussian integers in which the imaginary unit i is replaced by a number . Thus, they have the form, where and are integers and has one of two forms, depending on a parameter . If does not equal a multiple of four plus one, then

\omega=\sqrtD.

If, however, D does equal a multiple of four plus one, then

\omega=

1+\sqrt{D
} .

If the function corresponds to a norm function, such as that used to order the Gaussian integers above, then the domain is known as norm-Euclidean. The norm-Euclidean rings of quadratic integers are exactly those where is one of the values −11, −7, −3, −2, −1, 2, 3, 5, 6, 7, 11, 13, 17, 19, 21, 29, 33, 37, 41, 57, or 73.[99] The cases and yield the Gaussian integers and Eisenstein integers, respectively.

If is allowed to be any Euclidean function, then the list of possible values of for which the domain is Euclidean is not yet known.[100] The first example of a Euclidean domain that was not norm-Euclidean (with) was published in 1994. In 1973, Weinberger proved that a quadratic integer ring with is Euclidean if, and only if, it is a principal ideal domain, provided that the generalized Riemann hypothesis holds.[101]

Noncommutative rings

The Euclidean algorithm may be applied to some noncommutative rings such as the set of Hurwitz quaternions.[102] Let and represent two elements from such a ring. They have a common right divisor if and for some choice of and in the ring. Similarly, they have a common left divisor if and for some choice of and in the ring. Since multiplication is not commutative, there are two versions of the Euclidean algorithm, one for right divisors and one for left divisors.[102] Choosing the right divisors, the first step in finding the by the Euclidean algorithm can be written

\rho0=\alpha-\psi0\beta=(\xi-\psi)\delta,

where represents the quotient and the remainder. Here the quotent and remainder are chosen so that (if nonzero) the remainder has for a "Euclidean function" N defined analogously to the Euclidean functions of Euclidean domains in the non-commutative case.[102] This equation shows that any common right divisor of and is likewise a common divisor of the remainder . The analogous equation for the left divisors would be

\rho0=\alpha-\beta\psi0=\delta(\xi-η\psi0).

With either choice, the process is repeated as above until the greatest common right or left divisor is identified. As in the Euclidean domain, the "size" of the remainder (formally, its Euclidean function or "norm") must be strictly smaller than, and there must be only a finite number of possible sizes for, so that the algorithm is guaranteed to terminate.[103]

Many results for the GCD carry over to noncommutative numbers. For example, Bézout's identity states that the right can be expressed as a linear combination of and .[104] In other words, there are numbers and such that

\Gammaright=\sigma\alpha+\tau\beta.

The analogous identity for the left GCD is nearly the same:

\Gammaleft=\alpha\sigma+\beta\tau.

Bézout's identity can be used to solve Diophantine equations. For instance, one of the standard proofs of Lagrange's four-square theorem, that every positive integer can be represented as a sum of four squares, is based on quaternion GCDs in this way.[103]

See also

Bibliography

External links

Notes and References

  1. Some widely used textbooks, such as I. N. Herstein's Topics in Algebra and Serge Lang's Algebra, use the term "Euclidean algorithm" to refer to Euclidean division
  2. Lamé . Gabriel . 1844 . Note sur la limite du nombre des divisions dans la recherche du plus grand commun diviseur entre deux nombres entiers . Comptes Rendus des Séances de l'Académie des Sciences . French . 19 . 867–870.
  3. Shallit . Jeffrey . 1994-11-01 . Origins of the analysis of the Euclidean algorithm . Historia Mathematica . en . 21 . 4 . 401–419 . 10.1006/hmat.1994.1031 . 0315-0860. free .
  4. Book: Grossman, J. W. . 1990 . Discrete Mathematics . Macmillan . New York . 0-02-348331-8 . 213.
  5. Book: Ogilvy . C. S. . C. Stanley Ogilvy . Anderson . J. T. . 1966 . Excursions in number theory . . New York . 27–29.
  6. Book: Lovász . L.. László Lovász. Pelikán. J.. Vesztergombi. K. . Katalin Vesztergombi . 2003 . Discrete Mathematics: Elementary and Beyond . Springer-Verlag . New York . 0-387-95584-4 . 100–101.
  7. Kimberling. C.. Clark Kimberling . 1983 . A Visual Euclidean Algorithm . Mathematics Teacher . 76 . 108–109.
  8. Book: Abstract Algebra. Dummit. David S.. Foote. Richard M.. John Wiley & Sons, Inc.. 2004. 978-0-471-43334-7. 270–271.
  9. Book: Stewart, B. M. . 1964 . Theory of Numbers . 2nd . Macmillan . New York . 43–44 . 64010964.
  10. Lazard. D.. 1977. Le meilleur algorithme d'Euclide pour K[''X''] et Z . fr . Comptes Rendus de l'Académie des Sciences. 284. 1–4.
  11. , p. 318
  12. Book: Weil, A. . André Weil. 1983 . Number Theory . Birkhäuser . Boston . 0-8176-3141-0 . 4–6.
  13. Book: Jones, A. . 1994 . Greek mathematics to AD 300 . Companion encyclopedia of the history and philosophy of the mathematical sciences . Routledge . New York . 0-415-09238-8 . 46–48.
  14. Book: van der Waerden, B. L. . Bartel Leendert van der Waerden. 1954 . Science Awakening . registration. translated by Arnold Dresden . P. Noordhoff Ltd . Groningen . 114–115.
  15. von Fritz. K. . 1945 . The Discovery of Incommensurability by Hippasus of Metapontum . Annals of Mathematics . 46 . 242–264 . 10.2307/1969021 . 1969021 . 2.
  16. Book: Heath, T. L. . T. L. Heath . 1949 . Mathematics in Aristotle . registration . Oxford Press . 80–83.
  17. Book: Fowler, D. H. . David Fowler (mathematician). 1987 . The Mathematics of Plato's Academy: A New Reconstruction . Oxford University Press . Oxford . 0-19-853912-6 . 31–66.
  18. Becker . O. . 1933 . Eudoxus-Studien I. Eine voreuklidische Proportionslehre und ihre Spuren bei Aristoteles und Euklid . 2 . 311–333 . Quellen und Studien zur Geschichte der Mathematik B.
  19. Book: Saunderson. Nicholas. The Elements of Algebra in Ten Books. 1740. University of Cambridge Press. 1 November 2016.
  20. [Richard Dedekind]
  21. Sturm . C. . Jacques Charles François Sturm . 1829 . Mémoire sur la résolution des équations numériques . fr . Bull. Des sciences de Férussac . 11 . 419–422.
  22. Ferguson . H. R. P. . Helaman Ferguson . Forcade . R. W. . 10.1090/S0273-0979-1979-14691-3 . 6 . Bulletin of the American Mathematical Society . 546316 . 912–914 . New Series . Generalization of the Euclidean algorithm for real numbers to all dimensions higher than two . 1 . 1979. free .
  23. Peterson . I. . 12 August 2002 . Jazzing Up Euclid's Algorithm . ScienceNews .
  24. Cipra . Barry Arthur . Barry Arthur Cipra . The Best of the 20th Century: Editors Name Top 10 Algorithms . SIAM News . 33 . 16 May 2000 . . 4 . 19 July 2016 . https://web.archive.org/web/20160922144038/https://www.siam.org/pdf/news/637.pdf . 22 September 2016 . dead . dmy-all .
  25. Cole . A. J. . Davie . A. J. T. . 1969 . A game based on the Euclidean algorithm and a winning strategy for it . Math. Gaz. . 53 . 354–357 . 10.2307/3612461 . 3612461 . 386. 125164797 .
  26. 10.2307/2689037 . Spitznagel . E. L. . 1973 . Properties of a game based on Euclid's algorithm . 2689037 . Math. Mag. . 46 . 2 . 87–92.
  27. Book: Roberts, J. . 1977 . Elementary Number Theory: A Problem Oriented Approach . . Cambridge, MA . 0-262-68028-9 . 1–8 .
  28. Book: Jones . G. A. . Jones . J. M. . 1998 . Bezout's Identity . Elementary Number Theory . Springer-Verlag . New York . 7–11.
  29. Book: Koshy, T. . 2002 . Elementary Number Theory with Applications . Harcourt/Academic Press . Burlington, MA . 0-12-421171-2 . 167–169.
  30. Book: Bach . E. . Eric Bach . Shallit . J. . Jeffrey Shallit . 1996 . Algorithmic number theory . MIT Press . Cambridge, MA . 0-262-02405-5 . 70–73.
  31. Book: Moon, T. K.. Error Correction Coding: Mathematical Methods and Algorithms. 266. John Wiley and Sons. 2005. 0-471-64800-0.
  32. Book: Concrete mathematics. 123. Ronald Graham. Graham. R.. Donald Knuth. Knuth. D. E.. Oren Patashnik. Patashnik. O.. Addison-Wesley. 1989.
  33. Book: Vinogradov, I. M. . Ivan Matveyevich Vinogradov . 1954 . Elements of Number Theory . registration . Dover . New York . 3–13.
  34. , pp. 225–349
  35. , pp. 369–371
  36. Peter Shor. Shor . P. W. . 1997 . Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer . SIAM Journal on Scientific and Statistical Computing . 26 . 5 . 1484–1509 . 10.1137/s0097539795293172. quant-ph/9508027 . 1995quant.ph..8027S. 2337707 .
  37. Dixon . J. D. . 1981 . Asymptotically fast factorization of integers . Math. Comput. . 36 . 255–260 . 10.2307/2007743 . 2007743 . 153. free .
  38. Hendrik Lenstra. Lenstra. H. W. Jr. . 1987 . Factoring integers with elliptic curves . Annals of Mathematics . 126 . 649–673 . 10.2307/1971363 . 1971363 . 3. 1887/2140 . free .
  39. , pp. 380–384
  40. , pp. 339–364
  41. Book: Reynaud, A.-A.-L. . 1811 . Traité d'arithmétique à l'usage des élèves qui se destinent à l'École Polytechnique . 6th . Courcier . Paris . Note 60, p. 34 . As cited by .
  42. Book: Finck, P.-J.-E. . Traité élémentaire d'arithmétique à l'usage des candidats aux écoles spéciales . fr . Derivaux . 1841.
  43. Gabriel Lamé. Lamé. G. . 1844 . Note sur la limite du nombre des divisions dans la recherche du plus grand commun diviseur entre deux nombres entiers . fr . Comptes Rendus de l'Académie des Sciences . 19 . 867–870.
  44. Grossman . H. . 1924 . On the Number of Divisions in Finding a G.C.D . The American Mathematical Monthly . 31 . 443 . 10.2307/2298146 . 2298146 . 9.
  45. Book: Honsberger, R. . Ross Honsberger . 1976 . Mathematical Gems II . . 0-88385-302-7 . 54–57.
  46. , p. 344
  47. , p. 343
  48. , p. 353
  49. , p. 357
  50. Tonkov . T. . 1974 . On the average length of finite continued fractions . Acta Arithmetica . 26 . 47–57. 10.4064/aa-26-1-47-57 . free .
  51. Knuth . Donald E. . Donald E. Knuth . 10.1016/0898-1221(76)90025-0 . 2 . Computers & Mathematics with Applications . 137–139 . Evaluation of Porter's constant . 2 . 1976. free .
  52. Porter . J. W. . 1975 . On a Theorem of Heilbronn . . 22 . 20–28 . 10.1112/S0025579300004459.
  53. Knuth. D. E. . Donald Knuth . 1976 . Evaluation of Porter's Constant . Computers and Mathematics with Applications . 2 . 137–139 . 10.1016/0898-1221(76)90025-0 . 2. free .
  54. Dixon . J. D. . 1970 . The Number of Steps in the Euclidean Algorithm . J. Number Theory . 2 . 414–422 . 10.1016/0022-314X(70)90044-2 . 4. 1970JNT.....2..414D . free .
  55. Book: Heilbronn, H. A. . Hans Heilbronn . 1969 . On the Average Length of a Class of Finite Continued Fractions . Number Theory and Analysis . Paul Turán . Plenum . New York . 87–96 . 76016027.
  56. , p. 354
  57. Norton . G. H. . 1990 . On the Asymptotic Analysis of the Euclidean Algorithm . Journal of Symbolic Computation . 10 . 53–58 . 10.1016/S0747-7171(08)80036-3. free .
  58. , p. 355
  59. , p. 356
  60. , pp. 257–261
  61. , p. 352
  62. Book: Wagon, S. . Stan Wagon . 1999 . Mathematica in Action . Springer-Verlag . New York . 0-387-98252-3 . 335–336.
  63. Book: Sorenson, Jonathan P. . An analysis of the generalized binary GCD algorithm . 2076257 . 327–340 . American Mathematical Society . Providence, RI . Fields Institute Communications . High primes and misdemeanours: lectures in honour of the 60th birthday of Hugh Cowie Williams . 41 . 2004 . The algorithms that are used the most in practice today [for computing greatest common divisors] are probably the binary algorithm and Euclid's algorithm for smaller numbers, and either Lehmer's algorithm or Lebealean's version of the k-ary GCD algorithm for larger numbers.. 9780821887592 .
  64. , pp. 321–323
  65. Stein . J. . 1967 . Computational problems associated with Racah algebra . Journal of Computational Physics . 1 . 397–405 . 10.1016/0021-9991(67)90047-2 . 3. 1967JCoPh...1..397S .
  66. , pp. 77–79, 81–85, 425–431
  67. , p. 328
  68. Lehmer. D. H.. Derrick Henry Lehmer . 1938 . Euclid's Algorithm for Large Numbers . The American Mathematical Monthly . 45 . 227–233 . 10.2307/2302607 . 2302607 . 4.
  69. Sorenson . J. . 1994 . Two fast GCD algorithms . J. Algorithms . 16 . 110–144 . 10.1006/jagm.1994.1006.
  70. Weber . K. . 1995 . The accelerated GCD algorithm . ACM Trans. Math. Softw. . 21 . 111–122 . 10.1145/200979.201042. 14934919 . free .
  71. Book: Aho . A. . Alfred Aho . Hopcroft . J. . John Hopcroft . Ullman . J. . Jeffrey Ullman . 1974 . The Design and Analysis of Computer Algorithms . Addison–Wesley . New York . 300–310 . 0-201-00029-6 .
  72. Schönhage. A. . Arnold Schönhage. Schnelle Berechnung von Kettenbruchentwicklungen . de . Acta Informatica . 1 . 139–144 . 10.1007/BF00289520 . 1971 . 2. 34561609 .
  73. Book: Cesari, G. . 1998 . Parallel implementation of Schönhage's integer GCD algorithm . Algorithmic Number Theory: Proc. ANTS-III, Portland, OR . G. Buhler . Springer-Verlag . New York . 64–76. 1423. Lecture Notes in Computer Science.
  74. Book: Stehlé. D.. Zimmermann. P. . 2005 . Gal's accurate tables method revisited . Proceedings of the 17th IEEE Symposium on Computer Arithmetic (ARITH-17) . . Los Alamitos, CA.
  75. Möller. N. . On Schönhage's algorithm and subquadratic integer gcd computation . Mathematics of Computation . 77 . 589–607 . 10.1090/S0025-5718-07-02017-0 . 2008 . 261. 2008MaCom..77..589M . free .
  76. Book: Boyer . C. B. . Merzbach . U. C. . Uta Merzbach . 1991 . A History of Mathematics . 2nd . Wiley . New York . 0-471-54397-7 . 116–117 .
  77. Book: Cajori, F . Florian Cajori. 1894 . A History of Mathematics . Macmillan . New York . 70 . 0-486-43874-0.
  78. Book: Joux, Antoine. Algorithmic Cryptanalysis. CRC Press. 2009. 9781420070033. 33.
  79. Book: Mathematical Omnibus: Thirty Lectures on Classic Mathematics. D. B.. Fuks. Serge. Tabachnikov. Sergei Tabachnikov. American Mathematical Society. 2007. 9780821843161. 13.
  80. Book: Darling, David. The Universal Book of Mathematics: From Abracadabra to Zeno's Paradoxes. David J. Darling. John Wiley & Sons. 2004. 9780471667001. 175. Khintchine's constant.
  81. Book: Williams, Colin P.. Explorations in Quantum Computing. Springer. 2010. 9781846288876. 277–278.
  82. Book: Lang, S. . Serge Lang. 1984 . Algebra . 2nd . Addison–Wesley . Menlo Park, CA . 0-201-05487-6 . 190–194.
  83. Book: Grattan-Guinness, Ivor. Convolutions in French Mathematics, 1800-1840: From the Calculus and Mechanics to Mathematical Analysis and Mathematical Physics. Volume II: The Turns. Ivor Grattan-Guinness. Birkhäuser. Science Networks: Historical Studies. 3. Basel, Boston, Berlin. 1990. 9783764322380. 1148. Our subject here is the 'Sturm sequence' of functions defined from a function and its derivative by means of Euclid's algorithm, in order to calculate the number of real roots of a polynomial within a given interval.
  84. Book: Solving Ordinary Differential Equations I: Nonstiff Problems. Springer Series in Computational Mathematics. 8. Ernst. Hairer. Syvert P.. Nørsett. Gerhard. Wanner. 2nd. Springer. 1993. 9783540566700. 81ff. The Routh–Hurwitz Criterion.
  85. The phrase "ordinary integer" is commonly used for distinguishing usual integers from Gaussian integers, and more generally from algebraic integers.
  86. Carl Friedrich Gauss. Gauss. C. F. . 1832 . Theoria residuorum biquadraticorum . Comm. Soc. Reg. Sci. Gött. Rec. . 4. Reprinted in Book: Gauss, C. F.. 2011. Theoria residuorum biquadraticorum commentatio prima . Werke. 2. Cambridge Univ. Press. 65–92. 10.1017/CBO9781139058230.004. 9781139058230. and Book: Gauss, C. F.. 2011. Theoria residuorum biquadraticorum commentatio secunda. Werke. 2. Cambridge Univ. Press. 93–148. 10.1017/CBO9781139058230.005. 9781139058230.
  87. Book: Hensley, Doug. Continued Fractions. World Scientific. 2006. 9789812564771. 26.
  88. Book: Dedekind, Richard. Theory of Algebraic Integers. Cambridge Mathematical Library. Richard Dedekind. Cambridge University Press. 1996. 9780521565189. 22–24.
  89. Book: Numbers and Symmetry: An Introduction to Algebra. Bernard L.. Johnston. Fred. Richman. CRC Press. 1997. 9780849303012. 44.
  90. Book: Introduction to Number Theory. registration. William W.. Adams. Larry Joel. Goldstein. Prentice-Hall. 1976. 9780134912820. Exercise 24, p. 205. State and prove an analogue of the Chinese remainder theorem for the Gaussian integers..
  91. Book: Lauritzen, Niels. Concrete Abstract Algebra: From Numbers to Gröbner Bases. Cambridge University Press. 2003. 9780521534109. 130.
  92. , p. 132
  93. , p. 161
  94. Book: Sharpe, David. Rings and Factorization. Cambridge University Press. 1987. 9780521337182. 55. registration.
  95. , p. 52
  96. , p. 131
  97. Lamé . G. . Gabriel Lamé. 1847 . Mémoire sur la résolution, en nombres complexes, de l'équation An + Bn + Cn = 0 . fr . J. Math. Pures Appl. . 12 . 172–184.
  98. Book: Edwards, H.. Harold Edwards (mathematician) . Fermat's last theorem: a genetic introduction to algebraic number theory. 2000. Springer. 76.
  99. Book: LeVeque, W. J. . William J. LeVeque . Topics in Number Theory, Volumes I and II . Dover Publications . New York . 2002 . 1956 . 978-0-486-42539-9 . 1009.11001 . II:57,81 .
  100. Clark . D. A. . 1994 . A quadratic field which is Euclidean but not norm-Euclidean . Manuscripta Mathematica . 83 . 327–330 . 10.1007/BF02567617 . free . 0817.11047 . 895185 .
  101. Weinberger . P. . On Euclidean rings of algebraic integers . Proc. Sympos. Pure Math. . Proceedings of Symposia in Pure Mathematics . 1973 . 24 . 321–332. 10.1090/pspum/024/0337902 . 9780821814246 .
  102. see pp. 37-38 for non-commutative extensions of the Euclidean algorithm and Corollary 4.35, p. 40, for more examples of noncommutative rings to which they apply.
  103. Book: Elementary Number Theory, Group Theory and Ramanujan Graphs. Elementary Number Theory, Group Theory and Ramanujan Graphs. 55. London Mathematical Society Student Texts. Giuliana. Davidoff. Giuliana Davidoff . Peter. Sarnak. Alain. Valette. Cambridge University Press. 2003. 9780521531436. 2.6 The Arithmetic of Integer Quaternions. 59–70. https://books.google.com/books?id=AlvfFDJOGZ8C&pg=PA59.
  104. Book: Ribenboim, Paulo. Classical Theory of Algebraic Numbers. Universitext. Springer-Verlag. 2001. 9780387950709. 104.