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

Commit af43a2b

Browse files
ChrisHughes24mergify[bot]
authored andcommitted
feat(data/nat/enat): add_right_cancel and other (#1705)
1 parent 0d94020 commit af43a2b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/data/nat/enat.lean

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ lt_of_le_of_ne le_top (λ h, absurd (congr_arg dom h) true_ne_false)
110110

111111
lemma ne_top_iff {x : enat} : x ≠ ⊤ ↔ ∃(n : ℕ), x = n := roption.ne_none_iff
112112

113+
lemma ne_top_iff_dom {x : enat} : x ≠ ⊤ ↔ x.dom :=
114+
by classical; exact not_iff_comm.1 roption.eq_none_iff'.symm
115+
113116
lemma ne_top_of_lt {x y : enat} (h : x < y) : x ≠ ⊤ :=
114117
ne_of_lt $ lt_of_lt_of_le h lattice.le_top
115118

@@ -223,6 +226,21 @@ begin
223226
apply_mod_cast nat.lt_succ_of_le, apply_mod_cast h
224227
end
225228

229+
lemma add_eq_top_iff {a b : enat} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ :=
230+
by apply enat.cases_on a; apply enat.cases_on b;
231+
simp; simp only [(enat.coe_add _ _).symm, enat.coe_ne_top]; simp
232+
233+
protected lemma add_right_cancel_iff {a b c : enat} (hc : c ≠ ⊤) : a + c = b + c ↔ a = b :=
234+
begin
235+
rcases ne_top_iff.1 hc with ⟨c, rfl⟩,
236+
apply enat.cases_on a; apply enat.cases_on b;
237+
simp [add_eq_top_iff, coe_ne_top, @eq_comm _ (⊤ : enat)];
238+
simp only [(enat.coe_add _ _).symm, add_left_cancel_iff, enat.coe_inj]; tauto
239+
end
240+
241+
protected lemma add_left_cancel_iff {a b c : enat} (ha : a ≠ ⊤) : a + b = a + c ↔ b = c :=
242+
by rw [add_comm a, add_comm a, enat.add_right_cancel_iff ha]
243+
226244
section with_top
227245

228246
/-- Computably converts an `enat` to a `with_top ℕ`. -/

0 commit comments

Comments
 (0)