Theorem·T19
Existence of the gcd and the Euclidean algorithm
The greatest common divisor always exists and is computed by repeated division with remainder.
For all
not both
, the greatest common divisor
exists, and it is computed by the Euclidean algorithm: for
,
and for
,
where
is the remainder of
divided by
.
In words
For any natural numbers a and b, not both zero, their greatest common divisor exists, and the Euclidean algorithm computes it: for a positive, the gcd of a and 0 is a itself, and for b positive, the gcd of a and b equals the gcd of b and r, where r is the remainder of a divided by b.
Never needed: F05 · F10 · F13 · A02 · A03 · A04 · A05 · A07 (computed from the citation graph, not asserted).
Proof
- 1Uniqueness, so that 'the' gcd is well posed: if and both satisfy the characterisation for , then each is a common divisor and the other absorbs every common divisor, so and . Since are not both , say ; then and each divide the nonzero and so are themselves nonzero (if then gives , D030). Now L19 (vii) gives and , and antisymmetry of the order (L16 rules out both and ) forces . Existence is proved by strong induction on .
- 2Let (Separation). By T08 it suffices to show: if every lies in , then .
- 3Case : then . Put . Then (L19 (i)) and ((iii)), and any common divisor of and has . So meets the characterisation: .
- 4
- 5is the gcd of . Note first that , since (L12) is a multiple of (D030). Now : from and , transitivity L19 (iv) gives , and with , ((v)). So is a common divisor of and . Conversely, any common divisor of and divides : from and , ((iv)); with , this gives ((vi)). Then is a common divisor of and , hence . Thus satisfies the characterisation for , so .
- 6Both cases give , so T08 yields : the gcd exists for every pair not both , and the two displayed equations compute it.
∎
Remarks
This is the oldest nontrivial algorithm, from Euclid's Elements (Book VII). Termination is guaranteed because the second argument strictly decreases (
) and the naturals are well ordered. The same descent, carried with the identity
back up the chain, expresses
as a difference of multiples of
and
(Bezout's identity); a clean statement of that awaits the integers. Reducing
is exactly the step used in practice.