15-819 Homotopy Type Theory Lecture Notes Evan Cavallo and Stefan Muller November 18 and 20, 2013 1 Reconsder Nat n smple types s a warmup to dscussng nductve types, we frst revew several equvalent presentatons of the smple type Nat seen earler n the course. The ntroducton forms for Nat are 0 and succ(m) for any M : Nat. The elmnaton form s the recursor rec. 1.1 Tradtonal Form Γ 0 : Nat NatI z1 Γ M : Nat Γ succ(m) : Nat NatI s1 Γ M : Nat Γ M 0 : Γ, x : M 1 : Γ rec[](m; M 0 ; x.m 1 ) : NatE 1 We nclude the motve n the recursor to motvate the dependently-typed presentaton to come although t s not necessary n the smply-typed settng. The dynamc behavor of rec s defned by the followng β rules. rec[](0; M 0 ; x.m 1 ) M 0 rec[](succ(m); M 0 ; x.m 1 ) [rec[](m; M 0 ; x.m 1 )/x]m 1 The recursor on 0 returns the base case M 0. On succ(m), t substtutes the recursve result on M for x n M 1. The η rule states that any object that behaves lke the recursor s defntonally equal to the recursor on the approprate arguments. [0/y]N M 0 Γ, z : Nat [succ(z)/y]n [[z/y]n/x]m 1 : Γ, y : Nat N rec[](y; M 0 ; x.m 1 ) η 1
1.2 s elements of the exponental The ntroducton forms of Nat may be treated as exponentals n the absence of a context. 0 : 1 Nat (NatI z3 ) succ : Nat Nat (NatI s3 ) Note that the type 1 Nat s equvalent to the type Nat. There are two ways to present the elmnaton form n ths format. The frst moves the Nat on whch the recurson s done to the argument poston, mplyng that rec has exponental type. M 0 : x : M 1 : z : Nat rec[](m 0 ; x.m 1 )(z) : NatE 3a Ths can be presented n a more drect way by omttng the argument. M 0 : x : M 1 : rec[](m 0 ; x.m 1 ) : Nat NatE 3b We can derve rules NatI z1, NatI s1 and NatE 1. For example, 2 Nat-algebras Γ, M : Nat M : Nat Γ, M : Nat succ : Nat Nat NatI s3 Γ, M : Nat succ(m) : Nat We now motvate the dea of Nat-algebras, whch are maps of the form 1 +. From the name, one would expect there to be a Nat-algebra where s Nat. Indeed, there s. z : 1 + Nat case(z;.0; x.succ(x)) : Nat We can wrte case(z;.0; x.succ(x)) above as {.0; x.succ(x)}(z) or, somewhat abusvely, {0, succ}(z). Ths gves {0, succ} : 1 + Nat Nat as desred. More generally, we can wrte any Nat-algebra as = { 0, 1 } where 0 : 1 Nat (or, equvalently, 0 : Nat) and 1 : Nat Nat. We call 0 the bass or pseudo-zero and 1 the nductve step or pseudo-successor. In fact, {0, succ} holds a specal poston among Nat-algebras. The Nat-algebras form a category and {0, succ} s the ntal object n ths category. Recall that ths means t has a unque morphsm to any other object n the category. Ths requres us to defne Muller and Cavallo 2013/11/18 and 2013/11/20 2
morphsms between Nat-algebras, whch we wll call Nat-homomorphsms. Gven two Natalgebras, : 1 + and β : 1 + B B, h : B s a Nat-homomorphsm f t makes the followng dagram commute. 1+h 1 + 1 + B h B β The map 1 + h : 1 + 1 + B s defned n the natural way: 1 + h : {.nl ; a.nr h(a)} To show that Nat s an ntal algebra, we must show that for every Nat-algebra : 1 +, there exsts a unque Nat-homomorphsm : Nat such that the followng dagram commutes (note that the order of quantfcatons expressed n the prevous sentence s not nherently clear n the dagram, and must be consdered to get a full understandng of the dagram.) 1+ 1 + Nat 1 + Nat {0,succ} Let s consder the requrements on for the dagram to commute. 0 = 0 succ(x) = 1 (x) where the left sdes correspond to followng the path {0, succ} and the rght sdes correspond to followng 1+. Note that these two equatons match the β rules for rec, so we can defne : rec[]( 0 ; 1 ) or smply : rec[](). s we see above, the β rules for rec mply commutaton of the dagram. Unqueness of follows from the η rule for rec. It s worth notng that commutng dagrams hde exactly the type of equalty that s beng dscussed, whch s qute mportant n HoTT. For Nat, for example, unqueness of holds on the nose, whle, n general, unqueness may be only up to hgher homotopy. 3 F -algebras The above dscusson can be generalzed to any functor F. functor s a mappng between categores C and D. Functors act on objects n a category and the morphsms between Muller and Cavallo 2013/11/18 and 2013/11/20 3
them,.e. for all objects X C, F (X) D, and for all morphsms f : X Y between objects X and Y n C, F (f) : F (X) F (Y ). Functors respect dentty and composton: 1. For every object X C, F (d X ) = d F (X) 2. For all morphsms f : X Y and g : Y Z, F (g f) = F (g) F (f) [1] For example, F Nat (C) : 1 + C s a functor. We check that F Nat preserves denttes and composton. Let X be an object of C. F Nat (d X ) = 1 + d X = {, d X } whch s ndeed an dentty on 1 + X. Let f : X Y, g : Y Z be morphsms between objects of C. F Nat (g f) = 1 + g f = {, g f} = {, g} {, f} = (1 + g) (1 + f) = F (g) F (f) For any functor F, an F -algebra s a mappng F (X) X. Thus, a Nat-algebra s an F Nat -algebra. F -algebras form categores as Nat-algebras do. For a functor F, objects and B, two F -algebras : F () and β : F (B) B, and a morphsm h : B, the followng dagram commutes. F () F (h) F (B) h n ntal F -algebra s an F -algebra : I such that for all other F -algebras : F (), there exsts a unque map : I such that the followng dagram commutes. B β F () F () I There also exsts the noton of an F -coalgebra, whch, dual to the above, s a map : F (). fnal F -coalgebra s a mappng j : J F (J) such that for all other F -coalgebras : F (), there exsts a unque map : J makng the followng dagram commute. J F () j F (J) Muller and Cavallo 2013/11/18 and 2013/11/20 4
Lemma 1 (Lambek). If : I s an ntal F -algebra, then s an somorphsm. That s, I. Proof. To show that s an somorphsm, we must exhbt an nverse 1 : I such that 1 = d I and 1 = d. Consder the F -algebra F () : F (). We now treat as homomorphsm between the F -algebras F () and makng ths dagram commute. F () F () F () I Snce s an ntal F -algebra, however, we also have a unque mappng : I makng the top half of ths dagram commute. F () F () F () F () I I There s also a unque mappng from I to I, whch must be the dentty. Ths ndcates that the mappng along the rght sde of the dagram must be equal to d I : We also have = d I = F () F () = F ( ) = F (d I ) = d where the frst equalty follows from the commutatvty of the upper half of the dagram, the second and fourth follow from the propertes of functors and the thrd follows from the result above. Ths shows that for any functor F, the ntal F -algebra I s a fxed pont of F. dual result can be proven showng that, f J s the fnal F -coalgebra of a functor F, then F (J) J. Muller and Cavallo 2013/11/18 and 2013/11/20 5
4 Internalzng Nat-lgebras Insde type theory, we can defne the noton of Nat-algebra as Natlg : Σ:U. ((1 + ) ) We can defne the type of Nat-homomorphsms between two Nat-algebras (, ) and (B, β) as NatHom(, β) : Σh: B. (β (1 + h) = h ) The fact that ν : (Nat, {0, succ}) s ntal n the category of Nat-algebras s expressed by the fact that NatHom(ν, ) s contractble for all : ths means that there exsts a Nat-homomorphsm from ν to whch s unque up to hgher homotopy. 5 W-types We d lke to be able to take a functor F and defne the ntal F -algebra wthn HoTT (f one exsts). For the class of polynomal functors, we can do ths usng Brouwer ordnals, also called W-types. W-types are nspred by the mathematcal concept of well-founded nducton. In classcal mathematcs, a partally ordered set, < s sad to be well-founded f every subset of has a <-mnmal element (equvalently, there are no nfnte descendng chans). Wellfounded sets are useful because they admt an nducton prncple: Proposton (Well-Founded Inducton): Let, < be a well-founded set and P (x) be a proposton. If for any a we can prove P (a) by assumng P (b) for all b < a, then P (a) holds for all a. The set of natural numbers N, < together wth ts usual orderng s an example of a well-founded set, and the nducton prncple s the famlar mathematcal nducton. Classcally, the proof that nducton holds goes by contradcton, so ths defnton s unsatsfactory for a constructve theory. We wll nstead characterze well-founded sets as those for whch we have a (constructve) nducton prncple. To better understand what we mean by ths, we wll defne W-types. To form a W-type, we requre a type and a type famly B over : Γ : U Γ, x: B : U Γ Wx:.B : U WF s the type of node sorts. Each node sort represents a dfferent way of formng an element of Wx:.B. For example, n the case of the natural numbers, the node sorts are 0 and succ. We can thnk of each element of the natural numbers as a tree bult from these two sorts of nodes. For example, the numbers 0 through 2 can be represented as Muller and Cavallo 2013/11/18 and 2013/11/20 6
0 succ succ 0 succ nother natural example s the type of bnary trees. Ths type can be defned by two node sorts node and leaf, wth the elements takng the form of trees such as ths: node 0 leaf leaf In order to fully specfy these two types, we need to have some noton of a node s arty. Ths s gven by the type famly B. For each node sort a :, B(a) descrbes the branchng factor of a, the ndex type to specfy the predecessors of a node of sort a. For example, the branchng factor of the sort 0 or leaf would be 0, the branchng factor of succ would be 1, and the branchng factor of node would be 1+1. Thus we can wrte Nat as Wx:2. f(x; 0; 1), where tt represents 0 and ff represents succ. Now that we have the purposes of and B n hand, we can see how to defne the ntroducton rule for Wx:.B. a : x:b(a) w : Wx:.B Γ sup[a](x.w) : Wx:.B WI In other words, n order to construct a node of sort a, we must gve an element Wx:.B for each predecessor as specfed by the branchng factor B(a). Note that when B(a) s 0 we can construct a new node wthout any predecessor nformaton. For example, we can construct elements of the naturals as follows: 0 : sup[tt](x.abort Wx:2. f(x;0;1) (x)) 1 : sup[ff](.0) 2 : sup[ff](.1) The recursor for Wx:.B follows the dea of well-founded recurson: n order to defne the result of a functon f on an element w : Wx:.B, we can assume we ve already computed f for all of w s predecessors. Γ C : U Γ, a :, r : B(a) C M : C Γ, z : Wx:.B wrec[c](a, r.m)(z) : C WR Muller and Cavallo 2013/11/18 and 2013/11/20 7
In the hypothess, we assume that we are dealng wth a node of type a and that we have the value r(b) for each b : B(a) ndexng a predecessor. We use ths nformaton to construct the value M of the recursor at the current node. The recursor comes wth the compuaton rule wrec[c](a, r.m)(sup[a](w)) [a, λz.wrec[c](a, r.m)(w(z))/a, r]m whch, as expected, gves the value of wrec[c](a, r.m) on sup[a](w) n terms of the value on each predecessor w(z) for z : B(a). The dependent elmnator has a smlar form, expressng the dea of well-founded nducton. Γ, z : Wx:.B P : U Γ, a:, p : B(a) Wx:.B, h : b:b(a) P (p(b)) M : P (sup[a](p)) Γ, z : Wx:.B wnd[x.p ](a, p, h.m) : P (z) Here, n order to formulate the hypothess, we need to assume the addtonal data p : B(a) Wx:.B whch gves us the predecessors of the element we are consderng. The computaton rule takes the form wnd[x.p ](a, p, h.m)(sup[a](w)) = [a, w, λz.wnd[x.p ](a, p, h.m)(w(z))/a, p, h]m In general, we can only assert that ths computaton rule holds propostonally. Each W-type determnes a functor, n partcular a polynomal functor. Ths s a functor of the form F (X) = Σa:.(B(a) X) for some type and type famly B. We can see that the W-type Wx:.B defnes an F -algebra where F (X) : Σa:.(B(a) X): we have λ(a, w). sup[a](w) : F (X) X. The map λ(a, w). sup[a](w) s n fact an equvalence, and Wx:.B s a homotopy-ntal F -algebra. In the case of our W-type defnton of Nat, observe that the functor determned by Wx:2. f(x; 0; 1) s F (X) = Σb:2.(f(b; 0; 1) X). One can check that Σb:2.(f(b; 0; 1) X) 1 + X. Thus, ths type satsfes the equaton F (X) = 1 + X, our orgnal defnton of a Nat-algebra. References [1] Wkpeda. Functor. http://en.wkpeda.org/wk/functor, 2013. WE Muller and Cavallo 2013/11/18 and 2013/11/20 8