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

Commit 56185bd

Browse files
feat(data/finset): add some lemmas about finset.disj_union (#14910)
Co-authored-by: YaelDillies <yael.dillies@gmail.com>
1 parent 198cb64 commit 56185bd

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/algebra/big_operators/basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ lemma prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f
254254
by rw [h]; exact fold_congr
255255
attribute [congr] finset.sum_congr
256256

257+
@[to_additive]
258+
lemma prod_disj_union (h) : ∏ x in s₁.disj_union s₂ h, f x = (∏ x in s₁, f x) * ∏ x in s₂, f x :=
259+
by { refine eq.trans _ (fold_disj_union h), rw one_mul, refl }
260+
257261
@[to_additive]
258262
lemma prod_union_inter [decidable_eq α] :
259263
(∏ x in (s₁ ∪ s₂), f x) * (∏ x in (s₁ ∩ s₂), f x) = (∏ x in s₁, f x) * (∏ x in s₂, f x) :=

src/data/finset/basic.lean

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,11 @@ lemma mem_map' (f : α ↪ β) {a} {s : finset α} : f a ∈ s.map f ↔ a ∈ s
18611861

18621862
lemma mem_map_of_mem (f : α ↪ β) {a} {s : finset α} : a ∈ s → f a ∈ s.map f := (mem_map' _).2
18631863

1864+
lemma forall_mem_map {f : α ↪ β} {s : finset α} {p : Π a, a ∈ s.map f → Prop} :
1865+
(∀ y ∈ s.map f, p y H) ↔ ∀ x ∈ s, p (f x) (mem_map_of_mem _ H) :=
1866+
⟨λ h y hy, h (f y) (mem_map_of_mem _ hy), λ h x hx,
1867+
by { obtain ⟨y, hy, rfl⟩ := mem_map.1 hx, exact h _ hy }⟩
1868+
18641869
lemma apply_coe_mem_map (f : α ↪ β) (s : finset α) (x : s) : f x ∈ s.map f :=
18651870
mem_map_of_mem f x.prop
18661871

@@ -1910,6 +1915,20 @@ theorem map_filter {p : β → Prop} [decidable_pred p] :
19101915
(s.map f).filter p = (s.filter (p ∘ f)).map f :=
19111916
eq_of_veq (map_filter _ _ _)
19121917

1918+
/-- A helper lemma to produce a default proof for `finset.map_disj_union`. -/
1919+
theorem map_disj_union_aux {f : α ↪ β} {s₁ s₂ : finset α} :
1920+
(∀ a, a ∈ s₁ → a ∉ s₂) ↔ ∀ a, a ∈ map f s₁ → a ∉ map f s₂ :=
1921+
by simp_rw [forall_mem_map, mem_map']
1922+
1923+
theorem map_disj_union {f : α ↪ β} (s₁ s₂ : finset α) (h) (h' := map_disj_union_aux.1 h) :
1924+
(s₁.disj_union s₂ h).map f = (s₁.map f).disj_union (s₂.map f) h' :=
1925+
eq_of_veq $ multiset.map_add _ _ _
1926+
1927+
/-- A version of `finset.map_disj_union` for writing in the other direction. -/
1928+
theorem map_disj_union' {f : α ↪ β} (s₁ s₂ : finset α) (h') (h := map_disj_union_aux.2 h') :
1929+
(s₁.disj_union s₂ h).map f = (s₁.map f).disj_union (s₂.map f) h' :=
1930+
map_disj_union _ _ _
1931+
19131932
theorem map_union [decidable_eq α] [decidable_eq β]
19141933
{f : α ↪ β} (s₁ s₂ : finset α) : (s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f :=
19151934
coe_injective $ by simp only [coe_map, coe_union, set.image_union]

src/data/finset/fold.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ theorem fold_hom {op' : γ → γ → γ} [is_commutative γ op'] [is_associativ
7070
s.fold op' (m b) (λx, m (f x)) = m (s.fold op b f) :=
7171
by rw [fold, fold, ← fold_hom op hm, multiset.map_map]
7272

73+
theorem fold_disj_union {s₁ s₂ : finset α} {b₁ b₂ : β} (h) :
74+
(s₁.disj_union s₂ h).fold op (b₁ * b₂) f = s₁.fold op b₁ f * s₂.fold op b₂ f :=
75+
(congr_arg _ $ multiset.map_add _ _ _).trans (multiset.fold_add _ _ _ _ _)
76+
7377
theorem fold_union_inter [decidable_eq α] {s₁ s₂ : finset α} {b₁ b₂ : β} :
7478
(s₁ ∪ s₂).fold op b₁ f * (s₁ ∩ s₂).fold op b₂ f = s₁.fold op b₂ f * s₂.fold op b₁ f :=
7579
by unfold fold; rw [← fold_add op, ← multiset.map_add, union_val,

0 commit comments

Comments
 (0)