Bézout's identity Bézout's identity states that the greatest common divisor of two integers and can be represented as a linear sum of the original two numbers and . In other words, it is always possible to find integers and such that . The integers and can be calculated from the quotients , , etc. by reversing the order of equations in Euclid's algorithm. Beginning with the next-to-last equation, can be expressed in terms of the quotient and the two preceding remainders, and : : . Those two remainders can be likewise expressed in terms of their quotients and preceding remainders, : and : . Substituting these formulae for and into the first equation yields as a linear sum of the remainders and . The process of substituting remainders by formulae involving their predecessors can be continued until the original numbers and are reached: : : : . After all the remainders , , etc. have been substituted, the final equation expresses as a linear sum of and , so that . The Euclidean algorithm, and thus Bézout'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 of two numbers and . Consider the set of all numbers , where and are any two integers. Since and are both divisible by , every number in the set is divisible by . In other words, every number of the set is an integer multiple of . This is true for every common divisor of and . However, unlike other common divisors, the greatest common divisor is a member of the set; by Bézout's identity, choosing and gives . A smaller common divisor cannot be a member of the set, since every member of the set must be divisible by . Conversely, any multiple of can be obtained by choosing and , where and 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 is equivalent to the set of multiples of . In other words, the set of all possible sums of integer multiples of two numbers ( and ) is equivalent to the set of multiples of . The GCD is said to be the generator of the
ideal of and . 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 and . By adding/subtracting multiples of the first cup and multiples of the second cup, any volume can be measured out. These volumes are all multiples of .
Extended Euclidean algorithm The integers and 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 and are given by and , where is the step on which the algorithm terminates with . The validity of this approach can be shown by induction. Assume that the recursion formula is correct up to step of the algorithm; in other words, assume that : for all less than . The th step of the algorithm gives the equation : . Since the recursion formula has been assumed to be correct for and , they may be expressed in terms of the corresponding and variables : . Rearranging this equation yields the recursion formula for step , as required : .
Matrix method The integers and can also be found using an equivalent
matrix method. The sequence of equations of Euclid's algorithm : \begin{align} a & = q_0 b + r_0 \\ b & = q_1 r_0 + r_1 \\ & \,\,\,\vdots \\ r_{N-2} & = q_N r_{N-1} + 0 \end{align} can be written as a product of quotient matrices multiplying a two-dimensional remainder vector --> : \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} q_0 & 1 \\ 1 & 0 \end{pmatrix} \begin{pmatrix} b \\ r_0 \end{pmatrix} = \begin{pmatrix} q_0 & 1 \\ 1 & 0 \end{pmatrix} \begin{pmatrix} q_1 & 1 \\ 1 & 0 \end{pmatrix} \begin{pmatrix} r_0 \\ r_1 \end{pmatrix} = \cdots = \prod_{i=0}^N \begin{pmatrix} q_i & 1 \\ 1 & 0 \end{pmatrix} \begin{pmatrix} r_{N-1} \\ 0 \end{pmatrix} \,. Let represent the product of all the quotient matrices --> : \mathbf{M} = \begin{pmatrix} m_{11} & m_{12} \\ m_{21} & m_{22} \end{pmatrix} = \prod_{i=0}^N \begin{pmatrix} q_i & 1 \\ 1 & 0 \end{pmatrix} = \begin{pmatrix} q_0 & 1 \\ 1 & 0 \end{pmatrix} \begin{pmatrix} q_1 & 1 \\ 1 & 0 \end{pmatrix} \cdots \begin{pmatrix} q_{N} & 1 \\ 1 & 0 \end{pmatrix} \,. This simplifies the Euclidean algorithm to the form --> : \begin{pmatrix} a \\ b \end{pmatrix} = \mathbf{M} \begin{pmatrix} r_{N-1} \\ 0 \end{pmatrix} = \mathbf{M} \begin{pmatrix} g \\ 0 \end{pmatrix} \,. To express as a linear sum of and , both sides of this equation can be multiplied by the
inverse of the matrix . The
determinant of equals , since it equals the product of the determinants of the quotient matrices, each of which is negative one. Since the determinant of is never zero, the vector of the final remainders can be solved using the inverse of --> : \begin{pmatrix} g \\ 0 \end{pmatrix} = \mathbf{M}^{-1} \begin{pmatrix} a \\ b \end{pmatrix} = (-1)^{N+1} \begin{pmatrix} m_{22} & -m_{12} \\ -m_{21} & m_{11} \end{pmatrix} \begin{pmatrix} a \\ b \end{pmatrix} \,. Since the top equation gives : , the two integers of Bézout's identity are and . 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 can be written as a product of two factors and , that is, . If another number also divides but is coprime with , then must divide , by the following argument: If the greatest common divisor of and is , then integers and can be found such that : by Bézout's identity. Multiplying both sides by gives the relation: : Since divides both terms on the right-hand side, it must also divide the left-hand side, . This result is known as
Euclid's lemma. Specifically, if a prime number divides , then it must divide at least one factor of . Conversely, if a number is coprime to each of a series of numbers , , ..., , then is also coprime to their product, . To see this, assume the contrary, that there are two independent factorizations of into and prime factors, respectively : . Since each prime divides by assumption, it must also divide one of the factors; since each is prime as well, it must be that . Iteratively dividing by the factors shows that each has an equal counterpart ; 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 , . The solutions are shown as blue circles.
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 and such that : where , and are given integers. This can be written as an equation for in
modular arithmetic: : . Let be the greatest common divisor of and . Both terms in are divisible by ; therefore, must also be divisible by , or the equation has no solutions. By dividing both sides by , the equation can be reduced to Bezout's identity : , where and can be found by the
extended Euclidean algorithm. This provides one solution to the Diophantine equation, and . In general, a linear Diophantine equation has no solutions, or an infinite number of solutions. To find the latter, consider two solutions, and , where : or equivalently : . Therefore, the smallest difference between two solutions is , whereas the smallest difference between two solutions is . Thus, the solutions may be expressed as : : . By allowing to vary over all possible integers, an infinite family of solutions can be generated from a single solution . If the solutions are required to be
positive integers , 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 ; that is, multiples of are added or subtracted until the result is brought within the range –. For example, the result of . Such finite fields can be defined for any prime ; using more sophisticated definitions, they can also be defined for any power of a prime . Finite fields are often called
Galois fields, and are abbreviated as or ). In such a field with numbers, every nonzero element has a unique
modular multiplicative inverse, such that . This inverse can be found by solving the congruence equation , 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.
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} x_1 & \equiv x \pmod {m_1} \\ x_2 & \equiv x \pmod {m_2} \\ & \,\,\,\vdots \\ x_N & \equiv x \pmod {m_N} \,. \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 : M_i = \frac M {m_i}. Thus, each
Mi is the product of all the moduli
except mi. The solution depends on finding
N new numbers
hi such that : M_i h_i \equiv 1 \pmod {m_i} \,. With these numbers
hi, any integer
x can be reconstructed from its remainders
xi by the equation : x \equiv (x_1 M_1 h_1 + x_2 M_2 h_2 + \cdots + x_N M_N h_N) \pmod M \,. 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 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. 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) & \rightarrow \\ = {} & \gcd(2,1) & \rightarrow \\ = {} & \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. The sequence of equations can be written in the form : \begin{align} \frac a b &= q_0 + \frac{r_0} b \\ \frac b {r_0} &= q_1 + \frac{r_1}{r_0} \\ \frac{r_0}{r_1} &= q_2 + \frac{r_2}{r_1} \\ & \,\,\, \vdots \\ \frac{r_{k-2}}{r_{k-1}} &= q_k + \frac{r_k}{r_{k-1}} \\ & \,\,\, \vdots \\ \frac{r_{N-2}}{r_{N-1}} &= q_N\,. \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 : \frac a b = q_0 + \cfrac 1 {q_1 + \cfrac{r_1}{r_0}} \,. The third equation may be used to substitute the denominator term
r1/
r0, yielding : \frac a b = q_0 + \cfrac 1 {q_1 + \cfrac 1 {q_2 + \cfrac{r_2}{r_1}}}\,. 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 : \frac a b = q_0 + \cfrac 1 {q_1 + \cfrac 1 {q_2 + \cfrac{1}{\ddots + \cfrac 1 {q_N}}}} = [ q_0; q_1, q_2, \ldots , q_N ] \,. 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 : \frac{1071}{462} = 2 + \cfrac 1 {3 + \cfrac 1 7} = [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, such as
Pollard's rho algorithm,
Shor's algorithm,
Dixon's factorization method and the
Lenstra elliptic curve factorization. The Euclidean algorithm may be used to find this GCD efficiently.
Continued fraction factorization uses continued fractions, which are determined using Euclid's algorithm. == Algorithmic efficiency ==