doc-next-gen

Mathlib.Data.Finsupp.Basic

Module docstring

{"# Miscellaneous definitions, lemmas, and constructions using finsupp

Main declarations

  • Finsupp.graph: the finset of input and output pairs with non-zero outputs.
  • Finsupp.mapRange.equiv: Finsupp.mapRange as an equiv.
  • Finsupp.mapDomain: maps the domain of a Finsupp by a function and by summing.
  • Finsupp.comapDomain: postcomposition of a Finsupp with a function injective on the preimage of its support.
  • Finsupp.some: restrict a finitely supported function on Option α to a finitely supported function on α.
  • Finsupp.filter: filter p f is the finitely supported function that is f a if p a is true and 0 otherwise.
  • Finsupp.frange: the image of a finitely supported function on its support.
  • Finsupp.subtype_domain: the restriction of a finitely supported function f to a subtype.

Implementation notes

This file is a noncomputable theory and uses classical logic throughout.

TODO

  • This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas, so it should be divided into smaller pieces.

  • Expand the list of definitions and important lemmas to the module docstring.

","### Declarations about graph ","### Declarations about mapRange ","### Declarations about equivCongrLeft ","### Declarations about mapDomain ","### Declarations about comapDomain ","### Declarations about finitely supported functions whose support is an Option type ","### Declarations about Finsupp.filter ","### Declarations about frange ","### Declarations about Finsupp.subtypeDomain ","### Declarations about curry and uncurry ","### Declarations about finitely supported functions whose support is a Sum type ","### Declarations about sigma types "}

Finsupp.graph definition
(f : α →₀ M) : Finset (α × M)
Full source
/-- The graph of a finitely supported function over its support, i.e. the finset of input and output
pairs with non-zero outputs. -/
def graph (f : α →₀ M) : Finset (α × M) :=
  f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩
Graph of a finitely supported function
Informal description
For a finitely supported function $f \colon \alpha \to M$, the graph of $f$ is the finite set of pairs $(a, m) \in \alpha \times M$ such that $f(a) = m$ and $m \neq 0$.
Finsupp.mk_mem_graph_iff theorem
{a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0
Full source
theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m)(a, m) ∈ f.graph(a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by
  simp_rw [graph, mem_map, mem_support_iff]
  constructor
  · rintro ⟨b, ha, rfl, -⟩
    exact ⟨rfl, ha⟩
  · rintro ⟨rfl, ha⟩
    exact ⟨a, ha, rfl⟩
Characterization of Membership in the Graph of a Finitely Supported Function
Informal description
For a finitely supported function $f \colon \alpha \to M$, an element $(a, m) \in \alpha \times M$ belongs to the graph of $f$ if and only if $f(a) = m$ and $m \neq 0$.
Finsupp.mem_graph_iff theorem
{c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0
Full source
@[simp]
theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graphc ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by
  cases c
  exact mk_mem_graph_iff
Characterization of Membership in the Graph of a Finitely Supported Function via Pair Components
Informal description
For a finitely supported function $f \colon \alpha \to M$ and a pair $c = (a, m) \in \alpha \times M$, the pair $c$ belongs to the graph of $f$ if and only if $f(a) = m$ and $m \neq 0$.
Finsupp.mk_mem_graph theorem
(f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph
Full source
theorem mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a)(a, f a) ∈ f.graph :=
  mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩
Membership of $(a, f(a))$ in Graph for Supported Elements
Informal description
For any finitely supported function $f \colon \alpha \to M$ and any element $a \in \alpha$ in the support of $f$, the pair $(a, f(a))$ belongs to the graph of $f$.
Finsupp.apply_eq_of_mem_graph theorem
{a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m
Full source
theorem apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m)(a, m) ∈ f.graph) : f a = m :=
  (mem_graph_iff.1 h).1
Function Value at Graph Point in Finitely Supported Functions
Informal description
For a finitely supported function $f \colon \alpha \to M$ and elements $a \in \alpha$, $m \in M$, if the pair $(a, m)$ belongs to the graph of $f$, then $f(a) = m$.
Finsupp.not_mem_graph_snd_zero theorem
(a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph
Full source
@[simp 1100] -- Higher priority shortcut instance for `mem_graph_iff`.
theorem not_mem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M))(a, (0 : M)) ∉ f.graph := fun h =>
  (mem_graph_iff.1 h).2.irrefl
Exclusion of Zero-Output Pairs from Graph of Finitely Supported Function
Informal description
For any finitely supported function $f \colon \alpha \to M$ and any element $a \in \alpha$, the pair $(a, 0)$ does not belong to the graph of $f$.
Finsupp.image_fst_graph theorem
[DecidableEq α] (f : α →₀ M) : f.graph.image Prod.fst = f.support
Full source
@[simp]
theorem image_fst_graph [DecidableEq α] (f : α →₀ M) : f.graph.image Prod.fst = f.support := by
  classical
  simp only [graph, map_eq_image, image_image, Embedding.coeFn_mk, Function.comp_def, image_id']
Projection of Graph Equals Support in Finitely Supported Functions
Informal description
For any finitely supported function $f \colon \alpha \to M$ (where $M$ has a zero element) and with a decidable equality on $\alpha$, the image of the graph of $f$ under the first projection equals the support of $f$. That is, $\text{image}(\text{graph}(f), \pi_1) = \text{support}(f)$, where $\pi_1$ is the projection $(a, m) \mapsto a$.
Finsupp.graph_injective theorem
(α M) [Zero M] : Injective (@graph α M _)
Full source
theorem graph_injective (α M) [Zero M] : Injective (@graph α M _) := by
  intro f g h
  classical
    have hsup : f.support = g.support := by rw [← image_fst_graph, h, image_fst_graph]
    refine ext_iff'.2 ⟨hsup, fun x hx => apply_eq_of_mem_graph <| h.symm ▸ ?_⟩
    exact mk_mem_graph _ (hsup ▸ hx)
Injectivity of Graph Function for Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $M$ with a zero element, the graph function $\text{graph} \colon (\alpha \to_{\text{f}} M) \to \text{Finset}(\alpha \times M)$ is injective. That is, for any two finitely supported functions $f, g \colon \alpha \to M$, if $\text{graph}(f) = \text{graph}(g)$, then $f = g$.
Finsupp.graph_inj theorem
{f g : α →₀ M} : f.graph = g.graph ↔ f = g
Full source
@[simp]
theorem graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g :=
  (graph_injective α M).eq_iff
Graph Equality Characterizes Function Equality for Finitely Supported Functions
Informal description
For any two finitely supported functions $f, g \colon \alpha \to M$, the graphs of $f$ and $g$ are equal if and only if $f = g$. That is, $\text{graph}(f) = \text{graph}(g) \leftrightarrow f = g$.
Finsupp.graph_zero theorem
: graph (0 : α →₀ M) = ∅
Full source
@[simp]
theorem graph_zero : graph (0 : α →₀ M) =  := by simp [graph]
Graph of Zero Function is Empty
Informal description
For the zero function $0 \colon \alpha \to_{\text{f}} M$ in the space of finitely supported functions, its graph is the empty set, i.e., $\text{graph}(0) = \emptyset$.
Finsupp.graph_eq_empty theorem
{f : α →₀ M} : f.graph = ∅ ↔ f = 0
Full source
@[simp]
theorem graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 :=
  (graph_injective α M).eq_iff' graph_zero
Empty Graph Characterization of Zero Function in Finitely Supported Functions
Informal description
For a finitely supported function $f \colon \alpha \to M$, the graph of $f$ is empty if and only if $f$ is the zero function. That is, $\text{graph}(f) = \emptyset \leftrightarrow f = 0$.
Finsupp.mapRange.equiv definition
(f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M) ≃ (α →₀ N)
Full source
/-- `Finsupp.mapRange` as an equiv. -/
@[simps apply]
def mapRange.equiv (f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M) ≃ (α →₀ N) where
  toFun := (mapRange f hf : (α →₀ M) → α →₀ N)
  invFun := (mapRange f.symm hf' : (α →₀ N) → α →₀ M)
  left_inv x := by
    rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.symm_comp_self]
    · exact mapRange_id _
    · rfl
  right_inv x := by
    rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.self_comp_symm]
    · exact mapRange_id _
    · rfl
Equivalence of finitely supported functions via pointwise equivalence of codomains
Informal description
Given an equivalence $f \colon M \simeq N$ between types $M$ and $N$ such that $f(0) = 0$ and $f^{-1}(0) = 0$, the function `Finsupp.mapRange.equiv` constructs an equivalence between the types of finitely supported functions $\alpha \to_{\text{f}} M$ and $\alpha \to_{\text{f}} N$. This equivalence is defined by applying $f$ pointwise to the values of the finitely supported function, and its inverse is similarly defined by applying $f^{-1}$.
Finsupp.mapRange.equiv_refl theorem
: mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M)
Full source
@[simp]
theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M) :=
  Equiv.ext mapRange_id
Identity Equivalence Preserved Under `mapRange.equiv`
Informal description
The equivalence `mapRange.equiv` applied to the identity equivalence $\mathrm{id} \colon M \simeq M$ (with $\mathrm{id}(0) = 0$ and $\mathrm{id}^{-1}(0) = 0$) is equal to the identity equivalence on the type of finitely supported functions $\alpha \to_{\text{f}} M$.
Finsupp.mapRange.equiv_trans theorem
(f : M ≃ N) (hf : f 0 = 0) (hf') (f₂ : N ≃ P) (hf₂ : f₂ 0 = 0) (hf₂') : (mapRange.equiv (f.trans f₂) (by rw [Equiv.trans_apply, hf, hf₂]) (by rw [Equiv.symm_trans_apply, hf₂', hf']) : (α →₀ _) ≃ _) = (mapRange.equiv f hf hf').trans (mapRange.equiv f₂ hf₂ hf₂')
Full source
theorem mapRange.equiv_trans (f : M ≃ N) (hf : f 0 = 0) (hf') (f₂ : N ≃ P) (hf₂ : f₂ 0 = 0) (hf₂') :
    (mapRange.equiv (f.trans f₂) (by rw [Equiv.trans_apply, hf, hf₂])
          (by rw [Equiv.symm_trans_apply, hf₂', hf']) :
        (α →₀ _) ≃ _) =
      (mapRange.equiv f hf hf').trans (mapRange.equiv f₂ hf₂ hf₂') :=
  Equiv.ext <| mapRange_comp f₂ hf₂ f hf ((congrArg f₂ hf).trans hf₂)
Transitivity of Pointwise Equivalence on Finitely Supported Functions
Informal description
Let $f \colon M \simeq N$ and $f₂ \colon N \simeq P$ be equivalences between types $M$, $N$, and $P$ such that $f(0) = 0$, $f^{-1}(0) = 0$, $f₂(0) = 0$, and $f₂^{-1}(0) = 0$. Then the equivalence of finitely supported functions $\alpha \to_{\text{f}} M \simeq \alpha \to_{\text{f}} P$ obtained by composing $f$ and $f₂$ pointwise is equal to the composition of the equivalences $\alpha \to_{\text{f}} M \simeq \alpha \to_{\text{f}} N$ and $\alpha \to_{\text{f}} N \simeq \alpha \to_{\text{f}} P$ induced by $f$ and $f₂$ respectively.
Finsupp.mapRange.equiv_symm theorem
(f : M ≃ N) (hf hf') : ((mapRange.equiv f hf hf').symm : (α →₀ _) ≃ _) = mapRange.equiv f.symm hf' hf
Full source
@[simp]
theorem mapRange.equiv_symm (f : M ≃ N) (hf hf') :
    ((mapRange.equiv f hf hf').symm : (α →₀ _) ≃ _) = mapRange.equiv f.symm hf' hf :=
  Equiv.ext fun _ => rfl
Inverse of Pointwise Equivalence on Finitely Supported Functions
Informal description
Given an equivalence $f \colon M \simeq N$ between types $M$ and $N$ such that $f(0) = 0$ and $f^{-1}(0) = 0$, the inverse of the equivalence $\alpha \to_{\text{f}} M \simeq \alpha \to_{\text{f}} N$ (induced by applying $f$ pointwise) is equal to the equivalence $\alpha \to_{\text{f}} N \simeq \alpha \to_{\text{f}} M$ induced by applying $f^{-1}$ pointwise.
Finsupp.mapRange.zeroHom definition
(f : ZeroHom M N) : ZeroHom (α →₀ M) (α →₀ N)
Full source
/-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism
on functions. -/
@[simps]
def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (α →₀ M) (α →₀ N) where
  toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
  map_zero' := mapRange_zero
Zero-preserving homomorphism on finitely supported functions
Informal description
Given a zero-preserving homomorphism $f \colon M \to N$ (i.e., $f(0) = 0$), the function `Finsupp.mapRange.zeroHom` constructs a zero-preserving homomorphism from the type of finitely supported functions $\alpha \to_{\text{f}} M$ to the type of finitely supported functions $\alpha \to_{\text{f}} N$. This is done by applying $f$ pointwise to the values of the input finitely supported function.
Finsupp.mapRange.zeroHom_id theorem
: mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M)
Full source
@[simp]
theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M) :=
  ZeroHom.ext mapRange_id
Identity Zero-Homomorphism Preserved Under `mapRange`
Informal description
The zero-preserving homomorphism induced by the identity zero-homomorphism on $M$ is equal to the identity zero-homomorphism on the type of finitely supported functions $\alpha \to_{\text{f}} M$.
Finsupp.mapRange.zeroHom_comp theorem
(f : ZeroHom N P) (f₂ : ZeroHom M N) : (mapRange.zeroHom (f.comp f₂) : ZeroHom (α →₀ _) _) = (mapRange.zeroHom f).comp (mapRange.zeroHom f₂)
Full source
theorem mapRange.zeroHom_comp (f : ZeroHom N P) (f₂ : ZeroHom M N) :
    (mapRange.zeroHom (f.comp f₂) : ZeroHom (α →₀ _) _) =
      (mapRange.zeroHom f).comp (mapRange.zeroHom f₂) :=
  ZeroHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
Composition of Zero-Preserving Homomorphisms on Finitely Supported Functions
Informal description
Let $f \colon N \to P$ and $f₂ \colon M \to N$ be zero-preserving homomorphisms. Then the composition of the induced homomorphisms on finitely supported functions satisfies: $$ \text{mapRange.zeroHom}(f \circ f₂) = \text{mapRange.zeroHom}(f) \circ \text{mapRange.zeroHom}(f₂). $$
Finsupp.mapRange.addMonoidHom definition
(f : M →+ N) : (α →₀ M) →+ α →₀ N
Full source
/-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
@[simps]
def mapRange.addMonoidHom (f : M →+ N) : (α →₀ M) →+ α →₀ N where
  toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
  map_zero' := mapRange_zero
  -- Porting note: need either `dsimp only` or to specify `hf`:
  -- see also: https://github.com/leanprover-community/mathlib4/issues/12129
  map_add' := mapRange_add (hf := f.map_zero) f.map_add
Additive monoid homomorphism on finitely supported functions via range mapping
Informal description
Given an additive monoid homomorphism $f \colon M \to N$, the function `Finsupp.mapRange.addMonoidHom` maps a finitely supported function $g \colon \alpha \to_{\text{f}} M$ to the finitely supported function $f \circ g \colon \alpha \to_{\text{f}} N$. This operation preserves the additive structure, meaning it respects addition and maps the zero function to the zero function.
Finsupp.mapRange.addMonoidHom_id theorem
: mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M)
Full source
@[simp]
theorem mapRange.addMonoidHom_id :
    mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M) :=
  AddMonoidHom.ext mapRange_id
Identity Mapping Preserves Additive Structure on Finitely Supported Functions
Informal description
The additive monoid homomorphism induced by the identity homomorphism on $M$ is equal to the identity homomorphism on the type of finitely supported functions $\alpha \to_{\text{f}} M$. In other words, $\operatorname{mapRange.addMonoidHom}(\mathrm{id}_M) = \mathrm{id}_{\alpha \to_{\text{f}} M}$.
Finsupp.mapRange.addMonoidHom_comp theorem
(f : N →+ P) (f₂ : M →+ N) : (mapRange.addMonoidHom (f.comp f₂) : (α →₀ _) →+ _) = (mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂)
Full source
theorem mapRange.addMonoidHom_comp (f : N →+ P) (f₂ : M →+ N) :
    (mapRange.addMonoidHom (f.comp f₂) : (α →₀ _) →+ _) =
      (mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂) :=
  AddMonoidHom.ext <|
    mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
Composition of Additive Monoid Homomorphisms on Finitely Supported Functions
Informal description
Let $f \colon N \to P$ and $f_2 \colon M \to N$ be additive monoid homomorphisms. Then the additive monoid homomorphism obtained by first applying $f_2$ and then $f$ to finitely supported functions $\alpha \to_{\text{f}} M$ is equal to the composition of the corresponding homomorphisms on finitely supported functions. That is, $$ \operatorname{mapRange.addMonoidHom}(f \circ f_2) = \operatorname{mapRange.addMonoidHom}(f) \circ \operatorname{mapRange.addMonoidHom}(f_2). $$
Finsupp.mapRange.addMonoidHom_toZeroHom theorem
(f : M →+ N) : (mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _)
Full source
@[simp]
theorem mapRange.addMonoidHom_toZeroHom (f : M →+ N) :
    (mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _) :=
  ZeroHom.ext fun _ => rfl
Equality of Zero-Preserving Homomorphisms Induced by Additive Monoid Homomorphism on Finitely Supported Functions
Informal description
For any additive monoid homomorphism $f \colon M \to N$, the zero-preserving homomorphism induced by `Finsupp.mapRange.addMonoidHom f` is equal to the zero-preserving homomorphism obtained by first converting $f$ to a zero-preserving homomorphism and then applying `Finsupp.mapRange.zeroHom`.
Finsupp.mapRange_multiset_sum theorem
(f : F) (m : Multiset (α →₀ M)) : mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum
Full source
theorem mapRange_multiset_sum (f : F) (m : Multiset (α →₀ M)) :
    mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum :=
  (mapRange.addMonoidHom (f : M →+ N) : (α →₀ _) →+ _).map_multiset_sum _
Sum of Multiset of Finitely Supported Functions Commutes with Zero-Preserving Map
Informal description
Let $M$ and $N$ be types with zero elements, and let $f : M \to N$ be a function that preserves zero (i.e., $f(0) = 0$). For any multiset $m$ of finitely supported functions from $\alpha$ to $M$, the image under $f$ of the sum of $m$ equals the sum of the multiset obtained by applying $f$ pointwise to each function in $m$. In other words, \[ f\left(\sum_{g \in m} g\right) = \sum_{g \in m} (f \circ g). \]
Finsupp.mapRange_finset_sum theorem
(f : F) (s : Finset ι) (g : ι → α →₀ M) : mapRange f (map_zero f) (∑ x ∈ s, g x) = ∑ x ∈ s, mapRange f (map_zero f) (g x)
Full source
theorem mapRange_finset_sum (f : F) (s : Finset ι) (g : ι → α →₀ M) :
    mapRange f (map_zero f) (∑ x ∈ s, g x) = ∑ x ∈ s, mapRange f (map_zero f) (g x) :=
  map_sum (mapRange.addMonoidHom (f : M →+ N)) _ _
Summation Commutes with Composition of Finitely Supported Functions
Informal description
Let $f \colon M \to N$ be a zero-preserving function (i.e., $f(0) = 0$) and let $s$ be a finite set of indices. For any family of finitely supported functions $g_x \colon \alpha \to_{\text{f}} M$ indexed by $x \in s$, the composition of $f$ with the sum of the $g_x$ equals the sum of the compositions of $f$ with each $g_x$. In other words, \[ f \circ \left( \sum_{x \in s} g_x \right) = \sum_{x \in s} (f \circ g_x). \]
Finsupp.mapRange.addEquiv definition
(f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N)
Full source
/-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/
@[simps apply]
def mapRange.addEquiv (f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N) :=
  { mapRange.addMonoidHom f.toAddMonoidHom with
    toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
    invFun := (mapRange f.symm f.symm.map_zero : (α →₀ N) → α →₀ M)
    left_inv := fun x => by
      rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.symm_comp_self]
      · exact mapRange_id _
      · rfl
    right_inv := fun x => by
      rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.self_comp_symm]
      · exact mapRange_id _
      · rfl }
Additive equivalence of finitely supported functions via range mapping
Informal description
Given an additive equivalence \( f : M \simeq N \) between two types \( M \) and \( N \), the function `Finsupp.mapRange.addEquiv` constructs an additive equivalence between the types of finitely supported functions \( \alpha \to_{\text{f}} M \) and \( \alpha \to_{\text{f}} N \). This equivalence maps a finitely supported function \( g : \alpha \to_{\text{f}} M \) to \( f \circ g : \alpha \to_{\text{f}} N \), and its inverse maps \( h : \alpha \to_{\text{f}} N \) to \( f^{-1} \circ h : \alpha \to_{\text{f}} M \). The construction preserves the additive structure, ensuring that sums and zero functions are appropriately mapped.
Finsupp.mapRange.addEquiv_refl theorem
: mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M)
Full source
@[simp]
theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M) :=
  AddEquiv.ext mapRange_id
Identity Range Mapping Yields Identity Additive Equivalence on Finitely Supported Functions
Informal description
The additive equivalence obtained by mapping the range of finitely supported functions using the identity additive equivalence on $M$ is equal to the identity additive equivalence on the type of finitely supported functions $\alpha \to_{\text{f}} M$.
Finsupp.mapRange.addEquiv_trans theorem
(f : M ≃+ N) (f₂ : N ≃+ P) : (mapRange.addEquiv (f.trans f₂) : (α →₀ M) ≃+ (α →₀ P)) = (mapRange.addEquiv f).trans (mapRange.addEquiv f₂)
Full source
theorem mapRange.addEquiv_trans (f : M ≃+ N) (f₂ : N ≃+ P) :
    (mapRange.addEquiv (f.trans f₂) : (α →₀ M) ≃+ (α →₀ P)) =
      (mapRange.addEquiv f).trans (mapRange.addEquiv f₂) :=
  AddEquiv.ext (mapRange_comp _ f₂.map_zero _ f.map_zero (by simp))
Composition of Additive Equivalences on Finitely Supported Functions
Informal description
Given additive equivalences $f \colon M \simeq N$ and $f₂ \colon N \simeq P$, the composition of the induced additive equivalences on finitely supported functions satisfies $$ \text{mapRange.addEquiv}(f \circ f₂) = \text{mapRange.addEquiv}(f) \circ \text{mapRange.addEquiv}(f₂). $$
Finsupp.mapRange.addEquiv_symm theorem
(f : M ≃+ N) : ((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm
Full source
@[simp]
theorem mapRange.addEquiv_symm (f : M ≃+ N) :
    ((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm :=
  AddEquiv.ext fun _ => rfl
Inverse of Range-Mapped Additive Equivalence of Finitely Supported Functions
Informal description
Given an additive equivalence $f \colon M \simeq N$ between types $M$ and $N$, the inverse of the additive equivalence $\text{mapRange.addEquiv}\, f \colon (\alpha \to_{\text{f}} M) \simeq (\alpha \to_{\text{f}} N)$ is equal to the additive equivalence $\text{mapRange.addEquiv}\, f^{-1} \colon (\alpha \to_{\text{f}} N) \simeq (\alpha \to_{\text{f}} M)$.
Finsupp.mapRange.addEquiv_toAddMonoidHom theorem
(f : M ≃+ N) : ((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) = (mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _)
Full source
@[simp]
theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) :
    ((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) =
      (mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _) :=
  AddMonoidHom.ext fun _ => rfl
Underlying Homomorphism of `mapRange.addEquiv` Equals `mapRange.addMonoidHom`
Informal description
Given an additive equivalence $f \colon M \simeq N$, the underlying additive monoid homomorphism of the additive equivalence $\text{mapRange.addEquiv}\, f \colon (\alpha \to_{\text{f}} M) \simeq (\alpha \to_{\text{f}} N)$ is equal to the additive monoid homomorphism $\text{mapRange.addMonoidHom}\, f \colon (\alpha \to_{\text{f}} M) \to (\alpha \to_{\text{f}} N)$, where $f$ is viewed as an additive monoid homomorphism via its $\text{toAddMonoidHom}$ method.
Finsupp.mapRange.addEquiv_toEquiv theorem
(f : M ≃+ N) : ↑(mapRange.addEquiv f : (α →₀ _) ≃+ _) = (mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (α →₀ _) ≃ _)
Full source
@[simp]
theorem mapRange.addEquiv_toEquiv (f : M ≃+ N) :
    ↑(mapRange.addEquiv f : (α →₀ _) ≃+ _) =
      (mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (α →₀ _) ≃ _) :=
  Equiv.ext fun _ => rfl
Underlying Equivalence of `mapRange.addEquiv` Equals `mapRange.equiv`
Informal description
Let $f \colon M \simeq N$ be an additive equivalence between types $M$ and $N$. The underlying equivalence of the additive equivalence $\text{mapRange.addEquiv}\, f \colon (\alpha \to_{\text{f}} M) \simeq (\alpha \to_{\text{f}} N)$ is equal to the equivalence $\text{mapRange.equiv}\, f \colon (\alpha \to_{\text{f}} M) \simeq (\alpha \to_{\text{f}} N)$, where $f$ is viewed as a plain equivalence (with $f(0) = 0$ and $f^{-1}(0) = 0$).
Finsupp.equivMapDomain definition
(f : α ≃ β) (l : α →₀ M) : β →₀ M
Full source
/-- Given `f : α ≃ β`, we can map `l : α →₀ M` to `equivMapDomain f l : β →₀ M` (computably)
by mapping the support forwards and the function backwards. -/
def equivMapDomain (f : α ≃ β) (l : α →₀ M) : β →₀ M where
  support := l.support.map f.toEmbedding
  toFun a := l (f.symm a)
  mem_support_toFun a := by simp only [Finset.mem_map_equiv, mem_support_toFun]; rfl
Domain remapping of finitely supported functions via an equivalence
Informal description
Given an equivalence $f : \alpha \simeq \beta$ and a finitely supported function $l : \alpha \to₀ M$, the function `equivMapDomain f l` maps the domain of $l$ from $\alpha$ to $\beta$ via $f$, resulting in a finitely supported function $\beta \to₀ M$. Specifically, for any $b \in \beta$, the value of `equivMapDomain f l` at $b$ is equal to $l(f^{-1}(b))$. The support of the resulting function is the image of the support of $l$ under $f$.
Finsupp.equivMapDomain_apply theorem
(f : α ≃ β) (l : α →₀ M) (b : β) : equivMapDomain f l b = l (f.symm b)
Full source
@[simp]
theorem equivMapDomain_apply (f : α ≃ β) (l : α →₀ M) (b : β) :
    equivMapDomain f l b = l (f.symm b) :=
  rfl
Evaluation of Domain-Remapped Finitely Supported Function via Equivalence
Informal description
Given an equivalence $f : \alpha \simeq \beta$, a finitely supported function $l : \alpha \to_{\text{fin}} M$, and an element $b \in \beta$, the value of the remapped function $\text{equivMapDomain}(f, l)$ at $b$ is equal to $l(f^{-1}(b))$.
Finsupp.equivMapDomain_symm_apply theorem
(f : α ≃ β) (l : β →₀ M) (a : α) : equivMapDomain f.symm l a = l (f a)
Full source
theorem equivMapDomain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) :
    equivMapDomain f.symm l a = l (f a) :=
  rfl
Evaluation of Inverse-Domain-Remapped Finitely Supported Function via Equivalence
Informal description
Given an equivalence $f : \alpha \simeq \beta$, a finitely supported function $l : \beta \to_{\text{fin}} M$, and an element $a \in \alpha$, the value of the remapped function $\text{equivMapDomain}(f^{-1}, l)$ at $a$ is equal to $l(f(a))$.
Finsupp.equivMapDomain_refl theorem
(l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l
Full source
@[simp]
theorem equivMapDomain_refl (l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl
Identity Equivalence Preserves Finitely Supported Function under Domain Remapping
Informal description
For any finitely supported function $l \colon \alpha \to_{\text{fin}} M$, the domain remapping of $l$ via the identity equivalence $\text{Equiv.refl}(\alpha)$ is equal to $l$ itself, i.e., $\text{equivMapDomain}(\text{Equiv.refl}(\alpha), l) = l$.
Finsupp.equivMapDomain_refl' theorem
: equivMapDomain (Equiv.refl _) = @id (α →₀ M)
Full source
theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (α →₀ M) := by ext x; rfl
Identity Equivalence Preserves Finitely Supported Functions
Informal description
The domain remapping of a finitely supported function via the identity equivalence is equal to the identity function on the type of finitely supported functions. That is, for any type $\alpha$ and any type $M$ with a zero element, we have $\text{equivMapDomain}(\text{Equiv.refl}(\alpha)) = \text{id}$ as functions from $\alpha \to_{\text{fin}} M$ to itself.
Finsupp.equivMapDomain_trans theorem
(f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) : equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l)
Full source
theorem equivMapDomain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) :
    equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl
Composition of Domain Remappings for Finitely Supported Functions
Informal description
For any equivalences $f \colon \alpha \simeq \beta$ and $g \colon \beta \simeq \gamma$, and any finitely supported function $l \colon \alpha \to₀ M$, the domain remapping of $l$ via the composition $f \circ g$ is equal to the domain remapping of $l$ via $f$ followed by the domain remapping via $g$. In other words, \[ \text{equivMapDomain}(f \circ g, l) = \text{equivMapDomain}(g, \text{equivMapDomain}(f, l)). \]
Finsupp.equivMapDomain_trans' theorem
(f : α ≃ β) (g : β ≃ γ) : @equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f
Full source
theorem equivMapDomain_trans' (f : α ≃ β) (g : β ≃ γ) :
    @equivMapDomain _ _ M _ (f.trans g) = equivMapDomainequivMapDomain g ∘ equivMapDomain f := by ext x; rfl
Composition of Domain Remappings for Finitely Supported Functions
Informal description
For any equivalences $f \colon \alpha \simeq \beta$ and $g \colon \beta \simeq \gamma$, the composition of domain remappings via $f$ and $g$ is equal to the domain remapping via the composition $f \circ g$. That is, for any finitely supported function $l \colon \alpha \to₀ M$, we have \[ \text{equivMapDomain}(g \circ f, l) = \text{equivMapDomain}(g, \text{equivMapDomain}(f, l)). \]
Finsupp.equivMapDomain_single theorem
(f : α ≃ β) (a : α) (b : M) : equivMapDomain f (single a b) = single (f a) b
Full source
@[simp]
theorem equivMapDomain_single (f : α ≃ β) (a : α) (b : M) :
    equivMapDomain f (single a b) = single (f a) b := by
  classical
    ext x
    simp only [single_apply, Equiv.apply_eq_iff_eq_symm_apply, equivMapDomain_apply]
Domain Remapping Preserves Single Functions: $\text{equivMapDomain } f \, (\text{single } a \, b) = \text{single } (f(a)) \, b$
Informal description
Given an equivalence $f \colon \alpha \simeq \beta$, an element $a \in \alpha$, and an element $b \in M$, the domain remapping of the finitely supported function $\text{single } a \, b$ (which is the function that maps $a$ to $b$ and all other elements to zero) via $f$ is equal to the finitely supported function $\text{single } (f(a)) \, b$ (which maps $f(a)$ to $b$ and all other elements to zero). In other words, $\text{equivMapDomain } f \, (\text{single } a \, b) = \text{single } (f(a)) \, b$.
Finsupp.equivMapDomain_zero theorem
{f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M)
Full source
@[simp]
theorem equivMapDomain_zero {f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M) := by
  ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply]
Domain Remapping Preserves Zero Function: $\text{equivMapDomain } f \, 0 = 0$
Informal description
For any equivalence $f \colon \alpha \simeq \beta$, the domain remapping of the zero function in $\alpha \to₀ M$ via $f$ is equal to the zero function in $\beta \to₀ M$. That is, $\text{equivMapDomain } f \, 0 = 0$.
Finsupp.prod_equivMapDomain theorem
[CommMonoid N] (f : α ≃ β) (l : α →₀ M) (g : β → M → N) : prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m)
Full source
@[to_additive (attr := simp)]
theorem prod_equivMapDomain [CommMonoid N] (f : α ≃ β) (l : α →₀ M) (g : β → M → N) :
    prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m) := by
  simp [prod, equivMapDomain]
Product Preservation under Domain Remapping of Finitely Supported Functions
Informal description
Let $N$ be a commutative monoid, $f : \alpha \simeq \beta$ be an equivalence between types $\alpha$ and $\beta$, $l : \alpha \to₀ M$ be a finitely supported function, and $g : \beta \to M \to N$ be a function. Then the product $\prod_{b \in \beta} g(b, (\text{equivMapDomain } f \, l)(b))$ is equal to $\prod_{a \in \alpha} g(f(a), l(a))$.
Finsupp.equivCongrLeft definition
(f : α ≃ β) : (α →₀ M) ≃ (β →₀ M)
Full source
/-- Given `f : α ≃ β`, the finitely supported function spaces are also in bijection:
`(α →₀ M) ≃ (β →₀ M)`.

This is the finitely-supported version of `Equiv.piCongrLeft`. -/
def equivCongrLeft (f : α ≃ β) : (α →₀ M) ≃ (β →₀ M) := by
  refine ⟨equivMapDomain f, equivMapDomain f.symm, fun f => ?_, fun f => ?_⟩ <;> ext x <;>
    simp only [equivMapDomain_apply, Equiv.symm_symm, Equiv.symm_apply_apply,
      Equiv.apply_symm_apply]
Equivalence of finitely supported function spaces via domain equivalence
Informal description
Given an equivalence $f : \alpha \simeq \beta$, the function spaces of finitely supported functions $\alpha \to₀ M$ and $\beta \to₀ M$ are in bijection. This is the finitely supported version of `Equiv.piCongrLeft`. The bijection is constructed by mapping a finitely supported function $l : \alpha \to₀ M$ to the function $\beta \to₀ M$ defined by $b \mapsto l(f^{-1}(b))$, and vice versa via $f^{-1}$.
Finsupp.equivCongrLeft_apply theorem
(f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l
Full source
@[simp]
theorem equivCongrLeft_apply (f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l :=
  rfl
Equality of Equivalence Application and Domain Remapping for Finitely Supported Functions
Informal description
Given an equivalence $f : \alpha \simeq \beta$ and a finitely supported function $l : \alpha \to₀ M$, the application of the equivalence $\text{equivCongrLeft } f$ to $l$ is equal to the domain remapping $\text{equivMapDomain } f \ l$.
Finsupp.equivCongrLeft_symm theorem
(f : α ≃ β) : (@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm
Full source
@[simp]
theorem equivCongrLeft_symm (f : α ≃ β) :
    (@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm :=
  rfl
Inverse of Equivalence-Induced Bijection on Finitely Supported Function Spaces
Informal description
Given an equivalence $f : \alpha \simeq \beta$, the inverse of the bijection between finitely supported function spaces $\alpha \to₀ M$ and $\beta \to₀ M$ induced by $f$ is equal to the bijection induced by the inverse equivalence $f^{-1} : \beta \simeq \alpha$.
Nat.cast_finsuppProd theorem
[CommSemiring R] (g : α → M → ℕ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b)
Full source
@[simp, norm_cast]
theorem cast_finsuppProd [CommSemiring R] (g : α → M → ) :
    (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
  Nat.cast_prod _ _
Natural Number Cast of Finitely Supported Product
Informal description
Let $R$ be a commutative semiring, and let $f : \alpha \to₀ M$ be a finitely supported function. For any function $g : \alpha \to M \to \mathbb{N}$, the natural number cast of the product $\prod_{a \in \alpha} g(a, f(a))^{f(a)}$ in $R$ is equal to the product $\prod_{a \in \alpha} (g(a, f(a))^{f(a)}$ cast as an element of $R$.
Nat.cast_finsupp_sum theorem
[AddCommMonoidWithOne R] (g : α → M → ℕ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b)
Full source
@[simp, norm_cast]
theorem cast_finsupp_sum [AddCommMonoidWithOne R] (g : α → M → ) :
    (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
  Nat.cast_sum _ _
Natural Number Cast of Finitely Supported Sum
Informal description
Let $R$ be an additive commutative monoid with one, and let $f : \alpha \to₀ M$ be a finitely supported function. For any function $g : \alpha \to M \to \mathbb{N}$, the natural number cast of the sum $\sum_{a \in \alpha} f(a) \cdot g(a, f(a))$ in $R$ is equal to the sum $\sum_{a \in \alpha} f(a) \cdot (g(a, f(a))$ cast as an element of $R$.
Int.cast_finsuppProd theorem
[CommRing R] (g : α → M → ℤ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b)
Full source
@[simp, norm_cast]
theorem cast_finsuppProd [CommRing R] (g : α → M → ) :
    (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
  Int.cast_prod _ _
Integer Cast of Finitely Supported Product
Informal description
Let $R$ be a commutative ring, and let $f : \alpha \to₀ M$ be a finitely supported function. For any function $g : \alpha \to M \to \mathbb{Z}$, the integer cast of the product $\prod_{a \in \alpha} g(a, f(a))^{f(a)}$ in $R$ is equal to the product $\prod_{a \in \alpha} (g(a, f(a))^{f(a)}$ cast as an element of $R$.
Int.cast_finsupp_sum theorem
[AddCommGroupWithOne R] (g : α → M → ℤ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b)
Full source
@[simp, norm_cast]
theorem cast_finsupp_sum [AddCommGroupWithOne R] (g : α → M → ) :
    (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
  Int.cast_sum _ _
Integer Cast Preserves Sum of Finitely Supported Function Values
Informal description
Let $R$ be an additive commutative group with one, and let $f : \alpha \to₀ M$ be a finitely supported function. For any function $g : \alpha \to M \to \mathbb{Z}$, the integer cast of the sum $\sum_{a \in \alpha} f(a) \cdot g(a, f(a))$ in $R$ is equal to the sum $\sum_{a \in \alpha} f(a) \cdot (g(a, f(a))$ cast as an element of $R$.
Rat.cast_finsupp_sum theorem
[DivisionRing R] [CharZero R] (g : α → M → ℚ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b)
Full source
@[simp, norm_cast]
theorem cast_finsupp_sum [DivisionRing R] [CharZero R] (g : α → M → ℚ) :
    (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
  cast_sum _ _
Canonical Embedding Preserves Sum of Finitely Supported Function Values
Informal description
Let $R$ be a division ring of characteristic zero, and let $f : \alpha \to₀ M$ be a finitely supported function from $\alpha$ to $M$. For any function $g : \alpha \to M \to \mathbb{Q}$, the canonical embedding of the rational sum $\sum_{a \in \alpha} g(a, f(a))$ into $R$ equals the sum $\sum_{a \in \alpha} \text{can}(g(a, f(a)))$, where $\text{can} : \mathbb{Q} \to R$ is the canonical embedding of the rationals into $R$.
Rat.cast_finsuppProd theorem
[Field R] [CharZero R] (g : α → M → ℚ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b)
Full source
@[simp, norm_cast]
theorem cast_finsuppProd [Field R] [CharZero R] (g : α → M → ℚ) :
    (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
  cast_prod _ _
Canonical Embedding Preserves Product of Finitely Supported Function Values
Informal description
Let $R$ be a field of characteristic zero, and let $f : \alpha \to₀ M$ be a finitely supported function from $\alpha$ to $M$. For any function $g : \alpha \to M \to \mathbb{Q}$, the canonical map from the rationals to $R$ applied to the product $\prod_{a \in \alpha} g(a, f(a))$ equals the product $\prod_{a \in \alpha} \text{can}(g(a, f(a)))$, where $\text{can} : \mathbb{Q} \to R$ is the canonical embedding of the rationals into $R$.
Finsupp.mapDomain definition
(f : α → β) (v : α →₀ M) : β →₀ M
Full source
/-- Given `f : α → β` and `v : α →₀ M`, `mapDomain f v : β →₀ M`
  is the finitely supported function whose value at `a : β` is the sum
  of `v x` over all `x` such that `f x = a`. -/
def mapDomain (f : α → β) (v : α →₀ M) : β →₀ M :=
  v.sum fun a => single (f a)
Image of a finitely supported function under domain mapping
Informal description
Given a function $f : \alpha \to \beta$ and a finitely supported function $v : \alpha \to_{\text{f}} M$, the function `mapDomain f v` is the finitely supported function from $\beta$ to $M$ whose value at any $b \in \beta$ is the sum of $v(a)$ over all $a \in \alpha$ such that $f(a) = b$.
Finsupp.mapDomain_apply theorem
{f : α → β} (hf : Function.Injective f) (x : α →₀ M) (a : α) : mapDomain f x (f a) = x a
Full source
theorem mapDomain_apply {f : α → β} (hf : Function.Injective f) (x : α →₀ M) (a : α) :
    mapDomain f x (f a) = x a := by
  rw [mapDomain, sum_apply, sum_eq_single a, single_eq_same]
  · intro b _ hba
    exact single_eq_of_ne (hf.ne hba)
  · intro _
    rw [single_zero, coe_zero, Pi.zero_apply]
Image of Finitely Supported Function under Injective Domain Mapping Preserves Values
Informal description
Let $f : \alpha \to \beta$ be an injective function, and let $x : \alpha \to_{\text{f}} M$ be a finitely supported function. For any $a \in \alpha$, the value of the mapped function $\text{mapDomain}\,f\,x$ at $f(a)$ is equal to $x(a)$, i.e., $(\text{mapDomain}\,f\,x)(f(a)) = x(a)$.
Finsupp.mapDomain_notin_range theorem
{f : α → β} (x : α →₀ M) (a : β) (h : a ∉ Set.range f) : mapDomain f x a = 0
Full source
theorem mapDomain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ Set.range f) :
    mapDomain f x a = 0 := by
  rw [mapDomain, sum_apply, sum]
  exact Finset.sum_eq_zero fun a' _ => single_eq_of_ne fun eq => h <| eq ▸ Set.mem_range_self _
Vanishing of Mapped Finitely Supported Function Outside Range
Informal description
Let $f : \alpha \to \beta$ be a function and $x : \alpha \to_{\text{f}} M$ be a finitely supported function. For any $a \in \beta$ not in the range of $f$, the value of the mapped function $\text{mapDomain}\, f\, x$ at $a$ is zero, i.e., $(\text{mapDomain}\, f\, x)(a) = 0$.
Finsupp.mapDomain_id theorem
: mapDomain id v = v
Full source
@[simp]
theorem mapDomain_id : mapDomain id v = v :=
  sum_single _
Identity Mapping Preserves Finitely Supported Function
Informal description
For any finitely supported function $v : \alpha \to_{\text{f}} M$, the mapping of its domain by the identity function is equal to $v$ itself, i.e., $\text{mapDomain}(\text{id}, v) = v$.
Finsupp.mapDomain_comp theorem
{f : α → β} {g : β → γ} : mapDomain (g ∘ f) v = mapDomain g (mapDomain f v)
Full source
theorem mapDomain_comp {f : α → β} {g : β → γ} :
    mapDomain (g ∘ f) v = mapDomain g (mapDomain f v) := by
  refine ((sum_sum_index ?_ ?_).trans ?_).symm
  · intro
    exact single_zero _
  · intro
    exact single_add _
  refine sum_congr fun _ _ => sum_single_index ?_
  exact single_zero _
Composition Law for Domain Mapping of Finitely Supported Functions
Informal description
For any functions $f \colon \alpha \to \beta$ and $g \colon \beta \to \gamma$, and any finitely supported function $v \colon \alpha \to_{\text{f}} M$, the composition of domain mappings satisfies: \[ \text{mapDomain}\, (g \circ f)\, v = \text{mapDomain}\, g\, (\text{mapDomain}\, f\, v). \]
Finsupp.mapDomain_single theorem
{f : α → β} {a : α} {b : M} : mapDomain f (single a b) = single (f a) b
Full source
@[simp]
theorem mapDomain_single {f : α → β} {a : α} {b : M} : mapDomain f (single a b) = single (f a) b :=
  sum_single_index <| single_zero _
Image of a Single Finitely Supported Function under Domain Mapping
Informal description
For any function $f \colon \alpha \to \beta$ and any elements $a \in \alpha$ and $b \in M$, the image of the finitely supported function $\text{single}(a, b)$ under the domain mapping $f$ is equal to the finitely supported function $\text{single}(f(a), b)$. That is, \[ \text{mapDomain}\, f\, (\text{single}\, a\, b) = \text{single}\, (f\, a)\, b. \]
Finsupp.mapDomain_zero theorem
{f : α → β} : mapDomain f (0 : α →₀ M) = (0 : β →₀ M)
Full source
@[simp]
theorem mapDomain_zero {f : α → β} : mapDomain f (0 : α →₀ M) = (0 : β →₀ M) :=
  sum_zero_index
Mapping the Zero Function Yields the Zero Function
Informal description
For any function $f : \alpha \to \beta$, the image of the zero finitely supported function under the domain mapping operation is the zero finitely supported function, i.e., $\text{mapDomain}_f(0) = 0$.
Finsupp.mapDomain_congr theorem
{f g : α → β} (h : ∀ x ∈ v.support, f x = g x) : v.mapDomain f = v.mapDomain g
Full source
theorem mapDomain_congr {f g : α → β} (h : ∀ x ∈ v.support, f x = g x) :
    v.mapDomain f = v.mapDomain g :=
  Finset.sum_congr rfl fun _ H => by simp only [h _ H]
Equality of Mapped Domains under Function Agreement on Support
Informal description
Let $f, g : \alpha \to \beta$ be functions and $v : \alpha \to_{\text{f}} M$ a finitely supported function. If $f(x) = g(x)$ for all $x$ in the support of $v$, then the mapped functions $\text{mapDomain}_f(v)$ and $\text{mapDomain}_g(v)$ are equal.
Finsupp.mapDomain_add theorem
{f : α → β} : mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂
Full source
theorem mapDomain_add {f : α → β} : mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂ :=
  sum_add_index' (fun _ => single_zero _) fun _ => single_add _
Additivity of Domain Mapping for Finitely Supported Functions
Informal description
For any function $f \colon \alpha \to \beta$ and any two finitely supported functions $v_1, v_2 \colon \alpha \to_{\text{f}} M$, the image of their sum under domain mapping equals the sum of their images, i.e., \[ \text{mapDomain}\, f (v_1 + v_2) = \text{mapDomain}\, f\, v_1 + \text{mapDomain}\, f\, v_2. \]
Finsupp.mapDomain_equiv_apply theorem
{f : α ≃ β} (x : α →₀ M) (a : β) : mapDomain f x a = x (f.symm a)
Full source
@[simp]
theorem mapDomain_equiv_apply {f : α ≃ β} (x : α →₀ M) (a : β) :
    mapDomain f x a = x (f.symm a) := by
  conv_lhs => rw [← f.apply_symm_apply a]
  exact mapDomain_apply f.injective _ _
Equivariant Property of Domain Mapping for Finitely Supported Functions
Informal description
Let $f \colon \alpha \to \beta$ be an equivalence (bijection) between types $\alpha$ and $\beta$, and let $x \colon \alpha \to_{\text{f}} M$ be a finitely supported function. For any $a \in \beta$, the value of the mapped function $\text{mapDomain}\,f\,x$ at $a$ is equal to $x(f^{-1}(a))$, i.e., \[ (\text{mapDomain}\,f\,x)(a) = x(f^{-1}(a)). \]
Finsupp.mapDomain.addMonoidHom definition
(f : α → β) : (α →₀ M) →+ β →₀ M
Full source
/-- `Finsupp.mapDomain` is an `AddMonoidHom`. -/
@[simps]
def mapDomain.addMonoidHom (f : α → β) : (α →₀ M) →+ β →₀ M where
  toFun := mapDomain f
  map_zero' := mapDomain_zero
  map_add' _ _ := mapDomain_add
Additive monoid homomorphism induced by domain mapping of finitely supported functions
Informal description
For any function \( f : \alpha \to \beta \), the function `mapDomain.addMonoidHom f` is the additive monoid homomorphism from the type of finitely supported functions \( \alpha \to_{\text{f}} M \) to \( \beta \to_{\text{f}} M \) that maps a finitely supported function \( v \) to its image under domain mapping by \( f \), i.e., \( \text{mapDomain}\, f\, v \).
Finsupp.mapDomain.addMonoidHom_id theorem
: mapDomain.addMonoidHom id = AddMonoidHom.id (α →₀ M)
Full source
@[simp]
theorem mapDomain.addMonoidHom_id : mapDomain.addMonoidHom id = AddMonoidHom.id (α →₀ M) :=
  AddMonoidHom.ext fun _ => mapDomain_id
Identity Domain Mapping Yields Identity Homomorphism for Finitely Supported Functions
Informal description
The additive monoid homomorphism induced by mapping the domain of finitely supported functions using the identity function is equal to the identity additive monoid homomorphism on the type of finitely supported functions $\alpha \to_{\text{f}} M$.
Finsupp.mapDomain.addMonoidHom_comp theorem
(f : β → γ) (g : α → β) : (mapDomain.addMonoidHom (f ∘ g) : (α →₀ M) →+ γ →₀ M) = (mapDomain.addMonoidHom f).comp (mapDomain.addMonoidHom g)
Full source
theorem mapDomain.addMonoidHom_comp (f : β → γ) (g : α → β) :
    (mapDomain.addMonoidHom (f ∘ g) : (α →₀ M) →+ γ →₀ M) =
      (mapDomain.addMonoidHom f).comp (mapDomain.addMonoidHom g) :=
  AddMonoidHom.ext fun _ => mapDomain_comp
Composition of Domain Mapping Homomorphisms for Finitely Supported Functions
Informal description
For any functions $f \colon \beta \to \gamma$ and $g \colon \alpha \to \beta$, the additive monoid homomorphism induced by domain mapping of finitely supported functions satisfies: \[ \text{mapDomain.addMonoidHom}\, (f \circ g) = (\text{mapDomain.addMonoidHom}\, f) \circ (\text{mapDomain.addMonoidHom}\, g). \] Here, $\circ$ denotes the composition of additive monoid homomorphisms.
Finsupp.mapDomain_finset_sum theorem
{f : α → β} {s : Finset ι} {v : ι → α →₀ M} : mapDomain f (∑ i ∈ s, v i) = ∑ i ∈ s, mapDomain f (v i)
Full source
theorem mapDomain_finset_sum {f : α → β} {s : Finset ι} {v : ι → α →₀ M} :
    mapDomain f (∑ i ∈ s, v i) = ∑ i ∈ s, mapDomain f (v i) :=
  map_sum (mapDomain.addMonoidHom f) _ _
Sum Commutes with Domain Mapping for Finitely Supported Functions
Informal description
For any function $f \colon \alpha \to \beta$, any finite set $s \subseteq \iota$, and any family of finitely supported functions $v_i \colon \alpha \to_{\text{f}} M$ indexed by $i \in \iota$, the image under domain mapping of the sum of the $v_i$ over $s$ equals the sum of the images of the $v_i$ under domain mapping. That is, \[ \text{mapDomain}\, f \left( \sum_{i \in s} v_i \right) = \sum_{i \in s} \text{mapDomain}\, f\, v_i. \]
Finsupp.mapDomain_sum theorem
[Zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} : mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b)
Full source
theorem mapDomain_sum [Zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} :
    mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) :=
  map_finsuppSum (mapDomain.addMonoidHom f : (α →₀ M) →+ β →₀ M) _ _
Summation Commutes with Domain Mapping for Finitely Supported Functions
Informal description
Let $M$ and $N$ be types with zero elements, $f : \alpha \to \beta$ a function, $s : \alpha \to_{\text{f}} N$ a finitely supported function, and $v : \alpha \to N \to \alpha \to_{\text{f}} M$ a family of finitely supported functions. Then the image under domain mapping of the sum of $v$ over $s$ equals the sum over $s$ of the images under domain mapping of $v$, i.e., \[ \operatorname{mapDomain}_f \left( \sum_{a \in \alpha} s(a) \cdot v(a) \right) = \sum_{a \in \alpha} s(a) \cdot \operatorname{mapDomain}_f (v(a)). \]
Finsupp.mapDomain_support theorem
[DecidableEq β] {f : α → β} {s : α →₀ M} : (s.mapDomain f).support ⊆ s.support.image f
Full source
theorem mapDomain_support [DecidableEq β] {f : α → β} {s : α →₀ M} :
    (s.mapDomain f).support ⊆ s.support.image f :=
  Finset.Subset.trans support_sum <|
    Finset.Subset.trans (Finset.biUnion_mono fun _ _ => support_single_subset) <| by
      rw [Finset.biUnion_singleton]
Support of Mapped Finitely Supported Function is Subset of Image of Support
Informal description
For any function $f : \alpha \to \beta$ and any finitely supported function $s : \alpha \to_{\text{f}} M$, the support of the mapped function $\text{mapDomain}\, f\, s$ is a subset of the image of the support of $s$ under $f$. In other words, $\text{support}\, (\text{mapDomain}\, f\, s) \subseteq f[\text{support}\, s]$.
Finsupp.mapDomain_apply' theorem
(S : Set α) {f : α → β} (x : α →₀ M) (hS : (x.support : Set α) ⊆ S) (hf : Set.InjOn f S) {a : α} (ha : a ∈ S) : mapDomain f x (f a) = x a
Full source
theorem mapDomain_apply' (S : Set α) {f : α → β} (x : α →₀ M) (hS : (x.support : Set α) ⊆ S)
    (hf : Set.InjOn f S) {a : α} (ha : a ∈ S) : mapDomain f x (f a) = x a := by
  classical
    rw [mapDomain, sum_apply, sum]
    simp_rw [single_apply]
    by_cases hax : a ∈ x.support
    · rw [← Finset.add_sum_erase _ _ hax, if_pos rfl]
      convert add_zero (x a)
      refine Finset.sum_eq_zero fun i hi => if_neg ?_
      exact (hf.mono hS).ne (Finset.mem_of_mem_erase hi) hax (Finset.ne_of_mem_erase hi)
    · rw [not_mem_support_iff.1 hax]
      refine Finset.sum_eq_zero fun i hi => if_neg ?_
      exact hf.ne (hS hi) ha (ne_of_mem_of_not_mem hi hax)
Evaluation of Mapped Finitely Supported Function under Injection
Informal description
Let $S$ be a subset of $\alpha$, $f \colon \alpha \to \beta$ a function, and $x \colon \alpha \to_{\text{f}} M$ a finitely supported function. Suppose the support of $x$ is contained in $S$ and $f$ is injective on $S$. Then for any $a \in S$, the value of the mapped function $\operatorname{mapDomain}_f x$ at $f(a)$ equals $x(a)$, i.e., \[ \operatorname{mapDomain}_f x (f(a)) = x(a). \]
Finsupp.mapDomain_support_of_injOn theorem
[DecidableEq β] {f : α → β} (s : α →₀ M) (hf : Set.InjOn f s.support) : (mapDomain f s).support = Finset.image f s.support
Full source
theorem mapDomain_support_of_injOn [DecidableEq β] {f : α → β} (s : α →₀ M)
    (hf : Set.InjOn f s.support) : (mapDomain f s).support = Finset.image f s.support :=
  Finset.Subset.antisymm mapDomain_support <| by
    intro x hx
    simp only [mem_image, exists_prop, mem_support_iff, Ne] at hx
    rcases hx with ⟨hx_w, hx_h_left, rfl⟩
    simp only [mem_support_iff, Ne]
    rw [mapDomain_apply' (↑s.support : Set _) _ _ hf]
    · exact hx_h_left
    · simp only [mem_coe, mem_support_iff, Ne]
      exact hx_h_left
    · exact Subset.refl _
Support Equality for Mapped Finitely Supported Function under Injection on Support
Informal description
Let $f : \alpha \to \beta$ be a function and $s : \alpha \to_{\text{f}} M$ a finitely supported function. If $f$ is injective on the support of $s$, then the support of the mapped function $\text{mapDomain}\, f\, s$ is equal to the image of the support of $s$ under $f$, i.e., \[ \text{support}\, (\text{mapDomain}\, f\, s) = f[\text{support}\, s]. \]
Finsupp.mapDomain_support_of_injective theorem
[DecidableEq β] {f : α → β} (hf : Function.Injective f) (s : α →₀ M) : (mapDomain f s).support = Finset.image f s.support
Full source
theorem mapDomain_support_of_injective [DecidableEq β] {f : α → β} (hf : Function.Injective f)
    (s : α →₀ M) : (mapDomain f s).support = Finset.image f s.support :=
  mapDomain_support_of_injOn s hf.injOn
Support of Mapped Finitely Supported Function under Injective Domain Mapping
Informal description
Let $f \colon \alpha \to \beta$ be an injective function and $s \colon \alpha \to_{\text{f}} M$ a finitely supported function. Then the support of the mapped function $\operatorname{mapDomain}_f s$ is equal to the image of the support of $s$ under $f$, i.e., \[ \operatorname{support}(\operatorname{mapDomain}_f s) = f[\operatorname{support}(s)]. \]
Finsupp.prod_mapDomain_index theorem
[CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N} (h_zero : ∀ b, h b 0 = 1) (h_add : ∀ b m₁ m₂, h b (m₁ + m₂) = h b m₁ * h b m₂) : (mapDomain f s).prod h = s.prod fun a m => h (f a) m
Full source
@[to_additive]
theorem prod_mapDomain_index [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N}
    (h_zero : ∀ b, h b 0 = 1) (h_add : ∀ b m₁ m₂, h b (m₁ + m₂) = h b m₁ * h b m₂) :
    (mapDomain f s).prod h = s.prod fun a m => h (f a) m :=
  (prod_sum_index h_zero h_add).trans <| prod_congr fun _ _ => prod_single_index (h_zero _)
Product over Mapped Domain Equals Product over Original Domain for Finitely Supported Functions
Informal description
Let $\alpha$ and $\beta$ be types, $M$ be a type with a zero element, and $N$ be a commutative monoid. Given a function $f : \alpha \to \beta$, a finitely supported function $s : \alpha \to_{\text{f}} M$, and a function $h : \beta \to M \to N$ such that: 1. $h(b, 0) = 1$ for all $b \in \beta$, 2. $h(b, m_1 + m_2) = h(b, m_1) \cdot h(b, m_2)$ for all $b \in \beta$ and $m_1, m_2 \in M$, then the product of $h$ over the image of $s$ under domain mapping by $f$ is equal to the product of $h \circ f$ over $s$ itself. That is, \[ \prod_{b \in \beta} h(b, (\text{mapDomain } f \ s)(b)) = \prod_{a \in \alpha} h(f(a), s(a)). \]
Finsupp.sum_mapDomain_index_addMonoidHom theorem
[AddCommMonoid N] {f : α → β} {s : α →₀ M} (h : β → M →+ N) : ((mapDomain f s).sum fun b m => h b m) = s.sum fun a m => h (f a) m
Full source
/-- A version of `sum_mapDomain_index` that takes a bundled `AddMonoidHom`,
rather than separate linearity hypotheses.
-/
@[simp]
theorem sum_mapDomain_index_addMonoidHom [AddCommMonoid N] {f : α → β} {s : α →₀ M}
    (h : β → M →+ N) : ((mapDomain f s).sum fun b m => h b m) = s.sum fun a m => h (f a) m :=
  sum_mapDomain_index (fun b => (h b).map_zero) (fun b _ _ => (h b).map_add _ _)
Sum Preservation under Domain Mapping for Finitely Supported Functions with Additive Monoid Homomorphisms
Informal description
Let $\alpha$ and $\beta$ be types, $M$ be a type with a zero element, and $N$ be an additive commutative monoid. Given a function $f : \alpha \to \beta$, a finitely supported function $s : \alpha \to_{\text{f}} M$, and a family of additive monoid homomorphisms $h_b : M \to N$ indexed by $\beta$, the sum of $h_b$ evaluated at the values of the mapped function $\text{mapDomain } f \ s$ equals the sum of $h_{f(a)}$ evaluated at the values of $s$. That is, \[ \sum_{b \in \beta} h_b((\text{mapDomain } f \ s)(b)) = \sum_{a \in \alpha} h_{f(a)}(s(a)). \]
Finsupp.embDomain_eq_mapDomain theorem
(f : α ↪ β) (v : α →₀ M) : embDomain f v = mapDomain f v
Full source
theorem embDomain_eq_mapDomain (f : α ↪ β) (v : α →₀ M) : embDomain f v = mapDomain f v := by
  ext a
  by_cases h : a ∈ Set.range f
  · rcases h with ⟨a, rfl⟩
    rw [mapDomain_apply f.injective, embDomain_apply]
  · rw [mapDomain_notin_range, embDomain_notin_range] <;> assumption
Equality of Embedded and Mapped Finitely Supported Functions
Informal description
For any embedding $f \colon \alpha \hookrightarrow \beta$ and any finitely supported function $v \colon \alpha \to M$, the embedded function $\text{embDomain}\,f\,v$ is equal to the mapped function $\text{mapDomain}\,f\,v$.
Finsupp.prod_mapDomain_index_inj theorem
[CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N} (hf : Function.Injective f) : (s.mapDomain f).prod h = s.prod fun a b => h (f a) b
Full source
@[to_additive]
theorem prod_mapDomain_index_inj [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N}
    (hf : Function.Injective f) : (s.mapDomain f).prod h = s.prod fun a b => h (f a) b := by
  rw [← Function.Embedding.coeFn_mk f hf, ← embDomain_eq_mapDomain, prod_embDomain]
Product Preservation under Injective Domain Mapping for Finitely Supported Functions
Informal description
Let $\alpha$ and $\beta$ be types, $M$ be a type with a zero element, and $N$ be a commutative monoid. Given an injective function $f \colon \alpha \to \beta$, a finitely supported function $s \colon \alpha \to_{\text{f}} M$, and a function $h \colon \beta \to M \to N$, the product of $h$ evaluated at the values of the mapped function $\text{mapDomain}\,f\,s$ equals the product of $h(f(a))$ evaluated at the values of $s$. That is, \[ \prod_{b \in \beta} h(b, (\text{mapDomain}\,f\,s)(b)) = \prod_{a \in \alpha} h(f(a), s(a)). \]
Finsupp.mapDomain_injective theorem
{f : α → β} (hf : Function.Injective f) : Function.Injective (mapDomain f : (α →₀ M) → β →₀ M)
Full source
theorem mapDomain_injective {f : α → β} (hf : Function.Injective f) :
    Function.Injective (mapDomain f : (α →₀ M) → β →₀ M) := by
  intro v₁ v₂ eq
  ext a
  have : mapDomain f v₁ (f a) = mapDomain f v₂ (f a) := by rw [eq]
  rwa [mapDomain_apply hf, mapDomain_apply hf] at this
Injectivity of Domain Mapping on Finitely Supported Functions
Informal description
Let $f \colon \alpha \to \beta$ be an injective function. Then the induced mapping $\text{mapDomain}\,f \colon (\alpha \to_{\text{f}} M) \to (\beta \to_{\text{f}} M)$ on finitely supported functions is also injective.
Finsupp.mapDomainEmbedding definition
{α β : Type*} (f : α ↪ β) : (α →₀ ℕ) ↪ β →₀ ℕ
Full source
/-- When `f` is an embedding we have an embedding `(α →₀ ℕ) ↪ (β →₀ ℕ)` given by `mapDomain`. -/
@[simps]
def mapDomainEmbedding {α β : Type*} (f : α ↪ β) : (α →₀ ℕ) ↪ β →₀ ℕ :=
  ⟨Finsupp.mapDomain f, Finsupp.mapDomain_injective f.injective⟩
Embedding of finitely supported functions via domain mapping
Informal description
Given an embedding $f : \alpha \hookrightarrow \beta$, the function `mapDomainEmbedding f` is an embedding from the type of finitely supported functions $\alpha \to_{\text{f}} \mathbb{N}$ to the type of finitely supported functions $\beta \to_{\text{f}} \mathbb{N}$, defined by mapping the domain via $f$.
Finsupp.mapDomain.addMonoidHom_comp_mapRange theorem
[AddCommMonoid N] (f : α → β) (g : M →+ N) : (mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) = (mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f)
Full source
theorem mapDomain.addMonoidHom_comp_mapRange [AddCommMonoid N] (f : α → β) (g : M →+ N) :
    (mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) =
      (mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f) := by
  ext
  simp only [AddMonoidHom.coe_comp, Finsupp.mapRange_single, Finsupp.mapDomain.addMonoidHom_apply,
    Finsupp.singleAddHom_apply, eq_self_iff_true, Function.comp_apply, Finsupp.mapDomain_single,
    Finsupp.mapRange.addMonoidHom_apply]
Commutativity of Domain Mapping and Range Mapping for Finitely Supported Functions
Informal description
Let $M$ and $N$ be additive commutative monoids. For any function $f \colon \alpha \to \beta$ and any additive monoid homomorphism $g \colon M \to N$, the following diagram commutes: \[ \begin{CD} (\alpha \to_{\text{f}} M) @>{\text{mapDomain.addMonoidHom}\, f}>> (\beta \to_{\text{f}} M) \\ @V{\text{mapRange.addMonoidHom}\, g}VV @VV{\text{mapRange.addMonoidHom}\, g}V \\ (\alpha \to_{\text{f}} N) @>>{\text{mapDomain.addMonoidHom}\, f}> (\beta \to_{\text{f}} N) \end{CD} \] In other words, the composition of domain mapping followed by range mapping is equal to the composition of range mapping followed by domain mapping.
Finsupp.mapDomain_mapRange theorem
[AddCommMonoid N] (f : α → β) (v : α →₀ M) (g : M → N) (h0 : g 0 = 0) (hadd : ∀ x y, g (x + y) = g x + g y) : mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v)
Full source
/-- When `g` preserves addition, `mapRange` and `mapDomain` commute. -/
theorem mapDomain_mapRange [AddCommMonoid N] (f : α → β) (v : α →₀ M) (g : M → N) (h0 : g 0 = 0)
    (hadd : ∀ x y, g (x + y) = g x + g y) :
    mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v) :=
  let g' : M →+ N :=
    { toFun := g
      map_zero' := h0
      map_add' := hadd }
  DFunLike.congr_fun (mapDomain.addMonoidHom_comp_mapRange f g') v
Commutativity of Domain Mapping and Range Mapping for Finitely Supported Functions
Informal description
Let $M$ and $N$ be additive commutative monoids. Given a function $f \colon \alpha \to \beta$, a finitely supported function $v \colon \alpha \to_{\text{f}} M$, and a function $g \colon M \to N$ such that $g(0) = 0$ and $g$ preserves addition, the following equality holds: \[ \operatorname{mapDomain} f (\operatorname{mapRange} g v) = \operatorname{mapRange} g (\operatorname{mapDomain} f v). \]
Finsupp.sum_update_add theorem
[AddZeroClass α] [AddCommMonoid β] (f : ι →₀ α) (i : ι) (a : α) (g : ι → α → β) (hg : ∀ i, g i 0 = 0) (hgg : ∀ (j : ι) (a₁ a₂ : α), g j (a₁ + a₂) = g j a₁ + g j a₂) : (f.update i a).sum g + g i (f i) = f.sum g + g i a
Full source
theorem sum_update_add [AddZeroClass α] [AddCommMonoid β] (f : ι →₀ α) (i : ι) (a : α)
    (g : ι → α → β) (hg : ∀ i, g i 0 = 0)
    (hgg : ∀ (j : ι) (a₁ a₂ : α), g j (a₁ + a₂) = g j a₁ + g j a₂) :
    (f.update i a).sum g + g i (f i) = f.sum g + g i a := by
  rw [update_eq_erase_add_single, sum_add_index' hg hgg]
  conv_rhs => rw [← Finsupp.update_self f i]
  rw [update_eq_erase_add_single, sum_add_index' hg hgg, add_assoc, add_assoc]
  congr 1
  rw [add_comm, sum_single_index (hg _), sum_single_index (hg _)]
Sum of Updated Finitely Supported Function Plus Original Value Equals Original Sum Plus New Value
Informal description
Let $\alpha$ be an additive zero class and $\beta$ an additive commutative monoid. For any finitely supported function $f \colon \iota \to \alpha$, any index $i \in \iota$, any element $a \in \alpha$, and any function $g \colon \iota \to \alpha \to \beta$ such that: 1. $g_j(0) = 0$ for all $j \in \iota$, 2. $g_j(a_1 + a_2) = g_j(a_1) + g_j(a_2)$ for all $j \in \iota$ and $a_1, a_2 \in \alpha$, the following equality holds: \[ \sum_{j \in \iota} g_j(f(i \mapsto a)(j)) + g_i(f(i)) = \sum_{j \in \iota} g_j(f(j)) + g_i(a), \] where $f(i \mapsto a)$ denotes the function $f$ updated at $i$ with value $a$.
Finsupp.mapDomain_injOn theorem
(S : Set α) {f : α → β} (hf : Set.InjOn f S) : Set.InjOn (mapDomain f : (α →₀ M) → β →₀ M) {w | (w.support : Set α) ⊆ S}
Full source
theorem mapDomain_injOn (S : Set α) {f : α → β} (hf : Set.InjOn f S) :
    Set.InjOn (mapDomain f : (α →₀ M) → β →₀ M) { w | (w.support : Set α) ⊆ S } := by
  intro v₁ hv₁ v₂ hv₂ eq
  ext a
  classical
    by_cases h : a ∈ v₁.support ∪ v₂.support
    · rw [← mapDomain_apply' S _ hv₁ hf _, ← mapDomain_apply' S _ hv₂ hf _, eq] <;>
        · apply Set.union_subset hv₁ hv₂
          exact mod_cast h
    · simp only [not_or, mem_union, not_not, mem_support_iff] at h
      simp [h]
Injectivity of Domain Mapping for Finitely Supported Functions with Restricted Support
Informal description
Let $S$ be a subset of $\alpha$ and $f \colon \alpha \to \beta$ a function that is injective on $S$. Then the function $\operatorname{mapDomain}_f \colon (\alpha \to_{\text{f}} M) \to (\beta \to_{\text{f}} M)$ is injective when restricted to the set of finitely supported functions $w \colon \alpha \to M$ whose support is contained in $S$.
Finsupp.equivMapDomain_eq_mapDomain theorem
{M} [AddCommMonoid M] (f : α ≃ β) (l : α →₀ M) : equivMapDomain f l = mapDomain f l
Full source
theorem equivMapDomain_eq_mapDomain {M} [AddCommMonoid M] (f : α ≃ β) (l : α →₀ M) :
    equivMapDomain f l = mapDomain f l := by ext x; simp [mapDomain_equiv_apply]
Equality of Domain Remapping and Mapping for Finitely Supported Functions via Equivalence
Informal description
Let $M$ be an additive commutative monoid, and let $f \colon \alpha \simeq \beta$ be an equivalence between types $\alpha$ and $\beta$. For any finitely supported function $l \colon \alpha \to_{\text{f}} M$, the domain remapping via $f$ coincides with the domain mapping via $f$, i.e., \[ \text{equivMapDomain}\,f\,l = \text{mapDomain}\,f\,l. \]
Finsupp.comapDomain definition
[Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) : α →₀ M
Full source
/-- Given `f : α → β`, `l : β →₀ M` and a proof `hf` that `f` is injective on
the preimage of `l.support`, `comapDomain f l hf` is the finitely supported function
from `α` to `M` given by composing `l` with `f`. -/
@[simps support]
def comapDomain [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) :
    α →₀ M where
  support := l.support.preimage f hf
  toFun a := l (f a)
  mem_support_toFun := by
    intro a
    simp only [Finset.mem_def.symm, Finset.mem_preimage]
    exact l.mem_support_toFun (f a)
Preimage composition of finitely supported functions
Informal description
Given a function $f : \alpha \to \beta$, a finitely supported function $l : \beta \to M$ (where $M$ has a zero element), and a proof that $f$ is injective on the preimage of the support of $l$, the function `comapDomain f l hf` is the finitely supported function from $\alpha$ to $M$ defined by composing $l$ with $f$. Its support is the preimage of the support of $l$ under $f$.
Finsupp.comapDomain_apply theorem
[Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) (a : α) : comapDomain f l hf a = l (f a)
Full source
@[simp]
theorem comapDomain_apply [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support))
    (a : α) : comapDomain f l hf a = l (f a) :=
  rfl
Evaluation of Composed Finitely Supported Function: $\text{comapDomain}\,f\,l\,hf\,(a) = l(f(a))$
Informal description
Let $M$ be a type with a zero element, $f : \alpha \to \beta$ a function, $l : \beta \to M$ a finitely supported function, and $hf$ a proof that $f$ is injective on the preimage of the support of $l$. Then for any $a \in \alpha$, the value of the finitely supported function $\text{comapDomain}\,f\,l\,hf$ at $a$ is equal to the value of $l$ at $f(a)$, i.e., \[ (\text{comapDomain}\,f\,l\,hf)(a) = l(f(a)). \]
Finsupp.sum_comapDomain theorem
[Zero M] [AddCommMonoid N] (f : α → β) (l : β →₀ M) (g : β → M → N) (hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) : (comapDomain f l hf.injOn).sum (g ∘ f) = l.sum g
Full source
theorem sum_comapDomain [Zero M] [AddCommMonoid N] (f : α → β) (l : β →₀ M) (g : β → M → N)
    (hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) :
    (comapDomain f l hf.injOn).sum (g ∘ f) = l.sum g := by
  simp only [sum, comapDomain_apply, (· ∘ ·), comapDomain]
  exact Finset.sum_preimage_of_bij f _ hf fun x => g x (l x)
Sum Preservation under Composition of Finitely Supported Functions
Informal description
Let $M$ be a type with a zero element, $N$ an additive commutative monoid, $f : \alpha \to \beta$ a function, $l : \beta \to M$ a finitely supported function, and $g : \beta \to M \to N$ a function. Suppose $f$ is bijective between the preimage of the support of $l$ under $f$ and the support of $l$. Then the sum of $g \circ f$ over the finitely supported function $\text{comapDomain}\,f\,l\,hf.\text{injOn}$ is equal to the sum of $g$ over $l$, i.e., \[ \sum_{a \in \alpha} g(f(a)) \big((\text{comapDomain}\,f\,l\,hf.\text{injOn})(a)\big) = \sum_{b \in \beta} g(b) (l(b)). \]
Finsupp.embDomain_comapDomain theorem
{f : α ↪ β} {g : β →₀ M} (hg : ↑g.support ⊆ Set.range f) : embDomain f (comapDomain f g f.injective.injOn) = g
Full source
lemma embDomain_comapDomain {f : α ↪ β} {g : β →₀ M} (hg : ↑g.support ⊆ Set.range f) :
    embDomain f (comapDomain f g f.injective.injOn) = g := by
  ext b
  by_cases hb : b ∈ Set.range f
  · obtain ⟨a, rfl⟩ := hb
    rw [embDomain_apply, comapDomain_apply]
  · replace hg : g b = 0 := not_mem_support_iff.mp <| mt (hg ·) hb
    rw [embDomain_notin_range _ _ _ hb, hg]
Embedding of Preimage Composition Equals Original Function for Finitely Supported Functions
Informal description
Let $f \colon \alpha \hookrightarrow \beta$ be an embedding and $g \colon \beta \to M$ a finitely supported function such that the support of $g$ is contained in the range of $f$. Then the embedding of the preimage composition of $f$ with $g$ equals $g$, i.e., \[ \text{embDomain}\, f\, (\text{comapDomain}\, f\, g\, f.\text{injOn}) = g. \]
Finsupp.comapDomain_single theorem
(f : α → β) (a : α) (m : M) (hif : Set.InjOn f (f ⁻¹' (single (f a) m).support)) : comapDomain f (Finsupp.single (f a) m) hif = Finsupp.single a m
Full source
@[simp]
theorem comapDomain_single (f : α → β) (a : α) (m : M)
    (hif : Set.InjOn f (f ⁻¹' (single (f a) m).support)) :
    comapDomain f (Finsupp.single (f a) m) hif = Finsupp.single a m := by
  rcases eq_or_ne m 0 with (rfl | hm)
  · simp only [single_zero, comapDomain_zero]
  · rw [eq_single_iff, comapDomain_apply, comapDomain_support, ← Finset.coe_subset, coe_preimage,
      support_single_ne_zero _ hm, coe_singleton, coe_singleton, single_eq_same]
    rw [support_single_ne_zero _ hm, coe_singleton] at hif
    exact ⟨fun x hx => hif hx rfl hx, rfl⟩
Preimage Composition of Single Finitely Supported Function: $\text{comapDomain}\,f\,(\text{single}(f(a), m)) = \text{single}(a, m)$
Informal description
Let $f : \alpha \to \beta$ be a function, $a \in \alpha$, and $m \in M$ (where $M$ has a zero element). Suppose $f$ is injective on the preimage of the support of the finitely supported function $\text{single}(f(a), m)$. Then the preimage composition of $f$ with $\text{single}(f(a), m)$ is equal to $\text{single}(a, m)$, i.e., \[ \text{comapDomain}\,f\,(\text{single}(f(a), m))\,hif = \text{single}(a, m). \]
Finsupp.comapDomain_add theorem
(v₁ v₂ : β →₀ M) (hv₁ : Set.InjOn f (f ⁻¹' ↑v₁.support)) (hv₂ : Set.InjOn f (f ⁻¹' ↑v₂.support)) (hv₁₂ : Set.InjOn f (f ⁻¹' ↑(v₁ + v₂).support)) : comapDomain f (v₁ + v₂) hv₁₂ = comapDomain f v₁ hv₁ + comapDomain f v₂ hv₂
Full source
theorem comapDomain_add (v₁ v₂ : β →₀ M) (hv₁ : Set.InjOn f (f ⁻¹' ↑v₁.support))
    (hv₂ : Set.InjOn f (f ⁻¹' ↑v₂.support)) (hv₁₂ : Set.InjOn f (f ⁻¹' ↑(v₁ + v₂).support)) :
    comapDomain f (v₁ + v₂) hv₁₂ = comapDomain f v₁ hv₁ + comapDomain f v₂ hv₂ := by
  ext
  simp only [comapDomain_apply, coe_add, Pi.add_apply]
Additivity of Preimage Composition for Finitely Supported Functions
Informal description
Let $f : \alpha \to \beta$ be a function, and let $v_1, v_2 : \beta \to M$ be finitely supported functions. Suppose $f$ is injective on the preimage of the support of $v_1$, $v_2$, and $v_1 + v_2$ respectively. Then the preimage composition of $f$ with the sum $v_1 + v_2$ is equal to the sum of the preimage compositions of $f$ with $v_1$ and $v_2$, i.e., \[ \text{comapDomain}_f (v_1 + v_2) = \text{comapDomain}_f v_1 + \text{comapDomain}_f v_2. \]
Finsupp.comapDomain_add_of_injective theorem
(hf : Function.Injective f) (v₁ v₂ : β →₀ M) : comapDomain f (v₁ + v₂) hf.injOn = comapDomain f v₁ hf.injOn + comapDomain f v₂ hf.injOn
Full source
/-- A version of `Finsupp.comapDomain_add` that's easier to use. -/
theorem comapDomain_add_of_injective (hf : Function.Injective f) (v₁ v₂ : β →₀ M) :
    comapDomain f (v₁ + v₂) hf.injOn =
      comapDomain f v₁ hf.injOn + comapDomain f v₂ hf.injOn :=
  comapDomain_add _ _ _ _ _
Additivity of Preimage Composition for Finitely Supported Functions under Injective Maps
Informal description
Let $f : \alpha \to \beta$ be an injective function, and let $v_1, v_2 : \beta \to M$ be finitely supported functions. Then the preimage composition of $f$ with the sum $v_1 + v_2$ is equal to the sum of the preimage compositions of $f$ with $v_1$ and $v_2$, i.e., \[ \text{comapDomain}_f (v_1 + v_2) = \text{comapDomain}_f v_1 + \text{comapDomain}_f v_2. \]
Finsupp.comapDomain.addMonoidHom definition
(hf : Function.Injective f) : (β →₀ M) →+ α →₀ M
Full source
/-- `Finsupp.comapDomain` is an `AddMonoidHom`. -/
@[simps]
def comapDomain.addMonoidHom (hf : Function.Injective f) : (β →₀ M) →+ α →₀ M where
  toFun x := comapDomain f x hf.injOn
  map_zero' := comapDomain_zero f
  map_add' := comapDomain_add_of_injective hf
Additive monoid homomorphism induced by precomposition with an injective function
Informal description
Given an injective function $f : \alpha \to \beta$, the function `Finsupp.comapDomain.addMonoidHom hf` is the additive monoid homomorphism from finitely supported functions $\beta \to M$ to finitely supported functions $\alpha \to M$, defined by precomposition with $f$. It maps a finitely supported function $x : \beta \to M$ to $\text{comapDomain}_f x$, preserves addition, and sends the zero function to the zero function.
Finsupp.mapDomain_comapDomain theorem
(hf : Function.Injective f) (l : β →₀ M) (hl : ↑l.support ⊆ Set.range f) : mapDomain f (comapDomain f l hf.injOn) = l
Full source
theorem mapDomain_comapDomain (hf : Function.Injective f) (l : β →₀ M)
    (hl : ↑l.support ⊆ Set.range f) :
    mapDomain f (comapDomain f l hf.injOn) = l := by
  conv_rhs => rw [← embDomain_comapDomain (f := ⟨f, hf⟩) hl (M := M), embDomain_eq_mapDomain]
  rfl
Domain Mapping of Preimage Composition Equals Original Function for Finitely Supported Functions under Injective Maps
Informal description
Let $f \colon \alpha \to \beta$ be an injective function, and let $l \colon \beta \to M$ be a finitely supported function such that the support of $l$ is contained in the range of $f$. Then the domain mapping of $f$ applied to the preimage composition of $f$ with $l$ equals $l$, i.e., \[ \text{mapDomain}\, f\, (\text{comapDomain}\, f\, l\, f.\text{injOn}) = l. \]
Finsupp.some definition
[Zero M] (f : Option α →₀ M) : α →₀ M
Full source
/-- Restrict a finitely supported function on `Option α` to a finitely supported function on `α`. -/
def some [Zero M] (f : OptionOption α →₀ M) : α →₀ M :=
  f.comapDomain Option.some fun _ => by simp
Restriction of finitely supported function from Option α to α
Informal description
Given a finitely supported function $f$ from $\text{Option}\ \alpha$ to $M$ (where $M$ has a zero element), the function $\text{Finsupp.some}\ f$ restricts $f$ to $\alpha$ by considering only the values of $f$ at $\text{Option.some}\ a$ for each $a \in \alpha$. The support of the resulting function consists of those $a \in \alpha$ for which $f(\text{some}\ a) \neq 0$.
Finsupp.some_apply theorem
[Zero M] (f : Option α →₀ M) (a : α) : f.some a = f (Option.some a)
Full source
@[simp]
theorem some_apply [Zero M] (f : OptionOption α →₀ M) (a : α) : f.some a = f (Option.some a) :=
  rfl
Evaluation of Restricted Finitely Supported Function on Option Type
Informal description
For any finitely supported function $f \colon \text{Option}\ \alpha \to M$ (where $M$ has a zero element) and any element $a \in \alpha$, the value of the restricted function $f.\text{some}$ at $a$ is equal to the value of $f$ at $\text{some}\ a$, i.e., $f.\text{some}(a) = f(\text{some}\ a)$.
Finsupp.some_zero theorem
[Zero M] : (0 : Option α →₀ M).some = 0
Full source
@[simp]
theorem some_zero [Zero M] : (0 : OptionOption α →₀ M).some = 0 := by
  ext
  simp
Restriction of Zero Function from Option α to α is Zero
Informal description
For any type $\alpha$ and any type $M$ with a zero element, the restriction of the zero finitely supported function on $\text{Option}\ \alpha$ to $\alpha$ is equal to the zero function on $\alpha$. That is, $0.\text{some} = 0$.
Finsupp.some_add theorem
[AddZeroClass M] (f g : Option α →₀ M) : (f + g).some = f.some + g.some
Full source
@[simp]
theorem some_add [AddZeroClass M] (f g : OptionOption α →₀ M) : (f + g).some = f.some + g.some := by
  ext
  simp
Additivity of Restriction for Finitely Supported Functions on Option Types
Informal description
For any two finitely supported functions $f, g \colon \text{Option}\ \alpha \to M$ where $M$ is an additive monoid with zero, the restriction of their sum to $\alpha$ is equal to the sum of their restrictions, i.e., $(f + g).\text{some} = f.\text{some} + g.\text{some}$.
Finsupp.some_single_none theorem
[Zero M] (m : M) : (single none m : Option α →₀ M).some = 0
Full source
@[simp]
theorem some_single_none [Zero M] (m : M) : (single none m : OptionOption α →₀ M).some = 0 := by
  ext
  simp
Restriction of Single None Function Yields Zero Function
Informal description
For any type $\alpha$ and any type $M$ with a zero element, the restriction of the finitely supported function $\text{single}\ \text{none}\ m$ (which maps $\text{none}$ to $m$ and all other inputs to $0$) to $\alpha$ via $\text{Finsupp.some}$ yields the zero function, i.e., $(\text{single}\ \text{none}\ m).\text{some} = 0$.
Finsupp.some_single_some theorem
[Zero M] (a : α) (m : M) : (single (Option.some a) m : Option α →₀ M).some = single a m
Full source
@[simp]
theorem some_single_some [Zero M] (a : α) (m : M) :
    (single (Option.some a) m : OptionOption α →₀ M).some = single a m := by
  classical
    ext b
    simp [single_apply]
Restriction of Single Function at Some Point to Base Type
Informal description
For any type $\alpha$ and any type $M$ with a zero element, given an element $a \in \alpha$ and $m \in M$, the restriction of the finitely supported function $\text{single}(\text{some}(a), m)$ from $\text{Option}\ \alpha$ to $M$ to $\alpha$ is equal to the finitely supported function $\text{single}(a, m)$ from $\alpha$ to $M$. In other words, $(\text{single}(\text{some}(a), m)).\text{some} = \text{single}(a, m)$.
Finsupp.prod_option_index theorem
[AddZeroClass M] [CommMonoid N] (f : Option α →₀ M) (b : Option α → M → N) (h_zero : ∀ o, b o 0 = 1) (h_add : ∀ o m₁ m₂, b o (m₁ + m₂) = b o m₁ * b o m₂) : f.prod b = b none (f none) * f.some.prod fun a => b (Option.some a)
Full source
@[to_additive]
theorem prod_option_index [AddZeroClass M] [CommMonoid N] (f : OptionOption α →₀ M)
    (b : Option α → M → N) (h_zero : ∀ o, b o 0 = 1)
    (h_add : ∀ o m₁ m₂, b o (m₁ + m₂) = b o m₁ * b o m₂) :
    f.prod b = b none (f none) * f.some.prod fun a => b (Option.some a) := by
  classical
    induction f using induction_linear with
    | zero => simp [some_zero, h_zero]
    | add f₁ f₂ h₁ h₂ =>
      rw [Finsupp.prod_add_index, h₁, h₂, some_add, Finsupp.prod_add_index]
      · simp only [h_add, Pi.add_apply, Finsupp.coe_add]
        rw [mul_mul_mul_comm]
      all_goals simp [h_zero, h_add]
    | single a m => cases a <;> simp [h_zero, h_add]
Decomposition of Product over Option Type for Finitely Supported Functions
Informal description
Let $M$ be an additive monoid with zero, $N$ a commutative monoid, and $f \colon \text{Option}\ \alpha \to_{\text{f}} M$ a finitely supported function. Given a function $b \colon \text{Option}\ \alpha \to M \to N$ such that for any $o \in \text{Option}\ \alpha$, $b(o, 0) = 1$ (the multiplicative identity of $N$), and for any $o \in \text{Option}\ \alpha$ and $m_1, m_2 \in M$, $b(o, m_1 + m_2) = b(o, m_1) \cdot b(o, m_2)$, the product $\prod_{o \in \text{Option}\ \alpha} b(o, f(o))$ can be decomposed as: \[ \prod_{o \in \text{Option}\ \alpha} b(o, f(o)) = b(\text{none}, f(\text{none})) \cdot \prod_{a \in \alpha} b(\text{some}(a), f(\text{some}(a))). \]
Finsupp.sum_option_index_smul theorem
[Semiring R] [AddCommMonoid M] [Module R M] (f : Option α →₀ R) (b : Option α → M) : (f.sum fun o r => r • b o) = f none • b none + f.some.sum fun a r => r • b (Option.some a)
Full source
theorem sum_option_index_smul [Semiring R] [AddCommMonoid M] [Module R M] (f : OptionOption α →₀ R)
    (b : Option α → M) :
    (f.sum fun o r => r • b o) = f none • b none + f.some.sum fun a r => r • b (Option.some a) :=
  f.sum_option_index _ (fun _ => zero_smul _ _) fun _ _ _ => add_smul _ _ _
Decomposition of Scalar Sum over Option Type for Finitely Supported Functions
Informal description
Let $R$ be a semiring, $M$ an additive commutative monoid equipped with an $R$-module structure, and $f \colon \text{Option}\ \alpha \to_{\text{f}} R$ a finitely supported function. For any function $b \colon \text{Option}\ \alpha \to M$, the sum of the scalar multiples $r \cdot b(o)$ over all pairs $(o, r)$ in the support of $f$ can be decomposed as: \[ \sum_{(o, r)} r \cdot b(o) = f(\text{none}) \cdot b(\text{none}) + \sum_{(a, r)} r \cdot b(\text{some}(a)), \] where the second sum is taken over the restriction of $f$ to $\alpha$ via $\text{some}$.
Finsupp.some_embDomain_some theorem
[Zero M] (f : α →₀ M) : (f.embDomain .some).some = f
Full source
@[simp] lemma some_embDomain_some [Zero M] (f : α →₀ M) : (f.embDomain .some).some = f := by
  ext; rw [some_apply]; exact embDomain_apply _ _ _
Restriction of Embedded Function via Some Equals Original Function
Informal description
For any finitely supported function $f \colon \alpha \to M$ (where $M$ has a zero element), the restriction of the embedded function $\text{embDomain}\, \text{some}\, f$ to $\alpha$ via $\text{some}$ is equal to $f$ itself, i.e., $$ (\text{embDomain}\, \text{some}\, f).\text{some} = f. $$
Finsupp.embDomain_some_none theorem
[Zero M] (f : α →₀ M) : f.embDomain .some .none = 0
Full source
@[simp] lemma embDomain_some_none [Zero M] (f : α →₀ M) : f.embDomain .some .none = 0 :=
  embDomain_notin_range _ _ _ (by simp)
Vanishing of Embedded Finitely Supported Function at None
Informal description
For any finitely supported function $f \colon \alpha \to M$ (where $M$ has a zero element), the value of the embedded function $\text{embDomain}\, \text{some}\, f$ at $\text{none}$ is zero, i.e., $(\text{embDomain}\, \text{some}\, f)\, \text{none} = 0$.
Finsupp.filter definition
(p : α → Prop) [DecidablePred p] (f : α →₀ M) : α →₀ M
Full source
/--
`Finsupp.filter p f` is the finitely supported function that is `f a` if `p a` is true and `0`
otherwise. -/
def filter (p : α → Prop) [DecidablePred p] (f : α →₀ M) : α →₀ M where
  toFun a := if p a then f a else 0
  support := f.support.filter p
  mem_support_toFun a := by
    split_ifs with h <;>
      · simp only [h, mem_filter, mem_support_iff]
        tauto
Filtering finitely supported functions by a predicate
Informal description
Given a predicate $p$ on $\alpha$ and a finitely supported function $f : \alpha \to M$, the function `Finsupp.filter p f` is defined as the finitely supported function that equals $f(a)$ when $p(a)$ holds and $0$ otherwise. The support of this filtered function is the intersection of the support of $f$ with the set of elements satisfying $p$.
Finsupp.filter_apply theorem
(a : α) : f.filter p a = if p a then f a else 0
Full source
theorem filter_apply (a : α) : f.filter p a = if p a then f a else 0 := rfl
Value of Filtered Finitely Supported Function at a Point
Informal description
For any element $a$ of type $\alpha$, the value of the filtered finitely supported function $f \text{.filter } p$ at $a$ is equal to $f(a)$ if the predicate $p(a)$ holds, and $0$ otherwise. In other words, $(f \text{.filter } p)(a) = \begin{cases} f(a) & \text{if } p(a) \\ 0 & \text{otherwise} \end{cases}$.
Finsupp.filter_eq_indicator theorem
: ⇑(f.filter p) = Set.indicator {x | p x} f
Full source
theorem filter_eq_indicator : ⇑(f.filter p) = Set.indicator { x | p x } f := by
  ext
  simp [filter_apply, Set.indicator_apply]
Filtered Function as Indicator of Predicate Subset
Informal description
For a finitely supported function $f : \alpha \to M$ and a predicate $p$ on $\alpha$, the filtered function $f \text{.filter } p$ is equal to the set indicator function of the subset $\{x \mid p x\}$ applied to $f$. That is, $f \text{.filter } p = \text{indicator}_{\{x \mid p x\}} f$.
Finsupp.filter_eq_zero_iff theorem
: f.filter p = 0 ↔ ∀ x, p x → f x = 0
Full source
theorem filter_eq_zero_iff : f.filter p = 0 ↔ ∀ x, p x → f x = 0 := by
  simp only [DFunLike.ext_iff, filter_eq_indicator, zero_apply, Set.indicator_apply_eq_zero,
    Set.mem_setOf_eq]
Filtered Function is Zero if and only if Original Function Vanishes on Predicate
Informal description
For a finitely supported function $f \colon \alpha \to M$ and a predicate $p$ on $\alpha$, the filtered function $f \text{.filter } p$ equals the zero function if and only if $f(x) = 0$ for all $x$ satisfying $p(x)$.
Finsupp.filter_eq_self_iff theorem
: f.filter p = f ↔ ∀ x, f x ≠ 0 → p x
Full source
theorem filter_eq_self_iff : f.filter p = f ↔ ∀ x, f x ≠ 0 → p x := by
  simp only [DFunLike.ext_iff, filter_eq_indicator, Set.indicator_apply_eq_self, Set.mem_setOf_eq,
    not_imp_comm]
Characterization of when filtering a finitely supported function preserves it: $f \text{.filter } p = f \leftrightarrow \forall x, f(x) \neq 0 \to p(x)$
Informal description
For a finitely supported function $f \colon \alpha \to M$ and a predicate $p$ on $\alpha$, the filtered function $f \text{.filter } p$ equals $f$ if and only if for every $x \in \alpha$, if $f(x) \neq 0$ then $p(x)$ holds.
Finsupp.filter_apply_pos theorem
{a : α} (h : p a) : f.filter p a = f a
Full source
@[simp]
theorem filter_apply_pos {a : α} (h : p a) : f.filter p a = f a := if_pos h
Filtered Function Evaluation at Satisfying Point: $(f \text{ filter } p)(a) = f(a)$ when $p(a)$
Informal description
For any element $a \in \alpha$ and a finitely supported function $f : \alpha \to M$, if the predicate $p(a)$ holds, then the filtered function $(f \text{ filter } p)(a) = f(a)$.
Finsupp.filter_apply_neg theorem
{a : α} (h : ¬p a) : f.filter p a = 0
Full source
@[simp]
theorem filter_apply_neg {a : α} (h : ¬p a) : f.filter p a = 0 := if_neg h
Filtered Function Vanishes at Non-Satisfying Points
Informal description
For any element $a \in \alpha$ and a finitely supported function $f : \alpha \to M$, if the predicate $p(a)$ does not hold, then the filtered function $(f \text{ filter } p)(a) = 0$.
Finsupp.support_filter theorem
: (f.filter p).support = {x ∈ f.support | p x}
Full source
@[simp]
theorem support_filter : (f.filter p).support = {x ∈ f.support | p x} := rfl
Support of Filtered Finitely Supported Function
Informal description
For any finitely supported function $f \colon \alpha \to M$ and predicate $p$ on $\alpha$, the support of the filtered function $f \text{ filter } p$ is equal to the set of elements in the support of $f$ that satisfy $p$, i.e., $$\text{support}(f \text{ filter } p) = \{x \in \text{support}(f) \mid p(x)\}.$$
Finsupp.filter_zero theorem
: (0 : α →₀ M).filter p = 0
Full source
theorem filter_zero : (0 : α →₀ M).filter p = 0 := by
  classical rw [← support_eq_empty, support_filter, support_zero, Finset.filter_empty]
Filtering the Zero Function Yields Zero
Informal description
For any predicate $p$ on $\alpha$, the filtered function of the zero function $0 \colon \alpha \to_{\text{f}} M$ with respect to $p$ is equal to the zero function, i.e., $0 \text{ filter } p = 0$.
Finsupp.filter_single_of_pos theorem
{a : α} {b : M} (h : p a) : (single a b).filter p = single a b
Full source
@[simp]
theorem filter_single_of_pos {a : α} {b : M} (h : p a) : (single a b).filter p = single a b :=
  (filter_eq_self_iff _ _).2 fun _ hx => (single_apply_ne_zero.1 hx).1.symm ▸ h
Filtering a Single-Point Finitely Supported Function with a True Predicate Preserves It
Informal description
For any element $a$ in $\alpha$ and any element $b$ in $M$, if the predicate $p$ holds at $a$, then filtering the finitely supported function $\text{single } a b$ by $p$ yields $\text{single } a b$ itself.
Finsupp.filter_single_of_neg theorem
{a : α} {b : M} (h : ¬p a) : (single a b).filter p = 0
Full source
@[simp]
theorem filter_single_of_neg {a : α} {b : M} (h : ¬p a) : (single a b).filter p = 0 :=
  (filter_eq_zero_iff _ _).2 fun _ hpx =>
    single_apply_eq_zero.2 fun hxa => absurd hpx (hxa.symm ▸ h)
Filtered Single Function Vanishes When Predicate Fails
Informal description
For any element $a$ of type $\alpha$, any element $b$ of type $M$ with a zero element, and any predicate $p$ on $\alpha$, if $p(a)$ does not hold, then the filtered function $(single\ a\ b).filter\ p$ is equal to the zero function.
Finsupp.prod_filter_index theorem
[CommMonoid N] (g : α → M → N) : (f.filter p).prod g = ∏ x ∈ (f.filter p).support, g x (f x)
Full source
@[to_additive]
theorem prod_filter_index [CommMonoid N] (g : α → M → N) :
    (f.filter p).prod g = ∏ x ∈ (f.filter p).support, g x (f x) := by
  classical
    refine Finset.prod_congr rfl fun x hx => ?_
    rw [support_filter, Finset.mem_filter] at hx
    rw [filter_apply_pos _ _ hx.2]
Product over Filtered Support of Finitely Supported Function
Informal description
Let $M$ be a type with a zero element, $N$ a commutative monoid, and $f \colon \alpha \to M$ a finitely supported function. For any predicate $p$ on $\alpha$ and any function $g \colon \alpha \to M \to N$, the product of $g$ over the filtered function $f \text{ filter } p$ satisfies $$ \prod_{x \in \text{support}(f \text{ filter } p)} g(x, f(x)) = (f \text{ filter } p).\text{prod } g. $$
Finsupp.prod_filter_mul_prod_filter_not theorem
[CommMonoid N] (g : α → M → N) : (f.filter p).prod g * (f.filter fun a => ¬p a).prod g = f.prod g
Full source
@[to_additive (attr := simp)]
theorem prod_filter_mul_prod_filter_not [CommMonoid N] (g : α → M → N) :
    (f.filter p).prod g * (f.filter fun a => ¬p a).prod g = f.prod g := by
  classical simp_rw [prod_filter_index, support_filter, Finset.prod_filter_mul_prod_filter_not,
    Finsupp.prod]
Product Decomposition over Filtered Support of Finitely Supported Function
Informal description
Let $M$ be a type with a zero element, $N$ a commutative monoid, and $f \colon \alpha \to M$ a finitely supported function. For any predicate $p$ on $\alpha$ and any function $g \colon \alpha \to M \to N$, the product of $g$ over the filtered function $f \text{ filter } p$ multiplied by the product over $f \text{ filter } (\lambda a, \neg p a)$ equals the product over the entire function $f$. That is, $$ \prod_{x \in \text{support}(f \text{ filter } p)} g(x, f(x)) \cdot \prod_{x \in \text{support}(f \text{ filter } (\lambda a, \neg p a))} g(x, f(x)) = \prod_{x \in \text{support}(f)} g(x, f(x)). $$
Finsupp.prod_div_prod_filter theorem
[CommGroup G] (g : α → M → G) : f.prod g / (f.filter p).prod g = (f.filter fun a => ¬p a).prod g
Full source
@[to_additive (attr := simp)]
theorem prod_div_prod_filter [CommGroup G] (g : α → M → G) :
    f.prod g / (f.filter p).prod g = (f.filter fun a => ¬p a).prod g :=
  div_eq_of_eq_mul' (prod_filter_mul_prod_filter_not _ _ _).symm
Quotient of Products over Filtered Supports in Finitely Supported Functions
Informal description
Let $G$ be a commutative group, $M$ a type with a zero element, and $f \colon \alpha \to M$ a finitely supported function. For any predicate $p$ on $\alpha$ and any function $g \colon \alpha \to M \to G$, the quotient of the product of $g$ over $f$ by the product over the filtered function $f \text{ filter } p$ equals the product over the filtered function $f \text{ filter } (\lambda a, \neg p a)$. That is, $$ \frac{\prod_{x \in \text{support}(f)} g(x, f(x))}{\prod_{x \in \text{support}(f \text{ filter } p)} g(x, f(x))} = \prod_{x \in \text{support}(f \text{ filter } (\lambda a, \neg p a))} g(x, f(x)). $$
Finsupp.filter_pos_add_filter_neg theorem
[AddZeroClass M] (f : α →₀ M) (p : α → Prop) [DecidablePred p] : (f.filter p + f.filter fun a => ¬p a) = f
Full source
theorem filter_pos_add_filter_neg [AddZeroClass M] (f : α →₀ M) (p : α → Prop) [DecidablePred p] :
    (f.filter p + f.filter fun a => ¬p a) = f :=
  DFunLike.coe_injective <| by
    simp only [coe_add, filter_eq_indicator]
    exact Set.indicator_self_add_compl { x | p x } f
Decomposition of Finitely Supported Function via Filtering
Informal description
For any finitely supported function $f \colon \alpha \to M$ where $M$ is an add-zero class, and any decidable predicate $p$ on $\alpha$, the sum of the filtered functions $f \text{.filter } p$ and $f \text{.filter } (\lambda a, \neg p a)$ equals $f$. That is, $$ f \text{.filter } p + f \text{.filter } (\lambda a, \neg p a) = f. $$
Finsupp.frange definition
(f : α →₀ M) : Finset M
Full source
/-- `frange f` is the image of `f` on the support of `f`. -/
def frange (f : α →₀ M) : Finset M :=
  haveI := Classical.decEq M
  Finset.image f f.support
Image of a finitely supported function on its support
Informal description
For a finitely supported function \( f : \alpha \to M \), `frange f` is the finite subset of \( M \) consisting of all non-zero values attained by \( f \) on its support.
Finsupp.mem_frange theorem
{f : α →₀ M} {y : M} : y ∈ f.frange ↔ y ≠ 0 ∧ ∃ x, f x = y
Full source
theorem mem_frange {f : α →₀ M} {y : M} : y ∈ f.frangey ∈ f.frange ↔ y ≠ 0 ∧ ∃ x, f x = y := by
  rw [frange, @Finset.mem_image _ _ (Classical.decEq _) _ f.support]
  exact ⟨fun ⟨x, hx1, hx2⟩ => ⟨hx2 ▸ mem_support_iff.1 hx1, x, hx2⟩, fun ⟨hy, x, hx⟩ =>
    ⟨x, mem_support_iff.2 (hx.symm ▸ hy), hx⟩⟩
Characterization of Membership in Finite Range of Finitely Supported Function
Informal description
For a finitely supported function $f \colon \alpha \to_{\text{f}} M$ and an element $y \in M$, $y$ belongs to the finite range `frange f` if and only if $y \neq 0$ and there exists some $x \in \alpha$ such that $f(x) = y$.
Finsupp.zero_not_mem_frange theorem
{f : α →₀ M} : (0 : M) ∉ f.frange
Full source
theorem zero_not_mem_frange {f : α →₀ M} : (0 : M) ∉ f.frange := fun H => (mem_frange.1 H).1 rfl
Zero Excluded from Finite Range of Finitely Supported Function
Informal description
For any finitely supported function $f \colon \alpha \to_{\text{f}} M$, the zero element $0 \in M$ does not belong to the finite range $\mathrm{frange}(f)$ of $f$.
Finsupp.frange_single theorem
{x : α} {y : M} : frange (single x y) ⊆ { y }
Full source
theorem frange_single {x : α} {y : M} : frangefrange (single x y) ⊆ {y} := fun r hr =>
  let ⟨t, ht1, ht2⟩ := mem_frange.1 hr
  ht2 ▸ by
    classical
      rw [single_apply] at ht2 ⊢
      split_ifs at ht2 ⊢
      · exact Finset.mem_singleton_self _
      · exact (t ht2.symm).elim
Finite range of a single-element finitely supported function is a subset of $\{y\}$
Informal description
For any element $x$ in $\alpha$ and any element $y$ in $M$, the finite range of the finitely supported function `single x y` is a subset of the singleton set $\{y\}$.
Finsupp.subtypeDomain definition
(p : α → Prop) (f : α →₀ M) : Subtype p →₀ M
Full source
/--
`subtypeDomain p f` is the restriction of the finitely supported function `f` to subtype `p`. -/
def subtypeDomain (p : α → Prop) (f : α →₀ M) : SubtypeSubtype p →₀ M where
  support :=
    haveI := Classical.decPred p
    f.support.subtype p
  toFun := f ∘ Subtype.val
  mem_support_toFun a := by simp only [@mem_subtype _ _ (Classical.decPred p), mem_support_iff]; rfl
Restriction of a finitely supported function to a subtype
Informal description
Given a predicate `p` on `α` and a finitely supported function `f : α →₀ M`, the function `subtypeDomain p f` is the restriction of `f` to the subtype `{x // p x}`, i.e., it maps each `x` in the subtype to `f x`. More formally, for any `a : {x // p x}`, we have `(subtypeDomain p f) a = f a.val`.
Finsupp.support_subtypeDomain theorem
[D : DecidablePred p] {f : α →₀ M} : (subtypeDomain p f).support = f.support.subtype p
Full source
@[simp]
theorem support_subtypeDomain [D : DecidablePred p] {f : α →₀ M} :
    (subtypeDomain p f).support = f.support.subtype p := by rw [Subsingleton.elim D] <;> rfl
Support of Restricted Finitely Supported Function Equals Subtype of Original Support
Informal description
For any finitely supported function $f \colon \alpha \to M$ and a decidable predicate $p$ on $\alpha$, the support of the restricted function $\text{subtypeDomain}_p(f)$ is equal to the subtype of the support of $f$ consisting of elements satisfying $p$. That is, $$\text{support}(\text{subtypeDomain}_p(f)) = \{x \in \text{support}(f) \mid p(x)\}.$$
Finsupp.subtypeDomain_apply theorem
{a : Subtype p} {v : α →₀ M} : (subtypeDomain p v) a = v a.val
Full source
@[simp]
theorem subtypeDomain_apply {a : Subtype p} {v : α →₀ M} : (subtypeDomain p v) a = v a.val :=
  rfl
Restriction of Finitely Supported Function Evaluates as Original Function on Subtype
Informal description
For any finitely supported function $v \colon \alpha \to M$ and any element $a$ in the subtype $\{x \mid p(x)\}$, the value of the restricted function $\text{subtypeDomain}_p(v)$ at $a$ is equal to the value of $v$ at $a.\text{val}$.
Finsupp.subtypeDomain_zero theorem
: subtypeDomain p (0 : α →₀ M) = 0
Full source
@[simp]
theorem subtypeDomain_zero : subtypeDomain p (0 : α →₀ M) = 0 :=
  rfl
Restriction of Zero Function to Subtype is Zero
Informal description
For any predicate $p$ on $\alpha$, the restriction of the zero function in $\alpha \to_{\text{f}} M$ to the subtype $\{x \mid p(x)\}$ is equal to the zero function in $\{x \mid p(x)\} \to_{\text{f}} M$. That is, $\text{subtypeDomain}_p(0) = 0$.
Finsupp.subtypeDomain_eq_iff_forall theorem
{f g : α →₀ M} : f.subtypeDomain p = g.subtypeDomain p ↔ ∀ x, p x → f x = g x
Full source
theorem subtypeDomain_eq_iff_forall {f g : α →₀ M} :
    f.subtypeDomain p = g.subtypeDomain p ↔ ∀ x, p x → f x = g x := by
  simp_rw [DFunLike.ext_iff, subtypeDomain_apply, Subtype.forall]
Equality of Restricted Finitely Supported Functions via Pointwise Equality on Subtype
Informal description
For any two finitely supported functions $f, g \colon \alpha \to M$, the restrictions of $f$ and $g$ to the subtype $\{x \mid p(x)\}$ are equal if and only if $f(x) = g(x)$ for all $x \in \alpha$ satisfying $p(x)$. In other words, $\text{subtypeDomain}_p(f) = \text{subtypeDomain}_p(g) \leftrightarrow \forall x, p(x) \to f(x) = g(x)$.
Finsupp.subtypeDomain_eq_iff theorem
{f g : α →₀ M} (hf : ∀ x ∈ f.support, p x) (hg : ∀ x ∈ g.support, p x) : f.subtypeDomain p = g.subtypeDomain p ↔ f = g
Full source
theorem subtypeDomain_eq_iff {f g : α →₀ M}
    (hf : ∀ x ∈ f.support, p x) (hg : ∀ x ∈ g.support, p x) :
    f.subtypeDomain p = g.subtypeDomain p ↔ f = g :=
  subtypeDomain_eq_iff_forall.trans
    ⟨fun H ↦ Finsupp.ext fun _a ↦ (em _).elim (H _ <| hf _ ·) fun haf ↦ (em _).elim (H _ <| hg _ ·)
        fun hag ↦ (not_mem_support_iff.mp haf).trans (not_mem_support_iff.mp hag).symm,
      fun H _ _ ↦ congr($H _)⟩
Equality of Finitely Supported Functions via Equality of Their Restrictions on Full-Support Subtype
Informal description
Let $f, g \colon \alpha \to_{\text{f}} M$ be finitely supported functions, and let $p$ be a predicate on $\alpha$. Suppose that for every $x$ in the support of $f$, $p(x)$ holds, and similarly for every $x$ in the support of $g$, $p(x)$ holds. Then the restrictions of $f$ and $g$ to the subtype $\{x \mid p(x)\}$ are equal if and only if $f = g$. In other words, under the given support conditions, $\text{subtypeDomain}_p(f) = \text{subtypeDomain}_p(g) \leftrightarrow f = g$.
Finsupp.subtypeDomain_eq_zero_iff' theorem
{f : α →₀ M} : f.subtypeDomain p = 0 ↔ ∀ x, p x → f x = 0
Full source
theorem subtypeDomain_eq_zero_iff' {f : α →₀ M} : f.subtypeDomain p = 0 ↔ ∀ x, p x → f x = 0 :=
  subtypeDomain_eq_iff_forall (g := 0)
Restriction to Subtype is Zero iff Function Vanishes on Subtype
Informal description
For any finitely supported function $f \colon \alpha \to M$, the restriction of $f$ to the subtype $\{x \mid p(x)\}$ is the zero function if and only if $f(x) = 0$ for all $x \in \alpha$ satisfying $p(x)$. In symbols: \[ f\big|_{\{x \mid p(x)\}} = 0 \leftrightarrow \forall x, p(x) \to f(x) = 0 \]
Finsupp.subtypeDomain_eq_zero_iff theorem
{f : α →₀ M} (hf : ∀ x ∈ f.support, p x) : f.subtypeDomain p = 0 ↔ f = 0
Full source
theorem subtypeDomain_eq_zero_iff {f : α →₀ M} (hf : ∀ x ∈ f.support, p x) :
    f.subtypeDomain p = 0 ↔ f = 0 :=
  subtypeDomain_eq_iff (g := 0) hf (by simp)
Zero Restriction Criterion for Finitely Supported Functions
Informal description
Let $f \colon \alpha \to_{\text{f}} M$ be a finitely supported function and suppose that for every $x$ in the support of $f$, the predicate $p(x)$ holds. Then the restriction of $f$ to the subtype $\{x \mid p(x)\}$ is the zero function if and only if $f$ itself is the zero function. In symbols: \[ f\big|_{\{x \mid p(x)\}} = 0 \leftrightarrow f = 0 \]
Finsupp.prod_subtypeDomain_index theorem
[CommMonoid N] {v : α →₀ M} {h : α → M → N} (hp : ∀ x ∈ v.support, p x) : (v.subtypeDomain p).prod (fun a b ↦ h a b) = v.prod h
Full source
@[to_additive]
theorem prod_subtypeDomain_index [CommMonoid N] {v : α →₀ M} {h : α → M → N}
    (hp : ∀ x ∈ v.support, p x) : (v.subtypeDomain p).prod (fun a b ↦ h a b) = v.prod h := by
  refine Finset.prod_bij (fun p _ ↦ p) ?_ ?_ ?_ ?_ <;> aesop
Product Equality for Restricted Finitely Supported Function
Informal description
Let $N$ be a commutative monoid, $v : \alpha \to₀ M$ a finitely supported function, and $h : \alpha \to M \to N$ a function. If for every $x$ in the support of $v$ the predicate $p(x)$ holds, then the product of $h$ over the restriction of $v$ to the subtype $\{x \mid p(x)\}$ equals the product of $h$ over $v$ itself. In symbols: \[ \prod_{(a : \{x \mid p(x)\})} h(a, v(a)) = \prod_{(a : \alpha)} h(a, v(a)) \]
Finsupp.subtypeDomain_add theorem
{v v' : α →₀ M} : (v + v').subtypeDomain p = v.subtypeDomain p + v'.subtypeDomain p
Full source
@[simp]
theorem subtypeDomain_add {v v' : α →₀ M} :
    (v + v').subtypeDomain p = v.subtypeDomain p + v'.subtypeDomain p :=
  ext fun _ => rfl
Additivity of Subtype Restriction for Finitely Supported Functions
Informal description
For any two finitely supported functions $v, v' \colon \alpha \to M$ and any predicate $p$ on $\alpha$, the restriction of their sum to the subtype $\{x \mid p(x)\}$ is equal to the sum of their restrictions. That is, \[ (v + v').\text{subtypeDomain}\, p = v.\text{subtypeDomain}\, p + v'.\text{subtypeDomain}\, p. \]
Finsupp.subtypeDomainAddMonoidHom definition
: (α →₀ M) →+ Subtype p →₀ M
Full source
/-- `subtypeDomain` but as an `AddMonoidHom`. -/
def subtypeDomainAddMonoidHom : (α →₀ M) →+ Subtype p →₀ M where
  toFun := subtypeDomain p
  map_zero' := subtypeDomain_zero
  map_add' _ _ := subtypeDomain_add
Additive monoid homomorphism for restriction to a subtype
Informal description
The additive monoid homomorphism version of `subtypeDomain`, which restricts a finitely supported function $f \colon \alpha \to M$ to the subtype $\{x \mid p(x)\}$ of $\alpha$. More precisely, given a predicate $p$ on $\alpha$, this homomorphism maps a finitely supported function $f$ to its restriction $f|_{\{x \mid p(x)\}}$, which is a finitely supported function on the subtype $\{x \mid p(x)\}$. The homomorphism preserves addition and maps the zero function to the zero function.
Finsupp.filterAddHom definition
(p : α → Prop) [DecidablePred p] : (α →₀ M) →+ α →₀ M
Full source
/-- `Finsupp.filter` as an `AddMonoidHom`. -/
def filterAddHom (p : α → Prop) [DecidablePred p] : (α →₀ M) →+ α →₀ M where
  toFun := filter p
  map_zero' := filter_zero p
  map_add' f g := DFunLike.coe_injective <| by
    simp only [filter_eq_indicator, coe_add]
    exact Set.indicator_add { x | p x } f g
Filtering finitely supported functions as an additive monoid homomorphism
Informal description
The additive monoid homomorphism version of `Finsupp.filter`, which takes a predicate $p$ on $\alpha$ and maps a finitely supported function $f \colon \alpha \to M$ to the finitely supported function that equals $f(a)$ when $p(a)$ holds and $0$ otherwise. More precisely, for a predicate $p$ on $\alpha$, this homomorphism sends a finitely supported function $f$ to the function defined by: \[ (\text{filterAddHom } p \, f)(a) = \begin{cases} f(a) & \text{if } p(a) \\ 0 & \text{otherwise} \end{cases} \] The homomorphism preserves addition and maps the zero function to the zero function.
Finsupp.filter_add theorem
[DecidablePred p] {v v' : α →₀ M} : (v + v').filter p = v.filter p + v'.filter p
Full source
@[simp]
theorem filter_add [DecidablePred p] {v v' : α →₀ M} :
    (v + v').filter p = v.filter p + v'.filter p :=
  (filterAddHom p).map_add v v'
Filtering Preserves Addition of Finitely Supported Functions
Informal description
For any predicate $p$ on $\alpha$ and any two finitely supported functions $v, v' \colon \alpha \to M$, the filtered version of their sum equals the sum of their filtered versions. That is, \[ (v + v').filter\, p = v.filter\, p + v'.filter\, p. \]
Finsupp.subtypeDomain_sum theorem
{s : Finset ι} {h : ι → α →₀ M} : (∑ c ∈ s, h c).subtypeDomain p = ∑ c ∈ s, (h c).subtypeDomain p
Full source
theorem subtypeDomain_sum {s : Finset ι} {h : ι → α →₀ M} :
    (∑ c ∈ s, h c).subtypeDomain p = ∑ c ∈ s, (h c).subtypeDomain p :=
  map_sum subtypeDomainAddMonoidHom _ s
Sum Commutes with Restriction to Subtype for Finitely Supported Functions
Informal description
For any finite set $s$ of indices and any family of finitely supported functions $h \colon \iota \to \alpha \to_{\text{f}} M$, the restriction of the sum of $h$ over $s$ to the subtype $\{x \mid p(x)\}$ is equal to the sum of the restrictions of each $h_c$ to the same subtype. In other words, for any predicate $p$ on $\alpha$, we have: \[ \left(\sum_{c \in s} h_c\right)\Big|_{\{x \mid p(x)\}} = \sum_{c \in s} \left(h_c\Big|_{\{x \mid p(x)\}}\right). \]
Finsupp.subtypeDomain_finsupp_sum theorem
[Zero N] {s : β →₀ N} {h : β → N → α →₀ M} : (s.sum h).subtypeDomain p = s.sum fun c d => (h c d).subtypeDomain p
Full source
theorem subtypeDomain_finsupp_sum [Zero N] {s : β →₀ N} {h : β → N → α →₀ M} :
    (s.sum h).subtypeDomain p = s.sum fun c d => (h c d).subtypeDomain p :=
  subtypeDomain_sum
Restriction to Subtype Commutes with Weighted Sum of Finitely Supported Functions
Informal description
For any finitely supported function $s \colon \beta \to_{\text{f}} N$ (where $N$ has a zero element) and any family of finitely supported functions $h \colon \beta \to N \to \alpha \to_{\text{f}} M$, the restriction to the subtype $\{x \mid p(x)\}$ of the sum of $h$ weighted by $s$ is equal to the sum over $s$ of the restrictions of $h(c)(d)$ to the same subtype. In other words, for any predicate $p$ on $\alpha$, we have: \[ \left(\sum_{(c,d) \in s} h(c)(d)\right)\Big|_{\{x \mid p(x)\}} = \sum_{(c,d) \in s} \left(h(c)(d)\Big|_{\{x \mid p(x)\}}\right). \]
Finsupp.filter_sum theorem
[DecidablePred p] (s : Finset ι) (f : ι → α →₀ M) : (∑ a ∈ s, f a).filter p = ∑ a ∈ s, filter p (f a)
Full source
theorem filter_sum [DecidablePred p] (s : Finset ι) (f : ι → α →₀ M) :
    (∑ a ∈ s, f a).filter p = ∑ a ∈ s, filter p (f a) :=
  map_sum (filterAddHom p) f s
Filtering Commutes with Summation of Finitely Supported Functions
Informal description
For any predicate $p$ on $\alpha$ (with a decidable decision procedure), any finite set $s$ of indices, and any family of finitely supported functions $f \colon \iota \to \alpha \to_{\text{f}} M$, the filtering of the sum of the functions $f$ over $s$ by $p$ is equal to the sum of the filtering of each $f(a)$ by $p$ over $s$. In other words: $$ \left(\sum_{a \in s} f(a)\right)\big|_{p} = \sum_{a \in s} \big(f(a)\big|_{p}\big) $$
Finsupp.filter_eq_sum theorem
(p : α → Prop) [DecidablePred p] (f : α →₀ M) : f.filter p = ∑ i ∈ f.support.filter p, single i (f i)
Full source
theorem filter_eq_sum (p : α → Prop) [DecidablePred p] (f : α →₀ M) :
    f.filter p = ∑ i ∈ f.support.filter p, single i (f i) :=
  (f.filter p).sum_single.symm.trans <|
    Finset.sum_congr rfl fun x hx => by
      rw [filter_apply_pos _ _ (mem_filter.1 hx).2]
Filtered Function as Sum of Single-Element Functions
Informal description
For any predicate $p$ on $\alpha$ and any finitely supported function $f \colon \alpha \to M$, the filtered function $f \text{ filter } p$ is equal to the sum of the single-element functions $\text{single } i (f i)$ over all $i$ in the intersection of the support of $f$ with the set of elements satisfying $p$. In other words: $$ f \text{ filter } p = \sum_{i \in \text{supp}(f) \cap \{x \mid p(x)\}} \text{single } i (f i) $$
Finsupp.subtypeDomain_neg theorem
: (-v).subtypeDomain p = -v.subtypeDomain p
Full source
@[simp]
theorem subtypeDomain_neg : (-v).subtypeDomain p = -v.subtypeDomain p :=
  ext fun _ => rfl
Negation Commutes with Subtype Restriction for Finitely Supported Functions
Informal description
For any finitely supported function $v \colon \alpha \to G$ (where $G$ has a negation operation preserving zero) and any predicate $p$ on $\alpha$, the restriction of $-v$ to the subtype $\{x \mid p(x)\}$ is equal to the negation of the restriction of $v$ to the same subtype. In other words: $$ (-v)\big|_{\{x \mid p(x)\}} = -\big(v\big|_{\{x \mid p(x)\}}\big) $$
Finsupp.subtypeDomain_sub theorem
: (v - v').subtypeDomain p = v.subtypeDomain p - v'.subtypeDomain p
Full source
@[simp]
theorem subtypeDomain_sub : (v - v').subtypeDomain p = v.subtypeDomain p - v'.subtypeDomain p :=
  ext fun _ => rfl
Restriction of Difference Equals Difference of Restrictions for Finitely Supported Functions
Informal description
For any predicate $p$ on $\alpha$ and any finitely supported functions $v, v' \colon \alpha \to M$, the restriction of the difference $v - v'$ to the subtype $\{x \mid p(x)\}$ is equal to the difference of the restrictions of $v$ and $v'$ to the same subtype. In other words: $$(v - v')|_{\{x \mid p(x)\}} = v|_{\{x \mid p(x)\}} - v'|_{\{x \mid p(x)\}}$$
Finsupp.filter_neg theorem
(p : α → Prop) [DecidablePred p] (f : α →₀ G) : filter p (-f) = -filter p f
Full source
@[simp]
theorem filter_neg (p : α → Prop) [DecidablePred p] (f : α →₀ G) : filter p (-f) = -filter p f :=
  (filterAddHom p : (_ →₀ G) →+ _).map_neg f
Negation Commutes with Filtering of Finitely Supported Functions
Informal description
For any predicate $p$ on $\alpha$ and any finitely supported function $f \colon \alpha \to G$ (where $G$ has a negation operation preserving zero), the filtered version of $-f$ under $p$ is equal to the negation of the filtered version of $f$ under $p$. In other words: $$ \text{filter } p \, (-f) = -(\text{filter } p \, f) $$
Finsupp.filter_sub theorem
(p : α → Prop) [DecidablePred p] (f₁ f₂ : α →₀ G) : filter p (f₁ - f₂) = filter p f₁ - filter p f₂
Full source
@[simp]
theorem filter_sub (p : α → Prop) [DecidablePred p] (f₁ f₂ : α →₀ G) :
    filter p (f₁ - f₂) = filter p f₁ - filter p f₂ :=
  (filterAddHom p : (_ →₀ G) →+ _).map_sub f₁ f₂
Filter Preserves Subtraction of Finitely Supported Functions
Informal description
For any predicate $p$ on $\alpha$ and any finitely supported functions $f_1, f_2 \colon \alpha \to G$, the filtered version of their difference equals the difference of their filtered versions. That is: $$ \text{filter } p (f_1 - f_2) = (\text{filter } p f_1) - (\text{filter } p f_2) $$
Finsupp.mem_support_multiset_sum theorem
[AddCommMonoid M] {s : Multiset (α →₀ M)} (a : α) : a ∈ s.sum.support → ∃ f ∈ s, a ∈ (f : α →₀ M).support
Full source
theorem mem_support_multiset_sum [AddCommMonoid M] {s : Multiset (α →₀ M)} (a : α) :
    a ∈ s.sum.support∃ f ∈ s, a ∈ (f : α →₀ M).support :=
  Multiset.induction_on s (fun h => False.elim (by simp at h))
    (by
      intro f s ih ha
      by_cases h : a ∈ f.support
      · exact ⟨f, Multiset.mem_cons_self _ _, h⟩
      · simp only [Multiset.sum_cons, mem_support_iff, add_apply, not_mem_support_iff.1 h,
          zero_add] at ha
        rcases ih (mem_support_iff.2 ha) with ⟨f', h₀, h₁⟩
        exact ⟨f', Multiset.mem_cons_of_mem h₀, h₁⟩)
Support of Multiset Sum of Finitely Supported Functions
Informal description
Let $M$ be an additive commutative monoid and let $s$ be a multiset of finitely supported functions from $\alpha$ to $M$. For any element $a \in \alpha$, if $a$ belongs to the support of the sum of all functions in $s$, then there exists a function $f \in s$ such that $a$ belongs to the support of $f$.
Finsupp.mem_support_finset_sum theorem
[AddCommMonoid M] {s : Finset ι} {h : ι → α →₀ M} (a : α) (ha : a ∈ (∑ c ∈ s, h c).support) : ∃ c ∈ s, a ∈ (h c).support
Full source
theorem mem_support_finset_sum [AddCommMonoid M] {s : Finset ι} {h : ι → α →₀ M} (a : α)
    (ha : a ∈ (∑ c ∈ s, h c).support) : ∃ c ∈ s, a ∈ (h c).support :=
  let ⟨_, hf, hfa⟩ := mem_support_multiset_sum a ha
  let ⟨c, hc, Eq⟩ := Multiset.mem_map.1 hf
  ⟨c, hc, Eq.symm ▸ hfa⟩
Support of Finite Sum of Finitely Supported Functions
Informal description
Let $M$ be an additive commutative monoid, $s$ a finite set of indices, and $h \colon \iota \to (\alpha \to_{\text{f}} M)$ a family of finitely supported functions from $\alpha$ to $M$. For any element $a \in \alpha$, if $a$ belongs to the support of the sum $\sum_{c \in s} h(c)$, then there exists an index $c \in s$ such that $a$ belongs to the support of $h(c)$.
Finsupp.curry definition
(f : α × β →₀ M) : α →₀ β →₀ M
Full source
/-- Given a finitely supported function `f` from a product type `α × β` to `γ`,
`curry f` is the "curried" finitely supported function from `α` to the type of
finitely supported functions from `β` to `γ`. -/
protected def curry (f : α × βα × β →₀ M) : α →₀ β →₀ M :=
  f.sum fun p c => single p.1 (single p.2 c)
Currying of finitely supported functions
Informal description
Given a finitely supported function $f \colon \alpha \times \beta \to M$, the curried function $\text{curry}\, f \colon \alpha \to (\beta \to_{\text{f}} M)$ is defined such that for each $x \in \alpha$, the function $\text{curry}\, f\, x$ is the finitely supported function from $\beta$ to $M$ given by $y \mapsto f(x, y)$. More precisely, $\text{curry}\, f$ is constructed by summing over the pairs $(x, y) \in \alpha \times \beta$ in the support of $f$, and for each such pair, creating a finitely supported function that maps $x$ to the finitely supported function that maps $y$ to $f(x, y)$ and is zero elsewhere.
Finsupp.curry_apply theorem
(f : α × β →₀ M) (x : α) (y : β) : f.curry x y = f (x, y)
Full source
@[simp]
theorem curry_apply (f : α × βα × β →₀ M) (x : α) (y : β) : f.curry x y = f (x, y) := by
  classical
    have : ∀ b : α × β, single b.fst (single b.snd (f b)) x y = if b = (x, y) then f b else 0 := by
      rintro ⟨b₁, b₂⟩
      simp only [ne_eq, single_apply, Prod.ext_iff, ite_and]
      split_ifs <;> simp [single_apply, *]
    rw [Finsupp.curry, sum_apply, sum_apply, sum_eq_single, this, if_pos rfl]
    · intro b _ b_ne
      rw [this b, if_neg b_ne]
    · intro _
      rw [single_zero, single_zero, coe_zero, Pi.zero_apply, coe_zero, Pi.zero_apply]
Currying Preserves Function Values: $(\text{curry}\, f)(x)(y) = f(x, y)$
Informal description
For any finitely supported function $f \colon \alpha \times \beta \to M$ and any elements $x \in \alpha$, $y \in \beta$, the value of the curried function $\text{curry}\, f$ at $x$ and $y$ is equal to the value of $f$ at the pair $(x, y)$, i.e., $(\text{curry}\, f)(x)(y) = f(x, y)$.
Finsupp.sum_curry_index theorem
(f : α × β →₀ M) (g : α → β → M → N) (hg₀ : ∀ a b, g a b 0 = 0) (hg₁ : ∀ a b c₀ c₁, g a b (c₀ + c₁) = g a b c₀ + g a b c₁) : (f.curry.sum fun a f => f.sum (g a)) = f.sum fun p c => g p.1 p.2 c
Full source
theorem sum_curry_index (f : α × βα × β →₀ M) (g : α → β → M → N) (hg₀ : ∀ a b, g a b 0 = 0)
    (hg₁ : ∀ a b c₀ c₁, g a b (c₀ + c₁) = g a b c₀ + g a b c₁) :
    (f.curry.sum fun a f => f.sum (g a)) = f.sum fun p c => g p.1 p.2 c := by
  rw [Finsupp.curry]
  trans
  · exact
      sum_sum_index (fun a => sum_zero_index) fun a b₀ b₁ =>
        sum_add_index' (fun a => hg₀ _ _) fun c d₀ d₁ => hg₁ _ _ _ _
  congr; funext p c
  trans
  · exact sum_single_index sum_zero_index
  exact sum_single_index (hg₀ _ _)
Summation Equality for Curried Finitely Supported Functions
Informal description
Let $f \colon \alpha \times \beta \to_{\text{f}} M$ be a finitely supported function and $g \colon \alpha \to \beta \to M \to N$ be a function such that: 1. $g$ preserves zero: $g(a, b, 0) = 0$ for all $a \in \alpha$ and $b \in \beta$, 2. $g$ is additive in its third argument: $g(a, b, c_0 + c_1) = g(a, b, c_0) + g(a, b, c_1)$ for all $a \in \alpha$, $b \in \beta$, and $c_0, c_1 \in M$. Then the sum over the curried function $\text{curry}\, f$ satisfies: \[ \sum_{a \in \alpha} \left( \sum_{b \in \beta} g(a, b, f(a, b)) \right) = \sum_{(a, b) \in \alpha \times \beta} g(a, b, f(a, b)). \]
Finsupp.uncurry definition
(f : α →₀ β →₀ M) : α × β →₀ M
Full source
/-- Given a finitely supported function `f` from `α` to the type of
finitely supported functions from `β` to `M`,
`uncurry f` is the "uncurried" finitely supported function from `α × β` to `M`. -/
protected def uncurry (f : α →₀ β →₀ M) : α × βα × β →₀ M :=
  f.sum fun a g => g.sum fun b c => single (a, b) c
Uncurrying of finitely supported functions
Informal description
Given a finitely supported function $f$ from $\alpha$ to the type of finitely supported functions from $\beta$ to $M$, the function $\text{uncurry}\, f$ is the finitely supported function from $\alpha \times \beta$ to $M$ defined by summing the contributions of all pairs $(a, b)$ where $f(a)(b)$ is non-zero. Specifically, for each $a \in \alpha$ and $g = f(a) \in \beta \to_{\text{f}} M$, and for each $b \in \beta$ with $c = g(b) \neq 0$, the pair $(a, b)$ is mapped to $c$ in the resulting function.
Finsupp.uncurry_apply_pair theorem
(f : α →₀ β →₀ M) (x : α) (y : β) : f.uncurry (x, y) = f x y
Full source
@[simp]
protected theorem uncurry_apply_pair (f : α →₀ β →₀ M) (x : α) (y : β) :
    f.uncurry (x, y) = f x y := by
  rw [← curry_apply (f.uncurry) x y]
  simp only [Finsupp.curry, Finsupp.uncurry, sum_sum_index, single_zero, single_add,
    forall_true_iff, sum_single_index, single_zero, ← single_sum, sum_single]
Uncurrying Preserves Function Values: $(\text{uncurry}\, f)(x, y) = f(x)(y)$
Informal description
For any finitely supported function $f \colon \alpha \to (\beta \to_{\text{f}} M)$ and any elements $x \in \alpha$, $y \in \beta$, the value of the uncurried function $\text{uncurry}\, f$ at the pair $(x, y)$ is equal to the value of $f(x)$ at $y$, i.e., $(\text{uncurry}\, f)(x, y) = f(x)(y)$.
Finsupp.curry_uncurry theorem
(f : α →₀ β →₀ M) : f.uncurry.curry = f
Full source
@[simp]
theorem curry_uncurry (f : α →₀ β →₀ M) : f.uncurry.curry = f := by
  ext a b
  rw [curry_apply, Finsupp.uncurry_apply_pair]
Curry-Uncurry Identity for Finitely Supported Functions: $\text{curry} \circ \text{uncurry} = \text{id}$
Informal description
For any finitely supported function $f \colon \alpha \to (\beta \to_{\text{f}} M)$, the composition of uncurrying followed by currying returns the original function, i.e., $\text{curry}(\text{uncurry}\, f) = f$.
Finsupp.uncurry_curry theorem
(f : α × β →₀ M) : f.curry.uncurry = f
Full source
@[simp]
theorem uncurry_curry (f : α × βα × β →₀ M) : f.curry.uncurry = f := by
  ext ⟨a, b⟩
  rw [Finsupp.uncurry_apply_pair, curry_apply]
Uncurry-Curry Identity for Finitely Supported Functions: $\text{uncurry} \circ \text{curry} = \text{id}$
Informal description
For any finitely supported function $f \colon \alpha \times \beta \to M$, the composition of currying followed by uncurrying returns the original function, i.e., $\text{uncurry}(\text{curry}\, f) = f$.
Finsupp.finsuppProdEquiv definition
: (α × β →₀ M) ≃ (α →₀ β →₀ M)
Full source
/-- `finsuppProdEquiv` defines the `Equiv` between `((α × β) →₀ M)` and `(α →₀ (β →₀ M))` given by
currying and uncurrying. -/
def finsuppProdEquiv : (α × β →₀ M) ≃ (α →₀ β →₀ M) where
  toFun := Finsupp.curry
  invFun := Finsupp.uncurry
  left_inv := uncurry_curry
  right_inv := curry_uncurry
Equivalence between finitely supported functions on a product and curried finitely supported functions
Informal description
The equivalence `finsuppProdEquiv` establishes a bijection between finitely supported functions from $\alpha \times \beta$ to $M$ and finitely supported functions from $\alpha$ to finitely supported functions from $\beta$ to $M$. The bijection is given by currying (converting a function of two variables into a function returning a function) and uncurrying (converting a function returning a function into a function of two variables), with the properties that uncurrying after currying returns the original function and vice versa.
Finsupp.filter_curry theorem
(f : α × β →₀ M) (p : α → Prop) [DecidablePred p] : (f.filter fun a : α × β => p a.1).curry = f.curry.filter p
Full source
theorem filter_curry (f : α × βα × β →₀ M) (p : α → Prop) [DecidablePred p] :
    (f.filter fun a : α × β => p a.1).curry = f.curry.filter p := by
  classical
    rw [Finsupp.curry, Finsupp.curry, Finsupp.sum, Finsupp.sum, filter_sum, support_filter,
      sum_filter]
    refine Finset.sum_congr rfl ?_
    rintro ⟨a₁, a₂⟩ _
    split_ifs with h
    · rw [filter_apply_pos, filter_single_of_pos] <;> exact h
    · rwa [filter_single_of_neg]
Commutation of Currying and Filtering for Finitely Supported Functions
Informal description
For any finitely supported function $f \colon \alpha \times \beta \to M$ and any predicate $p \colon \alpha \to \text{Prop}$ (with a decidable decision procedure), the currying of the filtered function $f$ (where filtering is applied to the first component via $p$) equals the filtering of the curried function $f$ by $p$. In other words: $$ \text{curry}\big(f \text{ filter } (a \mapsto p(a_1))\big) = (\text{curry } f) \text{ filter } p $$
Finsupp.support_curry theorem
[DecidableEq α] (f : α × β →₀ M) : f.curry.support ⊆ f.support.image Prod.fst
Full source
theorem support_curry [DecidableEq α] (f : α × βα × β →₀ M) :
    f.curry.support ⊆ f.support.image Prod.fst := by
  rw [← Finset.biUnion_singleton]
  refine Finset.Subset.trans support_sum ?_
  exact Finset.biUnion_mono fun a _ => support_single_subset
Support of Curried Function is Contained in Projection of Original Support
Informal description
For any finitely supported function $f \colon \alpha \times \beta \to M$, where $\alpha$ has decidable equality, the support of the curried function $\operatorname{curry} f \colon \alpha \to (\beta \to_{\text{f}} M)$ is contained in the image under the first projection of the support of $f$. In other words, if $x$ is in the support of $\operatorname{curry} f$, then there exists some $y \in \beta$ such that $(x, y)$ is in the support of $f$.
Finsupp.sumElim definition
{α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) : α ⊕ β →₀ γ
Full source
/-- `Finsupp.sumElim f g` maps `inl x` to `f x` and `inr y` to `g y`. -/
@[simps support]
def sumElim {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) : α ⊕ βα ⊕ β →₀ γ where
  support := f.support.disjSum g.support
  toFun := Sum.elim f g
  mem_support_toFun := by simp
Sum elimination for finitely supported functions
Informal description
Given finitely supported functions $f \colon \alpha \to \gamma$ and $g \colon \beta \to \gamma$ (where $\gamma$ has a zero element), the function `Finsupp.sumElim f g` is the finitely supported function from the sum type $\alpha \oplus \beta$ to $\gamma$ that maps $\text{inl}(x)$ to $f(x)$ and $\text{inr}(y)$ to $g(y)$. The support of this function is the disjoint union of the supports of $f$ and $g$.
Finsupp.coe_sumElim theorem
{α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) : ⇑(sumElim f g) = Sum.elim f g
Full source
@[simp, norm_cast]
theorem coe_sumElim {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) :
    ⇑(sumElim f g) = Sum.elim f g :=
  rfl
Underlying Function of Sum Elimination Equals Pointwise Sum Elimination
Informal description
For any types $\alpha$, $\beta$, and $\gamma$ with a zero element in $\gamma$, given finitely supported functions $f \colon \alpha \to \gamma$ and $g \colon \beta \to \gamma$, the underlying function of the sum elimination $\operatorname{sumElim} f g$ is equal to the pointwise sum elimination of $f$ and $g$. That is, for all $x \in \alpha \oplus \beta$, \[ (\operatorname{sumElim} f g)(x) = \operatorname{Sum.elim} f g (x). \]
Finsupp.sumElim_apply theorem
{α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : α ⊕ β) : sumElim f g x = Sum.elim f g x
Full source
theorem sumElim_apply {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : α ⊕ β) :
    sumElim f g x = Sum.elim f g x :=
  rfl
Evaluation of Sum Elimination for Finitely Supported Functions
Informal description
For any types $\alpha$, $\beta$, and $\gamma$ with a zero element in $\gamma$, given finitely supported functions $f \colon \alpha \to \gamma$ and $g \colon \beta \to \gamma$, and any element $x$ in the sum type $\alpha \oplus \beta$, the evaluation of the sum elimination function $\operatorname{sumElim} f g$ at $x$ is equal to the elimination of $f$ and $g$ at $x$, i.e., \[ \operatorname{sumElim} f g (x) = \operatorname{Sum.elim} f g (x). \]
Finsupp.sumElim_inl theorem
{α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : α) : sumElim f g (Sum.inl x) = f x
Full source
theorem sumElim_inl {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : α) :
    sumElim f g (Sum.inl x) = f x :=
  rfl
Evaluation of Sum Elimination on Left Injection
Informal description
For any types $\alpha$, $\beta$, and $\gamma$ with a zero element in $\gamma$, given finitely supported functions $f \colon \alpha \to \gamma$ and $g \colon \beta \to \gamma$, and any element $x \in \alpha$, the evaluation of the sum elimination function $\operatorname{sumElim} f g$ at the left injection $\operatorname{Sum.inl}(x)$ equals $f(x)$, i.e., \[ \operatorname{sumElim} f g (\operatorname{Sum.inl}(x)) = f(x). \]
Finsupp.sumElim_inr theorem
{α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : β) : sumElim f g (Sum.inr x) = g x
Full source
theorem sumElim_inr {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : β) :
    sumElim f g (Sum.inr x) = g x :=
  rfl
Evaluation of Sum Elimination on Right Injection
Informal description
For any types $\alpha$, $\beta$, and $\gamma$ with a zero element in $\gamma$, given finitely supported functions $f \colon \alpha \to \gamma$ and $g \colon \beta \to \gamma$, and any element $x \in \beta$, the evaluation of the sum elimination function $\operatorname{sumElim} f g$ at the right injection $\operatorname{Sum.inr}(x)$ equals $g(x)$, i.e., \[ \operatorname{sumElim} f g (\operatorname{Sum.inr}(x)) = g(x). \]
Finsupp.prod_sumElim theorem
{ι₁ ι₂ α M : Type*} [Zero α] [CommMonoid M] (f₁ : ι₁ →₀ α) (f₂ : ι₂ →₀ α) (g : ι₁ ⊕ ι₂ → α → M) : (f₁.sumElim f₂).prod g = f₁.prod (g ∘ Sum.inl) * f₂.prod (g ∘ Sum.inr)
Full source
@[to_additive]
lemma prod_sumElim {ι₁ ι₂ α M : Type*} [Zero α] [CommMonoid M]
    (f₁ : ι₁ →₀ α) (f₂ : ι₂ →₀ α) (g : ι₁ ⊕ ι₂ → α → M) :
    (f₁.sumElim f₂).prod g = f₁.prod (g ∘ Sum.inl) * f₂.prod (g ∘ Sum.inr) := by
  simp [Finsupp.prod, Finset.prod_disj_sum]
Product Decomposition for Sum Elimination of Finitely Supported Functions
Informal description
Let $\iota_1$, $\iota_2$, $\alpha$, and $M$ be types, where $\alpha$ has a zero element and $M$ is a commutative monoid. Given finitely supported functions $f_1 \colon \iota_1 \to \alpha$ and $f_2 \colon \iota_2 \to \alpha$, and a function $g \colon \iota_1 \oplus \iota_2 \to \alpha \to M$, the product of the sum elimination $\operatorname{sumElim} f_1 f_2$ with respect to $g$ equals the product of $f_1$ with respect to $g \circ \operatorname{Sum.inl}$ multiplied by the product of $f_2$ with respect to $g \circ \operatorname{Sum.inr}$. In other words, \[ (\operatorname{sumElim} f_1 f_2).\operatorname{prod} g = f_1.\operatorname{prod} (g \circ \operatorname{Sum.inl}) \cdot f_2.\operatorname{prod} (g \circ \operatorname{Sum.inr}). \]
Finsupp.sumFinsuppEquivProdFinsupp definition
{α β γ : Type*} [Zero γ] : (α ⊕ β →₀ γ) ≃ (α →₀ γ) × (β →₀ γ)
Full source
/-- The equivalence between `(α ⊕ β) →₀ γ` and `(α →₀ γ) × (β →₀ γ)`.

This is the `Finsupp` version of `Equiv.sum_arrow_equiv_prod_arrow`. -/
@[simps apply symm_apply]
def sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] : (α ⊕ β →₀ γ) ≃ (α →₀ γ) × (β →₀ γ) where
  toFun f :=
    ⟨f.comapDomain Sum.inl Sum.inl_injective.injOn,
      f.comapDomain Sum.inr Sum.inr_injective.injOn⟩
  invFun fg := sumElim fg.1 fg.2
  left_inv f := by
    ext ab
    rcases ab with a | b <;> simp
  right_inv fg := by ext <;> simp
Equivalence between finitely supported functions on a sum type and pairs of finitely supported functions
Informal description
The equivalence between finitely supported functions on a sum type $\alpha \oplus \beta$ and pairs of finitely supported functions on $\alpha$ and $\beta$. Specifically, it establishes a bijection between the type $(\alpha \oplus \beta) \to_0 \gamma$ and the product type $(\alpha \to_0 \gamma) \times (\beta \to_0 \gamma)$, where $\gamma$ has a zero element. The forward direction splits a function $f \colon \alpha \oplus \beta \to_0 \gamma$ into two functions: one obtained by restricting $f$ to $\alpha$ via $\operatorname{Sum.inl}$, and the other by restricting $f$ to $\beta$ via $\operatorname{Sum.inr}$. The inverse direction combines two functions $f_1 \colon \alpha \to_0 \gamma$ and $f_2 \colon \beta \to_0 \gamma$ into a single function on $\alpha \oplus \beta$ using $\operatorname{sumElim}$.
Finsupp.fst_sumFinsuppEquivProdFinsupp theorem
{α β γ : Type*} [Zero γ] (f : α ⊕ β →₀ γ) (x : α) : (sumFinsuppEquivProdFinsupp f).1 x = f (Sum.inl x)
Full source
theorem fst_sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] (f : α ⊕ βα ⊕ β →₀ γ) (x : α) :
    (sumFinsuppEquivProdFinsupp f).1 x = f (Sum.inl x) :=
  rfl
First Component of Sum-to-Product Finsupp Equivalence Evaluates to Inl Application
Informal description
For any types $\alpha$, $\beta$, and $\gamma$ with $\gamma$ having a zero element, and for any finitely supported function $f \colon \alpha \oplus \beta \to \gamma$, the first component of the pair obtained from the equivalence `sumFinsuppEquivProdFinsupp` applied to $f$ evaluated at $x \in \alpha$ equals $f$ evaluated at $\operatorname{Sum.inl}(x)$. In other words, if $(f_1, f_2) = \operatorname{sumFinsuppEquivProdFinsupp}(f)$, then $f_1(x) = f(\operatorname{Sum.inl}(x))$ for all $x \in \alpha$.
Finsupp.snd_sumFinsuppEquivProdFinsupp theorem
{α β γ : Type*} [Zero γ] (f : α ⊕ β →₀ γ) (y : β) : (sumFinsuppEquivProdFinsupp f).2 y = f (Sum.inr y)
Full source
theorem snd_sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] (f : α ⊕ βα ⊕ β →₀ γ) (y : β) :
    (sumFinsuppEquivProdFinsupp f).2 y = f (Sum.inr y) :=
  rfl
Second Component of Sum-to-Product Finsupp Equivalence Evaluates to Right Injection
Informal description
For any types $\alpha$, $\beta$, and $\gamma$ with a zero element in $\gamma$, and for any finitely supported function $f \colon \alpha \oplus \beta \to \gamma$, the second component of the pair obtained from the equivalence `sumFinsuppEquivProdFinsupp` applied to $f$ satisfies $(sumFinsuppEquivProdFinsupp\, f).2\, y = f (\operatorname{Sum.inr}\, y)$ for any $y \in \beta$.
Finsupp.sumFinsuppEquivProdFinsupp_symm_inl theorem
{α β γ : Type*} [Zero γ] (fg : (α →₀ γ) × (β →₀ γ)) (x : α) : (sumFinsuppEquivProdFinsupp.symm fg) (Sum.inl x) = fg.1 x
Full source
theorem sumFinsuppEquivProdFinsupp_symm_inl {α β γ : Type*} [Zero γ] (fg : (α →₀ γ) × (β →₀ γ))
    (x : α) : (sumFinsuppEquivProdFinsupp.symm fg) (Sum.inl x) = fg.1 x :=
  rfl
Inverse of Sum Equivalence for Finitely Supported Functions Evaluates Left Injection as First Component
Informal description
For any types $\alpha$, $\beta$, and $\gamma$ with a zero element in $\gamma$, given a pair of finitely supported functions $(f, g) \colon (\alpha \to_0 \gamma) \times (\beta \to_0 \gamma)$ and an element $x \in \alpha$, the evaluation of the inverse of the sum equivalence at $\operatorname{Sum.inl}(x)$ equals $f(x)$. That is, $\operatorname{sumFinsuppEquivProdFinsupp}^{-1}(f, g)(\operatorname{inl}(x)) = f(x)$.
Finsupp.sumFinsuppEquivProdFinsupp_symm_inr theorem
{α β γ : Type*} [Zero γ] (fg : (α →₀ γ) × (β →₀ γ)) (y : β) : (sumFinsuppEquivProdFinsupp.symm fg) (Sum.inr y) = fg.2 y
Full source
theorem sumFinsuppEquivProdFinsupp_symm_inr {α β γ : Type*} [Zero γ] (fg : (α →₀ γ) × (β →₀ γ))
    (y : β) : (sumFinsuppEquivProdFinsupp.symm fg) (Sum.inr y) = fg.2 y :=
  rfl
Evaluation of Combined Finitely Supported Function on Right Injection
Informal description
For any types $\alpha$, $\beta$, and $\gamma$ with a zero element in $\gamma$, given a pair of finitely supported functions $(f, g) \in (\alpha \to_0 \gamma) \times (\beta \to_0 \gamma)$ and an element $y \in \beta$, the evaluation of the inverse of the equivalence `sumFinsuppEquivProdFinsupp` at $(f, g)$ applied to $\operatorname{Sum.inr}(y)$ equals $g(y)$. In other words, if $h$ is the combined finitely supported function on $\alpha \oplus \beta$ obtained from $(f, g)$, then $h(\operatorname{Sum.inr}(y)) = g(y)$ for all $y \in \beta$.
Finsupp.sumFinsuppAddEquivProdFinsupp definition
{α β : Type*} : (α ⊕ β →₀ M) ≃+ (α →₀ M) × (β →₀ M)
Full source
/-- The additive equivalence between `(α ⊕ β) →₀ M` and `(α →₀ M) × (β →₀ M)`.

This is the `Finsupp` version of `Equiv.sum_arrow_equiv_prod_arrow`. -/
@[simps! apply symm_apply]
def sumFinsuppAddEquivProdFinsupp {α β : Type*} : (α ⊕ β →₀ M) ≃+ (α →₀ M) × (β →₀ M) :=
  { sumFinsuppEquivProdFinsupp with
    map_add' := by
      intros
      ext <;>
        simp only [Equiv.toFun_as_coe, Prod.fst_add, Prod.snd_add, add_apply,
          snd_sumFinsuppEquivProdFinsupp, fst_sumFinsuppEquivProdFinsupp] }
Additive equivalence between finitely supported functions on a sum type and pairs of finitely supported functions
Informal description
The additive equivalence between the type of finitely supported functions on a sum type $\alpha \oplus \beta$ and the product type of finitely supported functions on $\alpha$ and $\beta$. Specifically, it establishes a bijection between $(\alpha \oplus \beta) \to_0 M$ and $(\alpha \to_0 M) \times (\beta \to_0 M)$, where $M$ has a zero element, and this bijection preserves addition. The forward direction splits a function $f \colon \alpha \oplus \beta \to_0 M$ into two functions: one obtained by restricting $f$ to $\alpha$ via $\operatorname{Sum.inl}$, and the other by restricting $f$ to $\beta$ via $\operatorname{Sum.inr}$. The inverse direction combines two functions $f_1 \colon \alpha \to_0 M$ and $f_2 \colon \beta \to_0 M$ into a single function on $\alpha \oplus \beta$ using $\operatorname{sumElim}$.
Finsupp.fst_sumFinsuppAddEquivProdFinsupp theorem
{α β : Type*} (f : α ⊕ β →₀ M) (x : α) : (sumFinsuppAddEquivProdFinsupp f).1 x = f (Sum.inl x)
Full source
theorem fst_sumFinsuppAddEquivProdFinsupp {α β : Type*} (f : α ⊕ βα ⊕ β →₀ M) (x : α) :
    (sumFinsuppAddEquivProdFinsupp f).1 x = f (Sum.inl x) :=
  rfl
First Component of Additive Equivalence for Finitely Supported Functions on Sum Type Evaluates to Left Injection
Informal description
For any types $\alpha$ and $\beta$, and any finitely supported function $f \colon \alpha \oplus \beta \to_0 M$, the first component of the additive equivalence `sumFinsuppAddEquivProdFinsupp` applied to $f$ evaluated at $x \in \alpha$ is equal to $f(\operatorname{Sum.inl}(x))$. In other words, if $(f_1, f_2) = \text{sumFinsuppAddEquivProdFinsupp}(f)$, then $f_1(x) = f(\operatorname{Sum.inl}(x))$ for all $x \in \alpha$.
Finsupp.snd_sumFinsuppAddEquivProdFinsupp theorem
{α β : Type*} (f : α ⊕ β →₀ M) (y : β) : (sumFinsuppAddEquivProdFinsupp f).2 y = f (Sum.inr y)
Full source
theorem snd_sumFinsuppAddEquivProdFinsupp {α β : Type*} (f : α ⊕ βα ⊕ β →₀ M) (y : β) :
    (sumFinsuppAddEquivProdFinsupp f).2 y = f (Sum.inr y) :=
  rfl
Second Component of Additive Equivalence for Finitely Supported Functions on Sum Types
Informal description
For any finitely supported function $f \colon \alpha \oplus \beta \to_0 M$ and any element $y \in \beta$, the second component of the pair obtained from the additive equivalence applied to $f$ evaluated at $y$ is equal to $f$ evaluated at the right inclusion $\operatorname{Sum.inr}(y)$. In other words, if $(f_1, f_2) = \text{sumFinsuppAddEquivProdFinsupp}(f)$, then $f_2(y) = f(\operatorname{Sum.inr}(y))$.
Finsupp.sumFinsuppAddEquivProdFinsupp_symm_inl theorem
{α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (x : α) : (sumFinsuppAddEquivProdFinsupp.symm fg) (Sum.inl x) = fg.1 x
Full source
theorem sumFinsuppAddEquivProdFinsupp_symm_inl {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (x : α) :
    (sumFinsuppAddEquivProdFinsupp.symm fg) (Sum.inl x) = fg.1 x :=
  rfl
Inverse Additive Equivalence Recovers Left Component at Left Injection
Informal description
For any types $\alpha$ and $\beta$, and any pair of finitely supported functions $(f,g) \in (\alpha \to₀ M) \times (\beta \to₀ M)$, the inverse of the additive equivalence `sumFinsuppAddEquivProdFinsupp` evaluated at $\operatorname{Sum.inl}(x)$ for $x \in \alpha$ equals $f(x)$. In other words, the left component of the pair is recovered by applying the inverse equivalence to the left injection of an element from $\alpha$.
Finsupp.sumFinsuppAddEquivProdFinsupp_symm_inr theorem
{α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (y : β) : (sumFinsuppAddEquivProdFinsupp.symm fg) (Sum.inr y) = fg.2 y
Full source
theorem sumFinsuppAddEquivProdFinsupp_symm_inr {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (y : β) :
    (sumFinsuppAddEquivProdFinsupp.symm fg) (Sum.inr y) = fg.2 y :=
  rfl
Right Component Preservation in Inverse of Sum-to-Product Finsupp Equivalence
Informal description
For any types $\alpha$ and $\beta$, and any pair of finitely supported functions $(f,g) \in (\alpha \to_0 M) \times (\beta \to_0 M)$, the inverse of the additive equivalence `sumFinsuppAddEquivProdFinsupp` maps $(f,g)$ to a finitely supported function on $\alpha \oplus \beta$ such that for any $y \in \beta$, the value at $\operatorname{Sum.inr}(y)$ is equal to $g(y)$. In other words, if $h = \text{sumFinsuppAddEquivProdFinsupp}^{-1}(f,g)$, then $h(\operatorname{Sum.inr}(y)) = g(y)$ for all $y \in \beta$.
Finsupp.uniqueOfRight instance
[Subsingleton R] : Unique (α →₀ R)
Full source
/-- The `Finsupp` version of `Pi.unique`. -/
instance uniqueOfRight [Subsingleton R] : Unique (α →₀ R) :=
  DFunLike.coe_injective.unique
Uniqueness of Finitely Supported Functions into a Subsingleton
Informal description
For any type $\alpha$ and any type $R$ with a unique term (i.e., a subsingleton), the type of finitely supported functions $\alpha \to_{\text{f}} R$ (denoted $\alpha \to₀ R$) has a unique term.
Finsupp.uniqueOfLeft instance
[IsEmpty α] : Unique (α →₀ R)
Full source
/-- The `Finsupp` version of `Pi.uniqueOfIsEmpty`. -/
instance uniqueOfLeft [IsEmpty α] : Unique (α →₀ R) :=
  DFunLike.coe_injective.unique
Uniqueness of Finitely Supported Functions on Empty Domains
Informal description
For any type $\alpha$ that is empty and any type $R$, the type of finitely supported functions $\alpha \to_{\text{f}} R$ (denoted $\alpha \to₀ R$) has a unique term. This unique function is the zero function, which maps every element of $\alpha$ to the zero element of $R$.
Finsupp.piecewise definition
(f : Subtype P →₀ M) (g : { a // ¬P a } →₀ M) : α →₀ M
Full source
/-- Combine finitely supported functions over `{a // P a}` and `{a // ¬P a}`, by case-splitting on
`P a`. -/
@[simps]
def piecewise (f : SubtypeSubtype P →₀ M) (g : {a // ¬ P a}{a // ¬ P a} →₀ M) : α →₀ M where
  toFun a := if h : P a then f ⟨a, h⟩ else g ⟨a, h⟩
  support := (f.support.map (.subtype _)).disjUnion (g.support.map (.subtype _)) <| by
    simp_rw [Finset.disjoint_left, mem_map, forall_exists_index, Embedding.coe_subtype,
      Subtype.forall, Subtype.exists]
    rintro _ a ha ⟨-, rfl⟩ ⟨b, hb, -, rfl⟩
    exact hb ha
  mem_support_toFun a := by
    by_cases ha : P a <;> simp [ha]
Piecewise combination of finitely supported functions
Informal description
Given a predicate $P$ on a type $\alpha$, and finitely supported functions $f$ on the subtype $\{a \mid P a\}$ and $g$ on the subtype $\{a \mid \neg P a\}$, the function `piecewise` combines $f$ and $g$ into a finitely supported function on $\alpha$ by case-splitting on $P a$. Specifically, for each $a \in \alpha$, the value is $f(\langle a, h \rangle)$ if $P a$ holds (with witness $h$), and $g(\langle a, h \rangle)$ otherwise.
Finsupp.subtypeDomain_piecewise theorem
(f : Subtype P →₀ M) (g : { a // ¬P a } →₀ M) : subtypeDomain P (f.piecewise g) = f
Full source
@[simp]
theorem subtypeDomain_piecewise (f : SubtypeSubtype P →₀ M) (g : {a // ¬ P a}{a // ¬ P a} →₀ M) :
    subtypeDomain P (f.piecewise g) = f :=
  Finsupp.ext fun a => dif_pos a.prop
Restriction of Piecewise Function to Subtype Equals Original Function
Informal description
For any predicate $P$ on a type $\alpha$ and finitely supported functions $f \colon \{a \mid P a\} \to M$ and $g \colon \{a \mid \neg P a\} \to M$, the restriction of the piecewise function $f.piecewise\, g$ to the subtype $\{a \mid P a\}$ equals $f$. In other words, $\text{subtypeDomain}\, P\, (f.piecewise\, g) = f$.
Finsupp.subtypeDomain_not_piecewise theorem
(f : Subtype P →₀ M) (g : { a // ¬P a } →₀ M) : subtypeDomain (¬P ·) (f.piecewise g) = g
Full source
@[simp]
theorem subtypeDomain_not_piecewise (f : SubtypeSubtype P →₀ M) (g : {a // ¬ P a}{a // ¬ P a} →₀ M) :
    subtypeDomain (¬P ·) (f.piecewise g) = g :=
  Finsupp.ext fun a => dif_neg a.prop
Restriction of Piecewise Function to Complement Subtype Equals Second Component
Informal description
For any predicate $P$ on a type $\alpha$, and for any finitely supported functions $f$ on the subtype $\{a \mid P a\}$ and $g$ on the subtype $\{a \mid \neg P a\}$, the restriction of the piecewise combination $f.piecewise\, g$ to the subtype $\{a \mid \neg P a\}$ is equal to $g$. In other words, $\text{subtypeDomain}\, (\neg P \circ \cdot)\, (f.piecewise\, g) = g$.
Finsupp.extendDomain definition
(f : Subtype P →₀ M) : α →₀ M
Full source
/-- Extend the domain of a `Finsupp` by using `0` where `P x` does not hold. -/
@[simps! support toFun]
def extendDomain (f : SubtypeSubtype P →₀ M) : α →₀ M := piecewise f 0
Extension of a finitely supported function by zero
Informal description
Given a predicate $P$ on a type $\alpha$ and a finitely supported function $f$ defined on the subtype $\{a \mid P a\}$, the function `extendDomain` extends $f$ to a finitely supported function on $\alpha$ by setting it to zero outside the subtype. In other words, for any $a \in \alpha$, the value of `extendDomain f` at $a$ is $f(a)$ if $P a$ holds, and $0$ otherwise.
Finsupp.extendDomain_eq_embDomain_subtype theorem
(f : Subtype P →₀ M) : extendDomain f = embDomain (.subtype _) f
Full source
theorem extendDomain_eq_embDomain_subtype (f : SubtypeSubtype P →₀ M) :
    extendDomain f = embDomain (.subtype _) f := by
  ext a
  by_cases h : P a
  · refine Eq.trans ?_ (embDomain_apply (.subtype P) f (Subtype.mk a h)).symm
    simp [h]
  · rw [embDomain_notin_range, extendDomain_toFun, dif_neg h]
    simp [h]
Extension by Zero Equals Embedding via Subtype Inclusion
Informal description
For any finitely supported function $f$ defined on the subtype $\{a \mid P a\}$ of a type $\alpha$, the extension of $f$ to $\alpha$ by zero is equal to the embedding of $f$ via the canonical inclusion map from the subtype to $\alpha$. That is, $$ \text{extendDomain}\, f = \text{embDomain}\, (\cdot\text{.subtype}\, P)\, f. $$
Finsupp.support_extendDomain_subset theorem
(f : Subtype P →₀ M) : ↑(f.extendDomain).support ⊆ {x | P x}
Full source
theorem support_extendDomain_subset (f : SubtypeSubtype P →₀ M) :
    ↑(f.extendDomain).support ⊆ {x | P x} := by
  intro x
  rw [extendDomain_support, mem_coe, mem_map, Embedding.coe_subtype]
  rintro ⟨x, -, rfl⟩
  exact x.prop
Support of Extended Function is Contained in Predicate Set
Informal description
For any finitely supported function $f$ defined on the subtype $\{a \mid P a\}$, the support of its extension by zero to the entire type $\alpha$ is contained within the set $\{x \mid P x\}$. In other words, $\text{supp}(\text{extendDomain}(f)) \subseteq \{x \mid P x\}$.
Finsupp.subtypeDomain_extendDomain theorem
(f : Subtype P →₀ M) : subtypeDomain P f.extendDomain = f
Full source
@[simp]
theorem subtypeDomain_extendDomain (f : SubtypeSubtype P →₀ M) :
    subtypeDomain P f.extendDomain = f :=
  subtypeDomain_piecewise _ _
Restriction of Extended Function Equals Original Function
Informal description
For any finitely supported function $f$ defined on the subtype $\{a \mid P a\}$, the restriction of its extension by zero to the entire type $\alpha$ back to the subtype $\{a \mid P a\}$ equals $f$ itself. In other words, $\text{subtypeDomain}\, P\, (f.\text{extendDomain}) = f$.
Finsupp.extendDomain_subtypeDomain theorem
(f : α →₀ M) (hf : ∀ a ∈ f.support, P a) : (subtypeDomain P f).extendDomain = f
Full source
theorem extendDomain_subtypeDomain (f : α →₀ M) (hf : ∀ a ∈ f.support, P a) :
    (subtypeDomain P f).extendDomain = f := by
  ext a
  by_cases h : P a
  · exact dif_pos h
  · #adaptation_note /-- nightly-2024-06-18
    this `rw` was done by `dsimp`. -/
    rw [extendDomain_toFun]
    dsimp
    rw [if_neg h, eq_comm, ← not_mem_support_iff]
    refine mt ?_ h
    exact @hf _
Extension-Restriction Identity for Finitely Supported Functions
Informal description
Let $f \colon \alpha \to_{\text{f}} M$ be a finitely supported function and $P$ a predicate on $\alpha$ such that for every $a$ in the support of $f$, $P(a)$ holds. Then the extension by zero of the restriction of $f$ to the subtype $\{a \mid P(a)\}$ is equal to $f$ itself. In other words, $(f|_P).\text{extendDomain} = f$.
Finsupp.extendDomain_single theorem
(a : Subtype P) (m : M) : (single a m).extendDomain = single a.val m
Full source
@[simp]
theorem extendDomain_single (a : Subtype P) (m : M) :
    (single a m).extendDomain = single a.val m := by
  ext a'
  #adaptation_note /-- nightly-2024-06-18
  this `rw` was instead `dsimp only`. -/
  rw [extendDomain_toFun]
  obtain rfl | ha := eq_or_ne a.val a'
  · simp_rw [single_eq_same, dif_pos a.prop]
  · simp_rw [single_eq_of_ne ha, dite_eq_right_iff]
    intro h
    rw [single_eq_of_ne]
    simp [Subtype.ext_iff, ha]
Extension of Single Function Preserves Value: $\text{extendDomain}(\text{single } a \, m) = \text{single } a.val \, m$
Informal description
For any element $a$ in the subtype defined by a predicate $P$ and any element $m$ in $M$, the extension by zero of the finitely supported function $\text{single } a \, m$ (which is the function that maps $a$ to $m$ and all other elements to zero) is equal to the finitely supported function $\text{single } a.val \, m$ on the entire type $\alpha$.
Finsupp.restrictSupportEquiv definition
(s : Set α) (M : Type*) [AddCommMonoid M] : { f : α →₀ M // ↑f.support ⊆ s } ≃ (s →₀ M)
Full source
/-- Given an `AddCommMonoid M` and `s : Set α`, `restrictSupportEquiv s M` is the `Equiv`
between the subtype of finitely supported functions with support contained in `s` and
the type of finitely supported functions from `s`. -/
-- TODO: add [DecidablePred (· ∈ s)] as an assumption
@[simps] def restrictSupportEquiv (s : Set α) (M : Type*) [AddCommMonoid M] :
    { f : α →₀ M // ↑f.support ⊆ s }{ f : α →₀ M // ↑f.support ⊆ s } ≃ (s →₀ M) where
  toFun f := subtypeDomain (· ∈ s) f.1
  invFun f := letI := Classical.decPred (· ∈ s); ⟨f.extendDomain, support_extendDomain_subset _⟩
  left_inv f :=
    letI := Classical.decPred (· ∈ s); Subtype.ext <| extendDomain_subtypeDomain f.1 f.prop
  right_inv _ := letI := Classical.decPred (· ∈ s); subtypeDomain_extendDomain _
Equivalence between finitely supported functions with restricted support and functions on the subset
Informal description
Given an additive commutative monoid $M$ and a subset $s$ of a type $\alpha$, the equivalence `restrictSupportEquiv s M` establishes a bijection between: 1. The subtype of finitely supported functions $f \colon \alpha \to M$ whose support is contained in $s$ 2. The type of finitely supported functions $s \to M$ The forward direction restricts a function to $s$, while the inverse direction extends a function from $s$ to $\alpha$ by setting it to zero outside $s$.
Finsupp.domCongr definition
[AddCommMonoid M] (e : α ≃ β) : (α →₀ M) ≃+ (β →₀ M)
Full source
/-- Given `AddCommMonoid M` and `e : α ≃ β`, `domCongr e` is the corresponding `Equiv` between
`α →₀ M` and `β →₀ M`.

This is `Finsupp.equivCongrLeft` as an `AddEquiv`. -/
@[simps apply]
protected def domCongr [AddCommMonoid M] (e : α ≃ β) : (α →₀ M) ≃+ (β →₀ M) where
  toFun := equivMapDomain e
  invFun := equivMapDomain e.symm
  left_inv v := by
    simp only [← equivMapDomain_trans, Equiv.self_trans_symm]
    exact equivMapDomain_refl _
  right_inv := by
    intro v
    simp only [← equivMapDomain_trans, Equiv.symm_trans_self]
    exact equivMapDomain_refl _
  map_add' a b := by simp only [equivMapDomain_eq_mapDomain]; exact mapDomain_add
Additive equivalence of finitely supported functions under domain equivalence
Informal description
Given an additive commutative monoid $M$ and an equivalence $e : \alpha \simeq \beta$, the function `Finsupp.domCongr e` is an additive equivalence between the types of finitely supported functions $\alpha \to_0 M$ and $\beta \to_0 M$. It maps a finitely supported function $f : \alpha \to_0 M$ to the function $\beta \to_0 M$ defined by $b \mapsto f(e^{-1}(b))$, and its inverse maps $g : \beta \to_0 M$ to $\alpha \to_0 M$ defined by $a \mapsto g(e(a))$. This equivalence preserves addition pointwise.
Finsupp.domCongr_refl theorem
[AddCommMonoid M] : Finsupp.domCongr (Equiv.refl α) = AddEquiv.refl (α →₀ M)
Full source
@[simp]
theorem domCongr_refl [AddCommMonoid M] :
    Finsupp.domCongr (Equiv.refl α) = AddEquiv.refl (α →₀ M) :=
  AddEquiv.ext fun _ => equivMapDomain_refl _
Identity Domain Congruence Preserves Finitely Supported Functions
Informal description
For any additive commutative monoid $M$, the domain congruence transformation `Finsupp.domCongr` applied to the identity equivalence $\text{Equiv.refl}(\alpha)$ is equal to the identity additive equivalence on the type of finitely supported functions $\alpha \to_0 M$.
Finsupp.domCongr_symm theorem
[AddCommMonoid M] (e : α ≃ β) : (Finsupp.domCongr e).symm = (Finsupp.domCongr e.symm : (β →₀ M) ≃+ (α →₀ M))
Full source
@[simp]
theorem domCongr_symm [AddCommMonoid M] (e : α ≃ β) :
    (Finsupp.domCongr e).symm = (Finsupp.domCongr e.symm : (β →₀ M) ≃+ (α →₀ M)) :=
  AddEquiv.ext fun _ => rfl
Inverse of Domain Congruence Equivalence for Finitely Supported Functions
Informal description
Given an additive commutative monoid $M$ and an equivalence $e : \alpha \simeq \beta$, the inverse of the additive equivalence $\text{domCongr}\, e$ between finitely supported functions $\alpha \to_0 M$ and $\beta \to_0 M$ is equal to the additive equivalence $\text{domCongr}\, e^{-1}$ between $\beta \to_0 M$ and $\alpha \to_0 M$.
Finsupp.domCongr_trans theorem
[AddCommMonoid M] (e : α ≃ β) (f : β ≃ γ) : (Finsupp.domCongr e).trans (Finsupp.domCongr f) = (Finsupp.domCongr (e.trans f) : (α →₀ M) ≃+ _)
Full source
@[simp]
theorem domCongr_trans [AddCommMonoid M] (e : α ≃ β) (f : β ≃ γ) :
    (Finsupp.domCongr e).trans (Finsupp.domCongr f) =
      (Finsupp.domCongr (e.trans f) : (α →₀ M) ≃+ _) :=
  AddEquiv.ext fun _ => (equivMapDomain_trans _ _ _).symm
Composition of Domain Equivalences for Finitely Supported Functions
Informal description
Let $M$ be an additive commutative monoid, and let $e \colon \alpha \simeq \beta$ and $f \colon \beta \simeq \gamma$ be equivalences. Then the composition of the additive equivalences `Finsupp.domCongr e` and `Finsupp.domCongr f` is equal to the additive equivalence `Finsupp.domCongr (e.trans f)`. In other words, the following diagram commutes: \[ (\alpha \to₀ M) \simeq^+ (\beta \to₀ M) \simeq^+ (\gamma \to₀ M) = (\alpha \to₀ M) \simeq^+ (\gamma \to₀ M), \] where $\simeq^+$ denotes an additive equivalence of finitely supported function spaces.
Finsupp.split definition
(i : ι) : αs i →₀ M
Full source
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `M` and
an index element `i : ι`, `split l i` is the `i`th component of `l`,
a finitely supported function from `as i` to `M`.

This is the `Finsupp` version of `Sigma.curry`.
-/
def split (i : ι) : αs i →₀ M :=
  l.comapDomain (Sigma.mk i) fun _ _ _ _ hx => heq_iff_eq.1 (Sigma.mk.inj hx).2
Restriction of a finitely supported function on a sigma type to a component
Informal description
Given a finitely supported function \( l \) from the sigma type \( \Sigma (i : \iota), \alpha_i \) to \( M \) (where \( M \) has a zero element), and an index \( i \in \iota \), the function `split l i` is the finitely supported function from \( \alpha_i \) to \( M \) obtained by restricting \( l \) to the elements of the form \( (i, x) \) for \( x \in \alpha_i \). More precisely, for any \( x \in \alpha_i \), the value `split l i x` is equal to \( l(i, x) \). The support of `split l i` consists of those \( x \in \alpha_i \) for which \( l(i, x) \neq 0 \).
Finsupp.split_apply theorem
(i : ι) (x : αs i) : split l i x = l ⟨i, x⟩
Full source
theorem split_apply (i : ι) (x : αs i) : split l i x = l ⟨i, x⟩ := by
  dsimp only [split]
  rw [comapDomain_apply]
Evaluation of Restricted Finitely Supported Function on Sigma Type: $(\text{split}\,l\,i)(x) = l(i, x)$
Informal description
For a finitely supported function $l$ from the sigma type $\Sigma (i : \iota), \alpha_i$ to $M$ (where $M$ has a zero element), and for any index $i \in \iota$ and element $x \in \alpha_i$, the value of the restricted function $\text{split}\,l\,i$ at $x$ is equal to the value of $l$ at the pair $\langle i, x \rangle$, i.e., \[ (\text{split}\,l\,i)(x) = l(i, x). \]
Finsupp.splitSupport definition
(l : (Σ i, αs i) →₀ M) : Finset ι
Full source
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `β`,
`split_support l` is the finset of indices in `ι` that appear in the support of `l`. -/
def splitSupport (l : (Σ i, αs i) →₀ M) : Finset ι :=
  haveI := Classical.decEq ι
  l.support.image Sigma.fst
Support indices of a finitely supported function on a sigma type
Informal description
Given a finitely supported function \( l \) from the sigma type \( \Sigma (i : \iota), \alpha_i \) to \( M \), the function `splitSupport` returns the finite set of indices \( i \in \iota \) for which there exists some \( x \in \alpha_i \) such that \( l(i, x) \neq 0 \). In other words, it collects the first components of all pairs in the support of \( l \).
Finsupp.mem_splitSupport_iff_nonzero theorem
(i : ι) : i ∈ splitSupport l ↔ split l i ≠ 0
Full source
theorem mem_splitSupport_iff_nonzero (i : ι) : i ∈ splitSupport li ∈ splitSupport l ↔ split l i ≠ 0 := by
  classical rw [splitSupport, mem_image, Ne, ← support_eq_empty, ← Ne,
    ← Finset.nonempty_iff_ne_empty, split, comapDomain, Finset.Nonempty]
  simp only [exists_prop, Finset.mem_preimage, exists_and_right, exists_eq_right, mem_support_iff,
    Sigma.exists, Ne]
Characterization of Split Support Membership via Nonzero Restriction
Informal description
For a finitely supported function $l$ from the sigma type $\Sigma (i : \iota), \alpha_i$ to $M$ (where $M$ has a zero element), an index $i \in \iota$ belongs to the split support of $l$ if and only if the restricted function $\text{split}\,l\,i$ is not the zero function. In other words, $i \in \text{splitSupport}(l) \leftrightarrow \text{split}\,l\,i \neq 0$.
Finsupp.splitComp definition
[Zero N] (g : ∀ i, (αs i →₀ M) → N) (hg : ∀ i x, x = 0 ↔ g i x = 0) : ι →₀ N
Full source
/-- Given `l`, a finitely supported function from the sigma type `Σ i, αs i` to `β` and
an `ι`-indexed family `g` of functions from `(αs i →₀ β)` to `γ`, `split_comp` defines a
finitely supported function from the index type `ι` to `γ` given by composing `g i` with
`split l i`. -/
def splitComp [Zero N] (g : ∀ i, (αs i →₀ M) → N) (hg : ∀ i x, x = 0 ↔ g i x = 0) : ι →₀ N where
  support := splitSupport l
  toFun i := g i (split l i)
  mem_support_toFun := by
    intro i
    rw [mem_splitSupport_iff_nonzero, not_iff_not, hg]
Composition of finitely supported functions on a sigma type with component-wise functions
Informal description
Given a finitely supported function \( l \) from the sigma type \( \Sigma (i : \iota), \alpha_i \) to \( M \) (where \( M \) has a zero element), and a family of functions \( g_i : (\alpha_i \to_{\text{f}} M) \to N \) (for each \( i \in \iota \)) such that \( g_i(x) = 0 \) if and only if \( x = 0 \), the function `splitComp` constructs a finitely supported function from \( \iota \) to \( N \) defined by \( i \mapsto g_i(\text{split } l \ i) \). The support of this function consists of those indices \( i \) for which \( \text{split } l \ i \) is non-zero.
Finsupp.sigma_support theorem
: l.support = l.splitSupport.sigma fun i => (l.split i).support
Full source
theorem sigma_support : l.support = l.splitSupport.sigma fun i => (l.split i).support := by
  simp only [Finset.ext_iff, splitSupport, split, comapDomain, mem_image, mem_preimage,
    Sigma.forall, mem_sigma]
  tauto
Support Decomposition for Finitely Supported Functions on Sigma Types
Informal description
For a finitely supported function $l$ from the sigma type $\Sigma (i : \iota), \alpha_i$ to $M$, the support of $l$ is equal to the disjoint union over all indices $i$ in the split support of $l$ of the supports of the restricted functions $l.split\ i$. In other words, the support of $l$ can be expressed as: $$\text{supp}(l) = \bigsqcup_{i \in \text{splitSupport}(l)} \text{supp}(l.split\ i)$$
Finsupp.sigma_sum theorem
[AddCommMonoid N] (f : (Σ i : ι, αs i) → M → N) : l.sum f = ∑ i ∈ splitSupport l, (split l i).sum fun (a : αs i) b => f ⟨i, a⟩ b
Full source
theorem sigma_sum [AddCommMonoid N] (f : (Σ i : ι, αs i) → M → N) :
    l.sum f = ∑ i ∈ splitSupport l, (split l i).sum fun (a : αs i) b => f ⟨i, a⟩ b := by
  simp only [sum, sigma_support, sum_sigma, split_apply]
Sum Decomposition for Finitely Supported Functions on Sigma Types
Informal description
Let $M$ be a type with a zero element, $N$ be an additive commutative monoid, and $l \colon (\Sigma i : \iota, \alpha_i) \to_{\text{f}} M$ be a finitely supported function from a sigma type to $M$. For any function $f \colon (\Sigma i : \iota, \alpha_i) \to M \to N$, the sum of $f$ over the support of $l$ can be decomposed as: \[ \sum_{(i, a) \in \text{supp}(l)} f(i, a)(l(i, a)) = \sum_{i \in \text{splitSupport}(l)} \sum_{a \in \text{supp}(\text{split } l \ i)} f(i, a)(l(i, a)) \] where $\text{splitSupport}(l)$ is the finite set of indices $i$ for which $\text{split } l \ i$ is non-zero, and $\text{split } l \ i \colon \alpha_i \to_{\text{f}} M$ is the restriction of $l$ to the component $\alpha_i$.
Finsupp.sigmaFinsuppEquivPiFinsupp definition
: ((Σ j, ιs j) →₀ α) ≃ ∀ j, ιs j →₀ α
Full source
/-- On a `Fintype η`, `Finsupp.split` is an equivalence between `(Σ (j : η), ιs j) →₀ α`
and `Π j, (ιs j →₀ α)`.

This is the `Finsupp` version of `Equiv.Pi_curry`. -/
noncomputable def sigmaFinsuppEquivPiFinsupp : ((Σ j, ιs j) →₀ α) ≃ ∀ j, ιs j →₀ α where
  toFun := split
  invFun f :=
    onFinset (Finset.univ.sigma fun j => (f j).support) (fun ji => f ji.1 ji.2) fun _ hg =>
      Finset.mem_sigma.mpr ⟨Finset.mem_univ _, mem_support_iff.mpr hg⟩
  left_inv f := by
    ext
    simp [split]
  right_inv f := by
    ext
    simp [split]
Equivalence between finitely supported functions on a sigma type and product of finitely supported functions
Informal description
Given a finite type $\eta$ and a family of types $\iota_j$ indexed by $j \in \eta$, the equivalence `Finsupp.sigmaFinsuppEquivPiFinsupp` establishes a bijection between finitely supported functions from the sigma type $\Sigma (j : \eta), \iota_j$ to $\alpha$ and the product type $\Pi j, (\iota_j \to₀ \alpha)$ of finitely supported functions from each $\iota_j$ to $\alpha$. More precisely, for any finitely supported function $f$ on the sigma type, the corresponding element in the product type is obtained by restricting $f$ to each component $\iota_j$. Conversely, given a family of finitely supported functions $f_j \colon \iota_j \to₀ \alpha$, the corresponding finitely supported function on the sigma type is defined by combining these functions, with support contained in the union of the supports of the $f_j$'s.
Finsupp.sigmaFinsuppEquivPiFinsupp_apply theorem
(f : (Σ j, ιs j) →₀ α) (j i) : sigmaFinsuppEquivPiFinsupp f j i = f ⟨j, i⟩
Full source
@[simp]
theorem sigmaFinsuppEquivPiFinsupp_apply (f : (Σ j, ιs j) →₀ α) (j i) :
    sigmaFinsuppEquivPiFinsupp f j i = f ⟨j, i⟩ :=
  rfl
Pointwise Preservation of Function Values in Sigma-to-Product Finsupp Equivalence
Informal description
For any finitely supported function $f$ from the sigma type $\Sigma (j : \eta), \iota_j$ to $\alpha$, and for any $j \in \eta$ and $i \in \iota_j$, the value of the corresponding finitely supported function in the product type $\Pi j, (\iota_j \to₀ \alpha)$ at $j$ and $i$ is equal to the value of $f$ at the pair $\langle j, i \rangle$. In other words, the equivalence `sigmaFinsuppEquivPiFinsupp` preserves function values pointwise.
Finsupp.sigmaFinsuppAddEquivPiFinsupp definition
{α : Type*} {ιs : η → Type*} [AddMonoid α] : ((Σ j, ιs j) →₀ α) ≃+ ∀ j, ιs j →₀ α
Full source
/-- On a `Fintype η`, `Finsupp.split` is an additive equivalence between
`(Σ (j : η), ιs j) →₀ α` and `Π j, (ιs j →₀ α)`.

This is the `AddEquiv` version of `Finsupp.sigmaFinsuppEquivPiFinsupp`.
-/
noncomputable def sigmaFinsuppAddEquivPiFinsupp {α : Type*} {ιs : η → Type*} [AddMonoid α] :
    ((Σ j, ιs j) →₀ α) ≃+ ∀ j, ιs j →₀ α :=
  { sigmaFinsuppEquivPiFinsupp with
    map_add' := fun f g => by
      ext
      simp }
Additive equivalence between finitely supported functions on a sigma type and product of finitely supported functions
Informal description
Given a finite type $\eta$, a family of types $\iota_j$ indexed by $j \in \eta$, and an additive monoid $\alpha$, the additive equivalence `Finsupp.sigmaFinsuppAddEquivPiFinsupp` establishes a bijection between finitely supported functions from the sigma type $\Sigma (j : \eta), \iota_j$ to $\alpha$ and the product type $\Pi j, (\iota_j \to₀ \alpha)$ of finitely supported functions from each $\iota_j$ to $\alpha$. This equivalence preserves addition, meaning that the sum of two finitely supported functions on the sigma type corresponds to the pointwise sum of their images under the equivalence.
Finsupp.sigmaFinsuppAddEquivPiFinsupp_apply theorem
{α : Type*} {ιs : η → Type*} [AddMonoid α] (f : (Σ j, ιs j) →₀ α) (j i) : sigmaFinsuppAddEquivPiFinsupp f j i = f ⟨j, i⟩
Full source
@[simp]
theorem sigmaFinsuppAddEquivPiFinsupp_apply {α : Type*} {ιs : η → Type*} [AddMonoid α]
    (f : (Σ j, ιs j) →₀ α) (j i) : sigmaFinsuppAddEquivPiFinsupp f j i = f ⟨j, i⟩ :=
  rfl
Pointwise Preservation of Function Values in Sigma-to-Product Finsupp Equivalence
Informal description
Let $\alpha$ be an additive monoid, $\eta$ a finite type, and $\iota_j$ a family of types indexed by $j \in \eta$. For any finitely supported function $f \colon (\Sigma j, \iota_j) \to₀ \alpha$, the value of the corresponding function under the additive equivalence $\sigma FinsuppAddEquivPiFinsupp$ at any $j \in \eta$ and $i \in \iota_j$ is equal to $f(\langle j, i \rangle)$. In other words, the equivalence preserves function values pointwise, i.e., $(\sigma FinsuppAddEquivPiFinsupp\, f)\, j\, i = f \langle j, i \rangle$.