We use this auxiliary constant to mark delayed congruence proofs.
Equations
Instances For
We use this auxiliary constant to mark delayed symmetric congruence proofs.
Example: a = b is symmetrically congruent to c = d if a = d and b = c.
Note: We previously used congrPlaceholderProof for this case, but it
caused non-termination during proof term construction when a = b = c = d.
The issue was that we did not have enough information to determine how
a = b and c = d became congruent. The new marker resolves this issue.
If congrPlaceholderProof is used, then a = b became congruent to c = d
because a = c and b = d.
If eqCongrSymmPlaceholderProof is used, then it was because a = d and b = c.
Example: suppose we have the following equivalence class:
{p, q, p = q, q = p, True}
Recall that True is always the root of its equivalence class.
Assume we also have the following two paths in the class:
1. p -> p = q -> q = p -> True
2. q -> True
Now suppose we try to build a proof for p = True.
We must construct a proof for (p = q) = (q = p).
These equalities are congruent, but if we try to prove p = q and q = p
using the facts p = True and q = True, we end up trying to prove p = True again.
In other words, we are missing the information that p = q became congruent to q = p
because of the symmetric case. By using eqCongrSymmPlaceholderProof, we retain this information.
Equations
Instances For
Returns true if e is True, False, or a literal value.
See Lean.Meta.LitValues for supported literals.
Equations
Instances For
Opaque solver extension state.
Equations
Case-split source. That is, where it came from.
We store the current source in the grind context.
- ematch
(origin : Origin)
: SplitSource
Generated while instantiating a theorem using E-matching.
- ext
(declName : Name)
: SplitSource
Generated while instantiating an extensionality theorem with name
declName - mbtc
(a b : Expr)
(i : Nat)
: SplitSource
Model-based theory combination equality coming from the i-th argument of applications
aandb - beta
(e : Expr)
: SplitSource
Beta-reduction.
- forallProp
(e : Expr)
: SplitSource
Forall-propagator.
- existsProp
(e : Expr)
: SplitSource
Exists-propagator.
- input : SplitSource
Input goal
- inj
(origin : Origin)
: SplitSource
Injectivity theorem.
- guard
(origin : Origin)
: SplitSource
grind_patternguard
Instances For
Equations
Instances For
Context for GrindM monad.
- simp : Simp.Context
- simpMethods : Simp.Methods
- config : Grind.Config
If
anchorRefs? := some anchorRefs, then only local instances and case-splits inanchorRefsare considered.- cheapCases : Bool
If
cheapCasesistrue,grindonly appliescasesto types that contain at most one minor premise. Recall thatgrindappliescaseswhen introducing types tagged with[grind cases eager], and atSplit.leanRemark: We add this option to implement thelookaheadfeature, we don't want to create several subgoals when performing lookahead. - reportMVarIssue : Bool
- splitSource : SplitSource
Current source of case-splits.
- symPrios : SymbolPriorities
Symbol priorities for inferring E-matching patterns
- extensions : ExtensionStateArray
- debug : Bool
Instances For
Key for the congruence theorem cache.
Instances For
Equations
Number of times E-match theorem has been instantiated.
Number of times a
caseshas been performed on an inductive type/predicateNumber of applications per function symbol. This information is only collected if
set_option diagnostics true
Instances For
Case-split diagnostic information
- lctx : LocalContext
- c : Expr
- gen : Nat
- numCases : Nat
- splitSource : SplitSource
Instances For
State for the GrindM monad.
- congrThms : PHashMap CongrTheoremCacheKey CongrTheorem
Congruence theorems generated so far. Recall that for constant symbols we rely on the reserved name feature (i.e.,
mkHCongrWithArityForConst?). Remark: we currently do not reuse congruence theorems - simp : Simp.State
- lastTag : Name
Used to generate trace messages of the for
[grind] working on <tag>, and implement the macrotrace_goal. - issues : List MessageData
Issues found during the proof search. These issues are reported to users when
grindfails. - counters : Counters
Performance counters
- splitDiags : PArray SplitDiagInfo
Split diagnostic information. This information is only collected when
set_option diagnostics true Cached anchors (aka stable hash codes) for terms in the
grindstate.
Instances For
Restore backtrackable parts of the state.
Equations
Instances For
Equations
withoutReportingMVarIssues x executes x without reporting metavariables found during internalization.
See comment at Grind.Context.reportMVarIssue for additional details.
Equations
Instances For
withSplitSource s x executes x and uses s as the split source for any case-split
registered.
Equations
Instances For
Returns the user-defined configuration options
Equations
Instances For
Runs k with the transparency setting specified by Config.reducible.
Uses reducible transparency if reducible is true, otherwise default transparency.
Equations
Instances For
Equations
Instances For
Returns symbol priorities for inferring E-matching patterns.
Equations
Instances For
Returns true if declName is the name of a match equation or a match congruence equation.
Equations
Instances For
Equations
Instances For
Equations
Instances For
Returns maximum term generation that is considered during ematching.
Equations
Instances For
Similar to expandReportIssueMacro, but only reports issue if grind.debug is set to true
Equations
Instances For
Each E-node may have "solver terms" attached to them.
Each term is an element of the equivalence class that the
solver cares about. Each solver is responsible for marking the terms they care about.
The grind core propagates equalities and disequalities to the theory solvers
using these "marked" terms. The root of the equivalence class
contains a list of representatives sorted by solver id. Note that many E-nodes
do not have any solver terms attached to them.
"Solver terms" are referenced as "theory variables" in the SMT literature. The SMT solver Z3 uses a similar representation.
- nil : SolverTerms
- next (solverId : Nat) (e : Expr) (rest : SolverTerms) : SolverTerms
Instances For
Equations
Instances For
Stores information for a node in the E-graph.
Each internalized expression e has an ENode associated with it.
- self : Expr
Node represented by this ENode.
- next : Expr
Next element in the equivalence class.
- root : Expr
Root (aka canonical representative) of the equivalence class
- congr : Expr
- flipped : Bool
Proof has been flipped.
- size : Nat
Number of elements in the equivalence class, this field is meaningless if node is not the root.
- interpreted : Bool
interpreted := trueif node should be viewed as an abstract value. - ctor : Bool
ctor := trueif the head symbol is a constructor application. - hasLambdas : Bool
hasLambdas := trueif the equivalence class contains lambda expressions. - heqProofs : Bool
If
heqProofs := true, then some proofs in the equivalence class are based on heterogeneous equality. - idx : Nat
Unique index used for pretty printing and debugging purposes.
- generation : Nat
The generation in which this enode was created.
- mt : Nat
Modification time
- sTerms : SolverTerms
Solver terms attached to this E-node.
- funCC : Bool
Instances For
Key for the congruence table.
We need access to the enodes to be able to retrieve the equivalence class roots.
- e : Expr
Instances For
Equations
Equations
Equations
Instances For
Equations
Instances For
The E-matching module instantiates theorems using the EMatchTheorem proof and a (partial) assignment.
We want to avoid instantiating the same theorem with the same assignment more than once.
Therefore, we store the (pre-)instance information in set.
Recall that the proofs of activated theorems have been hash-consed.
The assignment contains internalized expressions, which have also been hash-consed.
Note: We used to use pointer equality to implement PreInstanceSet. However,
this low-level trick was incorrect in interactive mode because we add new
EMatchTheorem objects using instantiate [...]. For example, suppose we write
instantiate [thm_1]; instantiate [thm_1]
The EMatchTheorem object thm_1 is created twice. Using pointer equality will
miss instances created using the two different objects. Recall we do not use
hash-consing on proof objects. If we hash-cons the proof objects, it would be ok
to use pointer equality.
- proof : Expr
Instances For
New raw fact to be preprocessed, and then asserted.
- proof : Expr
- prop : Expr
- generation : Nat
- splitSource : SplitSource
splitSourceto use when internalizing this fact.
Instances For
Equations
Instances For
A delayed theorem instantiation is an instantiation that includes one or more guards.
See TheoremGuard.
- thm : EMatchTheorem
- proof : Expr
- prop : Expr
- generation : Nat
- guards : List TheoremGuard
Instances For
Equations
Instances For
E-matching related fields for the grind goal.
- thmMap : EMatchTheoremsArray
Inactive global theorems. As we internalize terms, we activate theorems as we find their symbols. Local theorem provided by users are added directly into
newThms. - gmt : Nat
Goal modification time.
- thms : PArray EMatchTheorem
Active theorems that we have performed ematching at least once.
- newThms : PArray EMatchTheorem
Active theorems that we have not performed any round of ematching yet.
- numInstances : Nat
Number of theorem instances generated so far.
- numDelayedInstances : Nat
Number of delayed theorem instances generated so far. We track them to decide whether E-match made progress or not.
- num : Nat
Number of E-matching rounds performed in this goal since the last case-split.
- preInstances : PreInstanceSet
(pre-)instances found so far. It includes instances that failed to be instantiated.
- nextThmIdx : Nat
Next local E-match theorem idx.
matchauxiliary functions whose equations have already been created and activated.- delayedThmInsts : PHashMap ExprPtr (List DelayedTheoremInstance)
Delayed instantiations is a mapping from guards to theorems that are waiting them to become
True.
Instances For
Case-split information.
- default
(e : Expr)
(source : SplitSource)
: SplitInfo
Term
emay be an inductive predicate,match-expression,if-expression, implication, etc. - imp
(e : Expr)
(h : e.isForall = true)
(source : SplitSource)
: SplitInfo
eis an implication and we want to split on its antecedent. - arg
(a b : Expr)
(i : Nat)
(eq : Expr)
(source : SplitSource)
: SplitInfo
Given applications
aandb, case-split on whether the correspondingi-th arguments are equal or not. The split is only performed if all other arguments are already known to be equal or are also tagged as split candidates.
Instances For
Case splitting related fields for the grind goal.
- num : Nat
Number of splits performed to get to this goal.
Case-split candidates.
- added : Std.HashSet SplitInfo
Case-splits that have been inserted at
candidatesat some point. Case-splits that have already been performed, or that do not have to be performed anymore.
Sequence of cases steps that generated this goal. We only use this information for diagnostics. Remark:
casesTrace.length ≥ numSplitsbecause we don't increase the counter forcasesapplications that generated only 1 subgoal.Lookahead "case-splits".
A mapping
(a, b) ↦ iss.t. for eachSplitInfo.arg a b i eqincandidatesorlookaheadswe havei ∈ is. We use this information to decide whether the split/lookahead is "ready" to be tried or not.
Instances For
State for injective theorem support.
- thms : InjectiveTheoremsArray
- fns : PHashMap ExprPtr InjectiveInfo
Instances For
The grind state for a goal, excluding the metavariable.
This separation from Goal allows multiple goals with different metavariables to share
the same GoalState. This is useful for automation such as symbolic simulation, where applying
theorems create multiple goals that inherit the same E-graph, congruence closure state, and other
accumulated facts.
- nextDeclIdx : Nat
Next local declaration index to process.
- canon : Canon.State
- enodeMap : ENodeMap
- parents : ParentMap
- congrTable : CongrTable self.enodeMap
A mapping from each function application index (
HeadIndex) to a list of applications with that index. Recall that theHeadIndexfor a constant is its constant name, and for a free variable, it is its unique id.Equations and propositions to be processed.
- inconsistent : Bool
inconsistent := trueifENodes forTrueandFalseare in the same equivalence class. - nextIdx : Nat
Next unique index for creating ENodes
- newRawFacts : Std.Queue NewRawFact
new facts to be preprocessed and then asserted.
Asserted facts
- extThms : PHashMap ExprPtr (Array Ext.ExtTheorem)
Cached extensionality theorems for types.
- ematch : EMatch.State
State of the E-matching module.
- inj : Injective.State
State of the injective function procedure.
- split : Split.State
State of the case-splitting module.
- clean : Clean.State
State of the clean name generator.
- sstates : Array SolverExtensionState
Solver states.
Instances For
A grind goal, combining shared state with a specific metavariable.
See GoalState for details on why the state is factored out.
Note: The Goal internal representation is just a pair GoalState and MVarId.
- congrTable : CongrTable self.enodeMap
- mvarId : MVarId
Instances For
Sets nextDeclIdx to point past the last local declaration in the local context.
This marks all existing local declarations as already processed by grind. Use this when
initializing a goal whose hypotheses should not be processed or after internalizing all of them.
Equations
Instances For
Returns true if the goal has local declarations that have not yet been processed by grind.
A local declaration is "pending" if its index is greater than or equal to nextDeclIdx.
This is used to determine whether grind needs to internalize new hypotheses.
Equations
Instances For
Macro similar to trace[...], but it includes the trace message trace[grind] "working on <current goal>"
if the tag has changed since the last trace message.
Equations
Instances For
Adds a new fact prop with proof proof to the queue for preprocessing and the assertion.
Equations
Instances For
Returns the number of theorem instances generated so far.
Equations
Instances For
Returns true if the maximum number of instances has been reached.
Equations
Instances For
Returns true if the maximum number of case-splits has been reached.
Equations
Instances For
Returns true if the maximum number of E-matching rounds has been reached.
Equations
Instances For
Equations
Instances For
Equations
Instances For
Returns the generation of the given term. Is assumes it has been internalized
Equations
Instances For
Returns true if a and b are in the same equivalence class.
Equations
Instances For
Returns true if the root of its equivalence class.
Equations
Instances For
Return true if a and b have the same type.
Equations
Instances For
Equations
Instances For
Records that parent is a parent of child. This function actually stores the
information in the root (aka canonical representative) of child.
Equations
Instances For
Return true if the goal is inconsistent.
Equations
Instances For
Returns a proof that a = b.
It assumes a and b are in the same equivalence class, and have the same type.
Returns a proof that a ≍ b.
It assumes a and b are in the same equivalence class.
Internalizes a local declaration which is not a proposition. Note: We must internalize local variables because their types may be empty, and may not be referenced anywhere else. Example:
example (a : { x : Int // x < 0 ∧ x > 0 }) : False := by grind
etaStruct may also be applicable.
Equations
Instances For
Returns a proof that a = b if they have the same type. Otherwise, returns a proof of a ≍ b.
It assumes a and b are in the same equivalence class.
Equations
Instances For
Returns a proof that a = Bool.false.
It assumes a and Bool.false are in the same equivalence class.
Equations
Instances For
goal.withContext x executes x using the given metavariable LocalContext and LocalInstances.
The type class resolution cache is flushed when executing x if its LocalInstances are
different from the current ones.
Equations
Instances For
Returns all enodes in the goal
Equations
Instances For
- propagateUp : Propagator
- propagateDown : Propagator
- evalTactic : EvalTactic
Instances For
Returns true if s has been already added to the case-split list at one point.
Remark: this function returns true even if the split has already been resolved
and is not in the list anymore.
Equations
Instances For
Marks e as a case-split that does not need to be performed anymore.
Remark: we currently use this feature to disable match-case-splits.
Remark: we also use this feature to record the case-splits that have already been performed.
Equations
Instances For
- ready : ActivateNextGuardResult
- next (guard : Expr) (pending : List TheoremGuard) : ActivateNextGuardResult
Instances For
Equations
Instances For
Adds a new theorem instance produced using E-matching.
Equations
Instances For
Equations
Instances For
Returns extensionality theorems for the given type if available.
If Config.ext is false, the result is #[].
Equations
Instances For
Add a new lookahead candidate.
Equations
Instances For
Action is the control interface for grind’s search steps. It is defined in
Continuation-Passing Style (CPS).
See Grind/Action.lean for additional details.
Result type for a grind Action
- closed
(seq : List TGrind)
: ActionResult
The goal has been closed, and you can use
seqto close the goal efficiently. - stuck
(gs : List Goal)
: ActionResult
The action could not make further progress.
gsare subgoals that could not be closed. They are used for producing error messages.
Instances For
Solver Extensions
Solver extension, can only be generated by registerSolverExtension that allocates a unique index
for this extension into each goal's extension state's array.
Instances For
Equations
Equations
Instances For
Registers a new solver extension for grind.
Solver extensions can only be registered during initialization.
Reason: We do not use any synchronization primitive to access solverExtensionsRef.
Equations
Instances For
Sets methods/handlers for solver extension ext.
Solver extension methods can only be registered during initialization.
Reason: We do not use any synchronization primitive to access solverExtensionsRef.
Equations
Instances For
Returns initial state for registered solvers.
Equations
Instances For
Equations
Instances For
Checks invariants of all registered solvers.
Equations
Instances For
Invokes model-based theory combination extensions in all registered solvers.
Equations
Instances For
Sequential conjunction: executes both x and y.
- Runs
xand always runsyafterward, regardless of whetherxmade progress. - It is not applicable only if both
xandyare not applicable.
Equations
Instances For
Given a new disequality lhs ≠ rhs, propagates it to relevant theories.
Equations
Instances For
Equations
Instances For
Returns some t if t is the solver term for ext associated with e.
Equations
Instances For
Returns true if the root of es equivalence class is already attached to a term
of the given solver.
Equations
Instances For
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Returns activated match-declaration equations.
Recall that in tactics such as instantiate only [...], match-declarations are always instantiated.