fact
stringlengths
6
3.84k
type
stringclasses
11 values
library
stringclasses
32 values
imports
listlengths
1
14
filename
stringlengths
20
95
symbolic_name
stringlengths
1
90
docstring
stringlengths
7
20k
addACEq (e₁ e₂ : Expr) : CCM Unit := do dbgTraceACEq "cc eq:" e₁ e₂ modifyACTodo fun acTodo => acTodo.push (e₁, e₂, .eqProof e₁ e₂) processAC dbgTraceACState
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
addACEq
Given AC variables `e₁` and `e₂` which are in the same equivalence class, add the proof of `e₁ = e₂` to the AC module.
setACVar (e : Expr) : CCM Unit := do let eRoot ← getRoot e let some rootEntry ← getEntry eRoot | failure if let some acVar := rootEntry.acVar then addACEq acVar e else let newRootEntry := { rootEntry with acVar := some e } modify fun ccs => { ccs with entries := ccs.entries.insert eRoot newRootEntry...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
setACVar
If the root expression of `e` is AC variable, add equality to AC module. If not, register the AC variable to the root entry.
internalizeACVar (e : Expr) : CCM Bool := do let ccs ← get if ccs.acEntries.contains e then return false modify fun _ => { ccs with acEntries := ccs.acEntries.insert e { idx := ccs.acEntries.size } } setACVar e return true
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
internalizeACVar
If `e` isn't an AC variable, set `e` as an new AC variable.
isAC (e : Expr) : CCM (Option Expr) := do let .app (.app op _) _ := e | return none let ccs ← get if let some cop := ccs.canOps[op]? then let some b := ccs.opInfo[cop]? | throwError "opInfo should contain all canonical operators in canOps" return bif b then some cop else none for (cop, b) in ccs.o...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
isAC
If `e` is of the form `op e₁ e₂` where `op` is an associative and commutative binary operator, return the canonical form of `op`.
partial convertAC (op e : Expr) (args : Array Expr := #[]) : CCM (Array Expr × Expr) := do if let some currOp ← isAC e then if op == currOp then let (args, arg₁) ← convertAC op e.appFn!.appArg! args let (args, arg₂) ← convertAC op e.appArg! args return (args, mkApp2 op arg₁ arg₂) let _ ← inter...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
convertAC
Given `e := op₁ (op₂ a₁ a₂) (op₃ a₃ a₄)` where `opₙ`s are canonicalized to `op`, internalize `aₙ`s as AC variables and return `(op (op a₁ a₂) (op a₃ a₄), args ++ #[a₁, a₂, a₃, a₄])`.
internalizeAC (e : Expr) (parent? : Option Expr) : CCM Unit := do let some op ← isAC e | return let parentOp? ← parent?.casesOn (pure none) isAC if parentOp?.any (· == op) then return unless (← internalizeACVar e) do return let (args, norme) ← convertAC op e let rep := ACApps.mkApps op args let some true ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
internalizeAC
Internalize `e` so that the AC module can deal with the given expression. If the expression does not contain an AC operator, or the parent expression is already processed by `internalizeAC`, this operation does nothing.
partial internalizeAppLit (e : Expr) : CCM Unit := do if ← isInterpretedValue e then mkEntry e true if (← get).values then return -- we treat values as atomic symbols else mkEntry e false if (← get).values && isValue e then return -- we treat values as atomic symbols unless e.isApp do return if ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
internalizeAppLit
The specialized `internalizeCore` for applications or literals.
partial internalizeCore (e : Expr) (parent? : Option Expr) : CCM Unit := do guard !e.hasLooseBVars /- We allow metavariables after partitions have been frozen. -/ if e.hasExprMVar && !(← get).frozePartitions then return /- Check whether `e` has already been internalized. -/ if (← getEntry e).isNone then ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
internalizeCore
Internalize `e` so that the congruence closure can deal with the given expression. Don't forget to process the tasks in the `todo` field later.
partial propagateIffUp (e : Expr) : CCM Unit := do let some (a, b) := e.iff? | failure if ← isEqTrue a then pushEq e b (mkApp3 (.const ``iff_eq_of_eq_true_left []) a b (← getEqTrueProof a)) else if ← isEqTrue b then pushEq e a (mkApp3 (.const ``iff_eq_of_eq_true_right []) a b (← getEqTrueProof b)) else ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateIffUp
Propagate equality from `a` and `b` to `a ↔ b`.
partial propagateAndUp (e : Expr) : CCM Unit := do let some (a, b) := e.and? | failure if ← isEqTrue a then pushEq e b (mkApp3 (.const ``and_eq_of_eq_true_left []) a b (← getEqTrueProof a)) else if ← isEqTrue b then pushEq e a (mkApp3 (.const ``and_eq_of_eq_true_right []) a b (← getEqTrueProof b)) else ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateAndUp
Propagate equality from `a` and `b` to `a ∧ b`.
partial propagateOrUp (e : Expr) : CCM Unit := do let some (a, b) := e.app2? ``Or | failure if ← isEqTrue a then pushEq e (.const ``True []) (mkApp3 (.const ``or_eq_of_eq_true_left []) a b (← getEqTrueProof a)) else if ← isEqTrue b then pushEq e (.const ``True []) (mkApp3 (.const ``or_eq_of_eq...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateOrUp
Propagate equality from `a` and `b` to `a ∨ b`.
partial propagateNotUp (e : Expr) : CCM Unit := do let some a := e.not? | failure if ← isEqTrue a then pushEq e (.const ``False []) (mkApp2 (.const ``not_eq_of_eq_true []) a (← getEqTrueProof a)) else if ← isEqFalse a then pushEq e (.const ``True []) (mkApp2 (.const ``not_eq_of_eq_false []) a (← getEqFals...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateNotUp
Propagate equality from `a` to `¬a`.
partial propagateImpUp (e : Expr) : CCM Unit := do guard e.isArrow let .forallE _ a b _ := e | unreachable! if ← isEqTrue a then pushEq e b (mkApp3 (.const ``imp_eq_of_eq_true_left []) a b (← getEqTrueProof a)) else if ← isEqFalse a then pushEq e (.const ``True []) (mkApp3 (.const ``imp_eq_of_eq_f...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateImpUp
Propagate equality from `a` and `b` to `a → b`.
partial propagateIteUp (e : Expr) : CCM Unit := do let .app (.app (.app (.app (.app (.const ``ite [lvl]) A) c) d) a) b := e | failure if ← isEqTrue c then pushEq e a (mkApp6 (.const ``if_eq_of_eq_true [lvl]) c d A a b (← getEqTrueProof c)) else if ← isEqFalse c then pushEq e b (mkApp6 (.const ``if_eq_of_e...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateIteUp
Propagate equality from `p`, `a` and `b` to `if p then a else b`.
partial propagateEqUp (e : Expr) : CCM Unit := do let some (_, a, b) := e.eq? | failure let ra ← getRoot a let rb ← getRoot b if ra != rb then let mut raNeRb : Option Expr := none /- We disprove inequality for interpreted values here. The possible types of interpreted values are in `{String, Cha...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateEqUp
Propagate equality from `a` and `b` to *disprove* `a = b`.
partial propagateUp (e : Expr) : CCM Unit := do if (← get).inconsistent then return if e.isAppOfArity ``Iff 2 then propagateIffUp e else if e.isAppOfArity ``And 2 then propagateAndUp e else if e.isAppOfArity ``Or 2 then propagateOrUp e else if e.isAppOfArity ``Not 1 then propagateNotUp e els...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateUp
Propagate equality from subexpressions of `e` to `e`.
partial applySimpleEqvs (e : Expr) : CCM Unit := do if let .app (.app (.app (.app (.const ``cast [l₁]) A) B) H) a := e then /- ``` cast H a ≍ a theorem cast_heq.{l₁} : ∀ {A B : Sort l₁} (H : A = B) (a : A), @cast.{l₁} A B H a ≍ a ``` -/ let proof := mkApp4 (.const ``cast_heq [l₁]) A B H a ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
applySimpleEqvs
This method is invoked during internalization and eagerly apply basic equivalences for term `e` Examples: - If `e := cast H e'`, then it merges the equivalence classes of `cast H e'` and `e'` In principle, we could mark theorems such as `cast_eq` as simplification rules, but this created problems with the builtin supp...
partial processSubsingletonElem (e : Expr) : CCM Unit := do let type ← inferType e let ss ← synthInstance? (← mkAppM ``FastSubsingleton #[type]) if ss.isNone then return -- type is not a subsingleton let type ← normalize type internalizeCore type none if let some it := (← get).subsingletonReprs[type]? then ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
processSubsingletonElem
If `e` is a subsingleton element, push the equality proof between `e` and its canonical form to the todo list or register `e` as the canonical form of itself.
partial mkEntry (e : Expr) (interpreted : Bool) : CCM Unit := do if (← getEntry e).isSome then return let constructor ← isConstructorApp e modify fun ccs => { ccs with toCCState := ccs.toCCState.mkEntryCore e interpreted constructor } processSubsingletonElem e
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
mkEntry
Add an new entry for `e` to the congruence closure.
mayPropagate (e : Expr) : Bool := e.isAppOfArity ``Iff 2 || e.isAppOfArity ``And 2 || e.isAppOfArity ``Or 2 || e.isAppOfArity ``Not 1 || e.isArrow || e.isIte
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
mayPropagate
Can we propagate equality from subexpressions of `e` to `e`?
removeParents (e : Expr) (parentsToPropagate : Array Expr := #[]) : CCM (Array Expr) := do let some ps := (← get).parents[e]? | return parentsToPropagate let mut parentsToPropagate := parentsToPropagate for pocc in ps do let p := pocc.expr trace[Debug.Meta.Tactic.cc] "remove parent: {p}" if mayPropaga...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
removeParents
Remove parents of `e` from the congruence table and the symm congruence table, and append parents to propagate equality, to `parentsToPropagate`. Returns the new value of `parentsToPropagate`.
partial invertTrans (e : Expr) (newFlipped : Bool := false) (newTarget : Option Expr := none) (newProof : Option EntryExpr := none) : CCM Unit := do let some n ← getEntry e | failure if let some t := n.target then invertTrans t (!n.flipped) (some e) n.proof let newN : Entry := { n with flipped :...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
invertTrans
The fields `target` and `proof` in `e`'s entry are encoding a transitivity proof Let `e.rootTarget` and `e.rootProof` denote these fields. ```lean e = e.rootTarget := e.rootProof _ = e.rootTarget.rootTarget := e.rootTarget.rootProof ... _ = e.root := ... ``` The transitivity proof eventuall...
collectFnRoots (root : Expr) (fnRoots : Array Expr := #[]) : CCM (Array Expr) := do guard ((← getRoot root) == root) let mut fnRoots : Array Expr := fnRoots let mut visited : ExprSet := ∅ let mut it := root repeat let fnRoot ← getRoot (it.getAppFn) if !visited.contains fnRoot then visited := vis...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
collectFnRoots
Traverse the `root`'s equivalence class, and for each function application, collect the function's equivalence class root.
reinsertParents (e : Expr) : CCM Unit := do let some ps := (← get).parents[e]? | return () for p in ps do trace[Debug.Meta.Tactic.cc] "reinsert parent: {p.expr}" if p.expr.isApp then if p.symmTable then addSymmCongruenceTable p.expr else addCongruenceTable p.expr
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
reinsertParents
Reinsert parents of `e` to the congruence table and the symm congruence table. Together with `removeParents`, this allows modifying parents of an expression.
checkInvariant : CCM Unit := do guard (← get).checkInvariant
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
checkInvariant
Check for integrity of the `CCStructure`.
propagateBetaToEqc (fnRoots lambdas : Array Expr) (newLambdaApps : Array Expr := #[]) : CCM (Array Expr) := do if lambdas.isEmpty then return newLambdaApps let mut newLambdaApps := newLambdaApps let lambdaRoot ← getRoot lambdas.back! guard (← lambdas.allM fun l => pure l.isLambda <&&> (· == lambdaRoot) <$> ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateBetaToEqc
For each `fnRoot` in `fnRoots` traverse its parents, and look for a parent prefix that is in the same equivalence class of the given lambdas. remark All expressions in lambdas are in the same equivalence class
propagateProjectionConstructor (p c : Expr) : CCM Unit := do guard (← isConstructorApp c) p.withApp fun pFn pArgs => do let some pFnN := pFn.constName? | return let some info ← getProjectionFnInfo? pFnN | return let mkidx := info.numParams if h : mkidx < pArgs.size then unless ← isEqv (pArgs[m...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateProjectionConstructor
Given `c` a constructor application, if `p` is a projection application (not `.proj _ _ _`, but `.app (.const projName _) _`) such that major premise is equal to `c`, then propagate new equality. Example: if `p` is of the form `b.fst`, `c` is of the form `(x, y)`, and `b = c`, we add the equality `(x, y).fst = x`
partial propagateConstructorEq (e₁ e₂ : Expr) : CCM Unit := do let env ← getEnv let some c₁ ← isConstructorApp? e₁ | failure let some c₂ ← isConstructorApp? e₂ | failure unless ← pureIsDefEq (← inferType e₁) (← inferType e₂) do return let some h ← getEqProof e₁ e₂ | failure if c₁.name == c₂.name then ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateConstructorEq
Given a new equality `e₁ = e₂`, where `e₁` and `e₂` are constructor applications. Implement the following implications: ```lean c a₁ ... aₙ = c b₁ ... bₙ => a₁ = b₁, ..., aₙ = bₙ c₁ ... = c₂ ... => False ``` where `c`, `c₁` and `c₂` are constructors
propagateValueInconsistency (e₁ e₂ : Expr) : CCM Unit := do guard (← isInterpretedValue e₁) guard (← isInterpretedValue e₂) let some eqProof ← getEqProof e₁ e₂ | failure let trueEqFalse ← mkEq (.const ``True []) (.const ``False []) let neProof := Expr.app (.proj ``Iff 0 (← mkAppOptM ``bne_iff_ne #[none, n...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateValueInconsistency
Derive contradiction if we can get equality between different values.
propagateAndDown (e : Expr) : CCM Unit := do if ← isEqTrue e then let some (a, b) := e.and? | failure let h ← getEqTrueProof e pushEq a (.const ``True []) (mkApp3 (.const ``eq_true_of_and_eq_true_left []) a b h) pushEq b (.const ``True []) (mkApp3 (.const ``eq_true_of_and_eq_true_right []) a b h)
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateAndDown
Propagate equality from `a ∧ b = True` to `a = True` and `b = True`.
propagateOrDown (e : Expr) : CCM Unit := do if ← isEqFalse e then let some (a, b) := e.app2? ``Or | failure let h ← getEqFalseProof e pushEq a (.const ``False []) (mkApp3 (.const ``eq_false_of_or_eq_false_left []) a b h) pushEq b (.const ``False []) (mkApp3 (.const ``eq_false_of_or_eq_false_right []) ...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateOrDown
Propagate equality from `a ∨ b = False` to `a = False` and `b = False`.
propagateNotDown (e : Expr) : CCM Unit := do if ← isEqTrue e then let some a := e.not? | failure pushEq a (.const ``False []) (mkApp2 (.const ``eq_false_of_not_eq_true []) a (← getEqTrueProof e)) else if ← (·.em) <$> get <&&> isEqFalse e then let some a := e.not? | failure pushEq a (.const ``T...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateNotDown
Propagate equality from `¬a` to `a`.
propagateEqDown (e : Expr) : CCM Unit := do if ← isEqTrue e then let some (a, b) := e.eqOrIff? | failure pushEq a b (← mkAppM ``of_eq_true #[← getEqTrueProof e])
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateEqDown
Propagate equality from `(a = b) = True` to `a = b`.
propagateExistsDown (e : Expr) : CCM Unit := do if ← isEqFalse e then let hNotE ← mkAppM ``of_eq_false #[← getEqFalseProof e] let (all, hAll) ← e.forallNot_of_notExists hNotE internalizeCore all none pushEq all (.const ``True []) (← mkEqTrue hAll)
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateExistsDown
Propagate equality from `¬∃ x, p x` to `∀ x, ¬p x`.
propagateDown (e : Expr) : CCM Unit := do if e.isAppOfArity ``And 2 then propagateAndDown e else if e.isAppOfArity ``Or 2 then propagateOrDown e else if e.isAppOfArity ``Not 1 then propagateNotDown e else if e.isEq || e.isAppOfArity ``Iff 2 then propagateEqDown e else if e.isAppOfArity ``Exist...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
propagateDown
Propagate equality from `e` to subexpressions of `e`.
addEqvStep (e₁ e₂ : Expr) (H : EntryExpr) (heqProof : Bool) : CCM Unit := do let some n₁ ← getEntry e₁ | return -- `e₁` have not been internalized let some n₂ ← getEntry e₂ | return -- `e₂` have not been internalized if n₁.root == n₂.root then return -- they are already in the same equivalence class. let some r...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
addEqvStep
Performs one step in the process when the new equation is added. Here, `H` contains the proof that `e₁ = e₂` (if `heqProof` is false) or `e₁ ≍ e₂` (if `heqProof` is true).
processTodo : CCM Unit := do repeat let todo ← getTodo let some (lhs, rhs, H, heqProof) := todo.back? | return if (← get).inconsistent then modifyTodo fun _ => #[] return modifyTodo Array.pop addEqvStep lhs rhs H heqProof
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
processTodo
Process the tasks in the `todo` field.
internalize (e : Expr) : CCM Unit := do internalizeCore e none processTodo
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
internalize
Internalize `e` so that the congruence closure can deal with the given expression.
addEqvCore (lhs rhs H : Expr) (heqProof : Bool) : CCM Unit := do pushTodo lhs rhs H heqProof processTodo
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
addEqvCore
Add `H : lhs = rhs` or `H : lhs ≍ rhs` to the congruence closure. Don't forget to internalize `lhs` and `rhs` beforehand.
add (type : Expr) (proof : Expr) : CCM Unit := do if (← get).inconsistent then return modifyTodo fun _ => #[] let (isNeg, p) := match type with | .app (.const ``Not []) a => (true, a) | .forallE _ a (.const ``False []) _ => (true, a) | .app (.app (.app (.const ``Ne [u]) α) lhs) rhs => (true,...
def
Tactic
[ "Mathlib.Data.Option.Defs", "Mathlib.Tactic.CC.MkProof" ]
Mathlib/Tactic/CC/Addition.lean
add
Add `proof : type` to the congruence closure.
isValue (e : Expr) : Bool := e.int?.isSome || e.isCharLit || e.isStringLit
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
isValue
Return true if `e` represents a constant value (numeral, character, or string).
isInterpretedValue (e : Expr) : MetaM Bool := do if e.isCharLit || e.isStringLit then return true else if e.int?.isSome then let type ← inferType e pureIsDefEq type (.const ``Nat []) <||> pureIsDefEq type (.const ``Int []) else return false
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
isInterpretedValue
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.
liftFromEq (R : Name) (H : Expr) : MetaM Expr := do if R == ``Eq then return H let HType ← whnf (← inferType H) let some (A, a, _) := HType.eq? | throwError "failed to build liftFromEq equality proof expected: {H}" let motive ← withLocalDeclD `x A fun x => do let hType ← mkEq a x withLocalDe...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
liftFromEq
Given a reflexive relation `R`, and a proof `H : a = b`, build a proof for `R a b`
ExprMap (α : Type u) := Std.TreeMap Expr α compare
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ExprMap
Ordering on `Expr`. -/ scoped instance : Ord Expr where compare a b := bif Expr.lt a b then .lt else bif Expr.eqv b a then .eq else .gt /-- Red-black maps whose keys are `Expr`s. 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...
ExprSet := Std.TreeSet Expr compare
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ExprSet
Red-black sets of `Expr`s. 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.
CCCongrTheorem extends CongrTheorem where /-- If `heqResult` is true, then lemma is based on heterogeneous equality and the conclusion is a heterogeneous equality. -/ heqResult : Bool := false /-- If `hcongrTheorem` is true, then lemma was created using `mkHCongrWithArity`. -/ hcongrTheorem : Bool := false
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCCongrTheorem
`CongrTheorem`s equipped with additional infos used by congruence closure modules.
mkCCHCongrWithArity (fn : Expr) (nargs : Nat) : MetaM (Option CCCongrTheorem) := do let eqCongr ← try mkHCongrWithArity fn nargs catch _ => return none return some { eqCongr with heqResult := true hcongrTheorem := true }
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
mkCCHCongrWithArity
Automatically generated congruence lemma based on heterogeneous equality. This returns an annotated version of the result from `Lean.Meta.mkHCongrWithArity`.
CCCongrTheoremKey where /-- The function of the given `CCCongrTheorem`. -/ fn : Expr /-- The number of arguments of `fn`. -/ nargs : Nat deriving BEq, Hashable
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCCongrTheoremKey
Keys used to find corresponding `CCCongrTheorem`s.
CCCongrTheoremCache := Std.HashMap CCCongrTheoremKey (Option CCCongrTheorem)
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCCongrTheoremCache
Caches used to find corresponding `CCCongrTheorem`s.
CCConfig where /-- If `true`, congruence closure will treat implicit instance arguments as constants. This means that setting `ignoreInstances := false` will fail to unify two definitionally equal instances of the same class. -/ ignoreInstances : Bool := true /-- If `true`, congruence closure modulo Associati...
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCConfig
Configs used in congruence closure modules.
ACApps where /-- An `ACApps` of just an `Expr`. -/ | ofExpr (e : Expr) : ACApps /-- An `ACApps` of applications of a binary operator. `args` are assumed to be sorted. See also `ACApps.mkApps` if `args` are not yet sorted. -/ | apps (op : Expr) (args : Array Expr) : ACApps deriving Inhabited, BEq
inductive
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACApps
An `ACApps` represents either just an `Expr` or applications of an associative and commutative binary operator.
ACApps.isSubset : (e₁ e₂ : ACApps) → Bool | .ofExpr a, .ofExpr b => a == b | .ofExpr a, .apps _ args => args.contains a | .apps _ _, .ofExpr _ => false | .apps op₁ args₁, .apps op₂ args₂ => if op₁ == op₂ then if args₁.size ≤ args₂.size then Id.run do let mut i₁ := 0 let mut i₂ := 0 ...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACApps.isSubset
Ordering on `ACApps` sorts `.ofExpr` before `.apps`, and sorts `.apps` by function symbol, then by shortlex order. -/ scoped instance : Ord ACApps where compare | .ofExpr a, .ofExpr b => compare a b | .ofExpr _, .apps _ _ => .lt | .apps _ _, .ofExpr _ => .gt | .apps op₁ args₁, .apps op₂ args₂ => ...
ACApps.diff (e₁ e₂ : ACApps) (r : Array Expr := #[]) : Array Expr := match e₁ with | .apps op₁ args₁ => Id.run do let mut r := r match e₂ with | .apps op₂ args₂ => if op₁ == op₂ then let mut i₂ := 0 for h : i₁ in [:args₁.size] do if i₂ == args₂.size then r := ...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACApps.diff
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₁`
ACApps.append (op : Expr) (e : ACApps) (r : Array Expr := #[]) : Array Expr := match e with | .apps op' args => if op' == op then r ++ args else r | .ofExpr e => r.push e
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACApps.append
Appends arguments of `e` to `r`.
ACApps.intersection (e₁ e₂ : ACApps) (r : Array Expr := #[]) : Array Expr := match e₁, e₂ with | .apps _ args₁, .apps _ args₂ => Id.run do let mut r := r let mut i₁ := 0 let mut i₂ := 0 while h : i₁ < args₁.size ∧ i₂ < args₂.size do if args₁[i₁] == args₂[i₂] then r := r.push args₁[i₁] ...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACApps.intersection
Appends elements in the intersection of `e₁` and `e₂` to `r`.
ACApps.mkApps (op : Expr) (args : Array Expr) : ACApps := .apps op (args.qsort Expr.lt)
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACApps.mkApps
Sorts `args` and applies them to `ACApps.apps`.
ACApps.mkFlatApps (op : Expr) (e₁ e₂ : ACApps) : ACApps := let newArgs := ACApps.append op e₁ let newArgs := ACApps.append op e₂ newArgs ACApps.mkApps op newArgs
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACApps.mkFlatApps
Flattens given two `ACApps`.
ACApps.toExpr : ACApps → Option Expr | .apps _ ⟨[]⟩ => none | .apps op ⟨arg₀ :: args⟩ => some <| args.foldl (fun e arg => mkApp2 op e arg) arg₀ | .ofExpr e => some e
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACApps.toExpr
Converts an `ACApps` to an `Expr`. This returns `none` when the empty applications are given.
ACAppsMap (α : Type u) := Std.TreeMap ACApps α compare
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACAppsMap
Red-black maps whose keys are `ACApps`es. 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.
ACAppsSet := Std.TreeSet ACApps compare
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACAppsSet
Red-black sets of `ACApps`es. 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.
DelayedExpr where /-- A `DelayedExpr` of just an `Expr`. -/ | ofExpr (e : Expr) : DelayedExpr /-- A placeholder as an equality proof between given two terms which will be generated by non-AC congruence closure modules later. -/ | eqProof (lhs rhs : Expr) : DelayedExpr /-- Will be applied to `congr_arg`. -/ ...
inductive
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
DelayedExpr
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`.
EntryExpr /-- An `EntryExpr` of just an `Expr`. -/ | ofExpr (e : Expr) : EntryExpr /-- dummy congruence proof, it is just a placeholder. -/ | congr : EntryExpr /-- dummy eq_true proof, it is just a placeholder -/ | eqTrue : EntryExpr /-- dummy refl proof, it is just a placeholder. -/ | refl : EntryExpr ...
inductive
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
EntryExpr
This is used as a proof term in `Entry`s instead of `Expr`.
Entry where /-- next element in the equivalence class. -/ next : Expr /-- root (aka canonical) representative of the equivalence class. -/ root : Expr /-- root of the congruence class, it is meaningless if `e` is not an application. -/ cgRoot : Expr /-- When `e` was added to this equivalence class because...
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
Entry
Equivalence class data associated with an expression `e`.
Entries := ExprMap Entry
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
Entries
Stores equivalence class data associated with an expression `e`.
ACEntry where /-- Natural number associated to an expression. -/ idx : Nat /-- AC variables that occur on the left-hand side of an equality which `e` occurs as the left-hand side of in `CCState.acR`. -/ RLHSOccs : ACAppsSet := ∅ /-- AC variables that occur on the **left**-hand side of an equality which `e` ...
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACEntry
Equivalence class data associated with an expression `e` used by AC congruence closure modules.
ACEntry.ROccs (ent : ACEntry) : (inLHS : Bool) → ACAppsSet | true => ent.RLHSOccs | false => ent.RRHSOccs
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACEntry.ROccs
Returns the occurrences of this entry in either the LHS or RHS.
ParentOcc where expr : Expr /-- If `symmTable` is true, then we should use the `symmCongruences`, otherwise `congruences`. Remark: this information is redundant, it can be inferred from `expr`. We use store it for performance reasons. -/ symmTable : Bool
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ParentOcc
Used to record when an expression processed by `cc` occurs in another expression.
ParentOccSet := Std.TreeSet ParentOcc (Ordering.byKey ParentOcc.expr compare)
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ParentOccSet
Red-black sets of `ParentOcc`s.
Parents := ExprMap ParentOccSet
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
Parents
Used to map an expression `e` to another expression that contains `e`. When `e` is normalized, its parents should also change.
CongruencesKey /-- `fn` is First-Order: we do not consider all partial applications. -/ | fo (fn : Expr) (args : Array Expr) : CongruencesKey /-- `fn` is Higher-Order. -/ | ho (fn : Expr) (arg : Expr) : CongruencesKey deriving BEq, Hashable
inductive
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CongruencesKey
null
Congruences := Std.HashMap CongruencesKey (List Expr)
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
Congruences
Maps each expression (via `mkCongruenceKey`) to expressions it might be congruent to.
SymmCongruencesKey where (h₁ h₂ : Expr) deriving BEq, Hashable
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
SymmCongruencesKey
null
SymmCongruences := Std.HashMap SymmCongruencesKey (List (Expr × Name))
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
SymmCongruences
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.
SubsingletonReprs := ExprMap Expr
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
SubsingletonReprs
Stores the root representatives of subsingletons, this uses `FastSingleton` instead of `Subsingleton`.
InstImplicitReprs := ExprMap (List Expr)
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
InstImplicitReprs
Stores the root representatives of `.instImplicit` arguments.
TodoEntry := Expr × Expr × EntryExpr × Bool
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
TodoEntry
null
ACTodoEntry := ACApps × ACApps × DelayedExpr
abbrev
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ACTodoEntry
null
CCState extends CCConfig where /-- Maps known expressions to their equivalence class data. -/ entries : Entries := ∅ /-- Maps an expression `e` to the expressions `e` occurs in. -/ parents : Parents := ∅ /-- Maps each expression to a set of expressions it might be congruent to. -/ congruences : Congruences ...
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCState
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.
CCState.mkEntryCore (ccs : CCState) (e : Expr) (interpreted : Bool) (constructor : Bool) : CCState := assert! ccs.entries[e]? |>.isNone let n : Entry := { next := e root := e cgRoot := e size := 1 flipped := false interpreted constructor hasLambdas := e.isLambda ...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCState.mkEntryCore
Update the `CCState` by constructing and inserting a new `Entry`.
root (ccs : CCState) (e : Expr) : Expr := match ccs.entries[e]? with | some n => n.root | none => e
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
root
Get the root representative of the given expression.
next (ccs : CCState) (e : Expr) : Expr := match ccs.entries[e]? with | some n => n.next | none => e
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
next
Get the next element in the equivalence class. Note that if the given `Expr` `e` is not in the graph then it will just return `e`.
isCgRoot (ccs : CCState) (e : Expr) : Bool := match ccs.entries[e]? with | some n => e == n.cgRoot | none => true
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
isCgRoot
Check if `e` is the root of the congruence class.
mt (ccs : CCState) (e : Expr) : Nat := match ccs.entries[e]? with | some n => n.mt | none => ccs.gmt
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
mt
"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 instan...
inSingletonEqc (ccs : CCState) (e : Expr) : Bool := match ccs.entries[e]? with | some it => it.next == e | none => true
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
inSingletonEqc
Is the expression in an equivalence class with only one element (namely, itself)?
getRoots (ccs : CCState) (roots : Array Expr) (nonsingletonOnly : Bool) : Array Expr := Id.run do let mut roots := roots for (k, n) in ccs.entries do if k == n.root && (!nonsingletonOnly || !ccs.inSingletonEqc k) then roots := roots.push k return roots
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
getRoots
Append to `roots` all the roots of equivalence classes in `ccs`. If `nonsingletonOnly` is true, we skip all the singleton equivalence classes.
checkEqc (ccs : CCState) (e : Expr) : Bool := toBool <| Id.run <| OptionT.run do let root := ccs.root e let mut size : Nat := 0 let mut it := e repeat let some itN := ccs.entries[it]? | failure guard (itN.root == root) let mut it₂ := it repeat let it₂N := ccs.entries[it...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
checkEqc
Check for integrity of the `CCState`.
checkInvariant (ccs : CCState) : Bool := ccs.entries.all fun k n => k != n.root || checkEqc ccs k
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
checkInvariant
Check for integrity of the `CCState`.
getNumROccs (ccs : CCState) (e : Expr) (inLHS : Bool) : Nat := match ccs.acEntries[e]? with | some ent => (ent.ROccs inLHS).size | none => 0
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
getNumROccs
null
getVarWithLeastOccs (ccs : CCState) (e : ACApps) (inLHS : Bool) : Option Expr := match e with | .apps _ args => Id.run do let mut r := args[0]? let mut numOccs := r.casesOn 0 fun r' => ccs.getNumROccs r' inLHS for hi : i in [1:args.size] do if args[i] != (args[i - 1]'(Nat.lt_of_le_of_lt (i.sub_le ...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
getVarWithLeastOccs
Search for the AC-variable (`Entry.acVar`) with the least occurrences in the state.
getVarWithLeastLHSOccs (ccs : CCState) (e : ACApps) : Option Expr := ccs.getVarWithLeastOccs e true
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
getVarWithLeastLHSOccs
Search for the AC-variable (`Entry.acVar`) with the fewest occurrences in the LHS.
getVarWithLeastRHSOccs (ccs : CCState) (e : ACApps) : Option Expr := ccs.getVarWithLeastOccs e false open MessageData
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
getVarWithLeastRHSOccs
Search for the AC-variable (`Entry.acVar`) with the fewest occurrences in the RHS.
ppEqc (ccs : CCState) (e : Expr) : MessageData := Id.run do let mut lr : List MessageData := [] let mut it := e repeat let some itN := ccs.entries[it]? | break let mdIt : MessageData := if it.isForall || it.isLambda || it.isLet then paren (ofExpr it) else ofExpr it lr := mdIt :: lr it := itN...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppEqc
Pretty print the entry associated with the given expression.
ppEqcs (ccs : CCState) (nonSingleton : Bool := true) : MessageData := let roots := ccs.getRoots #[] nonSingleton let a := roots.map (fun root => ccs.ppEqc root) let l := a.toList bracket "{" (group <| joinSep l (ofFormat ("," ++ .line))) "}"
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppEqcs
Pretty print the entire cc graph. If the `nonSingleton` argument is set to `true` then singleton equivalence classes will be omitted.
ppParentOccsAux (ccs : CCState) (e : Expr) : MessageData := match ccs.parents[e]? with | some poccs => let r := ofExpr e ++ ofFormat (.line ++ ":=" ++ .line) let ps := poccs.toList.map fun o => ofExpr o.expr group (r ++ bracket "{" (group <| joinSep ps (ofFormat ("," ++ .line))) "}") | none => ofForma...
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppParentOccsAux
null
ppParentOccs (ccs : CCState) : MessageData := let r := ccs.parents.toList.map fun (k, _) => ccs.ppParentOccsAux k bracket "{" (group <| joinSep r (ofFormat ("," ++ .line))) "}"
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppParentOccs
null
ppACDecl (ccs : CCState) (e : Expr) : MessageData := match ccs.acEntries[e]? with | some it => group (ofFormat (s!"x_{it.idx}" ++ .line ++ ":=" ++ .line) ++ ofExpr e) | none => nil
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppACDecl
null
ppACDecls (ccs : CCState) : MessageData := let r := ccs.acEntries.toList.map fun (k, _) => ccs.ppACDecl k bracket "{" (joinSep r (ofFormat ("," ++ .line))) "}"
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppACDecls
null
ppACExpr (ccs : CCState) (e : Expr) : MessageData := if let some it := ccs.acEntries[e]? then s!"x_{it.idx}" else ofExpr e
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppACExpr
null
partial ppACApps (ccs : CCState) : ACApps → MessageData | .apps op args => let r := ofExpr op :: args.toList.map fun arg => ccs.ppACExpr arg sbracket (joinSep r (ofFormat .line)) | .ofExpr e => ccs.ppACExpr e
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppACApps
null
ppACR (ccs : CCState) : MessageData := let r := ccs.acR.toList.map fun (k, p, _) => group <| ccs.ppACApps k ++ ofFormat (Format.line ++ "--> ") ++ nest 4 (Format.line ++ ccs.ppACApps p) bracket "{" (joinSep r (ofFormat ("," ++ .line))) "}"
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppACR
null