{-# OPTIONS --cubical #-}
module Padova2025.Cubical.FirstSteps where
First steps
open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Padova2025.ProgrammingBasics.Naturals.Base open import Padova2025.ProgrammingBasics.Naturals.Arithmetic open import Padova2025.ProvingBasics.Negation open import Padova2025.ProvingBasics.Equality.Base renaming (_β‘_ to _β‘α΅’_) open import Padova2025.ProvingBasics.Equality.NaturalNumbers open import Padova2025.ProvingBasics.Termination.Gas using (π; tt)
Proper introduction. Split off menagerie of types.
Unordered pairs
data UnorderedPair (A : Set) : Set where pair : (x y : A) β UnorderedPair A swap : (x y : A) β pair x y β‘ pair y x
Generalities on equality
refl' : {X : Set} {a : X} β a β‘ a refl' {a = a} = Ξ» i β a
symm' : {X : Set} {a b : X} β a β‘ b β b β‘ a symm' p = Ξ» i β p (~ i)
cong' : {X Y : Set} {a b : X} β (f : X β Y) β a β‘ b β f a β‘ f b cong' f p = {!!}
funext : {A B : Set} {f g : A β B} β ((x : A) β f x β‘ g x) β f β‘ g funext = {!!}
Verifying transitivity is more difficult. Let us just use the function from the cubical standard library:
trans' : {X : Set} {a b c : X} β a β‘ b β b β‘ c β a β‘ c trans' p q = p β q
β‘α΅’ββ‘ : {X : Set} {a b : X} β a β‘α΅’ b β a β‘ b β‘α΅’ββ‘ = {!!}
β‘ββ‘α΅’ : {X : Set} {a b : X} β a β‘ b β a β‘α΅’ b β‘ββ‘α΅’ = J (Ξ» b q β _ β‘α΅’ b) _β‘α΅’_.refl
Exercise: Sum of unordered pair
sum-pair : UnorderedPair β β β sum-pair = {!!}
Integers
infixl 5 _β_ data β€ : Set where _β_ : (a b : β) β β€ cancel : (a b : β) β a β b β‘ succ a β succ b
Define the successor and predecessor functions.
succβ€ : β€ β β€ succβ€ (a β b) = succ a β b succβ€ (cancel a b i) = {!!}
predβ€ : β€ β β€ predβ€ (a β b) = a β succ b predβ€ (cancel a b i) = {!!}
Exercise: One is not zero, revisited
Show that one is not zero.
lemma-nontrivial : one β‘ zero β β₯ lemma-nontrivial = {!!}
With the inductive definition of _β‘_
we used before,
this required an empty pattern. Now that _β‘_
is no longer
inductively defined, but an in-built notion, we cannot case split on
equality witnesses.
Instead, proceed as follows:
Define a function
disambig : β β Set
which maps zero to β₯ and everything else to some inhabited type.Assuming that there is a path
zero β‘ succ zero
, combinetransport
from the standard library anddisambig
:transport : {A B : Set} β A β‘ B β A β B
Exercise: Robustness of the unordered pair abstraction
Show that the unordered pair abstraction is not leaky, in the sense that there cannot be a function which would extract the first component of an unordered pair.
lemma-not-leaky : (f : UnorderedPair β β β) β ((a b : β) β f (pair a b) β‘ a) β β₯ lemma-not-leaky = {!!}
Mere propositions
In homotopy type theory, a type is called a proposition if and only if all its inhabitants are equal. Hence all there is to know about a proposition is whether it is inhabited.
isProp' : Set β Set isProp' X = (a b : X) β a β‘ b
Show that the types β₯
and π
are
propositions in this sense.
β₯-isProp : isProp' β₯ β₯-isProp = {!!}
π-isProp : isProp' π π-isProp = {!!}
Show that negations are propositions.
lemma-negations-are-props : (X : Set) β isProp' (X β β₯) lemma-negations-are-props X f g = funext Ξ» x β β₯-isProp (f x) (g x)
Zero-dimensionality of the type of natural numbers
In homotopy type theory, a type is called hset (or just set) iff its identity types are mere propositions, i.e.Β iff there is at most one path between any two elements.
isHSet : Set β Set isHSet X = (a b : X) β isProp' (a β‘ b)
To verify that β
is an hset, we require an explicit
description of its identity types. For the following definition of
Code
, it will turn out that the types a β‘ b
and Code a b
are equivalent.
Code : β β β β Set Code zero zero = π Code zero (succ y) = β₯ Code (succ x) zero = β₯ Code (succ x) (succ y) = Code x y
fromCode : (a b : β) β Code a b β a β‘ b fromCode = {!!}
Code-refl : (a : β) β Code a a Code-refl = {!!}
Code-isProp : (a b : β) β isProp' (Code a b) Code-isProp = {!!}
toCode : (a b : β) β a β‘ b β Code a b toCode a b = J {!!} {!!}
If _β‘_
was the inductively-defined equality predicate
from before, we would do a case split on p
to reduce to the
case toCode a a refl
; this case could be solved by
Code-refl a
.
This kind of case split is not available for _β‘_
,
however we can emulate its effects by the standard libraryβs
J
function.
from-toβ : (a : β) β fromCode a a (toCode a a refl') β‘ refl' from-toβ zero = refl' from-toβ (succ a) i = cong succ (from-toβ a i)
from-to : (a b : β) β (p : a β‘ b) β fromCode a b (toCode a b p) β‘ p from-to a b p = J (Ξ» y q β fromCode a y (toCode a y q) β‘ q) (from-toβ a) p
β-isHSet : isHSet β β-isHSet = {!!}