\chapter{Set theory} \label{cha:set-math} \index{set|(}% Our conception of sets as types with particularly simple homotopical character, cf.\ \cref{sec:basics-sets}, is quite different from the sets of Zermelo--Fraenkel\index{set theory!Zermelo--Fraenkel} set theory, which form a cumulative hierarchy with an intricate nested membership structure. For many mathematical purposes, the homotopy-the\-o\-ret\-ic sets are just as good as the Zermelo--Fraenkel ones, but there are important differences. We begin this chapter in \cref{sec:piw-pretopos} by showing that the category $\uset$ has (most of) the usual properties of the category of sets. \index{mathematics!constructive}% \index{mathematics!predicative}% In constructive, predicative, univalent foundations, it is a ``$\Pi\mathsf{W}$-pretopos''; whereas if we assume propositional resizing \index{propositional!resizing}% (\cref{subsec:prop-subsets}) it is an elementary topos,\index{topos} and if we assume \LEM{} and \choice{} then it is a model of Lawvere's \emph{Elementary Theory of the Category of Sets}\index{Lawvere}. \index{Elementary Theory of the Category of Sets}% This is sufficient to ensure that the sets in homotopy type theory behave like sets as used by most mathematicians outside of set theory. In the rest of the chapter, we investigate some subjects that traditionally belong to ``set theory''. In \cref{sec:cardinals,sec:ordinals,sec:wellorderings} we study cardinal and ordinal numbers. These are traditionally defined in set theory using the global membership relation, but we will see that the univalence axiom enables an equally convenient, more ``structural'' approach. Finally, in \cref{sec:cumulative-hierarchy} we consider the possibility of constructing \emph{inside} of homotopy type theory a cumulative hierarchy of sets, equipped with a binary membership relation akin to that of Zermelo--Fraenkel set theory. This combines higher inductive types with ideas from the field of algebraic set theory. \index{algebraic set theory}% \index{set theory!algebraic}% In this chapter we will often use the traditional logical notation described in \cref{subsec:prop-trunc}. In addition to the basic theory of \cref{cha:basics,cha:logic}, we use higher inductive types for colimits and quotients as in \cref{sec:colimits,sec:set-quotients}, as well as some of the theory of truncation from \cref{cha:hlevels}, particularly the factorization system of \cref{sec:image-factorization} in the case $n=-1$. In \cref{sec:ordinals} we use an inductive family (\cref{sec:generalizations}) to describe well-foundedness, and in \cref{sec:cumulative-hierarchy} we use a more complicated higher inductive type to present the cumulative hierarchy. %\section{\texorpdfstring{$\set$}{Set} is a \texorpdfstring{$\Pi$}{Π}W-pretopos} \section{The category of sets} \label{sec:piw-pretopos} Recall that in \cref{cha:category-theory} we defined the category \uset to consist of all $0$-types (in some universe \UU) and maps between them, and observed that it is a category (not just a precategory). We consider successively the levels of structure which \uset possesses. \subsection{Limits and colimits} \label{subsec:limits-sets} \index{limit!of sets}% \index{colimit!of sets}% Since sets are closed under products, the universal property of products in \cref{thm:prod-ump} shows immediately that \uset has finite products. In fact, infinite products follow just as easily from the equivalence \[ \Parens{X\to \prd{a:A} B(a)} \eqvsym \Parens{\prd{a:A} (X\to B(a))}.\] And we saw in \cref{ex:pullback}\index{pullback} that the pullback of $f:A\to C$ and $g:B\to C$ can be defined as $\sm{a:A}{b:B} f(a)=g(b)$; this is a set if $A,B,C$ are and inherits the correct universal property. Thus, \uset is a \emph{complete} category in the obvious sense. \index{category!complete}% \index{complete!category}% Since sets are closed under $+$ and contain \emptyt, \uset has finite coproducts. Similarly, since $\sm{a:A}B(a)$ is a set whenever $A$ and each $B(a)$ are, it yields a coproduct of the family $B$ in \uset. Finally, we showed in \cref{sec:pushouts} that pushouts exist in $n$-types, which includes \uset in particular. Thus, \uset is also \emph{cocomplete}. \index{category!cocomplete}% \index{cocomplete category}% \subsection{Images} \label{sec:image} %We will show that $\uset$ is a $\Pi$W-pretopos. Next, we show that $\uset$ is a \define{regular category}, i.e.: \indexdef{category!regular}% \indexdef{regular!category}% % \begin{enumerate} \item $\uset$ is finitely complete.\label{item:reg1} \item The kernel pair $\proj1,\proj2: (\sm{x,y:A} f(x)= f(y)) \to A$ of any function $f : A \to B$ has a coequalizer.\label{item:reg2} \indexdef{kernel!pair} \item Pullbacks of regular epimorphisms are again regular epimorphisms.\label{item:reg3} \end{enumerate} % Recall that a \define{regular epimorphism} \indexdef{epimorphism!regular}% \indexdef{regular!epimorphism}% is a morphism that is the coequalizer of \emph{some} pair of maps. Thus in~\ref{item:reg3} the pullback of a coequalizer is required to again be a coequalizer, but not necessarily of the pulled-back pair. \index{set-coequalizer}% \index{image} The obvious candidate for the coequalizer of the kernel pair of $f:A\to B$ is the \emph{image} of $f$, as defined in \cref{sec:image-factorization}. Recall that we defined $\im(f)\defeq \sm{b:B} \brck{\hfib f b}$, with functions $\tilde{f}:A\to\im(f)$ and $i_f:\im(f)\to B$ defined by \begin{align*} \tilde{f} & \defeq \lam{a} \Pairr{f(a),\,\bproj{\pairr{a,\refl{f(a)}}}}\\ i_f & \defeq \proj1 \end{align*} fitting into a diagram: \begin{equation*} \xymatrix{ **[l]{\sm{x,y:A} f(x)= f(y)} \ar@<0.25em>[r]^{\proj1} \ar@<-0.25em>[r]_{\proj2} & {A} \ar[r]^(0.4){\tilde{f}} \ar[rd]_{f} & {\im(f)} \ar@{..>}[d]^{i_f} \\ & & B } \end{equation*} Recall that a function $f:A\to B$ is called \emph{surjective} if \index{function!surjective}% \narrowequation{\fall{b:B}\brck{\hfib f b},} or equivalently $\fall{b:B} \exis{a:A} f(a)=b$. We have also said that a function $f:A\to B$ between sets is called \emph{injective} if \index{function!injective}% $\fall{a,a':A} (f(a) = f(a')) \Rightarrow (a=a')$, or equivalently if each of its fibers is a mere proposition. Since these are the $(-1)$-connected and $(-1)$-truncated maps in the sense of \cref{cha:hlevels}, the general theory there implies that $\tilde f$ above is surjective and $i_f$ is injective, and that this factorization is stable under pullback. We now identify surjectivity and injectivity with the appropriate cat\-e\-go\-ry-theoretic notions. First we observe that categorical monomorphisms and epimorphisms have a slightly stronger equivalent formulation. \begin{lem}\label{thm:mono} For a morphism $f:\hom_A(a,b)$ in a category $A$, the following are equivalent. \begin{enumerate} \item $f$ is a \define{monomorphism}: \indexdef{monomorphism}% for all $x:A$ and ${g,h:\hom_A(x,a)}$, if $f\circ g = f\circ h$ then $g=h$.\label{item:mono1} \item (If $A$ has pullbacks) the diagonal map $a\to a\times_b a$ is an isomorphism.\label{item:mono4} \item For all $x:A$ and $k:\hom_A(x,b)$, the type $\sm{h:\hom_A(x,a)} (k = f\circ h)$ is a mere proposition.\label{item:mono2} \item For all $x:A$ and ${g:\hom_A(x,a)}$, the type $\sm{h:\hom_A(x,a)} (f\circ g = f\circ h)$ is contractible.\label{item:mono3} \end{enumerate} \end{lem} \begin{proof} The equivalence of conditions~\ref{item:mono1} and~\ref{item:mono4} is standard category theory. Now consider the function $(f\circ \blank ):\hom_A(x,a) \to \hom_A(x,b)$ between sets. Condition~\ref{item:mono1} says that it is injective, while~\ref{item:mono2} says that its fibers are mere propositions; hence they are equivalent. And~\ref{item:mono2} implies~\ref{item:mono3} by taking $k\defeq f\circ g$ and recalling that an inhabited mere proposition is contractible. Finally,~\ref{item:mono3} implies~\ref{item:mono1} since if $p:f\circ g= f\circ h$, then $(g,\refl{})$ and $(h,p)$ both inhabit the type in~\ref{item:mono3}, hence are equal and so $g=h$. \end{proof} \begin{lem}\label{thm:inj-mono} A function $f:A\to B$ between sets is injective if and only if it is a monomorphism\index{monomorphism} in \uset. \end{lem} \begin{proof} Left to the reader. \end{proof} Of course, an \define{epimorphism} \indexdef{epimorphism}% \indexsee{epi}{epimorphism}% is a monomorphism in the opposite category. We now show that in \uset, the epimorphisms are precisely the surjections, and also precisely the coequalizers (regular epimorphisms). The coequalizer of a pair of maps $f,g:A\to B$ in $\uset$ is defined as the 0-truncation of a general (homotopy) coequalizer. For clarity, we may call this the \define{set-coequalizer}. \indexdef{set-coequalizer}% \indexsee{coequalizer!of sets}{set-coequalizer}% It is convenient to express its universal property as follows. \begin{lem} \index{universal!property!of set-coequalizer}% Let $f,g:A\to B$ be functions between sets $A$ and $B$. The {set-co}equalizer $c_{f,g}:B\to Q$ has the property that, for any set $C$ and any $h:B\to C$ with $h\circ f = h\circ g$, the type \begin{equation*} \sm{k:Q\to C} (k\circ c_{f,g} = h) \end{equation*} is contractible. \end{lem} \begin{lem}\label{epis-surj} For any function $f:A\to B$ between sets, the following are equivalent: \begin{enumerate} \item $f$ is an epimorphism. \item Consider the pushout diagram \begin{equation*} \xymatrix{ {A} \ar[r]^{f} \ar[d] & {B} \ar[d]^{\iota} \\ {\unit} \ar[r]_{t} & {C_f} } \end{equation*} in $\uset$ defining the mapping cone\index{cone!of a function}. Then the type $C_f$ is contractible. \item $f$ is surjective. \end{enumerate} \end{lem} \begin{proof} Let $f:A\to B$ be a function between sets, and suppose it to be an epimorphism; we show $C_f$ is contractible. The constructor $\unit\to C_f$ of $C_f$ gives us an element $t:C_f$. We have to show that \begin{equation*} \prd{x:C_f} x= t. \end{equation*} Note that $x= t$ is a mere proposition, hence we can use induction on $C_f$. Of course when $x$ is $t$ we have $\refl{t}:t=t$, so it suffices to find \begin{align*} I_0 & : \prd{b:B} \iota(b)= t\\ I_1 & : \prd{a:A} \opp{\alpha_1(a)} \ct I_0(f(a))=\refl{t} \end{align*} where $\iota:B\to C_f$ and $\alpha_1:\prd{a:A} \iota(f(a))= t$ are the other constructors of $C_f$. Note that $\alpha_1$ is a homotopy from $\iota\circ f$ to $\mathsf{const}_t\circ f$, so we find the elements \begin{equation*} \pairr{\iota,\refl{\iota\circ f}},\pairr{\mathsf{const}_t,\alpha_1}: \sm{h:B\to C_f} \iota\circ f \htpy h\circ f. \end{equation*} By the dual of \cref{thm:mono}\ref{item:mono3} (and function extensionality), there is a path \begin{equation*} \gamma:\pairr{\iota,\refl{\iota\circ f}}=\pairr{\mathsf{const}_t,\alpha_1}. \end{equation*} Hence, we may define $I_0(b)\defeq \happly(\projpath1(\gamma),b):\iota(b)=t$. We also have \[\projpath2(\gamma) : \trans{\projpath1(\gamma)}{\refl{\iota\circ f}} = \alpha_1. \] This transport involves precomposition with $f$, which commutes with $\happly$. Thus, from transport in path types we obtain $I_0(f(a)) = \alpha_1(a)$ for any $a:A$, which gives us $I_1$. Now suppose $C_f$ is contractible; we show $f$ is surjective. We first construct a type family $P:C_f\to\prop$ by recursion on $C_f$, which is valid since \prop is a set. On the point constructors, we define \begin{align*} P(t) & \defeq \unit\\ P(\iota(b)) & \defeq \brck{\hfiber{f}b}. \end{align*} To complete the construction of $P$, it remains to give a path \narrowequation{\brck{\hfiber{f}{f(a)}} =_\prop \unit} for all $a:A$. However, $\brck{\hfiber{f}{f(a)}}$ is inhabited by $(f(a),\refl{f(a)})$. Since it is a mere proposition, this means it is contractible --- and thus equivalent, hence equal, to \unit. This completes the definition of $P$. Now, since $C_f$ is assumed to be contractible, it follows that $P(x)$ is equivalent to $P(t)$ for any $x:C_f$. In particular, $P(\iota(b))\jdeq \brck{\hfiber{f}b}$ is equivalent to $P(t)\jdeq \unit$ for each $b:B$, and hence contractible. Thus, $f$ is surjective. Finally, suppose $f:A\to B$ to be surjective, and consider a set $C$ and two functions $g,h:B\to C$ with the property that $g\circ f = h\circ f$. Since $f$ is assumed to be surjective, for all $b:B$ the type $\brck{\hfib f b}$ is contractible. Thus we have the following equivalences: \begin{align*} \prd{b:B} (g(b)= h(b)) & \eqvsym \prd{b:B} \Parens{\brck{\hfib f b} \to (g(b)= h(b))}\\ & \eqvsym \prd{b:B} \Parens{\hfib f b \to (g(b)= h(b))}\\ & \eqvsym \prd{b:B}{a:A}{p:f(a)= b} g(b)= h(b)\\ & \eqvsym \prd{a:A} g(f(a))= h(f(a)) \end{align*} using on the second line the fact that $g(b)=h(b)$ is a mere proposition, since $C$ is a set. But by assumption, there is an element of the latter type. \end{proof} % \begin{rem} % The above theorem is not true when we replace $\set$ by $\type$ % (replacing it also in the definition of $\mathsf{epi}$ and $\mathsf{epi}'$). % However, we do % get the implications $\textit{ii.}\Rightarrow\textit{iii.}\Rightarrow % \textit{iv.}$ % \end{rem} \begin{thm}\label{thm:set_regular}\label{lem:images_are_coequalizers} The category $\uset$ is regular. Moreover, surjective functions between sets are regular epimorphisms. \end{thm} \begin{proof} It is a standard lemma in category theory that a category is regular as soon as it admits finite limits and a pullback-stable orthogonal factorization system\index{orthogonal factorization system} $(\mathcal{E},\mathcal{M})$ with $\mathcal{M}$ the monomorphisms, in which case $\mathcal{E}$ consists automatically of the regular epimorphisms. (See e.g.~\cite[A1.3.4]{elephant}.) The existence of the factorization system was proved in \cref{thm:orth-fact}. \end{proof} \begin{lem}\label{lem:pb_of_coeq_is_coeq} Pullbacks of regular epis in \uset are regular epis. \end{lem} \begin{proof} We showed in \cref{thm:stable-images} that pullbacks of $n$-connected functions are $n$-connected. By \cref{lem:images_are_coequalizers}, it suffices to apply this when $n=-1$. \end{proof} \indexdef{image!of a subset} One of the consequences of \uset being a regular category is that we have an ``image'' operation on subsets. That is, given $f:A\to B$, any subset $P:\power A$ (i.e.\ a predicate $P:A\to \prop$) has an \define{image} which is a subset of $B$. This can be defined directly as $\setof{ y:B | \exis{x:A} f(x)=y \land P(x)}$, or indirectly as the image (in the previous sense) of the composite function \[ \setof{ x:A | P(x) } \to A \xrightarrow{f} B.\] \symlabel{subset-image} We will also sometimes use the common notation $\setof{f(x) | P(x)}$ for the image of $P$. \subsection{Quotients}\label{subsec:quotients} \index{set-quotient|(}% Now that we know that $\uset$ is regular, to show that $\uset$ is exact, we need to show that every equivalence relation is effective. \index{effective!equivalence relation|(}% \index{relation!effective equivalence|(}% In other words, given an equivalence relation $R:A\to A\to\prop$, there is a coequalizer $c_R$ of the pair $\proj1,\proj2:\sm{x,y:A} R(x,y)\to A$ and, moreover, the $\proj1$ and $\proj2$ form the kernel\index{kernel!pair} pair of $c_R$. We have already seen, in \cref{sec:set-quotients}, two general ways to construct the quotient of a set by an equivalence relation $R:A\to A\to\prop$. The first can be described as the set-coequalizer of the two projections \[\proj1,\proj2:\Parens{\sm{x,y:A} R(x,y)} \to A.\] The important property of such a quotient is the following. \begin{defn} A relation $R:A\to A\to\prop$ is said to be \define{effective} \indexdef{effective!relation} \indexdef{effective!equivalence relation}% \indexdef{relation!effective equivalence}% if the square \begin{equation*} \xymatrix{ {\sm{x,y:A} R (x,y)} \ar[r]^(0.7){\proj1} \ar[d]_{\proj2} & {A} \ar[d]^{c_R} \\ {A} \ar[r]_{c_R} & {A/R} } \end{equation*} is a pullback. \end{defn} Since the standard pullback of $c_R$ and itself is $\sm{x,y:A} (c_R(x)=c_R(y))$, by \cref{thm:total-fiber-equiv} this is equivalent to asking that the canonical transformation $\prd{x,y:A} R(x,y) \to (c_R(x)=c_R(y))$ be a fiberwise equivalence. \begin{lem}\label{lem:sets_exact} Suppose $\pairr{A,R}$ is an equivalence relation. Then there is an equivalence \begin{equation*} (c_R(x)= c_R(y))\eqvsym R(x,y) \end{equation*} for any $x,y:A$. In other words, equivalence relations are effective. \end{lem} \begin{proof} We begin by extending $R$ to a relation $\widetilde{R}:A/R\to A/R\to\prop$, which we will then show is equivalent to the identity type on $A/R$. We define $\widetilde{R}$ by double induction on $A/R$ (note that $\prop$ is a set by univalence for mere propositions). We define $\widetilde{R}(c_R(x),c_R(y)) \defeq R(x,y)$. For $r:R(x,x')$ and $s:R(y,y')$, the transitivity and symmetry of $R$ gives an equivalence from $R(x,y)$ to $R(x',y')$. This completes the definition of $\widetilde{R}$. It remains to show that $\widetilde{R}(w,w')\eqvsym (w= w')$ for every $w,w':A/R$. The direction $(w=w')\to \widetilde{R}(w,w')$ follows by transport once we show that $\widetilde{R}$ is reflexive, which is an easy induction. The other direction $\widetilde{R}(w,w')\to (w= w')$ is a mere proposition, so since $c_R:A\to A/R$ is surjective, it suffices to assume that $w$ and $w'$ are of the form $c_R(x)$ and $c_R(y)$. But in this case, we have the canonical map $\widetilde{R}(c_R(x),c_R(y)) \defeq R(x,y) \to (c_R(x)=c_R(y))$. (Note again the appearance of the encode-decode method.\index{encode-decode method}) \end{proof} The second construction of quotients is as the set of equivalence classes of $R$ (a subset of its power set\index{power set}): \[ A\sslash R \defeq \setof{ P:A\to\prop | P \text{ is an equivalence class of } R}. \] This requires propositional resizing\index{propositional resizing}\index{impredicative!quotient}\index{resizing} in order to remain in the same universe as $A$ and $R$. Note that if we regard $R$ as a function from $A$ to $A\to \prop$, then $A\sslash R$ is equivalent to $\im(R)$, as constructed in \cref{sec:image}. Now in \cref{lem:images_are_coequalizers} we have shown that images are coequalizers. In particular, we immediately get the coequalizer diagram \begin{equation*} \xymatrix{ **[l]{\sm{x,y:A} R (x)= R (y)} \ar@<0.25em>[r]^{\proj1} \ar@<-0.25em>[r]_{\proj2} & {A} \ar[r] & {A \sslash R.} } \end{equation*} We can use this to give an alternative proof that any equivalence relation is effective and that the two definitions of quotients agree. \begin{thm}\label{prop:kernels_are_effective} For any function $f:A\to B$ between any two sets, the relation $\ker(f):A\to A\to\prop$ given by $\ker(f,x,y)\defeq (f(x)= f(y))$ is effective. \end{thm} \begin{proof} We will use that $\im(f)$ is the coequalizer of $\proj1,\proj2: (\sm{x,y:A} f(x)= f(y))\to A$. %we get this equivalence from~\cref{prop:images_are_coequalizers} Note that the kernel pair of the function \[c_f\defeq\lam{a} \Parens{f(a),\brck{\pairr{a,\refl{f(a)}}}} : A \to \im(f) \] consists of the two projections \begin{equation*} \proj1,\proj2:\Parens{\sm{x,y:A} c_f(x)= c_f(y)}\to A. \end{equation*} For any $x,y:A$, we have equivalences \begin{align*} (c_f(x)= c_f(y)) & \eqvsym \Parens{\sm{p:f(x)= f(y)} \trans{p}{\brck{\pairr{x,\refl{f(x)}}}} =\brck{\pairr{y,\refl{f(x)}}}}\\ & \eqvsym (f(x)= f(y)), \end{align*} where the last equivalence holds because $\brck{\hfiber{f}b}$ is a mere proposition for any $b:B$. Therefore, we get that \begin{equation*} \Parens{\sm{x,y:A} c_f(x)= c_f(y)}\eqvsym \Parens{\sm{x,y:A} f(x)= f(y)} \end{equation*} and hence we may conclude that $\ker f$ is an effective relation for any function $f$. \end{proof} \begin{thm} Equivalence relations are effective and there is an equivalence $A/R \eqvsym A\sslash R $. \end{thm} \begin{proof} We need to analyze the coequalizer diagram \begin{equation*} \xymatrix{ **[l]{\sm{x,y:A} R (x)= R (y)} \ar@<0.25em>[r]^{\proj1} \ar@<-0.25em>[r]_{\proj2} & {A} \ar[r] & {A \sslash R} } \end{equation*} By the univalence axiom, the type $R(x) = R(y)$ is equivalent to the type of homotopies from $R(x)$ to $R(y)$, which is equivalent to \narrowequation{\prd{z:A} R (x,z)\eqvsym R (y,z).} Since $R$ is an equivalence relation, the latter space is equivalent to $R(x,y)$. To summarize, we get that $(R(x) = R(y)) \eqvsym R(x,y)$, so $R $ is effective since it is equivalent to an effective relation. Also, the diagram \begin{equation*} \xymatrix{ **[l]{\sm{x,y:A} R(x, y)} \ar@<0.25em>[r]^{\proj1} \ar@<-0.25em>[r]_{\proj2} & {A} \ar[r] & {A \sslash R.} } \end{equation*} is a coequalizer diagram. Since coequalizers are unique up to equivalence, it follows that $A/R \eqvsym A\sslash R $. \end{proof} We finish this section by mentioning a possible third construction of the quotient of a set $A$ by an equivalence relation $R$. Consider the precategory with objects $A$ and hom-sets $R$; the type of objects of the Rezk completion \index{completion!Rezk}% (see \cref{sec:rezk}) of this precategory will then be the quotient. The reader is invited to check the details. \index{effective!equivalence relation|)}% \index{relation!effective equivalence|)}% \index{set-quotient|)}% \subsection{\texorpdfstring{$\uset$}{Set} is a \texorpdfstring{$\Pi\mathsf{W}$}{ΠW}-pretopos} \label{subsec:piw} \index{structural!set theory|(}% The notion of a \emph{$\Pi\mathsf{W}$-pretopos} \index{PiW-pretopos@$\Pi\mathsf{W}$-pretopos}% \indexsee{pretopos}{$\Pi\mathsf{W}$-pretopos} --- that is, a locally cartesian closed category \index{locally cartesian closed category}% \index{category!locally cartesian closed}% with disjoint finite coproducts, effective equivalence relations, and initial algebras for polynomial endofunctors --- is intended as a ``predicative'' \index{mathematics!predicative}% notion of topos, i.e.\ a category of ``predicative sets'', which can serve the purpose for constructive mathematics \index{mathematics!constructive}% that the usual category of sets does for classical \index{mathematics!classical}% mathematics. Typically, in constructive type theory, one resorts to an external construction of ``setoids'' --- an exact completion --- to obtain a category with such closure properties. \index{setoid}\index{completion!exact}% In particular, the well-behaved quotients are required for many constructions in mathematics that usually involve (non-constructive) power sets. It is noteworthy that univalent foundations provides these constructions \emph{internally} (via higher inductive types), without requiring such external constructions. This represents a powerful advantage of our approach, as we shall see in subsequent examples. \begin{thm} \index{PiW-pretopos@$\Pi\mathsf{W}$-pretopos} The category $\uset$ is a $\Pi\mathsf{W}$-pretopos. \end{thm} \begin{proof} We have an initial object \index{initial!set}% $\emptyt$ and finite, disjoint sums $A+B$. These are stable under pullback, simply because pullback has a right adjoint\index{adjoint!functor}. Indeed, $\uset$ is locally cartesian closed, since for any map $f:A\to B$ between sets, the ``fibrant replacement'' \index{fibrant replacement} $\sm{a:A}f(a)=b$ is equivalent to $A$ (over $B$), and we have dependent function types for the replacement. We've just shown that $\uset$ is regular (\cref{thm:set_regular}) and that quotients are effective (\cref{lem:sets_exact}). We thus have a locally cartesian closed pretopos. Finally, since the $n$-types are closed under the formation of $W$-types by \cref{ex:ntypes-closed-under-wtypes}, and by \cref{thm:w-hinit} $W$-types are initial algebras for polynomial endofunctors, we see that $\uset$ is a $\Pi\mathsf{W}$-pretopos. \end{proof} \index{topos|(} One naturally wonders what, if anything, prevents $\uset$ from being an (elementary) topos? In addition to the structure already mentioned, a topos has a \emph{subobject classifier}: \indexdef{subobject classifier}% \index{classifier!subobject}% \index{power set}% a pointed object classifying (equivalence classes of) monomorphisms\index{monomorphism}. (In fact, in the presence of a subobject classifier, things become somewhat simpler: one merely needs cartesian closure in order to get the colimits.) In homotopy type theory, univalence implies that the type $\prop \defeq \sm{X:\UU}\isprop(X)$ does classify monomorphisms (by an argument similar to \cref{sec:object-classification}), but in general it is as large as the ambient universe $\UU$. Thus, it is a ``set'' in the sense of being a $0$-type, but it is not ``small'' in the sense of being an object of $\UU$, hence not an object of the category \uset. However, if we assume an appropriate form of propositional resizing (see \cref{subsec:prop-subsets}), then we can find a small version of $\prop$, so that \uset becomes an elementary topos. \begin{thm}\label{thm:settopos} \index{propositional!resizing}% If there is a type $\Omega:\UU$ of all mere propositions, then the category $\uset_\UU$ is an elementary topos. \end{thm} \index{topos|)} A sufficient condition for this is the law of excluded middle, in the ``mere-propositional'' form that we have called \LEM{}; for then we have $\prop = \bool$, which \emph{is} small, and which then also classifies all mere propositions. Moreover, in topos theory a well-known sufficient condition for \LEM{} is the axiom of choice, which is of course often assumed as an axiom in classical\index{mathematics!classical} set theory. In the next section, we briefly investigate the relation between these conditions in our setting. \index{structural!set theory|)}% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{The axiom of choice implies excluded middle} \label{subsec:emacinsets} % In this section we prove a classic result that the axiom of choice implies excluded % middle. We begin with the following lemma. \begin{lem}\label{prop:trunc_of_prop_is_set} If $A$ is a mere proposition then its suspension $\susp(A)$ is a set, and $A$ is equivalent to $\id[\susp(A)]{\north}{\south}$. \end{lem} \begin{proof} To show that $\susp(A)$ is a set, we define a family $P:\susp(A)\to\susp(A)\to\type$ with the property that $P(x,y)$ is a mere proposition for each $x,y:\susp(A)$, and which is equivalent to its identity type $\idtypevar{\susp(A)}$. % We make the following definitions: \begin{align*} P(\north,\north) & \defeq \unit & P(\south,\north) & \defeq A\\ P(\north,\south) & \defeq A & P(\south,\south) & \defeq \unit. \end{align*} We have to check that the definition preserves paths. Given any $a : A$, there is a meridian $\merid(a) : \north = \south$, so we should also have % \begin{equation*} P(\north, \north) = P(\north, \south) = P(\south, \north) = P(\south, \south). \end{equation*} % But since $A$ is inhabited by $a$, it is equivalent to $\unit$, so we have % \begin{equation*} P(\north, \north) \eqvsym P(\north, \south) \eqvsym P(\south, \north) \eqvsym P(\south, \south). \end{equation*} % The univalence axiom turns these into the desired equalities. Also, $P(x,y)$ is a mere proposition for all $x, y : \susp(A)$, which is proved by induction on $x$ and $y$, and using the fact that being a mere proposition is a mere proposition. Note that $P$ is a reflexive relation. Therefore we may apply \cref{thm:h-set-refrel-in-paths-sets}, so it suffices to construct $\tau : \prd{x,y:\susp(A)}P(x,y)\to(x=y)$. We do this by a double induction. When $x$ is $\north$, we define $\tau(\north)$ by % \begin{equation*} \tau(\north,\north,u) \defeq \refl{\north} \qquad\text{and}\qquad \tau(\north,\south,a) \defeq \merid(a). \end{equation*} % If $A$ is inhabited by $a$ then $\merid(a) : \north = \south$ so we also need \narrowequation{ \trans{\merid(a)}{\tau(\north, \north)} = \tau(\north, \south). } This we get by function extensionality using the fact that, for all $x : A$, % \begin{multline*} \trans{\merid(a)}{\tau(\north,\north,x)} = \tau(\north,\north,x) \ct \opp{\merid(a)} \jdeq \\ \refl{\north} \ct \merid(a) = \merid(a) = \merid(x) \jdeq \tau(\north, \south, x). \end{multline*} In a symmetric fashion we may define $\tau(\south)$ by % \begin{equation*} \tau(\south,\north, a) \defeq \opp{\merid(a)} \qquad\text{and}\qquad \tau(\south,\south, u) \defeq \refl{\south}. \end{equation*} % To complete the construction of $\tau$, we need to check $\trans{\merid(a)}{\tau(\north)} = \tau(\south)$, given any $a : A$. The verification proceeds much along the same lines by induction on the second argument of $\tau$. Thus, by \cref{thm:h-set-refrel-in-paths-sets} we have that $\susp(A)$ is a set and that $P(x,y) \eqvsym (\id{x}{y})$ for all $x,y:\susp(A)$. Taking $x\defeq \north$ and $y\defeq \south$ yields $\eqv{A}{(\id[\susp(A)]\north\south)}$ as desired. \end{proof} \begin{thm}[Diaconescu]\label{thm:1surj_to_surj_to_pem} \index{axiom!of choice}% \index{excluded middle}% \index{Diaconescu's theorem}\index{theorem!Diaconescu's}% The axiom of choice implies the law of excluded middle. \end{thm} \begin{proof} We use the equivalent form of choice given in \cref{thm:ac-epis-split}. Consider a mere proposition $A$. The function $f:\bool\to\susp(A)$ defined by $f(\bfalse) \defeq \north$ and $f(\btrue) \defeq \south$ is surjective. Indeed, we have $\pairr{\bfalse,\refl{\north}} : \hfiber{f}{\north}$ and $\pairr{\btrue,\refl{\south}} :\hfiber{f}{\south}$. Since $\bbrck{\hfiber{f}{x}}$ is a mere proposition, by induction the claimed surjectivity follows. By \cref{prop:trunc_of_prop_is_set} the suspension $\susp(A)$ is a set, so by the axiom of choice there merely exists a section $g: \susp(A) \to \bool$ of $f$. As equality on $\bool$ is decidable we get \begin{equation*} (g(f(\bfalse))= g(f(\btrue))) + \lnot (g(f(\bfalse))= g(f(\btrue))), \end{equation*} and, since $g$ is a section of $f$, hence injective, \begin{equation*} (f(\bfalse) = f(\btrue)) + \lnot (f(\bfalse) = f(\btrue)). \end{equation*} Finally, since $(f(\bfalse)=f(\btrue)) = (\north=\south) = A$ by \cref{prop:trunc_of_prop_is_set}, we have $A+\neg A$. \end{proof} % This conclusion needs only \LEM{}, see \cref{ex:lemnm}. % \begin{cor}\label{cor:ACtoLEM0} % If the axiom of choice \choice{} holds then $\brck{A + \neg A}$ for every set $A$. % \end{cor} % \begin{proof} % There is a surjection % \[ % A + \neg A \epi \brck{A} + \brck{\neg A} \epi % \brck{(\brck{A} + \brck{\neg A})} = \brck{A} \vee \brck{\neg A} = \brck{A} \vee \neg \brck{A} = \unit, % \] % % % where in the last step excluded middle is available as a consequence of the axiom of choice. % Again by the axiom of choice there merely exists a section of the surjection, but this % is none other than an inhabitant of $A + \neg A$. Therefore $\brck{A+\neg A}$. % \end{proof} \index{denial} \begin{thm}\label{thm:ETCS} \index{Elementary Theory of the Category of Sets}% \index{category!well-pointed}% If the axiom of choice holds then the category $\uset$ is a well-pointed boolean\index{topos!boolean}\index{boolean!topos} elementary topos\index{topos} with choice. \end{thm} \begin{proof} Since \choice{} implies \LEM{}, we have a boolean elementary topos with choice by \cref{thm:settopos} and the remark following it. We leave the proof of well-pointedness as an exercise for the reader (\cref{ex:well-pointed}). \end{proof} \begin{rmk} The conditions on a category mentioned in the theorem are known as Lawvere's\index{Lawvere} axioms for the \emph{Elementary Theory of the Category of Sets}~\cite{lawvere:etcs-long}. \end{rmk} \section{Cardinal numbers} \label{sec:cardinals} \begin{defn}\label{defn:card} The \define{type of cardinal numbers} \indexdef{type!of cardinal numbers}% \indexdef{cardinal number}% \indexsee{number!cardinal}{cardinal number}% is the 0-truncation of the type \set of sets: \[ \card \defeq \pizero{\set} \] Thus, a \define{cardinal number}, or \define{cardinal}, is an inhabitant of $\card\jdeq \pizero\set$. Technically, of course, there is a separate type $\card_\UU$ associated to each universe \type. \end{defn} %\begin{rmk} % , but with these conventions we can state theorems beginning with ``for all cardinal numbers\dots''\ and give them exactly the same sort of meaning as those beginning ``for all types\dots''. %\end{rmk} As usual for truncations, if $A$ is a set, then $\cd{A}$ denotes its image under the canonical projection $\set \to \trunc0\set \jdeq \card$; we call $\cd{A}$ the \define{cardinality}\indexdef{cardinality} of $A$. By definition, \card is a set. It also inherits the structure of a semiring from \set. \begin{defn} The operation of \define{cardinal addition} \indexdef{addition!of cardinal numbers}% \index{cardinal number!addition of}% \[ (\blank+\blank) : \card \to \card \to \card \] is defined by induction on truncation: \[ \cd{A} + \cd{B} \defeq \cd{A+B}.\] \end{defn} \begin{proof} Since $\card\to\card$ is a set, to define $(\alpha+\blank):\card\to\card$ for all $\alpha:\card$, by induction it suffices to assume that $\alpha$ is $\cd{A}$ for some $A:\set$. Now we want to define $(\cd{A}+\blank) :\card\to\card$, i.e.\ we want to define $\cd{A}+\beta :\card$ for all $\beta:\card$. However, since $\card$ is a set, by induction it suffices to assume that $\beta$ is $\cd{B}$ for some $B:\set$. But now we can define $\cd{A}+\cd{B}$ to be $\cd{A+B}$. \end{proof} \begin{defn} Similarly, the operation of \define{cardinal multiplication} \indexdef{multiplication!of cardinal numbers}% \index{cardinal number!multiplication of}% \[ (\blank\cdot\blank) : \card \to \card \to \card \] is defined by induction on truncation: \[ \cd{A} \cdot \cd{B} \defeq \cd{A\times B} \] \end{defn} \begin{lem}\label{card:semiring} \card is a commutative semiring\index{semiring}, i.e.\ for $\alpha,\beta,\gamma:\card$ we have the following. \begin{align*} (\alpha+\beta)+\gamma &= \alpha+(\beta+\gamma)\\ \alpha+0 &= \alpha\\ \alpha + \beta &= \beta + \alpha\\ (\alpha \cdot \beta) \cdot \gamma &= \alpha \cdot (\beta\cdot\gamma)\\ \alpha \cdot 1 &= \alpha\\ \alpha\cdot\beta &= \beta\cdot\alpha\\ \alpha\cdot(\beta+\gamma) &= \alpha\cdot\beta + \alpha\cdot\gamma \end{align*} where $0 \defeq \cd{\emptyt}$ and $1\defeq\cd{\unit}$. \end{lem} \begin{proof} We prove the commutativity of multiplication, $\alpha\cdot\beta = \beta\cdot\alpha$; the others are exactly analogous. Since \card is a set, the type $\alpha\cdot\beta = \beta\cdot\alpha$ is a mere proposition, and in particular a set. Thus, by induction it suffices to assume $\alpha$ and $\beta$ are of the form $\cd{A}$ and $\cd{B}$ respectively, for some $A,B:\set$. Now $\cd{A}\cdot \cd{B} \jdeq \cd{A\times B}$ and $\cd{B}\times\cd{A} \jdeq \cd{B\times A}$, so it suffices to show $A\times B = B\times A$. Finally, by univalence, it suffices to give an equivalence $A\times B \eqvsym B\times A$. But this is easy: take $(a,b) \mapsto (b,a)$ and its obvious inverse. \end{proof} \begin{defn} The operation of \define{cardinal exponentiation} is also defined by induction on truncation: \indexdef{exponentiation, of cardinal numbers}% \index{cardinal number!exponentiation of}% \[ \cd{A}^{\cd{B}} \defeq \cd{B\to A}. \] \end{defn} \begin{lem}\label{card:exp} For $\alpha,\beta,\gamma:\card$ we have \begin{align*} \alpha^0 &= 1\\ 1^\alpha &= 1\\ \alpha^1 &= \alpha\\ \alpha^{\beta+\gamma} &= \alpha^\beta \cdot \alpha^\gamma\\ \alpha^{\beta\cdot \gamma} &= (\alpha^{\beta})^\gamma\\ (\alpha\cdot\beta)^\gamma &= \alpha^\gamma \cdot \beta^\gamma \end{align*} \end{lem} \begin{proof} Exactly like \cref{card:semiring}. \end{proof} \begin{defn} The relation of \define{cardinal inequality} \index{order!non-strict}% \index{cardinal number!inequality of}% \[ (\blank\le\blank) : \card\to\card\to\prop \] is defined by induction on truncation: \symlabel{inj} \[ \cd{A} \le \cd{B} \defeq \brck{\inj(A,B)} \] where $\inj(A,B)$ is the type of injections from $A$ to $B$. \index{function!injective}% In other words, $\cd{A} \le \cd{B}$ means that there merely exists an injection from $A$ to $B$. \end{defn} \begin{lem} Cardinal inequality is a preorder, i.e.\ for $\alpha,\beta:\card$ we have \index{preorder!of cardinal numbers}% \begin{gather*} \alpha \le \alpha\\ (\alpha \le \beta) \to (\beta\le\gamma) \to (\alpha\le\gamma) \end{gather*} \end{lem} \begin{proof} As before, by induction on truncation. For instance, since $(\alpha \le \beta) \to (\beta\le\gamma) \to (\alpha\le\gamma)$ is a mere proposition, by induction on 0-truncation we may assume $\alpha$, $\beta$, and $\gamma$ are $\cd{A}$, $\cd{B}$, and $\cd{C}$ respectively. Now since $\cd{A} \le \cd{C}$ is a mere proposition, by induction on $(-1)$-truncation we may assume given injections $f:A\to B$ and $g:B\to C$. But then $g\circ f$ is an injection from $A$ to $C$, so $\cd{A} \le \cd{C}$ holds. Reflexivity is even easier. \end{proof} We may likewise show that cardinal inequality is compatible with the semiring operations. \begin{lem}\label{thm:injsurj} \index{function!injective}% \index{function!surjective}% Consider the following statements: \begin{enumerate} \item There is an injection $A\to B$.\label{item:cle-inj} \item There is a surjection $B\to A$.\label{item:cle-surj} \end{enumerate} Then, assuming excluded middle: \index{excluded middle}% \index{axiom!of choice}% \begin{itemize} \item Given $a_0:A$, we have~\ref{item:cle-inj}$\to$\ref{item:cle-surj}. \item Therefore, if $A$ is merely inhabited, we have~\ref{item:cle-inj} $\to$ merely \ref{item:cle-surj}. \item Assuming the axiom of choice, we have~\ref{item:cle-surj} $\to$ merely \ref{item:cle-inj}. \end{itemize} \end{lem} \begin{proof} If $f:A\to B$ is an injection, define $g:B\to A$ at $b:B$ as follows. Since $f$ is injective, the fiber of $f$ at $b$ is a mere proposition. Therefore, by excluded middle, either there is an $a:A$ with $f(a)=b$, or not. In the first case, define $g(b)\defeq a$; otherwise set $g(b)\defeq a_0$. Then for any $a:A$, we have $a = g(f(a))$, so $g$ is surjective. The second statement follows from this by induction on truncation. For the third, if $g:B\to A$ is surjective, then by the axiom of choice, there merely exists a function $f:A\to B$ with $g(f(a)) = a$ for all $a$. But then $f$ must be injective. \end{proof} \begin{thm}[Schroeder--Bernstein] \index{theorem!Schroeder--Bernstein}% \index{Schroeder--Bernstein theorem}% Assuming excluded middle, for sets $A$ and $B$ we have \[ \inj(A,B) \to \inj(B,A) \to (A\cong B) \] \end{thm} \begin{proof} The usual ``back-and-forth'' argument applies without significant changes. Note that it actually constructs an isomorphism $A\cong B$ (assuming excluded middle so that we can decide whether a given element belongs to a cycle, an infinite chain, a chain beginning in $A$, or a chain beginning in $B$). \end{proof} \begin{cor} Assuming excluded middle, cardinal inequality is a partial order, i.e.\ for $\alpha,\beta:\card$ we have \[ (\alpha\le\beta) \to (\beta\le\alpha) \to (\alpha=\beta). \] \end{cor} \begin{proof} Since $\alpha=\beta$ is a mere proposition, by induction on truncation we may assume $\alpha$ and $\beta$ are $\cd{A}$ and $\cd{B}$, respectively, and that we have injections $f:A\to B$ and $g:B\to A$. But then the Schroeder--Bernstein theorem gives an isomorphism $A\cong B$, hence an equality $\cd{A}=\cd{B}$. \end{proof} Finally, we can reproduce Cantor's theorem, showing that for every cardinal there is a greater one. \begin{thm}[Cantor] \index{Cantor's theorem}% \index{theorem!Cantor's}% For $A:\set$, there is no surjection $A \to (A\to \bool)$. \end{thm} \begin{proof} Suppose $f:A \to (A\to \bool)$ is any function, and define $g:A\to \bool$ by $g(a) \defeq \neg f(a)(a)$. If $g = f(a_0)$, then $g(a_0) = f(a_0)(a_0)$ but $g(a_0) = \neg f(a_0)(a_0)$, a contradiction. Thus, $f$ is not surjective. \end{proof} \begin{cor} Assuming excluded middle, for any $\alpha:\card$, there is a cardinal $\beta$ such that $\alpha\le\beta$ and $\alpha\neq\beta$. \end{cor} \begin{proof} Let $\beta = 2^\alpha$. Now we want to show a mere proposition, so by induction we may assume $\alpha$ is $\cd{A}$, so that $\beta\jdeq \cd{A\to \bool}$. Using excluded middle, we have a function $f:A\to (A\to \bool)$ defined by \[f(a)(a') \defeq \begin{cases} \btrue &\quad a=a'\\ \bfalse &\quad a\neq a'. \end{cases} \] And if $f(a)=f(a')$, then $f(a')(a) = f(a)(a) = \btrue$, so $a=a'$; hence $f$ is injective. Thus, $\alpha \jdeq \cd{A} \le \cd{A\to \bool} \jdeq 2^\alpha$. On the other hand, if $2^\alpha \le \alpha$, then we would have an injection $(A\to\bool)\to A$. By \cref{thm:injsurj}, since we have $(\lam{x} \bfalse):A\to \bool$ and excluded middle, there would then be a surjection $A \to (A\to \bool)$, contradicting Cantor's theorem. \end{proof} \section{Ordinal numbers} \label{sec:ordinals} \index{ordinal|(}% \begin{defn}\label{defn:accessibility} Let $A$ be a set and \[(\blank<\blank):A\to A\to \prop\] a binary relation on $A$. We define by induction what it means for an element $a:A$ to be \define{accessible} \indexdef{accessibility}% \indexsee{accessible}{accessibility}% by $<$: \begin{itemize} \item If $b$ is accessible for every $ba$. Thus, $A'$ is itself an ordinal. Finally, since \ord is an ordinal, we can take $A\defeq\ord$. Let $X'$ be the image of $g_\ord':\ord' \to X$; then the inverse of $g_\ord'$ yields an injection $H:X'\to \ord$. By \cref{thm:ordunion}, there is an ordinal $C$ such that $Hx\le C$ for all $x:X'$. Then by \cref{thm:ordsucc}, there is a further ordinal $D$ such that $C