doc-next-gen

Mathlib.Data.Finsupp.Defs

Module docstring

{"# Type of functions with finite support

For any type α and any type M with zero, we define the type Finsupp α M (notation: α →₀ M) of finitely supported functions from α to M, i.e. the functions which are zero everywhere on α except on a finite set.

Functions with finite support are used (at least) in the following parts of the library:

  • MonoidAlgebra R M and AddMonoidAlgebra R M are defined as M →₀ R;

  • polynomials and multivariate polynomials are defined as AddMonoidAlgebras, hence they use Finsupp under the hood;

  • the linear combination of a family of vectors v i with coefficients f i (as used, e.g., to define linearly independent family LinearIndependent) is defined as a map Finsupp.linearCombination : (ι → M) → (ι →₀ R) →ₗ[R] M.

Some other constructions are naturally equivalent to α →₀ M with some α and M but are defined in a different way in the library:

  • Multiset α ≃+ α →₀ ℕ;
  • FreeAbelianGroup α ≃+ α →₀ ℤ.

Most of the theory assumes that the range is a commutative additive monoid. This gives us the big sum operator as a powerful way to construct Finsupp elements, which is defined in Mathlib.Algebra.BigOperators.Finsupp.Basic.

Many constructions based on α →₀ M are defs rather than abbrevs to avoid reusing unwanted type class instances. E.g., MonoidAlgebra, AddMonoidAlgebra, and types based on these two have non-pointwise multiplication.

Main declarations

  • Finsupp: The type of finitely supported functions from α to β.
  • Finsupp.onFinset: The restriction of a function to a Finset as a Finsupp.
  • Finsupp.mapRange: Composition of a ZeroHom with a Finsupp.
  • Finsupp.embDomain: Maps the domain of a Finsupp by an embedding.
  • Finsupp.zipWith: Postcomposition of two Finsupps with a function f such that f 0 0 = 0.

Notations

This file adds α →₀ M as a global notation for Finsupp α M.

We also use the following convention for Type* variables in this file

  • α, β, γ: types with no additional structure that appear as the first argument to Finsupp somewhere in the statement;

  • ι : an auxiliary index type;

  • M, M', N, P: types with Zero or (Add)(Comm)Monoid structure; M is also used for a (semi)module over a (semi)ring.

  • G, H: groups (commutative or not, multiplicative or additive);

  • R, S: (semi)rings.

Implementation notes

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

TODO

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

","### Basic declarations about Finsupp ","### Declarations about onFinset ","### Declarations about mapRange ","### Declarations about embDomain ","### Declarations about zipWith ","### Additive monoid structure on α →₀ M "}

Finsupp structure
(α : Type*) (M : Type*) [Zero M]
Full source
/-- `Finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that
  `f x = 0` for all but finitely many `x`. -/
structure Finsupp (α : Type*) (M : Type*) [Zero M] where
  /-- The support of a finitely supported function (aka `Finsupp`). -/
  support : Finset α
  /-- The underlying function of a bundled finitely supported function (aka `Finsupp`). -/
  toFun : α → M
  /-- The witness that the support of a `Finsupp` is indeed the exact locus where its
  underlying function is nonzero. -/
  mem_support_toFun : ∀ a, a ∈ supporta ∈ support ↔ toFun a ≠ 0
Finitely supported functions
Informal description
The structure `Finsupp α M`, denoted by `α →₀ M`, represents the type of functions from `α` to `M` with finite support, i.e., functions that are zero everywhere except on a finite subset of `α`. Here, `M` is required to have a zero element.
term_→₀_ definition
: Lean.TrailingParserDescr✝
Full source
@[inherit_doc]
infixr:25 " →₀ " => Finsupp
Finitely supported functions
Informal description
The notation `α →₀ M` represents the type of finitely supported functions from `α` to `M`, where `M` has a zero element. A function is finitely supported if it is zero everywhere on `α` except on a finite subset.
Finsupp.instFunLike instance
: FunLike (α →₀ M) α M
Full source
instance instFunLike : FunLike (α →₀ M) α M :=
  ⟨toFun, by
    rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g)
    congr
    ext a
    exact (hf _).trans (hg _).symm⟩
Function-Like Structure on Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $M$ with a zero element, the type $\alpha \to₀ M$ of finitely supported functions from $\alpha$ to $M$ is equipped with a function-like structure, meaning it can be treated as a function from $\alpha$ to $M$ with the property that it is zero everywhere except on a finite subset of $\alpha$.
Finsupp.ext theorem
{f g : α →₀ M} (h : ∀ a, f a = g a) : f = g
Full source
@[ext]
theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g :=
  DFunLike.ext _ _ h
Extensionality for Finitely Supported Functions
Informal description
For any two finitely supported functions $f, g \colon \alpha \to M$, if $f(a) = g(a)$ for all $a \in \alpha$, then $f = g$.
Finsupp.ne_iff theorem
{f g : α →₀ M} : f ≠ g ↔ ∃ a, f a ≠ g a
Full source
lemma ne_iff {f g : α →₀ M} : f ≠ gf ≠ g ↔ ∃ a, f a ≠ g a := DFunLike.ne_iff
Inequality Criterion for Finitely Supported Functions
Informal description
For any two finitely supported functions $f, g \colon \alpha \to M$, $f$ is not equal to $g$ if and only if there exists an element $a \in \alpha$ such that $f(a) \neq g(a)$.
Finsupp.coe_mk theorem
(f : α → M) (s : Finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f
Full source
@[simp, norm_cast]
theorem coe_mk (f : α → M) (s : Finset α) (h : ∀ a, a ∈ sa ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f :=
  rfl
Underlying Function of Constructed Finitely Supported Function
Informal description
For any function $f : \alpha \to M$ and finite subset $s \subseteq \alpha$ such that for all $a \in \alpha$, $a \in s$ if and only if $f(a) \neq 0$, the underlying function of the finitely supported function $\langle s, f, h \rangle : \alpha \to_{\text{f}} M$ is equal to $f$.
Finsupp.coe_zero theorem
: ⇑(0 : α →₀ M) = 0
Full source
@[simp, norm_cast] lemma coe_zero : ⇑(0 : α →₀ M) = 0 := rfl
Zero Function in Finitely Supported Functions is Constant Zero
Informal description
The zero function in the type of finitely supported functions $\alpha \to_{\text{f}} M$ (denoted $\alpha \to₀ M$) is equal to the constant zero function, i.e., $0 = \lambda (a : \alpha), 0$.
Finsupp.zero_apply theorem
{a : α} : (0 : α →₀ M) a = 0
Full source
theorem zero_apply {a : α} : (0 : α →₀ M) a = 0 :=
  rfl
Evaluation of Zero Function in Finitely Supported Functions
Informal description
For any element $a$ of type $\alpha$, the zero function in the type of finitely supported functions $\alpha \to_{\text{f}} M$ evaluates to zero at $a$, i.e., $0(a) = 0$.
Finsupp.support_zero theorem
: (0 : α →₀ M).support = ∅
Full source
@[simp]
theorem support_zero : (0 : α →₀ M).support =  :=
  rfl
Support of Zero Function is Empty
Informal description
For the zero function in the type of finitely supported functions $\alpha \to_{\text{f}} M$, the support (the set of points where the function is nonzero) is empty, i.e., $\text{supp}(0) = \emptyset$.
Finsupp.instInhabited instance
: Inhabited (α →₀ M)
Full source
instance instInhabited : Inhabited (α →₀ M) :=
  ⟨0⟩
Inhabitedness of Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $M$ with a zero element, the type of finitely supported functions $\alpha \to_{\text{f}} M$ (denoted $\alpha \to₀ M$) is inhabited.
Finsupp.mem_support_iff theorem
{f : α →₀ M} : ∀ {a : α}, a ∈ f.support ↔ f a ≠ 0
Full source
@[simp]
theorem mem_support_iff {f : α →₀ M} : ∀ {a : α}, a ∈ f.supporta ∈ f.support ↔ f a ≠ 0 :=
  @(f.mem_support_toFun)
Characterization of Support Membership for Finitely Supported Functions
Informal description
For any finitely supported function $f \colon \alpha \to_{\text{f}} M$ and any element $a \in \alpha$, the element $a$ belongs to the support of $f$ if and only if $f(a) \neq 0$.
Finsupp.fun_support_eq theorem
(f : α →₀ M) : Function.support f = f.support
Full source
@[simp, norm_cast]
theorem fun_support_eq (f : α →₀ M) : Function.support f = f.support :=
  Set.ext fun _x => mem_support_iff.symm
Support Equality for Finitely Supported Functions
Informal description
For any finitely supported function $f \colon \alpha \to_{\text{f}} M$, the support of $f$ as a function (i.e., the set $\{a \in \alpha \mid f(a) \neq 0\}$) is equal to the finite support set $f.\text{support}$ associated with the `Finsupp` structure.
Finsupp.not_mem_support_iff theorem
{f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0
Full source
theorem not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.supporta ∉ f.support ↔ f a = 0 :=
  not_iff_comm.1 mem_support_iff.symm
Support Exclusion Criterion for Finitely Supported Functions
Informal description
For any finitely supported function $f \colon \alpha \to_{\text{f}} M$ and any element $a \in \alpha$, the element $a$ does not belong to the support of $f$ if and only if $f(a) = 0$.
Finsupp.coe_eq_zero theorem
{f : α →₀ M} : (f : α → M) = 0 ↔ f = 0
Full source
@[simp, norm_cast]
theorem coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq]
Characterization of Zero in Finitely Supported Functions: $f = 0 \leftrightarrow f \equiv 0$
Informal description
For any finitely supported function $f \colon \alpha \to_{\text{f}} M$, the function $f$ is identically zero if and only if $f$ is equal to the zero element in the type of finitely supported functions $\alpha \to_{\text{f}} M$.
Finsupp.ext_iff' theorem
{f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x
Full source
theorem ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x :=
  ⟨fun h => h ▸ ⟨rfl, fun _ _ => rfl⟩, fun ⟨h₁, h₂⟩ =>
    ext fun a => by
      classical
      exact if h : a ∈ f.support then h₂ a h else by
        have hf : f a = 0 := not_mem_support_iff.1 h
        have hg : g a = 0 := by rwa [h₁, not_mem_support_iff] at h
        rw [hf, hg]⟩
Support and Value Characterization of Equality for Finitely Supported Functions
Informal description
For any two finitely supported functions $f, g \colon \alpha \to M$, $f = g$ if and only if their supports are equal and $f(x) = g(x)$ for all $x$ in their common support.
Finsupp.support_eq_empty theorem
{f : α →₀ M} : f.support = ∅ ↔ f = 0
Full source
@[simp]
theorem support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 :=
  mod_cast @Function.support_eq_empty_iff _ _ _ f
Empty Support Characterization for Finitely Supported Functions
Informal description
For any finitely supported function $f \colon \alpha \to_{\text{f}} M$, the support of $f$ is empty if and only if $f$ is the zero function.
Finsupp.card_support_eq_zero theorem
{f : α →₀ M} : #f.support = 0 ↔ f = 0
Full source
theorem card_support_eq_zero {f : α →₀ M} : #f.support#f.support = 0 ↔ f = 0 := by simp
Zero Cardinality of Support Characterizes the Zero Function
Informal description
For any finitely supported function $f \colon \alpha \to_{\text{f}} M$, the cardinality of its support is zero if and only if $f$ is the zero function.
Finsupp.instDecidableEq instance
[DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M)
Full source
instance instDecidableEq [DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M) := fun f g =>
  decidable_of_iff (f.support = g.support ∧ ∀ a ∈ f.support, f a = g a) ext_iff'.symm
Decidable Equality for Finitely Supported Functions
Informal description
For any types $\alpha$ and $M$ with decidable equality, the type $\alpha \to_{\text{f}} M$ of finitely supported functions from $\alpha$ to $M$ also has decidable equality.
Finsupp.finite_support theorem
(f : α →₀ M) : Set.Finite (Function.support f)
Full source
theorem finite_support (f : α →₀ M) : Set.Finite (Function.support f) :=
  f.fun_support_eq.symm ▸ f.support.finite_toSet
Finite Support Property of Finitely Supported Functions
Informal description
For any finitely supported function $f \colon \alpha \to M$, the support of $f$ (i.e., the set $\{a \in \alpha \mid f(a) \neq 0\}$) is finite.
Finsupp.support_subset_iff theorem
{s : Set α} {f : α →₀ M} : ↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0
Full source
theorem support_subset_iff {s : Set α} {f : α →₀ M} :
    ↑f.support ⊆ s↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0 := by
  simp only [Set.subset_def, mem_coe, mem_support_iff]; exact forall_congr' fun a => not_imp_comm
Support Subset Criterion for Finitely Supported Functions
Informal description
For any set $s \subseteq \alpha$ and any finitely supported function $f \colon \alpha \to M$, the support of $f$ is contained in $s$ if and only if $f(a) = 0$ for all $a \notin s$.
Finsupp.equivFunOnFinite definition
[Finite α] : (α →₀ M) ≃ (α → M)
Full source
/-- Given `Finite α`, `equivFunOnFinite` is the `Equiv` between `α →₀ β` and `α → β`.
  (All functions on a finite type are finitely supported.) -/
@[simps]
def equivFunOnFinite [Finite α] : (α →₀ M) ≃ (α → M) where
  toFun := (⇑)
  invFun f := mk (Function.support f).toFinite.toFinset f fun _a => Set.Finite.mem_toFinset _
  left_inv _f := ext fun _x => rfl
  right_inv _f := rfl
Equivalence between finitely supported functions and all functions on a finite type
Informal description
Given a finite type $\alpha$ and a type $M$ with a zero element, the equivalence `equivFunOnFinite` establishes a bijection between the type of finitely supported functions $\alpha \to₀ M$ and the type of all functions $\alpha \to M$. This equivalence maps a finitely supported function to its underlying function, and its inverse constructs a finitely supported function from any function (which is automatically finitely supported when $\alpha$ is finite).
Finsupp.equivFunOnFinite_symm_coe theorem
{α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f
Full source
@[simp]
theorem equivFunOnFinite_symm_coe {α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f :=
  equivFunOnFinite.symm_apply_apply f
Inverse of Finitely Supported Function Equivalence Preserves Identity
Informal description
For any finite type $\alpha$ and any type $M$ with a zero element, the inverse of the equivalence `equivFunOnFinite` maps a finitely supported function $f \colon \alpha \to₀ M$ to itself. In other words, $\text{equivFunOnFinite.symm}(f) = f$.
Finsupp.coe_equivFunOnFinite_symm theorem
{α} [Finite α] (f : α → M) : ⇑(equivFunOnFinite.symm f) = f
Full source
@[simp]
lemma coe_equivFunOnFinite_symm {α} [Finite α] (f : α → M) : ⇑(equivFunOnFinite.symm f) = f := rfl
Inverse Equivalence Preserves Function Identity for Finitely Supported Functions on Finite Types
Informal description
For any finite type $\alpha$ and any type $M$ with a zero element, the underlying function of the finitely supported function obtained by applying the inverse of the equivalence `equivFunOnFinite` to a function $f \colon \alpha \to M$ is equal to $f$ itself. In other words, if we convert $f$ to a finitely supported function and then back to a regular function, we recover the original function $f$.
Equiv.finsuppUnique definition
{ι : Type*} [Unique ι] : (ι →₀ M) ≃ M
Full source
/--
If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`.
-/
@[simps!]
noncomputable def _root_.Equiv.finsuppUnique {ι : Type*} [Unique ι] : (ι →₀ M) ≃ M :=
  Finsupp.equivFunOnFinite.trans (Equiv.funUnique ι M)
Equivalence between finitely supported functions on a unique type and the codomain
Informal description
When the type $\iota$ has a unique element, the type of finitely supported functions $\iota \to₀ M$ is equivalent to $M$ itself. This equivalence is constructed by composing the equivalence between finitely supported functions and all functions (which holds trivially for finite types) with the equivalence between functions on a singleton type and their codomain.
Finsupp.unique_ext theorem
[Unique α] {f g : α →₀ M} (h : f default = g default) : f = g
Full source
@[ext]
theorem unique_ext [Unique α] {f g : α →₀ M} (h : f default = g default) : f = g :=
  ext fun a => by rwa [Unique.eq_default a]
Uniqueness of Finitely Supported Functions on a Unique Type
Informal description
For a type $\alpha$ with a unique element and any type $M$ with a zero element, if two finitely supported functions $f, g \colon \alpha \to₀ M$ agree at the default element of $\alpha$, then $f = g$.
Finsupp.onFinset definition
(s : Finset α) (f : α → M) (hf : ∀ a, f a ≠ 0 → a ∈ s) : α →₀ M
Full source
/-- `Finsupp.onFinset s f hf` is the finsupp function representing `f` restricted to the finset `s`.
The function must be `0` outside of `s`. Use this when the set needs to be filtered anyways,
otherwise a better set representation is often available. -/
def onFinset (s : Finset α) (f : α → M) (hf : ∀ a, f a ≠ 0a ∈ s) : α →₀ M where
  support :=
    haveI := Classical.decEq M
    {a ∈ s | f a ≠ 0}
  toFun := f
  mem_support_toFun := by classical simpa
Finitely supported function restricted to a finite set
Informal description
Given a finite set $s$ in $\alpha$, a function $f \colon \alpha \to M$, and a proof $hf$ that $f$ is zero outside $s$, the function `Finsupp.onFinset s f hf` represents the finitely supported function obtained by restricting $f$ to $s$. The support of this function is the subset of $s$ where $f$ is non-zero.
Finsupp.coe_onFinset theorem
(s : Finset α) (f : α → M) (hf) : onFinset s f hf = f
Full source
@[simp, norm_cast] lemma coe_onFinset (s : Finset α) (f : α → M) (hf) : onFinset s f hf = f := rfl
Equality of Finitely Supported Function and Original Function on Finite Set
Informal description
For any finite set $s \subseteq \alpha$, any function $f \colon \alpha \to M$, and any proof $hf$ that $f$ is zero outside $s$, the finitely supported function `onFinset s f hf` is equal to $f$ as functions from $\alpha$ to $M$.
Finsupp.onFinset_apply theorem
{s : Finset α} {f : α → M} {hf a} : (onFinset s f hf : α →₀ M) a = f a
Full source
@[simp]
theorem onFinset_apply {s : Finset α} {f : α → M} {hf a} : (onFinset s f hf : α →₀ M) a = f a :=
  rfl
Evaluation of Finitely Supported Function on Finite Set
Informal description
For any finite set $s \subseteq \alpha$, any function $f \colon \alpha \to M$, and any proof $hf$ that $f$ is zero outside $s$, the finitely supported function `onFinset s f hf` evaluated at any point $a \in \alpha$ equals $f(a)$.
Finsupp.support_onFinset_subset theorem
{s : Finset α} {f : α → M} {hf} : (onFinset s f hf).support ⊆ s
Full source
@[simp]
theorem support_onFinset_subset {s : Finset α} {f : α → M} {hf} :
    (onFinset s f hf).support ⊆ s := by
  classical convert filter_subset (f · ≠ 0) s
Support of Finitely Supported Function is Subset of Given Finite Set
Informal description
For any finite set $s \subseteq \alpha$, any function $f \colon \alpha \to M$, and any proof $hf$ that $f$ is zero outside $s$, the support of the finitely supported function `onFinset s f hf` is a subset of $s$.
Finsupp.mem_support_onFinset theorem
{s : Finset α} {f : α → M} (hf : ∀ a : α, f a ≠ 0 → a ∈ s) {a : α} : a ∈ (Finsupp.onFinset s f hf).support ↔ f a ≠ 0
Full source
theorem mem_support_onFinset {s : Finset α} {f : α → M} (hf : ∀ a : α, f a ≠ 0a ∈ s) {a : α} :
    a ∈ (Finsupp.onFinset s f hf).supporta ∈ (Finsupp.onFinset s f hf).support ↔ f a ≠ 0 := by
  rw [Finsupp.mem_support_iff, Finsupp.onFinset_apply]
Support Membership Criterion for Finitely Supported Function on Finite Set
Informal description
For any finite set $s \subseteq \alpha$, any function $f \colon \alpha \to M$, and any proof $hf$ that $f$ is zero outside $s$, an element $a \in \alpha$ belongs to the support of the finitely supported function $\text{onFinset } s f hf$ if and only if $f(a) \neq 0$.
Finsupp.support_onFinset theorem
[DecidableEq M] {s : Finset α} {f : α → M} (hf : ∀ a : α, f a ≠ 0 → a ∈ s) : (Finsupp.onFinset s f hf).support = {a ∈ s | f a ≠ 0}
Full source
theorem support_onFinset [DecidableEq M] {s : Finset α} {f : α → M}
    (hf : ∀ a : α, f a ≠ 0a ∈ s) :
    (Finsupp.onFinset s f hf).support = {a ∈ s | f a ≠ 0} := by
  dsimp [onFinset]; congr
Support of Finitely Supported Function on Finite Set
Informal description
Let $M$ be a type with a decidable equality, $s$ a finite subset of $\alpha$, and $f \colon \alpha \to M$ a function such that for every $a \in \alpha$, if $f(a) \neq 0$ then $a \in s$. Then the support of the finitely supported function `Finsupp.onFinset s f hf` is equal to the subset of $s$ where $f$ is non-zero, i.e., $$\text{support}(\text{onFinset } s f hf) = \{a \in s \mid f(a) \neq 0\}.$$
Finsupp.ofSupportFinite definition
(f : α → M) (hf : (Function.support f).Finite) : α →₀ M
Full source
/-- The natural `Finsupp` induced by the function `f` given that it has finite support. -/
noncomputable def ofSupportFinite (f : α → M) (hf : (Function.support f).Finite) : α →₀ M where
  support := hf.toFinset
  toFun := f
  mem_support_toFun _ := hf.mem_toFinset
Finitely supported function from a function with finite support
Informal description
Given a function \( f : \alpha \to M \) with finite support (i.e., the set \(\{a \in \alpha \mid f(a) \neq 0\}\) is finite), the construction `Finsupp.ofSupportFinite f hf` produces a finitely supported function from \(\alpha\) to \(M\), where `hf` is a proof that the support of \(f\) is finite. The resulting function is equal to \(f\) everywhere.
Finsupp.ofSupportFinite_coe theorem
{f : α → M} {hf : (Function.support f).Finite} : (ofSupportFinite f hf : α → M) = f
Full source
theorem ofSupportFinite_coe {f : α → M} {hf : (Function.support f).Finite} :
    (ofSupportFinite f hf : α → M) = f :=
  rfl
Equality of Finitely Supported Function Construction with Original Function
Informal description
For any function $f \colon \alpha \to M$ with finite support (i.e., the set $\{a \in \alpha \mid f(a) \neq 0\}$ is finite), the finitely supported function constructed from $f$ via `ofSupportFinite` is equal to $f$ pointwise.
Finsupp.instCanLift instance
: CanLift (α → M) (α →₀ M) (⇑) fun f => (Function.support f).Finite
Full source
instance instCanLift : CanLift (α → M) (α →₀ M) (⇑) fun f => (Function.support f).Finite where
  prf f hf := ⟨ofSupportFinite f hf, rfl⟩
Lifting Condition for Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $M$ with a zero element, there is a canonical way to lift a function $f \colon \alpha \to M$ to a finitely supported function $\alpha \to₀ M$ if and only if $f$ has finite support (i.e., the set $\{a \in \alpha \mid f(a) \neq 0\}$ is finite).
Finsupp.mapRange definition
(f : M → N) (hf : f 0 = 0) (g : α →₀ M) : α →₀ N
Full source
/-- The composition of `f : M → N` and `g : α →₀ M` is `mapRange f hf g : α →₀ N`,
which is well-defined when `f 0 = 0`.

This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself
bundled (defined in `Mathlib/Data/Finsupp/Basic.lean`):

* `Finsupp.mapRange.equiv`
* `Finsupp.mapRange.zeroHom`
* `Finsupp.mapRange.addMonoidHom`
* `Finsupp.mapRange.addEquiv`
* `Finsupp.mapRange.linearMap`
* `Finsupp.mapRange.linearEquiv`
-/
def mapRange (f : M → N) (hf : f 0 = 0) (g : α →₀ M) : α →₀ N :=
  onFinset g.support (f ∘ g) fun a => by
    rw [mem_support_iff, not_imp_not]; exact fun H => (congr_arg f H).trans hf
Composition of finitely supported functions with zero-preserving maps
Informal description
Given a function $f \colon M \to N$ with $f(0) = 0$ and a finitely supported function $g \colon \alpha \to₀ M$, the composition $f \circ g$ is a finitely supported function from $\alpha$ to $N$. This operation preserves the finitely supported property by restricting to the support of $g$.
Finsupp.mapRange_apply theorem
{f : M → N} {hf : f 0 = 0} {g : α →₀ M} {a : α} : mapRange f hf g a = f (g a)
Full source
@[simp]
theorem mapRange_apply {f : M → N} {hf : f 0 = 0} {g : α →₀ M} {a : α} :
    mapRange f hf g a = f (g a) :=
  rfl
Evaluation of Mapped Finitely Supported Function: $\operatorname{mapRange}(f, hf, g)(a) = f(g(a))$
Informal description
For any function $f \colon M \to N$ satisfying $f(0) = 0$, any finitely supported function $g \colon \alpha \to₀ M$, and any element $a \in \alpha$, the evaluation of the mapped function $\operatorname{mapRange}(f, hf, g)$ at $a$ equals $f(g(a))$.
Finsupp.mapRange_zero theorem
{f : M → N} {hf : f 0 = 0} : mapRange f hf (0 : α →₀ M) = 0
Full source
@[simp]
theorem mapRange_zero {f : M → N} {hf : f 0 = 0} : mapRange f hf (0 : α →₀ M) = 0 :=
  ext fun _ => by simp only [hf, zero_apply, mapRange_apply]
Zero Preservation under Function Mapping in Finitely Supported Functions
Informal description
For any function $f \colon M \to N$ satisfying $f(0) = 0$, the composition of $f$ with the zero function in $\alpha \to₀ M$ yields the zero function in $\alpha \to₀ N$. That is, $\operatorname{mapRange}(f, hf, 0) = 0$.
Finsupp.mapRange_id theorem
(g : α →₀ M) : mapRange id rfl g = g
Full source
@[simp]
theorem mapRange_id (g : α →₀ M) : mapRange id rfl g = g :=
  ext fun _ => rfl
Identity Mapping Preserves Finitely Supported Functions
Informal description
For any finitely supported function $g \colon \alpha \to₀ M$, the composition of $g$ with the identity function $\mathrm{id} \colon M \to M$ (which satisfies $\mathrm{id}(0) = 0$) yields $g$ itself, i.e., $\operatorname{mapRange}(\mathrm{id}, \mathrm{rfl}, g) = g$.
Finsupp.mapRange_comp theorem
(f : N → P) (hf : f 0 = 0) (f₂ : M → N) (hf₂ : f₂ 0 = 0) (h : (f ∘ f₂) 0 = 0) (g : α →₀ M) : mapRange (f ∘ f₂) h g = mapRange f hf (mapRange f₂ hf₂ g)
Full source
theorem mapRange_comp (f : N → P) (hf : f 0 = 0) (f₂ : M → N) (hf₂ : f₂ 0 = 0) (h : (f ∘ f₂) 0 = 0)
    (g : α →₀ M) : mapRange (f ∘ f₂) h g = mapRange f hf (mapRange f₂ hf₂ g) :=
  ext fun _ => rfl
Composition of Zero-Preserving Maps on Finitely Supported Functions
Informal description
Let $f \colon N \to P$ and $f₂ \colon M \to N$ be functions such that $f(0) = 0$, $f₂(0) = 0$, and $(f \circ f₂)(0) = 0$. For any finitely supported function $g \colon \alpha \to₀ M$, the composition of $g$ with $f \circ f₂$ is equal to the composition of $g$ with $f₂$ followed by $f$. That is, $$ \text{mapRange}(f \circ f₂, h) \, g = \text{mapRange}(f, hf) \big(\text{mapRange}(f₂, hf₂) \, g\big). $$
Finsupp.mapRange_mapRange theorem
(e₁ : N → P) (e₂ : M → N) (he₁ he₂) (f : α →₀ M) : mapRange e₁ he₁ (mapRange e₂ he₂ f) = mapRange (e₁ ∘ e₂) (by simp [*]) f
Full source
@[simp]
lemma mapRange_mapRange (e₁ : N → P) (e₂ : M → N) (he₁ he₂) (f : α →₀ M) :
    mapRange e₁ he₁ (mapRange e₂ he₂ f) = mapRange (e₁ ∘ e₂) (by simp [*]) f := ext fun _ ↦ rfl
Composition of Map Operations on Finitely Supported Functions
Informal description
Let $e_1 \colon N \to P$ and $e_2 \colon M \to N$ be functions such that $e_1(0) = 0$ and $e_2(0) = 0$, and let $f \colon \alpha \to₀ M$ be a finitely supported function. Then the composition of the map operations satisfies: \[ \text{mapRange } e_1 \text{ } he_1 (\text{mapRange } e_2 \text{ } he_2 f) = \text{mapRange } (e_1 \circ e_2) \text{ } (\text{by simp } [*]) f \] where $he_1$ and $he_2$ are proofs that $e_1(0) = 0$ and $e_2(0) = 0$ respectively.
Finsupp.support_mapRange theorem
{f : M → N} {hf : f 0 = 0} {g : α →₀ M} : (mapRange f hf g).support ⊆ g.support
Full source
theorem support_mapRange {f : M → N} {hf : f 0 = 0} {g : α →₀ M} :
    (mapRange f hf g).support ⊆ g.support :=
  support_onFinset_subset
Support Inclusion under Composition of Finitely Supported Functions
Informal description
For any function $f \colon M \to N$ with $f(0) = 0$ and any finitely supported function $g \colon \alpha \to₀ M$, the support of the composition $f \circ g$ (as a finitely supported function $\alpha \to₀ N$) is a subset of the support of $g$.
Finsupp.support_mapRange_of_injective theorem
{e : M → N} (he0 : e 0 = 0) (f : ι →₀ M) (he : Function.Injective e) : (Finsupp.mapRange e he0 f).support = f.support
Full source
theorem support_mapRange_of_injective {e : M → N} (he0 : e 0 = 0) (f : ι →₀ M)
    (he : Function.Injective e) : (Finsupp.mapRange e he0 f).support = f.support := by
  ext
  simp only [Finsupp.mem_support_iff, Ne, Finsupp.mapRange_apply]
  exact he.ne_iff' he0
Support Preservation under Injective Composition of Finitely Supported Functions
Informal description
Let $e \colon M \to N$ be an injective function with $e(0) = 0$, and let $f \colon \iota \to₀ M$ be a finitely supported function. Then the support of the composition $e \circ f$ (as a finitely supported function $\iota \to₀ N$) is equal to the support of $f$.
Finsupp.range_mapRange theorem
(e : M → N) (he₀ : e 0 = 0) : Set.range (Finsupp.mapRange (α := α) e he₀) = {g | ∀ i, g i ∈ Set.range e}
Full source
lemma range_mapRange (e : M → N) (he₀ : e 0 = 0) :
    Set.range (Finsupp.mapRange (α := α) e he₀) = {g | ∀ i, g i ∈ Set.range e} := by
  ext g
  simp only [Set.mem_range, Set.mem_setOf]
  constructor
  · rintro ⟨g, rfl⟩ i
    simp
  · intro h
    classical
    choose f h using h
    use onFinset g.support (Set.indicator g.support f) (by aesop)
    ext i
    simp only [mapRange_apply, onFinset_apply, Set.indicator_apply]
    split_ifs <;> simp_all
Range Characterization of Pointwise Composition for Finitely Supported Functions
Informal description
For any function $e \colon M \to N$ with $e(0) = 0$, the range of the map `Finsupp.mapRange e he₀` (which applies $e$ pointwise to finitely supported functions $\alpha \to₀ M$) is equal to the set of all finitely supported functions $g \colon \alpha \to₀ N$ such that for every $i \in \alpha$, $g(i)$ lies in the range of $e$.
Finsupp.mapRange_injective theorem
(e : M → N) (he₀ : e 0 = 0) (he : Injective e) : Injective (Finsupp.mapRange (α := α) e he₀)
Full source
/-- `Finsupp.mapRange` of a injective function is injective. -/
lemma mapRange_injective (e : M → N) (he₀ : e 0 = 0) (he : Injective e) :
    Injective (Finsupp.mapRange (α := α) e he₀) := by
  intro a b h
  rw [Finsupp.ext_iff] at h ⊢
  simpa only [mapRange_apply, he.eq_iff] using h
Injectivity of Pointwise Composition for Finitely Supported Functions
Informal description
Let $e \colon M \to N$ be an injective function that preserves zero (i.e., $e(0) = 0$). Then the induced map $\text{mapRange}\, e \colon (\alpha \to₀ M) \to (\alpha \to₀ N)$, which applies $e$ pointwise to finitely supported functions, is also injective.
Finsupp.mapRange_surjective theorem
(e : M → N) (he₀ : e 0 = 0) (he : Surjective e) : Surjective (Finsupp.mapRange (α := α) e he₀)
Full source
/-- `Finsupp.mapRange` of a surjective function is surjective. -/
lemma mapRange_surjective (e : M → N) (he₀ : e 0 = 0) (he : Surjective e) :
    Surjective (Finsupp.mapRange (α := α) e he₀) := by
  rw [← Set.range_eq_univ, range_mapRange, he.range_eq]
  simp
Surjectivity of Pointwise Composition for Finitely Supported Functions
Informal description
Let $e \colon M \to N$ be a surjective function with $e(0) = 0$. Then the induced map $Finsupp.mapRange\, e\, he₀ \colon (\alpha \to₀ M) \to (\alpha \to₀ N)$ is also surjective. Here, $\alpha \to₀ M$ denotes the type of finitely supported functions from $\alpha$ to $M$.
Finsupp.embDomain definition
(f : α ↪ β) (v : α →₀ M) : β →₀ M
Full source
/-- Given `f : α ↪ β` and `v : α →₀ M`, `Finsupp.embDomain f v : β →₀ M`
is the finitely supported function whose value at `f a : β` is `v a`.
For a `b : β` outside the range of `f`, it is zero. -/
def embDomain (f : α ↪ β) (v : α →₀ M) : β →₀ M where
  support := v.support.map f
  toFun a₂ :=
    haveI := Classical.decEq β
    if h : a₂ ∈ v.support.map f then
      v
        (v.support.choose (fun a₁ => f a₁ = a₂)
          (by
            rcases Finset.mem_map.1 h with ⟨a, ha, rfl⟩
            exact ExistsUnique.intro a ⟨ha, rfl⟩ fun b ⟨_, hb⟩ => f.injective hb))
    else 0
  mem_support_toFun a₂ := by
    dsimp
    split_ifs with h
    · simp only [h, true_iff, Ne]
      rw [← not_mem_support_iff, not_not]
      classical apply Finset.choose_mem
    · simp only [h, Ne, ne_self_iff_false, not_true_eq_false]
Embedding of finitely supported functions
Informal description
Given an embedding $f : \alpha \hookrightarrow \beta$ and a finitely supported function $v : \alpha \to M$, the function $\text{embDomain}\, f\, v : \beta \to M$ is defined as the finitely supported function whose value at $f(a)$ is $v(a)$ for any $a \in \alpha$, and zero elsewhere on $\beta$.
Finsupp.support_embDomain theorem
(f : α ↪ β) (v : α →₀ M) : (embDomain f v).support = v.support.map f
Full source
@[simp]
theorem support_embDomain (f : α ↪ β) (v : α →₀ M) : (embDomain f v).support = v.support.map f :=
  rfl
Support of Embedded Finitely Supported Function Equals Image of Support
Informal description
For any embedding $f \colon \alpha \hookrightarrow \beta$ and any finitely supported function $v \colon \alpha \to M$, the support of the embedded function $\text{embDomain}\, f\, v$ is equal to the image of the support of $v$ under $f$, i.e., $$ \text{supp}(\text{embDomain}\, f\, v) = f(\text{supp}(v)). $$
Finsupp.embDomain_zero theorem
(f : α ↪ β) : (embDomain f 0 : β →₀ M) = 0
Full source
@[simp]
theorem embDomain_zero (f : α ↪ β) : (embDomain f 0 : β →₀ M) = 0 :=
  rfl
Embedding of Zero Function Yields Zero Function
Informal description
For any embedding $f : \alpha \hookrightarrow \beta$, the embedding of the zero function under $f$ is the zero function in $\beta \to_{\text{f}} M$, i.e., $\text{embDomain}\, f\, 0 = 0$.
Finsupp.embDomain_apply theorem
(f : α ↪ β) (v : α →₀ M) (a : α) : embDomain f v (f a) = v a
Full source
@[simp]
theorem embDomain_apply (f : α ↪ β) (v : α →₀ M) (a : α) : embDomain f v (f a) = v a := by
  classical
    simp_rw [embDomain, coe_mk, mem_map']
    split_ifs with h
    · refine congr_arg (v : α → M) (f.inj' ?_)
      exact Finset.choose_property (fun a₁ => f a₁ = f a) _ _
    · exact (not_mem_support_iff.1 h).symm
Embedding Preserves Function Values for Finitely Supported Functions
Informal description
Given an embedding $f \colon \alpha \hookrightarrow \beta$ and a finitely supported function $v \colon \alpha \to M$, for any element $a \in \alpha$, the value of the embedded function $\text{embDomain}\, f\, v$ at $f(a)$ is equal to $v(a)$, i.e., $$ \text{embDomain}\, f\, v\, (f(a)) = v(a). $$
Finsupp.embDomain_notin_range theorem
(f : α ↪ β) (v : α →₀ M) (a : β) (h : a ∉ Set.range f) : embDomain f v a = 0
Full source
theorem embDomain_notin_range (f : α ↪ β) (v : α →₀ M) (a : β) (h : a ∉ Set.range f) :
    embDomain f v a = 0 := by
  classical
    refine dif_neg (mt (fun h => ?_) h)
    rcases Finset.mem_map.1 h with ⟨a, _h, rfl⟩
    exact Set.mem_range_self a
Vanishing Property of Embedded Finitely Supported Functions Outside the Range
Informal description
Given an embedding $f : \alpha \hookrightarrow \beta$, a finitely supported function $v : \alpha \to M$, and an element $a \in \beta$ such that $a$ is not in the range of $f$, the value of the embedded function $\text{embDomain}\, f\, v$ at $a$ is zero, i.e., $\text{embDomain}\, f\, v\, a = 0$.
Finsupp.embDomain_injective theorem
(f : α ↪ β) : Function.Injective (embDomain f : (α →₀ M) → β →₀ M)
Full source
theorem embDomain_injective (f : α ↪ β) : Function.Injective (embDomain f : (α →₀ M) → β →₀ M) :=
  fun l₁ l₂ h => ext fun a => by simpa only [embDomain_apply] using DFunLike.ext_iff.1 h (f a)
Injectivity of Embedding for Finitely Supported Functions
Informal description
Given an embedding $f \colon \alpha \hookrightarrow \beta$, the function $\text{embDomain}\, f \colon (\alpha \to₀ M) \to (\beta \to₀ M)$ is injective. That is, for any two finitely supported functions $v_1, v_2 \colon \alpha \to M$, if $\text{embDomain}\, f\, v_1 = \text{embDomain}\, f\, v_2$, then $v_1 = v_2$.
Finsupp.embDomain_inj theorem
{f : α ↪ β} {l₁ l₂ : α →₀ M} : embDomain f l₁ = embDomain f l₂ ↔ l₁ = l₂
Full source
@[simp]
theorem embDomain_inj {f : α ↪ β} {l₁ l₂ : α →₀ M} : embDomainembDomain f l₁ = embDomain f l₂ ↔ l₁ = l₂ :=
  (embDomain_injective f).eq_iff
Injectivity Criterion for Embedded Finitely Supported Functions: $\operatorname{embDomain} f\, l_1 = \operatorname{embDomain} f\, l_2 \leftrightarrow l_1 = l_2$
Informal description
For any embedding $f \colon \alpha \hookrightarrow \beta$ and any two finitely supported functions $l_1, l_2 \colon \alpha \to M$, the embedded functions $\operatorname{embDomain} f\, l_1$ and $\operatorname{embDomain} f\, l_2$ are equal if and only if $l_1 = l_2$.
Finsupp.embDomain_eq_zero theorem
{f : α ↪ β} {l : α →₀ M} : embDomain f l = 0 ↔ l = 0
Full source
@[simp]
theorem embDomain_eq_zero {f : α ↪ β} {l : α →₀ M} : embDomainembDomain f l = 0 ↔ l = 0 :=
  (embDomain_injective f).eq_iff' <| embDomain_zero f
Embedding of Finitely Supported Function Yields Zero if and Only if Function is Zero
Informal description
For any embedding $f \colon \alpha \hookrightarrow \beta$ and any finitely supported function $l \colon \alpha \to M$, the embedding of $l$ under $f$ is the zero function if and only if $l$ is the zero function. That is, $\text{embDomain}\, f\, l = 0 \leftrightarrow l = 0$.
Finsupp.embDomain_mapRange theorem
(f : α ↪ β) (g : M → N) (p : α →₀ M) (hg : g 0 = 0) : embDomain f (mapRange g hg p) = mapRange g hg (embDomain f p)
Full source
theorem embDomain_mapRange (f : α ↪ β) (g : M → N) (p : α →₀ M) (hg : g 0 = 0) :
    embDomain f (mapRange g hg p) = mapRange g hg (embDomain f p) := by
  ext a
  by_cases h : a ∈ Set.range f
  · rcases h with ⟨a', rfl⟩
    rw [mapRange_apply, embDomain_apply, embDomain_apply, mapRange_apply]
  · rw [mapRange_apply, embDomain_notin_range, embDomain_notin_range, ← hg] <;> assumption
Commutativity of Embedding and Mapping for Finitely Supported Functions
Informal description
Let $f \colon \alpha \hookrightarrow \beta$ be an embedding, $g \colon M \to N$ a function satisfying $g(0) = 0$, and $p \colon \alpha \to₀ M$ a finitely supported function. Then the embedding of the mapped function $\operatorname{embDomain}\, f\, (\operatorname{mapRange}\, g\, hg\, p)$ is equal to the mapped function of the embedding $\operatorname{mapRange}\, g\, hg\, (\operatorname{embDomain}\, f\, p)$. In other words, the following diagram commutes: $$ \operatorname{embDomain}\, f \circ \operatorname{mapRange}\, g\, hg = \operatorname{mapRange}\, g\, hg \circ \operatorname{embDomain}\, f. $$
Finsupp.zipWith definition
(f : M → N → P) (hf : f 0 0 = 0) (g₁ : α →₀ M) (g₂ : α →₀ N) : α →₀ P
Full source
/-- Given finitely supported functions `g₁ : α →₀ M` and `g₂ : α →₀ N` and function `f : M → N → P`,
`Finsupp.zipWith f hf g₁ g₂` is the finitely supported function `α →₀ P` satisfying
`zipWith f hf g₁ g₂ a = f (g₁ a) (g₂ a)`, which is well-defined when `f 0 0 = 0`. -/
def zipWith (f : M → N → P) (hf : f 0 0 = 0) (g₁ : α →₀ M) (g₂ : α →₀ N) : α →₀ P :=
  onFinset
    (haveI := Classical.decEq α; g₁.support ∪ g₂.support)
    (fun a => f (g₁ a) (g₂ a))
    fun a (H : f _ _ ≠ 0) => by
      classical
      rw [mem_union, mem_support_iff, mem_support_iff, ← not_and_or]
      rintro ⟨h₁, h₂⟩; rw [h₁, h₂] at H; exact H hf
Pointwise combination of finitely supported functions
Informal description
Given a function \( f \colon M \to N \to P \) satisfying \( f(0, 0) = 0 \), and two finitely supported functions \( g_1 \colon \alpha \to₀ M \) and \( g_2 \colon \alpha \to₀ N \), the function `Finsupp.zipWith f hf g₁ g₂` is the finitely supported function \( \alpha \to₀ P \) defined by \( a \mapsto f(g_1(a), g_2(a)) \). The support of this function is contained in the union of the supports of \( g_1 \) and \( g_2 \).
Finsupp.zipWith_apply theorem
{f : M → N → P} {hf : f 0 0 = 0} {g₁ : α →₀ M} {g₂ : α →₀ N} {a : α} : zipWith f hf g₁ g₂ a = f (g₁ a) (g₂ a)
Full source
@[simp]
theorem zipWith_apply {f : M → N → P} {hf : f 0 0 = 0} {g₁ : α →₀ M} {g₂ : α →₀ N} {a : α} :
    zipWith f hf g₁ g₂ a = f (g₁ a) (g₂ a) :=
  rfl
Evaluation of Pointwise Combination of Finitely Supported Functions
Informal description
For any function $f \colon M \to N \to P$ satisfying $f(0, 0) = 0$, any finitely supported functions $g_1 \colon \alpha \to₀ M$ and $g_2 \colon \alpha \to₀ N$, and any element $a \in \alpha$, the evaluation of the pointwise combination $\operatorname{zipWith}(f, hf, g_1, g_2)$ at $a$ satisfies $\operatorname{zipWith}(f, hf, g_1, g_2)(a) = f(g_1(a), g_2(a))$.
Finsupp.support_zipWith theorem
[D : DecidableEq α] {f : M → N → P} {hf : f 0 0 = 0} {g₁ : α →₀ M} {g₂ : α →₀ N} : (zipWith f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support
Full source
theorem support_zipWith [D : DecidableEq α] {f : M → N → P} {hf : f 0 0 = 0} {g₁ : α →₀ M}
    {g₂ : α →₀ N} : (zipWith f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support := by
  convert support_onFinset_subset
Support of Pointwise Combination of Finitely Supported Functions is Contained in Union of Supports
Informal description
Let $\alpha$ be a type with decidable equality, and let $M$, $N$, $P$ be types with zero elements. Given a function $f \colon M \to N \to P$ such that $f(0, 0) = 0$, and two finitely supported functions $g_1 \colon \alpha \to₀ M$ and $g_2 \colon \alpha \to₀ N$, the support of the finitely supported function $\operatorname{zipWith}(f, hf, g_1, g_2)$ is contained in the union of the supports of $g_1$ and $g_2$.
Finsupp.instAdd instance
: Add (α →₀ M)
Full source
instance instAdd : Add (α →₀ M) :=
  ⟨zipWith (· + ·) (add_zero 0)⟩
Pointwise Addition on Finitely Supported Functions
Informal description
The type of finitely supported functions $α →₀ M$ has an addition operation defined pointwise, where for any two functions $f, g \colon α →₀ M$, their sum $(f + g)(a) = f(a) + g(a)$ for all $a \in α$.
Finsupp.coe_add theorem
(f g : α →₀ M) : ⇑(f + g) = f + g
Full source
@[simp, norm_cast] lemma coe_add (f g : α →₀ M) : ⇑(f + g) = f + g := rfl
Pointwise Sum of Finitely Supported Functions
Informal description
For any two finitely supported functions $f, g \colon \alpha \to₀ M$, the underlying function of their sum $f + g$ is equal to the pointwise sum of the underlying functions of $f$ and $g$, i.e., $(f + g)(a) = f(a) + g(a)$ for all $a \in \alpha$.
Finsupp.add_apply theorem
(g₁ g₂ : α →₀ M) (a : α) : (g₁ + g₂) a = g₁ a + g₂ a
Full source
theorem add_apply (g₁ g₂ : α →₀ M) (a : α) : (g₁ + g₂) a = g₁ a + g₂ a :=
  rfl
Pointwise Evaluation of Sum of Finitely Supported Functions
Informal description
For any two finitely supported functions $g₁, g₂ \colon \alpha \to₀ M$ and any element $a \in \alpha$, the evaluation of their sum at $a$ is equal to the sum of their evaluations at $a$, i.e., $(g₁ + g₂)(a) = g₁(a) + g₂(a)$.
Finsupp.support_add theorem
[DecidableEq α] {g₁ g₂ : α →₀ M} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support
Full source
theorem support_add [DecidableEq α] {g₁ g₂ : α →₀ M} :
    (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
  support_zipWith
Support of Sum of Finitely Supported Functions is Contained in Union of Supports
Informal description
For any type $\alpha$ with decidable equality and any type $M$ with a zero element, let $g_1, g_2 \colon \alpha \to₀ M$ be finitely supported functions. Then the support of their sum $g_1 + g_2$ is contained in the union of their supports, i.e., $\operatorname{supp}(g_1 + g_2) \subseteq \operatorname{supp}(g_1) \cup \operatorname{supp}(g_2)$.
Finsupp.support_add_eq theorem
[DecidableEq α] {g₁ g₂ : α →₀ M} (h : Disjoint g₁.support g₂.support) : (g₁ + g₂).support = g₁.support ∪ g₂.support
Full source
theorem support_add_eq [DecidableEq α] {g₁ g₂ : α →₀ M} (h : Disjoint g₁.support g₂.support) :
    (g₁ + g₂).support = g₁.support ∪ g₂.support :=
  le_antisymm support_zipWith fun a ha =>
    (Finset.mem_union.1 ha).elim
      (fun ha => by
        have : a ∉ g₂.support := disjoint_left.1 h ha
        simp only [mem_support_iff, not_not] at *; simpa only [add_apply, this, add_zero] )
      fun ha => by
      have : a ∉ g₁.support := disjoint_right.1 h ha
      simp only [mem_support_iff, not_not] at *; simpa only [add_apply, this, zero_add]
Support of Sum of Finitely Supported Functions with Disjoint Supports Equals Union of Supports
Informal description
Let $\alpha$ be a type with decidable equality and $M$ be a type with a zero element. For any two finitely supported functions $g_1, g_2 \colon \alpha \to₀ M$ with disjoint supports, the support of their sum $g_1 + g_2$ is equal to the union of their individual supports, i.e., $\operatorname{supp}(g_1 + g_2) = \operatorname{supp}(g_1) \cup \operatorname{supp}(g_2)$.
Finsupp.instAddZeroClass instance
: AddZeroClass (α →₀ M)
Full source
instance instAddZeroClass : AddZeroClass (α →₀ M) :=
  fast_instance% DFunLike.coe_injective.addZeroClass _ coe_zero coe_add
Additive Structure on Finitely Supported Functions
Informal description
The type of finitely supported functions $\alpha \to_{\text{f}} M$ (denoted $\alpha \to₀ M$) forms an add-zero class, where addition is defined pointwise and the zero function serves as the additive identity.
Finsupp.instIsLeftCancelAdd instance
[IsLeftCancelAdd M] : IsLeftCancelAdd (α →₀ M)
Full source
instance instIsLeftCancelAdd [IsLeftCancelAdd M] : IsLeftCancelAdd (α →₀ M) where
  add_left_cancel _ _ _ h := ext fun x => add_left_cancel <| DFunLike.congr_fun h x
Left-Cancellative Addition on Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $M$ with a left-cancellative addition, the type $\alpha \to₀ M$ of finitely supported functions from $\alpha$ to $M$ also has a left-cancellative addition. That is, for any $f, g, h \in \alpha \to₀ M$, if $f + h = g + h$, then $f = g$.
Finsupp.addEquivFunOnFinite definition
{ι : Type*} [Finite ι] : (ι →₀ M) ≃+ (ι → M)
Full source
/-- When ι is finite and M is an AddMonoid,
  then Finsupp.equivFunOnFinite gives an AddEquiv -/
noncomputable def addEquivFunOnFinite {ι : Type*} [Finite ι] :
    (ι →₀ M) ≃+ (ι → M) where
  __ := Finsupp.equivFunOnFinite
  map_add' _ _ := rfl
Additive equivalence between finitely supported functions and all functions on a finite type
Informal description
Given a finite type $\iota$ and an additive monoid $M$, the equivalence `addEquivFunOnFinite` establishes an additive equivalence between the type of finitely supported functions $\iota \to₀ M$ and the type of all functions $\iota \to M$. This equivalence preserves the additive structure, mapping the pointwise addition of finitely supported functions to the pointwise addition of their corresponding functions.
AddEquiv.finsuppUnique definition
{ι : Type*} [Unique ι] : (ι →₀ M) ≃+ M
Full source
/-- AddEquiv between (ι →₀ M) and M, when ι has a unique element -/
noncomputable def _root_.AddEquiv.finsuppUnique {ι : Type*} [Unique ι] :
    (ι →₀ M) ≃+ M where
  __ := Equiv.finsuppUnique
  map_add' _ _ := rfl
Additive equivalence between finitely supported functions on a unique type and the codomain
Informal description
Given a type $\iota$ with a unique element, there is an additive equivalence between the type of finitely supported functions $\iota \to₀ M$ and $M$ itself. This equivalence maps a finitely supported function to its value at the unique element of $\iota$, and preserves addition.
Finsupp.instIsRightCancelAdd instance
[IsRightCancelAdd M] : IsRightCancelAdd (α →₀ M)
Full source
instance instIsRightCancelAdd [IsRightCancelAdd M] : IsRightCancelAdd (α →₀ M) where
  add_right_cancel _ _ _ h := ext fun x => add_right_cancel <| DFunLike.congr_fun h x
Right-Cancellative Addition on Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $M$ with a right-cancellative addition operation, the type $\alpha \to₀ M$ of finitely supported functions from $\alpha$ to $M$ also has a right-cancellative addition operation. That is, for any $f, g, h \colon \alpha \to₀ M$, if $f + h = g + h$, then $f = g$.
Finsupp.instIsCancelAdd instance
[IsCancelAdd M] : IsCancelAdd (α →₀ M)
Full source
instance instIsCancelAdd [IsCancelAdd M] : IsCancelAdd (α →₀ M) where
Cancellative Addition on Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $M$ with a cancellative addition operation, the type $\alpha \to₀ M$ of finitely supported functions from $\alpha$ to $M$ also has a cancellative addition operation. That is, for any $f, g, h \colon \alpha \to₀ M$, if $f + h = g + h$ or $h + f = h + g$, then $f = g$.
Finsupp.applyAddHom definition
(a : α) : (α →₀ M) →+ M
Full source
/-- Evaluation of a function `f : α →₀ M` at a point as an additive monoid homomorphism.

See `Finsupp.lapply` in `Mathlib/LinearAlgebra/Finsupp/Defs.lean` for the stronger version as a
linear map. -/
@[simps apply]
def applyAddHom (a : α) : (α →₀ M) →+ M where
  toFun g := g a
  map_zero' := zero_apply
  map_add' _ _ := add_apply _ _ _
Evaluation at a point as an additive monoid homomorphism
Informal description
For a fixed element $a \in \alpha$, the evaluation map that sends a finitely supported function $g \colon \alpha \to M$ to its value $g(a) \in M$ is an additive monoid homomorphism. That is, it preserves the zero element and addition: \[ \text{eval}_a(0) = 0 \quad \text{and} \quad \text{eval}_a(g_1 + g_2) = \text{eval}_a(g_1) + \text{eval}_a(g_2). \]
Finsupp.coeFnAddHom definition
: (α →₀ M) →+ α → M
Full source
/-- Coercion from a `Finsupp` to a function type is an `AddMonoidHom`. -/
@[simps]
noncomputable def coeFnAddHom : (α →₀ M) →+ α → M where
  toFun := (⇑)
  map_zero' := coe_zero
  map_add' := coe_add
Additive monoid homomorphism from finitely supported functions to all functions
Informal description
The function `Finsupp.coeFnAddHom` is an additive monoid homomorphism from the type of finitely supported functions `α →₀ M` to the type of all functions `α → M`. It maps a finitely supported function to its underlying function, preserves addition (i.e., `(f + g)(a) = f(a) + g(a)` for all `a ∈ α`), and maps the zero function to the zero function.
Finsupp.mapRange_add theorem
[AddZeroClass N] {f : M → N} {hf : f 0 = 0} (hf' : ∀ x y, f (x + y) = f x + f y) (v₁ v₂ : α →₀ M) : mapRange f hf (v₁ + v₂) = mapRange f hf v₁ + mapRange f hf v₂
Full source
theorem mapRange_add [AddZeroClass N] {f : M → N} {hf : f 0 = 0}
    (hf' : ∀ x y, f (x + y) = f x + f y) (v₁ v₂ : α →₀ M) :
    mapRange f hf (v₁ + v₂) = mapRange f hf v₁ + mapRange f hf v₂ :=
  ext fun _ => by simp only [hf', add_apply, mapRange_apply]
Additivity of Composition with Finitely Supported Functions
Informal description
Let $M$ and $N$ be types with additive zero structures, and let $f \colon M \to N$ be a function such that $f(0) = 0$ and $f(x + y) = f(x) + f(y)$ for all $x, y \in M$. Then for any two finitely supported functions $v_1, v_2 \colon \alpha \to M$, the following equality holds: \[ f \circ (v_1 + v_2) = (f \circ v_1) + (f \circ v_2), \] where $\circ$ denotes the composition of $f$ with the finitely supported functions, and $+$ denotes pointwise addition.
Finsupp.mapRange_add' theorem
[AddZeroClass N] [FunLike β M N] [AddMonoidHomClass β M N] {f : β} (v₁ v₂ : α →₀ M) : mapRange f (map_zero f) (v₁ + v₂) = mapRange f (map_zero f) v₁ + mapRange f (map_zero f) v₂
Full source
theorem mapRange_add' [AddZeroClass N] [FunLike β M N] [AddMonoidHomClass β M N]
    {f : β} (v₁ v₂ : α →₀ M) :
    mapRange f (map_zero f) (v₁ + v₂) = mapRange f (map_zero f) v₁ + mapRange f (map_zero f) v₂ :=
  mapRange_add (map_add f) v₁ v₂
Additivity of Monoid Homomorphism Composition with Finitely Supported Functions
Informal description
Let $M$ and $N$ be types with additive zero structures, and let $f \colon M \to N$ be an additive monoid homomorphism (i.e., $f(0) = 0$ and $f(x + y) = f(x) + f(y)$ for all $x, y \in M$). Then for any two finitely supported functions $v_1, v_2 \colon \alpha \to M$, the following equality holds: \[ f \circ (v_1 + v_2) = (f \circ v_1) + (f \circ v_2), \] where $\circ$ denotes the composition of $f$ with the finitely supported functions, and $+$ denotes pointwise addition.
Finsupp.embDomain.addMonoidHom definition
(f : α ↪ β) : (α →₀ M) →+ β →₀ M
Full source
/-- Bundle `Finsupp.embDomain f` as an additive map from `α →₀ M` to `β →₀ M`. -/
@[simps]
def embDomain.addMonoidHom (f : α ↪ β) : (α →₀ M) →+ β →₀ M where
  toFun v := embDomain f v
  map_zero' := by simp
  map_add' v w := by
    ext b
    by_cases h : b ∈ Set.range f
    · rcases h with ⟨a, rfl⟩
      simp
    · simp only [Set.mem_range, not_exists, coe_add, Pi.add_apply,
        embDomain_notin_range _ _ _ h, add_zero]
Additive monoid homomorphism induced by embedding of finitely supported functions
Informal description
Given an embedding $f \colon \alpha \hookrightarrow \beta$, the function $\text{embDomain}\ f$ is an additive monoid homomorphism from the type of finitely supported functions $\alpha \to_{\text{f}} M$ to $\beta \to_{\text{f}} M$. Specifically, it satisfies: 1. $\text{embDomain}\ f\ 0 = 0$ (preservation of zero) 2. $\text{embDomain}\ f\ (v + w) = \text{embDomain}\ f\ v + \text{embDomain}\ f\ w$ for any $v, w \in \alpha \to_{\text{f}} M$ (preservation of addition)
Finsupp.embDomain_add theorem
(f : α ↪ β) (v w : α →₀ M) : embDomain f (v + w) = embDomain f v + embDomain f w
Full source
@[simp]
theorem embDomain_add (f : α ↪ β) (v w : α →₀ M) :
    embDomain f (v + w) = embDomain f v + embDomain f w :=
  (embDomain.addMonoidHom f).map_add v w
Additivity of Embedding for Finitely Supported Functions
Informal description
Given an embedding $f \colon \alpha \hookrightarrow \beta$ and two finitely supported functions $v, w \colon \alpha \to M$, the embedding of their sum equals the sum of their embeddings: \[ \text{embDomain}\, f\, (v + w) = \text{embDomain}\, f\, v + \text{embDomain}\, f\, w. \]
Finsupp.instNatSMul instance
: SMul ℕ (α →₀ M)
Full source
/-- Note the general `SMul` instance for `Finsupp` doesn't apply as `ℕ` is not distributive
unless `β i`'s addition is commutative. -/
instance instNatSMul : SMul  (α →₀ M) :=
  ⟨fun n v => v.mapRange (n • ·) (nsmul_zero _)⟩
Natural Number Scalar Multiplication on Finitely Supported Functions
Informal description
For any type $\alpha$ and any additive monoid $M$, the type $\alpha \to₀ M$ of finitely supported functions from $\alpha$ to $M$ has a natural scalar multiplication by natural numbers. Specifically, for $n \in \mathbb{N}$ and $f \in \alpha \to₀ M$, the scalar multiplication $n \cdot f$ is defined pointwise as $(n \cdot f)(x) = n \cdot (f(x))$ for each $x \in \alpha$.
Finsupp.instAddMonoid instance
: AddMonoid (α →₀ M)
Full source
instance instAddMonoid : AddMonoid (α →₀ M) :=
  fast_instance% DFunLike.coe_injective.addMonoid _ coe_zero coe_add fun _ _ => rfl
Additive Monoid Structure on Finitely Supported Functions
Informal description
For any type $\alpha$ and any additive monoid $M$, the type $\alpha \to_{\text{f}} M$ of finitely supported functions from $\alpha$ to $M$ forms an additive monoid under pointwise addition, with the zero function as the additive identity.
Finsupp.instAddCommMonoid instance
[AddCommMonoid M] : AddCommMonoid (α →₀ M)
Full source
instance instAddCommMonoid [AddCommMonoid M] : AddCommMonoid (α →₀ M) :=
  fast_instance% DFunLike.coe_injective.addCommMonoid
    DFunLike.coe coe_zero coe_add (fun _ _ => rfl)
Additive Commutative Monoid Structure on Finitely Supported Functions
Informal description
For any type $\alpha$ and any additive commutative monoid $M$, the type $\alpha \to_{\text{f}} M$ of finitely supported functions from $\alpha$ to $M$ forms an additive commutative monoid under pointwise addition.
Finsupp.instNeg instance
[NegZeroClass G] : Neg (α →₀ G)
Full source
instance instNeg [NegZeroClass G] : Neg (α →₀ G) :=
  ⟨mapRange Neg.neg neg_zero⟩
Negation on Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $G$ equipped with a negation operation that preserves zero (i.e., a `NegZeroClass`), the type of finitely supported functions $\alpha \to₀ G$ inherits a negation operation defined pointwise.
Finsupp.coe_neg theorem
[NegZeroClass G] (g : α →₀ G) : ⇑(-g) = -g
Full source
@[simp, norm_cast] lemma coe_neg [NegZeroClass G] (g : α →₀ G) : ⇑(-g) = -g := rfl
Pointwise Negation of Finitely Supported Functions
Informal description
For any type $\alpha$ and any type $G$ with a negation operation that preserves zero (i.e., $-0 = 0$), and for any finitely supported function $g \colon \alpha \to₀ G$, the underlying function of $-g$ is equal to the pointwise negation of $g$, i.e., $(-g)(a) = -g(a)$ for all $a \in \alpha$.
Finsupp.neg_apply theorem
[NegZeroClass G] (g : α →₀ G) (a : α) : (-g) a = -g a
Full source
theorem neg_apply [NegZeroClass G] (g : α →₀ G) (a : α) : (-g) a = -g a :=
  rfl
Pointwise Negation of Finitely Supported Functions: $(-g)(a) = -g(a)$
Informal description
For any type $\alpha$ and any type $G$ equipped with a negation operation that preserves zero (i.e., $-0 = 0$), and for any finitely supported function $g \colon \alpha \to₀ G$ and any element $a \in \alpha$, the evaluation of the negated function $-g$ at $a$ is equal to the negation of the evaluation of $g$ at $a$, i.e., $(-g)(a) = -g(a)$.
Finsupp.mapRange_neg theorem
[NegZeroClass G] [NegZeroClass H] {f : G → H} {hf : f 0 = 0} (hf' : ∀ x, f (-x) = -f x) (v : α →₀ G) : mapRange f hf (-v) = -mapRange f hf v
Full source
theorem mapRange_neg [NegZeroClass G] [NegZeroClass H] {f : G → H} {hf : f 0 = 0}
    (hf' : ∀ x, f (-x) = -f x) (v : α →₀ G) : mapRange f hf (-v) = -mapRange f hf v :=
  ext fun _ => by simp only [hf', neg_apply, mapRange_apply]
Negation Commutes with Composition of Finitely Supported Functions
Informal description
Let $G$ and $H$ be types equipped with a negation operation that preserves zero (i.e., $-0 = 0$). Given a function $f \colon G \to H$ such that $f(0) = 0$ and $f(-x) = -f(x)$ for all $x \in G$, and a finitely supported function $v \colon \alpha \to_{\text{fs}} G$, the composition of $f$ with the negation of $v$ equals the negation of the composition of $f$ with $v$. That is, $$ \text{mapRange}_f (-v) = -\text{mapRange}_f v. $$
Finsupp.mapRange_neg' theorem
[AddGroup G] [SubtractionMonoid H] [FunLike β G H] [AddMonoidHomClass β G H] {f : β} (v : α →₀ G) : mapRange f (map_zero f) (-v) = -mapRange f (map_zero f) v
Full source
theorem mapRange_neg' [AddGroup G] [SubtractionMonoid H] [FunLike β G H] [AddMonoidHomClass β G H]
    {f : β} (v : α →₀ G) :
    mapRange f (map_zero f) (-v) = -mapRange f (map_zero f) v :=
  mapRange_neg (map_neg f) v
Negation commutes with composition for finitely supported functions via additive monoid homomorphisms
Informal description
Let $G$ be an additive group and $H$ a subtraction monoid. Given an additive monoid homomorphism $f \colon G \to H$ and a finitely supported function $v \colon \alpha \to_{\text{fs}} G$, the composition of $f$ with the negation of $v$ equals the negation of the composition of $f$ with $v$. That is, $$ \text{mapRange}_f (-v) = -\text{mapRange}_f v. $$
Finsupp.instSub instance
[SubNegZeroMonoid G] : Sub (α →₀ G)
Full source
instance instSub [SubNegZeroMonoid G] : Sub (α →₀ G) :=
  ⟨zipWith Sub.sub (sub_zero _)⟩
Subtraction on Finitely Supported Functions
Informal description
For any type $\alpha$ and any sub-negation-zero monoid $G$, the type of finitely supported functions $\alpha \to_{\text{fs}} G$ is equipped with a subtraction operation, defined pointwise.
Finsupp.coe_sub theorem
[SubNegZeroMonoid G] (g₁ g₂ : α →₀ G) : ⇑(g₁ - g₂) = g₁ - g₂
Full source
@[simp, norm_cast] lemma coe_sub [SubNegZeroMonoid G] (g₁ g₂ : α →₀ G) : ⇑(g₁ - g₂) = g₁ - g₂ := rfl
Pointwise Subtraction of Finitely Supported Functions
Informal description
For any type $\alpha$ and any sub-negation-zero monoid $G$, the canonical map from the difference of two finitely supported functions $g_1, g_2 : \alpha \to_{\text{fs}} G$ to their pointwise difference is equal to the pointwise difference of the functions themselves. That is, $(g_1 - g_2)(a) = g_1(a) - g_2(a)$ for all $a \in \alpha$.
Finsupp.sub_apply theorem
[SubNegZeroMonoid G] (g₁ g₂ : α →₀ G) (a : α) : (g₁ - g₂) a = g₁ a - g₂ a
Full source
theorem sub_apply [SubNegZeroMonoid G] (g₁ g₂ : α →₀ G) (a : α) : (g₁ - g₂) a = g₁ a - g₂ a :=
  rfl
Pointwise Subtraction for Finitely Supported Functions
Informal description
For any type $\alpha$ and any sub-negation-zero monoid $G$, given two finitely supported functions $g_1, g_2 : \alpha \to_{\text{fs}} G$ and an element $a \in \alpha$, the evaluation of their difference at $a$ equals the difference of their evaluations, i.e., $(g_1 - g_2)(a) = g_1(a) - g_2(a)$.
Finsupp.mapRange_sub theorem
[SubNegZeroMonoid G] [SubNegZeroMonoid H] {f : G → H} {hf : f 0 = 0} (hf' : ∀ x y, f (x - y) = f x - f y) (v₁ v₂ : α →₀ G) : mapRange f hf (v₁ - v₂) = mapRange f hf v₁ - mapRange f hf v₂
Full source
theorem mapRange_sub [SubNegZeroMonoid G] [SubNegZeroMonoid H] {f : G → H} {hf : f 0 = 0}
    (hf' : ∀ x y, f (x - y) = f x - f y) (v₁ v₂ : α →₀ G) :
    mapRange f hf (v₁ - v₂) = mapRange f hf v₁ - mapRange f hf v₂ :=
  ext fun _ => by simp only [hf', sub_apply, mapRange_apply]
Preservation of Subtraction under Composition for Finitely Supported Functions
Informal description
Let $G$ and $H$ be sub-negation-zero monoids, and let $f \colon G \to H$ be a function such that $f(0) = 0$ and $f(x - y) = f(x) - f(y)$ for all $x, y \in G$. Then for any two finitely supported functions $v_1, v_2 \colon \alpha \to_{\text{fs}} G$, the following equality holds: \[ \text{mapRange}_f (v_1 - v_2) = \text{mapRange}_f v_1 - \text{mapRange}_f v_2, \] where $\text{mapRange}_f$ denotes the composition of $f$ with a finitely supported function, preserving the finite support property.
Finsupp.mapRange_sub' theorem
[AddGroup G] [SubtractionMonoid H] [FunLike β G H] [AddMonoidHomClass β G H] {f : β} (v₁ v₂ : α →₀ G) : mapRange f (map_zero f) (v₁ - v₂) = mapRange f (map_zero f) v₁ - mapRange f (map_zero f) v₂
Full source
theorem mapRange_sub' [AddGroup G] [SubtractionMonoid H] [FunLike β G H] [AddMonoidHomClass β G H]
    {f : β} (v₁ v₂ : α →₀ G) :
    mapRange f (map_zero f) (v₁ - v₂) = mapRange f (map_zero f) v₁ - mapRange f (map_zero f) v₂ :=
  mapRange_sub (map_sub f) v₁ v₂
Preservation of Subtraction under Additive Monoid Homomorphisms for Finitely Supported Functions
Informal description
Let $G$ be an additive group and $H$ be a subtraction monoid. Given a type $\beta$ that is function-like from $G$ to $H$ and an additive monoid homomorphism class $\beta$, for any homomorphism $f \colon \beta$ and any two finitely supported functions $v_1, v_2 \colon \alpha \to_{\text{fs}} G$, the following equality holds: \[ \text{mapRange}_f (v_1 - v_2) = \text{mapRange}_f v_1 - \text{mapRange}_f v_2, \] where $\text{mapRange}_f$ denotes the composition of $f$ with a finitely supported function, preserving the finite support property, and $\text{map\_zero}\, f$ ensures that $f(0) = 0$.
Finsupp.instIntSMul instance
[AddGroup G] : SMul ℤ (α →₀ G)
Full source
/-- Note the general `SMul` instance for `Finsupp` doesn't apply as `ℤ` is not distributive
unless `β i`'s addition is commutative. -/
instance instIntSMul [AddGroup G] : SMul  (α →₀ G) :=
  ⟨fun n v => v.mapRange (n • ·) (zsmul_zero _)⟩
Scalar Multiplication of Finitely Supported Functions by Integers
Informal description
For any additive group $G$ and any type $\alpha$, the type of finitely supported functions $\alpha \to₀ G$ has a natural scalar multiplication by integers. Specifically, for any integer $n \in \mathbb{Z}$ and any finitely supported function $f \colon \alpha \to₀ G$, the scalar multiple $n \cdot f$ is defined pointwise as $(n \cdot f)(a) = n \cdot (f(a))$ for each $a \in \alpha$.
Finsupp.instAddGroup instance
[AddGroup G] : AddGroup (α →₀ G)
Full source
instance instAddGroup [AddGroup G] : AddGroup (α →₀ G) :=
  fast_instance% DFunLike.coe_injective.addGroup DFunLike.coe coe_zero coe_add coe_neg coe_sub
    (fun _ _ => rfl) fun _ _ => rfl
Additive Group Structure on Finitely Supported Functions
Informal description
For any type $\alpha$ and any additive group $G$, the type $\alpha \to_{\text{f}} G$ of finitely supported functions from $\alpha$ to $G$ forms an additive group under pointwise addition, with the zero function as the additive identity and pointwise negation as the inverse operation.
Finsupp.instAddCommGroup instance
[AddCommGroup G] : AddCommGroup (α →₀ G)
Full source
instance instAddCommGroup [AddCommGroup G] : AddCommGroup (α →₀ G) :=
  fast_instance%  DFunLike.coe_injective.addCommGroup DFunLike.coe coe_zero coe_add coe_neg coe_sub
    (fun _ _ => rfl) fun _ _ => rfl
Additive Commutative Group Structure on Finitely Supported Functions
Informal description
For any type $\alpha$ and any additive commutative group $G$, the type $\alpha \to_{\text{f}} G$ of finitely supported functions from $\alpha$ to $G$ forms an additive commutative group under pointwise addition, with the zero function as the additive identity and pointwise negation as the inverse operation.
Finsupp.support_neg theorem
[AddGroup G] (f : α →₀ G) : support (-f) = support f
Full source
@[simp]
theorem support_neg [AddGroup G] (f : α →₀ G) : support (-f) = support f :=
  Finset.Subset.antisymm support_mapRange
    (calc
      support f = support (- -f) := congr_arg support (neg_neg _).symm
      _ ⊆ support (-f) := support_mapRange
      )
Support of Negated Finitely Supported Function Equals Original Support
Informal description
For any additive group $G$ and any finitely supported function $f \colon \alpha \to_{\text{f}} G$, the support of the negation $-f$ is equal to the support of $f$.
Finsupp.support_sub theorem
[DecidableEq α] [AddGroup G] {f g : α →₀ G} : support (f - g) ⊆ support f ∪ support g
Full source
theorem support_sub [DecidableEq α] [AddGroup G] {f g : α →₀ G} :
    supportsupport (f - g) ⊆ support f ∪ support g := by
  rw [sub_eq_add_neg, ← support_neg g]
  exact support_add
Support of Difference of Finitely Supported Functions is Contained in Union of Supports
Informal description
For any type $\alpha$ with decidable equality and any additive group $G$, let $f, g \colon \alpha \to_{\text{f}} G$ be finitely supported functions. Then the support of their difference $f - g$ is contained in the union of their supports, i.e., $\operatorname{supp}(f - g) \subseteq \operatorname{supp}(f) \cup \operatorname{supp}(g)$.