@@ -587,6 +587,19 @@ finset.strong_induction_on s
587
587
← insert_erase (mem_erase.2 ⟨h₂ x hx hx1, h₃ x hx⟩),
588
588
prod_insert (not_mem_erase _ _), ih', mul_one, h₁ x hx]))
589
589
590
+ /-- The product of the composition of functions `f` and `g`, is the product
591
+ over `b ∈ s.image g` of `f b` to the power of the cardinality of the fibre of `b` -/
592
+ lemma prod_comp [decidable_eq γ] {s : finset α} (f : γ → β) (g : α → γ) :
593
+ ∏ a in s, f (g a) = ∏ b in s.image g, f b ^ (s.filter (λ a, g a = b)).card :=
594
+ calc ∏ a in s, f (g a)
595
+ = ∏ x in (s.image g).sigma (λ b : γ, s.filter (λ a, g a = b)), f (g x.2 ) :
596
+ prod_bij (λ a ha, ⟨g a, a⟩) (by simp; tauto) (λ _ _, rfl) (by simp) (by finish)
597
+ ... = ∏ b in s.image g, ∏ a in s.filter (λ a, g a = b), f (g a) : prod_sigma
598
+ ... = ∏ b in s.image g, ∏ a in s.filter (λ a, g a = b), f b :
599
+ prod_congr rfl (λ b hb, prod_congr rfl (by simp {contextual := tt}))
600
+ ... = ∏ b in s.image g, f b ^ (s.filter (λ a, g a = b)).card :
601
+ prod_congr rfl (λ _ _, prod_const _)
602
+
590
603
@[to_additive]
591
604
lemma prod_eq_one {f : α → β} {s : finset α} (h : ∀x∈s, f x = 1 ) : (∏ x in s, f x) = 1 :=
592
605
calc (∏ x in s, f x) = s.prod (λx, 1 ) : finset.prod_congr rfl h
@@ -662,6 +675,12 @@ attribute [to_additive sum_smul'] prod_pow
662
675
@prod_const _ (multiplicative β) _ _ _
663
676
attribute [to_additive] prod_const
664
677
678
+ lemma sum_comp [add_comm_monoid β] [decidable_eq γ] {s : finset α} (f : γ → β) (g : α → γ) :
679
+ ∑ a in s, f (g a) = ∑ b in s.image g, add_monoid.smul (s.filter (λ a, g a = b)).card (f b) :=
680
+ @prod_comp _ (multiplicative β) _ _ _ _ _ _
681
+ attribute [to_additive " The sum of the composition of functions `f` and `g`, is the sum
682
+ over `b ∈ s.image g` of `f b` times of the cardinality of the fibre of `b`" ] prod_comp
683
+
665
684
lemma sum_const_nat {m : ℕ} {f : α → ℕ} (h₁ : ∀x ∈ s, f x = m) :
666
685
(∑ x in s, f x) = card s * m :=
667
686
begin
0 commit comments