Skip to content

Commit

Permalink
feat: emod_pos_of_not_dvd for Nat and Int (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em authored Dec 14, 2023
1 parent 5d14993 commit dbaf8f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Std/Data/Int/DivMod.lean
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ theorem dvd_iff_mod_eq_zero (a b : Int) : a ∣ b ↔ mod b a = 0 :=
theorem dvd_iff_emod_eq_zero (a b : Int) : a ∣ b ↔ b % a = 0 :=
⟨emod_eq_zero_of_dvd, dvd_of_emod_eq_zero⟩

theorem emod_pos_of_not_dvd {a b : Int} (h : ¬ a ∣ b) : a = 00 < b % a := by
rw [dvd_iff_emod_eq_zero] at h
if w : a = 0 then simp_all
else exact Or.inr (Int.lt_iff_le_and_ne.mpr ⟨emod_nonneg b w, Ne.symm h⟩)

instance decidableDvd : DecidableRel (α := Int) (· ∣ ·) := fun _ _ =>
decidable_of_decidable_of_iff (dvd_iff_mod_eq_zero ..).symm

Expand Down
4 changes: 4 additions & 0 deletions Std/Data/Nat/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,10 @@ theorem mod_eq_zero_of_dvd {m n : Nat} (H : m ∣ n) : n % m = 0 := by
theorem dvd_iff_mod_eq_zero (m n : Nat) : m ∣ n ↔ n % m = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩

theorem emod_pos_of_not_dvd {a b : Nat} (h : ¬ a ∣ b) : 0 < b % a := by
rw [dvd_iff_mod_eq_zero] at h
exact Nat.pos_of_ne_zero h

instance decidable_dvd : @DecidableRel Nat (·∣·) :=
fun _ _ => decidable_of_decidable_of_iff (dvd_iff_mod_eq_zero _ _).symm

Expand Down

0 comments on commit dbaf8f0

Please sign in to comment.