{-# OPTIONS --without-K --safe #-} module lecture3 where -- lecture 3 -- Plan: Complete last lecture. -- Generalize some definitions to use universe levels. -- Uses of Sigma, including examples like monoids. -- Use of universes to prove that Β¬ (false β‘ true). -- Characterization of equality in Ξ£ types. open import lecture1 hiding (π ; π ; β ; D ; _β£_ ; β) open import lecture2 using (is-prime ; _*_ ; π ; π ; β ; _β₯_) open import introduction using (β ; zero ; suc ; _+_) -- Give Ξ£ a universe-polymorphic type open import Agda.Primitive using (Level; lzero; lsuc; _β_) renaming (Set to π€) public variable i j k : Level record Ξ£ {A : π€ i} (B : A β π€ j) : π€ (i β j) where constructor _,_ field prβ : A prβ : B prβ open Ξ£ public infixr 1 _,_ Sigma : (A : π€ i) (B : A β π€ j) β π€ (i β j) Sigma {i} {j} A B = Ξ£ {i} {j} {A} B syntax Sigma A (Ξ» x β b) = Ξ£ x κ A , b infix -1 Sigma _Γ_ : π€ i β π€ j β π€ (i β j) A Γ B = Ξ£ x κ A , B -- (x : X) β A x -- (x : X) Γ A x infixr 2 _Γ_ -- More general type of negation: Β¬_ : π€ i β π€ i Β¬ A = A β π -- Give the identity type more general universe assignments: data _β‘_ {X : π€ i} : X β X β π€ i where refl : (x : X) β x β‘ x _β’_ : {X : π€ i} β X β X β π€ i x β’ y = Β¬ (x β‘ y) infix 0 _β‘_ β‘-elim : {X : π€ i} (A : (x y : X) β x β‘ y β π€ j) β ((x : X) β A x x (refl x)) β (x y : X) (p : x β‘ y) β A x y p β‘-elim A f x x (refl x) = f x β‘-nondep-elim : {X : π€ i} (A : X β X β π€ j) β ((x : X) β A x x) β (x y : X) β x β‘ y β A x y β‘-nondep-elim A = β‘-elim (Ξ» x y _ β A x y) trans : {A : π€ i} {x y z : A} β x β‘ y β y β‘ z β x β‘ z trans p (refl y) = p sym : {A : π€ i} {x y : A} β x β‘ y β y β‘ x sym (refl x) = refl x ap : {A : π€ i} {B : π€ j} (f : A β B) {x y : A} β x β‘ y β f x β‘ f y ap f (refl x) = refl (f x) apβ : {A : π€ i} {B : π€ j} {C : π€ k} (f : A β B β C) {x x' : A} {y y' : B} β x β‘ x' β y β‘ y' β f x y β‘ f x' y' apβ f (refl x) (refl y) = refl (f x y) transport : {X : π€ i} (A : X β π€ j) β {x y : X} β x β‘ y β A x β A y transport A (refl x) a = a _β_ : {A : π€ i} {x y z : A} β x β‘ y β y β‘ z β x β‘ z _β_ = trans infixl 7 _β_ _β»ΒΉ : {A : π€ i} {x y : A} β x β‘ y β y β‘ x _β»ΒΉ = sym infix 40 _β»ΒΉ -- The (sub)type of prime numbers β : π€β β = Ξ£ p κ β , is-prime p β-inclusion : β β β β-inclusion = prβ -- We can prove that this map is left-cancellable, i.e. it satisfies -- β-inclusion u β‘ β-inclusion u β u β‘ v. -- Moreover, this map is an embedding (we haven't defined this concept yet). -- Not quite the type of composite numbers: CN : π€ CN = Ξ£ x κ β , Ξ£ (y , z) κ β Γ β , x β‘ y * z CN' : π€ CN' = Ξ£ x κ β , Ξ£ (y , z) κ β Γ β , (y β₯ 2) Γ (z β₯ 2) Γ (x β‘ y * z) CN-projection : CN β β CN-projection = prβ -- This map is not left-cancellable, and hence can't be considered to -- be an an inclusion. counter-example : CN-projection (6 , (3 , 2) , refl 6) β‘ CN-projection (6 , (2 , 3) , refl 6) counter-example = refl 6 -- But how do we prove that these two tuples are *different*? They -- certainly do look different. We'll do this later. -- We will need to define -- -- CN = Ξ£ x κ β , β₯ Ξ£ (y , z) κ β Γ β , x β‘ y * z β₯, or equivalently -- CN = Ξ£ x κ β , β (y , z) κ β Γ β , x β‘ y * z β₯ -- -- to really get a *subtype* of composite numbers. -- Another use of Ξ£. -- The type of monoids. is-prop : π€ i β π€ i is-prop X = (x y : X) β x β‘ y is-set : π€ i β π€ i is-set X = (x y : X) β is-prop (x β‘ y) Mon : π€ (lsuc i) Mon {i} = Ξ£ X κ π€ i -- data , is-set X -- property (we show that) Γ (Ξ£ π κ X , -- data (but...) Ξ£ _Β·_ κ (X β X β X) -- data , (((x : X) β (x Β· π β‘ x)) -- (1) property Γ ((x : X) β (π Β· x β‘ x)) -- (2) property Γ ((x y z : X) β (x Β· (y Β· z)) β‘ ((x Β· y) Β· z)))) -- (3) property -- This can be defined using a record in Agda: record Mon' : π€ (lsuc i) where constructor mon field carrier : π€ i -- X carrier-is-set : is-set carrier π : carrier _Β·_ : carrier β carrier β carrier left-unit-law : (x : carrier) β x Β· π β‘ x right-unit-law : (x : carrier) β π Β· x β‘ x assoc-law : (x y z : carrier) β (x Β· (y Β· z)) β‘ ((x Β· y) Β· z) Ξ± : Mon {i} β Mon' {i} Ξ± (X , X-is-set , π , _Β·_ , l , r , a) = mon X X-is-set π _Β·_ l r a Ξ² : Mon' {i} β Mon {i} Ξ² (mon X X-is-set π _Β·_ l r a) = (X , X-is-set , π , _Β·_ , l , r , a) Ξ²Ξ± : (M : Mon {i}) β Ξ² (Ξ± M) β‘ M Ξ²Ξ± = refl Ξ±Ξ² : (M : Mon' {i}) β Ξ± (Ξ² M) β‘ M Ξ±Ξ² = refl -- This kind of proof doesn't belong to the realm of MLTT: false-is-not-true[not-an-MLTT-proof] : false β’ true false-is-not-true[not-an-MLTT-proof] () -- Proof in MLTT, which requires a universe (Cf. Ulrik's 2nd HoTT -- lecture): _β£_ : Bool β Bool β π€β true β£ true = π true β£ false = π false β£ true = π false β£ false = π β‘-gives-β£ : {x y : Bool} β x β‘ y β x β£ y β‘-gives-β£ (refl true) = β β‘-gives-β£ (refl false) = β false-is-not-true : Β¬ (false β‘ true) false-is-not-true p = II where I : false β£ true I = β‘-gives-β£ p II : π II = I false-is-not-true' : Β¬ (false β‘ true) false-is-not-true' = β‘-gives-β£ -- Notice that this proof is different from the one given by Ulrik in -- the HoTT track. Exercise: implement Ulrik's proof in Agda. -- Exercise: prove that Β¬ (0 β‘ 1) in the natural numbers in MLTT style -- without using `()`. -- contrapositives. contrapositive : {A : π€ i} {B : π€ j} β (A β B) β (Β¬ B β Β¬ A) contrapositive f g a = g (f a) Ξ -Β¬-gives-Β¬-Ξ£ : {X : π€ i} {A : X β π€ j} β ((x : X) β Β¬ A x) β Β¬ (Ξ£ x κ X , A x) Ξ -Β¬-gives-Β¬-Ξ£ Ο (x , a) = Ο x a Β¬-Ξ£-gives-Ξ -Β¬ : {X : π€ i} {A : X β π€ j} β Β¬ (Ξ£ x κ X , A x) β ((x : X) β Β¬ A x) Β¬-Ξ£-gives-Ξ -Β¬ Ξ³ x a = Ξ³ (x , a) -- Equality in Ξ£ types. from-Ξ£-β‘' : {X : π€ i} {A : X β π€ j} {(x , a) (y , b) : Ξ£ A} β (x , a) β‘ (y , b) β Ξ£ p κ (x β‘ y) , (transport A p a β‘ b) from-Ξ£-β‘' (refl (x , a)) = (refl x , refl a) to-Ξ£-β‘' : {X : π€ i} {A : X β π€ j} {(x , a) (y , b) : Ξ£ A} β (Ξ£ p κ (x β‘ y) , (transport A p a β‘ b)) β (x , a) β‘ (y , b) to-Ξ£-β‘' (refl x , refl a) = refl (x , a) module _ {X : π€ i} {A : π€ j} {(x , a) (y , b) : X Γ A} where from-Γ-β‘ : (x , a) β‘ (y , b) β (x β‘ y) Γ (a β‘ b) from-Γ-β‘ (refl (x , a)) = refl x , refl a to-Γ-β‘ : (x β‘ y) Γ (a β‘ b) β (x , a) β‘ (y , b) to-Γ-β‘ (refl x , refl a) = refl (x , a) module _ {X : π€ i} {A : X β π€ j} {(x , a) (y , b) : Ξ£ A} where -- x y : X -- a : A x -- b : A y from-Ξ£-β‘ : (x , a) β‘ (y , b) β Ξ£ p κ (x β‘ y) , transport A p a β‘ b from-Ξ£-β‘ (refl (x , a)) = refl x , refl a to-Ξ£-β‘ : (Ξ£ p κ (x β‘ y) , (transport A p a β‘ b)) β (x , a) β‘ (y , b) to-Ξ£-β‘ (refl x , refl a) = refl (x , a) contra-from-Ξ£-β‘ : Β¬ (Ξ£ p κ (x β‘ y) , (transport A p a β‘ b)) β (x , a) β’ (y , b) contra-from-Ξ£-β‘ = contrapositive from-Ξ£-β‘ contra-to-Ξ£-β‘ : (x , a) β’ (y , b) β Β¬ (Ξ£ p κ (x β‘ y) , (transport A p a β‘ b)) contra-to-Ξ£-β‘ = contrapositive to-Ξ£-β‘ to-Ξ£-β’ : ((p : x β‘ y) β transport A p a β’ b) β (x , a) β’ (y , b) to-Ξ£-β’ u = contra-from-Ξ£-β‘ (Ξ -Β¬-gives-Β¬-Ξ£ u) from-Ξ£-β’ : (x , a) β’ (y , b) β ((p : x β‘ y) β transport A p a β’ b) from-Ξ£-β’ v = Β¬-Ξ£-gives-Ξ -Β¬ (contra-to-Ξ£-β‘ v)
We now revisit the example above. How do we prove that aa and bb are different? Itβs not easy. We use the above lemmas.
aa bb : CN aa = (6 , (3 , 2) , refl 6) bb = (6 , (2 , 3) , refl 6)
To prove that aa β’ bb, we need to know that β is a set! And this is difficult. See the module Hedbergs-Theorem for a complete proof.
For the moment we just assume that β is a set, and prove that 3 β’ 2 by cheating (produce a genuine MLTT proof as an exercise).
3-is-not-2 : 3 β’ 2 3-is-not-2 () example-revisited : is-set β β aa β’ bb example-revisited β-is-set = I where A : β β π€β A x = Ξ£ (y , z) κ β Γ β , x β‘ y * z II : (p : 6 β‘ 6) β transport A p ((3 , 2) , refl 6) β’ ((2 , 3) , refl 6) II p = VIII where III : p β‘ refl 6 III = β-is-set 6 6 p (refl 6) IV : transport A p ((3 , 2) , refl 6) β‘ ((3 , 2) , refl 6) IV = ap (Ξ» - β transport A - ((3 , 2) , refl 6)) III V : ((3 , 2) , refl 6) β’ ((2 , 3) , refl 6) V q = 3-is-not-2 VII where VI : (3 , 2) β‘ (2 , 3) VI = ap prβ q VII : 3 β‘ 2 VII = ap prβ VI VIII : transport A p ((3 , 2) , refl 6) β’ ((2 , 3) , refl 6) VIII r = V IX where IX : ((3 , 2) , refl 6) β‘ ((2 , 3) , refl 6) IX = trans (IV β»ΒΉ) r I : aa β’ bb I = to-Ξ£-β’ II
If there is time, I will do some isomorphisms.