Sym Extensions #
Extensible state mechanism for SymM, allowing modules to register persistent state
that lives across simp invocations within a sym => block. Follows the same pattern
as Grind.SolverExtension in Lean/Meta/Tactic/Grind/Types.lean.
Opaque extension state type used to store type-erased extension values.
Instances For
A registered extension for SymM. Each extension gets a unique index into the
extensions array in Sym.State. Can only be created via registerSymExtension.
Instances For
Equations
Registers a new SymM state extension. Extensions can only be registered during initialization.
Returns a handle for typed access to the extension's state.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns initial state for all registered extensions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Information about a single argument position in a function's type signature.
This is used during pattern matching and structural definitional equality tests to identify arguments that can be skipped or handled specially (e.g., instance arguments can be synthesized, proof arguments can be inferred).
- isProof : Bool
trueif this argument is a proof (its type is aProp). - isInstance : Bool
trueif this argument is a type class instance.
Instances For
Information about a function symbol. It stores which argument positions are proofs or instances, enabling optimizations during pattern matching and structural definitional equality tests such as skipping proof arguments or deferring instance synthesis.
- argsInfo : Array ProofInstArgInfo
Information about each argument position.
Instances For
Equations
Information on how to build congruence proofs for function applications. This enables efficient rewriting of subterms without repeatedly inferring types or instances.
- none : CongrInfo
None of the arguments of the function can be rewritten.
- fixedPrefix
(prefixSize suffixSize : Nat)
: CongrInfo
For functions with a fixed prefix of implicit/instance arguments followed by explicit non-dependent arguments that can be rewritten independently.
prefixSize: Number of leading arguments (types, instances) that are determined by the suffix arguments and should not be rewritten directly.suffixSize: Number of trailing arguments that can be rewritten using simple congruence.
Examples (showing
prefixSize,suffixSize): - interlaced
(rewritable : Array Bool)
: CongrInfo
For functions with interlaced rewritable and non-rewritable arguments. Each element indicates whether the corresponding argument position can be rewritten.
Example: For
HEq {α : Sort u} (a : α) {β : Sort u} (b : β), the mask would be#[false, true, false, true]— we can rewriteaandb, but notαorβ. - congrTheorem
(thm : CongrTheorem)
: CongrInfo
For functions that have proofs and
Decidablearguments. For this kind of function we generate a custom theorem. Example:Array.eraseIdx {α : Type u} (xs : Array α) (i : Nat) (h : i < xs.size) : Array α. The proof argumenthdepends onxsandi. To be able to rewritexsandi, we use the auto-generated theorem.Array.eraseIdx.congr_simp {α : Type u} (xs xs' : Array α) (e_xs : xs = xs') (i i' : Nat) (e_i : i = i') (h : i < xs.size) : xs.eraseIdx i h = xs'.eraseIdx i' ⋯
Instances For
Configuration options for the symbolic computation framework.
- verbose : Bool
When
true, issues are collected during proof search and reported on failure. - enforceUnfoldReducible : Bool
When
true,shareCommonmaintains theSymMinvariant that reducible constants have been eagerly unfolded: if a new term contains one,shareCommonunfolds it before adding the term to the table of maximally shared terms. - enforceFoldProjs : Bool
When
true,shareCommonmaintains theSymMinvariant that kernel projections have been folded into projection function applications: if a new term contains one,shareCommonfolds it before adding the term to the table of maximally shared terms.cbvdisables this check because it processes kernel projections natively.
Instances For
Equations
- cache : Std.HashMap Expr Expr
Cache for value-level canonicalization (no type reductions applied).
- cacheInType : Std.HashMap Expr Expr
Cache for type-level canonicalization (reductions applied).
Instances For
Mutable state for the symbolic computation framework.
Maps expressions to their maximal free variable (by declaration index).
maxFVar[e] = some fvarIdmeansfvarIdis the free variable with the largest declaration index occurring ine.maxFVar[e] = nonemeansecontains no free variables (but may contain metavariables).
Recall that if
econtains a metavariable?m, then we assumeemay contain any free variable in the local context associated with?m.This mapping enables O(1) local context compatibility checks during metavariable assignment. Instead of traversing local contexts with
isSubPrefixOf, we check if the maximal free variable in the assigned value is in scope of the metavariable's local context.Note: We considered using a mapping
PHashMap ExprPtr FVarId. However, there is a corner case that is not supported by this representation.econtains a metavariable (with an empty local context), and no free variables.- proofInstInfo : PHashMap Name (Option ProofInstInfo)
Cache for
getLevelresults, keyed by pointer equality.Cache for
isDefEqIresults- extensions : Array SymExtensionState
State for registered
SymExtensions, indexed by extension id. - issues : List MessageData
Issues found during symbolic computation. Accumulated across operations within a
sym =>block and reported when a tactic fails. - canon : Canon.State
Instances registered by satellite modules for types they create themselves (e.g.,
grind linarith's envelope typeIntModule.OfNatModule.Q).Sym.synthInstance?consults this table (keyed by the instance type, structural equality) before running typeclass resolution. This both skips searches whose results are known in advance, and ensures the registered term is used as the canonical representative.We currently use this table to reduce the overhead of type class resolution in
grind.- debug : Bool
Instances For
Equations
Instances For
Auxiliary function for implementing unfoldReducible and unfoldReducibleSimproc.
Performs a single step.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Unfolds all reducible declarations occurring in e.
This is meant as a preprocessing step. It does not guarantee maximally shared terms
Equations
- One or more equations did not get rendered due to their size.
Instances For
Converts nested Expr.projs into projection applications if possible.
The structural simplifier and pattern matcher do not handle kernel projection
terms; this preprocessing step folds them into projection function applications.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns the internalized True constant.
Equations
- Lean.Meta.Sym.getTrueExpr = do let __do_lift ← Lean.Meta.Sym.getSharedExprs pure __do_lift.trueExpr
Instances For
Returns true if e is the internalized True expression.
Equations
- Lean.Meta.Sym.isTrueExpr e = do let __do_lift ← Lean.Meta.Sym.getTrueExpr pure (Lean.Meta.Sym.isSameExpr e __do_lift)
Instances For
Returns the internalized False constant.
Equations
- Lean.Meta.Sym.getFalseExpr = do let __do_lift ← Lean.Meta.Sym.getSharedExprs pure __do_lift.falseExpr
Instances For
Returns true if e is the internalized False expression.
Equations
- Lean.Meta.Sym.isFalseExpr e = do let __do_lift ← Lean.Meta.Sym.getFalseExpr pure (Lean.Meta.Sym.isSameExpr e __do_lift)
Instances For
Returns the internalized Bool.true.
Equations
- Lean.Meta.Sym.getBoolTrueExpr = do let __do_lift ← Lean.Meta.Sym.getSharedExprs pure __do_lift.btrueExpr
Instances For
Returns true if e is the internalized Bool.true expression.
Equations
- Lean.Meta.Sym.isBoolTrueExpr e = do let __do_lift ← Lean.Meta.Sym.getBoolTrueExpr pure (Lean.Meta.Sym.isSameExpr e __do_lift)
Instances For
Returns the internalized Bool.false.
Equations
- Lean.Meta.Sym.getBoolFalseExpr = do let __do_lift ← Lean.Meta.Sym.getSharedExprs pure __do_lift.bfalseExpr
Instances For
Returns true if e is the internalized Bool.false expression.
Equations
- Lean.Meta.Sym.isBoolFalseExpr e = do let __do_lift ← Lean.Meta.Sym.getBoolFalseExpr pure (Lean.Meta.Sym.isSameExpr e __do_lift)
Instances For
Returns the internalized 0 : Nat numeral.
Equations
- Lean.Meta.Sym.getNatZeroExpr = do let __do_lift ← Lean.Meta.Sym.getSharedExprs pure __do_lift.natZExpr
Instances For
Returns the internalized Ordering.eq.
Equations
- Lean.Meta.Sym.getOrderingEqExpr = do let __do_lift ← Lean.Meta.Sym.getSharedExprs pure __do_lift.ordEqExpr
Instances For
Returns the internalized Int.
Equations
- Lean.Meta.Sym.getIntExpr = do let __do_lift ← Lean.Meta.Sym.getSharedExprs pure __do_lift.intExpr
Instances For
Runs x with the shareCommon kernel-projection check disabled.
Use this to wrap code that temporarily violates the SymM folded-projections
invariant, e.g., a head reducer that exposes kernel projections in intermediate
terms and restores the invariant in its final result.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.Sym.getConfig = do let __do_lift ← readThe Lean.Meta.Sym.Context pure __do_lift.config
Instances For
Adds an issue message to the issue tracker.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reports an issue if verbose mode is enabled. Does nothing if verbose is false.
Equations
- Lean.Meta.Sym.reportIssueIfVerbose msg = do let __do_lift ← Lean.Meta.Sym.getConfig if __do_lift.verbose = true then Lean.Meta.Sym.reportIssue msg else pure ()
Instances For
Reports an issue if verbose mode is enabled.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Similar to reportIssue!, but only reports issue if sym.debug is set to true.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns all accumulated issues without clearing them.
Equations
- Lean.Meta.Sym.getIssues = do let __do_lift ← get pure __do_lift.issues
Instances For
Runs x with a fresh issue context. Issues reported during x are
prepended to the issues that existed before the call.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.Sym.instInhabitedSymM = { default := Lean.throwError (Lean.toMessageData "<SymM default value>") }
SymExtension accessors #
Equations
- ext.getState = do let __do_lift ← get liftM (ext.getStateCore __do_lift.extensions)