In arithmetic and computer programming, the extended Euclidean algorithm is an extension to the Euclidean algorithm, and computes, in addition to the greatest common divisor (gcd) of integers a and b, also the coefficients of Bézout's identity, which are integers x and y such that ax+by=gcd(a,b); it is generally denoted as xgcd(a,b). This is a certifying algorithm, because the gcd is the only number that can simultaneously satisfy this equation and divide the inputs. It allows one to compute also, with almost no extra cost, the quotients of a and b by their greatest common divisor. Extended Euclidean algorithm also refers to a very similar algorithm for computing the polynomial greatest common divisor and the coefficients of Bézout's identity of two univariate polynomials. The extended Euclidean algorithm is particularly useful when a and b are coprime. With that provision, x is the modular multiplicative inverse of a modulo b, and y is the modular multiplicative inverse of b modulo a. Similarly, the polynomial extended Euclidean algorithm allows one to compute the multiplicative inverse in algebraic field extensions and, in particular in finite fields of non-prime order. It follows that both extended Euclidean algorithms are widely used in cryptography. In particular, the computation of the modular multiplicative inverse is an essential step in the derivation of key-pairs in the RSA public-key encryption method.
Description The standard Euclidean algorithm proceeds by a succession of Euclidean divisions whose quotients are not used. Only the remainders are kept. For the extended algorithm, the successive quotients are used. More precisely, the standard Euclidean algorithm with a and b as input, consists of computing a sequence q1,…,qk of quotients and a sequence r0,…,rk+1 of remainders such that
r0=ar1=b⋮ri+1=ri−1−qiriand0≤ri+1<|ri|(this defines qi)⋮ It is the main property of Euclidean division that the inequalities on the right define uniquely qi and ri+1 from ri−1 and ri. The computation stops when one reaches a remainder rk+1 which is zero; the greatest common divisor is then the last nonzero remainder rk. The extended Euclidean algorithm proceeds similarly, but adds two other sequences, as follows
r0=ar1=bs0=1s1=0t0=0t1=1⋮⋮ri+1=ri−1−qiriand 0≤ri+1<|ri|(this defines qi)si+1=si−1−qisiti+1=ti−1−qiti⋮ The computation also stops when rk+1=0 and gives
rk is the greatest common divisor of the input a=r0 and b=r1. The Bézout coefficients are sk and tk, that is gcd(a,b)=rk=ask+btk The quotients of a and b by their greatest common divisor are given by sk+1=±bgcd(a,b) and tk+1=∓agcd(a,b) (the sign ∓ is opposite to ±). Moreover, if a and b are both positive and gcd(a,b)≠min(a,b), then
|si|≤⌊b2gcd(a,b)⌋and|ti|≤⌊a2gcd(a,b)⌋ for 0≤i≤k, where ⌊x⌋ denotes the integral part of x, that is the greatest integer not greater than x. Together with the general form of all Bézout coefficient pairs, these inequalities imply that the extended Euclidean algorithm provides the unique pair that simultaneously minimizes the absolute values of both coefficients, called the minimal Bézout pair. It also means that if a and b fit into an unsigned integer data type, a computer program can compute the Bézout coefficients in the corresponding signed integer type without integer overflow.
Examples The following table shows how the extended Euclidean algorithm proceeds with input 240 and 46. The greatest common divisor is the last nonzero entry, 2 in the column "remainder". The computation stops at row 6, because the remainder in it is 0. Bézout coefficients appear in the last two columns of the second-to-last row. In fact, it is easy to verify that −9 × 240 + 47 × 46 = 2. Finally the last two entries 23 and −120 of the last row are, up to the sign, the quotients of the input 46 and 240 by the greatest common divisor 2.
The following example uses a more compact notation. The greatest common divisor of a=68 and b=30 can be calculated like this:
g=gcd(68,30)↑−−(−2)=gcd(8,30)(−3)−−↑ =gcd(8,6)↑−−(−1)=gcd(2,6)(−3)−−↑=gcd(2,0)=2, where ↑−−(−2) in the first step means that −2 times 30 is added to 68 (the gcd does not change when adding a multiple of one number to the other).
Applying the green-indicated additions of multiples analogously to equations, starting with a=1a+0b and b=0a+1b, leads to g=4a−9b, according to the adjacent calculations (the corresponding table far right uses row operations).
… excerpt ends here. Continue reading the full article.
