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 forsimps_attrandsimps_cfgfor more details and configuration options.@[_simps_str]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, likehas_mulandhas_zero. This specifies that the projections that@[simps]used are the projections from these notation classes instead of the projections of the superclasses. Example: ifhas_mulis tagged with@[notation_class]then the projection used forsemigroupwill beλ α hα, @has_mul.mul α (@semigroup.to_has_mul α hα)instead of@semigroup.mul.
Tags #
structures, projections, simp, simplifier, generates declarations
The type of rules that specify how metadata for projections in changes.
See initialize_simps_projection.
- attrs : list name
- simp_rhs : bool
- type_md : tactic.transparency
- rhs_md : tactic.transparency
- fully_applied : bool
- not_recursive : list name
- trace : bool
- add_additive : option name
Configuration options for the @[simps] attribute.
attrsspecifies the list of attributes given to the generated lemmas. Default:[`simp]. The attributes can be either basic attributes, or user attributes without parameters. There are two attributes whichsimpsmight add itself:- If
[`simp]is in the list, then[`_refl_lemma]is added automatically if appropriate. - If the definition is marked with
@[to_additive ...]then all generated lemmas are marked with@[to_additive]. This is governed by theadd_additiveconfiguration option.
- If
- if
simp_rhsisttthen the right-hand-side of the generated lemmas will be put in simp-normal form. More precisely:dsimp, simpwill be called on all these expressions. See note [dsimp, simp]. type_mdspecifies how aggressively definitions are unfolded in the type of expressions for the purposes of finding out whether the type is a function type. Default:instances. This will unfold coercion instances (so that a coercion to a function type is recognized as a function type), but not declarations likeset.rhs_mdspecifies how aggressively definition in the declaration are unfolded for the purposes of finding out whether it is a constructor. Default:noneException:@[simps]will automatically add the options{rhs_md := semireducible, simp_rhs := tt}if the given definition is not a constructor with the given reducibility setting forrhs_md.- If
fully_appliedisffthen the generatedsimplemmas will be between non-fully applied terms, i.e. equalities between functions. This does not restrict the recursive behavior of@[simps], so only the "final" projection will be non-fully applied. However, it can be used in combination with explicit field names, to get a partially applied intermediate projection. - The option
not_recursivecontains the list of names of types for which@[simps]doesn't recursively apply projections. For example, given an equivalenceα × β ≃ β × αone usually wants to only apply the projections forequiv, and not also those for×. This option is only relevant if no explicit projection names are given as argument to@[simps]. - The option
traceis set tottwhen you write@[simps?]. In this case, the attribute will print all generated lemmas. It is almost the same as setting the optiontrace.simps.verbose, except that it doesn't print information about the found projections. - if
add_additiveissome nmthen@[to_additive]is added to the generated lemma. This option is automatically set tottwhen the original declaration was tagged with@[to_additive, simps](in that order), wherenmis the additive name of the original declaration.
A common configuration for @[simps]: generate equalities between functions instead equalities
between fully applied expressions.
Equations
- as_fn = {attrs := [name.mk_string "simp" name.anonymous], simp_rhs := ff, type_md := tactic.transparency.instances, rhs_md := tactic.transparency.none, fully_applied := ff, not_recursive := [name.mk_string "prod" name.anonymous, name.mk_string "pprod" name.anonymous], trace := ff, add_additive := none name}
A common configuration for @[simps]: don't tag the generated lemmas with @[simp].
Equations
- lemmas_only = {attrs := list.nil name, simp_rhs := ff, type_md := tactic.transparency.instances, rhs_md := tactic.transparency.none, fully_applied := tt, not_recursive := [name.mk_string "prod" name.anonymous, name.mk_string "pprod" name.anonymous], trace := ff, add_additive := none name}