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

Commit f24cc28

Browse files
committed
chore(data/finset/locally_finite): lemmas about open intervals (#18533)
We had `cons` lemmas for the other four cases, but not these two. The new lemmas golf a proof a little. Also adds some docstrings to makes these lemmas easier to find. Forward-ported in leanprover-community/mathlib4#2812
1 parent da420a8 commit f24cc28

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/data/finset/locally_finite.lean

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,22 @@ end decidable_eq
332332

333333
-- Those lemmas are purposefully the other way around
334334

335+
/-- `finset.cons` version of `finset.Ico_insert_right`. -/
335336
lemma Icc_eq_cons_Ico (h : a ≤ b) : Icc a b = (Ico a b).cons b right_not_mem_Ico :=
336337
by { classical, rw [cons_eq_insert, Ico_insert_right h] }
337338

339+
/-- `finset.cons` version of `finset.Ioc_insert_left`. -/
338340
lemma Icc_eq_cons_Ioc (h : a ≤ b) : Icc a b = (Ioc a b).cons a left_not_mem_Ioc :=
339341
by { classical, rw [cons_eq_insert, Ioc_insert_left h] }
340342

343+
/-- `finset.cons` version of `finset.Ioo_insert_right`. -/
344+
lemma Ioc_eq_cons_Ioo (h : a < b) : Ioc a b = (Ioo a b).cons b right_not_mem_Ioo :=
345+
by { classical, rw [cons_eq_insert, Ioo_insert_right h], }
346+
347+
/-- `finset.cons` version of `finset.Ioo_insert_left`. -/
348+
lemma Ico_eq_cons_Ioo (h : a < b) : Ico a b = (Ioo a b).cons a left_not_mem_Ioo :=
349+
by { classical, rw [cons_eq_insert, Ioo_insert_left h] }
350+
341351
lemma Ico_filter_le_left {a b : α} [decidable_pred (≤ a)] (hab : a < b) :
342352
(Ico a b).filter (λ x, x ≤ a) = {a} :=
343353
begin
@@ -350,7 +360,7 @@ lemma card_Ico_eq_card_Icc_sub_one (a b : α) : (Ico a b).card = (Icc a b).card
350360
begin
351361
classical,
352362
by_cases h : a ≤ b,
353-
{ rw [←Ico_insert_right h, card_insert_of_not_mem right_not_mem_Ico],
363+
{ rw [Icc_eq_cons_Ico h, card_cons],
354364
exact (nat.add_sub_cancel _ _).symm },
355365
{ rw [Ico_eq_empty (λ h', h h'.le), Icc_eq_empty h, card_empty, zero_tsub] }
356366
end
@@ -361,12 +371,10 @@ lemma card_Ioc_eq_card_Icc_sub_one (a b : α) : (Ioc a b).card = (Icc a b).card
361371
lemma card_Ioo_eq_card_Ico_sub_one (a b : α) : (Ioo a b).card = (Ico a b).card - 1 :=
362372
begin
363373
classical,
364-
by_cases h : a ≤ b,
365-
{ obtain rfl | h' := h.eq_or_lt,
366-
{ rw [Ioo_self, Ico_self, card_empty] },
367-
rw [←Ioo_insert_left h', card_insert_of_not_mem left_not_mem_Ioo],
374+
by_cases h : a < b,
375+
{ rw [Ico_eq_cons_Ioo h, card_cons],
368376
exact (nat.add_sub_cancel _ _).symm },
369-
{ rw [Ioo_eq_empty (λ h', h h'.le), Ico_eq_empty (λ h', h h'.le), card_empty, zero_tsub] }
377+
{ rw [Ioo_eq_empty h, Ico_eq_empty h, card_empty, zero_tsub] }
370378
end
371379

372380
lemma card_Ioo_eq_card_Ioc_sub_one (a b : α) : (Ioo a b).card = (Ioc a b).card - 1 :=
@@ -391,6 +399,7 @@ by { ext, simp_rw [finset.mem_insert, mem_Ici, mem_Ioi, le_iff_lt_or_eq, or_comm
391399
@[simp] lemma not_mem_Ioi_self {b : α} : b ∉ Ioi b := λ h, lt_irrefl _ (mem_Ioi.1 h)
392400

393401
-- Purposefully written the other way around
402+
/-- `finset.cons` version of `finset.Ioi_insert`. -/
394403
lemma Ici_eq_cons_Ioi (a : α) : Ici a = (Ioi a).cons a not_mem_Ioi_self :=
395404
by { classical, rw [cons_eq_insert, Ioi_insert] }
396405

@@ -410,6 +419,7 @@ by { ext, simp_rw [finset.mem_insert, mem_Iic, mem_Iio, le_iff_lt_or_eq, or_comm
410419
@[simp] lemma not_mem_Iio_self {b : α} : b ∉ Iio b := λ h, lt_irrefl _ (mem_Iio.1 h)
411420

412421
-- Purposefully written the other way around
422+
/-- `finset.cons` version of `finset.Iio_insert`. -/
413423
lemma Iic_eq_cons_Iio (b : α) : Iic b = (Iio b).cons b not_mem_Iio_self :=
414424
by { classical, rw [cons_eq_insert, Iio_insert] }
415425

0 commit comments

Comments
 (0)