Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/Mathlib/Algebra/Group/     Datei vom 15.10.2026 mit Größe 10 kB image not shown  

Quelle  IsApply.lean   Sprache: Lean

 

/-
Copyright (c) 2026 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/

module

public import Mathlib.Algebra.Notation.Pi.Defs
public import Mathlib.Basic.FunLike.Basic
public import Mathlib.Data.Int.Cast.Pi
public import Mathlib.Data.Nat.Cast.Pi
public import Mathlib.Logic.Function.Iterate

/-! # 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`.

The following pointwise `Is*Apply` typeclasses are available:
* `IsZeroApply`, `IsOneApply`: `0 x = 0` and `1 x = 1`, respectively
* `IsAddApply`, `IsMulApply`: `(f + g) x = f x + g x` and `(f * g) x = f x * g x`, respectively
* `IsSubApply`, `IsDivApply`: `(f - g) x = f x - g x` and `(f / g) x = f x / g x`, respectively
* `IsNegApply`, `IsInvApply`: `(-f) x = -(f x)` and `(f⁻¹) x = (f x)⁻¹`, respectively
* `IsVAddApply`, `IsSMulApply` `IsPowApply`: `(n +ᵥ f) x = n +ᵥ f x`, `(n • f) x = n • f x`, and
  `(f ^ n) x = (f x) ^ n`, respectively
* `IsNatCastApply`, `IsIntCastApply`: `(n : F) x = n` for `n : ℕ` and `n : ℤ`, respectively

For endomorphism-like objects, we have additionally:
* `IsOneApplyEqSelf`: `1 x = x`
* `IsMulApplyEqComp`: `(f * g) x = f (g x)`
* `IsNatCastApplyEqSMul`, `IsIntCastApplyEqSMul`: `(n : F) x = n • x` for `n : ℕ` and `n : ℤ`,
  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
```
-/



public section

assert_not_exists Monoid

section Def

section Zero

/-- `IsZeroApply F` states for all `x : α`, `(0 : F) x = 0`. -/
class IsZeroApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [Zero β] [Zero F] where
  zero_apply (x : α) : (0 : F) x = 0 := by intros; rfl

/-- `IsOneApply F` states for all `x : α`, `(1 : F) x = 1`. -/
@[to_additive]
class IsOneApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [One β] [One F] where
  one_apply (x : α) : (1 : F) x = 1 := by intros; rfl

@[to_additive (attr := simp, grind =)] alias one_apply := IsOneApply.one_apply

/-- `IsOneApplyEqSelf F` states for all `x : α`, `(1 : F) x = x`. -/
class IsOneApplyEqSelf (F : Type*) {α : outParam Type*} [FunLike F α α] [One F] where
  one_apply_eq_self (x : α) : (1 : F) x = x := by intros; rfl

@[simp, grind =]
alias one_apply_eq_self := IsOneApplyEqSelf.one_apply_eq_self

end Zero

section Add

/-- `IsAddApply F` states for all `f g : F` and `x : α`, `(f + g) x = f x + g x`. -/
class IsAddApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [Add β] [Add F] where
  add_apply (f g : F) (x : α) : (f + g) x = f x + g x := by intros; rfl

/-- `IsMulApply F` states for all `f g : F` and `x : α`, `(f * g) x = f x * g x`. -/
@[to_additive]
class IsMulApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [Mul β] [Mul F] where
  mul_apply (f g : F) (x : α) : (f * g) x = f x * g x := by intros; rfl

@[to_additive (attr := simp, grind =)] alias mul_apply := IsMulApply.mul_apply

/-- `IsMulApplyEqComp F` states for all `x : α`, `(f * g) x = f (g x)`. -/
class IsMulApplyEqComp (F : Type*) {α : outParam Type*} [FunLike F α α] [Mul F] where
  mul_apply_eq_comp (f g : F) (x : α) : (f * g) x = f (g x) := by intros; rfl

@[simp, grind =]
alias mul_apply_eq_comp := IsMulApplyEqComp.mul_apply_eq_comp

end Add

section Sub

/-- `IsSubApply F` states for all `f g : F` and `x : α`, `(f - g) x = f x - g x`. -/
class IsSubApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [Sub β] [Sub F] where
  sub_apply (f g : F) (x : α) : (f - g) x = f x - g x := by intros; rfl

/-- `IsDivApply F` states for all `f g : F` and `x : α`, `(f / g) x = f x / g x`. -/
@[to_additive]
class IsDivApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [Div β] [Div F] where
  div_apply (f g : F) (x : α) : (f / g) x = f x / g x := by intros; rfl

@[to_additive (attr := simp, grind =)] alias div_apply := IsDivApply.div_apply

end Sub

section Neg

/-- `IsNegApply F` states for all `f : F` and `x : α`, `(-f) x = -f x`. -/
class IsNegApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [Neg β] [Neg F] where
  neg_apply (f : F) (x : α) : (-f) x = -f x := by intros; rfl

/-- `IsInvApply F` states for all `f : F` and `x : α`, `f⁻¹ x = (f x)⁻¹`. -/
@[to_additive]
class IsInvApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [Inv β] [Inv F] where
  inv_apply (f : F) (x : α) : f⁻¹ x = (f x)⁻¹ := by intros; rfl

@[to_additive (attr := simp, grind =)] alias inv_apply := IsInvApply.inv_apply

end Neg

section SMul

/-- `IsVAddApply M F` states for all `f : F`, `n : M` and `x : α`, `(n +ᵥ f) x = n +ᵥ f x`. -/
class IsVAddApply (M F : Type*) {α β : outParam Type*} [FunLike F α β] [VAdd M β] [VAdd M F] where
  vadd_apply (f : F) (n : M) (x : α) : (n +ᵥ f) x = n +ᵥ f x := by intros; rfl

/-- `IsSMulApply M F` states for all `f : F`, `n : M` and `x : α`, `(n • f) x = n • f x`. -/
@[to_additive]
class IsSMulApply (M F : Type*) {α β : outParam Type*} [FunLike F α β] [SMul M β] [SMul M F] where
  smul_apply (f : F) (r : M) (x : α) : (r • f) x = r • f x := by intros; rfl

/-- `IsPowApply M F` states for all `f : F`, `n : M` and `x : α`, `(f ^ n) x = (f x) ^ n`. -/
@[to_additive IsSMulApply]
class IsPowApply (M F : Type*) {α β : outParam Type*} [FunLike F α β] [Pow β M] [Pow F M] where
  pow_apply (f : F) (n : M) (x : α) : (f ^ n) x = (f x) ^ n := by intros; rfl

@[to_additive (attr := simp, grind =, to_additive) smul_apply]
alias pow_apply := IsPowApply.pow_apply

end SMul

section Cast

/-- `IsNatCastApply F` states for all `n : ℕ` and `x : α`, `(n : F) x = n`. -/
class IsNatCastApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [NatCast F]
    [NatCast β] where
  natCast_apply_eq_const (n : Nat) (x : α) : (n : F) x = n := by intros; rfl

@[simp, grind =]
alias natCast_apply_eq_const := IsNatCastApply.natCast_apply_eq_const

/-- `IsIntCastApply F` states for all `n : ℤ` and `x : α`, `(n : F) x = n`. -/
class IsIntCastApply (F : Type*) {α β : outParam Type*} [FunLike F α β] [IntCast F]
    [IntCast β] where
  intCast_apply_eq_const (n : Int) (x : α) : (n : F) x = n := by intros; rfl

@[simp, grind =]
alias intCast_apply_eq_const := IsIntCastApply.intCast_apply_eq_const

/-- `IsNatCastApplyEqSMul F` states for all `n : ℕ` and `x : α`, `(n : F) x = n • x`. -/
class IsNatCastApplyEqSMul (F : Type*) {α : outParam Type*} [FunLike F α α] [NatCast F]
    [SMul Nat α] where
  natCast_apply_eq_smul (n : Nat) (x : α) : (n : F) x = n • x := by intros; rfl

@[simp, grind =]
alias natCast_apply_eq_smul := IsNatCastApplyEqSMul.natCast_apply_eq_smul

/-- `IsIntCastApplyEqSMul F` states for all `n : ℤ` and `x : α`, `(n : F) x = n • x`. -/
class IsIntCastApplyEqSMul (F : Type*) {α : outParam Type*} [FunLike F α α] [IntCast F]
    [SMul Int α] where
  intCast_apply_eq_smul (n : Int) (x : α) : (n : F) x = n • x := by intros; rfl

@[simp, grind =]
alias intCast_apply_eq_smul := IsIntCastApplyEqSMul.intCast_apply_eq_smul

end Cast

end Def

namespace FunLike

variable {M F F' α β : Type*} [FunLike F α β] [FunLike F' α α]

section Coercion

@[to_additive (attr := simp, norm_cast)]
theorem coe_one [One F] [One β] [IsOneApply F] : ↑(1 : F) = (1 : α → β) := by ext; simp

@[to_additive (attr := simp, norm_cast)]
theorem coe_one_iff [One F] [One β] [IsOneApply F] {f : F} : (f : α → β) = 1 ↔ f = 1 := by
  constructor
  · intro h
    simp [DFunLike.ext_iff, h]
  · intro h
    simp [h]

@[to_additive (attr := simp, norm_cast)]
theorem coe_mul [Mul F] [Mul β] [IsMulApply F] (f g : F) : ↑(f * g) = (f : α → β) * g := by
  ext; simp

@[to_additive (attr := simp, norm_cast)]
theorem coe_div [Div F] [Div β] [IsDivApply F] (f g : F) : ↑(f / g) = (f : α → β) / g := by
  ext; simp

@[to_additive (attr := simp, norm_cast)]
theorem coe_inv [Inv F] [Inv β] [IsInvApply F] (f : F) : ↑(f⁻¹) = (f : α → β)⁻¹ := by
  ext; simp

@[to_additive (attr := simp, norm_cast, to_additive) (reorder := f n) coe_smul]
theorem coe_pow [Pow F M] [Pow β M] [IsPowApply M F] (f : F) (n : M) :
    ↑(f ^ n) = (f : α → β) ^ n := by
  ext; simp

@[deprecated (since := "2026-07-23")] alias coe_smul' := coe_smul

@[simp, norm_cast]
theorem coe_one_eq_id [One F'] [IsOneApplyEqSelf F'] : ↑(1 : F') = id := by
  ext; simp

@[simp, norm_cast]
theorem coe_one_eq_id_iff [One F'] [IsOneApplyEqSelf F'] (f : F') : (f : α → α) = id ↔ f = 1 := by
  constructor
  · intro h
    simp [DFunLike.ext_iff, h]
  · intro h
    simp [h]

@[simp, norm_cast]
theorem coe_mul_eq_comp [Mul F'] [IsMulApplyEqComp F'] (f g : F') : ↑(f * g) = f ∘ g := by
  ext; simp

-- this lemma cannot be `simp` since this creates loops
@[norm_cast]
theorem coe_natCast [NatCast F] [NatCast β] [IsNatCastApply F] (n : Nat) :
  ((n : F) : α → β) = n := by
  funext x; simp

@[norm_cast]
theorem coe_intCast [IntCast F] [IntCast β] [IsIntCastApply F] (n : Int) :
  ((n : F) : α → β) = n := by
  funext x; simp

@[norm_cast]
theorem natCast_eq_nsmul_one [NatCast F'] [One F'] [SMul Nat α] [SMul Nat F']
    [IsSMulApply Nat F'] [IsNatCastApplyEqSMul F'] [IsOneApplyEqSelf F'] (n : Nat) :
  (n : F') = n • (1 : F') := by
  apply DFunLike.ext
  simp

-- this lemma cannot be `simp` since this creates loops
@[norm_cast]
theorem intCast_eq_zsmul_one [IntCast F'] [One F'] [SMul Int α] [SMul Int F']
    [IsSMulApply Int F'] [IsIntCastApplyEqSMul F'] [IsOneApplyEqSelf F'] (n : Int) :
  (n : F') = n • (1 : F') := by
  apply DFunLike.ext
  simp

end Coercion

end FunLike

Messung
CHZG
9310010097

¤ Dauer der Verarbeitung: 0.2 Sekunden  (vorverarbeitet am  2026-11-24) ¤

*© Formatika GbR, Deutschland