The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V34. The tactics of Mathlib

Mathlib.Tactic.CategoryTheory.Coherence

37 declarations and 2 deprecated aliases. Mathlib docs · Source

A coherence tactic for monoidal categories

We provide a coherence tactic, which proves equations where the two sides differ by replacing strings of monoidal structural morphisms with other such strings. (The replacements are always equalities by the monoidal coherence theorem.)

A simpler version of this tactic is pure_coherence, which proves that any two morphisms (with the same source and target) in a monoidal category which are built out of associators and unitors are equal.

def Mathlib.Tactic.Coherence.LiftHom.ctorIdx E1 #

{C : Type u} →
  {inst : CategoryTheory.Category.{v, u} C} →
    {X Y : C} →
      {inst_1 : Mathlib.Tactic.Coherence.LiftObj X} →
        {inst_2 : Mathlib.Tactic.Coherence.LiftObj Y} → {f : X ⟶ Y} → Mathlib.Tactic.Coherence.LiftHom f → ℕ

def Mathlib.Tactic.Coherence.LiftObj.ctorIdx E1 #

{C : Type u} → {X : C} → Mathlib.Tactic.Coherence.LiftObj X → ℕ

class Mathlib.Tactic.Coherence.LiftObj E1 #

{C : Type u} → C → Type u

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.

ctor Mathlib.Tactic.Coherence.LiftObj.mk E0 #

{C : Type u} → {X : C} → CategoryTheory.FreeMonoidalCategory C → Mathlib.Tactic.Coherence.LiftObj X

abbrev Mathlib.Tactic.Coherence.LiftObj.lift E1 #

{C : Type u} → (X : C) → [self : Mathlib.Tactic.Coherence.LiftObj X] → CategoryTheory.FreeMonoidalCategory C

instance Mathlib.Tactic.Coherence.LiftObj.unit E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      Mathlib.Tactic.Coherence.LiftObj (CategoryTheory.MonoidalCategoryStruct.tensorUnit C)

instance Mathlib.Tactic.Coherence.LiftObj.tensor E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      (X Y : C) →
        [Mathlib.Tactic.Coherence.LiftObj X] →
          [Mathlib.Tactic.Coherence.LiftObj Y] →
            Mathlib.Tactic.Coherence.LiftObj (CategoryTheory.MonoidalCategoryStruct.tensorObj X Y)

instance Mathlib.Tactic.Coherence.LiftObj.of E0 #

{C : Type u} → (X : C) → Mathlib.Tactic.Coherence.LiftObj X

class Mathlib.Tactic.Coherence.LiftHom E1 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    {X Y : C} → [Mathlib.Tactic.Coherence.LiftObj X] → [Mathlib.Tactic.Coherence.LiftObj Y] → (X ⟶ Y) → Type u

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.

ctor Mathlib.Tactic.Coherence.LiftHom.mk E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    {X Y : C} →
      [inst_1 : Mathlib.Tactic.Coherence.LiftObj X] →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj Y] →
          {f : X ⟶ Y} →
            (Mathlib.Tactic.Coherence.LiftObj.lift X ⟶ Mathlib.Tactic.Coherence.LiftObj.lift Y) →
              Mathlib.Tactic.Coherence.LiftHom f

abbrev Mathlib.Tactic.Coherence.LiftHom.lift E1 #

{C : Type u} →
  {inst : CategoryTheory.Category.{v, u} C} →
    {X Y : C} →
      {inst_1 : Mathlib.Tactic.Coherence.LiftObj X} →
        {inst_2 : Mathlib.Tactic.Coherence.LiftObj Y} →
          (f : X ⟶ Y) →
            [self : Mathlib.Tactic.Coherence.LiftHom f] →
              Mathlib.Tactic.Coherence.LiftObj.lift X ⟶ Mathlib.Tactic.Coherence.LiftObj.lift Y

instance Mathlib.Tactic.Coherence.LiftHom.id E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    (X : C) →
      [inst_1 : Mathlib.Tactic.Coherence.LiftObj X] →
        Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.CategoryStruct.id X)

instance Mathlib.Tactic.Coherence.LiftHom.leftUnitorHom E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      (X : C) →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] →
          Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.leftUnitor X).hom

instance Mathlib.Tactic.Coherence.LiftHom.leftUnitorInv E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      (X : C) →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] →
          Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.leftUnitor X).inv

instance Mathlib.Tactic.Coherence.LiftHom.rightUnitorHom E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      (X : C) →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] →
          Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.rightUnitor X).hom

instance Mathlib.Tactic.Coherence.LiftHom.rightUnitorInv E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      (X : C) →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] →
          Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.rightUnitor X).inv

instance Mathlib.Tactic.Coherence.LiftHom.associatorHom E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      (X Y Z : C) →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] →
          [inst_3 : Mathlib.Tactic.Coherence.LiftObj Y] →
            [inst_4 : Mathlib.Tactic.Coherence.LiftObj Z] →
              Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.associator X Y Z).hom

instance Mathlib.Tactic.Coherence.LiftHom.associatorInv E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      (X Y Z : C) →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] →
          [inst_3 : Mathlib.Tactic.Coherence.LiftObj Y] →
            [inst_4 : Mathlib.Tactic.Coherence.LiftObj Z] →
              Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.associator X Y Z).inv

instance Mathlib.Tactic.Coherence.LiftHom.comp E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    {X Y Z : C} →
      [inst_1 : Mathlib.Tactic.Coherence.LiftObj X] →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj Y] →
          [inst_3 : Mathlib.Tactic.Coherence.LiftObj Z] →
            (f : X ⟶ Y) →
              (g : Y ⟶ Z) →
                [Mathlib.Tactic.Coherence.LiftHom f] →
                  [Mathlib.Tactic.Coherence.LiftHom g] →
                    Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.CategoryStruct.comp f g)

instance Mathlib.Tactic.Coherence.LiftHom.whiskerLeft E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      (X : C) →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] →
          {Y Z : C} →
            [inst_3 : Mathlib.Tactic.Coherence.LiftObj Y] →
              [inst_4 : Mathlib.Tactic.Coherence.LiftObj Z] →
                (f : Y ⟶ Z) →
                  [Mathlib.Tactic.Coherence.LiftHom f] →
                    Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.whiskerLeft X f)

instance Mathlib.Tactic.Coherence.LiftHom.whiskerRight E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      {X Y : C} →
        (f : X ⟶ Y) →
          [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] →
            [inst_3 : Mathlib.Tactic.Coherence.LiftObj Y] →
              [Mathlib.Tactic.Coherence.LiftHom f] →
                {Z : C} →
                  [inst_5 : Mathlib.Tactic.Coherence.LiftObj Z] →
                    Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.whiskerRight f Z)

instance Mathlib.Tactic.Coherence.LiftHom.tensor E0 #

{C : Type u} →
  [inst : CategoryTheory.Category.{v, u} C] →
    [inst_1 : CategoryTheory.MonoidalCategory C] →
      {W X Y Z : C} →
        [inst_2 : Mathlib.Tactic.Coherence.LiftObj W] →
          [inst_3 : Mathlib.Tactic.Coherence.LiftObj X] →
            [inst_4 : Mathlib.Tactic.Coherence.LiftObj Y] →
              [inst_5 : Mathlib.Tactic.Coherence.LiftObj Z] →
                (f : W ⟶ X) →
                  (g : Y ⟶ Z) →
                    [Mathlib.Tactic.Coherence.LiftHom f] →
                      [Mathlib.Tactic.Coherence.LiftHom g] →
                        Mathlib.Tactic.Coherence.LiftHom (CategoryTheory.MonoidalCategoryStruct.tensorHom f g)

def Mathlib.Tactic.Coherence.exception E1 #

{α : Type} → Lean.MVarId → Lean.MessageData → Lean.MetaM α

Helper function for throwing exceptions.

def Mathlib.Tactic.Coherence.exception' E1 #

Lean.MessageData → Lean.Elab.Tactic.TacticM Unit

Helper function for throwing exceptions with respect to the main goal.

def Mathlib.Tactic.Coherence.mkProjectMapExpr E1 #

Lean.Expr → Lean.Elab.TermElabM Lean.Expr

Auxiliary definition for monoidal_coherence.

def Mathlib.Tactic.Coherence.monoidalCoherence E1 #

Lean.MVarId → Lean.Elab.TermElabM Unit

Coherence tactic for monoidal categories.

opaque Mathlib.Tactic.Coherence.warn.refl_coherence E1 #

Lean.Option Bool

If set to false, the warning on the use of the deprecated coherence tactic is disabled.

def Mathlib.Tactic.Coherence.pure_coherence E1 #

Lean.ParserDescr

pure_coherence uses the coherence theorem for monoidal categories to prove the goal. It can prove any equality made up only of associators, unitors, and identities.

example {C : Type} [Category* C] [MonoidalCategory C] :
  (λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom := by
  pure_coherence

Users will typically just use the coherence tactic, which can also cope with identities of the form a ≫ f ≫ b ≫ g ≫ c = a' ≫ f ≫ b' ≫ g ≫ c' where a = a', b = b', and c = c' can be proved using pure_coherence

def Mathlib.Tactic.Coherence.pure_coherence_internal E1 #

Lean.ParserDescr

The same as pure_coherence, but used internally in coherence without the warning.

theorem Mathlib.Tactic.Coherence.assoc_liftHom E1 #

∀ {C : Type u} [inst : CategoryTheory.Category.{v, u} C] {W X Y Z : C} [inst_1 : Mathlib.Tactic.Coherence.LiftObj W]
  [inst_2 : Mathlib.Tactic.Coherence.LiftObj X] [inst_3 : Mathlib.Tactic.Coherence.LiftObj Y] (f : W ⟶ X) (g : X ⟶ Y)
  (h : Y ⟶ Z) [Mathlib.Tactic.Coherence.LiftHom f] [Mathlib.Tactic.Coherence.LiftHom g],
  CategoryTheory.CategoryStruct.comp f (CategoryTheory.CategoryStruct.comp g h) =
    CategoryTheory.CategoryStruct.comp (CategoryTheory.CategoryStruct.comp f g) h

Auxiliary simp lemma for the coherence tactic: this moves brackets to the left in order to expose a maximal prefix built out of unitors and associators.

def Mathlib.Tactic.Coherence.liftable_prefixes E1 #

Lean.ParserDescr

Internal tactic used in coherence.

Rewrites an equation f = g as f₀ ≫ f₁ = g₀ ≫ g₁, where f₀ and g₀ are maximal prefixes of f and g (possibly after reassociating) which are "liftable" (i.e. expressible as compositions of unitors and associators).

theorem Mathlib.Tactic.Coherence.insert_id_lhs E1 #

∀ {C : Type u_1} [inst : CategoryTheory.Category.{v_1, u_1} C] {X Y : C} (f g : X ⟶ Y),
  CategoryTheory.CategoryStruct.comp f (CategoryTheory.CategoryStruct.id Y) = g → f = g

theorem Mathlib.Tactic.Coherence.insert_id_rhs E1 #

∀ {C : Type u_1} [inst : CategoryTheory.Category.{v_1, u_1} C] {X Y : C} (f g : X ⟶ Y),
  f = CategoryTheory.CategoryStruct.comp g (CategoryTheory.CategoryStruct.id Y) → f = g

def Mathlib.Tactic.Coherence.insertTrailingIds E1 #

Lean.MVarId → Lean.MetaM Lean.MVarId

If either the lhs or rhs is not a composition, compose it on the right with an identity.

def Mathlib.Tactic.Coherence.coherenceLoop E1 #

optParam ℕ 37 → Lean.Elab.Tactic.TacticM Unit

The main part of coherence tactic.

def Mathlib.Tactic.Coherence.monoidal_simps E1 #

Lean.ParserDescr

Simp lemmas for rewriting a hom in monoidal categories into a normal form.

def Mathlib.Tactic.Coherence.coherence E1 #

Lean.ParserDescr

Use the coherence theorem for monoidal categories to solve equations in a monoidal equation, where the two sides only differ by replacing strings of monoidal structural morphisms (that is, associators, unitors, and identities) with different strings of structural morphisms with the same source and target.

That is, coherence can handle goals of the form a ≫ f ≫ b ≫ g ≫ c = a' ≫ f ≫ b' ≫ g ≫ c' where a = a', b = b', and c = c' can be proved using pure_coherence.

(If you have very large equations on which coherence is unexpectedly failing, you may need to increase the typeclass search depth, using e.g. set_option synthInstance.maxSize 500.)

Deprecated aliases

NameNew nameSince
Mathlib.Tactic.Coherence.coherence_loopMathlib.Tactic.Coherence.coherenceLoop2026-05-27
Mathlib.Tactic.Coherence.monoidal_coherenceMathlib.Tactic.Coherence.monoidalCoherence2026-05-27