Typeclasses for FunLike and algebraic operations #
In this file we provide typeclasses for the compatibility of algebraic structures and FunLike
instances.
These instances encode the property that algebraic operations such as addition, subtraction, and
negation are given by the pointwise operations, and moreover we provide classes for 1 acting as
the identity and multiplication acting as composition.
The algebraic FunLike typeclasses provide a simp lemma of the form add_apply and a norm_cast
lemma coe_add. See note [IsApply classes] for how these classes are intended to be used.
The following pointwise Is*Apply typeclasses are available:
IsZeroApply,IsOneApply:0 x = 0and1 x = 1, respectivelyIsAddApply,IsMulApply:(f + g) x = f x + g xand(f * g) x = f x * g x, respectivelyIsSubApply,IsDivApply:(f - g) x = f x - g xand(f / g) x = f x / g x, respectivelyIsNegApply,IsInvApply:(-f) x = -(f x)and(f⁻¹) x = (f x)⁻¹, respectivelyIsVAddApply,IsSMulApplyIsPowApply:(n +ᵥ f) x = n +ᵥ f x,(n • f) x = n • f x, and(f ^ n) x = (f x) ^ n, respectivelyIsNatCastApply,IsIntCastApply:(n : F) x = nforn : ℕandn : ℤ, respectively
We allow the above even for dependent function-like types DFunLike F α β.
But for endomorphism-like objects, we allow only FunLike F α α, and we have the addition classes:
IsOneApplyEqSelf:1 x = xIsMulApplyEqComp:(f * g) x = f (g x)IsNatCastApplyEqSMul,IsIntCastApplyEqSMul:(n : F) x = n • xforn : ℕandn : ℤ, respectively
For every type that declares a FunLike instance and an Add instance, there should be generally
an IsAddApply instance with the proof usually being solved automatically using rfl.
So for instance for the continuous linear maps equipped with the uniform convergence topology,
we have the instance
instance instIsAddApply [TopologicalSpace F] [IsTopologicalAddGroup F] (𝔖 : Set (Set E)) :
IsAddApply (E →SLᵤ[σ, 𝔖] F) where
There are a few lemmas that apply to any function space as long as they have an IsAddApply
instance. Then it is now possible to define generic lemmas as follows:
section FunLike
variable {F α β : Type*} [CommMonoid β] [CommMonoid F]
[FunLike F α β] [IsOneApply F] [IsMulApply F]
open Classical in
@[to_additive (attr := simp)]
theorem prod_apply {ι : Type*} (s : Finset ι) (f : ι → F) (x : α) :
(∏ i ∈ s, f i) x = ∏ i ∈ s, f i x := by
induction s using Finset.induction_on with
| empty => simp
| insert i s his h => simp [his, h]
end FunLike
The Is*Apply classes are used to register that a type of bundled morphisms has a specified
behavior of the corresponding algebraic operation on the underlying functions. These come in two
flavors: the pointwise operations (IsZeroApply, IsAddApply, IsSMulApply, IsPowApply,
IsNatCastApply, etc.) and the endomorphism-like operations (IsOneApplyEqSelf,
IsMulApplyEqComp, IsNatCastApplyEqSMul and IsIntCastApplyEqSMul) where 1 is the identity
and * is composition. For example, ContinuousMap is equipped with instances of all the pointwise
variants, while LinearMap is equipped with pointwise operations for addition and subtraction,
but with endomorphism-like operations for multiplication.
These instances give access to generic lemmas for morphisms applied to elements of the domain,
such as add_apply, smul_apply, pow_apply (tagged with simp, grind =), as well as their
unapplied variants FunLike.coe_add, FunLike.coe_smul, etc. (tagged with simp, norm_cast).
This obviates the need for type-specific lemmas like ContinuousMap.add_apply or
LinearMap.coe_add. Pre-existing type-specific lemmas should be deprecated (and protected) in
favor of the generic ones.
In addition to generic simp lemmas, the Is*Apply classes also provide means to transfer
algebraic structures from bare functions to bundled morphisms via the coercion to functions.
These are simply applications of Function.Injective.addCommMonoid (or similar) to the coercion
to function DFunLike.coe (using DFunLike.coe_injective). These are registered in the FunLike
namespace as FunLike.addCommMonoid.
Finally, various bundlings of DFunLike.coe into bundled morphisms are provided for classes
possessing the relevant Is*Apply instances, such as FunLike.coeAddMonoidHom. These are
type-agnostic, and can be used generically.
Equations
Instances For
Alias of IsZeroApply.zero_apply.
Alias of IsOneApplyEqSelf.one_apply_eq_self.
Alias of IsMulApplyEqComp.mul_apply_eq_comp.
Alias of IsVAddApply.vadd_apply.
Alias of IsNatCastApply.natCast_apply_eq_const.
Alias of IsIntCastApply.intCast_apply_eq_const.
Alias of FunLike.coe_smul.