doc-next-gen

Mathlib.Data.DFinsupp.Defs

Module docstring

{"# Dependent functions with finite support

For a non-dependent version see Mathlib.Data.Finsupp.Defs.

Notation

This file introduces the notation Π₀ a, β a as notation for DFinsupp β, mirroring the α →₀ β notation used for Finsupp. This works for nested binders too, with Π₀ a b, γ a b as notation for DFinsupp (fun a ↦ DFinsupp (γ a)).

Implementation notes

The support is internally represented (in the primed DFinsupp.support') as a Multiset that represents a superset of the true support of the function, quotiented by the always-true relation so that this does not impact equality. This approach has computational benefits over storing a Finset; it allows us to add together two finitely-supported functions without having to evaluate the resulting function to recompute its support (which would required decidability of b = 0 for b : β i).

The true support of the function can still be recovered with DFinsupp.support; but these decidability obligations are now postponed to when the support is actually needed. As a consequence, there are two ways to sum a DFinsupp: with DFinsupp.sum which works over an arbitrary function but requires recomputation of the support and therefore a Decidable argument; and with DFinsupp.sumAddHom which requires an additive morphism, using its properties to show that summing over a superset of the support is sufficient.

Finsupp takes an altogether different approach here; it uses Classical.Decidable and declares the Add instance as noncomputable. This design difference is independent of the fact that DFinsupp is dependently-typed and Finsupp is not; in future, we may want to align these two definitions, or introduce two more definitions for the other combinations of decisions. ","### Bundled versions of DFinsupp.mapRange

The names should match the equivalent bundled Finsupp.mapRange definitions. "}

DFinsupp structure
[∀ i, Zero (β i)]
Full source
/-- A dependent function `Π i, β i` with finite support, with notation `Π₀ i, β i`.

Note that `DFinsupp.support` is the preferred API for accessing the support of the function,
`DFinsupp.support'` is an implementation detail that aids computability; see the implementation
notes in this file for more information. -/
structure DFinsupp [∀ i, Zero (β i)] : Type max u v where mk' ::
  /-- The underlying function of a dependent function with finite support (aka `DFinsupp`). -/
  toFun : ∀ i, β i
  /-- The support of a dependent function with finite support (aka `DFinsupp`). -/
  support' : Trunc { s : Multiset ι // ∀ i, i ∈ s ∨ toFun i = 0 }
Dependent function with finite support
Informal description
The structure `DFinsupp β` represents a dependent function with finite support, where for each index `i`, the codomain `β i` has a zero element. This is denoted by the notation `Π₀ i, β i`. The support of the function (the set of indices where the function is non-zero) is internally represented in a way that optimizes computational efficiency, though the true support can be recovered when needed.
termΠ₀_,_ definition
: Lean.ParserDescr✝
Full source
/-- `Π₀ i, β i` denotes the type of dependent functions with finite support `DFinsupp β`. -/
notation3 "Π₀ "(...)", "r:(scoped f => DFinsupp f) => r
Dependent functions with finite support
Informal description
The notation $\Pi_0 i, \beta i$ represents the type of dependent functions with finite support, where each function is zero for all but finitely many indices $i$. This is denoted as `DFinsupp β` in the formalization.
termΠ₀_,_.delab_app.DFinsupp definition
: Delab✝
Full source
/-- `Π₀ i, β i` denotes the type of dependent functions with finite support `DFinsupp β`. -/
notation3 "Π₀ "(...)", "r:(scoped f => DFinsupp f) => r
Notation for dependent functions with finite support
Informal description
The notation `Π₀ i, β i` represents the type of dependent functions with finite support (denoted by `DFinsupp β`), where each function is zero for all but finitely many indices `i`. This generalizes the non-dependent version `α →₀ β` (from `Finsupp`) to the dependent case.
DFinsupp.instDFunLike instance
: DFunLike (Π₀ i, β i) ι β
Full source
instance instDFunLike : DFunLike (Π₀ i, β i) ι β :=
  ⟨fun f => f.toFun, fun ⟨f₁, s₁⟩ ⟨f₂, s₁⟩ ↦ fun (h : f₁ = f₂) ↦ by
    subst h
    congr
    subsingleton ⟩
Dependent Functions with Finite Support are Function-Like
Informal description
The type `Π₀ i, β i` of dependent functions with finite support (where each `β i` has a zero element) can be naturally viewed as a dependent function-like type, meaning its elements can be treated as functions from the index type `ι` to the respective codomains `β i`.
DFinsupp.toFun_eq_coe theorem
(f : Π₀ i, β i) : f.toFun = f
Full source
@[simp]
theorem toFun_eq_coe (f : Π₀ i, β i) : f.toFun = f :=
  rfl
Underlying Function Equals Coefficient Function in DFinsupp
Informal description
For any dependent function $f$ with finite support (i.e., $f \in \Pi₀ i, \beta i$), the underlying function $f.\text{toFun}$ is equal to $f$ itself.
DFinsupp.ext theorem
{f g : Π₀ i, β i} (h : ∀ i, f i = g i) : f = g
Full source
@[ext]
theorem ext {f g : Π₀ i, β i} (h : ∀ i, f i = g i) : f = g :=
  DFunLike.ext _ _ h
Extensionality of Dependent Functions with Finite Support
Informal description
For any two dependent functions $f, g \in \Pi₀ i, \beta i$ with finite support, if $f(i) = g(i)$ for all indices $i$, then $f = g$.
DFinsupp.ne_iff theorem
{f g : Π₀ i, β i} : f ≠ g ↔ ∃ i, f i ≠ g i
Full source
lemma ne_iff {f g : Π₀ i, β i} : f ≠ gf ≠ g ↔ ∃ i, f i ≠ g i := DFunLike.ne_iff
Inequality Criterion for Dependent Functions with Finite Support
Informal description
For any two dependent functions $f, g \in \Pi₀ i, \beta i$ with finite support, $f \neq g$ if and only if there exists an index $i$ such that $f(i) \neq g(i)$.
DFinsupp.instZero instance
: Zero (Π₀ i, β i)
Full source
instance : Zero (Π₀ i, β i) :=
  ⟨⟨0, Trunc.mk <| ⟨∅, fun _ => Or.inr rfl⟩⟩⟩
Zero Element in Dependent Functions with Finite Support
Informal description
For any family of types $(\beta_i)_{i}$ where each $\beta_i$ has a zero element, the type $\Pi_0 i, \beta_i$ of dependent functions with finite support has a zero element given by the function that is identically zero on all indices.
DFinsupp.instInhabited instance
: Inhabited (Π₀ i, β i)
Full source
instance : Inhabited (Π₀ i, β i) :=
  ⟨0⟩
Inhabitedness of Dependent Functions with Finite Support
Informal description
For any family of types $(\beta_i)_{i}$ where each $\beta_i$ has a zero element, the type $\Pi_0 i, \beta_i$ of dependent functions with finite support is inhabited.
DFinsupp.coe_mk' theorem
(f : ∀ i, β i) (s) : ⇑(⟨f, s⟩ : Π₀ i, β i) = f
Full source
@[simp, norm_cast] lemma coe_mk' (f : ∀ i, β i) (s) : ⇑(⟨f, s⟩ : Π₀ i, β i) = f := rfl
Coefficient Extraction from Dependent Finite Support Function Construction
Informal description
For any dependent function $f : \forall i, \beta i$ and support specification $s$, the underlying function of the dependent function with finite support $\langle f, s \rangle$ is equal to $f$.
DFinsupp.coe_zero theorem
: ⇑(0 : Π₀ i, β i) = 0
Full source
@[simp, norm_cast] lemma coe_zero : ⇑(0 : Π₀ i, β i) = 0 := rfl
Zero Function in Dependent Functions with Finite Support
Informal description
The zero element in the type of dependent functions with finite support $\Pi₀ i, \beta i$ is the function that evaluates to zero for all inputs, i.e., $0(i) = 0$ for all $i \in \iota$.
DFinsupp.zero_apply theorem
(i : ι) : (0 : Π₀ i, β i) i = 0
Full source
theorem zero_apply (i : ι) : (0 : Π₀ i, β i) i = 0 :=
  rfl
Zero Evaluation in Dependent Functions with Finite Support: $(0)(i) = 0$
Informal description
For any index $i$ in the index type $\iota$, the evaluation of the zero dependent function with finite support at $i$ is equal to the zero element of $\beta i$, i.e., $(0 : \Pi_0 i, \beta i)(i) = 0$.
DFinsupp.mapRange definition
(f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (x : Π₀ i, β₁ i) : Π₀ i, β₂ i
Full source
/-- The composition of `f : β₁ → β₂` and `g : Π₀ i, β₁ i` is
  `mapRange f hf g : Π₀ i, β₂ i`, well defined when `f 0 = 0`.

This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself
bundled:

* `DFinsupp.mapRange.addMonoidHom`
* `DFinsupp.mapRange.addEquiv`
* `dfinsupp.mapRange.linearMap`
* `dfinsupp.mapRange.linearEquiv`
-/
def mapRange (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (x : Π₀ i, β₁ i) : Π₀ i, β₂ i :=
  ⟨fun i => f i (x i),
    x.support'.map fun s => ⟨s.1, fun i => (s.2 i).imp_right fun h : x i = 0 => by
      rw [← hf i, ← h]⟩⟩
Mapping the range of a dependent function with finite support
Informal description
Given a family of functions \( f_i : \beta_1 i \to \beta_2 i \) for each index \( i \), such that each \( f_i \) maps zero to zero, and a dependent function \( x : \Pi_{i} \beta_1 i \) with finite support, the function `DFinsupp.mapRange` constructs a new dependent function \( \Pi_{i} \beta_2 i \) by applying each \( f_i \) to the corresponding value \( x i \). The resulting function also has finite support, which is a superset of the original support of \( x \).
DFinsupp.mapRange_apply theorem
(f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (g : Π₀ i, β₁ i) (i : ι) : mapRange f hf g i = f i (g i)
Full source
@[simp]
theorem mapRange_apply (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (g : Π₀ i, β₁ i) (i : ι) :
    mapRange f hf g i = f i (g i) :=
  rfl
Evaluation of Mapped Dependent Function with Finite Support
Informal description
Let $f_i : \beta_1(i) \to \beta_2(i)$ be a family of functions indexed by $i \in \iota$ such that $f_i(0) = 0$ for each $i$. For any dependent function $g : \Pi_{i} \beta_1(i)$ with finite support and any index $i \in \iota$, the evaluation of the mapped function $\operatorname{mapRange}(f, hf, g)$ at $i$ equals $f_i(g(i))$.
DFinsupp.mapRange_comp theorem
(f : ∀ i, β₁ i → β₂ i) (f₂ : ∀ i, β i → β₁ i) (hf : ∀ i, f i 0 = 0) (hf₂ : ∀ i, f₂ i 0 = 0) (h : ∀ i, (f i ∘ f₂ i) 0 = 0) (g : Π₀ i : ι, β i) : mapRange (fun i => f i ∘ f₂ i) h g = mapRange f hf (mapRange f₂ hf₂ g)
Full source
theorem mapRange_comp (f : ∀ i, β₁ i → β₂ i) (f₂ : ∀ i, β i → β₁ i) (hf : ∀ i, f i 0 = 0)
    (hf₂ : ∀ i, f₂ i 0 = 0) (h : ∀ i, (f i ∘ f₂ i) 0 = 0) (g : Π₀ i : ι, β i) :
    mapRange (fun i => f i ∘ f₂ i) h g = mapRange f hf (mapRange f₂ hf₂ g) := by
  ext
  simp only [mapRange_apply]; rfl
Composition Law for Mapping Ranges of Dependent Functions with Finite Support
Informal description
Let $\beta, \beta_1, \beta_2$ be families of types indexed by $\iota$, each equipped with a zero element. Given families of functions $f_i \colon \beta_1 i \to \beta_2 i$ and $f_{2,i} \colon \beta i \to \beta_1 i$ such that: 1. $f_i(0) = 0$ for all $i \in \iota$, 2. $f_{2,i}(0) = 0$ for all $i \in \iota$, 3. $(f_i \circ f_{2,i})(0) = 0$ for all $i \in \iota$, then for any dependent function $g \in \Pi_{i} \beta i$ with finite support, we have: \[ \operatorname{mapRange} (f \circ f_2) h g = \operatorname{mapRange} f hf (\operatorname{mapRange} f_2 hf_2 g) \] where $f \circ f_2$ denotes the pointwise composition $(f \circ f_2)_i = f_i \circ f_{2,i}$.
DFinsupp.mapRange_zero theorem
(f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) : mapRange f hf (0 : Π₀ i, β₁ i) = 0
Full source
@[simp]
theorem mapRange_zero (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) :
    mapRange f hf (0 : Π₀ i, β₁ i) = 0 := by
  ext
  simp only [mapRange_apply, coe_zero, Pi.zero_apply, hf]
Mapping the Zero Function Preserves Zero under `mapRange`
Informal description
For any family of functions $f_i \colon \beta_1(i) \to \beta_2(i)$ such that $f_i(0) = 0$ for each index $i$, the mapping operation $\operatorname{mapRange}(f, hf)$ applied to the zero function in $\Pi_{i} \beta_1(i)$ yields the zero function in $\Pi_{i} \beta_2(i)$. That is, \[ \operatorname{mapRange}(f, hf)(0) = 0. \]
DFinsupp.zipWith definition
(f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) (x : Π₀ i, β₁ i) (y : Π₀ i, β₂ i) : Π₀ i, β i
Full source
/-- Let `f i` be a binary operation `β₁ i → β₂ i → β i` such that `f i 0 0 = 0`.
Then `zipWith f hf` is a binary operation `Π₀ i, β₁ i → Π₀ i, β₂ i → Π₀ i, β i`. -/
def zipWith (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) (x : Π₀ i, β₁ i) (y : Π₀ i, β₂ i) :
    Π₀ i, β i :=
  ⟨fun i => f i (x i) (y i), by
    refine x.support'.bind fun xs => ?_
    refine y.support'.map fun ys => ?_
    refine ⟨xs + ys, fun i => ?_⟩
    obtain h1 | (h1 : x i = 0) := xs.prop i
    · left
      rw [Multiset.mem_add]
      left
      exact h1
    obtain h2 | (h2 : y i = 0) := ys.prop i
    · left
      rw [Multiset.mem_add]
      right
      exact h2
    right; rw [← hf, ← h1, ← h2]⟩
Pointwise combination of dependent functions with finite support
Informal description
Given a family of binary operations \( f_i \colon \beta_1 i \to \beta_2 i \to \beta i \) such that \( f_i\,0\,0 = 0 \) for each index \( i \), the operation `zipWith f hf` combines two dependent functions \( x \colon \Pi₀ i, \beta_1 i \) and \( y \colon \Pi₀ i, \beta_2 i \) with finite support into a new dependent function \( \Pi₀ i, \beta i \). The resulting function is defined pointwise by \( (f_i (x i) (y i)) \) for each \( i \), and has finite support as ensured by the condition \( f_i\,0\,0 = 0 \).
DFinsupp.zipWith_apply theorem
(f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) (g₁ : Π₀ i, β₁ i) (g₂ : Π₀ i, β₂ i) (i : ι) : zipWith f hf g₁ g₂ i = f i (g₁ i) (g₂ i)
Full source
@[simp]
theorem zipWith_apply (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) (g₁ : Π₀ i, β₁ i)
    (g₂ : Π₀ i, β₂ i) (i : ι) : zipWith f hf g₁ g₂ i = f i (g₁ i) (g₂ i) :=
  rfl
Pointwise Evaluation of Combined Dependent Functions with Finite Support
Informal description
For a family of binary operations \( f_i \colon \beta_1 i \to \beta_2 i \to \beta i \) such that \( f_i(0, 0) = 0 \) for each index \( i \), and for any two dependent functions with finite support \( g_1 \colon \Pi_{i} \beta_1 i \) and \( g_2 \colon \Pi_{i} \beta_2 i \), the evaluation of their pointwise combination \( \text{zipWith}\,f\,hf\,g_1\,g_2 \) at any index \( i \) satisfies \[ (\text{zipWith}\,f\,hf\,g_1\,g_2)(i) = f_i(g_1(i), g_2(i)). \]
DFinsupp.piecewise definition
: Π₀ i, β i
Full source
/-- `x.piecewise y s` is the finitely supported function equal to `x` on the set `s`,
  and to `y` on its complement. -/
def piecewise : Π₀ i, β i :=
  zipWith (fun i x y => if i ∈ s then x else y) (fun _ => ite_self 0) x y
Piecewise combination of dependent functions with finite support
Informal description
Given two dependent functions with finite support \( x, y \colon \Pi_{i} \beta i \) and a set \( s \) of indices, the function \( x.piecewise\,y\,s \) is defined as the pointwise combination of \( x \) and \( y \) where for each index \( i \), the value is \( x i \) if \( i \in s \) and \( y i \) otherwise. This operation ensures that the resulting function has finite support, as it inherits the support properties from \( x \) and \( y \).
DFinsupp.piecewise_apply theorem
(i : ι) : x.piecewise y s i = if i ∈ s then x i else y i
Full source
theorem piecewise_apply (i : ι) : x.piecewise y s i = if i ∈ s then x i else y i :=
  zipWith_apply _ _ x y i
Pointwise Evaluation of Piecewise Dependent Function
Informal description
For any index $i \in \iota$, the evaluation of the piecewise combination $x.piecewise\,y\,s$ at $i$ is given by: \[ (x.piecewise\,y\,s)(i) = \begin{cases} x(i) & \text{if } i \in s, \\ y(i) & \text{otherwise}. \end{cases} \]
DFinsupp.coe_piecewise theorem
: ⇑(x.piecewise y s) = s.piecewise x y
Full source
@[simp, norm_cast]
theorem coe_piecewise : ⇑(x.piecewise y s) = s.piecewise x y := by
  ext
  apply piecewise_apply
Coefficient of Piecewise Dependent Function Equals Set Piecewise Function
Informal description
For any dependent functions with finite support $x, y \colon \Pi_{i} \beta i$ and any set $s$ of indices, the underlying function of the piecewise combination $x.piecewise\,y\,s$ is equal to the set-theoretic piecewise function defined by: \[ (x.piecewise\,y\,s)(i) = \begin{cases} x(i) & \text{if } i \in s, \\ y(i) & \text{otherwise.} \end{cases} \]
DFinsupp.instAdd instance
[∀ i, AddZeroClass (β i)] : Add (Π₀ i, β i)
Full source
instance [∀ i, AddZeroClass (β i)] : Add (Π₀ i, β i) :=
  ⟨zipWith (fun _ => (· + ·)) fun _ => add_zero 0⟩
Addition on Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ has an additive zero class structure, the type $\Pi₀ i, \beta_i$ of dependent functions with finite support is equipped with a pointwise addition operation.
DFinsupp.add_apply theorem
[∀ i, AddZeroClass (β i)] (g₁ g₂ : Π₀ i, β i) (i : ι) : (g₁ + g₂) i = g₁ i + g₂ i
Full source
theorem add_apply [∀ i, AddZeroClass (β i)] (g₁ g₂ : Π₀ i, β i) (i : ι) :
    (g₁ + g₂) i = g₁ i + g₂ i :=
  rfl
Pointwise Addition of Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ has an additive zero class structure, and for any two dependent functions with finite support $g_1, g_2 \in \Pi₀ i, \beta_i$, the evaluation of their sum at any index $i$ is equal to the sum of their evaluations at $i$, i.e., $(g_1 + g_2)(i) = g_1(i) + g_2(i)$.
DFinsupp.coe_add theorem
[∀ i, AddZeroClass (β i)] (g₁ g₂ : Π₀ i, β i) : ⇑(g₁ + g₂) = g₁ + g₂
Full source
@[simp, norm_cast]
theorem coe_add [∀ i, AddZeroClass (β i)] (g₁ g₂ : Π₀ i, β i) : ⇑(g₁ + g₂) = g₁ + g₂ :=
  rfl
Pointwise Addition of Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ has an additive zero class structure, and for any two dependent functions with finite support $g_1, g_2 \in \Pi₀ i, \beta_i$, the underlying function of their sum $g_1 + g_2$ is equal to the pointwise sum of the underlying functions of $g_1$ and $g_2$.
DFinsupp.addZeroClass instance
[∀ i, AddZeroClass (β i)] : AddZeroClass (Π₀ i, β i)
Full source
instance addZeroClass [∀ i, AddZeroClass (β i)] : AddZeroClass (Π₀ i, β i) :=
  DFunLike.coe_injective.addZeroClass _ coe_zero coe_add
Additive Zero Class Structure on Dependent Functions with Finite Support
Informal description
For any family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has an additive zero class structure, the type $\Pi₀ i, \beta_i$ of dependent functions with finite support forms an additive zero class with pointwise addition and zero function.
DFinsupp.instIsLeftCancelAdd instance
[∀ i, AddZeroClass (β i)] [∀ i, IsLeftCancelAdd (β i)] : IsLeftCancelAdd (Π₀ i, β i)
Full source
instance instIsLeftCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsLeftCancelAdd (β i)] :
    IsLeftCancelAdd (Π₀ i, β i) where
  add_left_cancel _ _ _ h := ext fun x => add_left_cancel <| DFunLike.congr_fun h x
Left Cancellation Property for Addition of Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ has an additive zero class structure and satisfies the left cancellation property for addition, the type $\Pi₀ i, \beta_i$ of dependent functions with finite support also satisfies the left cancellation property for addition. That is, for any $f, g, h \in \Pi₀ i, \beta_i$, if $f + g = f + h$, then $g = h$.
DFinsupp.instIsRightCancelAdd instance
[∀ i, AddZeroClass (β i)] [∀ i, IsRightCancelAdd (β i)] : IsRightCancelAdd (Π₀ i, β i)
Full source
instance instIsRightCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsRightCancelAdd (β i)] :
    IsRightCancelAdd (Π₀ i, β i) where
  add_right_cancel _ _ _ h := ext fun x => add_right_cancel <| DFunLike.congr_fun h x
Right Cancellation of Addition for Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ has an additive zero class structure and satisfies the right cancellation property for addition, the type $\Pi₀ i, \beta_i$ of dependent functions with finite support also satisfies the right cancellation property for addition. That is, for any $f, g, h \in \Pi₀ i, \beta_i$, if $f + h = g + h$, then $f = g$.
DFinsupp.instIsCancelAdd instance
[∀ i, AddZeroClass (β i)] [∀ i, IsCancelAdd (β i)] : IsCancelAdd (Π₀ i, β i)
Full source
instance instIsCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsCancelAdd (β i)] :
    IsCancelAdd (Π₀ i, β i) where
Cancellation Properties for Addition of Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ has an additive zero class structure and satisfies both left and right cancellation properties for addition, the type $\Pi₀ i, \beta_i$ of dependent functions with finite support also satisfies both cancellation properties for addition. That is, for any $f, g, h \in \Pi₀ i, \beta_i$, if $f + g = f + h$, then $g = h$, and if $f + h = g + h$, then $f = g$.
DFinsupp.hasNatScalar instance
[∀ i, AddMonoid (β i)] : SMul ℕ (Π₀ i, β i)
Full source
/-- Note the general `SMul` instance doesn't apply as `ℕ` is not distributive
unless `β i`'s addition is commutative. -/
instance hasNatScalar [∀ i, AddMonoid (β i)] : SMul  (Π₀ i, β i) :=
  ⟨fun c v => v.mapRange (fun _ => (c • ·)) fun _ => nsmul_zero _⟩
Natural Scalar Multiplication on Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ is equipped with an add monoid structure, the type $\Pi_{i} \beta_i$ of dependent functions with finite support has a natural scalar multiplication by natural numbers. Specifically, for any natural number $n$ and any function $f \in \Pi_{i} \beta_i$, the scalar multiplication $n \cdot f$ is defined pointwise as $(n \cdot f)(i) = n \cdot (f(i))$ for each index $i$.
DFinsupp.nsmul_apply theorem
[∀ i, AddMonoid (β i)] (b : ℕ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i
Full source
theorem nsmul_apply [∀ i, AddMonoid (β i)] (b : ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i :=
  rfl
Pointwise Natural Scalar Multiplication for Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ is equipped with an add monoid structure, the scalar multiplication of a natural number $b$ and a dependent function $v$ with finite support (i.e., $v \in \Pi_{i} \beta_i$) satisfies $(b \cdot v)(i) = b \cdot v(i)$ for every index $i$.
DFinsupp.coe_nsmul theorem
[∀ i, AddMonoid (β i)] (b : ℕ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v
Full source
@[simp, norm_cast]
theorem coe_nsmul [∀ i, AddMonoid (β i)] (b : ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v :=
  rfl
Pointwise Natural Scalar Multiplication for Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ is equipped with an add monoid structure, and for any natural number $b$ and any dependent function $v$ with finite support in $\Pi_{i} \beta_i$, the underlying function of the scalar multiple $b \cdot v$ is equal to the pointwise scalar multiple of the underlying function of $v$, i.e., $(b \cdot v)(i) = b \cdot (v(i))$ for all $i$.
DFinsupp.instAddMonoid instance
[∀ i, AddMonoid (β i)] : AddMonoid (Π₀ i, β i)
Full source
instance [∀ i, AddMonoid (β i)] : AddMonoid (Π₀ i, β i) :=
  DFunLike.coe_injective.addMonoid _ coe_zero coe_add fun _ _ => coe_nsmul _ _
Add Monoid Structure on Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ is equipped with an add monoid structure, the type $\Pi₀ i, \beta_i$ of dependent functions with finite support forms an add monoid under pointwise addition.
DFinsupp.coeFnAddMonoidHom definition
[∀ i, AddZeroClass (β i)] : (Π₀ i, β i) →+ ∀ i, β i
Full source
/-- Coercion from a `DFinsupp` to a pi type is an `AddMonoidHom`. -/
def coeFnAddMonoidHom [∀ i, AddZeroClass (β i)] : (Π₀ i, β i) →+ ∀ i, β i where
  toFun := (⇑)
  map_zero' := coe_zero
  map_add' := coe_add
Coefficient function as an additive monoid homomorphism
Informal description
The function `DFinsupp.coeFnAddMonoidHom` is an additive monoid homomorphism from the type `Π₀ i, β i` of dependent functions with finite support (where each `β i` has an additive zero class structure) to the type of all dependent functions `∀ i, β i`. It maps a dependent function with finite support to its underlying function, preserving the additive structure (i.e., it maps the zero function to the zero function and preserves addition pointwise).
DFinsupp.coeFnAddMonoidHom_apply theorem
[∀ i, AddZeroClass (β i)] (v : Π₀ i, β i) : coeFnAddMonoidHom v = v
Full source
@[simp]
lemma coeFnAddMonoidHom_apply [∀ i, AddZeroClass (β i)] (v : Π₀ i, β i) : coeFnAddMonoidHom v = v :=
  rfl
Coefficient Function Identity for Dependent Functions with Finite Support
Informal description
For any family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has an additive zero class structure, the coefficient function $\text{coeFnAddMonoidHom}$ maps a dependent function $v$ with finite support to itself, i.e., $\text{coeFnAddMonoidHom}(v) = v$.
DFinsupp.addCommMonoid instance
[∀ i, AddCommMonoid (β i)] : AddCommMonoid (Π₀ i, β i)
Full source
instance addCommMonoid [∀ i, AddCommMonoid (β i)] : AddCommMonoid (Π₀ i, β i) :=
  DFunLike.coe_injective.addCommMonoid _ coe_zero coe_add fun _ _ => coe_nsmul _ _
Additive Commutative Monoid Structure on Dependent Functions with Finite Support
Informal description
For any family of additive commutative monoids $\beta_i$ indexed by $i$, the type $\Pi₀ i, \beta_i$ of dependent functions with finite support forms an additive commutative monoid under pointwise addition.
DFinsupp.instNeg instance
[∀ i, AddGroup (β i)] : Neg (Π₀ i, β i)
Full source
instance [∀ i, AddGroup (β i)] : Neg (Π₀ i, β i) :=
  ⟨fun f => f.mapRange (fun _ => Neg.neg) fun _ => neg_zero⟩
Negation on Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, the type $\Pi_{i} \beta_i$ of dependent functions with finite support inherits a negation operation, defined pointwise as $(-f)(i) = -f(i)$ for each $i$.
DFinsupp.neg_apply theorem
[∀ i, AddGroup (β i)] (g : Π₀ i, β i) (i : ι) : (-g) i = -g i
Full source
theorem neg_apply [∀ i, AddGroup (β i)] (g : Π₀ i, β i) (i : ι) : (-g) i = -g i :=
  rfl
Pointwise Negation of Dependent Functions with Finite Support: $(-g)(i) = -g(i)$
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and for any dependent function $g \in \Pi_{i} \beta_i$ with finite support, the evaluation of the negation $-g$ at any index $i$ equals the negation of $g$ evaluated at $i$, i.e., $(-g)(i) = -g(i)$.
DFinsupp.coe_neg theorem
[∀ i, AddGroup (β i)] (g : Π₀ i, β i) : ⇑(-g) = -g
Full source
@[simp, norm_cast] lemma coe_neg [∀ i, AddGroup (β i)] (g : Π₀ i, β i) : ⇑(-g) = -g := rfl
Negation of Dependent Functions is Pointwise Negation
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and for any dependent function $g$ with finite support in $\Pi_{i} \beta_i$, the underlying function of the negation $-g$ is equal to the pointwise negation of $g$, i.e., $(-g)(i) = -g(i)$ for all $i$.
DFinsupp.instSub instance
[∀ i, AddGroup (β i)] : Sub (Π₀ i, β i)
Full source
instance [∀ i, AddGroup (β i)] : Sub (Π₀ i, β i) :=
  ⟨zipWith (fun _ => Sub.sub) fun _ => sub_zero 0⟩
Subtraction on Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, the type $\Pi₀ i, \beta_i$ of dependent functions with finite support is equipped with a subtraction operation.
DFinsupp.sub_apply theorem
[∀ i, AddGroup (β i)] (g₁ g₂ : Π₀ i, β i) (i : ι) : (g₁ - g₂) i = g₁ i - g₂ i
Full source
theorem sub_apply [∀ i, AddGroup (β i)] (g₁ g₂ : Π₀ i, β i) (i : ι) : (g₁ - g₂) i = g₁ i - g₂ i :=
  rfl
Pointwise Subtraction for Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and for any two dependent functions with finite support $g_1, g_2 \in \Pi_{i} \beta_i$, the subtraction $(g_1 - g_2)(i)$ at any index $i$ is equal to $g_1(i) - g_2(i)$.
DFinsupp.coe_sub theorem
[∀ i, AddGroup (β i)] (g₁ g₂ : Π₀ i, β i) : ⇑(g₁ - g₂) = g₁ - g₂
Full source
@[simp, norm_cast]
theorem coe_sub [∀ i, AddGroup (β i)] (g₁ g₂ : Π₀ i, β i) : ⇑(g₁ - g₂) = g₁ - g₂ :=
  rfl
Coercion of Pointwise Difference in Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and for any two dependent functions $g_1, g_2 \in \Pi_{i} \beta_i$ with finite support, the coercion of their difference $g_1 - g_2$ is equal to the pointwise difference of the functions, i.e., $(g_1 - g_2)(i) = g_1(i) - g_2(i)$ for all $i$.
DFinsupp.hasIntScalar instance
[∀ i, AddGroup (β i)] : SMul ℤ (Π₀ i, β i)
Full source
/-- Note the general `SMul` instance doesn't apply as `ℤ` is not distributive
unless `β i`'s addition is commutative. -/
instance hasIntScalar [∀ i, AddGroup (β i)] : SMul  (Π₀ i, β i) :=
  ⟨fun c v => v.mapRange (fun _ => (c • ·)) fun _ => zsmul_zero _⟩
Integer Scalar Multiplication on Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, the type of dependent functions with finite support $\Pi_{i} \beta_i$ has a scalar multiplication operation by integers, where for any integer $b$ and function $v \in \Pi_{i} \beta_i$, the scalar multiplication $(b \cdot v)(i) = b \cdot v(i)$ for each index $i$.
DFinsupp.zsmul_apply theorem
[∀ i, AddGroup (β i)] (b : ℤ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i
Full source
theorem zsmul_apply [∀ i, AddGroup (β i)] (b : ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i :=
  rfl
Pointwise Evaluation of Integer Scalar Multiplication on Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, any integer $b$, and any dependent function $v \in \Pi_{i} \beta_i$ with finite support, the evaluation of the scalar multiple $b \cdot v$ at any index $i$ is equal to the scalar multiple of the evaluation of $v$ at $i$, i.e., $(b \cdot v)(i) = b \cdot v(i)$.
DFinsupp.coe_zsmul theorem
[∀ i, AddGroup (β i)] (b : ℤ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v
Full source
@[simp, norm_cast]
theorem coe_zsmul [∀ i, AddGroup (β i)] (b : ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v :=
  rfl
Pointwise Scalar Multiplication of Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and for any integer $b$ and dependent function $v \in \Pi_{i} \beta_i$ with finite support, the underlying function of the scalar multiple $b \cdot v$ is equal to the pointwise scalar multiple of the underlying function of $v$, i.e., $(b \cdot v)(i) = b \cdot v(i)$ for all $i$.
DFinsupp.instAddGroup instance
[∀ i, AddGroup (β i)] : AddGroup (Π₀ i, β i)
Full source
instance [∀ i, AddGroup (β i)] : AddGroup (Π₀ i, β i) :=
  DFunLike.coe_injective.addGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_nsmul _ _)
    fun _ _ => coe_zsmul _ _
Additive Group Structure on Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, the type $\Pi_{i} \beta_i$ of dependent functions with finite support forms an additive group, where the group operations (addition, negation, and zero) are defined pointwise.
DFinsupp.addCommGroup instance
[∀ i, AddCommGroup (β i)] : AddCommGroup (Π₀ i, β i)
Full source
instance addCommGroup [∀ i, AddCommGroup (β i)] : AddCommGroup (Π₀ i, β i) :=
  DFunLike.coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_nsmul _ _)
    fun _ _ => coe_zsmul _ _
Additive Commutative Group Structure on Dependent Functions with Finite Support
Informal description
For any family of additive commutative groups $(\beta_i)_{i \in \iota}$, the type $\Pi_{i \in \iota} \beta_i$ of dependent functions with finite support forms an additive commutative group, where the addition, negation, and zero element are defined pointwise.
DFinsupp.filter definition
[∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (x : Π₀ i, β i) : Π₀ i, β i
Full source
/-- `Filter p f` is the function which is `f i` if `p i` is true and 0 otherwise. -/
def filter [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (x : Π₀ i, β i) : Π₀ i, β i :=
  ⟨fun i => if p i then x i else 0,
    x.support'.map fun xs =>
      ⟨xs.1, fun i => (xs.prop i).imp_right fun H : x i = 0 => by simp only [H, ite_self]⟩⟩
Filtering a dependent function with finite support
Informal description
Given a predicate `p : ι → Prop` and a dependent function `x : Π₀ i, β i` with finite support, the function `DFinsupp.filter p x` is defined as the dependent function that equals `x i` when `p i` holds and `0` otherwise. Here, each `β i` is required to have a zero element. More formally, for each index `i`, we have: \[ (\text{DFinsupp.filter } p \ x)(i) = \begin{cases} x(i) & \text{if } p(i) \text{ holds} \\ 0 & \text{otherwise} \end{cases} \]
DFinsupp.filter_apply theorem
[∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (i : ι) (f : Π₀ i, β i) : f.filter p i = if p i then f i else 0
Full source
@[simp]
theorem filter_apply [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (i : ι) (f : Π₀ i, β i) :
    f.filter p i = if p i then f i else 0 :=
  rfl
Filtered Evaluation of Dependent Function with Finite Support
Informal description
For a dependent function $f$ with finite support (i.e., $f \in \Pi_{i} \beta_i$ where each $\beta_i$ has a zero element), a predicate $p$ on the index set $\iota$, and an index $i \in \iota$, the filtered function $f.\text{filter } p$ satisfies: \[ (f.\text{filter } p)(i) = \begin{cases} f(i) & \text{if } p(i) \text{ holds}, \\ 0 & \text{otherwise.} \end{cases} \]
DFinsupp.filter_apply_pos theorem
[∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] (f : Π₀ i, β i) {i : ι} (h : p i) : f.filter p i = f i
Full source
theorem filter_apply_pos [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] (f : Π₀ i, β i) {i : ι}
    (h : p i) : f.filter p i = f i := by simp only [filter_apply, if_pos h]
Filtered dependent function preserves values at positive indices
Informal description
For a dependent function $f \in \Pi_{i} \beta_i$ with finite support (where each $\beta_i$ has a zero element), a decidable predicate $p$ on the index set $\iota$, and an index $i \in \iota$ such that $p(i)$ holds, the filtered function satisfies $(f.\text{filter } p)(i) = f(i)$.
DFinsupp.filter_apply_neg theorem
[∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] (f : Π₀ i, β i) {i : ι} (h : ¬p i) : f.filter p i = 0
Full source
theorem filter_apply_neg [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] (f : Π₀ i, β i) {i : ι}
    (h : ¬p i) : f.filter p i = 0 := by simp only [filter_apply, if_neg h]
Filtered dependent function vanishes at negated indices
Informal description
For a dependent function $f \in \Pi_{i} \beta_i$ with finite support (where each $\beta_i$ has a zero element), a decidable predicate $p$ on the index set $\iota$, and an index $i \in \iota$ such that $\neg p(i)$ holds, the filtered function satisfies $(f.\text{filter } p)(i) = 0$.
DFinsupp.filter_pos_add_filter_neg theorem
[∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (p : ι → Prop) [DecidablePred p] : (f.filter p + f.filter fun i => ¬p i) = f
Full source
theorem filter_pos_add_filter_neg [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (p : ι → Prop)
    [DecidablePred p] : (f.filter p + f.filter fun i => ¬p i) = f :=
  ext fun i => by
    simp only [add_apply, filter_apply]; split_ifs <;> simp only [add_zero, zero_add]
Decomposition of Dependent Function via Filtering: $f_{\text{filter } p} + f_{\text{filter } \neg p} = f$
Informal description
For any dependent function $f \in \Pi_{i} \beta_i$ with finite support (where each $\beta_i$ has an additive zero class structure) and any decidable predicate $p$ on the index set $\iota$, the sum of the filtered functions $f.\text{filter } p$ and $f.\text{filter } (\lambda i, \neg p(i))$ equals $f$ itself. That is, \[ f.\text{filter } p + f.\text{filter } (\lambda i, \neg p(i)) = f. \]
DFinsupp.filter_zero theorem
[∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] : (0 : Π₀ i, β i).filter p = 0
Full source
@[simp]
theorem filter_zero [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] :
    (0 : Π₀ i, β i).filter p = 0 := by
  ext
  simp
Filtering the Zero Function Yields Zero
Informal description
For any predicate $p$ on the index set $\iota$ (with a decidable truth value) and for any family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has a zero element, the filtered zero function satisfies $(0.\text{filter } p) = 0$. Here, $0$ denotes the zero element in the type of dependent functions with finite support $\Pi_0 i, \beta_i$. More formally, for all $i \in \iota$: \[ (0.\text{filter } p)(i) = 0 \]
DFinsupp.filter_add theorem
[∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] (f g : Π₀ i, β i) : (f + g).filter p = f.filter p + g.filter p
Full source
@[simp]
theorem filter_add [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] (f g : Π₀ i, β i) :
    (f + g).filter p = f.filter p + g.filter p := by
  ext
  simp [ite_add_zero]
Filter Distributes Over Addition in Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ has an additive zero class structure, and for any predicate $p : \iota \to \text{Prop}$ with a decidable condition, the filter operation on dependent functions with finite support distributes over addition. That is, for any $f, g \in \Pi₀ i, \beta_i$, we have: \[ (f + g).\text{filter } p = f.\text{filter } p + g.\text{filter } p \]
DFinsupp.filterAddMonoidHom definition
[∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i, β i) →+ Π₀ i, β i
Full source
/-- `DFinsupp.filter` as an `AddMonoidHom`. -/
@[simps]
def filterAddMonoidHom [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] :
    (Π₀ i, β i) →+ Π₀ i, β i where
  toFun := filter p
  map_zero' := filter_zero p
  map_add' := filter_add p
Filter as an additive monoid homomorphism on dependent functions with finite support
Informal description
For a family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has an additive zero class structure, and for a predicate $p : \iota \to \text{Prop}$ with a decidable condition, the function $\text{filter } p$ is an additive monoid homomorphism from $\Pi₀ i, \beta_i$ to itself. More precisely, the homomorphism satisfies: 1. $\text{filter } p \ 0 = 0$ (preservation of zero) 2. $\text{filter } p \ (f + g) = \text{filter } p \ f + \text{filter } p \ g$ for any $f, g \in \Pi₀ i, \beta_i$ (additivity)
DFinsupp.filter_neg theorem
[∀ i, AddGroup (β i)] (p : ι → Prop) [DecidablePred p] (f : Π₀ i, β i) : (-f).filter p = -f.filter p
Full source
@[simp]
theorem filter_neg [∀ i, AddGroup (β i)] (p : ι → Prop) [DecidablePred p] (f : Π₀ i, β i) :
    (-f).filter p = -f.filter p :=
  (filterAddMonoidHom β p).map_neg f
Negation Commutes with Filter in Finitely Supported Dependent Functions
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, any predicate $p : \iota \to \text{Prop}$ with a decidable condition, and any dependent function $f \in \Pi₀ i, \beta_i$ with finite support, the filter operation commutes with negation. That is, \[ (-f).\text{filter } p = -(f.\text{filter } p). \]
DFinsupp.filter_sub theorem
[∀ i, AddGroup (β i)] (p : ι → Prop) [DecidablePred p] (f g : Π₀ i, β i) : (f - g).filter p = f.filter p - g.filter p
Full source
@[simp]
theorem filter_sub [∀ i, AddGroup (β i)] (p : ι → Prop) [DecidablePred p] (f g : Π₀ i, β i) :
    (f - g).filter p = f.filter p - g.filter p :=
  (filterAddMonoidHom β p).map_sub f g
Filtering Preserves Subtraction in Finitely Supported Dependent Functions
Informal description
For any family of additive groups $(\beta_i)_{i \in \iota}$, a decidable predicate $p : \iota \to \text{Prop}$, and any two dependent functions $f, g \in \Pi₀ i, \beta_i$ with finite support, the following equality holds: \[ \text{filter } p \ (f - g) = \text{filter } p \ f - \text{filter } p \ g \] where $\text{filter } p$ is the operation that restricts a function to the indices satisfying $p$ (setting others to zero), and the subtraction is performed pointwise.
DFinsupp.subtypeDomain definition
[∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (x : Π₀ i, β i) : Π₀ i : Subtype p, β i
Full source
/-- `subtypeDomain p f` is the restriction of the finitely supported function
  `f` to the subtype `p`. -/
def subtypeDomain [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (x : Π₀ i, β i) :
    Π₀ i : Subtype p, β i :=
  ⟨fun i => x (i : ι),
    x.support'.map fun xs =>
      ⟨(Multiset.filter p xs.1).attach.map fun j => ⟨j.1, (Multiset.mem_filter.1 j.2).2⟩, fun i =>
        (xs.prop i).imp_left fun H =>
          Multiset.mem_map.2
            ⟨⟨i, Multiset.mem_filter.2 ⟨H, i.2⟩⟩, Multiset.mem_attach _ _, Subtype.eta _ _⟩⟩⟩
Restriction of a finitely supported dependent function to a subtype
Informal description
Given a predicate \( p \) on the index type \( \iota \), the function `subtypeDomain p f` restricts the finitely supported dependent function \( f : \Pi₀ i, \beta i \) to the subtype of indices where \( p \) holds. The resulting function is still finitely supported and takes values in \( \beta i \) for \( i \) in the subtype defined by \( p \).
DFinsupp.subtypeDomain_zero theorem
[∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] : subtypeDomain p (0 : Π₀ i, β i) = 0
Full source
@[simp]
theorem subtypeDomain_zero [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] :
    subtypeDomain p (0 : Π₀ i, β i) = 0 :=
  rfl
Restriction of Zero Function to Subtype is Zero
Informal description
For any family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has a zero element, and for any decidable predicate $p$ on $\iota$, the restriction of the zero function to the subtype defined by $p$ is equal to the zero function in the restricted domain. That is, $\text{subtypeDomain}_p(0) = 0$.
DFinsupp.subtypeDomain_apply theorem
[∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] {i : Subtype p} {v : Π₀ i, β i} : (subtypeDomain p v) i = v i
Full source
@[simp]
theorem subtypeDomain_apply [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] {i : Subtype p}
    {v : Π₀ i, β i} : (subtypeDomain p v) i = v i :=
  rfl
Restriction of Finitely Supported Function Preserves Values on Subtype
Informal description
For any family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has a zero element, and for any decidable predicate $p$ on $\iota$, the restriction of a finitely supported dependent function $v : \Pi₀ i, \beta i$ to the subtype defined by $p$ satisfies $(v \restriction_p) i = v i$ for any $i$ in the subtype.
DFinsupp.subtypeDomain_add theorem
[∀ i, AddZeroClass (β i)] {p : ι → Prop} [DecidablePred p] (v v' : Π₀ i, β i) : (v + v').subtypeDomain p = v.subtypeDomain p + v'.subtypeDomain p
Full source
@[simp]
theorem subtypeDomain_add [∀ i, AddZeroClass (β i)] {p : ι → Prop} [DecidablePred p]
    (v v' : Π₀ i, β i) : (v + v').subtypeDomain p = v.subtypeDomain p + v'.subtypeDomain p :=
  DFunLike.coe_injective rfl
Additivity of Subtype Restriction for Finitely Supported Dependent Functions
Informal description
For any family of types $\beta_i$ indexed by $i \in \iota$ where each $\beta_i$ has an additive zero class structure, and for any decidable predicate $p$ on $\iota$, the restriction of the sum of two finitely supported dependent functions $v, v' \in \Pi₀ i, \beta i$ to the subtype defined by $p$ equals the sum of their restrictions. That is, $$(v + v') \restriction_p = v \restriction_p + v' \restriction_p.$$
DFinsupp.subtypeDomainAddMonoidHom definition
[∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i : ι, β i) →+ Π₀ i : Subtype p, β i
Full source
/-- `subtypeDomain` but as an `AddMonoidHom`. -/
@[simps]
def subtypeDomainAddMonoidHom [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] :
    (Π₀ i : ι, β i) →+ Π₀ i : Subtype p, β i where
  toFun := subtypeDomain p
  map_zero' := subtypeDomain_zero
  map_add' := subtypeDomain_add
Additive monoid homomorphism for restriction to subtype of finitely supported dependent functions
Informal description
Given a family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has an additive zero class structure, and a decidable predicate $p$ on $\iota$, the function `subtypeDomainAddMonoidHom p` is the additive monoid homomorphism that restricts a finitely supported dependent function $f \in \Pi₀ i, \beta i$ to the subtype $\{i \in \iota \mid p(i)\}$. Explicitly, it maps $f$ to the function $f \restriction_p$ defined by $(f \restriction_p)(i) = f(i)$ for $i$ in the subtype, and preserves addition and the zero function.
DFinsupp.subtypeDomain_neg theorem
[∀ i, AddGroup (β i)] {p : ι → Prop} [DecidablePred p] {v : Π₀ i, β i} : (-v).subtypeDomain p = -v.subtypeDomain p
Full source
@[simp]
theorem subtypeDomain_neg [∀ i, AddGroup (β i)] {p : ι → Prop} [DecidablePred p] {v : Π₀ i, β i} :
    (-v).subtypeDomain p = -v.subtypeDomain p :=
  DFunLike.coe_injective rfl
Negation Commutes with Restriction in Finitely Supported Dependent Functions
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and any decidable predicate $p$ on the index type $\iota$, the restriction of the negation of a finitely supported dependent function $v : \Pi_{i} \beta_i$ to the subtype defined by $p$ is equal to the negation of the restriction of $v$ to the same subtype. That is, $(-v)\big|_p = - (v\big|_p)$.
DFinsupp.subtypeDomain_sub theorem
[∀ i, AddGroup (β i)] {p : ι → Prop} [DecidablePred p] {v v' : Π₀ i, β i} : (v - v').subtypeDomain p = v.subtypeDomain p - v'.subtypeDomain p
Full source
@[simp]
theorem subtypeDomain_sub [∀ i, AddGroup (β i)] {p : ι → Prop} [DecidablePred p]
    {v v' : Π₀ i, β i} : (v - v').subtypeDomain p = v.subtypeDomain p - v'.subtypeDomain p :=
  DFunLike.coe_injective rfl
Restriction of Difference Equals Difference of Restrictions for Finitely Supported Dependent Functions
Informal description
Let $\beta_i$ be a family of additive groups indexed by $i \in \iota$, and let $p : \iota \to \text{Prop}$ be a decidable predicate on $\iota$. For any two dependent functions with finite support $v, v' \in \Pi_{i} \beta_i$, the restriction of their difference to the subtype defined by $p$ equals the difference of their restrictions. That is, $$(v - v')|_p = v|_p - v'|_p$$ where $(\cdot)|_p$ denotes the restriction to the subtype $\{i \in \iota \mid p(i)\}$.
DFinsupp.finite_support theorem
(f : Π₀ i, β i) : Set.Finite {i | f i ≠ 0}
Full source
theorem finite_support (f : Π₀ i, β i) : Set.Finite { i | f i ≠ 0 } :=
  Trunc.induction_on f.support' fun xs ↦
    xs.1.finite_toSet.subset fun i H ↦ ((xs.prop i).resolve_right H)
Finite Support Property of Dependent Functions
Informal description
For any dependent function $f$ with finite support (i.e., $f \in \Pi_{i} \beta i$ where each $\beta i$ has a zero element), the set of indices $\{i \mid f(i) \neq 0\}$ is finite.
DFinsupp.mk definition
(s : Finset ι) (x : ∀ i : (↑s : Set ι), β (i : ι)) : Π₀ i, β i
Full source
/-- Create an element of `Π₀ i, β i` from a finset `s` and a function `x`
defined on this `Finset`. -/
def mk (s : Finset ι) (x : ∀ i : (↑s : Set ι), β (i : ι)) : Π₀ i, β i :=
  ⟨fun i => if H : i ∈ s then x ⟨i, H⟩ else 0,
    Trunc.mk ⟨s.1, fun i => if H : i ∈ s then Or.inl H else Or.inr <| dif_neg H⟩⟩
Construction of dependent function with finite support from a finite set
Informal description
Given a finite set $s$ of indices and a function $x$ defined on $s$ (where for each $i \in s$, $x_i$ is an element of $\beta i$), this constructs a dependent function with finite support $\Pi_{i} \beta i$ that equals $x_i$ for $i \in s$ and zero otherwise.
DFinsupp.mk_apply theorem
: (mk s x : ∀ i, β i) i = if H : i ∈ s then x ⟨i, H⟩ else 0
Full source
@[simp]
theorem mk_apply : (mk s x : ∀ i, β i) i = if H : i ∈ s then x ⟨i, H⟩ else 0 :=
  rfl
Evaluation of Constructed Dependent Function with Finite Support
Informal description
For a dependent function with finite support constructed from a finite set $s$ of indices and a function $x$ defined on $s$, the value at any index $i$ is given by: \[ (\text{mk } s \, x)(i) = \begin{cases} x \langle i, H \rangle & \text{if } i \in s \text{ (with proof } H \text{)} \\ 0 & \text{otherwise} \end{cases} \]
DFinsupp.mk_of_mem theorem
(hi : i ∈ s) : (mk s x : ∀ i, β i) i = x ⟨i, hi⟩
Full source
theorem mk_of_mem (hi : i ∈ s) : (mk s x : ∀ i, β i) i = x ⟨i, hi⟩ :=
  dif_pos hi
Evaluation of Constructed Dependent Function at Member Index
Informal description
For a dependent function with finite support constructed from a finite set $s$ of indices and a function $x$ defined on $s$, if an index $i$ belongs to $s$ (with proof $hi$), then the value of the function at $i$ equals $x$ evaluated at the pair $\langle i, hi \rangle$, i.e., \[ (\text{mk } s \, x)(i) = x \langle i, hi \rangle. \]
DFinsupp.mk_of_not_mem theorem
(hi : i ∉ s) : (mk s x : ∀ i, β i) i = 0
Full source
theorem mk_of_not_mem (hi : i ∉ s) : (mk s x : ∀ i, β i) i = 0 :=
  dif_neg hi
Vanishing Property of Dependent Function Outside Support
Informal description
For a dependent function with finite support constructed from a finite set $s$ of indices and a function $x$ defined on $s$, if an index $i$ does not belong to $s$ (with proof $hi$), then the value of the function at $i$ is zero, i.e., \[ (\text{mk } s \, x)(i) = 0. \]
DFinsupp.mk_injective theorem
(s : Finset ι) : Function.Injective (@mk ι β _ _ s)
Full source
theorem mk_injective (s : Finset ι) : Function.Injective (@mk ι β _ _ s) := by
  intro x y H
  ext i
  have h1 : (mk s x : ∀ i, β i) i = (mk s y : ∀ i, β i) i := by rw [H]
  obtain ⟨i, hi : i ∈ s⟩ := i
  dsimp only [mk_apply, Subtype.coe_mk] at h1
  simpa only [dif_pos hi] using h1
Injectivity of Dependent Function Construction from Finite Support
Informal description
For any finite set $s$ of indices, the construction function `mk` that builds a dependent function with finite support from a function defined on $s$ is injective. In other words, if two functions $x$ and $y$ defined on $s$ satisfy `mk s x = mk s y`, then $x = y$ pointwise on $s$.
DFinsupp.unique instance
[∀ i, Subsingleton (β i)] : Unique (Π₀ i, β i)
Full source
instance unique [∀ i, Subsingleton (β i)] : Unique (Π₀ i, β i) :=
  DFunLike.coe_injective.unique
Uniqueness of Finitely Supported Dependent Functions on Subsingleton Codomains
Informal description
For any family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ is a subsingleton (i.e., has at most one element), the type $\Pi_0 i, \beta_i$ of dependent functions with finite support is uniquely inhabited (has exactly one element).
DFinsupp.uniqueOfIsEmpty instance
[IsEmpty ι] : Unique (Π₀ i, β i)
Full source
instance uniqueOfIsEmpty [IsEmpty ι] : Unique (Π₀ i, β i) :=
  DFunLike.coe_injective.unique
Uniqueness of Dependent Functions with Empty Domain
Informal description
For any empty index type $\iota$, the type $\Pi_0 i, \beta i$ of dependent functions with finite support is uniquely inhabited (i.e., it has exactly one element).
DFinsupp.equivFunOnFintype definition
[Fintype ι] : (Π₀ i, β i) ≃ ∀ i, β i
Full source
/-- Given `Fintype ι`, `equivFunOnFintype` is the `Equiv` between `Π₀ i, β i` and `Π i, β i`.
  (All dependent functions on a finite type are finitely supported.) -/
@[simps apply]
def equivFunOnFintype [Fintype ι] : (Π₀ i, β i) ≃ ∀ i, β i where
  toFun := (⇑)
  invFun f := ⟨f, Trunc.mk ⟨Finset.univ.1, fun _ => Or.inl <| Finset.mem_univ_val _⟩⟩
  left_inv _ := DFunLike.coe_injective rfl
  right_inv _ := rfl
Equivalence between finitely supported and arbitrary dependent functions on a finite type
Informal description
Given a finite type `ι`, the equivalence `equivFunOnFintype` establishes a bijection between the type `Π₀ i, β i` of dependent functions with finite support (where each `β i` has a zero element) and the type `Π i, β i` of all dependent functions on `ι`. This means that every dependent function on a finite type is automatically finitely supported.
DFinsupp.equivFunOnFintype_symm_coe theorem
[Fintype ι] (f : Π₀ i, β i) : equivFunOnFintype.symm f = f
Full source
@[simp]
theorem equivFunOnFintype_symm_coe [Fintype ι] (f : Π₀ i, β i) : equivFunOnFintype.symm f = f :=
  Equiv.symm_apply_apply _ _
Inverse Equivalence Preserves Finitely Supported Dependent Functions on Finite Types
Informal description
For any finite type $\iota$ and any dependent function $f$ with finite support in $\Pi_{i}, \beta i$, the inverse of the equivalence `equivFunOnFintype` applied to $f$ is equal to $f$ itself. That is, $\text{equivFunOnFintype}^{-1}(f) = f$.
DFinsupp.single definition
(i : ι) (b : β i) : Π₀ i, β i
Full source
/-- The function `single i b : Π₀ i, β i` sends `i` to `b`
and all other points to `0`. -/
def single (i : ι) (b : β i) : Π₀ i, β i :=
  ⟨Pi.single i b,
    Trunc.mk ⟨{i}, fun j => (Decidable.eq_or_ne j i).imp (by simp) fun h => Pi.single_eq_of_ne h _⟩⟩
Dependent Kronecker delta function
Informal description
The function `single i b` is the dependent function with finite support that maps the index `i` to `b` and all other indices to `0$. More formally, for any index `i'`, the value of `single i b` at `i'` is `b` if `i' = i` and `0` otherwise.
DFinsupp.single_eq_pi_single theorem
{i b} : ⇑(single i b : Π₀ i, β i) = Pi.single i b
Full source
theorem single_eq_pi_single {i b} : ⇑(single i b : Π₀ i, β i) = Pi.single i b :=
  rfl
Equality of Dependent Kronecker Delta and Pointwise Single Function
Informal description
For any index $i$ and element $b \in \beta i$, the dependent function with finite support $\text{single}_i(b)$ coincides with the pointwise-defined function $\text{Pi.single}_i(b)$ on their common domain. That is, $\text{single}_i(b) = \text{Pi.single}_i(b)$ as functions.
DFinsupp.single_apply theorem
{i i' b} : (single i b : Π₀ i, β i) i' = if h : i = i' then Eq.recOn h b else 0
Full source
@[simp]
theorem single_apply {i i' b} :
    (single i b : Π₀ i, β i) i' = if h : i = i' then Eq.recOn h b else 0 := by
  rw [single_eq_pi_single, Pi.single, Function.update]
  simp [@eq_comm _ i i']
Evaluation of Dependent Kronecker Delta Function: $\text{single}_i(b)(i') = b \text{ if } i = i' \text{ else } 0$
Informal description
For any indices $i, i'$ and element $b \in \beta i$, the value of the dependent Kronecker delta function $\text{single}_i(b)$ at index $i'$ is equal to $b$ if $i = i'$ (via the equality proof $h$) and $0$ otherwise. More formally: \[ \text{single}_i(b)(i') = \begin{cases} b & \text{if } i = i', \\ 0 & \text{otherwise.} \end{cases} \]
DFinsupp.single_zero theorem
(i) : (single i 0 : Π₀ i, β i) = 0
Full source
@[simp]
theorem single_zero (i) : (single i 0 : Π₀ i, β i) = 0 :=
  DFunLike.coe_injective <| Pi.single_zero _
Kronecker Delta at Zero is the Zero Function
Informal description
For any index $i$, the dependent Kronecker delta function `single i 0` is equal to the zero function in the space of dependent functions with finite support, i.e., $\text{single}_i(0) = 0$.
DFinsupp.single_eq_same theorem
{i b} : (single i b : Π₀ i, β i) i = b
Full source
theorem single_eq_same {i b} : (single i b : Π₀ i, β i) i = b := by
  simp only [single_apply, dite_eq_ite, ite_true]
Evaluation of Dependent Kronecker Delta at Same Index: $\text{single}_i(b)(i) = b$
Informal description
For any index $i$ and element $b \in \beta i$, the dependent Kronecker delta function $\text{single}_i(b)$ evaluated at $i$ equals $b$, i.e., \[ \text{single}_i(b)(i) = b. \]
DFinsupp.single_eq_of_ne theorem
{i i' b} (h : i ≠ i') : (single i b : Π₀ i, β i) i' = 0
Full source
theorem single_eq_of_ne {i i' b} (h : i ≠ i') : (single i b : Π₀ i, β i) i' = 0 := by
  simp only [single_apply, dif_neg h]
Vanishing of Kronecker Delta at Distinct Indices
Informal description
For any indices $i$ and $i'$ with $i \neq i'$ and any element $b \in \beta i$, the dependent Kronecker delta function $\text{single}_i(b)$ evaluated at $i'$ is zero, i.e., $\text{single}_i(b)(i') = 0$.
DFinsupp.single_injective theorem
{i} : Function.Injective (single i : β i → Π₀ i, β i)
Full source
theorem single_injective {i} : Function.Injective (single i : β i → Π₀ i, β i) := fun _ _ H =>
  Pi.single_injective β i <| DFunLike.coe_injective.eq_iff.mpr H
Injectivity of the Dependent Kronecker Delta Function at a Fixed Index
Informal description
For any index $i$, the function `single i : β i → Π₀ i, β i` is injective. That is, for any $b_1, b_2 \in β i$, if `single i b₁ = single i b₂`, then $b₁ = b₂$.
DFinsupp.single_eq_single_iff theorem
(i j : ι) (xi : β i) (xj : β j) : DFinsupp.single i xi = DFinsupp.single j xj ↔ i = j ∧ HEq xi xj ∨ xi = 0 ∧ xj = 0
Full source
/-- Like `Finsupp.single_eq_single_iff`, but with a `HEq` due to dependent types -/
theorem single_eq_single_iff (i j : ι) (xi : β i) (xj : β j) :
    DFinsupp.singleDFinsupp.single i xi = DFinsupp.single j xj ↔ i = j ∧ HEq xi xj ∨ xi = 0 ∧ xj = 0 := by
  constructor
  · intro h
    by_cases hij : i = j
    · subst hij
      exact Or.inl ⟨rfl, heq_of_eq (DFinsupp.single_injective h)⟩
    · have h_coe : ⇑(DFinsupp.single i xi) = DFinsupp.single j xj := congr_arg (⇑) h
      have hci := congr_fun h_coe i
      have hcj := congr_fun h_coe j
      rw [DFinsupp.single_eq_same] at hci hcj
      rw [DFinsupp.single_eq_of_ne (Ne.symm hij)] at hci
      rw [DFinsupp.single_eq_of_ne hij] at hcj
      exact Or.inr ⟨hci, hcj.symm⟩
  · rintro (⟨rfl, hxi⟩ | ⟨hi, hj⟩)
    · rw [eq_of_heq hxi]
    · rw [hi, hj, DFinsupp.single_zero, DFinsupp.single_zero]
Equality condition for dependent Kronecker delta functions: $\text{single}_i(x_i) = \text{single}_j(x_j) \leftrightarrow (i = j \land x_i \equiv x_j) \lor (x_i = 0 \land x_j = 0)$
Informal description
For any indices $i, j$ and elements $x_i \in \beta i$, $x_j \in \beta j$, the dependent Kronecker delta functions $\text{single}_i(x_i)$ and $\text{single}_j(x_j)$ are equal if and only if either: 1. $i = j$ and $x_i$ is hereditarily equal to $x_j$ (i.e., they are the same element in $\beta i$), or 2. Both $x_i$ and $x_j$ are zero elements in their respective types $\beta i$ and $\beta j$.
DFinsupp.single_left_injective theorem
{b : ∀ i : ι, β i} (h : ∀ i, b i ≠ 0) : Function.Injective (fun i => single i (b i) : ι → Π₀ i, β i)
Full source
/-- `DFinsupp.single a b` is injective in `a`. For the statement that it is injective in `b`, see
`DFinsupp.single_injective` -/
theorem single_left_injective {b : ∀ i : ι, β i} (h : ∀ i, b i ≠ 0) :
    Function.Injective (fun i => single i (b i) : ι → Π₀ i, β i) := fun _ _ H =>
  (((single_eq_single_iff _ _ _ _).mp H).resolve_right fun hb => h _ hb.1).left
Injectivity of Index Mapping for Nonzero Dependent Kronecker Delta Functions
Informal description
Let $\beta$ be a family of types indexed by $\iota$, each with a zero element. Given a dependent function $b : \prod_{i \in \iota} \beta i$ such that $b i \neq 0$ for all $i \in \iota$, the map $i \mapsto \text{single}_i (b i)$ is injective. Here, $\text{single}_i (b i)$ denotes the dependent function with finite support that is $b i$ at index $i$ and zero elsewhere.
DFinsupp.single_eq_zero theorem
{i : ι} {xi : β i} : single i xi = 0 ↔ xi = 0
Full source
@[simp]
theorem single_eq_zero {i : ι} {xi : β i} : singlesingle i xi = 0 ↔ xi = 0 := by
  rw [← single_zero i, single_eq_single_iff]
  simp
Zero Condition for Dependent Kronecker Delta: $\text{single}_i(x_i) = 0 \leftrightarrow x_i = 0$
Informal description
For any index $i$ and element $x_i \in \beta_i$, the dependent Kronecker delta function $\text{single}_i(x_i)$ equals the zero function if and only if $x_i = 0$.
DFinsupp.single_ne_zero theorem
{i : ι} {xi : β i} : single i xi ≠ 0 ↔ xi ≠ 0
Full source
theorem single_ne_zero {i : ι} {xi : β i} : singlesingle i xi ≠ 0single i xi ≠ 0 ↔ xi ≠ 0 :=
  single_eq_zero.not
Nonzero Condition for Dependent Kronecker Delta: $\text{single}_i(x_i) \neq 0 \leftrightarrow x_i \neq 0$
Informal description
For any index $i$ and element $x_i \in \beta_i$, the dependent Kronecker delta function $\text{single}_i(x_i)$ is not equal to the zero function if and only if $x_i \neq 0$.
DFinsupp.filter_single theorem
(p : ι → Prop) [DecidablePred p] (i : ι) (x : β i) : (single i x).filter p = if p i then single i x else 0
Full source
theorem filter_single (p : ι → Prop) [DecidablePred p] (i : ι) (x : β i) :
    (single i x).filter p = if p i then single i x else 0 := by
  ext j
  have := apply_ite (fun x : Π₀ i, β i => x j) (p i) (single i x) 0
  dsimp at this
  rw [filter_apply, this]
  obtain rfl | hij := Decidable.eq_or_ne i j
  · rfl
  · rw [single_eq_of_ne hij, ite_self, ite_self]
Filtered Kronecker Delta Function: $\text{filter } p (\text{single}_i(x)) = \text{if } p(i) \text{ then } \text{single}_i(x) \text{ else } 0$
Informal description
For a predicate $p$ on the index set $\iota$, an index $i \in \iota$, and an element $x \in \beta_i$, the filtered version of the dependent Kronecker delta function $\text{single}_i(x)$ satisfies: \[ \text{filter } p (\text{single}_i(x)) = \begin{cases} \text{single}_i(x) & \text{if } p(i) \text{ holds}, \\ 0 & \text{otherwise.} \end{cases} \]
DFinsupp.filter_single_pos theorem
{p : ι → Prop} [DecidablePred p] (i : ι) (x : β i) (h : p i) : (single i x).filter p = single i x
Full source
@[simp]
theorem filter_single_pos {p : ι → Prop} [DecidablePred p] (i : ι) (x : β i) (h : p i) :
    (single i x).filter p = single i x := by rw [filter_single, if_pos h]
Filtered Kronecker Delta Function Preserved Under Predicate
Informal description
For any predicate $p$ on the index set $\iota$, an index $i \in \iota$, and an element $x \in \beta_i$, if $p(i)$ holds, then the filtered version of the dependent Kronecker delta function $\text{single}_i(x)$ equals $\text{single}_i(x)$ itself. More formally, under the assumption $p(i)$, we have: \[ \text{filter } p (\text{single}_i(x)) = \text{single}_i(x). \]
DFinsupp.filter_single_neg theorem
{p : ι → Prop} [DecidablePred p] (i : ι) (x : β i) (h : ¬p i) : (single i x).filter p = 0
Full source
@[simp]
theorem filter_single_neg {p : ι → Prop} [DecidablePred p] (i : ι) (x : β i) (h : ¬p i) :
    (single i x).filter p = 0 := by rw [filter_single, if_neg h]
Filtered Kronecker Delta Vanishes When Predicate Fails: $\text{filter } p (\text{single}_i(x)) = 0$ when $\neg p(i)$
Informal description
For a predicate $p$ on the index set $\iota$, an index $i \in \iota$, and an element $x \in \beta_i$, if $p(i)$ does not hold, then the filtered version of the dependent Kronecker delta function $\text{single}_i(x)$ is identically zero, i.e., \[ \text{filter } p (\text{single}_i(x)) = 0. \]
DFinsupp.single_eq_of_sigma_eq theorem
{i j} {xi : β i} {xj : β j} (h : (⟨i, xi⟩ : Sigma β) = ⟨j, xj⟩) : DFinsupp.single i xi = DFinsupp.single j xj
Full source
/-- Equality of sigma types is sufficient (but not necessary) to show equality of `DFinsupp`s. -/
theorem single_eq_of_sigma_eq {i j} {xi : β i} {xj : β j} (h : (⟨i, xi⟩ : Sigma β) = ⟨j, xj⟩) :
    DFinsupp.single i xi = DFinsupp.single j xj := by
  cases h
  rfl
Equality of Sigma Types Implies Equality of Dependent Kronecker Delta Functions
Informal description
For any indices $i, j$ and elements $x_i \in \beta i$, $x_j \in \beta j$, if the sigma types $\langle i, x_i \rangle$ and $\langle j, x_j \rangle$ are equal, then the corresponding dependent Kronecker delta functions are equal, i.e., $\text{single}_i x_i = \text{single}_j x_j$.
DFinsupp.equivFunOnFintype_single theorem
[Fintype ι] (i : ι) (m : β i) : (@DFinsupp.equivFunOnFintype ι β _ _) (DFinsupp.single i m) = Pi.single i m
Full source
@[simp]
theorem equivFunOnFintype_single [Fintype ι] (i : ι) (m : β i) :
    (@DFinsupp.equivFunOnFintype ι β _ _) (DFinsupp.single i m) = Pi.single i m := by
  ext x
  dsimp [Pi.single, Function.update]
  simp [DFinsupp.single_eq_pi_single, @eq_comm _ i]
Equivalence Maps Dependent Kronecker Delta to Standard Kronecker Delta on Finite Types
Informal description
For a finite type $\iota$ and any index $i \in \iota$ with $m \in \beta i$, the equivalence $\text{equivFunOnFintype}$ maps the dependent Kronecker delta function $\text{single}_i m$ to the standard Kronecker delta function $\text{Pi.single}_i m$ in the function space $\forall i, \beta i$. More formally: \[ \text{equivFunOnFintype}(\text{single}_i m) = \text{Pi.single}_i m \]
DFinsupp.equivFunOnFintype_symm_single theorem
[Fintype ι] (i : ι) (m : β i) : (@DFinsupp.equivFunOnFintype ι β _ _).symm (Pi.single i m) = DFinsupp.single i m
Full source
@[simp]
theorem equivFunOnFintype_symm_single [Fintype ι] (i : ι) (m : β i) :
    (@DFinsupp.equivFunOnFintype ι β _ _).symm (Pi.single i m) = DFinsupp.single i m := by
  ext i'
  simp only [← single_eq_pi_single, equivFunOnFintype_symm_coe]
Inverse Equivalence Maps Single-Element Function to Kronecker Delta on Finite Types
Informal description
For any finite type $\iota$, index $i \in \iota$, and element $m \in \beta i$, the inverse of the equivalence `equivFunOnFintype` maps the single-element function $\text{Pi.single}_i m$ to the dependent Kronecker delta function $\text{DFinsupp.single}_i m$. More precisely, $\text{equivFunOnFintype}^{-1}(\text{Pi.single}_i m) = \text{single}_i m$.
DFinsupp.zipWith_single_single theorem
(f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) {i} (b₁ : β₁ i) (b₂ : β₂ i) : zipWith f hf (single i b₁) (single i b₂) = single i (f i b₁ b₂)
Full source
@[simp]
theorem zipWith_single_single (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0)
    {i} (b₁ : β₁ i) (b₂ : β₂ i) :
    zipWith f hf (single i b₁) (single i b₂) = single i (f i b₁ b₂) := by
  ext j
  rw [zipWith_apply]
  obtain rfl | hij := Decidable.eq_or_ne i j
  · rw [single_eq_same, single_eq_same, single_eq_same]
  · rw [single_eq_of_ne hij, single_eq_of_ne hij, single_eq_of_ne hij, hf]
Pointwise Combination of Kronecker Deltas: $\text{zipWith}\,f\,hf\,(\text{single}_i b_1)\,(\text{single}_i b_2) = \text{single}_i (f_i b_1 b_2)$
Informal description
For a family of binary operations \( f_i \colon \beta_1 i \to \beta_2 i \to \beta i \) such that \( f_i(0, 0) = 0 \) for each index \( i \), and for any elements \( b_1 \in \beta_1 i \) and \( b_2 \in \beta_2 i \), the pointwise combination of the dependent Kronecker delta functions \(\text{single}_i(b_1)\) and \(\text{single}_i(b_2)\) satisfies \[ \text{zipWith}\,f\,hf\,(\text{single}_i b_1)\,(\text{single}_i b_2) = \text{single}_i (f_i b_1 b_2). \]
DFinsupp.erase definition
(i : ι) (x : Π₀ i, β i) : Π₀ i, β i
Full source
/-- Redefine `f i` to be `0`. -/
def erase (i : ι) (x : Π₀ i, β i) : Π₀ i, β i :=
  ⟨fun j ↦ if j = i then 0 else x.1 j,
    x.support'.map fun xs ↦ ⟨xs.1, fun j ↦ (xs.prop j).imp_right (by simp only [·, ite_self])⟩⟩
Erase value at index in dependent function with finite support
Informal description
The function `DFinsupp.erase i x` modifies the dependent function `x` with finite support by setting its value at index `i$ to zero, while leaving all other values unchanged. Formally, for any index `j`, the value of `erase i x` at `j` is equal to zero if `j = i$, and equal to `x j` otherwise.
DFinsupp.erase_apply theorem
{i j : ι} {f : Π₀ i, β i} : (f.erase i) j = if j = i then 0 else f j
Full source
@[simp]
theorem erase_apply {i j : ι} {f : Π₀ i, β i} : (f.erase i) j = if j = i then 0 else f j :=
  rfl
Value of Erased Dependent Function at Index $j$: $(f \setminus i)(j) = \begin{cases} 0 & \text{if } j = i \\ f(j) & \text{otherwise} \end{cases}$
Informal description
For any indices $i$ and $j$ and any dependent function $f$ with finite support, the value of $f$ after erasing at index $i$ evaluated at $j$ is equal to $0$ if $j = i$, and equal to $f(j)$ otherwise. That is, $(f \setminus i)(j) = \begin{cases} 0 & \text{if } j = i \\ f(j) & \text{otherwise} \end{cases}$.
DFinsupp.erase_same theorem
{i : ι} {f : Π₀ i, β i} : (f.erase i) i = 0
Full source
theorem erase_same {i : ι} {f : Π₀ i, β i} : (f.erase i) i = 0 := by simp
Erased Index Yields Zero in Dependent Function
Informal description
For any index $i$ and any dependent function $f$ with finite support, the value of $f$ after erasing at index $i$ evaluated at $i$ equals zero, i.e., $(f \setminus i)(i) = 0$.
DFinsupp.erase_ne theorem
{i i' : ι} {f : Π₀ i, β i} (h : i' ≠ i) : (f.erase i) i' = f i'
Full source
theorem erase_ne {i i' : ι} {f : Π₀ i, β i} (h : i' ≠ i) : (f.erase i) i' = f i' := by simp [h]
Preservation of Function Values Outside Erased Index
Informal description
For any indices $i$ and $i'$ with $i' \neq i$, and for any dependent function $f$ with finite support, the value of $f$ after erasing at index $i$ evaluated at $i'$ equals the original value $f(i')$. That is, $(f \setminus i)(i') = f(i')$.
DFinsupp.piecewise_single_erase theorem
(x : Π₀ i, β i) (i : ι) : (single i (x i)).piecewise (x.erase i) { i } = x
Full source
theorem piecewise_single_erase (x : Π₀ i, β i) (i : ι) :
    (single i (x i)).piecewise (x.erase i) {i} = x := by
  ext j; rw [piecewise_apply]; split_ifs with h
  · rw [(id h : j = i), single_eq_same]
  · exact erase_ne h
Reconstruction of Dependent Function from Kronecker Delta and Erased Function: $\text{single}_i(x(i)) \sqcup_{i} (x \setminus i) = x$
Informal description
For any dependent function $x \in \Pi_{i} \beta i$ with finite support and any index $i$, the piecewise combination of the Kronecker delta function $\text{single}_i(x(i))$ and the erased function $x \setminus i$ over the singleton set $\{i\}$ equals $x$. That is, \[ \text{single}_i(x(i)).\text{piecewise}\,(x \setminus i)\,\{i\} = x. \]
DFinsupp.erase_eq_sub_single theorem
{β : ι → Type*} [∀ i, AddGroup (β i)] (f : Π₀ i, β i) (i : ι) : f.erase i = f - single i (f i)
Full source
theorem erase_eq_sub_single {β : ι → Type*} [∀ i, AddGroup (β i)] (f : Π₀ i, β i) (i : ι) :
    f.erase i = f - single i (f i) := by
  ext j
  rcases eq_or_ne i j with (rfl | h)
  · simp
  · simp [erase_ne h.symm, single_eq_of_ne h, @eq_comm _ j, h]
Erasure as Subtraction of Kronecker Delta: $f \setminus i = f - \text{single}_i(f(i))$
Informal description
For any family of additive groups $\beta_i$ indexed by $i$ and any dependent function $f \in \Pi₀ i, \beta_i$ with finite support, the operation of erasing the value of $f$ at index $i$ is equal to subtracting the Kronecker delta function $\text{single}_i(f(i))$ from $f$. That is, \[ f \setminus i = f - \text{single}_i(f(i)). \]
DFinsupp.erase_zero theorem
(i : ι) : erase i (0 : Π₀ i, β i) = 0
Full source
@[simp]
theorem erase_zero (i : ι) : erase i (0 : Π₀ i, β i) = 0 :=
  ext fun _ => ite_self _
Erasing Zero Function Yields Zero: $\text{erase}_i(0) = 0$
Informal description
For any index $i$, the operation of erasing the value at $i$ from the zero function in the space of dependent functions with finite support $\Pi₀ i, \beta i$ results again in the zero function, i.e., $\text{erase}_i(0) = 0$.
DFinsupp.filter_ne_eq_erase theorem
(f : Π₀ i, β i) (i : ι) : f.filter (· ≠ i) = f.erase i
Full source
@[simp]
theorem filter_ne_eq_erase (f : Π₀ i, β i) (i : ι) : f.filter (· ≠ i) = f.erase i := by
  ext1 j
  simp only [DFinsupp.filter_apply, DFinsupp.erase_apply, ite_not]
Filtering by Inequality Equals Erasure in Dependent Functions with Finite Support
Informal description
For any dependent function $f \in \Pi₀ i, \beta i$ with finite support and any index $i$, the result of filtering $f$ to keep only the values at indices not equal to $i$ is equal to erasing the value of $f$ at index $i$. In other words, \[ f \text{ filtered by } (\cdot \neq i) = f \text{ with value at } i \text{ erased}. \]
DFinsupp.filter_ne_eq_erase' theorem
(f : Π₀ i, β i) (i : ι) : f.filter (i ≠ ·) = f.erase i
Full source
@[simp]
theorem filter_ne_eq_erase' (f : Π₀ i, β i) (i : ι) : f.filter (i ≠ ·) = f.erase i := by
  rw [← filter_ne_eq_erase f i]
  congr with j
  exact ne_comm
Filtering by Reverse Inequality Equals Erasure in Dependent Functions with Finite Support
Informal description
For any dependent function $f \in \Pi₀ i, \beta i$ with finite support and any index $i$, the result of filtering $f$ to keep only the values at indices not equal to $i$ is equal to erasing the value of $f$ at index $i$. In other words, \[ f \text{ filtered by } (i \neq \cdot) = f \text{ with value at } i \text{ erased}. \]
DFinsupp.erase_single theorem
(j : ι) (i : ι) (x : β i) : (single i x).erase j = if i = j then 0 else single i x
Full source
theorem erase_single (j : ι) (i : ι) (x : β i) :
    (single i x).erase j = if i = j then 0 else single i x := by
  rw [← filter_ne_eq_erase, filter_single, ite_not]
Erasure of Kronecker Delta Function: $\text{erase}_j(\text{single}_i(x)) = \text{if } i = j \text{ then } 0 \text{ else } \text{single}_i(x)$
Informal description
For any indices $i$ and $j$ and any element $x \in \beta_i$, the erasure of the dependent Kronecker delta function $\text{single}_i(x)$ at index $j$ satisfies: \[ \text{erase}_j(\text{single}_i(x)) = \begin{cases} 0 & \text{if } i = j, \\ \text{single}_i(x) & \text{otherwise.} \end{cases} \]
DFinsupp.erase_single_same theorem
(i : ι) (x : β i) : (single i x).erase i = 0
Full source
@[simp]
theorem erase_single_same (i : ι) (x : β i) : (single i x).erase i = 0 := by
  rw [erase_single, if_pos rfl]
Erasure of Kronecker Delta at Same Index Yields Zero
Informal description
For any index $i$ and any element $x \in \beta_i$, the erasure of the dependent Kronecker delta function $\text{single}_i(x)$ at its own index $i$ yields the zero function, i.e., \[ \text{erase}_i(\text{single}_i(x)) = 0. \]
DFinsupp.erase_single_ne theorem
{i j : ι} (x : β i) (h : i ≠ j) : (single i x).erase j = single i x
Full source
@[simp]
theorem erase_single_ne {i j : ι} (x : β i) (h : i ≠ j) : (single i x).erase j = single i x := by
  rw [erase_single, if_neg h]
Erasure of Kronecker Delta Function at Distinct Indices: $\text{erase}_j(\text{single}_i(x)) = \text{single}_i(x)$ for $i \neq j$
Informal description
For any indices $i$ and $j$ with $i \neq j$ and any element $x \in \beta_i$, the erasure of the dependent Kronecker delta function $\text{single}_i(x)$ at index $j$ equals $\text{single}_i(x)$. That is, \[ \text{erase}_j(\text{single}_i(x)) = \text{single}_i(x). \]
DFinsupp.update definition
: Π₀ i, β i
Full source
/-- Replace the value of a `Π₀ i, β i` at a given point `i : ι` by a given value `b : β i`.
If `b = 0`, this amounts to removing `i` from the support.
Otherwise, `i` is added to it.

This is the (dependent) finitely-supported version of `Function.update`. -/
def update : Π₀ i, β i :=
  ⟨Function.update f i b,
    f.support'.map fun s =>
      ⟨i ::ₘ s.1, fun j => by
        rcases eq_or_ne i j with (rfl | hi)
        · simp
        · obtain hj | (hj : f j = 0) := s.prop j
          · exact Or.inl (Multiset.mem_cons_of_mem hj)
          · exact Or.inr ((Function.update_of_ne hi.symm b _).trans hj)⟩⟩
Update operation for dependent functions with finite support
Informal description
The function `DFinsupp.update` modifies a dependent function with finite support `f : Π₀ i, β i` by updating its value at a given index `i : ι` to a new value `b : β i`. If `b = 0`, this effectively removes `i` from the support of `f`; otherwise, `i` is added to the support. This operation is the finitely-supported dependent version of the standard function update operation.
DFinsupp.coe_update theorem
: (f.update i b : ∀ i : ι, β i) = Function.update f i b
Full source
@[simp, norm_cast] lemma coe_update : (f.update i b : ∀ i : ι, β i) = Function.update f i b := rfl
Coercion of Update for Dependent Functions with Finite Support
Informal description
For a dependent function with finite support $f \in \Pi_{i} \beta i$, updating $f$ at index $i$ with value $b \in \beta i$ and then coercing to a standard dependent function is equal to directly updating the standard dependent function $f$ at $i$ with $b$. That is, $(f.\text{update} \, i \, b) = \text{update} \, f \, i \, b$ as functions.
DFinsupp.update_self theorem
: f.update i (f i) = f
Full source
@[simp]
theorem update_self : f.update i (f i) = f := by
  ext
  simp
Update with Current Value Preserves Dependent Function Identity
Informal description
For any dependent function with finite support $f \in \Pi_{i} \beta i$ and any index $i$, updating $f$ at $i$ with its current value $f(i)$ leaves the function unchanged, i.e., $f.\text{update}\, i\, (f i) = f$.
DFinsupp.update_eq_erase theorem
: f.update i 0 = f.erase i
Full source
@[simp]
theorem update_eq_erase : f.update i 0 = f.erase i := by
  ext j
  rcases eq_or_ne i j with (rfl | hi)
  · simp
  · simp [hi.symm]
Update to Zero Equals Erase in Dependent Functions with Finite Support
Informal description
For any dependent function with finite support $f \in \Pi₀ i, \beta i$ and any index $i$, updating $f$ at $i$ with the zero element is equal to erasing the value of $f$ at $i$. That is, $f.\text{update}(i, 0) = f.\text{erase}(i)$.
DFinsupp.update_eq_single_add_erase theorem
{β : ι → Type*} [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = single i b + f.erase i
Full source
theorem update_eq_single_add_erase {β : ι → Type*} [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i)
    (i : ι) (b : β i) : f.update i b = single i b + f.erase i := by
  ext j
  rcases eq_or_ne i j with (rfl | h)
  · simp
  · simp [Function.update_of_ne h.symm, h, erase_ne, h.symm]
Decomposition of Update into Single and Erase: $f.\text{update}\, i\, b = \text{single}_i(b) + f.\text{erase}(i)$
Informal description
Let $\beta : \iota \to \text{Type}^*$ be a family of types where each $\beta i$ has an additive zero class structure. For any dependent function with finite support $f \in \Pi₀ i, \beta i$, any index $i \in \iota$, and any element $b \in \beta i$, the update of $f$ at $i$ with value $b$ satisfies: \[ f.\text{update}\, i\, b = \text{single}_i(b) + f.\text{erase}(i). \] Here, $\text{single}_i(b)$ is the function that is $b$ at $i$ and zero elsewhere, and $f.\text{erase}(i)$ is $f$ with its value at $i$ set to zero.
DFinsupp.update_eq_erase_add_single theorem
{β : ι → Type*} [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = f.erase i + single i b
Full source
theorem update_eq_erase_add_single {β : ι → Type*} [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i)
    (i : ι) (b : β i) : f.update i b = f.erase i + single i b := by
  ext j
  rcases eq_or_ne i j with (rfl | h)
  · simp
  · simp [Function.update_of_ne h.symm, h, erase_ne, h.symm]
Update as Erase Plus Single for Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i$ where each $\beta_i$ has an additive zero class structure, and for any dependent function with finite support $f \in \Pi₀ i, \beta i$, index $i$, and element $b \in \beta i$, the update of $f$ at $i$ with $b$ is equal to the sum of the erased function (where $f$ is set to zero at $i$) and the single function that maps $i$ to $b$. That is: \[ f.\text{update}(i, b) = f.\text{erase}(i) + \text{single}_i(b). \]
DFinsupp.update_eq_sub_add_single theorem
{β : ι → Type*} [∀ i, AddGroup (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = f - single i (f i) + single i b
Full source
theorem update_eq_sub_add_single {β : ι → Type*} [∀ i, AddGroup (β i)] (f : Π₀ i, β i) (i : ι)
    (b : β i) : f.update i b = f - single i (f i) + single i b := by
  rw [update_eq_erase_add_single f i b, erase_eq_sub_single f i]
Update Decomposition for Dependent Functions: $f.\text{update}(i, b) = f - \delta_i(f(i)) + \delta_i(b)$
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, any dependent function with finite support $f \in \Pi₀ i, \beta i$, any index $i$, and any element $b \in \beta i$, the update of $f$ at $i$ with value $b$ satisfies: \[ f.\text{update}(i, b) = f - \text{single}_i(f(i)) + \text{single}_i(b). \] Here, $\text{single}_i(b)$ denotes the function that is $b$ at $i$ and zero elsewhere.
DFinsupp.single_add theorem
(i : ι) (b₁ b₂ : β i) : single i (b₁ + b₂) = single i b₁ + single i b₂
Full source
@[simp]
theorem single_add (i : ι) (b₁ b₂ : β i) : single i (b₁ + b₂) = single i b₁ + single i b₂ :=
  (zipWith_single_single (fun _ => (· + ·)) _ b₁ b₂).symm
Additivity of Dependent Kronecker Delta Function: $\text{single}_i (b_1 + b_2) = \text{single}_i b_1 + \text{single}_i b_2$
Informal description
For any index $i$ and any two elements $b_1, b_2$ in $\beta i$, the dependent Kronecker delta function at $i$ with value $b_1 + b_2$ is equal to the sum of the dependent Kronecker delta functions at $i$ with values $b_1$ and $b_2$ respectively. That is, \[ \text{single}_i (b_1 + b_2) = \text{single}_i b_1 + \text{single}_i b_2. \]
DFinsupp.erase_add theorem
(i : ι) (f₁ f₂ : Π₀ i, β i) : erase i (f₁ + f₂) = erase i f₁ + erase i f₂
Full source
@[simp]
theorem erase_add (i : ι) (f₁ f₂ : Π₀ i, β i) : erase i (f₁ + f₂) = erase i f₁ + erase i f₂ :=
  ext fun _ => by simp [ite_zero_add]
Erasing Commutes with Addition in Dependent Functions with Finite Support
Informal description
For any index $i$ and any two dependent functions $f_1, f_2 \in \Pi₀ i, \beta i$ with finite support, the operation of erasing the value at index $i$ commutes with addition, i.e., \[ \text{erase}_i (f_1 + f_2) = \text{erase}_i f_1 + \text{erase}_i f_2. \]
DFinsupp.singleAddHom definition
(i : ι) : β i →+ Π₀ i, β i
Full source
/-- `DFinsupp.single` as an `AddMonoidHom`. -/
@[simps]
def singleAddHom (i : ι) : β i →+ Π₀ i, β i where
  toFun := single i
  map_zero' := single_zero i
  map_add' := single_add i
Additive monoid homomorphism version of the dependent Kronecker delta function
Informal description
For a given index $i$, the function `DFinsupp.singleAddHom i` is an additive monoid homomorphism from $\beta i$ to the type of dependent functions with finite support $\Pi₀ i, \beta i$. It maps an element $b \in \beta i$ to the dependent Kronecker delta function `single i b`, which is zero everywhere except at index $i$ where it takes the value $b$. The homomorphism properties are: 1. It maps the zero element to the zero function: `single i 0 = 0`. 2. It preserves addition: `single i (b₁ + b₂) = single i b₁ + single i b₂` for all $b₁, b₂ \in \beta i$.
DFinsupp.eraseAddHom definition
(i : ι) : (Π₀ i, β i) →+ Π₀ i, β i
Full source
/-- `DFinsupp.erase` as an `AddMonoidHom`. -/
@[simps]
def eraseAddHom (i : ι) : (Π₀ i, β i) →+ Π₀ i, β i where
  toFun := erase i
  map_zero' := erase_zero i
  map_add' := erase_add i
Erase as an additive monoid homomorphism for dependent functions with finite support
Informal description
The additive monoid homomorphism version of the `DFinsupp.erase` function, which maps a dependent function with finite support to another such function by setting the value at a given index $i$ to zero. Specifically, for any index $i$, the homomorphism `DFinsupp.eraseAddHom i` sends a function $f \in \Pi₀ i, \beta i$ to $\text{erase}_i f$, where $\text{erase}_i f$ is the function that coincides with $f$ everywhere except at $i$, where it takes the value zero.
DFinsupp.single_neg theorem
{β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (x : β i) : single i (-x) = -single i x
Full source
@[simp]
theorem single_neg {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (x : β i) :
    single i (-x) = -single i x :=
  (singleAddHom β i).map_neg x
Negation Commutes with Single in Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and for any index $i$ and element $x \in \beta_i$, the dependent Kronecker delta function satisfies $single_i(-x) = -single_i(x)$.
DFinsupp.single_sub theorem
{β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (x y : β i) : single i (x - y) = single i x - single i y
Full source
@[simp]
theorem single_sub {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (x y : β i) :
    single i (x - y) = single i x - single i y :=
  (singleAddHom β i).map_sub x y
Subtraction Preserved by Dependent Kronecker Delta Function
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and for any index $i$ and elements $x, y \in \beta_i$, the dependent Kronecker delta function satisfies: \[ \text{single}_i (x - y) = \text{single}_i x - \text{single}_i y. \]
DFinsupp.erase_neg theorem
{β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (f : Π₀ i, β i) : (-f).erase i = -f.erase i
Full source
@[simp]
theorem erase_neg {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (f : Π₀ i, β i) :
    (-f).erase i = -f.erase i :=
  (eraseAddHom β i).map_neg f
Negation Commutes with Erasure in Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, and for any index $i$ and dependent function $f$ with finite support (i.e., $f \in \Pi_{i} \beta_i$), the operation of erasing the value at index $i$ commutes with negation. That is, the erasure of the negation of $f$ at $i$ equals the negation of the erasure of $f$ at $i$: \[ (-f).\text{erase}(i) = - (f.\text{erase}(i)). \]
DFinsupp.erase_sub theorem
{β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (f g : Π₀ i, β i) : (f - g).erase i = f.erase i - g.erase i
Full source
@[simp]
theorem erase_sub {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (f g : Π₀ i, β i) :
    (f - g).erase i = f.erase i - g.erase i :=
  (eraseAddHom β i).map_sub f g
Erasure Preserves Subtraction in Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i$, any index $i$, and any dependent functions $f, g \in \Pi₀ i, \beta i$ with finite support, the erasure of the difference $f - g$ at index $i$ is equal to the difference of the erasures of $f$ and $g$ at $i$. More formally: \[ (f - g).\text{erase}(i) = f.\text{erase}(i) - g.\text{erase}(i). \]
DFinsupp.single_add_erase theorem
(i : ι) (f : Π₀ i, β i) : single i (f i) + f.erase i = f
Full source
theorem single_add_erase (i : ι) (f : Π₀ i, β i) : single i (f i) + f.erase i = f :=
  ext fun i' =>
    if h : i = i' then by
      subst h; simp only [add_apply, single_apply, erase_apply, add_zero, dite_eq_ite, if_true]
    else by
      simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (Ne.symm h), zero_add]
Decomposition of a Dependent Function via Kronecker Delta and Erasure
Informal description
For any index $i$ and any dependent function $f$ with finite support (i.e., $f \in \Pi₀ i, \beta i$), the sum of the Kronecker delta function $\text{single}_i(f(i))$ and the function obtained by erasing the value of $f$ at $i$ (i.e., setting $f(i) = 0$) equals $f$ itself. More formally: \[ \text{single}_i(f(i)) + f.\text{erase}(i) = f. \]
DFinsupp.erase_add_single theorem
(i : ι) (f : Π₀ i, β i) : f.erase i + single i (f i) = f
Full source
theorem erase_add_single (i : ι) (f : Π₀ i, β i) : f.erase i + single i (f i) = f :=
  ext fun i' =>
    if h : i = i' then by
      subst h; simp only [add_apply, single_apply, erase_apply, zero_add, dite_eq_ite, if_true]
    else by
      simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (Ne.symm h), add_zero]
Reconstruction of Dependent Function via Erasure and Kronecker Delta
Informal description
For any dependent function $f \in \Pi₀ i, \beta i$ with finite support and any index $i$, the sum of the function obtained by erasing the value of $f$ at $i$ (i.e., setting $f(i) = 0$) and the Kronecker delta function $\text{single}_i(f(i))$ equals $f$ itself. More formally: \[ f.\text{erase}(i) + \text{single}_i(f(i)) = f. \]
DFinsupp.induction theorem
{p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i) (h0 : p 0) (ha : ∀ (i b) (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (single i b + f)) : p f
Full source
protected theorem induction {p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i) (h0 : p 0)
    (ha : ∀ (i b) (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (single i b + f)) : p f := by
  obtain ⟨f, s⟩ := f
  induction' s using Trunc.induction_on with s
  obtain ⟨s, H⟩ := s
  induction' s using Multiset.induction_on with i s ih generalizing f
  · have : f = 0 := funext fun i => (H i).resolve_left (Multiset.not_mem_zero _)
    subst this
    exact h0
  have H2 : p (erase i ⟨f, Trunc.mk ⟨i ::ₘ s, H⟩⟩) := by
    dsimp only [erase, Trunc.map, Trunc.bind, Trunc.liftOn, Trunc.lift_mk,
      Function.comp, Subtype.coe_mk]
    have H2 : ∀ j, j ∈ sj ∈ s ∨ ite (j = i) 0 (f j) = 0 := by
      intro j
      rcases H j with H2 | H2
      · rcases Multiset.mem_cons.1 H2 with H3 | H3
        · right; exact if_pos H3
        · left; exact H3
      right
      split_ifs <;> [rfl; exact H2]
    have H3 : ∀ aux, (⟨fun j : ι => ite (j = i) 0 (f j), Trunc.mk ⟨i ::ₘ s, aux⟩⟩ : Π₀ i, β i) =
        ⟨fun j : ι => ite (j = i) 0 (f j), Trunc.mk ⟨s, H2⟩⟩ :=
      fun _ ↦ ext fun _ => rfl
    rw [H3]
    apply ih
  have H3 : single i _ + _ = (⟨f, Trunc.mk ⟨i ::ₘ s, H⟩⟩ : Π₀ i, β i) := single_add_erase _ _
  rw [← H3]
  change p (single i (f i) + _)
  rcases Classical.em (f i = 0) with h | h
  · rw [h, single_zero, zero_add]
    exact H2
  refine ha _ _ _ ?_ h H2
  rw [erase_same]
Induction Principle for Dependent Functions with Finite Support
Informal description
Let $p$ be a predicate on dependent functions with finite support $\Pi₀ i, \beta i$. For any such function $f$, if $p$ holds for the zero function, and for any index $i$, element $b \in \beta i$, and function $f$ with $f(i) = 0$ and $b \neq 0$, $p(f)$ implies $p(\text{single}_i(b) + f)$, then $p$ holds for $f$.
DFinsupp.induction₂ theorem
{p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i) (h0 : p 0) (ha : ∀ (i b) (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (f + single i b)) : p f
Full source
theorem induction₂ {p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i) (h0 : p 0)
    (ha : ∀ (i b) (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (f + single i b)) : p f :=
  DFinsupp.induction f h0 fun i b f h1 h2 h3 =>
    have h4 : f + single i b = single i b + f := by
      ext j; by_cases H : i = j
      · subst H
        simp [h1]
      · simp [H]
    Eq.recOn h4 <| ha i b f h1 h2 h3
Alternative Induction Principle for Dependent Functions with Finite Support
Informal description
Let $p$ be a predicate on dependent functions with finite support $\Pi₀ i, \beta i$. For any such function $f$, if $p$ holds for the zero function, and for any index $i$, element $b \in \beta i$, and function $f$ with $f(i) = 0$ and $b \neq 0$, $p(f)$ implies $p(f + \text{single}_i(b))$, then $p$ holds for $f$.
DFinsupp.mk_add theorem
[∀ i, AddZeroClass (β i)] {s : Finset ι} {x y : ∀ i : (↑s : Set ι), β i} : mk s (x + y) = mk s x + mk s y
Full source
@[simp]
theorem mk_add [∀ i, AddZeroClass (β i)] {s : Finset ι} {x y : ∀ i : (↑s : Set ι), β i} :
    mk s (x + y) = mk s x + mk s y :=
  ext fun i => by simp only [add_apply, mk_apply]; split_ifs <;> [rfl; rw [zero_add]]
Additivity of Construction for Dependent Functions with Finite Support
Informal description
Let $\beta$ be a family of types indexed by $\iota$, where each $\beta_i$ has an additive zero class structure. For any finite subset $s \subseteq \iota$ and any two functions $x, y \colon s \to \beta_i$ (where $x_i, y_i \in \beta_i$ for $i \in s$), the construction of a dependent function with finite support satisfies the additive property: \[ \text{mk}_s (x + y) = \text{mk}_s x + \text{mk}_s y, \] where $\text{mk}_s$ constructs a dependent function that is zero outside $s$ and matches the given function on $s$, and $+$ denotes pointwise addition.
DFinsupp.mk_zero theorem
[∀ i, Zero (β i)] {s : Finset ι} : mk s (0 : ∀ i : (↑s : Set ι), β i.1) = 0
Full source
@[simp]
theorem mk_zero [∀ i, Zero (β i)] {s : Finset ι} : mk s (0 : ∀ i : (↑s : Set ι), β i.1) = 0 :=
  ext fun i => by simp only [mk_apply]; split_ifs <;> rfl
Zero Construction in Dependent Functions with Finite Support
Informal description
For any finite set $s$ of indices and for each $i \in s$, if the function $x$ is identically zero on $s$ (i.e., $x_i = 0$ for all $i \in s$), then the dependent function with finite support constructed from $s$ and $x$ is the zero function in $\Pi_{i} \beta i$.
DFinsupp.mk_neg theorem
[∀ i, AddGroup (β i)] {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i.1} : mk s (-x) = -mk s x
Full source
@[simp]
theorem mk_neg [∀ i, AddGroup (β i)] {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i.1} :
    mk s (-x) = -mk s x :=
  ext fun i => by simp only [neg_apply, mk_apply]; split_ifs <;> [rfl; rw [neg_zero]]
Negation Commutes with Construction of Dependent Functions with Finite Support
Informal description
For any family of additive groups $\beta_i$ indexed by $i \in \iota$, given a finite set $s \subseteq \iota$ and a function $x$ defined on $s$ (where $x_i \in \beta_i$ for each $i \in s$), the construction of a dependent function with finite support satisfies $mk_s (-x) = -mk_s x$.
DFinsupp.mk_sub theorem
[∀ i, AddGroup (β i)] {s : Finset ι} {x y : ∀ i : (↑s : Set ι), β i.1} : mk s (x - y) = mk s x - mk s y
Full source
@[simp]
theorem mk_sub [∀ i, AddGroup (β i)] {s : Finset ι} {x y : ∀ i : (↑s : Set ι), β i.1} :
    mk s (x - y) = mk s x - mk s y :=
  ext fun i => by simp only [sub_apply, mk_apply]; split_ifs <;> [rfl; rw [sub_zero]]
Subtraction Commutes with Construction of Dependent Functions with Finite Support
Informal description
Let $\{\beta_i\}_{i \in \iota}$ be a family of additive groups indexed by $\iota$. For any finite subset $s \subseteq \iota$ and any two functions $x, y \colon s \to \beta_i$ (where $x_i, y_i \in \beta_i$ for $i \in s$), the construction of the dependent function with finite support satisfies: \[ \text{mk}_s (x - y) = \text{mk}_s x - \text{mk}_s y \] Here, $\text{mk}_s$ denotes the operation that constructs a dependent function with finite support from a function defined on $s$, extending it by zero outside $s$.
DFinsupp.mkAddGroupHom definition
[∀ i, AddGroup (β i)] (s : Finset ι) : (∀ i : (s : Set ι), β ↑i) →+ Π₀ i : ι, β i
Full source
/-- If `s` is a subset of `ι` then `mk_addGroupHom s` is the canonical additive
group homomorphism from $\prod_{i\in s}\beta_i$ to $\prod_{\mathtt{i : \iota}}\beta_i$. -/
def mkAddGroupHom [∀ i, AddGroup (β i)] (s : Finset ι) :
    (∀ i : (s : Set ι), β ↑i) →+ Π₀ i : ι, β i where
  toFun := mk s
  map_zero' := mk_zero
  map_add' _ _ := mk_add
Canonical additive group homomorphism from finite product to dependent functions with finite support
Informal description
For a family of additive groups $\{\beta_i\}_{i \in \iota}$ indexed by $\iota$, and given a finite subset $s \subseteq \iota$, the function `mkAddGroupHom s` is the canonical additive group homomorphism from the product $\prod_{i \in s} \beta_i$ to the space $\Pi_{i \in \iota} \beta_i$ of dependent functions with finite support. More precisely, it maps a function $x \colon s \to \beta_i$ (where $x_i \in \beta_i$ for each $i \in s$) to the dependent function with finite support that equals $x_i$ on $s$ and zero elsewhere. This construction preserves the additive group structure, meaning it respects addition and maps the zero function to the zero function.
DFinsupp.support definition
(f : Π₀ i, β i) : Finset ι
Full source
/-- Set `{i | f x ≠ 0}` as a `Finset`. -/
def support (f : Π₀ i, β i) : Finset ι :=
  (f.support'.lift fun xs => (Multiset.toFinset xs.1).filter fun i => f i ≠ 0) <| by
    rintro ⟨sx, hx⟩ ⟨sy, hy⟩
    dsimp only [Subtype.coe_mk, toFun_eq_coe] at *
    ext i; constructor
    · intro H
      rcases Finset.mem_filter.1 H with ⟨_, h⟩
      exact Finset.mem_filter.2 ⟨Multiset.mem_toFinset.2 <| (hy i).resolve_right h, h⟩
    · intro H
      rcases Finset.mem_filter.1 H with ⟨_, h⟩
      exact Finset.mem_filter.2 ⟨Multiset.mem_toFinset.2 <| (hx i).resolve_right h, h⟩
Support of a dependent function with finite support
Informal description
For a dependent function \( f \) with finite support (i.e., \( f \in \Pi_{i} \beta i \)), the support \( \text{supp}(f) \) is the finite set of indices \( i \) for which \( f(i) \neq 0 \). More formally, given \( f : \Pi_{i} \beta i \) where each \( \beta i \) has a zero element, the support is defined as the subset of indices \( i \) in the index set \( \iota \) such that \( f(i) \neq 0 \). This is represented as a finite set \( \text{supp}(f) \subseteq \iota \).
DFinsupp.support_mk_subset theorem
{s : Finset ι} {x : ∀ i : (↑s : Set ι), β i.1} : (mk s x).support ⊆ s
Full source
@[simp]
theorem support_mk_subset {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i.1} : (mk s x).support ⊆ s :=
  fun _ H => Multiset.mem_toFinset.1 (Finset.mem_filter.1 H).1
Support of Constructed Dependent Function is Subset of Input Finite Set
Informal description
For any finite set $s$ of indices and any function $x$ defined on $s$ (where for each $i \in s$, $x_i$ is an element of $\beta i$), the support of the dependent function with finite support constructed by `mk s x` is a subset of $s$.
DFinsupp.support_mk'_subset theorem
{f : ∀ i, β i} {s : Multiset ι} {h} : (mk' f <| Trunc.mk ⟨s, h⟩).support ⊆ s.toFinset
Full source
@[simp]
theorem support_mk'_subset {f : ∀ i, β i} {s : Multiset ι} {h} :
    (mk' f <| Trunc.mk ⟨s, h⟩).support ⊆ s.toFinset := fun i H =>
  Multiset.mem_toFinset.1 <| by simpa using (Finset.mem_filter.1 H).1
Support of Constructed Dependent Function is Subset of Multiset Conversion
Informal description
For any dependent function $f$ with finite support and any multiset $s$ of indices, the support of the function constructed via `mk'` from $f$ and a truncated pair $\langle s, h \rangle$ is a subset of the finite set obtained from $s$.
DFinsupp.mem_support_toFun theorem
(f : Π₀ i, β i) (i) : i ∈ f.support ↔ f i ≠ 0
Full source
@[simp]
theorem mem_support_toFun (f : Π₀ i, β i) (i) : i ∈ f.supporti ∈ f.support ↔ f i ≠ 0 := by
  obtain ⟨f, s⟩ := f
  induction' s using Trunc.induction_on with s
  dsimp only [support, Trunc.lift_mk]
  rw [Finset.mem_filter, Multiset.mem_toFinset, coe_mk']
  exact and_iff_right_of_imp (s.prop i).resolve_right
Characterization of Support for Dependent Functions with Finite Support
Informal description
For any dependent function $f$ with finite support (i.e., $f \in \Pi_{i} \beta i$) and any index $i$, the index $i$ belongs to the support of $f$ if and only if $f(i) \neq 0$.
DFinsupp.subtypeSupportEqEquiv definition
(s : Finset ι) : { f : Π₀ i, β i // f.support = s } ≃ ∀ i : s, { x : β i // x ≠ 0 }
Full source
/-- Equivalence between dependent functions with finite support `s : Finset ι` and functions
`∀ i, {x : β i // x ≠ 0}`. -/
@[simps]
def subtypeSupportEqEquiv (s : Finset ι) :
    {f : Π₀ i, β i // f.support = s}{f : Π₀ i, β i // f.support = s} ≃ ∀ i : s, {x : β i // x ≠ 0} where
  toFun | ⟨f, hf⟩ => fun ⟨i, hi⟩ ↦ ⟨f i, (f.mem_support_toFun i).1 <| hf.symm ▸ hi⟩
  invFun f := ⟨mk s fun i ↦ (f i).1, Finset.ext fun i ↦ by
    -- TODO: `simp` fails to use `(f _).2` inside `∃ _, _`
    calc
      i ∈ support (mk s fun i ↦ (f i).1) ↔ ∃ h : i ∈ s, (f ⟨i, h⟩).1 ≠ 0 := by simp
      _ ↔ ∃ _ : i ∈ s, True := exists_congr fun h ↦ (iff_true _).mpr (f _).2
      _ ↔ i ∈ s := by simp⟩
  left_inv := by
    rintro ⟨f, rfl⟩
    ext i
    simpa using Eq.symm
  right_inv f := by
    ext1
    simp [Subtype.eta]; rfl
Equivalence between dependent functions with fixed support and non-zero functions on the support
Informal description
For a given finite set of indices \( s \), there is an equivalence between the type of dependent functions with finite support \( f \) (where \( f \) has support exactly equal to \( s \)) and the type of functions that assign to each index \( i \in s \) a non-zero element of \( \beta i \). More precisely, the equivalence maps a function \( f \) with support \( s \) to the function that sends each \( i \in s \) to the pair \( \langle f(i), \text{proof that } f(i) \neq 0 \rangle \). Conversely, given a function \( g \) that assigns non-zero elements to each \( i \in s \), the equivalence constructs a dependent function with finite support that is zero outside \( s \) and agrees with \( g \) on \( s \).
DFinsupp.sigmaFinsetFunEquiv definition
: (Π₀ i, β i) ≃ Σ s : Finset ι, ∀ i : s, { x : β i // x ≠ 0 }
Full source
/-- Equivalence between all dependent finitely supported functions `f : Π₀ i, β i` and type
of pairs `⟨s : Finset ι, f : ∀ i : s, {x : β i // x ≠ 0}⟩`. -/
@[simps! apply_fst apply_snd_coe]
def sigmaFinsetFunEquiv : (Π₀ i, β i) ≃ Σ s : Finset ι, ∀ i : s, {x : β i // x ≠ 0} :=
  (Equiv.sigmaFiberEquiv DFinsupp.support).symm.trans (.sigmaCongrRight subtypeSupportEqEquiv)
Equivalence between dependent functions with finite support and pairs of finite support sets with non-zero functions
Informal description
There is an equivalence between the type of dependent functions with finite support \( \Pi_{i} \beta i \) and the type of pairs \( \langle s, f \rangle \), where \( s \) is a finite set of indices and \( f \) is a function assigning to each \( i \in s \) a non-zero element of \( \beta i \). More precisely, the equivalence maps a dependent function \( g \) with finite support to the pair \( \langle \text{supp}(g), \lambda i \in \text{supp}(g), \langle g(i), \text{proof that } g(i) \neq 0 \rangle \rangle \). Conversely, given a pair \( \langle s, f \rangle \), the equivalence constructs a dependent function that is zero outside \( s \) and agrees with \( f \) on \( s \).
DFinsupp.support_zero theorem
: (0 : Π₀ i, β i).support = ∅
Full source
@[simp]
theorem support_zero : (0 : Π₀ i, β i).support =  :=
  rfl
Support of Zero Function is Empty
Informal description
For the zero element $0$ in the type of dependent functions with finite support $\Pi₀ i, \beta i$, the support of $0$ is the empty set, i.e., $\text{supp}(0) = \emptyset$.
DFinsupp.mem_support_iff theorem
{f : Π₀ i, β i} {i : ι} : i ∈ f.support ↔ f i ≠ 0
Full source
theorem mem_support_iff {f : Π₀ i, β i} {i : ι} : i ∈ f.supporti ∈ f.support ↔ f i ≠ 0 :=
  f.mem_support_toFun _
Characterization of Support for Dependent Functions with Finite Support
Informal description
For a dependent function $f$ with finite support (i.e., $f \in \Pi_{i} \beta i$) and any index $i$, the index $i$ belongs to the support of $f$ if and only if $f(i) \neq 0$.
DFinsupp.not_mem_support_iff theorem
{f : Π₀ i, β i} {i : ι} : i ∉ f.support ↔ f i = 0
Full source
theorem not_mem_support_iff {f : Π₀ i, β i} {i : ι} : i ∉ f.supporti ∉ f.support ↔ f i = 0 :=
  not_iff_comm.1 mem_support_iff.symm
Characterization of Non-Support for Dependent Functions with Finite Support
Informal description
For a dependent function $f \in \Pi_{i} \beta i$ with finite support and any index $i$, the index $i$ does not belong to the support of $f$ if and only if $f(i) = 0$.
DFinsupp.support_eq_empty theorem
{f : Π₀ i, β i} : f.support = ∅ ↔ f = 0
Full source
@[simp]
theorem support_eq_empty {f : Π₀ i, β i} : f.support = ∅ ↔ f = 0 :=
  ⟨fun H => ext <| by simpa [Finset.ext_iff] using H, by simp +contextual⟩
Empty Support Characterization for Dependent Functions with Finite Support
Informal description
For a dependent function $f \in \Pi_{i} \beta i$ with finite support, the support of $f$ is empty if and only if $f$ is identically zero. That is, $\text{supp}(f) = \emptyset \leftrightarrow f = 0$.
DFinsupp.decidableZero instance
[∀ (i) (x : β i), Decidable (x = 0)] (f : Π₀ i, β i) : Decidable (f = 0)
Full source
instance decidableZero [∀ (i) (x : β i), Decidable (x = 0)] (f : Π₀ i, β i) : Decidable (f = 0) :=
  f.support'.recOnSubsingleton <| fun s =>
    decidable_of_iff (∀ i ∈ s.val, f i = 0) <| by
      constructor
      case mpr => rintro rfl _ _; rfl
      case mp =>
        intro hs₁; ext i
        -- This instance prevent consuming `DecidableEq ι` in the next `by_cases`.
        letI := Classical.propDecidable
        by_cases hs₂ : i ∈ s.val
        case pos => exact hs₁ _ hs₂
        case neg => exact (s.prop i).resolve_left hs₂
Decidability of Zero for Dependent Functions with Finite Support
Informal description
For any dependent function $f$ with finite support in $\Pi_0 i, \beta i$ where each $\beta i$ has a decidable zero element, it is decidable whether $f$ is identically zero.
DFinsupp.support_subset_iff theorem
{s : Set ι} {f : Π₀ i, β i} : ↑f.support ⊆ s ↔ ∀ i ∉ s, f i = 0
Full source
theorem support_subset_iff {s : Set ι} {f : Π₀ i, β i} : ↑f.support ⊆ s↑f.support ⊆ s ↔ ∀ i ∉ s, f i = 0 := by
  simpa [Set.subset_def] using forall_congr' fun i => not_imp_comm
Support Subset Characterization for Dependent Functions with Finite Support
Informal description
For a dependent function $f$ with finite support (i.e., $f \in \Pi_{i} \beta i$) and a set $s \subseteq \iota$, the support of $f$ is contained in $s$ if and only if for every index $i$ not in $s$, the value $f(i)$ is zero. In other words, $\text{supp}(f) \subseteq s \leftrightarrow (\forall i \notin s, f(i) = 0)$.
DFinsupp.support_single_ne_zero theorem
{i : ι} {b : β i} (hb : b ≠ 0) : (single i b).support = { i }
Full source
theorem support_single_ne_zero {i : ι} {b : β i} (hb : b ≠ 0) : (single i b).support = {i} := by
  ext j; by_cases h : i = j
  · subst h
    simp [hb]
  simp [Ne.symm h, h]
Support of Nonzero Dependent Kronecker Delta is Singleton
Informal description
For any index $i$ and nonzero element $b \in \beta i$ (i.e., $b \neq 0$), the support of the dependent Kronecker delta function $\text{single}_i(b)$ is exactly the singleton set $\{i\}$.
DFinsupp.support_single_subset theorem
{i : ι} {b : β i} : (single i b).support ⊆ { i }
Full source
theorem support_single_subset {i : ι} {b : β i} : (single i b).support ⊆ {i} :=
  support_mk'_subset
Support of Dependent Kronecker Delta is Subset of Singleton
Informal description
For any index $i$ and element $b \in \beta i$, the support of the dependent Kronecker delta function $\text{single}(i, b)$ is a subset of the singleton set $\{i\}$.
DFinsupp.mapRange_def theorem
[∀ (i) (x : β₁ i), Decidable (x ≠ 0)] {f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} : mapRange f hf g = mk g.support fun i => f i.1 (g i.1)
Full source
theorem mapRange_def [∀ (i) (x : β₁ i), Decidable (x ≠ 0)] {f : ∀ i, β₁ i → β₂ i}
    {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} :
    mapRange f hf g = mk g.support fun i => f i.1 (g i.1) := by
  ext i
  by_cases h : g i ≠ 0 <;> simp at h <;> simp [h, hf]
Definition of Range Mapping for Dependent Functions with Finite Support
Informal description
Let $\beta_1$ and $\beta_2$ be families of types indexed by $\iota$, each equipped with a zero element. Given a family of functions $f_i : \beta_1 i \to \beta_2 i$ such that $f_i(0) = 0$ for each $i \in \iota$, and a dependent function $g \in \Pi_{i} \beta_1 i$ with finite support, the mapping $\text{mapRange}\, f\, hf\, g$ is equal to the function constructed by restricting $g$ to its support and applying $f_i$ to each value $g(i)$. More precisely, if for each $i \in \iota$ and $x \in \beta_1 i$ it is decidable whether $x \neq 0$, then: \[ \text{mapRange}\, f\, hf\, g = \text{mk}\, (\text{supp}\, g)\, \big(\lambda i, f_i (g(i))\big), \] where $\text{supp}\, g$ is the finite set of indices where $g$ is non-zero, and $\text{mk}$ constructs a dependent function with specified values on the support and zero elsewhere.
DFinsupp.mapRange_single theorem
{f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {i : ι} {b : β₁ i} : mapRange f hf (single i b) = single i (f i b)
Full source
@[simp]
theorem mapRange_single {f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {i : ι} {b : β₁ i} :
    mapRange f hf (single i b) = single i (f i b) :=
  DFinsupp.ext fun i' => by
    by_cases h : i = i'
    · subst i'
      simp
    · simp [h, hf]
Mapping Range Preserves Kronecker Delta: $\text{mapRange}\, f\, (\text{single}_i(b)) = \text{single}_i(f_i(b))$
Informal description
Let $\beta_1$ and $\beta_2$ be families of types indexed by $\iota$, each equipped with a zero element. Given a family of functions $f_i : \beta_1 i \to \beta_2 i$ such that $f_i(0) = 0$ for each $i \in \iota$, and given an index $i \in \iota$ and an element $b \in \beta_1 i$, the mapping of the dependent Kronecker delta function $\text{single}_i(b)$ under $\text{mapRange}\, f\, hf$ is equal to the dependent Kronecker delta function $\text{single}_i(f_i(b))$. In other words: \[ \text{mapRange}\, f\, hf\, (\text{single}_i(b)) = \text{single}_i(f_i(b)). \]
DFinsupp.mapRange_injective theorem
(f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) : Function.Injective (mapRange f hf) ↔ ∀ i, Function.Injective (f i)
Full source
theorem mapRange_injective (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) :
    Function.InjectiveFunction.Injective (mapRange f hf) ↔ ∀ i, Function.Injective (f i) := by
  classical exact ⟨fun h i x y eq ↦ single_injective (@h (single i x) (single i y) <| by
    simpa using congr_arg _ eq), fun h _ _ eq ↦ DFinsupp.ext fun i ↦ h i congr($eq i)⟩
Injectivity of Range Mapping for Dependent Functions with Finite Support: $\text{mapRange}\,f\,hf$ is Injective $\leftrightarrow$ Each $f_i$ is Injective
Informal description
Let $\beta_1$ and $\beta_2$ be families of types indexed by $\iota$, each equipped with a zero element. Given a family of functions $f_i \colon \beta_1 i \to \beta_2 i$ such that $f_i(0) = 0$ for each $i \in \iota$, the mapping function $\text{mapRange}\,f\,hf \colon (\Pi_{i} \beta_1 i) \to (\Pi_{i} \beta_2 i)$ is injective if and only if each $f_i$ is injective.
DFinsupp.mapRange_surjective theorem
(f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) : Function.Surjective (mapRange f hf) ↔ ∀ i, Function.Surjective (f i)
Full source
theorem mapRange_surjective (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) :
    Function.SurjectiveFunction.Surjective (mapRange f hf) ↔ ∀ i, Function.Surjective (f i) := by
  classical
  refine ⟨fun h i u ↦ ?_, fun h x ↦ ?_⟩
  · obtain ⟨x, hx⟩ := h (single i u)
    exact ⟨x i, by simpa using congr($hx i)⟩
  · obtain ⟨x, s, hs⟩ := x
    have (i : ι) : ∃ u : β₁ i, f i u = x i ∧ (x i = 0 → u = 0) :=
      (eq_or_ne (x i) 0).elim
        (fun h ↦ ⟨0, (hf i).trans h.symm, fun _ ↦ rfl⟩)
        (fun h' ↦ by
          obtain ⟨u, hu⟩ := h i (x i)
          exact ⟨u, hu, fun h'' ↦ (h' h'').elim⟩)
    choose y hy using this
    refine ⟨⟨y, Trunc.mk ⟨s, fun i ↦ ?_⟩⟩, ext fun i ↦ ?_⟩
    · exact (hs i).imp_right (hy i).2
    · simp [(hy i).1]
Surjectivity of Range Mapping for Dependent Functions with Finite Support: $\text{mapRange}\,f\,hf$ is Surjective $\leftrightarrow$ Each $f_i$ is Surjective
Informal description
Let $\beta_1$ and $\beta_2$ be families of types indexed by $\iota$, each equipped with a zero element. Given a family of functions $f_i \colon \beta_1 i \to \beta_2 i$ such that $f_i(0) = 0$ for each $i \in \iota$, the mapping function $\text{mapRange}\,f\,hf \colon (\Pi_{i} \beta_1 i) \to (\Pi_{i} \beta_2 i)$ is surjective if and only if each $f_i$ is surjective.
DFinsupp.support_mapRange theorem
{f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} : (mapRange f hf g).support ⊆ g.support
Full source
theorem support_mapRange {f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} :
    (mapRange f hf g).support ⊆ g.support := by simp [mapRange_def]
Support Inclusion Under Range Mapping: $\text{supp}(\text{mapRange}\,f\,g) \subseteq \text{supp}(g)$
Informal description
Let $\iota$ be an index type, and let $\beta_1, \beta_2 \colon \iota \to \text{Type}$ be families of types with zero elements. Given a family of functions $f_i \colon \beta_1 i \to \beta_2 i$ such that $f_i(0) = 0$ for each $i \in \iota$, and a dependent function $g \in \Pi_{i} \beta_1 i$ with finite support, the support of the mapped function $\text{mapRange}\, f\, hf\, g$ is a subset of the support of $g$. In other words: \[ \text{supp}(\text{mapRange}\, f\, hf\, g) \subseteq \text{supp}(g). \]
DFinsupp.zipWith_def theorem
{ι : Type u} {β : ι → Type v} {β₁ : ι → Type v₁} {β₂ : ι → Type v₂} [dec : DecidableEq ι] [∀ i : ι, Zero (β i)] [∀ i : ι, Zero (β₁ i)] [∀ i : ι, Zero (β₂ i)] [∀ (i : ι) (x : β₁ i), Decidable (x ≠ 0)] [∀ (i : ι) (x : β₂ i), Decidable (x ≠ 0)] {f : ∀ i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0} {g₁ : Π₀ i, β₁ i} {g₂ : Π₀ i, β₂ i} : zipWith f hf g₁ g₂ = mk (g₁.support ∪ g₂.support) fun i => f i.1 (g₁ i.1) (g₂ i.1)
Full source
theorem zipWith_def {ι : Type u} {β : ι → Type v} {β₁ : ι → Type v₁} {β₂ : ι → Type v₂}
    [dec : DecidableEq ι] [∀ i : ι, Zero (β i)] [∀ i : ι, Zero (β₁ i)] [∀ i : ι, Zero (β₂ i)]
    [∀ (i : ι) (x : β₁ i), Decidable (x ≠ 0)] [∀ (i : ι) (x : β₂ i), Decidable (x ≠ 0)]
    {f : ∀ i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0} {g₁ : Π₀ i, β₁ i} {g₂ : Π₀ i, β₂ i} :
    zipWith f hf g₁ g₂ = mk (g₁.support ∪ g₂.support) fun i => f i.1 (g₁ i.1) (g₂ i.1) := by
  ext i
  by_cases h1 : g₁ i ≠ 0 <;> by_cases h2 : g₂ i ≠ 0 <;> simp only [not_not, Ne] at h1 h2 <;>
    simp [h1, h2, hf]
Definition of Pointwise Combination for Dependent Functions with Finite Support: $\text{zipWith}\,f\,g_1\,g_2 = \text{mk}\,(\text{supp}\,g_1 \cup \text{supp}\,g_2)\,(\lambda i \mapsto f_i (g_1 i) (g_2 i))$
Informal description
Let $\iota$ be a type with decidable equality, and let $\beta, \beta_1, \beta_2 \colon \iota \to \text{Type}$ be families of types such that for each $i \in \iota$, $\beta i$, $\beta_1 i$, and $\beta_2 i$ have a zero element. Suppose we have a family of binary operations $f_i \colon \beta_1 i \to \beta_2 i \to \beta i$ such that $f_i\,0\,0 = 0$ for each $i \in \iota$. Given two dependent functions with finite support $g_1 \in \Pi_{i} \beta_1 i$ and $g_2 \in \Pi_{i} \beta_2 i$, the pointwise combination $\text{zipWith}\,f\,hf\,g_1\,g_2$ is equal to the function constructed by taking the union of their supports $g_1.\text{supp} \cup g_2.\text{supp}$ and defining the value at each index $i$ in this union as $f_i (g_1 i) (g_2 i)$. More formally: \[ \text{zipWith}\,f\,hf\,g_1\,g_2 = \text{mk}\,(g_1.\text{supp} \cup g_2.\text{supp})\,\left(\lambda i \mapsto f_i (g_1 i) (g_2 i)\right). \]
DFinsupp.support_zipWith theorem
{f : ∀ i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0} {g₁ : Π₀ i, β₁ i} {g₂ : Π₀ i, β₂ i} : (zipWith f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support
Full source
theorem support_zipWith {f : ∀ i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0} {g₁ : Π₀ i, β₁ i}
    {g₂ : Π₀ i, β₂ i} : (zipWith f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support := by
  simp [zipWith_def]
Support of Pointwise Combination of Dependent Functions is Contained in Union of Supports
Informal description
Let $\iota$ be a type, and let $\beta_1, \beta_2, \beta \colon \iota \to \text{Type}$ be families of types such that for each $i \in \iota$, $\beta_1 i$, $\beta_2 i$, and $\beta i$ have a zero element. Given a family of binary operations $f_i \colon \beta_1 i \to \beta_2 i \to \beta i$ such that $f_i(0, 0) = 0$ for each $i \in \iota$, and given two dependent functions with finite support $g_1 \in \Pi_{i} \beta_1 i$ and $g_2 \in \Pi_{i} \beta_2 i$, the support of the pointwise combination $\text{zipWith}\,f\,hf\,g_1\,g_2$ is contained in the union of the supports of $g_1$ and $g_2$. That is, \[ \text{supp}(\text{zipWith}\,f\,hf\,g_1\,g_2) \subseteq \text{supp}(g_1) \cup \text{supp}(g_2). \]
DFinsupp.erase_def theorem
(i : ι) (f : Π₀ i, β i) : f.erase i = mk (f.support.erase i) fun j => f j.1
Full source
theorem erase_def (i : ι) (f : Π₀ i, β i) : f.erase i = mk (f.support.erase i) fun j => f j.1 := by
  ext j
  by_cases h1 : j = i <;> by_cases h2 : f j ≠ 0 <;> simp at h2 <;> simp [h1, h2]
Definition of Erasure in Dependent Functions with Finite Support
Informal description
For a dependent function with finite support $f \in \Pi_{i} \beta i$ and an index $i$, the function obtained by erasing the value at $i$ (setting it to zero) is equal to the function constructed from the support of $f$ with $i$ removed, where the values at all other indices remain unchanged. That is, \[ f.\text{erase}\, i = \text{mk}\, (f.\text{support} \setminus \{i\})\, (j \mapsto f j). \]
DFinsupp.support_erase theorem
(i : ι) (f : Π₀ i, β i) : (f.erase i).support = f.support.erase i
Full source
@[simp]
theorem support_erase (i : ι) (f : Π₀ i, β i) : (f.erase i).support = f.support.erase i := by
  ext j
  by_cases h1 : j = i
  · simp only [h1, mem_support_toFun, erase_apply, ite_true, ne_eq, not_true, not_not,
      Finset.mem_erase, false_and]
  by_cases h2 : f j ≠ 0 <;> simp at h2 <;> simp [h1, h2]
Support of Erased Dependent Function with Finite Support
Informal description
For a dependent function with finite support $f \in \Pi_{i} \beta i$ and an index $i$, the support of the function obtained by erasing the value at $i$ (setting it to zero) is equal to the support of $f$ with $i$ removed. That is, \[ \text{supp}(f.\text{erase}\, i) = \text{supp}(f) \setminus \{i\}. \]
DFinsupp.support_update_ne_zero theorem
(f : Π₀ i, β i) (i : ι) {b : β i} (h : b ≠ 0) : support (f.update i b) = insert i f.support
Full source
theorem support_update_ne_zero (f : Π₀ i, β i) (i : ι) {b : β i} (h : b ≠ 0) :
    support (f.update i b) = insert i f.support := by
  ext j
  rcases eq_or_ne i j with (rfl | hi)
  · simp [h]
  · simp [hi.symm]
Support of Updated Dependent Function with Non-Zero Value
Informal description
For a dependent function with finite support \( f \in \Pi_{i} \beta i \), an index \( i \), and a non-zero value \( b \in \beta i \), the support of the updated function \( f.update \, i \, b \) is equal to the union of the singleton set \(\{i\}\) with the support of \( f \). That is, \[ \text{supp}(f.update \, i \, b) = \{i\} \cup \text{supp}(f). \]
DFinsupp.support_update theorem
(f : Π₀ i, β i) (i : ι) (b : β i) [Decidable (b = 0)] : support (f.update i b) = if b = 0 then support (f.erase i) else insert i f.support
Full source
theorem support_update (f : Π₀ i, β i) (i : ι) (b : β i) [Decidable (b = 0)] :
    support (f.update i b) = if b = 0 then support (f.erase i) else insert i f.support := by
  ext j
  split_ifs with hb
  · subst hb
    simp [update_eq_erase, support_erase]
  · rw [support_update_ne_zero f _ hb]
Support of Updated Dependent Function with Finite Support: $\text{supp}(f.\text{update}(i, b)) = \text{if } b = 0 \text{ then } \text{supp}(f.\text{erase}(i)) \text{ else } \{i\} \cup \text{supp}(f)$
Informal description
For a dependent function with finite support $f \in \Pi_{i} \beta i$, an index $i$, and a value $b \in \beta i$ (with decidability of $b = 0$), the support of the updated function $f.\text{update}(i, b)$ is equal to: \[ \text{supp}(f.\text{erase}(i)) \quad \text{if } b = 0, \quad \text{or} \quad \{i\} \cup \text{supp}(f) \quad \text{otherwise.} \]
DFinsupp.filter_def theorem
(f : Π₀ i, β i) : f.filter p = mk (f.support.filter p) fun i => f i.1
Full source
theorem filter_def (f : Π₀ i, β i) : f.filter p = mk (f.support.filter p) fun i => f i.1 := by
  ext i; by_cases h1 : p i <;> by_cases h2 : f i ≠ 0 <;> simp at h2 <;> simp [h1, h2]
Definition of Filter Operation on Dependent Functions with Finite Support
Informal description
For a dependent function $f \in \Pi_{i} \beta i$ with finite support and a predicate $p$ on the index set $\iota$, the filtered function $f.filter\ p$ is equal to the dependent function constructed from the finite subset $\{i \in \text{supp}(f) \mid p(i)\}$ of the support of $f$, where for each $i$ in this subset, the value is $f(i)$. More formally: \[ f.filter\ p = \text{mk}\ (\text{supp}(f).filter\ p)\ (\lambda i \mapsto f(i)) \] where $\text{mk}$ constructs a dependent function with finite support from a finite set of indices and a function defined on those indices.
DFinsupp.support_filter theorem
(f : Π₀ i, β i) : (f.filter p).support = {x ∈ f.support | p x}
Full source
@[simp]
theorem support_filter (f : Π₀ i, β i) : (f.filter p).support = {x ∈ f.support | p x} := by
  ext i; by_cases h : p i <;> simp [h]
Support of Filtered Dependent Function with Finite Support
Informal description
For a dependent function $f \in \Pi_{i} \beta i$ with finite support and a predicate $p$ on the index set $\iota$, the support of the filtered function $f.filter\ p$ is equal to the subset of the support of $f$ where $p$ holds. More precisely, we have: \[ \text{supp}(f.filter\ p) = \{x \in \text{supp}(f) \mid p(x)\} \]
DFinsupp.subtypeDomain_def theorem
(f : Π₀ i, β i) : f.subtypeDomain p = mk (f.support.subtype p) fun i => f i
Full source
theorem subtypeDomain_def (f : Π₀ i, β i) :
    f.subtypeDomain p = mk (f.support.subtype p) fun i => f i := by
  ext i; by_cases h2 : f i ≠ 0 <;> try simp at h2; dsimp; simp [h2]
Restriction of Dependent Function Equals Construction from Restricted Support
Informal description
For any dependent function $f \in \Pi_{i} \beta i$ with finite support and any predicate $p$ on the index set $\iota$, the restriction of $f$ to the subtype defined by $p$ is equal to the function constructed from the restriction of $f$'s support to the subtype and the values of $f$ on this restricted support. More precisely, we have: \[ f \restriction_{\{i \mid p(i)\}} = \text{mk}\left(\text{supp}(f) \cap \{i \mid p(i)\}, \lambda i, f(i)\right) \] where $\text{mk}$ constructs a dependent function with finite support from a finite set of indices and a function defined on those indices.
DFinsupp.support_subtypeDomain theorem
{f : Π₀ i, β i} : (subtypeDomain p f).support = f.support.subtype p
Full source
@[simp]
theorem support_subtypeDomain {f : Π₀ i, β i} :
    (subtypeDomain p f).support = f.support.subtype p := by
  ext i
  simp
Support of Restricted Dependent Function Equals Subtype of Original Support
Informal description
For any dependent function $f \in \Pi_{i} \beta i$ with finite support and any predicate $p$ on the index set $\iota$, the support of the restricted function $f \restriction_{\{i \mid p(i)\}}$ is equal to the subtype of the support of $f$ where $p$ holds. More precisely, we have: \[ \text{supp}(f \restriction_{\{i \mid p(i)\}}) = \text{supp}(f) \cap \{i \mid p(i)\} \]
DFinsupp.support_add theorem
[∀ i, AddZeroClass (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] {g₁ g₂ : Π₀ i, β i} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support
Full source
theorem support_add [∀ i, AddZeroClass (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)]
    {g₁ g₂ : Π₀ i, β i} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
  support_zipWith
Support of Sum of Dependent Functions is Contained in Union of Supports
Informal description
Let $\iota$ be a type and $\beta \colon \iota \to \text{Type}$ be a family of types where each $\beta i$ has an additive zero class structure and decidable non-zero condition. For any two dependent functions $g_1, g_2 \in \Pi_{i} \beta i$ with finite support, the support of their sum satisfies: \[ \text{supp}(g_1 + g_2) \subseteq \text{supp}(g_1) \cup \text{supp}(g_2). \]
DFinsupp.support_neg theorem
[∀ i, AddGroup (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] {f : Π₀ i, β i} : support (-f) = support f
Full source
@[simp]
theorem support_neg [∀ i, AddGroup (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] {f : Π₀ i, β i} :
    support (-f) = support f := by ext i; simp
Support of Negated Dependent Function Equals Original Support
Informal description
For any dependent function $f \in \Pi_{i} \beta i$ with finite support, where each $\beta i$ is an additive group and the non-zero condition is decidable, the support of the negation $-f$ is equal to the support of $f$. That is, $\text{supp}(-f) = \text{supp}(f)$.
DFinsupp.instDecidableEq instance
[∀ i, Zero (β i)] [∀ i, DecidableEq (β i)] : DecidableEq (Π₀ i, β i)
Full source
instance [∀ i, Zero (β i)] [∀ i, DecidableEq (β i)] : DecidableEq (Π₀ i, β i) := fun f g =>
  decidable_of_iff (f.support = g.support ∧ ∀ i ∈ f.support, f i = g i)
    ⟨fun ⟨h₁, h₂⟩ => ext fun i => if h : i ∈ f.support then h₂ i h else by
      have hf : f i = 0 := by rwa [mem_support_iff, not_not] at h
      have hg : g i = 0 := by rwa [h₁, mem_support_iff, not_not] at h
      rw [hf, hg],
     by rintro rfl; simp⟩
Decidable Equality for Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i \in \iota$ where each $\beta_i$ has a zero element and a decidable equality, the type $\Pi_{i} \beta_i$ of dependent functions with finite support has decidable equality.
DFinsupp.comapDomain definition
[∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) (f : Π₀ i, β i) : Π₀ k, β (h k)
Full source
/-- Reindexing (and possibly removing) terms of a dfinsupp. -/
noncomputable def comapDomain [∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h)
    (f : Π₀ i, β i) : Π₀ k, β (h k) where
  toFun x := f (h x)
  support' :=
    f.support'.map fun s =>
      ⟨(s.1.finite_toSet.preimage hh.injOn).toFinset.val, fun x =>
        (s.prop (h x)).imp_left fun hx => (Set.Finite.mem_toFinset _).mpr <| hx⟩
Preimage of a dependent function with finite support under an injective map
Informal description
Given an injective function $h : \kappa \to \iota$ and a dependent function $f : \Pi₀ i, \beta i$ with finite support, the function `DFinsupp.comapDomain` constructs a new dependent function $g : \Pi₀ k, \beta (h k)$ defined by $g(k) = f(h(k))$ for each $k \in \kappa$. The support of $g$ is the preimage of the support of $f$ under $h$, ensuring that $g$ also has finite support.
DFinsupp.comapDomain_apply theorem
[∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) (f : Π₀ i, β i) (k : κ) : comapDomain h hh f k = f (h k)
Full source
@[simp]
theorem comapDomain_apply [∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) (f : Π₀ i, β i)
    (k : κ) : comapDomain h hh f k = f (h k) :=
  rfl
Evaluation of Preimage Function in Dependent Finite Support
Informal description
Let $\beta$ be a family of types indexed by $\iota$, each equipped with a zero element. Given an injective function $h : \kappa \to \iota$ and a dependent function $f : \Pi₀ i, \beta i$ with finite support, the evaluation of the preimage function $\operatorname{comapDomain}\, h\, hh\, f$ at any $k \in \kappa$ satisfies $(\operatorname{comapDomain}\, h\, hh\, f)(k) = f(h(k))$.
DFinsupp.comapDomain_zero theorem
[∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) : comapDomain h hh (0 : Π₀ i, β i) = 0
Full source
@[simp]
theorem comapDomain_zero [∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) :
    comapDomain h hh (0 : Π₀ i, β i) = 0 := by
  ext
  rw [zero_apply, comapDomain_apply, zero_apply]
Preimage of Zero Function under Injection is Zero
Informal description
For any family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has a zero element, and for any injective function $h : \kappa \to \iota$, the preimage of the zero dependent function under $h$ is the zero function in $\Pi₀ k, \beta (h k)$. That is, $\operatorname{comapDomain}\, h\, hh\, 0 = 0$.
DFinsupp.comapDomain_add theorem
[∀ i, AddZeroClass (β i)] (h : κ → ι) (hh : Function.Injective h) (f g : Π₀ i, β i) : comapDomain h hh (f + g) = comapDomain h hh f + comapDomain h hh g
Full source
@[simp]
theorem comapDomain_add [∀ i, AddZeroClass (β i)] (h : κ → ι) (hh : Function.Injective h)
    (f g : Π₀ i, β i) : comapDomain h hh (f + g) = comapDomain h hh f + comapDomain h hh g := by
  ext
  rw [add_apply, comapDomain_apply, comapDomain_apply, comapDomain_apply, add_apply]
Additivity of Preimage for Dependent Functions with Finite Support
Informal description
Let $\beta$ be a family of types indexed by $\iota$, where each $\beta_i$ has an additive zero class structure. For any injective function $h : \kappa \to \iota$ and any two dependent functions $f, g \in \Pi₀ i, \beta i$ with finite support, the preimage of their sum under $h$ equals the sum of their preimages, i.e., \[ \operatorname{comapDomain}\, h\, hh\, (f + g) = \operatorname{comapDomain}\, h\, hh\, f + \operatorname{comapDomain}\, h\, hh\, g. \]
DFinsupp.comapDomain_single theorem
[DecidableEq ι] [DecidableEq κ] [∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) (k : κ) (x : β (h k)) : comapDomain h hh (single (h k) x) = single k x
Full source
@[simp]
theorem comapDomain_single [DecidableEq ι] [DecidableEq κ] [∀ i, Zero (β i)] (h : κ → ι)
    (hh : Function.Injective h) (k : κ) (x : β (h k)) :
    comapDomain h hh (single (h k) x) = single k x := by
  ext i
  rw [comapDomain_apply]
  obtain rfl | hik := Decidable.eq_or_ne i k
  · rw [single_eq_same, single_eq_same]
  · rw [single_eq_of_ne hik.symm, single_eq_of_ne (hh.ne hik.symm)]
Preimage of Kronecker Delta under Injection: $\operatorname{comapDomain}\, h\, (\text{single}_{h(k)}(x)) = \text{single}_k(x)$
Informal description
Let $\iota$ and $\kappa$ be types with decidable equality, and let $\beta$ be a family of types indexed by $\iota$, each equipped with a zero element. Given an injective function $h \colon \kappa \to \iota$, a point $k \in \kappa$, and an element $x \in \beta(h(k))$, the preimage under $h$ of the Kronecker delta function $\text{single}_{h(k)}(x) \in \Pi₀ i, \beta i$ is equal to the Kronecker delta function $\text{single}_k(x) \in \Pi₀ k, \beta(h(k))$. That is, \[ \operatorname{comapDomain}\, h\, hh\, (\text{single}_{h(k)}(x)) = \text{single}_k(x). \]
DFinsupp.comapDomain' definition
[∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (f : Π₀ i, β i) : Π₀ k, β (h k)
Full source
/-- A computable version of comap_domain when an explicit left inverse is provided. -/
def comapDomain' [∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h)
    (f : Π₀ i, β i) : Π₀ k, β (h k) where
  toFun x := f (h x)
  support' :=
    f.support'.map fun s =>
      ⟨Multiset.map h' s.1, fun x =>
        (s.prop (h x)).imp_left fun hx => Multiset.mem_map.mpr ⟨_, hx, hh' _⟩⟩
Precomposition of dependent functions with finite support using a left inverse
Informal description
Given a function $h : \kappa \to \iota$ and a left inverse $h' : \iota \to \kappa$ of $h$ (i.e., $h' \circ h = \text{id}$), the function `comapDomain'` maps a dependent function $f : \Pi_{i} \beta i$ with finite support to a new dependent function $\Pi_{k} \beta (h k)$ with finite support, defined by $(f \circ h)$. The support of the resulting function is computed efficiently using the left inverse $h'$ to map the original support.
DFinsupp.comapDomain'_apply theorem
[∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (f : Π₀ i, β i) (k : κ) : comapDomain' h hh' f k = f (h k)
Full source
@[simp]
theorem comapDomain'_apply [∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ}
    (hh' : Function.LeftInverse h' h) (f : Π₀ i, β i) (k : κ) : comapDomain' h hh' f k = f (h k) :=
  rfl
Evaluation of Precomposed Dependent Function with Finite Support
Informal description
For a family of types $\beta_i$ each equipped with a zero element, given a function $h \colon \kappa \to \iota$ with a left inverse $h' \colon \iota \to \kappa$ (i.e., $h'(h(k)) = k$ for all $k \in \kappa$), and a dependent function $f \colon \Pi_{i} \beta i$ with finite support, the evaluation of the precomposed function $\text{comapDomain}'\, h\, hh'\, f$ at any $k \in \kappa$ satisfies \[ (\text{comapDomain}'\, h\, hh'\, f)(k) = f(h(k)). \]
DFinsupp.comapDomain'_zero theorem
[∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) : comapDomain' h hh' (0 : Π₀ i, β i) = 0
Full source
@[simp]
theorem comapDomain'_zero [∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ}
    (hh' : Function.LeftInverse h' h) : comapDomain' h hh' (0 : Π₀ i, β i) = 0 := by
  ext
  rw [zero_apply, comapDomain'_apply, zero_apply]
Precomposition of Zero Function Preserves Zero: $\text{comapDomain}'\, h\, hh'\, 0 = 0$
Informal description
For any family of types $(\beta_i)_{i \in \iota}$ where each $\beta_i$ has a zero element, given a function $h : \kappa \to \iota$ with a left inverse $h' : \iota \to \kappa$ (i.e., $h' \circ h = \text{id}_\kappa$), the precomposition of the zero dependent function with finite support via $h$ yields the zero function, i.e., \[ \text{comapDomain}'\, h\, hh'\, (0 : \Pi₀ i, \beta i) = 0. \]
DFinsupp.comapDomain'_add theorem
[∀ i, AddZeroClass (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (f g : Π₀ i, β i) : comapDomain' h hh' (f + g) = comapDomain' h hh' f + comapDomain' h hh' g
Full source
@[simp]
theorem comapDomain'_add [∀ i, AddZeroClass (β i)] (h : κ → ι) {h' : ι → κ}
    (hh' : Function.LeftInverse h' h) (f g : Π₀ i, β i) :
    comapDomain' h hh' (f + g) = comapDomain' h hh' f + comapDomain' h hh' g := by
  ext
  rw [add_apply, comapDomain'_apply, comapDomain'_apply, comapDomain'_apply, add_apply]
Additivity of Precomposition for Dependent Functions with Finite Support
Informal description
For any family of types $\beta_i$ indexed by $i \in \iota$ where each $\beta_i$ has an additive zero class structure, given a function $h : \kappa \to \iota$ with a left inverse $h' : \iota \to \kappa$ (i.e., $h'(h(k)) = k$ for all $k \in \kappa$), the precomposition operation $\text{comapDomain}'\, h\, hh'$ preserves addition. That is, for any two dependent functions with finite support $f, g \in \Pi₀ i, \beta i$, we have: \[ \text{comapDomain}'\, h\, hh'\, (f + g) = \text{comapDomain}'\, h\, hh'\, f + \text{comapDomain}'\, h\, hh'\, g. \]
DFinsupp.comapDomain'_single theorem
[DecidableEq ι] [DecidableEq κ] [∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (k : κ) (x : β (h k)) : comapDomain' h hh' (single (h k) x) = single k x
Full source
@[simp]
theorem comapDomain'_single [DecidableEq ι] [DecidableEq κ] [∀ i, Zero (β i)] (h : κ → ι)
    {h' : ι → κ} (hh' : Function.LeftInverse h' h) (k : κ) (x : β (h k)) :
    comapDomain' h hh' (single (h k) x) = single k x := by
  ext i
  rw [comapDomain'_apply]
  obtain rfl | hik := Decidable.eq_or_ne i k
  · rw [single_eq_same, single_eq_same]
  · rw [single_eq_of_ne hik.symm, single_eq_of_ne (hh'.injective.ne hik.symm)]
Precomposition of Kronecker Delta: $\text{comapDomain}'\, h\, hh'\, (\text{single}_{h(k)}(x)) = \text{single}_k(x)$
Informal description
Let $\iota$ and $\kappa$ be types with decidable equality, and let $(\beta_i)_{i \in \iota}$ be a family of types each equipped with a zero element. Given a function $h \colon \kappa \to \iota$ with a left inverse $h' \colon \iota \to \kappa$ (i.e., $h'(h(k)) = k$ for all $k \in \kappa$), and given any $k \in \kappa$ and $x \in \beta_{h(k)}$, the precomposition of the dependent Kronecker delta function $\text{single}_{h(k)}(x)$ via $h$ equals the dependent Kronecker delta function $\text{single}_k(x)$. That is, \[ \text{comapDomain}'\, h\, hh'\, (\text{single}_{h(k)}(x)) = \text{single}_k(x). \]
DFinsupp.equivCongrLeft definition
[∀ i, Zero (β i)] (h : ι ≃ κ) : (Π₀ i, β i) ≃ Π₀ k, β (h.symm k)
Full source
/-- Reindexing terms of a dfinsupp.

This is the dfinsupp version of `Equiv.piCongrLeft'`. -/
@[simps apply]
def equivCongrLeft [∀ i, Zero (β i)] (h : ι ≃ κ) : (Π₀ i, β i) ≃ Π₀ k, β (h.symm k) where
  toFun := comapDomain' h.symm h.right_inv
  invFun f :=
    mapRange (fun i => Equiv.cast <| congr_arg β <| h.symm_apply_apply i)
      (fun i => (Equiv.cast_eq_iff_heq _).mpr <| by rw [Equiv.symm_apply_apply])
      (@comapDomain' _ _ _ _ h _ h.left_inv f)
  left_inv f := by
    ext i
    rw [mapRange_apply, comapDomain'_apply, comapDomain'_apply, Equiv.cast_eq_iff_heq,
      h.symm_apply_apply]
  right_inv f := by
    ext k
    rw [comapDomain'_apply, mapRange_apply, comapDomain'_apply, Equiv.cast_eq_iff_heq,
      h.apply_symm_apply]
Equivalence of dependent functions with finite support under index reindexing
Informal description
Given an equivalence $h : \iota \simeq \kappa$ between index types $\iota$ and $\kappa$, and a family of types $\beta_i$ each equipped with a zero element, the function `DFinsupp.equivCongrLeft` constructs an equivalence between the type of dependent functions with finite support $\Pi_{i} \beta i$ and $\Pi_{k} \beta (h^{-1} k)$. The forward map is given by precomposing with $h^{-1}$ (using `comapDomain'`), and the inverse map is constructed by applying $h$ to the indices and adjusting the types via casting along the proof that $h^{-1} \circ h = \text{id}$. This equivalence preserves the finite support property of the functions.
DFinsupp.hasAdd₂ instance
[∀ i j, AddZeroClass (δ i j)] : Add (Π₀ (i : ι) (j : α i), δ i j)
Full source
instance hasAdd₂ [∀ i j, AddZeroClass (δ i j)] : Add (Π₀ (i : ι) (j : α i), δ i j) :=
  inferInstance
Addition on Doubly Dependent Functions with Finite Support
Informal description
For any family of types $(\delta_{i,j})_{i \in \iota, j \in \alpha_i}$ where each $\delta_{i,j}$ has an additive zero class structure, the type $\Pi₀ (i : \iota) (j : \alpha_i), \delta_{i,j}$ of doubly dependent functions with finite support is equipped with a pointwise addition operation.
DFinsupp.addZeroClass₂ instance
[∀ i j, AddZeroClass (δ i j)] : AddZeroClass (Π₀ (i : ι) (j : α i), δ i j)
Full source
instance addZeroClass₂ [∀ i j, AddZeroClass (δ i j)] : AddZeroClass (Π₀ (i : ι) (j : α i), δ i j) :=
  inferInstance
Additive Zero Class Structure on Doubly Dependent Functions with Finite Support
Informal description
For any family of types $(\delta_{i,j})_{i \in \iota, j \in \alpha_i}$ where each $\delta_{i,j}$ has an additive zero class structure, the type $\Pi₀ (i,j), \delta_{i,j}$ of doubly dependent functions with finite support forms an additive zero class with pointwise addition and zero function.
DFinsupp.addMonoid₂ instance
[∀ i j, AddMonoid (δ i j)] : AddMonoid (Π₀ (i : ι) (j : α i), δ i j)
Full source
instance addMonoid₂ [∀ i j, AddMonoid (δ i j)] : AddMonoid (Π₀ (i : ι) (j : α i), δ i j) :=
  inferInstance
Add Monoid Structure on Doubly Dependent Functions with Finite Support
Informal description
For any family of types $\delta_{i,j}$ indexed by $i$ and $j$, where each $\delta_{i,j}$ is equipped with an add monoid structure, the type $\Pi₀ (i,j), \delta_{i,j}$ of doubly dependent functions with finite support forms an add monoid under pointwise addition.
DFinsupp.extendWith definition
[∀ i, Zero (α i)] (a : α none) (f : Π₀ i, α (some i)) : Π₀ i, α i
Full source
/-- Adds a term to a dfinsupp, making a dfinsupp indexed by an `Option`.

This is the dfinsupp version of `Option.rec`. -/
def extendWith [∀ i, Zero (α i)] (a : α none) (f : Π₀ i, α (some i)) : Π₀ i, α i where
  toFun := fun i ↦ match i with | none => a | some _ => f _
  support' :=
    f.support'.map fun s =>
      ⟨none ::ₘ Multiset.map some s.1, fun i =>
        Option.rec (Or.inl <| Multiset.mem_cons_self _ _)
          (fun i =>
            (s.prop i).imp_left fun h => Multiset.mem_cons_of_mem <| Multiset.mem_map_of_mem _ h)
          i⟩
Extension of dependent function with finite support by adding a value at `none`
Informal description
Given a dependent function with finite support `f : Π₀ i, α (some i)` and an element `a : α none`, the function `DFinsupp.extendWith` constructs a new dependent function with finite support `Π₀ i, α i` by extending `f` to include the value `a` at the index `none` and preserving the values of `f` at all other indices. More precisely, the resulting function maps: - `none` to `a` - `some i` to `f i` for any `i` in the domain of `f` The support of the resulting function is constructed by adding `none` to the support of `f` and mapping the remaining support elements through `some`.
DFinsupp.extendWith_none theorem
[∀ i, Zero (α i)] (f : Π₀ i, α (some i)) (a : α none) : f.extendWith a none = a
Full source
@[simp]
theorem extendWith_none [∀ i, Zero (α i)] (f : Π₀ i, α (some i)) (a : α none) :
    f.extendWith a none = a :=
  rfl
Extension of Dependent Function Evaluates to Added Value at None
Informal description
For any dependent function with finite support $f \in \Pi_{i} \alpha (\text{some } i)$ and any element $a \in \alpha (\text{none})$, the extension of $f$ by $a$ satisfies $(f.\text{extendWith } a) (\text{none}) = a$.
DFinsupp.extendWith_some theorem
[∀ i, Zero (α i)] (f : Π₀ i, α (some i)) (a : α none) (i : ι) : f.extendWith a (some i) = f i
Full source
@[simp]
theorem extendWith_some [∀ i, Zero (α i)] (f : Π₀ i, α (some i)) (a : α none) (i : ι) :
    f.extendWith a (some i) = f i :=
  rfl
Extension of Dependent Function Preserves Values at Some Indices
Informal description
For any dependent function with finite support $f \in \Pi_{i} \alpha (\text{some } i)$ and any element $a \in \alpha (\text{none})$, the extension of $f$ by $a$ satisfies $(f.\text{extendWith } a) (\text{some } i) = f i$ for all indices $i$.
DFinsupp.extendWith_single_zero theorem
[DecidableEq ι] [∀ i, Zero (α i)] (i : ι) (x : α (some i)) : (single i x).extendWith 0 = single (some i) x
Full source
@[simp]
theorem extendWith_single_zero [DecidableEq ι] [∀ i, Zero (α i)] (i : ι) (x : α (some i)) :
    (single i x).extendWith 0 = single (some i) x := by
  ext (_ | j)
  · rw [extendWith_none, single_eq_of_ne (Option.some_ne_none _)]
  · rw [extendWith_some]
    obtain rfl | hij := Decidable.eq_or_ne i j
    · rw [single_eq_same, single_eq_same]
    · rw [single_eq_of_ne hij, single_eq_of_ne ((Option.some_injective _).ne hij)]
Extension of Kronecker Delta by Zero Equals Kronecker Delta at Some Index
Informal description
Let $\iota$ be a type with decidable equality, and let $\alpha$ be a family of types indexed by $\operatorname{Option} \iota$ where each $\alpha i$ has a zero element. For any index $i \in \iota$ and any element $x \in \alpha (\operatorname{some} i)$, the extension of the dependent Kronecker delta function $\operatorname{single}_i(x)$ by zero satisfies \[ (\operatorname{single}_i(x)).\operatorname{extendWith} 0 = \operatorname{single}_{\operatorname{some} i}(x). \]
DFinsupp.extendWith_zero theorem
[DecidableEq ι] [∀ i, Zero (α i)] (x : α none) : (0 : Π₀ i, α (some i)).extendWith x = single none x
Full source
@[simp]
theorem extendWith_zero [DecidableEq ι] [∀ i, Zero (α i)] (x : α none) :
    (0 : Π₀ i, α (some i)).extendWith x = single none x := by
  ext (_ | j)
  · rw [extendWith_none, single_eq_same]
  · rw [extendWith_some, single_eq_of_ne (Option.some_ne_none _).symm, zero_apply]
Extension of Zero Function by $x$ Equals Kronecker Delta at None Index: $(0).\text{extendWith } x = \text{single}_{\text{none}}(x)$
Informal description
Let $\iota$ be a type with decidable equality, and let $\alpha$ be a family of types indexed by $\operatorname{Option} \iota$ where each $\alpha i$ has a zero element. For any element $x \in \alpha (\operatorname{none})$, the extension of the zero dependent function with finite support by $x$ satisfies \[ (0 : \Pi₀ i, \alpha (\text{some } i)).\text{extendWith } x = \text{single}_{\text{none}}(x). \]
DFinsupp.equivProdDFinsupp definition
[∀ i, Zero (α i)] : (Π₀ i, α i) ≃ α none × Π₀ i, α (some i)
Full source
/-- Bijection obtained by separating the term of index `none` of a dfinsupp over `Option ι`.

This is the dfinsupp version of `Equiv.piOptionEquivProd`. -/
@[simps]
noncomputable def equivProdDFinsupp [∀ i, Zero (α i)] :
    (Π₀ i, α i) ≃ α none × Π₀ i, α (some i) where
  toFun f := (f none, comapDomain some (Option.some_injective _) f)
  invFun f := f.2.extendWith f.1
  left_inv f := by
    ext i; obtain - | i := i
    · rw [extendWith_none]
    · rw [extendWith_some, comapDomain_apply]
  right_inv x := by
    dsimp only
    ext
    · exact extendWith_none x.snd _
    · rw [comapDomain_apply, extendWith_some]
Bijection between dependent functions with finite support and product of value at `none` with restricted function
Informal description
The bijection `DFinsupp.equivProdDFinsupp` establishes an equivalence between the type of dependent functions with finite support `Π₀ i, α i` (where each `α i` has a zero element) and the product type `α none × Π₀ i, α (some i)`. - The forward direction maps a function `f : Π₀ i, α i` to the pair `(f none, f ∘ some)`, where `f ∘ some` is obtained by restricting `f` to the indices of the form `some i`. - The inverse direction takes a pair `(a, g)` where `a : α none` and `g : Π₀ i, α (some i)`, and constructs a function that maps `none` to `a` and `some i` to `g i` for each `i`. This equivalence is analogous to the bijection `Equiv.piOptionEquivProd` for ordinary functions.
DFinsupp.equivProdDFinsupp_add theorem
[∀ i, AddZeroClass (α i)] (f g : Π₀ i, α i) : equivProdDFinsupp (f + g) = equivProdDFinsupp f + equivProdDFinsupp g
Full source
theorem equivProdDFinsupp_add [∀ i, AddZeroClass (α i)] (f g : Π₀ i, α i) :
    equivProdDFinsupp (f + g) = equivProdDFinsupp f + equivProdDFinsupp g :=
  Prod.ext (add_apply _ _ _) (comapDomain_add _ (Option.some_injective _) _ _)
Additivity of the Bijection between Dependent Functions and Product Space
Informal description
For any family of types $\alpha_i$ indexed by $i$ where each $\alpha_i$ has an additive zero class structure, and for any two dependent functions with finite support $f, g \in \Pi₀ i, \alpha i$, the bijection `equivProdDFinsupp` preserves addition. That is, \[ \operatorname{equivProdDFinsupp}(f + g) = \operatorname{equivProdDFinsupp}(f) + \operatorname{equivProdDFinsupp}(g). \] Here, the addition on the right-hand side is the pointwise addition in the product type $\alpha_{\text{none}} \times \Pi₀ i, \alpha (\text{some } i)$.
DFinsupp.mapRange_add theorem
(f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (hf' : ∀ i x y, f i (x + y) = f i x + f i y) (g₁ g₂ : Π₀ i, β₁ i) : mapRange f hf (g₁ + g₂) = mapRange f hf g₁ + mapRange f hf g₂
Full source
theorem mapRange_add (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0)
    (hf' : ∀ i x y, f i (x + y) = f i x + f i y) (g₁ g₂ : Π₀ i, β₁ i) :
    mapRange f hf (g₁ + g₂) = mapRange f hf g₁ + mapRange f hf g₂ := by
  ext
  simp only [mapRange_apply f, coe_add, Pi.add_apply, hf']
Additivity of $\text{mapRange}$ for Dependent Functions with Finite Support
Informal description
For a family of additive functions $f_i \colon \beta_1 i \to \beta_2 i$ (indexed by $i$) such that each $f_i$ maps zero to zero and preserves addition, and for any two dependent functions $g_1, g_2 \in \Pi_{i} \beta_1 i$ with finite support, the following equality holds: \[ \text{mapRange}\, f\, hf\, (g_1 + g_2) = \text{mapRange}\, f\, hf\, g_1 + \text{mapRange}\, f\, hf\, g_2. \] Here, $\text{mapRange}$ applies each $f_i$ pointwise to the corresponding value of the input function.
DFinsupp.mapRange.addMonoidHom definition
(f : ∀ i, β₁ i →+ β₂ i) : (Π₀ i, β₁ i) →+ Π₀ i, β₂ i
Full source
/-- `DFinsupp.mapRange` as an `AddMonoidHom`. -/
@[simps apply]
def mapRange.addMonoidHom (f : ∀ i, β₁ i →+ β₂ i) : (Π₀ i, β₁ i) →+ Π₀ i, β₂ i where
  toFun := mapRange (fun i x => f i x) fun i => (f i).map_zero
  map_zero' := mapRange_zero _ _
  map_add' := mapRange_add _ (fun i => (f i).map_zero) fun i => (f i).map_add
Additive monoid homomorphism induced by pointwise mapping of dependent functions with finite support
Informal description
Given a family of additive monoid homomorphisms \( f_i \colon \beta_1 i \to \beta_2 i \) for each index \( i \), the function `DFinsupp.mapRange.addMonoidHom` constructs an additive monoid homomorphism from the type of dependent functions with finite support \( \Pi_{i} \beta_1 i \) to \( \Pi_{i} \beta_2 i \). This homomorphism applies each \( f_i \) pointwise to the corresponding value of the input function, preserves the zero function, and respects addition.
DFinsupp.mapRange.addMonoidHom_id theorem
: (mapRange.addMonoidHom fun i => AddMonoidHom.id (β₂ i)) = AddMonoidHom.id _
Full source
@[simp]
theorem mapRange.addMonoidHom_id :
    (mapRange.addMonoidHom fun i => AddMonoidHom.id (β₂ i)) = AddMonoidHom.id _ :=
  AddMonoidHom.ext mapRange_id
Identity Mapping Preserves Identity Homomorphism for Dependent Functions with Finite Support
Informal description
The additive monoid homomorphism obtained by applying the identity homomorphism pointwise to each component of a dependent function with finite support is equal to the identity homomorphism on the type of such functions. That is, for any family of types $(\beta_2 i)_{i \in \iota}$ with additive zero class structures, we have: \[ \text{mapRange.addMonoidHom} (\lambda i, \text{AddMonoidHom.id} (\beta_2 i)) = \text{AddMonoidHom.id} (\Pi_{i} \beta_2 i). \]
DFinsupp.mapRange.addMonoidHom_comp theorem
(f : ∀ i, β₁ i →+ β₂ i) (f₂ : ∀ i, β i →+ β₁ i) : (mapRange.addMonoidHom fun i => (f i).comp (f₂ i)) = (mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂)
Full source
theorem mapRange.addMonoidHom_comp (f : ∀ i, β₁ i →+ β₂ i) (f₂ : ∀ i, β i →+ β₁ i) :
    (mapRange.addMonoidHom fun i => (f i).comp (f₂ i)) =
      (mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂) := by
  refine AddMonoidHom.ext <| mapRange_comp (fun i x => f i x) (fun i x => f₂ i x) ?_ ?_ ?_
  · intros; apply map_zero
  · intros; apply map_zero
  · intros; dsimp; simp only [map_zero]
Composition of Additive Monoid Homomorphisms on Dependent Functions with Finite Support
Informal description
Given two families of additive monoid homomorphisms $f_i \colon \beta_1 i \to \beta_2 i$ and $f_{2,i} \colon \beta i \to \beta_1 i$ for each index $i$, the composition of the induced additive monoid homomorphisms on dependent functions with finite support satisfies: \[ \operatorname{mapRange.addMonoidHom} (f \circ f_2) = \operatorname{mapRange.addMonoidHom} f \circ \operatorname{mapRange.addMonoidHom} f_2 \] where $f \circ f_2$ denotes the pointwise composition $(f \circ f_2)_i = f_i \circ f_{2,i}$.
DFinsupp.mapRange.addEquiv definition
(e : ∀ i, β₁ i ≃+ β₂ i) : (Π₀ i, β₁ i) ≃+ Π₀ i, β₂ i
Full source
/-- `DFinsupp.mapRange.addMonoidHom` as an `AddEquiv`. -/
@[simps apply]
def mapRange.addEquiv (e : ∀ i, β₁ i ≃+ β₂ i) : (Π₀ i, β₁ i) ≃+ Π₀ i, β₂ i :=
  { mapRange.addMonoidHom fun i =>
      (e i).toAddMonoidHom with
    toFun := mapRange (fun i x => e i x) fun i => (e i).map_zero
    invFun := mapRange (fun i x => (e i).symm x) fun i => (e i).symm.map_zero
    left_inv := fun x => by
      rw [← mapRange_comp] <;>
        · simp_rw [AddEquiv.symm_comp_self]
          simp
    right_inv := fun x => by
      rw [← mapRange_comp] <;>
        · simp_rw [AddEquiv.self_comp_symm]
          simp }
Additive equivalence of dependent functions with finite support via pointwise mapping
Informal description
Given a family of additive equivalences \( e_i \colon \beta_1 i \simeq \beta_2 i \) for each index \( i \), the function `DFinsupp.mapRange.addEquiv` constructs an additive equivalence between the types of dependent functions with finite support \( \Pi_{i} \beta_1 i \) and \( \Pi_{i} \beta_2 i \). This equivalence applies each \( e_i \) pointwise to the corresponding value of the input function, preserves the zero function, and respects addition. The inverse function is constructed similarly using the inverses of the \( e_i \).
DFinsupp.mapRange.addEquiv_refl theorem
: (mapRange.addEquiv fun i => AddEquiv.refl (β₁ i)) = AddEquiv.refl _
Full source
@[simp]
theorem mapRange.addEquiv_refl :
    (mapRange.addEquiv fun i => AddEquiv.refl (β₁ i)) = AddEquiv.refl _ :=
  AddEquiv.ext mapRange_id
Identity Additive Equivalence for Pointwise Mapping of Dependent Functions
Informal description
The additive equivalence obtained by applying the identity additive equivalence pointwise to each component of a dependent function with finite support is equal to the identity additive equivalence on the space of such functions. That is, for any family of types $\beta_1 i$ with additive zero class structures, we have: \[ \operatorname{mapRange.addEquiv} (\lambda i, \operatorname{AddEquiv.refl} (\beta_1 i)) = \operatorname{AddEquiv.refl} (\Pi₀ i, \beta_1 i) \]
DFinsupp.mapRange.addEquiv_trans theorem
(f : ∀ i, β i ≃+ β₁ i) (f₂ : ∀ i, β₁ i ≃+ β₂ i) : (mapRange.addEquiv fun i => (f i).trans (f₂ i)) = (mapRange.addEquiv f).trans (mapRange.addEquiv f₂)
Full source
theorem mapRange.addEquiv_trans (f : ∀ i, β i ≃+ β₁ i) (f₂ : ∀ i, β₁ i ≃+ β₂ i) :
    (mapRange.addEquiv fun i => (f i).trans (f₂ i)) =
      (mapRange.addEquiv f).trans (mapRange.addEquiv f₂) := by
  refine AddEquiv.ext <| mapRange_comp (fun i x => f₂ i x) (fun i x => f i x) ?_ ?_ ?_
  · intros; apply map_zero
  · intros; apply map_zero
  · intros; dsimp; simp only [map_zero]
Transitivity of Additive Equivalence for Dependent Functions with Finite Support
Informal description
Let $\beta$, $\beta_1$, and $\beta_2$ be families of types indexed by $\iota$, each equipped with an additive structure. Given families of additive equivalences $f_i \colon \beta i \simeq \beta_1 i$ and $f_{2,i} \colon \beta_1 i \simeq \beta_2 i$ for each $i \in \iota$, the composition of the induced additive equivalences on dependent functions with finite support satisfies: \[ \operatorname{mapRange.addEquiv} (f \circ f_2) = \operatorname{mapRange.addEquiv} f \circ \operatorname{mapRange.addEquiv} f_2 \] where $f \circ f_2$ denotes the pointwise composition $(f \circ f_2)_i = f_i \circ f_{2,i}$.
DFinsupp.mapRange.addEquiv_symm theorem
(e : ∀ i, β₁ i ≃+ β₂ i) : (mapRange.addEquiv e).symm = mapRange.addEquiv fun i => (e i).symm
Full source
@[simp]
theorem mapRange.addEquiv_symm (e : ∀ i, β₁ i ≃+ β₂ i) :
    (mapRange.addEquiv e).symm = mapRange.addEquiv fun i => (e i).symm :=
  rfl
Inverse of Pointwise Additive Equivalence of Dependent Functions with Finite Support
Informal description
Given a family of additive equivalences \( e_i \colon \beta_1 i \simeq \beta_2 i \) for each index \( i \), the inverse of the additive equivalence between dependent functions with finite support \( \Pi_{i} \beta_1 i \) and \( \Pi_{i} \beta_2 i \) (constructed via pointwise application of \( e_i \)) is equal to the additive equivalence constructed via pointwise application of the inverses \( e_i^{-1} \).