Documentation

Mathlib.Algebra.Group.IsApply

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:

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:

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
    class IsZeroApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [(a : α) → Zero (β a)] [Zero F] :

    IsZeroApply F states for all x : α, (0 : F) x = 0.

    • zero_apply (x : α) : 0 x = 0
    Instances
      class IsOneApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [(a : α) → One (β a)] [One F] :

      IsOneApply F states for all x : α, (1 : F) x = 1.

      • one_apply (x : α) : 1 x = 1
      Instances
        @[simp]
        theorem one_apply {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → One (β a)} {inst✝² : One F} [self : IsOneApply F] (x : α) :
        1 x = 1

        Alias of IsOneApply.one_apply.

        @[simp]
        theorem zero_apply {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → Zero (β a)} {inst✝² : Zero F} [self : IsZeroApply F] (x : α) :
        0 x = 0

        Alias of IsZeroApply.zero_apply.

        class IsOneApplyEqSelf (F : Type u_1) {α : outParam (Type u_2)} [FunLike F α α] [One F] :

        IsOneApplyEqSelf F states for all x : α, (1 : F) x = x.

        • one_apply_eq_self (x : α) : 1 x = x
        Instances
          @[simp]
          theorem one_apply_eq_self {F : Type u_1} {α : outParam (Type u_2)} {inst✝ : FunLike F α α} {inst✝¹ : One F} [self : IsOneApplyEqSelf F] (x : α) :
          1 x = x

          Alias of IsOneApplyEqSelf.one_apply_eq_self.

          class IsAddApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [(a : α) → Add (β a)] [Add F] :

          IsAddApply F states for all f g : F and x : α, (f + g) x = f x + g x.

          • add_apply (f g : F) (x : α) : (f + g) x = f x + g x
          Instances
            class IsMulApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [(a : α) → Mul (β a)] [Mul F] :

            IsMulApply F states for all f g : F and x : α, (f * g) x = f x * g x.

            • mul_apply (f g : F) (x : α) : (f * g) x = f x * g x
            Instances
              @[simp]
              theorem mul_apply {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → Mul (β a)} {inst✝² : Mul F} [self : IsMulApply F] (f g : F) (x : α) :
              (f * g) x = f x * g x

              Alias of IsMulApply.mul_apply.

              @[simp]
              theorem add_apply {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → Add (β a)} {inst✝² : Add F} [self : IsAddApply F] (f g : F) (x : α) :
              (f + g) x = f x + g x

              Alias of IsAddApply.add_apply.

              class IsMulApplyEqComp (F : Type u_1) {α : outParam (Type u_2)} [FunLike F α α] [Mul F] :

              IsMulApplyEqComp F states for all x : α, (f * g) x = f (g x).

              • mul_apply_eq_comp (f g : F) (x : α) : (f * g) x = f (g x)
              Instances
                @[simp]
                theorem mul_apply_eq_comp {F : Type u_1} {α : outParam (Type u_2)} {inst✝ : FunLike F α α} {inst✝¹ : Mul F} [self : IsMulApplyEqComp F] (f g : F) (x : α) :
                (f * g) x = f (g x)

                Alias of IsMulApplyEqComp.mul_apply_eq_comp.

                class IsSubApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [(a : α) → Sub (β a)] [Sub F] :

                IsSubApply F states for all f g : F and x : α, (f - g) x = f x - g x.

                • sub_apply (f g : F) (x : α) : (f - g) x = f x - g x
                Instances
                  class IsDivApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [(a : α) → Div (β a)] [Div F] :

                  IsDivApply F states for all f g : F and x : α, (f / g) x = f x / g x.

                  • div_apply (f g : F) (x : α) : (f / g) x = f x / g x
                  Instances
                    @[simp]
                    theorem div_apply {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → Div (β a)} {inst✝² : Div F} [self : IsDivApply F] (f g : F) (x : α) :
                    (f / g) x = f x / g x

                    Alias of IsDivApply.div_apply.

                    @[simp]
                    theorem sub_apply {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → Sub (β a)} {inst✝² : Sub F} [self : IsSubApply F] (f g : F) (x : α) :
                    (f - g) x = f x - g x

                    Alias of IsSubApply.sub_apply.

                    class IsNegApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [(a : α) → Neg (β a)] [Neg F] :

                    IsNegApply F states for all f : F and x : α, (-f) x = -f x.

                    • neg_apply (f : F) (x : α) : (-f) x = -f x
                    Instances
                      class IsInvApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [(a : α) → Inv (β a)] [Inv F] :

                      IsInvApply F states for all f : F and x : α, f⁻¹ x = (f x)⁻¹.

                      Instances
                        @[simp]
                        theorem inv_apply {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → Inv (β a)} {inst✝² : Inv F} [self : IsInvApply F] (f : F) (x : α) :
                        f⁻¹ x = (f x)⁻¹

                        Alias of IsInvApply.inv_apply.

                        @[simp]
                        theorem neg_apply {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → Neg (β a)} {inst✝² : Neg F} [self : IsNegApply F] (f : F) (x : α) :
                        (-f) x = -f x

                        Alias of IsNegApply.neg_apply.

                        class IsVAddApply (M : Type u_1) (F : Type u_2) {α : outParam (Type u_3)} {β : outParam (α → Type u_4)} [DFunLike F α β] [(a : α) → VAdd M (β a)] [VAdd M F] :

                        IsVAddApply M F states for all f : F, n : M and x : α, (n +ᵥ f) x = n +ᵥ f x.

                        • vadd_apply (f : F) (n : M) (x : α) : (n +ᵥ f) x = n +ᵥ f x
                        Instances
                          class IsSMulApply (M : Type u_1) (F : Type u_2) {α : outParam (Type u_3)} {β : outParam (α → Type u_4)} [DFunLike F α β] [(a : α) → SMul M (β a)] [SMul M F] :

                          IsSMulApply M F states for all f : F, n : M and x : α, (n • f) x = n • f x.

                          • smul_apply (f : F) (r : M) (x : α) : (r • f) x = r • f x
                          Instances
                            class IsPowApply (M : Type u_1) (F : Type u_2) {α : outParam (Type u_3)} {β : outParam (α → Type u_4)} [DFunLike F α β] [(a : α) → Pow (β a) M] [Pow F M] :

                            IsPowApply M F states for all f : F, n : M and x : α, (f ^ n) x = (f x) ^ n.

                            • pow_apply (f : F) (n : M) (x : α) : (f ^ n) x = f x ^ n
                            Instances
                              @[simp]
                              theorem pow_apply {M : Type u_1} {F : Type u_2} {α : outParam (Type u_3)} {β : outParam (α → Type u_4)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → Pow (β a) M} {inst✝² : Pow F M} [self : IsPowApply M F] (f : F) (n : M) (x : α) :
                              (f ^ n) x = f x ^ n

                              Alias of IsPowApply.pow_apply.

                              @[simp]
                              theorem vadd_apply {M : Type u_1} {F : Type u_2} {α : outParam (Type u_3)} {β : outParam (α → Type u_4)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → VAdd M (β a)} {inst✝² : VAdd M F} [self : IsVAddApply M F] (f : F) (n : M) (x : α) :
                              (n +ᵥ f) x = n +ᵥ f x

                              Alias of IsVAddApply.vadd_apply.

                              @[simp]
                              theorem smul_apply {M : Type u_1} {F : Type u_2} {α : outParam (Type u_3)} {β : outParam (α → Type u_4)} {inst✝ : DFunLike F α β} {inst✝¹ : (a : α) → SMul M (β a)} {inst✝² : SMul M F} [self : IsSMulApply M F] (f : F) (n : M) (x : α) :
                              (n • f) x = n • f x

                              Alias of IsSMulApply.smul_apply.

                              class IsNatCastApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [NatCast F] [(a : α) → NatCast (β a)] :

                              IsNatCastApply F states for all n : ℕ and x : α, (n : F) x = n.

                              • natCast_apply_eq_const (n : ℕ) (x : α) : ↑n x = ↑n
                              Instances
                                @[simp]
                                theorem natCast_apply_eq_const {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : NatCast F} {inst✝² : (a : α) → NatCast (β a)} [self : IsNatCastApply F] (n : ℕ) (x : α) :
                                ↑n x = ↑n

                                Alias of IsNatCastApply.natCast_apply_eq_const.

                                class IsIntCastApply (F : Type u_1) {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} [DFunLike F α β] [IntCast F] [(a : α) → IntCast (β a)] :

                                IsIntCastApply F states for all n : ℤ and x : α, (n : F) x = n.

                                • intCast_apply_eq_const (n : ℤ) (x : α) : ↑n x = ↑n
                                Instances
                                  @[simp]
                                  theorem intCast_apply_eq_const {F : Type u_1} {α : outParam (Type u_2)} {β : outParam (α → Type u_3)} {inst✝ : DFunLike F α β} {inst✝¹ : IntCast F} {inst✝² : (a : α) → IntCast (β a)} [self : IsIntCastApply F] (n : ℤ) (x : α) :
                                  ↑n x = ↑n

                                  Alias of IsIntCastApply.intCast_apply_eq_const.

                                  class IsNatCastApplyEqSMul (F : Type u_1) {α : outParam (Type u_2)} [FunLike F α α] [NatCast F] [SMul ℕ α] :

                                  IsNatCastApplyEqSMul F states for all n : ℕ and x : α, (n : F) x = n • x.

                                  • natCast_apply_eq_smul (n : ℕ) (x : α) : ↑n x = n • x
                                  Instances
                                    @[simp]
                                    theorem natCast_apply_eq_smul {F : Type u_1} {α : outParam (Type u_2)} {inst✝ : FunLike F α α} {inst✝¹ : NatCast F} {inst✝² : SMul ℕ α} [self : IsNatCastApplyEqSMul F] (n : ℕ) (x : α) :
                                    ↑n x = n • x

                                    Alias of IsNatCastApplyEqSMul.natCast_apply_eq_smul.

                                    class IsIntCastApplyEqSMul (F : Type u_1) {α : outParam (Type u_2)} [FunLike F α α] [IntCast F] [SMul ℤ α] :

                                    IsIntCastApplyEqSMul F states for all n : ℤ and x : α, (n : F) x = n • x.

                                    • intCast_apply_eq_smul (n : ℤ) (x : α) : ↑n x = n • x
                                    Instances
                                      @[simp]
                                      theorem intCast_apply_eq_smul {F : Type u_1} {α : outParam (Type u_2)} {inst✝ : FunLike F α α} {inst✝¹ : IntCast F} {inst✝² : SMul ℤ α} [self : IsIntCastApplyEqSMul F] (n : ℤ) (x : α) :
                                      ↑n x = n • x

                                      Alias of IsIntCastApplyEqSMul.intCast_apply_eq_smul.

                                      @[simp]
                                      theorem FunLike.coe_one {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [One F] [(a : α) → One (β a)] [IsOneApply F] :
                                      ⇑1 = 1
                                      @[simp]
                                      theorem FunLike.coe_zero {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Zero F] [(a : α) → Zero (β a)] [IsZeroApply F] :
                                      ⇑0 = 0
                                      @[simp]
                                      theorem FunLike.coe_one_iff {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [One F] [(a : α) → One (β a)] [IsOneApply F] {f : F} :
                                      ⇑f = 1 ↔ f = 1
                                      @[simp]
                                      theorem FunLike.coe_zero_iff {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Zero F] [(a : α) → Zero (β a)] [IsZeroApply F] {f : F} :
                                      ⇑f = 0 ↔ f = 0
                                      @[simp]
                                      theorem FunLike.coe_mul {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Mul F] [(a : α) → Mul (β a)] [IsMulApply F] (f g : F) :
                                      ⇑(f * g) = ⇑f * ⇑g
                                      @[simp]
                                      theorem FunLike.coe_add {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Add F] [(a : α) → Add (β a)] [IsAddApply F] (f g : F) :
                                      ⇑(f + g) = ⇑f + ⇑g
                                      @[simp]
                                      theorem FunLike.coe_div {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Div F] [(a : α) → Div (β a)] [IsDivApply F] (f g : F) :
                                      ⇑(f / g) = ⇑f / ⇑g
                                      @[simp]
                                      theorem FunLike.coe_sub {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Sub F] [(a : α) → Sub (β a)] [IsSubApply F] (f g : F) :
                                      ⇑(f - g) = ⇑f - ⇑g
                                      @[simp]
                                      theorem FunLike.coe_inv {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Inv F] [(a : α) → Inv (β a)] [IsInvApply F] (f : F) :
                                      ⇑f⁻¹ = (⇑f)⁻¹
                                      @[simp]
                                      theorem FunLike.coe_neg {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Neg F] [(a : α) → Neg (β a)] [IsNegApply F] (f : F) :
                                      ⇑(-f) = -⇑f
                                      @[simp]
                                      theorem FunLike.coe_pow {M : Type u_1} {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [Pow F M] [(a : α) → Pow (β a) M] [IsPowApply M F] (f : F) (n : M) :
                                      ⇑(f ^ n) = ⇑f ^ n
                                      @[simp]
                                      theorem FunLike.coe_vadd {M : Type u_1} {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [VAdd M F] [(a : α) → VAdd M (β a)] [IsVAddApply M F] (n : M) (f : F) :
                                      ⇑(n +ᵥ f) = n +ᵥ ⇑f
                                      @[simp]
                                      theorem FunLike.coe_smul {M : Type u_1} {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [SMul M F] [(a : α) → SMul M (β a)] [IsSMulApply M F] (n : M) (f : F) :
                                      ⇑(n • f) = n • ⇑f
                                      @[deprecated FunLike.coe_smul (since := "2026-07-23")]
                                      theorem FunLike.coe_smul' {M : Type u_1} {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [SMul M F] [(a : α) → SMul M (β a)] [IsSMulApply M F] (n : M) (f : F) :
                                      ⇑(n • f) = n • ⇑f

                                      Alias of FunLike.coe_smul.

                                      @[simp]
                                      theorem FunLike.coe_one_eq_id {F' : Type u_3} {α : Type u_4} [FunLike F' α α] [One F'] [IsOneApplyEqSelf F'] :
                                      ⇑1 = id
                                      @[simp]
                                      theorem FunLike.coe_one_eq_id_iff {F' : Type u_3} {α : Type u_4} [FunLike F' α α] [One F'] [IsOneApplyEqSelf F'] (f : F') :
                                      ⇑f = id ↔ f = 1
                                      @[simp]
                                      theorem FunLike.coe_mul_eq_comp {F' : Type u_3} {α : Type u_4} [FunLike F' α α] [Mul F'] [IsMulApplyEqComp F'] (f g : F') :
                                      ⇑(f * g) = ⇑f ∘ ⇑g
                                      theorem FunLike.coe_natCast {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [NatCast F] [(a : α) → NatCast (β a)] [IsNatCastApply F] (n : ℕ) :
                                      ⇑↑n = ↑n
                                      theorem FunLike.coe_intCast {F : Type u_2} {α : Type u_4} {β : α → Type u_5} [DFunLike F α β] [IntCast F] [(a : α) → IntCast (β a)] [IsIntCastApply F] (n : ℤ) :
                                      ⇑↑n = ↑n
                                      theorem FunLike.natCast_eq_nsmul_one {F' : Type u_3} {α : Type u_4} [FunLike F' α α] [NatCast F'] [One F'] [SMul ℕ α] [SMul ℕ F'] [IsSMulApply ℕ F'] [IsNatCastApplyEqSMul F'] [IsOneApplyEqSelf F'] (n : ℕ) :
                                      ↑n = n • 1
                                      theorem FunLike.intCast_eq_zsmul_one {F' : Type u_3} {α : Type u_4} [FunLike F' α α] [IntCast F'] [One F'] [SMul ℤ α] [SMul ℤ F'] [IsSMulApply ℤ F'] [IsIntCastApplyEqSMul F'] [IsOneApplyEqSelf F'] (n : ℤ) :
                                      ↑n = n • 1