Datatypes for cc #
Some of the data structures here are used in multiple parts of the tactic. We split them into their own file.
TODO #
This file is ported from C++ code, so many declarations lack documents.
Return true if e represents a constant value (numeral, character, or string).
Equations
- Mathlib.Tactic.CC.isValue e = (e.int?.isSome || e.isCharLit || e.isStringLit)
Instances For
Return true if e represents a value (nat/int numeral, character, or string).
In addition to the conditions in Mathlib.Tactic.CC.isValue, this also checks that
kernel computation can compare the values for equality.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a reflexive relation R, and a proof H : a = b, build a proof for R a b
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ordering on Expr.
Equations
- Mathlib.Tactic.CC.instOrdExpr_mathlib = { compare := fun (a b : Lean.Expr) => bif a.lt b then Ordering.lt else bif b.eqv a then Ordering.eq else Ordering.gt }
Instances For
Red-black maps whose keys are Exprs.
TODO: the choice between TreeMap and HashMap is not obvious:
once the cc tactic is used a lot in Mathlib, we should profile and see
if HashMap could be more optimal.
Equations
Instances For
Red-black sets of Exprs.
TODO: the choice between TreeSet and HashSet is not obvious:
once the cc tactic is used a lot in Mathlib, we should profile and see
if HashSet could be more optimal.
Instances For
CongrTheorems equipped with additional infos used by congruence closure modules.
- heqResult : Bool
If
heqResultis true, then lemma is based on heterogeneous equality and the conclusion is a heterogeneous equality. - hcongrTheorem : Bool
If
hcongrTheoremis true, then lemma was created usingmkHCongrWithArity.
Instances For
Automatically generated congruence lemma based on heterogeneous equality.
This returns an annotated version of the result from Lean.Meta.mkHCongrWithArity.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Keys used to find corresponding CCCongrTheorems.
- fn : Lean.Expr
The function of the given
CCCongrTheorem. - nargs : ℕ
The number of arguments of
fn.
Instances For
Configs used in congruence closure modules.
- ignoreInstances : Bool
If
true, congruence closure will treat implicit instance arguments as constants.This means that setting
ignoreInstances := falsewill fail to unify two definitionally equal instances of the same class. - ac : Bool
If
true, congruence closure modulo Associativity and Commutativity. If
hoFnsissome fns, then full (and more expensive) support for higher-order functions is only considered for the functions in fns and local functions. The performance overhead is described in the paper "Congruence Closure in Intensional Type Theory". IfhoFnsisnone, then full support is provided for all constants.- em : Bool
If
true, then use excluded middle - values : Bool
If
true, we treat values as atomic symbols
Instances For
An ACApps represents either just an Expr or applications of an associative and commutative
binary operator.
- ofExpr
(e : Lean.Expr)
: ACApps
An
ACAppsof just anExpr. - apps
(op : Lean.Expr)
(args : Array Lean.Expr)
: ACApps
An
ACAppsof applications of a binary operator.argsare assumed to be sorted.See also
ACApps.mkAppsifargsare not yet sorted.
Instances For
Equations
- Mathlib.Tactic.CC.instInhabitedACApps = { default := ↑default }
Equations
Equations
Return true iff e₁ is a "subset" of e₂.
Example: The result is true for e₁ := a*a*a*b*d and e₂ := a*a*a*a*b*b*c*d*d.
The result is also true for e₁ := a and e₂ := a*a*a*b*c.
Equations
Instances For
Appends elements of the set difference e₁ \ e₂ to r.
Example: given e₁ := a*a*a*a*b*b*c*d*d*d and e₂ := a*a*a*b*b*d,
the result is #[a, c, d, d]
Precondition: e₂.isSubset e₁
Equations
Instances For
Appends arguments of e to r.
Equations
- Mathlib.Tactic.CC.ACApps.append op (Mathlib.Tactic.CC.ACApps.apps op₂ args₂) r = if (op₂ == op) = true then r ++ args₂ else r
- Mathlib.Tactic.CC.ACApps.append op (↑e₂_1) r = r.push e₂_1
Instances For
Sorts args and applies them to ACApps.apps.
Equations
- Mathlib.Tactic.CC.ACApps.mkApps op args = Mathlib.Tactic.CC.ACApps.apps op (args.qsort Lean.Expr.lt)
Instances For
Converts an ACApps to an Expr. This returns none when the empty applications are given.
Equations
Instances For
Red-black maps whose keys are ACAppses.
TODO: the choice between TreeMap and HashMap is not obvious:
once the cc tactic is used a lot in Mathlib, we should profile and see
if HashMap could be more optimal.
Instances For
Red-black sets of ACAppses.
TODO: the choice between TreeSet and HashSet is not obvious:
once the cc tactic is used a lot in Mathlib, we should profile and see
if HashSet could be more optimal.
Instances For
For proof terms generated by AC congruence closure modules, we want a placeholder as an equality
proof between given two terms which will be generated by non-AC congruence closure modules later.
DelayedExpr represents it using eqProof.
- ofExpr
(e : Lean.Expr)
: DelayedExpr
A
DelayedExprof just anExpr. - eqProof
(lhs rhs : Lean.Expr)
: DelayedExpr
A placeholder as an equality proof between given two terms which will be generated by non-AC congruence closure modules later.
- congrArg
(f : Lean.Expr)
(h : DelayedExpr)
: DelayedExpr
Will be applied to
congr_arg. - congrFun
(h : DelayedExpr)
(a : ACApps)
: DelayedExpr
Will be applied to
congr_fun. - eqSymm
(h : DelayedExpr)
: DelayedExpr
Will be applied to
Eq.symm. - eqSymmOpt
(a₁ a₂ : ACApps)
(h : DelayedExpr)
: DelayedExpr
Will be applied to
Eq.symm. - eqTrans
(h₁ h₂ : DelayedExpr)
: DelayedExpr
Will be applied to
Eq.trans. - eqTransOpt
(a₁ a₂ a₃ : ACApps)
(h₁ h₂ : DelayedExpr)
: DelayedExpr
Will be applied to
Eq.trans. - heqOfEq
(h : DelayedExpr)
: DelayedExpr
Will be applied to
heq_of_eq. - heqSymm
(h : DelayedExpr)
: DelayedExpr
Will be applied to
HEq.symm.
Instances For
Equations
- Mathlib.Tactic.CC.instInhabitedDelayedExpr = { default := ↑default }
This is used as a proof term in Entrys instead of Expr.
- ofExpr
(e : Lean.Expr)
: EntryExpr
An
EntryExprof just anExpr. - congr : EntryExpr
dummy congruence proof, it is just a placeholder.
- eqTrue : EntryExpr
dummy eq_true proof, it is just a placeholder
- refl : EntryExpr
dummy refl proof, it is just a placeholder.
- ofDExpr
(e : DelayedExpr)
: EntryExpr
An
EntryExprof aDelayedExpr.
Instances For
Equations
- Mathlib.Tactic.CC.instInhabitedEntryExpr = { default := ↑default }
Equations
- One or more equations did not get rendered due to their size.
Equivalence class data associated with an expression e.
- next : Lean.Expr
next element in the equivalence class.
- root : Lean.Expr
root (aka canonical) representative of the equivalence class.
- cgRoot : Lean.Expr
root of the congruence class, it is meaningless if
eis not an application. Variable in the AC theory.
- flipped : Bool
proof has been flipped
- interpreted : Bool
trueif the node should be viewed as an abstract value - constructor : Bool
trueif head symbol is a constructor - hasLambdas : Bool
trueif equivalence class contains lambda expressions - heqProofs : Bool
heqProofs == trueiff some proofs in the equivalence class are based on heterogeneous equality. We represent equality and heterogeneous equality in a single equivalence class. - fo : Bool
If
fo == true, then the expression associated with this entry is an application, and we are using first-order approximation to encode it. That is, we ignore its partial applications. - size : ℕ
number of elements in the equivalence class, it is meaningless if
e != root - mt : ℕ
The field
mtis used to implement the mod-time optimization introduce by the Simplify theorem prover. The basic idea is to introduce a counter gmt that records the number of heuristic instantiation that have occurred in the current branch. It is incremented after each round of heuristic instantiation. The fieldmtrecords the last time any proper descendant of this entry was involved in a merge.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Stores equivalence class data associated with an expression e.
Instances For
Equivalence class data associated with an expression e used by AC congruence closure
modules.
- idx : ℕ
Natural number associated to an expression.
- RLHSOccs : ACAppsSet
AC variables that occur on the left hand side of an equality which
eoccurs as the left hand side of inCCState.acR. - RRHSOccs : ACAppsSet
AC variables that occur on the left hand side of an equality which
eoccurs as the right hand side of inCCState.acR. Don't confuse.
Instances For
Used to record when an expression processed by cc occurs in another expression.
- expr : Lean.Expr
- symmTable : Bool
If
symmTableis true, then we should use thesymmCongruences, otherwisecongruences. Remark: this information is redundant, it can be inferred fromexpr. We use store it for performance reasons.
Instances For
Used to map an expression e to another expression that contains e.
When e is normalized, its parents should also change.
Instances For
- fo
(fn : Lean.Expr)
(args : Array Lean.Expr)
: CongruencesKey
fnis First-Order: we do not consider all partial applications. - ho
(fn arg : Lean.Expr)
: CongruencesKey
fnis Higher-Order.
Instances For
Maps each expression (via mkCongruenceKey) to expressions it might be congruent to.
Equations
Instances For
The symmetric variant of Congruences.
The Name identifies which relation the congruence is considered for.
Note that this only works for two-argument relations: ModEq n and ModEq m are considered the
same.
Equations
Instances For
Stores the root representatives of subsingletons, this uses FastSingleton instead of
Subsingleton.
Instances For
Stores the root representatives of .instImplicit arguments.
Instances For
Instances For
Equations
Instances For
Congruence closure state.
This may be considered to be a set of expressions and an equivalence class over this set.
The equivalence class is generated by the equational rules that are added to the CCState and
congruence, that is, if a = b then f(a) = f(b) and so on.
- entries : Entries
Maps known expressions to their equivalence class data.
- parents : Parents
Maps an expression
eto the expressionseoccurs in. - congruences : Congruences
Maps each expression to a set of expressions it might be congruent to.
- symmCongruences : SymmCongruences
Maps each expression to a set of expressions it might be congruent to, via the symmetrical relation.
- subsingletonReprs : SubsingletonReprs
Stores the root representatives of subsingletons, this uses
FastSingletoninstead ofSubsingleton. - instImplicitReprs : InstImplicitReprs
Records which instances of the same class are defeq.
- frozePartitions : Bool
The congruence closure module has a mode where the root of each equivalence class is marked as an interpreted/abstract value. Moreover, in this mode proof production is disabled. This capability is useful for heuristic instantiation.
Mapping from operators occurring in terms and their canonical representation in this module
Whether the canonical operator is supported by AC.
Extra
Entryinformation used by the AC part of the tactic.- acR : ACAppsMap (ACApps × DelayedExpr)
Records equality between
ACApps. - inconsistent : Bool
Returns true if the
CCStateis inconsistent. For example if it had botha = banda ≠ bin it. - gmt : ℕ
"Global Modification Time". gmt is a number stored on the
CCState, it is compared with the modification time of a cc_entry in e-matching. SeeCCState.mt.
Instances For
Equations
- One or more equations did not get rendered due to their size.
"Modification Time". The field mt is used to implement the mod-time optimization introduced by the
Simplify theorem prover. The basic idea is to introduce a counter gmt that records the number of
heuristic instantiation that have occurred in the current branch. It is incremented after each round
of heuristic instantiation. The field mt records the last time any proper descendant of this
entry was involved in a merge.
Instances For
Append to roots all the roots of equivalence classes in ccs.
If nonsingletonOnly is true, we skip all the singleton equivalence classes.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check for integrity of the CCState.
Equations
- ccs.checkInvariant = Std.TreeMap.all ccs.entries fun (k : Lean.Expr) (n : Mathlib.Tactic.CC.Entry) => k != n.root || ccs.checkEqc k
Instances For
Search for the AC-variable (Entry.acVar) with the least occurrences in the state.
Equations
- One or more equations did not get rendered due to their size.
- ccs.getVarWithLeastOccs (↑e₂_1) inLHS = some e₂_1
Instances For
Search for the AC-variable (Entry.acVar) with the fewest occurrences in the LHS.
Equations
- ccs.getVarWithLeastLHSOccs e = ccs.getVarWithLeastOccs e true
Instances For
Search for the AC-variable (Entry.acVar) with the fewest occurrences in the RHS.
Equations
- ccs.getVarWithLeastRHSOccs e = ccs.getVarWithLeastOccs e false
Instances For
Pretty print the entry associated with the given expression.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Pretty print the entire cc graph.
If the nonSingleton argument is set to true then singleton equivalence classes will be
omitted.
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
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
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- ccs.ppAC = (ccs.ppACDecls ++ Lean.MessageData.ofFormat (Std.Format.text "," ++ Std.Format.line) ++ ccs.ppACR).sbracket
Instances For
The congruence closure module (optionally) uses a normalizer. The idea is to use it (if available) to normalize auxiliary expressions produced by internal propagation rules (e.g., subsingleton propagator).
- normalize : Lean.Expr → Lean.MetaM Lean.Expr
The congruence closure module (optionally) uses a normalizer. The idea is to use it (if available) to normalize auxiliary expressions produced by internal propagation rules (e.g., subsingleton propagator).
Instances For
- propagated : Array Lean.Expr → Lean.MetaM Unit
- newAuxCCTerm : Lean.Expr → Lean.MetaM Unit
Congruence closure module invokes the following method when a new auxiliary term is created during propagation.
Instances For
CCStructure extends CCState (which records a set of facts derived by congruence closure)
by recording which steps still need to be taken to solve the goal.
- acR : ACAppsMap (ACApps × DelayedExpr)
Equalities that have been discovered but not processed.
- acTodo : Array ACTodoEntry
AC-equalities that have been discovered but not processed.
- normalizer : Option CCNormalizer
- phandler : Option CCPropagationHandler
- cache : CCCongrTheoremCache
Instances For
Equations
- One or more equations did not get rendered due to their size.