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
ppAC (ccs : CCState) : MessageData := sbracket (ccs.ppACDecls ++ ofFormat ("," ++ .line) ++ ccs.ppACR)
def
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
ppAC
null
CCNormalizer where normalize : Expr → MetaM Expr attribute [inherit_doc CCNormalizer] CCNormalizer.normalize
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCNormalizer
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).
CCPropagationHandler where propagated : Array Expr → MetaM Unit /-- Congruence closure module invokes the following method when a new auxiliary term is created during propagation. -/ newAuxCCTerm : Expr → MetaM Unit
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCPropagationHandler
null
CCStructure extends CCState where /-- Equalities that have been discovered but not processed. -/ todo : Array TodoEntry := #[] /-- AC-equalities that have been discovered but not processed. -/ acTodo : Array ACTodoEntry := #[] normalizer : Option CCNormalizer := none phandler : Option CCPropagationHandler := none cache : CCCongrTheoremCache := ∅ deriving Inhabited initialize registerTraceClass `Meta.Tactic.cc.merge registerTraceClass `Meta.Tactic.cc.failure registerTraceClass `Debug.Meta.Tactic.cc registerTraceClass `Debug.Meta.Tactic.cc.ac registerTraceClass `Debug.Meta.Tactic.cc.parentOccs
structure
Tactic
[ "Batteries.Classes.Order", "Mathlib.Lean.Meta.Basic", "Mathlib.Lean.Meta.CongrTheorems", "Mathlib.Data.Ordering.Basic" ]
Mathlib/Tactic/CC/Datatypes.lean
CCStructure
`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.
iff_eq_of_eq_true_left {a b : Prop} (h : a = True) : (a ↔ b) = b := h.symm ▸ true_iff _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
iff_eq_of_eq_true_left
null
iff_eq_of_eq_true_right {a b : Prop} (h : b = True) : (a ↔ b) = a := h.symm ▸ iff_true _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
iff_eq_of_eq_true_right
null
iff_eq_true_of_eq {a b : Prop} (h : a = b) : (a ↔ b) = True := h ▸ iff_self _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
iff_eq_true_of_eq
null
and_eq_of_eq_true_left {a b : Prop} (h : a = True) : (a ∧ b) = b := h.symm ▸ true_and _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
and_eq_of_eq_true_left
null
and_eq_of_eq_true_right {a b : Prop} (h : b = True) : (a ∧ b) = a := h.symm ▸ and_true _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
and_eq_of_eq_true_right
null
and_eq_of_eq_false_left {a b : Prop} (h : a = False) : (a ∧ b) = False := h.symm ▸ false_and _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
and_eq_of_eq_false_left
null
and_eq_of_eq_false_right {a b : Prop} (h : b = False) : (a ∧ b) = False := h.symm ▸ and_false _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
and_eq_of_eq_false_right
null
and_eq_of_eq {a b : Prop} (h : a = b) : (a ∧ b) = a := h ▸ propext and_self_iff
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
and_eq_of_eq
null
or_eq_of_eq_true_left {a b : Prop} (h : a = True) : (a ∨ b) = True := h.symm ▸ true_or _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
or_eq_of_eq_true_left
null
or_eq_of_eq_true_right {a b : Prop} (h : b = True) : (a ∨ b) = True := h.symm ▸ or_true _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
or_eq_of_eq_true_right
null
or_eq_of_eq_false_left {a b : Prop} (h : a = False) : (a ∨ b) = b := h.symm ▸ false_or _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
or_eq_of_eq_false_left
null
or_eq_of_eq_false_right {a b : Prop} (h : b = False) : (a ∨ b) = a := h.symm ▸ or_false _
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
or_eq_of_eq_false_right
null
or_eq_of_eq {a b : Prop} (h : a = b) : (a ∨ b) = a := h ▸ propext or_self_iff
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
or_eq_of_eq
null
imp_eq_of_eq_true_left {a b : Prop} (h : a = True) : (a → b) = b := h.symm ▸ propext ⟨fun h ↦ h trivial, fun h₁ _ ↦ h₁⟩
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
imp_eq_of_eq_true_left
null
imp_eq_of_eq_true_right {a b : Prop} (h : b = True) : (a → b) = True := h.symm ▸ propext ⟨fun _ ↦ trivial, fun h₁ _ ↦ h₁⟩
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
imp_eq_of_eq_true_right
null
imp_eq_of_eq_false_left {a b : Prop} (h : a = False) : (a → b) = True := h.symm ▸ propext ⟨fun _ ↦ trivial, fun _ h₂ ↦ False.elim h₂⟩
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
imp_eq_of_eq_false_left
null
imp_eq_of_eq_false_right {a b : Prop} (h : b = False) : (a → b) = Not a := h.symm ▸ propext ⟨fun h ↦ h, fun hna ha ↦ hna ha⟩ /- Remark: the congruence closure module will only use the following lemma is `CCConfig.em` is `true`. -/
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
imp_eq_of_eq_false_right
null
not_imp_eq_of_eq_false_right {a b : Prop} (h : b = False) : (Not a → b) = a := h.symm ▸ propext (Iff.intro ( fun h' ↦ Classical.byContradiction fun hna ↦ h' hna) fun ha hna ↦ hna ha)
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
not_imp_eq_of_eq_false_right
null
imp_eq_true_of_eq {a b : Prop} (h : a = b) : (a → b) = True := h ▸ propext ⟨fun _ ↦ trivial, fun _ ha ↦ ha⟩
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
imp_eq_true_of_eq
null
not_eq_of_eq_true {a : Prop} (h : a = True) : Not a = False := h.symm ▸ propext not_true
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
not_eq_of_eq_true
null
not_eq_of_eq_false {a : Prop} (h : a = False) : Not a = True := h.symm ▸ propext not_false_iff
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
not_eq_of_eq_false
null
false_of_a_eq_not_a {a : Prop} (h : a = Not a) : False := have : Not a := fun ha ↦ absurd ha (Eq.mp h ha) absurd (Eq.mpr h this) this universe u
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
false_of_a_eq_not_a
null
if_eq_of_eq_true {c : Prop} [d : Decidable c] {α : Sort u} (t e : α) (h : c = True) : @ite α c d t e = t := if_pos (of_eq_true h)
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
if_eq_of_eq_true
null
if_eq_of_eq_false {c : Prop} [d : Decidable c] {α : Sort u} (t e : α) (h : c = False) : @ite α c d t e = e := if_neg (of_eq_false h)
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
if_eq_of_eq_false
null
if_eq_of_eq (c : Prop) [d : Decidable c] {α : Sort u} {t e : α} (h : t = e) : @ite α c d t e = t := match d with | isTrue _ => rfl | isFalse _ => Eq.symm h
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
if_eq_of_eq
null
eq_true_of_and_eq_true_left {a b : Prop} (h : (a ∧ b) = True) : a = True := eq_true (And.left (of_eq_true h))
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
eq_true_of_and_eq_true_left
null
eq_true_of_and_eq_true_right {a b : Prop} (h : (a ∧ b) = True) : b = True := eq_true (And.right (of_eq_true h))
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
eq_true_of_and_eq_true_right
null
eq_false_of_or_eq_false_left {a b : Prop} (h : (a ∨ b) = False) : a = False := eq_false fun ha ↦ False.elim (Eq.mp h (Or.inl ha))
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
eq_false_of_or_eq_false_left
null
eq_false_of_or_eq_false_right {a b : Prop} (h : (a ∨ b) = False) : b = False := eq_false fun hb ↦ False.elim (Eq.mp h (Or.inr hb))
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
eq_false_of_or_eq_false_right
null
eq_false_of_not_eq_true {a : Prop} (h : Not a = True) : a = False := eq_false fun ha ↦ absurd ha (Eq.mpr h trivial) /- Remark: the congruence closure module will only use the following lemma is `CCConfig.em` is `true`. -/
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
eq_false_of_not_eq_true
null
eq_true_of_not_eq_false {a : Prop} (h : Not a = False) : a = True := eq_true (Classical.byContradiction fun hna ↦ Eq.mp h hna)
theorem
Tactic
[ "Mathlib.Init" ]
Mathlib/Tactic/CC/Lemmas.lean
eq_true_of_not_eq_false
null
CCM := StateRefT CCStructure MetaM
abbrev
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
CCM
The monad for the `cc` tactic stores the current state of the tactic.
@[inline] run {α : Type} (x : CCM α) (c : CCStructure) : MetaM (α × CCStructure) := StateRefT'.run x c
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
run
Run a computation in the `CCM` monad.
@[inline] modifyCache (f : CCCongrTheoremCache → CCCongrTheoremCache) : CCM Unit := modify fun cc => { cc with cache := f cc.cache }
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
modifyCache
Update the `cache` field of the state.
@[inline] getCache : CCM CCCongrTheoremCache := do return (← get).cache
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getCache
Read the `cache` field of the state.
getEntry (e : Expr) : CCM (Option Entry) := do return (← get).entries[e]?
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getEntry
Look up an entry associated with the given expression.
normalize (e : Expr) : CCM Expr := do if let some normalizer := (← get).normalizer then normalizer.normalize e else return e
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
normalize
Use the normalizer to normalize `e`. If no normalizer was configured, returns `e` itself.
getRoot (e : Expr) : CCM Expr := do return (← get).root e
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getRoot
Return the root expression of the expression's congruence class.
isCgRoot (e : Expr) : CCM Bool := do return (← get).isCgRoot e
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
isCgRoot
Is `e` the root of its congruence class?
partial isCongruent (e₁ e₂ : Expr) : CCM Bool := do let .app f a := e₁ | failure let .app g b := e₂ | failure if (← getEntry e₁).any Entry.fo then e₁.withApp fun f₁ args₁ => e₂.withApp fun f₂ args₂ => do if ha : args₁.size = args₂.size then for hi : i in [:args₁.size] do if (← getRoot args₁[i]) != (← getRoot (args₂[i]'(ha.symm ▸ hi.2.1))) then return false if f₁ == f₂ then return true else if (← getRoot f₁) != (← getRoot f₂) then return false else if ← pureIsDefEq (← inferType f₁) (← inferType f₂) then return true else return false else return false else if (← getRoot a) != (← getRoot b) then return false else if (← getRoot f) != (← getRoot g) then return false else if ← pureIsDefEq (← inferType f) (← inferType g) then /- Case 1: `f` and `g` have the same type, then we can create a congruence proof for `f a ≍ g b` -/ return true else if f.isApp && g.isApp then isCongruent f g else /- f and g are not congruent nor they have the same type. We can't generate a congruence proof in this case because the following lemma `hcongr : f₁ ≍ f₂ → a₁ ≍ a₂ → f₁ a₁ ≍ f₂ a₂` is not provable. Remark: it is also not provable in MLTT, Coq and Agda (even if we assume UIP). -/ return false
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
isCongruent
Return true iff the given function application are congruent `e₁` should have the form `f a` and `e₂` the form `g b`. See paper: Congruence Closure for Intensional Type Theory.
mkCCHCongrTheorem (fn : Expr) (nargs : Nat) : CCM (Option CCCongrTheorem) := do let cache ← getCache let key₁ : CCCongrTheoremKey := { fn, nargs } if let some it := cache[key₁]? then return it let lemm ← mkCCHCongrWithArity fn nargs if let some lemm := lemm then modifyCache fun ccc => ccc.insert key₁ (some lemm) return lemm modifyCache fun ccc => ccc.insert key₁ none return none
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkCCHCongrTheorem
Try to find a congruence theorem for an application of `fn` with `nargs` arguments, with support for `HEq`.
mkCCCongrTheorem (e : Expr) : CCM (Option CCCongrTheorem) := do let fn := e.getAppFn let nargs := e.getAppNumArgs mkCCHCongrTheorem fn nargs
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkCCCongrTheorem
Try to find a congruence theorem for the expression `e` with support for `HEq`.
setFO (e : Expr) : CCM Unit := modify fun ccs => { ccs with entries := ccs.entries.modify e fun d => { d with fo := true } }
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
setFO
Treat the entry associated with `e` as a first-order function.
partial updateMT (e : Expr) : CCM Unit := do let r ← getRoot e let some ps := (← get).parents[r]? | return for p in ps do let some it ← getEntry p.expr | failure let gmt := (← get).gmt if it.mt < gmt then let newIt := { it with mt := gmt } modify fun ccs => { ccs with entries := ccs.entries.insert p.expr newIt } updateMT p.expr
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
updateMT
Update the modification time of the congruence class of `e`.
hasHEqProofs (root : Expr) : CCM Bool := do let some n ← getEntry root | failure guard (n.root == root) return n.heqProofs
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
hasHEqProofs
Does the congruence class with root `root` have any `HEq` proofs?
flipProofCore (H : Expr) (flipped heqProofs : Bool) : CCM Expr := do let mut newH := H if ← liftM <| pure heqProofs <&&> Expr.isEq <$> (inferType H >>= whnf) then newH ← mkAppM ``heq_of_eq #[H] if !flipped then return newH else if heqProofs then mkHEqSymm newH else mkEqSymm newH
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
flipProofCore
Apply symmetry to `H`, which is an `Eq` or a `HEq`. * If `heqProofs` is true, ensure the result is a `HEq` (otherwise it is assumed to be `Eq`). * If `flipped` is true, apply `symm`, otherwise keep the same direction.
flipDelayedProofCore (H : DelayedExpr) (flipped heqProofs : Bool) : CCM DelayedExpr := do let mut newH := H if heqProofs then newH := .heqOfEq H if !flipped then return newH else if heqProofs then return .heqSymm newH else return .eqSymm newH
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
flipDelayedProofCore
In a delayed way, apply symmetry to `H`, which is an `Eq` or a `HEq`. * If `heqProofs` is true, ensure the result is a `HEq` (otherwise it is assumed to be `Eq`). * If `flipped` is true, apply `symm`, otherwise keep the same direction.
flipProof (H : EntryExpr) (flipped heqProofs : Bool) : CCM EntryExpr := match H with | .ofExpr H => EntryExpr.ofExpr <$> flipProofCore H flipped heqProofs | .ofDExpr H => EntryExpr.ofDExpr <$> flipDelayedProofCore H flipped heqProofs | _ => return H
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
flipProof
Apply symmetry to `H`, which is an `Eq` or a `HEq`. * If `heqProofs` is true, ensure the result is a `HEq` (otherwise it is assumed to be `Eq`). * If `flipped` is true, apply `symm`, otherwise keep the same direction.
isEqv (e₁ e₂ : Expr) : CCM Bool := do let some n₁ ← getEntry e₁ | return false let some n₂ ← getEntry e₂ | return false return n₁.root == n₂.root
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
isEqv
Are `e₁` and `e₂` known to be in the same equivalence class?
isNotEqv (e₁ e₂ : Expr) : CCM Bool := do let tmp ← mkEq e₁ e₂ if ← isEqv tmp (.const ``False []) then return true let tmp ← mkHEq e₁ e₂ isEqv tmp (.const ``False [])
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
isNotEqv
Is `e₁ ≠ e₂` known to be true? Note that this is stronger than `not (isEqv e₁ e₂)`: only if we can prove they are distinct this returns `true`.
@[inline] isEqTrue (e : Expr) : CCM Bool := isEqv e (.const ``True [])
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
isEqTrue
Is the proposition `e` known to be true?
@[inline] isEqFalse (e : Expr) : CCM Bool := isEqv e (.const ``False [])
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
isEqFalse
Is the proposition `e` known to be false?
mkTrans (H₁ H₂ : Expr) (heqProofs : Bool) : MetaM Expr := if heqProofs then mkHEqTrans H₁ H₂ else mkEqTrans H₁ H₂
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkTrans
Apply transitivity to `H₁` and `H₂`, which are both `Eq` or `HEq` depending on `heqProofs`.
mkTransOpt (H₁? : Option Expr) (H₂ : Expr) (heqProofs : Bool) : MetaM Expr := match H₁? with | some H₁ => mkTrans H₁ H₂ heqProofs | none => pure H₂ mutual
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkTransOpt
Apply transitivity to `H₁?` and `H₂`, which are both `Eq` or `HEq` depending on `heqProofs`. If `H₁?` is `none`, return `H₂` instead.
partial mkCongrProofCore (lhs rhs : Expr) (heqProofs : Bool) : CCM Expr := do let mut lhsArgsRev : Array Expr := #[] let mut rhsArgsRev : Array Expr := #[] let mut lhsIt := lhs let mut rhsIt := rhs if lhs != rhs then repeat let .app lhsItFn lhsItArg := lhsIt | failure let .app rhsItFn rhsItArg := rhsIt | failure lhsArgsRev := lhsArgsRev.push lhsItArg rhsArgsRev := rhsArgsRev.push rhsItArg lhsIt := lhsItFn rhsIt := rhsItFn if lhsIt == rhsIt then break if ← pureIsDefEq lhsIt rhsIt then break if ← isEqv lhsIt rhsIt <&&> inferType lhsIt >>= fun i₁ => inferType rhsIt >>= fun i₂ => pureIsDefEq i₁ i₂ then break if lhsArgsRev.isEmpty then if heqProofs then return (← mkHEqRefl lhs) else return (← mkEqRefl lhs) let lhsArgs := lhsArgsRev.reverse let rhsArgs := rhsArgsRev.reverse let PLift.up ha ← if ha : lhsArgs.size = rhsArgs.size then pure (PLift.up ha) else failure let lhsFn := lhsIt let rhsFn := rhsIt guard (← isEqv lhsFn rhsFn <||> pureIsDefEq lhsFn rhsFn) guard (← pureIsDefEq (← inferType lhsFn) (← inferType rhsFn)) /- Create `r`, a proof for `lhsFn lhsArgs[0] ... lhsArgs[n-1] = lhsFn rhsArgs[0] ... rhsArgs[n-1]` where `n := lhsArgs.size` -/ let some specLemma ← mkCCHCongrTheorem lhsFn lhsArgs.size | failure let mut kindsIt := specLemma.argKinds let mut lemmaArgs : Array Expr := #[] for hi : i in [:lhsArgs.size] do guard !kindsIt.isEmpty lemmaArgs := lemmaArgs.push lhsArgs[i] |>.push (rhsArgs[i]'(ha.symm ▸ hi.2.1)) if kindsIt[0]! matches CongrArgKind.heq then let some p ← getHEqProof lhsArgs[i] (rhsArgs[i]'(ha.symm ▸ hi.2.1)) | failure lemmaArgs := lemmaArgs.push p else guard (kindsIt[0]! matches .eq) let some p ← getEqProof lhsArgs[i] (rhsArgs[i]'(ha.symm ▸ hi.2.1)) | failure lemmaArgs := lemmaArgs.push p kindsIt := kindsIt.eraseIdx! 0 let mut r := mkAppN specLemma.proof lemmaArgs if specLemma.heqResult && !heqProofs then ...
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkCongrProofCore
Use congruence on arguments to prove `lhs = rhs`. That is, tries to prove that `lhsFn lhsArgs[0] ... lhsArgs[n-1] = lhsFn rhsArgs[0] ... rhsArgs[n-1]` by showing that `lhsArgs[i] = rhsArgs[i]` for all `i`. Fails if the head function of `lhs` is not that of `rhs`.
partial mkSymmCongrProof (e₁ e₂ : Expr) (heqProofs : Bool) : CCM (Option Expr) := do let some (R₁, lhs₁, rhs₁) ← e₁.relSidesIfSymm? | return none let some (R₂, lhs₂, rhs₂) ← e₂.relSidesIfSymm? | return none if R₁ != R₂ then return none if (← isEqv lhs₁ lhs₂) then return none guard (← isEqv lhs₁ rhs₂) /- We must apply symmetry. The symm congruence table is implicitly using symmetry. That is, we have `e₁ := lhs₁ ~R₁~ rhs₁` and `e2 := lhs₂ ~R₁~ rhs₂` But, `lhs₁ ~R₁~ rhs₂` and `rhs₁ ~R₁~ lhs₂` -/ /- Given `e₁ := lhs₁ ~R₁~ rhs₁`, create proof for `lhs₁ ~R₁~ rhs₁` = `rhs₁ ~R₁~ lhs₁` -/ let newE₁ ← mkRel R₁ rhs₁ lhs₁ let e₁IffNewE₁ ← withLocalDeclD `h₁ e₁ fun h₁ => withLocalDeclD `h₂ newE₁ fun h₂ => do mkAppM ``Iff.intro #[← mkLambdaFVars #[h₁] (← h₁.applySymm), ← mkLambdaFVars #[h₂] (← h₂.applySymm)] let mut e₁EqNewE₁ := mkApp3 (.const ``propext []) e₁ newE₁ e₁IffNewE₁ let newE₁EqE₂ ← mkCongrProofCore newE₁ e₂ heqProofs if heqProofs then e₁EqNewE₁ ← mkAppM ``heq_of_eq #[e₁EqNewE₁] return some (← mkTrans e₁EqNewE₁ newE₁EqE₂ heqProofs)
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkSymmCongrProof
If `e₁ : R lhs₁ rhs₁`, `e₂ : R lhs₂ rhs₂` and `lhs₁ = rhs₂`, where `R` is a symmetric relation, prove `R lhs₁ rhs₁` is equivalent to `R lhs₂ rhs₂`. * if `lhs₁` is known to equal `lhs₂`, return `none` * if `lhs₁` is not known to equal `rhs₂`, fail.
partial mkCongrProof (e₁ e₂ : Expr) (heqProofs : Bool) : CCM Expr := do if let some r ← mkSymmCongrProof e₁ e₂ heqProofs then return r else mkCongrProofCore e₁ e₂ heqProofs
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkCongrProof
Use congruence on arguments to prove `e₁ = e₂`. Special case: if `e₁` and `e₂` have the form `R lhs₁ rhs₁` and `R lhs₂ rhs₂` such that `R` is symmetric and `lhs₁ = rhs₂`, then use those facts instead.
partial mkDelayedProof (H : DelayedExpr) : CCM Expr := do match H with | .ofExpr H => return H | .eqProof lhs rhs => liftOption (← getEqProof lhs rhs) | .congrArg f h => mkCongrArg f (← mkDelayedProof h) | .congrFun h a => mkCongrFun (← mkDelayedProof h) (← liftOption a.toExpr) | .eqSymm h => mkEqSymm (← mkDelayedProof h) | .eqSymmOpt a₁ a₂ h => mkAppOptM ``Eq.symm #[none, ← liftOption a₁.toExpr, ← liftOption a₂.toExpr, ← mkDelayedProof h] | .eqTrans h₁ h₂ => mkEqTrans (← mkDelayedProof h₁) (← mkDelayedProof h₂) | .eqTransOpt a₁ a₂ a₃ h₁ h₂ => mkAppOptM ``Eq.trans #[none, ← liftOption a₁.toExpr, ← liftOption a₂.toExpr, ← liftOption a₃.toExpr, ← mkDelayedProof h₁, ← mkDelayedProof h₂] | .heqOfEq h => mkAppM ``heq_of_eq #[← mkDelayedProof h] | .heqSymm h => mkHEqSymm (← mkDelayedProof h)
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkDelayedProof
Turn a delayed proof into an actual proof term.
partial mkProof (lhs rhs : Expr) (H : EntryExpr) (heqProofs : Bool) : CCM Expr := do match H with | .congr => mkCongrProof lhs rhs heqProofs | .eqTrue => let (flip, some (R, a, b)) ← if lhs == .const ``True [] then ((true, ·)) <$> rhs.relSidesIfRefl? else ((false, ·)) <$> lhs.relSidesIfRefl? | failure let aRb ← if R == ``Eq then getEqProof a b >>= liftOption else if R == ``HEq then getHEqProof a b >>= liftOption else getEqProof a b >>= liftOption >>= fun aEqb => liftM (liftFromEq R aEqb) let aRbEqTrue ← mkEqTrue aRb if flip then mkEqSymm aRbEqTrue else return aRbEqTrue | .refl => let type ← if heqProofs then mkHEq lhs rhs else mkEq lhs rhs let proof ← if heqProofs then mkHEqRefl lhs else mkEqRefl lhs mkExpectedTypeHint proof type | .ofExpr H => return H | .ofDExpr H => mkDelayedProof H
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkProof
Use the format of `H` to try and construct a proof or `lhs = rhs`: * If `H = .congr`, then use congruence. * If `H = .eqTrue`, try to prove `lhs = True` or `rhs = True`, if they have the format `R a b`, by proving `a = b`. * Otherwise, return the (delayed) proof encoded by `H` itself.
partial getEqProofCore (e₁ e₂ : Expr) (asHEq : Bool) : CCM (Option Expr) := do if e₁.hasExprMVar || e₂.hasExprMVar then return none if ← pureIsDefEq e₁ e₂ then if asHEq then return some (← mkHEqRefl e₁) else return some (← mkEqRefl e₁) let some n₁ ← getEntry e₁ | return none let some n₂ ← getEntry e₂ | return none if n₁.root != n₂.root then return none let heqProofs ← hasHEqProofs n₁.root let mut path₁ : Array Expr := #[] let mut Hs₁ : Array EntryExpr := #[] let mut visited : ExprSet := ∅ let mut it₁ := e₁ repeat visited := visited.insert it₁ let some it₁N ← getEntry it₁ | failure let some t := it₁N.target | break path₁ := path₁.push t let some p := it₁N.proof | failure Hs₁ := Hs₁.push (← flipProof p it₁N.flipped heqProofs) it₁ := t guard (it₁ == n₁.root) let mut path₂ : Array Expr := #[] let mut Hs₂ : Array EntryExpr := #[] let mut it₂ := e₂ repeat if visited.contains it₂ then break -- found common let some it₂N ← getEntry it₂ | failure let some t := it₂N.target | failure path₂ := path₂.push it₂ let some p := it₂N.proof | failure Hs₂ := Hs₂.push (← flipProof p (!it₂N.flipped) heqProofs) it₂ := t repeat if path₁.isEmpty then guard (it₂ == e₁) break if path₁.back! == it₂ then break path₁ := path₁.pop Hs₁ := Hs₁.pop let mut pr? : Option Expr := none let mut lhs := e₁ for h : i in [:path₁.size] do pr? ← some <$> mkTransOpt pr? (← mkProof lhs path₁[i] Hs₁[i]! heqProofs) heqProofs lhs := path₁[i] let mut i := Hs₂.size while i > 0 do ...
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getEqProofCore
If `asHEq` is `true`, then build a proof for `e₁ ≍ e₂`. Otherwise, build a proof for `e₁ = e₂`. The result is `none` if `e₁` and `e₂` are not in the same equivalence class.
@[inline] partial getEqProof (e₁ e₂ : Expr) : CCM (Option Expr) := getEqProofCore e₁ e₂ false
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getEqProof
Build a proof for `e₁ = e₂`. The result is `none` if `e₁` and `e₂` are not in the same equivalence class.
@[inline] partial getHEqProof (e₁ e₂ : Expr) : CCM (Option Expr) := getEqProofCore e₁ e₂ true
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getHEqProof
Build a proof for `e₁ ≍ e₂`. The result is `none` if `e₁` and `e₂` are not in the same equivalence class.
getEqTrueProof (e : Expr) : CCM Expr := do guard (← isEqTrue e) let some p ← getEqProof e (.const ``True []) | failure return p
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getEqTrueProof
Build a proof for `e = True`. Fails if `e` is not known to be true.
getEqFalseProof (e : Expr) : CCM Expr := do guard (← isEqFalse e) let some p ← getEqProof e (.const ``False []) | failure return p
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getEqFalseProof
Build a proof for `e = False`. Fails if `e` is not known to be false.
getPropEqProof (a b : Expr) : CCM Expr := do guard (← isEqv a b) let some p ← getEqProof a b | failure return p
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getPropEqProof
Build a proof for `a = b`. Fails if `a` and `b` are not known to be equal.
getInconsistencyProof : CCM (Option Expr) := do guard !(← get).frozePartitions if let some p ← getEqProof (.const ``True []) (.const ``False []) then return some (← mkAppM ``false_of_true_eq_false #[p]) else return none
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
getInconsistencyProof
Build a proof of `False` if the context is inconsistent. Returns `none` if `False` is not known to be true.
mkNeOfEqOfNe (a a₁ a₁NeB : Expr) : CCM (Option Expr) := do guard (← isEqv a a₁) if a == a₁ then return some a₁NeB let aEqA₁ ← getEqProof a a₁ match aEqA₁ with | none => return none -- failed to build proof | some aEqA₁ => mkAppM ``ne_of_eq_of_ne #[aEqA₁, a₁NeB]
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkNeOfEqOfNe
Given `a`, `a₁` and `a₁NeB : a₁ ≠ b`, return a proof of `a ≠ b` if `a` and `a₁` are in the same equivalence class.
mkNeOfNeOfEq (aNeB₁ b₁ b : Expr) : CCM (Option Expr) := do guard (← isEqv b b₁) if b == b₁ then return some aNeB₁ let b₁EqB ← getEqProof b b₁ match b₁EqB with | none => return none -- failed to build proof | some b₁EqB => mkAppM ``ne_of_ne_of_eq #[aNeB₁, b₁EqB]
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkNeOfNeOfEq
Given `aNeB₁ : a ≠ b₁`, `b₁` and `b`, return a proof of `a ≠ b` if `b` and `b₁` are in the same equivalence class.
mkACProof (e₁ e₂ : Expr) : MetaM Expr := do let eq ← mkEq e₁ e₂ let .mvar m ← mkFreshExprSyntheticOpaqueMVar eq | failure AC.rewriteUnnormalizedRefl m let pr ← instantiateMVars (.mvar m) mkExpectedTypeHint pr eq
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkACProof
Return the proof of `e₁ = e₂` using `ac_rfl` tactic.
mkACSimpProof (tr t s r sr : ACApps) (tEqs : DelayedExpr) : MetaM DelayedExpr := do if tr == t then return tEqs else if tr == sr then let some tre := tr.toExpr | failure DelayedExpr.ofExpr <$> mkEqRefl tre else let .apps op _ := tr | failure let some re := r.toExpr | failure let some te := t.toExpr | failure let some se := s.toExpr | failure let some tre := tr.toExpr | failure let some sre := sr.toExpr | failure let opr := op.app re -- `(*) r` let rt := mkApp2 op re te -- `r * t` let rs := mkApp2 op re se -- `r * s` let rtEqrs := DelayedExpr.congrArg opr tEqs let trEqrt ← mkACProof tre rt let rsEqsr ← mkACProof rs sre return .eqTrans (.eqTrans trEqrt rtEqrs) rsEqsr
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
mkACSimpProof
Given `tr := t*r` `sr := s*r` `tEqs : t = s`, return a proof for `tr = sr` We use `a*b` to denote an AC application. That is, `(a*b)*(c*a)` is the term `a*a*b*c`.
simplifyACCore (e lhs rhs : ACApps) (H : DelayedExpr) : CCM (ACApps × DelayedExpr) := do guard (lhs.isSubset e) if e == lhs then return (rhs, H) else let .apps op _ := e | failure let newArgs := e.diff lhs let r : ACApps := if newArgs.isEmpty then default else .mkApps op newArgs let newArgs := ACApps.append op rhs newArgs let newE := ACApps.mkApps op newArgs let some true := (← get).opInfo[op]? | failure let newPr ← mkACSimpProof e lhs rhs r newE H return (newE, newPr)
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
simplifyACCore
Given `e := lhs * r` and `H : lhs = rhs`, return `rhs * r` and the proof of `e = rhs * r`.
simplifyACStep (e : ACApps) : CCM (Option (ACApps × DelayedExpr)) := do if let .apps _ args := e then for h : i in [:args.size] do if i == 0 || args[i] != (args[i - 1]'(Nat.lt_of_le_of_lt (i.sub_le 1) h.2.1)) then let some ae := (← get).acEntries[args[i]]? | failure let occs := ae.RLHSOccs let mut Rlhs? : Option ACApps := none for Rlhs in occs do if Rlhs.isSubset e then Rlhs? := some Rlhs break if let some Rlhs := Rlhs? then let some (Rrhs, H) := (← get).acR[Rlhs]? | failure return (some <| ← simplifyACCore e Rlhs Rrhs H) else if let some p := (← get).acR[e]? then return some p return none
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
simplifyACStep
The single step of `simplifyAC`. Simplifies an expression `e` by either simplifying one argument to the AC operator, or the whole expression.
simplifyAC (e : ACApps) : CCM (Option (ACApps × DelayedExpr)) := do let mut some (curr, pr) ← simplifyACStep e | return none repeat let some (newCurr, newPr) ← simplifyACStep curr | break pr := .eqTransOpt e curr newCurr pr newPr curr := newCurr return some (curr, pr)
def
Tactic
[ "Mathlib.Tactic.CC.Datatypes", "Mathlib.Tactic.CC.Lemmas", "Mathlib.Tactic.Relation.Rfl", "Mathlib.Tactic.Relation.Symm" ]
Mathlib/Tactic/CC/MkProof.lean
simplifyAC
If `e` can be simplified by the AC module, return the simplified term and the proof term of the equality.
Status where /-- `├` Start intro (top-level) -/ | sintro : Status /-- `Entry.depth` * `│` + `┌` Normal intro -/ | intro : Status /-- `Entry.depth` * `│` + `├` Continuation intro -/ | cintro : Status /-- `Entry.depth` * `│` -/ | lam : Status /-- `Entry.depth` * `│` -/ | reg : Status deriving Inhabited
inductive
Tactic
[ "Mathlib.Init", "Lean.Util.Trace" ]
Mathlib/Tactic/Explode/Datatypes.lean
Status
How to display pipes (`│`) for this entry in the Fitch table .
Entry where /-- A type of this expression as a `MessageData`. Make sure to use `addMessageContext`. -/ type : MessageData /-- The row number, starting from `0`. This is set by `Entries.add`. -/ line : Option Nat := none /-- How many `if`s (aka lambda-abstractions) this row is nested under. -/ depth : Nat /-- What `Status` this entry has - this only affects how `│`s are displayed. -/ status : Status /-- What to display in the "theorem applied" column. Make sure to use `addMessageContext` if needed. -/ thm : MessageData /-- Which other lines (aka rows) this row depends on. `none` means that the dependency has been filtered out of the table. -/ deps : List (Option Nat) /-- Whether or not to use this in future deps lists. Generally controlled by the `select` function passed to `explodeCore`. Exception: `∀I` may ignore this for introduced hypotheses. -/ useAsDep : Bool
structure
Tactic
[ "Mathlib.Init", "Lean.Util.Trace" ]
Mathlib/Tactic/Explode/Datatypes.lean
Entry
The row in the Fitch table.
Entry.line! (entry : Entry) : Nat := entry.line.get!
def
Tactic
[ "Mathlib.Init", "Lean.Util.Trace" ]
Mathlib/Tactic/Explode/Datatypes.lean
Entry.line
Get the `line` for an `Entry` that has been added to the `Entries` structure.
Entries : Type where /-- Allows us to compare `Expr`s fast. -/ s : ExprMap Entry /-- Simple list of `Expr`s. -/ l : List Entry deriving Inhabited
structure
Tactic
[ "Mathlib.Init", "Lean.Util.Trace" ]
Mathlib/Tactic/Explode/Datatypes.lean
Entries
Instead of simply keeping a list of entries (`List Entry`), we create a datatype `Entries` that allows us to compare expressions faster.
Entries.find? (es : Entries) (e : Expr) : Option Entry := es.s[e]?
def
Tactic
[ "Mathlib.Init", "Lean.Util.Trace" ]
Mathlib/Tactic/Explode/Datatypes.lean
Entries.find
Find a row where `Entry.expr` == `e`.
Entries.size (es : Entries) : Nat := es.s.size
def
Tactic
[ "Mathlib.Init", "Lean.Util.Trace" ]
Mathlib/Tactic/Explode/Datatypes.lean
Entries.size
Length of our entries.
Entries.add (entries : Entries) (expr : Expr) (entry : Entry) : Entry × Entries := if let some entry' := entries.find? expr then (entry', entries) else let entry := { entry with line := entries.size } (entry, ⟨entries.s.insert expr entry, entry :: entries.l⟩)
def
Tactic
[ "Mathlib.Init", "Lean.Util.Trace" ]
Mathlib/Tactic/Explode/Datatypes.lean
Entries.add
Add the entry unless it already exists. Sets the `line` field to the next available value.
Entries.addSynonym (entries : Entries) (expr : Expr) (entry : Entry) : Entries := ⟨entries.s.insert expr entry, entries.l⟩
def
Tactic
[ "Mathlib.Init", "Lean.Util.Trace" ]
Mathlib/Tactic/Explode/Datatypes.lean
Entries.addSynonym
Add a pre-existing entry to the `ExprMap` for an additional expression. This is used by `let` bindings where `expr` is an fvar.
padRight (mds : List MessageData) : MetaM (List MessageData) := do let mut maxLength := 0 for md in mds do maxLength := max maxLength (← md.toString).length let pad (md : MessageData) : MetaM MessageData := do let padWidth : Nat := maxLength - (← md.toString).length return md ++ "".pushn ' ' padWidth mds.mapM pad
def
Tactic
[ "Lean.Meta.Basic", "Mathlib.Tactic.Explode.Datatypes" ]
Mathlib/Tactic/Explode/Pretty.lean
padRight
Given a list of `MessageData`s, make them of equal length. We need this in order to form columns in our Fitch table. ```lean padRight ["hi", "hello"] = ["hi ", "hello"] ```
rowToMessageData : List MessageData → List MessageData → List MessageData → List Entry → MetaM MessageData | line :: lines, dep :: deps, thm :: thms, en :: es => do let pipes := String.join (List.replicate en.depth "│ ") let pipes := match en.status with | Status.sintro => s!"├ " | Status.intro => s!"│ {pipes}┌ " | Status.cintro => s!"│ {pipes}├ " | Status.lam => s!"│ {pipes}" | Status.reg => s!"│ {pipes}" let row := m!"{line}│{dep}│ {thm} {pipes}{en.type}\n" return (← rowToMessageData lines deps thms es).compose row | _, _, _, _ => return MessageData.nil
def
Tactic
[ "Lean.Meta.Basic", "Mathlib.Tactic.Explode.Datatypes" ]
Mathlib/Tactic/Explode/Pretty.lean
rowToMessageData
Render a particular row of the Fitch table.
entriesToMessageData (entries : Entries) : MetaM MessageData := do let paddedLines ← padRight <| entries.l.map fun entry => m!"{entry.line!}" let paddedDeps ← padRight <| entries.l.map fun entry => String.intercalate "," <| entry.deps.map (fun dep => (dep.map toString).getD "_") let paddedThms ← padRight <| entries.l.map (·.thm) rowToMessageData paddedLines paddedDeps paddedThms entries.l
def
Tactic
[ "Lean.Meta.Basic", "Mathlib.Tactic.Explode.Datatypes" ]
Mathlib/Tactic/Explode/Pretty.lean
entriesToMessageData
Given all `Entries`, return the entire Fitch table.
private dischargerTraceMessage {ε : Type*} (prop : Expr) : Except ε (Option Expr) → SimpM MessageData | .error _ | .ok none => return m!"{crossEmoji} discharge {prop}" | .ok (some _) => return m!"{checkEmoji} discharge {prop}" open private Simp.dischargeUsingAssumption? from Lean.Meta.Tactic.Simp.Rewrite
def
Tactic
[ "Mathlib.Tactic.Positivity.Core", "Mathlib.Util.DischargerAsTactic" ]
Mathlib/Tactic/FieldSimp/Discharger.lean
dischargerTraceMessage
Constructs a trace message for the `discharge` function.
partial discharge (prop : Expr) : SimpM (Option Expr) := withTraceNode `Tactic.field_simp (dischargerTraceMessage prop) do if let some r ← Simp.dischargeUsingAssumption? prop then return some r let prop : Q(Prop) ← (do pure prop) let pf? ← match prop with | ~q(($e : $α) ≠ $b) => try let res ← Mathlib.Meta.NormNum.derive prop match res with | .isTrue pf => pure (some pf) | _ => pure none catch _ => pure none | _ => pure none if let some pf := pf? then return some pf let pf? ← try some <$> Mathlib.Meta.Positivity.solve prop catch _ => pure none if let some pf := pf? then return some pf Simp.withIncDischargeDepth do let ctx ← readThe Simp.Context let lems := [``two_ne_zero, ``three_ne_zero, ``four_ne_zero, ``mul_ne_zero, ``pow_ne_zero, ``zpow_ne_zero, ``Nat.cast_add_one_ne_zero] let ctx' := ctx.setSimpTheorems <| ctx.simpTheorems.push <| ← lems.foldlM (SimpTheorems.addConst · · (post := false)) {} let stats : Simp.Stats := { (← get) with } let ⟨simpResult, stats'⟩ ← simp prop ctx' #[(← Simp.getSimprocs)] discharge stats set { (← get) with usedTheorems := stats'.usedTheorems, diag := stats'.diag } if simpResult.expr.isConstOf ``True then try return some (← mkOfEqTrue (← simpResult.getProof)) catch _ => return none else return none @[inherit_doc discharge] elab "field_simp_discharge" : tactic => wrapSimpDischarger Mathlib.Tactic.FieldSimp.discharge
def
Tactic
[ "Mathlib.Tactic.Positivity.Core", "Mathlib.Util.DischargerAsTactic" ]
Mathlib/Tactic/FieldSimp/Discharger.lean
discharge
Discharge strategy for the `field_simp` tactic.
noncomputable zpow' (a : α) (n : ℤ) : α := if a = 0 ∧ n = 0 then 0 else a ^ n
def
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'
This is a variant of integer exponentiation, defined for internal use in the `field_simp` tactic implementation. It differs from the usual integer exponentiation in that `0 ^ 0` is `0`, not `1`. With this choice, the function `n ↦ a ^ n` is always a homomorphism (`a ^ (n + m) = a ^ n * a ^ m`), even if `a` is zero.
zpow'_add (a : α) (m n : ℤ) : zpow' a (m + n) = zpow' a m * zpow' a n := by by_cases ha : a = 0 · simp [zpow', ha] by_cases hn : n = 0 · simp +contextual [hn, zero_zpow] · simp +contextual [hn, zero_zpow] · simp [zpow', ha, zpow_add₀]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_add
null
zpow'_of_ne_zero_right (a : α) (n : ℤ) (hn : n ≠ 0) : zpow' a n = a ^ n := by simp [zpow', hn]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_of_ne_zero_right
null
zpow'_of_ne_zero_left (a : α) (n : ℤ) (ha : a ≠ 0) : zpow' a n = a ^ n := by simp [zpow', ha] @[simp]
theorem
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_of_ne_zero_left
null
zero_zpow' (n : ℤ) : zpow' (0 : α) n = 0 := by simp +contextual only [zpow', true_and, ite_eq_left_iff] intro hn exact zero_zpow n hn
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zero_zpow'
null
zpow'_eq_zero_iff (a : α) (n : ℤ) : zpow' a n = 0 ↔ a = 0 := by obtain rfl | hn := eq_or_ne n 0 · simp [zpow'] · simp [zpow', zpow_eq_zero_iff hn] tauto @[simp]
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_eq_zero_iff
null
one_zpow' (n : ℤ) : zpow' (1 : α) n = 1 := by simp [zpow'] @[simp]
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
one_zpow'
null
zpow'_one (a : α) : zpow' a 1 = a := by simp [zpow']
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_one
null
zpow'_zero_eq_div (a : α) : zpow' a 0 = a / a := by simp [zpow'] by_cases h : a = 0 · simp [h] · simp [h]
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_zero_eq_div
null
zpow'_zero_of_ne_zero {a : α} (ha : a ≠ 0) : zpow' a 0 = 1 := by simp [zpow', ha]
lemma
Tactic
[ "Mathlib.Algebra.BigOperators.Group.List.Basic", "Mathlib.Algebra.Field.Power", "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic", "Mathlib.Util.Qq" ]
Mathlib/Tactic/FieldSimp/Lemmas.lean
zpow'_zero_of_ne_zero
null