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 : BoolIf heqResultis true, then lemma is based on heterogeneous equality and the conclusion is a heterogeneous equality.
- hcongrTheorem : BoolIf 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.ExprThe function of the given CCCongrTheorem.
- nargs : ℕThe number of arguments of fn.
Instances For
Equations
Instances For
Equations
Instances For
Configs used in congruence closure modules.
- ignoreInstances : BoolIf 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 : BoolIf true, congruence closure modulo Associativity and Commutativity.
- If - hoFnsis- some 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". If- hoFnsis- none, then full support is provided for all constants.
- em : BoolIf true, then use excluded middle
- values : BoolIf 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)
 : ACAppsAn ACAppsof just anExpr.
- apps
(op : Lean.Expr)
(args : Array Lean.Expr)
 : ACAppsAn ACAppsof applications of a binary operator.argsare assumed to be sorted.See also ACApps.mkAppsifargsare not yet sorted.
Instances For
Equations
Instances For
Equations
Equations
- Mathlib.Tactic.CC.instBEqACApps.beq ↑a ↑b = (a == b)
- Mathlib.Tactic.CC.instBEqACApps.beq (Mathlib.Tactic.CC.ACApps.apps a a_1) (Mathlib.Tactic.CC.ACApps.apps b b_1) = (a == b && a_1 == b_1)
- Mathlib.Tactic.CC.instBEqACApps.beq x✝¹ x✝ = false
Instances For
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)
 : DelayedExprA DelayedExprof just anExpr.
- eqProof
(lhs rhs : Lean.Expr)
 : DelayedExprA 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)
 : DelayedExprWill be applied to congr_arg.
- congrFun
(h : DelayedExpr)
(a : ACApps)
 : DelayedExprWill be applied to congr_fun.
- eqSymm
(h : DelayedExpr)
 : DelayedExprWill be applied to Eq.symm.
- eqSymmOpt
(a₁ a₂ : ACApps)
(h : DelayedExpr)
 : DelayedExprWill be applied to Eq.symm.
- eqTrans
(h₁ h₂ : DelayedExpr)
 : DelayedExprWill be applied to Eq.trans.
- eqTransOpt
(a₁ a₂ a₃ : ACApps)
(h₁ h₂ : DelayedExpr)
 : DelayedExprWill be applied to Eq.trans.
- heqOfEq
(h : DelayedExpr)
 : DelayedExprWill be applied to heq_of_eq.
- heqSymm
(h : DelayedExpr)
 : DelayedExprWill be applied to HEq.symm.
Instances For
This is used as a proof term in Entrys instead of Expr.
- ofExpr
(e : Lean.Expr)
 : EntryExprAn EntryExprof just anExpr.
- congr : EntryExprdummy congruence proof, it is just a placeholder. 
- eqTrue : EntryExprdummy eq_true proof, it is just a placeholder 
- refl : EntryExprdummy refl proof, it is just a placeholder. 
- ofDExpr
(e : DelayedExpr)
 : EntryExprAn EntryExprof aDelayedExpr.
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equivalence class data associated with an expression e.
- next : Lean.Exprnext element in the equivalence class. 
- root : Lean.Exprroot (aka canonical) representative of the equivalence class. 
- cgRoot : Lean.Exprroot of the congruence class, it is meaningless if eis not an application.
- Variable in the AC theory. 
- flipped : Boolproof has been flipped 
- interpreted : Booltrueif the node should be viewed as an abstract value
- constructor : Booltrueif head symbol is a constructor
- hasLambdas : Booltrueif equivalence class contains lambda expressions
- heqProofs : BoolheqProofs == trueiff some proofs in the equivalence class are based on heterogeneous equality. We represent equality and heterogeneous equality in a single equivalence class.
- fo : BoolIf 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.
Instances For
Equations
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 : ACAppsSetAC variables that occur on the left-hand side of an equality which eoccurs as the left-hand side of inCCState.acR.
- RRHSOccs : ACAppsSetAC 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
Equations
Instances For
Used to record when an expression processed by cc occurs in another expression.
- expr : Lean.Expr
- symmTable : BoolIf 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)
 : CongruencesKeyfnis First-Order: we do not consider all partial applications.
- ho
(fn arg : Lean.Expr)
 : CongruencesKeyfnis Higher-Order.
Instances For
Equations
- Mathlib.Tactic.CC.instBEqCongruencesKey.beq (Mathlib.Tactic.CC.CongruencesKey.fo a a_1) (Mathlib.Tactic.CC.CongruencesKey.fo b b_1) = (a == b && a_1 == b_1)
- Mathlib.Tactic.CC.instBEqCongruencesKey.beq (Mathlib.Tactic.CC.CongruencesKey.ho a a_1) (Mathlib.Tactic.CC.CongruencesKey.ho b b_1) = (a == b && a_1 == b_1)
- Mathlib.Tactic.CC.instBEqCongruencesKey.beq x✝¹ x✝ = false
Instances For
Equations
- Mathlib.Tactic.CC.instHashableCongruencesKey.hash (Mathlib.Tactic.CC.CongruencesKey.fo a a_1) = mixHash (mixHash 0 (hash a)) (hash a_1)
- Mathlib.Tactic.CC.instHashableCongruencesKey.hash (Mathlib.Tactic.CC.CongruencesKey.ho a a_1) = mixHash (mixHash 1 (hash a)) (hash a_1)
Instances For
Maps each expression (via mkCongruenceKey) to expressions it might be congruent to.
Equations
Instances For
Equations
Instances For
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 : EntriesMaps known expressions to their equivalence class data. 
- parents : ParentsMaps an expression eto the expressionseoccurs in.
- congruences : CongruencesMaps each expression to a set of expressions it might be congruent to. 
- symmCongruences : SymmCongruencesMaps each expression to a set of expressions it might be congruent to, via the symmetrical relation. 
- subsingletonReprs : SubsingletonReprsStores the root representatives of subsingletons, this uses FastSingletoninstead ofSubsingleton.
- instImplicitReprs : InstImplicitReprsRecords which instances of the same class are defeq. 
- frozePartitions : BoolThe 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 : BoolReturns 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.
Instances For
"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
- ccs.ppACExpr e = match ccs.acEntries[e]? with | some it => (Lean.MessageData.ofFormat ∘ Std.format) (toString "x_" ++ toString it.idx) | x => Lean.MessageData.ofExpr e
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.ExprThe 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 UnitCongruence 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 ACTodoEntryAC-equalities that have been discovered but not processed. 
- normalizer : Option CCNormalizer
- phandler : Option CCPropagationHandler
- cache : CCCongrTheoremCache