napkin solutions > HoTT

Back to Chapter Selection

Table of Contents

  1. 1.2
  2. 1.6
  3. 1.8
  4. 1.10
  5. 1.13
  6. 1.15

1.2 #

HoTT-1.2. Derive the recursion principle for products rec𝐴×𝐵 using only the projections, and verify thatthe definitional equalities are valid. Do the same for Σ-types.Solution by RanolPThe exercise makes us define the recursor based on the projection of (maybe dependent) product types.1.rec𝐴×𝐵We have projectionspr1:𝐴×𝐵𝐴pr2:𝐴×𝐵𝐵with the following defining equationspr1((𝑎,𝑏)):𝑎pr2((𝑎,𝑏)):𝑏Here, our goal is to definerec𝐴×𝐵:Π𝐶:𝒰(𝐴𝐵𝐶)𝐴×𝐵𝐶and the definition isrec𝐴×𝐵(𝐶,𝑔,(𝑎,𝑏)):𝑔(pr1((𝑎,𝑏)))(pr2((𝑎,𝑏)))We can verify that the recursor above has the desired property by doing 𝛽-reduction on pr1 and pr2.After the reduction, we get 𝑔(𝑎)(𝑏), correctly Church-encoding the product.2.recΣ𝑥:𝐴𝐵(𝑥)We have projectionspr1:(Σ𝑥:𝐴𝐵(𝑥))𝐴pr2:Π𝑝:Σ(𝑥:𝐴)𝐵(𝑥)𝐵(pr1(𝑝))with the following defining equationspr1((𝑎,𝑏)):𝑎pr2((𝑎,𝑏)):𝑏Here, our goal is to definerecΣ𝑥:𝐴𝐵(𝑥):Π(𝐶:𝒰)(Π(𝑥:𝐴)𝐵(𝑥)𝐶)(Σ(𝑥:𝐴)𝐵(𝑥))𝐶and its definition isrecΣ𝑥:𝐴𝐵(𝑥)(𝐶,𝑔,(𝑎,𝑏)):𝑔(pr1((𝑎,𝑏)))(pr2((𝑎,𝑏)))Let’s verify that the definition concludes with the property we desired once more:By 𝛽-reducing on pr1 and pr2, we get recΣ𝑥:𝐴𝐵(𝑥)(𝐶,𝑔,(𝑎,𝑏)):𝑔(𝑎)(𝑏),and it correctly Church-encodes the dependent product.As shown above, the recursor can be defined with the projection functions of (maybe dependent) products.

1.6 #

HoTT 1.6. Show that if we define 𝐴×𝐵:𝑥:𝟐𝗋𝖾𝖼𝟐(𝒰,𝐴,𝐵,𝑥), then we can give a definition of 𝗂𝗇𝖽𝐴×𝐵 forwhich the definitional equalities stated in §1.5 hold propositionally (i.e. using equality types). (This requiresthe function extensionality axiom, which is introduced in §2.9.)𝗂𝗇𝖽𝐴×𝐵:𝐶:𝐴×𝐵𝒰((((𝑥:𝐴)(𝑦:𝐵)𝐶((𝑥,𝑦)))))𝑥:𝐴×𝐵𝐶(𝑥)𝗂𝗇𝖽𝐴×𝐵(𝐶,𝑔,(𝑎,𝑏)):𝑔(𝑎)(𝑏)(§1.5)𝖿𝗎𝗇𝖾𝗑𝗍:(𝑥:𝐴(𝑓(𝑥)=𝑔(𝑥)))(𝑓=𝑔)(§2.9)Solution by kiwiyouFrom definition of 𝐴×𝐵:𝑥:𝟐𝗋𝖾𝖼𝟐(𝒰,𝐴,𝐵,𝑥), we can natrally try defining our 𝗂𝗇𝖽𝐴×𝐵:𝗂𝗇𝖽𝐴×𝐵(𝐶,𝑔,𝑥):𝑔(𝑥(0𝟐))(𝑥(1𝟐))Sadly, 𝗂𝗇𝖽𝐴×𝐵 has a different type from 𝗂𝗇𝖽𝐴×𝐵 in §1.5:𝗂𝗇𝖽𝐴×𝐵:𝐶:𝐴×𝐵𝒰((((𝑥:𝐴)(𝑦:𝐵)𝐶((𝑥,𝑦)))))𝑥:𝐴×𝐵𝐶((𝑥(0𝟐),𝑥(1𝟐)))How can we get value of type 𝑥:𝐴×𝐵𝐶(𝑥) from that of type 𝑥:𝐴×𝐵𝐶((𝑥(0𝟐),𝑥(1𝟐)))?See this lemma, hidden in §2.3:Lemma 2.3.1 (Transport). Suppose that 𝑃 is a type family over 𝐴 and that 𝑝:𝑥=𝐴𝑦. Then there isa function 𝑝:𝑃(𝑥)𝑃(𝑦).So if we have 𝑝:(𝑥(0𝟐),𝑥(1𝟐))=𝑥, we can transport 𝐶((𝑥(0𝟐),𝑥(1𝟐))) into 𝐶(𝑥). Let’s call this 𝑝 as 𝗎𝗇𝗂𝗊𝐴×𝐵.𝗎𝗇𝗂𝗊𝐴×𝐵:𝑥:𝐴×𝐵((𝑥(0𝟐),𝑥(1𝟐))=𝑥)Since we don’t have judgemental equality, it’s time for the function extensionality axiom.𝗎𝗇𝗂𝗊𝐴×𝐵(𝑥):𝖿𝗎𝗇𝖾𝗑𝗍(𝗂𝗇𝖽𝟐(𝜆𝑦.((𝑥(0𝟐),𝑥(1𝟐))(𝑦)=𝑥(𝑦)),𝗋𝖾𝖿𝗅𝑥(0𝟐),𝗋𝖾𝖿𝗅𝑥(1𝟐)))Verify the type by case analysis:(𝜆𝑦.((𝑥(0𝟐),𝑥(1𝟐))(𝑦)=𝑥(𝑦))(0𝟐)((𝑥(0𝟐),𝑥(1𝟐))(0𝟐)=𝑥(0𝟐))((𝗂𝗇𝖽𝟐(𝗋𝖾𝖼𝟐(𝒰,𝐴,𝐵),𝑥(0𝟐),𝑥(1𝟐)))(0𝟐)=𝑥(0𝟐))(𝑥(0𝟐)=𝑥(0𝟐))𝗋𝖾𝖿𝗅𝑥(0𝟐):(𝜆𝑦.((𝑥(0𝟐),𝑥(1𝟐))(𝑦)=𝑥(𝑦))(0𝟐)(𝜆𝑦.((𝑥(0𝟐),𝑥(1𝟐))(𝑦)=𝑥(𝑦))(1𝟐)((𝑥(0𝟐),𝑥(1𝟐))(1𝟐)=𝑥(1𝟐))((𝗂𝗇𝖽𝟐(𝗋𝖾𝖼𝟐(𝒰,𝐴,𝐵),𝑥(0𝟐),𝑥(1𝟐)))(1𝟐)=𝑥(1𝟐))(𝑥(1𝟐)=𝑥(1𝟐))𝗋𝖾𝖿𝗅𝑥(1𝟐):(𝜆𝑦.((𝑥(0𝟐),𝑥(1𝟐))(𝑦)=𝑥(𝑦))(1𝟐)Finally, we have 𝗎𝗇𝗂𝗊𝐴×𝐵(𝑥):𝐶((𝑥(0𝟐),𝑥(1𝟐)))𝐶(𝑥) to complete 𝗂𝗇𝖽𝐴×𝐵. This is a new definition:𝗂𝗇𝖽𝐴×𝐵:𝐶:𝐴×𝐵𝒰((((𝑥:𝐴)(𝑦:𝐵)𝐶((𝑥,𝑦)))))𝑥:𝐴×𝐵𝐶(𝑥)𝗂𝗇𝖽𝐴×𝐵(𝐶,𝑔,𝑥):𝗎𝗇𝗂𝗊𝐴×𝐵(𝑥)(𝑔(𝑥(0𝟐))(𝑥(1𝟐)))Remaining question: 𝗂𝗇𝖽𝐴×𝐵=𝗂𝗇𝖽𝐴×𝐵 holds?

1.8 #

HoTT-1.8. Define multiplication and exponentiation using rec. Verify that (,+,0,×,1) is a semiringusing only ind. You will probably also need to use symmetry and transitivity of equality, Lemmas 2.1.1and 2.1.2.Solution by finalchildDefinition of multiplication and exponentiationDefine multiplication and exponentiation as follows. This is just like how we defined add. Note that exponentiate has an extra step that reverses the order of parameters.multiply:rec(,𝜆𝑛.0,𝜆𝑚.𝜆𝑔.𝜆𝑛.𝑛+𝑔(𝑛))exponentiate:𝜆𝑚.𝜆𝑛.rec(,𝜆𝑚.1,𝜆𝑛.𝜆𝑔.𝜆𝑚.𝑚×𝑔(𝑚))(𝑛,𝑚)(,+,0,×,1) is a semiringNow we verify that (,+,0,×,1) is a semiring. Note that summon(𝑇) is a notation for summoning a knownproof that becomes type 𝑇 with appropriate arguments.(,+,0) is a commutative monoidProve 𝑖+𝑗+𝑘=𝑖+(𝑗+𝑘) with induction.assoc+:𝑖,𝑗,𝑘:𝑖+𝑗+𝑘=𝑖+(𝑗+𝑘)assoc+:ind(𝜆(𝑖:).𝑗,𝑘:𝑖+𝑗+𝑘=𝑖+(𝑗+𝑘),assoc+,0,assoc+,s)assoc+,0:𝑗,𝑘:0+𝑗+𝑘=0+(𝑗+𝑘)assoc+,0(𝑗,𝑘):refl𝑗+𝑘assoc+,s:𝑖:(𝑗,𝑘:𝑖+𝑗+𝑘=𝑖+(𝑗+𝑘))succ(𝑖)+𝑗+𝑘=succ(𝑖)+(𝑗+𝑘)assoc+,s(,𝑖,𝑗,𝑘):apsucc((𝑗,𝑘))Prove that 0 is the identity of (,+).𝜆𝑖.refl𝑖:𝑖:0+𝑖=𝑖ind(𝜆(𝑖:). 𝑖+0=𝑖,refl0,𝜆𝑖.𝜆.apsucc()):𝑖:𝑖+0=𝑖Prove 𝑖+𝑗=𝑗+𝑖 with double induction.commut+:𝑖,𝑗:𝑖+𝑗=𝑗+𝑖commut+:ind(𝜆(𝑖:).𝑗:𝑖+𝑗=𝑗+𝑖,commut+,0,commut+,s)commut+,0:𝑗:0+𝑗=𝑗+0commut+,0(𝑗):summon(𝑗+0=𝑗))1commut+,s:𝑖:(𝑗:𝑖+𝑗=𝑗+𝑖)𝑗:succ(𝑖)+𝑗=𝑗+succ(𝑖)commut+,s(𝑖,1):ind(𝜆(𝑗:).succ(𝑖)+𝑗=𝑗+succ(𝑖),summon(succ(𝑖)+0=succ(𝑖)),commut_inner(𝑖,1))commut_inner:𝑖:(𝑗:𝑖+𝑗=𝑗+𝑖)𝑗:(succ(𝑖)+𝑗=𝑗+succ(𝑖))succ(𝑖)+succ(𝑗)=succ(𝑗)+succ(𝑖)Prove commut_inner(𝑖,1,𝑗,2) with the composition of three equalities:succ(𝑖+succ(𝑗))=succ2(𝑗+𝑖)(by1)=succ2(𝑖+𝑗)(by1)=succ(𝑗+succ(𝑖))(by2)commut_inner(𝑖,1,𝑗,2):apsucc(1(succ(𝑗)))apsucc2(1(𝑗))1apsucc(2)Axioms on ×Prove that 1 is the identity of (,×).𝜆𝑖.summon(𝑖+0=𝑖):𝑖:1×𝑖=𝑖ind(𝜆(𝑖:). 𝑖×1=𝑖,refl0,𝜆𝑖.𝜆.apsucc()):𝑖:𝑖×1=𝑖Prove 0 annihilates multiplication.𝜆𝑖.refl0:𝑖:0×𝑖=0ind(𝜆(𝑖:). 𝑖×0=0,refl0,𝜆𝑖.𝜆.):𝑖:𝑖×0=0Prove distribution.distrbl:𝑖,𝑗,𝑘:𝑖×(𝑗+𝑘)=𝑖×𝑗+𝑖×𝑘distrbl:ind(𝜆(𝑖:).𝑗,𝑘:𝑖×(𝑗+𝑘)=𝑖×𝑗+𝑖×𝑘,distrbl0,distrbls)distrbl0:𝑗,𝑘:0×(𝑗+𝑘)=0×𝑗+0×𝑘distrbl0(𝑗,𝑘):refl0distrbls:𝑖:(𝑗,𝑘:𝑖×(𝑗+𝑘)=𝑖×𝑗+𝑖×𝑘)𝑗,𝑘:succ(𝑖)×(𝑗+𝑘)=succ(𝑖)×𝑗+succ(𝑖)×𝑘Prove distrbl𝑠(𝑖,,𝑗,𝑘) by the composition of equalities:𝑗+𝑘+𝑖×(𝑗+𝑘)=𝑗+𝑘+(𝑖×𝑗+𝑖×𝑘)(by)=𝑗+(𝑘+𝑖×𝑗+𝑖×𝑘)(byassoc+)=𝑗+(𝑖×𝑗+𝑘+𝑖×𝑘)(bycommut+)=𝑗+(𝑖×𝑗+(𝑘+𝑖×𝑘))(byassoc+)=𝑗+𝑖×𝑗+(𝑘+𝑖×𝑘)(byassoc+)I omit the explicit term for this composition. The components are just , commut+ and assoc+ wrappedwith ap.distribr:𝑖,𝑗,𝑘:(𝑖+𝑗)×𝑘=𝑖×𝑘+𝑗×𝑘distribr:ind(𝜆(𝑖:).𝑗,𝑘:(𝑖+𝑗)×𝑘=𝑖×𝑘+𝑗×𝑘,distribr0,distribrs)distribr0:𝑗,𝑘:(0+𝑗)×𝑘=0×𝑘+𝑗×𝑘distribr0(𝑗,𝑘):refl𝑗×𝑘distribrs:𝑖:(𝑗,𝑘:(𝑖+𝑗)×𝑘=𝑖×𝑘+𝑗×𝑘)𝑗,𝑘:(succ(𝑖)+𝑗)×𝑘=succ(𝑖)×𝑘+𝑗×𝑘Prove distribr𝑠(𝑖,,𝑗,𝑘) by the composition of equalities:𝑘+(𝑖+𝑗)×𝑘=𝑘+(𝑖×𝑘+𝑗×𝑘)(by)=𝑘+𝑖×𝑘+𝑗×𝑘(byassoc+)Prove 𝑖×𝑗×𝑘=𝑖×(𝑗×𝑘) with induction.assoc×:𝑖,𝑗,𝑘:𝑖×𝑗×𝑘=𝑖×(𝑗×𝑘)assoc×:ind(𝜆(𝑖:).𝑗,𝑘:𝑖×𝑗×𝑘=𝑖×(𝑗×𝑘),assoc×,0,assoc×,s)assoc×,0:𝑗,𝑘:0×𝑗×𝑘=0×(𝑗×𝑘)assoc×,0(𝑗,𝑘):refl0assoc×,s:𝑖:(𝑗,𝑘:𝑖×𝑗×𝑘=𝑖×(𝑗×𝑘))succ(𝑖)×𝑗×𝑘=succ(𝑖)×(𝑗×𝑘)Prove assoc×,s(𝑖,) by the composition of equalities:(𝑗+𝑖×𝑗)×𝑘=𝑗×𝑘+𝑖×𝑗×𝑘(bydistribr)=𝑗×𝑘+𝑖×(𝑗×𝑘)(by)Therefore, (,+,0,×,1) is a semiring.

1.10 #

HoTT-1.10. Show that the Ackermann function ack: is definable using only rec satisfying thefollowing equations:ack(0,𝑛)succ(𝑛)ack(succ(𝑚),0)ack(𝑚,1)ack(succ(𝑚),succ(𝑛))ack(𝑚,ack(succ(𝑚),𝑛))Solution by finalchildack:rec(,succ,𝜆(𝑚:). 𝜆(𝑓:). rec(,𝑓(1),𝜆(𝑛:). 𝜆(𝑐:). 𝑓(𝑐)))Verify the equations:ack(0)succack(succ(𝑚))rec(,ack(𝑚,1),𝜆(𝑛:). 𝜆(𝑐:). ack(𝑚,𝑐))Thusack(0,𝑛)succ(𝑛)ack(succ(𝑚),0)ack(𝑚,1)ack(succ(𝑚),succ(𝑛))(𝜆(𝑛:). 𝜆(𝑐:). ack(𝑚,𝑐))(𝑛,ack(succ(𝑚),𝑛))ack(𝑚,ack(succ(𝑚),𝑛))Note that we folded some instances of recursive calls implicitly.

1.13 #

HoTT 1.13. Using propositions-as-types, derive the double negation of the principle of excluded middle,i.e. prove not (not (P or not P)).Solution by kiwiyouWe need to find a witness of the type not (not (P or not P)).¬¬𝖫𝖤𝖬:𝑃:𝒰((𝑃+(𝑃𝟎))𝟎)𝟎¬¬𝖫𝖤𝖬:𝜆𝑃. (:((𝑃+(𝑃𝟎))𝟎)𝟎)Our first hole must get a function of type (𝑃+(𝑃𝟎))𝟎 and derive a contradiction.¬¬𝖫𝖤𝖬:𝜆𝑃. 𝜆𝑓. (:𝟎)We must use 𝑓 to derive a contradiction as we cannot prove a contradiction directly. Note that 𝑓 derivesa contradiction from a witness of either 𝑃 or 𝑃𝟎. 𝑃 is not inhabited yet, so we can try constructing afunction of type 𝑃𝟎.¬¬𝖫𝖤𝖬:𝜆𝑃. 𝜆𝑓. 𝑓(𝗂𝗇𝗋(:𝑃𝟎))Our hole now must receive a witness of 𝑃 and derive a contradiction. This time 𝑓 can receive a witness of𝑃.¬¬𝖫𝖤𝖬:𝜆𝑃. 𝜆𝑓. 𝑓(𝗂𝗇𝗋(𝜆𝑝. 𝑓(𝗂𝗇𝗅(𝑝))))

1.15 #

HoTT-1.15. Show that the indiscernibility of identicals follows from path induction.Path induction:ind=𝐴:𝐶:Π(𝑥,𝑦:𝐴)(𝑥=𝐴𝑦)𝒰(Π(𝑥:𝐴)𝐶(𝑥,𝑥,refl𝑥))(𝑥,𝑦:𝐴)(𝑝:𝑥=𝐴𝑦)𝐶(𝑥,𝑦,𝑝)with equalityind=𝐴(𝐶,𝑐,𝑥,𝑥,refl𝑥):𝑐(𝑥)Indiscernibility of identicals: for every family𝐶:𝐴𝒰there is a function𝑓:(𝑥,𝑦:𝐴)(𝑝:𝑥=𝐴𝑦)𝐶(𝑥)𝐶(𝑦)such that𝑓(𝑥,𝑥,refl𝑥):id𝐶(𝑥)Solution by RanolPHole Notation (:𝜏). To show the reasoning step, we’ll present a hole notation, which displays thecurrent goal(s) typed 𝜏. The hole may be untyped if it’s too obvious or annoying to write explicitly. Onthe reasoning step, we’ll replace hole(s) and may introduce new hole(s).The goal is to construct such 𝑓. Let’s solve step-by-step.Given type family 𝐶:𝐴𝒰,𝑓::(𝑥,𝑦:𝐴)(𝑝:𝑥=𝐴𝑦)𝐶(𝑥)𝐶(𝑦)ind=𝐴()():(𝑥,𝑦:𝐴)(𝑝:𝑥=𝐴𝑦)𝐶(𝑥)𝐶(𝑦)ind=𝐴(𝜆𝑥.𝜆𝑦.𝜆𝑝.𝐶(𝑥)𝐶(𝑦))(:Π(𝑥:𝐴)𝐶(𝑥)𝐶(𝑥))ind=𝐴(𝜆𝑥.𝜆𝑦.𝜆𝑝.𝐶(𝑥)𝐶(𝑦))(𝜆𝑥.(:𝐶(𝑥)𝐶(𝑥)))ind=𝐴(𝜆𝑥.𝜆𝑦.𝜆𝑝.𝐶(𝑥)𝐶(𝑦))(𝜆𝑥.id𝐶(𝑥))Let’s verify 𝑓(𝑥,𝑥,refl𝑥)id𝐶(𝑥).𝑓(𝑥,𝑥,refl𝑥)ind=𝐴(𝜆𝑥.𝜆𝑦.𝜆𝑝.𝐶(𝑥)𝐶(𝑦))(𝜆𝑥.id𝐶(𝑥))(𝑥,𝑥,refl𝑥)(𝜆𝑥.id𝐶(𝑥))(𝑥)id𝐶(𝑥)So, the indicernibility of identicals can be derived from the path induction.