-
Notifications
You must be signed in to change notification settings - Fork 23
/
intro-uf.tex
4585 lines (4076 loc) · 219 KB
/
intro-uf.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
%% this chapter sets up the foundational system, which is Univalent Foundations
\chapter{An introduction to univalent mathematics}
\label{ch:univalent-mathematics}
\section{What is a type?}
\label{sec:what-is-a-type}
In some computer programming languages, all variables are introduced along with a declaration of the type of thing they will refer to. Knowing
the type of thing a variable refers to allows the computer to determine which expressions in the language are \emph{grammatically well
formed}\footnote{The grammar of a programming language consists of all the language's rules. A statement or expression in a programming
language is grammatically well formed if it follows all the rules.}, and hence valid. For example, if $s$ is a
string\footnote{A \emph{string} is a sequence of characters, such as ``qwertyuiop''.} and $x$ is a real number, we may write $1/x$, but we may not write $1/s$.%
\footnote{In a programming language, the well formed expression $1/x$ may produce a run-time error if $x$ happens to have the value $0$.}
To enable the programmer to express such declarations, names are introduced to refer to the various types of things. For example, the name
$\bool$ may be used to declare that a variable is a Boolean value\footnote{A Boolean value is either \emph{true} or \emph{false}.},
$\integer$ may refer to 32-bit integers, and $\real$ may refer to 64-bit floating point numbers\footnote{An example of a \emph{floating
point number} is $.625 \times 2^{33}$ -- the \emph{mantissa} $.625$ and the \emph{exponent} $33$ are stored inside the floating point number.
The ``point'', when the number is written in base $2$ notation, is called ``floating'', because its position is easily changed by modifying the exponent.}.
Types occur in mathematics, too, and are used in the same way: all variables are introduced along with a declaration of the type of thing they
will refer to.\index{type} For example, one may say ``consider a real number $x$'', ``consider a natural number $n$'', ``consider a point $P$ of
the plane'', or ``consider a line $L$ of the plane''. After that introduction, one may say that the \emph{type} of $n$ is \emph{natural number} and
that the \emph{type} of $P$ is \emph{point of the
plane}. Just as in a computer program, type declarations such as those are used to determine which mathematical statements are grammatically
well formed. Thus one may write ``$P$ lies on $L$'' or $1/x$, but not ``$L$ lies on $P$'' nor $1/L$.\footnote{In mathematics there are no
``run-time'' errors; rather, it is legitimate to write the expression $1/x$ only if we already know that $x$ is a non-zero real number.}
Often ordinary English writing is good enough for such declarations in mathematics expositions, but, for convenience, mathematicians usually
introduce symbolic names to refer to the various types of things under discussion. For example, the name $\NN$ is usually used when declaring
that a variable is a natural number, the name $\ZZ$ is usually used when declaring that a variable is an integer, and the name $\RR$ is usually
used when declaring that a variable is a real number. Ways are also given for constructing new type names from old ones: for example, the name
$\RR\times\RR$ may be used when declaring that a variable is a point of the plane, for it conveys the information that a point of the plane is a
pair of real numbers.
Once one becomes accustomed to the use of names such as $\NN$ in mathematical writing and speaking, it is natural to take the next step and
regard those names as denoting things that exist. Thus, we shall refer to $\NN$ as the \emph{type of all natural numbers}, and we will think of
it as a mathematical object in its own right. Intuitively and informally, it is a collection whose members (or \emph{elements}) are the natural
numbers.
Once we view the various types as existing as mathematical objects, they become worthy of study. The language of mathematics is thereby
improved, and the scope of mathematics is broadened. For example, we can consider statements such as ``$\NN$ is infinite'' and to try to prove
it.
Historically, there was some hesitation\footnote{TO DO : Include some pointers to discussions of potential infinity and actual infinity, perhaps.} about
introducing the collection of all natural numbers as a mathematical object, perhaps because if one were to attempt to build the collection from
nothing by adding numbers to it one at a time, it would take an eternity to complete the assembly. We won't regard that as an obstacle.
We have said that the types of things are used to determine whether mathematical statements are well formed.
Therefore, if we expect ``$\NN$ is infinite'' to be a well-formed statement, we'll have to know what type of thing $\NN$ is, and we'll
have to have a name for that type. Similarly, we'll have to know what type of thing that type is, and we'll have to have a name for it,
and so on forever. Indeed, all of that is part of what will be presented in this chapter.
\section{Types, elements, families, and functions}
\label{univalent-mathematics}
In this section we build on the intuition imparted in the previous section.
In \emph{univalent mathematics},\index{mathematics!univalent}\footnote{The term ``univalent'' is a word coined by Vladimir Voevodsky, who
introduced it to describe his principle that types that are \emph{equivalent} in a certain sense can be identified with each other. The
principle is stated precisely in \cref{def:univalence}. As Voevodsky explained, the word comes from a Russian translation of a mathematics
book, where the English mathematical term ``faithful'' was translated into Russian as the Russian word that sounds like ``univalent''. He also
said ``Indeed these foundations seem to be faithful to the way in which I think about mathematical objects in my head.''} types are used to
classify all mathematical objects. Every mathematical object is an \emph{element} (or a \emph{member}) of some \emph{type}. Before
one can talk about an object of a certain type, one must introduce the type itself. There are enough ways to form new types from old ones to
provide everything we need to write mathematics.
One expresses the declaration that an object $a$ is an element of the \emph{type} $X$ by writing $a:X$.%
\footnote{The notation in mathematics based on \emph{set theory} that corresponds (sort of) to this is $a \in X$.}
\index{element}
\glossary(2:){${:}$}{element judgment}
Using that notation, each variable $x$ is introduced along with a declaration of the form $x:X$, which declares that $x$ will refer to something
of type $X$, but provides no other information about $x$. The declared types of the variables are used to determine which statements of the
theory are grammatically well formed.
After introducing a variable $x:X$, it may be possible to form an expression $T$ representing a type, all of whose components have
already been given a meaning.
(Here the variable $x$ is regarded also as having already been given a meaning, even though the only thing known about it is its type.)
To clarify the dependence of $T$ on $x$ primarily, we may write $T(x)$ (or $T_x$) instead of $T$.
Such an expression will be called a \emph{family of types} \index{family!of types} parametrized by the variable $x$ of type $X$.
Such a family provides a variety of types, for, if $a$ is any expression denoting an object of $X$, one may replace all
occurrences of $x$ by $a$ in $T$, thereby obtaining a new expression representing a type, which may be regarded as a \emph{member}
and which may be denoted by $T(a)$.
Naturally, if the expression $T$ doesn't actually involve the variable $x$, then the members of the family are all the same,
and we'll refer to the family as a \emph{constant family} of types.
Here's an example of a family of types: let $T$ be the type
of all natural numbers greater than $2$. For any element $n$ of $T$
we let $P_n$ be the type of $n$-sided polygons in the plane.
It gives a family of types parametrized by the elements of $T$.%
\footnote{\color{casred} See if you like my solution. If so, remove footnote.}
One of the members of the family is the type $P_5$ of all pentagons in the plane.
A family of types may be parametrized by more than one variable. For example, after introducing a variable $x:X$ and a family of types $T$
parametrized by $x$, we may introduce a variable $t:T$. Then it may be possible to form an expression $S$ representing a type that involves the
variables $x$ and $t$. Such an expression will be called a family of types parametrized by $x$ and $t$, and we may write $S(x,t)$ instead of
$S$ to emphasize the dependence on $x$ and $t$. The same sort of thing works with more variables.
After introducing a variable $x:X$ and a family of types $T$, it may be possible to form an expression $e$ of type $T$, all of whose components have already been
given a meaning.
Such an expression will also be called a \emph{family of elements of $T$} \index{family!of elements} parametrized by the elements of $X$, when
we wish to focus on the dependence of $e$ (and perhaps $T$) on the variable $x$.
To clarify the dependence of $e$ on $x$ primarily, we may write $e(x)$ (or $e_x$) instead of $e$.
Such a family provides a variety of elements of members of the family $T$, for, if $a$ is any expression denoting an object of $X$, one may replace all
occurrences of $x$ by $a$ in $e$ and in $T$, thereby obtaining an element of $T(a)$, which may be regarded as a \emph{member} of the family $e$
and which will be denoted by $e(a)$.
Naturally, if the expressions $e$ and $T$ don't actually involve the variable $x$, then the members of the family are all the same,
and we'll refer to the family as a \emph{constant family} of elements.
Here's an example of a family of elements in a constant family of types: we let $n$ be a natural number and consider the real number $\sqrt n$.
It gives a family of real numbers parametrized by the natural numbers.
(The family may also be called a \emph{sequence} of real numbers).
One of the members of the family is $\sqrt{11}$.
Here's an example of a family of elements in a (non-constant) family of types.
As above, let $T$ be the type of all natural numbers greater than $2$ and let
$P_n$ be the type of $n$-sided polygons in the plane, for any $n:T$.
Now consider the regular $n$-sided polygon $p_n$ of radius $1$ with
a vertex on the positive $x$-axis, for any $n:T$. We see that $p_n : P_n$.
One of the members of this family of \emph{elements} $p_n$ is the regular
pentagon $p_5$ of radius $1$ with a vertex on the positive $x$-axis.
The pentagon $p_5$ is an element of the type $P_5$, which is a member of the
family of \emph{types} $P_n$ ($n:T$). In short, $5:T$ and $p_5 : P_5$.
The type $X$ containing the variable for a family of types or a family of elements is called the \emph{parameter type}\index{parameter type} of
the family.
Just as a family of types may depend on more than one variable, a family of elements may also depend on more than one variable.
Families of elements can be enclosed in mathematical objects called \emph{functions}\index{function} (or \emph{maps}\index{map}), as one might
expect.
Let $e$ be a family of elements of a family of types $T$,
both of which are parametrized by the elements $x$ of $X$. We use the notation $x \mapsto e$ for the function that sends an element $a$ of $X$
to the element $e(a)$ of $T(a)$; the notation $x \mapsto e$ can be read as ``$x$ maps to $e$'' or ``$x$ goes to $e$''. (Recall that $e(a)$ is
the expression that is obtained from $e$ by replacing all occurrences of $x$ in $e$ by $a$.) If we name the function $f$, then that element of
$T$ will be denoted by $f(a)$. The \emph{type} of the function $x \mapsto e$ is called a \emph{product type} and will be denoted by
$\prod_{x:X} T(x)$.\index{product type}\glossary(916Pi){$\prodop_{x:X}T(x)$}{product type of dependent functions}
If $T$ is a constant family of types, then the type will also be
called a \emph{function type} and will be denoted by $X \to T$\glossary(2fun){$\protect\to$}{function type}. Thus when we write $f : X \to T$,
we mean that $f$ is an element of the type $X \to T$, and we are saying that $f$ is a function from $X$ to $T$. The type $X$ may be called the
\emph{domain} of $f$, and the type $T$ may be called the \emph{codomain} of $f$.
An example of a function is the function $n \mapsto \sqrt n$ of type $\NN \to \RR$.
Another example of a function is the function $n \mapsto p_n$ of type $\prod_{n:\NN} P_n$, where $P_n$ is the type of polygons introduced above,
and $p_n$ is the polygon introduced above.
Another example of a function is the function $m \mapsto (n \mapsto m+n)$ of type $\NN \to (\NN \to \NN)$. It is a function that accepts a
natural number as argument and returns a function as its value. The function returned is of type $\NN \to \NN$. It accepts a natural number
as argument and returns a natural number as value.
The reader may wonder why the word ``product'' is used when speaking of product types. To motivate that, we consider a simple example
informally. We take $X$ to be a type with just two elements, $b$ and $c$. We take $T(x)$ to be a family of types parametrized by the elements
of $X$, with $T(b)$ being a type with $5$ elements and $T(c)$ being a type with $11$ elements. Then the various functions $f$ of type
$\prod_{x:X} T(x)$ are plausibly obtained by picking a suitable element for $f(b)$ from the $5$ possibilities in $T(b)$ and by picking a
suitable element for $f(c)$ from the $11$ possibilities in $T(c)$. The number of ways to make both choices is $5 \times 11$, which is a
\emph{product} of two numbers. Thus $\prod_{x:X} T(x)$ is sort of like the product of $T(b)$ and $T(c)$, at least as far as counting is
concerned.
The reader may wonder why we bother with functions at all: doesn't the expression $e$ serve just as well as the function $x \mapsto e$, for all
practical purposes? The answer is no. One reason is that the expression $e$ doesn't inform the reader that the variable under consideration is
$x$. Another reason is that we may want to use the variable $x$ for elements of a different type later on: then $e(x)$ is no longer well
formed. For example, imagine first writing this: ``For a natural number $n$ we consider the real number $\sqrt n$'' and then writing this:
``Now consider a triangle $n$ in the plane.'' The result is that $\sqrt n$ is no longer usable, whereas the function $n \mapsto \sqrt n$ has
enclosed the variable and the family into a single object and remains usable.\footnote{Students of trigonometry are already familiar with the
concept of function, as something enclosed this way. The sine and cosine functions, $\sin$ and $\cos$, are examples.}
Once a family $e$ has been enclosed in the function $x \mapsto e$, the variable $x$ is referred to as a \emph{dummy variable}\index{dummy
variable} or as a \emph{bound variable}\index{bound variable}.\footnote{Students of calculus are familiar with the concept of dummy variable
and are accustomed to using identities such as $\int_a^b f(t)\,dt = \int_a^b f(x)\,dx$.} This signifies that the name of the variable no longer
matters, in other words, that $x \mapsto e(x)$ and $t \mapsto e(t)$ may regarded as identical. Moreover, the variable $x$ that occurs inside
the function $x \mapsto e$ is regarded as unrelated to variables $x$ which may appear elsewhere in the discussion.
If the variable $x$ in our notation $x \mapsto e(x)$ is a dummy variable, and its name doesn't matter, then we may consider the possibility of
not specifying a variable at all. We introduce now a methodical way to do that, by replacing the occurrences of the variable $x$ in the
expression $e(x)$ by an \emph{underscore},\index{underscore}
yielding $e(\blank)$ as alternative notation for the function $x \mapsto e(x)$.
For example, the
notation $\sqrt{\vphantom{n}\blank}$ can serve as alternative notation for the function $n \mapsto \sqrt n$ introduced above, and $2 + \blank$ can serve as
alternative notation for the function $n \mapsto 2 + n$ of type $\NN \to \NN$.
We have mentioned above the possibility of giving a name to a function.
We expand on that now by introducing notation for making and for using \emph{definitions}.\index{definition}
The notation $x \defeq z$ will be an announcement that we are defining
the expression $x$ to be the expression $z$, all of whose components have already been given a meaning;
in that case, we will say that $x$ has been \emph{defined} to be (or to mean) $z$.%
\glossary(2:=){$\protect\defeq$}{definition}
The forms allowed for the expression $x$ will be made clear by the examples we give.
For example, after writing $n \defeq 12$, we will say that $n$ has
been defined to be $12$.
For another example, naming the function $x \mapsto e(x)$ as $f$
(as we did above) can be done by writing $f \defeq ( x \mapsto e(x) )$.
Alternatively and more traditionally, we may write $f(x) \defeq e(x)$.
Both mean that $f$ has been defined to be $x \mapsto e(x)$
and that, consequently, $f(a)$ has been defined to be $e(a)$,
for any element $a$ of $X$.
The notation $b \jdeq c$ will denote the statement that the expressions $b$ and $c$ become the same thing if all the subexpressions within $b$
or $c$ are expanded according to their definitions, if any; in that case, we will say that $b$ and $c$ are \emph{the same by
definition}\glossary(2==){$\jdeq$}{equality by definition}. For example, after writing $n \defeq 12$ and $m \defeq n$, we may say that $j + 12
\jdeq j + m$ and that $m \times 11 \jdeq 12 \times 11$.
Whenever two expressions are the same by definition, we may replace one with the other inside any other expression, because the expansion of
definitions is regarded as trivial and transparent.
We proceed now to the promised example. Consider functions $f : X \to Y$ and $g : Y \to Z$. We define the \emph{composite} function
$g \circ f : X \to Z$ by setting $g \circ f \defeq (a \mapsto g(f(a)))$.\glossary(2fundef){$\mapsto$}{``maps to'', function definition}\index{composition!of functions}
In other words, it
is the function that sends an arbitrary element $a$ of $X$ to $g(f(a))$ in $Z$. (The expression $g \circ f$ may be read as ``$g$ circle $f$''
or as ``$g$ composed with $f$''.) The composite function $g \circ f$ may also be denoted simply by $gf$.\glossary(2circ){$\circ$}{function composition}
Now consider functions $f : X \to Y$, $g : Y \to Z$, and $h : Z \to W$. Then $(h \circ g) \circ f$ and $h \circ (g \circ f)$ are the same by
definition, since applying the definitions within expands both expressions to $a \mapsto h(g(f(a)))$. In other
words, we have established that $(h \circ g) \circ f \jdeq h \circ (g \circ f)$. Thus, we may write $h \circ g \circ f$ for
either expression, without danger of confusion.
One may define the identity function $\id_X : X \to X$ by setting
$\id_X \defeq (a \mapsto a)$.\index{function!identity}
\glossary(id){$\id$}{identity function} Application of definitions shows that
$f \circ \id_X$ is the same by definition as $a \mapsto f(a)$, which, by a standard convention, which we adopt\footnote{The convention that
$f \jdeq (a \mapsto f(a))$ is referred to as the \emph{$\eta$-rule}\glossary(907-rule){$\eta$}{$\eta$-rule} in the jargon of type theory.}, is to be regarded as the same as $f$. In
other words, we have established that $f \circ \id_X \jdeq f$.%
\phantomsection\label{page:idofetaf}
A similar computation applies to $\id_Y \circ f$.
In the following sections we will present various other elementary types and elementary ways to make new types from old ones.
\section{Universes}
\label{sec:universes}
In~\cref{univalent-mathematics} we have introduced the objects known as \emph{types}. They have \emph{elements}, and the type an
element belongs to determines the type of thing that it is. At various points in the sequel, it will be convenient for types also to be
elements, for that will allow us, for example, to enclose families of types in functions. To achieve this
convenience, we introduce types that are \emph{universes}. Some care is required, for the first temptation is to posit a
single new type $\UU$ called \emph{the universe}, so that every type is realized as an element of $\UU$. This universe would be ``the type of
all types'', but introducing it would lead to an absurdity, for roughly the same reason that introduction of a ``set of all sets'' leads to the absurdity
in traditional mathematics known as Russell's paradox.\footnote{%
In fact, type theory can trace its origins to Russell's paradox,
announced in a 1902 letter to Frege as follows:\\
\begin{adjustwidth}{\parindent}{}
There is just one point where I have encountered a difficulty.
You state that a function too, can act as the indeterminate element.
This I formerly believed,
but now this view seems doubtful to me because of the following contradiction.
Let $w$ be the predicate: to be a predicate that cannot be predicated of itself.
Can $w$ be predicated of itself? From each answer its opposite follows.
Therefore we must conclude that $w$ is not a predicate.
Likewise there is no class (as a totality) of those classes which,
each taken as a totality, do not belong to themselves.
\end{adjustwidth}
To which Frege replied:
\begin{adjustwidth}{\parindent}{}
Incidentally, it seems to me that the expression
``a predicate is predicated of itself'' is not exact.
A predicate is as a rule a first-level function,
and this function requires an object as argument
and cannot have itself as argument (subject).
\end{adjustwidth}
Russell then quickly added \emph{Appendex~B} to his
\emph{Principles of Mathematics} (1903), in which he said that
``it is the distinction of logical types that is the key to the whole mystery'',
where types are the \emph{ranges of significance} of variables.
For more on the history of type theory,
see~\citeauthor{sep-type-theory}\footnotemark{}.}\footcitetext{sep-type-theory}
Some later approaches to set theory included the notion of a \emph{class}, with the collection of all sets being the primary example of a class.
Classes are much like sets, and every set is a class, but not every class is a set.
Then one may wonder what sort of thing the collection of all classes would be. Such
musings are resolved in univalent mathematics as follows.
\begin{enumerate}
\item There are some types called \emph{universes}.\index{universe}\glossary(UU){$\protect\UU$}{universe}
\item If $\UU$ is a universe, and $X : \UU$ is an element of $\UU$, then $X$ is a type.
\item If $X$ is a type, then it appears as an element in some
universe $\UU$. Moreover, if $X$ and $Y$ are types,
then there is a universe $\UU$ containing both of them.
This universe $\UU$ also contains the type $X\to Y$ and similar
types constructed from $X$ and $Y$.
\item\label{it:cumulative} If $\UU$ and $\UU'$ are universes,
$\UU:\UU'$, $X$ is a type, and $X:\UU$, then also $X:\UU'$.
(Thus we may regard $\UU'$ as being \emph{larger} than $\UU$.)
\item There is a particular universe $\UU_0$, which we single out to serve
as a repository for certain basic types to be introduced in the sequel.
Moreover, $\UU_0 : \UU$ for every other universe $\UU$,
and thus $\UU_0$ is the \emph{smallest} universe.
\end{enumerate}
It follows from the properties above that there are an infinite number of
universes, for each one is an element of a larger one. For the sake of
clarity, throughout this book, we use an infinite sequence of universes
$\UU_0 : \UU_1 : \UU_2 : \dots$.
Now suppose we have a type $X$ and a family $T(x)$ of types parametrized by a variable $x$ of type $X$. Choose a universe $\UU$ with $T(x) : \UU$.
Then we can make a function of type $X \to \UU$, namely $f \defeq (x \mapsto T(x))$. Conversely, if $f'$ is a function of type $X \to \UU$, then
we can make a family of types parametrized by $x$, namely $T' \defeq f'(x)$. The flexibility offered by this correspondence between families of
types in $\UU$ and functions to $\UU$ will often be used.
\section{The type of natural numbers}
\label{sec:natural-numbers}
Here are Peano's rules\footcite{peano-principia} for constructing the natural numbers in the form that is used in type theory.
\begin{enumerate}[label=(P\arabic*),ref=(P\arabic*)]
\item\label{P1} there is a type called $\NN$ in the universe $\UU_0$
(whose elements will be called \emph{natural numbers});%
\glossary(N){$\protect\NN$}{the type of natural numbers, Peano's rules, \cref{P1}}
\item\label{P2} there is an element of $\NN$ called $0$, called \emph{zero};%
\glossary(80){$0$}{the natural number zero, Peano's rules, \cref{P2}}\index{zero}
\item\label{P3} if $m$ is a natural number, then there is also a natural number $\Succ(m)$, called the \emph{successor} of $m$;%
\glossary(succ){$\protect\Succ$}{the successor function on $\NN$, Peano's rules, \cref{P3}}%
\index{successor}
\item\label{P4} suppose we are given:
\begin{enumerate}
\item a family of types $X(m)$ parametrized by a variable $m$ of type $\NN$;
\item an element $a$ of $X(0)$; and
\item a family of functions $g_m : X(m) \to X(\Succ(m))$.
\end{enumerate}
Then from those data we are provided with a family of elements $f(m) : X(m)$,
satisfying $f(0) \jdeq a$ and $f(\Succ(m)) \jdeq g_m(f(m))$.
\end{enumerate}
The first three rules present few problems for the reader. They provide us with the smallest natural number $0:\NN$, and we may introduce as
many others as we like with the following definitions.
\begin{align*}
1 & \defeq \Succ(0) \glossary(81){$1$}{the natural number 1} \\
2 & \defeq \Succ(1) \glossary(82){$2$}{the natural number 2} \\
3 & \defeq \Succ(2) \glossary(83){$3$}{the natural number 3} \\
& \quad \vdots
\end{align*}
You may recognize rule \ref{P4} as ``the principle of mathematical induction''.\footnote{%
Rule \ref{P4} and our logical framework are stronger than in Peano's original formulation, and this allows us to omit some rules that Peano had to include:
that different natural numbers have different successors; and that no number has $0$ as its successor. Those omitted rules
remain true in this formulation and can be proved from the other rules, after we have introduced the notion of equality in
our logical framework.}
We will refer to it simply as ``induction on $\NN$''.
You may also recognize the function $f$ in \ref{P4} as ``defined by recursion''.
The point of the induction principle is that the type $X(m)$ of
$f(m)$ may depend on $m$. An important special case is when $X(m)$
does not depend on $m$, that is, when $X(m)\defeq Y$ for some type Y.
In this non-dependent case we refer to the principle as
``the recursion principle for $\NN$''. In other words, throughout
this book, the difference between an induction principle and the
corresponding recursion principle is that in the latter principle
the type family is constant.
\index{principle!induction}\index{induction principle}
\index{principle!recursion}\index{recursion principle}
The resulting family $f$ may be regarded as having been defined inductively
by the two declarations $f(0) \defeq a$ and $f(\Succ(m)) \defeq g_m(f(m))$,
and indeed, we will often simply write such a pair of declarations as a shorthand way of applying rule \ref{P4}.
The two declarations cover the two ways of introducing elements of $\NN$ via the use of the two rules \ref{P2} and \ref{P3}.
(In terms of computer programming, those two declarations amount to the code for a recursive subroutine that can handle any incoming natural number.)
With that notation in hand, speaking informally, we may regard \ref{P4} above as defining the family $f$ by the following infinite sequence of definitions.
\begin{align*}
f(0) & \defeq a \\
f(1) & \defeq g_0(a) \\
f(2) & \defeq g_1(g_0(a)) \\
f(3) & \defeq g_2(g_1(g_0(a))) \\
& \quad \vdots
\end{align*}
(The need for the rule \ref{P4} arises from our inability to write down an infinite sequence of definitions in a finite amount of space, and
from the need for $f(m)$ to be defined when $m$ is a variable of type $\NN$, and thus is not known to be equal to $0$, nor to $1$, nor to $2$,
etc.)
We may use induction on $\NN$ to define of \emph{iteration} of functions. Let $Y$ be a type, and suppose we have a function $e : Y \to Y$. We
define by induction on $\NN$ the $m$-fold \emph{iteration} $e^m : Y \to Y$ by setting $e^0 \defeq \id_Y$ and $e^{\Succ(m)}\defeq e\circ e^m$.
(Here we apply rule \ref{P4} with the the type $Y \to Y$ as the family of types $X(m)$, the identity function $\id_Y$ for $a$, and the function
$d \mapsto e\circ d$ for the family $g_m : (Y\to Y)\to(Y\to Y)$ of functions.)
We may now define addition of natural numbers by induction on $\NN$. For natural numbers $n$ and $m$ we define $n+m : \NN$ by induction on
$\NN$ with respect to the variable $m$ by setting $n+0\defeq n$ and $n+\Succ(m)\defeq \Succ(n+m)$. (The reader should be able to extract the
family $X(m)$, the element $a$, and the family of functions $g_m$ from that pair of definitions.) Application of definitions shows, for
example, that $2+2$ and $4$ are the same by definition, and thus we may write $2+2 \jdeq 4$, because both expressions reduce to
$\Succ(\Succ(\Succ(\Succ(0))))$.
Similarly we define the product $m \cdot n : \NN$ by induction on $m$ by setting setting $ 0 \cdot n \defeq 0$ and
$ \Succ(m) \cdot n \defeq (m \cdot n) + n$.
Alternatively (and equivalently) we may use iteration of functions to define addition and multiplication, by setting $n+m \defeq \Succ^m(n)$ and
$m \cdot n \defeq ( i \mapsto i + n )^m (0) $.
Finally, we may define the factorial function%
\index{factorial function}\index{function!factorial}
$\fact : \NN \to \NN$ by induction on $\NN$, setting $\fact(0) \defeq 1$ and
$\fact(\Succ(m)) \defeq \Succ(m) \cdot \fact(m)$. (One can see that this definition applies rule \ref{P4} with $X(m) \defeq \NN$, with $1$ for
$a$, and with the function $n \mapsto \Succ(m) \cdot n$ for $g_m$.) Application of the definitions shows, for example, that $\fact(3) \jdeq 6$, as
the reader may verify.
\section{Identity types}
\label{sec:identity-types}
One of the most important types is the \emph{identity type},
which implements a notion of equality.
Identity types are formed of a type and two elements of that type;
we shall have no need to compare elements of different types.
Here are the rules for constructing and using identity types.
\begin{enumerate}[label=(E\arabic*),ref=(E\arabic*)]\label{rules-for-equality}
\item\label{E1}
for any type $X$ and for any elements $a$ and $b$ of it, there is an \emph{identity type} $a \eqto b$;%
\glossary(2=){$\xrightarrow =$}{identity type, \cref{E1}}%
\index{identity type}
moreover, if $X$ is an element of a universe $\UU$, then so is $a \eqto b$.
\marginnote{When the type of $a$ and $b$ is not clear
we may clarify it by writing $a \eqto_X b$.}
\item\label{E2} for any type $X$ and for any element $a$ of it, there is an element $\refl a$ of type $a \eqto a$
(the name $\refl{}$ comes from the word ``reflexivity'')%
\glossary(refl){$\protect\refl{a}$}{reflexivity, identity type, \cref{E2}}
\item\label{E3} suppose we are given:
\begin{enumerate}
\item a type $X$ and an element $a:X$;
\item a family of types $P(b,e,\dots)$ parametrized by a variable $b$ of type $X$, a variable $e$ of type $a \eqto b$, and perhaps some
further variables; and
\item an element $p$ of $P(a,\refl a,\dots)$.
\end{enumerate}
Then from those data we are provided with a family of elements $f(b,e,\dots) : P(b,e,\dots)$.
Moreover, $f(a,\refl a,\dots) \jdeq p$.
\end{enumerate}
We will refer to an element $i$ of $a \eqto b$ as an
\emph{identification} of $a$ with $b$.
Since the word ``identification'' is a long one,
we may also refer to $i$ as a \emph{path} from $a$ to
$b$ -- this has the advantage of incorporating the intuition that an identification may proceed gradually through intermediate steps.%
\index{identification}
The need to record, using the element $i$, the way we identify $a$
with $b$ may come as a surprise, since normally, in mathematics, one is
accustomed to regarding $a$ as either equal to $b$ or not.
However, this reflects a situation commonly encountered in geometry
when \emph{congruence} of geometric figures is considered.%
\index{congruence}
For example, in Euclidean space, two equilateral triangles of the same size are congruent in six (different)
ways.\footnote{Six, since we allow reflections, otherwise there are only three.\par
\begin{tikzpicture}[tri/.style={draw,regular polygon,regular polygon sides=3,minimum height=6em}]
\node[tri,rotate=-15]{};
\begin{scope}[xshift=7em]
\node[tri,rotate=15]{};
\end{scope}
\end{tikzpicture}
}
The chief novelty of univalent mathematics is that the basic logical notion of equality, as implemented by the identity types $a \eqto b$, is carefully
engineered to accommodate notions of congruence and symmetry from diverse areas of mathematics, including geometry. Exposing that point of view
in the context of geometry is the main point of this book.
In light of the analogy with geometry just introduced,
we will refer to an element $i$ of $a \eqto a$ as a \emph{symmetry} of $a$.%
\index{symmetry!of an element}
Think, for example, of a congruence of a triangle with itself.
An example of a non-trivial symmetry will be seen in \cref{xca:C2}.
Consider the identity type $\fact(2) \eqto 2$, where $\fact$ denotes the factorial function defined in \cref{sec:natural-numbers}.
Expansion of the definitions in $\fact(2) \eqto 2$ simplifies it to $\Succ(\Succ(0)) \eqto \Succ(\Succ(0))$,
so we see from rule \ref{E2} that $\refl{\Succ(\Succ(0))}$ serves
as an element of it.\footnote{We will see later that numbers only have
trivial symmetries, so the possibility that there are other ways to
identify $\fact(2)$ with $2$ doesn't arise.}
We may also write either $\refl{2}$ or $\refl{\fact(2)}$ for that element.
A student might want a more detailed derivation that $\fact(2)$ may be identified with $2$,
but as a result of our convention above that definitions may be applied without changing anything, the application of definitions, including
inductive definitions, is normally regarded as a trivial operation, and the details are usually omitted.
We will refer to rule \ref{E3} as ``induction for identity''.
To signal that we wish to apply it, we may announce that we argue
\emph{by (path) induction on $e$}, or simply \emph{by path induction}.
The family $f$ resulting from an application of rule \ref{E3} may be regarded as having been completely defined by the single declaration
$f(a,\refl a) \defeq p$,
and indeed, we will often simply write such a declaration as a shorthand way of applying rule \ref{E3}.
The rule says that to construct something from every identification $e$ of $a$ with something else,
it suffices to consider the special case where the identification $e$ is $\refl a : a \eqto a$.%
\footnote{Notice that the single special case in such an induction corresponds to the single way of introducing elements of
identity types via rule \ref{E2}, and compare that with \ref{P4}, which dealt with the two ways of introducing elements of $\NN$.}
Intuitively, the induction principle for identity amounts to saying that the element $\refl a$ ``generates'' the system of types $a \eqto b$, as $b$
ranges over elements of $A$.\footnote{%
We can also use a geometric intuition: when $b$ ``freely ranges'' over elements of $A$,
together with a path $e : a \eqto b$,
while we keep the element $a$ fixed, we can picture $e$ as a piece of string
winding through $A$, and the ``freeness'' of the pair $(b,e)$ allows us to pull the string $e$,
and $b$ with it, until we have the constant path at $a$, $\refl a$.\par
\begin{tikzpicture}
\draw plot [smooth cycle] coordinates {(0,0) (1.5,0) (1.3,1) (0,1.5)};
\node[dot,label=above:$a$] (a) at (0.1,0.1) {};
\node[dot,label=below:$b$] (b) at (1.3,0.8) {};
\node (A1) at (1.5,1.5) {$A$};
\draw[->] (a) .. controls ++(-20:1) and ++(170:1) .. node[auto] {$e$} (b);
\node at (1.9,0.6) {$\mapsto$};
\begin{scope}[xshift=2.5cm]
\draw plot [smooth cycle] coordinates {(0,0) (1.5,0) (1.3,1) (0,1.5)};
\node[dot,label=above:$a$] at (0.1,0.1) {};
\node at (0.5,0.2) {$\refl a$};
\node (A2) at (1.5,1.5) {$A$};
\end{scope}
\end{tikzpicture}
Conversely, we can imagine $b$ starting at $a$ and $e$ starting out as $\refl a$, and then think of $b$ roaming throughout $A$, pulling
the string $e$ along with it, until it finds every path from $a$ to some other element.
}
Equality relations are \emph{symmetric}. For identity types
we establish something similar, taking into account that
the notion of equality implemented here keeps track of the way
two things are identified, and there can be multiple ways.
Given a type $X$ and elements $a$ and $b$ of $X$,
we have an identity type $a \eqto b$
of (zero or more) identifications of $a$ with $b$. We also have
an identity type $b \eqto a$ of identifications of $b$ with $a$.
Symmetry now takes the form of a function from
type $a \eqto b$ to type $b \eqto a$, intuitively reversing
any identification of $a$ with $b$
to give an identification of $b$ with $a$.
In order to produce an element of $b \eqto a$ from an element $e$
of $a \eqto b$, for any $b$ and $e$, we argue by induction on $e$.
We let $P(b,e)$ be $b \eqto a$ for any $b$ of type $X$ and for
any $e$ of type $a \eqto b$, for use in rule \ref{E3} above.
Application of rule \ref{E3} reduces us to the case where $b$ is
$a$ and $p$ is $\refl a$, and our task is now to produce an
element of $a \eqto a$; we choose $\refl a$ for it.
Equality relations are also \emph{transitive}. We proceed in a
similar way as for symmetry. For each $a,b,c:X$ and for each
$p:a \eqto b$ and for each $q:b \eqto c$ we want to produce an
element of type $a \eqto c$. By induction on $q$ we are reduced
to the case where $c$ is $b$ and $q$ is $\refl b$,
and we are to produce an element of $a \eqto b$.
The element $p$ serves the purpose.
%Notice the similarity of this inductive definition with the definition given above
%of the sum $m+n$. HMM ... (left versus right recursion)
Now we state our symmetry result a little more formally.
\begin{definition}\label{def:eq-symm}
For any type $X$ and for any $a,b:X$, let
$$\symm_{a,b} : (a \eqto b) \to (b \eqto a)$$
be the function defined by induction by setting
$\symm_{a,a}(\refl a) \defeq \refl a$.
This operation on paths is called \emph{path inverse}, and we may abbreviate $\symm_{a,b}(p)$ as $p^{-1}$.
\glossary(1-1){$p^{-1}$}{reverse identification, path inverse, \cref{def:eq-symm}}
\end{definition}
Similarly, we formulate transitivity a little more formally, as follows.
\begin{definition}\label{def:eq-trans}
For any type $X$ and for any $a,b,c:X$, let $$\trans_{a,b,c} : (a \eqto b) \to ((b \eqto c) \to (a \eqto c))$$ be the function defined by induction by setting
$(\trans_{a,b,b} (p)) (\refl b ) \defeq p$.
This binary operation is called \emph{path composition} or \emph{path concatenation}\index{composition!of paths}\index{concatenation!of paths},
and we may abbreviate $(\trans_{a,b,c}(p))(q)$ as either $p \ct q$, or as $q \cdot p$, $qp$, or $q \circ p$.
\glossary(2conc){$p\protect\ct q, q\cdot p, qp, q\circ p$}{path concatenation or composition}
\end{definition}
The intuition that the path $p$ summarizes a gradual change from $a$ to $b$, and $q$ summarizes a gradual change from $b$ to $c$, leads to the
intuition that $p \ct q$ progresses gradually from $a$ to $c$ by first changing $a$ to $b$ and then changing $b$ to $c$; see
\cref{fig:path-concatenation}.
The notation $q\circ p$ for path composition, with $p$ and $q$ in reverse order,
fits our intution particularly well when the paths are related to functions and the composition of
the paths is related to the composition of the related functions in the same order, as happens, for example, in connection with {\em transport}
(defined below in \cref{def:transport}) in \cref{xca:trp-compose}.
\begin{marginfigure}
% \centering
\begin{tikzpicture}
\node (X) at (0,-1.5) {$X$};
\draw (0,-1)
.. controls ++(200:-1) and ++(180:1) .. (2,-2)
.. controls ++(180:-1) and ++(270:1) .. (4,0)
.. controls ++(270:-1) and ++(20:2) .. (2,2)
.. controls ++(20:-2) and ++(90:1) .. (-1,0)
.. controls ++(90:-1) and ++(200:1) .. (0,-1);
\node[dot,label=below:$a$] (a) at (0,0) {};
\node[dot,label=below:$b$] (b) at (2,-1) {};
\node[dot,label=above:$c$] (c) at (3,1) {};
\node (ct) at (1.2,1) {$q\circ p \jdeq p\ct q$};
\draw[->] (a) .. controls ++(-20:1) and ++(170:1) .. node[auto,swap] {$p$} (b);
\draw[->] (b) .. controls ++(170:-1) and ++(-70:1) .. node[auto,swap] {$q$} (c);
\draw[->] (a) .. controls ++(15:1) and ++(210:1) .. (c);
%\draw (1,0) arc(210:330:.8 and .5);
%\draw (2.09,-.18) arc(60:120:.8 and .7);
\end{tikzpicture}
\caption{Composition (also called concatenation) of paths in $X$}
\label{fig:path-concatenation}
\end{marginfigure}
The types of $\symm_{a,b}$ and $\trans_{a,b,c}$ express that
$\eqto$ is symmetric and transitive. Another view of
$\symm_{a,b}$ and $\trans_{a,b,c}$ is that they are
operations on identifications, namely reversing an identification
and concatenating two identifications. The results of various
combinations of these operations can often be identified:
we formulate some of these identifications in the following exercise.
\begin{xca}\label{xca:path-groupoid-laws}
Let $X$ be a type and let $a,b,c,d:X$ be elements.
\begin{enumerate}
\item For $p:a \eqto b$, construct an identification of type $p \ct \refl b \eqto p$.
\item For $p:a \eqto b$, construct an identification of type $\refl a \ct p \eqto p$.
\item For $p:a \eqto b$, $q:b \eqto c$, and $r:c \eqto d$, construct an identification of type $(p \ct q) \ct r \eqto p \ct (q \ct r)$.
\item For $p:a \eqto b$, construct an identification of type $p^{-1} \ct p \eqto \refl b$.
\item For $p:a \eqto b$, construct an identification of type $p \ct p^{-1} \eqto \refl a$.
\item For $p:a \eqto b$, construct an identification of type $(p^{-1})^{-1} \eqto p$.
\qedhere
\end{enumerate}
\end{xca}
Given an element $p:a \eqto a$, we may use concatenation to define powers $p^n : a \eqto a$
by induction on $n:\NN$; we set $p^0\defeq\refl{a}$ and
$p^{n+1}\defeq p\cdot p^n$. Negative powers $p^{-n}$ are defined
as $(p^{-1})^n$.\footnote{We haven't yet assigned a meaning to $-n$,
but after we introduce the set of integers $\zet$ below in~\cref{def:zet},
we'll be justified in writing $p^z$ for any $z:\zet$. See also \cref{exa:nnn}.}
One frequent use of elements of identity types is in \emph{substitution}\index{substitution}, which is
the logical principle that supports our intuition that when $x$ can by identified with $y$, we may replace $x$ by $y$
in mathematical expressions at will. A wrinkle new to students will likely be that, in our logical framework
where there may be various ways to identify $x$ with $y$, one must specify the identification used in the substitution.
Thus one may prefer to speak of using an identification to \emph{transport} properties and data about $x$ to properties and data about $y$.
Here is a geometric example: if $x$ is a triangle of area $3$ in the plane, and $y$ is congruent to $x$, then $y$ also has area $3$.
Here is another example: if $x$ is a right triangle in the plane, and $y$ is congruent to $x$, then $y$ is also a right triangle, and
the congruence informs us which of the $3$ angles of $y$ is the right angle.
Now we introduce the notion more formally.
\begin{definition}\label{def:transport}
Let $X$ be a type, and let $T(x)$ be a family of types parametrized by a variable $x:X$ (as discussed in \cref{univalent-mathematics}).
Suppose $a,b:X$ and $e:a \eqto b$.
Then we may construct a function of type $T(a) \to T(b)$.
The function
\[
\trp[T]{e} : T(a) \to T(b)
\]
is defined by induction setting $\trp[T]{\refl{a}} \defeq \id_{T(a)}$.%
\glossary(trp){$\protect\trp[T]{e}$}{transport function, \cref{def:transport}}
\end{definition}
The function thus defined may be called
\emph{the transport function in the type family $T$ along the path $e$},
or, less verbosely, \emph{transport}.\footnote{%
We sometimes picture this schematically as follows:
We draw $X$ as a (mostly horizontal) line,
and we draw each type $T(x)$ as a vertical line lying over $x:X$.
As $x$ moves around in $X$, these lines can change shape,
and taken all together they form a $2$-dimensional blob lying over $X$.
The transport functions map points between the vertical lines.\par
\begin{tikzpicture}
% Name the coordinates so they are easy to change
% first: X
\coordinate (X-left) at (-1,-1);
\node[dot,label=below:$a$] (X-x) at (0,-1.2) {};
\node[dot,label=below:$b$] (X-xp) at (1.5,-.9) {};
\coordinate (X-right) at (2.8,-1);
\node (X) at (3,-1) {$X$};
% then: T top and bottom
\coordinate (T-top-left) at (-1,1.5);
\coordinate (T-bot-left) at (-1,0.5);
\coordinate[label=above:$T(a)$] (T-top-x) at (0,1.9);
\coordinate (T-bot-x) at (0,-.1);
\coordinate[label=above:$T(b)$] (T-top-xp) at (1.5,2.1);
\coordinate (T-bot-xp) at (1.5,.2);
\coordinate (T-top-right) at (2.8,1.3);
\coordinate (T-bot-right) at (2.8,0.8);
\draw (T-bot-left) .. controls +(-90:.5) and +(0:-.5) .. (T-bot-x)
.. controls +(0:.5) and +(-10:-.5) .. (T-bot-xp)
.. controls +(-10:.5) and +(90:-.5) .. (T-bot-right)
-- (T-top-right)
.. controls +(90:.5) and +(0:.5) .. (T-top-xp)
.. controls +(0:-.5) and +(-10:.4) .. (T-top-x)
.. controls +(-10:-.4) and +(90:.5) .. (T-top-left)
-- (T-bot-left);
\draw[dashed] (T-bot-x) -- (T-top-x);
\draw[dashed] (T-bot-xp) -- (T-top-xp);
\draw (X-left) .. controls +(-10:.3) and +(0:-.3) .. (X-x);
\draw[->] (X-x) .. controls +(0:.3) and +(-10:-.5) ..
node[anchor=north] {$e$} (X-xp);
\draw (X-xp) .. controls +(-10:.5) and +(0:-.1) .. (X-right);
% Now the specifics: a point t and its transport to T(x')
\node[dot,label=left:$t$] (t) at (0,0.9) {};
\node[dot,label=right:${\trp[T]e(t)}$] (tp) at (1.5,1.1) {};
\draw[mapsto] (t) .. controls +(0:.5) and +(0:-.5) .. (tp);
\end{tikzpicture}}%
\index{transport}
We may also simplify the notation to just $\trp e$.
The transport functions behave as expected: we may construct an identification of type $\trp {e'\circ e} \eqto \trp {e'} \circ \trp {e}$.
In words: transport along the composition $e\circ e'$ can be identified with the composition of the two
transport functions. This may be proved by induction in the following exercise.
\begin{xca}\label{xca:trp-compose}
Let $X$ be a type, and let $T(x)$ be a family of types parametrized by a variable $x:X$.
Suppose we are given elements $a,b,c:X$, $e:a \eqto b$, and $e':b \eqto c$. Construct an identification of type
\[
\trp {e'\circ e} \eqto \trp {e'} \circ \trp {e}.\qedhere
\]
\end{xca}
Yet another example of good behavior is given in the following exercise.
\begin{xca}\label{xca:trp-nondep}
Let $X,Y$ be types.
As discussed in \cref{univalent-mathematics}, we may regard the expression $Y$ as a constant family of types parametrized by a variable $x:X$.
Produce an identification of type $\trp[Y]{p} \eqto \id_Y$, for any path $p:a \eqto b$.
\end{xca}
In \cref{sec:props-sets-grpds} below we will discuss what it means for a type to have at most one element.
When the types $T(x)$ may have more than one element,
we may regard an element of $T(x)$ as providing additional \emph{structure} on $x$.
In that case, we will refer to the transport function $\trp e : T(a) \to T(b)$ as
\emph{transport of structure} from $a$ to $b$.
Take, for example, $T(x)\defeq (x \eqto x)$.
Then $\trp e$ is of type $(a \eqto a) \to (b \eqto b)$ and transports a
symmetry of $a$ to a symmetry of $b$.
By contrast, when the types
$T(x)$ have at most one element, we may regard an element of $T(x)$
as providing a proof of a property of $x$. In that case, the transport
function $\trp e : T(a) \to T(b)$ provides a way to establish a claim about $b$
from a claim about $a$, so we will refer to it as \emph{substitution}. In
other words, elements that can be identified have the same properties.
\section{Product types}
\label{sec:product-types}
Functions and product types have been introduced in \cref{univalent-mathematics}, where we have also explained how to create a function by
enclosing a family of elements in one. In this section we treat functions and product types in more detail.
Recall that if $X$ is a type and $Y(x)$ is a family of types parametrized by a variable $x$ of type $X$, then there is a \emph{product type}\footnote{%
Also known as a \emph{Pi-type}.}
$\prod_{x:X} Y(x)$ whose elements $f$ are functions that provide elements $f(a)$ of type $Y(a)$, one for each $a:X$. We will refer to $X$ as the
\emph{parameter type} of the product.%
\index{product type}\index{Pi type}\index{parameter type}
By contrast, if $Y$ happens to be a constant family of types, then
$\prod_{x:X} Y$ will also be denoted by $X \to Y$, and it will also be called a \emph{function type}.
If $X$ and $Y(x)$ are elements of a universe $\UU$, then so is $\prod_{x:X} Y(x)$.
Functions preserve identity, and we will use this frequently later on. More precisely, functions induce maps on identity types, as the
following definition makes precise.
\begin{definition}\label{def:ap}
For all types $X$, $Y$, functions $f:X\to Y$ and elements $x,x':X$, the function
$$\ap{f,x,x'} : (x \eqto x') \to (f(x) \eqto f(x'))$$ is defined by induction by setting
$\ap{f,x,x}(\refl{x})\defeq\refl{f(x)}$.%
\glossary(ap){$\protect\ap{f}$}{application of $f$ to a path, \cref{def:ap}}
\glossary(ap){$f(p)$}{application of $f$ to the path $p$, \cref{def:ap}}
\end{definition}
The function $\ap{f,x,x'}$, for any elements $x$ and $x'$ of $X$, is called an \emph{application} of $f$ to paths or to identifications,
and this explains the choice of the symbol $\ap{}$ in the notation for it.
It may also be called the function (or map) \emph{induced} by $f$ on identity types.
When $x$ and $x'$ are clear from the context, we may abbreviate $\ap{f,x,x'}$ by writing $\ap{f}$ instead.
For convenience, we may abbreviate it even further, writing $f(p)$ for $\ap f (p)$.
The following lemma shows that $\ap f$ is compatible with composition.
\begin{construction}\label{lem:apcomp}
Given a function $f:X\to Y$, and elements $x,x',x'':X$, and paths $p : x \eqto x'$ and $p' : x' \eqto x''$,
we have an identification of type $\ap f (p' \cdot p) \eqto \ap f (p') \cdot \ap f (p)$.
Similarly, we have that $\ap f$ is compatible with path inverse
in that we have an identification of type
$\ap f(p^{-1}) \eqto (\ap f (p))^{-1}$ for all $p : x \eqto x'$.
Finally, we have an identification of type $\ap \id (p) \eqto p$ for all
$p : x \eqto x'$.
\end{construction}
\begin{implementation}{lem:apcomp}
By induction on $p$ and $p'$, one reduces to producing an identification of type
\[
\ap f (\refl x \cdot \refl x) \eqto \ap f ( \refl x ) \cdot \ap f ( \refl x ).
\]
Both $\ap f (\refl x \cdot \refl x)$ and
$\ap f ( \refl x ) \cdot \ap f ( \refl x )$
are equal to $\refl { f(x) }$ by definition,
so the identification $\refl {\refl { f(x) }}$ has the desired type.
The other two parts of the construction are also easily done by induction on $p$.
\end{implementation}
\begin{xca}\label{xca:trp-ap}
Let $X$ be a type and $T(x)$ a family of types parametrized by a variable $x:X$. Furthermore, let $A$ be a type, let $f:A\to X$ be a
function, let $a$ and $a'$ be elements of $A$, and let $p: a \eqto a'$ be a path.
Verify that the two functions $\trp[T \circ f]{p}$ and $\trp[T]{\ap{f}(p)}$ are of type $T(f(a)) \to T(f(a'))$.
Then construct an identification between them, i.e., construct an element of type $\trp[T \circ f]{p} \eqto \trp[T]{\ap{f}(p)}$.
\end{xca}
If two functions $f$ and $g$ of type $\prod_{x:X} Y(x)$ can be identified, then their values can be identified, i.e., for every element $x$ of
$X$, we may produce an identification of type $f(x) \eqto g(x)$, which can be constructed by induction, as follows.
\begin{definition}\label{def:ptw}
Let $f,g:\prod_{x:X} Y(x)$. Define the function
\[
{\ptw}_{f,g}: ( f \eqto g ) \to \left( \prod_{x:X} f(x) \eqto g(x) \right),
\]
by induction by setting ${\ptw}_{f,f}(\refl{f}) \defeq x \mapsto \refl{f(x)}$.
\footnote{The notation $\ptw$ is chosen to remind the reader of the word ``point-wise'', because the identifications are provided just for each
point $x$. An alternative approach goes by considering, for any $x:X$, the evaluation function $\ev_x : \big(\prod_{x:X} Y(x)\bigr) \to Y(x)$ defined by
$\ev_x(f) \defeq f(x)$. Then one could define ${\ptw}_{f,g}(p,x) \defeq \ap{\ev_x}(p)$. The functions provided by these two definitions
are not equal by definition, but they can be identified, and one can easily be used in place of the other.}
\end{definition}
Conversely, given $f,g:\prod_{x:X} Y(x)$,
from a basic axiom called \emph{function extensionality},%
\index{function extensionality}
postulated below in \cref{def:funext}, an identification $f \eqto g$
can be produced from a family of identifications of type $f(x) \eqto g(x)$
parametrized by a variable $x$ of type $X$.
\begin{definition}\label{def:naturality-square}
Let $X,Y$ be types and $f,g: X\to Y$ functions.
Given an element $h$ of type $\prod_{x:X} f(x) \eqto g(x)$, elements $x$ and $x'$ of $X$, and a path $p: x \eqto x'$,
we have two elements $h(x')\cdot \ap{f}(p)$ and $\ap{g}(p)\cdot h(x)$ of type $f(x) \eqto g(x')$.
We construct an identification
\[
\ns(h,p): \left(h(x')\cdot \ap{f}(p) \eqto \ap{g}(p)\cdot h(x)\right),
\]
between them by induction, by setting $\ns(h,\refl{x})$ to be some
element of $h(x) \cdot \refl{f(x)} \eqto h(x)$, which can be constructed by induction, as in Exercise \ref{xca:path-groupoid-laws}.%
\glossary(ns){$\protect\ns$}{naturality square, \cref{def:naturality-square}}
The type of $\ns(h,p)$ can be depicted as a square\footnote{%
\begin{displaymath}
\begin{tikzcd}[column sep=large,row sep=large,ampersand replacement=\&]
f(x) \ar[r,"="',"\ap f(p)"] \ar[d,"=","h(x)"'] \& f(x') \ar[d,"="',"h(x')"] \\
g(x) \ar[r,"=","\ap g(p)"'] \& g(x')
\end{tikzcd}
\end{displaymath}%
} and $\ns(h,p)$ is called a \emph{naturality square}.%
\index{naturality square}
%\footnote{This terminology comes from category theory.}
\end{definition}
\section{Identifying elements in members of families of types}
If $Y(x)$ is a family of types parametrized by a variable $x$ of type $X$, and $a$ and $a'$ are elements of type $X$, then after identifying $a$
with $a'$ it turns out that it is possible to ``identify'' an element of $Y(a)$ with an element of $Y(a')$, in a certain sense. That is the
idea of the following definition.
\begin{definition}\label{def:pathsoverpaths}
Suppose we are given a type $X$ in a universe $\UU$ and a family of types $Y(x)$, also in $\UU$, parametrized by a variable $x$ of type $X$.
Given elements $a,a':X$, $y:Y(a)$, and
$y':Y(a')$ and a path $p : a \eqto a'$,
we define a new type $\pathover y Y p {y'}$ in $\UU$ as follows.%
\glossary(2=over){$\protect\pathover y Y p {y'}$}{path-over type,
\cref{def:pathsoverpaths}}
We proceed by induction on $a'$ and $p$, which reduces us to the case where $a'$ is $a$ and $p$ is $\refl a$,
rendering $y$ and $y'$ of the same type $Y(a)$ in $\UU$, allowing us to define
$\pathover y Y {\refl a} {y'}$ to be $y \eqto y'$, which is also in $\UU$.
\end{definition}
\begin{remark} TODO: what if the $\UU$'s above are different?
Also: a remark/exercise about the special case where $Y$ is the constant
family.
\end{remark}
An element $q : \pathover y Y p {y'}$ is called an \emph{identification} of $y$ with $y'$ \emph{over} $p$, or a
\emph{path} from $y$ to $y'$ \emph{over} $p$.\index{path over}
Intuitively, we regard $p$ as specifying a way for $a$ to change gradually into $a'$, and this provides a way
for $Y(a)$ to change gradually into $Y(a')$; then $q$ charts a way for $y$ to change gradually into $y'$ as $Y(a)$ changes gradually into $Y(a')$.\footnote{\label{ft:path-over-pic}%
We picture this as follows: the path from $y$ to $y'$ over $p$ travels
through the vertical lines representing the types $Y(x)$ as $x:X$
moves along the path $p$ in $X$ from $a$ to $a'$:\par
\begin{tikzpicture}
% Name the coordinates so they are easy to change
% first: X
\coordinate (X-left) at (-1,-1);
\node[dot,label=below:$a$] (X-x) at (0,-1.2) {};
\node[dot,label=below:$a'$] (X-xp) at (1.5,-.9) {};
\coordinate (X-right) at (2.8,-1);
\node (X) at (3,-1) {$X$};
% then: Y top and bottom
\coordinate (Y-top-left) at (-1,1.5);
\coordinate (Y-bot-left) at (-1,0.5);
\coordinate[label=above:$Y(a)$] (Y-top-x) at (0,1.9);
\coordinate (Y-bot-x) at (0,-.1);
\coordinate[label=above:$Y(a')$] (Y-top-xp) at (1.5,2.1);
\coordinate (Y-bot-xp) at (1.5,.2);
\coordinate (Y-top-right) at (2.8,1.3);
\coordinate (Y-bot-right) at (2.8,0.8);
\draw (Y-bot-left) .. controls +(-90:.5) and +(0:-.5) .. (Y-bot-x)
.. controls +(0:.5) and +(-10:-.5) .. (Y-bot-xp)
.. controls +(-10:.5) and +(90:-.5) .. (Y-bot-right)
-- (Y-top-right)
.. controls +(90:.5) and +(0:.5) .. (Y-top-xp)
.. controls +(0:-.5) and +(-10:.4) .. (Y-top-x)
.. controls +(-10:-.4) and +(90:.5) .. (Y-top-left)
-- (Y-bot-left);
\draw[dashed] (Y-bot-x) -- (Y-top-x);
\draw[dashed] (Y-bot-xp) -- (Y-top-xp);
\draw (X-left) .. controls +(-10:.3) and +(0:-.3) .. (X-x);
\draw[->] (X-x) .. controls +(0:.3) and +(-10:-.5) ..
node[anchor=north] {$p$} (X-xp);
\draw (X-xp) .. controls +(-10:.5) and +(0:-.1) .. (X-right);
% Now the specifics: two points y,y' and the pathover
\node[dot,label=left:$y$] (y) at (0,0.9) {};
\node[dot,label=right:$y'$] (yp) at (1.5,1.1) {};
\draw[->] (y) .. controls +(0:.5) and +(0:-.5) ..
node[anchor=south] {$q$} (yp);
\end{tikzpicture}}%
The following definition identifies the type of paths over $p$ with a type
of paths using transport along $p$.
\begin{definition}\label{def:pathover-trp}
In the context of \cref{def:pathsoverpaths}, define by induction on $p$ an
identification
$\po_p: \left(\pathover y Y p {y'}\right) \eqto \left( \trp[Y]{p}(y) \eqto y'\right)$ in $\UU$,
by setting $\po_{\refl{x}} \defeq \refl{y \eqto y'}$.%
\glossary(po){$\protect\po_p$}{convert path over path, \cref{def:pathover-trp}}
\end{definition}
Many of the operations on paths have counterparts for paths over paths.
For example, we may define composition of paths over paths as follows.
\begin{definition}\label{def:pathovercomposition}
Suppose we are given a type $X$ and a family of types $Y(x)$ parametrized by the elements $x$ of $X$.
Suppose also that we have elements $x, x', x'' : X$, a path $p : x \eqto x'$, and a path $p' : x' \eqto x''$.
Suppose further that we have elements $y : Y(x)$, $y' : Y(x')$, and $y'' : Y(x'')$, with paths $q : \pathover y Y p {y'}$ over $p$
and $q' : \pathover {y'} Y {p'} {y''}$ over $p'$.
Then we define the \emph{composite} path $(q' \pathovercomp q) : \pathover y Y {p' \circ p} {y''}$ over $p' \circ p$ as follows.
First we apply path induction on $p'$ to reduce to the case where $x''$ is $x'$ and $p'$ is $\refl{x'}$.
That also reduces the type $\pathover {y'} Y {p'} {y''}$ to the identity type $y' \eqto y''$, so we may apply path induction on $q'$ to reduce
to the case where $y''$ is $y'$ and $q'$ is $\refl{y'}$.
Now observe that $p' \circ p$ is $p$, so $q$ provides the element we need.
\end{definition}
Similarly, one can define the inverse of a path over a path,
writing $\inv q : \pathover {y'} Y {\inv p} y$ for the inverse
of $q : \pathover y Y p {y'}$.
For these operations on paths over paths we have identifications
analogous to those for the operations on paths in
\cref{xca:path-groupoid-laws}, after some modification.
For example,
${\inv g} \pathovercomp q$ of type $\pathover {y} Y {{\inv p}\circ p} y$ and
$\refl{y}$ of type $\pathover {y} Y {\refl{x}} y$ cannot be directly used
to form an identity type, since their types are not equal by definition.
We will state these identifications when we need them.
\begin{xca}\label{xca:cp}
Try to state some of these identifications yourself.
\end{xca}
The following construction shows how to handle application of a dependent
function $f$ to paths using the definition above.
\begin{definition}\label{def:apd}
Suppose we are given a type $X$, a family of types $Y(x)$ parametrized by the elements $x$ of $X$, and a function $f:\prod_x Y(x)$.
Given elements $x,x':X$ and a path $p : x \eqto x'$, we define
\[
\apd{f}(p) : \pathover {f(x)} Y p {f(x')}
\]
by induction on $p$, setting
\[
\apd f {(\refl x)} \defeq \refl {f(x)}.\qedhere
\]
\glossary(apd){$\protect \apd f$}{application of a dependent function
to a path, \cref{def:apd}}
\glossary(apd){$f(p)$}{application of dependent $f$ to the path $p$ \cref{def:apd}}
\end{definition}
The function $\apd f$ is called \emph{dependent application} of $f$ to paths.\footnote{%
We picture $f$ via its \emph{graph} of the values $f(x)$
as $x$ varies in $X$.
The dependent application of $f$ to $p$ is then the piece of the graph
that lies over $p$:\par
\begin{tikzpicture}
% Name the coordinates so they are easy to change
% first: X
\coordinate (X-left) at (-1,-1);
\node[dot,label=below:$x$] (X-x) at (0,-1.2) {};
\node[dot,label=below:$x'$] (X-xp) at (1.5,-.9) {};
\coordinate (X-right) at (2.8,-1);
\node (X) at (3,-1) {$X$};
% then: Y top and bottom
\coordinate (Y-top-left) at (-1,1.5);
\coordinate (Y-bot-left) at (-1,0.5);
\coordinate[label=above:$Y(x)$] (Y-top-x) at (0,1.9);
\coordinate (Y-bot-x) at (0,-.1);
\coordinate[label=above:$Y(x')$] (Y-top-xp) at (1.5,2.1);
\coordinate (Y-bot-xp) at (1.5,.2);
\coordinate (Y-top-right) at (2.8,1.3);
\coordinate (Y-bot-right) at (2.8,0.8);
\draw (Y-bot-left) .. controls +(-90:.5) and +(0:-.5) .. (Y-bot-x)
.. controls +(0:.5) and +(-10:-.5) .. (Y-bot-xp)
.. controls +(-10:.5) and +(90:-.5) .. (Y-bot-right)
-- (Y-top-right)
.. controls +(90:.5) and +(0:.5) .. (Y-top-xp)
.. controls +(0:-.5) and +(-10:.4) .. (Y-top-x)
.. controls +(-10:-.4) and +(90:.5) .. (Y-top-left)