Skip to content

Commit f4243b9

Browse files
committed
feat: Lemmas about the iterated shadow (#7863)
Move the lemmas characterising `Covby` on `Finset α` from `Data.Finset.Interval` to `Data.Finset.Basic`. Golf the other proofs in `Data.Finset.Interval` and make sure the lemma names reflect whether each lemma is about `insert` or `cons`.
1 parent 2c48e92 commit f4243b9

File tree

4 files changed

+213
-166
lines changed

4 files changed

+213
-166
lines changed

Mathlib/Combinatorics/SetFamily/Shadow.lean

Lines changed: 132 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ theorem shadow_empty : ∂ (∅ : Finset (Finset α)) = ∅ :=
7171
rfl
7272
#align finset.shadow_empty Finset.shadow_empty
7373

74+
@[simp] lemma shadow_iterate_empty (k : ℕ) : ∂^[k] (∅ : Finset (Finset α)) = ∅ := by
75+
induction' k <;> simp [*, shadow_empty]
76+
7477
@[simp]
7578
theorem shadow_singleton_empty : ∂ ({∅} : Finset (Finset α)) = ∅ :=
7679
rfl
@@ -83,34 +86,84 @@ theorem shadow_monotone : Monotone (shadow : Finset (Finset α) → Finset (Fins
8386
sup_mono
8487
#align finset.shadow_monotone Finset.shadow_monotone
8588

86-
/-- `s` is in the shadow of `𝒜` iff there is a `t ∈ 𝒜` from which we can remove one element to
87-
get `s`. -/
88-
theorem mem_shadow_iff : s ∈ ∂ 𝒜 ↔ ∃ t ∈ 𝒜, ∃ a ∈ t, erase t a = s := by
89+
/-- `t` is in the shadow of `𝒜` iff there is a `s ∈ 𝒜` from which we can remove one element to
90+
get `t`. -/
91+
lemma mem_shadow_iff : t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, ∃ a ∈ s, erase s a = t := by
8992
simp only [shadow, mem_sup, mem_image]
9093
#align finset.mem_shadow_iff Finset.mem_shadow_iff
9194

9295
theorem erase_mem_shadow (hs : s ∈ 𝒜) (ha : a ∈ s) : erase s a ∈ ∂ 𝒜 :=
9396
mem_shadow_iff.2 ⟨s, hs, a, ha, rfl⟩
9497
#align finset.erase_mem_shadow Finset.erase_mem_shadow
9598

99+
/-- `t ∈ ∂𝒜` iff `t` is exactly one element less than something from `𝒜`.
100+
101+
See also `Finset.mem_shadow_iff_exists_mem_card_add_one`. -/
102+
lemma mem_shadow_iff_exists_sdiff : t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ (s \ t).card = 1 := by
103+
simp_rw [mem_shadow_iff, ←covby_iff_card_sdiff_eq_one, covby_iff_exists_erase, eq_comm]
104+
96105
/-- `t` is in the shadow of `𝒜` iff we can add an element to it so that the resulting finset is in
97106
`𝒜`. -/
98-
theorem mem_shadow_iff_insert_mem : s ∈ ∂ 𝒜 ↔ ∃ (a : _) (_ : a ∉ s), insert a s ∈ 𝒜 := by
99-
refine' mem_shadow_iff.trans ⟨_, _⟩
100-
· rintro ⟨s, hs, a, ha, rfl⟩
101-
refine' ⟨a, not_mem_erase a s, _⟩
102-
rwa [insert_erase ha]
103-
· rintro ⟨a, ha, hs⟩
104-
exact ⟨insert a s, hs, a, mem_insert_self _ _, erase_insert ha⟩
107+
lemma mem_shadow_iff_insert_mem : t ∈ ∂ 𝒜 ↔ ∃ a, a ∉ t ∧ insert a t ∈ 𝒜 := by
108+
simp_rw [mem_shadow_iff_exists_sdiff, ←covby_iff_card_sdiff_eq_one, covby_iff_exists_insert]
109+
aesop
105110
#align finset.mem_shadow_iff_insert_mem Finset.mem_shadow_iff_insert_mem
106111

112+
/-- `s ∈ ∂ 𝒜` iff `s` is exactly one element less than something from `𝒜`.
113+
114+
See also `Finset.mem_shadow_iff_exists_sdiff`. -/
115+
lemma mem_shadow_iff_exists_mem_card_add_one :
116+
t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ s.card = t.card + 1 := by
117+
refine mem_shadow_iff_exists_sdiff.trans $ exists_congr fun t ↦ and_congr_right fun _ ↦
118+
and_congr_right fun hst ↦ ?_
119+
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
120+
exact card_mono hst
121+
#align finset.mem_shadow_iff_exists_mem_card_add_one Finset.mem_shadow_iff_exists_mem_card_add_one
122+
123+
lemma mem_shadow_iterate_iff_exists_card :
124+
t ∈ ∂^[k] 𝒜 ↔ ∃ u : Finset α, u.card = k ∧ Disjoint t u ∧ t ∪ u ∈ 𝒜 := by
125+
induction' k with k ih generalizing t
126+
· simp
127+
simp only [mem_shadow_iff_insert_mem, ih, Function.iterate_succ_apply', card_eq_succ]
128+
aesop
129+
130+
/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something from `𝒜`.
131+
132+
See also `Finset.mem_shadow_iff_exists_mem_card_add`. -/
133+
lemma mem_shadow_iterate_iff_exists_sdiff : t ∈ ∂^[k] 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ (s \ t).card = k := by
134+
rw [mem_shadow_iterate_iff_exists_card]
135+
constructor
136+
· rintro ⟨u, rfl, htu, hsuA⟩
137+
exact ⟨_, hsuA, subset_union_left _ _, by rw [union_sdiff_cancel_left htu]⟩
138+
· rintro ⟨s, hs, hts, rfl⟩
139+
refine ⟨s \ t, rfl, disjoint_sdiff, ?_⟩
140+
rwa [union_sdiff_self_eq_union, union_eq_right.2 hts]
141+
142+
/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something in `𝒜`.
143+
144+
See also `Finset.mem_shadow_iterate_iff_exists_sdiff`. -/
145+
lemma mem_shadow_iterate_iff_exists_mem_card_add :
146+
t ∈ ∂^[k] 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ s.card = t.card + k := by
147+
refine mem_shadow_iterate_iff_exists_sdiff.trans $ exists_congr fun t ↦ and_congr_right fun _ ↦
148+
and_congr_right fun hst ↦ ?_
149+
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
150+
exact card_mono hst
151+
#align finset.mem_shadow_iff_exists_mem_card_add Finset.mem_shadow_iterate_iff_exists_mem_card_add
152+
107153
/-- The shadow of a family of `r`-sets is a family of `r - 1`-sets. -/
108-
protected theorem Set.Sized.shadow (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
154+
protected theorem _root_.Set.Sized.shadow (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
109155
(∂ 𝒜 : Set (Finset α)).Sized (r - 1) := by
110156
intro A h
111157
obtain ⟨A, hA, i, hi, rfl⟩ := mem_shadow_iff.1 h
112158
rw [card_erase_of_mem hi, h𝒜 hA]
113-
#align finset.set.sized.shadow Finset.Set.Sized.shadow
159+
#align finset.set.sized.shadow Set.Sized.shadow
160+
161+
/-- The `k`-th shadow of a family of `r`-sets is a family of `r - k`-sets. -/
162+
lemma _root_.Set.Sized.shadow_iterate (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
163+
(∂^[k] 𝒜 : Set (Finset α)).Sized (r - k) := by
164+
simp_rw [Set.Sized, mem_coe, mem_shadow_iterate_iff_exists_sdiff]
165+
rintro t ⟨s, hs, hts, rfl⟩
166+
rw [card_sdiff hts, ←h𝒜 hs, Nat.sub_sub_self (card_le_of_subset hts)]
114167

115168
theorem sized_shadow_iff (h : ∅ ∉ 𝒜) :
116169
(∂ 𝒜 : Set (Finset α)).Sized r ↔ (𝒜 : Set (Finset α)).Sized (r + 1) := by
@@ -119,55 +172,12 @@ theorem sized_shadow_iff (h : ∅ ∉ 𝒜) :
119172
rw [← h𝒜 (erase_mem_shadow hs ha), card_erase_add_one ha]
120173
#align finset.sized_shadow_iff Finset.sized_shadow_iff
121174

122-
/-- `s ∈ ∂ 𝒜` iff `s` is exactly one element less than something from `𝒜` -/
123-
theorem mem_shadow_iff_exists_mem_card_add_one :
124-
s ∈ ∂ 𝒜 ↔ ∃ t ∈ 𝒜, s ⊆ t ∧ t.card = s.card + 1 := by
125-
refine' mem_shadow_iff_insert_mem.trans ⟨_, _⟩
126-
· rintro ⟨a, ha, hs⟩
127-
exact ⟨insert a s, hs, subset_insert _ _, card_insert_of_not_mem ha⟩
128-
· rintro ⟨t, ht, hst, h⟩
129-
obtain ⟨a, ha⟩ : ∃ a, t \ s = {a} :=
130-
card_eq_one.1 (by rw [card_sdiff hst, h, add_tsub_cancel_left])
131-
exact
132-
⟨a, fun hat => not_mem_sdiff_of_mem_right hat (ha.superset <| mem_singleton_self a),
133-
by rwa [insert_eq a s, ← ha, sdiff_union_of_subset hst]⟩
134-
#align finset.mem_shadow_iff_exists_mem_card_add_one Finset.mem_shadow_iff_exists_mem_card_add_one
135-
136175
/-- Being in the shadow of `𝒜` means we have a superset in `𝒜`. -/
137-
theorem exists_subset_of_mem_shadow (hs : s ∈ ∂ 𝒜) : ∃ t ∈ 𝒜, st :=
176+
lemma exists_subset_of_mem_shadow (hs : t ∈ ∂ 𝒜) : ∃ s ∈ 𝒜, ts :=
138177
let ⟨t, ht, hst⟩ := mem_shadow_iff_exists_mem_card_add_one.1 hs
139178
⟨t, ht, hst.1
140179
#align finset.exists_subset_of_mem_shadow Finset.exists_subset_of_mem_shadow
141180

142-
/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something in `𝒜`. -/
143-
theorem mem_shadow_iff_exists_mem_card_add :
144-
s ∈ ∂ ^[k] 𝒜 ↔ ∃ t ∈ 𝒜, s ⊆ t ∧ t.card = s.card + k := by
145-
induction' k with k ih generalizing 𝒜 s
146-
· refine' ⟨fun hs => ⟨s, hs, Subset.refl _, rfl⟩, _⟩
147-
rintro ⟨t, ht, hst, hcard⟩
148-
rwa [eq_of_subset_of_card_le hst hcard.le]
149-
simp only [exists_prop, Function.comp_apply, Function.iterate_succ]
150-
refine' ih.trans _
151-
clear ih
152-
constructor
153-
· rintro ⟨t, ht, hst, hcardst⟩
154-
obtain ⟨u, hu, htu, hcardtu⟩ := mem_shadow_iff_exists_mem_card_add_one.1 ht
155-
refine' ⟨u, hu, hst.trans htu, _⟩
156-
rw [hcardtu, hcardst]
157-
rfl
158-
· rintro ⟨t, ht, hst, hcard⟩
159-
obtain ⟨u, hsu, hut, hu⟩ :=
160-
Finset.exists_intermediate_set k
161-
(by
162-
rw [add_comm, hcard]
163-
exact le_succ _)
164-
hst
165-
rw [add_comm] at hu
166-
refine' ⟨u, mem_shadow_iff_exists_mem_card_add_one.2 ⟨t, ht, hut, _⟩, hsu, hu⟩
167-
rw [hcard, hu]
168-
rfl
169-
#align finset.mem_shadow_iff_exists_mem_card_add Finset.mem_shadow_iff_exists_mem_card_add
170-
171181
end Shadow
172182

173183
open FinsetFamily
@@ -198,48 +208,83 @@ theorem upShadow_monotone : Monotone (upShadow : Finset (Finset α) → Finset (
198208
fun _ _ => sup_mono
199209
#align finset.up_shadow_monotone Finset.upShadow_monotone
200210

201-
/-- `s` is in the upper shadow of `𝒜` iff there is a `t ∈ 𝒜` from which we can remove one element
202-
to get `s`. -/
203-
theorem mem_upShadow_iff : s ∈ ∂⁺ 𝒜 ↔ ∃ t ∈ 𝒜, ∃ (a : _) (_ : a ∉ t), insert a t = s := by
204-
simp_rw [upShadow, mem_sup, mem_image, exists_prop, mem_compl]
211+
/-- `t` is in the upper shadow of `𝒜` iff there is a `s ∈ 𝒜` from which we can remove one element
212+
to get `t`. -/
213+
lemma mem_upShadow_iff : t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, ∃ a, a ∉ s ∧ insert a s = t := by
214+
simp_rw [upShadow, mem_sup, mem_image, mem_compl]
205215
#align finset.mem_up_shadow_iff Finset.mem_upShadow_iff
206216

207217
theorem insert_mem_upShadow (hs : s ∈ 𝒜) (ha : a ∉ s) : insert a s ∈ ∂⁺ 𝒜 :=
208218
mem_upShadow_iff.2 ⟨s, hs, a, ha, rfl⟩
209219
#align finset.insert_mem_up_shadow Finset.insert_mem_upShadow
210220

211-
/-- The upper shadow of a family of `r`-sets is a family of `r + 1`-sets. -/
212-
protected theorem Set.Sized.upShadow (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
213-
(∂⁺ 𝒜 : Set (Finset α)).Sized (r + 1) := by
214-
intro A h
215-
obtain ⟨A, hA, i, hi, rfl⟩ := mem_upShadow_iff.1 h
216-
rw [card_insert_of_not_mem hi, h𝒜 hA]
217-
#align finset.set.sized.up_shadow Finset.Set.Sized.upShadow
221+
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly one element more than something from `𝒜`.
222+
223+
See also `Finset.mem_upShadow_iff_exists_mem_card_add_one`. -/
224+
lemma mem_upShadow_iff_exists_sdiff : t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ (t \ s).card = 1 := by
225+
simp_rw [mem_upShadow_iff, ←covby_iff_card_sdiff_eq_one, covby_iff_exists_insert]
218226

219227
/-- `t` is in the upper shadow of `𝒜` iff we can remove an element from it so that the resulting
220228
finset is in `𝒜`. -/
221-
theorem mem_upShadow_iff_erase_mem : s ∈ ∂⁺ 𝒜 ↔ ∃ a ∈ s, s.erase a ∈ 𝒜 := by
222-
refine' mem_upShadow_iff.trans ⟨_, _⟩
223-
· rintro ⟨s, hs, a, ha, rfl⟩
224-
refine' ⟨a, mem_insert_self a s, _⟩
225-
rwa [erase_insert ha]
226-
· rintro ⟨a, ha, hs⟩
227-
exact ⟨s.erase a, hs, a, not_mem_erase _ _, insert_erase ha⟩
229+
lemma mem_upShadow_iff_erase_mem : t ∈ ∂⁺ 𝒜 ↔ ∃ a, a ∈ t ∧ erase t a ∈ 𝒜 := by
230+
simp_rw [mem_upShadow_iff_exists_sdiff, ←covby_iff_card_sdiff_eq_one, covby_iff_exists_erase]
231+
aesop
228232
#align finset.mem_up_shadow_iff_erase_mem Finset.mem_upShadow_iff_erase_mem
229233

230-
/-- `s ∈ ∂⁺ 𝒜` iff `s` is exactly one element less than something from `𝒜`. -/
231-
theorem mem_upShadow_iff_exists_mem_card_add_one :
232-
s ∈ ∂⁺ 𝒜 ↔ ∃ t ∈ 𝒜, t ⊆ s ∧ t.card + 1 = s.card := by
233-
refine' mem_upShadow_iff_erase_mem.trans ⟨_, _⟩
234-
· rintro ⟨a, ha, hs⟩
235-
exact ⟨s.erase a, hs, erase_subset _ _, card_erase_add_one ha⟩
236-
· rintro ⟨t, ht, hts, h⟩
237-
obtain ⟨a, ha⟩ : ∃ a, s \ t = {a} :=
238-
card_eq_one.1 (by rw [card_sdiff hts, ← h, add_tsub_cancel_left])
239-
refine' ⟨a, sdiff_subset _ _ ((ha.ge : _ ⊆ _) <| mem_singleton_self a), _⟩
240-
rwa [← sdiff_singleton_eq_erase, ← ha, sdiff_sdiff_eq_self hts]
234+
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly one element less than something from `𝒜`.
235+
236+
See also `Finset.mem_upShadow_iff_exists_sdiff`. -/
237+
lemma mem_upShadow_iff_exists_mem_card_add_one :
238+
t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ t.card = s.card + 1 := by
239+
refine mem_upShadow_iff_exists_sdiff.trans $ exists_congr fun t ↦ and_congr_right fun _ ↦
240+
and_congr_right fun hst ↦ ?_
241+
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
242+
exact card_mono hst
241243
#align finset.mem_up_shadow_iff_exists_mem_card_add_one Finset.mem_upShadow_iff_exists_mem_card_add_one
242244

245+
lemma mem_upShadow_iterate_iff_exists_card :
246+
t ∈ ∂⁺^[k] 𝒜 ↔ ∃ u : Finset α, u.card = k ∧ u ⊆ t ∧ t \ u ∈ 𝒜 := by
247+
induction' k with k ih generalizing t
248+
· simp
249+
simp only [mem_upShadow_iff_erase_mem, ih, Function.iterate_succ_apply', card_eq_succ,
250+
subset_erase, erase_sdiff_comm, ←sdiff_insert]
251+
constructor
252+
· rintro ⟨a, hat, u, rfl, ⟨hut, hau⟩, htu⟩
253+
exact ⟨_, ⟨_, _, hau, rfl, rfl⟩, insert_subset hat hut, htu⟩
254+
· rintro ⟨_, ⟨a, u, hau, rfl, rfl⟩, hut, htu⟩
255+
rw [insert_subset_iff] at hut
256+
exact ⟨a, hut.1, _, rfl, ⟨hut.2, hau⟩, htu⟩
257+
258+
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly `k` elements less than something from `𝒜`.
259+
260+
See also `Finset.mem_upShadow_iff_exists_mem_card_add`. -/
261+
lemma mem_upShadow_iterate_iff_exists_sdiff :
262+
t ∈ ∂⁺^[k] 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ (t \ s).card = k := by
263+
rw [mem_upShadow_iterate_iff_exists_card]
264+
constructor
265+
· rintro ⟨u, rfl, hut, htu⟩
266+
exact ⟨_, htu, sdiff_subset _ _, by rw [sdiff_sdiff_eq_self hut]⟩
267+
· rintro ⟨s, hs, hst, rfl⟩
268+
exact ⟨_, rfl, sdiff_subset _ _, by rwa [sdiff_sdiff_eq_self hst]⟩
269+
270+
/-- `t ∈ ∂⁺^k 𝒜` iff `t` is exactly `k` elements less than something in `𝒜`.
271+
272+
See also `Finset.mem_upShadow_iterate_iff_exists_sdiff`. -/
273+
lemma mem_upShadow_iterate_iff_exists_mem_card_add :
274+
t ∈ ∂⁺^[k] 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ t.card = s.card + k := by
275+
refine mem_upShadow_iterate_iff_exists_sdiff.trans $ exists_congr fun t ↦ and_congr_right fun _ ↦
276+
and_congr_right fun hst ↦ ?_
277+
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
278+
exact card_mono hst
279+
280+
/-- The upper shadow of a family of `r`-sets is a family of `r + 1`-sets. -/
281+
protected lemma _root_.Set.Sized.upShadow (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
282+
(∂⁺ 𝒜 : Set (Finset α)).Sized (r + 1) := by
283+
intro A h
284+
obtain ⟨A, hA, i, hi, rfl⟩ := mem_upShadow_iff.1 h
285+
rw [card_insert_of_not_mem hi, h𝒜 hA]
286+
#align finset.set.sized.up_shadow Set.Sized.upShadow
287+
243288
/-- Being in the upper shadow of `𝒜` means we have a superset in `𝒜`. -/
244289
theorem exists_subset_of_mem_upShadow (hs : s ∈ ∂⁺ 𝒜) : ∃ t ∈ 𝒜, t ⊆ s :=
245290
let ⟨t, ht, hts, _⟩ := mem_upShadow_iff_exists_mem_card_add_one.1 hs
@@ -260,7 +305,7 @@ theorem mem_upShadow_iff_exists_mem_card_add :
260305
· rintro ⟨t, ht, hts, hcardst⟩
261306
obtain ⟨u, hu, hut, hcardtu⟩ := mem_upShadow_iff_exists_mem_card_add_one.1 ht
262307
refine' ⟨u, hu, hut.trans hts, _⟩
263-
rw [← hcardst, hcardtu, add_right_comm]
308+
rw [← hcardst, hcardtu, add_right_comm]
264309
rfl
265310
· rintro ⟨t, ht, hts, hcard⟩
266311
obtain ⟨u, htu, hus, hu⟩ :=
@@ -270,7 +315,7 @@ theorem mem_upShadow_iff_exists_mem_card_add :
270315
exact add_le_add_left (succ_le_of_lt (zero_lt_succ _)) _)
271316
hts
272317
rw [add_comm] at hu
273-
refine' ⟨u, mem_upShadow_iff_exists_mem_card_add_one.2 ⟨t, ht, htu, hu.symm⟩, hus, _⟩
318+
refine' ⟨u, mem_upShadow_iff_exists_mem_card_add_one.2 ⟨t, ht, htu, hu⟩, hus, _⟩
274319
rw [hu, ← hcard, add_right_comm]
275320
rfl
276321
#align finset.mem_up_shadow_iff_exists_mem_card_add Finset.mem_upShadow_iff_exists_mem_card_add

Mathlib/Data/Finset/Basic.lean

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
55
-/
66
import Mathlib.Data.Multiset.FinsetOps
77
import Mathlib.Data.Set.Lattice
8+
import Mathlib.Order.Cover
89

910
#align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d"
1011

@@ -927,6 +928,17 @@ theorem ssubset_iff_exists_cons_subset : s ⊂ t ↔ ∃ (a : _) (h : a ∉ s),
927928
exact ⟨a, ht, cons_subset.2 ⟨hs, h.subset⟩⟩
928929
#align finset.ssubset_iff_exists_cons_subset Finset.ssubset_iff_exists_cons_subset
929930

931+
lemma covby_cons (ha : a ∉ s) : s ⋖ cons a s ha :=
932+
Covby.of_image ⟨⟨_, coe_injective⟩, coe_subset⟩ <| by
933+
simpa using Set.covby_insert (show a ∉ (s : Set α) from ha)
934+
935+
lemma covby_iff_exists_cons : s ⋖ t ↔ ∃ a, ∃ ha : a ∉ s, cons a s ha = t := by
936+
refine ⟨fun hst ↦ ?_, ?_⟩
937+
· obtain ⟨a, ha, hast⟩ := ssubset_iff_exists_cons_subset.1 hst.1
938+
exact ⟨a, ha, eq_of_le_of_not_lt hast <| hst.2 <| ssubset_cons _⟩
939+
· rintro ⟨a, ha, rfl⟩
940+
exact covby_cons ha
941+
930942
end Cons
931943

932944
/-! ### disjoint -/
@@ -1191,7 +1203,7 @@ theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by
11911203
theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t :=
11921204
insert_subset_iff.mpr ⟨ha,hs⟩
11931205

1194-
theorem subset_insert (a : α) (s : Finset α) : s ⊆ insert a s := fun _b => mem_insert_of_mem
1206+
@[simp] theorem subset_insert (a : α) (s : Finset α) : s ⊆ insert a s := fun _b => mem_insert_of_mem
11951207
#align finset.subset_insert Finset.subset_insert
11961208

11971209
theorem insert_subset_insert (a : α) {s t : Finset α} (h : s ⊆ t) : insert a s ⊆ insert a t :=
@@ -1311,6 +1323,11 @@ theorem disjoint_insert_right : Disjoint s (insert a t) ↔ a ∉ s ∧ Disjoint
13111323
disjoint_comm.trans <| by rw [disjoint_insert_left, _root_.disjoint_comm]
13121324
#align finset.disjoint_insert_right Finset.disjoint_insert_right
13131325

1326+
lemma covby_insert (ha : a ∉ s) : s ⋖ insert a s := by simpa using covby_cons ha
1327+
1328+
lemma covby_iff_exists_insert : t ⋖ s ↔ ∃ a, a ∉ t ∧ insert a t = s := by
1329+
simp [covby_iff_exists_cons]
1330+
13141331
end Insert
13151332

13161333
/-! ### Lattice structure -/
@@ -1954,7 +1971,7 @@ theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b
19541971
simp only [cons_eq_insert, erase_insert_of_ne hb]
19551972
#align finset.erase_cons_of_ne Finset.erase_cons_of_ne
19561973

1957-
theorem insert_erase {a : α} {s : Finset α} (h : a ∈ s) : insert a (erase s a) = s :=
1974+
@[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s :=
19581975
ext fun x => by
19591976
simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and_iff]
19601977
apply or_iff_right_of_imp
@@ -1963,7 +1980,7 @@ theorem insert_erase {a : α} {s : Finset α} (h : a ∈ s) : insert a (erase s
19631980
#align finset.insert_erase Finset.insert_erase
19641981

19651982
lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by
1966-
have := insert_erase hs; aesop
1983+
aesop
19671984

19681985
lemma insert_erase_invOn :
19691986
Set.InvOn (insert a) (λ s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} :=
@@ -2055,6 +2072,9 @@ theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase
20552072
fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h]
20562073
#align finset.erase_inj_on' Finset.erase_injOn'
20572074

2075+
lemma covby_iff_exists_erase : t ⋖ s ↔ ∃ a, a ∈ s ∧ t = s.erase a :=
2076+
covby_iff_exists_insert.trans $ exists_congr fun a ↦ by aesop
2077+
20582078
end Erase
20592079

20602080
/-! ### sdiff -/
@@ -2218,7 +2238,7 @@ theorem insert_sdiff_of_mem (s : Finset α) {x : α} (h : x ∈ t) : insert x s
22182238
exact Set.insert_diff_of_mem _ h
22192239
#align finset.insert_sdiff_of_mem Finset.insert_sdiff_of_mem
22202240

2221-
lemma insert_sdiff_cancel (ha : a ∉ s) : insert a s \ s = {a} := by
2241+
@[simp] lemma insert_sdiff_cancel (ha : a ∉ s) : insert a s \ s = {a} := by
22222242
rw [insert_sdiff_of_not_mem _ ha, Finset.sdiff_self, insert_emptyc_eq]
22232243

22242244
@[simp]

0 commit comments

Comments
 (0)