Dependent types II › More on identifications [01J9]
- August 27, 2025
- Jon Sterling
Flipping identifications [01EJ]
- October 15, 2025
- Jon Sterling
Fix A~\mathit {type} and u,v:A. Given an identification p:u=_Av we should be able to define a “flipped” identification \bar {p}:v=_Au. We will do so by means of an implicit definition:
\begin {aligned} & \mathsf {flip}: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v:A)}}\; u=_Av\to v=_Au \\ & \mathsf {flip}~u~u~\mathsf {refl}_u :\equiv \mathsf {refl}_u \end {aligned}Then we define \bar {p}:\equiv \mathsf {flip}\,u\,v\,p when u,v are understood.
Above we were allowed to collapse the pair (v,p) to (u,\mathsf {refl}_u) by virtue of the identification elimination rule. The corresponding explicit definition is as follows:
\mathsf {flip} :\equiv \lambda u,v,p\mathpunct {.} \mathsf {J}_{y,z\mathpunct {.}y=u}(p; \mathsf {refl}_u)Lemma Flipping is involutive [01EK]
- October 15, 2025
- Jon Sterling
Given p:u=_Av, we may identify p with \overline {\overline {p}}. In particular, we may construct the following witness of involution:
\begin {aligned} & \mathsf {flipInv} : {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(p:u=_Av)}} \overline {\overline {p}}=_{u=_Av} p \\ & \mathsf {flipInv}~u~u~\mathsf {refl}_u :\equiv \mathsf {refl}_{\mathsf {refl}_u} \end {aligned}The implicit definition above is justified by the following closed form:
\mathsf {flipInv} :\equiv \lambda u,v,p\mathpunct {.} \mathsf {J}_{y,q\mathpunct {.} \overline {\overline {q}} =_{u=_Ay} q}(p; \mathsf {refl}_{\mathsf {refl}_u})Definition Fibres [01ES]
By combining function types, dependent pair types, and identification types, we can finally define something useful. Given a function f:A\to B and an element b:B, we define the fibre of f over b to by the type of elements of A whose image in B is identified with b:
\mathsf {fib}_f(b) :\equiv {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}} fx=_B bWe could have defined fibres with an equation in the opposite direction. The two versions are going to be equivalent; but if it matters, we’ll write the following notations:
\begin {aligned} \mathsf {fib}^-_f(b) &:\equiv {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{fx=_Bb} \\ \mathsf {fib}^+_f(b) &:\equiv {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}}{b=_B fx} \end {aligned}Singletons and singleton induction [01J6]
- October 15, 2025
- Jon Sterling
A special case of fibres is the singleton types.
Definition Inward and outward singleton types [01J7]
- October 15, 2025
- Jon Sterling
Given an element u:A, we may define the “inward” and “outward” singleton types respectively as follows:
\begin {aligned} \left \{u\right \}^-_{A} &:\equiv \mathsf {fib}^-_{1_A}(u) \equiv {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}} x=_Au \\ \left \{u\right \}^+_{A} &:\equiv \mathsf {fib}^+_{1_A}(u) \equiv {\mathop {\mathchoice {\textstyle \sum }{\textstyle \sum }{\scriptstyle \sum }{\scriptscriptstyle \sum } }_{(x:A)}} u=_Ax \end {aligned}Both the inward and outward singletons at u are inhabited by the pair \left \langle u,\mathsf {refl}_u\right \rangle .
Singleton induction [01J8]
- October 15, 2025
- Jon Sterling
We will now see how to reformulate the identification elimination rule into an “induction principle” for singletons. The idea is the following:
If you want to prove something about all \left \{u\right \}^\pm _{A} it suffices to consider just the trivial element \left \langle u,\mathsf {refl}_u\right \rangle .
In other words, \left \langle u,\mathsf {refl}_u\right \rangle is the “base case” for an induction on \left \{u\right \}^\pm _{A}, in the same way that 0 is the base case for mathematical induction; the induction here is simpler than mathematical induction, because there is only a base case and no inductive step.
We will derive singleton induction using the \mathsf {J} elimination rule, which we recall below:
\frac { w:u=_Av\quad y:A,z:u=_Ay\vdash C[y,z]~\mathit {type}\quad c:C[u,\mathsf {refl}_u] }{ \mathsf {J}_{y,z\mathpunct {.} C[y,z]}(w; c) :C[v,w] }We wish to define the following derived forms:
\frac { z:\left \{u\right \}^-_{A}\vdash C[z]~\mathit {type} \quad p:\left \{u\right \}^\pm _{A} \quad c:C[\left \langle u,\mathsf {refl}_u\right \rangle ] }{ \mathsf {J}^\pm _{z\mathpunct {.}{C[z]}}(p; c): C[p] }We can specify the following implicit definitions for the derived induction principles:
\begin {aligned} \mathsf {J}^+_{z\mathpunct {.}C[z]}(\left \langle u,\mathsf {refl}_u\right \rangle ; c) &:\equiv c\\ \mathsf {J}^-_{z\mathpunct {.}C[z]}(\left \langle u,\mathsf {refl}_u\right \rangle ; c) &:\equiv c \end {aligned}The first one above is easy to justify:
\begin {aligned} \mathsf {J}^+_{z\mathpunct {.}{C[z]}}(p; c) &:\equiv \mathsf {J}_{y,z\mathpunct {.}{C[\left \langle y,z\right \rangle ]}}( p.2 ; c) \end {aligned}The second one is harder to justify. It turns out that the simplest way to proceed is to first define a “defective” version of \mathsf {J}^- in terms of \mathsf {J}^- that has the wrong type, and then use transport to correct the type. In particular, we define:
\begin {aligned} & \tilde {\mathsf {J}}^-_{z\mathpunct {.}C[z]}(p;c) : C \left \langle p.1, \overline {\overline {p.2}}\right \rangle \\ &\tilde {\mathsf {J}}^-_{z\mathpunct {.}C[z]}(p;c) :\equiv \mathsf {J}^+_{z\mathpunct {.}{C\left [\left \langle z.1,\overline {z.2}\right \rangle \right ]}}\left (\left \langle p.1,\overline {p.2}\right \rangle ; c\right ) \end {aligned}Then we define:
\mathsf {J}^-_{z\mathpunct {.}{C[z]}}(p; c) :\equiv \mathsf {transport}_{q\mathpunct {.} C[\left \langle p.1,q\right \rangle ]}(\mathsf {flipInv}~(p.1)~u~(p.2); \tilde {\mathsf {J}}^-_{z\mathpunct {.}C[z]}(p;c) )You need to convince yourself that all of the above is well-typed.
The benefit of singleton induction is that it provides a (perhaps) less noisy way to think about the identification elimination rule, and gives a schema for defining correct implicit definitions by “matching” on identifications no matter which side of the identification the “fixed” variable is located.
The three operations \mathsf {J}, \mathsf {J}^+, and \mathsf {J}^- are all equivalent, in the sense that you can derive any two from the remaining one. There is a further option seen in Exercise [01EE], which is also equivalent to all of these. In the end, we work mainly with implicit definitions which we know to be justified by any one of these principles.
Contractibility of singletons [01ER]
Using singleton induction, we can easily prove that any singleton \left \{u\right \}^\pm _{A} is “really” a singleton, in the sense that all its elements are equal to the trivial element \left \langle u,\mathsf {refl}_u\right \rangle . This property is called contractibility, which we will learn about in generality later. In particular, singleton elimination justifies the following implicit definition:
\begin {aligned} &\mathsf {singlContr}_A^\pm : {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(s:\left \{u\right \}^\pm _{A})}} s=_{\left \{u\right \}^\pm _{A}} \left \langle u,\mathsf {refl}_u\right \rangle \\ &\mathsf {singlContr}_A^\pm ~u~\left \langle u,\mathsf {refl}_u\right \rangle :\equiv \mathsf {refl}_{\left \langle u,\mathsf {refl}_u\right \rangle } \end {aligned}Before we justify this with an explicit definition, we will first explain the “idea” of the definition in English.
- We have u:A and s:\left \{u\right \}^\pm _{A} and we are trying to construct \mathsf {singlContr}_A^\pm ~u~s : s =_{\left \{u\right \}^\pm _{A}} \left \langle u,\mathsf {refl}_u\right \rangle .
- By singleton induction it suffices to consider just the case where s \equiv \left \langle u,\mathsf {refl}_u\right \rangle ; in this case, then, we are trying to construct \mathsf {singlContr}_A^\pm ~\left \langle u,\mathsf {refl}_u\right \rangle : \left \langle u,\mathsf {refl}_u\right \rangle =_{\left \{u\right \}^\pm _{A}} \left \langle u,\mathsf {refl}_u\right \rangle .
- We finish off with the reflexive identification.
The explicit definition is as follows:
\mathsf {singlContr}^\pm _A :\equiv \lambda u,s\mathpunct {.} \mathsf {J}^\pm _{z\mathpunct {.} z=_{\left \{u\right \}^\pm _{A}} \left \langle u,\mathsf {refl}_u\right \rangle }(s; \mathsf {refl}_{\left \langle u,\mathsf {refl}_u\right \rangle })Pasting identifications [01EH]
- October 15, 2025
- Jon Sterling
Fix A~\mathit {type} and u,v,w:A. Given p:u=_Av and q:v=_Aw we may define an identification p\cdot q:u=_Aw. The idea of the pasting operation is to use identification elimination to consider just the case where (v,p) \equiv (u,\mathsf {refl}_u); in that case we would have q:u=_Aw and so we may just return that. We first give an implicit definition of the pasting operation, and then we will show that it is well-defined by constructing an explicit definition:
\begin {aligned} & \mathsf {paste}: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v,w:A)}} \; u=_Av\to v=_Aw\to u=_Aw \\ & \mathsf {paste}~u~u~w~\mathsf {refl}_{u}~q :\equiv q \end {aligned}Then we would define p\cdot q :\equiv \mathsf {paste}~u~v~w~p~q when u,v,w are understood.
In our implicit definition above, we have given an equation just for the case where the first two vertices are exactly the same and the first edge is the trivial one. The informal rule of thumb is that when you are binding a pair (v,p) of an identification p:u=_Av with one of its endpoints, you are free to collapse this data to (u,\mathsf {refl}_u); when both endpoints are fixed, you can’t do this. The collapsing move used above is justified by the identification elimination rule, which we can show by instantiating the above with an explicit definition.
\begin {aligned} & \mathsf {paste}: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v,w:A)}} \; u=_Av\to v=_Aw\to u=_Aw \\ & \mathsf {paste} :\equiv \lambda u,v,w,p\mathpunct {.} \mathsf {J}_{ y,z\mathpunct {.} y=_Aw\to u=_Aw }(p; \lambda q\mathpunct {.}{q}) \end {aligned}We verify that the defining equation holds:
\begin {aligned} &\mathsf {paste}~u~u~w~\mathsf {refl}_u~q \\ &\quad \equiv \mathsf {J}_{y,z\mathpunct {.}y=_Aw\to u=_Aw}(\mathsf {refl}_u; \lambda q\mathpunct {.}{q}) ~q \\ &\quad \equiv (\lambda q\mathpunct {.}{q})~q \\ &\quad \equiv q \end {aligned}If you are not yet confident in the use of implicit definitions, you should verify that this equation uniquely defines \mathsf {paste}. In particular, we might check for any f:{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v,w:A)}}u=_Av\to v=_Aw\to u=_Aw satisfying f~u~u~w~\mathsf {refl}_u~q \equiv q we may find some family of identifications H_f: {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v,w:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(p:u=_Av)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(q:v=_Aw)}} fuvwpq =_{u=_Aw} \mathsf {paste}~u~v~w~p~q \text {.}
For clarity, we give an implicit definition of H_f:
H_f~u~u~w~\mathsf {refl}_u~q :\equiv \mathsf {refl}_qThe corresponding explicit definition would be a more complicated instance of \mathsf {J}:
H_f :\equiv \lambda u,v,w,p\mathpunct {.} \mathsf {J}_{ y,z\mathpunct {.} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(q:y=_Aw)}} fuywzq =_{u=_Aw} \mathsf {paste}~u~y~w~z~q }(p; \lambda q\mathpunct {.} \mathsf {refl}_q )Basic results [01EL]
- October 15, 2025
- Jon Sterling
Exercise Pasting is associative [01EM]
- October 15, 2025
- Jon Sterling
Construct an element of the following type witnessing that pasting is associative:
{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v,w,x:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(p:u=_Av)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(q:v=_Aw)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(r:w=_Ax)}} u\cdot (v\cdot w) =_{u=_Aw} (u\cdot v) \cdot wExercise Flipping inverts identifications [01EN]
- October 15, 2025
- Jon Sterling
Construct an element of the following type witnessing that the result of composing an identification with its flipping is trivial:
{\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(u,v:A)}} {\mathop {\mathchoice {\textstyle \prod }{\textstyle \prod }{\scriptstyle \prod }{\scriptscriptstyle \prod } }_{(p:u=_Av)}} p\cdot \bar p =_{u=_Au} \mathsf {refl}_u