-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlevels.tex
2092 lines (1828 loc) · 106 KB
/
hlevels.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{Homotopy \texorpdfstring{$n$}{n}-types}
\label{cha:hlevels}
\index{n-type@$n$-type|(}%
\indexsee{h-level}{$n$-type}
One of the basic notions of homotopy theory is that of a \emph{homotopy $n$-type}: a space containing no interesting homotopy above dimension $n$.
For instance, a homotopy $0$-type is essentially a set, containing no nontrivial paths, while a homotopy $1$-type may contain nontrivial paths, but no nontrivial paths between paths.
Homotopy $n$-types are also called \emph{$n$-truncated spaces}.
We have mentioned this notion already in \cref{sec:basics-sets}; our first goal in this chapter is to give it a precise definition in homotopy type theory.
A dual notion to truncatedness is connectedness: a space is \emph{$n$-connected} if it has no interesting homotopy in dimensions $n$ and \emph{below}.
For instance, a space is $0$-connected (also called just ``connected'') if it has only one connected component, and $1$-connected (also called ``simply connected'') if it also has no nontrivial loops (though it may have nontrivial higher loops between loops\index{loop!n-@$n$-}).
The duality between truncatedness and connectedness is most easily seen by extending both notions to maps.
We call a map \emph{$n$-truncated} or \emph{$n$-connected} if all its fibers are so.
Then $n$-connected and $n$-truncated maps form the two classes of maps in an \emph{orthogonal factorization system},
\index{orthogonal factorization system}
\indexsee{factorization!system, orthogonal}{orthogonal factorization system}
i.e.\ every map factors uniquely as an $n$-connected map followed by an $n$-truncated one.
In the case $n={-1}$, the $n$-truncated maps are the embeddings and the $n$-connected maps are the surjections, as defined in \cref{sec:mono-surj}.
Thus, the $n$-connected factorization system is a massive generalization of the standard image factorization of a function between sets into a surjection followed by an injection.
At the end of this chapter, we sketch briefly an even more general theory: any type-theoretic \emph{modality} gives rise to an analogous factorization system.
\section{Definition of \texorpdfstring{$n$}{n}-types}
\label{sec:n-types}
As mentioned in \cref{sec:basics-sets,sec:contractibility}, it turns out to be convenient to define $n$-types starting two levels below zero, with the $(-1)$-types being the mere propositions and the $(-2)$-types the contractible ones.
\begin{defn}\label{def:hlevel}
Define the predicate $\istype{n} : \type \to \type$ for $n \geq -2$ by recursion as follows:
\[ \istype{n}(X) \defeq
\begin{cases}
\iscontr(X) & \text{ if } n = -2, \\
\prd{x,y : X} \istype{n'}(\id[X]{x}{y}) & \text{ if } n = n'+1.
\end{cases}
\]
We say that $X$ is an \define{$n$-type}, or sometimes that it is \emph{$n$-truncated},
\indexdef{n-type@$n$-type}%
\indexsee{n-truncated@$n$-truncated!type}{$n$-type}%
\indexsee{type!n-type@$n$-type}{$n$-type}%
\indexsee{type!n-truncated@$n$-truncated}{$n$-type}%
if $\istype{n}(X)$ is inhabited.
\end{defn}
\begin{rmk}
The number $n$ in \cref{def:hlevel} ranges over all integers greater than or equal to $-2$.
We could make sense of this formally by defining a type $\Z_{{\geq}-2}$ of such integers (a type whose induction principle is identical to that of $\nat$), or instead defining a predicate $\istype{(k-2)}$ for $k : \nat$.
Either way, we can prove theorems about $n$-types by induction on $n$, with $n = -2$ as the base case.
\end{rmk}
\begin{eg}
\index{set}
We saw in \cref{thm:prop-minusonetype} that $X$ is a $(-1)$-type if and only if it is a mere proposition.
Therefore, $X$ is a $0$-type if and only if it is a set.
\end{eg}
We have also seen that there are types which are not sets (\cref{thm:type-is-not-a-set}).
So far, however, we have not shown for any $n>0$ that there exist types which are not $n$-types.
In \cref{cha:homotopy}, however, we will show that the $(n+1)$-sphere $\Sn^{n+1}$ is not an $n$-type.
(Kraus has also shown that the $n^{\mathrm{th}}$ nested univalent universe is also not an $n$-type, without using any higher inductive types.)
Moreover, in \cref{sec:whitehead} will give an example of a type that is not an $n$-type for \emph{any} (finite) number $n$.
We begin the general theory of $n$-types by showing they are closed under certain operations and constructors.
\begin{thm}\label{thm:h-level-retracts}
\index{retract!of a type}%
\index{retraction}%
Let $p : X \to Y$ be a retraction and suppose that $X$ is an $n$-type, for any $n\geq -2$.
Then $Y$ is also an $n$-type.
\end{thm}
\begin{proof}
We proceed by induction on $n$.
The base case $n=-2$ is handled by \cref{thm:retract-contr}.
For the inductive step, assume that any retract of an $n$-type is an $n$-type, and that $X$ is an $\nplusone$-type.
Let $y, y' : Y$; we must show that $\id{y}{y'}$ is an $n$-type.
Let $s$ be a section of $p$, and let $\epsilon$ be a homotopy $\epsilon : p \circ s \htpy 1$.
Since $X$ is an $\nplusone$-type, $\id[X]{s(y)}{s(y')}$ is an $n$-type.
We claim that $\id{y}{y'}$ is a retract of $\id[X]{s(y)}{s(y')}$.
For the section, we take
\[ \apfunc s : (y=y') \to (s(y)=s(y')). \]
For the retraction, we define $t:(s(y)=s(y'))\to(y=y')$ by
\[ t(q) \defeq \opp{\epsilon_y} \ct \ap p q \ct \epsilon_{y'}.\]
To show that $t$ is a retraction of $\apfunc s$, we must show that
\[ \opp{\epsilon_y} \ct \ap p {\ap sr} \ct \epsilon_{y'} = r \]
for any $r:y=y'$.
But this follows from \cref{lem:htpy-natural}.
\end{proof}
As an immediate corollary we obtain the stability of $n$-types under equivalence (which is also immediate from univalence):
\begin{cor}\label{cor:preservation-hlevels-weq}
If $\eqv{X}{Y}$ and $X$ is an $n$-type, then so is $Y$.
\end{cor}
Recall also the notion of embedding from \cref{sec:mono-surj}.
\begin{thm}\label{thm:isntype-mono}
\index{function!embedding}
If $f:X\to Y$ is an embedding and $Y$ is an $n$-type for some $n\ge -1$, then so is $X$.
\end{thm}
\begin{proof}
Let $x,x':X$; we must show that $\id[X]{x}{x'}$ is an $\nminusone$-type.
But since $f$ is an embedding, we have $(\id[X]{x}{x'}) \eqvsym (\id[Y]{f(x)}{f(x')})$, and the latter is an $\nminusone$-type by assumption.
\end{proof}
Note that this theorem fails when $n=-2$: the map $\emptyt \to \unit$ is an embedding, but $\unit$ is a $(-2)$-type while $\emptyt$ is not.
\begin{thm}\label{thm:hlevel-cumulative}
The hierarchy of $n$-types is cumulative in the following sense:
given a number $n \geq -2$, if $X$ is an $n$-type, then it is also an $\nplusone$-type.
\end{thm}
\begin{proof}
We proceed by induction on $n$.
For $n = -2$, we need to show that a contractible type, say, $A$, has contractible path spaces.
Let $a_0: A$ be the center of contraction of $A$, and let $x, y : A$. We show that $\id[A]{x}{y}$
is contractible.
By contractibility of $A$ we have a path $\contr_x \ct \opp{\contr_y} : x = y$, which we choose as
the center of contraction for $\id{x}{y}$.
Given any $p : x = y$, we need to show $p = \contr_x \ct \opp{\contr_y}$.
By path induction, it suffices to show that
$\refl{x} = \contr_x \ct \opp{\contr_x}$, which is trivial.
For the inductive step, we need to show that $\id[X]{x}{y}$ is an $\nplusone$-type, provided
that $X$ is an $\nplusone$-type. Applying the inductive hypothesis to $\id[X]{x}{y}$
yields the desired result.
\end{proof}
% \section{Preservation under constructors}
% \label{sec:ntype-pres}
We now show that $n$-types are preserved by most of the type forming operations.
\begin{thm}\label{thm:ntypes-sigma}
Let $n \geq -2$, and let $A : \type$ and $B : A \to \type$.
If $A$ is an $n$-type and for all $a : A$, $B(a)$ is an $n$-type, then so is $\sm{x : A} B(x)$.
\end{thm}
\begin{proof}
We proceed by induction on $n$.
For $n = -2$, we choose the center of contraction for $\sm{x : A} B(x)$ to be the pair
$(a_0, b_0)$, where $a_0 : A$ is the center of contraction of $A$ and $b_0 : B(a_0)$ is the center of contraction of $B(a_0)$.
Given any other element $(a,b)$ of $\sm{x : A} B(x)$, we provide a path $\id{(a, b)}{(a_0,b_0)}$
by contractibility of $A$ and $B(a_0)$, respectively.
For the inductive step, suppose that $A$ is an $\nplusone$-type and
for any $a : A$, $B(a)$ is an $\nplusone$-type. We show that $\sm{x : A} B(x)$ is an $\nplusone$-type:
fix $(a_1, b_1)$ and $(a_2,b_2)$ in $\sm{x : A} B(x)$,
we show that $\id{(a_1, b_1)}{(a_2,b_2)}$ is an $n$-type.
By \cref{thm:path-sigma} we have
\[ \eqvspaced{(\id{(a_1, b_1)}{(a_2,b_2)})}{\sm{p : \id{a_1}{a_2}} (\id[B(a_2)]{\trans{p}{b_1}}{b_2})} \]
and by preservation of $n$-types under equivalences (\cref{cor:preservation-hlevels-weq})
it suffices to prove that the latter is an $n$-type. This follows from the
inductive hypothesis.
\end{proof}
As a special case, if $A$ and $B$ are $n$-types, so is $A\times B$.
Note also that \cref{thm:hlevel-cumulative} implies that if $A$ is an $n$-type, then so is $\id[A]xy$ for any $x,y:A$.
Combining this with \cref{thm:ntypes-sigma}, we see that for any functions $f:A\to C$ and $g:B\to C$ between $n$-types, their pullback\index{pullback}
\[ A\times_C B \defeq \sm{x:A}{y:B} (f(x)=g(y)) \]
(see \cref{ex:pullback}) is also an $n$-type.
More generally, $n$-types are closed under all \emph{limits}.
\begin{thm}\label{thm:hlevel-prod}
Let $n\geq -2$, and let $A : \type$ and $B : A \to \type$.
If for all $a : A$, $B(a)$ is an $n$-type, then so is $\prd{x : A} B(x)$.
\end{thm}
\begin{proof}
We proceed by induction on $n$.
For $n = -2$, the result is simply \cref{thm:contr-forall}.
For the inductive step, assume the result is true for $n$-types, and that each $B(a)$ is an $\nplusone$-type.
Let $f, g : \prd{a:A}B(a)$.
We need to show that $\id{f}{g}$ is an $n$-type.
By function extensionality and closure of $n$-types under equivalence, it suffices to show that $\prd{a : A} (\id[B(a)]{f(a)}{g(a)})$ is an $n$-type.
This follows from the inductive hypothesis.
\end{proof}
As a special case of the above theorem, the function space $A \to B$ is an $n$-type provided that $B$ is an $n$-type.
We can now generalize our observations in \cref{cha:basics} that $\isset(A)$ and $\isprop(A)$ are mere propositions.
\begin{thm}\label{thm:isaprop-isofhlevel}
For any $n \geq -2$ and any type $X$, the type $\istype{n}(X)$ is a mere proposition.
\end{thm}
\begin{proof}
We proceed by induction with respect to $n$.
For the base case, we need to show that for any $X$, the type $\iscontr(X)$ is a mere proposition.
This is \cref{thm:isprop-iscontr}.
For the inductive step we need to show
\[\prd{X : \type} \isprop (\istype{n}(X)) \to \prd{X : \type} \isprop (\istype{\nplusone}(X)) \]
To show the conclusion of this implication, we need to show that for any type $X$, the type
\[\prd{x, x' : X}\istype{n}(x = x')\]
is a mere proposition. By \cref{thm:isprop-forall} or \cref{thm:hlevel-prod}, it suffices to show that for any $x, x' : X$, the type $\istype{n}(x =_X x')$ is a mere
proposition.
But this follows from the inductive hypothesis applied to the type $(x =_X x')$.
\end{proof}
Finally, we show that the type of $n$-types is itself an $\nplusone$-type.
We define this to be:
\symlabel{universe-of-ntypes}
\[\ntype{n} \defeq \sm{X : \type} \istype{n}(X) \]
If necessary, we may specify the universe $\UU$ by writing $\ntypeU{n}$.
In particular, we have $\prop \defeq \ntype{(-1)}$ and $\set \defeq \ntype{0}$, as defined in \cref{cha:basics}.
Note that just as for \prop and \set, because $\istype{n}(X)$ is a mere proposition, by \cref{thm:path-subset} for any $(X,p), (X',p'):\ntype{n}$ we have
\begin{align*}
\Big(\id[\ntype{n}]{(X, p)}{(X', p')}\Big) &\eqvsym (\id[\type] X X')\\
&\eqvsym (\eqv{X}{X'}).
\end{align*}
\begin{thm}\label{thm:hleveln-of-hlevelSn}
For any $n \geq -2$, the type $\ntype{n}$ is an $\nplusone$-type.
\end{thm}
\begin{proof}%[Proof of \cref{thm:hleveln-of-hlevelSn}]
Let $(X, p), (X', p') : \ntype{n}$; we need to show that $\id{(X, p)}{(X', p')}$ is an $n$-type.
By the above observation, this type is equivalent to $\eqv{X}{X'}$.
Next, we observe that the projection
\[(\eqv{X}{X'}) \to (X \rightarrow X').\]
is an embedding, so that if $n\geq -1$, then by \cref{thm:isntype-mono} it suffices to show that $X \rightarrow X'$ is an $n$-type.
But since $n$-types are preserved under the arrow type, this reduces to an assumption that $X'$ is an $n$-type.
In the case $n=-2$, this argument shows that $\eqv{X}{X'}$ is a $(-1)$-type --- but it is also inhabited, since any two contractible types
are equivalent to \unit, and hence to each other.
Thus, $\eqv{X}{X'}$ is also a $(-2)$-type.
\end{proof}
\section{Uniqueness of identity proofs and Hedberg's theorem}
\label{sec:hedberg}
\index{set|(}%
In \cref{sec:basics-sets} we defined a type $X$ to be a \emph{set} if for all $x, y : X$ and $p, q : x =_X y$ we have $p = q$.
In conventional type theory, this property goes by the name of \define{uniqueness of identity proofs (UIP)}.
\indexdef{uniqueness!of identity proofs}%
We have seen also that it is equivalent to being a $0$-type in the sense of the previous section.
Here is another equivalent characterization, involving Streicher's ``Axiom K'' \cite{Streicher93}:
\begin{thm}\label{thm:h-set-uip-K}
A type $X$ is a set if and only if it satisfies \define{Axiom K}:
\indexdef{axiom!Streicher's Axiom K}%
for all $x : X$ and $p : (x =_A x)$ we have $p = \refl{x}$.
\end{thm}
\begin{proof}
Clearly Axiom K is a special case of UIP.
Conversely, if $X$ satisfies Axiom K, let $x, y : X$ and $p, q : (\id{x}{y})$; we want to show $p=q$.
But induction on $q$ reduces this goal precisely to Axiom K.
\end{proof}
We stress that \emph{we} are not assuming UIP or the K principle as axioms!
They are simply properties which a particular type may or may not satisfy (which are equivalent to being a set).
Recall from \cref{thm:type-is-not-a-set} that \emph{not} all types are sets.
The following theorem is another useful way to show that types are sets.
\begin{thm}\label{thm:h-set-refrel-in-paths-sets}
\index{relation!reflexive}%
Suppose $R$ is a reflexive\index{reflexivity!of a relation} mere relation on a type $X$ implying identity.
Then $X$ is a set, and $R(x,y)$ is equivalent to $\id[X]{x}{y}$ for all $x,y:X$.
\end{thm}
\begin{proof}
Let $\rho : \prd{x:X} R(x,x)$ witness reflexivity of $R$, and let \narrowequation{f : \prd{x,y:X} R(x,y) \to (\id[X]{x}{y})} be a witness that $R$
implies identity.
Note first that the two statements in the theorem are equivalent.
For on one hand, if $X$ is a set, then $\id[X]xy$ is a mere proposition, and since it is logically equivalent to the mere proposition
$R(x,y)$ by hypothesis, it must also be equivalent to it.
On the other hand, if $\id[X]xy$ is equivalent to $R(x,y)$, then like the latter it is a mere proposition for all $x,y:X$, and hence $X$
is a set.
We give two proofs of this theorem.
The first shows directly that $X$ is a set; the second shows directly that $R(x,y)\eqvsym (x=y)$.
\emph{First proof:} we show that $X$ is a set.
The idea is the same as that of \cref{thm:prop-set}: the function $f$ must be continuous in its arguments $x$ and $y$.
However, it is slightly more notationally complicated because we have to deal with the additional argument of type $R(x,y)$.
Firstly, for any $x:X$ and $p:\id[X]xx$, consider $\apdfunc{f(x)}(p)$.
This is a dependent path from $f(x,x)$ to itself.
Since $f(x,x)$ is still a function $R(x,x) \to (\id[X]xy)$, by \cref{thm:dpath-arrow} this yields for any $r:R(x,x)$ a path
\[\trans{p}{f(x,x,r)} = f(x,x,\trans{p}r).
\]
On the left-hand side, we have transport in an identity type, which is concatenation.
And on the right-hand side, we have $\trans{p}r = r$, since both lie in the mere proposition $R(x,x)$.
Thus, substituting $r\defeq \rho(x)$, we obtain
\[ f(x,x,\rho(x)) \ct p = f(x,x,\rho(x)). \]
By cancellation, $p=\refl{x}$.
So $X$ satisfies Axiom K, and hence is a set.
\emph{Second proof:} we show that each $f(x,y) : R(x,y) \to \id[X]{x}{y}$ is an equivalence.
By \cref{thm:total-fiber-equiv}, it suffices to show that $f$ induces an equivalence of total spaces:
\begin{equation*}
\eqv{\Parens{\sm{y:X}R(x,y)}}{\Parens{\sm{y:X}\id[X]{x}{y}}}.
\end{equation*}
By \cref{thm:contr-paths}, the type on the right is contractible, so it
suffices to show that the type on the left is contractible. As the center of
contraction we take the pair $\pairr{x,\rho(x)}$. It remains to show, for
every ${y:X}$ and every ${H:R(x,y)}$ that
\begin{equation*}
\id{\pairr{x,\rho(x)}}{\pairr{y,H}}.
\end{equation*}
But since $R(x,y)$ is a mere proposition, by \cref{thm:path-sigma} it suffices to show that
$\id[X]{x}{y}$, which we get from $f(H)$.
\end{proof}
\begin{cor}\label{notnotstable-equality-to-set}
If a type $X$ has the property that $\neg\neg(x=y)\to(x=y)$ for any $x,y:X$, then $X$ is a set.
\end{cor}
Another convenient way to show that a type is a set is the following.
Recall from \cref{sec:intuitionism} that a type $X$ is said to have \emph{decidable equality}
\index{decidable!equality|(}%
if for all $x, y : X$ we have
\[(x =_X y) + \neg (x =_X y).\]
\index{continuity of functions in type theory@``continuity'' of functions in type theory}%
\index{functoriality of functions in type theory@``functoriality'' of functions in type theory}%
This is a very strong condition: it says that a path $x=y$ can be chosen, when it exists, continuously (or computably, or functorially) in $x$ and $y$.
This turns out to imply that $X$ is a set, by way of \cref{thm:h-set-refrel-in-paths-sets} and the following lemma.
\begin{lem}\label{lem:hedberg-helper}
For any type $A$ we have $(A+\neg A)\to(\neg\neg A\to A)$.
\end{lem}
\begin{proof}
Suppose $x:A+\neg A$. We have two cases to consider.
If $x$ is $\inl(a)$ for some $a:A$, then we have the constant function $\neg\neg A
\to A$ which maps everything to $a$. If $x$ is $\inr(t)$ for some $t:\neg A$,
we have $g(t):\emptyt$ for every $g:\neg\neg A$. Hence we may use
\emph{ex falso quodlibet}, that is $\rec{\emptyt}$, to obtain an element of $A$ for any $g:\neg\neg A$.
\end{proof}
\index{anger}
\begin{thm}[Hedberg]\label{thm:hedberg}
\index{Hedberg's theorem}%
\index{theorem!Hedberg's}%
If $X$ has decidable equality, then $X$ is a set.
\end{thm}
\begin{proof}
If $X$ has decidable equality, it follows that $\neg\neg(x=y)\to(x=y)$ for any
$x,y:X$. Therefore, Hedberg's theorem follows from
\cref{notnotstable-equality-to-set}.
\end{proof}
There is, of course, a strong connection between this theorem and \cref{thm:not-lem}.
The statement \LEM{\infty} that is denied by \cref{thm:not-lem} clearly implies that every type has decidable equality, and hence is a set, which we know is not the case.
\index{excluded middle}%
Note that the consistent axiom \LEM{} from \cref{sec:intuitionism} implies only that every type has \emph{merely decidable equality}, i.e.\ that for any $A$ we have
\indexdef{equality!merely decidable}%
\indexdef{merely!decidable equality}%
\[ \prd{a,b:A} (\brck{a=b} + \neg\brck{a=b}). \]
\index{decidable!equality|)}%
As an example application of \cref{thm:hedberg}, recall that in \cref{thm:nat-set} we observed that $\nat$ is a set, using our characterization of its equality types in
\cref{sec:compute-nat}.
A more traditional proof of this theorem uses only~\eqref{eq:zero-not-succ} and~\eqref{eq:suc-injective}, rather than the full
characterization of \cref{thm:path-nat}, with \cref{thm:hedberg} to fill in the blanks.
\begin{thm}\label{prop:nat-is-set}
The type $\nat$ of natural numbers has decidable equality, and hence is a set.
\end{thm}
\begin{proof}
Let $x, y : \nat$ be given; we proceed by induction on $x$ and case analysis on $y$ to prove $(x=y)+\neg(x=y)$.
If $x \jdeq 0$ and $y \jdeq 0$, we take $\inl(\refl0)$.
If $x \jdeq 0$ and $y \jdeq \suc(n)$, then by~\eqref{eq:zero-not-succ} we get $\neg (0 = \suc (n))$.
For the inductive step, let $x \jdeq \suc (n)$.
If $y \jdeq 0$, we use~\eqref{eq:zero-not-succ} again.
Finally, if $y \jdeq \suc (m)$, the inductive hypothesis gives $(m = n)+\neg(m = n)$.
In the first case, if $p:m=n$, then $\ap \suc p:\suc(m)=\suc(n)$.
And in the second case,~\eqref{eq:suc-injective} yields $\neg(\suc(m)=\suc(n))$.
\end{proof}
\index{set|)}%
\index{axiom!Streicher's Axiom K!generalization to n-types@generalization to $n$-types}%
Although Hedberg's theorem appears rather special to sets ($0$-types), ``Axiom K'' generalizes naturally to $n$-types.
Note that the ordinary Axiom K (as a property of a type $X$) states that for all $x:X$, the loop space\index{loop space} $\Omega(X,x)$ (see \cref{def:loopspace}) is contractible.
Since $\Omega(X,x)$ is always inhabited (by $\refl{x}$), this is equivalent to its being a mere proposition (a $(-1)$-type).
Since $0 = (-1)+1$, this suggests the following generalization.
\begin{thm}\label{thm:hlevel-loops}
For any $n\geq -1$, a type $X$ is an $\nplusone$-type if and only if for all $x : X$, the type $\Omega(X, x)$ is an $n$-type.
\end{thm}
Before proving this, we prove an auxiliary lemma:
\begin{lem}\label{lem:hlevel-if-inhab-hlevel}
Given $n \geq -1$ and $X : \type$.
If, given any inhabitant of $X$ it follows that $X$ is an $n$-type, then $X$ is an $n$-type.
\end{lem}
\begin{proof}
Let $f : X \to \istype{n}(X)$ be the given map.
We need to show that for any $x, x' : X$, the type $\id{x}{x'}$ is an $\nminusone$-type.
But then $f(x)$ shows that $X$ is an $n$-type, hence all its path spaces are $\nminusone$-types.
\end{proof}
\begin{proof}[Proof of \cref{thm:hlevel-loops}]
The ``only if'' direction is obvious, since $\Omega(X,x)\defeq (\id[X]xx)$.
Conversely, in order to show that $X$ is an $\nplusone$-type, we need to show that for any $x, x' : X$, the type $\id{x}{x'}$ is an
$n$-type.
Following \cref{lem:hlevel-if-inhab-hlevel} it suffices to give a map
\[ (\id{x}{x'}) \to \istype{n}(\id{x}{x'}). \]
By path induction, it suffices to do this when $x\jdeq x'$, in which case it follows from the assumption that $\Omega(X, x)$ is an
$n$-type.
\end{proof}
\index{whiskering}
By induction and some slightly clever whiskering, we can obtain a generalization of the K property to $n>0$.
\begin{thm}\label{thm:ntype-nloop}
\index{loop space!iterated}%
For every $n\ge -1$, a type $A$ is an $n$-type if and only if $\Omega^{n+1}(A,a)$ is contractible for all $a:A$.
\end{thm}
\begin{proof}
Recalling that $\Omega^0(A,a) = (A,a)$, the case $n=-1$ is \cref{ex:prop-inhabcontr}.
The case $n=0$ is \cref{thm:h-set-uip-K}.
Now we use induction; suppose the statement holds for $n:\N$.
By \cref{thm:hlevel-loops}, $A$ is an $(n+1)$-type iff $\Omega(A,a)$ is an $n$-type for all $a:A$.
By the inductive hypothesis, the latter is equivalent to saying that $\Omega^{n+1}(\Omega(A,a),p)$ is contractible for all $p:\Omega(A,a)$.
Since $\Omega^{n+2}(A,a) \defeq \Omega^{n+1}(\Omega(A,a),\refl{a})$, and $\Omega^{n+1} = \Omega^n \circ \Omega$, it will suffice to show that $\Omega(\Omega(A,a),p)$ is equal to $\Omega(\Omega(A,a),\refl{a})$, in the type $\pointed\type$ of pointed types.
For this, it suffices to give an equivalence
\[ g : \Omega(\Omega(A,a),p) \eqvsym \Omega(\Omega(A,a),\refl{a}) \]
which carries the basepoint $\refl{p}$ to the basepoint $\refl{\refl{a}}$.
For $q:p=p$, define $g(q):\refl{a} = \refl{a}$ to be the following composite:
\[ \refl{a} = p\ct \opp p \overset{q}{=} p\ct\opp p = \refl{a}, \]
where the path labeled ``$q$'' is actually $\apfunc{\lam{r} r\ct\opp p} (q)$.
Then $g$ is an equivalence because it is a composite of equivalences
\[ (p=p) \xrightarrow{\apfunc{\lam{r} r\ct\opp p}} (p\ct \opp p = p\ct \opp p) \xrightarrow{i\ct - \ct \opp i} (\refl{a} = \refl{a}). \]
using \cref{eg:concatequiv,thm:paths-respects-equiv}, where $i:\refl{a} = p\ct \opp p$ is the canonical equality.
And it is evident that $g(\refl{p}) = \refl{\refl{a}}$.
\end{proof}
\section{Truncations}
\label{sec:truncations}
\indexsee{n-truncation@$n$-truncation}{truncation}%
\index{truncation!n-truncation@$n$-truncation|(defstyle}%
In \cref{subsec:prop-trunc} we introduced the propositional truncation, which makes the ``best approximation'' of a type that is a mere
proposition, i.e.\ a $(-1)$-type.
In \cref{sec:hittruncations} we constructed this truncation as a higher inductive type, and gave one way to generalize it to a
0-truncation.
We now explain a better generalization of this, which truncates any type into an $n$-type for any $n\geq -2$; in classical homotopy theory this would be called its \define{$n^{\mathrm{th}}$ Postnikov section}.\index{Postnikov tower}
The idea is to make use of \cref{thm:ntype-nloop}, which states that $A$ is an $n$-type just when $\Omega^{n+1}(A,a)$
\index{loop space!iterated}%
is contractible for
all $a:A$, and \cref{lem:susp-loop-adj}, which implies that
\narrowequation{\Omega^{n+1}(A,a) \eqvsym \Map_{*}(\Sn^{n+1},(A,a)),} where $\Sn^{n+1}$ is equipp\-ed with some basepoint which we may as well call \base.
However, contractibility of $\Map_*(\Sn^{n+1},(A,a))$ is something that we can ensure directly by giving path constructors.
\index{hub and spoke}%
We will use the ``hub and spoke'' construction as in \cref{sec:hubs-spokes}.
Thus, for $n\ge -1$, we take $\trunc nA$ to be the higher inductive type generated by:
\begin{itemize}
\item a function $\tprojf n : A \to \trunc n A$,
\item for each $r:\Sn^{n+1} \to \trunc n A$, a \emph{hub} point $h(r):\trunc n A$, and
\item for each $r:\Sn^{n+1} \to \trunc n A$ and each $x:\Sn^{n+1}$, a \emph{spoke} path $s_r(x):r(x) = h(r)$.
\end{itemize}
\noindent
The existence of these constructors is now enough to show:
\begin{lem}
$\trunc n A$ is an $n$-type.
\end{lem}
\begin{proof}
By \cref{thm:ntype-nloop}, it suffices to show that $\Omega ^{n+1}(\trunc nA,b)$ is contractible for all $b:\trunc nA$, which by
\cref{lem:susp-loop-adj} is equivalent to \narrowequation{\Map_*(\Sn^{n+1},(\trunc nA,b)).}
As center of contraction for the latter, we choose the function $c_b:\Sn^{n+1} \to \trunc nA$ which is constant at $b$, together with
$\refl b : c_b(\base) = b$.
Now, an arbitrary element of $\Map_*(\Sn^{n+1},(\trunc nA,b))$ consists of a map $r:\Sn^{n+1} \to \trunc n A$ together with a path
$p:r(\base)=b$.
By function extensionality, to show $r = c_b$ it suffices to give, for each $x:\Sn^{n+1}$, a path $r(x)=c_b(x) \jdeq b$.
We choose this to be the composite $s_r(x) \ct \opp{s_r(\base)} \ct p$, where $s_r(x)$ is the spoke at $x$.
Finally, we must show that when transported along this equality $r=c_b$, the path $p$ becomes $\refl b$.
By transport in path types, this means we need
\[\opp{(s_r(\base) \ct \opp{s_r(\base)} \ct p)} \ct p = \refl b.\]
But this is immediate from path operations.
\end{proof}
(This construction fails for $n=-2$, but in that case we can simply define $\trunc{-2}{A}\defeq \unit$ for all $A$.
From now on we assume $n\ge -1$.)
\index{induction principle!for truncation}%
To show the desired universal property of the $n$-truncation, we need the induction principle.
We extract this from the constructors in the usual way; it says that given $P:\trunc nA\to\type$ together with
\begin{itemize}
\item For each $a:A$, an element $g(a) : P(\tproj na)$,
\item For each $r:\Sn^{n+1} \to \trunc n A$ and $r':\prd{x:\Sn^{n+1}} P(r(x))$, an element $h'(r,r'):P(h(r))$,
\item For each $r:\Sn^{n+1} \to \trunc n A$ and $r':\prd{x:\Sn^{n+1}} P(r(x))$, and each $x:\Sn^{n+1}$, a dependent path
$\dpath{P}{s_r(x)}{r'(x)}{h'(r,r')}$,
\end{itemize}
there exists a section $f:\prd{x:\trunc n A} P(x)$ with $f(\tproj n a) \jdeq g(a)$ for all $a:A$.
To make this more useful, we reformulate it as follows.
\begin{thm}\label{thm:truncn-ind}
For any type family $P:\trunc n A \to \type$ such that each $P(x)$ is an $n$-type, and any function $g : \prd{a:A} P(\tproj n a)$, there
exists a section $f:\prd{x:\trunc n A} P(x)$ such that $f(\tproj n a)\defeq g(a)$ for all $a:A$.
\end{thm}
\begin{proof}
It will suffice to construct the second and third data listed above, since $g$ has exactly the type of the first datum.
Given $r:\Sn^{n+1} \to \trunc n A$ and $r':\prd{x:\Sn^{n+1}} P(r(x))$, we have $h(r):\trunc n A$ and $s_r :\prd{x:\Sn^{n+1}} (r(x) =
h(r))$.
Define $t:\Sn^{n+1} \to P(h(r))$ by $t(x) \defeq \trans{s_r(x)}{r'(x)}$.
Then since $P(h(r))$ is $n$-truncated, there exists a point $u:P(h(r))$ and a contraction $v:\prd{x:\Sn^{n+1}} (t(x) = u)$.
Define $h'(r,r') \defeq u$, giving the second datum.
Then (recalling the definition of dependent paths), $v$ has exactly the type required of the third datum.
\end{proof}
In particular, if $E$ is some $n$-type, we can consider the constant family of types equal to $E$ for every point of $A$.
\symlabel{extend}
\index{recursion principle!for truncation}%
Thus, every map $f:A\to{}E$ can be extended to a map $\extend{f}:\trunc nA\to{}E$ defined by $\extend{f}(\tproj na)\defeq f(a)$; this is the \emph{recursion principle} for $\trunc n A$.
The induction principle also implies a uniqueness principle for functions of this form.
\index{uniqueness!principle, propositional!for functions on a truncation}%
Namely, if $E$ is an $n$-type and $g,g':\trunc nA\to{}E$ are such
that $g(\tproj na)=g'(\tproj na)$ for every $a:A$, then $g(x)=g'(x)$ for all $x:\trunc nA$, since the type $g(x)=g'(x)$ is an $n$-type.
Thus, $g=g'$.
(In fact, this uniqueness principle holds more generally when $E$ is an $\nplusone$-type.)
This yields the following universal property.
\begin{lem}[Universal property of truncations]\label{thm:trunc-reflective}
\index{universal!property!of truncation}%
Let $n\ge-2$, $A:\type$ and $B:\typele{n}$. The following map is an
equivalence:
\[\function{(\trunc nA\to{}B)}{(A\to{}B)}{g}{g\circ\tprojf n}\]
\end{lem}
\begin{proof}
Given that $B$ is $n$-truncated, any $f:A\to{}B$ can be extended to a map $\extend{f}:\trunc nA\to{}B$.
The map $\extend{f}\circ\tprojf n$ is equal to $f$, because for every $a:A$ we have $\extend{f}(\tproj na)=f(a)$ by definition.
And the map $\extend{g\circ\tprojf n}$ is equal to $g$, because they both send $\tproj na$ to $g(\tproj na)$.
\end{proof}
In categorical language, this says that the $n$-types form a \emph{reflective subcategory} of the category of types.
\index{reflective!subcategory}%
(To state this fully precisely, one ought to use the language of $(\infty,1)$-categories.)
\index{.infinity1-category@$(\infty,1)$-category}%
In particular, this implies that the $n$-truncation is functorial:
given $f:A\to B$, applying the recursion principle to the composite $A\xrightarrow{f} B \to \trunc n B$ yields a map $\trunc n f: \trunc n A \to \trunc n B$.
By definition, we have a homotopy
\begin{equation}
\mathsf{nat}^f_n : \prd{a:A} \trunc n f(\tproj n a) = \tproj n {f(a)},\label{eq:trunc-nat}
\end{equation}
expressing \emph{naturality} of the maps $\tprojf n$.
Uniqueness implies functoriality laws such as $\trunc n {g\circ f} = \trunc n g \circ \trunc n f$ and $\trunc n{\idfunc[A]} = \idfunc[\trunc n A]$, with attendant coherence laws.
We also have higher functoriality, for instance:
\begin{lem}\label{thm:trunc-htpy}
Given $f,g:A\to B$ and a homotopy $h:f\htpy g$, there is an induced homotopy $\trunc n h : \trunc n f \htpy \trunc n g$ such that the composite
\begin{equation}
\xymatrix@C=3.6pc{\tproj n{f(a)} \ar@{=}[r]^-{\opp{\mathsf{nat}^f_n(a)}} &
\trunc n f(\tproj n a) \ar@{=}[r]^-{\trunc n h(\tproj na)} &
\trunc n g(\tproj n a) \ar@{=}[r]^-{\mathsf{nat}^g_n(a)} &
\tproj n{g(a)}}\label{eq:trunc-htpy}
\end{equation}
is equal to $\apfunc{\tprojf n}(h(a))$.
\end{lem}
\begin{proof}
First, we indeed have a homotopy with components $\apfunc{\tprojf n}(h(a)) : \tproj n{f(a)} = \tproj n{g(a)}$.
Composing on either sides with the paths $\tproj n{f(a)} = \trunc n f(\tproj n a)$ and $\tproj n{g(a)} = \trunc n g(\tproj n a)$, which arise from the definitions of $\trunc n f$ and $\trunc ng$, we obtain a homotopy $(\trunc n f \circ \tprojf n) \htpy (\trunc n g \circ \tprojf n)$, and hence an equality by function extensionality.
But since $(\blank\circ \tprojf n)$ is an equivalence, there must be a path $\trunc nf = \trunc ng$ inducing it, and the coherence laws for function extensionality imply~\eqref{eq:trunc-htpy}.
\end{proof}
The following observation about reflective subcategories is also standard.
\begin{cor}
A type $A$ is an $n$-type if and only if $\tprojf n : A \to \trunc n A$ is an equivalence.
\end{cor}
\begin{proof}
``If'' follows from closure of $n$-types under equivalence.
On the other hand, if $A$ is an $n$-type, we can define $\ext(\idfunc[A]):\trunc n A\to{}A$.
Then we have $\ext(\idfunc[A])\circ\tprojf n=\idfunc[A]:A\to{}A$ by
definition. In order to prove that
$\tprojf n\circ\ext(\idfunc[A])=\idfunc[\trunc nA]$, we only need to prove
that $\tprojf n\circ\ext(\idfunc[A])\circ\tprojf n=
\idfunc[\trunc nA]\circ\tprojf n$.
This is again true:
\[\raisebox{\depth-\height+1em}{\xymatrix{
A \ar^-{\tprojf n}[r] \ar_{\idfunc[A]}[rd] &
\trunc nA \ar^>>>{\ext(\idfunc[A])}[d] \ar@/^40pt/^{\idfunc[\trunc nA]}[dd] \\
& A \ar_{\tprojf n}[d] \\
& \trunc nA}}
\qedhere\]
\end{proof}
The category of $n$-types also has some special properties not possessed by all reflective subcategories.
For instance, the reflector $\trunc n-$ preserves finite products.
\begin{thm}\label{cor:trunc-prod}
For any types $A$ and $B$, the induced map $\trunc n{A\times B} \to \trunc nA \times \trunc nB$ is an equivalence.
\end{thm}
\begin{proof}
It suffices to show that $\trunc nA \times \trunc nB$ has the same universal property as $\trunc n{A\times B}$.
Thus, let $C$ be an $n$-type; we have
\begin{align*}
(\trunc nA \times \trunc nB \to C)
&= (\trunc nA \to (\trunc nB \to C))\\
&= (\trunc nA \to (B \to C))\\
&= (A \to (B \to C))\\
&= (A \times B \to C)
\end{align*}
using the universal properties of $\trunc nB$ and $\trunc nA$, along with the fact that $B\to C$ is an $n$-type since $C$ is.
It is straightforward to verify that this equivalence is given by composing with $\tprojf n \times \tprojf n$, as needed.
\end{proof}
The following related fact about dependent sums is often useful.
\begin{thm}\label{thm:trunc-in-truncated-sigma}
Let $P:A\to\type$ be a family of types. Then there is an equivalence
\begin{equation*}
\eqv{\Trunc n{\sm{x:A}\trunc n{P(x)}}}{\Trunc n{\sm{x:A}P(x)}}.
\end{equation*}
\end{thm}
\begin{proof}
We use the induction principle of $n$-truncation several times to construct
functions
\begin{align*}
\varphi & : \Trunc n{\sm{x:A}\trunc n{P(x)}}\to\Trunc n{\sm{x:A}P(x)}\\
\psi & : \Trunc n{\sm{x:A}P(x)}\to \Trunc n{\sm{x:A} \trunc n{P(x)}}
\end{align*}
and homotopies $H:\varphi\circ\psi\htpy \idfunc$ and $K:\psi\circ\varphi\htpy
\idfunc$ exhibiting them as quasi-inverses.
We define $\varphi$ by setting $\varphi(\tproj n{\pairr{x,\tproj nu}})\defeq\tproj n{\pairr{x,u}}$.
We define $\psi$ by setting $\psi(\tproj n{\pairr{x,u}})\defeq\tproj n{\pairr{x,\tproj nu}}$.
Then we define $H(\tproj n{\pairr{x,u}})\defeq \refl{\tproj n{\pairr{x,u}}}$ and
$K(\tproj n{\pairr{x,\tproj nu}})\defeq \refl{\tproj n{\pairr{x,\tproj nu}}}$.
\end{proof}
\begin{cor}\label{thm:refl-over-ntype-base}
If $A$ is an $n$-type and $P:A\to\type$ is any type family, then
\[ \eqv{\sm{a:A} \trunc n{P(a)}}{\Trunc n{\sm{a:A}P(a)}} \]
\end{cor}
\begin{proof}
If $A$ is an $n$-type, then the left-hand type above is already an $n$-type, hence equivalent to its $n$-truncation; thus this follows from \cref{thm:trunc-in-truncated-sigma}.
\end{proof}
We can characterize the path spaces of a truncation using the same method that we used in \cref{sec:compute-coprod,sec:compute-nat} for
coproducts and natural numbers (and which we will use in \cref{cha:homotopy} to calculate homotopy groups).
Unsurprisingly, the path spaces in the $(n+1)$-truncation of $A$ are the $n$-truncations of the path spaces of $A$.
Indeed, for any $x,y:A$ there is a canonical map
\begin{equation}
f:\ttrunc n{x=_Ay}\to \Big(\tproj {n+1}x=_{\trunc{n+1}A}\tproj {n+1}y\Big)\label{eq:path-trunc-map}
\end{equation}
defined by
\[f(\tproj n{p})\defeq \apfunc{\tprojf {n+1}}(p). \]
This definition uses the recursion principle for $\truncf n$, which is correct because $\trunc {n+1}A$ is $(n+1)$-truncated, so that the
codomain of $f$ is $n$-truncated.
\begin{thm} \label{thm:path-truncation}
For any $A$ and $x,y:A$ and $n\ge -2$, the map~\eqref{eq:path-trunc-map} is an equivalence; thus we have
\[ \eqv{\ttrunc n{x=_Ay}}{\Big(\tproj {n+1}x=_{\trunc{n+1}A}\tproj {n+1}y\Big)}. \]
\end{thm}
\begin{proof}
The proof is a simple application of the encode-decode method:
As in previous situations, we cannot directly define a quasi-inverse to the map~\eqref{eq:path-trunc-map} because there is no way to induct on an
equality between $\tproj {n+1}x$ and $\tproj {n+1}y$.
Thus, instead we generalize its type, in order to have general elements of the type $\trunc{n+1}A$ instead of $\tproj {n+1}x$ and $\tproj
{n+1}y$.
Define $P:\trunc {n+1}A\to\trunc {n+1}A\to\typele{n}$ by
\[P(\tproj {n+1}x,\tproj {n+1}y)\defeq \trunc n{x=_Ay}\]
This definition is correct because $\trunc n{x=_Ay}$ is $n$-truncated, and $\typele{n}$ is $(n+1)$-truncated by
\cref{thm:hleveln-of-hlevelSn}.
Now for every $u,v:\trunc{n+1}A$, there is a map
\[\decode:P(u,v) \to \big(u=_{\trunc{n+1}A}v\big)\]
defined for $u=\tproj {n+1}x$ and $v=\tproj {n+1}y$ and $p:x=y$ by
\[\decode(\tproj n{p})\defeq \apfunc{\tprojf{n+1}} (p).\]
Since the codomain of $\decode$ is $n$-truncated, it suffices to define it only for $u$ and $v$ of this form, and then it's just the same
definition as before.
We also define a function
\[ r : \prd{u:\trunc{n+1} A} P(u,u) \]
by induction on $u$, where $r(\tproj{n+1} x) \defeq \tproj n {\refl x}$.
Now we can define an inverse map
\[\encode: (u=_{\trunc{n+1}A}v) \to P(u,v)\]
by
\[\encode(p) \defeq \transfib{v\mapsto P(u,v)}{p}{r(u)}. \]
To show that the composite
\[ (u=_{\trunc{n+1}A}v) \xrightarrow{\encode} P(u,v) \xrightarrow{\decode} (u=_{\trunc{n+1}A}v) \]
is the identity function, by path induction it suffices to check it for $\refl u : u=u$, in which case what we need to know is that
$\encode(r(u)) = \refl{u}$.
But since this is an $n$-type, hence also an $(n+1)$-type, we may assume $u\jdeq \tproj {n+1} x$, in which case it follows by definition
of $r$ and $\encode$.
Finally, to show that
\[ P(u,v) \xrightarrow{\decode} (u=_{\trunc{n+1}A}v) \xrightarrow{\encode} P(u,v) \]
is the identity function, since this goal is again an $n$-type, we may assume that $u=\tproj {n+1}x$ and $v=\tproj {n+1}y$ and that we are
considering $\tproj n p:P(\tproj{n+1}x,\tproj{n+1}y)$ for some $p:x=y$.
Then we have
\begin{align*}
\encode(\decode(\tproj n p)) &= \encode(\apfunc{\tprojf{n+1}}(p))\\
&= \transfib{v\mapsto P(\tproj{n+1}x,v)}{\apfunc{\tprojf{n+1}}(p)}{\tproj n {\refl x}}\\
&= \transfib{v\mapsto \trunc n{u=v}}{p}{\tproj n {\refl x}}\\
&= \tproj n {\transfib{v \mapsto (u=v)}{p}{\refl x}}\\
&= \tproj n p.
\end{align*}
This completes the proof that \decode and \encode are quasi-inverses.
The stated result is then the special case where $u=\tproj {n+1}x$ and $v=\tproj {n+1}y$.
\end{proof}
\begin{cor}
Let $n\ge-2$ and $(A,a)$ be a pointed type. Then
\[\ttrunc n{\Omega(A,a)}=\Omega\mathopen{}\left(\trunc{n+1}{(A,a)}\right)\]
\end{cor}
\begin{proof}
This is a special case of the previous lemma where $x=y=a$.
\end{proof}
\begin{cor}
Let $n\ge -2$ and $k\ge 0$ and $(A,a)$ a pointed type. Then
\[\ttrunc n{\Omega^k(A,a)} = \Omega^k\mathopen{}\left(\trunc{n+k}{(A,a)}\right). \]
\end{cor}
\begin{proof}
By induction on $k$, using the recursive definition of $\Omega^k$.
\end{proof}
We also observe that ``truncations are cumulative'': if we truncate to an $n$-type and then to a $k$-type with $k\le n$, then we might as
well have truncated directly to a $k$-type.
\begin{lem} \label{lem:truncation-le}
Let $k,n\ge-2$ with $k\le{}n$ and $A:\type$. Then
$\trunc k{\trunc nA}=\trunc kA$.
\end{lem}
\begin{proof}
We define two maps $f:\trunc k{\trunc nA}\to\trunc kA$ and
$g:\trunc kA\to\trunc k{\trunc nA}$ by
%
\[
f(\tproj k{\tproj na}) \defeq \tproj ka
\qquad\text{and}\qquad
g(\tproj ka) \defeq \tproj k{\tproj na}.
\]
%
The map $f$ is well-defined because $\trunc kA$ is $k$-truncated and also
$n$-truncated (because $k\le{}n$), and the map $g$ is well-defined because
$\trunc k{\trunc nA}$ is $k$-truncated.
The composition $f\circ{}g:\trunc kA\to\trunc kA$ satisfies
$(f\circ{}g)(\tproj ka)=\tproj ka$, hence $f\circ{}g=\idfunc[\trunc kA]$.
Similarly, we have $(g\circ{}f)(\tproj k{\tproj na})=\tproj k{\tproj na}$ and hence $g\circ{}f=\idfunc[\trunc k{\trunc nA}]$.
\end{proof}
% \begin{lem}
% We have $\trunc n{\unit}=\unit$.
% \end{lem}
% \begin{proof}
% Indeed, $\unit$ is $n$-truncated for every $n$ hence $\trunc n{\unit}=\unit$ by
% \cref{reflectPequiv}.
% \end{proof}
\index{truncation!n-truncation@$n$-truncation|)}%
\section{Colimits of \texorpdfstring{$n$}{n}-types}
\label{sec:pushouts}
Recall that in \cref{sec:colimits}, we used higher inductive types to define pushouts of types, and proved their universal property.
In general, a (homotopy) colimit of $n$-types may no longer be an $n$-type (for an extreme counterexample, see \cref{ex:s2-colim-unit}).
However, if we $n$-truncate it, we obtain an $n$-type which satisfies the correct universal property with respect to other $n$-types.
In this section we prove this for pushouts, which are the most important and nontrivial case of colimits.
Recall the following definitions from \cref{sec:colimits}.
\begin{defn}
A \define{span} % in $\P$
\indexdef{span} %
is a 5-tuple $\Ddiag=(A,B,C,f,g)$ with % $A,B,C:\P$ and
$f:C\to{}A$ and $g:C\to{}B$.
\[\Ddiag=\quad\vcenter{\xymatrix{C \ar^g[r] \ar_f[d] & B \\ A & }}\]
\end{defn}
\begin{defn}
Given a span $\Ddiag=(A,B,C,f,g)$ and a type $D$, a %$D:\P$, a
\define{cocone under $\Ddiag$ with base $D$} is a triple $(i, j, h)$
\index{cocone} %
with $i:A\to{}D$, $j:B\to{}D$ and $h : \prd{c:C}i(f(c))=j(g(c))$:
\[\uppercurveobject{{ }}\lowercurveobject{{ }}\twocellhead{{ }}
\xymatrix{C \ar^g[r] \ar_f[d] \drtwocell{^h} & B \ar^j[d] \\ A \ar_i[r] & D
}\]
We denote by $\cocone{\Ddiag}{D}$ the type of all such cocones.
\end{defn}
The type of cocones is (covariantly) functorial.
For instance, given $D,E$ % $D,E:\P$
and a map $t:D\to{}E$, there is a map
\[\function{\cocone{\Ddiag}{D}}{\cocone{\Ddiag}{E}}{c}{\composecocone{t}c}\]
defined by:
\[\composecocone{t}(i,j,h)=(t\circ{}i,t\circ{}j,\mapfunc{t}\circ{}h)\]
And given $D,E,F$, %$:\P$,
functions $t:D\to{}E$, $u:E\to{}F$ and $c:\cocone{\Ddiag}{D}$, we have
\begin{align}
\composecocone{\idfunc[D]}c &= c \label{eq:composeconeid}\\
\composecocone{(u\circ{}t)}c&=\composecocone{u}(\composecocone{t}c). \label{eq:composeconefunc}
\end{align}
\begin{defn}
Given a span $\Ddiag$ of $n$-types, an $n$-type $D$, and a cocone
$c:\cocone{\Ddiag}{D}$, the pair $(D,c)$ is said to be a \define{pushout
of $\Ddiag$ in $n$-types}
\indexdef{pushout!in ntypes@in $n$-types}%
if for every $n$-type $E$, the map
\[\function{(D\to{}E)}{\cocone{\Ddiag}{E}}{t}{\composecocone{t}c}\]
is an equivalence.
\end{defn}
\begin{comment}
We showed in \cref{thm:pushout-ump} that pushouts exist when $\P$ is \type itself, by giving a direct construction in terms of higher
inductive types.
For a general \P, pushouts may or may not exist, but if they do, then they are unique.
\begin{lem}
If $(D,c)$ and $(D',c')$ are two pushouts of $\Ddiag$ in $\P$, then
$(D,c)=(D',c')$.
\end{lem}
\begin{proof}
We first prove that the two types $D$ and $D'$ are equivalent.
Using the universal property of $D$ with $D'$, we see that the following map is an
equivalence
%
\[
\function{(D\to{}D')}{\cocone{\Ddiag}{D'}}{t}{\composecocone{t}c}
\]
%
In particular, there is a function $f:D\to{}D'$ satisfying $\composecocone{f}c=c'$. In the
same way there is a function $g:D'\to{}D$ such that $\composecocone{g}c'=c$.
In order to prove that $g\circ{}f=\idfunc[D]$ we use the universal property of
$D$ for $D$, which says that the following map is an equivalence:
%
\[
\function{(D\to{}D)}{\cocone{\Ddiag}{D}}{t}{\composecocone{t}c}
\]
%
Using the functoriality of $t\mapsto{}\composecocone{t}c$ we see that
\begin{align*}
\composecocone{(g\circ{}f)}c &= \composecocone{g}(\composecocone{f}c) \\
&= \composecocone{g}c' \\
&= c \\
&= \composecocone{\idfunc[D]}c
\end{align*}
hence
$g\circ{}f=\idfunc[D]$, because equivalences are injective. The same argument
with $D'$ instead of $D$ shows that $f\circ{}g=\idfunc[D']$.
Hence $D$ and $D'$ are equal, and the fact that $(D,c)=(D',c')$ follows from
the fact that the equivalence between $D$ and $D'$ we just defined sends $c$
to $c'$.
\end{proof}
\begin{cor}
The type of pushouts of $\Ddiag$ in $\P$ is a mere proposition. In particular if
pushouts merely exist then they actually exist.
\end{cor}
As in the case of pullbacks, if \P is reflective, then pushouts in \P always exist.
However, unlike the case of pullbacks, pushouts in \P are not the same as the pushouts in \type: they are obtained by applying the
reflector.
\end{comment}
In order to construct pushouts of $n$-types, we need to explain how to reflect spans and cocones.
\bgroup
\def\reflect(#1){\trunc n{#1}}
\begin{defn}
Let
\[\Ddiag=\quad\vcenter{\xymatrix{C \ar^g[r] \ar_f[d] & B \\ A & }}\]
be a span. We denote by $\reflect(\Ddiag)$ the following
span of $n$-types:
\[\reflect(\Ddiag)\defeq\quad \vcenter{\xymatrix{\reflect(C) \ar^{\reflect(g)}[r]
\ar_{\reflect(f)}[d] & \reflect(B) \\ \reflect(A) & }}\]
\end{defn}
\begin{defn}
Let $D:\type$ and $c=(i,j,h):\cocone{\Ddiag}{D}$.
We define
\[\reflect(c)=(\reflect(i),\reflect(j),\reflect(h)):
\cocone{\reflect(\Ddiag)}{\reflect(D)}\]
where $\reflect(h): \reflect(i) \circ \reflect(f) \htpy \reflect(j) \circ \reflect(g)$ is defined as in \cref{thm:trunc-htpy}.
% \[\reflect(h):\prd{c:\reflect(C)}\reflect(i)(\reflect(f)(c))=\reflect(j)(\reflect(g)(c))\]
% is defined in the following way:
\end{defn}
\egroup
We now observe that the maps from each type to its $n$-truncation assemble into a map of spans, in the following sense.
\begin{defn}
Let
\[\Ddiag=\quad\vcenter{\xymatrix{C \ar^g[r] \ar_f[d] & B \\ A & }}
\qquad\text{and}\qquad
\Ddiag'=\quad\vcenter{\xymatrix{C' \ar^{g'}[r] \ar_{f'}[d] & B' \\ A' & }}
\]
be spans.
A \define{map of spans}
\indexdef{map!of spans}%
$\Ddiag \to \Ddiag'$ consists of functions $\alpha:A\to A'$, $\beta:B\to B'$, and $\gamma:C\to C'$ and homotopies $\phi: \alpha\circ f \htpy f'\circ \gamma$ and $\psi:\beta\circ g \htpy g' \circ \gamma$.
\end{defn}
Thus, for any span $\Ddiag$, we have a map of spans $\tprojf[\Ddiag] n : \Ddiag \to \trunc n\Ddiag$ consisting of $\tprojf[A]n$, $\tprojf[B]n$, $\tprojf[C]n$, and the naturality homotopies $\mathsf{nat}^f_n$ and $\mathsf{nat}^g_n$ from~\eqref{eq:trunc-nat}.
We also need to know that maps of spans behave functorially.
Namely, if $(\alpha,\beta,\gamma,\phi,\psi):\Ddiag \to \Ddiag'$ is a map of spans and $D$ any type, then we have
\[ \function{\cocone{\Ddiag'}{D}}{\cocone{\Ddiag}{D}}{(i,j,h)}{(i\circ \alpha,j\circ\beta, k)} \]
where $k: \prd{z:C} i(\alpha(f(z))) = j(\beta(g(z)))$ is the composite
\begin{equation}\label{eq:mapofspans-htpy}
\xymatrix{
i(\alpha(f(z))) \ar@{=}[r]^{\apfunc{i}(\phi)} &
i(f'(\gamma(z))) \ar@{=}[r]^{h(\gamma(z))} &
j(g'(\gamma(z))) \ar@{=}[r]^{\apfunc{j}(\psi)} &
j(\beta(g(z))). }
\end{equation}
We denote this cocone by $(i,j,h) \circ (\alpha,\beta,\gamma,\phi,\psi)$.
Moreover, this functorial action commutes with the other functoriality of cocones:
\begin{lem}\label{thm:conemap-funct}
Given $(\alpha,\beta,\gamma,\phi,\psi):\Ddiag \to \Ddiag'$ and $t:D\to E$, the following diagram commutes:
\begin{equation*}
\vcenter{\xymatrix{
\cocone{\Ddiag'}{D}\ar[r]^{t \circ {\blank}}\ar[d] &
\cocone{\Ddiag'}{E}\ar[d]\\
\cocone{\Ddiag}{D}\ar[r]_{t \circ {\blank}} &
\cocone{\Ddiag}{E}
}}
\end{equation*}
\end{lem}
\begin{proof}
Given $(i,j,h):\cocone{\Ddiag'}{D}$, note that both composites yield a cocone whose first two components are $t\circ i\circ \alpha$ and $t\circ j\circ\beta$.
Thus, it remains to verify that the homotopies agree.
For the top-right composite, the homotopy is~\eqref{eq:mapofspans-htpy} with $(i,j,h)$ replaced by $(t\circ i, t\circ j, \apfunc{t}\circ h)$:
\begin{equation*}
\xymatrix@+2.8em{
{t \, i \, \alpha \, f \, z} \ar@{=}[r]^{\apfunc{t\circ i}(\phi)} &
{t \, i \, f' \, \gamma \, z} \ar@{=}[r]^{\apfunc{t}(h(\gamma(z)))} &
{t \, j \, g' \, \gamma \, z} \ar@{=}[r]^{\apfunc{t\circ j}(\psi)} &
{t \, j \, \beta \, g \, z}
}
\end{equation*}
(For brevity, we are omitting the parentheses around the arguments of functions.)
On the other hand, for the left-bottom composite, the homotopy is $\apfunc{t}$ applied to~\eqref{eq:mapofspans-htpy}.
Since $\apfunc{}$ respects path-concatenation, this is equal to
\begin{equation*}
\xymatrix@+2.8em{
{t \, i \, \alpha \, f \, z} \ar@{=}[r]^{\apfunc{t}(\apfunc{i}(\phi))} &
{t \, i \, f' \, \gamma \, z} \ar@{=}[r]^{\apfunc{t}(h(\gamma(z)))} &
{t \, j \, g' \, \gamma \, z} \ar@{=}[r]^{\apfunc{t}(\apfunc{j}(\psi))} &
{t \, j \, \beta \, g \, z}. }
\end{equation*}
But $\apfunc{t}\circ \apfunc{i} = \apfunc{t\circ i}$ and similarly for $j$, so these two homotopies are equal.
\end{proof}
Finally, note that since we defined $\trunc nc : \cocone{\trunc n \Ddiag}{\trunc n D}$ using \cref{thm:trunc-htpy}, the additional condition~\eqref{eq:trunc-htpy} implies
\begin{equation}
\tprojf[D] n \circ c = \trunc n c \circ \tprojf[\Ddiag]n. \label{eq:conetrunc}
\end{equation}
for any $c:\cocone{\Ddiag}{D}$.
Now we can prove our desired theorem.
\begin{thm}
\label{reflectcommutespushout}
\index{universal!property!of pushout}%
Let $\Ddiag$ be a span and $(D,c)$ its pushout.
Then $(\trunc nD,\trunc n c)$ is a pushout of $\trunc n\Ddiag$ in $n$-types.
\end{thm}
\begin{proof}
Let $E$ be an $n$-type, and consider the following diagram:
\bgroup
\def\reflect(#1){\trunc n{#1}}
\begin{equation*}
\vcenter{\xymatrix{
(\trunc nD \to E)\ar[r]^-{\blank\circ \tprojf[D] n}\ar[d]_{\blank\circ \trunc nc} &
(D\to E)\ar[d]^{\blank\circ c}\\
\cocone{\trunc n \Ddiag}{E}\ar[r]^-{\blank\circ \tprojf[\Ddiag]n}\ar@{<-}[d]_{\ell_1} &
\cocone{\Ddiag}{E}\ar@{<-}[d]^{\ell_2}\\
(\reflect(A)\to{}E)\times_{(\reflect(C)\to{}E)}(\reflect(B)\to{}E)\ar[r] &
(A\to{}E)\times_{(C\to{}E)}(B\to{}E)
}}
\end{equation*}
\egroup
The upper horizontal arrow is an equivalence since $E$ is an $n$-type, while $\blank\circ c$ is an equivalence since $c$ is a pushout cocone.