lean4-htt/library/init/data/nat/gcd.lean
Mario Carneiro b557d9012d refactor(init/data/nat/gcd): swap args in gcd.induction
to match swapped induction arg of gcd
2017-07-05 12:37:54 -07:00

56 lines
No EOL
1.6 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro
Definitions and properties of gcd, lcm, and coprime.
-/
prelude
import init.data.nat.lemmas init.meta.well_founded_tactics
open well_founded
namespace nat
/- gcd -/
def gcd : nat → nat → nat
| 0 y := y
| (succ x) y := have y % succ x < succ x, from mod_lt _ $ succ_pos _,
gcd (y % succ x) (succ x)
@[simp] theorem gcd_zero_left (x : nat) : gcd 0 x = x := by simp [gcd]
@[simp] theorem gcd_succ (x y : nat) : gcd (succ x) y = gcd (y % succ x) (succ x) :=
by simp [gcd]
@[simp] theorem gcd_one_left (n : ) : gcd 1 n = 1 := by simp [gcd]
theorem gcd_def (x y : ) : gcd x y = if x = 0 then y else gcd (y % x) x :=
by cases x; simp [gcd, succ_ne_zero]
@[simp] theorem gcd_self (n : ) : gcd n n = n :=
by cases n; simp [gcd, mod_self]
@[simp] theorem gcd_zero_right (n : ) : gcd n 0 = n :=
by cases n; simp [gcd]
theorem gcd_rec (m n : ) : gcd m n = gcd (n % m) m :=
by cases m; simp [gcd]
@[elab_as_eliminator]
theorem gcd.induction {P : → Prop}
(m n : )
(H0 : ∀n, P 0 n)
(H1 : ∀m n, 0 < m → P (n % m) m → P m n) :
P m n :=
@induction _ _ lt_wf (λm, ∀n, P m n) m (λk IH,
by {induction k with k ih, exact H0,
exact λn, H1 _ _ (succ_pos _) (IH _ (mod_lt _ (succ_pos _)) _)}) n
def lcm (m n : ) : := m * n / (gcd m n)
@[reducible] def coprime (m n : ) : Prop := gcd m n = 1
end nat