@@ -34,7 +34,10 @@ variables {α : Type u} {β : Type v} {γ : Type w}
34
34
35
35
namespace finset
36
36
37
- /-- `∏ x in s, f x` is the product of `f x` as `x` ranges over the elements of the finite set `s`. -/
37
+ /--
38
+ `∏ x in s, f x` is the product of `f x`
39
+ as `x` ranges over the elements of the finite set `s`.
40
+ -/
38
41
@[to_additive " `∑ x in s, f` is the sum of `f x` as `x` ranges over the elements
39
42
of the finite set `s`." ]
40
43
protected def prod [comm_monoid β] (s : finset α) (f : α → β) : β := (s.1 .map f).prod
@@ -66,11 +69,15 @@ In practice, this means that parentheses should be placed as follows:
66
69
(Example taken from page 490 of Knuth's *Concrete Mathematics* .)
67
70
-/
68
71
69
- localized " notation `∑` binders `, ` r:(scoped:67 f, finset.sum finset.univ f) := r" in big_operators
70
- localized " notation `∏` binders `, ` r:(scoped:67 f, finset.prod finset.univ f) := r" in big_operators
72
+ localized " notation `∑` binders `, ` r:(scoped:67 f, finset.sum finset.univ f) := r"
73
+ in big_operators
74
+ localized " notation `∏` binders `, ` r:(scoped:67 f, finset.prod finset.univ f) := r"
75
+ in big_operators
71
76
72
- localized " notation `∑` binders ` in ` s `, ` r:(scoped:67 f, finset.sum s f) := r" in big_operators
73
- localized " notation `∏` binders ` in ` s `, ` r:(scoped:67 f, finset.prod s f) := r" in big_operators
77
+ localized " notation `∑` binders ` in ` s `, ` r:(scoped:67 f, finset.sum s f) := r"
78
+ in big_operators
79
+ localized " notation `∏` binders ` in ` s `, ` r:(scoped:67 f, finset.prod s f) := r"
80
+ in big_operators
74
81
75
82
open_locale big_operators
76
83
@@ -81,7 +88,9 @@ variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
81
88
∏ x in s, f x = (s.1 .map f).prod := rfl
82
89
83
90
@[to_additive]
84
- theorem prod_eq_fold [comm_monoid β] (s : finset α) (f : α → β) : (∏ x in s, f x) = s.fold (*) 1 f := rfl
91
+ theorem prod_eq_fold [comm_monoid β] (s : finset α) (f : α → β) :
92
+ (∏ x in s, f x) = s.fold (*) 1 f :=
93
+ rfl
85
94
86
95
end finset
87
96
@@ -113,8 +122,7 @@ lemma ring_hom.map_multiset_sum [semiring β] [semiring γ] (f : β →+* γ) (s
113
122
f s.sum = (s.map f).sum :=
114
123
f.to_add_monoid_hom.map_multiset_sum s
115
124
116
- lemma ring_hom.map_prod [comm_semiring β] [comm_semiring γ]
117
- (g : β →+* γ) (f : α → β) (s : finset α) :
125
+ lemma ring_hom.map_prod [comm_semiring β] [comm_semiring γ] (g : β →+* γ) (f : α → β) (s : finset α) :
118
126
g (∏ x in s, f x) = ∏ x in s, g (f x) :=
119
127
g.to_monoid_hom.map_prod f s
120
128
@@ -137,10 +145,11 @@ lemma prod_insert [decidable_eq α] :
137
145
a ∉ s → (∏ x in (insert a s), f x) = f a * ∏ x in s, f x := fold_insert
138
146
139
147
/--
140
- The product of `f` over `insert a s` is the same as the product over `s`, as long as `a` is in `s` or `f a = 1`.
148
+ The product of `f` over `insert a s` is the same as
149
+ the product over `s`, as long as `a` is in `s` or `f a = 1`.
141
150
-/
142
- @[simp, to_additive " The sum of `f` over `insert a s` is the same as the sum over `s`, as long as `a` is in `s` or `f a = 0`.
143
- " ]
151
+ @[simp, to_additive " The sum of `f` over `insert a s` is the same as
152
+ the sum over `s`, as long as `a` is in `s` or `f a = 0`. " ]
144
153
lemma prod_insert_of_eq_one_if_not_mem [decidable_eq α] (h : a ∉ s → f a = 1 ) :
145
154
∏ x in insert a s, f x = ∏ x in s, f x :=
146
155
begin
152
161
/--
153
162
The product of `f` over `insert a s` is the same as the product over `s`, as long as `f a = 1`.
154
163
-/
155
- @[simp, to_additive " The sum of `f` over `insert a s` is the same as the sum over `s`, as long as `f a = 0`." ]
164
+ @[simp, to_additive " The sum of `f` over `insert a s` is the same as
165
+ the sum over `s`, as long as `f a = 0`." ]
156
166
lemma prod_insert_one [decidable_eq α] (h : f a = 1 ) :
157
167
∏ x in insert a s, f x = ∏ x in s, f x :=
158
168
prod_insert_of_eq_one_if_not_mem (λ _, h)
220
230
221
231
@[to_additive]
222
232
lemma prod_bind [decidable_eq α] {s : finset γ} {t : γ → finset α} :
223
- (∀x∈s, ∀y∈s, x ≠ y → disjoint (t x) (t y)) → (∏ x in (s.bind t), f x) = ∏ x in s, ∏ i in t x, f i :=
233
+ (∀ x ∈ s, ∀ y ∈ s, x ≠ y → disjoint (t x) (t y)) →
234
+ (∏ x in (s.bind t), f x) = ∏ x in s, ∏ i in t x, f i :=
224
235
by haveI := classical.dec_eq γ; exact
225
236
finset.induction_on s (λ _, by simp only [bind_empty, prod_empty])
226
237
(assume x s hxs ih hd,
@@ -313,7 +324,8 @@ lemma prod_hom_rel [comm_monoid γ] {r : β → γ → Prop} {f : α → β} {g
313
324
by { delta finset.prod, apply multiset.prod_hom_rel; assumption }
314
325
315
326
@[to_additive]
316
- lemma prod_subset (h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → f x = 1 ) : (∏ x in s₁, f x) = ∏ x in s₂, f x :=
327
+ lemma prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1 ) :
328
+ (∏ x in s₁, f x) = ∏ x in s₂, f x :=
317
329
by haveI := classical.dec_eq α; exact
318
330
have ∏ x in s₂ \ s₁, f x = ∏ x in s₂ \ s₁, 1 ,
319
331
from prod_congr rfl $ by simpa only [mem_sdiff, and_imp],
@@ -431,7 +443,8 @@ calc ∏ x in s, h (if hx : p x then f x hx else g x hx)
431
443
{p : α → Prop } {hp : decidable_pred p} (f g : α → γ) (h : γ → β) :
432
444
(∏ x in s, h (if p x then f x else g x)) =
433
445
(∏ x in s.filter p, h (f x)) * (∏ x in s.filter (λ x, ¬ p x), h (g x)) :=
434
- trans (prod_apply_dite _ _ _) (congr_arg2 _ (@prod_attach _ _ _ _ (h ∘ f)) (@prod_attach _ _ _ _ (h ∘ g)))
446
+ trans (prod_apply_dite _ _ _)
447
+ (congr_arg2 _ (@prod_attach _ _ _ _ (h ∘ f)) (@prod_attach _ _ _ _ (h ∘ g)))
435
448
436
449
@[to_additive] lemma prod_dite {s : finset α} {p : α → Prop } {hp : decidable_pred p}
437
450
(f : Π (x : α), p x → β) (g : Π (x : α), ¬p x → β) :
@@ -536,7 +549,8 @@ calc (∏ x in s, f x) = ∏ x in (s.filter $ λx, f x ≠ 1), f x : prod_filter
536
549
⟨hi₁ a h₁ h₂, λ hg, h₂ (hg ▸ h a h₁ h₂)⟩)
537
550
(assume a ha, (mem_filter.mp ha).elim $ h a)
538
551
(assume a₁ a₂ ha₁ ha₂,
539
- (mem_filter.mp ha₁).elim $ λha₁₁ ha₁₂, (mem_filter.mp ha₂).elim $ λha₂₁ ha₂₂, hi₂ a₁ a₂ _ _ _ _)
552
+ (mem_filter.mp ha₁).elim $ λ ha₁₁ ha₁₂,
553
+ (mem_filter.mp ha₂).elim $ λ ha₂₁ ha₂₂, hi₂ a₁ a₂ _ _ _ _)
540
554
(assume b hb, (mem_filter.mp hb).elim $ λh₁ h₂,
541
555
let ⟨a, ha₁, ha₂, eq⟩ := hi₃ b h₁ h₂ in ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩)
542
556
... = (∏ x in t, g x) : prod_filter_ne_one
@@ -601,16 +615,20 @@ begin
601
615
{ rw [prod_cons, to_finset_cons, finset.insert_eq_of_mem has, ih,
602
616
← finset.insert_erase has, finset.prod_insert (finset.not_mem_erase _ _),
603
617
finset.prod_insert (finset.not_mem_erase _ _), ← mul_assoc, count_cons_self, pow_succ],
604
- congr' 1 , refine finset.prod_congr rfl (λ x hx, _), rw [count_cons_of_ne (finset.ne_of_mem_erase hx)] },
618
+ congr' 1 , refine finset.prod_congr rfl (λ x hx, _),
619
+ rw [count_cons_of_ne (finset.ne_of_mem_erase hx)] },
605
620
rw [prod_cons, to_finset_cons, finset.prod_insert has, count_cons_self],
606
621
rw mem_to_finset at has, rw [count_eq_zero_of_not_mem has, pow_one], congr' 1 ,
607
622
rw ih, refine finset.prod_congr rfl (λ x hx, _), rw mem_to_finset at hx, rw count_cons_of_ne,
608
623
rintro rfl, exact has hx
609
624
end
610
625
611
- /-- To prove a property of a product, it suffices to prove that the property is multiplicative and holds on factors.
626
+ /--
627
+ To prove a property of a product, it suffices to prove that
628
+ the property is multiplicative and holds on factors.
612
629
-/
613
- @[to_additive " To prove a property of a sum, it suffices to prove that the property is additive and holds on summands." ]
630
+ @[to_additive " To prove a property of a sum, it suffices to prove that
631
+ the property is additive and holds on summands." ]
614
632
lemma prod_induction {M : Type *} [comm_monoid M] (f : α → M) (p : M → Prop )
615
633
(p_mul : ∀ a b, p a → p b → p (a * b)) (p_one : p 1 ) (p_s : ∀ x ∈ s, p $ f x) :
616
634
p $ ∏ x in s, f x :=
@@ -622,7 +640,8 @@ begin
622
640
apply hs, intros a ha, apply p_s, simp [ha],
623
641
end
624
642
625
- /-- For any product along `{0, ..., n-1}` of a commutative-monoid-valued function, we can verify that
643
+ /--
644
+ For any product along `{0, ..., n-1}` of a commutative-monoid-valued function, we can verify that
626
645
it's equal to a different function just by checking ratios of adjacent terms.
627
646
This is a multiplicative discrete analogue of the fundamental theorem of calculus. -/
628
647
lemma prod_range_induction {M : Type *} [comm_monoid M]
@@ -634,9 +653,13 @@ begin
634
653
{ simp only [hk, finset.prod_range_succ, h, mul_comm] }
635
654
end
636
655
637
- /-- For any sum along `{0, ..., n-1}` of a commutative-monoid-valued function, we can verify that it's equal
638
- to a different function just by checking differences of adjacent terms. This is a discrete analogue
639
- of the fundamental theorem of calculus. -/
656
+ /--
657
+ For any sum along `{0, ..., n-1}` of a commutative-monoid-valued function,
658
+ we can verify that it's equal to a different function
659
+ just by checking differences of adjacent terms.
660
+ This is a discrete analogue
661
+ of the fundamental theorem of calculus.
662
+ -/
640
663
lemma sum_range_induction {M : Type *} [add_comm_monoid M]
641
664
(f s : ℕ → M) (h0 : s 0 = 0 ) (h : ∀ n, s (n + 1 ) = s n + f n) (n : ℕ) :
642
665
∑ k in finset.range n, f k = s n :=
@@ -664,8 +687,11 @@ lemma prod_range_div' {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
664
687
∏ i in range n, (f i * (f (i+1 ))⁻¹) = (f 0 ) * (f n)⁻¹ :=
665
688
by apply @sum_range_sub' (additive M)
666
689
667
- /-- A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function reduces to the difference of
668
- the last and first terms when the function we are summing is monotone. -/
690
+ /--
691
+ A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
692
+ reduces to the difference of the last and first terms
693
+ when the function we are summing is monotone.
694
+ -/
669
695
lemma sum_range_sub_of_monotone {f : ℕ → ℕ} (h : monotone f) (n : ℕ) :
670
696
∑ i in range n, (f (i+1 ) - f i) = f n - f 0 :=
671
697
begin
@@ -773,7 +799,8 @@ by { convert s.prod_inter_mul_prod_diff {i} f, simp [h] }
773
799
lemma prod_cancels_of_partition_cancels (R : setoid α) [decidable_rel R.r]
774
800
(h : ∀ x ∈ s, (∏ a in s.filter (λy, y ≈ x), f a) = 1 ) : (∏ x in s, f x) = 1 :=
775
801
begin
776
- suffices : ∏ xbar in s.image quotient.mk, ∏ y in s.filter (λ y, ⟦y⟧ = xbar), f y = (∏ x in s, f x),
802
+ suffices : ∏ xbar in s.image quotient.mk, ∏ y in s.filter (λ y, ⟦y⟧ = xbar),
803
+ f y = (∏ x in s, f x),
777
804
{ rw [←this , ←finset.prod_eq_one],
778
805
intros xbar xbar_in_s,
779
806
rcases (mem_image).mp xbar_in_s with ⟨x, x_in_s, xbar_eq_x⟩,
0 commit comments