@@ -3097,63 +3097,70 @@ \section{The replacement principle}
30973097\section {Predicates and subtypes }
30983098\label {sec:subtype }
30993099
3100- In this section, we consider the relationship between predicates on a type $ T $
3101- and subtypes of $ T$ . The basic idea is that the predicate tells
3102- whether an element of $ T$ belongs to the subtype. Conversely ,
3103- the predicate can be recovered from the subtype by asking whether an element of $ T $
3104- is in it .
3100+ In this section, we give two (equivalent) definitions of the notion
3101+ of a subtype of a given type $ T$ . The first definition is based
3102+ on the notion of a predicate on $ T$ . A predicate tells, or `predicates' ,
3103+ whether an element of $ T $ belongs to the subtype. The second definition
3104+ is based on the notion of injection, defined in \cref { def:injection } .
31053105
31063106\begin {definition }\label {def:predicate }
31073107 Let $ T$ be a type and let $ P(t)$ be a family of propositions
3108- parametrized by an variable $ t:T$ .
3108+ parametrized by a variable $ t:T$ .
31093109 Then we call $ P$ a \emph {predicate }\index {predicate} on $ T$ .\footnote {%
31103110 Note that giving a predicate on $ T$ is
31113111 equivalent to giving a map $ Q: T\to\Prop _\UU $ for a suitable universe $ \UU $ ,
3112- and we sometimes say that $ Q$ itself is the predicate.}
3113- If $ P(t)$ is a decidable proposition,
3112+ and we sometimes say that $ Q$ itself is the predicate.
3113+ We leave $ \UU $ implicit.}
3114+ If $ P(t)$ is a decidable proposition for any $ t:T$ ,
31143115 then we say that $ P$ is a \emph {decidable predicate } on $ T$ .
31153116\end {definition }
31163117
3117- By \cref {xca:lem-prop }, the decidable predicates $ P$ on $ T$
3118- correspond uniquely to the characteristic functions $ \chi _P:T\to\bool $ .
3119-
3120- We recall from \cref {def:injection } the notion of \emph {injection },
3121- which will be key to saying what a \emph {subtype } is.
3122-
3118+ The decidable predicates $ P$ on $ T$
3119+ correspond uniquely to the characteristic functions $ \chi _P:T\to\bool $ ,
3120+ cf.\ \cref {xca:lem-prop }.
31233121
31243122\begin {definition }\label {def:subtype }
3125- A \emph {subtype }\index {subtype} of a type $ T$
3126- is a type $ S$ together with an injection $ f : S \to T$ .%
3127- \glossary (SubT){$ \protect\Sub (T)$ }{type of subtypes of $ T$ }
3128- The type $ S$ is called the \emph {underlying type } of this subtype.
3129- Selecting a universe $ \UU $ as a repository for such types $ S$ allows
3130- us to introduce the type of subtypes of $ T$ in $ \UU $ as follows.
3123+ Let $ T$ be a type.
3124+ The type of \emph {subtypes }\index {subtype} of $ T$ ,
3125+ denoted by $ \Sub (T)$ , is defined by
31313126 \[
3132- \Sub ^ \UU (T) \defeq \sum _{S: \UU } \sum _{f:S \to T} \isinj (f ).
3127+ \Sub (T) \defeq (T \to\Prop ).
31333128 \]
3134- When no confusion can arise, we simply write $ \Sub (T)$ for $ \Sub ^\UU (T)$ .
3135- \end {definition }
3129+ Given a predicate $ P$ on $ T$ , we define $ T_P\defeq \sum _{t:T} P(t)$
3130+ to be the \emph {underlying type } of the subtype of $ T$ characterized by $ P$ .
3131+ \end {definition }
31363132
3137- \begin {xca }\label {xca:subtypes-set }
3138- Show that $ \Sub (T)$ is a set, for any type $ T$ . Hint:
3139- given subtypes $ T_f\defeq (S,f,p)$ and $ T_{f'}\defeq (S',f',p')$ of $ T$ ,
3140- show that $ T_f=T_{f'}$ amounts to finding a (unique) equivalence%
3141- \marginnote {%
3133+ Since $ \Prop $ is a set, $ \Sub (T)$ is also a set, for any type $ T$ .
3134+
3135+ \begin {xca }\label {xca:subtype-univ-prop }
3136+ Let $ T$ and $ X$ be types, $ f: X\to T$ a function,
3137+ and $ P : T\to\Prop $ a predicate. Show that $ \prod _{x:X} P(f(x))$
3138+ \marginnote {%
31423139 \[
31433140 \begin {tikzcd }[ampersand replacement=\& ]
3144- S \ar [rr,"{e}","{\sim }"']\ar [dr,"{f}"'] \& \& S'\ar [dl,"{f'}"] \\
3145- \& T \&
3141+ X \ar [dd,dashed,"g"']\ar [r,"f"] \& T \\
3142+ \\
3143+ \sum _{t:T} P(t) \ar [uur,"{\fst }"']
31463144 \end {tikzcd }
3147- \] }
3148- $ e: S\equivto S'$ such that $ f = f'\circ e$ . See the diagram in the margin.
3145+ \] }
3146+ holds if and only if the following type, visualized in the margin,
3147+ is contractible:
3148+ \begin {displaymath }
3149+ \sum _{g: X \to \sum _{t:T} P(t)} f \eqto \fst\circ g.
3150+ \end {displaymath }
31493151\end {xca }
31503152
3153+ We call the result in \cref {xca:subtype-univ-prop } the
3154+ \emph {universal property of subtypes }.
3155+ The following lemma states that identity types in a
3156+ subtype are equivalent to those in the type itself.
3157+
31513158\begin {lemma }\label {lem:subtype-eq- =}
31523159 Let $ T$ be a type and $ P$ a predicate on $ T$ .
3153- Consider $ \sum _{t:T}P(t) $ and the corresponding projection map
3154- $ \fst : T_P \defeq \Bigl (\sum _{t:T}P(t)\Bigr ) \ to T$ .
3155- Then $ \ap {\fst }: ((x_1 ,p_1 ) \eqto (x_2 ,p_2 )) \to (x_1 \eqto x_2 )$ is an equivalence,
3156- for any elements $ (x_1 ,p_1 )$ and $ (x_2 ,p_2 )$ of $ T_P$ .
3160+ Consider the projection map $ \fst $ from the underlying type
3161+ $ T_P \jdeq \Bigl (\sum _{t:T}P(t)\Bigr )$ to $ T$ .
3162+ Then $ \ap {\fst }: ((x_1 ,p_1 ) \eqto (x_2 ,p_2 )) \to (x_1 \eqto x_2 )$ is an
3163+ equivalence, for any elements $ (x_1 ,p_1 )$ and $ (x_2 ,p_2 )$ of $ T_P$ .
31573164\end {lemma }
31583165
31593166\begin {proof }
@@ -3166,15 +3173,86 @@ \section{Predicates and subtypes}
31663173These give identifications in $ \ap {\fst }\pathpair q {c_q} \eqto q$
31673174for all $ q: x_1 \eqto x_2 $ .
31683175Also, for any $ r: (x_1 ,p_1 ) \eqto (x_2 ,p_2 )$ we have an identification
3169- in $ r \eqto \pathpair {\fst (r)}{\snd (r)}$ .
3170- The latter pair can be identified with
3171- $ \pathpair {\ap {\fst (r)}}{c}$ for any $ c$
3176+ in $ r \eqto \pathpair {\fst (r)}{\snd (r)}$ .\footnote {%
3177+ Note that $ \fst (r)\jdeq\ap {\fst }(r)$ , since $ r$ is a path,
3178+ and similarly for $ \snd $ .}
3179+ The right hand side of the latter can be identified with
3180+ $ \pathpair {\ap {\fst }(r)} {c}$ for any $ c$
31723181in the contractible type $ \pathover {p_1} P {\fst (r)} {p_2}$ .
31733182\end {proof }
31743183
3175- Combined with \cref {lem:inj-ap },
3176- this gives that $ \fst $ is an injection.\footnote {%
3177- Alternatively, one uses that $ \inv\fst (t)\weq P(t)$ for all $ t:T$ .}
3184+ \cref {cor:contract-away } gives that $ \inv\fst (t)\weq P(t)$ for all $ t:T$ ,
3185+ so $ \fst : \sum _{t:T}P(t) \to T$ is an injection.
3186+ Such a pair $ (T_P,\fst )$ is actually an example of
3187+ the second approach to subtypes, which we will explain now.
3188+
3189+ \begin {definition }\label {def:injtype }
3190+ A \emph {injection into a type }\index {injection!into a type} $ T$
3191+ is a type $ S$ together with an injection $ f : S \to T$ .%
3192+ \glossary (Injinto){$ \protect\Inj (T)$ }{type of injections into $ T$ }
3193+ The type $ S$ is called the \emph {underlying type } of the injection into $ T$ .
3194+ Selecting a universe $ \UU $ as a repository for such types $ S$ allows
3195+ us to introduce the type of injections into $ T$ in $ \UU $ as follows.
3196+ \[
3197+ \Inj ^\UU (T) \defeq \sum _{S:\UU }\sum _{f:S\to T}\isinj (f).
3198+ \]
3199+ When no confusion can arise, we simply write $ \Inj (T)$ for $ \Inj ^\UU (T)$ .
3200+ \end {definition }
3201+
3202+ \cref {lem:subtype-eq- =} yields the following special case
3203+ of \cref {xca:subtype-univ-prop }.
3204+
3205+ \begin {lemma }\label {lem:subtype-univ-injection }
3206+ Let $ S$ and $ T$ be types and $ i:S\to T$ an injection, \ie all fibers
3207+ of $ i$ are propositions.
3208+ Then the following type is contractible:
3209+ \begin {displaymath }
3210+ \sum _{g: S \to \sum _{t:T} \inv i (t)} \isEq (g)\times (i \eqto \fst\circ g).
3211+ \end {displaymath }
3212+ \end {lemma }
3213+ \begin {proof }
3214+ We first note that we have a proof $ p(s)\defeq (s,\refl {i(s)})$
3215+ of the proposition $ \inv i (i(s))$ , for all $ s:S$ .
3216+ Hence \cref {xca:subtype-univ-prop } implies that the displayed type is
3217+ a proposition. Thus it suffices to show that the function $ g$ defined by
3218+ $ g(s)\defeq (i(s),p(s))$ is an equivalence. We show that all fibers
3219+ of $ g$ are contractible. Let $ (t,q):\sum _{t:T} \inv i (t)$ . Then
3220+ $ \inv i (t)$ is contractible.
3221+ Now, $ \inv g(t,q) \jdeq \sum _{s:S} ((t,q)\eqto (i(s),p(s)))$
3222+ is equivalent to $ \sum _{s:S} (t\eqto i(s))$ , by \cref {lem:subtype-eq- =},
3223+ and hence contractble since the latter type is $ \inv i (t)$ .
3224+ \end {proof }
3225+
3226+ \begin {lemma }\label {lem:Sub (T )=Inj (T )}
3227+ The function mapping any $ P:\Sub (T)$ to $ (T_P,\fst ):\Inj (T)$ is an
3228+ equivalence from $ \Sub (T)$ to $ \Inj (T)$ , for any type $ T$ .
3229+ \end {lemma }
3230+ \begin {proof }
3231+ We apply \cref {lem:weq-iso }.
3232+ The inverse equivalence maps $ (S,i):\Inj (T)$ to $ (t\mapsto \inv i (t)):\Sub (T)$ .
3233+ One round trip thus maps $ P$ to $ (t\mapsto \inv\fst (t))$ , and they can
3234+ be identified using function extensionality and \cref {cor:contract-away },
3235+ as already mentioned just above \cref {def:injtype }.
3236+
3237+ The other round trip maps $ (S,i)$ to $ (\sum _{t:T} \inv i (t),\fst )$ .
3238+ This can be identified using \cref {lem:subtype-univ-injection },
3239+ which provides an equivalence $ g$ as visualized in the diagram
3240+ in the margin.
3241+ \marginnote {%
3242+ \[
3243+ \begin {tikzcd }[ampersand replacement=\& ]
3244+ S \ar [rr,"{g}","{\sim }"']\ar [dr,"{i}"'] \& \& \sum _{t:T} \inv i (t)\ar [dl,"{\fst }"] \\
3245+ \& T \&
3246+ \end {tikzcd }
3247+ \] }
3248+ \end {proof }
3249+
3250+
3251+ Consequently, $ \Inj (T)$ is a set since $ \Sub (T)$ is, for any type $ T$ .
3252+
3253+ Cursor
3254+
3255+
31783256Hence, given a predicate $ P$ on $ T$ ,
31793257the \emph {subtype of $ T$ characterized by $ P$ } is defined
31803258as $ T_P\defeq \sum _{t:T} P(t)$ ,
@@ -3243,26 +3321,6 @@ \section{Predicates and subtypes}
32433321 with a least and a greatest element (even if $ T$ is the empty type).
32443322\end {xca }
32453323
3246- \begin {xca }\label {xca:subtype-univ-prop }
3247- Let $ T$ and $ X$ be types, $ f: X\to T$ a function,
3248- and $ P : T\to\Prop $ a predicate.
3249- \marginnote {%
3250- \[
3251- \begin {tikzcd }[ampersand replacement=\& ]
3252- X \ar [dd,dashed,"g"']\ar [r,"f"] \& T \\
3253- \\
3254- \sum _{t:T} P(t) \ar [uur,"{\fst }"']
3255- \end {tikzcd }
3256- \] }
3257- Construct an equivalence from the proposition
3258- $ \prod _{x:X} P(f(x))$ to the type
3259- \begin {displaymath }
3260- \sum _{g: X \to \sum _{t:T} P(t)} f \eqto \fst\circ g.
3261- \end {displaymath }
3262- We may call this result the \emph {universal property of subtypes }.
3263- \end {xca }
3264-
3265-
32663324\begin {remark }\label {rem:subtype-convention }
32673325 Another important consequence of~\cref {lem:subtype-eq- =}
32683326 is that we can afford not to distinguish carefully
0 commit comments