Concrete categories #
A concrete category is a category C
where the objects and morphisms correspond with types and
(bundled) functions between these types. We define concrete categories using
class ConcreteCategory
. To convert an object to a type, write ToHom
. To convert a morphism
to a (bundled) function, write hom
.
Each concrete category C
comes with a canonical faithful functor forget C : C ⥤ Type*
,
see class HasForget
. In particular, we impose no restrictions on the category C
, so Type
has the identity forgetful functor.
We say that a concrete category C
admits a forgetful functor to a concrete category D
, if it
has a functor forget₂ C D : C ⥤ D
such that (forget₂ C D) ⋙ (forget D) = forget C
, see
class HasForget₂
. Due to Faithful.div_comp
, it suffices to verify that forget₂.obj
and
forget₂.map
agree with the equality above; then forget₂
will satisfy the functor laws
automatically, see HasForget₂.mk'
.
Two classes helping construct concrete categories in the two most
common cases are provided in the files BundledHom
and
UnbundledHom
, see their documentation for details.
Implementation notes #
We are currently switching over from HasForget
to a new class ConcreteCategory
,
see Zulip thread: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Concrete.20category.20class.20redesign
Previously, ConcreteCategory
had the same definition as now HasForget
; the coercion of
objects/morphisms to types/functions was defined as (forget C).obj
and (forget C).map
respectively. This leads to defeq issues since existing CoeFun
and FunLike
instances provide
their own casts. We replace this with a less bundled ConcreteCategory
that does not directly
use these coercions.
We do not use CoeSort
to convert objects in a concrete category to types, since this would lead
to elaboration mismatches between results taking a [ConcreteCategory C]
instance and specific
types C
that hold a ConcreteCategory C
instance: the first gets a literal CoeSort.coe
and
the second gets unfolded to the actual coe
field.
ToType
and ToHom
are abbrev
s so that we do not need to copy over instances such as Ring
or RingHomClass
respectively.
Since X → Y
is not a FunLike
, the category of types is not a ConcreteCategory
, but it does
have a HasForget
instance.
References #
See Ahrens and Lumsdaine, Displayed Categories for related work.
A concrete category is a category C
with a fixed faithful functor Forget : C ⥤ Type
.
Note that HasForget
potentially depends on three independent universe levels,
- the universe level
w
appearing inForget : C ⥤ Type w
- the universe level
v
of the morphisms (i.e. we have aCategory.{v} C
) - the universe level
u
of the objects (i.eC : Type u
) They are specified that order, to avoid unnecessary universe annotations.
We have a functor to Type
- forget_faithful : HasForget.forget.Faithful
That functor is faithful
Instances
The forgetful functor from a concrete category to Type u
.
Instances For
Provide a coercion to Type u
for a concrete category. This is not marked as an instance
as it could potentially apply to every type, and so is too expensive in typeclass search.
You can use it on particular examples as:
instance : HasCoeToSort X := HasForget.hasCoeToSort X
Equations
- CategoryTheory.HasForget.hasCoeToSort C = { coe := fun (X : C) => (CategoryTheory.forget C).obj X }
Instances For
In any concrete category, (forget C).map
is injective.
Equations
- CategoryTheory.HasForget.instFunLike = { coe := fun (f : X ⟶ Y) => (CategoryTheory.forget C).map f, coe_injective' := ⋯ }
Instances For
In any concrete category, we can test equality of morphisms by pointwise evaluations.
Analogue of congr_fun h x
,
when h : f = g
is an equality between morphisms in a concrete category.
Variation of ConcreteCategory.comp_apply
that uses forget
instead.
HasForget₂ C D
, where C
and D
are both concrete categories, provides a functor
forget₂ C D : C ⥤ D
and a proof that forget₂ ⋙ (forget D) = forget C
.
- forget₂ : Functor C D
A functor from
C
toD
It covers the
HasForget.forget
forC
andD
Instances
The forgetful functor C ⥤ D
between concrete categories for which we have an instance
HasForget₂ C
.
Equations
Instances For
Equations
Equations
- CategoryTheory.InducedCategory.hasForget₂ f = { forget₂ := CategoryTheory.inducedFunctor f, forget_comp := ⋯ }
Equations
- CategoryTheory.FullSubcategory.hasForget₂ Z = { forget₂ := CategoryTheory.fullSubcategoryInclusion Z, forget_comp := ⋯ }
In order to construct a “partially forgetting” functor, we do not need to verify functor laws;
it suffices to ensure that compositions agree with forget₂ C D ⋙ forget D = forget C
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Composition of HasForget₂
instances.
Equations
- CategoryTheory.HasForget₂.trans C D E = { forget₂ := (CategoryTheory.forget₂ C D).comp (CategoryTheory.forget₂ D E), forget_comp := ⋯ }
Instances For
Every forgetful functor factors through the identity functor. This is not a global instance as it is prone to creating type class resolution loops.
Equations
- CategoryTheory.hasForgetToType C = { forget₂ := CategoryTheory.forget C, forget_comp := ⋯ }
Instances For
A concrete category is a category C
where objects correspond to types and morphisms to
(bundled) functions between those types.
In other words, it has a fixed faithful functor forget : C ⥤ Type
.
Note that ConcreteCategory
potentially depends on three independent universe levels,
- the universe level
w
appearing inforget : C ⥤ Type w
- the universe level
v
of the morphisms (i.e. we have aCategory.{v} C
) - the universe level
u
of the objects (i.eC : Type u
) They are specified that order, to avoid unnecessary universe annotations.
- hom {X Y : C} : (X ⟶ Y) → FC X Y
Convert a morphism of
C
to a bundled function. - ofHom {X Y : C} : FC X Y → (X ⟶ Y)
Convert a bundled function to a morphism of
C
.
Instances
ToType X
converts the object X
of the concrete category C
to a type.
This is an abbrev
so that instances on X
(e.g. Ring
) do not need to be redeclared.
Equations
Instances For
ToHom X Y
is the type of (bundled) functions between objects X Y : C
.
This is an abbrev
so that instances (e.g. RingHomClass
) do not need to be redeclared.
Equations
Instances For
We can apply morphisms of concrete categories by first casting them down to the base functions.
Equations
- CategoryTheory.ConcreteCategory.instCoeFunHomForallToType = { coe := fun (f : X ⟶ Y) => ⇑(CategoryTheory.ConcreteCategory.hom f) }
ConcreteCategory.hom
bundled as an Equiv
.
Equations
- CategoryTheory.ConcreteCategory.homEquiv = { toFun := CategoryTheory.ConcreteCategory.hom, invFun := CategoryTheory.ConcreteCategory.ofHom, left_inv := ⋯, right_inv := ⋯ }
Instances For
In any concrete category, we can test equality of morphisms by pointwise evaluations.
A concrete category comes with a forgetful functor to Type
.
Warning: because of the way that ConcreteCategory
and HasForget
are set up, we can't make
forget Type
reducibly defeq to the identity functor.
Equations
- One or more equations did not get rendered due to their size.
Analogue of congr_fun h x
,
when h : f = g
is an equality between morphisms in a concrete category.
Analogue of congr_arg f h
,
when h : x = x'
is an equality between elements of objects in a concrete category.
Using the FunLike
coercion of HasForget
does the same as the original coercion.
Build a coercion to functions out of HasForget
.
The intended usecase is to provide a FunLike
instance in HasForget.toConcreteCategory
.
See that definition for the considerations in making this an instance.
See note [reducible non-instances].
Equations
- CategoryTheory.HasForget.toFunLike C X Y = { coe := (CategoryTheory.forget C).map, coe_injective' := ⋯ }
Instances For
Build a concrete category out of HasForget
.
The intended usecase is to prove theorems referencing only (forget C)
and not (forget C).obj X
nor (forget C).map f
: those should be written
as ToType X
and ConcreteCategory.hom f
respectively.
See note [reducible non-instances].
Equations
- One or more equations did not get rendered due to their size.
Instances For
Note that the ConcreteCategory
and HasForget
instances here differ from forget_map_eq_coe
.
A FunLike
instance on plain functions, in order to instantiate a ConcreteCategory
structure
on the category of types.
This is not an instance (yet) because that would require a lot of downstream fixes.
See note [reducible non-instances].
Equations
Instances For
The category of types is concrete, using the identity functor.
This is not an instance (yet) because that would require a lot of downstream fixes.
See note [reducible non-instances].
Equations
- One or more equations did not get rendered due to their size.