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

Commit 3a3249e

Browse files
committed
feat(data/finsupp): multiset_map_sum/_sum_sum/_index
1 parent 92b9a00 commit 3a3249e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

data/finsupp.lean

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ The best is to define a copy and select the instances best suited.
2222
-/
2323
import data.finset data.set.finite algebra.big_operators algebra.module
2424
open finset
25-
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*}
25+
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Type*}
26+
{α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*}
2627

2728
reserve infix ` →₀ `:25
2829

@@ -342,6 +343,7 @@ lemma single_sum [has_zero γ] [add_comm_monoid β] [decidable_eq α] [decidable
342343
(s : δ →₀ γ) (f : δ → γ → β) (a : α) : single a (s.sum f) = s.sum (λd c, single a (f d c)) :=
343344
single_finset_sum _ _ _
344345

346+
345347
@[to_additive finsupp.sum_neg_index]
346348
lemma prod_neg_index [add_group β] [comm_monoid γ]
347349
{g : α →₀ β} {h : α → β → γ} (h0 : ∀a, h a 0 = 1) :
@@ -449,7 +451,7 @@ calc (f - g).sum h = (f + - g).sum h : by simp
449451
... = _ : by simp
450452

451453
@[to_additive finsupp.sum_finset_sum_index]
452-
lemma prod_finset_sum_index {ι : Type*} [add_comm_monoid β] [comm_monoid γ] [decidable_eq ι]
454+
lemma prod_finset_sum_index [add_comm_monoid β] [comm_monoid γ] [decidable_eq ι]
453455
{s : finset ι} {g : ι → α →₀ β}
454456
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂):
455457
s.prod (λi, (g i).prod h) = (s.sum g).prod h :=
@@ -465,6 +467,26 @@ lemma prod_sum_index
465467
(f.sum g).prod h = f.prod (λa b, (g a b).prod h) :=
466468
(prod_finset_sum_index h_zero h_add).symm
467469

470+
lemma multiset_sum_sum_index
471+
[decidable_eq α] [decidable_eq β] [add_comm_monoid β] [add_comm_monoid γ]
472+
(f : multiset (α →₀ β)) (h : α → β → γ)
473+
(h₀ : ∀a, h a 0 = 0) (h₁ : ∀ (a : α) (b₁ b₂ : β), h a (b₁ + b₂) = h a b₁ + h a b₂) :
474+
(f.sum.sum h) = (f.map $ λg:α →₀ β, g.sum h).sum :=
475+
multiset.induction_on f (by simp [finsupp.sum_zero_index])
476+
(assume a s ih, by simp [finsupp.sum_add_index h₀ h₁, ih] {contextual := tt})
477+
478+
lemma multiset_map_sum [has_zero β] {f : α →₀ β} {m : γ → δ} {h : α → β → multiset γ} :
479+
multiset.map m (f.sum h) = f.sum (λa b, (h a b).map m) :=
480+
(finset.sum_hom _ (multiset.map_zero m) (multiset.map_add m)).symm
481+
482+
lemma multiset_sum_sum [has_zero β] [add_comm_monoid γ] {f : α →₀ β} {h : α → β → multiset γ} :
483+
multiset.sum (f.sum h) = f.sum (λa b, multiset.sum (h a b)) :=
484+
begin
485+
refine (finset.sum_hom multiset.sum _ _).symm,
486+
exact multiset.sum_zero,
487+
exact multiset.sum_add
488+
end
489+
468490
section map_domain
469491
variables [decidable_eq α₁] [decidable_eq α₂] [add_comm_monoid β] {v v₁ v₂ : α →₀ β}
470492

@@ -494,8 +516,7 @@ finset.sum_congr rfl $ by simp [*] at * {contextual := tt}
494516
lemma map_domain_add {f : α → α₂} : map_domain f (v₁ + v₂) = map_domain f v₁ + map_domain f v₂ :=
495517
sum_add_index (by simp) (by simp)
496518

497-
lemma map_domain_finset_sum {ι : Type*} [decidable_eq ι]
498-
{f : α → α₂} {s : finset ι} {v : ι → α →₀ β} :
519+
lemma map_domain_finset_sum [decidable_eq ι] {f : α → α₂} {s : finset ι} {v : ι → α →₀ β} :
499520
map_domain f (s.sum v) = s.sum (λi, map_domain f (v i)) :=
500521
by refine (sum_finset_sum_index _ _).symm; simp
501522

@@ -779,7 +800,7 @@ lemma single_mul_single [has_add α] [semiring β] {a₁ a₂ : α} {b₁ b₂ :
779800
single a₁ b₁ * single a₂ b₂ = single (a₁ + a₂) (b₁ * b₂) :=
780801
by simp [mul_def, sum_single_index]
781802

782-
lemma prod_single {ι : Type x} [decidable_eq ι] [add_comm_monoid α] [comm_semiring β]
803+
lemma prod_single [decidable_eq ι] [add_comm_monoid α] [comm_semiring β]
783804
{s : finset ι} {a : ι → α} {b : ι → β} :
784805
s.prod (λi, single (a i) (b i)) = single (s.sum a) (s.prod b) :=
785806
finset.induction_on s (by simp [one_def]) (by simp [single_mul_single] {contextual := tt})

0 commit comments

Comments
 (0)