Skip to content

Commit 93207dc

Browse files
committed
chore: split Algebra/BigOperators/Group/Finset/Basic (#22261)
1 parent 2dccc4b commit 93207dc

File tree

52 files changed

+270
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+270
-172
lines changed

Mathlib.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ import Mathlib.Algebra.BigOperators.Finprod
5050
import Mathlib.Algebra.BigOperators.Finsupp
5151
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
5252
import Mathlib.Algebra.BigOperators.Group.Finset.Defs
53+
import Mathlib.Algebra.BigOperators.Group.Finset.Pi
54+
import Mathlib.Algebra.BigOperators.Group.Finset.Preimage
55+
import Mathlib.Algebra.BigOperators.Group.Finset.Sigma
5356
import Mathlib.Algebra.BigOperators.Group.List.Basic
5457
import Mathlib.Algebra.BigOperators.Group.List.Defs
5558
import Mathlib.Algebra.BigOperators.Group.List.Lemmas

Mathlib/Algebra/BigOperators/Group/Finset/Basic.lean

Lines changed: 5 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import Mathlib.Algebra.BigOperators.Group.Finset.Defs
88
import Mathlib.Algebra.Group.Even
99
import Mathlib.Data.Finset.Piecewise
1010
import Mathlib.Data.Finset.Powerset
11-
import Mathlib.Data.Finset.Preimage
11+
import Mathlib.Data.Finset.Lattice.Fold
12+
import Mathlib.Order.CompleteLattice.Finset
13+
import Mathlib.Data.Finset.Sum
1214
import Mathlib.Data.Finset.Prod
13-
import Mathlib.Data.Fintype.Pi
1415

1516
/-!
1617
# Big operators
@@ -41,6 +42,7 @@ See the documentation of `to_additive.attr` for more information.
4142
-- TODO
4243
-- assert_not_exists AddCommMonoidWithOne
4344
assert_not_exists MonoidWithZero MulAction OrderedCommMonoid
45+
assert_not_exists Finset.preimage Finset.sigma Fintype.piFinset
4446

4547
variable {ι κ α β γ : Type*}
4648

@@ -289,26 +291,6 @@ theorem prod_biUnion [DecidableEq α] {s : Finset γ} {t : γ → Finset α}
289291
(hs : Set.PairwiseDisjoint (↑s) t) : ∏ x ∈ s.biUnion t, f x = ∏ x ∈ s, ∏ i ∈ t x, f i := by
290292
rw [← disjiUnion_eq_biUnion _ _ hs, prod_disjiUnion]
291293

292-
/-- The product over a sigma type equals the product of the fiberwise products.
293-
For rewriting in the reverse direction, use `Finset.prod_sigma'`.
294-
295-
See also `Fintype.prod_sigma` for the product over the whole type. -/
296-
@[to_additive "The sum over a sigma type equals the sum of the fiberwise sums. For rewriting
297-
in the reverse direction, use `Finset.sum_sigma'`.
298-
299-
See also `Fintype.sum_sigma` for the sum over the whole type."]
300-
theorem prod_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : Sigma σ → β) :
301-
∏ x ∈ s.sigma t, f x = ∏ a ∈ s, ∏ s ∈ t a, f ⟨a, s⟩ := by
302-
simp_rw [← disjiUnion_map_sigma_mk, prod_disjiUnion, prod_map, Function.Embedding.sigmaMk_apply]
303-
304-
/-- The product over a sigma type equals the product of the fiberwise products. For rewriting
305-
in the reverse direction, use `Finset.prod_sigma`. -/
306-
@[to_additive "The sum over a sigma type equals the sum of the fiberwise sums. For rewriting
307-
in the reverse direction, use `Finset.sum_sigma`"]
308-
theorem prod_sigma' {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : ∀ a, σ a → β) :
309-
(∏ a ∈ s, ∏ s ∈ t a, f a s) = ∏ x ∈ s.sigma t, f x.1 x.2 :=
310-
Eq.symm <| prod_sigma s t fun x => f x.1 x.2
311-
312294
section bij
313295
variable {ι κ α : Type*} [CommMonoid α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α}
314296

@@ -362,50 +344,11 @@ lemma prod_fiberwise' (s : Finset ι) (g : ι → κ) (f : κ → α) :
362344

363345
end bij
364346

365-
/-- Taking a product over `univ.pi t` is the same as taking the product over `Fintype.piFinset t`.
366-
`univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ
367-
in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
368-
`Fintype.piFinset t` is a `Finset (Π a, t a)`. -/
369-
@[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over
370-
`Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`,
371-
but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
372-
`Fintype.piFinset t` is a `Finset (Π a, t a)`."]
373-
lemma prod_univ_pi [DecidableEq ι] [Fintype ι] {κ : ι → Type*} (t : ∀ i, Finset (κ i))
374-
(f : (∀ i ∈ (univ : Finset ι), κ i) → β) :
375-
∏ x ∈ univ.pi t, f x = ∏ x ∈ Fintype.piFinset t, f fun a _ ↦ x a := by
376-
apply prod_nbij' (fun x i ↦ x i <| mem_univ _) (fun x i _ ↦ x i) <;> simp
377-
378347
@[to_additive (attr := simp)]
379348
lemma prod_diag [DecidableEq α] (s : Finset α) (f : α × α → β) :
380349
∏ i ∈ s.diag, f i = ∏ i ∈ s, f (i, i) := by
381350
apply prod_nbij' Prod.fst (fun i ↦ (i, i)) <;> simp
382351

383-
@[to_additive]
384-
theorem prod_finset_product (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α)
385-
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ × α → β} :
386-
∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (c, a) := by
387-
refine Eq.trans ?_ (prod_sigma s t fun p => f (p.1, p.2))
388-
apply prod_equiv (Equiv.sigmaEquivProd _ _).symm <;> simp [h]
389-
390-
@[to_additive]
391-
theorem prod_finset_product' (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α)
392-
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ → α → β} :
393-
∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f c a :=
394-
prod_finset_product r s t h
395-
396-
@[to_additive]
397-
theorem prod_finset_product_right (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α)
398-
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α × γ → β} :
399-
∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (a, c) := by
400-
refine Eq.trans ?_ (prod_sigma s t fun p => f (p.2, p.1))
401-
apply prod_equiv ((Equiv.prodComm _ _).trans (Equiv.sigmaEquivProd _ _).symm) <;> simp [h]
402-
403-
@[to_additive]
404-
theorem prod_finset_product_right' (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α)
405-
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α → γ → β} :
406-
∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f a c :=
407-
prod_finset_product_right r s t h
408-
409352
@[to_additive]
410353
theorem prod_image' [DecidableEq α] {s : Finset ι} {g : ι → α} (h : ι → β)
411354
(eq : ∀ i ∈ s, f (g i) = ∏ j ∈ s with g j = g i, h j) :
@@ -426,55 +369,6 @@ lemma prod_mul_prod_comm (f g h i : α → β) :
426369
(∏ a ∈ s, f a * g a) * ∏ a ∈ s, h a * i a = (∏ a ∈ s, f a * h a) * ∏ a ∈ s, g a * i a := by
427370
simp_rw [prod_mul_distrib, mul_mul_mul_comm]
428371

429-
/-- The product over a product set equals the product of the fiberwise products. For rewriting
430-
in the reverse direction, use `Finset.prod_product'`. -/
431-
@[to_additive "The sum over a product set equals the sum of the fiberwise sums. For rewriting
432-
in the reverse direction, use `Finset.sum_product'`"]
433-
theorem prod_product (s : Finset γ) (t : Finset α) (f : γ × α → β) :
434-
∏ x ∈ s ×ˢ t, f x = ∏ x ∈ s, ∏ y ∈ t, f (x, y) :=
435-
prod_finset_product (s ×ˢ t) s (fun _a => t) fun _p => mem_product
436-
437-
/-- The product over a product set equals the product of the fiberwise products. For rewriting
438-
in the reverse direction, use `Finset.prod_product`. -/
439-
@[to_additive "The sum over a product set equals the sum of the fiberwise sums. For rewriting
440-
in the reverse direction, use `Finset.sum_product`"]
441-
theorem prod_product' (s : Finset γ) (t : Finset α) (f : γ → α → β) :
442-
∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ x ∈ s, ∏ y ∈ t, f x y :=
443-
prod_product ..
444-
445-
@[to_additive]
446-
theorem prod_product_right (s : Finset γ) (t : Finset α) (f : γ × α → β) :
447-
∏ x ∈ s ×ˢ t, f x = ∏ y ∈ t, ∏ x ∈ s, f (x, y) :=
448-
prod_finset_product_right (s ×ˢ t) t (fun _a => s) fun _p => mem_product.trans and_comm
449-
450-
/-- An uncurried version of `Finset.prod_product_right`. -/
451-
@[to_additive "An uncurried version of `Finset.sum_product_right`"]
452-
theorem prod_product_right' (s : Finset γ) (t : Finset α) (f : γ → α → β) :
453-
∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ y ∈ t, ∏ x ∈ s, f x y :=
454-
prod_product_right ..
455-
456-
/-- Generalization of `Finset.prod_comm` to the case when the inner `Finset`s depend on the outer
457-
variable. -/
458-
@[to_additive "Generalization of `Finset.sum_comm` to the case when the inner `Finset`s depend on
459-
the outer variable."]
460-
theorem prod_comm' {s : Finset γ} {t : γ → Finset α} {t' : Finset α} {s' : α → Finset γ}
461-
(h : ∀ x y, x ∈ s ∧ y ∈ t x ↔ x ∈ s' y ∧ y ∈ t') {f : γ → α → β} :
462-
(∏ x ∈ s, ∏ y ∈ t x, f x y) = ∏ y ∈ t', ∏ x ∈ s' y, f x y := by
463-
classical
464-
have : ∀ z : γ × α, (z ∈ s.biUnion fun x => (t x).map <| Function.Embedding.sectR x _) ↔
465-
z.1 ∈ s ∧ z.2 ∈ t z.1 := by
466-
rintro ⟨x, y⟩
467-
simp only [mem_biUnion, mem_map, Function.Embedding.sectR_apply, Prod.mk.injEq,
468-
exists_eq_right, ← and_assoc]
469-
exact
470-
(prod_finset_product' _ _ _ this).symm.trans
471-
((prod_finset_product_right' _ _ _) fun ⟨x, y⟩ => (this _).trans ((h x y).trans and_comm))
472-
473-
@[to_additive]
474-
theorem prod_comm {s : Finset γ} {t : Finset α} {f : γ → α → β} :
475-
(∏ x ∈ s, ∏ y ∈ t, f x y) = ∏ y ∈ t, ∏ x ∈ s, f x y :=
476-
prod_comm' fun _ _ => Iff.rfl
477-
478372
@[to_additive]
479373
theorem prod_filter_of_ne {p : α → Prop} [DecidablePred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) :
480374
∏ x ∈ s with p x, f x = ∏ x ∈ s, f x :=
@@ -617,26 +511,6 @@ theorem prod_subtype {p : α → Prop} {F : Fintype (Subtype p)} (s : Finset α)
617511
rw [← prod_coe_sort]
618512
congr!
619513

620-
@[to_additive]
621-
lemma prod_preimage' (f : ι → κ) [DecidablePred (· ∈ Set.range f)] (s : Finset κ) (hf) (g : κ → β) :
622-
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s with x ∈ Set.range f, g x := by
623-
classical
624-
calc
625-
∏ x ∈ preimage s f hf, g (f x) = ∏ x ∈ image f (preimage s f hf), g x :=
626-
Eq.symm <| prod_image <| by simpa only [mem_preimage, Set.InjOn] using hf
627-
_ = ∏ x ∈ s with x ∈ Set.range f, g x := by rw [image_preimage]
628-
629-
@[to_additive]
630-
lemma prod_preimage (f : ι → κ) (s : Finset κ) (hf) (g : κ → β)
631-
(hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) :
632-
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s, g x := by
633-
classical rw [prod_preimage', prod_filter_of_ne]; exact fun x hx ↦ Not.imp_symm (hg x hx)
634-
635-
@[to_additive]
636-
lemma prod_preimage_of_bij (f : ι → κ) (s : Finset κ) (hf : Set.BijOn f (f ⁻¹' ↑s) ↑s) (g : κ → β) :
637-
∏ x ∈ s.preimage f hf.injOn, g (f x) = ∏ x ∈ s, g x :=
638-
prod_preimage _ _ hf.injOn g fun _ hs h_f ↦ (h_f <| hf.subset_range hs).elim
639-
640514
@[to_additive]
641515
theorem prod_set_coe (s : Set α) [Fintype s] : (∏ i : s, f i) = ∏ i ∈ s.toFinset, f i :=
642516
(Finset.prod_subtype s.toFinset (fun _ ↦ Set.mem_toFinset) f).symm
@@ -1410,11 +1284,6 @@ theorem prod_erase_eq_div {a : α} (h : a ∈ s) :
14101284

14111285
end CommGroup
14121286

1413-
@[simp]
1414-
theorem card_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) :
1415-
#(s.sigma t) = ∑ a ∈ s, #(t a) :=
1416-
Multiset.card_sigma _ _
1417-
14181287
@[simp]
14191288
theorem card_disjiUnion (s : Finset α) (t : α → Finset β) (h) :
14201289
#(s.disjiUnion t h) = ∑ a ∈ s, #(t a) :=
@@ -1674,4 +1543,4 @@ theorem nat_abs_sum_le {ι : Type*} (s : Finset ι) (f : ι → ℤ) :
16741543
simp only [Finset.sum_cons, not_false_iff]
16751544
exact (Int.natAbs_add_le _ _).trans (Nat.add_le_add_left IH _)
16761545

1677-
set_option linter.style.longFile 1800
1546+
set_option linter.style.longFile 1700
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/-
2+
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Johannes Hölzl
5+
-/
6+
import Mathlib.Data.Fintype.Pi
7+
import Mathlib.Algebra.BigOperators.Group.Finset.Defs
8+
9+
10+
/-!
11+
# Products over `univ.pi`
12+
13+
-/
14+
15+
assert_not_exists MonoidWithZero MulAction OrderedCommMonoid
16+
17+
variable {ι β : Type*}
18+
19+
open Fin Function
20+
21+
namespace Finset
22+
23+
variable [CommMonoid β]
24+
25+
/-- Taking a product over `univ.pi t` is the same as taking the product over `Fintype.piFinset t`.
26+
`univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ
27+
in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
28+
`Fintype.piFinset t` is a `Finset (Π a, t a)`. -/
29+
@[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over
30+
`Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`,
31+
but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
32+
`Fintype.piFinset t` is a `Finset (Π a, t a)`."]
33+
lemma prod_univ_pi [DecidableEq ι] [Fintype ι] {κ : ι → Type*} (t : ∀ i, Finset (κ i))
34+
(f : (∀ i ∈ (univ : Finset ι), κ i) → β) :
35+
∏ x ∈ univ.pi t, f x = ∏ x ∈ Fintype.piFinset t, f fun a _ ↦ x a := by
36+
apply prod_nbij' (fun x i ↦ x i <| mem_univ _) (fun x i _ ↦ x i) <;> simp
37+
38+
end Finset
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/-
2+
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Johannes Hölzl
5+
-/
6+
import Mathlib.Data.Finset.Preimage
7+
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
8+
9+
/-!
10+
# Sums and products over preimages of finite sets.
11+
-/
12+
13+
assert_not_exists MonoidWithZero MulAction OrderedCommMonoid
14+
15+
variable {ι κ β : Type*}
16+
17+
open Fin Function
18+
19+
namespace Finset
20+
21+
variable [CommMonoid β]
22+
23+
@[to_additive]
24+
lemma prod_preimage' (f : ι → κ) [DecidablePred (· ∈ Set.range f)] (s : Finset κ) (hf) (g : κ → β) :
25+
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s with x ∈ Set.range f, g x := by
26+
classical
27+
calc
28+
∏ x ∈ preimage s f hf, g (f x) = ∏ x ∈ image f (preimage s f hf), g x :=
29+
Eq.symm <| prod_image <| by simpa only [mem_preimage, Set.InjOn] using hf
30+
_ = ∏ x ∈ s with x ∈ Set.range f, g x := by rw [image_preimage]
31+
32+
@[to_additive]
33+
lemma prod_preimage (f : ι → κ) (s : Finset κ) (hf) (g : κ → β)
34+
(hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) :
35+
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s, g x := by
36+
classical rw [prod_preimage', prod_filter_of_ne]; exact fun x hx ↦ Not.imp_symm (hg x hx)
37+
38+
@[to_additive]
39+
lemma prod_preimage_of_bij (f : ι → κ) (s : Finset κ) (hf : Set.BijOn f (f ⁻¹' ↑s) ↑s) (g : κ → β) :
40+
∏ x ∈ s.preimage f hf.injOn, g (f x) = ∏ x ∈ s, g x :=
41+
prod_preimage _ _ hf.injOn g fun _ hs h_f ↦ (h_f <| hf.subset_range hs).elim
42+
43+
end Finset

0 commit comments

Comments
 (0)