The areas / V01. The language of Mathlib
Mathlib.Util.AtomM
22 declarations. Mathlib docs · Source
A monad for tracking and deduplicating atoms
This monad is used by tactics like ring and abel to keep uninterpreted atoms in a consistent
order, and also to allow unifying atoms up to a specified transparency mode.
Note: this can become very expensive because it is using isDefEq.
For performance reasons, consider whether Lean.Meta.Canonicalizer.canon can be used instead.
After canonicalizing, a HashMap Expr Nat suffices to keep track of previously seen atoms,
and is much faster as it uses Expr equality rather than isDefEq.
theorem Mathlib.Tactic.AtomM.Context.mk.injEq E0 #
∀ (red : Lean.Meta.TransparencyMode) (evalAtom : Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result)
(red_1 : Lean.Meta.TransparencyMode) (evalAtom_1 : Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result),
({ red := red, evalAtom := evalAtom } = { red := red_1, evalAtom := evalAtom_1 }) =
(red = red_1 ∧ evalAtom = evalAtom_1)
theorem Mathlib.Tactic.AtomM.Context.mk.inj E1 #
∀ {red : Lean.Meta.TransparencyMode} {evalAtom : Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result}
{red_1 : Lean.Meta.TransparencyMode} {evalAtom_1 : Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result},
{ red := red, evalAtom := evalAtom } = { red := red_1, evalAtom := evalAtom_1 } → red = red_1 ∧ evalAtom = evalAtom_1
def Mathlib.Tactic.AtomM.Context.ctorIdx E1 #
Mathlib.Tactic.AtomM.Context → ℕ
theorem Mathlib.Tactic.AtomM.State.mk.injEq E0 #
∀ (atoms atoms_1 : Array Lean.Expr), ({ atoms := atoms } = { atoms := atoms_1 }) = (atoms = atoms_1)
def Mathlib.Tactic.AtomM.State.ctorIdx E1 #
Mathlib.Tactic.AtomM.State → ℕ
theorem Mathlib.Tactic.AtomM.State.mk.inj E1 #
∀ {atoms atoms_1 : Array Lean.Expr}, { atoms := atoms } = { atoms := atoms_1 } → atoms = atoms_1
def Mathlib.Tactic.AtomM.instInhabitedContext.default E1 #
Mathlib.Tactic.AtomM.Context
structure Mathlib.Tactic.AtomM.Context E1 #
Type
The context (read-only state) of the AtomM monad.
ctor Mathlib.Tactic.AtomM.Context.mk E0 #
Lean.Meta.TransparencyMode → (Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result) → Mathlib.Tactic.AtomM.Context
abbrev Mathlib.Tactic.AtomM.Context.red E1 #
Mathlib.Tactic.AtomM.Context → Lean.Meta.TransparencyMode
The reducibility setting for definitional equality of atoms
abbrev Mathlib.Tactic.AtomM.Context.evalAtom E1 #
Mathlib.Tactic.AtomM.Context → Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result
A simplification to apply to atomic expressions when they are encountered, before interning them in the atom list.
instance Mathlib.Tactic.AtomM.instInhabitedContext E0 #
Inhabited Mathlib.Tactic.AtomM.Context
structure Mathlib.Tactic.AtomM.State E1 #
Type
The mutable state of the AtomM monad.
ctor Mathlib.Tactic.AtomM.State.mk E0 #
Array Lean.Expr → Mathlib.Tactic.AtomM.State
abbrev Mathlib.Tactic.AtomM.State.atoms E1 #
Mathlib.Tactic.AtomM.State → Array Lean.Expr
The list of atoms-up-to-defeq encountered thus far, used for atom sorting.
abbrev Mathlib.Tactic.AtomM E1 #
Type → Type
The monad that ring works in. This is only used for collecting atoms.
def Mathlib.Tactic.AtomM.run E1 #
{α : Type} →
Lean.Meta.TransparencyMode →
Mathlib.Tactic.AtomM α →
(optParam (Lean.Expr → Lean.MetaM Lean.Meta.Simp.Result) fun e ↦ pure { expr := e }) → Lean.MetaM α
Run a computation in the AtomM monad.
def Mathlib.Tactic.isDefEqSafe E1 #
Lean.Expr → Lean.Expr → Lean.MetaM Bool
A safe version of isDefEq that doesn't throw errors. We use it to avoid
"unknown free variable _fvar.102937" errors when there may be out-of-scope free variables.
TODO: don't catch any other errors
def Mathlib.Tactic.AtomM.containsThenAdd E1 #
Lean.Expr → Mathlib.Tactic.AtomM (Bool × ℕ × Lean.Expr)
If an atomic expression has already been encountered, return true, the index and the stored
form of the atom (which will be defeq at the specified transparency, but not necessarily
syntactically equal). If the atomic expression has not already been encountered, store it in the
list of atoms, and return the new index (and the stored form of the atom, which will be itself).
In a normalizing tactic, the expression returned by containsThenAdd should be considered
the normal form.
def Mathlib.Tactic.AtomM.containsThenAddQ E1 #
{u : Lean.Level} → {α : Q(Type u)} → (e : Q(«$α»)) → Mathlib.Tactic.AtomM (Bool × ℕ × { e' // «$e» =Q «$e'» })
If an atomic expression has already been encountered, return true, the index and the stored
form of the atom (which will be defeq at the specified transparency, but not necessarily
syntactically equal). If the atomic expression has not already been encountered, store it in the
list of atoms, and return the new index (and the stored form of the atom, which will be itself).
In a normalizing tactic, the expression returned by AtomM.containsThenAddQ should be considered
the normal form.
This is a strongly-typed version of AtomM.containsThenAdd for code using Qq.
def Mathlib.Tactic.AtomM.addAtom E1 #
Lean.Expr → Mathlib.Tactic.AtomM (ℕ × Lean.Expr)
If an atomic expression has already been encountered, get the index and the stored form of the atom (which will be defeq at the specified transparency, but not necessarily syntactically equal). If the atomic expression has not already been encountered, store it in the list of atoms, and return the new index (and the stored form of the atom, which will be itself).
In a normalizing tactic, the expression returned by addAtom should be considered the normal form.
def Mathlib.Tactic.AtomM.addAtomQ E1 #
{u : Lean.Level} → {α : Q(Type u)} → (e : Q(«$α»)) → Mathlib.Tactic.AtomM (ℕ × { e' // «$e» =Q «$e'» })
If an atomic expression has already been encountered, get the index and the stored form of the atom (which will be defeq at the specified transparency, but not necessarily syntactically equal). If the atomic expression has not already been encountered, store it in the list of atoms, and return the new index (and the stored form of the atom, which will be itself).
In a normalizing tactic, the expression returned by addAtomQ should be considered the normal form.
This is a strongly-typed version of AtomM.addAtom for code using Qq.