Categories #
Defines a category, as a type class parametrised by the type of objects.
Notation #
Introduces notations in the CategoryTheory scope
X ⟶ Yfor the morphism spaces (type as\hom),𝟙 Xfor the identity morphism onX(type as\b1),f ≫ gfor composition in the 'arrows' convention (type as\gg).
Users may like to add g ⊚ f for composition in the standard convention, using
local notation:80 g " ⊚ " f:80 => CategoryTheory.CategoryStruct.comp f g -- type as \oo
The typeclass Category C describes morphisms associated to objects of type C : Type u.
The universe levels of the objects and morphisms are independent, and will often need to be
specified explicitly, as Category.{v} C.
Typically any concrete example will either be a SmallCategory, where v = u,
which can be introduced as
universe u
variable {C : Type u} [SmallCategory C]
or a LargeCategory, where u = v+1, which can be introduced as
universe u
variable {C : Type (u+1)} [LargeCategory C]
In order for the library to handle these cases uniformly,
we generally work with the unconstrained Category.{v u},
for which objects live in Type u and morphisms live in Type v.
Because the universe parameter u for the objects can be inferred from C
when we write Category C, while the universe parameter v for the morphisms
cannot be automatically inferred, through the category theory library
we introduce universe parameters with morphism levels listed first,
as in
universe v u
or
universe v₁ v₂ u₁ u₂
when multiple independent universes are needed.
This has the effect that we can simply write Category.{v} C
(that is, only specifying a single parameter) while u will be inferred.
Often, however, it's not even necessary to include the .{v}.
(Although it was in earlier versions of Lean.)
If it is omitted a "free" universe will be used.
Instances For
A preliminary structure on the way to defining a category, containing the data, but none of the axioms.
The identity morphism on an object.
Composition of morphisms in a category, written
f ≫ g.
Instances
Notation for the identity morphism in a category.
Equations
- CategoryTheory.«term𝟙» = Lean.ParserDescr.node `CategoryTheory.«term𝟙» 1024 (Lean.ParserDescr.symbol "𝟙")
Instances For
Notation for composition of morphisms in a category.
Equations
- CategoryTheory.«term_≫_» = Lean.ParserDescr.trailingNode `CategoryTheory.«term_≫_» 80 81 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ≫ ") (Lean.ParserDescr.cat `term 80))
Instances For
Close the main goal with sorry if its type contains sorry, and fail otherwise.
Equations
- CategoryTheory.sorryIfSorry = Lean.ParserDescr.node `CategoryTheory.sorryIfSorry 1024 (Lean.ParserDescr.nonReservedSymbol "sorry_if_sorry" false)
Instances For
Close the main goal with sorry if its type contains sorry, and fail otherwise.
Equations
- One or more equations did not get rendered due to their size.
Instances For
rfl_cat is a macro for intros; rfl which is attempted in aesop_cat before
doing the more expensive aesop tactic.
This gives a speedup because simp (called by aesop) can be very slow.
https://github.com/leanprover-community/mathlib4/pull/25475 contains measurements from June 2025.
Implementation notes:
refine id ?_: In some cases it is important that the type of the proof matches the expected type exactly. e.g. if the goal is2 = 1 + 1, therfltactic will give a proof of type2 = 2. Starting a proof withrefine id ?_is a trick to make sure that the proof has exactly the expected type, in this case2 = 1 + 1. See also https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/changing.20a.20proof.20can.20break.20a.20later.20proofapply_rfl:rflis a macro that attempts botheq_reflandapply_rfl. Sinceapply_rflsubsumeseq_refl, we can useapply_rflinstead. This fails twice as fast asrfl.
Equations
- CategoryTheory.rfl_cat = Lean.ParserDescr.node `CategoryTheory.rfl_cat 1024 (Lean.ParserDescr.nonReservedSymbol "rfl_cat" false)
Instances For
A thin wrapper for aesop which adds the CategoryTheory rule set and
allows aesop to look through semireducible definitions when calling intros.
This tactic fails when it is unable to solve the goal, making it suitable for
use in auto-params.
Equations
- One or more equations did not get rendered due to their size.
Instances For
We also use aesop_cat? to pass along a Try this suggestion when using aesop_cat
Equations
- One or more equations did not get rendered due to their size.
Instances For
A variant of aesop_cat which does not fail when it is unable to solve the
goal. Use this only for exploration! Nonterminal aesop is even worse than
nonterminal simp.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A tactic for discharging easy category theory goals, widely used as an autoparameter.
Currently this defaults to the aesop_cat wrapper around aesop, but by setting
the option mathlib.tactic.category.grind to true, it will use the grind tactic instead.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A tactic for discharging easy category theory goals, widely used as an autoparameter.
Currently this defaults to the aesop_cat wrapper around aesop, but by setting
the option mathlib.tactic.category.grind to true, it will use the grind tactic instead.
Equations
- CategoryTheory.cat_disch = Lean.ParserDescr.node `CategoryTheory.cat_disch 1024 (Lean.ParserDescr.nonReservedSymbol "cat_disch" false)
Instances For
The typeclass Category C describes morphisms associated to objects of type C.
The universe levels of the objects and morphisms are unconstrained, and will often need to be
specified explicitly, as Category.{v} C. (See also LargeCategory and SmallCategory.)
Identity morphisms are left identities for composition.
Identity morphisms are right identities for composition.
- assoc {W X Y Z : obj} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z) : CategoryStruct.comp (CategoryStruct.comp f g) h = CategoryStruct.comp f (CategoryStruct.comp g h)
Composition in a category is associative.
Instances
A LargeCategory has objects in one universe level higher than the universe level of
the morphisms. It is useful for examples such as the category of types, or the category
of groups, etc.
Instances For
A SmallCategory has objects and morphisms in the same universe level.
Instances For
postcompose an equation between morphisms by another morphism
precompose an equation between morphisms by another morphism
Notation for whiskering an equation by a morphism (on the right).
If f g : X ⟶ Y and w : f = g and h : Y ⟶ Z, then w =≫ h : f ≫ h = g ≫ h.
Equations
- CategoryTheory.«term_=≫_» = Lean.ParserDescr.trailingNode `CategoryTheory.«term_=≫_» 80 81 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " =≫ ") (Lean.ParserDescr.cat `term 80))
Instances For
Notation for whiskering an equation by a morphism (on the left).
If g h : Y ⟶ Z and w : g = h and f : X ⟶ Y, then f ≫= w : f ≫ g = f ≫ h.
Equations
- CategoryTheory.«term_≫=_» = Lean.ParserDescr.trailingNode `CategoryTheory.«term_≫=_» 80 81 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ≫= ") (Lean.ParserDescr.cat `term 80))
Instances For
A morphism f is an epimorphism if it can be cancelled when precomposed:
f ≫ g = f ≫ h implies g = h.
A morphism
fis an epimorphism if it can be cancelled when precomposed.
Instances
A morphism f is a monomorphism if it can be cancelled when postcomposed:
g ≫ f = h ≫ f implies g = h.
- right_cancellation {Z : C} (g h : Z ⟶ X) : CategoryStruct.comp g f = CategoryStruct.comp h f → g = h
A morphism
fis a monomorphism if it can be cancelled when postcomposed.
Instances
The composition of epimorphisms is again an epimorphism. This version takes Epi f and Epi g
as typeclass arguments. For a version taking them as explicit arguments, see epi_comp'.
The composition of epimorphisms is again an epimorphism. This version takes Epi f and Epi g
as explicit arguments. For a version taking them as typeclass arguments, see epi_comp.
The composition of monomorphisms is again a monomorphism. This version takes Mono f and
Mono g as typeclass arguments. For a version taking them as explicit arguments, see mono_comp'.
The composition of monomorphisms is again a monomorphism. This version takes Mono f and
Mono g as explicit arguments. For a version taking them as typeclass arguments, see mono_comp.
f : X ⟶ Y is a monomorphism iff for all Z, composition of morphisms Z ⟶ X with f
is injective.
f : X ⟶ Y is an epimorphism iff for all Z, composition of morphisms Y ⟶ Z with f
is injective.
The category structure on ULift C that is induced from the category
structure on C. This is not made a global instance because of a diamond
when C is a preordered type.
Equations
- One or more equations did not get rendered due to their size.