The areas / V01. The language of Mathlib
Mathlib.Util.AtomM.Recurse
25 declarations. Mathlib docs · Source
Running AtomM metaprograms recursively
Tactics such as ring and abel are implemented using the AtomM monad, which tracks "atoms" --
expressions which cannot be further parsed according to the arithmetic operations they handle --
to allow for consistent normalization relative to these atoms.
This file provides methods to allow for such normalization to run recursively: the atoms themselves
will have the normalization run on any of their subterms for which this makes sense. For example,
given an implementation of ring-normalization, the methods in this file implement the bottom-to-top
recursive ring-normalization in which sin (x + y) + sin (y + x) is normalized first to
sin (x + y) + sin (x + y) and then to 2 * sin (x + y).
Main declarations
-
Mathlib.Tactic.AtomM.RecurseM.run: run a metaprogram (inAtomMor its slight extensionAtomM.RecurseM), with atoms normalized according to a provided normalization operation (inAtomM), run recursively. -
Mathlib.Tactic.AtomM.recurse: run a normalization operation (inAtomM) recursively on an expression.
theorem Mathlib.Tactic.AtomM.Recurse.Config.mk.inj E1 #
∀ {red : Lean.Meta.TransparencyMode} {zetaDelta contextual : Bool} {red_1 : Lean.Meta.TransparencyMode}
{zetaDelta_1 contextual_1 : Bool},
{ red := red, zetaDelta := zetaDelta, contextual := contextual } =
{ red := red_1, zetaDelta := zetaDelta_1, contextual := contextual_1 } →
red = red_1 ∧ zetaDelta = zetaDelta_1 ∧ contextual = contextual_1
def Mathlib.Tactic.AtomM.Recurse.instInhabitedConfig.default E1 #
Mathlib.Tactic.AtomM.Recurse.Config
theorem Mathlib.Tactic.AtomM.Recurse.Context.mk.injEq E0 #
∀ (ctx : Lean.Meta.Simp.Context) (simp : Lean.Meta.Simp.Result → Lean.MetaM Lean.Meta.Simp.Result)
(ctx_1 : Lean.Meta.Simp.Context) (simp_1 : Lean.Meta.Simp.Result → Lean.MetaM Lean.Meta.Simp.Result),
({ ctx := ctx, simp := simp } = { ctx := ctx_1, simp := simp_1 }) = (ctx = ctx_1 ∧ simp = simp_1)
theorem Mathlib.Tactic.AtomM.Recurse.Config.mk.injEq E0 #
∀ (red : Lean.Meta.TransparencyMode) (zetaDelta contextual : Bool) (red_1 : Lean.Meta.TransparencyMode)
(zetaDelta_1 contextual_1 : Bool),
({ red := red, zetaDelta := zetaDelta, contextual := contextual } =
{ red := red_1, zetaDelta := zetaDelta_1, contextual := contextual_1 }) =
(red = red_1 ∧ zetaDelta = zetaDelta_1 ∧ contextual = contextual_1)
theorem Mathlib.Tactic.AtomM.Recurse.Context.mk.inj E1 #
∀ {ctx : Lean.Meta.Simp.Context} {simp : Lean.Meta.Simp.Result → Lean.MetaM Lean.Meta.Simp.Result}
{ctx_1 : Lean.Meta.Simp.Context} {simp_1 : Lean.Meta.Simp.Result → Lean.MetaM Lean.Meta.Simp.Result},
{ ctx := ctx, simp := simp } = { ctx := ctx_1, simp := simp_1 } → ctx = ctx_1 ∧ simp = simp_1
def Mathlib.Tactic.AtomM.Recurse.Config.ctorIdx E1 #
Mathlib.Tactic.AtomM.Recurse.Config → ℕ
def Mathlib.Tactic.AtomM.Recurse.Context.ctorIdx E1 #
Mathlib.Tactic.AtomM.Recurse.Context → ℕ
structure Mathlib.Tactic.AtomM.Recurse.Config E1 #
Type
Configuration for AtomM.Recurse.
ctor Mathlib.Tactic.AtomM.Recurse.Config.mk E0 #
Lean.Meta.TransparencyMode → Bool → Bool → Mathlib.Tactic.AtomM.Recurse.Config
abbrev Mathlib.Tactic.AtomM.Recurse.Config.red E1 #
Mathlib.Tactic.AtomM.Recurse.Config → Lean.Meta.TransparencyMode
the reducibility setting to use when comparing atoms for defeq
abbrev Mathlib.Tactic.AtomM.Recurse.Config.zetaDelta E1 #
Mathlib.Tactic.AtomM.Recurse.Config → Bool
if true, local let variables can be unfolded
abbrev Mathlib.Tactic.AtomM.Recurse.Config.contextual E1 #
Mathlib.Tactic.AtomM.Recurse.Config → Bool
if true, implication hypotheses are added to the local context of the discharger
def Mathlib.Tactic.AtomM.Recurse.instBEqConfig.beq E1 #
Mathlib.Tactic.AtomM.Recurse.Config → Mathlib.Tactic.AtomM.Recurse.Config → Bool
def Mathlib.Tactic.AtomM.Recurse.instReprConfig.repr E1 #
Mathlib.Tactic.AtomM.Recurse.Config → ℕ → Std.Format
instance Mathlib.Tactic.AtomM.Recurse.instInhabitedConfig E0 #
Inhabited Mathlib.Tactic.AtomM.Recurse.Config
instance Mathlib.Tactic.AtomM.Recurse.instReprConfig E0 #
Repr Mathlib.Tactic.AtomM.Recurse.Config
instance Mathlib.Tactic.AtomM.Recurse.instBEqConfig E0 #
BEq Mathlib.Tactic.AtomM.Recurse.Config
structure Mathlib.Tactic.AtomM.Recurse.Context E1 #
Type
The read-only state of the AtomM.Recurse monad.
ctor Mathlib.Tactic.AtomM.Recurse.Context.mk E0 #
Lean.Meta.Simp.Context →
(Lean.Meta.Simp.Result → Lean.MetaM Lean.Meta.Simp.Result) → Mathlib.Tactic.AtomM.Recurse.Context
abbrev Mathlib.Tactic.AtomM.Recurse.Context.ctx E1 #
Mathlib.Tactic.AtomM.Recurse.Context → Lean.Meta.Simp.Context
A basically empty simp context, passed to the simp traversal in AtomM.onSubexpressions.
abbrev Mathlib.Tactic.AtomM.Recurse.Context.simp E1 #
Mathlib.Tactic.AtomM.Recurse.Context → Lean.Meta.Simp.Result → Lean.MetaM Lean.Meta.Simp.Result
A cleanup routine, which simplifies evaluation results to a more human-friendly format.
abbrev Mathlib.Tactic.AtomM.RecurseM E3 #
Type → Type
The monad for AtomM.Recurse contains, in addition to the AtomM state,
a simp context for the main traversal and a cleanup function to simplify evaluation results.
def Mathlib.Tactic.AtomM.onSubexpressions E1 #
(Lean.Expr → Mathlib.Tactic.AtomM Lean.Meta.Simp.Result) →
Lean.Expr → Bool → optParam Bool true → Mathlib.Tactic.AtomM.RecurseM Lean.Meta.Simp.Result
A tactic in the AtomM.RecurseM monad which will simplify expression parent to a normal form, by
running a core operation eval (in the AtomM monad) on the maximal subexpression(s) on which
eval does not fail.
There is also a subsequent clean-up operation, governed by the context from the AtomM.RecurseM
monad.
root: true if this is a direct call to the function.AtomM.RecurseM.runsets this tofalsein recursive mode.
def Mathlib.Tactic.AtomM.RecurseM.run E3 #
{α : Type} →
IO.Ref Mathlib.Tactic.AtomM.State →
Mathlib.Tactic.AtomM.Recurse.Config →
Bool →
(Lean.Expr → Mathlib.Tactic.AtomM Lean.Meta.Simp.Result) →
(Lean.Meta.Simp.Result → Lean.MetaM Lean.Meta.Simp.Result) → Mathlib.Tactic.AtomM.RecurseM α → Lean.MetaM α
Runs a tactic in the AtomM.RecurseM monad, given initial data:
s: a reference to the mutableAtomMstate, for persisting across calls. This ensures that atom ordering is used consistently.cfg: the configuration optionswellBehavedDischarge: MUST be set tofalseIFevalaccesses local declarations with index >=Context.lctxInitIndices. Reason: it would causesimpto cache results too aggressively.eval: a normalization operation which will be run recursively, potentially dependent on a known atom orderingsimp: a cleanup operation which will be used to post-process expressionsx: the tactic to run
def Mathlib.Tactic.AtomM.recurse E3 #
IO.Ref Mathlib.Tactic.AtomM.State →
Mathlib.Tactic.AtomM.Recurse.Config →
Bool →
(Lean.Expr → Mathlib.Tactic.AtomM Lean.Meta.Simp.Result) →
(Lean.Meta.Simp.Result → Lean.MetaM Lean.Meta.Simp.Result) → Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result
Normalizes an expression, given initial data:
s: a reference to the mutableAtomMstate, for persisting across calls. This ensures that atom ordering is used consistently.cfg: the configuration optionswellBehavedDischarge: MUST be set tofalseIFevalaccesses local declarations with index >=Context.lctxInitIndices. Reason: it would causesimpto cache results too aggressively.eval: a normalization operation which will be run recursively, potentially dependent on a known atom orderingsimp: a cleanup operation which will be used to post-process expressionstgt: the expression to normalize