Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 1236ced

Browse files
ChrisHughes24mergify[bot]
authored andcommitted
feat(data/nat/basic): succ_div (#1664)
* feat(data/nat/basic): succ_div Rather long proof, but it was the best I could do. * Update basic.lean * add the two lemmas for each case * get rid of positivity assumption
1 parent 1c24f92 commit 1236ced

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/data/nat/basic.lean

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,47 @@ exists_congr $ λ d, by rw [mul_assoc, nat.mul_left_inj ha]
511511
protected theorem mul_dvd_mul_iff_right {a b c : ℕ} (hc : 0 < c) : a * c ∣ b * c ↔ a ∣ b :=
512512
exists_congr $ λ d, by rw [mul_right_comm, nat.mul_right_inj hc]
513513

514+
lemma succ_div : ∀ (a b : ℕ), (a + 1) / b =
515+
a / b + if b ∣ a + 1 then 1 else 0
516+
| a 0 := by simp
517+
| 0 1 := rfl
518+
| 0 (b+2) := have hb2 : b + 2 > 1, from dec_trivial,
519+
by simp [ne_of_gt hb2, div_eq_of_lt hb2]
520+
| (a+1) (b+1) := begin
521+
rw [nat.div_def], conv_rhs { rw nat.div_def },
522+
by_cases hb_eq_a : b = a + 1,
523+
{ simp [hb_eq_a, le_refl] },
524+
by_cases hb_le_a1 : b ≤ a + 1,
525+
{ have hb_le_a : b ≤ a, from le_of_lt_succ (lt_of_le_of_ne hb_le_a1 hb_eq_a),
526+
have h₁ : (0 < b + 1 ∧ b + 1 ≤ a + 1 + 1),
527+
from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a1⟩,
528+
have h₂ : (0 < b + 1 ∧ b + 1 ≤ a + 1),
529+
from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a⟩,
530+
have dvd_iff : b + 1 ∣ a - b + 1 ↔ b + 1 ∣ a + 1 + 1,
531+
{ rw [nat.dvd_add_iff_left (dvd_refl (b + 1)),
532+
← nat.add_sub_add_right a 1 b, add_comm (_ - _), add_assoc,
533+
nat.sub_add_cancel (succ_le_succ hb_le_a)],
534+
simp },
535+
have wf : a - b < a + 1, from lt_succ_of_le (nat.sub_le_self _ _),
536+
rw [if_pos h₁, if_pos h₂, nat.add_sub_add_right, nat.sub_add_comm hb_le_a,
537+
by exact have _ := wf, succ_div (a - b),
538+
nat.add_sub_add_right],
539+
simp [dvd_iff, succ_eq_add_one], congr },
540+
{ have hba : ¬ b ≤ a,
541+
from not_le_of_gt (lt_trans (lt_succ_self a) (lt_of_not_ge hb_le_a1)),
542+
have hb_dvd_a : ¬ b + 1 ∣ a + 2,
543+
from λ h, hb_le_a1 (le_of_succ_le_succ (le_of_dvd (succ_pos _) h)),
544+
simp [hba, hb_le_a1, hb_dvd_a], }
545+
end
546+
547+
lemma succ_div_of_dvd {a b : ℕ} (hba : b ∣ a + 1) :
548+
(a + 1) / b = a / b + 1 :=
549+
by rw [succ_div, if_pos hba]
550+
551+
lemma succ_div_of_not_dvd {a b : ℕ} (hba : ¬ b ∣ a + 1) :
552+
(a + 1) / b = a / b :=
553+
by rw [succ_div, if_neg hba, add_zero]
554+
514555
@[simp] theorem mod_mod (a n : ℕ) : (a % n) % n = a % n :=
515556
(eq_zero_or_pos n).elim
516557
(λ n0, by simp [n0])

0 commit comments

Comments
 (0)