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 ⌀ |
|---|---|---|---|---|---|---|
exception' (msg : MessageData) : TacticM Unit := do
try
liftMetaTactic (exception (msg := msg))
catch _ =>
throwError msg
set_option quotPrecheck false in | def | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | exception' | Helper function for throwing exceptions with respect to the main goal. |
bicategory_coherence (g : MVarId) : TermElabM Unit := g.withContext do
withOptions (fun opts => synthInstance.maxSize.set opts
(max 256 (synthInstance.maxSize.get opts))) do
let thms := [``BicategoricalCoherence.iso, ``Iso.trans, ``Iso.symm, ``Iso.refl,
``Bicategory.whiskerRightIso, ``Bicategory.whiskerLeft... | def | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | bicategory_coherence | Auxiliary definition for `bicategorical_coherence`. -/
-- We could construct this expression directly without using `elabTerm`,
-- but it would require preparing many implicit arguments by hand.
def mkLiftMap₂LiftExpr (e : Expr) : TermElabM Expr := do
Term.elabTerm
(← ``((FreeBicategory.lift (Prefunctor.id _)).ma... |
@[nolint unusedArguments]
assoc_liftHom₂ {f g h i : a ⟶ b} [LiftHom f] [LiftHom g] [LiftHom h]
(η : f ⟶ g) (θ : g ⟶ h) (ι : h ⟶ i) [LiftHom₂ η] [LiftHom₂ θ] : η ≫ θ ≫ ι = (η ≫ θ) ≫ ι :=
(Category.assoc _ _ _).symm | theorem | Tactic | [
"Mathlib.CategoryTheory.Bicategory.Coherence",
"Mathlib.Tactic.CategoryTheory.BicategoricalComp"
] | Mathlib/Tactic/CategoryTheory/BicategoryCoherence.lean | assoc_liftHom₂ | Coherence tactic for bicategories.
Use `pure_coherence` instead, which is a frontend to this one. -/
elab "bicategory_coherence" : tactic => do bicategory_coherence (← getMainGoal)
open Lean.Parser.Tactic
/--
Simp lemmas for rewriting a 2-morphism into a normal form.
-/
syntax (name := whisker_simps) "whisker_simps" ... |
forEachComposition (e : Expr) (f : Expr → MetaM Unit) : MetaM Unit := do
e.forEach (fun e ↦ if e.isAppOfArity ``CategoryStruct.comp 7 then f e else pure ()) | def | Tactic | [
"Mathlib.CategoryTheory.Category.Basic"
] | Mathlib/Tactic/CategoryTheory/CheckCompositions.lean | forEachComposition | Find appearances of `CategoryStruct.comp C inst X Y Z f g`, and apply `f` to each. |
checkComposition (e : Expr) : MetaM Unit := do
match_expr e with
| CategoryStruct.comp _ _ X Y Z f g =>
match_expr ← inferType f with
| Quiver.Hom _ _ X' Y' =>
withReducibleAndInstances do
if !(← isDefEq X' X) then
logInfo m!"In composition\n {e}\nthe source of\n {f}\nis\n {X'}\nb... | def | Tactic | [
"Mathlib.CategoryTheory.Category.Basic"
] | Mathlib/Tactic/CategoryTheory/CheckCompositions.lean | checkComposition | Given a composition `CategoryStruct.comp _ _ X Y Z f g`,
infer the types of `f` and `g` and check whether their sources and targets agree,
at "instances and reducible" transparency, with `X`, `Y`, and `Z`,
reporting any discrepancies. |
checkCompositions (e : Expr) : MetaM Unit := do
forEachComposition e checkComposition | def | Tactic | [
"Mathlib.CategoryTheory.Category.Basic"
] | Mathlib/Tactic/CategoryTheory/CheckCompositions.lean | checkCompositions | Check the typing of categorical compositions in an expression. |
checkCompositionsTac : TacticM Unit := withMainContext do
let e ← getMainTarget
checkCompositions e | def | Tactic | [
"Mathlib.CategoryTheory.Category.Basic"
] | Mathlib/Tactic/CategoryTheory/CheckCompositions.lean | checkCompositionsTac | Check the typing of categorical compositions in the goal. |
LiftObj (X : C) where
protected lift : FreeMonoidalCategory C | class | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftObj | A typeclass carrying a choice of lift of an object from `C` to `FreeMonoidalCategory C`.
It must be the case that `projectObj id (LiftObj.lift x) = x` by defeq. |
LiftObj_unit : LiftObj (𝟙_ C) := ⟨unit⟩ | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftObj_unit | null |
LiftObj_tensor (X Y : C) [LiftObj X] [LiftObj Y] : LiftObj (X ⊗ Y) where
lift := LiftObj.lift X ⊗ LiftObj.lift Y | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftObj_tensor | null |
LiftHom {X Y : C} [LiftObj X] [LiftObj Y] (f : X ⟶ Y) where
protected lift : LiftObj.lift X ⟶ LiftObj.lift Y | class | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom | A typeclass carrying a choice of lift of a morphism from `C` to `FreeMonoidalCategory C`.
It must be the case that `projectMap id _ _ (LiftHom.lift f) = f` by defeq. |
LiftHom_id (X : C) [LiftObj X] : LiftHom (𝟙 X) := ⟨𝟙 _⟩ | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_id | null |
LiftHom_left_unitor_hom (X : C) [LiftObj X] : LiftHom (λ_ X).hom where
lift := (λ_ (LiftObj.lift X)).hom | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_left_unitor_hom | null |
LiftHom_left_unitor_inv (X : C) [LiftObj X] : LiftHom (λ_ X).inv where
lift := (λ_ (LiftObj.lift X)).inv | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_left_unitor_inv | null |
LiftHom_right_unitor_hom (X : C) [LiftObj X] : LiftHom (ρ_ X).hom where
lift := (ρ_ (LiftObj.lift X)).hom | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_right_unitor_hom | null |
LiftHom_right_unitor_inv (X : C) [LiftObj X] : LiftHom (ρ_ X).inv where
lift := (ρ_ (LiftObj.lift X)).inv | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_right_unitor_inv | null |
LiftHom_associator_hom (X Y Z : C) [LiftObj X] [LiftObj Y] [LiftObj Z] :
LiftHom (α_ X Y Z).hom where
lift := (α_ (LiftObj.lift X) (LiftObj.lift Y) (LiftObj.lift Z)).hom | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_associator_hom | null |
LiftHom_associator_inv (X Y Z : C) [LiftObj X] [LiftObj Y] [LiftObj Z] :
LiftHom (α_ X Y Z).inv where
lift := (α_ (LiftObj.lift X) (LiftObj.lift Y) (LiftObj.lift Z)).inv | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_associator_inv | null |
LiftHom_comp {X Y Z : C} [LiftObj X] [LiftObj Y] [LiftObj Z] (f : X ⟶ Y) (g : Y ⟶ Z)
[LiftHom f] [LiftHom g] : LiftHom (f ≫ g) where
lift := LiftHom.lift f ≫ LiftHom.lift g | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_comp | null |
liftHom_WhiskerLeft (X : C) [LiftObj X] {Y Z : C} [LiftObj Y] [LiftObj Z]
(f : Y ⟶ Z) [LiftHom f] : LiftHom (X ◁ f) where
lift := LiftObj.lift X ◁ LiftHom.lift f | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | liftHom_WhiskerLeft | null |
liftHom_WhiskerRight {X Y : C} (f : X ⟶ Y) [LiftObj X] [LiftObj Y] [LiftHom f]
{Z : C} [LiftObj Z] : LiftHom (f ▷ Z) where
lift := LiftHom.lift f ▷ LiftObj.lift Z | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | liftHom_WhiskerRight | null |
LiftHom_tensor {W X Y Z : C} [LiftObj W] [LiftObj X] [LiftObj Y] [LiftObj Z]
(f : W ⟶ X) (g : Y ⟶ Z) [LiftHom f] [LiftHom g] : LiftHom (f ⊗ₘ g) where
lift := LiftHom.lift f ⊗ₘ LiftHom.lift g | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | LiftHom_tensor | null |
exception {α : Type} (g : MVarId) (msg : MessageData) : MetaM α :=
throwTacticEx `monoidal_coherence g msg | def | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | exception | Helper function for throwing exceptions. |
exception' (msg : MessageData) : TacticM Unit := do
try
liftMetaTactic (exception (msg := msg))
catch _ =>
throwError msg | def | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | exception' | Helper function for throwing exceptions with respect to the main goal. |
monoidal_coherence (g : MVarId) : TermElabM Unit := g.withContext do
withOptions (fun opts => synthInstance.maxSize.set opts
(max 512 (synthInstance.maxSize.get opts))) do
let thms := [``MonoidalCoherence.iso, ``Iso.trans, ``Iso.symm, ``Iso.refl,
``MonoidalCategory.whiskerRightIso, ``MonoidalCategory.whiske... | def | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | monoidal_coherence | Auxiliary definition for `monoidal_coherence`. -/
-- We could construct this expression directly without using `elabTerm`,
-- but it would require preparing many implicit arguments by hand.
def mkProjectMapExpr (e : Expr) : TermElabM Expr := do
Term.elabTerm
(← ``(FreeMonoidalCategory.projectMap _root_.id _ _ (Li... |
insertTrailingIds (g : MVarId) : MetaM MVarId := do
let some (_, lhs, rhs) := (← withReducible g.getType').eq? | exception g "Not an equality."
let mut g := g
if !(lhs.isAppOf ``CategoryStruct.comp) then
let [g'] ← g.applyConst ``insert_id_lhs | exception g "failed to apply insert_id_lhs"
g := g'
if !(r... | def | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | insertTrailingIds | Coherence tactic for monoidal categories.
Use `pure_coherence` instead, which is a frontend to this one. -/
elab "monoidal_coherence" : tactic => do monoidal_coherence (← getMainGoal)
open Mathlib.Tactic.BicategoryCoherence
/--
`pure_coherence` uses the coherence theorem for monoidal categories to prove the goal.
It ... |
coherence_loop (maxSteps := 37) : TacticM Unit :=
match maxSteps with
| 0 => exception' "`coherence` tactic reached iteration limit"
| maxSteps' + 1 => do
evalTactic (← `(tactic| pure_coherence)) <|> do
evalTactic (← `(tactic| liftable_prefixes)) <|>
exception' "Something went wrong in the `coherenc... | def | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Free.Coherence",
"Mathlib.Lean.Meta",
"Mathlib.Tactic.CategoryTheory.BicategoryCoherence",
"Mathlib.Tactic.CategoryTheory.MonoidalComp"
] | Mathlib/Tactic/CategoryTheory/Coherence.lean | coherence_loop | null |
forall_congr_forget_Type (α : Type u) (p : α → Prop) :
(∀ (x : (forget (Type u)).obj α), p x) ↔ ∀ (x : α), p x := Iff.rfl
attribute [local instance] HasForget.instFunLike HasForget.hasCoeToSort | theorem | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | forall_congr_forget_Type | null |
forget_hom_Type (α β : Type u) (f : α ⟶ β) : DFunLike.coe f = f := rfl | theorem | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | forget_hom_Type | null |
hom_elementwise {C : Type*} [Category C] [HasForget C]
{X Y : C} {f g : X ⟶ Y} (h : f = g) (x : X) : f x = g x := by rw [h] | theorem | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | hom_elementwise | null |
elementwiseThms : List Name :=
[ -- HasForget lemmas
``CategoryTheory.coe_id, ``CategoryTheory.coe_comp, ``CategoryTheory.comp_apply,
``CategoryTheory.id_apply,
``CategoryTheory.hom_id, ``CategoryTheory.hom_comp, ``id_eq, ``Function.comp_apply,
``forget_hom_Type, ``forall_congr_forget_Type, ``types_co... | def | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | elementwiseThms | List of simp lemmas to apply to the elementwise theorem. |
elementwiseExpr (src : Name) (type pf : Expr) (simpSides := true) :
MetaM (Expr × Option (Level × Level)) := do
let type := (← instantiateMVars type).cleanupAnnotations
forallTelescope type fun fvars type' => do
mkHomElementwise type' (← mkExpectedTypeHint (mkAppN pf fvars) type') fun eqPf instConcr? => do
... | def | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | elementwiseExpr | Given an equation `f = g` between morphisms `X ⟶ Y` in a category `C`
(possibly after a `∀` binder), produce the equation `∀ (x : X), f x = g x` or
`∀ [HasForget C] (x : X), f x = g x` as needed (after the `∀` binder), but
with compositions fully right associated and identities removed.
Returns the proof of the new th... |
private partial mkUnusedName (names : List Name) (baseName : Name) : Name :=
if not (names.contains baseName) then
baseName
else
let rec loop (i : Nat := 0) : Name :=
let w := Name.appendIndexAfter baseName i
if names.contains w then
loop (i + 1)
else
w
loop 1 | def | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | mkUnusedName | Gives a name based on `baseName` that's not already in the list. |
@[elementwise]
some_lemma {C : Type*} [Category C]
{X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : X ⟶ Z) (w : ...) : f ≫ g = h := ...
```
produces
```lean | lemma | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | some_lemma | null |
some_lemma_apply {C : Type*} [Category C]
{X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : X ⟶ Z) (w : ...)
[HasForget C] (x : X) : g (f x) = h x := ...
```
Here `X` is being coerced to a type via `CategoryTheory.HasForget.hasCoeToSort` and
`f`, `g`, and `h` are being coerced to functions via `CategoryTheory.HasForget.... | lemma | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | some_lemma_apply | null |
argument if it can't synthesize a relevant `HasForget` instance.
(Technical note: The forgetful functor's universe variable is instantiated with a
fresh level metavariable in this case.)
One difference between `elementwise_of%` and `@[elementwise]` is that `@[elementwise]` by
default applies `simp` to both sides of the... | instance | Tactic | [
"Mathlib.CategoryTheory.ConcreteCategory.Basic",
"Mathlib.Util.AddRelatedDecl",
"Batteries.Tactic.Lint"
] | Mathlib/Tactic/CategoryTheory/Elementwise.lean | argument | null |
Iso.eq_whisker {C : Type*} [Category C]
{X Y : C} {f g : X ≅ Y} (w : f = g) {Z : C} (h : Y ≅ Z) :
f ≪≫ h = g ≪≫ h := by rw [w] | theorem | Tactic | [
"Mathlib.CategoryTheory.Iso"
] | Mathlib/Tactic/CategoryTheory/IsoReassoc.lean | Iso.eq_whisker | null |
categoryIsoSimp (e : Expr) : MetaM Simp.Result :=
simpOnlyNames [``Iso.trans_symm, ``Iso.trans_refl, ``Iso.refl_trans, ``Iso.trans_assoc,
``Iso.symm_self_id, ``Iso.self_symm_id, ``Iso.symm_self_id_assoc, ``Iso.self_symm_id_assoc,
``Functor.mapIso_trans, ``Functor.mapIso_symm, ``Functor.mapIso_refl, ``Functor.... | def | Tactic | [
"Mathlib.CategoryTheory.Iso"
] | Mathlib/Tactic/CategoryTheory/IsoReassoc.lean | categoryIsoSimp | Simplify an expression using only the axioms of a groupoid. |
reassocExprIso (e : Expr) : MetaM (Expr × Array MVarId) := do
let lem₀ ← mkConstWithFreshMVarLevels ``Iso.eq_whisker
let (args, _, _) ← forallMetaBoundedTelescope (← inferType lem₀) 7
let inst := args[1]!
inst.mvarId!.setKind .synthetic
let w := args[6]!
w.mvarId!.assignIfDefEq e
withEnsuringLocalInstance... | def | Tactic | [
"Mathlib.CategoryTheory.Iso"
] | Mathlib/Tactic/CategoryTheory/IsoReassoc.lean | reassocExprIso | Given an equation `f = g` between isomorphisms `X ≅ Y` in a category,
produce the equation `∀ {Z} (h : Y ≅ Z), f ≪≫ h = g ≪≫ h`,
but with compositions fully right associated, identities removed, and functors applied. |
monoidalIso (X Y : C) [MonoidalCoherence X Y] : X ≅ Y := MonoidalCoherence.iso | abbrev | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | monoidalIso | A typeclass carrying a choice of monoidal structural isomorphism between two objects.
Used by the `⊗≫` monoidal composition operator, and the `coherence` tactic.
-/
-- We could likely turn this into a `Prop`-valued existential if that proves useful.
class MonoidalCoherence (X Y : C) where
/-- A monoidal structural is... |
monoidalComp {W X Y Z : C} [MonoidalCoherence X Y] (f : W ⟶ X) (g : Y ⟶ Z) : W ⟶ Z :=
f ≫ ⊗𝟙.hom ≫ g
@[inherit_doc monoidalComp]
scoped[CategoryTheory.MonoidalCategory] infixr:80 " ⊗≫ " =>
monoidalComp -- type as \ot \gg | def | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | monoidalComp | Compose two morphisms in a monoidal category,
inserting unitors and associators between as necessary. |
monoidalIsoComp {W X Y Z : C} [MonoidalCoherence X Y] (f : W ≅ X) (g : Y ≅ Z) : W ≅ Z :=
f ≪≫ ⊗𝟙 ≪≫ g
@[inherit_doc monoidalIsoComp]
scoped[CategoryTheory.MonoidalCategory] infixr:80 " ≪⊗≫ " =>
monoidalIsoComp -- type as \ll \ot \gg | def | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | monoidalIsoComp | Compose two isomorphisms in a monoidal category,
inserting unitors and associators between as necessary. |
@[simps]
refl (X : C) : MonoidalCoherence X X := ⟨Iso.refl _⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | refl | null |
whiskerLeft (X Y Z : C) [MonoidalCoherence Y Z] :
MonoidalCoherence (X ⊗ Y) (X ⊗ Z) :=
⟨whiskerLeftIso X ⊗𝟙⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | whiskerLeft | null |
whiskerRight (X Y Z : C) [MonoidalCoherence X Y] :
MonoidalCoherence (X ⊗ Z) (Y ⊗ Z) :=
⟨whiskerRightIso ⊗𝟙 Z⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | whiskerRight | null |
tensor_right (X Y : C) [MonoidalCoherence (𝟙_ C) Y] :
MonoidalCoherence X (X ⊗ Y) :=
⟨(ρ_ X).symm ≪≫ (whiskerLeftIso X ⊗𝟙)⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | tensor_right | null |
tensor_right' (X Y : C) [MonoidalCoherence Y (𝟙_ C)] :
MonoidalCoherence (X ⊗ Y) X :=
⟨whiskerLeftIso X ⊗𝟙 ≪≫ (ρ_ X)⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | tensor_right' | null |
left (X Y : C) [MonoidalCoherence X Y] :
MonoidalCoherence (𝟙_ C ⊗ X) Y :=
⟨λ_ X ≪≫ ⊗𝟙⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | left | null |
left' (X Y : C) [MonoidalCoherence X Y] :
MonoidalCoherence X (𝟙_ C ⊗ Y) :=
⟨⊗𝟙 ≪≫ (λ_ Y).symm⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | left' | null |
right (X Y : C) [MonoidalCoherence X Y] :
MonoidalCoherence (X ⊗ 𝟙_ C) Y :=
⟨ρ_ X ≪≫ ⊗𝟙⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | right | null |
right' (X Y : C) [MonoidalCoherence X Y] :
MonoidalCoherence X (Y ⊗ 𝟙_ C) :=
⟨⊗𝟙 ≪≫ (ρ_ Y).symm⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | right' | null |
assoc (X Y Z W : C) [MonoidalCoherence (X ⊗ (Y ⊗ Z)) W] :
MonoidalCoherence ((X ⊗ Y) ⊗ Z) W :=
⟨α_ X Y Z ≪≫ ⊗𝟙⟩
@[simps] | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | assoc | null |
assoc' (W X Y Z : C) [MonoidalCoherence W (X ⊗ (Y ⊗ Z))] :
MonoidalCoherence W ((X ⊗ Y) ⊗ Z) :=
⟨⊗𝟙 ≪≫ (α_ X Y Z).symm⟩ | instance | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | assoc' | null |
@[simp] monoidalComp_refl {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) :
f ⊗≫ g = f ≫ g := by
simp [monoidalComp] | lemma | Tactic | [
"Mathlib.CategoryTheory.Monoidal.Category"
] | Mathlib/Tactic/CategoryTheory/MonoidalComp.lean | monoidalComp_refl | null |
eq_whisker' {C : Type*} [Category C]
{X Y : C} {f g : X ⟶ Y} (w : f = g) {Z : C} (h : Y ⟶ Z) :
f ≫ h = g ≫ h := by rw [w] | theorem | Tactic | [
"Mathlib.CategoryTheory.Functor.Basic",
"Mathlib.Lean.Meta.Simp",
"Mathlib.Tactic.Simps.Basic",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/Reassoc.lean | eq_whisker' | A variant of `eq_whisker` with a more convenient argument order for use in tactics. |
categorySimp (e : Expr) : MetaM Simp.Result :=
simpOnlyNames [``Category.comp_id, ``Category.id_comp, ``Category.assoc,
``Functor.id_obj, ``Functor.id_map, ``Functor.comp_obj, ``Functor.comp_map] e
(config := { decide := false }) | def | Tactic | [
"Mathlib.CategoryTheory.Functor.Basic",
"Mathlib.Lean.Meta.Simp",
"Mathlib.Tactic.Simps.Basic",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/Reassoc.lean | categorySimp | Simplify an expression using only the axioms of a category. |
reassocExprHom (e : Expr) : MetaM (Expr × Array MVarId) := do
let lem₀ ← mkConstWithFreshMVarLevels ``eq_whisker'
let (args, _, _) ← forallMetaBoundedTelescope (← inferType lem₀) 7
let inst := args[1]!
inst.mvarId!.setKind .synthetic
let w := args[6]!
w.mvarId!.assignIfDefEq e
withEnsuringLocalInstance in... | def | Tactic | [
"Mathlib.CategoryTheory.Functor.Basic",
"Mathlib.Lean.Meta.Simp",
"Mathlib.Tactic.Simps.Basic",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/Reassoc.lean | reassocExprHom | Given an equation `f = g` between morphisms `X ⟶ Y` in a category,
produce the equation `∀ {Z} (h : Y ⟶ Z), f ≫ h = g ≫ h`,
but with compositions fully right associated and identities removed.
Also returns the category `C` and any instance metavariables that need to be solved for. |
registerReassocExpr (f : Expr → MetaM (Expr × Array MVarId)) : IO Unit := do
reassocImplRef.modify (·.push f) | def | Tactic | [
"Mathlib.CategoryTheory.Functor.Basic",
"Mathlib.Lean.Meta.Simp",
"Mathlib.Tactic.Simps.Basic",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/Reassoc.lean | registerReassocExpr | Adding `@[reassoc]` to a lemma named `F` of shape `∀ .., f = g`, where `f g : X ⟶ Y` are
morphisms in some category, will create a new lemma named `F_assoc` of shape
`∀ .. {Z : C} (h : Y ⟶ Z), f ≫ h = g ≫ h`
but with the conclusions simplified using the axioms for a category
(`Category.comp_id`, `Category.id_comp`, and... |
reassocExpr (pf : Expr) (type? : Option Expr) : MetaM (Expr × Array MVarId) := do
let pf ← if let some type := type? then mkExpectedTypeHint pf type else pure pf
forallTelescopeReducing (← inferType pf) fun xs _ => do
let pf := mkAppN pf xs
let handlers ← reassocImplRef.get
let (pf, insts) ← handlers.fi... | def | Tactic | [
"Mathlib.CategoryTheory.Functor.Basic",
"Mathlib.Lean.Meta.Simp",
"Mathlib.Tactic.Simps.Basic",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/Reassoc.lean | reassocExpr | Reassociates the morphisms in `type?` using the registered handlers,
using `reassocExprHom` as the default.
If `type?` is not given, it is assumed to be the type of `pf`.
Returns the proof of the lemma along with instance metavariables that need synthesis. |
reassocExpr' (pf : Expr) (type? : Option Expr) : TermElabM Expr := do
let (e, insts) ← reassocExpr pf type?
for inst in insts do
inst.withContext do
unless ← Term.synthesizeInstMVarCore inst do
Term.registerSyntheticMVarWithCurrRef inst (.typeClass none)
return e
initialize registerBuiltinAttrib... | def | Tactic | [
"Mathlib.CategoryTheory.Functor.Basic",
"Mathlib.Lean.Meta.Simp",
"Mathlib.Tactic.Simps.Basic",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/Reassoc.lean | reassocExpr' | Version of `reassocExpr` for the `TermElabM` monad. Handles instance metavariables automatically. |
evalSlice (a b : Nat) : TacticM Unit := do
let _ ← iterateUntilFailureWithResults do
evalTactic (← `(conv| rw [Category.assoc]))
iterateRange (a - 1) (a - 1) do
evalTactic (← `(conv| congr))
evalTactic (← `(tactic| rotate_left))
let k ← iterateUntilFailureCount
<| evalTactic (← `(conv| rw [← C... | def | Tactic | [
"Mathlib.CategoryTheory.Category.Basic",
"Mathlib.Tactic.Conv"
] | Mathlib/Tactic/CategoryTheory/Slice.lean | evalSlice | `slice` is a conv tactic; if the current focus is a composition of several morphisms,
`slice a b` reassociates as needed, and zooms in on the `a`-th through `b`-th morphisms.
Thus if the current focus is `(a ≫ b) ≫ ((c ≫ d) ≫ e)`, then `slice 2 3` zooms to `b ≫ c`.
-/
syntax (name := slice) "slice " num ppSpace num : c... |
catAppSimp (e : Expr) : MetaM Simp.Result :=
simpOnlyNames [
``Cat.whiskerLeft_app, ``Cat.whiskerRight_app, ``Cat.id_app, ``Cat.comp_app,
``Cat.eqToHom_app] e
(config := { decide := false }) | def | Tactic | [
"Mathlib.CategoryTheory.Category.Cat",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/ToApp.lean | catAppSimp | Simplify an expression in `Cat` using basic properties of `NatTrans.app`. |
toCatExpr (e : Expr) : MetaM Expr := do
let (args, binderInfos, conclusion) ← forallMetaTelescope (← inferType e)
let B ←
match conclusion.getAppFnArgs with
| (`Eq, #[_, η, _]) =>
match (← inferType η).getAppFnArgs with
| (`Quiver.Hom, #[_, _, f, _]) =>
match (← inferType f).getAppFnArgs... | def | Tactic | [
"Mathlib.CategoryTheory.Category.Cat",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/ToApp.lean | toCatExpr | Given a term of type `∀ ..., η = θ`, where `η θ : f ⟶ g` are 2-morphisms in some bicategory
`B`, which is bound by the `∀` binder, get the corresponding equation in the bicategory `Cat`.
It is important here that the levels in the term are level metavariables, as otherwise these will
not be reassignable to the corresp... |
toAppExpr (e : Expr) : MetaM Expr := do
mapForallTelescope (fun e => do simpType catAppSimp (← mkAppM ``NatTrans.congr_app #[e])) e | def | Tactic | [
"Mathlib.CategoryTheory.Category.Cat",
"Mathlib.Util.AddRelatedDecl"
] | Mathlib/Tactic/CategoryTheory/ToApp.lean | toAppExpr | Given morphisms `f g : C ⟶ D` in the bicategory `Cat`, and an equation `η = θ` between 2-morphisms
(possibly after a `∀` binder), produce the equation `∀ (X : C), f.app X = g.app X`, and simplify
it using basic lemmas about `NatTrans.app`. |
@[inline]
modifyTodo (f : Array TodoEntry → Array TodoEntry) : CCM Unit :=
modify fun cc => { cc with todo := f cc.todo } | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | modifyTodo | Update the `todo` field of the state. |
@[inline]
modifyACTodo (f : Array ACTodoEntry → Array ACTodoEntry) : CCM Unit :=
modify fun cc => { cc with acTodo := f cc.acTodo } | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | modifyACTodo | Update the `acTodo` field of the state. |
@[inline]
getTodo : CCM (Array TodoEntry) := do
return (← get).todo | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | getTodo | Read the `todo` field of the state. |
@[inline]
getACTodo : CCM (Array ACTodoEntry) := do
return (← get).acTodo | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | getACTodo | Read the `acTodo` field of the state. |
pushTodo (lhs rhs : Expr) (H : EntryExpr) (heqProof : Bool) : CCM Unit := do
modifyTodo fun todo => todo.push (lhs, rhs, H, heqProof) | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | pushTodo | Add a new entry to the end of the todo list.
See also `pushEq`, `pushHEq` and `pushReflEq`. |
@[inline]
pushEq (lhs rhs : Expr) (H : EntryExpr) : CCM Unit :=
pushTodo lhs rhs H false | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | pushEq | Add the equality proof `H : lhs = rhs` to the end of the todo list. |
@[inline]
pushHEq (lhs rhs : Expr) (H : EntryExpr) : CCM Unit :=
pushTodo lhs rhs H true | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | pushHEq | Add the heterogeneous equality proof `H : lhs ≍ rhs` to the end of the todo list. |
@[inline]
pushReflEq (lhs rhs : Expr) : CCM Unit :=
pushEq lhs rhs .refl | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | pushReflEq | Add `rfl : lhs = rhs` to the todo list. |
addOccurrence (parent child : Expr) (symmTable : Bool) : CCM Unit := do
let childRoot ← getRoot child
modify fun ccs =>
{ ccs with
parents := ccs.parents.alter childRoot fun ps? =>
let ps := ps?.getD ∅
ps.insert { expr := parent, symmTable } } | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | addOccurrence | Update the `child` so its parent becomes `parent`. |
propagateInstImplicit (e : Expr) : CCM Unit := do
let type ← inferType e
let type ← normalize type
match (← get).instImplicitReprs[type]? with
| some l =>
for e' in l do
if ← pureIsDefEq e e' then
pushReflEq e e'
return
modify fun ccs =>
{ ccs with instImplicitReprs := ccs.in... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | propagateInstImplicit | Record the instance `e` and add it to the set of known defeq instances. |
mkCongruencesKey (e : Expr) : CCM CongruencesKey := do
let .app f a := e | failure
if (← getEntry e).any Entry.fo then
e.withApp fun fn args => do
return .fo (← getRoot fn) (← args.mapM getRoot)
else
return .ho (← getRoot f) (← getRoot a) | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | mkCongruencesKey | Return the `CongruencesKey` associated with an expression of the form `f a`. |
mkSymmCongruencesKey (lhs rhs : Expr) : CCM SymmCongruencesKey := do
let lhs ← getRoot lhs
let rhs ← getRoot rhs
if hash lhs > hash rhs then return { h₁ := rhs, h₂ := lhs } else return { h₁ := lhs, h₂ := rhs } | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | mkSymmCongruencesKey | Return the `SymmCongruencesKey` associated with the equality `lhs = rhs`. |
compareSymmAux (lhs₁ rhs₁ lhs₂ rhs₂ : Expr) : CCM Bool := do
let lhs₁ ← getRoot lhs₁
let rhs₁ ← getRoot rhs₁
let lhs₂ ← getRoot lhs₂
let rhs₂ ← getRoot rhs₂
let (lhs₁, rhs₁) := if rhs₁.lt lhs₁ then (rhs₁, lhs₁) else (lhs₁, rhs₁)
let (lhs₂, rhs₂) := if rhs₂.lt lhs₂ then (rhs₂, lhs₂) else (lhs₂, rhs₂)
retur... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | compareSymmAux | Auxiliary function for comparing `lhs₁ ~ rhs₁` and `lhs₂ ~ rhs₂`,
when `~` is symmetric/commutative.
It returns `true` (equal) for `a ~ b` `b ~ a`. |
compareSymm : (k₁ k₂ : Expr × Name) → CCM Bool
| (e₁, n₁), (e₂, n₂) => do
if n₁ != n₂ then return false
if n₁ == ``Eq || n₁ == ``Iff then
compareSymmAux e₁.appFn!.appArg! e₁.appArg! e₂.appFn!.appArg! e₂.appArg!
else
let some (_, lhs₁, rhs₁) ← e₁.relSidesIfSymm? | failure
let some (_, lhs... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | compareSymm | Given ``k₁ := (R₁ lhs₁ rhs₁, `R₁)`` and ``k₂ := (R₂ lhs₂ rhs₂, `R₂)``, return `true` if
`R₁ lhs₁ rhs₁` is equivalent to `R₂ lhs₂ rhs₂` modulo the symmetry of `R₁` and `R₂`. |
checkEqTrue (e : Expr) : CCM Unit := do
let some (_, lhs, rhs) ← e.relSidesIfRefl? | return
if ← isEqv e (.const ``True []) then return -- it is already equivalent to `True`
let lhsR ← getRoot lhs
let rhsR ← getRoot rhs
if lhsR != rhsR then return
pushEq e (.const ``True []) .eqTrue | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | checkEqTrue | Given `e := R lhs rhs`, if `R` is a reflexive relation and `lhs` is equivalent to `rhs`, add
equality `e = True`. |
addCongruenceTable (e : Expr) : CCM Unit := do
guard e.isApp
let k ← mkCongruencesKey e
if let some es := (← get).congruences[k]? then
for oldE in es do
if ← isCongruent e oldE then
let some currEntry ← getEntry e | failure
let newEntry := { currEntry with cgRoot := oldE }
modify... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | addCongruenceTable | If the congruence table (`congruences` field) has congruent expression to `e`, add the
equality to the todo list. If not, add `e` to the congruence table. |
addSymmCongruenceTable (e : Expr) : CCM Unit := do
let some (rel, lhs, rhs) ← e.relSidesIfSymm? | failure
let k ← mkSymmCongruencesKey lhs rhs
let newP := (e, rel)
if let some ps := (← get).symmCongruences[k]? then
for p in ps do
if ← compareSymm newP p then
let some currEntry ← getEntry e | f... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | addSymmCongruenceTable | If the symm congruence table (`symmCongruences` field) has congruent expression to `e`, add the
equality to the todo list. If not, add `e` to the symm congruence table. |
pushSubsingletonEq (a b : Expr) : CCM Unit := do
let A ← normalize (← inferType a)
let B ← normalize (← inferType b)
if ← pureIsDefEq A B then
let proof ← mkAppM ``FastSubsingleton.elim #[a, b]
pushEq a b proof
else
let some AEqB ← getEqProof A B | failure
let proof ← mkAppM ``FastSubsingleton.h... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | pushSubsingletonEq | Given subsingleton elements `a` and `b` which are not necessarily of the same type, if the
types of `a` and `b` are equivalent, add the (heterogeneous) equality proof between `a` and `b` to
the todo list. |
checkNewSubsingletonEq (oldRoot newRoot : Expr) : CCM Unit := do
guard (← isEqv oldRoot newRoot)
guard ((← getRoot oldRoot) == newRoot)
let some it₁ := (← get).subsingletonReprs[oldRoot]? | return
if let some it₂ := (← get).subsingletonReprs[newRoot]? then
pushSubsingletonEq it₁ it₂
else
modify fun cc... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | checkNewSubsingletonEq | Given the equivalent expressions `oldRoot` and `newRoot` the root of `oldRoot` is
`newRoot`, if `oldRoot` has root representative of subsingletons, try to push the equality proof
between their root representatives to the todo list, or update the root representative to
`newRoot`. |
getEqcLambdas (e : Expr) (r : Array Expr := #[]) : CCM (Array Expr) := do
guard ((← getRoot e) == e)
let mut r := r
let some ee ← getEntry e | failure
unless ee.hasLambdas do return r
let mut it := e
repeat
if it.isLambda then
r := r.push it
let some itN ← getEntry it | failure
it := itN.n... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | getEqcLambdas | Get all lambda expressions in the equivalence class of `e` and append to `r`.
`e` must be the root of its equivalence class. |
propagateBeta (fn : Expr) (revArgs : Array Expr) (lambdas : Array Expr)
(newLambdaApps : Array Expr := #[]) : CCM (Array Expr) := do
let mut newLambdaApps := newLambdaApps
for lambda in lambdas do
guard lambda.isLambda
if fn != lambda then
if ← pureIsDefEq (← inferType fn) (← inferType lambda) the... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | propagateBeta | Remove `fn` and expressions whose type isn't def-eq to `fn`'s type out from `lambdas`,
return the remaining lambdas applied to the reversed arguments. |
dbgTraceACEq (header : String) (lhs rhs : ACApps) : CCM Unit := do
let ccs ← get
trace[Debug.Meta.Tactic.cc.ac]
group (ofFormat (header ++ .line) ++ ccs.ppACApps lhs ++
ofFormat (.line ++ "=" ++ .line) ++ ccs.ppACApps rhs) | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | dbgTraceACEq | Given `lhs`, `rhs`, and `header := "my header:"`, Trace `my header: lhs = rhs`. |
dbgTraceACState : CCM Unit := do
let ccs ← get
trace[Debug.Meta.Tactic.cc.ac] group ("state: " ++ nest 6 ccs.ppAC) | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | dbgTraceACState | Trace the state of AC module. |
insertEraseROcc (arg : Expr) (lhs : ACApps) (inLHS isInsert : Bool) : CCM Unit := do
let some entry := (← get).acEntries[arg]? | failure
let occs := entry.ROccs inLHS
let newOccs := if isInsert then occs.insert lhs else occs.erase lhs
let newEntry :=
if inLHS then { entry with RLHSOccs := newOccs } else { e... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | insertEraseROcc | Insert or erase `lhs` to the occurrences of `arg` on an equality in `acR`. |
insertEraseROccs (e lhs : ACApps) (inLHS isInsert : Bool) : CCM Unit := do
match e with
| .apps _ args =>
insertEraseROcc args[0]! lhs inLHS isInsert
for h : i in [1:args.size] do
if args[i] != args[i - 1]! then
insertEraseROcc args[i] lhs inLHS isInsert
| .ofExpr e => insertEraseROcc e lhs ... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | insertEraseROccs | Insert or erase `lhs` to the occurrences of arguments of `e` on an equality in `acR`. |
@[inline]
insertROccs (e lhs : ACApps) (inLHS : Bool) : CCM Unit :=
insertEraseROccs e lhs inLHS true | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | insertROccs | Insert `lhs` to the occurrences of arguments of `e` on an equality in `acR`. |
@[inline]
eraseROccs (e lhs : ACApps) (inLHS : Bool) : CCM Unit :=
insertEraseROccs e lhs inLHS false | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | eraseROccs | Erase `lhs` to the occurrences of arguments of `e` on an equality in `acR`. |
@[inline]
insertRBHSOccs (lhs rhs : ACApps) : CCM Unit := do
insertROccs lhs lhs true
insertROccs rhs lhs false | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | insertRBHSOccs | Insert `lhs` to the occurrences on an equality in `acR` corresponding to the equality
`lhs := rhs`. |
@[inline]
eraseRBHSOccs (lhs rhs : ACApps) : CCM Unit := do
eraseROccs lhs lhs true
eraseROccs rhs lhs false | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | eraseRBHSOccs | Erase `lhs` to the occurrences on an equality in `acR` corresponding to the equality
`lhs := rhs`. |
@[inline]
insertRRHSOccs (e lhs : ACApps) : CCM Unit :=
insertROccs e lhs false | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | insertRRHSOccs | Insert `lhs` to the occurrences of arguments of `e` on the right-hand side of
an equality in `acR`. |
@[inline]
eraseRRHSOccs (e lhs : ACApps) : CCM Unit :=
eraseROccs e lhs false | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | eraseRRHSOccs | Erase `lhs` to the occurrences of arguments of `e` on the right-hand side of
an equality in `acR`. |
composeAC (lhs rhs : ACApps) (H : DelayedExpr) : CCM Unit := do
let some x := (← get).getVarWithLeastRHSOccs lhs | failure
let some ent := (← get).acEntries[x]? | failure
let occs := ent.RRHSOccs
for Rlhs in occs do
let some (Rrhs, RH) := (← get).acR[Rlhs]? | failure
if lhs.isSubset Rrhs then
let ... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | composeAC | Try to simplify the right-hand sides of equalities in `acR` by `H : lhs = rhs`. |
collapseAC (lhs rhs : ACApps) (H : DelayedExpr) : CCM Unit := do
let some x := (← get).getVarWithLeastLHSOccs lhs | failure
let some ent := (← get).acEntries[x]? | failure
let occs := ent.RLHSOccs
for Rlhs in occs do
if lhs.isSubset Rlhs then
let some (Rrhs, RH) := (← get).acR[Rlhs]? | failure
e... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | collapseAC | Try to simplify the left-hand sides of equalities in `acR` by `H : lhs = rhs`. |
mkACSuperposeProof (ra sb a b r s ts tr : ACApps) (tsEqa trEqb : DelayedExpr) :
MetaM DelayedExpr := do
let .apps _ _ := tr | failure
let .apps op _ := ts | failure
let some tse := ts.toExpr | failure
let some re := r.toExpr | failure
let some tre := tr.toExpr | failure
let some se := s.toExpr | failure... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | mkACSuperposeProof | Given `ra := a*r` `sb := b*s` `ts := t*s` `tr := t*r` `tsEqa : t*s = a` `trEqb : t*r = b`,
return a proof for `ra = sb`.
We use `a*b` to denote an AC application. That is, `(a*b)*(c*a)` is the term `a*a*b*c`. |
superposeAC (ts a : ACApps) (tsEqa : DelayedExpr) : CCM Unit := do
let .apps op args := ts | return
for hi : i in [:args.size] do
if i == 0 || args[i] != (args[i - 1]'(Nat.lt_of_le_of_lt (i.sub_le 1) hi.2.1)) then
let some ent := (← get).acEntries[args[i]]? | failure
let occs := ent.RLHSOccs
f... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | superposeAC | Given `tsEqa : ts = a`, for each equality `trEqb : tr = b` in `acR` where
the intersection `t` of `ts` and `tr` is nonempty, let `ts = t*s` and `tr := t*r`, add a new
equality `r*a = s*b`. |
processAC : CCM Unit := do
repeat
let acTodo ← getACTodo
let mut some (lhs, rhs, H) := acTodo.back? | break
modifyACTodo fun _ => acTodo.pop
let lhs₀ := lhs
let rhs₀ := rhs
dbgTraceACEq "process eq:" lhs rhs
if let some p ← simplifyAC lhs then
H := .eqTransOpt p.1 lhs rhs (.eqSymmOpt... | def | Tactic | [
"Mathlib.Data.Option.Defs",
"Mathlib.Tactic.CC.MkProof"
] | Mathlib/Tactic/CC/Addition.lean | processAC | Process the tasks in the `acTodo` field. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.