Bezout's Identity

lean4-proofnumber-theorylinear-combinationsvisualization
gcd(a,b)=ax+by\gcd(a,b) = a \cdot x + b \cdot y

Statement

For any integers aa and bb, there exist integers xx and yy such that:

gcd(a,b)=ax+by\gcd(a, b) = a \cdot x + b \cdot y

These are called Bezout coefficients. The gcd is the smallest positive integer expressible as such a combination, and every integer linear combination of aa and bb is a multiple of gcd(a,b)\gcd(a,b).

In particular, aa and bb are coprime (i.e. gcd(a,b)=1\gcd(a,b)=1) if and only if there exist integers with ax+by=1ax + by = 1.

Visualization

Extended Euclidean algorithm for gcd(35,15)\gcd(35, 15):

StepEquationxxyy
135=2×15+535 = 2 \times 15 + 5
215=3×5+015 = 3 \times 5 + 0
Back-sub: 5=352×155 = 35 - 2 \times 15112-2

Check: 351+15(2)=3530=5=gcd(35,15)35 \cdot 1 + 15 \cdot (-2) = 35 - 30 = 5 = \gcd(35, 15). ✓

Lattice of multiples for a=6,b=9a=6, b=9:

Multiples of 6:  ..., -12, -6,  0,  6, 12, 18, 24, 30, ...
Multiples of 9:  ..., -18, -9,  0,  9, 18, 27, 36, ...
Combinations:    ...,  -3,  0,  3,  6,  9, 12, 15, ...
                       ↑ smallest positive = gcd(6,9) = 3

Coefficients: 3=6(1)+913 = 6 \cdot (-1) + 9 \cdot 1 (and also 3=62+9(1)3 = 6 \cdot 2 + 9 \cdot (-1), etc.)

Proof Sketch

  1. Existence via the algorithm. The Euclidean AlgorithmEuclidean Algorithmgcd(m,n)=gcd(nmodm,m)\gcd(m,n) = \gcd(n \bmod m, m)The oldest surviving algorithm, computing the greatest common divisor via iterated remaindersRead more → maintains coefficients (s,t)(s, t) such that the current remainder equals as+btas + bt. Initialising with (s,t)=(1,0)(s,t) = (1,0) for aa and (0,1)(0,1) for bb, each step updates (s,t)(s,t) by integer row operations. The final nonzero remainder is gcd(a,b)\gcd(a,b).

  2. Minimality. Let dd be the smallest positive integer linear combination of aa and bb. Then dad \mid a and dbd \mid b (divide with remainder and use minimality), so dgcd(a,b)d \mid \gcd(a,b). But gcd(a,b)\gcd(a,b) is a linear combination, so gcd(a,b)d\gcd(a,b) \le d. Thus d=gcd(a,b)d = \gcd(a,b).

  3. All combinations are multiples. If c=ax+byc = ax + by then gcd(a,b)a\gcd(a,b) \mid a and gcd(a,b)b\gcd(a,b) \mid b implies gcd(a,b)c\gcd(a,b) \mid c.

Connections

Bezout's Identity gives the bridge from the Euclidean AlgorithmEuclidean Algorithmgcd(m,n)=gcd(nmodm,m)\gcd(m,n) = \gcd(n \bmod m, m)The oldest surviving algorithm, computing the greatest common divisor via iterated remaindersRead more → to modular arithmetic. It directly implies that in Z/pZ\mathbb{Z}/p\mathbb{Z} every nonzero element has a multiplicative inverse (feeding into Fermat's Little TheoremFermat's Little Theoremapa(modp)a^p \equiv a \pmod{p}For prime p, a^p is congruent to a mod pRead more →). It is also the key lemma in proving the Chinese Remainder TheoremChinese Remainder TheoremZ/mnZZ/mZ×Z/nZ\mathbb{Z}/mn\mathbb{Z} \cong \mathbb{Z}/m\mathbb{Z} \times \mathbb{Z}/n\mathbb{Z}Simultaneous congruences with coprime moduli have a unique solution mod their productRead more → (constructing the simultaneous solution) and Euler's Totient FunctionEuler's Totient Functionaφ(n)1(modn)a^{\varphi(n)} \equiv 1 \pmod{n}φ(n) counts integers up to n coprime to n, and governs modular exponentiationRead more → (characterising units).

Lean4 Proof

/-- **Bezout's identity**: the gcd is an integer linear combination of the two inputs.
    Mathlib provides the Bezout coefficients `Int.gcdA` and `Int.gcdB` and
    proves the identity as `Int.gcd_eq_gcd_ab`. -/
theorem bezout (a b : ) :
     x y : , (Nat.gcd a b : ) = a * x + b * y :=
  Int.gcdA a b, Int.gcdB a b, (Int.gcd_eq_gcd_ab a b).symm