-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexed-tt-ams.tex
2923 lines (2571 loc) · 174 KB
/
indexed-tt-ams.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
\documentclass[reqno]{amsart}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{mathtools}
\usepackage[all]{xy}
\usepackage{verbatim}
\usepackage{ifthen}
\usepackage{xargs}
\usepackage{bussproofs}
\usepackage{turnstile}
\usepackage{etex}
\hypersetup{colorlinks=true,linkcolor=blue}
\newcommand{\axlabel}[1]{(#1) \phantomsection \label{ax:#1}}
\newcommand{\axtag}[1]{\label{ax:#1} \tag{#1}}
\newcommand{\axref}[1]{(\hyperref[ax:#1]{#1})}
\newcommand{\newref}[4][]{
\ifthenelse{\equal{#1}{}}{\newtheorem{h#2}[hthm]{#4}}{\newtheorem{h#2}{#4}[#1]}
\expandafter\newcommand\csname r#2\endcsname[1]{#3~\ref{#2:##1}}
\expandafter\newcommand\csname R#2\endcsname[1]{#4~\ref{#2:##1}}
\expandafter\newcommand\csname n#2\endcsname[1]{\ref{#2:##1}}
\newenvironmentx{#2}[2][1=,2=]{
\ifthenelse{\equal{##2}{}}{\begin{h#2}}{\begin{h#2}[##2]}
\ifthenelse{\equal{##1}{}}{}{\label{#2:##1}}
}{\end{h#2}}
}
\newref[section]{thm}{Theorem}{Theorem}
\newref{lem}{Lemma}{Lemma}
\newref{prop}{Proposition}{Proposition}
\newref{cor}{Corollary}{Corollary}
\newref{cond}{Condition}{Condition}
\theoremstyle{definition}
\newref{defn}{Definition}{Definition}
\newref{example}{Example}{Example}
\theoremstyle{remark}
\newref{remark}{Remark}{Remark}
\newcommand{\type}{}
\newcommand{\ob}{}
\newcommand{\term}{1}
\newcommand{\unit}{()}
\newcommand{\fs}[1]{\mathrm{#1}}
\newcommand{\subst}{\fs{subst}}
\newcommand{\Hom}{\fs{Hom}}
\newcommand{\Id}{\fs{Id}}
\newcommand{\refl}{\fs{refl}}
\newcommand{\sym}[1]{#1^{-1}}
\newcommand{\id}{\fs{id}}
\newcommand{\pmap}{\fs{ap}}
\newcommand{\Fib}{\fs{Fib}}
\newcommand{\fib}{\ \fs{fib}}
\newcommand{\El}{\fs{El}}
\numberwithin{figure}{section}
\newcommand{\ct}{%
\mathchoice{\mathbin{\raisebox{0.25ex}{$\displaystyle\centerdot$}}}%
{\mathbin{\raisebox{0.25ex}{$\centerdot$}}}%
{\mathbin{\raisebox{0.25ex}{$\scriptstyle\,\centerdot\,$}}}%
{\mathbin{\raisebox{0.25ex}{$\scriptscriptstyle\,\centerdot\,$}}}
}
\newcommand{\pb}[1][dr]{\save*!/#1-1.2pc/#1:(-1,1)@^{|-}\restore}
\newcommand{\po}[1][dr]{\save*!/#1+1.2pc/#1:(1,-1)@^{|-}\restore}
\begin{document}
\title{Indexed type theories}
\author{Valery Isaev}
\begin{abstract}
In this paper, we define indexed type theories which are related to indexed ($\infty$-)categories in the same way as (homotopy) type theories are related to ($\infty$-)categories.
We define several standard constructions for such theories including finite (co)limits, arbitrary (co)products, exponents, object classifiers, and orthogonal factorization systems.
We also prove that these constructions are equivalent to their type theoretic counterparts such as $\Sigma$-types, unit types, identity types, finite higher inductive types, $\Pi$-types, univalent universes, and higher modalities.
\end{abstract}
\maketitle
\section{Introduction}
Indexed categories were defined in \cite{indexed-cats} (see also \cite[B1]{elephant}).
We define an analogue of this notion using the language of type theory.
Ordinary homotopy type theory is an internal language of $\infty$-categories with some additional structure depending on constructions that we assume in the theory.
Often we need to assume that the $\infty$-category is at least locally Cartesian closed.
Indexed type theories allows us to discuss properties of arbitrary (indexed) $\infty$-categories.
Indexed type theories can be useful even when applied to $\infty$-categories which have all the required structure such as $\infty$-toposes.
One problem of ordinary homotopy type theory is that every construction must be stable under pullbacks.
For example, we will define orthogonal factorization systems in section~\ref{sec:refl-fib}.
In ordinary homotopy type theory only the stable factorization systems can be defined (which was done in \cite{modality-hott}).
Similar problem occurs when we try to describe certain universes.
For example, we could try to add a universe $\mathcal{U}_\mathrm{cov}$ of discrete Segal types and covariant maps between them to the theory described in \cite{riehl-dhott}.
A naive definition of such a universe postulates that we have an equivalence between the type of functions $X \to \mathcal{U}_\mathrm{cov}$ and the type of covariant fibrations over $X$.
This is not a correct definition since this condition is too strong.
The correct definition requires only an equivalence between the space of maps from $X$ to $\mathcal{U}_\mathrm{cov}$ and the space of covariant fibrations over $X$.
It is impossible to formulate this condition in ordinary homotopy type theory, but it is easy to do in an indexed type theory as we will see in section~\ref{sec:class}.
We will define two kinds of indexed type theories: unary and dependent.
Indexed unary type theories allow us to discuss properties of arbitrary categories.
Such a theory has two levels: the base theory and the indexed theory.
The base theory has the usual type-theoretic syntax and the language of the indexed theory can be described informally as the language of type-enriched categories.
Indexed dependent type theories also have two levels.
The first one is the same as for unary theories, but the second has type-theoretic syntax, so it is more convenient to use such theories, but it applies only to finitely complete theories.
We will define several categorical constructions in both styles and prove that they are equivalent:
\begin{enumerate}
\item Finite limits in unary theories and $\Sigma$-types, unit types, and identity types in dependent theories.
\item Finite colimits in unary theories and finite higher inductive types in dependent theories.
\item Exponents in unary theories and $\Pi$-types in dependent theories.
\item Object classifiers in unary theories and univalent universes in dependent theories.
\item Orthogonal factorization systems in unary theories and higher modalities in dependent theories.
\end{enumerate}
The paper is organized as follows.
In section~\ref{sec:unary}, we define indexed unary type theories.
In section~\ref{sec:equivalence}, we define the notion of an equivalence in unary theories.
In section~\ref{sec:colimits}, we define limits and colimits in unary theories.
In section~\ref{sec:dependent}, we define indexed dependent type theories.
In section~\ref{sec:lccc}, we define exponent and $\Pi$-types in indexed theories.
In section~\ref{sec:colimits-dep}, we define limits and colimits in dependent theories.
In section~\ref{sec:initial}, we prove the initial type theorem, which is the first step in the proof of the general adjoint functor theorem.
In section~\ref{sec:class}, we defined object classifiers.
In section~\ref{sec:refl-fib}, we define orthogonal factorization systems.
\section{Indexed unary type theories}
\label{sec:unary}
We can think about an indexed type theory as a syntactic representation of indexed $\infty$-categories, that is a functor $F$ from an $\infty$-category $\mathcal{B}$ to the large $\infty$-category of $\infty$-categories.
An indexed type theory consists of two levels.
The first level is just an ordinary type theory and it represents $\mathcal{B}$.
Since we are mostly interested in the case when $\mathcal{B}$ is the $\infty$-category of spaces,
we can assume that the first level has all usual constructions such as identity types, $\Sigma$-types, $\Pi$-types, (univalent) universes, and (higher) inductive types.
Nevertheless, in general, we will assume that the base theory has only identity types and $\Sigma$-types; all additional assumptions will be explicitly specified.
We will often talk about functions, but this is only for notational convenience and does not assume that function types exist.
Terms of type $A \to B$ correspond to terms of type $B$ in context $x : A$, so we can talk about functions $A \to B$ as long as this type does not appear inside other types.
The second level of the theory represents $\infty$-categories $F(\Gamma)$ for various objects $\Gamma$ of $\mathcal{B}$.
In this section, we will discuss \emph{indexed unary type theories}, that is indexed type theories in which the second level consists of unary type theories.
A unary type theory is a non-dependent type theory in which contexts consist of exactly one type.
Such theories represent arbitrary 1-categories.
We do not know whether indexed unary type theories represent all indexed $\infty$-categories over a given base, but it seems that this should be true at least for locally small indexed $\infty$-categories.
Indexed unary type theories have four kinds of judgments:
\[ \Gamma \vdash A \type \qquad \Gamma \vdash a : A \qquad \Gamma \mid \cdot \vdash B \ob \qquad \Gamma \mid x : A \vdash b : B \]
In each of these judgments, $\Gamma$ is a context, that is a sequence of the form $x_1 : A_1, \ldots x_n : A_n$, where $A_1$, \ldots $A_n$ are types and $x_1$, \ldots $x_n$ are pairwise distinct variables.
Judgments $\Gamma \vdash A \type$ and $\Gamma \vdash a : A$ represent types and terms of the first level of the theory.
We will call such types and terms \emph{base types} and \emph{base terms}, respectively.
The collection of rules that involve only judgments for base types and base terms will be called the base (sub)theory.
When we say that the base theory has some construction such as $\Pi$-types or universes, this means that there are usual rules for these constructions formulated in terms of these judgments.
Judgments $\Gamma \mid \cdot \vdash A \ob$ represent types of the second level of the theory.
We will call these types \emph{indexed types} to distinguish them from base types.
In a judgment $\Gamma \mid x : A \vdash b : B$, $x$ is a variable which is distinct from the variables in $\Gamma$, $A$ and $B$ are indexed types, and $b$ is a term of the second level of the theory.
We will call such terms \emph{indexed terms}.
Indexed types represent objects indexed by $\Gamma$ and indexed an indexed term $\Gamma \mid x : A \vdash b : B$ represents a morphism between $A$ and $B$.
We have the usual rules for variables and substitutions for the base theory:
\begin{center}
\AxiomC{}
\UnaryInfC{$x_1 : A_1, \ldots x_n : A_n \vdash x_i : A_i$}
\DisplayProof
\end{center}
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \vdash b_1 : B_1$
\noLine
\UnaryInf$\fCenter \ldots$
\noLine
\UnaryInf$\fCenter \Gamma \vdash b_k : B_k[b_1/y_1, \ldots b_{k-1}/y_{k-1}]$
\Axiom$\fCenter \Gamma, y_1 : B_1, \ldots y_k : B_k \vdash C \type$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma \vdash C[b_1/y_1, \ldots b_k/y_k] \type$}
\DisplayProof
\end{center}
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \vdash b_1 : B_1$
\noLine
\UnaryInf$\fCenter \ldots$
\noLine
\UnaryInf$\fCenter \Gamma \vdash b_k : B_k[b_1/y_1, \ldots b_{k-1}/y_{k-1}]$
\Axiom$\fCenter \Gamma, y_1 : B_1, \ldots y_k : B_k \vdash c : C$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma \vdash c[b_1/y_1, \ldots b_k/y_k] : C[b_1/y_1, \ldots b_k/y_k]$}
\DisplayProof
\end{center}
We also have the usual equations for substitution:
\begin{align*}
y_i[b_1/y_1, \ldots b_k/y_k] & = b_i \\
c[y_1/y_1, \ldots y_k/y_k] & = c \\
d[c_1/z_1, \ldots c_n/z_n][b_1/y_1, \ldots b_k/y_k] & = d[c_1'/z_1, \ldots c_n'/z_n],
\end{align*}
where $c_i' = c_i[b_1/y_1, \ldots b_k/y_k]$.
For every construction $\sigma(\overline{z_1}.\,c_1, \ldots \overline{z_n}.\,c_n)$ in the base theory, we have the following equation whenever variables $\overline{z_1}$, \ldots $\overline{z_n}$ are not free in $b_1$, \ldots $b_k$:
\[ \sigma(\ldots, \overline{z_i}.\,c_i, \ldots)[b_1/y_1, \ldots b_k/y_k] = \sigma(\ldots, \overline{z_i}.\,c_i[b_1/y_1, \ldots b_k/y_k], \ldots) \]
We also have the weakening operation which is left implicit as usual.
This concludes the description of basic rules of the base theory.
They are the usual rules of a dependent type theory which we include here so that they can be compared to the rules of the indexed theory.
Variables of the indexed theory represent identity morphisms and substitution represents composition:
\begin{center}
\AxiomC{}
\UnaryInfC{$\Gamma \mid x : A \vdash x : A$}
\DisplayProof
\qquad
\AxiomC{$\Gamma \mid \Delta \vdash b : B$}
\AxiomC{$\Gamma \mid y : B \vdash c : C$}
\BinaryInfC{$\Gamma \mid \Delta \vdash c[b/y] : C$}
\DisplayProof
\end{center}
These operations satisfy the obvious equations:
\begin{align*}
y[b/y] & = b \\
b[x/x] & = b \\
d[c/z][b/y] & = d[c[b/y]/z]
\end{align*}
We can also substitute base terms into indexed types and terms:
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \vdash b_1 : B_1$
\noLine
\UnaryInf$\fCenter \ldots$
\noLine
\UnaryInf$\fCenter \Gamma \vdash b_k : B_k[b_1/y_1, \ldots b_{k-1}/y_{k-1}]$
\Axiom$\fCenter \Gamma, y_1 : B_1, \ldots y_k : B_k \mid \cdot \vdash C \ob$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma \mid \cdot \vdash C[b_1/y_1, \ldots b_k/y_k] \ob$}
\DisplayProof
\end{center}
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \vdash b_1 : B_1$
\noLine
\UnaryInf$\fCenter \ldots$
\noLine
\UnaryInf$\fCenter \Gamma \vdash b_k : B_k[b_1/y_1, \ldots b_{k-1}/y_{k-1}]$
\Axiom$\fCenter \Gamma, y_1 : B_1, \ldots y_k : B_k \mid z : C \vdash d : D$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma \mid z : C[b_1/y_1, \ldots b_k/y_k] \vdash d[b_1/y_1, \ldots b_k/y_k] : D[b_1/y_1, \ldots b_k/y_k]$}
\DisplayProof
\end{center}
These operations represent reindexing along a morphism in the base category.
They satisfy the following equations:
\begin{align*}
x[b_1/y_1, \ldots b_k/y_k] & = x \\
d[c/z][b_1/y_1, \ldots b_k/y_k] & = d[b_1/y_1, \ldots b_k/y_k][c[b_1/y_1, \ldots b_k/y_k]/z] \\
c[y_1/y_1, \ldots y_k/y_k] & = c \\
d[c_1/z_1, \ldots c_n/z_n][b_1/y_1, \ldots b_k/y_k] & = d[c_1'/z_1, \ldots c_n'/z_n],
\end{align*}
where $c_i' = c_i[b_1/y_1, \ldots b_k/y_k]$.
The first two equations correspond to the fact that reindexing preserves identity morphisms and composition in the indexed theory.
The last two equations correspond to the fact that reindexing is functorial, that is it preserves identity morphisms and composition in the base theory.
For every construction $\sigma(\overline{z_1}.\,c_1, \ldots \overline{z_n}.\,c_k)$ in the indexed theory, we have the following equation whenever variables $\overline{z_1}$, \ldots $\overline{z_n}$ are not free in $b_1$, \ldots $b_k$:
\[ \sigma(\ldots, \overline{z_i}.\,c_i, \ldots)[b_1/y_1, \ldots b_k/y_k] = \sigma(\ldots, \overline{z_i}.\,c_i[b_1/y_1, \ldots b_k/y_k], \ldots) \]
We also have the weakening operation which is left implicit as usual.
This equation corresponds to the fact that all constructions in the indexed category must be stable under reindexing.
As we noted before, we assume that the base theory has identity types:
\begin{center}
\AxiomC{$\Gamma \vdash a : A$}
\AxiomC{$\Gamma \vdash a' : A$}
\BinaryInfC{$\Gamma \vdash \Id_A(a,a') \type$}
\DisplayProof
\qquad
\AxiomC{$\Gamma \vdash a : A$}
\UnaryInfC{$\Gamma \vdash \refl(a) : \Id_A(a,a)$}
\DisplayProof
\end{center}
\medskip
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \vdash a : A$
\noLine
\UnaryInf$\fCenter \Gamma \vdash a' : A$
\noLine
\UnaryInf$\fCenter \Gamma \vdash t : \Id_A(a,a')$
\Axiom$\fCenter \Gamma, x : A, p : \Id_A(a,x), \Delta \vdash D \type$
\noLine
\UnaryInf$\fCenter \Gamma, \Delta[a/x,\refl(a)/p] \vdash d : D[a/x,\refl(a)/p]$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma, \Delta[a'/x,t/p] \vdash J(a, x p \Delta.\,D, \Delta.\,d, a', t) : D[a'/x,t/p]$}
\DisplayProof
\end{center}
\[ J(a, x p \Delta.\,D, \Delta.\,d, a, \refl(a)) = d \]
We will sometimes omit the type in the notation $\Id_A(a,a')$.
The fact that the type $\Id(a,a')$ is inhabited will be denoted by $a \sim a'$.
If $\Gamma \vdash p : \Id_A(a,a')$, $\Gamma, x : A \vdash B \type$, and $\Gamma \vdash b : B[a/x]$, then we will write $\Gamma \vdash p_*(b) : B[a'/x]$ for the usual transport operation defined in terms of $J$.
Operation $\pmap$ is defined in terms of $J$ and has the following type:
if $\Gamma \vdash B \type$, $\Gamma, x : A \vdash b : B$, and $\Gamma \vdash p : \Id_A(a,a')$, then $\Gamma \vdash \pmap(x.b, p) : \Id_B(b[a/x],b[a'/x])$.
An indexed type theory is \emph{locally small} if there is a type of its morphisms.
That is, it must contain the following rules and equations:
\begin{center}
\AxiomC{$\Gamma \mid \cdot \vdash A \ob$}
\AxiomC{$\Gamma \mid \cdot \vdash B \ob$}
\BinaryInfC{$\Gamma \vdash \Hom(A,B) \type$}
\DisplayProof
\qquad
\AxiomC{$\Gamma \mid x : A \vdash b : B$}
\UnaryInfC{$\Gamma \vdash \lambda x.\,b : \Hom(A,B)$}
\DisplayProof
\end{center}
\medskip
\begin{center}
\AxiomC{$\Gamma \vdash f : \Hom(A,B)$}
\AxiomC{$\Gamma \mid \Delta \vdash a : A$}
\BinaryInfC{$\Gamma \mid \Delta \vdash f\,a : B$}
\DisplayProof
\end{center}
\begin{align*}
(\lambda x.\,b)\,a & = b[a/x] \\
\lambda x.\,f\,x & = f
\end{align*}
We might also use notation $A \to B$ for $\Hom(A,B)$, but we prefer the latter notation since the former may be confusing.
Indeed, $A \to B$ might also denote the indexed type of functions if the indexed theory is Cartesian closed or the base type of function if $A$ and $B$ are base types.
If the indexed theory is locally small, then indexed types must carry the structure of an $\infty$-category.
We cannot construct this structure internally due to coherence issues, but we can at least construct lower levels of this structure.
Morphisms between indexed types $A$ and $B$ are terms of type $\Hom(A,B)$.
The identity morphism $\id_A$ on an indexed type $A$ is $\lambda x.\,x : \Hom(A,A)$.
Composition of morphisms $f : \Hom(A,B)$ and $g : \Hom(B,C)$ is defined as $\lambda x.\,g\,(f\,x) : \Hom(A,C)$ and denoted by $g \circ f$.
Composition is strictly associative and identity morphisms are strictly unital.
If $f,g : \Hom(A,B)$ are morphisms, then a 2-morphism between them is a term $p : \Id_{\Hom(A,B)}(f,g)$.
Vertical composition $p \ct q$ of 2-morphisms $p$ and $q$ is defined as the usual operation of path concatenation.
The identity 2-morphism on $f : \Hom(A,B)$ is $\refl(f)$.
Vertical composition is associative, identity 2-morphisms are unital, and every 2-morphism is invertible.
These facts are true in a weak sense, that is up to a 3-morphism.
Let $f,g : \Hom(A,B)$ and $h,i : \Hom(B,C)$ be morphisms and let $p : \Id_{\Hom(A,B)}(f,g)$ and $q : \Id_{\Hom(B,C)}(h,i)$ be 2-morphisms.
The horizontal composition of $p$ and $q$ is a term $p * q$ of type $\Id_{\Hom(A,C)}(\lambda x.\,h\,(f\,x), \lambda x.\,i\,(g\,x))$.
To define $p * q$, we just need to eliminate $p$ and $q$ and then define $\refl(f) * \refl(h)$ as $\refl(\lambda x.\,h\,(f\,x))$.
It is easy to prove that usual properties of this operation hold.
Expressions $\refl(f) * q$, $p * \refl(g)$, and $\refl(f) * \refl(g)$ will be denoted by $f * q$, $p * g$, and $f * g$, respectively.
\begin{defn}
An equivalence between indexed types $A$ and $B$ is a morphism $f : \Hom(A,B)$ such that there is a morphism $g : \Hom(B,A)$ such that $g \circ f \sim \id_A$ and $f \circ g \sim \id_B$.
\end{defn}
If the indexed theory is locally small, then not only base morphisms act on indexed types and terms, but also homotopies between them.
Let $\Gamma \vdash a : A$ and $\Gamma \vdash a' : A$ be two base terms.
If $\Gamma, x : A \mid \cdot \vdash B \ob$ be an indexed type, then we have indexed types $\Gamma \mid \cdot \vdash B[a/x] \ob$ and $\Gamma \mid \cdot \vdash B[a'/x] \ob$.
Let $\Gamma \vdash h : \Id_A(a,a')$ be homotopy between $a$ and $a'$.
Then we can construct an equivalence between $B[a/x]$ and $B[a'/x]$.
A map $f : \Hom(B[a/x],B[a'/x])$ is defined as $J(a, x p.\,\Hom(B[a/x],B), \id_{B[a/x]}, a', h)$.
A map $g : \Hom(B[a'/x],B[a/x])$ is constructed similarly: $J(a, x p.\,\Hom(B,B[a/x]), \id_{B[a/x]}, a', h)$.
To prove that $g \circ f$ and $f \circ g$ are homotopic to identity morphisms, it is enough to eliminate $h$ using $J$ and then both $g \circ f$ and $f \circ g$ become identity morphisms.
\section{Equivalences}
\label{sec:equivalence}
In this section, we define types that express the property of a map $f : \Hom(A,B)$ of being an equivalence and prove that they are equivalent.
We also prove a few simple properties of equivalences.
These questions were studied in \cite[Section~4]{hottbook} for ordinary homotopy type theory.
Most of the theorems in this section also hold in the framework of indexed unary type theories, but the proofs must be modified.
\subsection{Bi-invertible maps}
Let $f : \Hom(A,B)$ be a morphism.
We will say that $f$ is \emph{bi-invertible} if the following type is inhabited:
\[ \fs{biinv}(f) = \fs{linv}(f) \times \fs{rinv}(f), \]
where $\fs{linv}(f)$ and $\fs{rinv}(f)$ are types of left and right inverses of $f$, respectively:
\begin{align*}
\fs{linv}(f) & = \sum_{g : \Hom(B,A)} \Id(g \circ f, \id_A) \\
\fs{rinv}(f) & = \sum_{g : \Hom(B,A)} \Id(f \circ g, \id_B)
\end{align*}
\begin{prop}[biinv-equiv]
A map is bi-invertible if and only if it is an equivalence.
\end{prop}
\begin{proof}
Obviously, if a map is an equivalence, then it is bi-invertible.
Let us prove the converse.
Let $g : \Hom(B,A)$, $p : \Id(g \circ f, \id_A)$ be a left inverse of $f$ and let $g' : \Hom(B,A)$, $p' : \Id(f \circ g', \id_B)$ be a right inverse of $f$.
Then $g' * p : \Id(g \circ f \circ g', g')$.
Since $f \circ g' \sim \id_B$, there is a term of type $\Id(g,g')$.
It follows that $g$ is an inverse of $f$.
\end{proof}
\begin{lem}[lrinv-contr]
If $f$ is an equivalence, then types $\fs{linv}(f)$ and $\fs{rinv}(f)$ are contractible.
\end{lem}
\begin{proof}
If $f$ is an equivalence, then precomposition with $f$ is an equivalence between types $\Hom(B,C)$ and $\Hom(A,C)$.
Similarly, postcomposition with $f$ is an equivalence between types $\Hom(C,A)$ and $\Hom(C,B)$.
Since $\fs{linv}(f)$ and $\fs{rinv}(f)$ are fibres of these maps over the identity morphisms, \cite[Theorem~4.2.3]{hottbook} and \cite[Theorem~4.2.6]{hottbook} imply that these types are contractible.
Note that the proofs of these theorems work even if we do not have $\Pi$-types.
\end{proof}
\begin{prop}
The type $\fs{biinv}(f)$ is a proposition.
\end{prop}
\begin{proof}
This follows from \rprop{biinv-equiv} and \rlem{lrinv-contr}.
\end{proof}
\subsection{Half adjoint equivalences}
Let $f : \Hom(A,B)$ be a morphism.
We will say that $f$ is a \emph{half adjoint equivalence} if the following type is inhabited:
\[ \fs{ishae}(f) = \sum_{g : \Hom(B,A)} \sum_{\eta : \Id(g \circ f, \id_A)} \sum_{\epsilon : \Id(f \circ g, \id_B)} \Id(\eta * f, f * \epsilon). \]
\begin{prop}
A map is a half adjoint equivalence if and only if it is an equivalence.
\end{prop}
\begin{proof}
Obviously, if a map is a half adjoint equivalence, then it is an equivalence.
Let us prove the converse.
Let $g : \Hom(B,A)$, $\eta : \Id(g \circ f, \id_A)$, $\epsilon : \Id(f \circ g, \id_B)$ be an inverse of $f$.
Then we define $\epsilon' : \Id(f \circ g, \id_B)$ as concatenation of paths
$g * f * \sym{\epsilon} : \Id(f \circ g, f \circ g \circ f \circ g)$, $g * \eta * f : \Id(f \circ g \circ f \circ g, f \circ g)$, and $\epsilon : \Id(f \circ g, \id_B)$.
We need to prove that $f * \epsilon' \sim \eta * f$.
First, note that $\eta * f * g \sim f * g * \eta$.
Indeed, $(\eta * f * g) \ct \eta \sim \eta * \eta \sim (f * g * \eta) \ct \eta$.
Thus, if we cancel $\eta$, this gives us a homotopy between the original paths.
Now, we can finish the proof:
\begin{align*}
f * \epsilon' & \sim \\
(f * g * f * \sym{\epsilon}) \ct (f * g * \eta * f) \ct (f * \epsilon) & \sim \\
(f * g * f * \sym{\epsilon}) \ct (\eta * f * g * f) \ct (f * \epsilon) & \sim \\
(\eta * f * \sym{\epsilon}) \ct (f * \epsilon) & \sim \\
(\eta * f) \ct (f * \sym{\epsilon}) \ct (f * \epsilon) & \sim \\
\eta * f & .
\end{align*}
\end{proof}
\begin{prop}
The type $\fs{ishae}(f)$ is a proposition.
\end{prop}
\begin{proof}
We can assume that $f$ is an equivalence and prove that $\fs{ishae}(f)$ is contractible.
By \rlem{lrinv-contr}, the type $\Sigma_{g : \Hom(B,A)} \Id(g \circ f, \id_A)$ is contractible.
Thus, we just need to prove that, for every $g : \Hom(B,A)$ and $\eta : \Id(g \circ f, \id_A)$, the type $\Sigma_{\epsilon : \Id(f \circ g, \id_B)} \Id(\eta * f, f * \epsilon)$ is also contractible.
Since $f$ is an equivalence, the function $f * -$ is also an equivalence.
It follows that the type $\Id(\eta * f, f * \epsilon)$ is equivalent to the type $\Id(h(\eta * f), \epsilon)$, where $h$ is the inverse of $f * -$.
Thus, the type $\Sigma_{\epsilon : \Id(f \circ g, \id_B)} \Id(\eta * f, f * \epsilon)$ is equivalent to the type $\Sigma_{\epsilon : \Id(f \circ g, \id_B)} \Id(h(\eta * f), \epsilon)$, which is contractible by \cite[Lemma~3.11.8]{hottbook}.
\end{proof}
\subsection{Properties of equivalences}
\begin{prop}
Equivalences satisfy the 2-out-of-6 property.
That is, if $f : \Hom(A,B)$, $g : \Hom(B,C)$, and $h : \Hom(C,D)$ are maps such that $g \circ f$ and $h \circ g$ are equivalences, then so are the maps $f$, $g$, $h$, and $h \circ g \circ f$.
\end{prop}
\begin{proof}
Let $i : \Hom(C,A)$ be an inverse of $g \circ f$ and let $k : \Hom(D,B)$ be an inverse of $h \circ g$.
Since $g \circ f \circ i \sim \id_C$ and $h \circ g \circ k \sim \id_D$, \rprop{biinv-equiv} implies that $g$ is an equivalence.
The map $i \circ g$ is an inverse of $f$.
Indeed, $i \circ g \circ f \sim \id_A$ since $i$ is an inverse of $g \circ f$.
Since $g \circ f \circ i \sim \id_C$, it follows that $g \circ f \circ i \circ g \sim g$.
Since $g$ is an equivalence, this implies that $f \circ i \circ g \sim \id_B$.
Similarly, $g \circ k$ is an inverse of $h$.
The map $h \circ g \circ f$ is an equivalence since equivalences are closed under composition.
\end{proof}
A map $f : \Hom(A,B)$ is a \emph{quasi-retract} of a map $g : \Hom(C,D)$ if there is a commutative diagram of the form
\[ \xymatrix{ A \ar[r]^i \ar[d]_f & C \ar[r]^j \ar[d]_g & A \ar[d]_f \\
B \ar[r]_k & D \ar[r]_m & B
} \]
such that $j \circ i \sim \id_A$ and $m \circ k \sim \id_B$.
\begin{prop}
Equivalences are closed under quasi-retracts.
\end{prop}
\begin{proof}
Let $f : \Hom(A,B)$ be a retract of $g : \Hom(C,D)$ and let $i,j,k,m$ be maps as in the diagram above.
Let $h : \Hom(D,C)$ be an inverse of $g$.
Then $j \circ h \circ k$ is an inverse of $f$.
Indeed, $j \circ h \circ k \circ f \sim j \circ h \circ g \circ i \sim j \circ \id_C \circ i = j \circ i \sim \id_B$ and
$f \circ j \circ h \circ k \sim m \circ g \circ h \circ k \sim m \circ \id_D \circ k = m \circ k \sim \id_B$.
\end{proof}
\section{Limits and colimits}
\label{sec:colimits}
In this section, we will work in a locally small indexed unary type theory.
We will define specific finite (co)limits and arbitrary (co)products.
\subsection{Finite (co)limits}
An indexed type $T$ is \emph{terminal} if, for every indexed type $X$, the type $\Hom(X,T)$ is contractible.
Dually, an indexed type $T$ is \emph{initial} if, for every indexed type $X$, the type $\Hom(T,X)$ is contractible.
Terminal and initial types are unique up to unique equivalence, that is the type of equivalences between a pair of terminal or initial types is contractible.
We will say that an indexed unary type theory \emph{has terminal (resp., initial) types} if, for every context $\Gamma$, there is a terminal (resp., initial) type $\Gamma \mid \cdot \vdash T \ob$.
A \emph{binary product} of indexed types $A$ and $B$ is an indexed type $A \times B$ together with a pair of maps $\pi_1 : \Hom(A \times B, A)$ and $\pi_2 : \Hom(A \times B, B)$
such that the following function is an equivalence for every indexed type $C$:
\[ \lambda h.\,(\pi_1 \circ h, \pi_2 \circ h) : \Hom(C, A \times B) \to \Hom(C,A) \times \Hom(C,B). \]
The inverse of this function will be denoted by $\langle -, - \rangle$.
An indexed unary type theory \emph{has binary products} if a binary product exists for every pair of types in every context.
\emph{Binary coproducts} $A \amalg B$ are defined dually.
An \emph{equalizer} of a pair of maps $f,g : \Hom(A,B)$ is a map $e : \Hom(E,A)$ together with a homotopy $p : \Id(f \circ e, g \circ e)$
such that the following function is an equivalence for every indexed type $E'$:
\[ \lambda h.\,(e \circ h, h * p) : \Hom(E', E) \to \sum_{e' : \Hom(E',A)} \Id(f \circ e', g \circ e'). \]
An indexed unary type theory \emph{has equalizers} if an equalizer exists for every parallel pair of maps in every context.
\emph{Coequalizers} are defined dually.
A \emph{pullback} of a pair of maps $f : \Hom(A,C)$ and $g : \Hom(B,C)$ is a triple $\pi_1 : \Hom(A \times_C B, A)$, $\pi_2 : \Hom(A \times_C B, B)$, $\pi_3 : \Id(f \circ \pi_1, g \circ \pi_2)$
such that the following function is an equivalence for every indexed type $P'$:
\[ \lambda h.\,(\pi_1 \circ h, \pi_2 \circ h, h * \pi_3) : \Hom(P, A \times_C B) \to \Hom(P,A) \times_{\Hom(P,C)} \Hom(P,B), \]
where the pullback of types $\Hom(P,A) \times_{\Hom(P,C)} \Hom(P,B)$ is defined as usual:
\[ \sum_{\pi_1' : \Hom(P,A)} \sum_{\pi_2' : \Hom(P,B)} \Id(f \circ \pi_1', g \circ \pi_2'). \]
An indexed unary type theory \emph{has pullbacks} if a pullback exists for every pair of maps with a common codomain in every context.
\emph{Pushouts} $A \amalg_C B$ are defined dually.
\begin{remark}
Binary (co)products, (co)equalizers, pullbacks, and pushouts are unique up to unique equivalence.
\end{remark}
\begin{remark}
The function $\Hom(C,-)$ preserves binary products, equalizers, and pullbacks.
\end{remark}
We have the following standard proposition:
\begin{prop}[fin-lim]
An indexed unary type theory with terminal types has pullbacks if and only if it has equalizers and binary products.
\end{prop}
\begin{proof}
First, suppose that the theory has a terminal type $1$ and pullbacks.
Then we can define a product of types $A$ and $B$ as the pullback of unique maps $!_A : \Hom(A,1)$ and $!_B : \Hom(B,1)$.
Since $\Hom(P,1)$ is contractible, the obvious projection $\Hom(P,A) \times_{\Hom(P,1)} \Hom(P,B) \to \Hom(P,A) \times \Hom(P,B)$ is an equivalence.
This implies that $A \times_1 B$ is a product of $A$ and $B$.
An equalizer of maps $f,g : \Hom(A,B)$ can be defined as the pullback of $\langle \id_B, \id_B \rangle : \Hom(B, B \times B)$ along $\langle f, g \rangle : \Hom(A, B \times B)$:
\[ \xymatrix{ E \ar[r]^s \ar[d]_e & B \ar[d]^{\langle \id_B, \id_B \rangle} \\
A \ar[r]_-{\langle f, g \rangle} & B \times B
} \]
By the definition of products, the type of homotopies $\Id_{\Hom(P, B \times B)}(r,r')$ is equivalent to the type $\Id_{\Hom(P,B)}(\pi_1 \circ r, \pi_1 \circ r') \times \Id_{\Hom(P,B)}(\pi_2 \circ r, \pi_2 \circ r')$.
Thus, by the definition of pushouts, we have the following equivalence:
\begin{align*}
& \Hom(P,E) \to \sum_{a : \Hom(P,A)} \sum_{b : \Hom(P,B)} \Id(f \circ a, b) \times \Id(g \circ a, b) \\
& \lambda q.\,(e \circ q, s \circ q, q * h_1, q * h_2),
\end{align*}
where $h_1 : \Id(f \circ e, s)$ and $h_2 : \Id(g \circ e, s)$ are certain homotopies.
The codomain of this function is equivalent to $\Sigma_{a : \Hom(P,A)} \Id(f \circ a, g \circ a)$.
This implies that we have the following equivalence:
\[ \lambda q.\,(e \circ q, q * (h_1 \ct \sym{h_2})) : \Hom(P,E) \to \sum_{a : \Hom(P,A)} \Id(f \circ a, g \circ a). \]
Thus, we can define an equalizer of maps $f$ and $g$ as the triple $E$, $e$, $h_1 \ct \sym{h_2}$.
Now, suppose that the theory has binary products and equalizers.
Let $f : \Hom(A,C)$ and $g : \Hom(B,C)$ be a pair of maps.
Let $e : P \to A \times B$, $h : \Id(f \circ \pi_1 \circ e, g \circ \pi_2 \circ e)$ be the equalizer of the maps $f \circ \pi_1, g \circ \pi_2 : A \times B \to C$.
Then we can define a pullback of $f$ and $g$ as the triple $\pi_1 \circ e$, $\pi_2 \circ e$, $h$.
The universal property of equalizers implies the universal property of pullbacks.
\end{proof}
\begin{defn}[fin-lim]
An indexed unary type theory \emph{has finite limits} if equivalent conditions of \rprop{fin-lim} hold.
\end{defn}
\begin{example}
If an indexed unary type theory has a terminal type $\term$ with a point $\unit : \term$, then the \emph{loop space type} of a pointed type $Y$, $y_0 : \Hom(\term,Y)$ is the pullback of $y_0$ and $y_0$.
Equivalently, the loop space type is the equalizer of $y_0$ and $y_0$.
Thus, the loop space type is a type $\Omega(Y,y_0)$ together with a homotopy $\Id_{\Hom(\Omega(Y,y_0), Y)}(\lambda s.\,y_0\,\unit, \lambda s.\,y_0\,\unit)$ satisfying the universal property.
Since $\Hom(X,-)$ preserves terminal types and pullbacks, we have the following equivalence:
\[ \Hom(X, \Omega(Y,y_0)) \simeq \Omega(\Hom(X,Y), \lambda x.\,y_0\,\unit), \]
where the second $\Omega$ is the usual loop space base type: $\Omega(S,s_0) = \Id_S(s_0,s_0)$.
\end{example}
\begin{example}
The \emph{suspension} $\Sigma X$ of a type $X$ is the pushout of the maps $\lambda x.\,\unit, \lambda x.\,\unit : \Hom(X,\term)$.
The \emph{$0$-sphere} $S^0$ is the coproduct $\term \amalg \term$.
The \emph{$(n+1)$-sphere} $S^{n+1}$ is the suspension $\Sigma S^n$.
\end{example}
\subsection{(Co)products}
\label{sec:products}
A \emph{product} of an indexed type $\Gamma, i : I \mid \cdot \vdash B \ob$ is an indexed type $\Gamma \mid \cdot \vdash P \ob$ together with a term $\Gamma, i : I \vdash \pi : \Hom(P,B)$
such that the function $\pi \circ -$ has an inverse in the sense that there is a rule of the form
\begin{center}
\AxiomC{$\Gamma \mid \cdot \vdash P' \ob$}
\AxiomC{$\Gamma, i : I \vdash f : \Hom(P',B)$}
\BinaryInfC{$\Gamma \vdash \langle f \rangle_{i : I} : \Hom(P',P)$}
\DisplayProof
\end{center}
and the following types are inhabited:
\begin{align*}
& \Id(\pi \circ \langle f \rangle_{i : I}, f) \\
& \Id(\langle \pi \circ f \rangle_{i : I}, f).
\end{align*}
The theory of coproducts is defined dually.
A \emph{coproduct} of an indexed type $\Gamma, i : I \mid \cdot \vdash B \ob$ is an indexed type $\Gamma \mid \cdot \vdash C \ob$ together with a term $\Gamma, i : I \vdash \fs{in} : \Hom(B,C)$
such that the function $- \circ \fs{in}$ has an inverse in the sense that there is a rule of the form
\begin{center}
\AxiomC{$\Gamma \mid \cdot \vdash C' \ob$}
\AxiomC{$\Gamma, i : I \vdash f : \Hom(B,C')$}
\BinaryInfC{$\Gamma \vdash [ f ]_{i : I} : \Hom(C,C')$}
\DisplayProof
\end{center}
and the following types are inhabited:
\begin{align*}
& \Id([ f ]_{i : I} \circ \fs{in}, f) \\
& \Id([ f \circ \fs{in} ]_{i : I}, f).
\end{align*}
If the $\Pi$-type $\Pi_{i : I} \Hom(P',B)$ exists for all indexed types $\Gamma \mid \cdot \vdash P' \ob$, then a pair $P$, $\pi$ is a product of a family $B$ if and only if the following function is an equivalence for every indexed type $P'$:
\[ \lambda h.\,\lambda i.\,\pi \circ h : \Hom(P',P) \to \prod_{i : I} \Hom(P',B). \]
Dually, if the $\Pi$-type $\Pi_{i : I} \Hom(B,C')$ exists for all indexed types $\Gamma \mid \cdot \vdash C' \ob$, then a pair $C$, $\fs{in}$ is a product of a family $B$ if and only if the following function is an equivalence for every indexed type $C'$:
\[ \lambda h.\,\lambda i.\,h \circ \fs{in}(i) : \Hom(C,C') \to \prod_{i : I} \Hom(B,C'). \]
Products and coproducts are unique up to unique equivalence.
We will denote the product and the coproduct of a family $\Gamma, i : I \mid \cdot \vdash B \type$ by $\prod_{i : I} B$ and $\coprod_{i : I} B$, respectively.
We will say that the product $\prod_{i : I} B$ is \emph{extensional} if the type $\Hom(P, \prod_{i : I} B)$ satisfies functional extensionality as a weak $\Pi$-type $\Pi_{i : I} \Hom(P,B)$ for all indexed types $P$.
Similarly, we will say that the coproduct $\coprod_{i : I} B$ is \emph{extensional} if the type $\Hom(\coprod_{i : I} B, C)$ satisfies functional extensionality as a weak $\Pi$-type $\Pi_{i : I} \Hom(B,C)$ for all indexed types $C$.
\begin{example}
If $\Gamma \vdash I \type$ is a base type and $\Gamma \mid \cdot \vdash X \type$ is an indexed type, then the \emph{power} (or \emph{cotensor}) of $X$ by $I$ is the product $\prod_{i : I} X$.
The \emph{copower} (or \emph{tensor}) of $X$ by $I$ is the coproduct $\coprod_{i : I} X$.
The power will be denoted by $X^I$ and the tensor by $I \cdot X$.
\end{example}
We can also define the theory of \emph{strict products}:
\begin{center}
\AxiomC{$\Gamma, i : I \mid \cdot \vdash B \ob$}
\UnaryInfC{$\Gamma \mid \cdot \vdash \prod_{i : I} B \ob$}
\DisplayProof
\qquad
\AxiomC{$\Gamma, i : I \mid \Delta \vdash b : B$}
\RightLabel{, $i \notin \mathrm{FV}(\Delta)$}
\UnaryInfC{$\Gamma \mid \Delta \vdash \lambda i.\,b : \prod_{i : I} B$}
\DisplayProof
\end{center}
\medskip
\begin{center}
\AxiomC{$\Gamma \mid \Delta \vdash f : \prod_{i : I} B$}
\AxiomC{$\Gamma \vdash j : I$}
\BinaryInfC{$\Gamma \mid \Delta \vdash f\,j : B[j/i]$}
\DisplayProof
\end{center}
\begin{align*}
(\lambda i.\,b)\,j & = b[j/i] \\
\lambda i.\,f\,i & = f
\end{align*}
The difference between weak and strict products is that the former requires types $\Hom(P',\prod_{i : I} B)$ and $\Pi_{i : I} \Hom(P',B)$ to be equivalent while the latter requires them to be \emph{isomorphic}.
The theory of \emph{weak products} is define in the same way as the theory of strict products with the difference that the last two equations hold only propositionally.
\begin{prop}
A type $\Gamma \mid \cdot \vdash \prod_{i : I} B$ is a product of a family $\Gamma, i : I \mid \cdot \vdash B \ob$ if and only if it is a weak product of this family.
\end{prop}
\begin{proof}
First, suppose that $\prod_{i : I} B$ is a product.
If $\Gamma, i : I \mid x : A \vdash b : B$, then we define $\lambda i.\,b$ as $\langle \lambda x.\,b \rangle_{i : I}\,x$.
If $\Gamma \mid x : A \vdash f : \prod_{i : I} B$ and $\Gamma \vdash j : I$, then we define $f\,j$ as $\pi[j/i]\,f$.
The $\beta$ and $\eta$ equations hold for these definitions:
\begin{align*}
& \lambda x.\,(\lambda i.b)\,j = \lambda x.\,\pi[j/i]\,(\langle \lambda x.b \rangle_{i : I}\,x) = (\pi \circ \langle \lambda x.b \rangle_{i : I})[j/i] \sim (\lambda x.b)[j/i] = \lambda x.\,b[j/i] \\
& \lambda x.\,\lambda i.\,f\,i = \lambda x.\,\langle \lambda x.\,\pi\,f \rangle_{i : I}\,x = \langle \lambda x.\,\pi\,f \rangle_{i : I} = \langle \pi \circ (\lambda x.f) \rangle_{i : I} \sim \lambda x.f
\end{align*}
Now, suppose that $\prod_{i : I} B$ is a weak product.
We define
\[ \Gamma, i : I \vdash \pi : \Hom(\prod_{i : I} B, B) \]
as $\lambda f.\,f\,i$.
If $\Gamma, i : I \vdash g : \Hom(P,B)$, then we define $\Gamma \vdash \langle g \rangle_{i : I} : \Hom(P, \prod_{i : I} B)$ as $\lambda x.\,\lambda i.\,g\,x$.
The required homotopies can be constructed as follows:
\begin{align*}
& \pi \circ \langle g \rangle_{i : I} = \lambda x.\,(\lambda i.\,g\,x)\,i \sim \lambda x.\,g\,x = g \\
& \langle \pi \circ g \rangle_{i : I} = \lambda x.\,\lambda i.\,g\,x\,i \sim \lambda x.\,g\,x = g
\end{align*}
\end{proof}
Let us prove a few properties of products and coproducts.
To simplify the notation, we will assume that the base theory of an indexed theory with a product $\prod_{i : I} B$ has $\Pi$-types $\Pi_{i : I} \Hom(P,B)$ for all $P$.
The following proposition shows that the (co)product of a contractible family of types is any type of this family:
\begin{prop}
Let $I$ be a contractible type and let $i_0$ be a point of $I$.
Then types $\prod_{i : I} B$, $\coprod_{i : I} B$, and $B[i_0/i]$ are equivalent.
\end{prop}
\begin{proof}
Let $p(i)$ be a path between $i_0$ and $i : I$.
Then the pair $B[i_0/i], \pi_i = \lambda x.\,p(i)_*(x)$ is a product of $B$.
We can define $\langle f \rangle_{i : I}$ as $\lambda x.\,\sym{p(i)}_*(f\,x)$.
Clearly, this is an inverse to $\pi \circ -$.
Since $B[i_0/i],\pi$ is a product and products are unique up to equivalence, it follows that $B[i_0/i]$ is equivalent to $\prod_{i : I} B$.
Similar argument shows that it is also equivalent to $\coprod_{i : I} B$.
\end{proof}
The following proposition shows how to compute products and coproducts indexed by $\Sigma$-types:
\begin{prop}
Let $\Gamma \vdash I \type$ and $\Gamma, i : I \vdash J \type$ be base types and let $\Gamma, i : I, j : J \mid \cdot \vdash B \ob$ be an indexed type.
Then types $\prod_{(p : \Sigma_{i : I} J)} B[\pi_1(p)/i, \pi_2(p)/j]$ and $\prod_{i : I} \prod_{j : J} B$ are equivalent.
Dually, types $\coprod_{(p : \Sigma_{i : I} J)} B[\pi_1(p)/i, \pi_2(p)/j]$ and $\coprod_{i : I} \coprod_{j : J} B$ are equivalent.
\end{prop}
\begin{proof}
We will prove this statement for products; the case of coproducts is dual.
To do this, it is enough to show that $\prod_{i : I} \prod_{j : J} B$ is a product of $\Gamma , p : \Sigma_{i : I} J \mid \cdot \vdash B[\pi_1(p)/i, \pi_2(p)/j] \ob$.
We define projections as follows:
\[ \lambda f.\,f\,(\pi_1(p))\,(\pi_2(p)) : \Hom(\prod_{i : I} \prod_{j : J} B, B[\pi_1(p)/i,\pi_2(p)/j]). \]
We need to show that the following map is an equivalence:
\begin{align*}
& \Hom(X, \prod_{i : I} \prod_{j : J} B) \to \prod_{p : \sum_{i : I} J} \Hom(X, B[\pi_1(p)/i,\pi_2(p)/j]) \\
& \lambda g.\,\lambda p.\,\lambda x.\,g\,x\,(\pi_1(p))\,(\pi_2(p)).
\end{align*}
Note that this map factors through the following maps:
\begin{align*}
\lambda g.\,\lambda i j.\,\lambda x.\,g\,x\,i\,j & : \Hom(X, \prod_{i : I} \prod_{j : J} B) \to \prod_{i : I} \prod_{j : J} \Hom(X,B) \\
\lambda h p.\,h\,(\pi_1(p))\,(\pi_2(p)) & : (\prod_{i : I} \prod_{j : J} \Hom(X,B)) \to \prod_{p : \sum_{i : I} J} \Hom(X, B[\pi_1(p)/i,\pi_2(p)/j]).
\end{align*}
The first map is an equivalence since $\prod_{i : I} \prod_{j : J} B$ is a product and the fact that the second map is an equivalence is an easy exercise in the ordinary type theory.
\end{proof}
The following proposition shows that the product of an empty family of types is the terminal object and the coproduct of such a family is initial:
\begin{prop}
Suppose that the base theory has the empty type $\bot$.
Let $\Gamma, i : \bot \mid \cdot \vdash B \ob$ be an indexed type.
Then $\prod_{i : \bot} B$ is terminal and $\coprod_{i : \bot} B$ is initial.
\end{prop}
\begin{proof}
Since $\Hom(P, \prod_{i : \bot} B)$ is equivalent to $\Pi_{i : \bot} \Hom(P,B)$ and $\Hom(\coprod_{i : \bot} B, P)$ is equivalent $\Pi_{i : \bot} \Hom(B,P)$,
the statement follows from the fact that $\Pi_{i : \bot} X$ is contractible for every base type $X$.
\end{proof}
The following proposition shows how to compute products and coproducts indexed by pushouts:
\begin{prop}
Suppose that the base theory has the following pushout:
\[ \xymatrix{ K \ar[r]^-g \ar[d]_-f & J \ar[d]^-{f'} \\
I \ar[r]_-{g'} & \po I \amalg_K J.
} \]
Let $\Gamma, s : I \amalg_K J \mid \cdot \vdash B \ob$ be an indexed type.
Then we have the following canonical equivalences:
\begin{align*}
\prod_{s : I \amalg_K J} B & \simeq (\prod_{i : I} B[g' i/s]) \times_{(\prod_{k : K} B[g' (f k) / s])} (\prod_{j : J} B[f' j/s]) \\
\coprod_{s : I \amalg_K J} B & \simeq (\coprod_{i : I} B[g' i/s]) \amalg_{(\coprod_{k : K} B[f' (g k) / s])} (\coprod_{j : J} B[f' j/s]).
\end{align*}
\end{prop}
\begin{proof}
We will construct the first equivalence; the second is its dual.
First, let us define maps that appears in the pullback in the statement of this proposition.
The map $\Hom(\prod_{i : I} B[g' i/s], \prod_{k : K} B[g' (f k) / s])$ is defined as $\lambda p.\,\lambda k.\,p\,(f\,k)$.
One of the constructors of the pushout $I \amalg_K J$ gives us a map $h : \Pi_{k : K} \Id(f'\,(g\,k),g'\,(f\,k))$.
The map $\Hom(\prod_{j : J} B[f' j/s], \prod_{k : K} B[g' (f k) / s])$ is defined as $\lambda p.\,\lambda k.\,(h\,k)_*(p\,(g\,k))$.
Now, we need to prove that, for every type $P$, the type $\Hom(P, \prod_{s : I \amalg_K J} B)$ is the weak $\Pi$-type $\Pi_{s : I \amalg_K J} \Hom(P,B)$.
By the universal property of pullbacks, we have an equivalence between $\Hom(P, \prod_{s : I \amalg_K J} B)$ and the following type:
\[ \Hom(P, \prod_{i : I} B[g' i/s]) \times_{\Hom(P, \prod_{k : K} B[g' (f k) / s])} \Hom(P, \prod_{j : J} B[f' j/s]). \]
By the universal property of products, this type is equivalent to the following one:
\[ (\prod_{i : I} \Hom(P, B[g' i/s])) \times_{(\prod_{k : K} \Hom(P, B[g' (f k) / s]))} (\prod_{j : J} \Hom(P, B[f' j/s])). \]
The standard argument about pushouts shows that this type is equivalent to the weak $\Pi$-type $\Pi_{s : I \amalg_K J} \Hom(P,B)$.
\end{proof}
The following corollary shows how to compute tensoring by different type-theoretic constructions:
\begin{cor}
We have the following canonical equivalences:
\begin{align*}
\bot \cdot X & \simeq 0 \\
(I \amalg_K J) \cdot X & \simeq I \cdot X \amalg_{K \cdot X} J \cdot X \\
\top \cdot X & \simeq X \\
(\sum_{i : I} J) \cdot X & \simeq \coprod_{i : I} J \cdot X \\
(\Sigma I) \cdot 1 & \simeq \Sigma (I \cdot 1) \\
S^n \cdot 1 & \simeq S^n
\end{align*}
\end{cor}
\begin{proof}
The first four equivalences follow from previous propositions.
The equivalence for suspension follows from previous equations since suspension is defined in terms of pushouts and terminal types.
The last equivalence follows from previous since spheres are defined in terms of suspensions, coproducts, and terminal types.
\end{proof}
\begin{example}
Let $S^1$ be the pushout of $1 \amalg 1$ in the base theory, that is a higher inductive type with two point constructors $N,S : S^1$ and two path constructors $L,R : \Id_{S^1}(N,S)$.
Then the product of a family $\Gamma, x : S^1 \mid \cdot \vdash B$ is the equalizer of the maps $L_*(-),R_*(-) : B[N/x] \to B[S/x]$.
\end{example}
\section{Indexed dependent type theories}
\label{sec:dependent}
In this section, we define the dependent version of indexed type theories.
\subsection{Basic rules}
\emph{Indexed dependent type theories} have four kinds of judgments:
\[ \Gamma \vdash A \type \qquad \Gamma \vdash a : A \qquad \Gamma \mid \Delta \vdash B \ob \qquad \Gamma \mid \Delta \vdash b : B \]
In each of these judgments, $\Delta$ is an indexed context, that is a sequence of the form $y_1 : B_1, \ldots y_k : B_k$, where $B_1$, \ldots $B_k$ are indexed types and $y_1$, \ldots $y_k$ are pairwise distinct variables.
The base theory has the same rules as the base theory in indexed unary type theories.
The indexed theory has the following rules:
\begin{center}
\AxiomC{}
\UnaryInfC{$\Gamma \mid x_1 : A_1, \ldots x_n : A_n \vdash x_i : A_i$}
\DisplayProof
\end{center}
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \mid \Delta \vdash b_1 : B_1$
\noLine
\UnaryInf$\fCenter \ldots$
\noLine
\UnaryInf$\fCenter \Gamma \mid \Delta \vdash b_k : B_k[b_1/y_1, \ldots b_{k-1}/y_{k-1}]$
\Axiom$\fCenter \Gamma \mid \Delta, y_1 : B_1, \ldots y_k : B_k \vdash C \type$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma \mid \Delta \vdash C[b_1/y_1, \ldots b_k/y_k] \type$}
\DisplayProof
\end{center}
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \mid \Delta \vdash b_1 : B_1$
\noLine
\UnaryInf$\fCenter \ldots$
\noLine
\UnaryInf$\fCenter \Gamma \mid \Delta \vdash b_k : B_k[b_1/y_1, \ldots b_{k-1}/y_{k-1}]$
\Axiom$\fCenter \Gamma \mid \Delta, y_1 : B_1, \ldots y_k : B_k \vdash c : C$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma \mid \Delta \vdash c[b_1/y_1, \ldots b_k/y_k] : C[b_1/y_1, \ldots b_k/y_k]$}
\DisplayProof
\end{center}
We also have the usual equations for substitution:
\begin{align*}
y_i[b_1/y_1, \ldots b_k/y_k] & = b_i \\
c[y_1/y_1, \ldots y_k/y_k] & = c \\
d[c_1/z_1, \ldots c_n/z_n][b_1/y_1, \ldots b_k/y_k] & = d[c_1'/z_1, \ldots c_n'/z_n],
\end{align*}
where $c_i' = c_i[b_1/y_1, \ldots b_k/y_k]$.
We often assume that, for every construction $\sigma(\overline{z_1}.\,c_1, \ldots \overline{z_n}.\,c_n)$ in the indexed theory, the following equation holds whenever variables $\overline{z_1}$, \ldots $\overline{z_n}$ are not free in $b_1$, \ldots $b_k$:
\[ \sigma(\ldots, \overline{z_i}.\,c_i, \ldots)[b_1/y_1, \ldots b_k/y_k] = \sigma(\ldots, \overline{z_i}.\,c_i[b_1/y_1, \ldots b_k/y_k], \ldots) \]
We also have the weakening operation which is left implicit as usual.
We will call a theory or a construction \emph{unstable} if this equation does not hold.
We can also substitute base terms into indexed types and terms:
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \vdash b_1 : B_1$
\noLine
\UnaryInf$\fCenter \ldots$
\noLine
\UnaryInf$\fCenter \Gamma \vdash b_k : B_k[b_1/y_1, \ldots b_{k-1}/y_{k-1}]$
\Axiom$\fCenter \Gamma, y_1 : B_1, \ldots y_k : B_k \mid \Delta \vdash C \ob$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma \mid \Delta[b_1/y_1, \ldots b_k/y_k] \vdash C[b_1/y_1, \ldots b_k/y_k] \ob$}
\DisplayProof
\end{center}
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \vdash b_1 : B_1$
\noLine
\UnaryInf$\fCenter \ldots$
\noLine
\UnaryInf$\fCenter \Gamma \vdash b_k : B_k[b_1/y_1, \ldots b_{k-1}/y_{k-1}]$
\Axiom$\fCenter \Gamma, y_1 : B_1, \ldots y_k : B_k \mid \Delta \vdash c : C$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma \mid \Delta[b_1/y_1, \ldots b_k/y_k] \vdash c[b_1/y_1, \ldots b_k/y_k] : C[b_1/y_1, \ldots b_k/y_k]$}
\DisplayProof
\end{center}
These operations satisfy the following equations for all base terms $b_1$, \ldots $b_k$ and indexed terms $c_1$, \ldots $c_n$:
\begin{align*}
x[b_1/y_1, \ldots b_k/y_k] & = x \\
d[c_1/z_1, \ldots c_n/z_n][b_1/y_1, \ldots b_k/y_k] & = d[c_1'/z_1, \ldots c_n'/z_n],
\end{align*}
where $c_i' = c_i[b_1/y_1, \ldots b_k/y_k]$.
These operations satisfy the following equations for all base terms $b_1$, \ldots $b_k$, $c_1$, \ldots $c_n$:
\begin{align*}
c[y_1/y_1, \ldots y_k/y_k] & = c \\
d[c_1/z_1, \ldots c_n/z_n][b_1/y_1, \ldots b_k/y_k] & = d[c_1'/z_1, \ldots c_n'/z_n],
\end{align*}
where $c_i' = c_i[b_1/y_1, \ldots b_k/y_k]$.
Since the second level of an indexed dependent type theory is also a dependent type theory,
we can add standard type-theoretic construction to it.
When we add such a construction, we always assume that it is defined in every base context.
Indexed dependent type theories have the same rules as indexed unary type theories.
This means that indexed unary type theories can be interpreted in indexed dependent type theories.
This implies that every model of an indexed dependent type theory is a model of corresponding unary theory
(that is, there is a forgetful functor from the category of models of an indexed dependent theory to the category of models of an indexed unary theory).
Every model of an ordinary dependent type theory (as defined in \cite{alg-tt}) is a model of an indexed dependent type theory.
This follows from the fact that indexed type theories can be interpreted in ordinary dependent type theories.
Judgments $\Gamma \mid \Delta \vdash A \ob$ and $\Gamma \mid \Delta \vdash a : A$ are interpreted as $\Gamma, \Delta \vdash A \type$ and $\Gamma, \Delta \vdash a : A$, respectively.
All the rules of indexed dependent type theories correspond to some rules of ordinary dependent type theories.
This interpretation will be called \emph{the canonical indexing of a dependent type theory over itself}.
It is analogous to the canonical indexing of a Cartesian category over itself.
\subsection{Dependent $\Hom$-types}
Since every indexed dependent type theory is an indexed unary type theory, the extensions that we discussed in the context of unary theories also applies to dependent versions.
Note that these constructions apply only to closed indexed types.
Sometimes we can extend the notion, so that it applies to indexed types in a non-empty context.
For example, there is a notion of locally small indexed dependent type theory.
We can also define the following dependent version of $\Hom$-types:
\begin{center}
\AxiomC{$\Gamma \mid \Delta \vdash B \ob$}
\UnaryInfC{$\Gamma \vdash \Hom(\Delta.B) \type$}
\DisplayProof
\qquad
\AxiomC{$\Gamma \mid \Delta \vdash b : B$}
\UnaryInfC{$\Gamma \vdash \lambda \Delta.\,b : \Hom(\Delta.B)$}
\DisplayProof
\end{center}
\medskip
\begin{center}
\AxiomC{$\Gamma \vdash f : \Hom(\Delta.B)$}
\AxiomC{$\Gamma \mid E \vdash a_1 : A_1\ \ldots\ \Gamma \mid E \vdash a_k : A_k[a_1/x_1, \ldots a_{k-1}/x_{k-1}]$}
\BinaryInfC{$\Gamma \mid E \vdash f\,a_1\,\ldots\,a_k : B[a_1/x_1, \ldots a_k/x_k]$}
\DisplayProof
\end{center}
where $\Delta = x_1 : A_1, \ldots x_k : A_k$.
\begin{align*}
(\lambda x_1 \ldots x_k.\,b)\,a_1\,\ldots\,a_k & = b[a_1/x_1, \ldots a_k/x_k] \\
\lambda x_1 \ldots x_k.\,f\,x_1\,\ldots\,x_k & = f
\end{align*}
If $\Delta$ is empty, then we will write $\Hom(\Delta.B)$ as $\Hom(B)$, abstraction as $\lambda(b)$, and the application operation as $f\,()$.
If we have such dependent $\Hom$-types, then we can define the following operation:
\begin{center}
\def\extraVskip{1pt}
\Axiom$\fCenter \Gamma \vdash a : A$
\noLine
\UnaryInf$\fCenter \Gamma \vdash a' : A$
\noLine
\UnaryInf$\fCenter \Gamma \vdash t : \Id_A(a,a')$
\Axiom$\fCenter \Gamma, x : A, p : \Id_A(a,x), \Delta \mid E \vdash D \ob$
\noLine
\UnaryInf$\fCenter \Gamma, \Delta[a/x,\refl(a)/p] \mid E[a/x,\refl(a)/p] \vdash d : D[a/x,\refl(a)/p]$
\def\extraVskip{2pt}
\BinaryInfC{$\Gamma, \Delta[a'/x,t/p] \mid E[a'/x,t/p] \vdash J(a, x p \Delta E.\,D, \Delta E.\,d, a', t) : D[a'/x,t/p]$}
\DisplayProof
\end{center}
\[ J(a, x p \Delta E.\,D, \Delta E.\,d, a, \refl(a)) = d \]
Indeed, we define $J(a, x p \Delta E.\,D, \Delta E.\,d, a', t)$ as follows:
\[ J(a, x p \Delta.\,\Hom(E.D), \Delta.\,\lambda E.\,d, a', t)\,y_1\,\ldots\,y_k, \]
where $E = y_1 : B_1, \ldots y_k : B_k$.
If we do not assume the existence dependent $\Hom$-types, then we need to add this operation explicitly.
If the indexed theory has identity types, then we can define the following operation:
\begin{center}
\AxiomC{$\Gamma \vdash p : \Id_{\Hom(A,B)}(f,g)$}
\AxiomC{$\Gamma \mid \Delta \vdash a : A$}
\BinaryInfC{$\Gamma \mid \Delta \vdash \fs{hap}(p,a) : \Id_B(f\,a,g\,a)$}
\DisplayProof
\end{center}
It is defined as follows:
\[ \fs{hap}(p,a) = \pmap(f.\,f\,a,p). \]
We will say that identity types are \emph{extensional} if $\fs{hap}$ is an equivalence.
More precisely, the theory of extensional identity types has the following constructions:
\begin{center}
\AxiomC{$\Gamma \mid x : A \vdash p : \Id_{B}(f\,x,g\,x)$}
\UnaryInfC{$\Gamma \vdash \fs{Idext}(x.\,p) : \Id_{\Hom(A,B)}(f,g)$}
\DisplayProof
\end{center}
\medskip
\begin{center}
\AxiomC{$\Gamma \mid x : A \vdash p : \Id_{B}(f\,x,g\,x)$}
\AxiomC{$\Gamma \mid \Delta \vdash a : A$}
\BinaryInfC{$\Gamma \mid \Delta \vdash \fs{hap_h}(x.\,p,a) : \Id_B(\fs{hap}(\fs{Idext}(x.\,p),a),p[a/x])$}
\DisplayProof
\end{center}
\medskip
The standard argument implies that we also have the following homotopy:
\begin{center}
\AxiomC{$\Gamma \vdash p : \Id_{\Hom(A,B)}(f,g)$}