Introduction
The rules should be rules of immediate inference; we cannot further analyse them, but only explain them. However, in the end, no explanation can substitute each individual’s understanding.
—Per Martin-Löf
About Type Theory—A Quickstart
Type Theory deals with types and terms with equalities, in the plainest—syntactic—sense of the word, between such types and terms. We refer to equality in this sense (which is not much) as definitional equality.
Judgements
Formally, statements we make about types and terms are called judgements and there are four of them:
\(Γ ⊢ A : \mathbb{U}\)
This says that A is a type. I am writing 𝕌 instead of \(\mathbf{Type}\). By this, we mean to suggest there is an appropriate universe of types, but more about this later.
\(Γ ⊢ x : A\)
This says that x is a term of type A.
\(Γ ⊢ A = B : \mathbb{U}\)
This says that A is equal to B. Duh!
\(Γ ⊢ x = y : A\)
This says that x and y are equal terms of type A, again definitionally.
So, in the theory, these judgements are derived from axioms (previous judgements) using inference rules.
These derivations, which are essentially finite trees labeled by judgements and inference rules, are the main object of study, and typically derive new judgements from old ones.
The axioms typically include judgements stating the existence of certain basic types and terms.
Observations:
Note that in ordinary Set Theory things like \(a ∈ A\) or \(a = b\) are propositions, while they are judgements here.
In order to say that \(A = B : \mathbb{U}\) of course we have to know that \(A : \mathbb{U}\) and \(B : \mathbb{U}\), etc.
Context
The Γ above is a context. This is the essential feature of Dependent Type Theory: we allow types and terms to depend on (free) variables that may refer to other types and terms.
For example:
\[x : A ⊢ B (x) : \mathbb{U}\]
states that \(B(x)\) is a type that depends on a term \(x\) of type \(A\), a judgement that has previously been derived.
This is of crucial importance: \(B\) is a dependent type.
In general, this can be upgraded to many variables, so that a context can be something like
\[Γ = x_1 : A_1, x_2 : A_2, \dots, x_n : A_n\]
where for each \(m ≤ n\) each type \(A_m\) can only depend on the variables that were declared previously, that is, \(x_1, … , x_{m-1}\).
An observation…
One more example of dependency: let’s say we have the above judgement \(x : A ⊢ B (x) : \mathbb{U}\). So we know that \(B\) is a dependent type. Now, suppose that we can state:
\[x : A ⊢ f (x) : B (x)\]
This means we hold true that \(f(x)\) is term of type \(B(x)\), depending on the variable \(x\), which is a term of type \(A\). So \(f\) is a term of a dependent type \(B\).
But now, suppose that \(B (x)\) does not depend on \(x\), in fact. This is (the analog of) a function from \(A\) to \(B\), which we write
\[x : A ⊢ f (x) : B\]
So, what is a type?
According to Martin-Löf, for each of the four judgements, we must answer one of the following equivalent questions:
- What is it? (Ontological—Ancient Greeks)
- What do we have to know about it? (Epistemological—Descartes, Kant, …)
- What does it
<judgement here>
mean? (Semantical)
The way Martin-Löf asnwers the question is to call canonical the terms that we can directly “see” that they are the resul of one of the rules, to be distinguished from all the other possible terms, to be deemed noncanonical. Thus, the answer is articulated as follows.
A type \(A\) is defined by prescribing how a canonical term of \(A\) is formed
Two types \(A\) and \(B\) are equal if
a : A a : B ----- & ----- a : B a : A
and
a = b : A a = b : B --------- & --------- a = b : B a = b : A
A term
a : A
is a method (program) which yields a canonical term ofA
.Example: When we build the naturals we can see that
2 + 2 : ℕ
because it computes tosuc (2 + 1)
.Two arbitrary terms
a : A
andb : A
are equal if, when executed,a
andb
yield equal canonical elements as a result.
Rules for (definitional) equality
Equality is an equivalence relation, in the sense that it satisfies the three traditional relations, plus it is a congruence with respect to substitution into types and terms:
a = b : A x : A ⊢ B (x) : 𝕌
-------------------------------
B (a) = B (b) : 𝕌
a = b : A x : A ⊢ f (x) : B (x)
----------------------------------
f (a) = f (b) : B (a)
A = B : 𝕌 a : A
-----------------
a : B
The rules of the game
In summary, when we try to grasp what a certain type is, that is, when we answer the questions above, we use the following rules:
- Formation: this is a judgement that given a certain context we can form the type in question
- Introduction: We specify what are the canonical terms and equalities between canonical terms
- Elimination: How the newly introduced terms are applied.
- Conversion: How the introducton and the elimination rules intereract
An example: Products
Formation:
x : A ⊢ B (x) : 𝕌 ------------------- Π [x : A] B (x) : 𝕌
Introduction:
x : A ⊢ f(x) : B (x) ---------------------------- λ x. f (x) : Π [x : A] B (x)
Elimination:
f : Π [x : A] B (x) a : A ---------------------------- app(f,a) : B (a)
Conversion:
λ x. f (x) : Π [x : A] B (x) a : A ------------------------------------- app(λ x.f (x), a) = f (a) : B (a)
Interpretations
The HoTT book summarizes the different points of view about type-theoretic operations as follows:
Types | Logic | Sets | Homotopy |
---|---|---|---|
A |
proposition | set | space |
a:A |
proof | element | point |
B x |
predicate | family of sets | fibration |
b x : B x |
conditional proof | family of elements | section |
𝟘, 𝟙 |
⊥, ⊤ | ∅, {∅} | ∅,* |
A + B |
A ∨ B | disjoint union | coproduct |
A x B |
A ∧ B | set of pairs | product space |
A → B |
A ⇒ B | set of functions | function space |
Σ [x : A] B x |
∃ x:A (B x) | disjoint sum | total space |
Π [x : A] B x |
∀ x:A (B x) | product | space of sections |
≡ |
= | \(\{(x,x) | x ∈ A\}\) | path space \(A^I\) |
Types to build
We will incrementally build a minimal depende type system, including the following types:
The empty type
𝟘
The unit type
𝟙
More general finite types
The natural numbers
ℕ
(Dependent) Products—these correspond to Cartesian products
(Dependent) Sums—these generalize disjoint unions
Identity types
Identity types embody the equality relation not in the shallow definitional sense stated above, but as a proposition. We will see that, far from being a simple equivalence relation, they embody the homotopical and categorical content of HoTT.