Skip to content

Commit

Permalink
feat(data/nat/basic): four lemmas on nat and int division (#13991)
Browse files Browse the repository at this point in the history
`lt_div_iff_mul_lt (hnd : d ∣ n) : a < n / d ↔ d * a < n`

`div_left_inj (hda : d ∣ a) (hdb : d ∣ b) : a / d = b / d ↔ a = b` (for `ℕ` and `ℤ`)

`div_lt_div_of_lt_of_dvd (hdb : d ∣ b) (h : a < b) : a / d < b / d`
  • Loading branch information
stuart-presnell committed May 12, 2022
1 parent 4b3988a commit 3c1ced3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/data/int/basic.lean
Expand Up @@ -913,6 +913,13 @@ end
lemma sub_div_of_dvd_sub {a b c : ℤ} (hcab : c ∣ (a - b)) : (a - b) / c = a / c - b / c :=
by rw [eq_sub_iff_add_eq, ← int.add_div_of_dvd_left hcab, sub_add_cancel]

@[simp]
protected lemma div_left_inj {a b d : ℤ} (hda : d ∣ a) (hdb : d ∣ b) : a / d = b / d ↔ a = b :=
begin
refine ⟨λ h, _, congr_arg _⟩,
rw [←int.mul_div_cancel' hda, ←int.mul_div_cancel' hdb, h],
end

lemma nat_abs_sign (z : ℤ) :
z.sign.nat_abs = if z = 0 then 0 else 1 :=
by rcases z with (_ | _) | _; refl
Expand Down
16 changes: 16 additions & 0 deletions src/data/nat/basic.lean
Expand Up @@ -886,6 +886,12 @@ protected theorem eq_mul_of_div_eq_left {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b
a = c * b :=
by rw [mul_comm, nat.eq_mul_of_div_eq_right H1 H2]

protected lemma lt_div_iff_mul_lt {n d : ℕ} (hnd : d ∣ n) (a : ℕ) : a < n / d ↔ d * a < n :=
begin
rcases d.eq_zero_or_pos with rfl | hd0, { simp [zero_dvd_iff.mp hnd] },
rw [←mul_lt_mul_left hd0, ←nat.eq_mul_of_div_eq_right hnd rfl],
end

protected theorem mul_div_cancel_left' {a b : ℕ} (Hd : a ∣ b) : a * (b / a) = b :=
by rw [mul_comm,nat.div_mul_cancel Hd]

Expand Down Expand Up @@ -913,6 +919,13 @@ begin
{ intros h, rw h },
end

@[simp]
protected lemma div_left_inj {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b) : a / d = b / d ↔ a = b :=
begin
refine ⟨λ h, _, congr_arg _⟩,
rw [←nat.mul_div_cancel' hda, ←nat.mul_div_cancel' hdb, h],
end

/-! ### `mod`, `dvd` -/

lemma div_add_mod (m k : ℕ) : k * (m / k) + m % k = m :=
Expand Down Expand Up @@ -1252,6 +1265,9 @@ lemma dvd_left_iff_eq {m n : ℕ} : (∀ a : ℕ, a ∣ m ↔ a ∣ n) ↔ m = n
lemma dvd_left_injective : function.injective ((∣) : ℕ → ℕ → Prop) :=
λ m n h, dvd_right_iff_eq.mp $ λ a, iff_of_eq (congr_fun h a)

lemma div_lt_div_of_lt_of_dvd {a b d : ℕ} (hdb : d ∣ b) (h : a < b) : a / d < b / d :=
by { rw nat.lt_div_iff_mul_lt hdb, exact lt_of_le_of_lt (mul_div_le a d) h }

/-! ### `find` -/
section find

Expand Down

0 comments on commit 3c1ced3

Please sign in to comment.