Bezout's Equation and The GCD

For integers a,ba,b consider the linear form ax+byax + by. It takes on all multiples of aa, all multiples of bb and all sums and differences of those numbers. Notice that when a,ba,b have a common factor (e.g. they are both even) then every value the linear form takes on will also be a multiple of that common factor.

It turns out that the smallest positive value this form takes on is the greatest common divisor of aa and bb. The best way to see this is along with the algorithm to compute it. In fact we'll present an algorithm to compute x,y,(a,b)x,y,(a,b) (the notation (a,b)(a,b) denotes the gcd of the two numbers) in ax+by=(a,b)ax + by = (a,b)

Combining linear equations

Starting with

a1+b0=aa \cdot 1 + b \cdot 0 = a a0+b1=ba \cdot 0 + b \cdot 1 = b

then, supposing a>ba > b we can get represent a smaller number c=abc = a - b with this form by subtracting so that we now have:

a0+b1=ba \cdot 0 + b \cdot 1 = b a1+b(1)=ca \cdot 1 + b \cdot (-1) = c

continuing in this way you find the integers x,yx,y that produce the minimum positive value.

Example

Here's an example of running this procedure for the form 6x+4y6x + 4y, to be more compact I'll write the equations as a table of numbers.

(106014)\begin{pmatrix} 1 & 0 & 6 \\ 0 & 1 & 4 \end{pmatrix} (112014)\begin{pmatrix} 1 & -1 & 2 \\ 0 & 1 & 4 \end{pmatrix} (112122)\begin{pmatrix} 1 & -1 & 2 \\ -1 & 2 & 2 \end{pmatrix} (112230)\begin{pmatrix} 1 & -1 & 2 \\ -2 & 3 & 0 \end{pmatrix}

Upon reaching 0 the algorithm is complete, and the result is that (6,4)=2(6,4) = 2 and 61+5(1)=46 \cdot 1 + 5 \cdot (-1) = 4

Proof

There are two facts which are used to justify the correctness of algorithm.

Lemma 1: (a,0)=a(a,0) = a.

Lemma 2: a>ba > b implies (a,b)=(ab,b)(a,b) = (a-b,b).