The areas / V34. The tactics of Mathlib
Mathlib.Tactic.Simps.Basic
106 declarations. Mathlib docs · Source
Simps attribute
This file defines the @[simps] attribute, to automatically generate simp lemmas
reducing a definition when projections are applied to it.
Implementation notes
There are three attributes being defined here
@[simps]is the attribute for objects of a structure or instances of a class. It will automatically generate simplification lemmas for each projection of the object/instance that contains data. See the doc strings forLean.Parser.Attr.simpsandSimps.Configfor more details and configuration options.structureExt(just an environment extension, not actually an attribute) is automatically added to structures that have been used in@[simps]at least once. This attribute contains the data of the projections used for this structure by all following invocations of@[simps].@[notation_class]should be added to all classes that define notation, likeMulandZero. This specifies that the projections that@[simps]used are the projections from these notation classes instead of the projections of the superclasses. Example: ifMulis tagged with@[notation_class]then the projection used forSemigroupwill befun α hα ↦ @Mul.mul α (@Semigroup.toMul α hα)instead of@Semigroup.mul. [this is not correctly implemented in Lean 4 yet]
Possible Future Improvements
- If multiple declarations are generated from a
simpswithout explicit projection names, then only the first one is shown when mousing oversimps.
Changes w.r.t. Lean 3
There are some small changes in the attribute. None of them should have great effects
- The attribute will now raise an error if it tries to generate a lemma when there already exists a lemma with that name (in Lean 3 it would generate a different unique name)
transparency.nonehas been replaced byTransparencyMode.reducible- The
attrconfiguration option has been split intoisSimpandattrs(for extra attributes) - Because Lean 4 uses bundled structures, this means that
simpsapplied to anything that implements a notation class will almost certainly require a user-provided custom simps projection.
Tags
structures, projections, simp, simplifier, generates declarations
theorem Simps.ProjectionRule.add.inj E1 #
∀ {a : Lean.Name} {a_1 : Lean.Syntax} {a_2 : Lean.Name} {a_3 : Lean.Syntax},
Simps.ProjectionRule.add a a_1 = Simps.ProjectionRule.add a_2 a_3 → a = a_2 ∧ a_1 = a_3
def Simps.instInhabitedConfig.default E1 #
Simps.Config
def Simps.Config.ctorIdx E1 #
Simps.Config → ℕ
abbrev Simps.ProjectionRule.ctorElimType E1 #
{motive : Simps.ProjectionRule → Sort u} → ℕ → Sort (max 1 u)
theorem Simps.ProjectionRule.erase.injEq E0 #
∀ (a : Lean.Name) (a_1 : Lean.Syntax) (a_2 : Lean.Name) (a_3 : Lean.Syntax),
(Simps.ProjectionRule.erase a a_1 = Simps.ProjectionRule.erase a_2 a_3) = (a = a_2 ∧ a_1 = a_3)
def Simps.ProjectionData.ctorIdx E1 #
Simps.ProjectionData → ℕ
theorem Simps.Config.mk.inj E1 #
∀ {isSimp : Bool} {attrs : Array Lean.Elab.Attribute} {simpRhs dsimpLhs : Bool}
{typeMd rhsMd : Lean.Meta.TransparencyMode} {fullyApplied : Bool} {notRecursive : List Lean.Name} {debug : Bool}
{nameStem : Option String} {isSimp_1 : Bool} {attrs_1 : Array Lean.Elab.Attribute} {simpRhs_1 dsimpLhs_1 : Bool}
{typeMd_1 rhsMd_1 : Lean.Meta.TransparencyMode} {fullyApplied_1 : Bool} {notRecursive_1 : List Lean.Name}
{debug_1 : Bool} {nameStem_1 : Option String},
{ isSimp := isSimp, attrs := attrs, simpRhs := simpRhs, dsimpLhs := dsimpLhs, typeMd := typeMd, rhsMd := rhsMd,
fullyApplied := fullyApplied, notRecursive := notRecursive, debug := debug, nameStem := nameStem } =
{ isSimp := isSimp_1, attrs := attrs_1, simpRhs := simpRhs_1, dsimpLhs := dsimpLhs_1, typeMd := typeMd_1,
rhsMd := rhsMd_1, fullyApplied := fullyApplied_1, notRecursive := notRecursive_1, debug := debug_1,
nameStem := nameStem_1 } →
isSimp = isSimp_1 ∧
attrs = attrs_1 ∧
simpRhs = simpRhs_1 ∧
dsimpLhs = dsimpLhs_1 ∧
typeMd = typeMd_1 ∧
rhsMd = rhsMd_1 ∧
fullyApplied = fullyApplied_1 ∧ notRecursive = notRecursive_1 ∧ debug = debug_1 ∧ nameStem = nameStem_1
theorem Simps.ProjectionData.mk.injEq E0 #
∀ (name : Lean.Name) (expr : Lean.Expr) (projNrs : List ℕ) (isDefault isPrefix : Bool) (name_1 : Lean.Name)
(expr_1 : Lean.Expr) (projNrs_1 : List ℕ) (isDefault_1 isPrefix_1 : Bool),
({ name := name, expr := expr, projNrs := projNrs, isDefault := isDefault, isPrefix := isPrefix } =
{ name := name_1, expr := expr_1, projNrs := projNrs_1, isDefault := isDefault_1, isPrefix := isPrefix_1 }) =
(name = name_1 ∧ expr = expr_1 ∧ projNrs = projNrs_1 ∧ isDefault = isDefault_1 ∧ isPrefix = isPrefix_1)
def Simps.instInhabitedProjectionData.default E1 #
Simps.ProjectionData
theorem Simps.ProjectionData.mk.inj E1 #
∀ {name : Lean.Name} {expr : Lean.Expr} {projNrs : List ℕ} {isDefault isPrefix : Bool} {name_1 : Lean.Name}
{expr_1 : Lean.Expr} {projNrs_1 : List ℕ} {isDefault_1 isPrefix_1 : Bool},
{ name := name, expr := expr, projNrs := projNrs, isDefault := isDefault, isPrefix := isPrefix } =
{ name := name_1, expr := expr_1, projNrs := projNrs_1, isDefault := isDefault_1, isPrefix := isPrefix_1 } →
name = name_1 ∧ expr = expr_1 ∧ projNrs = projNrs_1 ∧ isDefault = isDefault_1 ∧ isPrefix = isPrefix_1
theorem Simps.ParsedProjectionData.mk.injEq E0 #
∀ (strName : Lean.Name) (strStx : Lean.Syntax) (newName : Lean.Name) (newStx : Lean.Syntax) (isDefault isPrefix : Bool)
(expr? : Option Lean.Expr) (projNrs : Array ℕ) (isCustom : Bool) (strName_1 : Lean.Name) (strStx_1 : Lean.Syntax)
(newName_1 : Lean.Name) (newStx_1 : Lean.Syntax) (isDefault_1 isPrefix_1 : Bool) (expr?_1 : Option Lean.Expr)
(projNrs_1 : Array ℕ) (isCustom_1 : Bool),
({ strName := strName, strStx := strStx, newName := newName, newStx := newStx, isDefault := isDefault,
isPrefix := isPrefix, expr? := expr?, projNrs := projNrs, isCustom := isCustom } =
{ strName := strName_1, strStx := strStx_1, newName := newName_1, newStx := newStx_1, isDefault := isDefault_1,
isPrefix := isPrefix_1, expr? := expr?_1, projNrs := projNrs_1, isCustom := isCustom_1 }) =
(strName = strName_1 ∧
strStx = strStx_1 ∧
newName = newName_1 ∧
newStx = newStx_1 ∧
isDefault = isDefault_1 ∧
isPrefix = isPrefix_1 ∧ expr? = expr?_1 ∧ projNrs = projNrs_1 ∧ isCustom = isCustom_1)
theorem Simps.ProjectionRule.prefix.injEq E0 #
∀ (a : Lean.Name) (a_1 : Lean.Syntax) (a_2 : Lean.Name) (a_3 : Lean.Syntax),
(Simps.ProjectionRule.prefix a a_1 = Simps.ProjectionRule.prefix a_2 a_3) = (a = a_2 ∧ a_1 = a_3)
def Simps.ParsedProjectionData.ctorIdx E1 #
Simps.ParsedProjectionData → ℕ
def Simps.ProjectionRule.ctorIdx E1 #
Simps.ProjectionRule → ℕ
theorem Simps.ProjectionRule.prefix.inj E1 #
∀ {a : Lean.Name} {a_1 : Lean.Syntax} {a_2 : Lean.Name} {a_3 : Lean.Syntax},
Simps.ProjectionRule.prefix a a_1 = Simps.ProjectionRule.prefix a_2 a_3 → a = a_2 ∧ a_1 = a_3
theorem Simps.ProjectionRule.erase.inj E1 #
∀ {a : Lean.Name} {a_1 : Lean.Syntax} {a_2 : Lean.Name} {a_3 : Lean.Syntax},
Simps.ProjectionRule.erase a a_1 = Simps.ProjectionRule.erase a_2 a_3 → a = a_2 ∧ a_1 = a_3
theorem Simps.ProjectionRule.rename.injEq E0 #
∀ (oldName : Lean.Name) (oldStx : Lean.Syntax) (newName : Lean.Name) (newStx : Lean.Syntax) (oldName_1 : Lean.Name)
(oldStx_1 : Lean.Syntax) (newName_1 : Lean.Name) (newStx_1 : Lean.Syntax),
(Simps.ProjectionRule.rename oldName oldStx newName newStx =
Simps.ProjectionRule.rename oldName_1 oldStx_1 newName_1 newStx_1) =
(oldName = oldName_1 ∧ oldStx = oldStx_1 ∧ newName = newName_1 ∧ newStx = newStx_1)
theorem Simps.ProjectionRule.add.injEq E0 #
∀ (a : Lean.Name) (a_1 : Lean.Syntax) (a_2 : Lean.Name) (a_3 : Lean.Syntax),
(Simps.ProjectionRule.add a a_1 = Simps.ProjectionRule.add a_2 a_3) = (a = a_2 ∧ a_1 = a_3)
theorem Simps.ParsedProjectionData.mk.inj E1 #
∀ {strName : Lean.Name} {strStx : Lean.Syntax} {newName : Lean.Name} {newStx : Lean.Syntax} {isDefault isPrefix : Bool}
{expr? : Option Lean.Expr} {projNrs : Array ℕ} {isCustom : Bool} {strName_1 : Lean.Name} {strStx_1 : Lean.Syntax}
{newName_1 : Lean.Name} {newStx_1 : Lean.Syntax} {isDefault_1 isPrefix_1 : Bool} {expr?_1 : Option Lean.Expr}
{projNrs_1 : Array ℕ} {isCustom_1 : Bool},
{ strName := strName, strStx := strStx, newName := newName, newStx := newStx, isDefault := isDefault,
isPrefix := isPrefix, expr? := expr?, projNrs := projNrs, isCustom := isCustom } =
{ strName := strName_1, strStx := strStx_1, newName := newName_1, newStx := newStx_1, isDefault := isDefault_1,
isPrefix := isPrefix_1, expr? := expr?_1, projNrs := projNrs_1, isCustom := isCustom_1 } →
strName = strName_1 ∧
strStx = strStx_1 ∧
newName = newName_1 ∧
newStx = newStx_1 ∧
isDefault = isDefault_1 ∧
isPrefix = isPrefix_1 ∧ expr? = expr?_1 ∧ projNrs = projNrs_1 ∧ isCustom = isCustom_1
theorem Simps.ProjectionRule.rename.inj E1 #
∀ {oldName : Lean.Name} {oldStx : Lean.Syntax} {newName : Lean.Name} {newStx : Lean.Syntax} {oldName_1 : Lean.Name}
{oldStx_1 : Lean.Syntax} {newName_1 : Lean.Name} {newStx_1 : Lean.Syntax},
Simps.ProjectionRule.rename oldName oldStx newName newStx =
Simps.ProjectionRule.rename oldName_1 oldStx_1 newName_1 newStx_1 →
oldName = oldName_1 ∧ oldStx = oldStx_1 ∧ newName = newName_1 ∧ newStx = newStx_1
theorem Simps.Config.mk.injEq E0 #
∀ (isSimp : Bool) (attrs : Array Lean.Elab.Attribute) (simpRhs dsimpLhs : Bool)
(typeMd rhsMd : Lean.Meta.TransparencyMode) (fullyApplied : Bool) (notRecursive : List Lean.Name) (debug : Bool)
(nameStem : Option String) (isSimp_1 : Bool) (attrs_1 : Array Lean.Elab.Attribute) (simpRhs_1 dsimpLhs_1 : Bool)
(typeMd_1 rhsMd_1 : Lean.Meta.TransparencyMode) (fullyApplied_1 : Bool) (notRecursive_1 : List Lean.Name)
(debug_1 : Bool) (nameStem_1 : Option String),
({ isSimp := isSimp, attrs := attrs, simpRhs := simpRhs, dsimpLhs := dsimpLhs, typeMd := typeMd, rhsMd := rhsMd,
fullyApplied := fullyApplied, notRecursive := notRecursive, debug := debug, nameStem := nameStem } =
{ isSimp := isSimp_1, attrs := attrs_1, simpRhs := simpRhs_1, dsimpLhs := dsimpLhs_1, typeMd := typeMd_1,
rhsMd := rhsMd_1, fullyApplied := fullyApplied_1, notRecursive := notRecursive_1, debug := debug_1,
nameStem := nameStem_1 }) =
(isSimp = isSimp_1 ∧
attrs = attrs_1 ∧
simpRhs = simpRhs_1 ∧
dsimpLhs = dsimpLhs_1 ∧
typeMd = typeMd_1 ∧
rhsMd = rhsMd_1 ∧
fullyApplied = fullyApplied_1 ∧ notRecursive = notRecursive_1 ∧ debug = debug_1 ∧ nameStem = nameStem_1)
def Lean.Meta.mkSimpContextResult E1 #
optParam Lean.Meta.Simp.Config { } →
optParam Bool false →
optParam Lean.Elab.Tactic.SimpKind Lean.Elab.Tactic.SimpKind.simp →
optParam Lean.Elab.Tactic.Simp.DischargeWrapper Lean.Elab.Tactic.Simp.DischargeWrapper.default →
optParam Bool false → Lean.MetaM Lean.Elab.Tactic.MkSimpContextResult
Make MkSimpContextResult giving data instead of Syntax. Doesn't support arguments.
Intended to be very similar to Lean.Elab.Tactic.mkSimpContext
Todo: support arguments.
def Lean.Meta.mkSimpContext E1 #
optParam Lean.Meta.Simp.Config { } →
optParam Bool false →
optParam Lean.Elab.Tactic.SimpKind Lean.Elab.Tactic.SimpKind.simp →
optParam Lean.Elab.Tactic.Simp.DischargeWrapper Lean.Elab.Tactic.Simp.DischargeWrapper.default →
optParam Bool false → Lean.MetaM Lean.Meta.Simp.Context
Make Simp.Context giving data instead of Syntax. Doesn't support arguments.
Intended to be very similar to Lean.Elab.Tactic.mkSimpContext
Todo: support arguments.
def Lean.Parser.Attr.simpsConfigAttrItem E1 #
Lean.ParserDescr
@[simps (attr := attr1, attr2, ...)] adds additional attributes to all lemmas
generated by simps.
def Lean.Parser.Attr.simpsConfigItem E1 #
Lean.ParserDescr
Configuration items for @[simps] attribute.
def Lean.Parser.Attr.simpsConfig E1 #
Lean.ParserDescr
Configuration for @[simps] attribute.
def Lean.Parser.Attr.simpsArgsRest E1 #
Lean.ParserDescr
Arguments to @[simps] attribute.
def Lean.Parser.Attr.simps E1 #
Lean.ParserDescr
The @[simps] attribute automatically derives lemmas specifying the projections of this
declaration.
Example:
@[simps] def foo : ℕ × ℤ := (1, 2)
derives two simp lemmas:
@[simp] lemma foo_fst : foo.fst = 1
@[simp] lemma foo_snd : foo.snd = 2
-
It does not derive
simplemmas for the prop-valued projections. -
It will automatically reduce newly created beta-redexes, but will not unfold any definitions.
-
If the structure has a coercion to either sorts or functions, and this is defined to be one of the projections, then this coercion will be used instead of the projection.
-
If the structure is a class that has an instance to a notation class, like
NegorMul, then this notation is used instead of the corresponding projection. -
You can specify custom projections, by giving a declaration with name
{StructureName}.Simps.{projectionName}. See Note [custom simps projection].Example:
def Equiv.Simps.invFun (e : α ≃ β) : β → α := e.symm @[simps] def Equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩generates
@[simp] lemma Equiv.trans_toFun : ∀ {α β γ} (e₁ e₂) (a : α), ⇑(e₁.trans e₂) a = (⇑e₂ ∘ ⇑e₁) a @[simp] lemma Equiv.trans_invFun : ∀ {α β γ} (e₁ e₂) (a : γ), ⇑((e₁.trans e₂).symm) a = (⇑(e₁.symm) ∘ ⇑(e₂.symm)) a -
You can specify custom projection names, by specifying the new projection names using
initialize_simps_projections. Example:initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply). Seeinitialize_simps_projectionsfor more information. -
If one of the fields itself is a structure, this command will recursively create
simplemmas for all fields in that structure.- Exception: by default it will not recursively create
simplemmas for fields in the structuresProd,PProd, andOpposite. You can give explicit projection names or change the value ofSimps.Config.notRecursiveto override this behavior.
Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_snd_fst : foo.snd.fst = 3 @[simp] lemma foo_snd_snd : foo.snd.snd = 4 - Exception: by default it will not recursively create
-
You can use
@[simps proj1 proj2 ...]to only generate the projection lemmas for the specified projections. -
Recursive projection names can be specified using
proj1_proj2_proj3. This will create a lemma of the formfoo.proj1.proj2.proj3 = ....Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps fst fst_fst snd] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_fst_fst : foo.fst.fst = 1 @[simp] lemma foo_snd : foo.snd = {fst := 3, snd := 4} -
If one of the values is an eta-expanded structure, we will eta-reduce this structure.
Example:
structure EquivPlusData (α β) extends α ≃ β where data : Bool @[simps] def EquivPlusData.rfl {α} : EquivPlusData α α := { Equiv.refl α with data := true }generates the following:
@[simp] lemma bar_toEquiv : ∀ {α : Sort*}, bar.toEquiv = Equiv.refl α @[simp] lemma bar_data : ∀ {α : Sort*}, bar.data = trueThis is true, even though Lean inserts an eta-expanded version of
Equiv.refl αin the definition ofbar. -
You can add additional attributes to all lemmas generated by
simpsusing e.g.@[simps (attr := grind =)]. -
For configuration options, see the doc string of
Simps.Config. -
The precise syntax is
simps config ident*, whereconfigdeclares configuration options, andident*is a list of desired projection names. Theconfigcan contain(attr := a)entries, whereais a list of attributes. -
Configuration options can be given using
(config := e)wheree : Simps.Config, or by specifying options directly, like-fullyAppliedor(notRecursive := []). -
@[simps]reduces let-expressions where necessary. -
When option
trace.simpsis true,simpswill print the lemmas it generates. The same can be achieved by using@[simps?]. Other available trace options aretrace.simps.verboseandtrace.simps.debug -
Use
@[to_additive (attr := simps)]to apply bothto_additiveandsimpsto a definition This will also generate the additive versions of allsimplemmas.
def Lean.Parser.Attr.attrSimps?_ E1 #
Lean.ParserDescr
The @[simps] attribute automatically derives lemmas specifying the projections of this
declaration.
Example:
@[simps] def foo : ℕ × ℤ := (1, 2)
derives two simp lemmas:
@[simp] lemma foo_fst : foo.fst = 1
@[simp] lemma foo_snd : foo.snd = 2
-
It does not derive
simplemmas for the prop-valued projections. -
It will automatically reduce newly created beta-redexes, but will not unfold any definitions.
-
If the structure has a coercion to either sorts or functions, and this is defined to be one of the projections, then this coercion will be used instead of the projection.
-
If the structure is a class that has an instance to a notation class, like
NegorMul, then this notation is used instead of the corresponding projection. -
You can specify custom projections, by giving a declaration with name
{StructureName}.Simps.{projectionName}. See Note [custom simps projection].Example:
def Equiv.Simps.invFun (e : α ≃ β) : β → α := e.symm @[simps] def Equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩generates
@[simp] lemma Equiv.trans_toFun : ∀ {α β γ} (e₁ e₂) (a : α), ⇑(e₁.trans e₂) a = (⇑e₂ ∘ ⇑e₁) a @[simp] lemma Equiv.trans_invFun : ∀ {α β γ} (e₁ e₂) (a : γ), ⇑((e₁.trans e₂).symm) a = (⇑(e₁.symm) ∘ ⇑(e₂.symm)) a -
You can specify custom projection names, by specifying the new projection names using
initialize_simps_projections. Example:initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply). Seeinitialize_simps_projectionsfor more information. -
If one of the fields itself is a structure, this command will recursively create
simplemmas for all fields in that structure.- Exception: by default it will not recursively create
simplemmas for fields in the structuresProd,PProd, andOpposite. You can give explicit projection names or change the value ofSimps.Config.notRecursiveto override this behavior.
Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_snd_fst : foo.snd.fst = 3 @[simp] lemma foo_snd_snd : foo.snd.snd = 4 - Exception: by default it will not recursively create
-
You can use
@[simps proj1 proj2 ...]to only generate the projection lemmas for the specified projections. -
Recursive projection names can be specified using
proj1_proj2_proj3. This will create a lemma of the formfoo.proj1.proj2.proj3 = ....Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps fst fst_fst snd] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_fst_fst : foo.fst.fst = 1 @[simp] lemma foo_snd : foo.snd = {fst := 3, snd := 4} -
If one of the values is an eta-expanded structure, we will eta-reduce this structure.
Example:
structure EquivPlusData (α β) extends α ≃ β where data : Bool @[simps] def EquivPlusData.rfl {α} : EquivPlusData α α := { Equiv.refl α with data := true }generates the following:
@[simp] lemma bar_toEquiv : ∀ {α : Sort*}, bar.toEquiv = Equiv.refl α @[simp] lemma bar_data : ∀ {α : Sort*}, bar.data = trueThis is true, even though Lean inserts an eta-expanded version of
Equiv.refl αin the definition ofbar. -
You can add additional attributes to all lemmas generated by
simpsusing e.g.@[simps (attr := grind =)]. -
For configuration options, see the doc string of
Simps.Config. -
The precise syntax is
simps config ident*, whereconfigdeclares configuration options, andident*is a list of desired projection names. Theconfigcan contain(attr := a)entries, whereais a list of attributes. -
Configuration options can be given using
(config := e)wheree : Simps.Config, or by specifying options directly, like-fullyAppliedor(notRecursive := []). -
@[simps]reduces let-expressions where necessary. -
When option
trace.simpsis true,simpswill print the lemmas it generates. The same can be achieved by using@[simps?]. Other available trace options aretrace.simps.verboseandtrace.simps.debug -
Use
@[to_additive (attr := simps)]to apply bothto_additiveandsimpsto a definition This will also generate the additive versions of allsimplemmas.
def Lean.Parser.Attr.attrSimps!_ E1 #
Lean.ParserDescr
The @[simps] attribute automatically derives lemmas specifying the projections of this
declaration.
Example:
@[simps] def foo : ℕ × ℤ := (1, 2)
derives two simp lemmas:
@[simp] lemma foo_fst : foo.fst = 1
@[simp] lemma foo_snd : foo.snd = 2
-
It does not derive
simplemmas for the prop-valued projections. -
It will automatically reduce newly created beta-redexes, but will not unfold any definitions.
-
If the structure has a coercion to either sorts or functions, and this is defined to be one of the projections, then this coercion will be used instead of the projection.
-
If the structure is a class that has an instance to a notation class, like
NegorMul, then this notation is used instead of the corresponding projection. -
You can specify custom projections, by giving a declaration with name
{StructureName}.Simps.{projectionName}. See Note [custom simps projection].Example:
def Equiv.Simps.invFun (e : α ≃ β) : β → α := e.symm @[simps] def Equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩generates
@[simp] lemma Equiv.trans_toFun : ∀ {α β γ} (e₁ e₂) (a : α), ⇑(e₁.trans e₂) a = (⇑e₂ ∘ ⇑e₁) a @[simp] lemma Equiv.trans_invFun : ∀ {α β γ} (e₁ e₂) (a : γ), ⇑((e₁.trans e₂).symm) a = (⇑(e₁.symm) ∘ ⇑(e₂.symm)) a -
You can specify custom projection names, by specifying the new projection names using
initialize_simps_projections. Example:initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply). Seeinitialize_simps_projectionsfor more information. -
If one of the fields itself is a structure, this command will recursively create
simplemmas for all fields in that structure.- Exception: by default it will not recursively create
simplemmas for fields in the structuresProd,PProd, andOpposite. You can give explicit projection names or change the value ofSimps.Config.notRecursiveto override this behavior.
Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_snd_fst : foo.snd.fst = 3 @[simp] lemma foo_snd_snd : foo.snd.snd = 4 - Exception: by default it will not recursively create
-
You can use
@[simps proj1 proj2 ...]to only generate the projection lemmas for the specified projections. -
Recursive projection names can be specified using
proj1_proj2_proj3. This will create a lemma of the formfoo.proj1.proj2.proj3 = ....Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps fst fst_fst snd] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_fst_fst : foo.fst.fst = 1 @[simp] lemma foo_snd : foo.snd = {fst := 3, snd := 4} -
If one of the values is an eta-expanded structure, we will eta-reduce this structure.
Example:
structure EquivPlusData (α β) extends α ≃ β where data : Bool @[simps] def EquivPlusData.rfl {α} : EquivPlusData α α := { Equiv.refl α with data := true }generates the following:
@[simp] lemma bar_toEquiv : ∀ {α : Sort*}, bar.toEquiv = Equiv.refl α @[simp] lemma bar_data : ∀ {α : Sort*}, bar.data = trueThis is true, even though Lean inserts an eta-expanded version of
Equiv.refl αin the definition ofbar. -
You can add additional attributes to all lemmas generated by
simpsusing e.g.@[simps (attr := grind =)]. -
For configuration options, see the doc string of
Simps.Config. -
The precise syntax is
simps config ident*, whereconfigdeclares configuration options, andident*is a list of desired projection names. Theconfigcan contain(attr := a)entries, whereais a list of attributes. -
Configuration options can be given using
(config := e)wheree : Simps.Config, or by specifying options directly, like-fullyAppliedor(notRecursive := []). -
@[simps]reduces let-expressions where necessary. -
When option
trace.simpsis true,simpswill print the lemmas it generates. The same can be achieved by using@[simps?]. Other available trace options aretrace.simps.verboseandtrace.simps.debug -
Use
@[to_additive (attr := simps)]to apply bothto_additiveandsimpsto a definition This will also generate the additive versions of allsimplemmas.
def Lean.Parser.Attr.attrSimps!?_ E1 #
Lean.ParserDescr
The @[simps] attribute automatically derives lemmas specifying the projections of this
declaration.
Example:
@[simps] def foo : ℕ × ℤ := (1, 2)
derives two simp lemmas:
@[simp] lemma foo_fst : foo.fst = 1
@[simp] lemma foo_snd : foo.snd = 2
-
It does not derive
simplemmas for the prop-valued projections. -
It will automatically reduce newly created beta-redexes, but will not unfold any definitions.
-
If the structure has a coercion to either sorts or functions, and this is defined to be one of the projections, then this coercion will be used instead of the projection.
-
If the structure is a class that has an instance to a notation class, like
NegorMul, then this notation is used instead of the corresponding projection. -
You can specify custom projections, by giving a declaration with name
{StructureName}.Simps.{projectionName}. See Note [custom simps projection].Example:
def Equiv.Simps.invFun (e : α ≃ β) : β → α := e.symm @[simps] def Equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩generates
@[simp] lemma Equiv.trans_toFun : ∀ {α β γ} (e₁ e₂) (a : α), ⇑(e₁.trans e₂) a = (⇑e₂ ∘ ⇑e₁) a @[simp] lemma Equiv.trans_invFun : ∀ {α β γ} (e₁ e₂) (a : γ), ⇑((e₁.trans e₂).symm) a = (⇑(e₁.symm) ∘ ⇑(e₂.symm)) a -
You can specify custom projection names, by specifying the new projection names using
initialize_simps_projections. Example:initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply). Seeinitialize_simps_projectionsfor more information. -
If one of the fields itself is a structure, this command will recursively create
simplemmas for all fields in that structure.- Exception: by default it will not recursively create
simplemmas for fields in the structuresProd,PProd, andOpposite. You can give explicit projection names or change the value ofSimps.Config.notRecursiveto override this behavior.
Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_snd_fst : foo.snd.fst = 3 @[simp] lemma foo_snd_snd : foo.snd.snd = 4 - Exception: by default it will not recursively create
-
You can use
@[simps proj1 proj2 ...]to only generate the projection lemmas for the specified projections. -
Recursive projection names can be specified using
proj1_proj2_proj3. This will create a lemma of the formfoo.proj1.proj2.proj3 = ....Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps fst fst_fst snd] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_fst_fst : foo.fst.fst = 1 @[simp] lemma foo_snd : foo.snd = {fst := 3, snd := 4} -
If one of the values is an eta-expanded structure, we will eta-reduce this structure.
Example:
structure EquivPlusData (α β) extends α ≃ β where data : Bool @[simps] def EquivPlusData.rfl {α} : EquivPlusData α α := { Equiv.refl α with data := true }generates the following:
@[simp] lemma bar_toEquiv : ∀ {α : Sort*}, bar.toEquiv = Equiv.refl α @[simp] lemma bar_data : ∀ {α : Sort*}, bar.data = trueThis is true, even though Lean inserts an eta-expanded version of
Equiv.refl αin the definition ofbar. -
You can add additional attributes to all lemmas generated by
simpsusing e.g.@[simps (attr := grind =)]. -
For configuration options, see the doc string of
Simps.Config. -
The precise syntax is
simps config ident*, whereconfigdeclares configuration options, andident*is a list of desired projection names. Theconfigcan contain(attr := a)entries, whereais a list of attributes. -
Configuration options can be given using
(config := e)wheree : Simps.Config, or by specifying options directly, like-fullyAppliedor(notRecursive := []). -
@[simps]reduces let-expressions where necessary. -
When option
trace.simpsis true,simpswill print the lemmas it generates. The same can be achieved by using@[simps?]. Other available trace options aretrace.simps.verboseandtrace.simps.debug -
Use
@[to_additive (attr := simps)]to apply bothto_additiveandsimpsto a definition This will also generate the additive versions of allsimplemmas.
def Lean.Parser.Attr.attrSimps?!_ E1 #
Lean.ParserDescr
The @[simps] attribute automatically derives lemmas specifying the projections of this
declaration.
Example:
@[simps] def foo : ℕ × ℤ := (1, 2)
derives two simp lemmas:
@[simp] lemma foo_fst : foo.fst = 1
@[simp] lemma foo_snd : foo.snd = 2
-
It does not derive
simplemmas for the prop-valued projections. -
It will automatically reduce newly created beta-redexes, but will not unfold any definitions.
-
If the structure has a coercion to either sorts or functions, and this is defined to be one of the projections, then this coercion will be used instead of the projection.
-
If the structure is a class that has an instance to a notation class, like
NegorMul, then this notation is used instead of the corresponding projection. -
You can specify custom projections, by giving a declaration with name
{StructureName}.Simps.{projectionName}. See Note [custom simps projection].Example:
def Equiv.Simps.invFun (e : α ≃ β) : β → α := e.symm @[simps] def Equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩generates
@[simp] lemma Equiv.trans_toFun : ∀ {α β γ} (e₁ e₂) (a : α), ⇑(e₁.trans e₂) a = (⇑e₂ ∘ ⇑e₁) a @[simp] lemma Equiv.trans_invFun : ∀ {α β γ} (e₁ e₂) (a : γ), ⇑((e₁.trans e₂).symm) a = (⇑(e₁.symm) ∘ ⇑(e₂.symm)) a -
You can specify custom projection names, by specifying the new projection names using
initialize_simps_projections. Example:initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply). Seeinitialize_simps_projectionsfor more information. -
If one of the fields itself is a structure, this command will recursively create
simplemmas for all fields in that structure.- Exception: by default it will not recursively create
simplemmas for fields in the structuresProd,PProd, andOpposite. You can give explicit projection names or change the value ofSimps.Config.notRecursiveto override this behavior.
Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_snd_fst : foo.snd.fst = 3 @[simp] lemma foo_snd_snd : foo.snd.snd = 4 - Exception: by default it will not recursively create
-
You can use
@[simps proj1 proj2 ...]to only generate the projection lemmas for the specified projections. -
Recursive projection names can be specified using
proj1_proj2_proj3. This will create a lemma of the formfoo.proj1.proj2.proj3 = ....Example:
structure MyProd (α β : Type*) := (fst : α) (snd : β) @[simps fst fst_fst snd] def foo : Prod ℕ ℕ × MyProd ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩generates
@[simp] lemma foo_fst : foo.fst = (1, 2) @[simp] lemma foo_fst_fst : foo.fst.fst = 1 @[simp] lemma foo_snd : foo.snd = {fst := 3, snd := 4} -
If one of the values is an eta-expanded structure, we will eta-reduce this structure.
Example:
structure EquivPlusData (α β) extends α ≃ β where data : Bool @[simps] def EquivPlusData.rfl {α} : EquivPlusData α α := { Equiv.refl α with data := true }generates the following:
@[simp] lemma bar_toEquiv : ∀ {α : Sort*}, bar.toEquiv = Equiv.refl α @[simp] lemma bar_data : ∀ {α : Sort*}, bar.data = trueThis is true, even though Lean inserts an eta-expanded version of
Equiv.refl αin the definition ofbar. -
You can add additional attributes to all lemmas generated by
simpsusing e.g.@[simps (attr := grind =)]. -
For configuration options, see the doc string of
Simps.Config. -
The precise syntax is
simps config ident*, whereconfigdeclares configuration options, andident*is a list of desired projection names. Theconfigcan contain(attr := a)entries, whereais a list of attributes. -
Configuration options can be given using
(config := e)wheree : Simps.Config, or by specifying options directly, like-fullyAppliedor(notRecursive := []). -
@[simps]reduces let-expressions where necessary. -
When option
trace.simpsis true,simpswill print the lemmas it generates. The same can be achieved by using@[simps?]. Other available trace options aretrace.simps.verboseandtrace.simps.debug -
Use
@[to_additive (attr := simps)]to apply bothto_additiveandsimpsto a definition This will also generate the additive versions of allsimplemmas.
opaque Lean.Parser.linter.simpsNoConstructor E1 #
Lean.Option Bool
Linter to check that simps! is used when needed
opaque Lean.Parser.linter.simpsUnusedCustomDeclarations E1 #
Lean.Option Bool
Linter to check that no unused custom declarations are declared for simps.
def Lean.Parser.Command.simpsRule.rename E1 #
Lean.ParserDescr
Syntax for renaming a projection in initialize_simps_projections.
def Lean.Parser.Command.simpsRule.erase E1 #
Lean.ParserDescr
Syntax for making a projection non-default in initialize_simps_projections.
def Lean.Parser.Command.simpsRule.add E1 #
Lean.ParserDescr
Syntax for making a projection default in initialize_simps_projections.
def Lean.Parser.Command.simpsRule.prefix E1 #
Lean.ParserDescr
Syntax for making a projection prefix.
def Lean.Parser.Command.simpsRule E1 #
Lean.ParserDescr
Syntax for a single rule in initialize_simps_projections.
def Lean.Parser.Command.simpsProj E1 #
Lean.ParserDescr
Syntax for initialize_simps_projections.
def Lean.Parser.Command.initialize_simps_projections E1 #
Lean.ParserDescr
This command allows customisation of the lemmas generated by simps.
By default, tagging a definition of an element myObj of a structure MyStruct with @[simps]
generates one @[simp] lemma myObj_myProj for each projection myProj of MyStruct. There are a
few exceptions to this general rule:
- For algebraic structures, we will automatically use the notation (like
Mul) for the projections if such an instance is available. - By default, the projections to parent structures are not default projections, but all the data-carrying fields are (including those in parent structures).
This default behavior is customisable as such:
- You can disable a projection by default by running
initialize_simps_projections MulEquiv (-invFun)This will ensure that no simp lemmas are generated for this projection, unless this projection is explicitly specified by the user (as in@[simps invFun] def myEquiv : MulEquiv _ _ := _). - Conversely, you can enable a projection by default by running
initialize_simps_projections MulEquiv (+toEquiv). - You can specify custom names by writing e.g.
initialize_simps_projections MulEquiv (toFun → apply, invFun → symm_apply). - If you want the projection name added as a prefix in the generated lemma name, you can use
as_prefix fieldName:initialize_simps_projections MulEquiv (toFun → coe, as_prefix coe)Note that this does not influence the parsing of projection names: if you have a declarationfooand you want to apply the projectionssnd,coe(which is a prefix) andfst, in that order you can run@[simps snd_coe_fst] def foo ...and this will generate a lemma with the namecoe_foo_snd_fst.
Here are a few extra pieces of information:
- Run
initialize_simps_projections?(orset_option trace.simps.verbose true) to see the generated projections. - Running
initialize_simps_projections MyStructwithout arguments is not necessary, it has the same effect if you just add@[simps]to a declaration. - It is recommended to call
@[simps]orinitialize_simps_projectionsin the same file as the structure declaration. Otherwise, the projections could be generated multiple times in different files.
Some common uses:
- If you define a new homomorphism-like structure (like
MulHom) you can just runinitialize_simps_projectionsafter defining theDFunLikeinstance (or instance that implies aDFunLikeinstance).
This will generate@[macro_inline] instance {mM : Mul M} {mN : Mul N} : FunLike (MulHom M N) M N := ... initialize_simps_projections MulHom (toFun → apply)foo_applylemmas for each declarationfoo. - If you prefer
coe_foolemmas that state equalities between functions, useinitialize_simps_projections MulHom (toFun → coe, as_prefix coe)In this case you have to use@[simps -fullyApplied]whenever you call@[simps]. - You can also initialize to use both, in which case you have to choose which one to use by default,
by using either of the following
In the first case, you can get both lemmas usinginitialize_simps_projections MulHom (toFun → apply, toFun → coe, as_prefix coe, -coe) initialize_simps_projections MulHom (toFun → apply, toFun → coe, as_prefix coe, -apply)@[simps, simps -fullyApplied coe]and in the second case you can get both lemmas using@[simps -fullyApplied, simps apply]. - If you declare a new homomorphism-like structure (like
RelEmbedding), theninitialize_simps_projectionswill automatically find anyDFunLikecoercions that will be used as the default projection for thetoFunfield.initialize_simps_projections relEmbedding (toFun → apply) - If you have an isomorphism-like structure (like
Equiv) you often want to define a custom projection for the inverse:def Equiv.Simps.symm_apply (e : α ≃ β) : β → α := e.symm initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply)
def Lean.Parser.Command.commandInitialize_simps_projections?_ E1 #
Lean.ParserDescr
This command allows customisation of the lemmas generated by simps.
By default, tagging a definition of an element myObj of a structure MyStruct with @[simps]
generates one @[simp] lemma myObj_myProj for each projection myProj of MyStruct. There are a
few exceptions to this general rule:
- For algebraic structures, we will automatically use the notation (like
Mul) for the projections if such an instance is available. - By default, the projections to parent structures are not default projections, but all the data-carrying fields are (including those in parent structures).
This default behavior is customisable as such:
- You can disable a projection by default by running
initialize_simps_projections MulEquiv (-invFun)This will ensure that no simp lemmas are generated for this projection, unless this projection is explicitly specified by the user (as in@[simps invFun] def myEquiv : MulEquiv _ _ := _). - Conversely, you can enable a projection by default by running
initialize_simps_projections MulEquiv (+toEquiv). - You can specify custom names by writing e.g.
initialize_simps_projections MulEquiv (toFun → apply, invFun → symm_apply). - If you want the projection name added as a prefix in the generated lemma name, you can use
as_prefix fieldName:initialize_simps_projections MulEquiv (toFun → coe, as_prefix coe)Note that this does not influence the parsing of projection names: if you have a declarationfooand you want to apply the projectionssnd,coe(which is a prefix) andfst, in that order you can run@[simps snd_coe_fst] def foo ...and this will generate a lemma with the namecoe_foo_snd_fst.
Here are a few extra pieces of information:
- Run
initialize_simps_projections?(orset_option trace.simps.verbose true) to see the generated projections. - Running
initialize_simps_projections MyStructwithout arguments is not necessary, it has the same effect if you just add@[simps]to a declaration. - It is recommended to call
@[simps]orinitialize_simps_projectionsin the same file as the structure declaration. Otherwise, the projections could be generated multiple times in different files.
Some common uses:
- If you define a new homomorphism-like structure (like
MulHom) you can just runinitialize_simps_projectionsafter defining theDFunLikeinstance (or instance that implies aDFunLikeinstance).
This will generate@[macro_inline] instance {mM : Mul M} {mN : Mul N} : FunLike (MulHom M N) M N := ... initialize_simps_projections MulHom (toFun → apply)foo_applylemmas for each declarationfoo. - If you prefer
coe_foolemmas that state equalities between functions, useinitialize_simps_projections MulHom (toFun → coe, as_prefix coe)In this case you have to use@[simps -fullyApplied]whenever you call@[simps]. - You can also initialize to use both, in which case you have to choose which one to use by default,
by using either of the following
In the first case, you can get both lemmas usinginitialize_simps_projections MulHom (toFun → apply, toFun → coe, as_prefix coe, -coe) initialize_simps_projections MulHom (toFun → apply, toFun → coe, as_prefix coe, -apply)@[simps, simps -fullyApplied coe]and in the second case you can get both lemmas using@[simps -fullyApplied, simps apply]. - If you declare a new homomorphism-like structure (like
RelEmbedding), theninitialize_simps_projectionswill automatically find anyDFunLikecoercions that will be used as the default projection for thetoFunfield.initialize_simps_projections relEmbedding (toFun → apply) - If you have an isomorphism-like structure (like
Equiv) you often want to define a custom projection for the inverse:def Equiv.Simps.symm_apply (e : α ≃ β) : β → α := e.symm initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply)
structure Simps.ProjectionData E1 #
Type
Projection data for a single projection of a structure
ctor Simps.ProjectionData.mk E0 #
Lean.Name → Lean.Expr → List ℕ → Bool → Bool → Simps.ProjectionData
abbrev Simps.ProjectionData.name E1 #
Simps.ProjectionData → Lean.Name
The name used in the generated simp lemmas
abbrev Simps.ProjectionData.expr E1 #
Simps.ProjectionData → Lean.Expr
An Expression used by simps for the projection. It must be definitionally equal to an original
projection (or a composition of multiple projections).
These Expressions can contain the universe parameters specified in the first argument of
structureExt.
abbrev Simps.ProjectionData.projNrs E1 #
Simps.ProjectionData → List ℕ
A list of natural numbers, which is the projection number(s) that have to be applied to the
Expression. For example the list [0, 1] corresponds to applying the first projection of the
structure, and then the second projection of the resulting structure (this assumes that the
target of the first projection is a structure with at least two projections).
The composition of these projections is required to be definitionally equal to the provided
Expression.
abbrev Simps.ProjectionData.isDefault E1 #
Simps.ProjectionData → Bool
A Boolean specifying whether simp lemmas are generated for this projection by default.
abbrev Simps.ProjectionData.isPrefix E1 #
Simps.ProjectionData → Bool
A Boolean specifying whether this projection is written as prefix.
instance Simps.instInhabitedProjectionData E0 #
Inhabited Simps.ProjectionData
instance Simps.instToMessageDataProjectionData E0 #
Lean.ToMessageData Simps.ProjectionData
opaque Simps.structureExt E1 #
Lean.NameMapExtension (List Lean.Name × Array Simps.ProjectionData)
The Simps.structureExt environment extension specifies the preferred projections of the given
structure, used by the @[simps] attribute.
- You can generate this with the command
initialize_simps_projections. - If not generated, the
@[simps]attribute will generate this automatically. - To change the default value, see Note [custom simps projection].
- The first argument is the list of names of the universe variables used in the structure
- The second argument is an array that consists of the projection data for each projection.
structure Simps.ParsedProjectionData E1 #
Type
Projection data used internally in getRawProjections.
ctor Simps.ParsedProjectionData.mk E0 #
Lean.Name →
Lean.Syntax → Lean.Name → Lean.Syntax → Bool → Bool → Option Lean.Expr → Array ℕ → Bool → Simps.ParsedProjectionData
abbrev Simps.ParsedProjectionData.strName E1 #
Simps.ParsedProjectionData → Lean.Name
name for this projection used in the structure definition
abbrev Simps.ParsedProjectionData.strStx E1 #
Simps.ParsedProjectionData → Lean.Syntax
syntax that might have provided strName
abbrev Simps.ParsedProjectionData.newName E1 #
Simps.ParsedProjectionData → Lean.Name
name for this projection used in the generated simp lemmas
abbrev Simps.ParsedProjectionData.newStx E1 #
Simps.ParsedProjectionData → Lean.Syntax
syntax that provided newName
abbrev Simps.ParsedProjectionData.isDefault E1 #
Simps.ParsedProjectionData → Bool
will simp lemmas be generated for with (without specifically naming this?)
abbrev Simps.ParsedProjectionData.isPrefix E1 #
Simps.ParsedProjectionData → Bool
is the projection name a prefix?
abbrev Simps.ParsedProjectionData.expr? E1 #
Simps.ParsedProjectionData → Option Lean.Expr
projection expression
abbrev Simps.ParsedProjectionData.projNrs E1 #
Simps.ParsedProjectionData → Array ℕ
the list of projection numbers this expression corresponds to
abbrev Simps.ParsedProjectionData.isCustom E1 #
Simps.ParsedProjectionData → Bool
is this a projection that is changed by the user?
def Simps.ParsedProjectionData.toProjectionData E1 #
Simps.ParsedProjectionData → Simps.ProjectionData
Turn ParsedProjectionData into ProjectionData.
instance Simps.instToMessageDataParsedProjectionData E0 #
Lean.ToMessageData Simps.ParsedProjectionData
inductive Simps.ProjectionRule E1 #
Type
The type of rules that specify how metadata for projections in changes.
See initialize_simps_projections.
ctor Simps.ProjectionRule.rename E0 #
Lean.Name → Lean.Syntax → Lean.Name → Lean.Syntax → Simps.ProjectionRule
A renaming rule before→after or
Each name comes with the syntax used to write the rule,
which is used to declare hover information.
ctor Simps.ProjectionRule.add E0 #
Lean.Name → Lean.Syntax → Simps.ProjectionRule
An adding rule +fieldName
ctor Simps.ProjectionRule.erase E0 #
Lean.Name → Lean.Syntax → Simps.ProjectionRule
A hiding rule -fieldName
ctor Simps.ProjectionRule.prefix E0 #
Lean.Name → Lean.Syntax → Simps.ProjectionRule
A prefix rule prefix fieldName
instance Simps.instToMessageDataProjectionRule E0 #
Lean.ToMessageData Simps.ProjectionRule
def Simps.projectionsInfo E1 #
List Simps.ProjectionData → String → Lean.Name → Lean.MessageData
Returns the projection information of a structure.
def Simps.findProjectionIndices E1 #
Lean.Name → Lean.Name → Lean.MetaM (List ℕ)
Find the indices of the projections that need to be applied to elaborate $e.$projName.
Example: If e : α ≃+ β and projName = `invFun then this returns [0, 1], because the first
projection of MulEquiv is toEquiv and the second projection of Equiv is invFun.
opaque Simps.getCompositeOfProjectionsAux E0 #
String → Lean.Expr → Array ℕ → Array Lean.Expr → Lean.MetaM (Lean.Expr × Array ℕ)
Auxiliary function of getCompositeOfProjections.
def Simps.getCompositeOfProjections E1 #
Lean.Name → String → Lean.MetaM (Lean.Expr × Array ℕ)
Suppose we are given a structure str and a projection proj, that could be multiple nested
projections (separated by _), where each projection could be a projection of a parent structure.
This function returns an expression that is the composition of these projections and a
list of natural numbers, that are the projection numbers of the applied projections.
Note that this function is similar to elaborating dot notation, but it can do a little more.
Example: if we do
structure gradedFun (A : ℕ → Type*) where
toFun := ∀ i j, A i →+ A j →+ A (i + j)
initialize_simps_projections (toFun_toFun_toFun → myMul)
we will be able to generate the "projection"
fun {A} (f : gradedFun A) (x : A i) (y : A j) ↦ ↑(↑(f.toFun i j) x) y,
which projection notation cannot do.
def Simps.mkParsedProjectionData E1 #
Lean.Name → Lean.CoreM (Array Simps.ParsedProjectionData)
Get the default ParsedProjectionData for structure str.
It first returns the direct fields of the structure in the right order, and then
all (non-subobject fields) of all parent structures. The subobject fields are precisely the
non-default fields.
def Simps.applyProjectionRules E1 #
Array Simps.ParsedProjectionData → Array Simps.ProjectionRule → Lean.CoreM (Array Simps.ParsedProjectionData)
Execute the projection renamings (and turning off projections) as specified by rules.
def Simps.findProjection E1 #
Lean.Name → Simps.ParsedProjectionData → List Lean.Level → Lean.CoreM Simps.ParsedProjectionData
Auxiliary function for getRawProjections.
Generates the default projection, and looks for a custom projection declared by the user,
and replaces the default projection with the custom one, if it can find it.
def Simps.checkForUnusedCustomProjs E1 #
Lean.Syntax → Lean.Name → Array Simps.ParsedProjectionData → Lean.CoreM Unit
Checks if there are declarations in the current file in the namespace {str}.Simps that are
not used.
def Simps.findAutomaticProjectionsAux E0 #
Lean.Name → Simps.ParsedProjectionData → Array Lean.Expr → Lean.Elab.TermElabM (Option (Lean.Expr × Lean.Name))
If a structure has a field that corresponds to a coercion to functions or sets, or corresponds to notation, find the custom projection that uses this coercion or notation. Returns the custom projection and the name of the projection used.
We catch most errors this function causes, so that we don't fail if an unrelated projection has
an applicable name. (e.g. Iso.inv)
Implementation note: getting rid of TermElabM is tricky, since Expr.mkAppOptM doesn't allow to
keep metavariables around, which are necessary for OutParam.
def Simps.findAutomaticProjections E1 #
Lean.Name → Array Simps.ParsedProjectionData → Lean.CoreM (Array Simps.ParsedProjectionData)
Auxiliary function for getRawProjections.
Find custom projections, automatically found by simps.
These come from DFunLike and SetLike instances.
def Simps.getRawProjections E1 #
Lean.Syntax →
Lean.Name →
optParam Bool false →
optParam (Array Simps.ProjectionRule) #[] →
optParam Bool false → Lean.CoreM (List Lean.Name × Array Simps.ProjectionData)
Get the projections used by simps associated to a given structure str.
The returned information is also stored in the environment extension Simps.structureExt, which
is given to str. If str already has this attribute, the information is read from this
extension instead. See the documentation for this extension for the data this tactic returns.
The returned universe levels are the universe levels of the structure. For the projections there are three cases
- If the declaration
{StructureName}.Simps.{projectionName}has been declared, then the value of this declaration is used (after checking that it is definitionally equal to the actual projection). If you rename the projection name, the declaration should have the new projection name. - You can also declare a custom projection that is a composite of multiple projections.
- Otherwise, for every class with the
notation_classattribute, and the structure has an instance of that notation class, then the projection of that notation class is used for the projection that is definitionally equal to it (if there is such a projection). This means in practice that coercions to function types and sorts will be used instead of a projection, if this coercion is definitionally equal to a projection. Furthermore, for notation classes likeMulandZerothose projections are used instead of the corresponding projection. Projections for coercions and notation classes are not automatically generated if they are composites of multiple projections (for example when you useextendwithout theoldStructureCmd(does this exist?)). - Otherwise, the projection of the structure is chosen.
For example:
getRawProjections env `Prodgives the default projections.([u, v], [(`fst, `(Prod.fst.{u v}), [0], true, false), (`snd, `(@Prod.snd.{u v}), [1], true, false)])
Optionally, this command accepts three optional arguments:
- If
traceIfExiststhe command will always generate a trace message when the structure already has an entry instructureExt. - The
rulesargument specifies whether projections should be added, renamed, used as prefix, and not used by default. - if
trcis true, this tactic will trace information just as ifset_option trace.simps.verbose truewas set.
def LibraryNote.custom_simps_projection E1 #
Batteries.Util.LibraryNote
You can specify custom projections for the @[simps] attribute.
To do this for the projection MyStructure.originalProjection by adding a declaration
MyStructure.Simps.myProjection that is definitionally equal to
MyStructure.originalProjection but has the projection in the desired (simp-normal) form.
Then you can call
initialize_simps_projections (originalProjection → myProjection, ...)
to register this projection. See elabInitializeSimpsProjections for more information.
You can also specify custom projections that are definitionally equal to a composite of multiple
projections. This is often desirable when extending structures (without oldStructureCmd).
CoeFun and notation class (like Mul) instances will be automatically used, if they
are definitionally equal to a projection of the structure (but not when they are equal to the
composite of multiple projections).
def Simps.elabSimpsRule E1 #
Lean.Syntax → Lean.Elab.Command.CommandElabM Simps.ProjectionRule
Parse a rule for initialize_simps_projections. It is <name>→<name>, -<name>, +<name>
or as_prefix <name>.
def Simps.elabInitializeSimpsProjections E1 #
Lean.Elab.Command.CommandElab
Function elaborating initialize_simps_projections.
structure Simps.Config E1 #
Type
Configuration options for @[simps]
ctor Simps.Config.mk E0 #
Bool →
Array Lean.Elab.Attribute →
Bool →
Bool →
Lean.Meta.TransparencyMode →
Lean.Meta.TransparencyMode → Bool → List Lean.Name → Bool → Option String → Simps.Config
abbrev Simps.Config.isSimp E1 #
Simps.Config → Bool
Make generated lemmas simp lemmas
abbrev Simps.Config.attrs E1 #
Simps.Config → Array Lean.Elab.Attribute
Other attributes to apply to generated lemmas.
abbrev Simps.Config.simpRhs E1 #
Simps.Config → Bool
simplify the right-hand side of generated simp-lemmas using dsimp, simp.
abbrev Simps.Config.dsimpLhs E1 #
Simps.Config → Bool
simplify the left-hand side of the generated lemmas using dsimp.
abbrev Simps.Config.typeMd E1 #
Simps.Config → Lean.Meta.TransparencyMode
TransparencyMode used to reduce the type in order to detect whether it is a structure.
abbrev Simps.Config.rhsMd E1 #
Simps.Config → Lean.Meta.TransparencyMode
TransparencyMode used to reduce the right-hand side in order to detect whether it is a
constructor. Note: was none in Lean 3
abbrev Simps.Config.fullyApplied E1 #
Simps.Config → Bool
Generated lemmas that are fully applied, i.e. generates equalities between applied functions.
Set this to false to generate equalities between functions.
abbrev Simps.Config.notRecursive E1 #
Simps.Config → List Lean.Name
List of types in which we are not recursing to generate simplification lemmas.
E.g. if we write @[simps] def e : α × β ≃ β × α := ... we will generate e_apply and not
e_apply_fst.
abbrev Simps.Config.debug E1 #
Simps.Config → Bool
Output debug messages. Not used much, use set_option simps.debug true instead.
abbrev Simps.Config.nameStem E1 #
Simps.Config → Option String
The stem to use for the projection names. If none, the default, use the suffix of the
current declaration name, or the empty string if the declaration is an instance and the instance
is named according to the inst convention.
instance Simps.instInhabitedConfig E0 #
Inhabited Simps.Config
def Simps.elabSimpsConfig E1 #
Lean.Syntax → optParam Simps.Config { } → optParam Bool false → Lean.CoreM Simps.Config
Function elaborating Config.
def Lean.Expr.instantiateLambdasOrApps E1 #
Array Lean.Expr → Lean.Expr → Lean.Expr
instantiateLambdasOrApps es e instantiates lambdas in e by expressions from es.
If the length of es is larger than the number of lambdas in e,
then the term is applied to the remaining terms.
Also reduces head let-expressions in e, including those after instantiating all lambdas.
This is very similar to expr.substs, but this also reduces head let-expressions.
def Simps.getProjectionExprs E1 #
Lean.Syntax → Lean.Expr → Lean.Expr → Simps.Config → Lean.MetaM (Array (Lean.Expr × Simps.ProjectionData))
Get the projections of a structure used by @[simps] applied to the appropriate arguments.
Returns a list of tuples
(corresponding right-hand-side, given projection name, projection Expression,
future projection numbers, used by default, is prefix)
(where all fields except the first are packed in a ProjectionData structure)
one for each projection. The given projection name is the name for the projection used by the user
used to generate (and parse) projection names. For example, in the structure
Example 1: getProjectionExprs env `(α × β) `(⟨x, y⟩) will give the output
[(`(x), `fst, `(@Prod.fst.{u v} α β), [], true, false),
(`(y), `snd, `(@Prod.snd.{u v} α β), [], true, false)]
Example 2: getProjectionExprs env `(α ≃ α) `(⟨id, id, fun _ ↦ rfl, fun _ ↦ rfl⟩)
will give the output
[(`(id), `apply, (Equiv.toFun), [], true, false),
(`(id), `symm_apply, (fun e ↦ e.symm.toFun), [], true, false),
...,
...]
def Simps.addProjection E1 #
Lean.Syntax →
List Lean.Name → Lean.Name → Lean.Expr → Lean.Expr → Lean.Expr → Array Lean.Expr → Simps.Config → Lean.MetaM Unit
Add a lemma with nm stating that lhs = rhs. type is the type of both lhs and rhs,
args is the list of local constants occurring, and univs is the list of universe variables.
opaque Simps.headStructureEtaReduce E1 #
Lean.Expr → Lean.MetaM Lean.Expr
Perform head-structure-eta-reduction on expression e. That is, if e is of the form
⟨f.1, f.2, ..., f.n⟩ with f definitionally equal to e, then
headStructureEtaReduce e = headStructureEtaReduce f and headStructureEtaReduce e = e otherwise.
def simpsTac E1 #
Lean.Syntax →
Lean.Name →
optParam Simps.Config { } →
optParam (List (String × Lean.Syntax)) [] → optParam Bool false → Lean.AttrM (Array Lean.Name)
simpsTac derives simp lemmas for all (nested) non-Prop projections of the declaration.
If todo is non-empty, it will generate exactly the names in todo.
If shortNm is true, the generated names will only use the last projection name.
If trc is true, trace as if trace.simps is true.
def simpsTacFromSyntax E1 #
Lean.Name → Lean.Syntax → Lean.AttrM (Array Lean.Name)
elaborate the syntax and run simpsTac.
opaque simpsAttr E1 #
Lean.ParametricAttribute (Array Lean.Name)
The simps attribute.