I'm a total beginner in Coq and I'm trying to implement some category theory stuff as an exercise.
I surfed a little among git repos of the many avaible such implementations (HoTT, Awodey's Coq companion, etc.) it seems that every single project implements something like that
Record Category : Type :=
mkCategory{
ob : Type ;
mor : ob -> ob -> Type ;
compose : forall x y z : ob,
mor x y -> mor y z -> mor x z ;
identity : forall x, mor x x ;
(* ... axioms ... *)
}.
It is kind of natural, considering most definition of categories in modern book. However, I feel that it would be easier to implement it internally (if not mistaken, it was the common definition at Grothendieck's time) :
Definition. A category is the data of
- a set/class $\rm Ob$ of objects,
- a set/class $\rm Mor$ of morphisms,
- functions $s,t \colon {\rm Mor} \to {\rm Ob}$, and $i \colon {\rm Ob} \to {\rm Mor}$ ($s$ stands for source, $t$ for target, and $i$ for identity)
- a function $\circ \colon {\rm Mor} \times_{s,t} {\rm Mor} \to {\rm Mor}$ whose domain is the fiber product of $${\rm Mor} \stackrel s \to {\rm Ob} \stackrel t \leftarrow {\rm Mor}$$
satisfying some axioms...
The advantage of such a definition is that it generalizes directly by replacing "set/class" by "objects of some category" and "functions" by "morphisms of this category", leading to the concept of internal category. (Then you can talk of topological/differential categories, or categories inside a topos, etc.)
My problem is to formalize the fiber product in Coq. My first attemp would be to do something like
Record Category : Type :=
mkCategory{
ob : Type ;
mor : Type ;
s : mor -> ob ;
t : mor -> ob ;
compose : mor -> mor -> option mor ;
i : ob -> mor ;
adequacy : forall f g : mor,
(exists h, (compose f g) = (some h)) -> (t f = s g) ;
(* ... axioms ... *)
}.
But I feel that could lead to some curbersome later code. For example, chained compositions would be difficult to read.
Is there a project with an implementation based on the internal definition? Is there a quick way to define the fiber product I need in Coq?
Edit. By the way, I see a lot of
Ob :> Type
rather of
Ob : Type
What is the meaning of the extra ">"? From the doc, it seems it is some kind of coercion. What exactly does this mean?
Ob
)? $\endgroup$mor
depend ons
andt
, e.g.mor: forall s t : ob, Type
. $\endgroup$