tag:blogger.com,1999:blog-58259748132747624182018-03-06T17:23:26.241+01:00Stepping into Homotopy Type TheoryMarc de Falconoreply@blogger.comBlogger3125tag:blogger.com,1999:blog-5825974813274762418.post-40848815876632102602013-11-17T21:02:00.003+01:002013-11-23T21:38:35.440+01:00Chapter 2 in the Agda proof assistantI've decided this morning to learn a bit of Agda.<br />Here's what I've done today, it goes through chapter 2 proving everything in Agda by staying as close as possible to the book (for example when multiple proof terms worked, I choose the one from the book).<br /><br />I also choose to stay away from implicit propositional equality, with its powerful refl induction. The reason for this is that it looks like Agda is doing all the work and in the end, I still don't understand why things work.<br /><br />Here is the agda file. It is self-contained but I've stopped at 2.4.7.<br /><br /><a href="http://marc.de-falco.fr/IdentityTypes.agda">IdentityTypes.agda</a><br /><br />Marc de Falcohttps://plus.google.com/113365078981733655808noreply@blogger.com0tag:blogger.com,1999:blog-5825974813274762418.post-13074003057471200962013-11-16T18:12:00.002+01:002013-11-16T20:00:19.971+01:002.3 -- An explanation of "Type families as fibrations" using diagrams (Part 1)<i>I'm often in need of diagrams for understanding abstract concepts. I perfectly understand why there's not a lot of diagram in HOTT book : it was made in a very short time to explain the theory in the doing.</i><br /><i>Here I'll try to re-explain 2.3 using diagrams. I will stay very close to the book material.</i><br /><br /><h2> 2.3 -- An explanation of "Type families as fibrations" using diagrams (Part 1)<i></i></h2><h3>Type families</h3>A type family is the basis of the definition of a dependent pair. It's a function $P : A \rightarrow \mathcal{U}$ for a type $A$ and an universe $\mathcal{U}$. Using this function we can define the type of dependent pair $\sum_{x:A} P(x)$ with the basic construction $(a,b)$ taking an element $a: A$ and an element $b: P(a)$. As $b$ in the pair depends on the first component, it's called a dependent pair.<br /><br />Here we can display the type family $P$ using this diagram : <br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-8U8Q2pW7zOk/Uod6FcLy5EI/AAAAAAAAAfQ/BtXV0LqIZTQ/s1600/c2-3-type_family.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="226" src="http://4.bp.blogspot.com/-8U8Q2pW7zOk/Uod6FcLy5EI/AAAAAAAAAfQ/BtXV0LqIZTQ/s400/c2-3-type_family.png" width="400" /></a></div>where to each element we have associated a whole type.<br /><br />Elements of type $\sum_{a:A} P(a)$ can be displayed as pairings preserving those yellow arrows :<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-QW4qtjON0sk/UoebvVpH9vI/AAAAAAAAAfo/avfMlGBzFZw/s1600/c2-3-sum_type.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="226" src="http://1.bp.blogspot.com/-QW4qtjON0sk/UoebvVpH9vI/AAAAAAAAAfo/avfMlGBzFZw/s400/c2-3-sum_type.png" width="400" /></a></div><h3>Fibrations</h3>Before explaining why such a type family is a fibration, I'll recall what is a fibration through the most trivial example.<br /><br />Take an onto morphism between vector spaces $f : X \rightarrow Y$, we can define the mapping $g$ over $Y$ by setting $g(y) = f^{(-1)}(x) = \{ x \in X ~|~ f(x) = y \}$. Each $g(y)$ is called the fiber over $y$. All fibers are affine subspace of $Y$ with the same direction $Ker(f)$.<br /><br />The space $Y$ is called the base space of $f$ because the defining element of each fiber lives there. The space $X$ is called the total space because its the disjoint union of all the fibers.<br /><br />Now, let's take a path from $y$ to $y'$ in $Y$. I.e. a continuous mapping $p : [0,1] \rightarrow Y$ such that $p(0) = y$ and $p(1) = y'$. Note that this is a trivial case of homotopy between two constants functions.<br />Taking a starting point $u$ in the fiber over $y$. We can try to lift this path in a path $p_*$ in the total space $X$ by walking through fibers starting in $u$ and by mimicking the path $p$. If such a map is guaranteed to exists we say that $f$ is a fibration.<br /><br />Here we can explicitly define this map. Take $E$ to be such that $Ker f \oplus E = X$ and $u \in E$. The map $f_{|E}$ is an isomorphism from $E$ to $Y$. We can set $p_* = f_{|E}^{-1} p$. We have $p_*(0) = f_{|E}^{-1}(y) = u$ and $p_*$ is continuous because it's the compound of a linear, hence continuous, map and the continuous map $p$. Note that $p_*(1) = f_{|E|}^{-1}(y')$ and $f(p_*(1)) = y'$ so $p_*(1)$ in the fiber over $y'$.<br /><br />This situation is depicted here :<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-_qFABp6oQmI/UofAsZ3oMXI/AAAAAAAAAf4/GOwoXhJ9JZg/s1600/c2-3-trivialbundle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://2.bp.blogspot.com/-_qFABp6oQmI/UofAsZ3oMXI/AAAAAAAAAf4/GOwoXhJ9JZg/s320/c2-3-trivialbundle.png" width="238" /></a></div><br /><br /><i>(What we have described here is the structure of a trivial vector bundle.)</i><br /> <br /><h3>Type family as fibration</h3>Looking back at the type family $P : A \rightarrow \mathcal{U}$ we can see that $P(x)$ looks just like a fiber with base point $x$. So we could think of $A$ as a base space. The total space is the union of all fibers, therefore it would be here $\sum_{x:A} P(x)$. We don't really have a candidate for a fibration but it doesn't prevent us from looking at the fibration defining property in this setting.<br /><br />One of the most important fact of homotopy theory is that given two elements $x, y : A$, a proof $p : x = y$ of equality between those two elements can be interpreted as a path from $x$ to $y$.<br /><br />The fibration property would ensure that given $u : P(x)$ we could define a path $p'$ starting at $(x,u)$ in the total space $\sum_{a:A} P(a)$. There's no way of knowing in which fibers would this path walk, but what is certain is that its ending point has to be of the form $(y, v)$ with $v : P(y)$.<br /><br />If we sum it up, what we want to construct is a function $transport_p : P(x) \rightarrow P(y)$. We can construct it by path induction by assuming that $p \equiv refl_x$ and thus $x \equiv y$. The function we want in this case has to go from $P(x)$ to itself, therefore we can set it to be $id_{P(x)}$ and we are done.<br /><br />We note $p_*(u) = transport_p(u)$. And it is depicted here : .<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-oxq8_1Cym58/Uod6FbfUpII/AAAAAAAAAfI/aOW5X9NM1lI/s1600/c2-3-transport.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="226" src="http://3.bp.blogspot.com/-oxq8_1Cym58/Uod6FbfUpII/AAAAAAAAAfI/aOW5X9NM1lI/s400/c2-3-transport.png" width="400" /></a></div>To get back the full fibration property we need to show that $p$ itself can be lifted to a path $lift(p,u) : (x,u) =_{\sum_{a:A} P(a)} (y,p_*(u))$. By path induction, we can assume that $p \equiv refl_x$ and that $x \equiv y$. Then we need to build a path $(x,u) = (x,u)$ as $p_* = id$ in this case. We can take $refl_{(x,u)}$ and it concludes the proof.<br /><br />Here this path is depicted between the boxed elements of $\sum_{x:A} P(x)$ :<br /><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-xxUeN5LO4Jk/Uod6FWXgxoI/AAAAAAAAAfM/7_gejFBJYD0/s1600/c2-3-lift.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /><img border="0" height="226" src="http://2.bp.blogspot.com/-xxUeN5LO4Jk/Uod6FWXgxoI/AAAAAAAAAfM/7_gejFBJYD0/s400/c2-3-lift.png" width="400" /></a></div><br /><br /><br />Marc de Falcohttps://plus.google.com/113365078981733655808noreply@blogger.com0tag:blogger.com,1999:blog-5825974813274762418.post-90606311681248160252013-11-16T08:37:00.000+01:002013-11-16T10:50:33.687+01:002.7 -- Functoriality of ap under $\sum$-types<i>(I won't start with the introduction of HOTT, as it very well explained here http://homotopytypetheory.org/book/ . Instead, I'll present what was lately on my scratchpad.</i>)<br /><h2>2.7 -- Functoriality of ap under $\sum$-types</h2>The statement of this theorem and its proof was left to the reader and it gave me some trouble to state it right.<br /><br />First, let's recall what happens for a cartesian product. To build a function $f : A \times B \rightarrow A' \times B'$ we can join two functions $g : A \rightarrow A'$ and $h : B \rightarrow B'$ in the following way : for every $x \in A \times B$ we set $f(x) :\equiv (g(pr_1(x)), h(pr_2(y)))$. What is done is a split of $x$ into its components on which we apply separately $g$ and $h$.<br /><br />To extend this definition to $\sum$-type, given two type families $P : A \rightarrow \mathcal{U}$ and $P' : A' \rightarrow \mathcal{U}'$, we want to build a function $f : \sum_{x : A} P(x) \rightarrow \sum_{x' : A'} P'(x')$ by joining two functions applied component-wise. The first function is straightforward to type : we reuse $g : A \rightarrow A'$. But, for the second function we can't take one unrelated to $g$. The reason for this lies in the result of $f$, as it will make a dependent pair of the form $( g(pr_1(x)), h(pr_2(x)))$ for it to inhabit the type $\sum_{x':A'} P'(x')$ we must have the typing $h(pr_2(x)) : P'(g(pr_1(x)))$, Therefore, the type of $h$ <b>must</b> depend on $g(pr_1(x))$! Then to get this dependency, the simplest approach is to have $h(a,a') : P(a) \rightarrow P'(a')$ but we could have taken $h(a,g) : P(a) \rightarrow P'(g(a))$. I think the first type is more general, but the second one makes a stronger theorem because it's easier to build this kind of $h$ as it doesn't need to provide functions when $a' \neq g(a)$.<br /><br />Our definition of $f$ is then like this : take $g : A \rightarrow A'$ and $h : \prod_{a : A} P(a) \rightarrow P'(g(a))$, we can then define<br />\[<br />f(x) :\equiv (g(pr_1(x)), h(pr_1(x), pr_2(x))) <br />\]<br />(Note here that I'm unsure of the type of $h$, one could argue that $h : \prod_{g : A' \rightarrow A} \prod_{a : A} P(a) \rightarrow P'(g(a))$ would be clearer as it removes the explicit dependency of $h$ over $g$. But, for me, it means that such $h$ is infinitely harder to build because it needs to be defined <b>for every possible</b> $g$!) <br /><br />It remains to state the equivalent of theorem 2.6.5 in this context. Recall that the equality $q : pr_2(x) = pr_2(y)$ needs to be transported in the right space as $pr_2(x) : P(pr_1(x))$ and $pr_2(y) : P(pr_1(y))$. We can set it to happen in $P(pr_1(y))$ but we have to transport $pr_2(x)$ there using $transport^P(p,pr_2(x)) = p_*(pr_2(x))$ where $p : pr_1(x) = pr_1(y)$.<br /><br /><b>Theorem 2.7.5 : </b>In the above situation, given $x, y : \sum_{a:A} P(a)$ and $p : pr_1(x) = pr_1(y)$ and $q : p_*(pr_2(x)) = pr_2(y)$, we have<br />\[<br />f(pair^=(p,q)) =_{(f(x)=f(y))} pair^=(g(p), h(pr_1(y), q)) <br />\]<br /><br /><i>Proof.</i>By induction we can assume that $x \equiv (a,b)$ and $y \equiv (a',b')$. Then $p : a = a'$ and we can assume that $p \equiv refl_a$ by path induction. We now have $p_* \equiv id_{P(a)}$ and $q : b = b'$. We can assume that $q \equiv refl_b$ by path induction. At this point the left member of the equality is<br />\[<br />f(pair^=(refl_a, refl_b)) \equiv f(refl_{(a,b)} \equiv refl_{f(a,b)}<br />\]<br />and the right member is<br />\[<br />pair^=( g(refl_a), h(a, refl_b) ) \equiv pair^=(refl_{g(a)}, refl_{h(a, b)}) \equiv refl_{(g(a), h(a,b))} \equiv refl_{f(a,b)}<br />\]<br />So we now need a proof of the theorem in this case, but we already have one : $refl_{refl_{f(a,b)}}$.<br /><br />Marc de Falcohttps://plus.google.com/113365078981733655808noreply@blogger.com0