doc-next-gen

Mathlib.Algebra.BigOperators.Group.Finset.Basic

Module docstring

{"# Big operators

In this file we prove theorems about products and sums indexed by a Finset. "}

Finset.prod_eq_fold theorem
(s : Finset ι) (f : ι → M) : ∏ i ∈ s, f i = s.fold (β := M) (· * ·) 1 f
Full source
@[to_additive]
lemma prod_eq_fold (s : Finset ι) (f : ι → M) : ∏ i ∈ s, f i = s.fold (β := M) (· * ·) 1 f := rfl
Product as Fold over Finite Set in Commutative Monoid
Informal description
Let $M$ be a commutative monoid, $s$ a finite set of type $\iota$, and $f : \iota \to M$ a function. The product $\prod_{i \in s} f(i)$ is equal to the fold of the multiplication operation over $s$ with initial value $1$, i.e., $$\prod_{i \in s} f(i) = \text{fold } (\cdot) \text{ } 1 \text{ } f \text{ } s.$$
Finset.prod_cons theorem
(h : a ∉ s) : ∏ x ∈ cons a s h, f x = f a * ∏ x ∈ s, f x
Full source
@[to_additive (attr := simp)]
theorem prod_cons (h : a ∉ s) : ∏ x ∈ cons a s h, f x = f a * ∏ x ∈ s, f x :=
  fold_cons h
Product over disjoint union of singleton and finite set
Informal description
Let $\beta$ be a commutative monoid, $s$ a finite subset of $\alpha$, and $f : \alpha \to \beta$ a function. For any element $a \notin s$, we have $$\prod_{x \in \{a\} \cup s} f(x) = f(a) \cdot \prod_{x \in s} f(x).$$
Finset.prod_insert theorem
[DecidableEq ι] : a ∉ s → ∏ x ∈ insert a s, f x = f a * ∏ x ∈ s, f x
Full source
@[to_additive (attr := simp)]
theorem prod_insert [DecidableEq ι] : a ∉ s∏ x ∈ insert a s, f x = f a * ∏ x ∈ s, f x :=
  fold_insert
Product over Insertion of an Element into a Finite Set
Informal description
Let $\beta$ be a commutative monoid, $s$ a finite set of type $\iota$, and $f : \iota \to \beta$ a function. For any element $a \notin s$, we have $$\prod_{x \in \text{insert } a \text{ } s} f(x) = f(a) \cdot \prod_{x \in s} f(x).$$
Finset.prod_insert_of_eq_one_if_not_mem theorem
[DecidableEq ι] (h : a ∉ s → f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x
Full source
/-- 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`. -/
@[to_additive (attr := simp) "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`."]
theorem prod_insert_of_eq_one_if_not_mem [DecidableEq ι] (h : a ∉ s → f a = 1) :
    ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := by
  by_cases hm : a ∈ s
  · simp_rw [insert_eq_of_mem hm]
  · rw [prod_insert hm, h hm, one_mul]
Product over Insertion Equals Original Product When Function is One or Element is Present
Informal description
Let $\iota$ be a type with decidable equality, $s$ a finite subset of $\iota$, $f : \iota \to M$ a function to a commutative monoid $M$, and $a \in \iota$. If either $a \in s$ or $f(a) = 1$, then the product of $f$ over the set $\{a\} \cup s$ equals the product of $f$ over $s$, i.e., \[ \prod_{x \in \{a\} \cup s} f(x) = \prod_{x \in s} f(x). \]
Finset.prod_insert_one theorem
[DecidableEq ι] (h : f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x
Full source
/-- The product of `f` over `insert a s` is the same as
the product over `s`, as long as `f a = 1`. -/
@[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `f a = 0`."]
theorem prod_insert_one [DecidableEq ι] (h : f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x :=
  prod_insert_of_eq_one_if_not_mem fun _ => h
Product over Insertion of One Equals Original Product
Informal description
Let $\iota$ be a type with decidable equality, $M$ a commutative monoid, $s$ a finite subset of $\iota$, $f : \iota \to M$ a function, and $a \in \iota$. If $f(a) = 1$, then the product of $f$ over the set $\{a\} \cup s$ equals the product of $f$ over $s$, i.e., \[ \prod_{x \in \{a\} \cup s} f(x) = \prod_{x \in s} f(x). \]
Finset.prod_singleton theorem
(f : ι → M) (a : ι) : ∏ x ∈ singleton a, f x = f a
Full source
@[to_additive (attr := simp)]
theorem prod_singleton (f : ι → M) (a : ι) : ∏ x ∈ singleton a, f x = f a :=
  Eq.trans fold_singleton <| mul_one _
Product over Singleton Set Equals Function Value
Informal description
For any function $f : \iota \to M$ where $M$ is a commutative monoid, and any element $a \in \iota$, the product of $f$ over the singleton set $\{a\}$ is equal to $f(a)$, i.e., \[ \prod_{x \in \{a\}} f(x) = f(a). \]
Finset.prod_pair theorem
[DecidableEq ι] {a b : ι} (h : a ≠ b) : (∏ x ∈ ({ a, b } : Finset ι), f x) = f a * f b
Full source
@[to_additive]
theorem prod_pair [DecidableEq ι] {a b : ι} (h : a ≠ b) :
    (∏ x ∈ ({a, b} : Finset ι), f x) = f a * f b := by
  rw [prod_insert (not_mem_singleton.2 h), prod_singleton]
Product over Pair of Distinct Elements Equals Product of Their Values
Informal description
Let $\iota$ be a type with decidable equality, $M$ a commutative monoid, and $f : \iota \to M$ a function. For any two distinct elements $a, b \in \iota$, the product of $f$ over the finite set $\{a, b\}$ is equal to $f(a) \cdot f(b)$, i.e., \[ \prod_{x \in \{a, b\}} f(x) = f(a) \cdot f(b). \]
Finset.prod_image theorem
[DecidableEq ι] {s : Finset κ} {g : κ → ι} : (∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → ∏ x ∈ s.image g, f x = ∏ x ∈ s, f (g x)
Full source
@[to_additive (attr := simp)]
theorem prod_image [DecidableEq ι] {s : Finset κ} {g : κ → ι} :
    (∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → ∏ x ∈ s.image g, f x = ∏ x ∈ s, f (g x) :=
  fold_image
Product over Image Equals Product over Preimage under Injective Map
Informal description
Let $\iota$ and $\kappa$ be types with decidable equality on $\iota$, and let $s$ be a finite subset of $\kappa$. Given a function $g : \kappa \to \iota$ that is injective on $s$ (i.e., for any $x, y \in s$, if $g(x) = g(y)$, then $x = y$), and a function $f : \iota \to M$ where $M$ is a commutative monoid, we have: \[ \prod_{x \in g(s)} f(x) = \prod_{x \in s} f(g(x)). \]
Finset.prod_attach theorem
(s : Finset ι) (f : ι → M) : ∏ x ∈ s.attach, f x = ∏ x ∈ s, f x
Full source
@[to_additive]
lemma prod_attach (s : Finset ι) (f : ι → M) : ∏ x ∈ s.attach, f x = ∏ x ∈ s, f x := by
  classical rw [← prod_image Subtype.coe_injective.injOn, attach_image_val]
Product Equality over Attached Finite Set
Informal description
Let $s$ be a finite set of elements of type $\iota$, and let $f : \iota \to M$ be a function where $M$ is a commutative monoid. Then the product of $f$ over the attached set $s.\text{attach}$ is equal to the product of $f$ over $s$ itself, i.e., \[ \prod_{x \in s.\text{attach}} f(x) = \prod_{x \in s} f(x). \]
Finset.prod_congr theorem
(h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g
Full source
@[to_additive (attr := congr)]
theorem prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g := by
  rw [h]; exact fold_congr
Product Equality under Function Congruence on Equal Finite Sets
Informal description
Let $s_1$ and $s_2$ be two finite sets of type $\alpha$ such that $s_1 = s_2$, and let $f, g : \alpha \to \beta$ be functions where $\beta$ is a commutative monoid. If for every $x \in s_2$ we have $f(x) = g(x)$, then the product of $f$ over $s_1$ is equal to the product of $g$ over $s_2$, i.e., \[ \prod_{x \in s_1} f(x) = \prod_{x \in s_2} g(x). \]
Finset.prod_eq_one_iff theorem
[Subsingleton Mˣ] : ∏ i ∈ s, f i = 1 ↔ ∀ i ∈ s, f i = 1
Full source
/-- In a monoid whose only unit is `1`, a product is equal to `1` iff all factors are `1`. -/
@[to_additive (attr := simp)
"In an additive monoid whose only unit is `0`, a sum is equal to `0` iff all terms are `0`."]
lemma prod_eq_one_iff [Subsingleton ] : ∏ i ∈ s, f i∏ i ∈ s, f i = 1 ↔ ∀ i ∈ s, f i = 1 := by
  induction' s using Finset.cons_induction with i s hi ih <;> simp [*]
Product equals one iff all factors are one in a monoid with trivial units
Informal description
Let $M$ be a commutative monoid whose only unit is $1$, and let $s$ be a finite set. For a function $f : \alpha \to M$, the product $\prod_{i \in s} f(i) = 1$ if and only if $f(i) = 1$ for all $i \in s$.
Finset.prod_disjUnion theorem
(h) : ∏ x ∈ s₁.disjUnion s₂ h, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x
Full source
@[to_additive]
theorem prod_disjUnion (h) :
    ∏ x ∈ s₁.disjUnion s₂ h, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by
  refine Eq.trans ?_ (fold_disjUnion h)
  rw [one_mul]
  rfl
Product over Disjoint Union: $\prod_{x \in s_1 \sqcup s_2} f(x) = (\prod_{x \in s_1} f(x)) \cdot (\prod_{x \in s_2} f(x))$
Informal description
For any two disjoint finite sets $s_1$ and $s_2$ of type $\alpha$ (with disjointness witnessed by $h$), and any function $f : \alpha \to M$ where $M$ is a commutative monoid, the product of $f$ over the disjoint union $s_1 \sqcup s_2$ equals the product of the product over $s_1$ and the product over $s_2$. That is, \[ \prod_{x \in s_1 \sqcup s_2} f(x) = \left(\prod_{x \in s_1} f(x)\right) \cdot \left(\prod_{x \in s_2} f(x)\right). \]
Finset.prod_disjiUnion theorem
(s : Finset κ) (t : κ → Finset ι) (h) : ∏ x ∈ s.disjiUnion t h, f x = ∏ i ∈ s, ∏ x ∈ t i, f x
Full source
@[to_additive]
theorem prod_disjiUnion (s : Finset κ) (t : κ → Finset ι) (h) :
    ∏ x ∈ s.disjiUnion t h, f x = ∏ i ∈ s, ∏ x ∈ t i, f x := by
  refine Eq.trans ?_ (fold_disjiUnion h)
  dsimp [Finset.prod, Multiset.prod, Multiset.fold, Finset.disjUnion, Finset.fold]
  congr
  exact prod_const_one.symm
Product over Disjoint Union Equals Iterated Product: $\prod_{\text{disjiUnion}\, s\, t\, h} f = \prod_{i \in s} \prod_{x \in t(i)} f$
Informal description
Let $\kappa$ and $\iota$ be types, $s$ a finite subset of $\kappa$, and $t \colon \kappa \to \text{Finset} \iota$ a function such that the images $t(i)$ for $i \in s$ are pairwise disjoint. For any commutative monoid $M$ and function $f \colon \iota \to M$, the product of $f$ over the disjoint union $\text{disjiUnion}\, s\, t\, h$ equals the iterated product over $s$ of the products of $f$ over each $t(i)$. That is, \[ \prod_{x \in \text{disjiUnion}\, s\, t\, h} f(x) = \prod_{i \in s} \prod_{x \in t(i)} f(x). \]
Finset.prod_union_inter theorem
[DecidableEq ι] : (∏ x ∈ s₁ ∪ s₂, f x) * ∏ x ∈ s₁ ∩ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x
Full source
@[to_additive]
theorem prod_union_inter [DecidableEq ι] :
    (∏ x ∈ s₁ ∪ s₂, f x) * ∏ x ∈ s₁ ∩ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x :=
  fold_union_inter
Product over Union and Intersection Identity: $\prod_{s_1 \cup s_2} f \cdot \prod_{s_1 \cap s_2} f = \prod_{s_1} f \cdot \prod_{s_2} f$
Informal description
For any finite sets $s_1, s_2$ of type $\iota$ (with decidable equality) and any function $f : \iota \to \beta$ where $\beta$ is a commutative monoid, the following identity holds: \[ \left(\prod_{x \in s_1 \cup s_2} f(x)\right) \cdot \left(\prod_{x \in s_1 \cap s_2} f(x)\right) = \left(\prod_{x \in s_1} f(x)\right) \cdot \left(\prod_{x \in s_2} f(x)\right). \]
Finset.prod_union theorem
[DecidableEq ι] (h : Disjoint s₁ s₂) : ∏ x ∈ s₁ ∪ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x
Full source
@[to_additive]
theorem prod_union [DecidableEq ι] (h : Disjoint s₁ s₂) :
    ∏ x ∈ s₁ ∪ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by
  rw [← prod_union_inter, disjoint_iff_inter_eq_empty.mp h]; exact (mul_one _).symm
Product over Union of Disjoint Sets: $\prod_{s_1 \cup s_2} f = \prod_{s_1} f \cdot \prod_{s_2} f$
Informal description
For any finite sets $s_1$ and $s_2$ of type $\iota$ (with decidable equality) that are disjoint, and for any function $f : \iota \to \beta$ where $\beta$ is a commutative monoid, the product over the union of $s_1$ and $s_2$ satisfies: \[ \prod_{x \in s_1 \cup s_2} f(x) = \left(\prod_{x \in s_1} f(x)\right) \cdot \left(\prod_{x \in s_2} f(x)\right). \]
Finset.prod_filter_mul_prod_filter_not theorem
(s : Finset ι) (p : ι → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : ι → M) : (∏ x ∈ s with p x, f x) * ∏ x ∈ s with ¬p x, f x = ∏ x ∈ s, f x
Full source
@[to_additive]
theorem prod_filter_mul_prod_filter_not
    (s : Finset ι) (p : ι → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : ι → M) :
    (∏ x ∈ s with p x, f x) * ∏ x ∈ s with ¬p x, f x = ∏ x ∈ s, f x := by
  have := Classical.decEq ι
  rw [← prod_union (disjoint_filter_filter_neg s s p), filter_union_filter_neg_eq]
Product Decomposition over Filtered Sets: $\prod_{s \text{ with } p} f \cdot \prod_{s \text{ with } \neg p} f = \prod_s f$
Informal description
For any finite set $s$ of type $\iota$, any decidable predicate $p$ on $\iota$ (with decidable negation), and any function $f : \iota \to M$ where $M$ is a commutative monoid, the product of $f$ over the elements of $s$ satisfying $p$ multiplied by the product of $f$ over the elements of $s$ not satisfying $p$ equals the product of $f$ over all elements of $s$. That is, \[ \left(\prod_{x \in s \text{ with } p(x)} f(x)\right) \cdot \left(\prod_{x \in s \text{ with } \neg p(x)} f(x)\right) = \prod_{x \in s} f(x). \]
Finset.prod_filter_not_mul_prod_filter theorem
(s : Finset ι) (p : ι → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : ι → M) : (∏ x ∈ s with ¬p x, f x) * ∏ x ∈ s with p x, f x = ∏ x ∈ s, f x
Full source
@[to_additive]
lemma prod_filter_not_mul_prod_filter (s : Finset ι) (p : ι → Prop) [DecidablePred p]
    [∀ x, Decidable (¬p x)] (f : ι → M) :
    (∏ x ∈ s with ¬p x, f x) * ∏ x ∈ s with p x, f x = ∏ x ∈ s, f x := by
  rw [mul_comm, prod_filter_mul_prod_filter_not]
Product Decomposition over Complementary Filters: $\prod_{s \text{ with } \neg p} f \cdot \prod_{s \text{ with } p} f = \prod_s f$
Informal description
For any finite set $s$ of type $\iota$, any decidable predicate $p$ on $\iota$ (with decidable negation), and any function $f : \iota \to M$ where $M$ is a commutative monoid, the product of $f$ over the elements of $s$ not satisfying $p$ multiplied by the product of $f$ over the elements of $s$ satisfying $p$ equals the product of $f$ over all elements of $s$. That is, \[ \left(\prod_{x \in s \text{ with } \neg p(x)} f(x)\right) \cdot \left(\prod_{x \in s \text{ with } p(x)} f(x)\right) = \prod_{x \in s} f(x). \]
Finset.prod_filter_xor theorem
(p q : ι → Prop) [DecidablePred p] [DecidablePred q] : (∏ x ∈ s with (Xor' (p x) (q x)), f x) = (∏ x ∈ s with (p x ∧ ¬q x), f x) * (∏ x ∈ s with (q x ∧ ¬p x), f x)
Full source
@[to_additive]
theorem prod_filter_xor (p q : ι → Prop) [DecidablePred p] [DecidablePred q] :
    (∏ x ∈ s with (Xor' (p x) (q x)), f x) =
      (∏ x ∈ s with (p x ∧ ¬ q x), f x) * (∏ x ∈ s with (q x ∧ ¬ p x), f x) := by
  classical rw [← prod_union (disjoint_filter_and_not_filter _ _), ← filter_or]
  simp only [Xor']
Product over Exclusive-or Condition: $\prod_{s \text{ with } p \mathbin{\text{Xor}} q} f = \prod_{s \text{ with } p \land \neg q} f \cdot \prod_{s \text{ with } q \land \neg p} f$
Informal description
Let $s$ be a finite set of type $\iota$, and let $p, q : \iota \to \text{Prop}$ be decidable predicates. For any commutative monoid $M$ and function $f : \iota \to M$, the product of $f$ over the elements of $s$ satisfying the exclusive-or condition $p(x) \mathbin{\text{Xor}} q(x)$ is equal to the product of the product over elements satisfying $p(x) \land \neg q(x)$ and the product over elements satisfying $q(x) \land \neg p(x)$. That is, \[ \prod_{\substack{x \in s \\ p(x) \mathbin{\text{Xor}} q(x)}} f(x) = \left(\prod_{\substack{x \in s \\ p(x) \land \neg q(x)}} f(x)\right) \cdot \left(\prod_{\substack{x \in s \\ q(x) \land \neg p(x)}} f(x)\right). \]
IsCompl.prod_mul_prod theorem
[Fintype ι] {s t : Finset ι} (h : IsCompl s t) (f : ι → M) : (∏ i ∈ s, f i) * ∏ i ∈ t, f i = ∏ i, f i
Full source
@[to_additive]
theorem _root_.IsCompl.prod_mul_prod [Fintype ι] {s t : Finset ι} (h : IsCompl s t) (f : ι → M) :
    (∏ i ∈ s, f i) * ∏ i ∈ t, f i = ∏ i, f i :=
  (Finset.prod_disjUnion h.disjoint).symm.trans <| by
    classical rw [Finset.disjUnion_eq_union, ← Finset.sup_eq_union, h.sup_eq_top]; rfl
Product over Complementary Finite Subsets: $\prod_{s} f \cdot \prod_{t} f = \prod_{\iota} f$
Informal description
Let $\iota$ be a finite type, and let $s$ and $t$ be finite subsets of $\iota$ that are complements in the lattice of finite subsets (i.e., $s \cap t = \emptyset$ and $s \cup t = \text{univ}$). For any commutative monoid $M$ and any function $f : \iota \to M$, the product of $f$ over $s$ multiplied by the product of $f$ over $t$ equals the product of $f$ over the entire type $\iota$. That is, \[ \left(\prod_{i \in s} f(i)\right) \cdot \left(\prod_{i \in t} f(i)\right) = \prod_{i \in \iota} f(i). \]
Finset.prod_mul_prod_compl theorem
[Fintype ι] [DecidableEq ι] (s : Finset ι) (f : ι → M) : (∏ i ∈ s, f i) * ∏ i ∈ sᶜ, f i = ∏ i, f i
Full source
/-- Multiplying the products of a function over `s` and over `sᶜ` gives the whole product.
For a version expressed with subtypes, see `Fintype.prod_subtype_mul_prod_subtype`. -/
@[to_additive "Adding the sums of a function over `s` and over `sᶜ` gives the whole sum.
For a version expressed with subtypes, see `Fintype.sum_subtype_add_sum_subtype`. "]
lemma prod_mul_prod_compl [Fintype ι] [DecidableEq ι] (s : Finset ι) (f : ι → M) :
    (∏ i ∈ s, f i) * ∏ i ∈ sᶜ, f i = ∏ i, f i :=
  IsCompl.prod_mul_prod isCompl_compl f
Product over Set and Complement Equals Total Product: $\prod_{s} f \cdot \prod_{s^\complement} f = \prod_{\iota} f$
Informal description
Let $\iota$ be a finite type with decidable equality, $M$ a commutative monoid, $s$ a finite subset of $\iota$, and $f : \iota \to M$ a function. Then the product of $f$ over $s$ multiplied by the product of $f$ over the complement $s^\complement$ equals the product of $f$ over all elements of $\iota$: \[ \left(\prod_{i \in s} f(i)\right) \cdot \left(\prod_{i \in s^\complement} f(i)\right) = \prod_{i \in \iota} f(i). \]
Finset.prod_compl_mul_prod theorem
[Fintype ι] [DecidableEq ι] (s : Finset ι) (f : ι → M) : (∏ i ∈ sᶜ, f i) * ∏ i ∈ s, f i = ∏ i, f i
Full source
@[to_additive]
lemma prod_compl_mul_prod [Fintype ι] [DecidableEq ι] (s : Finset ι) (f : ι → M) :
    (∏ i ∈ sᶜ, f i) * ∏ i ∈ s, f i = ∏ i, f i :=
  (@isCompl_compl _ s _).symm.prod_mul_prod f
Product over Set and Complement: $\prod_{s^\complement} f \cdot \prod_s f = \prod_\iota f$
Informal description
Let $\iota$ be a finite type with decidable equality, $s$ be a finite subset of $\iota$, and $M$ be a commutative monoid. For any function $f : \iota \to M$, the product of $f$ over the complement of $s$ multiplied by the product of $f$ over $s$ equals the product of $f$ over the entire type $\iota$. That is, \[ \left(\prod_{i \in s^\complement} f(i)\right) \cdot \left(\prod_{i \in s} f(i)\right) = \prod_{i \in \iota} f(i). \]
Finset.prod_sdiff theorem
[DecidableEq ι] (h : s₁ ⊆ s₂) : (∏ x ∈ s₂ \ s₁, f x) * ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x
Full source
@[to_additive]
theorem prod_sdiff [DecidableEq ι] (h : s₁ ⊆ s₂) :
    (∏ x ∈ s₂ \ s₁, f x) * ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x := by
  rw [← prod_union sdiff_disjoint, sdiff_union_of_subset h]
Product Decomposition over Set Difference: $\prod_{s_2} f = (\prod_{s_2 \setminus s_1} f) \cdot (\prod_{s_1} f)$
Informal description
Let $\iota$ be a type with decidable equality, and let $s_1$ and $s_2$ be finite subsets of $\iota$ such that $s_1 \subseteq s_2$. For any commutative monoid $\beta$ and any function $f : \iota \to \beta$, the product over $s_2$ can be decomposed as: \[ \left(\prod_{x \in s_2 \setminus s_1} f(x)\right) \cdot \left(\prod_{x \in s_1} f(x)\right) = \prod_{x \in s_2} f(x). \]
Finset.prod_subset_one_on_sdiff theorem
[DecidableEq ι] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ s₂ \ s₁, g x = 1) (hfg : ∀ x ∈ s₁, f x = g x) : ∏ i ∈ s₁, f i = ∏ i ∈ s₂, g i
Full source
@[to_additive]
theorem prod_subset_one_on_sdiff [DecidableEq ι] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ s₂ \ s₁, g x = 1)
    (hfg : ∀ x ∈ s₁, f x = g x) : ∏ i ∈ s₁, f i = ∏ i ∈ s₂, g i := by
  rw [← prod_sdiff h, prod_eq_one hg, one_mul]
  exact prod_congr rfl hfg
Product Equality under Function Agreement and Triviality on Set Difference: $\prod_{s_1} f = \prod_{s_2} g$
Informal description
Let $\iota$ be a type with decidable equality, and let $s_1$ and $s_2$ be finite subsets of $\iota$ such that $s_1 \subseteq s_2$. Given functions $f, g : \iota \to M$ where $M$ is a commutative monoid, suppose that: 1. For all $x \in s_2 \setminus s_1$, $g(x) = 1$, and 2. For all $x \in s_1$, $f(x) = g(x)$. Then the product of $f$ over $s_1$ equals the product of $g$ over $s_2$, i.e., \[ \prod_{i \in s_1} f(i) = \prod_{i \in s_2} g(i). \]
Finset.prod_subset theorem
(h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) : ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x
Full source
@[to_additive]
theorem prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) :
    ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x :=
  haveI := Classical.decEq ι
  prod_subset_one_on_sdiff h (by simpa) fun _ _ => rfl
Product Equality under Triviality on Set Difference: $\prod_{s_1} f = \prod_{s_2} f$
Informal description
Let $s_1$ and $s_2$ be finite subsets of a type $\alpha$ with decidable equality, such that $s_1 \subseteq s_2$. Given a function $f : \alpha \to M$ where $M$ is a commutative monoid, suppose that for all $x \in s_2$ not in $s_1$, $f(x) = 1$. Then the product of $f$ over $s_1$ equals the product of $f$ over $s_2$, i.e., \[ \prod_{x \in s_1} f(x) = \prod_{x \in s_2} f(x). \]
Finset.prod_disj_sum theorem
(s : Finset ι) (t : Finset κ) (f : ι ⊕ κ → M) : ∏ x ∈ s.disjSum t, f x = (∏ x ∈ s, f (Sum.inl x)) * ∏ x ∈ t, f (Sum.inr x)
Full source
@[to_additive (attr := simp)]
theorem prod_disj_sum (s : Finset ι) (t : Finset κ) (f : ι ⊕ κ → M) :
    ∏ x ∈ s.disjSum t, f x = (∏ x ∈ s, f (Sum.inl x)) * ∏ x ∈ t, f (Sum.inr x) := by
  rw [← map_inl_disjUnion_map_inr, prod_disjUnion, prod_map, prod_map]
  rfl
Product over Disjoint Sum: $\prod_{x \in s \uplus t} f(x) = (\prod_{x \in s} f(\text{inl}(x))) \cdot (\prod_{x \in t} f(\text{inr}(x)))$
Informal description
Let $s$ be a finite set of type $\iota$, $t$ a finite set of type $\kappa$, and $f : \iota \oplus \kappa \to M$ a function where $M$ is a commutative monoid. Then the product of $f$ over the disjoint sum $s \uplus t$ equals the product of $f$ applied to the left injections of elements of $s$ multiplied by the product of $f$ applied to the right injections of elements of $t$. In symbols: \[ \prod_{x \in s \uplus t} f(x) = \left(\prod_{x \in s} f(\text{inl}(x))\right) \cdot \left(\prod_{x \in t} f(\text{inr}(x))\right). \]
Finset.prod_sum_eq_prod_toLeft_mul_prod_toRight theorem
(s : Finset (ι ⊕ κ)) (f : ι ⊕ κ → M) : ∏ x ∈ s, f x = (∏ x ∈ s.toLeft, f (Sum.inl x)) * ∏ x ∈ s.toRight, f (Sum.inr x)
Full source
@[to_additive]
lemma prod_sum_eq_prod_toLeft_mul_prod_toRight (s : Finset (ι ⊕ κ)) (f : ι ⊕ κ → M) :
    ∏ x ∈ s, f x = (∏ x ∈ s.toLeft, f (Sum.inl x)) * ∏ x ∈ s.toRight, f (Sum.inr x) := by
  rw [← Finset.toLeft_disjSum_toRight (u := s), Finset.prod_disj_sum, Finset.toLeft_disjSum,
    Finset.toRight_disjSum]
Product Decomposition over Disjoint Union: $\prod_{x \in s} f(x) = \prod_{\text{left}} f \cdot \prod_{\text{right}} f$
Informal description
For any finite set $s$ of elements in the disjoint union type $\iota \oplus \kappa$ and any function $f : \iota \oplus \kappa \to M$ where $M$ is a commutative monoid, the product of $f$ over $s$ equals the product of $f$ applied to the left components of $s$ multiplied by the product of $f$ applied to the right components of $s$. In symbols: \[ \prod_{x \in s} f(x) = \left(\prod_{x \in \text{toLeft}(s)} f(\text{inl}(x))\right) \cdot \left(\prod_{x \in \text{toRight}(s)} f(\text{inr}(x))\right). \]
Finset.prod_sumElim theorem
(s : Finset ι) (t : Finset κ) (f : ι → M) (g : κ → M) : ∏ x ∈ s.disjSum t, Sum.elim f g x = (∏ x ∈ s, f x) * ∏ x ∈ t, g x
Full source
@[to_additive]
theorem prod_sumElim (s : Finset ι) (t : Finset κ) (f : ι → M) (g : κ → M) :
    ∏ x ∈ s.disjSum t, Sum.elim f g x = (∏ x ∈ s, f x) * ∏ x ∈ t, g x := by simp
Product of Sum Elimination over Disjoint Sum: $\prod_{x \in s \uplus t} \text{Sum.elim}\,f\,g\,x = (\prod_{x \in s} f(x)) \cdot (\prod_{x \in t} g(x))$
Informal description
Let $s$ be a finite set of type $\iota$, $t$ a finite set of type $\kappa$, and $f : \iota \to M$, $g : \kappa \to M$ functions where $M$ is a commutative monoid. Then the product of the sum elimination function $\text{Sum.elim}\,f\,g$ over the disjoint sum $s \uplus t$ equals the product of $f$ over $s$ multiplied by the product of $g$ over $t$. In symbols: \[ \prod_{x \in s \uplus t} \text{Sum.elim}\,f\,g\,x = \left(\prod_{x \in s} f(x)\right) \cdot \left(\prod_{x \in t} g(x)\right). \]
Finset.prod_biUnion theorem
[DecidableEq ι] {s : Finset κ} {t : κ → Finset ι} (hs : Set.PairwiseDisjoint (↑s) t) : ∏ x ∈ s.biUnion t, f x = ∏ x ∈ s, ∏ i ∈ t x, f i
Full source
@[to_additive]
theorem prod_biUnion [DecidableEq ι] {s : Finset κ} {t : κ → Finset ι}
    (hs : Set.PairwiseDisjoint (↑s) t) : ∏ x ∈ s.biUnion t, f x = ∏ x ∈ s, ∏ i ∈ t x, f i := by
  rw [← disjiUnion_eq_biUnion _ _ hs, prod_disjiUnion]
Product over Finite Union Equals Iterated Product under Pairwise Disjointness: $\prod_{\text{biUnion}(s, t)} f = \prod_{x \in s} \prod_{i \in t(x)} f(i)$
Informal description
Let $\kappa$ and $\iota$ be types with decidable equality on $\iota$, $s$ a finite subset of $\kappa$, and $t \colon \kappa \to \text{Finset} \iota$ a function such that the images $t(x)$ for $x \in s$ are pairwise disjoint. For any commutative monoid $M$ and function $f \colon \iota \to M$, the product of $f$ over the finite union $\text{biUnion}(s, t)$ equals the iterated product over $s$ of the products of $f$ over each $t(x)$. That is, \[ \prod_{x \in \text{biUnion}(s, t)} f(x) = \prod_{x \in s} \prod_{i \in t(x)} f(i). \]
Finset.prod_of_injOn theorem
(e : ι → κ) (he : Set.InjOn e s) (hest : Set.MapsTo e s t) (h' : ∀ i ∈ t, i ∉ e '' s → g i = 1) (h : ∀ i ∈ s, f i = g (e i)) : ∏ i ∈ s, f i = ∏ j ∈ t, g j
Full source
@[to_additive]
lemma prod_of_injOn (e : ι → κ) (he : Set.InjOn e s) (hest : Set.MapsTo e s t)
    (h' : ∀ i ∈ t, i ∉ e '' s → g i = 1) (h : ∀ i ∈ s, f i = g (e i))  :
    ∏ i ∈ s, f i = ∏ j ∈ t, g j := by
  classical
  exact (prod_nbij e (fun a ↦ mem_image_of_mem e) he (by simp [Set.surjOn_image]) h).trans <|
    prod_subset (image_subset_iff.2 hest) <| by simpa using h'
Product Equality under Injection and Triviality Conditions: $\prod_{s} f = \prod_{t} g$
Informal description
Let $s$ be a finite subset of $\iota$, $t$ a finite subset of $\kappa$, and $e : \iota \to \kappa$ an injective function on $s$ such that $e$ maps $s$ into $t$. Suppose that for all $i \in t$ not in the image of $e$ on $s$, we have $g(i) = 1$, and that for all $i \in s$, $f(i) = g(e(i))$. Then the product of $f$ over $s$ equals the product of $g$ over $t$, i.e., \[ \prod_{i \in s} f(i) = \prod_{j \in t} g(j). \]
Finset.prod_fiberwise_eq_prod_filter theorem
(s : Finset ι) (t : Finset κ) (g : ι → κ) (f : ι → M) : ∏ j ∈ t, ∏ i ∈ s with g i = j, f i = ∏ i ∈ s with g i ∈ t, f i
Full source
@[to_additive]
lemma prod_fiberwise_eq_prod_filter (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : ι → M) :
    ∏ j ∈ t, ∏ i ∈ s with g i = j, f i = ∏ i ∈ s with g i ∈ t, f i := by
  rw [← prod_disjiUnion, disjiUnion_filter_eq]
Equality of Fiberwise and Filtered Products: $\prod_{j \in t} \prod_{i \in s, g(i)=j} f(i) = \prod_{i \in s, g(i) \in t} f(i)$
Informal description
Let $s$ be a finite subset of a type $\iota$, $t$ a finite subset of a type $\kappa$, $g \colon \iota \to \kappa$ a function, and $f \colon \iota \to M$ a function into a commutative monoid $M$. Then the iterated product over $t$ of the products of $f$ over the elements of $s$ mapped to each $j \in t$ equals the product of $f$ over the elements of $s$ mapped into $t$. That is, \[ \prod_{j \in t} \prod_{\substack{i \in s \\ g(i) = j}} f(i) = \prod_{\substack{i \in s \\ g(i) \in t}} f(i). \]
Finset.prod_fiberwise_eq_prod_filter' theorem
(s : Finset ι) (t : Finset κ) (g : ι → κ) (f : κ → M) : ∏ j ∈ t, ∏ i ∈ s with g i = j, f j = ∏ i ∈ s with g i ∈ t, f (g i)
Full source
@[to_additive]
lemma prod_fiberwise_eq_prod_filter' (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : κ → M) :
    ∏ j ∈ t, ∏ i ∈ s with g i = j, f j = ∏ i ∈ s with g i ∈ t, f (g i) := by
  calc
    _ = ∏ j ∈ t, ∏ i ∈ s with g i = j, f (g i) :=
        prod_congr rfl fun j _ ↦ prod_congr rfl fun i hi ↦ by rw [(mem_filter.1 hi).2]
    _ = _ := prod_fiberwise_eq_prod_filter _ _ _ _
Equality of Fiberwise and Filtered Products: $\prod_{j \in t} \prod_{\substack{i \in s \\ g(i) = j}} f(j) = \prod_{\substack{i \in s \\ g(i) \in t}} f(g(i))$
Informal description
Let $s$ be a finite subset of a type $\iota$, $t$ a finite subset of a type $\kappa$, and $g \colon \iota \to \kappa$ a function. For any commutative monoid $M$ and function $f \colon \kappa \to M$, the iterated product over $t$ of the products of $f(j)$ over the elements $i \in s$ with $g(i) = j$ equals the product of $f(g(i))$ over the elements $i \in s$ with $g(i) \in t$. That is, \[ \prod_{j \in t} \prod_{\substack{i \in s \\ g(i) = j}} f(j) = \prod_{\substack{i \in s \\ g(i) \in t}} f(g(i)). \]
Finset.prod_fiberwise_of_maps_to theorem
{g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : ι → M) : ∏ j ∈ t, ∏ i ∈ s with g i = j, f i = ∏ i ∈ s, f i
Full source
@[to_additive]
lemma prod_fiberwise_of_maps_to {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : ι → M) :
    ∏ j ∈ t, ∏ i ∈ s with g i = j, f i = ∏ i ∈ s, f i := by
  rw [← prod_disjiUnion, disjiUnion_filter_eq_of_maps_to h]
Product over Fibers Equals Total Product under Mapping Condition: $\prod_{j \in t} \prod_{\substack{i \in s \\ g(i) = j}} f(i) = \prod_{i \in s} f(i)$
Informal description
Let $s$ be a finite subset of a type $\iota$, $t$ a finite subset of a type $\kappa$, and $g \colon \iota \to \kappa$ a function such that $g(i) \in t$ for all $i \in s$. For any commutative monoid $M$ and function $f \colon \iota \to M$, the iterated product over $t$ of the products of $f$ over the fibers $\{i \in s \mid g(i) = j\}$ equals the product of $f$ over $s$. That is, \[ \prod_{j \in t} \prod_{\substack{i \in s \\ g(i) = j}} f(i) = \prod_{i \in s} f(i). \]
Finset.prod_fiberwise_of_maps_to' theorem
{g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : κ → M) : ∏ j ∈ t, ∏ i ∈ s with g i = j, f j = ∏ i ∈ s, f (g i)
Full source
@[to_additive]
lemma prod_fiberwise_of_maps_to' {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : κ → M) :
    ∏ j ∈ t, ∏ i ∈ s with g i = j, f j = ∏ i ∈ s, f (g i) := by
  calc
    _ = ∏ j ∈ t, ∏ i ∈ s with g i = j, f (g i) :=
        prod_congr rfl fun y _ ↦ prod_congr rfl fun x hx ↦ by rw [(mem_filter.1 hx).2]
    _ = _ := prod_fiberwise_of_maps_to h _
Fiberwise Product Equals Composition Product under Mapping Condition: $\prod_{j \in t} \prod_{\substack{i \in s \\ g(i) = j}} f(j) = \prod_{i \in s} f(g(i))$
Informal description
Let $s$ be a finite subset of a type $\iota$, $t$ a finite subset of a type $\kappa$, and $g \colon \iota \to \kappa$ a function such that $g(i) \in t$ for all $i \in s$. For any commutative monoid $M$ and function $f \colon \kappa \to M$, the iterated product over $t$ of the products of $f(j)$ over the fibers $\{i \in s \mid g(i) = j\}$ equals the product of $f(g(i))$ over $s$. That is, \[ \prod_{j \in t} \prod_{\substack{i \in s \\ g(i) = j}} f(j) = \prod_{i \in s} f(g(i)). \]
Finset.prod_fiberwise theorem
(s : Finset ι) (g : ι → κ) (f : ι → M) : ∏ j, ∏ i ∈ s with g i = j, f i = ∏ i ∈ s, f i
Full source
@[to_additive]
lemma prod_fiberwise (s : Finset ι) (g : ι → κ) (f : ι → M) :
    ∏ j, ∏ i ∈ s with g i = j, f i = ∏ i ∈ s, f i :=
  prod_fiberwise_of_maps_to (fun _ _ ↦ mem_univ _) _
Product over Fibers Equals Total Product: $\prod_j \prod_{\substack{i \in s \\ g(i) = j}} f(i) = \prod_{i \in s} f(i)$
Informal description
Let $s$ be a finite subset of a type $\iota$, $g \colon \iota \to \kappa$ a function, and $f \colon \iota \to M$ a function where $M$ is a commutative monoid. Then the iterated product over all possible values $j$ of $g$ of the products of $f$ over the fibers $\{i \in s \mid g(i) = j\}$ equals the product of $f$ over $s$. That is, \[ \prod_{j} \prod_{\substack{i \in s \\ g(i) = j}} f(i) = \prod_{i \in s} f(i). \]
Finset.prod_fiberwise' theorem
(s : Finset ι) (g : ι → κ) (f : κ → M) : ∏ j, ∏ i ∈ s with g i = j, f j = ∏ i ∈ s, f (g i)
Full source
@[to_additive]
lemma prod_fiberwise' (s : Finset ι) (g : ι → κ) (f : κ → M) :
    ∏ j, ∏ i ∈ s with g i = j, f j = ∏ i ∈ s, f (g i) :=
  prod_fiberwise_of_maps_to' (fun _ _ ↦ mem_univ _) _
Fiberwise Product Equals Composition Product: $\prod_j \prod_{\substack{i \in s \\ g(i) = j}} f(j) = \prod_{i \in s} f(g(i))$
Informal description
Let $s$ be a finite subset of a type $\iota$, $g \colon \iota \to \kappa$ a function, and $f \colon \kappa \to M$ a function where $M$ is a commutative monoid. Then the iterated product over all possible values $j$ of $g$ of the products of $f(j)$ over the fibers $\{i \in s \mid g(i) = j\}$ equals the product of $f(g(i))$ over $s$. That is, \[ \prod_{j} \prod_{\substack{i \in s \\ g(i) = j}} f(j) = \prod_{i \in s} f(g(i)). \]
Finset.prod_diag theorem
[DecidableEq ι] (s : Finset ι) (f : ι × ι → M) : ∏ i ∈ s.diag, f i = ∏ i ∈ s, f (i, i)
Full source
@[to_additive (attr := simp)]
lemma prod_diag [DecidableEq ι] (s : Finset ι) (f : ι × ι → M) :
    ∏ i ∈ s.diag, f i = ∏ i ∈ s, f (i, i) := by
  apply prod_nbij' Prod.fst (fun i ↦ (i, i)) <;> simp
Product over Diagonal Equals Product of Diagonal Elements
Informal description
Let $M$ be a commutative monoid, $\iota$ a type with decidable equality, $s$ a finite subset of $\iota$, and $f : \iota \times \iota \to M$ a function. Then the product of $f$ over the diagonal of $s$ equals the product of $f$ evaluated at $(i,i)$ for each $i \in s$: \[ \prod_{(i,i) \in s \times s} f(i,i) = \prod_{i \in s} f(i,i). \]
Finset.prod_image' theorem
[DecidableEq ι] {s : Finset κ} {g : κ → ι} (h : κ → M) (eq : ∀ i ∈ s, f (g i) = ∏ j ∈ s with g j = g i, h j) : ∏ a ∈ s.image g, f a = ∏ i ∈ s, h i
Full source
@[to_additive]
theorem prod_image' [DecidableEq ι] {s : Finset κ} {g : κ → ι} (h : κ → M)
    (eq : ∀ i ∈ s, f (g i) = ∏ j ∈ s with g j = g i, h j) :
    ∏ a ∈ s.image g, f a = ∏ i ∈ s, h i :=
  calc
    ∏ a ∈ s.image g, f a = ∏ a ∈ s.image g, ∏ j ∈ s with g j = a, h j :=
      (prod_congr rfl) fun _a hx =>
        let ⟨i, his, hi⟩ := mem_image.1 hx
        hi ▸ eq i his
    _ = ∏ i ∈ s, h i := prod_fiberwise_of_maps_to (fun _ => mem_image_of_mem g) _
Product over Image Equals Product under Fiber Condition: $\prod_{a \in g(s)} f(a) = \prod_{i \in s} h(i)$
Informal description
Let $\iota$ and $\kappa$ be types with $\iota$ having decidable equality, $s$ a finite subset of $\kappa$, and $g \colon \kappa \to \iota$ a function. For any commutative monoid $M$ and functions $f \colon \iota \to M$ and $h \colon \kappa \to M$, suppose that for every $i \in s$, the value $f(g(i))$ equals the product of $h(j)$ over all $j \in s$ such that $g(j) = g(i)$. Then the product of $f$ over the image of $s$ under $g$ equals the product of $h$ over $s$: \[ \prod_{a \in g(s)} f(a) = \prod_{i \in s} h(i). \]
Finset.prod_mul_distrib theorem
: ∏ x ∈ s, f x * g x = (∏ x ∈ s, f x) * ∏ x ∈ s, g x
Full source
@[to_additive]
theorem prod_mul_distrib : ∏ x ∈ s, f x * g x = (∏ x ∈ s, f x) * ∏ x ∈ s, g x :=
  Eq.trans (by rw [one_mul]; rfl) fold_op_distrib
Product of Pointwise Products Equals Product of Products
Informal description
For any commutative monoid $M$, finite set $s$, and functions $f, g : \alpha \to M$, the product of the pointwise multiplication of $f$ and $g$ over $s$ is equal to the product of $f$ over $s$ multiplied by the product of $g$ over $s$. In symbols: \[ \prod_{x \in s} (f(x) * g(x)) = \left(\prod_{x \in s} f(x)\right) * \left(\prod_{x \in s} g(x)\right). \]
Finset.prod_mul_prod_comm theorem
(f g h i : ι → M) : (∏ a ∈ s, f a * g a) * ∏ a ∈ s, h a * i a = (∏ a ∈ s, f a * h a) * ∏ a ∈ s, g a * i a
Full source
@[to_additive]
lemma prod_mul_prod_comm (f g h i : ι → M) :
    (∏ 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
  simp_rw [prod_mul_distrib, mul_mul_mul_comm]
Commutation of Double Products over Finite Sets: $(\prod fg)(\prod hi) = (\prod fh)(\prod gi)$
Informal description
For any commutative monoid $M$, finite set $s \subseteq \iota$, and functions $f, g, h, i : \iota \to M$, the following equality holds: \[ \left(\prod_{a \in s} f(a) g(a)\right) \left(\prod_{a \in s} h(a) i(a)\right) = \left(\prod_{a \in s} f(a) h(a)\right) \left(\prod_{a \in s} g(a) i(a)\right). \]
Finset.prod_filter_of_ne theorem
{p : ι → Prop} [DecidablePred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) : ∏ x ∈ s with p x, f x = ∏ x ∈ s, f x
Full source
@[to_additive]
theorem prod_filter_of_ne {p : ι → Prop} [DecidablePred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) :
    ∏ x ∈ s with p x, f x = ∏ x ∈ s, f x :=
  (prod_subset (filter_subset _ _)) fun x => by
    classical
      rw [not_imp_comm, mem_filter]
      exact fun h₁ h₂ => ⟨h₁, by simpa using hp _ h₁ h₂⟩
Product Equality under Filtering by Non-Identity Condition: $\prod_{\{x \in s \mid p(x)\}} f = \prod_s f$
Informal description
Let $M$ be a commutative monoid, $s$ a finite subset of a type $\iota$, and $f : \iota \to M$ a function. For any decidable predicate $p$ on $\iota$, if for all $x \in s$ with $f(x) \neq 1$ we have $p(x)$ holds, then the product of $f$ over the filtered subset $\{x \in s \mid p(x)\}$ equals the product of $f$ over $s$: \[ \prod_{x \in s \text{ with } p(x)} f(x) = \prod_{x \in s} f(x). \]
Finset.prod_filter_ne_one theorem
(s : Finset ι) [∀ x, Decidable (f x ≠ 1)] : ∏ x ∈ s with f x ≠ 1, f x = ∏ x ∈ s, f x
Full source
@[to_additive]
theorem prod_filter_ne_one (s : Finset ι) [∀ x, Decidable (f x ≠ 1)] :
    ∏ x ∈ s with f x ≠ 1, f x = ∏ x ∈ s, f x :=
  prod_filter_of_ne fun _ _ => id
Product Equality over Non-Identity Elements: $\prod_{\{x \in s \mid f(x) \neq 1\}} f = \prod_s f$
Informal description
Let $M$ be a commutative monoid, $s$ a finite subset of a type $\iota$, and $f : \iota \to M$ a function. Then the product of $f$ over the subset $\{x \in s \mid f(x) \neq 1\}$ equals the product of $f$ over $s$: \[ \prod_{\substack{x \in s \\ f(x) \neq 1}} f(x) = \prod_{x \in s} f(x). \]
Finset.prod_filter theorem
(p : ι → Prop) [DecidablePred p] (f : ι → M) : ∏ a ∈ s with p a, f a = ∏ a ∈ s, if p a then f a else 1
Full source
@[to_additive]
theorem prod_filter (p : ι → Prop) [DecidablePred p] (f : ι → M) :
    ∏ a ∈ s with p a, f a = ∏ a ∈ s, if p a then f a else 1 :=
  calc
    ∏ a ∈ s with p a, f a = ∏ a ∈ s with p a, if p a then f a else 1 :=
      prod_congr rfl fun a h => by rw [if_pos]; simpa using (mem_filter.1 h).2
    _ = ∏ a ∈ s, if p a then f a else 1 := by
      { refine prod_subset (filter_subset _ s) fun x hs h => ?_
        rw [mem_filter, not_and] at h
        exact if_neg (by simpa using h hs) }
Product over Filtered Finite Set Equals Conditional Product
Informal description
Let $s$ be a finite set of type $\iota$, $p : \iota \to \text{Prop}$ a decidable predicate, and $f : \iota \to M$ a function where $M$ is a commutative monoid. Then the product of $f$ over the filtered subset $\{a \in s \mid p(a)\}$ is equal to the product over $s$ of the function that maps $a$ to $f(a)$ if $p(a)$ holds and to $1$ otherwise. In other words, \[ \prod_{a \in s \text{ with } p(a)} f(a) = \prod_{a \in s} \begin{cases} f(a) & \text{if } p(a), \\ 1 & \text{otherwise}. \end{cases} \]
Finset.prod_eq_single_of_mem theorem
{s : Finset ι} {f : ι → M} (a : ι) (h : a ∈ s) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : ∏ x ∈ s, f x = f a
Full source
@[to_additive]
theorem prod_eq_single_of_mem {s : Finset ι} {f : ι → M} (a : ι) (h : a ∈ s)
    (h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : ∏ x ∈ s, f x = f a := by
  haveI := Classical.decEq ι
  calc
    ∏ x ∈ s, f x = ∏ x ∈ {a}, f x := by
      { refine (prod_subset ?_ ?_).symm
        · intro _ H
          rwa [mem_singleton.1 H]
        · simpa only [mem_singleton] }
    _ = f a := prod_singleton _ _
Product over Finite Set Equals Single Non-Trivial Value
Informal description
Let $M$ be a commutative monoid, $s$ a finite subset of a type $\iota$, and $f : \iota \to M$ a function. If $a \in s$ is such that $f(b) = 1$ for all $b \in s$ with $b \neq a$, then the product of $f$ over $s$ equals $f(a)$, i.e., \[ \prod_{x \in s} f(x) = f(a). \]
Finset.prod_eq_single theorem
{s : Finset ι} {f : ι → M} (a : ι) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : ∏ x ∈ s, f x = f a
Full source
@[to_additive]
theorem prod_eq_single {s : Finset ι} {f : ι → M} (a : ι) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1)
    (h₁ : a ∉ s → f a = 1) : ∏ x ∈ s, f x = f a :=
  haveI := Classical.decEq ι
  by_cases (prod_eq_single_of_mem a · h₀) fun this =>
    (prod_congr rfl fun b hb => h₀ b hb <| by rintro rfl; exact this hb).trans <|
      prod_const_one.trans (h₁ this).symm
Product over Finite Set Equals Single Non-Trivial Value (General Case)
Informal description
Let $M$ be a commutative monoid, $s$ a finite subset of a type $\iota$, and $f : \iota \to M$ a function. Given an element $a \in \iota$ such that: 1. For all $b \in s$ with $b \neq a$, we have $f(b) = 1$, and 2. If $a \notin s$, then $f(a) = 1$, then the product of $f$ over $s$ equals $f(a)$, i.e., \[ \prod_{x \in s} f(x) = f(a). \]
Finset.prod_union_eq_left theorem
[DecidableEq ι] (hs : ∀ a ∈ s₂, a ∉ s₁ → f a = 1) : ∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₁, f a
Full source
@[to_additive]
lemma prod_union_eq_left [DecidableEq ι] (hs : ∀ a ∈ s₂, a ∉ s₁ → f a = 1) :
    ∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₁, f a :=
  Eq.symm <|
    prod_subset subset_union_left fun _a ha ha' ↦ hs _ ((mem_union.1 ha).resolve_left ha') ha'
Product over Union Equals Product over Left Set When Trivial on Right Difference
Informal description
Let $\iota$ be a type with decidable equality, $s_1$ and $s_2$ be finite subsets of $\iota$, and $f : \iota \to M$ be a function where $M$ is a commutative monoid. If for every element $a \in s_2$ not in $s_1$, we have $f(a) = 1$, then the product of $f$ over the union $s_1 \cup s_2$ equals the product of $f$ over $s_1$, i.e., \[ \prod_{a \in s_1 \cup s_2} f(a) = \prod_{a \in s_1} f(a). \]
Finset.prod_union_eq_right theorem
[DecidableEq ι] (hs : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) : ∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₂, f a
Full source
@[to_additive]
lemma prod_union_eq_right [DecidableEq ι] (hs : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) :
    ∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₂, f a := by rw [union_comm, prod_union_eq_left hs]
Product over Union Equals Product over Right Set When Trivial on Left Difference
Informal description
Let $\iota$ be a type with decidable equality, $s_1$ and $s_2$ be finite subsets of $\iota$, and $f : \iota \to M$ be a function where $M$ is a commutative monoid. If for every element $a \in s_1$ not in $s_2$, we have $f(a) = 1$, then the product of $f$ over the union $s_1 \cup s_2$ equals the product of $f$ over $s_2$, i.e., \[ \prod_{a \in s_1 \cup s_2} f(a) = \prod_{a \in s_2} f(a). \]
Finset.prod_congr_of_eq_on_inter theorem
{ι M : Type*} {s₁ s₂ : Finset ι} {f g : ι → M} [CommMonoid M] (h₁ : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) (h₂ : ∀ a ∈ s₂, a ∉ s₁ → g a = 1) (h : ∀ a ∈ s₁, a ∈ s₂ → f a = g a) : ∏ a ∈ s₁, f a = ∏ a ∈ s₂, g a
Full source
/-- The products of two functions `f g : ι → M` over finite sets `s₁ s₂ : Finset ι`
are equal if the functions agree on `s₁ ∩ s₂`, `f = 1` and `g = 1` on the respective
set differences. -/
@[to_additive "The sum of two functions `f g : ι → M` over finite sets `s₁ s₂ : Finset ι`
are equal if the functions agree on `s₁ ∩ s₂`, `f = 0` and `g = 0` on the respective
set differences."]
lemma prod_congr_of_eq_on_inter {ι M : Type*} {s₁ s₂ : Finset ι} {f g : ι → M} [CommMonoid M]
    (h₁ : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) (h₂ : ∀ a ∈ s₂, a ∉ s₁ → g a = 1)
    (h : ∀ a ∈ s₁, a ∈ s₂ → f a = g a) :
    ∏ a ∈ s₁, f a = ∏ a ∈ s₂, g a := by
  classical
  conv_lhs => rw [← sdiff_union_inter s₁ s₂, prod_union_eq_right (by aesop)]
  conv_rhs => rw [← sdiff_union_inter s₂ s₁, prod_union_eq_right (by aesop), inter_comm]
  exact prod_congr rfl (by simpa)
Product Equality under Agreement on Intersection and Triviality on Differences
Informal description
Let $M$ be a commutative monoid, $s_1$ and $s_2$ be finite subsets of a type $\iota$, and $f, g : \iota \to M$ be functions. Suppose that: 1. For all $a \in s_1$ not in $s_2$, we have $f(a) = 1$, 2. For all $a \in s_2$ not in $s_1$, we have $g(a) = 1$, 3. For all $a \in s_1 \cap s_2$, we have $f(a) = g(a)$. Then the product of $f$ over $s_1$ equals the product of $g$ over $s_2$, i.e., \[ \prod_{a \in s_1} f(a) = \prod_{a \in s_2} g(a). \]
Finset.prod_eq_mul_of_mem theorem
{s : Finset ι} {f : ι → M} (a b : ι) (ha : a ∈ s) (hb : b ∈ s) (hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : ∏ x ∈ s, f x = f a * f b
Full source
@[to_additive]
theorem prod_eq_mul_of_mem {s : Finset ι} {f : ι → M} (a b : ι) (ha : a ∈ s) (hb : b ∈ s)
    (hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : ∏ x ∈ s, f x = f a * f b := by
  haveI := Classical.decEq ι; let s' := ({a, b} : Finset ι)
  have hu : s' ⊆ s := by
    refine insert_subset_iff.mpr ?_
    apply And.intro ha
    apply singleton_subset_iff.mpr hb
  have hf : ∀ c ∈ s, c ∉ s' → f c = 1 := by
    intro c hc hcs
    apply h₀ c hc
    apply not_or.mp
    intro hab
    apply hcs
    rw [mem_insert, mem_singleton]
    exact hab
  rw [← prod_subset hu hf]
  exact Finset.prod_pair hn
Product over Finite Set with Two Non-Trivial Elements Equals Their Product
Informal description
Let $s$ be a finite set of elements of type $\iota$, $f : \iota \to M$ a function where $M$ is a commutative monoid, and $a, b \in s$ two distinct elements of $s$. Suppose that for all other elements $c \in s$ (i.e., $c \neq a$ and $c \neq b$), $f(c) = 1$. Then the product of $f$ over $s$ equals $f(a) \cdot f(b)$, i.e., \[ \prod_{x \in s} f(x) = f(a) \cdot f(b). \]
Finset.prod_eq_mul theorem
{s : Finset ι} {f : ι → M} (a b : ι) (hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) : ∏ x ∈ s, f x = f a * f b
Full source
@[to_additive]
theorem prod_eq_mul {s : Finset ι} {f : ι → M} (a b : ι) (hn : a ≠ b)
    (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) :
    ∏ x ∈ s, f x = f a * f b := by
  haveI := Classical.decEq ι; by_cases h₁ : a ∈ s <;> by_cases h₂ : b ∈ s
  · exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀
  · rw [hb h₂, mul_one]
    apply prod_eq_single_of_mem a h₁
    exact fun c hc hca => h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩
  · rw [ha h₁, one_mul]
    apply prod_eq_single_of_mem b h₂
    exact fun c hc hcb => h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩
  · rw [ha h₁, hb h₂, mul_one]
    exact
      _root_.trans
        (prod_congr rfl fun c hc =>
          h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩)
        prod_const_one
Product over Finite Set with Two Non-Trivial Elements Equals Their Product (General Case)
Informal description
Let $M$ be a commutative monoid, $s$ a finite subset of a type $\iota$, and $f : \iota \to M$ a function. Given two distinct elements $a, b \in \iota$ such that: 1. For all $c \in s$ with $c \neq a$ and $c \neq b$, we have $f(c) = 1$, 2. If $a \notin s$, then $f(a) = 1$, 3. If $b \notin s$, then $f(b) = 1$, then the product of $f$ over $s$ equals $f(a) \cdot f(b)$, i.e., \[ \prod_{x \in s} f(x) = f(a) \cdot f(b). \]
Finset.prod_subtype_eq_prod_filter theorem
(f : ι → M) {p : ι → Prop} [DecidablePred p] : ∏ x ∈ s.subtype p, f x = ∏ x ∈ s with p x, f x
Full source
/-- A product over `s.subtype p` equals one over `{x ∈ s | p x}`. -/
@[to_additive (attr := simp)
"A sum over `s.subtype p` equals one over `{x ∈ s | p x}`."]
theorem prod_subtype_eq_prod_filter (f : ι → M) {p : ι → Prop} [DecidablePred p] :
    ∏ x ∈ s.subtype p, f x = ∏ x ∈ s with p x, f x := by
  have := prod_map (s.subtype p) (Function.Embedding.subtype _) f
  simp_all
Product over Subtype Equals Product over Filtered Set
Informal description
Let $s$ be a finite set of elements of type $\iota$, $f : \iota \to M$ a function where $M$ is a commutative monoid, and $p : \iota \to \text{Prop}$ a decidable predicate. Then the product of $f$ over the subtype $\{x \in s \mid p(x)\}$ is equal to the product of $f$ over the filtered set $\{x \in s \mid p(x)\}$: \[ \prod_{x \in \{x \in s \mid p(x)\}} f(x) = \prod_{\substack{x \in s \\ p(x)}} f(x). \]
Finset.prod_subtype_of_mem theorem
(f : ι → M) {p : ι → Prop} [DecidablePred p] (h : ∀ x ∈ s, p x) : ∏ x ∈ s.subtype p, f x = ∏ x ∈ s, f x
Full source
/-- If all elements of a `Finset` satisfy the predicate `p`, a product
over `s.subtype p` equals that product over `s`. -/
@[to_additive "If all elements of a `Finset` satisfy the predicate `p`, a sum
over `s.subtype p` equals that sum over `s`."]
theorem prod_subtype_of_mem (f : ι → M) {p : ι → Prop} [DecidablePred p] (h : ∀ x ∈ s, p x) :
    ∏ x ∈ s.subtype p, f x = ∏ x ∈ s, f x := by
  rw [prod_subtype_eq_prod_filter, filter_true_of_mem]
  simpa using h
Product Equality for Subtype When All Elements Satisfy Predicate
Informal description
Let $s$ be a finite set of elements of type $\iota$, $f : \iota \to M$ a function where $M$ is a commutative monoid, and $p : \iota \to \text{Prop}$ a decidable predicate. If every element $x \in s$ satisfies $p(x)$, then the product of $f$ over the subtype $\{x \in s \mid p(x)\}$ is equal to the product of $f$ over the entire set $s$: \[ \prod_{x \in \{x \in s \mid p(x)\}} f(x) = \prod_{x \in s} f(x). \]
Finset.prod_subtype_map_embedding theorem
{p : ι → Prop} {s : Finset { x // p x }} {f : { x // p x } → M} {g : ι → M} (h : ∀ x : { x // p x }, x ∈ s → g x = f x) : (∏ x ∈ s.map (Function.Embedding.subtype _), g x) = ∏ x ∈ s, f x
Full source
/-- A product of a function over a `Finset` in a subtype equals a
product in the main type of a function that agrees with the first
function on that `Finset`. -/
@[to_additive "A sum of a function over a `Finset` in a subtype equals a
sum in the main type of a function that agrees with the first
function on that `Finset`."]
theorem prod_subtype_map_embedding {p : ι → Prop} {s : Finset { x // p x }} {f : { x // p x } → M}
    {g : ι → M} (h : ∀ x : { x // p x }, x ∈ s → g x = f x) :
    (∏ x ∈ s.map (Function.Embedding.subtype _), g x) = ∏ x ∈ s, f x := by
  rw [Finset.prod_map]
  exact Finset.prod_congr rfl h
Product Equality for Subtype Inclusion of Finite Sets
Informal description
Let $p$ be a predicate on a type $\iota$, $s$ be a finite subset of the subtype $\{x \in \iota \mid p(x)\}$, and $f : \{x \in \iota \mid p(x)\} \to M$ and $g : \iota \to M$ be functions where $M$ is a commutative monoid. Suppose that for every $x$ in $s$, $g(x) = f(x)$. Then the product of $g$ over the image of $s$ under the subtype inclusion map equals the product of $f$ over $s$: \[ \prod_{x \in s} f(x) = \prod_{x \in \iota \mid p(x), x \in s} g(x). \]
Finset.prod_coe_sort theorem
: ∏ i : s, f i = ∏ i ∈ s, f i
Full source
@[to_additive]
theorem prod_coe_sort : ∏ i : s, f i = ∏ i ∈ s, f i := prod_attach _ _
Product Equality over Finite Set Subtype
Informal description
For any finite set $s$ of type $\alpha$ and any function $f : \alpha \to M$ where $M$ is a commutative monoid, the product of $f$ over the elements of $s$ viewed as a subtype is equal to the product of $f$ over the elements of $s$ directly, i.e., \[ \prod_{i \in s} f(i) = \prod_{i \in s} f(i). \]
Finset.prod_finset_coe theorem
(f : ι → M) (s : Finset ι) : (∏ i : (s : Set ι), f i) = ∏ i ∈ s, f i
Full source
@[to_additive]
theorem prod_finset_coe (f : ι → M) (s : Finset ι) : (∏ i : (s : Set ι), f i) = ∏ i ∈ s, f i :=
  prod_coe_sort s f
Product Equality over Finite Set Subtype
Informal description
For any commutative monoid $M$, any function $f : \iota \to M$, and any finite set $s$ of elements of type $\iota$, the product of $f$ over the elements of $s$ viewed as a subtype is equal to the product of $f$ over the elements of $s$ directly, i.e., \[ \prod_{i \in s} f(i) = \prod_{i \in s} f(i). \]
Finset.prod_subtype theorem
{p : ι → Prop} {F : Fintype (Subtype p)} (s : Finset ι) (h : ∀ x, x ∈ s ↔ p x) (f : ι → M) : ∏ a ∈ s, f a = ∏ a : Subtype p, f a
Full source
@[to_additive]
theorem prod_subtype {p : ι → Prop} {F : Fintype (Subtype p)} (s : Finset ι) (h : ∀ x, x ∈ sx ∈ s ↔ p x)
    (f : ι → M) : ∏ a ∈ s, f a = ∏ a : Subtype p, f a := by
  have : (· ∈ s) = p := Set.ext h
  subst p
  rw [← prod_coe_sort]
  congr!
Product over Finite Set Equals Product over Subtype
Informal description
Let $\iota$ be a type, $M$ a commutative monoid, and $p : \iota \to \text{Prop}$ a predicate on $\iota$. Suppose $\text{Subtype } p$ is a finite type. For any finite set $s \subseteq \iota$ such that $x \in s \leftrightarrow p(x)$ holds for all $x \in \iota$, and any function $f : \iota \to M$, we have: \[ \prod_{a \in s} f(a) = \prod_{a : \text{Subtype } p} f(a). \]
Finset.prod_set_coe theorem
(s : Set ι) [Fintype s] : (∏ i : s, f i) = ∏ i ∈ s.toFinset, f i
Full source
@[to_additive]
theorem prod_set_coe (s : Set ι) [Fintype s] : (∏ i : s, f i) = ∏ i ∈ s.toFinset, f i :=
  (Finset.prod_subtype s.toFinset (fun _ ↦ Set.mem_toFinset) f).symm
Product Equality over Set Subtype and its Finite Set Representation
Informal description
For any type $\iota$, any commutative monoid $M$, any set $s \subseteq \iota$ that is finite (with a `Fintype` instance), and any function $f : \iota \to M$, the product of $f$ over the elements of $s$ viewed as a subtype is equal to the product of $f$ over the finite set representation of $s$, i.e., \[ \prod_{i \in s} f(i) = \prod_{i \in s.\text{toFinset}} f(i). \]
Finset.prod_congr_set theorem
[Fintype ι] (s : Set ι) [DecidablePred (· ∈ s)] (f : ι → M) (g : s → M) (w : ∀ x (hx : x ∈ s), f x = g ⟨x, hx⟩) (w' : ∀ x ∉ s, f x = 1) : ∏ i, f i = ∏ i, g i
Full source
/-- The product of a function `g` defined only on a set `s` is equal to
the product of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 1` off `s`. -/
@[to_additive "The sum of a function `g` defined only on a set `s` is equal to
the sum of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 0` off `s`."]
theorem prod_congr_set [Fintype ι] (s : Set ι) [DecidablePred (· ∈ s)] (f : ι → M) (g : s → M)
    (w : ∀ x (hx : x ∈ s), f x = g ⟨x, hx⟩) (w' : ∀ x ∉ s, f x = 1) : ∏ i, f i = ∏ i, g i := by
  rw [← prod_subset s.toFinset.subset_univ (by simpa), prod_subtype (p := (· ∈ s)) _ (by simp)]
  congr! with ⟨x, h⟩
  exact w x h
Product Equality for Functions Agreeing on a Subset and Trivial Outside
Informal description
Let $\iota$ be a finite type, $M$ a commutative monoid, and $s \subseteq \iota$ a subset with decidable membership. Given functions $f : \iota \to M$ and $g : s \to M$ such that: 1. For every $x \in s$, $f(x) = g(x)$ (where $g(x)$ is viewed as $g$ applied to the subtype element $\langle x, hx\rangle$ with $hx$ being the proof that $x \in s$), 2. For every $x \notin s$, $f(x) = 1$, then the product of $f$ over all elements of $\iota$ equals the product of $g$ over all elements of $s$, i.e., \[ \prod_{i \in \iota} f(i) = \prod_{i \in s} g(i). \]
Finset.prod_extend_by_one theorem
[DecidableEq ι] (s : Finset ι) (f : ι → M) : ∏ i ∈ s, (if i ∈ s then f i else 1) = ∏ i ∈ s, f i
Full source
@[to_additive]
theorem prod_extend_by_one [DecidableEq ι] (s : Finset ι) (f : ι → M) :
    ∏ i ∈ s, (if i ∈ s then f i else 1) = ∏ i ∈ s, f i :=
  (prod_congr rfl) fun _i hi => if_pos hi
Product of Extended-by-One Function Equals Original Product
Informal description
Let $\iota$ be a type with decidable equality, $s$ a finite subset of $\iota$, and $f : \iota \to M$ a function where $M$ is a commutative monoid. Then the product over $s$ of the function that equals $f(i)$ when $i \in s$ and $1$ otherwise is equal to the product of $f$ over $s$, i.e., \[ \prod_{i \in s} \left( \begin{cases} f(i) & \text{if } i \in s \\ 1 & \text{otherwise} \end{cases} \right) = \prod_{i \in s} f(i). \]
Finset.prod_eq_prod_extend theorem
(f : s → M) : ∏ x, f x = ∏ x ∈ s, Subtype.val.extend f 1 x
Full source
@[to_additive]
theorem prod_eq_prod_extend (f : s → M) : ∏ x, f x = ∏ x ∈ s, Subtype.val.extend f 1 x := by
  rw [univ_eq_attach, ← Finset.prod_attach s]
  congr with ⟨x, hx⟩
  rw [Subtype.val_injective.extend_apply]
Product Equality for Extended Function over Finite Set
Informal description
Let $s$ be a finite subset of a type $\alpha$, and let $f : s \to M$ be a function where $M$ is a commutative monoid. Then the product of $f$ over all elements of the subtype $s$ is equal to the product over $s$ of the extension of $f$ by the identity element $1$, i.e., \[ \prod_{x \in s} f(x) = \prod_{x \in s} \left( \begin{cases} f(x) & \text{if } x \in s \\ 1 & \text{otherwise} \end{cases} \right). \]
Finset.prod_bij_ne_one theorem
{s : Finset ι} {t : Finset κ} {f : ι → M} {g : κ → M} (i : ∀ a ∈ s, f a ≠ 1 → κ) (hi : ∀ a h₁ h₂, i a h₁ h₂ ∈ t) (i_inj : ∀ a₁ h₁₁ h₁₂ a₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂) (i_surj : ∀ b ∈ t, g b ≠ 1 → ∃ a h₁ h₂, i a h₁ h₂ = b) (h : ∀ a h₁ h₂, f a = g (i a h₁ h₂)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x
Full source
@[to_additive]
theorem prod_bij_ne_one {s : Finset ι} {t : Finset κ} {f : ι → M} {g : κ → M}
    (i : ∀ a ∈ s, f a ≠ 1 → κ) (hi : ∀ a h₁ h₂, i a h₁ h₂ ∈ t)
    (i_inj : ∀ a₁ h₁₁ h₁₂ a₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
    (i_surj : ∀ b ∈ t, g b ≠ 1 → ∃ a h₁ h₂, i a h₁ h₂ = b) (h : ∀ a h₁ h₂, f a = g (i a h₁ h₂)) :
    ∏ x ∈ s, f x = ∏ x ∈ t, g x := by
  classical
  calc
    ∏ x ∈ s, f x = ∏ x ∈ s with f x ≠ 1, f x := by rw [prod_filter_ne_one]
    _ = ∏ x ∈ t with g x ≠ 1, g x :=
      prod_bij (fun a ha => i a (mem_filter.mp ha).1 <| by simpa using (mem_filter.mp ha).2)
        ?_ ?_ ?_ ?_
    _ = ∏ x ∈ t, g x := prod_filter_ne_one _
  · intros a ha
    refine (mem_filter.mp ha).elim ?_
    intros h₁ h₂
    refine (mem_filter.mpr ⟨hi a h₁ _, ?_⟩)
    specialize h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂
    rwa [← h]
  · intros a₁ ha₁ a₂ ha₂
    refine (mem_filter.mp ha₁).elim fun _ha₁₁ _ha₁₂ ↦ ?_
    refine (mem_filter.mp ha₂).elim fun _ha₂₁ _ha₂₂ ↦ ?_
    apply i_inj
  · intros b hb
    refine (mem_filter.mp hb).elim fun h₁ h₂ ↦ ?_
    obtain ⟨a, ha₁, ha₂, eq⟩ := i_surj b h₁ fun H ↦ by rw [H] at h₂; simp at h₂
    exact ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩
  · refine (fun a ha => (mem_filter.mp ha).elim fun h₁ h₂ ↦ ?_)
    exact h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂
Product Equality under Bijection of Non-Identity Elements: $\prod_s f = \prod_t g$
Informal description
Let $s$ and $t$ be finite sets of types $\iota$ and $\kappa$ respectively, and let $f \colon \iota \to M$ and $g \colon \kappa \to M$ be functions where $M$ is a commutative monoid. Suppose there exists a function $i \colon \iota \to \kappa$ defined for all $a \in s$ with $f(a) \neq 1$ such that: 1. For every $a \in s$ with $f(a) \neq 1$, $i(a) \in t$, 2. $i$ is injective on $\{a \in s \mid f(a) \neq 1\}$: for any $a_1, a_2 \in s$ with $f(a_1), f(a_2) \neq 1$, if $i(a_1) = i(a_2)$ then $a_1 = a_2$, 3. $i$ is surjective onto $\{b \in t \mid g(b) \neq 1\}$: for every $b \in t$ with $g(b) \neq 1$, there exists $a \in s$ with $f(a) \neq 1$ such that $i(a) = b$, 4. The functions agree on corresponding elements: $f(a) = g(i(a))$ for all $a \in s$ with $f(a) \neq 1$. Then the products satisfy: \[ \prod_{x \in s} f(x) = \prod_{x \in t} g(x). \]
Finset.exists_ne_one_of_prod_ne_one theorem
(h : ∏ x ∈ s, f x ≠ 1) : ∃ a ∈ s, f a ≠ 1
Full source
@[to_additive]
theorem exists_ne_one_of_prod_ne_one (h : ∏ x ∈ s, f x∏ x ∈ s, f x ≠ 1) : ∃ a ∈ s, f a ≠ 1 := by
  classical
    rw [← prod_filter_ne_one] at h
    rcases nonempty_of_prod_ne_one h with ⟨x, hx⟩
    exact ⟨x, (mem_filter.1 hx).1, by simpa using (mem_filter.1 hx).2⟩
Existence of Non-Identity Element in Non-Identity Product: $\prod_{x \in s} f(x) \neq 1 \implies \exists a \in s, f(a) \neq 1$
Informal description
For any finite set $s$ and any function $f$ mapping elements of $s$ to a commutative monoid, if the product $\prod_{x \in s} f(x)$ is not equal to the multiplicative identity $1$, then there exists an element $a \in s$ such that $f(a) \neq 1$.
Finset.prod_range_succ_comm theorem
(f : ℕ → M) (n : ℕ) : (∏ x ∈ range (n + 1), f x) = f n * ∏ x ∈ range n, f x
Full source
@[to_additive]
theorem prod_range_succ_comm (f :  → M) (n : ) :
    (∏ x ∈ range (n + 1), f x) = f n * ∏ x ∈ range n, f x := by
  rw [range_succ, prod_insert not_mem_range_self]
Product over range of $n+1$ elements equals $f(n)$ times product over range of $n$ elements
Informal description
For any function $f \colon \mathbb{N} \to M$ where $M$ is a commutative monoid, and for any natural number $n$, the product of $f$ over the finite set $\{0, 1, \ldots, n\}$ is equal to $f(n)$ multiplied by the product of $f$ over the finite set $\{0, 1, \ldots, n-1\}$. That is, \[ \prod_{x \in \{0, \ldots, n\}} f(x) = f(n) \cdot \prod_{x \in \{0, \ldots, n-1\}} f(x). \]
Finset.prod_range_succ theorem
(f : ℕ → M) (n : ℕ) : (∏ x ∈ range (n + 1), f x) = (∏ x ∈ range n, f x) * f n
Full source
@[to_additive]
theorem prod_range_succ (f :  → M) (n : ) :
    (∏ x ∈ range (n + 1), f x) = (∏ x ∈ range n, f x) * f n := by
  simp only [mul_comm, prod_range_succ_comm]
Recursive Product Formula over Range of Natural Numbers
Informal description
For any function $f \colon \mathbb{N} \to M$ where $M$ is a commutative monoid, and for any natural number $n$, the product of $f$ over the finite set $\{0, 1, \ldots, n\}$ is equal to the product of $f$ over the finite set $\{0, 1, \ldots, n-1\}$ multiplied by $f(n)$. That is, \[ \prod_{x \in \{0, \ldots, n\}} f(x) = \left( \prod_{x \in \{0, \ldots, n-1\}} f(x) \right) \cdot f(n). \]
Finset.prod_range_succ' theorem
(f : ℕ → M) : ∀ n : ℕ, (∏ k ∈ range (n + 1), f k) = (∏ k ∈ range n, f (k + 1)) * f 0
Full source
@[to_additive]
theorem prod_range_succ' (f :  → M) :
    ∀ n : , (∏ k ∈ range (n + 1), f k) = (∏ k ∈ range n, f (k + 1)) * f 0
  | 0 => prod_range_succ _ _
  | n + 1 => by rw [prod_range_succ _ n, mul_right_comm, ← prod_range_succ' _ n, prod_range_succ]
Shifted Product Formula for Range of Natural Numbers: $\prod_{k=0}^n f(k) = (\prod_{k=1}^n f(k)) \cdot f(0)$
Informal description
For any function $f \colon \mathbb{N} \to M$ where $M$ is a commutative monoid, and for any natural number $n$, the product of $f$ over the finite set $\{0, 1, \ldots, n\}$ is equal to the product of $f$ over the shifted set $\{1, 2, \ldots, n\}$ multiplied by $f(0)$. That is, \[ \prod_{k=0}^n f(k) = \left( \prod_{k=0}^{n-1} f(k+1) \right) \cdot f(0). \]
Finset.eventually_constant_prod theorem
{u : ℕ → M} {N : ℕ} (hu : ∀ n ≥ N, u n = 1) {n : ℕ} (hn : N ≤ n) : (∏ k ∈ range n, u k) = ∏ k ∈ range N, u k
Full source
@[to_additive]
theorem eventually_constant_prod {u :  → M} {N : } (hu : ∀ n ≥ N, u n = 1) {n : } (hn : N ≤ n) :
    (∏ k ∈ range n, u k) = ∏ k ∈ range N, u k := by
  obtain ⟨m, rfl : n = N + m⟩ := Nat.exists_eq_add_of_le hn
  clear hn
  induction m with
  | zero => simp
  | succ m hm => simp [← add_assoc, prod_range_succ, hm, hu]
Product of Eventually Constant Sequence Equals Truncated Product
Informal description
Let $M$ be a commutative monoid and let $u \colon \mathbb{N} \to M$ be a sequence such that $u(n) = 1$ for all $n \geq N$, where $N$ is a fixed natural number. Then for any natural number $n \geq N$, the product $\prod_{k \in \{0, \ldots, n-1\}} u(k)$ is equal to the product $\prod_{k \in \{0, \ldots, N-1\}} u(k)$.
Finset.prod_range_add theorem
(f : ℕ → M) (n m : ℕ) : (∏ x ∈ range (n + m), f x) = (∏ x ∈ range n, f x) * ∏ x ∈ range m, f (n + x)
Full source
@[to_additive]
theorem prod_range_add (f :  → M) (n m : ) :
    (∏ x ∈ range (n + m), f x) = (∏ x ∈ range n, f x) * ∏ x ∈ range m, f (n + x) := by
  induction m with
  | zero => simp
  | succ m hm => rw [Nat.add_succ, prod_range_succ, prod_range_succ, hm, mul_assoc]
Product Splitting Formula over Range Addition: $\prod_{x \in \text{range}(n + m)} f(x) = \prod_{x \in \text{range}(n)} f(x) \cdot \prod_{x \in \text{range}(m)} f(n + x)$
Informal description
For any function $f \colon \mathbb{N} \to M$ where $M$ is a commutative monoid, and for any natural numbers $n$ and $m$, the product of $f$ over the range $\{0, 1, \ldots, n + m - 1\}$ is equal to the product of $f$ over $\{0, 1, \ldots, n - 1\}$ multiplied by the product of $f(n + x)$ over $\{0, 1, \ldots, m - 1\}$. That is, \[ \prod_{x \in \{0, \ldots, n + m - 1\}} f(x) = \left( \prod_{x \in \{0, \ldots, n - 1\}} f(x) \right) \cdot \left( \prod_{x \in \{0, \ldots, m - 1\}} f(n + x) \right). \]
Finset.prod_range_one theorem
(f : ℕ → M) : ∏ k ∈ range 1, f k = f 0
Full source
@[to_additive sum_range_one]
theorem prod_range_one (f :  → M) : ∏ k ∈ range 1, f k = f 0 := by
  rw [range_one, prod_singleton]
Product over Singleton Range: $\prod_{k \in \{0\}} f(k) = f(0)$
Informal description
For any function $f \colon \mathbb{N} \to M$ where $M$ is a commutative monoid, the product of $f$ over the finite set $\{0\}$ is equal to $f(0)$, i.e., \[ \prod_{k \in \{0\}} f(k) = f(0). \]
Finset.prod_list_map_count theorem
[DecidableEq ι] (l : List ι) (f : ι → M) : (l.map f).prod = ∏ m ∈ l.toFinset, f m ^ l.count m
Full source
@[to_additive]
theorem prod_list_map_count [DecidableEq ι] (l : List ι) (f : ι → M) :
    (l.map f).prod = ∏ m ∈ l.toFinset, f m ^ l.count m := by
  induction l with
  | nil => simp only [map_nil, prod_nil, count_nil, pow_zero, prod_const_one]
  | cons a s IH =>
  simp only [List.map, List.prod_cons, toFinset_cons, IH]
  by_cases has : a ∈ s.toFinset
  · rw [insert_eq_of_mem has, ← insert_erase has, prod_insert (not_mem_erase _ _),
      prod_insert (not_mem_erase _ _), ← mul_assoc, count_cons_self, pow_succ']
    congr 1
    refine prod_congr rfl fun x hx => ?_
    rw [count_cons_of_ne (ne_of_mem_erase hx).symm]
  rw [prod_insert has, count_cons_self, count_eq_zero_of_not_mem (mt mem_toFinset.2 has), pow_one]
  congr 1
  refine prod_congr rfl fun x hx => ?_
  rw [count_cons_of_ne]
  rintro rfl
  exact has hx
Product of List via Distinct Elements and Counts: $\prod_{x \in l} f(x) = \prod_{m \in \text{toFinset}(l)} f(m)^{\text{count}(m, l)}$
Informal description
Let $\iota$ be a type with decidable equality, $M$ a commutative monoid, $l$ a list of elements of type $\iota$, and $f : \iota \to M$ a function. Then the product of the list obtained by applying $f$ to each element of $l$ is equal to the product over the finite set of distinct elements in $l$ of $f(m)$ raised to the power of the number of times $m$ appears in $l$. That is, \[ \prod_{x \in l} f(x) = \prod_{m \in \text{toFinset}(l)} f(m)^{\text{count}(m, l)}. \]
Finset.prod_list_count theorem
[DecidableEq M] (s : List M) : s.prod = ∏ m ∈ s.toFinset, m ^ s.count m
Full source
@[to_additive]
theorem prod_list_count [DecidableEq M] (s : List M) :
    s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by simpa using prod_list_map_count s id
Product of List via Distinct Elements and Counts: $\prod_{x \in s} x = \prod_{m \in \text{toFinset}(s)} m^{\text{count}(m, s)}$
Informal description
Let $M$ be a commutative monoid with decidable equality, and let $s$ be a list of elements in $M$. Then the product of the elements in $s$ is equal to the product over the finite set of distinct elements in $s$ of each element raised to the power of its count in $s$. That is, \[ \prod_{x \in s} x = \prod_{m \in \text{toFinset}(s)} m^{\text{count}(m, s)}. \]
Finset.prod_list_count_of_subset theorem
[DecidableEq M] (m : List M) (s : Finset M) (hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i
Full source
@[to_additive]
theorem prod_list_count_of_subset [DecidableEq M] (m : List M) (s : Finset M)
    (hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by
  rw [prod_list_count]
  refine prod_subset hs fun x _ hx => ?_
  rw [mem_toFinset] at hx
  rw [count_eq_zero_of_not_mem hx, pow_zero]
Product of List via Superset Counts: $\prod_{m} x = \prod_{s} i^{\text{count}(i, m)}$
Informal description
Let $M$ be a commutative monoid with decidable equality, $m$ a list of elements in $M$, and $s$ a finite subset of $M$ such that the finite set of distinct elements in $m$ is contained in $s$. Then the product of the elements in $m$ equals the product over $s$ of each element $i$ raised to the power of its count in $m$, i.e., \[ \prod_{x \in m} x = \prod_{i \in s} i^{\text{count}(i, m)}. \]
Finset.prod_multiset_map_count theorem
[DecidableEq ι] (s : Multiset ι) {M : Type*} [CommMonoid M] (f : ι → M) : (s.map f).prod = ∏ m ∈ s.toFinset, f m ^ s.count m
Full source
@[to_additive]
theorem prod_multiset_map_count [DecidableEq ι] (s : Multiset ι) {M : Type*} [CommMonoid M]
    (f : ι → M) : (s.map f).prod = ∏ m ∈ s.toFinset, f m ^ s.count m := by
  refine Quot.induction_on s fun l => ?_
  simp [prod_list_map_count l f]
Product of Multiset Image via Distinct Elements and Counts: $\prod_{x \in s} f(x) = \prod_{m \in \text{toFinset}(s)} f(m)^{\text{count}(m, s)}$
Informal description
Let $\iota$ be a type with decidable equality, $M$ a commutative monoid, $s$ a multiset of elements of type $\iota$, and $f : \iota \to M$ a function. Then the product of the multiset obtained by applying $f$ to each element of $s$ is equal to the product over the finite set of distinct elements in $s$ of $f(m)$ raised to the power of the multiplicity of $m$ in $s$. That is, \[ \prod_{x \in s} f(x) = \prod_{m \in \text{toFinset}(s)} f(m)^{\text{count}(m, s)}. \]
Finset.prod_multiset_count theorem
[DecidableEq M] (s : Multiset M) : s.prod = ∏ m ∈ s.toFinset, m ^ s.count m
Full source
@[to_additive]
theorem prod_multiset_count [DecidableEq M] (s : Multiset M) :
    s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by
  convert prod_multiset_map_count s id
  rw [Multiset.map_id]
Product of Multiset Elements via Distinct Elements and Counts: $\prod_{x \in s} x = \prod_{m \in \text{toFinset}(s)} m^{\text{count}(m, s)}$
Informal description
Let $M$ be a type with decidable equality and a commutative monoid structure. For any multiset $s$ of elements in $M$, the product of all elements in $s$ (counting multiplicities) equals the product over the finite set of distinct elements in $s$ of each element raised to the power of its multiplicity in $s$. That is, \[ \prod_{x \in s} x = \prod_{m \in \text{toFinset}(s)} m^{\text{count}(m, s)}. \]
Finset.prod_multiset_count_of_subset theorem
[DecidableEq M] (m : Multiset M) (s : Finset M) (hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i
Full source
@[to_additive]
theorem prod_multiset_count_of_subset [DecidableEq M] (m : Multiset M) (s : Finset M)
    (hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by
  revert hs
  refine Quot.induction_on m fun l => ?_
  simp only [quot_mk_to_coe'', prod_coe, coe_count]
  apply prod_list_count_of_subset l s
Product of Multiset Elements via Superset Counts: $\prod_{m} x = \prod_{s} i^{\text{count}(i, m)}$
Informal description
Let $M$ be a type with decidable equality and a commutative monoid structure. For any multiset $m$ of elements in $M$ and any finite subset $s$ of $M$ such that the set of distinct elements of $m$ is contained in $s$, the product of all elements in $m$ equals the product over $s$ of each element $i$ raised to the power of its multiplicity in $m$. That is, \[ \prod_{x \in m} x = \prod_{i \in s} i^{\text{count}(i, m)}. \]
Finset.prod_range_induction theorem
(f s : ℕ → M) (base : s 0 = 1) (step : ∀ n, s (n + 1) = s n * f n) (n : ℕ) : ∏ k ∈ Finset.range n, f k = s n
Full source
/-- For any product along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can verify
that it's equal to a different function just by checking ratios of adjacent terms.

This is a multiplicative discrete analogue of the fundamental theorem of calculus. -/
@[to_additive "For any sum along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can
verify that it's equal to a different function just by checking differences of adjacent terms.

This is a discrete analogue of the fundamental theorem of calculus."]
theorem prod_range_induction (f s :  → M) (base : s 0 = 1)
    (step : ∀ n, s (n + 1) = s n * f n) (n : ) :
    ∏ k ∈ Finset.range n, f k = s n := by
  induction n with
  | zero => rw [Finset.prod_range_zero, base]
  | succ k hk => simp only [hk, Finset.prod_range_succ, step, mul_comm]
Inductive Product Formula over Finite Range in a Commutative Monoid
Informal description
Let $M$ be a commutative monoid, and let $f, s \colon \mathbb{N} \to M$ be functions such that: 1. $s(0) = 1$ (base case), and 2. For all $n \in \mathbb{N}$, $s(n+1) = s(n) \cdot f(n)$ (inductive step). Then for any natural number $n$, the product $\prod_{k \in \{0, \ldots, n-1\}} f(k)$ equals $s(n)$. That is, \[ \prod_{k=0}^{n-1} f(k) = s(n). \]
Finset.prod_const theorem
(b : M) : ∏ _x ∈ s, b = b ^ #s
Full source
@[to_additive (attr := simp)]
theorem prod_const (b : M) : ∏ _x ∈ s, b = b ^ #s :=
  (congr_arg _ <| s.val.map_const b).trans <| Multiset.prod_replicate #s b
Product of Constant Function over Finite Set: $\prod_{x \in s} b = b^{\#s}$
Informal description
Let $M$ be a commutative monoid, $s$ be a finite set, and $b \in M$. The product of the constant function $f(x) = b$ over $s$ equals $b$ raised to the power of the cardinality of $s$, i.e., \[ \prod_{x \in s} b = b^{\#s}. \]
Finset.prod_eq_pow_card theorem
{b : M} (hf : ∀ a ∈ s, f a = b) : ∏ a ∈ s, f a = b ^ #s
Full source
@[to_additive sum_eq_card_nsmul]
theorem prod_eq_pow_card {b : M} (hf : ∀ a ∈ s, f a = b) : ∏ a ∈ s, f a = b ^ #s :=
  (prod_congr rfl hf).trans <| prod_const _
Product of Function Equal to Constant over Finite Set: $\prod_{a \in s} f(a) = b^{\#s}$
Informal description
Let $M$ be a commutative monoid, $s$ be a finite set, and $f \colon \alpha \to M$ a function such that $f(a) = b$ for all $a \in s$ and some fixed $b \in M$. Then the product of $f$ over $s$ equals $b$ raised to the power of the cardinality of $s$, i.e., \[ \prod_{a \in s} f(a) = b^{\#s}. \]
Finset.pow_card_mul_prod theorem
{b : M} : b ^ #s * ∏ a ∈ s, f a = ∏ a ∈ s, b * f a
Full source
@[to_additive card_nsmul_add_sum]
theorem pow_card_mul_prod {b : M} : b ^ #s * ∏ a ∈ s, f a = ∏ a ∈ s, b * f a :=
  (Finset.prod_const b).symmprod_mul_distrib.symm
Power-Cardinality Product Identity: $b^{\#s} \cdot \prod f = \prod (b \cdot f)$
Informal description
Let $M$ be a commutative monoid, $s$ be a finite set, $b \in M$, and $f : \alpha \to M$ be a function. Then the following equality holds: \[ b^{\#s} \cdot \prod_{a \in s} f(a) = \prod_{a \in s} (b \cdot f(a)). \]
Finset.prod_mul_pow_card theorem
{b : M} : (∏ a ∈ s, f a) * b ^ #s = ∏ a ∈ s, f a * b
Full source
@[to_additive sum_add_card_nsmul]
theorem prod_mul_pow_card {b : M} : (∏ a ∈ s, f a) * b ^ #s = ∏ a ∈ s, f a * b :=
  (Finset.prod_const b).symmprod_mul_distrib.symm
Product-Multiplication-Power Identity in Commutative Monoids
Informal description
Let $M$ be a commutative monoid, $s$ a finite set, $f : \alpha \to M$ a function, and $b \in M$ an element. Then the product of $f$ over $s$ multiplied by $b$ raised to the power of the cardinality of $s$ equals the product of $f(a) * b$ over all $a \in s$. In symbols: \[ \left(\prod_{a \in s} f(a)\right) \cdot b^{\#s} = \prod_{a \in s} (f(a) \cdot b). \]
Finset.pow_eq_prod_const theorem
(b : M) : ∀ n, b ^ n = ∏ _k ∈ range n, b
Full source
@[to_additive]
theorem pow_eq_prod_const (b : M) : ∀ n, b ^ n = ∏ _k ∈ range n, b := by simp
Power as Product of Constant Function: $b^n = \prod_{k=0}^{n-1} b$
Informal description
For any element $b$ in a commutative monoid $M$ and any natural number $n$, the $n$-th power of $b$ is equal to the product of $b$ over the finite set $\{0, 1, \ldots, n-1\}$, i.e., \[ b^n = \prod_{k \in \{0, \ldots, n-1\}} b. \]
Finset.prod_pow_eq_pow_sum theorem
(s : Finset ι) (f : ι → ℕ) (a : M) : ∏ i ∈ s, a ^ f i = a ^ ∑ i ∈ s, f i
Full source
@[to_additive sum_nsmul_assoc]
lemma prod_pow_eq_pow_sum (s : Finset ι) (f : ι → ) (a : M) :
    ∏ i ∈ s, a ^ f i = a ^ ∑ i ∈ s, f i :=
  cons_induction (by simp) (fun _ _ _ _ ↦ by simp [prod_cons, sum_cons, pow_add, *]) s
Product of Powers Equals Power of Sum in Commutative Monoids
Informal description
Let $M$ be a commutative monoid, $s$ a finite set indexed by $\iota$, $f : \iota \to \mathbb{N}$ a function, and $a \in M$ an element. Then the product of $a$ raised to the power $f(i)$ over all $i \in s$ equals $a$ raised to the power of the sum of $f(i)$ over all $i \in s$, i.e., $$\prod_{i \in s} a^{f(i)} = a^{\sum_{i \in s} f(i)}.$$
Finset.prod_flip theorem
{n : ℕ} (f : ℕ → M) : (∏ r ∈ range (n + 1), f (n - r)) = ∏ k ∈ range (n + 1), f k
Full source
@[to_additive]
theorem prod_flip {n : } (f :  → M) :
    (∏ r ∈ range (n + 1), f (n - r)) = ∏ k ∈ range (n + 1), f k := by
  induction n with
  | zero => rw [prod_range_one, prod_range_one]
  | succ n ih =>
    rw [prod_range_succ', prod_range_succ _ (Nat.succ n)]
    simp [← ih]
Product Invariance under Index Reversal: $\prod_{r=0}^n f(n - r) = \prod_{k=0}^n f(k)$
Informal description
For any natural number $n$ and any function $f \colon \mathbb{N} \to M$ where $M$ is a commutative monoid, the product of $f$ evaluated at $n - r$ over the range $r \in \{0, \ldots, n\}$ is equal to the product of $f$ evaluated at $k$ over the same range. That is, \[ \prod_{r=0}^n f(n - r) = \prod_{k=0}^n f(k). \]
Finset.prod_involution theorem
(g : ∀ a ∈ s, ι) (hg₁ : ∀ a ha, f a * f (g a ha) = 1) (hg₃ : ∀ a ha, f a ≠ 1 → g a ha ≠ a) (g_mem : ∀ a ha, g a ha ∈ s) (hg₄ : ∀ a ha, g (g a ha) (g_mem a ha) = a) : ∏ x ∈ s, f x = 1
Full source
/-- The difference with `Finset.prod_ninvolution` is that the involution is allowed to use
membership of the domain of the product, rather than being a non-dependent function. -/
@[to_additive "The difference with `Finset.sum_ninvolution` is that the involution is allowed to use
membership of the domain of the sum, rather than being a non-dependent function."]
lemma prod_involution (g : ∀ a ∈ s, ι) (hg₁ : ∀ a ha, f a * f (g a ha) = 1)
    (hg₃ : ∀ a ha, f a ≠ 1g a ha ≠ a)
    (g_mem : ∀ a ha, g a ha ∈ s) (hg₄ : ∀ a ha, g (g a ha) (g_mem a ha) = a) :
    ∏ x ∈ s, f x = 1 := by
  classical
  induction s using Finset.strongInduction with | H s ih => ?_
  obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
  · simp
  have : {x, g x hx}{x, g x hx} ⊆ s := by simp [insert_subset_iff, hx, g_mem]
  suffices h : ∏ x ∈ s \ {x, g x hx}, f x = 1 by
    rw [← prod_sdiff this, h, one_mul]
    cases eq_or_ne (g x hx) x with
    | inl hx' => simpa [hx'] using hg₃ x hx
    | inr hx' => rw [prod_pair hx'.symm, hg₁]
  suffices h₃ : ∀ a (ha : a ∈ s \ {x, g x hx}), g a (sdiff_subset ha) ∈ s \ {x, g x hx} from
    ih (s \ {x, g x hx}) (ssubset_iff.2 ⟨x, by simp [insert_subset_iff, hx]⟩) _
      (by simp [hg₁]) (fun _ _ => hg₃ _ _) h₃ (fun _ _ => hg₄ _ _)
  simp only [mem_sdiff, mem_insert, mem_singleton, not_or, g_mem, true_and]
  rintro a ⟨ha₁, ha₂, ha₃⟩
  refine ⟨fun h => by simp [← h, hg₄] at ha₃, fun h => ?_⟩
  have : g (g a ha₁) (g_mem _ _) = g (g x hx) (g_mem _ _) := by simp only [h]
  exact ha₂ (by simpa [hg₄] using this)
Product Involution Theorem: $\prod_{x \in s} f(x) = 1$ under Pairwise Cancellation
Informal description
Let $s$ be a finite set, $M$ a commutative monoid, and $f \colon \iota \to M$ a function. Suppose there exists a function $g \colon \iota \to \iota$ defined for all $a \in s$ such that: 1. For all $a \in s$, $f(a) \cdot f(g(a)) = 1$, 2. For all $a \in s$, if $f(a) \neq 1$, then $g(a) \neq a$, 3. For all $a \in s$, $g(a) \in s$, 4. For all $a \in s$, $g(g(a)) = a$. Then the product of $f$ over $s$ equals $1$, i.e., \[ \prod_{x \in s} f(x) = 1. \]
Finset.prod_ninvolution theorem
(g : ι → ι) (hg₁ : ∀ a, f a * f (g a) = 1) (hg₂ : ∀ a, f a ≠ 1 → g a ≠ a) (g_mem : ∀ a, g a ∈ s) (hg₃ : ∀ a, g (g a) = a) : ∏ x ∈ s, f x = 1
Full source
/-- The difference with `Finset.prod_involution` is that the involution is a non-dependent function,
rather than being allowed to use membership of the domain of the product. -/
@[to_additive "The difference with `Finset.sum_involution` is that the involution is a non-dependent
function, rather than being allowed to use membership of the domain of the sum."]
lemma prod_ninvolution (g : ι → ι) (hg₁ : ∀ a, f a * f (g a) = 1) (hg₂ : ∀ a, f a ≠ 1g a ≠ a)
    (g_mem : ∀ a, g a ∈ s) (hg₃ : ∀ a, g (g a) = a) : ∏ x ∈ s, f x = 1 :=
  prod_involution (fun i _ => g i) (fun i _ => hg₁ i) (fun _ _ hi => hg₂ _ hi)
    (fun i _ => g_mem i) (fun i _ => hg₃ i)
Product Involution Theorem: $\prod_{x \in s} f(x) = 1$ under Non-Dependent Pairwise Cancellation
Informal description
Let $s$ be a finite set, $M$ a commutative monoid, and $f \colon \iota \to M$ a function. Suppose there exists a function $g \colon \iota \to \iota$ such that: 1. For all $a \in \iota$, $f(a) \cdot f(g(a)) = 1$, 2. For all $a \in \iota$, if $f(a) \neq 1$, then $g(a) \neq a$, 3. For all $a \in \iota$, $g(a) \in s$, 4. For all $a \in \iota$, $g(g(a)) = a$. Then the product of $f$ over $s$ equals $1$, i.e., \[ \prod_{x \in s} f(x) = 1. \]
Finset.prod_comp theorem
[DecidableEq κ] (f : κ → M) (g : ι → κ) : ∏ a ∈ s, f (g a) = ∏ b ∈ s.image g, f b ^ #({a ∈ s | g a = b})
Full source
/-- The product of the composition of functions `f` and `g`, is the product over `b ∈ s.image g` of
`f b` to the power of the cardinality of the fibre of `b`. See also `Finset.prod_image`. -/
@[to_additive "The sum of the composition of functions `f` and `g`, is the sum over `b ∈ s.image g`
of `f b` times of the cardinality of the fibre of `b`. See also `Finset.sum_image`."]
theorem prod_comp [DecidableEq κ] (f : κ → M) (g : ι → κ) :
    ∏ a ∈ s, f (g a) = ∏ b ∈ s.image g, f b ^ #{a ∈ s | g a = b} := by
  simp_rw [← prod_const, prod_fiberwise_of_maps_to' fun _ ↦ mem_image_of_mem _]
Product of Composition Equals Product over Image with Fiber Cardinality Exponents
Informal description
Let $s$ be a finite set of type $\iota$, $M$ a commutative monoid, and $f \colon \kappa \to M$ and $g \colon \iota \to \kappa$ functions. Then the product of $f \circ g$ over $s$ equals the product over the image $g(s)$ of $f(b)$ raised to the power of the cardinality of the fiber $\{a \in s \mid g(a) = b\}$ for each $b \in g(s)$. That is, \[ \prod_{a \in s} f(g(a)) = \prod_{b \in g(s)} f(b)^{\#\{a \in s \mid g(a) = b\}}. \]
Finset.prod_partition theorem
(R : Setoid ι) [DecidableRel R.r] : ∏ x ∈ s, f x = ∏ xbar ∈ s.image (Quotient.mk _), ∏ y ∈ s with ⟦y⟧ = xbar, f y
Full source
/-- A product can be partitioned into a product of products, each equivalent under a setoid. -/
@[to_additive "A sum can be partitioned into a sum of sums, each equivalent under a setoid."]
theorem prod_partition (R : Setoid ι) [DecidableRel R.r] :
    ∏ x ∈ s, f x = ∏ xbar ∈ s.image (Quotient.mk _), ∏ y ∈ s with ⟦y⟧ = xbar, f y := by
  refine (Finset.prod_image' f fun x _hx => ?_).symm
  rfl
Partitioned Product over Equivalence Classes: $\prod_{x \in s} f(x) = \prod_{\overline{x}} \prod_{y \sim x} f(y)$
Informal description
Let $R$ be a setoid (an equivalence relation) on a type $\iota$ with decidable relation $R.r$, and let $s$ be a finite subset of $\iota$. For any commutative monoid $M$ and function $f \colon \iota \to M$, the product of $f$ over $s$ can be partitioned into a product of products over equivalence classes: \[ \prod_{x \in s} f(x) = \prod_{\overline{x} \in \text{image}(\text{Quotient.mk } R, s)} \prod_{\substack{y \in s \\ \llbracket y \rrbracket = \overline{x}}} f(y), \] where $\text{Quotient.mk } R$ maps an element to its equivalence class under $R$, and $\llbracket y \rrbracket$ denotes the equivalence class of $y$.
Finset.prod_cancels_of_partition_cancels theorem
(R : Setoid ι) [DecidableRel R] (h : ∀ x ∈ s, ∏ a ∈ s with R a x, f a = 1) : ∏ x ∈ s, f x = 1
Full source
/-- If we can partition a product into subsets that cancel out, then the whole product cancels. -/
@[to_additive "If we can partition a sum into subsets that cancel out, then the whole sum cancels."]
theorem prod_cancels_of_partition_cancels (R : Setoid ι) [DecidableRel R]
    (h : ∀ x ∈ s, ∏ a ∈ s with R a x, f a = 1) : ∏ x ∈ s, f x = 1 := by
  rw [prod_partition R, ← Finset.prod_eq_one]
  intro xbar xbar_in_s
  obtain ⟨x, x_in_s, rfl⟩ := mem_image.mp xbar_in_s
  simp only [← Quotient.eq] at h
  exact h x x_in_s
Product Cancellation via Partition into Trivial Products
Informal description
Let $R$ be a decidable equivalence relation on a type $\iota$, and let $s$ be a finite subset of $\iota$. For a function $f \colon \iota \to M$ into a commutative monoid $M$, if for every $x \in s$ the product of $f$ over the equivalence class of $x$ in $s$ is equal to $1$, then the product of $f$ over the entire set $s$ is also equal to $1$. That is, if \[ \forall x \in s, \prod_{\substack{a \in s \\ R\,a\,x}} f(a) = 1, \] then \[ \prod_{x \in s} f(x) = 1. \]
Finset.mul_prod_erase theorem
[DecidableEq ι] (s : Finset ι) (f : ι → M) {a : ι} (h : a ∈ s) : (f a * ∏ x ∈ s.erase a, f x) = ∏ x ∈ s, f x
Full source
/-- Taking a product over `s : Finset ι` is the same as multiplying the value on a single element
`f a` by the product of `s.erase a`.

See `Multiset.prod_map_erase` for the `Multiset` version. -/
@[to_additive "Taking a sum over `s : Finset ι` is the same as adding the value on a single element
`f a` to the sum over `s.erase a`.

See `Multiset.sum_map_erase` for the `Multiset` version."]
theorem mul_prod_erase [DecidableEq ι] (s : Finset ι) (f : ι → M) {a : ι} (h : a ∈ s) :
    (f a * ∏ x ∈ s.erase a, f x) = ∏ x ∈ s, f x := by
  rw [← prod_insert (not_mem_erase a s), insert_erase h]
Product Decomposition over a Finite Set: $f(a) \cdot \prod_{x \in s \setminus \{a\}} f(x) = \prod_{x \in s} f(x)$
Informal description
Let $M$ be a commutative monoid, $s$ a finite set of type $\iota$, and $f : \iota \to M$ a function. For any element $a \in s$, we have $$f(a) \cdot \prod_{x \in s \setminus \{a\}} f(x) = \prod_{x \in s} f(x).$$
Finset.prod_erase_mul theorem
[DecidableEq ι] (s : Finset ι) (f : ι → M) {a : ι} (h : a ∈ s) : (∏ x ∈ s.erase a, f x) * f a = ∏ x ∈ s, f x
Full source
/-- A variant of `Finset.mul_prod_erase` with the multiplication swapped. -/
@[to_additive "A variant of `Finset.add_sum_erase` with the addition swapped."]
theorem prod_erase_mul [DecidableEq ι] (s : Finset ι) (f : ι → M) {a : ι} (h : a ∈ s) :
    (∏ x ∈ s.erase a, f x) * f a = ∏ x ∈ s, f x := by rw [mul_comm, mul_prod_erase s f h]
Commutative Product Decomposition over a Finite Set: $\left(\prod_{x \in s \setminus \{a\}} f(x)\right) \cdot f(a) = \prod_{x \in s} f(x)$
Informal description
Let $M$ be a commutative monoid, $s$ a finite set of type $\iota$, and $f : \iota \to M$ a function. For any element $a \in s$, we have $$\left(\prod_{x \in s \setminus \{a\}} f(x)\right) \cdot f(a) = \prod_{x \in s} f(x).$$
Finset.prod_erase theorem
[DecidableEq ι] (s : Finset ι) {f : ι → M} {a : ι} (h : f a = 1) : ∏ x ∈ s.erase a, f x = ∏ x ∈ s, f x
Full source
/-- If a function applied at a point is 1, a product is unchanged by
removing that point, if present, from a `Finset`. -/
@[to_additive "If a function applied at a point is 0, a sum is unchanged by
removing that point, if present, from a `Finset`."]
theorem prod_erase [DecidableEq ι] (s : Finset ι) {f : ι → M} {a : ι} (h : f a = 1) :
    ∏ x ∈ s.erase a, f x = ∏ x ∈ s, f x := by
  rw [← sdiff_singleton_eq_erase]
  refine prod_subset sdiff_subset fun x hx hnx => ?_
  rw [sdiff_singleton_eq_erase] at hnx
  rwa [eq_of_mem_of_not_mem_erase hx hnx]
Product Invariance Under Removal of Trivial Element: $\prod_{s \setminus \{a\}} f = \prod_s f$ when $f(a) = 1$
Informal description
Let $M$ be a commutative monoid, $s$ a finite set of type $\iota$, and $f : \iota \to M$ a function. For any element $a \in \iota$ such that $f(a) = 1$, the product of $f$ over the set $s \setminus \{a\}$ equals the product of $f$ over $s$, i.e., $$\prod_{x \in s \setminus \{a\}} f(x) = \prod_{x \in s} f(x).$$
Finset.prod_erase_lt_of_one_lt theorem
{κ : Type*} [DecidableEq ι] [CommMonoid κ] [LT κ] [MulLeftStrictMono κ] {s : Finset ι} {d : ι} (hd : d ∈ s) {f : ι → κ} (hdf : 1 < f d) : ∏ m ∈ s.erase d, f m < ∏ m ∈ s, f m
Full source
@[to_additive]
theorem prod_erase_lt_of_one_lt {κ : Type*} [DecidableEq ι] [CommMonoid κ] [LT κ]
    [MulLeftStrictMono κ] {s : Finset ι} {d : ι} (hd : d ∈ s) {f : ι → κ}
    (hdf : 1 < f d) : ∏ m ∈ s.erase d, f m < ∏ m ∈ s, f m := by
  conv in ∏ m ∈ s, f m => rw [← Finset.insert_erase hd]
  rw [Finset.prod_insert (Finset.not_mem_erase d s)]
  exact lt_mul_of_one_lt_left' _ hdf
Strict Inequality for Products Over Finite Sets with One Element Greater Than One
Informal description
Let $\kappa$ be a commutative monoid with a strict order relation $<$ such that left multiplication is strictly monotone. For any finite set $s$ of type $\iota$, any element $d \in s$, and any function $f : \iota \to \kappa$ such that $1 < f(d)$, the product of $f$ over the set $s \setminus \{d\}$ is strictly less than the product of $f$ over $s$, i.e., $$\prod_{m \in s \setminus \{d\}} f(m) < \prod_{m \in s} f(m).$$
Finset.prod_mul_eq_prod_mul_of_exists theorem
{s : Finset ι} {f : ι → M} {b₁ b₂ : M} (a : ι) (ha : a ∈ s) (h : f a * b₁ = f a * b₂) : (∏ a ∈ s, f a) * b₁ = (∏ a ∈ s, f a) * b₂
Full source
@[to_additive]
lemma prod_mul_eq_prod_mul_of_exists {s : Finset ι} {f : ι → M} {b₁ b₂ : M}
    (a : ι) (ha : a ∈ s) (h : f a * b₁ = f a * b₂) :
    (∏ a ∈ s, f a) * b₁ = (∏ a ∈ s, f a) * b₂ := by
  classical
  rw [← insert_erase ha]
  simp only [mem_erase, ne_eq, not_true_eq_false, false_and, not_false_eq_true, prod_insert]
  rw [mul_assoc, mul_comm, mul_assoc, mul_comm b₁, h, ← mul_assoc, mul_comm _ (f a)]
Product Equality under Cancellation in Commutative Monoid
Informal description
Let $M$ be a commutative monoid, $s$ a finite set of type $\iota$, and $f : \iota \to M$ a function. For any elements $b_1, b_2 \in M$ and any element $a \in s$ such that $f(a) \cdot b_1 = f(a) \cdot b_2$, we have $$\left(\prod_{x \in s} f(x)\right) \cdot b_1 = \left(\prod_{x \in s} f(x)\right) \cdot b_2.$$
Finset.prod_filter_of_pairwise_eq_one theorem
[DecidableEq ι] {f : κ → ι} {g : ι → M} {n : κ} {I : Finset κ} (hn : n ∈ I) (hf : (I : Set κ).Pairwise fun i j ↦ f i = f j → g (f i) = 1) : ∏ j ∈ I with f j = f n, g (f j) = g (f n)
Full source
@[to_additive]
lemma prod_filter_of_pairwise_eq_one [DecidableEq ι] {f : κ → ι} {g : ι → M} {n : κ} {I : Finset κ}
    (hn : n ∈ I) (hf : (I : Set κ).Pairwise fun i j ↦ f i = f j → g (f i) = 1) :
    ∏ j ∈ I with f j = f n, g (f j) = g (f n) := by
  classical
  have h j (hj : j ∈ {i ∈ I | f i = f n}.erase n) : g (f j) = 1 := by
    simp only [mem_erase, mem_filter] at hj
    exact hf hj.2.1 hn hj.1 hj.2.2
  rw [← mul_one (g (f n)), ← prod_eq_one h,
    ← mul_prod_erase {i ∈ I | f i = f n} (fun i ↦ g (f i)) <| mem_filter.mpr ⟨hn, by rfl⟩]
Product over Filtered Set with Pairwise Condition: $\prod_{j \in I, f(j) = f(n)} g(f(j)) = g(f(n))$
Informal description
Let $M$ be a commutative monoid, $I$ a finite set of type $\kappa$, and $f : \kappa \to \iota$, $g : \iota \to M$ functions. For any element $n \in I$, if for any distinct $i, j \in I$ the equality $f(i) = f(j)$ implies $g(f(i)) = 1$, then the product of $g(f(j))$ over all $j \in I$ such that $f(j) = f(n)$ equals $g(f(n))$.
Finset.prod_image_of_pairwise_eq_one theorem
[DecidableEq ι] {f : κ → ι} {g : ι → M} {I : Finset κ} (hf : (I : Set κ).Pairwise fun i j ↦ f i = f j → g (f i) = 1) : ∏ s ∈ I.image f, g s = ∏ i ∈ I, g (f i)
Full source
/-- A version of `Finset.prod_map` and `Finset.prod_image`, but we do not assume that `f` is
injective. Rather, we assume that the image of `f` on `I` only overlaps where `g (f i) = 1`.
The conclusion is the same as in `prod_image`. -/
@[to_additive (attr := simp)
"A version of `Finset.sum_map` and `Finset.sum_image`, but we do not assume that `f` is
injective. Rather, we assume that the image of `f` on `I` only overlaps where `g (f i) = 0`.
The conclusion is the same as in `sum_image`."]
lemma prod_image_of_pairwise_eq_one [DecidableEq ι] {f : κ → ι} {g : ι → M} {I : Finset κ}
    (hf : (I : Set κ).Pairwise fun i j ↦ f i = f j → g (f i) = 1) :
    ∏ s ∈ I.image f, g s = ∏ i ∈ I, g (f i) := by
  rw [prod_image']
  exact fun n hnI => (prod_filter_of_pairwise_eq_one hnI hf).symm
Product over Image Equals Product under Pairwise Condition: $\prod_{s \in f(I)} g(s) = \prod_{i \in I} g(f(i))$
Informal description
Let $M$ be a commutative monoid, $I$ a finite set of type $\kappa$, and $f \colon \kappa \to \iota$, $g \colon \iota \to M$ functions. Suppose that for any distinct $i, j \in I$, if $f(i) = f(j)$ then $g(f(i)) = 1$. Then the product of $g$ over the image of $I$ under $f$ equals the product of $g \circ f$ over $I$: \[ \prod_{s \in f(I)} g(s) = \prod_{i \in I} g(f(i)). \]
Finset.prod_image_of_disjoint theorem
[DecidableEq ι] [PartialOrder ι] [OrderBot ι] {f : κ → ι} {g : ι → M} (hg_bot : g ⊥ = 1) {I : Finset κ} (hf_disj : (I : Set κ).PairwiseDisjoint f) : ∏ s ∈ I.image f, g s = ∏ i ∈ I, g (f i)
Full source
/-- A version of `Finset.prod_map` and `Finset.prod_image`, but we do not assume that `f` is
injective. Rather, we assume that the images of `f` are disjoint on `I`, and `g ⊥ = 1`. The
conclusion is the same as in `prod_image`. -/
@[to_additive (attr := simp)
"A version of `Finset.sum_map` and `Finset.sum_image`, but we do not assume that `f` is
injective. Rather, we assume that the images of `f` are disjoint on `I`, and `g ⊥ = 0`. The
conclusion is the same as in `sum_image`."]
lemma prod_image_of_disjoint [DecidableEq ι] [PartialOrder ι] [OrderBot ι] {f : κ → ι} {g : ι → M}
    (hg_bot : g  = 1) {I : Finset κ} (hf_disj : (I : Set κ).PairwiseDisjoint f) :
    ∏ s ∈ I.image f, g s = ∏ i ∈ I, g (f i) := by
  refine prod_image_of_pairwise_eq_one <| hf_disj.imp fun i j hdisj hfij ↦ ?_
  rw [Function.onFun, ← hfij, disjoint_self] at hdisj
  rw [hdisj, hg_bot]
Product over Image Equals Product under Disjointness Condition: $\prod_{s \in f(I)} g(s) = \prod_{i \in I} g(f(i))$
Informal description
Let $\iota$ be a type with a partial order and a bottom element $\bot$, and let $M$ be a commutative monoid. Given a function $f \colon \kappa \to \iota$ and a function $g \colon \iota \to M$ such that $g(\bot) = 1$, and a finite set $I \subseteq \kappa$ where the images of $f$ are pairwise disjoint on $I$, then the product of $g$ over the image of $I$ under $f$ equals the product of $g \circ f$ over $I$: \[ \prod_{s \in f(I)} g(s) = \prod_{i \in I} g(f(i)). \]
Finset.prod_unique_nonempty theorem
[Unique ι] (s : Finset ι) (f : ι → M) (h : s.Nonempty) : ∏ x ∈ s, f x = f default
Full source
@[to_additive]
theorem prod_unique_nonempty [Unique ι] (s : Finset ι) (f : ι → M) (h : s.Nonempty) :
   ∏ x ∈ s, f x = f default := by
  rw [h.eq_singleton_default, Finset.prod_singleton]
Product over Nonempty Finite Set in Unique Type Equals Function at Default Element
Informal description
Let $\iota$ be a type with a unique element, $s$ be a nonempty finite subset of $\iota$, and $f : \iota \to M$ be a function where $M$ is a commutative monoid. Then the product of $f$ over $s$ is equal to $f$ evaluated at the unique element of $\iota$, i.e., \[ \prod_{x \in s} f(x) = f(\text{default}). \]
Finset.prod_dvd_prod_of_dvd theorem
(f g : ι → M) (h : ∀ i ∈ s, f i ∣ g i) : ∏ i ∈ s, f i ∣ ∏ i ∈ s, g i
Full source
lemma prod_dvd_prod_of_dvd (f g : ι → M) (h : ∀ i ∈ s, f i ∣ g i) :
    ∏ i ∈ s, f i∏ i ∈ s, f i ∣ ∏ i ∈ s, g i := by
  induction s using Finset.cons_induction with
  | empty => simp
  | cons a T haT IH =>
    rw [Finset.prod_cons, Finset.prod_cons]
    rw [Finset.forall_mem_cons] at h
    exact mul_dvd_mul h.1 <| IH h.2
Product Divisibility in Commutative Monoids
Informal description
Let $M$ be a commutative monoid, $s$ a finite set, and $f, g : \iota \to M$ functions. If for every $i \in s$, $f(i)$ divides $g(i)$, then the product $\prod_{i \in s} f(i)$ divides the product $\prod_{i \in s} g(i)$.
Finset.prod_sdiff_eq_prod_sdiff_iff theorem
: ∏ i ∈ s \ t, f i = ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i = ∏ i ∈ t, f i
Full source
@[to_additive]
lemma prod_sdiff_eq_prod_sdiff_iff :
    ∏ i ∈ s \ t, f i∏ i ∈ s \ t, f i = ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i = ∏ i ∈ t, f i :=
  eq_comm.trans <| eq_iff_eq_of_mul_eq_mul <| by
    rw [← prod_union disjoint_sdiff_self_left, ← prod_union disjoint_sdiff_self_left,
      sdiff_union_self_eq_union, sdiff_union_self_eq_union, union_comm]
Equality of Products over Symmetric Differences Implies Equality of Full Products
Informal description
For any finite sets $s$ and $t$ of type $\iota$ and any function $f : \iota \to M$ where $M$ is a commutative monoid, the following equivalence holds: \[ \prod_{i \in s \setminus t} f(i) = \prod_{i \in t \setminus s} f(i) \quad \text{if and only if} \quad \prod_{i \in s} f(i) = \prod_{i \in t} f(i). \]
Finset.prod_sdiff_ne_prod_sdiff_iff theorem
: ∏ i ∈ s \ t, f i ≠ ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i ≠ ∏ i ∈ t, f i
Full source
@[to_additive]
lemma prod_sdiff_ne_prod_sdiff_iff :
    ∏ i ∈ s \ t, f i∏ i ∈ s \ t, f i ≠ ∏ i ∈ t \ s, f i∏ i ∈ s \ t, f i ≠ ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i ≠ ∏ i ∈ t, f i :=
  prod_sdiff_eq_prod_sdiff_iff.not
Inequality of Products over Symmetric Differences Implies Inequality of Full Products
Informal description
For any finite sets $s$ and $t$ of type $\iota$ and any function $f : \iota \to M$ where $M$ is a commutative monoid, the following equivalence holds: \[ \prod_{i \in s \setminus t} f(i) \neq \prod_{i \in t \setminus s} f(i) \quad \text{if and only if} \quad \prod_{i \in s} f(i) \neq \prod_{i \in t} f(i). \]
Finset.prod_insert_div theorem
(ha : a ∉ s) (f : ι → G) : (∏ x ∈ insert a s, f x) / f a = ∏ x ∈ s, f x
Full source
@[to_additive]
lemma prod_insert_div (ha : a ∉ s) (f : ι → G) :
    (∏ x ∈ insert a s, f x) / f a = ∏ x ∈ s, f x := by simp [ha]
Cancellation of Product over Inserted Element in Commutative Group: $\left( \prod_{x \in s \cup \{a\}} f(x) \right) / f(a) = \prod_{x \in s} f(x)$
Informal description
Let $G$ be a commutative group, $s$ a finite set of type $\iota$, and $f : \iota \to G$ a function. For any element $a \notin s$, we have $$\left( \prod_{x \in s \cup \{a\}} f(x) \right) / f(a) = \prod_{x \in s} f(x).$$
Finset.prod_erase_eq_div theorem
{a : ι} (h : a ∈ s) : ∏ x ∈ s.erase a, f x = (∏ x ∈ s, f x) / f a
Full source
@[to_additive (attr := simp)]
theorem prod_erase_eq_div {a : ι} (h : a ∈ s) : ∏ x ∈ s.erase a, f x = (∏ x ∈ s, f x) / f a := by
  rw [eq_div_iff_mul_eq', prod_erase_mul _ _ h]
Product Decomposition over Finite Set Minus Element: $\prod_{s \setminus \{a\}} f = (\prod_s f) / f(a)$
Informal description
Let $G$ be a commutative group, $s$ a finite set of type $\iota$, and $f : \iota \to G$ a function. For any element $a \in s$, the product over $s \setminus \{a\}$ equals the product over $s$ divided by $f(a)$, i.e., $$\prod_{x \in s \setminus \{a\}} f(x) = \left( \prod_{x \in s} f(x) \right) / f(a).$$
Finset.prod_range_div theorem
(f : ℕ → G) (n : ℕ) : (∏ i ∈ range n, f (i + 1) / f i) = f n / f 0
Full source
/-- A telescoping product along `{0, ..., n - 1}` of a commutative group valued function reduces to
the ratio of the last and first factors. -/
@[to_additive "A telescoping sum along `{0, ..., n - 1}` of an additive commutative group valued
function reduces to the difference of the last and first terms."]
lemma prod_range_div (f :  → G) (n : ) : (∏ i ∈ range n, f (i + 1) / f i) = f n / f 0 := by
  apply prod_range_induction <;> simp
Telescoping Product Identity: $\prod_{i=0}^{n-1} \frac{f(i+1)}{f(i)} = \frac{f(n)}{f(0)}$
Informal description
Let $G$ be a commutative group and $f \colon \mathbb{N} \to G$ a function. For any natural number $n$, the telescoping product over the finite set $\{0, \ldots, n-1\}$ satisfies: \[ \prod_{i=0}^{n-1} \frac{f(i+1)}{f(i)} = \frac{f(n)}{f(0)}. \]
Finset.prod_range_div' theorem
(f : ℕ → G) (n : ℕ) : (∏ i ∈ range n, f i / f (i + 1)) = f 0 / f n
Full source
@[to_additive]
lemma prod_range_div' (f :  → G) (n : ) : (∏ i ∈ range n, f i / f (i + 1)) = f 0 / f n := by
  apply prod_range_induction <;> simp
Telescoping Product Identity: $\prod_{i=0}^{n-1} \frac{f(i)}{f(i+1)} = \frac{f(0)}{f(n)}$
Informal description
Let $G$ be a commutative group and $f \colon \mathbb{N} \to G$ a function. For any natural number $n$, the product $\prod_{i=0}^{n-1} \frac{f(i)}{f(i+1)}$ equals $\frac{f(0)}{f(n)}$.
Finset.prod_range_add_div_prod_range theorem
(f : ℕ → G) (n m : ℕ) : (∏ k ∈ range (n + m), f k) / ∏ k ∈ range n, f k = ∏ k ∈ Finset.range m, f (n + k)
Full source
@[to_additive]
lemma prod_range_add_div_prod_range (f :  → G) (n m : ) :
    (∏ k ∈ range (n + m), f k) / ∏ k ∈ range n, f k = ∏ k ∈ Finset.range m, f (n + k) :=
  div_eq_of_eq_mul' (prod_range_add f n m)
Ratio of Products over Ranges: $\frac{\prod_{k=0}^{n+m-1} f(k)}{\prod_{k=0}^{n-1} f(k)} = \prod_{k=0}^{m-1} f(n + k)$
Informal description
Let $G$ be a commutative group and $f \colon \mathbb{N} \to G$ be a function. For any natural numbers $n, m$, we have \[ \frac{\prod_{k=0}^{n+m-1} f(k)}{\prod_{k=0}^{n-1} f(k)} = \prod_{k=0}^{m-1} f(n + k). \]
Finset.prod_sdiff_eq_div theorem
(h : s₁ ⊆ s₂) : ∏ x ∈ s₂ \ s₁, f x = (∏ x ∈ s₂, f x) / ∏ x ∈ s₁, f x
Full source
@[to_additive (attr := simp)]
lemma prod_sdiff_eq_div (h : s₁ ⊆ s₂) : ∏ x ∈ s₂ \ s₁, f x = (∏ x ∈ s₂, f x) / ∏ x ∈ s₁, f x := by
  rw [eq_div_iff_mul_eq', prod_sdiff h]
Product over Set Difference Equals Quotient of Products: $\prod_{s_2 \setminus s_1} f = \frac{\prod_{s_2} f}{\prod_{s_1} f}$
Informal description
Let $s_1$ and $s_2$ be finite subsets of a type $\iota$ with decidable equality such that $s_1 \subseteq s_2$, and let $f : \iota \to G$ be a function where $G$ is a commutative group. Then the product of $f$ over the set difference $s_2 \setminus s_1$ equals the quotient of the product over $s_2$ divided by the product over $s_1$: \[ \prod_{x \in s_2 \setminus s_1} f(x) = \frac{\prod_{x \in s_2} f(x)}{\prod_{x \in s_1} f(x)}. \]
Finset.prod_sdiff_div_prod_sdiff theorem
: (∏ x ∈ s₂ \ s₁, f x) / ∏ x ∈ s₁ \ s₂, f x = (∏ x ∈ s₂, f x) / ∏ x ∈ s₁, f x
Full source
@[to_additive]
theorem prod_sdiff_div_prod_sdiff :
    (∏ x ∈ s₂ \ s₁, f x) / ∏ x ∈ s₁ \ s₂, f x = (∏ x ∈ s₂, f x) / ∏ x ∈ s₁, f x := by
  simp [← Finset.prod_sdiff (@inf_le_left _ _ s₁ s₂), ← Finset.prod_sdiff (@inf_le_right _ _ s₁ s₂)]
Ratio of Products over Set Differences: $\frac{\prod_{s_2 \setminus s_1} f}{\prod_{s_1 \setminus s_2} f} = \frac{\prod_{s_2} f}{\prod_{s_1} f}$
Informal description
For any finite sets $s_1$ and $s_2$ of a type $\alpha$, and any function $f \colon \alpha \to G$ where $G$ is a commutative group, the following equality holds: \[ \frac{\prod_{x \in s_2 \setminus s_1} f(x)}{\prod_{x \in s_1 \setminus s_2} f(x)} = \frac{\prod_{x \in s_2} f(x)}{\prod_{x \in s_1} f(x)}. \]
Finset.sum_range_tsub theorem
{f : ℕ → M} (h : Monotone f) (n : ℕ) : ∑ i ∈ range n, (f (i + 1) - f i) = f n - f 0
Full source
/-- A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function reduces to the difference of
the last and first terms when the function we are summing is monotone. -/
lemma sum_range_tsub {f :  → M} (h : Monotone f) (n : ) :
    ∑ i ∈ range n, (f (i + 1) - f i) = f n - f 0 := by
  apply sum_range_induction
  case base => apply tsub_eq_of_eq_add; rw [zero_add]
  case step =>
    intro n
    have h₁ : f n ≤ f (n + 1) := h (Nat.le_succ _)
    have h₂ : f 0 ≤ f n := h (Nat.zero_le _)
    rw [tsub_add_eq_add_tsub h₂, add_tsub_cancel_of_le h₁]
Telescoping Sum Identity for Monotone Functions: $\sum_{i=0}^{n-1} (f(i+1) - f(i)) = f(n) - f(0)$
Informal description
Let $M$ be an additive commutative monoid with a partial order and a subtraction operation satisfying the ordered subtraction property. For any monotone function $f \colon \mathbb{N} \to M$ and any natural number $n$, the telescoping sum over the finite set $\{0, \ldots, n-1\}$ satisfies: \[ \sum_{i=0}^{n-1} (f(i+1) - f(i)) = f(n) - f(0). \]
Finset.sum_tsub_distrib theorem
(s : Finset ι) {f g : ι → M} (hfg : ∀ x ∈ s, g x ≤ f x) : ∑ x ∈ s, (f x - g x) = ∑ x ∈ s, f x - ∑ x ∈ s, g x
Full source
lemma sum_tsub_distrib (s : Finset ι) {f g : ι → M} (hfg : ∀ x ∈ s, g x ≤ f x) :
    ∑ x ∈ s, (f x - g x) = ∑ x ∈ s, f x - ∑ x ∈ s, g x := Multiset.sum_map_tsub _ hfg
Sum of Differences Equals Difference of Sums for Finite Sets
Informal description
Let $M$ be an additive commutative monoid with a partial order and a subtraction operation satisfying the ordered subtraction property. For any finite set $s$ over a type $\iota$ and functions $f, g : \iota \to M$ such that $g(x) \leq f(x)$ for all $x \in s$, the sum of the differences $f(x) - g(x)$ over $s$ equals the difference of the sums: \[ \sum_{x \in s} (f(x) - g(x)) = \left(\sum_{x \in s} f(x)\right) - \left(\sum_{x \in s} g(x)\right). \]
Finset.card_eq_sum_ones theorem
(s : Finset ι) : #s = ∑ _ ∈ s, 1
Full source
lemma card_eq_sum_ones (s : Finset ι) : #s = ∑ _ ∈ s, 1 := by simp
Cardinality as Sum of Ones: $\#s = \sum_{x \in s} 1$
Informal description
For any finite set $s$ of type $\iota$, the cardinality of $s$ is equal to the sum of the constant function $1$ over all elements of $s$, i.e., \[ \#s = \sum_{x \in s} 1. \]
Finset.sum_const_nat theorem
{m : ℕ} {f : ι → ℕ} (h₁ : ∀ x ∈ s, f x = m) : ∑ x ∈ s, f x = #s * m
Full source
theorem sum_const_nat {m : } {f : ι → } (h₁ : ∀ x ∈ s, f x = m) : ∑ x ∈ s, f x = #s * m := by
  rw [← Nat.nsmul_eq_mul, ← sum_const]
  apply sum_congr rfl h₁
Sum of Constant Function Equals Cardinality Times Constant
Informal description
For any finite set $s$ over a type $\iota$, any natural number $m$, and any function $f \colon \iota \to \mathbb{N}$ such that $f(x) = m$ for all $x \in s$, the sum of $f$ over $s$ equals the product of the cardinality of $s$ and $m$: \[ \sum_{x \in s} f(x) = \#s \cdot m. \]
Finset.sum_card_fiberwise_eq_card_filter theorem
{κ : Type*} [DecidableEq κ] (s : Finset ι) (t : Finset κ) (g : ι → κ) : ∑ j ∈ t, #({i ∈ s | g i = j}) = #({i ∈ s | g i ∈ t})
Full source
lemma sum_card_fiberwise_eq_card_filter {κ : Type*} [DecidableEq κ] (s : Finset ι) (t : Finset κ)
    (g : ι → κ) : ∑ j ∈ t, #{i ∈ s | g i = j} = #{i ∈ s | g i ∈ t} := by
  simpa only [card_eq_sum_ones] using sum_fiberwise_eq_sum_filter _ _ _ _
Sum of Fiber Cardinalities Equals Cardinality of Preimage
Informal description
For any finite sets $s$ (of type $\iota$) and $t$ (of type $\kappa$) with decidable equality on $\kappa$, and any function $g \colon \iota \to \kappa$, the sum of the cardinalities of the fibers of $g$ over $t$ equals the cardinality of the subset of $s$ mapped into $t$ by $g$. In symbols: \[ \sum_{j \in t} \#\{i \in s \mid g(i) = j\} = \#\{i \in s \mid g(i) \in t\}. \]
Finset.card_disjiUnion theorem
(s : Finset ι) (t : ι → Finset M) (h) : #(s.disjiUnion t h) = ∑ a ∈ s, #(t a)
Full source
@[simp]
theorem card_disjiUnion (s : Finset ι) (t : ι → Finset M) (h) :
    #(s.disjiUnion t h) = ∑ a ∈ s, #(t a) :=
  Multiset.card_bind _ _
Cardinality of Disjoint Union Equals Sum of Cardinalities
Informal description
For any finite set $s$ of type $\iota$, any function $t \colon \iota \to \text{Finset} M$, and any proof $h$ that the images $t(a)$ for $a \in s$ are pairwise disjoint, the cardinality of the disjoint union $\text{disjiUnion}(s, t, h)$ is equal to the sum of the cardinalities of the sets $t(a)$ for each $a \in s$. In symbols: \[ \#(\text{disjiUnion}(s, t, h)) = \sum_{a \in s} \#(t(a)) \]
Finset.card_biUnion theorem
[DecidableEq M] {t : ι → Finset M} (h : s.toSet.PairwiseDisjoint t) : #(s.biUnion t) = ∑ u ∈ s, #(t u)
Full source
theorem card_biUnion [DecidableEq M] {t : ι → Finset M} (h : s.toSet.PairwiseDisjoint t) :
    #(s.biUnion t) = ∑ u ∈ s, #(t u) := by simpa using sum_biUnion h (M := ) (f := 1)
Cardinality of Finite Union Equals Sum of Cardinalities for Pairwise Disjoint Sets
Informal description
For any finite set $s$ of type $\iota$ and any function $t \colon \iota \to \text{Finset} M$ (where $M$ has decidable equality), if the images $t(u)$ for $u \in s$ are pairwise disjoint, then the cardinality of the finite union $\bigcup_{u \in s} t(u)$ is equal to the sum of the cardinalities of the sets $t(u)$ for each $u \in s$. In symbols: \[ \#\left( \bigcup_{u \in s} t(u) \right) = \sum_{u \in s} \#(t(u)) \]
Finset.card_biUnion_le theorem
[DecidableEq M] {s : Finset ι} {t : ι → Finset M} : #(s.biUnion t) ≤ ∑ a ∈ s, #(t a)
Full source
theorem card_biUnion_le [DecidableEq M] {s : Finset ι} {t : ι → Finset M} :
    #(s.biUnion t)∑ a ∈ s, #(t a) :=
  haveI := Classical.decEq ι
  Finset.induction_on s (by simp) fun a s has ih =>
    calc
      #((insert a s).biUnion t)#(t a) + #(s.biUnion t) := by
        rw [biUnion_insert]; exact card_union_le ..
      _ ≤ ∑ a ∈ insert a s, #(t a) := by rw [sum_insert has]; exact Nat.add_le_add_left ih _
Cardinality Bound for Finite Union: $\#\left( \bigcup_{a \in s} t(a) \right) \leq \sum_{a \in s} \#(t(a))$
Informal description
For any finite set $s$ of type $\iota$ and any function $t \colon \iota \to \text{Finset} M$ (where $M$ has decidable equality), the cardinality of the finite union $\bigcup_{a \in s} t(a)$ is less than or equal to the sum of the cardinalities of the sets $t(a)$ for each $a \in s$. In symbols: \[ \#\left( \bigcup_{a \in s} t(a) \right) \leq \sum_{a \in s} \#(t(a)) \]
Finset.card_eq_sum_card_fiberwise theorem
[DecidableEq M] {f : ι → M} {s : Finset ι} {t : Finset M} (H : s.toSet.MapsTo f t) : #s = ∑ b ∈ t, #({a ∈ s | f a = b})
Full source
theorem card_eq_sum_card_fiberwise [DecidableEq M] {f : ι → M} {s : Finset ι} {t : Finset M}
    (H : s.toSet.MapsTo f t) : #s = ∑ b ∈ t, #{a ∈ s | f a = b} := by
  simp only [card_eq_sum_ones, sum_fiberwise_of_maps_to H]
Cardinality as Sum of Fiber Cardinalities: $\#s = \sum_{b \in t} \#\{a \in s \mid f(a) = b\}$
Informal description
Let $f \colon \iota \to M$ be a function, $s$ be a finite subset of $\iota$, and $t$ be a finite subset of $M$ such that $f$ maps every element of $s$ into $t$. Then the cardinality of $s$ is equal to the sum over $b \in t$ of the cardinalities of the fibers $\{a \in s \mid f(a) = b\}$. In symbols: \[ \#s = \sum_{b \in t} \#\{a \in s \mid f(a) = b\}. \]
Finset.card_eq_sum_card_image theorem
[DecidableEq M] (f : ι → M) (s : Finset ι) : #s = ∑ b ∈ s.image f, #({a ∈ s | f a = b})
Full source
theorem card_eq_sum_card_image [DecidableEq M] (f : ι → M) (s : Finset ι) :
    #s = ∑ b ∈ s.image f, #{a ∈ s | f a = b} :=
  card_eq_sum_card_fiberwise fun _ => mem_image_of_mem _
Cardinality as Sum of Fiber Cardinalities over Image: $\#s = \sum_{b \in f(s)} \#\{a \in s \mid f(a) = b\}$
Informal description
For any function $f \colon \iota \to M$ (where $M$ has decidable equality) and any finite subset $s$ of $\iota$, the cardinality of $s$ is equal to the sum over $b \in f(s)$ of the cardinalities of the fibers $\{a \in s \mid f(a) = b\}$. In symbols: \[ \#s = \sum_{b \in f(s)} \#\{a \in s \mid f(a) = b\}. \]
Finset.mem_sum theorem
{f : ι → Multiset M} (s : Finset ι) (b : M) : (b ∈ ∑ x ∈ s, f x) ↔ ∃ a ∈ s, b ∈ f a
Full source
theorem mem_sum {f : ι → Multiset M} (s : Finset ι) (b : M) :
    (b ∈ ∑ x ∈ s, f x) ↔ ∃ a ∈ s, b ∈ f a := by
  induction s using Finset.cons_induction with
  | empty => simp
  | cons a t hi ih => simp [sum_cons, ih, or_and_right, exists_or]
Membership in Sum of Multisets over Finite Set
Informal description
For any function $f \colon \iota \to \text{Multiset } M$, finite set $s \subseteq \iota$, and element $b \in M$, the element $b$ belongs to the sum $\sum_{x \in s} f(x)$ if and only if there exists an element $a \in s$ such that $b \in f(a)$.
Fintype.prod_of_injective theorem
(e : ι → κ) (he : Injective e) (f : ι → M) (g : κ → M) (h' : ∀ i ∉ Set.range e, g i = 1) (h : ∀ i, f i = g (e i)) : ∏ i, f i = ∏ j, g j
Full source
@[to_additive]
lemma prod_of_injective (e : ι → κ) (he : Injective e) (f : ι → M) (g : κ → M)
    (h' : ∀ i ∉ Set.range e, g i = 1) (h : ∀ i, f i = g (e i)) : ∏ i, f i = ∏ j, g j :=
  prod_of_injOn e he.injOn (by simp) (by simpa using h') (fun i _ ↦ h i)
Product Equality under Injection and Triviality Conditions: $\prod_{\iota} f = \prod_{\kappa} g$
Informal description
Let $\iota$ and $\kappa$ be finite types, and let $e \colon \iota \to \kappa$ be an injective function. Given functions $f \colon \iota \to M$ and $g \colon \kappa \to M$ where $M$ is a commutative monoid, suppose that: 1. For all $i \notin \text{range}(e)$, $g(i) = 1$, and 2. For all $i \in \iota$, $f(i) = g(e(i))$. Then the product of $f$ over all elements of $\iota$ equals the product of $g$ over all elements of $\kappa$, i.e., \[ \prod_{i \in \iota} f(i) = \prod_{j \in \kappa} g(j). \]
Fintype.prod_fiberwise theorem
[DecidableEq κ] (g : ι → κ) (f : ι → M) : ∏ j, ∏ i : { i // g i = j }, f i = ∏ i, f i
Full source
@[to_additive]
lemma prod_fiberwise [DecidableEq κ] (g : ι → κ) (f : ι → M) :
    ∏ j, ∏ i : {i // g i = j}, f i = ∏ i, f i := by
  rw [← Finset.prod_fiberwise _ g f]
  congr with j
  exact (prod_subtype _ (by simp) _).symm
Fiberwise Product Equals Total Product for Finite Types: $\prod_j \prod_{\substack{i \\ g(i) = j}} f(i) = \prod_i f(i)$
Informal description
Let $\iota$ and $\kappa$ be finite types, with $\kappa$ having decidable equality. Given a function $g \colon \iota \to \kappa$ and a function $f \colon \iota \to M$ where $M$ is a commutative monoid, the product over all $j \in \kappa$ of the products of $f$ over the fibers $\{i \in \iota \mid g(i) = j\}$ equals the product of $f$ over all $i \in \iota$. That is, \[ \prod_{j \in \kappa} \prod_{\substack{i \in \iota \\ g(i) = j}} f(i) = \prod_{i \in \iota} f(i). \]
Fintype.prod_fiberwise' theorem
[DecidableEq κ] (g : ι → κ) (f : κ → M) : ∏ j, ∏ _i : { i // g i = j }, f j = ∏ i, f (g i)
Full source
@[to_additive]
lemma prod_fiberwise' [DecidableEq κ] (g : ι → κ) (f : κ → M) :
    ∏ j, ∏ _i : {i // g i = j}, f j = ∏ i, f (g i) := by
  rw [← Finset.prod_fiberwise' _ g f]
  congr with j
  exact (prod_subtype _ (by simp) fun _ ↦ _).symm
Fiberwise Product Equals Composition Product for Finite Types: $\prod_j \prod_{\substack{i \\ g(i) = j}} f(j) = \prod_i f(g(i))$
Informal description
Let $\iota$ and $\kappa$ be finite types with $\kappa$ having decidable equality. Given a function $g \colon \iota \to \kappa$ and a function $f \colon \kappa \to M$ where $M$ is a commutative monoid, the product over all $j \in \kappa$ of the products of $f(j)$ over the fibers $\{i \in \iota \mid g(i) = j\}$ equals the product of $f(g(i))$ over all $i \in \iota$. That is, \[ \prod_{j \in \kappa} \prod_{\substack{i \in \iota \\ g(i) = j}} f(j) = \prod_{i \in \iota} f(g(i)). \]
Fintype.prod_unique theorem
[Unique ι] (f : ι → M) : ∏ x : ι, f x = f default
Full source
@[to_additive]
theorem prod_unique [Unique ι] (f : ι → M) : ∏ x : ι, f x = f default := by
  rw [univ_unique, prod_singleton]
Product over Unique Type Equals Function at Default Element
Informal description
For a finite type $\iota$ with a unique element (denoted as `default`), and any function $f : \iota \to M$ where $M$ is a commutative monoid, the product of $f$ over all elements of $\iota$ is equal to $f(\text{default})$, i.e., \[ \prod_{x \in \iota} f(x) = f(\text{default}). \]
Fintype.prod_subsingleton theorem
[Subsingleton ι] (f : ι → M) (a : ι) : ∏ x : ι, f x = f a
Full source
@[to_additive]
theorem prod_subsingleton [Subsingleton ι] (f : ι → M) (a : ι) : ∏ x : ι, f x = f a := by
  have : Unique ι := uniqueOfSubsingleton a
  rw [prod_unique f, Subsingleton.elim default a]
Product over a Subsingleton Type Equals Function at Any Element
Informal description
For a subsingleton type $\iota$ (i.e., any two elements are equal) and any function $f : \iota \to M$ where $M$ is a commutative monoid, the product of $f$ over all elements of $\iota$ is equal to $f(a)$ for any element $a \in \iota$, i.e., \[ \prod_{x \in \iota} f(x) = f(a). \]
Fintype.prod_Prop theorem
(f : Prop → M) : ∏ p, f p = f True * f False
Full source
@[to_additive] theorem prod_Prop (f : Prop → M) : ∏ p, f p = f True * f False := by simp
Product over All Propositions Equals $f(\text{True}) \cdot f(\text{False})$
Informal description
For any function $f : \text{Prop} \to M$ where $M$ is a commutative monoid, the product of $f$ over all propositions is equal to $f(\text{True})$ multiplied by $f(\text{False})$, i.e., \[ \prod_{p \in \text{Prop}} f(p) = f(\text{True}) \cdot f(\text{False}). \]
Fintype.prod_subtype_mul_prod_subtype theorem
(p : ι → Prop) (f : ι → M) [DecidablePred p] : (∏ i : { x // p x }, f i) * ∏ i : { x // ¬p x }, f i = ∏ i, f i
Full source
@[to_additive]
theorem prod_subtype_mul_prod_subtype (p : ι → Prop) (f : ι → M) [DecidablePred p] :
    (∏ i : { x // p x }, f i) * ∏ i : { x // ¬p x }, f i = ∏ i, f i := by
  classical
    let s := { x | p x }.toFinset
    rw [← Finset.prod_subtype s, ← Finset.prod_subtype sᶜ]
    · exact Finset.prod_mul_prod_compl _ _
    · simp [s]
    · simp [s]
Product Decomposition over Subtypes: $\prod_{\{p\}} f \cdot \prod_{\{\neg p\}} f = \prod_{\iota} f$
Informal description
Let $\iota$ be a finite type, $M$ a commutative monoid, and $p : \iota \to \text{Prop}$ a decidable predicate. For any function $f : \iota \to M$, the product of $f$ over the subtype $\{x \mid p(x)\}$ multiplied by the product of $f$ over the subtype $\{x \mid \neg p(x)\}$ equals the product of $f$ over all elements of $\iota$: \[ \left(\prod_{i \in \{x \mid p(x)\}} f(i)\right) \cdot \left(\prod_{i \in \{x \mid \neg p(x)\}} f(i)\right) = \prod_{i \in \iota} f(i). \]
Fintype.prod_subset theorem
{s : Finset ι} {f : ι → M} (h : ∀ i, f i ≠ 1 → i ∈ s) : ∏ i ∈ s, f i = ∏ i, f i
Full source
@[to_additive] lemma prod_subset {s : Finset ι} {f : ι → M} (h : ∀ i, f i ≠ 1i ∈ s) :
    ∏ i ∈ s, f i = ∏ i, f i :=
  Finset.prod_subset s.subset_univ <| by simpa [not_imp_comm (a := _ ∈ s)]
Product Equality for Triviality Outside Subset: $\prod_s f = \prod_\iota f$
Informal description
Let $\iota$ be a finite type and $M$ a commutative monoid. Given a finite subset $s \subseteq \iota$ and a function $f : \iota \to M$, if for every $i \in \iota$ with $f(i) \neq 1$ we have $i \in s$, then the product of $f$ over $s$ equals the product of $f$ over all elements of $\iota$, i.e., \[ \prod_{i \in s} f(i) = \prod_{i \in \iota} f(i). \]
List.prod_toFinset theorem
{M : Type*} [DecidableEq ι] [CommMonoid M] (f : ι → M) : ∀ {l : List ι} (_hl : l.Nodup), l.toFinset.prod f = (l.map f).prod
Full source
@[to_additive]
theorem prod_toFinset {M : Type*} [DecidableEq ι] [CommMonoid M] (f : ι → M) :
    ∀ {l : List ι} (_hl : l.Nodup), l.toFinset.prod f = (l.map f).prod
  | [], _ => by simp
  | a :: l, hl => by
    let ⟨not_mem, hl⟩ := List.nodup_cons.mp hl
    simp [Finset.prod_insert (mt List.mem_toFinset.mp not_mem), prod_toFinset _ hl]
Product over Finite Set from Duplicate-Free List Equals Product of Mapped List
Informal description
Let $M$ be a commutative monoid, $\iota$ a type with decidable equality, and $f : \iota \to M$ a function. For any duplicate-free list $l$ of elements of $\iota$, the product of $f$ over the finite set obtained from $l$ is equal to the product of the list obtained by applying $f$ to each element of $l$. That is, \[ \prod_{x \in l.\mathrm{toFinset}} f(x) = \prod_{y \in l.\mathrm{map}\, f} y. \]
List.sum_toFinset_count_eq_length theorem
[DecidableEq ι] (l : List ι) : ∑ a ∈ l.toFinset, l.count a = l.length
Full source
@[simp]
theorem sum_toFinset_count_eq_length [DecidableEq ι] (l : List ι) :
    ∑ a ∈ l.toFinset, l.count a = l.length := by
  simpa [List.map_const'] using (Finset.sum_list_map_count l fun _ => (1 : )).symm
Sum of Element Counts in List Equals Length
Informal description
For any list $l$ of elements of type $\iota$ (with decidable equality), the sum of the counts of each distinct element in $l$ (over the finite set obtained from $l$ by removing duplicates) equals the length of $l$. In symbols: \[ \sum_{a \in l.\mathrm{toFinset}} l.\mathrm{count}(a) = l.\mathrm{length}. \]
Multiset.mem_sum theorem
{s : Finset ι} {m : ι → Multiset ι} : a ∈ ∑ i ∈ s, m i ↔ ∃ i ∈ s, a ∈ m i
Full source
@[simp]
lemma mem_sum {s : Finset ι} {m : ι → Multiset ι} : a ∈ ∑ i ∈ s, m ia ∈ ∑ i ∈ s, m i ↔ ∃ i ∈ s, a ∈ m i := by
  induction s using Finset.cons_induction <;> simp [*]
Membership in Sum of Multisets over Finite Set
Informal description
For a finite set $s$ of type $\iota$ and a function $m : \iota \to \text{Multiset } \iota$, an element $a$ belongs to the sum of multisets $\sum_{i \in s} m(i)$ if and only if there exists an element $i \in s$ such that $a$ belongs to $m(i)$. In symbols: \[ a \in \sum_{i \in s} m(i) \leftrightarrow \exists i \in s, a \in m(i). \]
Multiset.toFinset_sum_count_eq theorem
(s : Multiset ι) : ∑ a ∈ s.toFinset, s.count a = card s
Full source
theorem toFinset_sum_count_eq (s : Multiset ι) : ∑ a ∈ s.toFinset, s.count a = card s := by
  simpa using (Finset.sum_multiset_map_count s (fun _ => (1 : ))).symm
Sum of Element Counts in Multiset Equals Cardinality
Informal description
For any multiset $s$ over a type $\iota$, the sum of the multiplicities of each distinct element in $s$ (over the finite set obtained by removing duplicates from $s$) equals the cardinality of $s$. In symbols: \[ \sum_{a \in s.\mathrm{toFinset}} s.\mathrm{count}(a) = \mathrm{card}(s). \]
Multiset.sum_count_eq_card theorem
{s : Finset ι} {m : Multiset ι} (hms : ∀ a ∈ m, a ∈ s) : ∑ a ∈ s, m.count a = card m
Full source
@[simp] lemma sum_count_eq_card {s : Finset ι} {m : Multiset ι} (hms : ∀ a ∈ m, a ∈ s) :
    ∑ a ∈ s, m.count a = card m := by
  rw [← toFinset_sum_count_eq, ← Finset.sum_filter_ne_zero]
  congr with a
  simpa using hms a
Sum of Element Counts over Finite Set Equals Multiset Cardinality
Informal description
For any finite set $s$ of type $\iota$ and any multiset $m$ over $\iota$, if every element of $m$ belongs to $s$, then the sum of the multiplicities of each element in $m$ (over the finite set $s$) equals the cardinality of $m$. In symbols: \[ \sum_{a \in s} \mathrm{count}_a(m) = \mathrm{card}(m). \]
Multiset.toFinset_sum_count_nsmul_eq theorem
(s : Multiset ι) : ∑ a ∈ s.toFinset, s.count a • { a } = s
Full source
@[simp]
theorem toFinset_sum_count_nsmul_eq (s : Multiset ι) :
    ∑ a ∈ s.toFinset, s.count a • {a} = s := by
  rw [← Finset.sum_multiset_map_count, Multiset.sum_map_singleton]
Decomposition of Multiset into Weighted Sum of Singletons
Informal description
For any multiset $s$ over a type $\iota$, the sum over the finite set of distinct elements of $s$ of the scalar multiples of their singleton multisets (where each scalar is the count of the element in $s$) equals $s$ itself. In other words, \[ \sum_{a \in \text{toFinset}(s)} (\text{count}_a s) \cdot \{a\} = s. \]
Multiset.exists_smul_of_dvd_count theorem
(s : Multiset ι) {k : ℕ} (h : ∀ a : ι, a ∈ s → k ∣ Multiset.count a s) : ∃ u : Multiset ι, s = k • u
Full source
theorem exists_smul_of_dvd_count (s : Multiset ι) {k : }
    (h : ∀ a : ι, a ∈ sk ∣ Multiset.count a s) : ∃ u : Multiset ι, s = k • u := by
  use ∑ a ∈ s.toFinset, (s.count a / k) • {a}
  have h₂ :
    (∑ x ∈ s.toFinset, k • (count x s / k) • ({x} : Multiset ι)) =
      ∑ x ∈ s.toFinset, count x s • {x} := by
    apply Finset.sum_congr rfl
    intro x hx
    rw [← mul_nsmul', Nat.mul_div_cancel' (h x (mem_toFinset.mp hx))]
  rw [← Finset.sum_nsmul, h₂, toFinset_sum_count_nsmul_eq]
Existence of Scalar Multiple When Counts Are Divisible by $k$ in Multisets
Informal description
For any multiset $s$ over a type $\iota$ and any natural number $k$, if $k$ divides the multiplicity $\text{count}_a s$ of every element $a$ in $s$, then there exists a multiset $u$ over $\iota$ such that $s$ is equal to the scalar multiple $k \cdot u$.
Multiset.prod_sum theorem
{ι : Type*} [CommMonoid M] (f : ι → Multiset M) (s : Finset ι) : (∑ x ∈ s, f x).prod = ∏ x ∈ s, (f x).prod
Full source
@[to_additive]
theorem prod_sum {ι : Type*} [CommMonoid M] (f : ι → Multiset M) (s : Finset ι) :
    (∑ x ∈ s, f x).prod = ∏ x ∈ s, (f x).prod := by
  induction s using Finset.cons_induction with
  | empty => rw [Finset.sum_empty, Finset.prod_empty, Multiset.prod_zero]
  | cons a s has ih => rw [Finset.sum_cons, Finset.prod_cons, Multiset.prod_add, ih]
Product of Sum of Multiset-Valued Functions Equals Product of Individual Multiset Products
Informal description
Let $M$ be a commutative monoid and $\iota$ a type. For any function $f \colon \iota \to \text{Multiset}(M)$ and any finite subset $s \subseteq \iota$, the product of the sum of multisets $\sum_{x \in s} f(x)$ is equal to the product over $s$ of the products of the multisets $f(x)$, i.e., \[ \left(\sum_{x \in s} f(x)\right).\!\prod = \prod_{x \in s} \left(f(x).\!\prod\right). \]
IsUnit.prod_iff theorem
[CommMonoid M] {f : ι → M} : IsUnit (∏ a ∈ s, f a) ↔ ∀ a ∈ s, IsUnit (f a)
Full source
@[to_additive (attr := simp)]
lemma IsUnit.prod_iff [CommMonoid M] {f : ι → M} :
    IsUnitIsUnit (∏ a ∈ s, f a) ↔ ∀ a ∈ s, IsUnit (f a) := by
  induction s using Finset.cons_induction with
  | empty => simp
  | cons a s ha hs => rw [Finset.prod_cons, IsUnit.mul_iff, hs, Finset.forall_mem_cons]
Product is Unit if and only if All Factors are Units in Finite Set
Informal description
Let $M$ be a commutative monoid, $s$ a finite subset of a type $\iota$, and $f : \iota \to M$ a function. The product $\prod_{a \in s} f(a)$ is a unit in $M$ if and only if $f(a)$ is a unit for every $a \in s$.
IsUnit.prod_univ_iff theorem
[Fintype ι] [CommMonoid M] {f : ι → M} : IsUnit (∏ a, f a) ↔ ∀ a, IsUnit (f a)
Full source
@[to_additive]
lemma IsUnit.prod_univ_iff [Fintype ι] [CommMonoid M] {f : ι → M} :
    IsUnitIsUnit (∏ a, f a) ↔ ∀ a, IsUnit (f a) := by simp
Product is Unit if and only if All Factors are Units in Finite Type
Informal description
Let $M$ be a commutative monoid and $\iota$ a finite type. For a function $f \colon \iota \to M$, the product $\prod_{a \in \iota} f(a)$ is a unit in $M$ if and only if $f(a)$ is a unit for every $a \in \iota$.
nat_abs_sum_le theorem
(s : Finset ι) (f : ι → ℤ) : (∑ i ∈ s, f i).natAbs ≤ ∑ i ∈ s, (f i).natAbs
Full source
theorem nat_abs_sum_le (s : Finset ι) (f : ι → ) :
    (∑ i ∈ s, f i).natAbs∑ i ∈ s, (f i).natAbs := by
  induction s using Finset.cons_induction with
  | empty => simp only [Finset.sum_empty, Int.natAbs_zero, le_refl]
  | cons i s his IH =>
    simp only [Finset.sum_cons, not_false_iff]
    exact (Int.natAbs_add_le _ _).trans (Nat.add_le_add_left IH _)
Triangle Inequality for Sums of Integers: $\left|\sum_{i \in s} f(i)\right| \leq \sum_{i \in s} |f(i)|$
Informal description
For any finite set $s$ and any function $f$ from the index type $\iota$ to the integers $\mathbb{Z}$, the natural absolute value of the sum $\sum_{i \in s} f(i)$ is less than or equal to the sum of the natural absolute values $\sum_{i \in s} |f(i)|$.