-
Notifications
You must be signed in to change notification settings - Fork 0
/
categories.tex
1854 lines (1596 loc) · 105 KB
/
categories.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\chapter{Category theory}
\label{cha:category-theory}
Of the branches of mathematics, category theory is one which perhaps fits the least comfortably in set theoretic foundations.
One problem is that most of category theory is invariant under weaker notions of ``sameness'' than equality, such as isomorphism in a category or equivalence of categories, in a way which set theory fails to capture.
But this is the same sort of problem that the univalence axiom solves for types, by identifying equality with equivalence.
Thus, in univalent foundations it makes sense to consider a notion of ``category'' in which equality of objects is identified with isomorphism in a similar way.
Ignoring size issues, in set-based mathematics a category consists of a \emph{set} $A_0$ of objects and, for each $x,y\in A_0$, a \emph{set} $\hom_A(x,y)$ of morphisms.
Under univalent foundations, a ``naive'' definition of category would simply mimic this with a \emph{type} of objects and \emph{types} of morphisms.
If we allowed these types to contain arbitrary higher homotopy, then we ought to impose higher coherence conditions, leading to some notion of $(\infty,1)$-category,
\index{.infinity1-category@$(\infty,1)$-category}%
but at present our goal is more modest.
We consider only 1-categories, and therefore we restrict the types $\hom_A(x,y)$ to be sets, i.e.\ 0-types.
If we impose no further conditions, we will call this notion a \emph{precategory}.
If we add the requirement that the type $A_0$ of objects is a set, then we end up with a definition that behaves much like the traditional set-theoretic one.
Following Toby Bartels, we call this notion a \emph{strict category}.
\index{strict!category}%
But we can also require a generalized version of the univalence axiom, identifying $(x=_{A_0} y)$ with the type $\mathsf{iso}(x,y)$ of isomorphisms from $x$ to $y$.
Since we regard this as usually the ``correct'' definition, we will call it simply a \emph{category}.
A good example of the difference between the three notions of category is provided by the statement ``every fully faithful and essentially surjective functor is an equivalence of categories'', which in classical set-based category theory is equivalent to the axiom of choice.
\index{mathematics!classical}%
\index{axiom!of choice}%
\index{classical!category theory}%
\begin{enumerate}
\item For strict categories, this is still equivalent to the axiom of choice.
\item For precategories, there is no consistent axiom of choice which can make it true.
\item For categories, it is provable \emph{without} any axiom of choice.
\end{enumerate}
We will prove the latter statement in this chapter, as well as other pleasant properties of categories, e.g.\ that equivalent categories are equal (as elements of the type of categories).
We will also describe a universal way of ``saturating'' a precategory $A$ into a category $\widehat A$, which we call its \emph{Rezk completion},
\index{completion!Rezk}%
although it could also reasonably be called the \emph{stack completion} (see the Notes).
The Rezk completion also sheds further light on the notion of equivalence of categories.
For instance, the functor $A \to \widehat{A}$ is always fully faithful and essentially surjective, hence a ``weak equivalence''.
It follows that a precategory is a category exactly when it ``sees'' all fully faithful and essentially surjective functors as equivalences; thus our notion of ``category'' is already inherent in the notion of ``fully faithful and essentially surjective functor''.
We assume the reader has some basic familiarity with classical category theory.\index{classical!category theory}
Recall that whenever we write \type it denotes some universe of types, but perhaps a different one at different times; everything we say remains true for any consistent choice of universe levels\index{universe level}.
We will use the basic notions of homotopy type theory from \cref{cha:typetheory,cha:basics} and the propositional truncation from \cref{cha:logic}, but not much else from \cref{part:foundations}, except that our second construction of the Rezk completion will use a higher inductive type.
\section{Categories and precategories}
\label{sec:cats}
In classical mathematics, there are many equivalent definitions of a category.
In our case, since we have dependent types, it is natural to choose the arrows to be a type family indexed by the objects.
This matches the way hom-types are always used in category theory: we never even consider comparing two arrows unless we know their domains and codomains agree.
Furthermore, it seems clear that for a theory of 1-categories, the hom-types should all be sets.
This leads us to the following definition.
\begin{defn}\label{ct:precategory}
A \define{precategory}
\indexdef{precategory}
$A$ consists of the following.
\begin{enumerate}
\item A type $A_0$ of \define{objects}.%
\indexdef{object!in a (pre)category}
We write $a:A$ for $a:A_0$.
\item For each $a,b:A$, a set $\hom_A(a,b)$ of \define{arrows} or \define{morphisms}.%
\indexsee{arrow}{morphism}%
\indexdef{morphism!in a (pre)category}%
\indexdef{hom-set}%
\item For each $a:A$, a morphism $1_a:\hom_A(a,a)$.%
\indexdef{identity!morphism in a (pre)category}
\item For each $a,b,c:A$, a function%
\indexdef{composition!of morphisms in a (pre)category}
\[ \hom_A(b,c) \to \hom_A(a,b) \to \hom_A(a,c) \]
denoted infix by $g\mapsto f\mapsto g\circ f$, or sometimes simply by $gf$.
\item For each $a,b:A$ and $f:\hom_A(a,b)$, we have $\id f {1_b\circ f}$ and $\id f {f\circ 1_a}$.
\item For each $a,b,c,d:A$ and
\begin{equation*}
f:\hom_A(a,b), \qquad
g:\hom_A(b,c), \qquad
h:\hom_A(c,d),
\end{equation*}
we have $\id {h\circ (g\circ f)}{(h\circ g)\circ f}$.
\end{enumerate}
\end{defn}
The problem with the notion of precategory is that for objects $a,b:A$, we have two possibly-different notions of ``sameness''.
On the one hand, we have the type $(\id[A_0]{a}{b})$.
But on the other hand, there is the standard categorical notion of \emph{isomorphism}.
\begin{defn}\label{ct:isomorphism}
A morphism $f:\hom_A(a,b)$ is an \define{isomorphism}
\indexdef{isomorphism!in a (pre)category}%
if there is a morphism $g:\hom_A(b,a)$ such that $\id{g\circ f}{1_a}$ and $\id{f\circ g}{1_b}$.
We write $a\cong b$ for the type of such isomorphisms.
\end{defn}
\begin{lem}\label{ct:isoprop}
For any $f:\hom_A(a,b)$, the type ``$f$ is an isomorphism'' is a mere proposition.
Therefore, for any $a,b:A$ the type $a\cong b$ is a set.
\end{lem}
\begin{proof}
Suppose given $g:\hom_A(b,a)$ and $\eta:(\id{1_a}{g\circ f})$ and $\epsilon:(\id{f\circ g}{1_b})$, and similarly $g'$, $\eta'$, and $\epsilon'$.
We must show $\id{(g,\eta,\epsilon)}{(g',\eta',\epsilon')}$.
But since all hom-sets are sets, their identity types are mere propositions, so it suffices to show $\id g {g'}$.
For this we have
\[g' = 1_a\circ g' = (g\circ f)\circ g' = g\circ (f\circ g') = g\circ 1_b = g\]
using $\eta$ and $\epsilon'$.
\end{proof}
\symlabel{ct:inv}
\index{inverse!in a (pre)category}%
If $f:a\cong b$, then we write $\inv f$ for its inverse, which by \cref{ct:isoprop} is uniquely determined.
The only relationship between these two notions of sameness that we have in a precategory is the following.
\begin{lem}[\textsf{idtoiso}]\label{ct:idtoiso}
If $A$ is a precategory and $a,b:A$, then
\[(\id a b)\to (a \cong b).\]
\end{lem}
\begin{proof}
By induction on identity, we may assume $a$ and $b$ are the same.
But then we have $1_a:\hom_A(a,a)$, which is clearly an isomorphism.
\end{proof}
Evidently, this situation is analogous to the issue that motivated us to introduce the univalence axiom.
In fact, we have the following:
\begin{eg}\label{ct:precatset}
\index{set}%
There is a precategory \uset, whose type of objects is \set, and with $\hom_{\uset}(A,B) \defeq (A\to B)$.
The identity morphisms are identity functions and the composition is function composition.
For this precategory, \cref{ct:idtoiso} is equal to (the restriction to sets of) the map $\idtoeqv$ from \cref{sec:compute-universe}.
Of course, to be more precise we should call this category $\uset_\UU$, since its objects are only the \emph{small sets}
\index{small!set}%
relative to a universe \UU.
\end{eg}
Thus, it is natural to make the following definition.
\begin{defn}\label{ct:category}
A \define{category}
\indexdef{category}
is a precategory such that for all $a,b:A$, the function $\idtoiso_{a,b}$ from \cref{ct:idtoiso} is an equivalence.
\end{defn}
In particular, in a category, if $a\cong b$, then $a=b$.
\begin{eg}\label{ct:eg:set}
\index{univalence axiom}%
The univalence axiom implies immediately that \uset is a category.
One can also show, using univalence, that any precategory of set-level structures such as groups, rings, topological spaces, etc.\ is a category; see \cref{sec:sip}.
\end{eg}
We also note the following.
\begin{lem}\label{ct:obj-1type}
In a category, the type of objects is a 1-type.
\end{lem}
\begin{proof}
It suffices to show that for any $a,b:A$, the type $\id a b$ is a set.
But $\id a b$ is equivalent to $a \cong b$, which is a set.
\end{proof}
\symlabel{isotoid}
We write $\isotoid$ for the inverse $(a\cong b) \to (\id a b)$ of the map $\idtoiso$ from \cref{ct:idtoiso}.
The following relationship between the two is important.
\begin{lem}\label{ct:idtoiso-trans}
For $p:\id a a'$ and $q:\id b b'$ and $f:\hom_A(a,b)$, we have
\begin{equation}\label{ct:idtoisocompute}
\id{\trans{(p,q)}{f}}
{\idtoiso(q)\circ f \circ \inv{\idtoiso(p)}}.
\end{equation}
\end{lem}
\begin{proof}
By induction, we may assume $p$ and $q$ are $\refl a$ and $\refl b$ respectively.
Then the left-hand side of~\eqref{ct:idtoisocompute} is simply $f$.
But by definition, $\idtoiso(\refl a)$ is $1_a$, and $\idtoiso(\refl b)$ is $1_b$, so the right-hand side of~\eqref{ct:idtoisocompute} is $1_b\circ f\circ 1_a$, which is equal to $f$.
\end{proof}
Similarly, we can show
\begin{gather}
\id{\idtoiso(\rev p)}{\inv {(\idtoiso(p))}}\\
\id{\idtoiso(p\ct q)}{\idtoiso(q)\circ \idtoiso(p)}\\
\id{\isotoid(f\circ e)}{\isotoid(e)\ct \isotoid(f)}
\end{gather}
and so on.
\begin{eg}\label{ct:orders}
A precategory in which each set $\hom_A(a,b)$ is a mere proposition is equivalently a type $A_0$ equipped with a mere relation ``$\le$'' that is reflexive ($a\le a$) and transitive (if $a\le b$ and $b\le c$, then $a\le c$).
We call this a \define{preorder}.
\indexdef{preorder}
In a preorder, a witness $f: a\le b$ is an isomorphism just when there exists some witness $g: b\le a$.
Thus, $a\cong b$ is the mere proposition that $a\le b$ and $b\le a$.
Therefore, a preorder $A$ is a category just when (1) each type $a=b$ is a mere proposition, and (2) for any $a,b:A_0$ there exists a function $(a\cong b) \to (a=b)$.
In other words, $A_0$ must be a set, and $\le$ must be antisymmetric\index{relation!antisymmetric} (if $a\le b$ and $b\le a$, then $a=b$).
We call this a \define{(partial) order} or a \define{poset}.
\indexdef{partial order}%
\indexdef{poset}%
\end{eg}
\begin{eg}\label{ct:gaunt}
If $A$ is a category, then $A_0$ is a set if and only if for any $a,b:A_0$, the type $a\cong b$ is a mere proposition.
This is equivalent to saying that every isomorphism in $A$ is an identity; thus it is rather stronger than the classical\index{mathematics!classical} notion of ``skeletal'' category.
Categories of this sort are sometimes called \define{gaunt}~\cite{bsp12infncats}.
\indexdef{category!gaunt}%
\indexdef{gaunt category}%
\index{skeletal category}%
\index{category!skeletal}%
There is not really any notion of ``skeletality'' for our categories, unless one considers \cref{ct:category} itself to be such.
\end{eg}
\begin{eg}\label{ct:discrete}
For any 1-type $X$, there is a category with $X$ as its type of objects and with $\hom(x,y) \defeq (x=y)$.
If $X$ is a set, we call this the \define{discrete}
\indexdef{category!discrete}%
\indexdef{discrete!category}%
category on $X$.
In general, we call it a \define{groupoid}
\indexdef{groupoid}
(see \cref{ct:groupoids}).
\end{eg}
\begin{eg}\label{ct:fundgpd}
For \emph{any} type $X$, there is a precategory with $X$ as its type of objects and with $\hom(x,y) \defeq \pizero{x=y}$.
The composition operation
\[ \pizero{y=z} \to \pizero{x=y} \to \pizero{x=z} \]
is defined by induction on truncation from concatenation $(y=z)\to(x=y)\to(x=z)$.
We call this the \define{fundamental pregroupoid}
\indexdef{fundamental!pregroupoid}%
\indexsee{pregroupoid, fundamental}{fundamental pregroupoid}%
of $X$.
(In fact, we have met it already in \cref{sec:van-kampen}; see also \cref{ex:rezk-vankampen}.)
\end{eg}
\begin{eg}\label{ct:hoprecat}
There is a precategory whose type of objects is \type and with $\hom(X,Y) \defeq \pizero{X\to Y}$, and composition defined by induction on truncation from ordinary composition $(Y\to Z) \to (X\to Y) \to (X\to Z)$.
We call this the \define{homotopy precategory of types}.
\indexdef{precategory!of types}%
\index{homotopy!category of types@(pre)category of types}%
\end{eg}
\begin{eg}\label{ct:rel}
Let \urel be the following precategory:
\begin{itemize}
\item Its objects are sets.
\item $\hom_{\urel}(X,Y) = X\to Y\to \prop$.
\item For a set $X$, we have $1_X(x,x') \defeq (x=x')$.
\item For $R:\hom_{\urel}(X,Y)$ and $S:\hom_{\urel}(Y,Z)$, their composite is defined by
\[ (S\circ R)(x,z) \defeq \Brck{\sm{y:Y} R(x,y) \times S(y,z)}.\]
\end{itemize}
Suppose $R:\hom_{\urel}(X,Y)$ is an isomorphism, with inverse $S$.
We observe the following.
\begin{enumerate}
\item If $R(x,y)$ and $S(y',x)$, then $(R\circ S)(y',y)$, and hence $y'=y$.
Similarly, if $R(x,y)$ and $S(y,x')$, then $x=x'$.\label{item:rel1}
\item For any $x$, we have $x=x$, hence $(S\circ R)(x,x)$.
Thus, there merely exists a $y:Y$ such that $R(x,y)$ and $S(y,x)$.\label{item:rel2}
\item Suppose $R(x,y)$.
By~\ref{item:rel2}, there merely exists a $y'$ with $R(x,y')$ and $S(y',x)$.
But then by~\ref{item:rel1}, merely $y'=y$, and hence $y'=y$ since $Y$ is a set.
Therefore, by transporting $S(y',x)$ along this equality, we have $S(y,x)$.
In conclusion, $R(x,y)\to S(y,x)$.
Similarly, $S(y,x) \to R(x,y)$.\label{item:rel3}
\item If $R(x,y)$ and $R(x,y')$, then by~\ref{item:rel3}, $S(y',x)$, so that by~\ref{item:rel1}, $y=y'$.
Thus, for any $x$ there is at most one $y$ such that $R(x,y)$.
And by~\ref{item:rel2}, there merely exists such a $y$, hence there exists such a $y$.
\end{enumerate}
In conclusion, if $R:\hom_{\urel}(X,Y)$ is an isomorphism, then for each $x:X$ there is exactly one $y:Y$ such that $R(x,y)$, and dually.
Thus, there is a function $f:X\to Y$ sending each $x$ to this $y$, which is an equivalence; hence $X=Y$.
With a little more work, we conclude that \urel is a category.
\end{eg}
We might now restrict ourselves to considering categories rather than precategories.
Instead, we will develop many concepts for precategories as well as categories, in order to emphasize how much better-behaved categories are, as compared both to precategories and to ordinary categories in classical\index{mathematics!classical} mathematics.
We will also see in \crefrange{sec:strict-categories}{sec:dagger-categories} that in slightly more exotic contexts, there are uses for certain kinds of precategories other than categories, each of which ``fixes'' the equality of objects in different ways.
This emphasizes the ``pre''-ness of precategories: they are the raw material out of which multiple important categorical structures can be defined.
\section{Functors and transformations}
\label{sec:transfors}
The following definitions are fairly obvious, and need no modification.
\begin{defn}\label{ct:functor}
Let $A$ and $B$ be precategories.
A \define{functor}
\indexdef{functor}%
$F:A\to B$ consists of
\begin{enumerate}
\item A function $F_0:A_0\to B_0$, generally also denoted $F$.
\item For each $a,b:A$, a function $F_{a,b}:\hom_A(a,b) \to \hom_B(Fa,Fb)$, generally also denoted $F$.
\item For each $a:A$, we have $\id{F(1_a)}{1_{Fa}}$.
\item For each $a,b,c:A$ and $f:\hom_A(a,b)$ and $g:\hom_B(b,c)$, we have
\[\id{F(g\circ f)}{Fg\circ Ff}.\]
\end{enumerate}
\end{defn}
Note that by induction on identity, a functor also preserves \idtoiso.
\begin{defn}\label{ct:nattrans}
For functors $F,G:A\to B$, a \define{natural transformation}
\indexdef{natural!transformation}%
\indexsee{transformation!natural}{natural transformation}%
$\gamma:F\to G$ consists of
\begin{enumerate}
\item For each $a:A$, a morphism $\gamma_a:\hom_B(Fa,Ga)$ (the ``components'').
\item For each $a,b:A$ and $f:\hom_A(a,b)$, we have $\id{Gf\circ \gamma_a}{\gamma_b\circ Ff}$ (the ``naturality axiom'').
\end{enumerate}
\end{defn}
Since each type $\hom_B(Fa,Gb)$ is a set, its identity type is a mere proposition.
Thus, the naturality axiom is a mere proposition, so identity of natural transformations is determined by identity of their components.
In particular, for any $F$ and $G$, the type of natural transformations from $F$ to $G$ is again a set.
Similarly, identity of functors is determined by identity of the functions $A_0\to B_0$ and (transported along this) of the corresponding functions on hom-sets.
\begin{defn}\label{ct:functor-precat}
\indexdef{precategory!of functors}%
For precategories $A,B$, there is a precategory $B^A$ defined by
\begin{itemize}
\item $(B^A)_0$ is the type of functors from $A$ to $B$.
\item $\hom_{B^A}(F,G)$ is the type of natural transformations from $F$ to $G$.
\end{itemize}
\end{defn}
\begin{proof}
We define $(1_F)_a\defeq 1_{Fa}$.
Naturality follows by the unit axioms of a precategory.
For $\gamma:F\to G$ and $\delta:G\to H$, we define $(\delta\circ\gamma)_a\defeq \delta_a\circ \gamma_a$.
Naturality follows by associativity.
Similarly, the unit and associativity laws for $B^A$ follow from those for $B$.
\end{proof}
\begin{lem}\label{ct:natiso}
\index{natural!isomorphism}%
\index{isomorphism!natural}%
A natural transformation $\gamma:F\to G$ is an isomorphism in $B^A$ if and only if each $\gamma_a$ is an isomorphism in $B$.
\end{lem}
\begin{proof}
If $\gamma$ is an isomorphism, then we have $\delta:G\to F$ that is its inverse.
By definition of composition in $B^A$, $(\delta\gamma)_a\jdeq \delta_a\gamma_a$ and similarly.
Thus, $\id{\delta\gamma}{1_F}$ and $\id{\gamma\delta}{1_G}$ imply $\id{\delta_a\gamma_a}{1_{Fa}}$ and $\id{\gamma_a\delta_a}{1_{Ga}}$, so $\gamma_a$ is an isomorphism.
Conversely, suppose each $\gamma_a$ is an isomorphism, with inverse called $\delta_a$, say.
We define a natural transformation $\delta:G\to F$ with components $\delta_a$; for the naturality axiom we have
\[ Ff\circ \delta_a = \delta_b\circ \gamma_b\circ Ff \circ \delta_a = \delta_b\circ Gf\circ \gamma_a\circ \delta_a = \delta_b\circ Gf. \]
Now since composition and identity of natural transformations is determined on their components, we have $\id{\gamma\delta}{1_G}$ and $\id{\delta\gamma}{1_F}$.
\end{proof}
The following result is fundamental.
\begin{thm}\label{ct:functor-cat}
\indexdef{category!of functors}%
\indexdef{functor!category of}%
If $A$ is a precategory and $B$ is a category, then $B^A$ is a category.
\end{thm}
\begin{proof}
Let $F,G:A\to B$; we must show that $\idtoiso:(\id{F}{G}) \to (F\cong G)$ is an equivalence.
To give an inverse to it, suppose $\gamma:F\cong G$ is a natural isomorphism.
Then for any $a:A$, we have an isomorphism $\gamma_a:Fa \cong Ga$, hence an identity $\isotoid(\gamma_a):\id{Fa}{Ga}$.
By function extensionality, we have an identity $\bar{\gamma}:\id[(A_0\to B_0)]{F_0}{G_0}$.
Now since the last two axioms of a functor are mere propositions, to show that $\id{F}{G}$ it will suffice to show that for any $a,b:A$, the functions
\begin{align*}
F_{a,b}&:\hom_A(a,b) \to \hom_B(Fa,Fb)\mathrlap{\qquad\text{and}}\\
G_{a,b}&:\hom_A(a,b) \to \hom_B(Ga,Gb)
\end{align*}
become equal when transported along $\bar\gamma$.
By computation for function extensionality, when applied to $a$, $\bar\gamma$ becomes equal to $\isotoid(\gamma_a)$.
But by \cref{ct:idtoiso-trans}, transporting $Ff:\hom_B(Fa,Fb)$ along $\isotoid(\gamma_a)$ and $\isotoid(\gamma_b)$ is equal to the composite $\gamma_b\circ Ff\circ \inv{(\gamma_a)}$, which by naturality of $\gamma$ is equal to $Gf$.
This completes the definition of a function $(F\cong G) \to (\id F G)$.
Now consider the composite
\[ (\id F G) \to (F\cong G) \to (\id F G). \]
Since hom-sets are sets, their identity types are mere propositions, so to show that two identities $p,q:\id F G$ are equal, it suffices to show that $\id[\id{F_0}{G_0}]{p}{q}$.
But in the definition of $\bar\gamma$, if $\gamma$ were of the form $\idtoiso(p)$, then $\gamma_a$ would be equal to $\idtoiso(p_a)$ (this can easily be proved by induction on $p$).
Thus, $\isotoid(\gamma_a)$ would be equal to $p_a$, and so by function extensionality we would have $\id{\bar\gamma}{p}$, which is what we need.
Finally, consider the composite
\[(F\cong G)\to (\id F G) \to (F\cong G). \]
Since identity of natural transformations can be tested componentwise, it suffices to show that for each $a$ we have $\id{\idtoiso(\bar\gamma)_a}{\gamma_a}$.
But as observed above, we have $\id{\idtoiso(\bar\gamma)_a}{\idtoiso((\bar\gamma)_a)}$, while $\id{(\bar\gamma)_a}{\isotoid(\gamma_a)}$ by computation for function extensionality.
Since $\isotoid$ and $\idtoiso$ are inverses, we have $\id{\idtoiso(\bar\gamma)_a}{\gamma_a}$ as desired.
\end{proof}
In particular, naturally isomorphic functors between categories (as opposed to precategories) are equal.
\mentalpause
We now define all the usual ways to compose functors and natural transformations.
\begin{defn}\label{ct:functor-composition}
For functors $F:A\to B$ and $G:B\to C$, their composite $G\circ F:A\to C$ is given by
\begin{itemize}
\item The composite $(G_0\circ F_0) : A_0 \to C_0$
\item For each $a,b:A$, the composite
\[(G_{Fa,Fb}\circ F_{a,b}):\hom_A(a,b) \to \hom_C(GFa,GFb).\]
\end{itemize}
It is easy to check the axioms.
\end{defn}
\begin{defn}\label{ct:whisker}
For functors $F:A\to B$ and $G,H:B\to C$ and a natural transformation $\gamma:G\to H$, the composite $(\gamma F):GF\to HF$ is given by
\begin{itemize}
\item For each $a:A$, the component $\gamma_{Fa}$.
\end{itemize}
Naturality is easy to check.
Similarly, for $\gamma$ as above and $K:C\to D$, the composite $(K\gamma):KG\to KH$ is given by
\begin{itemize}
\item For each $b:B$, the component $K(\gamma_b)$.
\end{itemize}
\end{defn}
\begin{lem}\label{ct:interchange}
\index{interchange law}%
For functors $F,G:A\to B$ and $H,K:B\to C$ and natural transformations $\gamma:F\to G$ and $\delta:H\to K$, we have
\[\id{(\delta G)(H\gamma)}{(K\gamma)(\delta F)}.\]
\end{lem}
\begin{proof}
It suffices to check componentwise: at $a:A$ we have
\begin{align*}
((\delta G)(H\gamma))_a
&\jdeq (\delta G)_{a}(H\gamma)_a\\
&\jdeq \delta_{Ga}\circ H(\gamma_a)\\
&= K(\gamma_a) \circ \delta_{Fa} \tag{by naturality of $\delta$}\\
&\jdeq (K \gamma)_a\circ (\delta F)_a\\
&\jdeq ((K \gamma)(\delta F))_a.\qedhere
\end{align*}
\end{proof}
\index{horizontal composition!of natural transformations}%
\index{classical!category theory}%
Classically, one defines the ``horizontal composite'' of $\gamma:F\to G$ and $\delta:H\to K$ to be the common value of ${(\delta G)(H\gamma)}$ and ${(K\gamma)(\delta F)}$.
We will refrain from doing this, because while equal, these two transformations are not \emph{definitionally} equal.
This also has the consequence that we can use the symbol $\circ$ (or juxtaposition) for all kinds of composition unambiguously: there is only one way to compose two natural transformations (as opposed to composing a natural transformation with a functor on either side).
\begin{lem}\label{ct:functor-assoc}
\index{associativity!of functor composition}
Composition of functors is associative: $\id{H(GF)}{(HG)F}$.
\end{lem}
\begin{proof}
Since composition of functions is associative, this follows immediately for the actions on objects and on homs.
And since hom-sets are sets, the rest of the data is automatic.
\end{proof}
The equality in \cref{ct:functor-assoc} is likewise not definitional.
(Composition of functions is definitionally associative, but the axioms that go into a functor must also be composed, and this breaks definitional associativity.) For this reason, we need also to know about \emph{coherence}\index{coherence} for associativity.
\begin{lem}\label{ct:pentagon}
\index{associativity!of functor composition!coherence of}%
\cref{ct:functor-assoc} is coherent, i.e.\ the following pentagon\index{pentagon, Mac Lane} of equalities commutes:
\[ \xymatrix{ & K(H(GF)) \ar@{=}[dl] \ar@{=}[dr]\\
(KH)(GF) \ar@{=}[d] && K((HG)F) \ar@{=}[d]\\
((KH)G)F && (K(HG))F \ar@{=}[ll] }
\]
\end{lem}
\begin{proof}
As in \cref{ct:functor-assoc}, this is evident for the actions on objects, and the rest is automatic.
\end{proof}
We will henceforth abuse notation by writing $H\circ G\circ F$ or $HGF$ for either $H(GF)$ or $(HG)F$, transporting along \cref{ct:functor-assoc} whenever necessary.
We have a similar coherence result for units.
\begin{lem}\label{ct:units}
For a functor $F:A\to B$, we have equalities $\id{(1_B\circ F)}{F}$ and $\id{(F\circ 1_A)}{F}$, such that given also $G:B\to C$, the following triangle of equalities commutes.
\[ \xymatrix{
G\circ (1_B \circ F) \ar@{=}[rr] \ar@{=}[dr] &&
(G\circ 1_B)\circ F \ar@{=}[dl] \\
& G \circ F.}
\]
\end{lem}
See \cref{ct:pre2cat,ct:2cat} for further development of these ideas.
\section{Adjunctions}
\label{sec:adjunctions}
The definition of adjoint functors is straightforward; the main interesting aspect arises from proof-relevance.
\begin{defn}\label{ct:adjoints}
A functor $F:A\to B$ is a \define{left adjoint}
\indexdef{left!adjoint}%
\indexdef{adjoint!functor}%
\indexdef{right!adjoint}%
\indexdef{adjoint!functor}%
\index{functor!adjoint}%
if there exists
\begin{itemize}
\item A functor $G:B\to A$.
\item A natural transformation $\eta:1_A \to GF$ (the \define{unit}\indexdef{unit!of an adjunction}).
\item A natural transformation $\epsilon:FG\to 1_B$ (the \define{counit}\indexdef{counit of an adjunction}).
\item $\id{(\epsilon F)(F\eta)}{1_F}$.
\item $\id{(G\epsilon)(\eta G)}{1_G}$.
\end{itemize}
\end{defn}
The last two equations are called the \define{triangle identities}\indexdef{triangle!identity} or \define{zigzag identities}\indexdef{zigzag identity}.
\indexdef{identity!triangle}\indexdef{identity!zigzag}
We leave it to the reader to define right adjoints analogously.
\begin{lem}\label{ct:adjprop}
If $A$ is a category (but $B$ may be only a precategory), then the type ``$F$ is a left adjoint'' is a mere proposition.
\end{lem}
\begin{proof}
Suppose we are given $(G,\eta,\epsilon)$ with the triangle identities and also $(G',\eta',\epsilon')$.
Define $\gamma:G\to G'$ to be $(G'\epsilon)(\eta' G)$, and $\delta:G'\to G$ to be $(G\epsilon')(\eta G')$.
Then
\begin{align*}
\delta\gamma &=
(G\epsilon')(\eta G')(G'\epsilon)(\eta'G)\\
&= (G\epsilon')(G F G'\epsilon)(\eta G' F G)(\eta'G)\\
&= (G\epsilon)(G\epsilon'FG)(G F \eta' G)(\eta G)\\
&= (G\epsilon)(\eta G)\\
&= 1_G
\end{align*}
using \cref{ct:interchange} and the triangle identities.
Similarly, we show $\id{\gamma\delta}{1_{G'}}$, so $\gamma$ is a natural isomorphism $G\cong G'$.
By \cref{ct:functor-cat}, we have an identity $\id G {G'}$.
Now we need to know that when $\eta$ and $\epsilon$ are transported along this identity, they become equal to $\eta'$ and $\epsilon'$.
By \cref{ct:idtoiso-trans}, this transport is given by composing with $\gamma$ or $\delta$ as appropriate.
For $\eta$, this yields
\begin{equation*}
(G'\epsilon F)(\eta'GF)\eta
= (G'\epsilon F)(G'F\eta)\eta'
= \eta'
\end{equation*}
using \cref{ct:interchange} and the triangle identity.
The case of $\epsilon$ is similar.
Finally, the triangle identities transport correctly automatically, since hom-sets are sets.
\end{proof}
In \cref{sec:yoneda} we will give another proof of \cref{ct:adjprop}.
\section{Equivalences}
\label{sec:equivalences}
It is usual in category theory to define an \emph{equivalence of categories} to be a functor $F:A\to B$ such that there exists a functor $G:B\to A$ and natural isomorphisms $F G \cong 1_B$ and $G F \cong 1_A$.
Unlike the property of being an adjunction, however, this would not be a mere proposition without truncating it, for the same reasons that the type of quasi-inverses is ill-behaved (see \cref{sec:quasi-inverses}).
And as in \cref{sec:hae}, we can avoid this by using the usual notion of \emph{adjoint} equivalence.
\indexdef{adjoint!equivalence!of (pre)categories}
\begin{defn}\label{ct:equiv}
A functor $F:A\to B$ is an \define{equivalence of (pre)categories}
\indexdef{equivalence!of (pre)categories}%
\indexdef{category!equivalence of}%
\indexdef{precategory!equivalence of}%
\index{functor!equivalence}%
if it is a left adjoint for which $\eta$ and $\epsilon$ are isomorphisms.
We write $\cteqv A B$ for the type of equivalences of categories from $A$ to $B$.
\end{defn}
By \cref{ct:adjprop,ct:isoprop}, if $A$ is a category, then the type ``$F$ is an equivalence of precategories'' is a mere proposition.
\begin{lem}\label{ct:adjointification}
If for $F:A\to B$ there exists $G:B\to A$ and isomorphisms $GF\cong 1_A$ and $FG\cong 1_B$, then $F$ is an equivalence of precategories.
\end{lem}
\begin{proof}
Just like the proof of \cref{thm:equiv-iso-adj} for equivalences of types.
\end{proof}
\begin{defn}\label{ct:full-faithful}
We say a functor $F:A\to B$ is \define{faithful}
\indexdef{functor!faithful}%
\index{faithful functor}%a
if for all $a,b:A$, the function
\[F_{a,b}:\hom_A(a,b) \to \hom_B(Fa,Fb)\]
is injective, and \define{full}
\indexdef{functor!full}%
\indexdef{full functor}%
if for all $a,b:A$ this function is surjective.
If it is both (hence each $F_{a,b}$ is an equivalence) we say $F$ is \define{fully faithful}.
\indexdef{functor!fully faithful}%
\indexdef{fully faithful functor}%
\end{defn}
\begin{defn}\label{ct:split-essentially-surjective}
We say a functor $F:A\to B$ is \define{split essentially surjective}
\indexdef{functor!split essentially surjective}%
\indexdef{split!essentially surjective functor}%
if for all $b:B$ there exists an $a:A$ such that $Fa\cong b$.
\end{defn}
\begin{lem}\label{ct:ffeso}
For any precategories $A$ and $B$ and functor $F:A\to B$, the following types are equivalent.
\begin{enumerate}
\item $F$ is an equivalence of precategories.\label{item:ct:ffeso1}
\item $F$ is fully faithful and split essentially surjective.\label{item:ct:ffeso2}
\end{enumerate}
\end{lem}
\begin{proof}
Suppose $F$ is an equivalence of precategories, with $G,\eta,\epsilon$ specified.
Then we have the function
\begin{align*}
\hom_B(Fa,Fb) &\to \hom_A(a,b),\\
g &\mapsto \inv{\eta_b}\circ G(g)\circ \eta_a.
\end{align*}
For $f:\hom_A(a,b)$, we have
\[ \inv{\eta_{b}}\circ G(F(f))\circ \eta_{a} =
\inv{\eta_{b}} \circ \eta_{b} \circ f=
f
\]
while for $g:\hom_B(Fa,Fb)$ we have
\begin{align*}
F(\inv{\eta_b} \circ G(g)\circ\eta_a)
&= F(\inv{\eta_b})\circ F(G(g))\circ F(\eta_a)\\
&= \epsilon_{Fb}\circ F(G(g))\circ F(\eta_a)\\
&= g\circ\epsilon_{Fa}\circ F(\eta_a)\\
&= g
\end{align*}
using naturality of $\epsilon$, and the triangle identities twice.
Thus, $F_{a,b}$ is an equivalence, so $F$ is fully faithful.
Finally, for any $b:B$, we have $Gb:A$ and $\epsilon_b:FGb\cong b$.
On the other hand, suppose $F$ is fully faithful and split essentially surjective.
Define $G_0:B_0\to A_0$ by sending $b:B$ to the $a:A$ given by the specified essential splitting, and write $\epsilon_b$ for the likewise specified isomorphism $FGb\cong b$.
Now for any $g:\hom_B(b,b')$, define $G(g):\hom_A(Gb,Gb')$ to be the unique morphism such that $\id{F(G(g))}{\inv{(\epsilon_{b'})}\circ g \circ \epsilon_b }$ (which exists since $F$ is fully faithful).
Finally, for $a:A$ define $\eta_a:\hom_A(a,GFa)$ to be the unique morphism such that $\id{F\eta_a}{\inv{\epsilon_{Fa}}}$.
It is easy to verify that $G$ is a functor and that $(G,\eta,\epsilon)$ exhibit $F$ as an equivalence of precategories.
Now consider the composite~\ref{item:ct:ffeso1}$\to$\ref{item:ct:ffeso2}$\to$\ref{item:ct:ffeso1}.
We clearly recover the same function $G_0:B_0 \to A_0$.
For the action of $G$ on hom-sets, we must show that for $g:\hom_B(b,b')$, $G(g)$ is the (necessarily unique) morphism such that $F(G(g)) = \inv{(\epsilon_{b'})}\circ g \circ \epsilon_b$.
But this equation holds by the assumed naturality of $\epsilon$.
We also clearly recover $\epsilon$, while $\eta$ is uniquely characterized by $\id{F\eta_a}{\inv{\epsilon_{Fa}}}$ (which is one of the triangle identities assumed to hold in the structure of an equivalence of precategories).
Thus, this composite is equal to the identity.
Finally, consider the other composite~\ref{item:ct:ffeso2}$\to$\ref{item:ct:ffeso1}$\to$\ref{item:ct:ffeso2}.
Since being fully faithful is a mere proposition, it suffices to observe that we recover, for each $b:B$, the same $a:A$ and isomorphism $F a \cong b$.
But this is clear, since we used this function and isomorphism to define $G_0$ and $\epsilon$ in~\ref{item:ct:ffeso1}, which in turn are precisely what we used to recover~\ref{item:ct:ffeso2} again.
Thus, the composites in both directions are equal to identities, hence we have an equivalence \eqv{\text{\ref{item:ct:ffeso1}}}{\text{\ref{item:ct:ffeso2}}}.
\end{proof}
However, if $B$ is not a category, then neither type in \cref{ct:ffeso} may necessarily be a mere proposition.
This suggests considering as well the following notions.
\begin{defn}\label{ct:essentially-surjective}
A functor $F:A\to B$ is \define{essentially surjective}
\indexdef{functor!essentially surjective}%
\indexdef{essentially surjective functor}%
if for all $b:B$, there \emph{merely} exists an $a:A$ such that $Fa\cong b$.
We say $F$ is a \define{weak equivalence}
\indexsee{equivalence!of (pre)categories!weak}{weak equivalence}%
\indexdef{weak equivalence!of precategories}%
\indexsee{functor!weak equivalence}{weak equivalence}%
if it is fully faithful and essentially surjective.
\end{defn}
Being a weak equivalence is \emph{always} a mere proposition.
For categories, however, there is no difference between equivalences and weak ones.
\index{acceptance}
\begin{lem}\label{ct:catweq}
If $F:A\to B$ is fully faithful and $A$ is a category, then for any $b:B$ the type $\sm{a:A} (Fa\cong b)$ is a mere proposition.
Hence a functor between categories is an equivalence if and only if it is a weak equivalence.
\end{lem}
\begin{proof}
Suppose given $(a,f)$ and $(a',f')$ in $\sm{a:A} (Fa\cong b)$.
Then $\inv{f'}\circ f$ is an isomorphism $Fa \cong Fa'$.
Since $F$ is fully faithful, we have $g:a\cong a'$ with $Fg = \inv{f'}\circ f$.
And since $A$ is a category, we have $p:a=a'$ with $\idtoiso(p)=g$.
Now $Fg = \inv{f'}\circ f$ implies $\trans{(\map{(F_0)}{p})}{f} = f'$, hence (by the characterization of equalities in dependent pair types) $(a,f)=(a',f')$.
Thus, for fully faithful functors whose domain is a category, essential surjectivity is equivalent to split essential surjectivity, and so being a weak equivalence is equivalent to being an equivalence.
\end{proof}
This is an important advantage of our category theory over set-based approaches.
With a purely set-based definition of category, the statement ``every fully faithful and essentially surjective functor is an equivalence of categories'' is equivalent to the axiom of choice \choice{}.
Here we have it for free, as a category-theoretic version of the principle of unique choice (\cref{sec:unique-choice}).
(In fact, this property characterizes categories among precategories; see \cref{sec:rezk}.)
On the other hand, the following characterization of equivalences of categories is perhaps even more useful.
\begin{defn}\label{ct:isocat}
A functor $F:A\to B$ is an \define{isomorphism of (pre)cat\-ego\-ries}
\indexdef{isomorphism!of (pre)categories}%
\indexdef{category!isomorphism of}%
\indexdef{precategory!isomorphism of}%
if $F$ is fully faithful and $F_0:A_0\to B_0$ is an equivalence of types.
\end{defn}
This definition is an exception to our general rule (see \cref{sec:basics-equivalences}) of only using the word ``isomorphism'' for sets and set-like objects.
However, it does carry an appropriate connotation here, because for general precategories, isomorphism is stronger than equivalence.
Note that being an isomorphism of precategories is always a mere property.
Let $A\cong B$ denote the type of isomorphisms of (pre)categories from $A$ to $B$.
\begin{lem}\label{ct:isoprecat}
For precategories $A$ and $B$ and $F:A\to B$, the following are equivalent.
\begin{enumerate}
\item $F$ is an isomorphism of precategories.\label{item:ct:ipc1}
\item There exist $G:B\to A$ and $\eta:1_A = GF$ and $\epsilon:FG=1_B$ such that\label{item:ct:ipc2}
\begin{equation}
\apfunc{(\lam{H} F H)}({\eta}) = \apfunc{(\lam{K} K F)}({\opp\epsilon}).\label{eq:ct:isoprecattri}
\end{equation}
\item There merely exist $G:B\to A$ and $\eta:1_A = GF$ and $\epsilon:FG=1_B$.\label{item:ct:ipc3}
\end{enumerate}
\end{lem}
Note that if $B_0$ is not a 1-type, then~\eqref{eq:ct:isoprecattri} may not be a mere proposition.
\begin{proof}
First note that since hom-sets are sets, equalities between equalities of functors are uniquely determined by their object-parts.
Thus, by function extensionality,~\eqref{eq:ct:isoprecattri} is equivalent to
\begin{equation}
\map{(F_0)}{\eta_0}_a = \opp{(\epsilon_0)}_{F_0 a}.\label{eq:ct:ipctri}
\end{equation}
for all $a:A_0$.
Note that this is precisely the triangle identity for $G_0$, $\eta_0$, and $\epsilon_0$ to be a proof that $F_0$ is a half adjoint equivalence of types.
Now suppose~\ref{item:ct:ipc1}.
Let $G_0:B_0 \to A_0$ be the inverse of $F_0$, with $\eta_0: \idfunc[A_0] = G_0 F_0$ and $\epsilon_0:F_0G_0 = \idfunc[B_0]$ satisfying the triangle identity, which is precisely~\eqref{eq:ct:ipctri}.
Now define $G_{b,b'}:\hom_B(b,b') \to \hom_A(G_0b,G_0b')$ by
\[ G_{b,b'}(g) \defeq
\inv{(F_{G_0b,G_0b'})}\Big(\idtoiso(\opp{(\epsilon_0)}_{b'}) \circ g \circ \idtoiso((\epsilon_0)_b)\Big)
\]
(using the assumption that $F$ is fully faithful).
Since \idtoiso takes inverses to inverses and concatenation to composition, and $F$ is a functor, it follows that $G$ is a functor.
By definition, we have $(GF)_0 \jdeq G_0 F_0$, which is equal to $\idfunc[A_0]$ by $\eta_0$.
To obtain $1_A = GF$, we need to show that when transported along $\eta_0$, the identity function of $\hom_A(a,a')$ becomes equal to the composite $G_{Fa,Fa'} \circ F_{a,a'}$.
In other words, for any $f:\hom_A(a,a')$ we must have
\begin{multline*}
\idtoiso((\eta_0)_{a'}) \circ f \circ \idtoiso(\opp{(\eta_0)}_a)\\
= \inv{(F_{GFa,GFa'})}\Big(\idtoiso(\opp{(\epsilon_0)}_{Fa'})
\circ F_{a,a'}(f) \circ \idtoiso((\epsilon_0)_{Fa})\Big).
\end{multline*}
But this is equivalent to
\begin{multline*}
(F_{GFa,GFa'})\Big(\idtoiso((\eta_0)_{a'}) \circ f \circ \idtoiso(\opp{(\eta_0)}_a)\Big)\\
= \idtoiso(\opp{(\epsilon_0)}_{Fa'})
\circ F_{a,a'}(f) \circ \idtoiso((\epsilon_0)_{Fa}).
\end{multline*}
which follows from functoriality of $F$, the fact that $F$ preserves \idtoiso, and~\eqref{eq:ct:ipctri}.
Thus we have $\eta:1_A = GF$.
On the other side, we have $(FG)_0\jdeq F_0 G_0$, which is equal to $\idfunc[B_0]$ by $\epsilon_0$.
To obtain $FG=1_B$, we need to show that when transported along $\epsilon_0$, the identity function of $\hom_B(b,b')$ becomes equal to the composite $F_{Gb,Gb'} \circ G_{b,b'}$.
That is, for any $g:\hom_B(b,b')$ we must have
\begin{multline*}
F_{Gb,Gb'}\Big(\inv{(F_{Gb,Gb'})}\Big(\idtoiso(\opp{(\epsilon_0)}_{b'}) \circ g \circ \idtoiso((\epsilon_0)_b)\Big)\Big)\\
= \idtoiso((\opp{\epsilon_0})_{b'}) \circ g \circ \idtoiso((\epsilon_0)_b).
\end{multline*}
But this is just the fact that $\inv{(F_{Gb,Gb'})}$ is the inverse of $F_{Gb,Gb'}$.
And we have remarked that~\eqref{eq:ct:isoprecattri} is equivalent to~\eqref{eq:ct:ipctri}, so~\ref{item:ct:ipc2} holds.
Conversely, suppose given~\ref{item:ct:ipc2}; then the object-parts of $G$, $\eta$, and $\epsilon$ together with~\eqref{eq:ct:ipctri} show that $F_0$ is an equivalence of types.
And for $a,a':A_0$, we define $\overline{G}_{a,a'}: \hom_B(Fa,Fa') \to \hom_A(a,a')$ by
\begin{equation}
\overline{G}_{a,a'}(g) \defeq \idtoiso(\opp{\eta})_{a'} \circ G(g) \circ \idtoiso(\eta)_a.\label{eq:ct:gbar}
\end{equation}
By naturality of $\idtoiso(\eta)$, for any $f:\hom_A(a,a')$ we have
\begin{align*}
\overline{G}_{a,a'}(F_{a,a'}(f))
&= \idtoiso(\opp{\eta})_{a'} \circ G(F(f)) \circ \idtoiso(\eta)_a\\
&= \idtoiso(\opp{\eta})_{a'} \circ \idtoiso(\eta)_{a'} \circ f \\
&= f.
\end{align*}
On the other hand, for $g:\hom_B(Fa,Fa')$ we have
\begin{align*}
F_{a,a'}(\overline{G}_{a,a'}(g))
&= F(\idtoiso(\opp{\eta})_{a'}) \circ F(G(g)) \circ F(\idtoiso(\eta)_a)\\
&= \idtoiso(\epsilon)_{Fa'}
\circ F(G(g))
\circ \idtoiso(\opp{\epsilon})_{Fa}\\
&= \idtoiso(\epsilon)_{Fa'}
\circ \idtoiso(\opp{\epsilon})_{Fa'}
\circ g\\
&= g.
\end{align*}
(There are lemmas needed here regarding the compatibility of \idtoiso and whiskering, which we leave it to the reader to state and prove.)
Thus, $F_{a,a'}$ is an equivalence, so $F$ is fully faithful; i.e.~\ref{item:ct:ipc1} holds.
Now the composite~\ref{item:ct:ipc1}$\to$\ref{item:ct:ipc2}$\to$\ref{item:ct:ipc1} is equal to the identity since~\ref{item:ct:ipc1} is a mere proposition.
On the other side, tracing through the above constructions we see that the composite~\ref{item:ct:ipc2}$\to$\ref{item:ct:ipc1}$\to$\ref{item:ct:ipc2} essentially preserves the object-parts $G_0$, $\eta_0$, $\epsilon_0$, and the object-part of~\eqref{eq:ct:isoprecattri}.
And in the latter three cases, the object-part is all there is, since hom-sets are sets.
Thus, it suffices to show that we recover the action of $G$ on hom-sets.
In other words, we must show that if $g:\hom_B(b,b')$, then
\[ G_{b,b'}(g) =
\overline{G}_{G_0b,G_0b'}\Big(\idtoiso(\opp{(\epsilon_0)}_{b'}) \circ g \circ \idtoiso((\epsilon_0)_b)\Big)
\]
where $\overline{G}$ is defined by~\eqref{eq:ct:gbar}.
However, this follows from functoriality of $G$ and the \emph{other} triangle identity, which we have seen in \cref{cha:equivalences} is equivalent to~\eqref{eq:ct:ipctri}.
Now since~\ref{item:ct:ipc1} is a mere proposition, so is~\ref{item:ct:ipc2}, so it suffices to show they are logically equivalent to~\ref{item:ct:ipc3}.
Of course,~\ref{item:ct:ipc2}$\to$\ref{item:ct:ipc3}, so let us assume~\ref{item:ct:ipc3}.
Since~\ref{item:ct:ipc1} is a mere proposition, we may assume given $G$, $\eta$, and $\epsilon$.
Then $G_0$ along with $\eta$ and $\epsilon$ imply that $F_0$ is an equivalence.
Moreover, we also have natural isomorphisms $\idtoiso(\eta):1_A\cong GF$ and $\idtoiso(\epsilon):FG\cong 1_B$, so by \cref{ct:adjointification}, $F$ is an equivalence of precategories, and in particular fully faithful.
\end{proof}
From \cref{ct:isoprecat}\ref{item:ct:ipc2} and $\idtoiso$ in functor categories, we conclude immediately that any isomorphism of precategories is an equivalence.
For precategories, the converse can fail.
\begin{eg}\label{ct:chaotic}
Let $X$ be a type and $x_0:X$ an element, and let $X_{\mathrm{ch}}$ denote the \emph{chaotic}\indexdef{chaotic precategory} or \emph{indiscrete}\indexdef{indiscrete precategory} precategory on $X$.
By definition, we have $(X_{\mathrm{ch}})_0\defeq X$, and $\hom_{X_{\mathrm{ch}}}(x,x') \defeq \unit$ for all $x,x'$.
Then the unique functor $X_{\mathrm{ch}}\to \unit$ is an equivalence of precategories, but not an isomorphism unless $X$ is contractible.
This example also shows that a precategory can be equivalent to a category without itself being a category.
Of course, if a precategory is \emph{isomorphic} to a category, then it must itself be a category.
\end{eg}
However, for categories, the two notions coincide.
\begin{lem}\label{ct:eqv-levelwise}
For categories $A$ and $B$, a functor $F:A\to B$ is an equivalence of categories if and only if it is an isomorphism of categories.
\end{lem}
\begin{proof}
Since both are mere properties, it suffices to show they are logically equivalent.
So first suppose $F$ is an equivalence of categories, with $(G,\eta,\epsilon)$ given.
We have already seen that $F$ is fully faithful.
By \cref{ct:functor-cat}, the natural isomorphisms $\eta$ and $\epsilon$ yield identities $\id{1_A}{GF}$ and $\id{FG}{1_B}$, hence in particular identities $\id{\idfunc[A]}{G_0\circ F_0}$ and $\id{F_0\circ G_0}{\idfunc[B]}$.
Thus, $F_0$ is an equivalence of types.
Conversely, suppose $F$ is fully faithful and $F_0$ is an equivalence of types, with inverse $G_0$, say.
Then for each $b:B$ we have $G_0 b:A$ and an identity $\id{FGb}{b}$, hence an isomorphism $FGb\cong b$.
Thus, by \cref{ct:ffeso}, $F$ is an equivalence of categories.
\end{proof}
Of course, there is yet a third notion of sameness for (pre)categories: equality.
However, the univalence axiom implies that it coincides with isomorphism.
\begin{lem}\label{ct:cat-eq-iso}
If $A$ and $B$ are precategories, then the function
\[(\id A B) \to (A\cong B)\]
(defined by induction from the identity functor) is an equivalence of types.
\end{lem}
\begin{proof}
As usual for dependent sum types, to give an element of $\id A B$ is equivalent to giving
\begin{itemize}
\item an identity $P_0:\id{A_0}{B_0}$,
\item for each $a,b:A_0$, an identity
\[P_{a,b}:\id{\hom_A(a,b)}{\hom_B(\trans {P_0} a,\trans {P_0} b)},\]
\item identities $\id{\trans {(P_{a,a})} {1_a}}{1_{\trans {P_0} a}}$ and
\narrowequation{\id{\trans {(P_{a,c})} {gf}}{\trans {(P_{b,c})} g \circ \trans {(P_{a,b})} f}.}
\end{itemize}
(Again, we use the fact that the identity types of hom-sets are mere propositions.)
However, by univalence, this is equivalent to giving
\begin{itemize}
\item an equivalence of types $F_0:\eqv{A_0}{B_0}$,
\item for each $a,b:A_0$, an equivalence of types
\[F_{a,b}:\eqv{\hom_A(a,b)}{\hom_B(F_0 (a),F_0 (b))},\]
\item and identities $\id{F_{a,a}(1_a)}{1_{F_0 (a)}}$ and $\id{F_{a,c}(gf)}{F_{b,c} (g)\circ F_{a,b} (f)}$.
\end{itemize}
But this consists exactly of a functor $F:A\to B$ that is an isomorphism of categories.
And by induction on identity, this equivalence $\eqv{(\id A B)}{(A\cong B)}$ is equal to the one obtained by induction.
\end{proof}
Thus, for categories, equality also coincides with equivalence.
We can interpret this as saying that categories, functors, and natural transformations form, not just a pre-2-category, but a 2-category (see \cref{ct:pre2cat}).
\begin{thm}\label{ct:cat-2cat}
If $A$ and $B$ are categories, then the function
\[(\id A B) \to (\cteqv A B)\]
(defined by induction from the identity functor) is an equivalence of types.
\end{thm}
\begin{proof}
By \cref{ct:cat-eq-iso,ct:eqv-levelwise}.
\end{proof}
As a consequence, the type of categories is a 2-type.
For since $\cteqv A B$ is a subtype of the type of functors from $A$ to $B$, which are the objects of a category, it is a 1-type; hence the identity types $\id A B$ are also 1-types.
\section{The Yoneda lemma}
\label{sec:yoneda}
\index{Yoneda!lemma|(}
Recall that we have a category \uset whose objects are sets and whose morphisms are functions.
We now show that every precategory has a \uset-valued hom-functor.
First we need to define opposites and products of (pre)categories.
\begin{defn}\label{ct:opposite-category}
For a precategory $A$, its \define{opposite}
\indexdef{opposite of a (pre)category}%
\indexdef{precategory!opposite}%
\indexdef{category!opposite}%
$A\op$ is a precategory with the same type of objects, with $\hom_{A\op}(a,b) \defeq \hom_A(b,a)$, and with identities and composition inherited from $A$.
\end{defn}
\begin{defn}\label{ct:prod-cat}
For precategories $A$ and $B$, their \define{product}
\index{precategory!product of}%
\index{category!product of}%
\index{product!of (pre)categories}%
$A\times B$ is a precategory with $(A\times B)_0 \defeq A_0 \times B_0$ and
\[\hom_{A\times B}((a,b),(a',b')) \defeq \hom_A(a,a') \times \hom_B(b,b').\]
Identities are defined by $1_{(a,b)}\defeq (1_a,1_b)$ and composition by
\narrowequation{(g,g')(f,f') \defeq ((gf),(g'f')).}
\end{defn}
\begin{lem}\label{ct:functorexpadj}
For precategories $A,B,C$, the following types are equivalent.
\begin{enumerate}
\item Functors $A\times B\to C$.
\item Functors $A\to C^B$.
\end{enumerate}
\end{lem}
\begin{proof}
Given $F:A\times B\to C$, for any $a:A$ we obviously have a functor $F_a : B\to C$.
This gives a function $A_0 \to (C^B)_0$.
Next, for any $f:\hom_A(a,a')$, we have for any $b:B$ the morphism $F_{(a,b),(a',b)}(f,1_b):F_a(b) \to F_{a'}(b)$.
These are the components of a natural transformation $F_a \to F_{a'}$.
Functoriality in $a$ is easy to check, so we have a functor $\hat{F}:A\to C^B$.
Conversely, suppose given $G:A\to C^B$.
Then for any $a:A$ and $b:B$ we have the object $G(a)(b):C$, giving a function $A_0 \times B_0 \to C_0$.
And for $f:\hom_A(a,a')$ and $g:\hom_B(b,b')$, we have the morphism
\begin{equation*}
G(a')_{b,b'}(g)\circ G_{a,a'}(f)_b = G_{a,a'}(f)_{b'} \circ G(a)_{b,b'}(g)
\end{equation*}
in $\hom_C(G(a)(b), G(a')(b'))$.
Functoriality is again easy to check, so we have a functor $\check{G}:A\times B \to C$.
Finally, it is also clear that these operations are inverses.
\end{proof}
Now for any precategory $A$, we have a hom-functor
\indexdef{hom-functor}%
\[\hom_A : A\op \times A \to \uset.\]
It takes a pair $(a,b): (A\op)_0 \times A_0 \jdeq A_0 \times A_0$ to the set $\hom_A(a,b)$.
For a morphism $(f,f') : \hom_{A\op\times A}((a,b),(a',b'))$, by definition we have $f:\hom_A(a',a)$ and $f':\hom_A(b,b')$, so we can define
\begin{align*}
(\hom_A)_{(a,b),(a',b')}(f,f')
&\defeq (g \mapsto (f'gf))\\
&: \hom_A(a,b) \to \hom_A(a',b').
\end{align*}
Functoriality is easy to check.
By \cref{ct:functorexpadj}, therefore, we have an induced functor $\y:A\to \uset^{A\op}$, which we call the \define{Yoneda embedding}.
\indexdef{Yoneda!embedding}%
\indexdef{embedding!Yoneda}%
\begin{thm}[The Yoneda lemma]\label{ct:yoneda}
\indexdef{Yoneda!lemma}
For any precategory $A$, any $a:A$, and any functor $F:\uset^{A\op}$, we have an isomorphism
\begin{equation}\label{eq:yoneda}
\hom_{\uset^{A\op}}(\y a, F) \cong Fa.
\end{equation}
Moreover, this is natural in both $a$ and $F$.
\end{thm}
\begin{proof}
Given a natural transformation $\alpha:\y a \to F$, we can consider the component $\alpha_a : \y a(a) \to F a$.
Since $\y a(a)\jdeq \hom_A(a,a)$, we have $1_a : \y a(a)$, so that $\alpha_a(1_a) : F a$.
This gives a function $(\alpha \mapsto \alpha_a(1_a))$ from left to right in~\eqref{eq:yoneda}.
In the other direction, given $x:F a$, we define $\alpha:\y a \to F$ by
\[\alpha_{a'}(f) \defeq F_{a',a}(f)(x). \]
Naturality is easy to check, so this gives a function from right to left in~\eqref{eq:yoneda}.
To show that these are inverses, first suppose given $x:F a$.
Then with $\alpha$ defined as above, we have $\alpha_a(1_a) = F_{a,a}(1_a)(x) = 1_{F a}(x) = x$.
On the other hand, if we suppose given $\alpha:\y a \to F$ and define $x$ as above, then for any $f:\hom_A(a',a)$ we have
\begin{align*}
\alpha_{a'}(f)
&= \alpha_{a'} (\y a_{a',a}(f))\\
&= (\alpha_{a'}\circ \y a_{a',a}(f))(1_a)\\
&= (F_{a',a}(f)\circ \alpha_a)(1_a)\\
&= F_{a',a}(f)(\alpha_a(1_a))\\
&= F_{a',a}(f)(x).
\end{align*}
Thus, both composites are equal to identities.
We leave the proof of naturality to the reader.
\end{proof}
\begin{cor}\label{ct:yoneda-embedding}
The Yoneda embedding $\y :A\to \uset^{A\op}$ is fully faithful.
\end{cor}
\begin{proof}
By \cref{ct:yoneda}, we have
\[ \hom_{\uset^{A\op}}(\y a, \y b) \cong \y b(a) \jdeq \hom_A(a,b). \]
It is easy to check that this isomorphism is in fact the action of \y on hom-sets.
\end{proof}
\begin{cor}\label{ct:yoneda-mono}
If $A$ is a category, then $\y_0 : A_0 \to (\uset^{A\op})_0$ is an embedding.
In particular, if $\y a = \y b$, then $a=b$.
\end{cor}
\begin{proof}
By \cref{ct:yoneda-embedding}, \y induces an isomorphism on sets of isomorphisms.
But as $A$ and $\uset^{A\op}$ are categories and \y is a functor, this is equivalently an isomorphism on identity types, which is the definition of being an embedding.
\end{proof}
\begin{defn}\label{ct:representable}
A functor $F:\uset^{A\op}$ is said to be \define{representable}
\indexdef{functor!representable}%
\indexdef{representable functor}%
if there exists $a:A$ and an isomorphism $\y a \cong F$.
\end{defn}
\begin{thm}\label{ct:representable-prop}
If $A$ is a category, then the type ``$F$ is representable'' is a mere proposition.
\end{thm}