Normalization of morphisms in monoidal categories #
This file provides a tactic that normalizes morphisms in monoidal categories. This is used in the
string diagram widget given in Mathlib.Tactic.StringDiagram
.
We say that the morphism η
in a monoidal category is in normal form if
η
is of the formα₀ ≫ η₀ ≫ α₁ ≫ η₁ ≫ ... αₘ ≫ ηₘ ≫ αₘ₊₁
where eachαᵢ
is a structural 2-morphism (consisting of associators and unitors),- each
ηᵢ
is a non-structural 2-morphism of the formf₁ ◁ ... ◁ fₘ ◁ θ
, and θ
is of the formι ▷ g₁ ▷ ... ▷ gₗ
Note that the structural morphisms αᵢ
are not necessarily normalized, as the main purpose
is to get a list of the non-structural morphisms out.
Currently, the primary application of the normalization tactic in mind is drawing string diagrams, which are graphical representations of morphisms in monoidal categories, in the infoview. When drawing string diagrams, we often ignore associators and unitors (i.e., drawing morphisms in strict monoidal categories). On the other hand, in Lean, it is considered difficult to formalize the concept of strict monoidal categories due to the feature of dependent type theory. The normalization tactic can remove associators and unitors from the expression, extracting the necessary data for drawing string diagrams.
The current plan on drawing string diagrams (#10581) is to use Penrose (https://github.com/penrose) via ProofWidget. However, it should be noted that the normalization procedure in this file does not rely on specific settings, allowing for broader application.
Future plans include the following. At least I (Yuma) would like to work on these in the future, but it might not be immediate. If anyone is interested, I would be happy to discuss.
Currently (#10581), the string diagrams only do drawing. It would be better they also generate proofs. That is, by manipulating the string diagrams displayed in the infoview with a mouse to generate proofs. In #10581, the string diagram widget only uses the morphisms generated by the normalization tactic and does not use proof terms ensuring that the original morphism and the normalized morphism are equal. Proof terms will be necessary for proof generation.
There is also the possibility of using homotopy.io (https://github.com/homotopy-io), a graphical proof assistant for category theory, from Lean. At this point, I have very few ideas regarding this approach.
The normalization tactic allows for an alternative implementation of the coherent tactic.
Main definitions #
Tactic.Monoidal.eval
: Given a Lean expressione
that represents a morphism in a monoidal category, this function returns a pair of⟨e', pf⟩
wheree'
is the normalized expression ofe
andpf
is a proof thate = e'
.
The context for evaluating expressions.
- C : Lean.Expr
The expression for the underlying category.
Instances For
Populate a context
object for evaluating e
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The monad for the normalization of 2-morphisms.
Instances For
Run a computation in the M
monad.
Equations
Instances For
Expressions for atomic 1-morphisms.
Instances For
Expressions for 1-morphisms.
- id: Mathlib.Tactic.Monoidal.Mor₁
- comp: Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.Mor₁
comp X Y
is the expression forX ⊗ Y
- of: Mathlib.Tactic.Monoidal.Atom₁ → Mathlib.Tactic.Monoidal.Mor₁
Construct the expression for an atomic 1-morphism.
Instances For
Converts a 1-morphism into a list of its components.
Equations
- Mathlib.Tactic.Monoidal.Mor₁.id.toList = []
- (f.comp g).toList = f.toList ++ g.toList
- (Mathlib.Tactic.Monoidal.Mor₁.of f).toList = [f]
Instances For
Returns (f, g)
if the expression e
is of the form f ⊗ g
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Construct a Mor₁
expression from a Lean expression.
Expressions for atomic structural 2-morphisms.
- associator: Mathlib.Tactic.Monoidal.Mor₁ →
Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.StructuralAtom
The expression for the associator
(α_ f g h).hom
. - associatorInv: Mathlib.Tactic.Monoidal.Mor₁ →
Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.StructuralAtom
The expression for the inverse of the associator
(α_ f g h).inv
. - leftUnitor: Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.StructuralAtom
The expression for the left unitor
(λ_ f).hom
. - leftUnitorInv: Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.StructuralAtom
The expression for the inverse of the left unitor
(λ_ f).inv
. - rightUnitor: Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.StructuralAtom
The expression for the right unitor
(ρ_ f).hom
. - rightUnitorInv: Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.StructuralAtom
The expression for the inverse of the right unitor
(ρ_ f).inv
. - monoidalCoherence: Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.Mor₁ → Lean.Expr → Mathlib.Tactic.Monoidal.StructuralAtom
Expressions for
α
in the monoidal compositionη ⊗≫ θ := η ≫ α ≫ θ
.
Instances For
Equations
- Mathlib.Tactic.Monoidal.instInhabitedStructuralAtom = { default := Mathlib.Tactic.Monoidal.StructuralAtom.associator default default default }
Construct a StructuralAtom
expression from a Lean expression.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Expressions for atomic non-structural 2-morphisms.
Instances For
Equations
- Mathlib.Tactic.Monoidal.instInhabitedAtom = { default := { e := default } }
Expressions of the form η ▷ f₁ ▷ ... ▷ fₙ
.
- of: Mathlib.Tactic.Monoidal.Atom → Mathlib.Tactic.Monoidal.WhiskerRightExpr
Construct the expression for an atomic 2-morphism.
- whisker: Mathlib.Tactic.Monoidal.WhiskerRightExpr → Mathlib.Tactic.Monoidal.Atom₁ → Mathlib.Tactic.Monoidal.WhiskerRightExpr
Construct the expression for
η ▷ f
.
Instances For
Expressions of the form f₁ ◁ ... ◁ fₙ ◁ η
.
- of: Mathlib.Tactic.Monoidal.WhiskerRightExpr → Mathlib.Tactic.Monoidal.WhiskerLeftExpr
Construct the expression for a right-whiskered 2-morphism.
- whisker: Mathlib.Tactic.Monoidal.Atom₁ → Mathlib.Tactic.Monoidal.WhiskerLeftExpr → Mathlib.Tactic.Monoidal.WhiskerLeftExpr
Construct the expression for
f ◁ η
.
Instances For
Expressions for structural 2-morphisms.
- atom: Mathlib.Tactic.Monoidal.StructuralAtom → Mathlib.Tactic.Monoidal.Structural
Expressions for atomic structural 2-morphisms.
- id: Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.Structural
Expressions for the identity
𝟙 f
. - comp: Mathlib.Tactic.Monoidal.Structural → Mathlib.Tactic.Monoidal.Structural → Mathlib.Tactic.Monoidal.Structural
Expressions for the composition
η ≫ θ
. - whiskerLeft: Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.Structural → Mathlib.Tactic.Monoidal.Structural
Expressions for the left whiskering
f ◁ η
. - whiskerRight: Mathlib.Tactic.Monoidal.Structural → Mathlib.Tactic.Monoidal.Mor₁ → Mathlib.Tactic.Monoidal.Structural
Expressions for the right whiskering
η ▷ f
.
Instances For
Equations
- Mathlib.Tactic.Monoidal.instInhabitedStructural = { default := Mathlib.Tactic.Monoidal.Structural.atom default }
Normalized expressions for 2-morphisms.
- nil: Mathlib.Tactic.Monoidal.Structural → Mathlib.Tactic.Monoidal.NormalExpr
Construct the expression for a structural 2-morphism.
- cons: Mathlib.Tactic.Monoidal.Structural →
Mathlib.Tactic.Monoidal.WhiskerLeftExpr → Mathlib.Tactic.Monoidal.NormalExpr → Mathlib.Tactic.Monoidal.NormalExpr
Construct the normalized expression of 2-morphisms recursively.
Instances For
Equations
- Mathlib.Tactic.Monoidal.instInhabitedNormalExpr = { default := Mathlib.Tactic.Monoidal.NormalExpr.nil default }
The domain of a morphism.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The codomain of a morphism.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The domain of a 2-morphism.
Equations
- η.src = Mathlib.Tactic.Monoidal.src η.e
Instances For
The codomain of a 2-morphism.
Equations
- η.tgt = Mathlib.Tactic.Monoidal.tgt η.e
Instances For
The domain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.WhiskerRightExpr.of η).src = η.src
- (η.whisker f).src = do let __do_lift ← η.src pure (__do_lift.comp (Mathlib.Tactic.Monoidal.Mor₁.of f))
Instances For
The codomain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.WhiskerRightExpr.of η).tgt = η.tgt
- (η.whisker f).tgt = do let __do_lift ← η.tgt pure (__do_lift.comp (Mathlib.Tactic.Monoidal.Mor₁.of f))
Instances For
The domain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.WhiskerLeftExpr.of η).src = η.src
- (Mathlib.Tactic.Monoidal.WhiskerLeftExpr.whisker f η).src = do let __do_lift ← η.src pure ((Mathlib.Tactic.Monoidal.Mor₁.of f).comp __do_lift)
Instances For
The codomain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.WhiskerLeftExpr.of η).tgt = η.tgt
- (Mathlib.Tactic.Monoidal.WhiskerLeftExpr.whisker f η).tgt = do let __do_lift ← η.tgt pure ((Mathlib.Tactic.Monoidal.Mor₁.of f).comp __do_lift)
Instances For
The domain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.StructuralAtom.associator f g h).src = (f.comp g).comp h
- (Mathlib.Tactic.Monoidal.StructuralAtom.associatorInv f g h).src = f.comp (g.comp h)
- (Mathlib.Tactic.Monoidal.StructuralAtom.leftUnitor f).src = Mathlib.Tactic.Monoidal.Mor₁.id.comp f
- (Mathlib.Tactic.Monoidal.StructuralAtom.leftUnitorInv f).src = f
- (Mathlib.Tactic.Monoidal.StructuralAtom.rightUnitor f).src = f.comp Mathlib.Tactic.Monoidal.Mor₁.id
- (Mathlib.Tactic.Monoidal.StructuralAtom.rightUnitorInv f).src = f
- (Mathlib.Tactic.Monoidal.StructuralAtom.monoidalCoherence f g e).src = f
Instances For
The codomain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.StructuralAtom.associator f g h).tgt = f.comp (g.comp h)
- (Mathlib.Tactic.Monoidal.StructuralAtom.associatorInv f g h).tgt = (f.comp g).comp h
- (Mathlib.Tactic.Monoidal.StructuralAtom.leftUnitor f).tgt = f
- (Mathlib.Tactic.Monoidal.StructuralAtom.leftUnitorInv f).tgt = Mathlib.Tactic.Monoidal.Mor₁.id.comp f
- (Mathlib.Tactic.Monoidal.StructuralAtom.rightUnitor f).tgt = f
- (Mathlib.Tactic.Monoidal.StructuralAtom.rightUnitorInv f).tgt = f.comp Mathlib.Tactic.Monoidal.Mor₁.id
- (Mathlib.Tactic.Monoidal.StructuralAtom.monoidalCoherence f g e).tgt = g
Instances For
The domain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.Structural.atom η).src = η.src
- (Mathlib.Tactic.Monoidal.Structural.id f).src = f
- (α.comp β).src = α.src
- (Mathlib.Tactic.Monoidal.Structural.whiskerLeft f η).src = f.comp η.src
- (η.whiskerRight f).src = η.src.comp f
Instances For
The codomain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.Structural.atom η).tgt = η.tgt
- (Mathlib.Tactic.Monoidal.Structural.id f).tgt = f
- (α.comp β).tgt = β.tgt
- (Mathlib.Tactic.Monoidal.Structural.whiskerLeft f η).tgt = f.comp η.tgt
- (η.whiskerRight f).tgt = η.tgt.comp f
Instances For
The domain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.NormalExpr.nil η).src = η.src
- (Mathlib.Tactic.Monoidal.NormalExpr.cons α head tail).src = α.src
Instances For
The codomain of a 2-morphism.
Equations
- (Mathlib.Tactic.Monoidal.NormalExpr.nil η).tgt = η.tgt
- (Mathlib.Tactic.Monoidal.NormalExpr.cons α head tail).tgt = tail.tgt
Instances For
The associator as a term of normalExpr
.
Equations
Instances For
The inverse of the associator as a term of normalExpr
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The left unitor as a term of normalExpr
.
Equations
Instances For
The inverse of the left unitor as a term of normalExpr
.
Equations
Instances For
The right unitor as a term of normalExpr
.
Equations
Instances For
The inverse of the right unitor as a term of normalExpr
.
Equations
Instances For
Construct a NormalExpr
expression from a WhiskerLeftExpr
expression.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Construct a NormalExpr
expression from a Lean expression for an atomic 2-morphism.
Equations
Instances For
If e
is an expression of the form η ⊗≫ θ := η ≫ α ≫ θ
in the monoidal category C
,
return the expression for α
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract a Lean expression from a Mor₁
expression.
Equations
- Mathlib.Tactic.Monoidal.Mor₁.id.e = do let ctx ← read liftM (Lean.Meta.mkAppOptM `CategoryTheory.MonoidalCategoryStruct.tensorUnit #[some ctx.C, none, none])
- (f.comp g).e = do let __do_lift ← f.e let __do_lift_1 ← g.e liftM (Lean.Meta.mkAppM `CategoryTheory.MonoidalCategoryStruct.tensorObj #[__do_lift, __do_lift_1])
- (Mathlib.Tactic.Monoidal.Mor₁.of f).e = pure f.e
Instances For
Extract a Lean expression from a StructuralAtom
expression.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract a Lean expression from a Structural
expression.
Extract a Lean expression from a WhiskerRightExpr
expression.
Equations
- (Mathlib.Tactic.Monoidal.WhiskerRightExpr.of η).e = pure η.e
- (η.whisker f).e = do let __do_lift ← η.e liftM (Lean.Meta.mkAppM `CategoryTheory.MonoidalCategoryStruct.whiskerRight #[__do_lift, f.e])
Instances For
Extract a Lean expression from a WhiskerLeftExpr
expression.
Equations
- (Mathlib.Tactic.Monoidal.WhiskerLeftExpr.of η).e = η.e
- (Mathlib.Tactic.Monoidal.WhiskerLeftExpr.whisker f η).e = do let __do_lift ← η.e liftM (Lean.Meta.mkAppM `CategoryTheory.MonoidalCategoryStruct.whiskerLeft #[f.e, __do_lift])
Instances For
Extract a Lean expression from a NormalExpr
expression.
Equations
- One or more equations did not get rendered due to their size.
- (Mathlib.Tactic.Monoidal.NormalExpr.nil η).e = η.e
Instances For
The result of evaluating an expression into normal form.
The normalized expression of the 2-morphism.
- proof : Lean.Expr
The proof that the normalized expression is equal to the original expression.
Instances For
Evaluate the expression η ≫ θ
into a normalized form.
Evaluate the expression f ◁ η
into a normalized form.
Evaluate the expression η ▷ f
into a normalized form.
Evaluate the expression of a 2-morphism into a normalized form.
Convert a NormalExpr
expression into a list of WhiskerLeftExpr
expressions.
Equations
- (Mathlib.Tactic.Monoidal.NormalExpr.nil η).toList = []
- (Mathlib.Tactic.Monoidal.NormalExpr.cons α head tail).toList = head :: tail.toList
Instances For
normalize% η
is the normalization of the 2-morphism η
.
- The normalized 2-morphism is of the form
α₀ ≫ η₀ ≫ α₁ ≫ η₁ ≫ ... αₘ ≫ ηₘ ≫ αₘ₊₁
where eachαᵢ
is a structural 2-morphism (consisting of associators and unitors), - each
ηᵢ
is a non-structural 2-morphism of the formf₁ ◁ ... ◁ fₘ ◁ θ
, and θ
is of the formι ▷ g₁ ▷ ... ▷ gₗ
Equations
- «termNormalize%_» = Lean.ParserDescr.node `termNormalize%_ 1022 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "normalize% ") (Lean.ParserDescr.cat `term 51))
Instances For
Transform an equality between 2-morphisms into the equality between their normalizations.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Normalize the both sides of an equality.
Equations
- tacticMonoidal_nf = Lean.ParserDescr.node `tacticMonoidal_nf 1024 (Lean.ParserDescr.nonReservedSymbol "monoidal_nf" false)