Dependent functions with finite support #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
For a non-dependent version see data/finsupp.lean.
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 (λ 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 (dfinsupp.has_add) 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.sum_add_hom 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
finsupp.has_add 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.
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 a implementation detail that aids computability; see the implementation
notes in this file for more information.
Instances for dfinsupp
- dfinsupp.has_sizeof_inst
- dfinsupp.fun_like
- dfinsupp.has_coe_to_fun
- dfinsupp.has_zero
- dfinsupp.inhabited
- dfinsupp.has_add
- dfinsupp.add_zero_class
- dfinsupp.has_nat_scalar
- dfinsupp.add_monoid
- dfinsupp.add_comm_monoid
- dfinsupp.has_neg
- dfinsupp.has_sub
- dfinsupp.has_int_scalar
- dfinsupp.add_group
- dfinsupp.add_comm_group
- dfinsupp.has_smul
- dfinsupp.smul_comm_class
- dfinsupp.is_scalar_tower
- dfinsupp.is_central_scalar
- dfinsupp.distrib_mul_action
- dfinsupp.module
- dfinsupp.unique
- dfinsupp.unique_of_is_empty
- dfinsupp.has_add₂
- dfinsupp.add_zero_class₂
- dfinsupp.add_monoid₂
- dfinsupp.distrib_mul_action₂
- dfinsupp.fintype
- dfinsupp.infinite_of_left
- dfinsupp.infinite_of_right
- dfinsupp.add_comm_monoid_of_linear_map
- dfinsupp.module_of_linear_map
- module.free.dfinsupp
- module.dfinsupp.projective
- dfinsupp.has_le
- dfinsupp.preorder
- dfinsupp.partial_order
- dfinsupp.semilattice_inf
- dfinsupp.semilattice_sup
- dfinsupp.lattice
- dfinsupp.ordered_add_comm_monoid
- dfinsupp.ordered_cancel_add_comm_monoid
- dfinsupp.has_le.le.contravariant_class
- dfinsupp.order_bot
- dfinsupp.tsub
- dfinsupp.has_ordered_sub
- dfinsupp.canonically_ordered_add_monoid
- slim_check.total_function.dfinsupp.sampleable_ext
- dfinsupp.locally_finite_order
- dfinsupp.well_founded_lt'
- dfinsupp.well_founded_lt_of_finite
- dfinsupp.add_zero_class'
Helper instance for when there are too many metavariables to apply fun_like.has_coe_to_fun
directly.
Equations
Deprecated. Use fun_like.coe_injective instead.
The composition of f : β₁ → β₂ and g : Π₀ i, β₁ i is
map_range 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:
Let f i be a binary operation β₁ i → β₂ i → β i such that f i 0 0 = 0.
Then zip_with f hf is a binary operation Π₀ i, β₁ i → Π₀ i, β₂ i → Π₀ i, β i.
x.piecewise y s is the finitely supported function equal to x on the set s,
and to y on its complement.
Equations
- x.piecewise y s = dfinsupp.zip_with (λ (i : ι) (x y : β i), ite (i ∈ s) x y) _ x y
Equations
- dfinsupp.has_add = {add := dfinsupp.zip_with (λ (_x : ι), has_add.add) dfinsupp.has_add._proof_1}
Equations
- dfinsupp.add_zero_class = function.injective.add_zero_class coe_fn dfinsupp.add_zero_class._proof_1 dfinsupp.add_zero_class._proof_2 dfinsupp.add_zero_class._proof_3
Note the general dfinsupp.has_smul instance doesn't apply as ℕ is not distributive
unless β i's addition is commutative.
Equations
- dfinsupp.has_nat_scalar = {smul := λ (c : ℕ) (v : Π₀ (i : ι), β i), dfinsupp.map_range (λ (_x : ι), has_smul.smul c) _ v}
Equations
- dfinsupp.add_monoid = function.injective.add_monoid coe_fn dfinsupp.add_monoid._proof_1 dfinsupp.add_monoid._proof_2 dfinsupp.add_monoid._proof_3 dfinsupp.add_monoid._proof_4
Coercion from a dfinsupp to a pi type is an add_monoid_hom.
Equations
- dfinsupp.coe_fn_add_monoid_hom = {to_fun := coe_fn dfinsupp.has_coe_to_fun, map_zero' := _, map_add' := _}
Evaluation at a point is an add_monoid_hom. This is the finitely-supported version of
pi.eval_add_monoid_hom.
Equations
Equations
- dfinsupp.add_comm_monoid = function.injective.add_comm_monoid coe_fn dfinsupp.add_comm_monoid._proof_1 dfinsupp.add_comm_monoid._proof_2 dfinsupp.add_comm_monoid._proof_3 dfinsupp.add_comm_monoid._proof_4
Equations
- dfinsupp.has_neg = {neg := λ (f : Π₀ (i : ι), β i), dfinsupp.map_range (λ (_x : ι), has_neg.neg) dfinsupp.has_neg._proof_1 f}
Equations
- dfinsupp.has_sub = {sub := dfinsupp.zip_with (λ (_x : ι), has_sub.sub) dfinsupp.has_sub._proof_1}
Note the general dfinsupp.has_smul instance doesn't apply as ℤ is not distributive
unless β i's addition is commutative.
Equations
- dfinsupp.has_int_scalar = {smul := λ (c : ℤ) (v : Π₀ (i : ι), β i), dfinsupp.map_range (λ (_x : ι), has_smul.smul c) _ v}
Equations
- dfinsupp.add_group = function.injective.add_group coe_fn dfinsupp.add_group._proof_1 dfinsupp.add_group._proof_2 dfinsupp.add_group._proof_3 dfinsupp.add_group._proof_4 dfinsupp.add_group._proof_5 dfinsupp.add_group._proof_6 dfinsupp.add_group._proof_7
Equations
- dfinsupp.add_comm_group = function.injective.add_comm_group coe_fn dfinsupp.add_comm_group._proof_1 dfinsupp.add_comm_group._proof_2 dfinsupp.add_comm_group._proof_3 dfinsupp.add_comm_group._proof_4 dfinsupp.add_comm_group._proof_5 dfinsupp.add_comm_group._proof_6 dfinsupp.add_comm_group._proof_7
Dependent functions with finite support inherit a semiring action from an action on each coordinate.
Equations
- dfinsupp.has_smul = {smul := λ (c : γ) (v : Π₀ (i : ι), β i), dfinsupp.map_range (λ (_x : ι), has_smul.smul c) _ v}
Dependent functions with finite support inherit a distrib_mul_action structure from such a
structure on each coordinate.
Equations
- dfinsupp.distrib_mul_action = function.injective.distrib_mul_action dfinsupp.coe_fn_add_monoid_hom dfinsupp.distrib_mul_action._proof_1 dfinsupp.distrib_mul_action._proof_2
Dependent functions with finite support inherit a module structure from such a structure on each coordinate.
Equations
- dfinsupp.module = {to_distrib_mul_action := {to_mul_action := distrib_mul_action.to_mul_action dfinsupp.distrib_mul_action, smul_zero := _, smul_add := _}, add_smul := _, zero_smul := _}
dfinsupp.filter as an add_monoid_hom.
Equations
- dfinsupp.filter_add_monoid_hom β p = {to_fun := dfinsupp.filter p (λ (a : ι), _inst_2 a), map_zero' := _, map_add' := _}
dfinsupp.filter as a linear_map.
Equations
- dfinsupp.filter_linear_map γ β p = {to_fun := dfinsupp.filter p (λ (a : ι), _inst_4 a), map_add' := _, map_smul' := _}
subtype_domain p f is the restriction of the finitely supported function
f to the subtype p.
subtype_domain but as an add_monoid_hom.
Equations
- dfinsupp.subtype_domain_add_monoid_hom β p = {to_fun := dfinsupp.subtype_domain p (λ (a : ι), _inst_2 a), map_zero' := _, map_add' := _}
dfinsupp.subtype_domain as a linear_map.
Equations
- dfinsupp.subtype_domain_linear_map γ β p = {to_fun := dfinsupp.subtype_domain p (λ (a : ι), _inst_4 a), map_add' := _, map_smul' := _}
Equations
- dfinsupp.unique = dfinsupp.unique._proof_2.unique
The function single i b : Π₀ i, β i sends i to b
and all other points to 0.
Like finsupp.single_eq_single_iff, but with a heq due to dependent types
dfinsupp.single a b is injective in a. For the statement that it is injective in b, see
dfinsupp.single_injective
Equality of sigma types is sufficient (but not necessary) to show equality of dfinsupps.
Redefine f i to be 0.
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.
dfinsupp.single as an add_monoid_hom.
Equations
- dfinsupp.single_add_hom β i = {to_fun := dfinsupp.single i, map_zero' := _, map_add' := _}
dfinsupp.erase as an add_monoid_hom.
Equations
- dfinsupp.erase_add_hom β i = {to_fun := dfinsupp.erase i, map_zero' := _, map_add' := _}
If two additive homomorphisms from Π₀ i, β i are equal on each single a b, then
they are equal.
If two additive homomorphisms from Π₀ i, β i are equal on each single a b, then
they are equal.
If s is a subset of ι then mk_add_group_hom s is the canonical additive
group homomorphism from $\prod_{i\in s}\beta_i$ to $\prod_{\mathtt{i : \iota}}\beta_i.$
Equations
- dfinsupp.mk_add_group_hom s = {to_fun := dfinsupp.mk s, map_zero' := _, map_add' := _}
Equations
- dfinsupp.decidable_zero = λ (f : Π₀ (i : ι), β i), decidable_of_iff (f.support = ∅) _
Reindexing (and possibly removing) terms of a dfinsupp.
Reindexing terms of a dfinsupp.
This is the dfinsupp version of equiv.Pi_congr_left'.
Equations
- dfinsupp.equiv_congr_left h = {to_fun := dfinsupp.comap_domain' ⇑(h.symm) _, inv_fun := λ (f : Π₀ (k : κ), β (⇑(h.symm) k)), dfinsupp.map_range (λ (i : ι), ⇑(equiv.cast _)) _ (dfinsupp.comap_domain' ⇑h _ f), left_inv := _, right_inv := _}
Equations
Equations
Equations
The natural map between Π₀ i (j : α i), δ i j and Π₀ (i : Σ i, α i), δ i.1 i.2, inverse of
curry.
The natural bijection between Π₀ (i : Σ i, α i), δ i.1 i.2 and Π₀ i (j : α i), δ i j.
This is the dfinsupp version of equiv.Pi_curry.
Equations
- dfinsupp.sigma_curry_equiv = {to_fun := dfinsupp.sigma_curry _inst_1, inv_fun := dfinsupp.sigma_uncurry (λ (i : ι) (j : α i) (x : δ i j), _inst_3 i j x), left_inv := _, right_inv := _}
Adds a term to a dfinsupp, making a dfinsupp indexed by an option.
This is the dfinsupp version of option.rec.
Equations
- dfinsupp.extend_with a f = {to_fun := option.rec a ⇑f, support' := trunc.map (λ (s : {s // ∀ (i : ι), i ∈ s ∨ f.to_fun i = 0}), ⟨option.none ::ₘ multiset.map option.some ↑s, _⟩) f.support'}
Bijection obtained by separating the term of index none of a dfinsupp over option ι.
This is the dfinsupp version of equiv.pi_option_equiv_prod.
Equations
- dfinsupp.equiv_prod_dfinsupp = {to_fun := λ (f : Π₀ (i : option ι), α i), (⇑f option.none, dfinsupp.comap_domain option.some _ f), inv_fun := λ (f : α option.none × Π₀ (i : ι), α (option.some i)), dfinsupp.extend_with f.fst f.snd, left_inv := _, right_inv := _}
When summing over an add_monoid_hom, the decidability assumption is not needed, and the result is
also an add_monoid_hom.
While we didn't need decidable instances to define it, we do to reduce it to a sum
The supremum of a family of commutative additive submonoids is equal to the range of
dfinsupp.sum_add_hom; that is, every element in the supr can be produced from taking a finite
number of non-zero elements of S i, coercing them to γ, and summing them.
The bounded supremum of a family of commutative additive submonoids is equal to the range of
dfinsupp.sum_add_hom composed with dfinsupp.filter_add_monoid_hom; that is, every element in the
bounded supr can be produced from taking a finite number of non-zero elements from the S i that
satisfy p i, coercing them to γ, and summing them.
A variant of add_submonoid.mem_supr_iff_exists_dfinsupp with the RHS fully unfolded.
The dfinsupp version of finsupp.lift_add_hom,
Equations
- dfinsupp.lift_add_hom = {to_fun := dfinsupp.sum_add_hom _inst_2, inv_fun := λ (F : (Π₀ (i : ι), β i) →+ γ) (i : ι), F.comp (dfinsupp.single_add_hom β i), left_inv := _, right_inv := _, map_add' := _}
The dfinsupp version of finsupp.lift_add_hom_single_add_hom,
The dfinsupp version of finsupp.lift_add_hom_apply_single,
The dfinsupp version of finsupp.lift_add_hom_comp_single,
The dfinsupp version of finsupp.comp_lift_add_hom,
Bundled versions of dfinsupp.map_range #
The names should match the equivalent bundled finsupp.map_range definitions.
dfinsupp.map_range as an add_monoid_hom.
Equations
- dfinsupp.map_range.add_monoid_hom f = {to_fun := dfinsupp.map_range (λ (i : ι) (x : β₁ i), ⇑(f i) x) _, map_zero' := _, map_add' := _}
dfinsupp.map_range.add_monoid_hom as an add_equiv.
Equations
- dfinsupp.map_range.add_equiv e = {to_fun := dfinsupp.map_range (λ (i : ι) (x : β₁ i), ⇑(e i) x) _, inv_fun := dfinsupp.map_range (λ (i : ι) (x : β₂ i), ⇑((e i).symm) x) _, left_inv := _, right_inv := _, map_add' := _}
Product and sum lemmas for bundled morphisms. #
In this section, we provide analogues of add_monoid_hom.map_sum, add_monoid_hom.coe_finset_sum,
and add_monoid_hom.finset_sum_apply for dfinsupp.sum and dfinsupp.sum_add_hom instead of
finset.sum.
We provide these for add_monoid_hom, monoid_hom, ring_hom, add_equiv, and mul_equiv.
Lemmas for linear_map and linear_equiv are in another file.
The above lemmas, repeated for dfinsupp.sum_add_hom.
Equations
- dfinsupp.fintype = fintype.of_equiv (Π (i : ι), π i) dfinsupp.equiv_fun_on_fintype.symm