Universes
Why
- We need to define type families by induction, so that we can prove things like
- We should have a method to abstract over types, eg.
instead of writing
for each type, we can write - To do category theory in a streamlined way. (Grothendieck universe1)
What is a Universe?
In some type theories, especially in systems with dependent types, types themselves can be regarded as terms. There is a type called the universe (often denoted
) which has types as its elements. To avoid paradoxes such as Girard's paradox (an analogue of Russell's paradox for type theory), type theories are often equipped with a countably infinite hierarchy of such universes, with each universe being a term of the next one. —— Wikipedia
Basically it is type of types.
A universe in type theory is a type
How we prevent Russell’s paradox
As I mentioned before, universe is type of types, so a universe can technically in another universe, and this leads to the famous Russell’s paradox.
To prevent this paradox from happening, and keep enough universes to use meanwhile, we organize the universes and types in them in this way:
-
For every finite list of types:
there is a universe that contains each in the sense that comes equipped with for which the judgement holds. -
is the universe which contains no types. -
For each universe
, there is a successor universe that We can have an infinite tower with these universes: and each universe is contained in the next. -
We can join universes, ie.
contains all types in and .
Example
Now we'll show why we need these universes.
We'll prove:
or in other words:
So what we want to do is find a term:
Start with
We need a term of
For
For
And fill the
In lean, I won't use Agda this time since in Agda a simple λ ()
will do the prove, it's convenient but too far from what we want to show here:
def boolToType x :=
match x with
| true => True
| false => False
theorem notTrueImpliesFalseType : ¬(True → False) :=
λ (h: True → False) => False.elim (h True.intro)
theorem trueIsNotFalse : true ≠ false :=
Ne.intro
λ (t: true = false) => absurd (Eq.mp (congrArg boolToType t)) notTrueImpliesFalseType
Observational equality of the natural numbers
In dependent type theory, sometimes one could inductively define an equality type directly on an inductive type, rather than using Martin-Loef’s identity types using the j-rule. This equality type is called observational equality. —— nLab
We define the observational equality of natural numbers like:
Curry-Howard interpretation
Definition omitted, since we've already very familiar with it.
Example
We define: if
And we can write some properties of division like:
Every natural number is divisible by 1 and itself
Proof5:
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.Nat.Divisibility using (_∣_; divides)
open import Data.Nat.Properties using (*-identityʳ; *-identityˡ)
open import Relation.Binary.PropositionalEquality using (sym)
open import Data.Product renaming (_×_ to _∧_)
div1 : ∀ (n : ℕ) → 1 ∣ n
div1 n = divides n (sym (*-identityʳ n))
divn : ∀ (n : ℕ) → n ∣ n
divn n = divides 1 (sym (*-identityˡ n))
div1n : ∀ (n : ℕ) → (1 ∣ n) ∧ (n ∣ n)
div1n n = (div1 n) , (divn n)
Every natural number divides 0
div0 : ∀ (n : ℕ) → n ∣ 0
div0 n = divides zero refl
Axiom of Choice in Type Theory
I knew what AC is intuitively, it means we can find a choice function for any set in a collection of sets to select an element of it out, now I'll show the formalized form:
Or in type theory:
This is actually provable:
open import Data.Product
choice : {A B : Set} {R : A → B → Set} →
((x : A) → Σ B (λ y → R x y)) →
Σ (A → B) (λ f → (x : A) → R x (f x))
choice h = (λ z → fst (h z)) , (λ x → snd (h x))
And the reverse proposition is also provable:
choice-rev : {A B : Set} (R : A → B → Set) →
Σ (A → B) (λ f → (x : A) → R x (f x)) →
((x : A) → Σ B (λ y → R x y))
choice-rev R h' = λ x → (fst h' x) , (snd h' x)
However this direct "Curry-Howard translation" of AC is not as powerful as it is in set theory, I guess we move the complexity of AC to somewhere else in the type theory. Anyway, we'll see a more complex form of AC representing in later courses.
Materials
Lecture Note
Record on Youtube
ref, to_learn++
.
In computer science, a type family associates data types with other data types, using a type-level function defined by an open-ended collection of valid instances of input types and the corresponding output types. —— Wikipedia
Seems the book of this course is using a “Tarski-style universes”, personally I think “Russell-style universes”, which doesn't have
Ref section 6.1 of the book Introduction to Homotopy Type Theory by Egbert Rijke for these structures, I'm too tired to type all these with latex.
Unless necessary, I'll write all proofs in Agda in the future, since typing proof tree in latex is too tiring.