@[irreducible, extern lean_nat_gcd]
Computes the greatest common divisor of two natural numbers.
This reference implementation via the Euclidean algorithm
is overridden in both the kernel and the compiler to efficiently
evaluate using the "bignum" representation (see Nat
).
The definition provided here is the logical model
(and it is soundness-critical that they coincide).
The GCD of two natural numbers is the largest natural number
that divides both arguments.
In particular, the GCD of a number and 0
is the number itself:
example : Nat.gcd 10 15 = 5 := rfl
example : Nat.gcd 0 5 = 5 := rfl
example : Nat.gcd 7 0 = 7 := rfl
Instances For
Represent a divisor of m * n
as a product of a divisor of m
and a divisor of n
.
Equations
- Nat.prod_dvd_and_dvd_of_dvd_prod H = if h0 : k.gcd m = 0 then ⟨(⟨0, ⋯⟩, ⟨n, ⋯⟩), ⋯⟩ else let_fun hd := ⋯; ⟨(⟨k.gcd m, ⋯⟩, ⟨k / k.gcd m, ⋯⟩), ⋯⟩