Académique Documents
Professionnel Documents
Culture Documents
An introduction to Martin-L
of type theory
Tor kland Barstad
Spring 2015
Contents
1 Introduction
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
7
7
7
8
8
9
10
10
10
11
11
12
13
13
14
15
16
17
1 Introduction
This is a slightly modified version of a text I wrote for a university course where
I learned Martin-Lof type theory. It may be that my lack of depth/experience is
reflected in the text, but I hope that it regardless will serve as a good introduction.
Writing an introduction that is both less formal and takes better care to explain
things to people who are new to this kind of stuff, and is broader and more in-depth
and complete than this one, is on the list of things that I hope Ill have time to
do once I understand the material better myself. If you want to learn Martin-Lof
type theory this list of resources may be also be of help: http://tinyurl.com/
LearnDependentTypeTheory.
Martin-Lof type theory was developed in the 1970s and 1980s by Per Martin-Lof [2], and
has become one of the most important and influential approaches to the foundations
of mathematics outside of set theory, with a particular surge of interest in recent years
due to the emergence of homotopy type theory, which could be seen as interpretation
of Martin-L
of type theory [5]. Martin-Lof type theory has also been put to significant
uses outside of mathematics, especially in computer science, for instance in the field of
programme certification [1], but also for instance in linguistics [3].
In this text we give an introduction to Martin-L
of type theory, with a view towards how
it can be used to represent claims about the real world that usually are expressed in
natural language. Throughout this work, well abbreviate Martin-Lof type theory to
MLTT.
In type theory, various notations are commonly in use to denote the same types, and
terminology also differs. The choices of notation and terminology made here may differ
from what is found elsewhere. Also, MLTT does not refer to a single type theory, but
rather to various type theories which have certain fundamental aspects in common, and
thus there will be differences between what is presented here and other presentations of
MLTT.
On a different note, that different variables have different types, such as string, integer,
char, or more complicated gadgets, is common to many programming languages. There
are parallels between this and the notion of a type in MLTT, but there also large
differences. The most important of these is that MLTT allows for new types to be built
from others, and in this way highly complex types can be constructed in MLTT. These
types can be used to carry out much of what other formal systems implement by different
means.
Reading
A : type
a:A
a=b:A
A=B
A is a type
a is a term of type A
a and b are equal terms of type A
A and B are equal types
Notice the convention of using small letters to refer to terms, and of using large letters
to refer to types.
Some versions of MLTT are hierarchical: there are types type, type1 , type2 , type3 , and
so on, such that type : type1 , type1 : type2 , and so on. Such types are often referred to
as universes. There will then be four forms of judgments for each universe type, type1 ,
type2 , and so on.
In other versions of MLTT, type, type1 , type2 , type3 , and so on, are instead denoted set,
set1 , set2 , set3 , and so on. In some implementations of MLTT, such as Coq, a universe
hierarchy is implicit, but the user is not permitted to explicitly make judgments A : typei
for i 2.
As we will see later in this section, MLTT allows various ways to construct types from other
types. These type constructions correspond, under the reading of types as propositions, to
the ways to construct propositions from other propositions in predicate logic: implication,
conjunction, disjunction, universal quantification, existential quantification, and negation.
In this way, we can carry out first order logic in MLTT, with one significant caveat: a
proposition in MLTT is considered to be true if we can give a proof of it, and thus MLTT
corresponds to constructive predicate logic. Since we do not necessarily know for any
given proposition whether or not we can give a proof of it, we do not know whether it is
true. Thus, from this point of view, we must reject the law of excluded middle. However,
its entirely possible to disregard this reading of MLTT by expressing the law of excluded
middle within MLTT, and then taking as an axiom that it holds.
The following table gives an overview of the logical reading of the types which we will
introduce in this section:
Type
Logical reading
AB
AB
A+B
(x : A)B(x)
(x : A)B(x)
A
4.3 Rules
We have rules that prescribe new judgments which can be made given that we have
already made other judgments. Typically these are rules are written as follows (but this
notation is only one of several possibilities).
Some judgement
Some other judgement
Name of rule
Judgment thats true if the two judgments above are true
Under the Curry-Howard correspondence, this can be read as: if some proposition is
true, and some other proposition is true, then a third proposition is true. In this way,
rules can be thought of as functions on true propositions, where the premises are the
input and the conclusion is the output.
A : type
B : type
A B : type
It depends upoon two types, A and B. We do not, though, usually refer to A B as a
dependent type, because it does not depend upon the terms of any type.
Formation rules need not depend upon any types. For instance, the formation rule for
the type of natural numbers is as follows:
N : type
Given that we have a type A and a type B, well see that there are rules which allow
us to form new types such as A B, A B, and A + B. Iterated applications of type
formation rules allow us to construct ever more complex types, like for instance the one
bellow:
(A A B B) A + B.
true : Boolean
f alse : Boolean
10
set of all numbers between 10 and 14 which are divisible by 3, and the set of all numbers
between 10 and 14 which are divisible by 6, are extensionally equal, but intensionally
distinct.
Equality of types in MLTT is an intensional notion: it cannot be reduced to checking
equalities of terms, unless this is forced as an additional rule.
4.5 Contexts
In MLTT, judgments are often made in context. That is to say, relying upon other
judgments having been made. For instance, the judgment a = b : A only makes sense if
A is a type, and if a and b are of type A. In other words, when we make the judgment
a = b : A, we presuppose the judgments, A : type, a : A, and b : A. We say that a = b : A
is a judgment in the context of the latter three judgments, and write:
A : type, a : A, b : A ` a = b : A.
Thus the judgment we are making, a = b : A in this case, is written to the right of the
symbol `, and the judgments which we are supposing to have been made are written
to the left of the symbol `, separated by commas. The order in which the presupposed
judgments are written, from left to right, is significant: judgments may presuppose those
to their left. For instance, the judgment a : A presupposes the judgment A : type:
A : type ` a : A.
Another notation that sometimes is used for the contexts is the following:
a : A[A : type]
In this notation the context is put inside the parenthesis.
Greek letters such as and are often used to represent contexts. In MLTT notation,
all or some of the context is often omitted when whats left out can be inferred without
ambiguity from the judgment being made.
11
f :AB
Elimination
f (a) : B
12
A B C.
On a different note, a dependent type x : A ` B(x) : type can be viewed as a term of type
A type (assuming that there is a type type1 such that type : type1 ). This is typically
how dependent types are encoded in a computer implementation of MLTT.
13
Whilst we remarked in 4.6.2 that a term of type A B can be thought of as a pair (a, b)
of a term a of type A and a term b of type B, a term of type A + B can be thought of as
a term of either A or of B.
Under the set theoretic reading of MLTT discussed in 4.4, the type A + B corresponds
to the set that is the disjoint union of the set A and the set B. Under the logical reading
of MLTT, A + B is thought of as the proposition A B, or as we could say in natural
language: A or B are true. The introduction rule for A + B corresponds to asserting
that, to give a proof of A B, it is necessary and sufficient to either give a proof of A or
a proof of B.
14
people. We would then express everyone is mortal, or, more precisely, every person is
mortal, by the type
(x : P erson)M ortal(x).
As a second example, making use of dependent types
x1 : P erson, x2 : P erson ` Enmity(x1 , x2 )
and
x1 : P erson, x2 : P erson ` F riendship(x1 , x2 )
expressing enmity and friendship.
We can express that two people with a common enemy are friends, or, more precisely,
every pair of people with a common enemy are friends, by the following type:
x1 : P erson x2 : P erson x3 : P erson
(y : Enmity(x1 , x2 ) z : Enmity(x3 , x2 ) F riendship(x1 , x3 )
Elimination II
second(p) : B f irst(p)
Dependent sum types are a generalisation of the binary product types of 4.6.2. A B
is really a special case of (a : A)B(a) where we take B(a) to be B for each a : A. A
term of type (a : A)B(a) can be thought of as a pair (a, b), where a is of type A, and b
is of type B(a). Under the set theoretic reading of MLTT discussed
in 4.4, the type
F
(a : A)B(a) corresponds to the set that is the disjoint union aA B(a) of the sets B(a)
for a A.
Under the logical reading of MLTT, (a : A)B(a) is thought of as the proposition
a A B(a), or as we would say in natural language: B(a) is true for some a. The
introduction and elimination rules for (a : A)B(a) correspond to asserting that, to give
a proof of a A, B(a), it is necessary and sufficient to give a proof of B(a) for some
a : A.
15
A natural language example of a dependent sum type would one that expresses the
proposition that friendships exist, or more precisely: There exists a person who is Bills
friend. Such a dependent sum type could look as follows:
(x : P erson)F riendship(x, Bill)
To give an example of a dependent product type that references a and dependent sum
type, we can express the proposition everybody has a friend by the following type:
(x : P erson)(y : P erson)F riendship(x, y).
To give an example of how the introduction and elimination rules of dependent types
can be made use of in practise, the following expresses type theoretically the following
argument: Socrates is a person; all people are mortal; hence there is a mortal person.
f : (x : P erson)M ortal(x)
Socrates : P erson
Socrates : P erson
f (Socrates) : M ortal(Socrates)
(Intro )
Socrates, f (Socrates) : (x : P erson)M ortal(x)
(Elim )
In a proof tree such as this, rules are applied sequentially from the top down. The
judgments below a line are can be made as a consequence of a rule which depends upon
the judgments above this line. The rules are indicated to the right of the line. Here
Elim is the elimination rule for dependent products, and Intro is the introduction
rule for dependent sums.
Formation
c:
A : type
Elimination
abort(c) : A
There is no introduction rule, that is to say, the type has no canonical terms. Under
the set theoretic reading of MLTT discussed in 4.4, the type corresponds to the empty
set.
Under the logical reading of MLTT, is thought of as falsity, . The elimination rule
for corresponds to the logical principle known as ex falso quodlibet. That is, given a
proof of falsity, one can give a proof of any proposition.
In constructive logic, negation of a proposition A (A is false ) is typically defined to be
the proposition A . Giving a proof of A is to demonstrate that a proof of A
implies a proof of falsity, which is to say that the negation of a proposition is true when
the truth of that proposition leads to a contradiction. Thus, when viewing a type A as
a proposition under the Curry-Howard correspondence, we think of the type A as
corresponding to the negation of A.
16
17
18
Bibliography
[1] A. Chlipala, Certified programming with dependent types, 2011.
f, Intuitionistic Type Theory: Notes by Giovanni Sambin of a series
[2] P. Martin-Lo
of lectures given in Padova, June 1980, 1984.
[3] A. Ranta, Type-theoretical grammar, (1994).
, Grammatical framework, Journal of Functional Programming, 14 (2004), pp. 145
[4]
189.
19