{-# OPTIONS --cubical #-} open import Cubical.Core.Everything -- contains _≡_ {- A ROSETTA STONE BETWEEN LOGIC, TYPE THEORY AND HOMOTOPY THEORY LOGIC TYPE THEORY HOMOTOPY THEORY a set X a type X a space X x ∈ X x : X x ∈ X element value point ∅ ⊥ ∅ empty set empty type empty space x = y (x = y) space of paths from x to y statement type of witnesses that x that x equals y equals y trivial refl : (x = x) the trivial path proof from x to x that x = x -} -- In Cubical Type Theory, a type X can both be imagined -- as some kind of set (as before) AND as a space. -- In Cubical Type Theory, (x ≡ y) can both be imagined -- as the type of witnesses that x equals y (as before) -- AND as the type of paths from x to y. -- In fact, if x, y : X, a value of (x ≡ y) is a function I → X, -- where I is a built-in interval type. {- In ordinary mathematics, we define a *path* in a space X to be a continuous function γ : I → X, where I is the unit interval [0,1]. x=γ(0) y=γ(1) * * \γ(0.1) ^ \ /\ | +----+ +-+ γ(0.5) Here is a picture of the trivial path from x to x: x * Formally: γ(t) = x. (This γ is a constant function.) -} refl : {A : Set} {x : A} → x ≡ x refl {A} {x} i = x -- alternative: refl {A} {x} = λ i → x -- I is the built-in interval type. It can be pictured as the unit interval [0,1]. -- i0 : I can be pictured as the number 0 (the left end of the unit interval). -- i1 : I can be pictured as the number 1 (the right end of the unit interval). -- ~ i : I can be pictured as 1 - i (the result of mirroring the point i at the midpoint of the interval) symm : {A : Set} {x y : A} → x ≡ y → y ≡ x symm {A} {x} {y} p = λ i → p (~ i) -- p is actually a function I → A such that p i0 ≡ x and p i1 ≡ y. {- _∘_ : {X Y Z : Set} → (Y → Z) → (X → Y) → (X → Z) g ∘ f = λ x → g (f x) -} cong : {A B : Set} {x y : A} → (f : A → B) → x ≡ y → f x ≡ f y cong f p = λ i → f (p i) -- p : I → A -- f : A → B -- f (p i0) ≡ f x -- f (p i1) ≡ f y {- ADVANTAGES OF CUBICAL TYPE THEORY OVER ORDINARY MLTT: * function extensionality * quotients * higher inductive types ADVANTAGES OF CUBICAL TYPE THEORY OVER HOTT: * univalence computes ADVANTAGES OF CUBICAL TYPE THEORY OVER ORDINARY PROGRAMMING: * univalence theorem ADVANTAGES OF HOTT OVER ORDINARY SET THEORY: * can do homotopy theory right away ("batteries included") without having to first define reals, topological spaces, homotopy, ... * new grip on identity * ... -} funext : {A B : Set} (f g : A → B) → ((x : A) → f x ≡ g x) → f ≡ g funext f g p = λ i → λ x → p x i -- funext f g p i0 ≡ (λ x → p x i0) ≡ (λ x → f x) ≡ f -- funext f g p i1 ≡ (λ x → p x i1) ≡ (λ x → g x) ≡ g data ℕ : Set where zero : ℕ succ : ℕ → ℕ -- The only inhabitants of ℕ are what can be created using these constructions: -- zero, succ zero, succ (succ zero), ... data ℤ : Set where _⊖_ : ℕ → ℕ → ℤ -- n ⊖ m should represent the integer n - m -- the integer 3 can be represented as 5 ⊖ 2 or as 6 ⊖ 3 or as 3 ⊖ 0 cancel : (a b : ℕ) → a ⊖ b ≡ (succ a) ⊖ (succ b) -- for any a, b : ℕ, we have a path cancel a b : I → ℤ. -- cancel a b i0 ≡ (a ⊖ b) -- cancel a b i1 ≡ (succ a ⊖ succ b) rec : {A : Set} → (f : ℕ → ℕ → A) → (p : (a b : ℕ) → f a b ≡ f (succ a) (succ b)) → ℤ → A rec f p (a ⊖ b) = f a b rec f p (cancel a b i) = p a b i -- computation rule: rec f (a ⊖ b) ≡ f a b -- but, for general functions f, it might be that f a b ≢ f (succ a) (succ b) fromℕ : ℕ → ℤ fromℕ n = n ⊖ zero succℤ : ℤ → ℤ succℤ (a ⊖ b) = succ a ⊖ b succℤ (cancel a b i) = cancel (succ a) b i -- cancel a b is a path from a ⊖ b to succ a ⊖ succ b -- we need a path from succℤ (a ⊖ b) to succℤ (succ a ⊖ succ b) -- succ a ⊖ b succ (succ a) ⊖ succ b negate : ℤ → ℤ negate (a ⊖ b) = b ⊖ a negate (cancel a b i) = cancel b a i -- 0, 1, 2, 3, 4, 5, 6, ... but 4 ≡ 0, 5 ≡ 1, 6 ≡ 2 data ℤmod4 : Set where zero : ℤmod4 succ : ℤmod4 → ℤmod4 wrap : zero ≡ succ (succ (succ (succ zero))) -- alternative: (n : ℤmod4) → n ≡ succ (succ (succ (succ n))) -- Picture of ℤmod4: -- * * * * * * * * ... -- | ^ -- +----------------+ -- The type ℤmod4 is "freely generated" by zero, succ, wrap. -- Any value of ℤmod4 is generated by those constructors AND by the general operations -- available in our type theory. -- For instance, for i : I, there is not only wrap i : ℤmod4 such that wrap i0 ≡ zero -- and such that wrap i1 ≡ succ (succ (succ (succ zero))), -- but there is also cong succ wrap i. cong succ wrap is a path from succ zero to -- succ (succ (succ (succ (succ zero)))). fromℕ' : ℕ → ℤmod4 fromℕ' zero = zero fromℕ' (succ n) = succ (fromℕ' n) general-wrap : (n : ℕ) → fromℕ' n ≡ succ (succ (succ (succ (fromℕ' n)))) general-wrap zero = wrap general-wrap (succ k) = cong succ (general-wrap k) data Circle : Set where north : Circle loop : north ≡ north -- Inhabitants of the type (north ≡ north) are: -- refl, loop, loop ∙ loop, loop ∙ loop ∙ loop, ..., symm loop, symm loop ∙ symm loop, ... -- Hard exercise: Show that the type (north ≡ north) is equivalent to ℤ. -- In doing that, you will have proven the following theorem of homotopy theory: -- The loop space of the circle at the north pole is homotopy equivalent to ℤ. data Trunc (A : Set) : Set where lift : A → Trunc A trunc : (x y : Trunc A) → x ≡ y -- If we are given a value of type Trunc A, we may conclude that A is inhabited, -- but we cannot reconstruct a particular value of A. -- lift x ≡ lift y ≡ lift z ... -- hlevel -2 IsContractible : Set → Set IsContractible A = Σ[ x ∈ A ] ((y : A) → x ≡ y) -- for instance, the unit type is contractible, that is, we can write down a -- value of type IsContractible Unit where data Unit : Set where * : Unit -- the only interesting thing about a contractible type A is nothing at all. -- hlevel -1 IsProposition : Set → Set IsProposition A = (x y : A) → x ≡ y -- for instance, Trunc A is a proposition for any type A -- the only interesting thing about a proposition A is whether it is inhabitated. exercise : {A : Set} → IsProposition A → (A → IsContractible A) exercise = {!!} -- hlevel 0 IsDiscrete : Set → Set --- usual name: "IsSet" IsDiscrete A = (x y : A) → IsProposition (x ≡ y) -- for instance, the type ℕ is discrete. -- but the type Circle is not, for there are several distinct inhabitants of (north ≡ north) -- the only interesting thing about a discrete type are its (many) inhabitants, -- but not its equalities. data Discretization (A : Set) : Set where lift : A → Discretization A trunc : IsDiscrete (Discretization A) -- for instance, Discretization Circle is equivalent to the unit type. -- hlevel 1 Ishlevel1 : Set → Set Ishlevel1 A = (x y : A) → IsDiscrete (x ≡ y) -- hlevel 2 Ishlevel2 : Set → Set Ishlevel2 A = (x y : A) → Ishlevel1 (x ≡ y)