@@ -54,7 +54,7 @@ by simp [finset.prod]
54
54
attribute [to_additive finset.sum_const_zero] prod_const_one
55
55
56
56
@[simp, to_additive finset.sum_image]
57
- lemma prod_image [decidable_eq α] [decidable_eq γ] {s : finset γ} {g : γ → α} :
57
+ lemma prod_image [decidable_eq α] {s : finset γ} {g : γ → α} :
58
58
(∀x∈s, ∀y∈s, g x = g y → x = y) → (s.image g).prod f = s.prod (λx, f (g x)) :=
59
59
fold_image
60
60
@@ -229,14 +229,70 @@ lemma prod_range_succ' (f : ℕ → β) :
229
229
| (n + 1 ) := by rw [prod_range_succ (λ m, f (nat.succ m)), mul_assoc, ← prod_range_succ'];
230
230
exact prod_range_succ _ _
231
231
232
- @[simp] lemma prod_const [decidable_eq α] (b : β) : s.prod (λ a, b) = b ^ s.card :=
232
+ @[simp] lemma prod_const (b : β) : s.prod (λ a, b) = b ^ s.card :=
233
+ by haveI := classical.dec_eq α; exact
233
234
finset.induction_on s rfl (by simp [pow_add, mul_comm] {contextual := tt})
234
235
236
+ lemma prod_pow (s : finset α) (n : ℕ) (f : α → β) :
237
+ s.prod (λ x, f x ^ n) = s.prod f ^ n :=
238
+ by haveI := classical.dec_eq α; exact
239
+ finset.induction_on s (by simp) (by simp [_root_.mul_pow] {contextual := tt})
240
+
241
+ lemma prod_nat_pow (s : finset α) (n : ℕ) (f : α → ℕ) :
242
+ s.prod (λ x, f x ^ n) = s.prod f ^ n :=
243
+ by haveI := classical.dec_eq α; exact
244
+ finset.induction_on s (by simp) (by simp [nat.mul_pow] {contextual := tt})
245
+
246
+ @[to_additive finset.sum_involution]
247
+ lemma prod_involution {s : finset α} {f : α → β} :
248
+ ∀ (g : Π a ∈ s, α)
249
+ (h₁ : ∀ a ha, f a * f (g a ha) = 1 )
250
+ (h₂ : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
251
+ (h₃ : ∀ a ha, g a ha ∈ s)
252
+ (h₄ : ∀ a ha, g (g a ha) (h₃ a ha) = a),
253
+ s.prod f = 1 :=
254
+ by haveI := classical.dec_eq α;
255
+ haveI := classical.dec_eq β; exact
256
+ finset.strong_induction_on s
257
+ (λ s ih g h₁ h₂ h₃ h₄,
258
+ if hs : s = ∅ then hs.symm ▸ rfl
259
+ else let ⟨x, hx⟩ := exists_mem_of_ne_empty hs in
260
+ have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s,
261
+ from λ y hy, (mem_of_mem_erase (mem_of_mem_erase hy)),
262
+ have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y,
263
+ from λ x hx y hy h, by rw [← h₄ x hx, ← h₄ y hy]; simp [h],
264
+ have ih': (erase (erase s x) (g x hx)).prod f = (1 : β) :=
265
+ ih ((s.erase x).erase (g x hx))
266
+ ⟨subset.trans (erase_subset _ _) (erase_subset _ _),
267
+ λ h, not_mem_erase (g x hx) (s.erase x) (h (h₃ x hx))⟩
268
+ (λ y hy, g y (hmem y hy))
269
+ (λ y hy, h₁ y (hmem y hy))
270
+ (λ y hy, h₂ y (hmem y hy))
271
+ (λ y hy, mem_erase.2 ⟨λ (h : g y _ = g x hx), by simpa [g_inj h] using hy,
272
+ mem_erase.2 ⟨λ (h : g y _ = x),
273
+ have y = g x hx, from h₄ y (hmem y hy) ▸ by simp [h],
274
+ by simpa [this ] using hy, h₃ y (hmem y hy)⟩⟩)
275
+ (λ y hy, h₄ y (hmem y hy)),
276
+ if hx1 : f x = 1
277
+ then ih' ▸ eq.symm (prod_subset hmem
278
+ (λ y hy hy₁,
279
+ have y = x ∨ y = g x hx, by simp [hy] at hy₁; tauto,
280
+ this.elim (λ h, h.symm ▸ hx1)
281
+ (λ h, h₁ x hx ▸ h ▸ hx1.symm ▸ (one_mul _).symm)))
282
+ else by rw [← insert_erase hx, prod_insert (not_mem_erase _ _),
283
+ ← insert_erase (mem_erase.2 ⟨h₂ x hx hx1, h₃ x hx⟩),
284
+ prod_insert (not_mem_erase _ _), ih', mul_one, h₁ x hx])
285
+
235
286
end comm_monoid
236
287
237
- @[simp] lemma sum_const [add_comm_monoid β] [decidable_eq α] (b : β) :
288
+ lemma sum_smul [add_comm_monoid β] (s : finset α) (n : ℕ) (f : α → β) :
289
+ s.sum (λ x, add_monoid.smul n (f x)) = add_monoid.smul n (s.sum f) :=
290
+ @prod_pow _ (multiplicative β) _ _ _ _
291
+ attribute [to_additive finset.sum_smul] prod_pow
292
+
293
+ @[simp] lemma sum_const [add_comm_monoid β] (b : β) :
238
294
s.sum (λ a, b) = add_monoid.smul s.card b :=
239
- @prod_const _ (multiplicative β) _ _ _ _
295
+ @prod_const _ (multiplicative β) _ _ _
240
296
attribute [to_additive finset.sum_const] prod_const
241
297
242
298
lemma sum_range_succ' [add_comm_monoid β] (f : ℕ → β) :
@@ -257,6 +313,23 @@ end comm_group
257
313
card (s.sigma t) = s.sum (λ a, card (t a)) :=
258
314
multiset.card_sigma _ _
259
315
316
+ lemma card_bind [decidable_eq β] {s : finset α} {t : α → finset β}
317
+ (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → t x ∩ t y = ∅) :
318
+ (s.bind t).card = s.sum (λ u, card (t u)) :=
319
+ calc (s.bind t).card = (s.bind t).sum (λ _, 1 ) : by simp
320
+ ... = s.sum (λ a, (t a).sum (λ _, 1 )) : finset.sum_bind h
321
+ ... = s.sum (λ u, card (t u)) : by simp
322
+
323
+ lemma card_bind_le [decidable_eq β] {s : finset α} {t : α → finset β} :
324
+ (s.bind t).card ≤ s.sum (λ a, (t a).card) :=
325
+ by haveI := classical.dec_eq α; exact
326
+ finset.induction_on s (by simp)
327
+ (λ a s has ih,
328
+ calc ((insert a s).bind t).card ≤ (t a).card + (s.bind t).card :
329
+ by rw bind_insert; exact finset.card_union_le _ _
330
+ ... ≤ (insert a s).sum (λ a, card (t a)) :
331
+ by rw sum_insert has; exact add_le_add_left ih _)
332
+
260
333
end finset
261
334
262
335
namespace finset
@@ -402,6 +475,17 @@ end discrete_linear_ordered_field
402
475
(s.pi t).card = s.prod (λ a, card (t a)) :=
403
476
multiset.card_pi _ _
404
477
478
+ @[simp] lemma prod_range_id_eq_fact (n : ℕ) : ((range n.succ).erase 0 ).prod (λ x, x) = nat.fact n :=
479
+ calc ((range n.succ).erase 0 ).prod (λ x, x) = (range n).prod nat.succ :
480
+ eq.symm (prod_bij (λ x _, nat.succ x)
481
+ (λ a h₁, mem_erase.2 ⟨nat.succ_ne_zero _, mem_range.2 $ nat.succ_lt_succ $ by simpa using h₁⟩)
482
+ (by simp) (λ _ _ _ _, nat.succ_inj)
483
+ (λ b h,
484
+ have b.pred.succ = b, from nat.succ_pred_eq_of_pos $
485
+ by simp [nat.pos_iff_ne_zero] at *; tauto,
486
+ ⟨nat.pred b, mem_range.2 $ nat.lt_of_succ_lt_succ (by simp [*, - range_succ] at *), this.symm⟩))
487
+ ... = nat.fact n : by induction n; simp *
488
+
405
489
end finset
406
490
407
491
section group
0 commit comments