Skip to content

Commit be6b01d

Browse files
committed
feat(Finset): interaction of attach and cons (#31025)
and golf the corresponding `insert` lemma. This lets us golf a proof by induction.
1 parent 2ba365e commit be6b01d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Mathlib/Algebra/BigOperators/GroupWithZero/Finset.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ end Fintype
7272
lemma Units.mk0_prod [CommGroupWithZero G₀] (s : Finset ι) (f : ι → G₀) (h) :
7373
Units.mk0 (∏ i ∈ s, f i) h =
7474
∏ i ∈ s.attach, Units.mk0 (f i) fun hh ↦ h (Finset.prod_eq_zero i.2 hh) := by
75-
classical induction s using Finset.induction_on <;> simp [*]
75+
induction s using Finset.cons_induction_on <;> simp [*]

Mathlib/Data/Finset/Image.lean

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,17 @@ theorem attach_image_val [DecidableEq α] {s : Finset α} : s.attach.image Subty
477477
eq_of_veq <| by rw [image_val, attach_val, Multiset.attach_map_val, dedup_eq_self]
478478

479479
@[simp]
480-
theorem attach_insert [DecidableEq α] {a : α} {s : Finset α} :
480+
lemma attach_cons (a : α) (s : Finset α) (ha) :
481+
attach (cons a s ha) =
482+
cons ⟨a, mem_cons_self a s⟩
483+
((attach s).map ⟨fun x ↦ ⟨x.1, mem_cons_of_mem x.2⟩, fun x y => by simp⟩)
484+
(by simpa) := by ext ⟨x, hx⟩; simpa using hx
485+
486+
@[simp]
487+
theorem attach_insert [DecidableEq α] (s : Finset α) (a : α) :
481488
attach (insert a s) =
482489
insert (⟨a, mem_insert_self a s⟩ : { x // x ∈ insert a s })
483-
((attach s).image fun x => ⟨x.1, mem_insert_of_mem x.2⟩) :=
484-
ext fun ⟨x, hx⟩ =>
485-
⟨Or.casesOn (mem_insert.1 hx)
486-
(fun h : x = a => fun _ => mem_insert.2 <| Or.inl <| Subtype.eq h) fun h : x ∈ s => fun _ =>
487-
mem_insert_of_mem <| mem_image.2 <| ⟨⟨x, h⟩, mem_attach _ _, Subtype.eq rfl⟩,
488-
fun _ => Finset.mem_attach _ _⟩
490+
((attach s).image fun x => ⟨x.1, mem_insert_of_mem x.2⟩) := by ext ⟨x, hx⟩; simpa using hx
489491

490492
@[simp]
491493
theorem disjoint_image {s t : Finset α} {f : α → β} (hf : Injective f) :

0 commit comments

Comments
 (0)