Академический Документы
Профессиональный Документы
Культура Документы
. . . . . . . . . . . . . . . . . . . . . . . . . . . 1
z.z Normalisation by Evaluation for
. . . . . . . . . . . . . . z
z. Normalisation by Evaluation for
. . . . . . . . . . . . . . z
z. Correctness of NbE . . . . . . . . . . . . . . . . . . . . . . . 1
z. A Haskell Implementation of NbE . . . . . . . . . . . . . . . 6
NbE for Martin-Lf Type Theory
.1 The calculus
. . . . . . . . . . . . . . . . . . . . . . . . . j
.z Semantics and Normalisation by Evaluation . . . . . . . . . z
. Correctness of NbE via logical relations . . . . . . . . . . . . 6
. Implementation of a type-checker for
. . . . . . . . . . . 1
Extended Martin-Lf Type Theory
.1 The Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . .
.z Semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
. Correctness of NbE . . . . . . . . . . . . . . . . . . . . . . . 8
. Type-checking algorithm . . . . . . . . . . . . . . . . . . . . 88
. Normalisation by evaluation . . . . . . . . . . . . . . . . . . j
.6 Type-checking algorithm . . . . . . . . . . . . . . . . . . . . j8
Pure Type Systems 1o1
.1 Formal systems . . . . . . . . . . . . . . . . . . . . . . . . . 1o1
.z Equivalence between
and
=
. . . . . . . . . . . . . . . 1oj
. Semantics for
=
. . . . . . . . . . . . . . . . . . . . . . . . 1oj
. Correctness of Nbe . . . . . . . . . . . . . . . . . . . . . . . 11
. From
to
=
. . . . . . . . . . . . . . . . . . . . . . . . . 118
6 Conclusion 1z1
6.1 Commutativity in Martin-Lf type theory . . . . . . . . . . 1z1
6.z Further work . . . . . . . . . . . . . . . . . . . . . . . . . . . 1z6
Bibliography 1z
ii
Acknowledgements
Id like to start expressing my gratitude to Daniel Fridlender: he started all
this seven years ago when he asked me if I was interested in pursuing a Ph.D.
He was always patient with my impatience to learn and to express my vague
intuitions; he encouraged me when I was not too condent in my abilities. Our
meetings were the source of several ideas in the thesis. I also appreciate very
much Daniels humanity and intellectual honesty.
I am thankful to Thierry Coquand for accepting to be my advisor at
Chalmers. My year in Sweden was crucial for my progressing, and a part
of that should be credited to Thierry: he taught me several of the techniques
employed on this thesis and suggested to look at various of the issues covered.
Most of the chapters of this thesis are based on joint works with Andreas
Abel, Thierry Coquand, and Daniel Fridlender. I am grateful to them for they
kindly granted me to include these works in the thesis. Andreas explained to
me various points about dependent type theory; I learned a lot working with
him. Danke schn!
I am grateful to Peter Dybjer for accepting to be in the jury, in spite of
the long trip from Sweden, and for his valuable suggestions. I thank also to
Eduardo Bonelli and Carlos Areces, the Argentinian members of the jury, for
reading the thesis and pointing out omissions and errors.
My Ph.D. was supported by scholarships from Agencia Nacional de Promo-
cin Cientca y Tecnolgica, Consejo Nacional de Investigaciones Cientcas y
Tcnicas, and the LerNet project funded by the EU. Part of my activities and
travels were supported by funds provided by Ministerio de Ciencia de Crdoba
and Secretara de Ciencia y Tcnica - UNC.
My roommates and colleagues at FaMAF made of the workplace a nice en-
vironment. In particular, I have great times sharing teaching times with Hctor
(el Flaco) and Pedro ST. I liked my talks with Ara, Renato, and Javier; with
them I discovered a taste for understanding more deeply our daily activities,
specially as computer scientist, and questioning the usual state-of-aairs.
I enjoyed the last year at oce z; its atmosphere was so pleasant that
someone call it the smiling oce. I thank my friends Any, Cristian, Chun, Eze,
Franco, and Leti for the good time in the oce and for the after oce hours.
During my stance in Gothenburg I lived with Ruben, who opened his house
to me although we did not know before, just because Mnica y Juan asked
him to receive me. In great part, I felt at home in Gothenburg, because Ruben
adopted me. Muchas gracias! Every meeting with my dearest friends Anna
och Anders was joyful: Tack s mycket! I also enjoyed talking with Ana Bove
and Andrs Sicard-Ramrez.
My parents and siblings have been supportive in many ways all this time;
they never doubted to assist me in every situation when I asked for their help.
They respected all my weird decisions, no matter the outcome and always
helped me to paid the prices (sometimes literally so). Id like to thank also to
Rafa for his generosity and his hospitality in Barcelona. Muchas gracias!
iii
iv
Vale has been mi compaera for most of this journey. She always had tender
words when I was anxious or depressed; her backing was most important in
the moments of doubt and disappointment. Vale sustained me, even when it
meant to live separate for almost a year. Gracias, muchas gracias por todo eso
[...] y [por] lo que paso en silencio.
Introduction
1
The type systems studied in this thesis can be seen from two perspectives. They
can be used as a foundation for constructive mathematics [z1]; for example,
Martin Lf type theory was originally meant as a formal language for intuition-
ism [8]. Dependent type systems can also be seen as functional programming
languages whose type discipline can be used for enconding the specication
of programs [j]. The main contributions of this thesis are the denition of
a normalisation algorithm that leads to type-checking algorithms and new proof
methods for some meta-theoretical results for predicative type theories.
In the following sections we briey introduce type theory; then we ex-
plain the relationship with constructivism and show a program with a strong
specication; nally we shortly discuss some issues related to type-checking
dependent type systems and we introduce normalisation by evaluation. In the
last section we comment on the organisation of the thesis and the contributions
of each chapter.
1.1 Type Theories
The use of types in logic was rst proposed by Russell to avoid the paradoxes
discovered in formal systems at the dawn of the twentieth century. In this
section we briey expound the type theories studied in the rest of the thesis.
1
Simple Type Theory: Church and Curry
The simple theory of types was introduced by Church [6] to classify terms of
his lambda calculus []. In his axiomatisation, types were built up from two
basic constants called the types of individuals and the types of propositions,
with symbols and o, respectively and by forming A B, where A and B
are already dened type expressions.
To better explain simple type theory (STT), we introduce the formal terms
of Churchs lambda calculus: given a set V of variables, the set of terms of
the untyped lambda calculus are constructed by the following clauses:
(var)
x V
x
(app)
t t
t t
(abs)
x V t
x.t (1.1)
The rules of the formal system are presented in the following denition.
z
Denition 1 (Rules of conversion). Let x, y V and r, t, s, s
; then s =
s
if they are provably equal by using the rules derived from the reexive,
symmetric, transitive, and contextual closure of the following equations:
1
We refer the reader to [, 8, 1, 111] for the history of type-theory.
z
Lambda calculus was intended to be a formal system for predicate logic, thus the original
presentation also had constants for logical connectives. We restrict our presentation to the pure
lambda calculus and omit the logical constructors and the formal postulates related with them.
1
z 1. Introduction
() If y does not occur freely in t, x.t = y.t[x/y]
() (x.t) r = t[x/r].
() If x does not occur freely in t, x.t x = t.
Rule () makes clear how the lambda notation formalises the notion of
function and application of functions to arguments: if t is a term where
the variable x occurs, then x.t is the function such that when applied to
r yields the value t[x/r], this being the notation for substituting r for the
free occurrences of x in t. In x.t, x is say to be a bound variable. Rule ()
formalises that names of bound variables are absolutely irrelevant and they
can be changed (carefully). Finally rule () together with congruence under
abstraction makes the system extensional; i.e. we can show that two terms are
equal i their application to every term is equal.
Already in [] there was an idea of computation: the equations are called
reductions when interpreted as, in modern terminology, rewrite rules trans-
forming the left hand side into the right hand side; in particular one is usu-
ally interested in the rewriting relation generated by considering only ().
Given a term t
0
we say that it evaluates to t
n
if there is a reduction sequence
t
0
t
1
. . . t
n
, where t
i
is transformed into t
i+1
by applying rule ()
to a sub-term of t
i
. We say that t
n
is a normal form if it cannot be further
reduced; then we say that t
n
is the normal form of t
0
note that there are
terms without normal forms; i.e. terms with all theirs reduction sequences
innite. The lambda calculus is consistent in the sense that a given term can
have at most one normal form, up to renaming of bound variables using ().
After Kleene and Rossers [] proof of the inconsistency of logic based on
lambda calculus, this untyped version was disregarded as a feasible foundation
for logic. The discipline of types of STT [6] avoided the inconsistency; but it
also imposed a serious restriction on the expressiveness of the lambda calculus
(for example, every typed term is strongly normalising). Instead of adding
types on top of untyped terms, Church considered types as part of terms in
the form of subscripts: for example, if A and B are distinct types, then x
A
and
x
B
are two dierent variables. Well-formed terms are given by the following
rules:
x
A
t
AB
t
A
(t t
)
B
x
A
V t
B
(x
A
.t)
AB
(1.z)
Churchs STT is still alive as the theoretical foundation of HOL [6] and
Isabelle/HOL [j], two of the most prominent proof-assistants based on type
theory.
Curry Curry, cf.[8, j, o], adopted a dierent approach to types from that
of Church. Instead of building terms out of typed variables, Curry started
with untyped terms, those generated by the rules in (1.1); types were later
assigned to those terms. Of course, not every untyped lambda term can be
assigned a type, and each typeable term can have an innitude of types. For
instance, while in STT (x
A
.x
A
)
AA
was a particular term for each type A, in
Currys view x.x had any type of the form A A, for any type A. In [o] it is
proved the existence of a type-checking algorithm: given a term t and a type
A, decide if t can be assigned the type A. Both Hindley [68] and Curry [j]
1.1. Type Theories
proved that it is decidable if one can assign any type to a given term; in fact
both of them proved that if any type can be given, there exists a most general
schema, called the principal schema, which can be inferred from the structure
of the term. Hindleys algorithms basically builds a unication problem, over
type expressions, by postulating the types each sub-term should have; this
procedure is dened by recursion on the structure of the term. The unication
problem, then, is to nd a substitution for type variables that satises all the
constraints.
Stronger type-systems: Polymorphism, Martin-Lf, and PTSs
In the last paragraph we saw that in typings la Curry more than one type can
be assigned to a single term. The next step was to understand that phenomenon
by adding type variables in the system and analysing the most general type
expression assignable by a unication algorithm on type expressions. Gir-
ard [61] and Reynolds [j8] considered independently the explicit addition of a
universal quantier (Girards system features also an existential quantier) to
STT la Curry. This extension is known as the polymorphic lambda calculus;
a simpler form of that type system is at the core of functional languages like
SML, OCaml, and Haskell. For example we can internalise the fact that the
identity function x.x has type A A for each type A by assigning the type
. ; in the following we use t: A to say that the term t has the type
A. Milner [86] extended Hindleys type-inference algorithm to polymorphic
languages where the quantication is only allowed at the top level.
Martin-Lf [8] presented another type theory where types can depend on
terms. The most fundamental dependent type is the cartesian product: if A
is a type and Ba is also a type for each a: A, then (x: A)B(x) is the type of
functions mapping each a: A to an element in Ba. This sort of dependency
was previously considered by Howard [6j] and by N. G. de Bruijn [o] in his
project Automath. The dependently typed programming language Agda [8]
is based on Martin-Lf type theory.
Coquand and Huet [1] proposed the Calculus of Constructions (CoC),
an impredicative type theory with dependent types. The Edingburgh Logical
Framework [6] is weaker than CoC in that dependent types can be only rst
order: this is enforced by introducing kinds, that are to types (called families
in LF) as types are to terms. Kinds are also present in languages like Haskell
and SML. In Haskell, for instance, basic types, Bool or Int, have kind ; type
constructors, like List, have kind ; so it will be a type once it is applied
to some type of kind . Berardi [z] and Terlouw [11] presented uniformly
several type systems, collectively referred as Pure Type Systems. The basic
idea is that all forms of function spaces, from the non-dependent and non-
polymorphic of STT, up to the dependent, polymorphic, and impredicative one
of CoC, can be captured by the same typing rules by parameterizing the formal
system by a set of sorts. We refer the reader to Barendregts [1], the standard
reference for PTSs, for more information about them. An extended version
of CoC, the Calculus of Inductive Constructions, serves as the theoretical
foundation for Coq [8].
1. Introduction
1.z Using dependent types
In this section I explain how dependent type systems can be used both as a
basis for writing formal proofs of mathematical theorems and as programming
languages whose type systems allowexpressing the specication of programs as
types. We rst explain the use of dependent types as the theoretical foundation
of proof assistants; then, we show how to program correctly a type-inference
algorithm for STT.
Curry-Howard Isomorphism
In the previous section I sketched the introduction of types and the emergence
of more complicated systems; as we moved from the beginning to the present
we cited some languages and proof assistants based on the dierent type
systems we mentioned. If we go back to Churchs pure lambda calculus we
see how logic was treated as a formal system with logical connectives as terms
(or term constructors) of the calculus. In this section we review a deeper
connection between typing systems and logical formalisms.
Curry was the rst to notice that the type schema of his combinators I, K,
and S correspond to the axioms of Hilberts minimal intuitionistic logic. In fact,
if we express the combinators as their corresponding lambda terms and then
apply Hindleys algorithm we get the following type-schemas (associates to
the right):
I = x.x: A A,
K = x.y.x: A B A, and
S = x.y.z.(x z) (yz): (A B C) (A B) A C.
We can think that Hindleys algorithm builds a tree guided by the structure
of the term whose type we want to infer. If the algorithm succeeds for some
term t, the built tree corresponds to a logical derivation of the propositional
formula represented by the inferred type. This means that we can decide if
a purported proof of a given theorem is in fact a proof by building a term
out of the proof and then applying the type-checking algorithm. Howard
[6j] later made this correspondence precise and showed how normalisation of
terms corresponds to cut-normalisation in proofs. This correspondence was
also noticed by Lambek [], who extended the correspondence of STT with
cartesian closed categories.
Identifying proposition with types is one in a series of readings across
the history and the dierent schools of constructivism, which are collectively
referred as the Brouwer-Heyting-Kolmogorov interpretation [zz, o, 81, 11].
Kolmogorov viewed propositions as problems; thus to know a proposition
true, is to have a method for solving the problem. Brouwer and Heytings [6]
reading is based on the idea that proofs of a composed propositional formula
consist in constructions built from the ones corresponding to the sub-formulas
involved. For example, a universal statement is intuitionistically true if one
has a method to produce, for each element of the domain of discourse, a proof
of the instance of the predicate for that particular element; in symbols, say P is
a predicate over some type A, the domain of discourse, a proof of x A, Px
1.z. Using dependent types
should be a method f which when applied to every a A yields a proof of Pa;
which ts with the description of dependent products of the previous section.
Let us analyse a concrete example of a proposition to see the formalisation
of proofs in type theory. Suppose we want to prove 1 +1 is even. First of all,
we need to dene a basic type corresponding to the set of natural numbers and
dene the adding operation; then we need to dene a type corresponding to
the proposition n is even.
Martin-Lf proposed [8z] that new types can be added to the formal system
by giving, and explaining: the conditions for forming the type, the valid forms
of constructing (canonical) elements for the newtype, the elimination operators
for each type, and a method for deciding when two canonical elements of the
new type are equal. These conditions are formalised by rules of some form of
judgement: formation rules, introduction rules, elimination rules, and axioms
for equalities.
The formation rule for the type of natural numbers is
Nat type
there are two introduction rules for canonical elements of Nat:
0: Nat
n: Nat
Suc n: Nat
Natural numbers can be used, eliminated, by the induction operator:
[n: Nat]
An type a: A0
[m: Nat b: Am]
f m b: A(Suc m)
natrec(n, A, a, f): An
Notice that A is not a type by itself, but a family of types indexed by natural
numbers; we indicate this dependency by putting the hypothesis in brackets.
Using the elimination principle for natural numbers we can dene addition
n +m = natrec(n, Nat, m, n
.p.Suc p).
Equality rules include those making equality an equivalence relation and
also a congruence with respect to constructors. For natural numbers we also
have axioms involving the eliminator:
natrec(0, A, a, f) = a natrec(Suc n, A, a, f) = f n natrec(n, A, a, f)
For example, using these axioms, and beta-reduction, we can prove Suc 0 +
Suc 0 = Suc (Suc 0).
The predicate n is even is introduced also with rules; the formation
rule for the type corresponding to that propostion should make explicit the
condition that n is a natural number:
n: Nat
Even n type
We can say that Even is a family of types indexed by Nat; the introduction rules
correspond to the inductive denition of even numbers:
EvZ: Even 0
n: Nat evn: Even n
EvInd evn: Even (Suc (Suc n))
6 1. Introduction
Notice that EvZ has not, a priori, the type Even (Suc n), for any n: Nat. In
the proposition-as-type correspondence, a proposition P is true if the type
representing P has some inhabitant; i.e., if there is some term with that type.
For example, let 1 be Suc 0 and 2 be Suc 1, we can derive EvInd EvZ: Even 2.
On the other hand we can derive that Even 1 +1 is equal, as a type, to Even 2;
so, it is to be expected that EvInd EvZ had also the type Even 1 +1. In general,
dierent representations of the same proposition should have the same proofs;
that means that we need a conversion rule:
(conv)
A type B type A = B a: A
a: B
Applying conversion we know that a proof of Even 2 also counts as a proof of
Even (1 +1).
The proposition-as-types principle that we have described justies the use
of type systems as the formalism on which mathematical knowledge is pre-
cisely written and proofs can be carried out. In particular, if the type system is
decidable, see Sec. 1., then it is possible to program a type-checker to verify
that some construction, represented as a term, is a proof for some proposition,
represented as a type. Geuvers [6o] reviews the history of proof assistants,
explains the dierences between several proof assistants and their theoretical
background (some of them are not based on the proposition-as-types principle),
and discusses a few issues arising when large pieces of mathematics are formal-
ised. Wiedijks compilation [118] of formalised proof of the irrationality of
2
can give an idea of the outlook of formalisations in dierent proof assistants.
Wiedijk [11j] lists the following four theorems as the most impressive pieces
of formalised mathematics:
1. Gdels rst incompleteness theorem.
z. Jordan curve theorem.
. Prime number theorem.
. Four-colour theorem.
Programming with Correctness
In the previous section we have explained the reasons for constructing proof
assistants as implementations on computers of type systems and referred to
some papers discussing formalisations of mathematical results. Dependent
types allow to program in a correct way by making it possible to write the
specication of each function as its type. We illustrate this point by the
following implementation in Agda of a type-inference algorithm for a variant
of the simple typed lambda calculus.
We only explain the most peculiar aspects of the program; an introduction
to Agda can be found in [z8].
module STT where
open import Data.Product
open import Data.Sum hiding (map)
1.z. Using dependent types
The underscores that appear in denitions are used to indicate arguments of
mixxed operators, be them variables, type constructors, or term constructors.
Arguments enclosed between curly braces are implict and can be inferred by
Agda. When one needs to know the implicit parameters in an application, they
are also enclosed in curly brackets.
inxl 10 _ _
inxr 20 __
_ _ : {A B C : Set} (B C) (A B) A C
g f = x g (f x)
id : {A : Set} A A
id x = x
Note that the type False lacks any constructor; this fact is recognised by
the compiler that permits to dene magic. This function can be thought as the
elimination principle for falsehood.
data False : Set where
magic : {A : Set} False A
magic ()
_ : Set Set
A = A False
The following type, called intensional equality, has only one constructor for
equality. We use this type to prove that each term has at most one type. A type,
or predicate, is decidable if we know if it has or not any member.
data _ _ {A : Set} : A A Set where
re : {a : A} a a
data Dec (A : Set) : Set where
yes : (a : A) Dec A
no : A Dec A
In the next snippet we introduce the types and prove that their intensional
equality is decidable. The with construct brings the result of some function
call to the left hand side of a denition, allowing to do pattern-matching in
the result of the function call.
data Ty : Set where
int : Ty
__ : Ty Ty Ty
arrEq : {t t
s s
: Ty} (t t
) (ss
) (t s) (t
)
arrEq re = re, re
_ _ : (t t
: Ty) Dec (t t
)
int int = yes re
(t t
) (ss
) with t s | t
(.s.s
) (ss
) (ss
) | _ | no p = no (p proj
2
arrEq)
(t _) (ss
) | no p | _ = no (p proj
1
arrEq)
8 1. Introduction
int (t t
) = no ( ())
(t t
) int = no ( ())
The untyped terms are either constants (natural numbers), addition, vari-
ables (we explain after the whole program our encoding of variables), abstrac-
tions (we use a bold lambda to distinguish the term constructor from the
internal abstraction operator of Agda), and applications.
data Nat : Set where
zero : Nat
suc : Nat Nat
data Tm : Set where
nat : Nat Tm
_ + _ : Tm Tm Tm
V : Tm
: Tm Tm
_._ : Ty Tm Tm
_ _ : Tm Tm Tm
The typing relation depends on a context assigning types to free variables;
each constructors of the type __: _ corresponds to a typing rule. We point out
that the typing rules are too strong; for example, we cannot type the weakening
of closed terms in the empty context. We accept this articiality for the sake of
simplicity of the algorithm.
data Ctx : Set where
: Ctx
__ : Ctx Ty Ctx
data __: _ : Ctx Tm Ty Set where
Con : forall {c n} cnat n: int
Add : forall {c e e
} ce: int ce
: int ce + e
: int
Var : forall {c t} (ct)V: t
Weak : forall {c t t
e} ce: t (ct
)e: t
Abs : forall {c t t
e} (ct)e: t
c t . e: t t
App : forall {c t t
e e
} ce: t t
ce
: t ce e
: t
_ _ : Ctx Tm Set
c e = ( t ce: t)
_ _ : Ctx Tm Set
c e = (c e)
In this part we prove several properties for this presentation of STT: unique-
ness of typing, some inversion properties, and some properties showing the
impossibility of assigning any type to some terms (under particular contexts).
uniqTy : (c : Ctx) (e : Tm) (t t
: Ty) (ce: t)
(ce: t
) t t
) (e) t t
)
1.z. Using dependent types j
= uniqTy c e t t
jdg jdg
uniqTy c ( t . e) .(t t
) .(t t
} jdg)
(Abs {.c} {.t} {t
} jdg
)
with uniqTy (ct) e t
jdg jdg
uniqTy _ ( s. _) .(st
) .(st
)
| re = re
uniqTy c (e e
) t t
} {.t
} jf
ja
)
with uniqTy c e (st) (s
) jf jf
uniqTy c (e e
ja
)
| re = re
The rst two results prove that both variables and terms applied to the
shifting operator cannot be typed in the empty context. Then we have the
inversion lemmas for typing of weakenings and abstractions.
varEmptyCtx : V
varEmptyCtx (t, ())
weakEmptyCtx : (e : Tm) ( e)
weakEmptyCtx e (t, ())
weakTy : (c : Ctx) (t : Ty) (e : Tm) (ct) (e) c e
weakTy c t e (t
, Weak je) = t
, je
absTy : (c : Ctx) (t : Ty) (e : Tm) (c ( t . e))
((ct) e)
absTy c t e (.(t t
} je) = t
, je
The following lemmata state properties about the typing of sums.
invAdd : (c : Ctx) (e e
: Tm) (c (e + e
))
(ce: int) (ce
: int)
invAdd c e e
(int, Add je je
) = je, je
invAdd c e e
(t t
, ())
addFunL : (c : Ctx) (t t
: Ty) (e e
: Tm) (ce: t t
)
c (e + e
)
addFunL c t t
e e
))
with uniqTy c e (t t
) int jdg je
addFunL jdg e
_ _ _ _ (.int, (Add je je
)) | ()
addFunR : (c : Ctx) (t t
: Ty) (e e
: Tm) (ce: t t
)
c (e
+ e)
addFunR c t t
e e
))
with uniqTy c e (t t
) int jdg je
addFunR jdg e
_ _ _ _ (.int, (Add je je
)) | ()
This last group of properties deal with typing judgements of applications.
invApp : (c : Ctx) (e e
: Tm) (c (e e
))
2
( t t
ce: t t
ce
: t)
invApp .c .e .e
(.t
} {e} {e
} je je
)
= t, t
, je, je
1o 1. Introduction
appFunTy : (c : Ctx) (e e
: Tm) (c (e e
)) (c e)
appFunTy c e e
japp
... | t, t
, je, _ = t t
, je
appArgTy : (c : Ctx) (e e
: Tm) (c (e e
)) (c e
)
appArgTy c e e
japp
... | t, _, _, je
= t, je
: Tm)
c (e e
)
appFunInt c e jint e
))
with uniqTy c e int (st) jint y
appFunInt t _ t
_ (_, (App y y
)) | ()
appArgOther : (c : Ctx) (e e
: Tm) (t t
s : Ty)
(ce: t t
) (ce
: s) (t s) c (e e
)
appArgOther c e e
t t
s jdge jdge
neq (s
} y y
))
with uniqTy c e (t t
) (r s
) jdge y | uniqTy c e
s r jdge
appArgOther c e e
.s .s
s jdge jdge
neq (s
, (App y y
))
| re | re = neq re
appEqTy : (c : Ctx) (t s t
: Ty) (e e
: Tm) (ce: t t
)
(ce
: s) t s ce e
: t
appEqTy c .s s t
e e
ce ce
re = App ce ce
The previous results are useful to program the function to infer types; note
the strong type of this function: given a context and a term we either infer
a type, in that case we also build a derivation showing that the term can be
typed in that context, or we prove that there is no type assignable to the term.
tyInf : (c : Ctx) (e : Tm) (c e) ( t ce: t)
tyInf c (nat n) = inj
2
(int, Con)
tyInf c (e + e
... | inj
1
er | _ = inj
1
( ih (magic er) (int, proj
1
(invAdd c e e
ih)))
... | _ | inj
1
er = inj
1
( ih (magic er) (int, proj
2
(invAdd c e e
ih)))
tyInf c (e + e
) | inj
2
(t t
, je) | _ = inj
1
(addFunL c t t
e e
je)
tyInf c (e + e
) | _ | inj
2
(t t
, je
) = inj
1
(addFunR c t t
e je
)
... | inj
2
(int, p) | inj
2
(int, p
) = inj
2
(int, Add p p
)
tyInf V = inj
1
varEmptyCtx
tyInf (ct) V = inj
2
(t, Var)
tyInf (e) = inj
1
(weakEmptyCtx e)
tyInf (ct) (e) with tyInf c e
... | inj
1
er = inj
1
( ih (magic er) (weakTy c t e ih))
... | inj
2
(t
, prf) = inj
2
(t
, Weak prf)
tyInf c ( t . e) with (tyInf (ct) e)
... | inj
1
er = inj
1
( ih (magic er) (absTy c t e ih))
... | inj
2
(t
, prf) = inj
2
(t t
, Abs prf)
tyInf c (e e
... | inj
1
er | _ = inj
1
( ih (magic er) (appFunTy c e e
ih))
... | inj
2
_ | inj
1
er = inj
1
( ih (magic er) (appArgTy c e e
ih))
... | inj
2
(s, ie) | inj
2
(s
, ie
) with s
... | int = inj
1
(appFunInt c e ie e
)
1.. Type-Checking: Deciding the Typing Relation 11
... | t t
with t s
t t
ie ie
neq)
... | yes eq = inj
2
(t
, appEqTy c t s
e e
ie ie
eq)
Let us explain briey the variation of the calculus with respect to that of
Sec. 1.1. Rule () in Def. 1 says that names of bound variables are irrelevant.
Explicit use of () becomes tedious and it is customary to avoid it by using
some convention over the terms for example, identify -equivalent terms
or assume all bound variables to be dierent. De Bruijn [1] was the rst to
notice that what is relevant is the distance, measured by how many binders
we should cross over by going upwards in the abstract syntax tree, between
an occurence of a bound variable and its binder. He replaced the set Var of
variables by natural numbers; if a natural number is greater than the distance
to the outer-most binder, then it represents a free variable. In our case, free
variables should be thought as assumptions referring to some hypotheses in
the context. Let us consider some examples showing how to translate to de
Bruijn notation. The combinator K = x.y.x becomes 1, and combinator
S = x.y.z.(x z) (yz), (((2 0) (1 0))). If we consider a term with free
variables as in x.f x we can use any index greater than 0 for f: 1 0.
Some of the subtleties of substitution become more apparent with indices;
for instance to avoid the capture of free variables in r when substituting r
inside an abstraction one needs to shift the free variables in r; that is, if n is an
occurrence of a free variable in r, it should become n+1 under the abstraction.
On the other hand, this shifting should not act on bound-variables. This
informal considerations can be internalised in the formal system by adding a
new grammatical category for explicit substitutions.
A
D
A
, see Fig. 1.1. If this reication
function maps elements in the image of _ to terms in normal form, then
we can compose the two functions and get a normal form for each term. The
reication function will be useful if we can prove that the composition of the
two functions maps terms to their normal form; that is, we need a proof that
t = R(t) is provable in the formal system. In order to use NbE for deciding
the equality in a theory we need another property: if t = t
is provable, then
we need to know that R(t) R(t
A
Nf
Syntax
t
D
A
R
1
(Nf)
Semantics
R
Figure 1.1: Normalisation by Evaluation
1. Related work
In this section I revise the state-of-the-art in the main themes of this thesis; in
the next section I highlight the contribution of each chapter with respect to
the literature mentioned here.
The technique of NbE for STT was introduced by Berger and Schwichten-
berg [z6]; but a model of normal forms has been already considered for a
dependent type systems (but without conversion under abstractions) in [8o],
where some combinatorial results are proved by reasoning over the model. As
far as I know, most of the literature of NbE for STT [11, 1z, 1, z, j, , 6],
in various presentations and under dierent points of view, considered -
long-normal forms; one exception is [1o] where the normalisation algorithm
does not -expand terms.
The rst paper on NbE for Martin-Lf type theory (MLTT) is [z], the cal-
culus considered here has an untyped notion of conversion. NbE for MLTT
with equality under types is considered in []. These papers are followed by
[], which presents an incremental type-checking algorithm based on [] and
uses ideas coming from the previous two works to prove the correctness and
completeness of the decision procedure for equality. Another related work
is [] which uses hereditary substitution to decide equality and presents a
type-checking algorithm for MLTT without (). A proof of the correctness and
completeness of type-checking for a weaker logical framework is in [6]. In
[1o8] the type-checking algorithm is extended to a logical framework with
singleton types and subtyping. Pollack [j] developed a formal proof of the
decidability of type-checking for ECC []. Barras [18] implemented in Coq a
correct and complete type-checking algorithm for the Calculus of Construc-
tions; later Barras [1j] considered stonger type systems closer to the actual
implementation of Coq.
1 1. Introduction
In the previous paragraph we mentioned two presentations of MLTT: with
typed-equality (two terms are equal under a type) and with equality generated
by a reduction relation on untyped-terms. Geuvers [j] conjectured that both
presentations are equivalent for PTSs. For PTSs without (), Adams [j] proved
the equivalence for functional PTSs. Later, Herbelin and Siles [1o] extended
and formalised Adams result to semi-full systems; Siles nally settled in his
PhD thesis [1o] the equivalence for every PTS.
1. Our contributions
In this section I briey comment on the contributions of the following chapters.
Most of them are based on work that I have done in collaboration with other
people; for each chapter I refer to the relevant papers and also make explicit
my personal contributions to them. Let us invoke the preface paradox, any
mistake or oversight of this thesis is my own responsibility.
A common trait of all the chapters is a NbE algorithm, suggested by Thierry
Coquand in the context of dependent type systems. The NbE algorithm is rst
presented for STT in Chap. z; we use STT to explain the technical issues to be
solved in NbE and how the algorithm handles them. One novelty of this NbE
algorithm is that it separates the phases of reication from that of -expansion;
thus the same architecture can be used for calculi with and without (). All the
chapters are organised in a similar way as that of Chap. z: rst we introduce
the formal system. Then we introduce a model suitable for the denition
of NbE. Correctness of the NbE algorithm is based on logical relations and
deserves a separate section. The normalisation algorithm is used in the last
section of each chapter.
In Chapter we dene NbE for Martin-Lf type theory with a universe and
dependent function spaces without rule (). From the proof of the correctness
of the normalisation function we prove the injectivity of the constructor of
dependent functions spaces; as far as we know, that result has not been proved
by elementary syntactical arguments. This chapter is based on a paper in
preparation, co-authored with Thierry Coquand and Daniel Fridlender; this
work is based on the papers mentioned in the next paragraph. My contribution
to the paper is the adaptation of the NbE algorithm for a calculus without ().
Chapter is an adapted version of joint-work with Andreas Abel and
Thierry Coquand. In this work we considered Martin-Lf type theory extended,
among others, with singleton types and proof-irrelevant types. This was rst
presented in TLCA [6] and later published in a journal version []; these articles
beneted and can be considered as follow-ups of [z, , ]. My contribution to
that work consisted in carrying on the proofs; in particular, I came up with the
method of proving completeness for the type-checker and the conservativity
of MLTT with a canonical element for proof-irrelevant types. The emphasis of
this chapter is on the use of NbE to dene a type-checking algorithm; as far as
I know, there is no proof of correctness and completeness for MLTT.
In Chapter we dene NbE for a class of Pure Type Systems; this chapter
is based on joint-work with Daniel Fridlender. As in Chap. , we prove the
injectivity of the constructor of dependent function spaces for predicative PTSs;
the model construction also leads to a proof of equivalence between systems
1.. Our contributions 1
with typed equality and untyped conversion for predicative PTSs. As I said, this
result has been already proved for every PTS by Siles [1o]; the contribution is
the proof method; which can be useful to study the equivalence for some PTSs
with (). The particular presentation of PTSs with explicit substitutions of this
chapter is a novelty in itself and we formalised some of their meta-theory. A
preliminary report of the results on this chapter was presented at Types-zo11
[]. My contribution to the results on this chapter are the formalisation of
the equivalence proof in Agda and the adaptation of the proof method of
correctness of NbE.
In Chapter 6 I show that the NbE algorithm can be adapted for theories in-
volving axioms like commutativity. Moreover I suggest some more applications
of NbE for dependent type systems.
Normalisation By Evaluation
2 This chapter is a technical introduction to NbE and the methods used in the
proofs of completeness and correctness of NbE. We study them in the more
elementary setting of STT. We rst present the formal system of STT, denoted
by
, a variant of
without ();
we skip the proofs of completeness and correctness for
. Later we adapt
that algorithm for
1j
(id-subs)
Ctx
id
(empty-subs)
Ctx
(fst-subs)
Ctx A Type
p .A
(comp-subs)
, , Ctx
(ext-subs)
, Ctx A Type t Term(, A)
(, t) .A
Figure z.z: Introductory rules for substitutions
operators and p are not. In the formal syntax of GATs every polymorphic
operator should be fully applied; in our case, the conclusions should read
, r): B
(eta)
t: A B
(App (t p) q) = t: A B
In rule () the weakening substitution is explictly applied to term t, thus none
of its free variables are bound by the binder.
Substitutions on terms The following rules axiomatise substitution; if we
read these axioms as rewrite rules, we can observe that they reduce redices
involving substitutions applied to terms. Keeping in mind our explanation
of substitutions, we can see that (snd-sub) corresponds to the replacement
of the rst free variable for the second component. Consider, for example,
an application App (q) t: A, we can rst reduce the -redex to get
App (q) t = q (id
z1
to avoid them being captured.
(sub-ass)
t: A : :
t () = (t ) : A
(sub-id)
t: A
t id
= t: A
(snd-sub)
t: A :
q (, t) = t: A
(abs-sub)
t: A B :
(t) = (t (p, q)): A B
(app-sub)
t: A B r: A :
(App t r) = App (t ) (r ): B
Substitutions The following rules can be understood as the equational theory
of a category with nite products: associativity of composition, identity is the
neutral element of composition, the universal property for the terminal object,
and properties for binary products: post-composition with the rst projection,
identity for products, and post-composition with a mediating morphism to a
product object.
(sub-ass)
: : :
() = ( ):
(sub-empty)
:
= :
(sub-idl)
:
id
= :
(sub-idr)
:
id
= :
(sub-id-empty)
id
= :
(sub-id-ext)
.A id
.A
= (p, q): .A
(sub-fst)
t: A :
p (, t) = :
(sub-map)
t: A : :
(, t) = (, t ): .A
Congruence The last two groups of rules correspond to reexivity, symmetry,
transitivity, and contextual clousure of equality.
(refl)
t: A
t = t: A
(refl-subs)
:
= :
(sym)
t = r: A
r = t: A
(sym-subs)
=
= :
(trans)
t = r: A r = s: A
t = s: A
(trans-sub)
= : = :
= :
zz z. Normalisation By Evaluation
(cong-app)
t = t
: A r = r
: A
App t r = App t
: A
(cong-abs)
.A t = t
: B
t = t
: A B
(cong-subs)
t = t
: A =
:
t = t
: A
(cong-map)
t = t
: A =
:
(, t) = (
, t
): .A
(cong-comp)
=
: =
:
=
:
Properties of the formal system
In our encoding of de Bruijn variables can be identied with q, q p
1
, q p
2
, . . .
where the notation p
i
denotes the i-times composition of p with itself:
p
i
=
id if i = 0
p if i = 1
p p
i1
if i > 1 .
Note that this substitution can be typed in a context by extending it by
successive applications of rules (comp-subs) and (fst-subs). In general we will
say that
i
if p
i
: . So, it is clear that if t: A then for any
i
we can derive t p
i
: A.
Remark 1 (Pre-order between contexts). The relation
i
denes a preorder
on contexts; in fact
0
, by (id-subs); and
if
j
and
i
, then
i+j
, by (comp-subs) and associativity of
composition.
Remark z (Inversion of substitution). It is clear that any substitution : .A
is judgmentally equal to some substitution (
, t): .A:
= id
.A
= (p, q) = (p , q ) .
Finally we characterise the set of terms in normal form. The shape of
normal forms, in the setting of untyped lambda calculus with named variables,
is x
1
.x
2
. . . . x
n
.(. . . ((yt
1
) t
2
) . . .) t
m
, where m 0, n 0, and every t
i
has
also that shape; it is easy to see that the following grammar captures those
terms.
Ne k ::= x | App k v
Nf v ::= x.v | k .
After replacing indexed variables for named variables in that grammar we
arrive at the denition of normal forms and neutral terms.
Denition z (Neutral terms and normal forms).
Ne k ::= q | q p
i+1
| App k v
Nf v ::= v | k
z.z. Normalisation by Evaluation for
z
z.z Normalisation by Evaluation for
DD ; (z.1)
where Var is a denumerable set (we write x
i
and assume x
i
= x
j
if i = j, for
i, j N), O = {, } (called the Sierpinskis space), [D D] is the set of
continuous functions from D to D, and D D is the cartesian product of D
with itself. The set Var is viewed as a at pre-domain. Every element of D
which is not , is an element of some component of the smashed sum in the
right hand side of Eq. z.1; in this case we write D for O and
pair : DD D lam : [D D] D
Var : N D App : DD D .
Reication We dene a partial readback function R which given an element
in D returns a term of the calculus. This function is similar as the readback
function introduced by Gregoire and Leroy [6z] to dene a normalisation
procedure by means of an evaluator. When the evaluator returns an abstraction
x.t, the readback function creates a new abstracion y.v, where v is the normal
form that results from the evaluation and reading back the term (x.t) y; the
constant y is later substituted for y by the readback function. In our case, in
an element of D of the form lamf, the function f can be thought of as being
the normaliser of the body of some abstraction, so we need only to apply f to
get a value which can be reied.
Denition (Reication function).
R
j
(App dd
) = App (R
j
d) (R
j
d
)
R
j
(lamf) = (R
j+1
(f(Var j)))
R
j
(Var i) =
q if j i +1
q p
j(i+1)
if j > i +1
Recall that in Fig. 1.1 we identied a subset of Dby taking the inverse image
of R over the set of normal forms; we also need to consider semantical neutral
values. Since our R is a family of functions indexed by a natural number, we
should consider all the indices:
Ne =
iN
{d D | R
i
d Ne} and Nf =
iN
{d D | R
i
d Nf} .
z z. Normalisation By Evaluation
Notice that if the case j < i +1 were undened in the clause for variables
in Def. , then for any m N the application R
0
(Var m) would be undened;
hence Var m Ne and, consequently, Ne would be empty. Since we depend on
having a semantic representation of variables and neutrals we add the case
j < i +1. This case will not arise in our use of the readback function.
Note that we can extend the projection functions
1
,
2
: D D D to
functions over D:
p d =
d
1
if d = (d
1
, d
2
)
otherwise
q d =
d
2
if d = (d
1
, d
2
)
otherwise
.
We also dene an application operation on D:
d e =
f e if d = lamf
App de if d Ne
otherwise
.
With these functions we can construct an environment model for
over
the applicative structure D, . The interpretation of terms and substitutions
is given by mappings _
t
_ : Terms D D and _
s
_ : Substs D D,
respectively. The second argument for both functions is an environment
assigning values to free variables.
App t r
t
d = t
t
d r
t
d
t
t
d = lam(e t
t
(d, e))
t
t
d = t
t
(
s
d)
q
t
d = q d
s
d =
id
s
d = d
(, t)
s
d = (
s
d, t
t
d)
p
s
d = p d
s
d =
s
(
s
d)
Our model is completed by xing the interpretation of types N = Ne
and A B = {d D | d e B, for all e A}. This model can be
viewed as a cartesian closed category, cf. next section; so we have soundness
for free. As a corollary we obtain a normalisation function. In fact, let =
A
1
. . . . .A
n
and t: A we only need to specify an appropiate environment
d for interpreting t. Since Var A for every type A, we can let d be the
sequence ((. . . (, Var 0) . . .), Var n 1) and dene our normalisation function
nbe
(t) = R
n
(t
t
d) .
We claim that nbe(_) is a normalisation function that can be used to decide
equality; but to support our claim we should prove:
1. normalisation: t: A, then nbe
(t) Nf;
z. correctness: if t: A, then t = nbe
(t): A; and
. completeness: if t = t
: A, then nbe
(t) nbe
(t
).
These results will be proved for
.
z.z. Normalisation by Evaluation for
z
Cartesian closed categories
The categorical models of STT are cartesian closed categories (CCC) [o, ]. A
cartesian closed category is a category with:
1. a terminal object,
z. binary products, and
. exponentials.
Now we give the interpretation of
t
t = t
q =
2
= !
id
= 1
(, t) = , t
p =
1
=
The notion of validity in this setting consists of showing that the semantics
of two equal terms are equal as morphisms in the underlying category of the
model and the semantic of equal substitutions are also equal as morphisms.
Denition (Validity).
Terms: t = t
: A i t = t
: A
Substitutions: =
: i =
: .
Since the formal system is the initial object in the category of cartesian
closed categories, soundness follows from initiality. This result is valid both
for
and
t[d | x : d
] .
The problem with this nave interpretation is that if application is inter-
preted as regular evaluation of functions, we cannot interpret open terms:
e.g., App x td is not well-dened, because x (td) does not make sense
remember that variables are interpreted as themselves. What we do instead is
to redene the semantics of application. This is achieved by tagging elements
in A B as neutral terms or functions, an idea coming from NbE for the
untyped lambda calculus []; now we can use the tag of the value in the
function place to redene application:
fun
f d = f d
neut
t d = App t d .
When we use this operator to interpret application and consider
neut
td, where
t is a neutral with type N B and d is the semantics of some term with type N,
we know that d is a normal form and the right hand side makes sense. On the
other hand, if t has type (A B) C and d A B, then the argument
d can be a function and the right hand side does not make sense. To solve
this, we can switch to a domain-theoretic model based on the solution of the
domain equation
D Var DD[D D] ,
analogous to the domain of Eq. z.1. An element d D will be called a neutral
value if d = Var x, with x Var, or if d = App e e
f e if d = lamf
App de if d is neutral
otherwise .
Coming back to the interpretation of types, we can set N to be the set of
neutral values, and A B = {d | d e B, for all e A}. The next step
is to dene the reication function: R : DA Terms.
R(Var x) = x
R(App de) = App R(d) R(e)
R(lamf) = x.R(f (Var x)) .
The reication of functions looks suspicious, because we are putting a binder
without checking that x, the binding variable, is fresh. One possibility, cf. [8],
z.. Normalisation by Evaluation for
z
is to use a dummy variable x, calculate the set of free-variables in the resulting
term, V = FV(R(f (Var x))) and pick any variable z Var\V to nally compute
z.R(f (Var z)). This method is clearly inecient, but it illustrates the problem
of freshness: a fresh binder is needed to avoid capturing other variables, and
the chosen variable should not be captured by any binder in the reication of
the body of the new abstraction.
In Berger and Schwichtenbergs [z6] seminal paper, they solved the problem
of fresh name generation by using the gensym facility of Scheme in a pure
functional language one would resort to a state monad, as in Filinskis [].
However, Berger and Schwichtenberg came up with another solution based
on a model where ground types are interpreted as term families indexed by
natural numbers, by xing the index one gets a term with de Bruijn levels;
1
higher-order types A B are still interpreted as the set of functions A B.
The interpretation of open terms depends on a family of reection functions
A
: Terms A, indexed by types. Reication is also dierent; it is dened
by induction on types and turns semantical elements into term families: R
A
:
A (N
A
). Note that when reifying a function f A B we have
at our disposition an index k telling that we can freely construct a term with
binding variable x
k
and, if we increment that index to k +1, no bound variable
will be used in the reication of the body: R
AB
(f, k) = x
k
.R
B
(f ( x
k
), k+1).
The normalisation of a closed term t : A is obtained by R
A
(t, 0). A similar
approach is used by Aehlig and Joachimski [11], but they use de Bruijn indices
instead of levels, so more accounting is needed when injecting variables into
the model and in the reication.
In this thesis the problem of generating fresh variable while reifying are
based on the same strategy presented in Sec. z.z: free variables are interpreted
as (semantical) variable corresponding to the position of the variable in the
context but in reversed order note that this correspond to pass from indices
to levels. When we reify values into terms, we keep a counter (as an extra
parameter of the reication function) of how many variables we have already
used.
z. Normalisation by Evaluation for
f d
if d = lamf
otherwise
(z.z)
1
Like with de Bruijn indices, variables are taken to be natural numbers, but now the binders
are counted downwards, if we see terms as abstract trees, x.y.x becomes ..0.
z8 z. Normalisation By Evaluation
Instead of interpreting typing derivations this is problematic because
one needs to prove a coherence result: if there are two derivations of the same
judgement, the interpretation of both derivations are equal we interpret
every term and substitution expression in the environment model arising from
the new applicative structure.
Interpretation
App t rd = td rd
td = lam(e t(d, e))
td = t(d)
qd = q d
d =
id
d = d
(, t)d = (d, td)
pd = p d
d = (d)
PER semantics Now we dene a PER model
z
for the calculus; this amounts
to dening a relation for each type which models the equality of the formal
system. Let us recall the denition of partial equivalence relations.
Denition . A partial equivalence relation (PER) over a set A is a binary
relation over A which is symmetric and transitive.
The class of all PERs over a set A is written PER(A). If R PER(A) then
its domain is dom(R) = {a A | (a, a) R}. Clearly, R is an equivalence
relation over its domain. If (d, e) R, sometimes we will write d =
R
e or
d = e R, and if d dom(R), we tend to write d R. It seems natural to
try to build a category of PERs over a set A; the objects of PER(A) are PERs
over A and morphisms are functions preserving the relation; i.e. functions
f : dom(R) dom(S), such that fd =
S
fe, for all d =
R
e.
D, D
is
isomorphic to 1; in particular DD as in [1, z].
The product of Aand B is given by AB = {(d, e) | p d =
A
p e and q d =
B
q e}. The projection morphisms are p and q. The morphismf, g : C
AB is given by f, g d = (f d, g d). We leave the proof of the universal
property for products; for it follows straightforward from the denition.
z
We refer the reader to [88] for a short report on the historical developments of PER models.
To be precise, two functions f, g : dom(R) dom(S) are considered to be the same morphism
if f d =
S
g e, for all d =
R
e.
z.. Normalisation by Evaluation for
zj
The exponential of A and B is B
A
= {(f, g) | f d =
B
g e, for all d =
A
e}.
The adjunction between Hom(_, C
B
) and Hom(_ B, C) is given by:
A
: Hom(AB, C) Hom(A, C
B
)
A
f = d lam(e f(d, e))
A
: Hom(A, C
B
) Hom(AB, C)
A
g = d g(pd) (qd)
Now that we have a cartesian closed category of PERs over D, we can
construct the model and get soundness of this model by Thm. 1. As we said
previously, for STT it is enough to choose an object of the category, PER(D) in
our case, for base types; the rest of the structure is obtained by the cartesian
structure of the category. In our case, N is interpreted by Ne PER(D), which
is analogous to Ne of Sec. z.z. The PER Ne equates elements of D that are
invariably reied as the same neutral term.
Denition 6 (Semantical neutrals and normal forms).
d = e Ne if, for all i N, R
i
d and R
i
e are both dened, R
i
d R
i
e,
and R
i
d Ne.
d = e Nf if, for all i N, R
i
d and R
i
e are both dened, R
i
d R
i
e,
and R
i
d Nf.
Remark . These are clearly PERs over D: symmetry is trivial and transitivity
follows from transitivity of the syntactical equality.
Remark (Closure properties over Nf and Ne).
1. Var dom(Ne).
z. Since Ne Nf, Ne Nf.
. If k = k
Ne and d = d
Ne.
. Let f, g [D D] such that f d = g d
Nf, then
lamf = lamg Nf:
R
i
(lamf) = (R
i+1
(f (Var i))) = (R
i+1
(g(Var i))) = R
i
(lamg) .
If we choose N = Ne, then we have a model of STT given by the cartesian
structure of PER(D):
= 1 .A = A A B = B
A
.
We recast soundness (Thm. 1) in our concrete model. Of course, soundness can
be proved straightforwardly by induction on derivations.
Theorem . Let d = d
;
1. If t: A, then td A.
z. If : , then d .
. If t = t
: A, then td = t
A.
o z. Normalisation By Evaluation
. If =
: , then d =
.
Remark . Clearly dom(N); since d = we conclude A for any
type A. Moreover if d dom(A B), then d = lamf, for some f [D D].
We have explained in Sec. z.z why the model should contain some syn-
tactical material as to reect neutral terms. Our model can indeed represent
variables and neutrals; but as an immediate consequence of Rem. we cannot
interpret syntactic variables with a higher-order type as mere semantic vari-
ables. In fact, from that remark we know that injection of variables should
transform variables into functions lamf; this has the pleasing side eect of
-expanding variables of type A B while Var i is reied as some variable
q or q p
n
for some n, lamf is read back as t for some term t. Remember that
injection was done by a family of functions
A
_ indexed by types; in Berger
and Schwichtenbergs work that function turned syntactical variables into term
families. Our approach consists in dening reection
A
_ completely in the
semantic realm; as we explain after its denition, reection needs a mate
A
_.
These functions are dened simultaneously by induction on types.
Denition (Up and down).
N
k = k
AB
k = lam(d
B
(App k (
A
d)))
N
v = v
AB
d = lam(e
B
(d
A
e))
Notice that we do not restrict the domain of the reection function to
elements in Var; in fact, since we want to simulate -expansion by means of
AB
, it is necessary to take into account representation of any neutral term
and not only variables. The need of
A
arises as we want to avoid to reify
values as in Berger and Schwichtenbergs approach: since the body of the
newly created function is in turn expanded, we need to know that it is morally
a neutral value. That would be the case if the second argument of App k _
is a normal value, cf. Rem. ; the mate of reection,
A
maps elements of
dom(A) to dom(Nf).
The following lemma states precisely that the pair of functions do what we
claimed. We can also read the lemma as showing that every PER denoting a
type can be seen as a saturated object [8, Ch. ].
Lemma . For all A Type.
1. If k = k
Ne then
A
k =
A
k
A, and
z. if d = d
A, then
A
d =
A
d
Nf.
Proof. (By induction on types) We show only the case for functional types.
1. Let k = k
Ne and d = d
. To prove
A
B
k =
A
B
k
B, we prove (
A
B
k) d = (
A
B
k
) d
B. By i.h. on
the second part for A
we know
A
d =
A
d
(
A
d
(
A
d
)) B.
z. Let d = d
we have
A
Var i =
A
Var i A
, so by denition d
A
(Var i) =
d
A
(Var i) B, therefore we conclude, by i.h. on the second part
for B,
B
(d (
A
Var i)) =
B
(d
(
A
Var i)) Nf.
z.. Correctness of NbE 1
Theorem (Completeness). If t = t
: A and d = d
, then
A
(td) =
A
(t
) Nf.
Proof. By Thm. and Lem. .
We still do not have a normalisation algorithm because we do not know how
to construct a suitable environment. Let us illustrate this point by postulating
a base type with two values, call it Bool with constructors True and False. Since
these are normal forms, we need to reect them on the domain; so we extend
the domain Dwith {T, F}
;
these are families of relations, indexed by types, relating two models. In our
case, the models involved are the term model and the PER model: that means
that we should relate equivalence classes of terms and equivalence classes over
the domain of PERs. To understand our use of logical relations let us state
soundness of NbE:
If t: A, then t = R
n
(
A
(td)): A, for some n N, d .
To prove that property for every well-typed term we rst dene the relations
between well-typed terms and elements in (the domain of) the interpretation
of types and prove the more general statement
If t: A d A, then t = R
n
(
A
d): A for some n N . (z.)
The logical relations are dened by induction on types. For the basic
type N, we say that a term t is logically related with d N if t =
R
n
(
N
d): N holds note that we are not relating equivalence classes of
terms with equivalent classes over dom(N); we then prove that the relations
preserve both equivalences. For higher-order types A B, the relation is
dened by using the relations for A and B:
t: A B d A B if App t t
: B d d
B,
for all t
: A d
A .
As we try to prove (z.) for abstractions we discover that we need to gen-
eralise its statement to be able to change the context. The reason is that the
term model is a Kripke model, with contexts taking the rle of possible worlds;
this leads us to Kripke logical relations [j1]. At this point we would have
,
substitutions are internalised in the system; so we introduce logical relations
for substitutions and elements in the interpretation of contexts. Finally, by
constructing an environment logically related with the identity substitution
we can conclude that every term is logically related with its denotation.
Denition 8 (Logical relations).
For the basic type N: t: N d N if t p
i
= R
||
(
N
d): N, for
all
i
.
For function spaces, A B: t: A B d A B if
App (t p
i
) s: B f d B, for all
i
and s: A d A.
The following two lemmas show that the relations introduced over sets
of well-typed terms and domains of the PERs are indeed relations between
equivalence classes of terms and equivalence classes over the domain of PERs.
Lemma 6 (Preservation of the logical relation by PERs). If t: A d A
and d = d
A, then t: A d
A.
Proof. (By induction on types)
For N is obtained directly from the denition of the logical relation and
from the denition of Ne.
For A
B: let
i
and s: A
e A
. From e = e A
we have d e = d
e B.
Lemma (Preservation of the logical relation by judgemental equality). If
t: A d A and t = t
: A, then t
: A d A.
Proof. (By induction on types).
For N : we have t = R
||
(
N
d): N and t = t
: N, by transitivity
we conclude t
= R
||
(
N
d): N
For A
B : Let
i
and s: A
p
i
: A B and App (t p
i
) s =
App (t
p
i
) s: B. From the hypothesis about the logical relation we know
App (t p
i
) s: B de B. By i.h. on B we have App (t
p
i
) s: B
d e B.
Lemma 8 (Monotonicity of the logical relation). If t: A d A and
i
, then t p
i
: A d A.
Proof. (By cases on A) Let
i
. In both cases we need to prove a property
involving a new context
such that
j
. By Rem. 1 we know
i+j
.
z.. Correctness of NbE
To prove t p
i
: N d N, we need to show
(t p
i
) p
j
=
R
|
|
d: N, for any
j
. So by denition of the logical relation we
have
t p
i+j
= R
|
|
d: N; we conclude by using associativity of
substitutions and Lem. .
For A
B : Let
j
and
s: A
e A
and show
App ((t p
i
) p
j
) s: B d e B. Again, by denition of logical relation
for function spaces
App (t p
i+j
) s: B d e B; we conclude by
using associativity of substitutions and Lem. .
The following lemma is one of the key results to prove correctness. Note
that we are interested in the second part, which is the general statement of
(z.); the rst part is needed to prove the second part for higher-order types.
Lemma j (In-out Lemma).
1 Let t: A, k dom(Ne) and t = R
||
k: A for all
i
, then
t: A
A
k A.
z If t: A d A, then t p
i
= R
||
(
A
d): A, for all
i
.
Proof. (We prove simultaneously both points by induction on types) We show
only the case for functional types.
1. To prove t: A
B
A
B
k A
B, let
i
and
s: A
d A
to prove
App (t p
i
) s: B (
A
B
k) d B .
Note that by denition of
A
B
k, that amounts to prove
App (t p
i
) s: B
B
(App k (
A
d)) B .
In turn, this can be proved by i.h. of j.1 on B, because k Ne and
A
d Nf, by Rem. , App k (
A
d) Ne; so we take
j
and prove
App (t p
i+j
) (s p
j
) = R
|
|
(App k (
A
d)): B .
Note that by denition of readback, our new goal is
App (t p
i+j
) (s p
j
) = App (R
|
|
k) (R
|
|
(
A
d)): B .
We know by hypothesis
t p
i+j
= R
|
|
k: A
s p
j
= R
|
|
(
A
d): A
q: A
Var n
A
by i.h. of j.1 on A
App (t p
i+1
) q: B d
A
(Var n) B. By
i.h. of j.z on B we have
.A
App (t p
i+1
) q = R
n+1
(
B
(d (
A
(Var n)))): B .
By (cong-abs),
(App (t p
i+1
) q) = (R
n+1
(
B
(d (
A
(Var n))))): A
B .
z. Normalisation By Evaluation
Now, by (), we have (App (t p
i+1
) q) = t p
i
: A
B; on the right
hand side, in turn, we have by denition of readback
(R
n+1
(
B
d (
A
Var n))) = R
n
(
A
B
d) .
By transitivity, we conclude t p
i
= R
n
(
A
B
d): A
B.
We extend the logical relations to substitutions and environments. This
family of relations is dened by induction on the codomain of substitutions.
Denition j (Logical relations for substitutions).
: d if d .
(, t): .A (d, d
) .A if : d and t: A
d
A.
Of course we need to prove analogous results for substitutions to that of
Lem. 6, , and 8. Note that Lem. j is not needed because we do not reify
substitutions.
Lemma 1o. Let : d .
1. If =
: , then
: d .
z. If d = d
, then : d
.
. If
i
, then
p
i
: d .
Let us recapitulate how far we went towards correctness of NbE, the goal of
this section: we have dened a relation between the term model and the PER
model; we have proved that if a term t is related with some semantic element
d, then the reication of d will be provable equal to the t. The next theorem
states that every term (and substitution) is related to its denotation.
Theorem 11 (Fundamental theorem of logical relations).
1. If t: A and : d , then t : A td A.
z. If : and : d , then : d .
Proof. (By simultaneous induction on t: A and : ). In several
cases, Lem. 6 and are used to get the right premises that permit us to apply
induction hypotheses.
1. Terms:
(hyp) .A q: A. Let : .A d .A. By denition of
logical relation for substitutions we have = (
, t): and
t: A q d A. We nish by Lem. on .A q (
, t) = t: A.
(app-i): App t t
: A t
d A. By denition of
logical relations we conclude App (t ) (t
): B td t
d
B. On one side we have td t
d = App t t
) = (App t t
) : B. We conclude by Lem. .
z.. Correctness of NbE
(abs-i) t: A B. To prove (t) : A B td A
B, we need to take
i
and
s: A e A and show
App (((t) ) p
i
) s: B td e B. Notice that we can derive
App ((t) ) p
i
s = t ((p
i
), s): B by the following equational
reasoning:
App ((t) ) p
i
s = App ((t) (p
i
)) s
= App (t (p
i+1
, q)) s = (t (p
i+1
, q)) (id, s)
= t (p
i+1
, q) (id, s) = t ((p
i+1
) (id, s), q (id, s))
= t ((p
i
) id, s) = t (p
i
, s)
On the other hand, we have by Lem. 1o and denition of logical
relation for substitutions
(p
i
, s): .A (d, e) .A. So
by i.h. on .A t: B, with this extended substitution, we get
t (p
i
, s): B t(d, e) B. Note that td e = t(d, e), thus
by Lem. , we get
App (((t) ) p
i
) s: B td e B.
(subs-term) t : A. By i.h. on : we have :
d . By i.h. using that substitution and environment on
t: A we conclude t ( ): A t(d) A. We conclude
by Lem. on t ( ) = (t ) : A.
z. Substitutions: we omit some trivial cases.
(comp-subs). Let : and : d . By inversion,
we have : and : . By i.h. on the rst one, we have
: d and using that and the second premise by
i.h. , we get (): (d) . By using Lem. 1o we
conclude ( ) : d .
(ext-subs). Let (, t): .A. By inversion, we know : and
t: A. By i.h. we have : d ; and by i.h.
for t: A we conclude t : A td A: these are the
premises for (, t) : .A (, t)d .A.
(fst-subs). Let .A p: . By inversion on : .A d .A we
know = (
, t), d = (e, e
), and
: e . By Lem. 1o,
using (sub-fst) on p (
, t) =
: , we conclude p (
, t):
p(e, e
) .
Remark 6. It is immediate to see that R
n
(Var (n 1)) = q and for all m > n
R
m
(Var (n 1)) = q p
mn
. Let n = ||, then we can use Lem. j to conclude
.A q: A
A
(Var n) A.
Denition 1o (Canonical environment). By induction on we dene an envir-
onment
.
1.
= .
z.
.A
= (
,
A
(Var n)), where n = ||.
Remark . Clearly, by induction on and using Rem. 6, we have id
.
6 z. Normalisation By Evaluation
Our normalisation function is the composition of evaluation with the ca-
nonical environment, eta-expansion on the model, and reication.
Denition 11 (Normalisation function).
nbe
A
(t) = R
||
(
A
(t
)) (z.)
After the long trip we nally arrive at the main results of this section. First
we show the proof of correctness of the normalisation function and then we
explain how to decide if two well-typed terms are judgmentally equal.
Corollary 1z. If t: A, then t = nbe
A
(t): A.
Proof. We use Thm. 11 and Lem. with the identity substitution on the context
to get t: A t
)): A.
Corollary 1. If t: A and t
: A we can decide if t = t
: A is
derivable.
Proof. Let
t = nbe
A
(t) and
t
= nbe
A
(t
). By Cor. 1z we have
t =
t: A and (D1)
t
=
t
: A (Dz)
since
t and
t
: A by checking
syntactically that they are the same term. If t = t
: A, then by Thm.
t
t
The presentation of
, but
now types can depend on terms. This dierence can be appreciated in the
introductory rules for sorts. Notice that Type(_) is not any more a xed sort;
now we have a set of well-formed types for each well-formed context.
(ctx-sort)
Ctx is a sort
(subs-sort)
, Ctx
is a sort
(type-sort)
Ctx
Type() is a sort
(term-sort)
Ctx A Type()
Term(, A) is a sort
Introductory Rules
Contexts Several of the introductory rules for
:
(emp-subs)
:
(fst-subs)
A
.A p:
(comp-subs)
: :
:
(ext-subs)
: A t: A
(, t): .A
Types Note that (u-el) reects terms with type U as types. The type Fun AB is
the dependent function space: note that B is a type under .A, so B(id, t) is a,
possible distinct, type under for each t: A.
(u-i)
U
(u-el)
A: U
A
(fun-i)
A .A B
Fun AB
(subs-type)
A :
A
Terms We see in the introductory rules for terms that the universe is closed
under formation of dependent products. Rule (fun-el) makes explicit that
Fun AB is a dependent product space. Rule (conv) is another distinctive feature
of dependent type systems; it manifests that types can be computed. It is
because of this rule that we need a decision procedure for equality to dene a
type-checking algorithm.
1
(fun-u-i)
A: U .A B: U
Fun AB: U
(hyp)
A
.A q: Ap
(fun-i)
A .A B .A t: B
t: Fun AB
(fun-el)
A .A B t: Fun AB r: A
App t r: B(id
, r)
(subs-term)
A t: A :
t : A
(conv)
t: A A = B
t: B
1
In GATs the conversion rule (conv) is an instance of a derived rule.
.1. The calculus
1
Axioms
We omit the premises for axioms. The premises for substitutions are similar
to those for
= p (, t) =
id
.A
= (p, q) (, t) = (, t )
Terms and types
U = U (Fun AB) = Fun (A) (B(p, q))
t () = (t ) t id = t
q (, t) = t (t) = (t (p, q))
(App r s) = App (r ) (s ) App (t) r = t (id, r)
Congruence The only new congruences are those involving Fun (we present
the one corresponding to Fun as a type constructor and skip the rule for its rle
as term constructor) and substitutions on types. Remember that these rules
are obtained freely from the logical framework we are using.
(cong-fun)
A = A
.A B = B
Fun AB = Fun A
(cong-subs)
A = A
:
A = A
Properties of
: A t
= t
: A
t = t
: A
The following inversion lemma is easily proved by induction on derivations;
we show only one case of the proof, because all the other are analogous.
Lemma 1 (Inversion of typing judgements).
1. If Fun A
: A, then A = U, A
: U and .A
: U;
z. If Fun AB, then A and .A B.
z . NbE for Martin-Lf Type Theory
. If t: A, then A = Fun A
and .A
t: B
;
. If App t r: A, then A = B
, and r: A
.
Proof. Let us consider the last point. If App t r: A, it is clear that the last
rule used can only be either (fun-el) or (conv). In the rst case, the premises
give t: Fun A
, r: A
, and A = B
(id
, r) is obtained by (refl).
If the last rule used was (conv) from App t r: C and C = A,
we use the i.h. on the rst premise to get t: Fun A
, r: A
, and
C = B
(id
(id
, r).
The next lemma is a property of the meta-theory of GATs; to prove it
directly we should add a new form of judgement for equality between contexts.
Lemma 1 (Inversion of equality).
1. If A = B, then A and B.
z. If t = t
: A, then t: A and t
: A.
Remark j. The main result proved in this chapter is injectivity of Fun: if
Fun AB = Fun A
, then A = A
and .A B = B
[D D] D[D D] DD {U}
.
.z. Semantics and Normalisation by Evaluation
Some of the components are the analogous as those of Def. (z.1): Var is a
denumerable set of variables, neutrals values accounts for one copy of DD;
environments will be modeled using the same sequences built from and
elements in DD. Elements of the lifted singleton {U}
and of D[D D]
will be used to represent types in the semantics.
Notation. We use for injections into D the same symbols for constructors in
the syntax, so an element distinct from is written as:
(d, d
) for d, d
D
Var i U for i Var
lamf Fun d f for d D, and f [D D]
App dd
for d, d
D
The readback function of the previous chapter should be extended to cover
the new elements in the domain.
Denition 1 (Readback function).
R
j
U = U
R
j
(Fun X F) = Fun (R
j
X) (R
j+1
(F Var j))
R
j
(App dd
) = App (R
j
d) (R
j
d
)
R
j
(lamf) = (R
j+1
f(Var j))
R
j
(Var i) =
q if j i +1
q p
j(i+1)
if j > i +1
Our model will be based on the reection of neutral terms in D, as in
Sec. z.z. Intuitively, the sets of semantical neutral values Ne and semantical
normal forms Nf have more elements than those of Sec. z.z, because we have
more normal forms.
Denition 1 (Semantical neutral values and normal forms).
Ne =
iN
{d D | R
i
d Ne} and Nf =
iN
{d D | R
i
d Nf} .
The application operator for
f e if d = lamf
App de if d Ne
otherwise .
The interpretation of expressions in this applicative structure is given by
a pair of functions _
t
_ Terms D D and _
s
_ Subs D D;
they are shown in Fig. .1. In the following we omit the superscript from the
semantic brackets. Remember the over-loading rle of p and q as projection
functions in D:
p d =
if d = (d
, e)
otherwise .
. NbE for Martin-Lf Type Theory
U
t
d = U
Fun AB
t
d = Fun (A
t
d) (e B
t
(d, e))
App t r
t
d = t
t
d r
t
d
t
t
d = lam(d
t
t
(d, d
))
t
t
d = t
t
(
s
d)
q
t
d = q d
s
d =
id
s
d = d
(, t)
s
d = (
s
d, t
t
d)
p
s
d = p d
s
d =
s
(
s
d)
Figure .1: Semantics
Domain model
In
F Nf
if Fun X
F U: By i.h. X
Nf and Var i [X
Nf and R
i+1
(F Var i) Nf, hence
R
i
(Fun X
F) Nf.
Finally we consider X = Fun X
F] Nf. Given
d Ne and d
[X
] we show d d
[F d
]: by i.h. d
Nf and d d
=
App d d
U we conclude
d [Fun X
] for each d
[X
] Nf
and Nf. Let us suppose d = lamf: since Var i Ne, by i.h. Var i [X
], so
f (Var i) [F d
) |
d and d
[Ad]}.
z. Types: A if and only if and for all d , Ad T.
. Terms: t : A if and only if A and for all d , td [Ad].
. Substitutions: : if and only if , , and for all d ,
d .
We extend the denition of validity to equality judgements, for example
t = t
: A i t : A, t
: A, and td = t
d, for all d .
The following theorem states that this construction over the applicative
structure models the calculus. We omit the proof of soundness which can be
done by a tedious, but straightforward, induction on derivations.
Theorem 1 (Soundness). If J, then J.
6 . NbE for Martin-Lf Type Theory
As before, soundness and Lem. 16 are the crucial results for having com-
pleteness of the normalisation algorithm, dened as the composition of reica-
tion and interpretation.
Corollary 18 (Completeness of normalisation). Let and d .
1. If A, then R
||
(Ad) Nf.
z. If A = A
, then R
||
(Ad) R
||
(A
d).
. If t: A, then R
||
(td) Nf.
. If t = t
: A, then R
||
(td) R
||
(t
d).
Proof. By Thm. 1, Ad T and td [Ad]; by Lem. 16, td Nf.
. Correctness of NbE via logical relations
As in the previous chapter, correctness of normalisation is proved using logical
relations. For
B, and
A
X T, and B(p
i
, s) F d T for all
i
and all
s: A
p
i
d X.
t: A d Fun X F if and only if A = Fun A
B,
A
p
i
d
X,
App (t p
i
) s: B(p
i
, s) d d
F d
;
if d = lamf, then t = t
: A,
if d Ne, then (t p
i
) = R
||
d: Ap
i
.
.. Correctness of NbE via logical relations
Note that the denition of the logical relation for dependent products is a
bit contrived; in fact, logical relations of functional types are usually dened
using the logical relations of the lower types involved, as in Sec. z.. For
this calculus, however, we need to impose additional conditions on terms
basically, that functions in the semantics are related only with abstractions,
otherwise it is not clear how to prove Lem. z1.
The following lemma shows that judgemental equality preserves the logical
relation; since we have dened the logical relations using denitional equality,
this lemma is easily proved.
Lemma 1j (Preservation by judgemental equality). Let A = A
and
A X T.
1. A
X T; and
z. if t = t
: A and t: A d X, then t
: A
d X.
Proof. By induction on X T. Every case boils down to get the relevant part
of the hypothesis and using (sym-trans) and congruence for getting the key
equality judgement in the denition of the relation. We show only some cases.
For types, we consider X = Fun X
Fun X
F T is
immediate.
For terms, we also consider X = Fun X
F;
then we make case analysis on d [Fun X
= t
: A
. The other
possibility for d [Fun X
;
then by (sym-trans) t
p
i
= R
||
d: Ap
i
. By congruence App (t p
i
) s =
App (t
p
i
) s: C(p
i
, s), so by i.h. on App (t p
i
) s: C(p
i
, s) App dd
F d
,
we conclude App (t
p
i
) s: C(p
i
, s) App dd
F d
.
Lemma zo (Monotonicity). Let
i
then
1. If A X T, then Ap
i
X T; and
z. If t: A d X, then t p
i
: Ap
i
d X.
Proof. By induction on X T. We will show rst the proof of the rst point,
and then the proof of the second point.
Types. We consider only the case of neutrals and function spaces. For X
Ne: Let A X T and
i
. For
j
, we have
i+j
, by denition
of the log. rel. for types, Ap
i+j
= R
||
X. Since Ap
i+j
= (Ap
i
) p
j
, we
have (Ap
i
) p
j
= R
||
X; thus Ap
i
X T.
Let us consider now the case X = Fun X
F: let A Fun X
F T and
i
. We rst prove that Ap
i
= Fun B
1
C
1
for some B
1
and C
1
: note that we
can get Ap
i
= Fun (Bp
i
) (C(p
i
p, q)) from the hypothesis after applying
congruence under weakening. The second point, Bp
i
X
T, follows
from the induction hypothesis for B X
T. Finally, let
j
and
s: Bp
i
p
j
d
, by Lem. 1j s: Bp
i+j
d
; thus by def.
we have C(p
i+j
, s) F d
T.
8 . NbE for Martin-Lf Type Theory
Terms. We only consider the case for X = Fun X
F
and
i
. As before, from A = Fun BC we get by congruence
Ap
i
= Fun (Bp
i
) (C(p
i+1
, q)), and by i.h. Bp
i
X
T. Let
j
and
s: Bp
i
p
j
d
; by Lem. 1j we have s: Bp
i+j
d
; thus
by def. App (t p
i+j
) s: C(p
i+j
, s) d d
F d
F d
. Finally we
do case analysis on d [Fun X
: A, hence by
congruence t = (t
(p
i
p, q)): A. If d Ne, then we have (t p
i
) p
j
= t p
i+j
,
thus (t p
i
) p
j
= R
||
d: (Ap
i
) p
j
, from def. of logical relations.
The next lemma (sometimes called in-out lemma) is almost what we need
to nish the proof of soundness; in fact, the only remaining step is to show
that each term is logically related to its denotation.
Lemma z1 (Derivability of equality of reied elements). Let A X T,
and t: A d X, then
1. A = R
||
X,
z. t = R
||
d: A; and
. if k Ne and for all
i
, t p
i
= R
||
k: Ap
i
, then t: A k X.
Proof. By induction on X T. The base cases are obtained immediately from
the denition. So we show only the proofs for X = Fun X
F.
1. From A Fun X
T, and .B C F Var || T; thus by i.h. we get B = R
||
X
and .B C = R
|.B|
(F Var ||). Hence by congruence, Fun BC =
Fun (R
||
X) (R
||+1
(F Var ||)); and by def. of readback Fun BC =
R
||
(Fun X F).
z. We show only the case for X = Fun X
F.
By i.h. on the third point .B q: Bp Var || X
) p) q = R
||+1
(f (Var ||)): C(p, q) ;
by trans. and conversion .B t
= R
||+1
f Var || : C. By def. of read-
back R
||+1
(f (Var ||)) = R
||
(lamf), hence by congruence t
=
R
||
(lamf): Fun BC.
. let k Ne and t p
i
= R
||
k: Ap
i
, for all
i
. The only point
to show is App (t p
i+j
) s: C(p
i+j
, s) App k d F d, for all
j
and s: Bp
i+j
d X
) .A if and only if : d ,
A Ad T, and t: A d
Ad.
Lemma zz (Preservation by judgemental equality). If = : , and
: d , then : d .
Lemma z (Monotonicity). If : d , then for any
i
,
p
i
: d .
Theorem z (Fundamental theorem of logical relations).
1. if A and : d , then A Ad T;
z. if t: A and : d , then t : A td Ad; and
. if : and : d , then : d .
Proof. By induction on the derivations. We note that for terms we show only
some cases when the last rule used was the introductory rule; the case when the
last rule used was the conversion rule, we can conclude by i.h., and Lem. 1j.
1. For types we show the case for Fun AB. It is clear that we can apply
the congruence for Fun to deduce (Fun AB) = Fun (A) (B( p, q)),
and by inversion and i.h. A Ad T. Let
i
and
s: (A) p
i
e Ad, then ( p
i
, s): .A (d, e) .A,
hence by i.h. B( p
i
, s) B(d, e) T; thus by Lem. 1j,
(B( p, q)) (p
i
, s) B(d, e) T.
z. For terms we only show the proof for rules (fun-i), (fun-el), (hyp), and
(subs-term).
a) Let t: Fun AB. As before, A Ad T, and for
i
and s: (A) p
i
e Ad, by i.h. on .A t: B,
we have t ( p
i
, s): B( p
i
, s) t(d, e) B(d, e). Note that
t(d, e) = td e and t ( p
i
, s) = App (t ( p
i
, q)) s, hence by
Lem. 1j, we have App ((t) p
i
) s: B( p
i
, s) td e
(Bd) e.
b) Let App t r: B(id, r). This case is easy. By inversion and
i.h. r : A rd Ad and t : (Fun AB) td
Fun ABd. By def. of log. rel. App (t ) (r ): B(, r )
(td rd) B(d, rd); and by Lem. 1j, we conclude
(App t r) : (B(id, r)) App t rd B(id, r)d.
c) Let .A q: Ap. From Rem. 1 we know = (, t), and from def.
of log. rel. for substitutions d = (e, e
), : e , and
t: A e
(_) = R
||
(_
) , where
(t): A.
Proof. By Thm. z and Lem. z1.
From soundness and completeness of NbE we obtain a decision procedure
for judgemental equality for well-formed types and well-typed terms.
Corollary z6 (Decision procedure for judgemental equality). Given A and
A
we can decide if A = A
. Also, if t: A and t
: A we can
decide if t = t
: A.
Another consequence of soundness is the injectivity of the constructor Fun.
As we said in Rem. j, this cannot be proved by induction on derivations.
Corollary z (Injectivity of Fun _ _). If Fun AB = Fun A
, then A =
A
and .A B = B
.
Proof. Assume Fun AB = Fun A
T . (.1)
From the denition of logical relations we deduce A A
T and
.A B B
.A
T; by Lem. z1 A = R
||
(A
) and .A B =
R
|.A|
(B
.A
). By Lem. 1j on (.1) and Fun AB = Fun A
we get
Fun A
Fun AB
) .A B = R
|.A|
(B
.A
). Finally we can apply (sym) and (trans)
to conclude A = A
and .A B = B
.
.. Implementation of a type-checker for
1
. Implementation of a type-checker for
.
(empty-ctx)
Ctx
(ext-ctx)
Ctx A Type()
.A Ctx
(empty-subs)
Ctx
(id-subs)
Ctx
id
(fst-subs)
A Type()
p .A
(ext-subs)
t Term(, A)
(, t) .A
(comp-subs)
Types The only new type constructor is {t}
A
, for singletons: a subtype of A
containing t as single inhabitant.
(u-f)
Ctx
U Type()
(u-el)
A Term(, U)
A Type()
(fun-f)
A Type() B Type(.A)
Fun AB Type()
(sing-f)
A Type() t Term(, A)
{t}
A
Type()
(subs-type)
A Type()
A Type()
Terms Singleton types do not have a special constructor for their inhabitants;
on the other hand, we close the universe under singleton types.
(fun-u-i)
A Term(, U) B Term(.A, U)
Fun AB Term(, U)
(fun-i)
t Term(.A, B)
t Term(, Fun AB)
(fun-el)
B Type(.A) t Term(, Fun AB) u Term(, A)
App t u Term(, B(id
, u))
(hyp)
A Type()
q Term(.A, Ap)
(subs-term)
t Term(, A)
t Term(, A)
.1. The Calculus
(sing-u-i)
A Term(, U) t Term(, A)
{t}
A
Term(, U)
(sing-i)
t Term(, A)
t Term(, {t}
A
)
(sing-el)
a Term(, A) t Term(, {a}
A
)
t Term(, A)
Axioms for the Equational Theory In the following, we present the axioms of
the equational theory of
Sing
. Equality is considered as the congruence closure
of these axioms. Congruence rules, also called derived rules, are generated
mechanically for each symbol from its typing. For instance, rule (subs-type)
induces the derived rule
(subs-cong-ty)
A = B Type() =
A = B Type() .
Another instance of a derived rule is conversion, it holds because of equality
between sorts, such as Term(, A) = Term(, A
):
(conv)
t Term(, A) A = A
Type()
t Term(, A
)
In the following, we present equality axioms without the premises concern-
ing typing, except in the cases where they cannot be inferred.
Substitutions The rst two equations witness extensionality for the identity
substitution, the next three the composition laws for the category of substitu-
tions. Then there is a law for the rst projection p, and the last two laws show
how to propagate a substitution into a tuple.
id
= id
.A
= (p, q)
id = id =
() = ( ) p (, t) =
= (, t) = (, t )
Axioms for and , propagation and resolution of substitutions An explicit
substitution (id
, r) (App (t p) q) = t
U = U ({t}
A
) = {t }
A
(Fun AB) = Fun (A) (B(p, q)) (t) = (t (p, q))
(App r s) = App (r ) (s ) (t ) = t ( )
q (, t) = t t id = t
8 . Extended Martin-Lf Type Theory
Singleton types All inhabitants of a singleton type are equal (sing-eq-i). We
mention the important derived rule (sing-eq-el) here explicitly.
(sing-eq-i)
t, t
Term(, {a}
A
)
t = t
Term(, {a}
A
)
(sing-eq-el)
t = t
Term(, {a}
A
)
t = t
Term(, A)
There is a choice how to express the last two rules; they could be replaced with
(sing-eq-i)
t Term(, {a}
A
)
t = a Term(, {a}
A
)
(sing-eq-el)
t Term(, {a}
A
)
t = a Term(, A)
The rule (sing-eq-el) is essential; in fact, since we have eta-expansion for
singletons, we would like to derive
.{t}
Fun AB
App q a = t (id, a): B(id, a)
from .{t}
Fun AB
q = t: {t}
Fun AB
, and a: A. Which would be im-
possible if (sing-eq-el) were not a rule.
Properties of
Sing
An advantage of introducing the calculus as a GAT is that we can derive several
syntactical results from the meta-theory of GATs; for instance, some of the
following inversion results, which are needed in the proof of completeness of
the type-checking algorithm.
Remark 11 (Weakening of judgements). Let
i
, A = A
, and t =
t
: A; then Ap
i
= A
p
i
, and t p
i
= t
p
i
: Ap
i
.
Remark 1z (Syntactic validity).
1. If t: A, then A.
z. If t = t
: A.
. If A = A
.
Lemma z8 (Inversion of types).
1. If Fun AB, then A, and .A B.
z. If {a}
A
, then A, and a: A.
. If k, then k: U.
The following lemma can be proved directly by induction on derivations
by checking the possibles rules used in the last step.
Lemma zj (Inversion of typing).
1. If Fun A
: A, then A = U, A
: U, and also .A
: U;
z. if {b}
B
: A, then A = U, B: U, and also b: B;
. if t: A, then either
.1. The Calculus j
a) A = Fun A
B with .A
t: B; or
b) A = {a}
A
with t = a: A
.
. if App t r: A, then t: Fun A
, r: A
, and A = B
(id, r
).
Proof. (1) The last rule used is one of (fun-u-i), (conv), (sing-i), or (sing-e).
In the rst case the premises of the rule are what is to be proved; in all other
cases we have a premise with the form Fun A
t, just
compose it with each t
i
that is not a binder (e.g., A in AB), and compose its
lifted version (p, q) with each t
j
that is a binder (e.g., B in AB). Binders are
those formed in an extended context (here, B Type(.A)). In the following,
we will skip the propagation laws.
Natural numbers We add an inductive type Nat with constructors zero and
suc() and primitive recursion natrec.
(nat-u-i)
Ctx
Nat Term(, U)
(nat-z-i)
Ctx
zero Term(, Nat)
(nat-s-i)
t Term(, Nat)
suc(t) Term(, Nat)
(nat-el)
B Type(.Nat)
t Term(, Nat) z Term(, B(id, zero)) s Term(, Rec(B))
natrec(B, z, s, t) Term(, B(id, t))
Here, we used Rec(B) as an abbreviation for Fun Nat (Fun B (B(p, suc(q)) p))
which in conventional notation reads x : Nat. B B[suc(x)/x]. Since B is a
big type, it can mention the universe U, thus, we can dene small types by
recursion via natrec. This so called large elimination excludes normalization
proofs which use induction on type expressions [, 6]. We add the usual
computation laws for primitive recursion.
natrec(B, z, s, zero) = z
natrec(B, z, s, (suc(t))) = App (App s t) (natrec(B, z, s, t))
Enumeration sets The type N
n
has the n canonical inhabitants c
n
0
, . . . , c
n
n1
,
which can be eliminated by the dependent case distinction case
n
B t
0
t
n1
t
with n branches.
(n
n
-u-i)
Ctx
N
n
Term(, U)
(n
n
-i)
Ctx i < n
c
n
i
Term(, N
n
)
(n
n
-e )
B Type(.N
n
) t Term(, N
n
)
t
0
Term(, B(id, c
n
0
)) t
n1
Term(, B(id, c
n
n1
))
case
n
B t
0
t
n1
t Term(, B(id, t))
We add the usual computational law for case distinction, and weak extension-
ality, which for booleans (N
2
) reads if t then true else false = t in sugared
.1. The Calculus 61
syntax.
case
n
B t
0
t
n1
c
n
i
= t
i
case
n
N
n
c
n
0
c
n
n1
t = t
In the sequel we use
t for denoting, in case
n
B t
0
t
n1
r, the n terms
t
0
t
n1
. We will omit superscripts n in c
i
, and in case B
t r.
For N
0
and N
1
we can formulate strong -laws: all their inhabitants are
considered equal, since there is at most one. To realize this, we introduce a new
term in N
0
if it already has an inhabitant t; we consider as normal form of t.
Note that this seemingly paradoxical canonical form N
0
does not threaten
consistency, since it cannot exist in the empty context = ; otherwise there
would have already been a term t Term(, N
0
).
(n
0
-tm)
t Term(, N
0
)
Term(, N
0
)
(n
0
-eq)
t, t
Term(, N
0
)
t = t
Term(, N
0
)
(n
1
-eq)
t, t
Term(, N
1
)
t = t
Term(, N
1
)
On the one hand, rule (n
0
-tm) destroys decidability of type checking: to
check whether Term(, N
0
) we would have to decide the consistency of
which is certainly impossible in a theory with natural numbers. On the
other hand, it allows us to decide equality by computing canonical forms.
We solve this dilemma by forbidding in the user syntax which is input for
the type-checker; is only used internally in the NbE algorithm and in the
canonical forms it produces. Formally this is reected by having two calculi:
one with the rule (n
0
-tm) and one without it. To distinguish the calculi, we
decorate the turnstile (
Term(, [A])
t = t
Term(, [A])
6z . Extended Martin-Lf Type Theory
Note that (prf-tm) is analogous to (n
0
-tm) and the same remarks apply; in
particular, (prf-tm) is also a rule in (
, k) |
case
n
V v
0
v
n1
k | v where
V
k |
Nf v, V ::= . . . | V W | Nat | N
n
| [V] | (v, v
) | zero | suc(v) | c
n
i
| [v]
.1. The Calculus 6
The next lemma can be strengthened by stating that the judgements in the
conclusion of each property corresponds to a sub-derivation of the derivation
in the premise. The importance of the stronger version is that, in proof by
induction on derivations, one can use induction hypotheses in the inverted
judgements.
Lemma o (Inversion of types).
1. If AB, then A, and .A B.
z. If [A], then A.
Lemma 1 (Inversion of typing).
1. If A
B: A, then A = U, and A
: U, and .A
B: U.
z. If Nat : A, then A = U.
. If N
n
: A, then A = U.
. If (t, b): A , then A = A
B, and t: A
, and t: A
B, for some A
, and B.
6. If snd t: B, then B = B
, for some A,
and B
.
. If zero: A, then A = Nat.
8. If suc(t): A, then t: Nat, and A = Nat.
j. If natrec(B, z, s, t): A , then .Nat B, z: B(id, zero),
s: Rec(B), t: Nat, and A = B(id, t).
1o. if c
n
i
: A, then A = N
n
;
11. If case B
t t
: A, then .N
n
B, t
i
: B(id, c
i
), t
: N
n
, and
A = B(id, t).
1z. If [t] : A, then A = [A
] and t
: A
.
1. If bwhere
B
t: A, then A = B, t: [A
] for some A
, .A
b: Bp,
and .A
.A
).
Denition z. A term is called pure if it does not contain any occurrence of .
Let be a syntactical entity, if is obtained from by replacing all occurrences
of by pure terms, then is called a lifting of .
We will distinguish those liftings that are judgmentally equal to the lifted
entity, these liftings are called good liftings.
Denition z (Good lifting).
6 . Extended Martin-Lf Type Theory
1. A context
is a good lifting of
if
.
z. A substitution
is a good lifting of
: if
and
are good liftings of
and
, resp., and
: .
. A type A
is a good lifting of
A if
is a good lifting of
and A
A = A
.
. A term t
: A
is a good lifting of
t : A if
is a good lifting
of
A and t
t = t
: A.
Now we can prove that there is a good lifting for each syntactic entity; for
proving this, we need the stronger condition that any pair of good liftings for
some entity are judgmentally equal.
Theorem z.
1. Let
of
; moreover if
is also
a good lifting of
then
.
z. Let
of
: ;
moreover if
: then
, and
.
. Let
of
A ; moreover if
A then
and
= A
.
. Let
: A
of
t : A
; moreover if
: A
t : A then
= A
, and
= t
: A
.
Proof. By induction on derivations, in each rule we use i.h., and build up the
corresponding entity to the good lifting for each part of the judgement; then,
given any other good lifting of the whole judgement, we do inversion on the
denition of good lifting, and get the equalities for each part; we nish using
congruence for showing that both good lifting are judgmental equal.
We show the case for (prf-tm). First we prove the existence of a good lifting.
t : A by inversion on (*) ()
: A
[t
] : [A
[A]
= [A
] by ind. hyp.
[t
] = s: [A
R, F a = F a
) | f a = f
F a, for all a = a
X};
z. { {a} }
X
= {(b, b
) | a = b X and a = b
X}.
Besides interpreting function spaces and singletons we need PERs for the
denotation of the universe of small types, and for the set of large types; jointly
with these PERs we need functions assigning a PER for each element in the
domain of these universe PERs. Note that this forces the applicative structure
to have some distinguished elements.
Denition z6 (Universe). Given an applicative structure A with distinguished
elements Fun and Sing, a universe (U, [_]) is a PER U over A and a family
[_] : U Per(A) with the condition that U is closed under function and
singleton types. This means:
1. Whenever X = X
[X], F a = F
U, then
Fun XF = Fun X
[X] (a [F a]).
z. Whenever X = X
U and a = a
U
and [Sing a X] = { {a} }
[X]
.
An applicative structure paired with one universe for small types and one
universe for large types is the minimal structure needed for having a model of
our theory.
Denition z (PER model). Let A be an applicative structure with distinguished
elements U, Fun, and Sing; a PER model is a tuple (A, U, T, [_]) satisfying:
1. U T PER(A), such that (T, [_]) and (U, [_]
U
) are both universes, and
z. U dom(T), with [U] = U.
In the following denition we introduce an abstract concept for environ-
ments: since variables are represented as projection functions from lists (think
of q as taking the head of a list, and p as taking the tail), it is enough having
sequences together with projections.
Denition z8 (Sequences). Given a set A, a set A
, Pair : A
A A
, fst : A
, and
snd : A
A such that
fst (Pair ab) = a snd (Pair ab) = b .
Now we need to extend the notion of PERs over A to PERs over A
for
interpreting substitutions.
Denition zj. Let A be an applicative structure and let A
) and F X PER(A).
1. 1 = {(, )};
z.
XF = {(a, a
) | fst a = fst a
F (fst a)};
Until here we have introduced semantic concepts. Now we are going to
axiomatise the notion of evaluation, connecting the syntactic realm with the
semantic one.
.z. Semantics 6
Denition o (Environment model). Let (A, U, T, [_]) be a PER model and let
A
, ,
s
) an environment
model if the evaluation functions __: Terms A
A and _
s
_: Terms A
satisfy:
Ua = U
Fun ABa = Fun (Aa) F
where F b = B(Pair a b)
{t}
A
a = Sing (ta) (Aa)
t a = t(
s
a)
ta = f , where f b = t(Pair a b)
App t ua = (ta) (ua)
qa = snd a
id
s
a = a
s
a =
s
a =
s
(
s
a)
(, t)
s
a = Pair (
s
a) (ta)
p
s
a = fst a
Since no ambiguities arise, we shall henceforth write instead of
s
.
Once we have an environment model M we can dene the denotation for
contexts. The second clause in the next denition is not well-dened a priori;
its totality is a corollary of Thm. contrast this approach with the one in
the previous chapter, where we dened simultaneously the notion of validity
with the semantics of contexts.
Denition 1. Given an environment model M, we dene recursively the
semantic of contexts _: Ctx PER(A
):
1. = 1,
z. .A =
(a [Aa]) .
We use PERs for validating equality judgements and the domain of each
PER for validating typing judgements.
Denition z (Validity). Let M be an environment model. We dene inductively
the predicate of satisfability of judgements by the model, denoted with
M
J:
1. i true
z. .A i A
. A i A = A
. A = A
, Ad = A
T
. t : A i t = t : A
6. t = t
, td = t
[Ad]
. : i = :
8. =
, d =
.
Theorem (Soundness). Let M be a model. If J, then
M
J.
Proof. By easy induction on J.
68 . Extended Martin-Lf Type Theory
A concrete PER model
In this subsection we dene a concrete PER model over a Scott domain which
extends that of Def. 1.
Denition . In this section the domain used comes fromthe following domain
equation:
D OVar
[D D] (DD)(DD)O(D[D D])(DD) .
When comparing with the domain of the previous chapter, the only new
possible shape for an element of D which is not is Sing d d
for d, d
D; so,
we have the following forms for elements that are not :
(d, d
) for d, d
D
Var i U for i Var
lamf Fun d f for d D, and f [D D]
App dd
Sing d d
for d, d
D.
In order to dene an environment model over D, we endow it with an
applicative structure. Note also that D has pairing, letting us to take the
set of sequences over D simply as D
f e if d = lamf
otherwise
p d =
d
1
if d = (d
1
, d
2
)
otherwise
q d =
d
2
if d = (d
1
, d
2
)
otherwise
The denition of the readback function is dened just as before; the only
new case with respect to Def. 1 is Sing d d
) = App (R
j
d) (R
j
d
)
R
j
(lamf) = (R
j+1
(f(Var j)))
R
j
(Var i) =
q if j i +1
q p
j(i+1)
if j > i +1
As in Sec. z. our PER model is based on the notions of semantical normal
forms and neutral values.
Denition (Semantical neutrals and normal forms).
d = e Ne if, for all i N, R
i
d and R
i
e are both dened, R
i
d R
i
e,
and R
i
d Ne.
.z. Semantics 6j
d = e Nf if, for all i N, R
i
d and R
i
e are both dened, R
i
d R
i
e,
and R
i
d Nf.
Lemma (Closure properties of Ne and Nf).
1. U = U Nf.
z. Let X = X
Ne. If F k = F
Nf for all k = k
Ne, then
Fun X F = Fun X
Nf.
. If d = d
Nf and X = X
Nf.
. If f k = f
Nf for all k = k
Ne, then f = f
Nf.
. Var i = Var i Ne for all i N.
6. If k = k
Ne and d = d
Ne.
We dene U, T PER(D) and [_] : domT PER(D) using Dybjers schema
of inductive-recursive denition [z]. We show then that [_] is a family of PERs
over D.
Denition 6 (PER model).
1. Inductive denition of U PER(D).
a) Ne U,
b) if X = X
U and d = d
U,
c) if X = X
[X], F d = F
U then
Fun X F = Fun X
U.
z. Inductive denition of T PER(D).
a) U T,
b) U = U T,
c) if X = X
T, and d = d
T,
d) if X = X
[X], F d = F
T, then
Fun X F = Fun X
T.
. Recursive denition of [_] dom(T) PER(D).
a) [U] = U,
b) [Sing d X] = { {d} }
[X]
,
c) [Fun X F] =
[X] (d [F d]),
d) [d] = Ne, in all other cases.
Remark 1. The generation order on T is well-founded. The minimal ele-
ments are U, and elements in Ne; X Fun X F, and for all d [X], F d Fun X F;
and, nally, X Sing d X.
Lemma 6. The function [_] : dom(T) PER(D) is a family of PER(D) over T,
i.e., [_] : T PER(D).
o . Extended Martin-Lf Type Theory
Proof. By induction on X = X
T.
[X] = [X
] by ind. hyp.
d = d
= d [X] hypothesis
e = d
[X] and e
= d
[X] by transitivity
{ {d} }
X
= { {d
} }
X
by denition.
z. Let Fun X F = Fun X
T.
[X] = [X
] by ind. hyp.
for all d dom([X]), F d = F
d T by denition (*)
for all d = d
[X], f d = f
[F d] hypothesis
f d = f
[F
Fun X F
k = lam(d
F d
(App k
X
d))
Fun X F
d = lam(e
F
X
e
(d
X
e))
Sing d X
k = d
U
k = k
X
k = k, in all other cases.
Sing d X
e =
X
d
U
d = d
X
e = e, in all other cases.
(Fun X F) = Fun (X) (d (F
X
d))
(Sing d X) = Sing (
X
d) (X)
U = U
X = X, in all other cases.
.z. Semantics 1
In the following lemma we show that reection corresponds to Berger
and Schwichtenbergs make self evaluating and both reication functions
and correspond toinverse of the evaluation function [z6]. Note that they
are indexed by types values instead of syntactic types, since we are dealing
with dependent instead of simple types.
Lemma 8 (Characterisation of , , and ). Let X = X
T, then
1. if k = k
Ne then
X
k =
X
k
[X];
z. if d = d
[X], then
X
d =
X
d
Nf;
. and also X = X
Nf.
Proof. By induction on X = X
T.
1. Case Sing d X = Sing d
T.
a) The partial function
_
_ maps neutrals to related elements in the
corresponding PER.
k = k Ne hypothesis
d = d
[X] and X = X
T by inversion
Sing d X
k = d and
Sing d
X
k
= d
by def.
d = d
{ {d} }
X
by def. of this PER.
b) The partial function
_
_ maps related elements to related normal
forms.
d
1
= d
2
{ {d} }
X
hypothesis
d
1
= d
2
= d = d
[X] and X = X
T by inversion
X
d =
X
d
Nf by ind. hyp.
Sing d X
d
1
=
Sing d
X
d
2
Nf by def.
c) The function _ maps related elements in T to normal forms.
Sing d X = Sing (
X
d) (X) by def.
Sing d
= Sing (
X
d
) (X
) by def.
X
d =
X
d
Nf by ind. hyp.
X = X
Nf by ind. hyp.
Sing (
X
d) (X) = Sing (
X
d) (X) Nf by Lem. .
z. Case Fun X F = Fun X
T.
z . Extended Martin-Lf Type Theory
a) The partial function
_
_ maps neutrals to related elements in the
corresponding PER.
k = k
Ne hypothesis
d = d
T by inversion ()
F d = F
T by inversion (**)
X
d =
X
d
(
X
d
) Ne by Lem. ()
F d
(App k (
X
d)) =
d
(App k
(
X
d
Fun X F
k =
Fun X
F
k
[Fun X F] by def.
b) The partial function
_
_ maps related elements to related normal
forms.
X = X
T by inversion (*)
f = f
[Fun X F] hypothesis
k = k
Ne hypothesis
X
k =
X
k
:=
X
k
abbreviation
F d = F
[F d] denition of [Fun X F] ()
F d
(f d) =
F
d
(f
) Nf by ind. hyp. on ()
(
Fun X F
f) k =
(
Fun X
F
f
) k
Nf by def.
Fun X F
f =
Fun X
F
f
Nf by Lem.
c) The function _ maps related elements in T to normal forms.
X = X
T by inversion (*)
X = X
Ne hypothesis.
X
k =
X
k
:=
X
k
abbr.
F d = F
T by inversion and () ()
(F d) = (F
) Nf by ind. hyp. on ()
(Fun X F) = (Fun X
) Nf by Lem.
.z. Semantics
Let us recapitulate what we have achieved: we have dened a PER model
over the domain D; then we dened a family of functions
X
indexed over
denotation of types with the property that when applied to elements in the
corresponding PER we get back elements which will be reied as normal forms.
In fact, we have the stronger result that whenever we apply
X
to two related
elements d = d
t(d, d
))
App t ud = (td) (ud)
qd = snd d
idd = d
d =
d = (d)
(, t)d = (d, td)
pd = fst d
Theorem j (Completeness of NbE). Let t = t
Ad
(td) =
Ad
(t
d) Nf.
Proof. By Thm. and Lem. 8.
Calculus
Irr
with proof irrelevance
We extend all the denitions concerning the construction of the model.
Denition j (Extension of domain D).
D = . . . D[D D] DD
OOD[D D] D[D [D D]] D
DON N N N [D D] D
D .
In the last summand D
) for d, d
D, F [D D], g [D [D D]]
Case
n
(F,
d, d
) for d, d
D, F [D D],
d D
, n N .
. Extended Martin-Lf Type Theory
In this extension, the injections Fst, Snd, Natrec, and Case construct neutral
elements k. Soundness for the calculus (
and q
d =
d
1
if d = (d
1
, d
2
)
if d =
Proj
1
(d) otherwise
q
d =
d
2
if d = (d
1
, d
2
)
if d =
Proj
2
(d) otherwise
Denition o (Readback function).
R
j
Nat = Nat
R
j
zero = zero
R
j
(suc d) = suc((R
j
d))
R
j
(Prf d) = [(R
j
d)]
R
j
(N
n
) = N
n
R
j
(d, d
) = (R
j
d, R
j
d
)
R
j
(Proj
1
(d)) = fst (R
j
d)
R
j
(Proj
2
(d)) = snd (R
j
d)
R
j
=
R
j
(c
n
i
) = c
n
i
R
j
(Sum(X, F)) = (R
j
X) (R
j+1
(F Var j))
R
j
(Natrec(F, d, f, e)) = natrec((R
j+1
(F Var j)), (R
j
d), (R
j
f), (R
j
e))
R
j
(Case
n
(F, d
0
, . . . , d
n1
, e)) = case
n
(R
j+1
(F Var j)) (R
j
d
0
)
(R
j
d
n1
) (R
j
e)
We dene inductively new PERs for interpreting naturals and nite types.
Note that C
0
and C
1
are irrelevant, in this way we can model -expansion for
N
0
and N
1
; |X| is also irrelevant, even when X distinguishes its elements.
Denition 1 (More semantic types).
1. N is the smallest PER over D, such that
a) Ne N
b) zero = zero N
c) suc d = suc d
N, if d = d
N
z. If X PER(D) then |X| := {(d, d
) | d, d
) | d, d
{, c
1
0
}},
. C
n
= {(c
n
i
, c
n
i
) | i < n} Ne, for n 2.
We add new clauses in the denitions of the partial equivalences for uni-
verse and types, these clauses do not aect the well-foundedness of the order
dened in Rem. 1, but now we have that N
n
and Nat are also minimal
elements for that order.
.z. Semantics
Denition z (Extension of U and T).
1. Inductive denition of U PER(D).
a) If X = X
[X], F d = F
U, then
Sum(X, F) = Sum(X
, F
) U.
b) Nat = Nat U,
c) N
n
= N
n
U,
d) if X = X
U.
z. Inductive denition of T PER(D).
a) If X = X
[X], F d = F
T, then
Sum(X, F) = Sum(X
, F
) T.
b) if X = X
T.
. Recursive denition of [_] dom(T) PER(D).
a) [Sum(X, F)] =
[X] (d [F d]),
b) [N
n
] = C
n
c) [Nat] = N,
d) if X domT, then [Prf X] = {(, )}.
Note that in the PER model, all propositions Prf X are inhabited. In fact, all
types are inhabited, for there is a reection from variables into any type, be it
empty or not. So, the PER model is unsuited for refuting propositions. How-
ever, the logical relation we dene in the next section will only be inhabited
for non-empty types.
Remark 1. It can be proved by induction on X T that [X].
Denition (Reection and reication, cf. ).
Sum(X,F)
k = (
X
Fst k,
F (
X
Fst k)
Snd k)
Sum(X,F)
d = (
X
p
d,
F (p
d)
q
d)
Nat
k = k
N
0
k =
N
1
k = c
1
0
N
n
k = k for n 2
Prf X
k =
Nat
d = d
N
0
d =
N
1
d = c
1
0
N
n
d = d
Prf X
d =
Sum(X, F) = Sum((X), (d (F
X
d))) Nat = Nat
N
n
= N
n
Prf X = Prf (X)
To give semantics to eliminators for data types we dene partial functions
natrec : [D D] DDD D, and case : [D D] DDD D.
Denition (Eliminations on D).
6 . Extended Martin-Lf Type Theory
1. Elimination operator for naturals.
natrec(F, d, f, ) =
natrec(F, d, f, zero) = d
natrec(F, d, f, suc e) = (f e) natrec(F, d, f, e)
natrec(F, d, f, k) =
F k
(Natrec(d
F d
F zero
d,
lamd
(lame
F (suc d
)
f d
),
k))
z. Elimination operator for nite types.
case
n
(F, d
0
, . . . , d
n1
, ) =
case
n
(F, d
0
, . . . , d
n1
, c
n
i
) = d
i
case
n
(F, c
n
0
, . . . , c
n
n1
, d) = d
case
n
(F, d
0
, . . . , d
n1
, k) =
F k
(Case
n
(e F e,
F c
n
0
d
0
, . . . ,
F c
n
n1
d
n1
, k))
Remark 16. If for all d = d
N, F d = F
T, and z = z
[F zero], and
for all d = d
N and e = e
[F d], s d e = s
) [F d].
With these new denitions we can now give the semantic equations for the
new constructs.
Denition (Extension of interpretation).
ABd = Sum((Ad), (d
B(d, d
)))
Natd = Nat
fst td = p
td
(t, t
)d = (td, t
d)
suc(t)d = suc td
[a]d =
bwhere
B
td = b(d, )
N
n
d = N
n
[A]d = Prf Ad
snd td = q
td
zerod = zero
d =
c
n
i
d = c
n
i
natrec(B, z, s, t)d = natrec(e B(d, e), zd, sd, td)
case
n
B t
0
t
n1
td = case
n
(e B(d, e), t
0
d, . . . , t
n1
d, td)
Lemma o (Laws of proof elimination). , , and associativity for where are
modeled by the extended applicative structure.
Proof. The proofs of soundness for (prf-) and (prf-) have the same structure,
so we show only the rst one.
.z. Semantics
(prf-) bwhere
B
[a] = b(id, a)
bwhere
B
[a]d
= b(d, ) def. of semantics for bwhere
B
[a]
= b(d, ad) ind. hypothesis on .A.Ap bp = b(p p, q): Bp p
= b((id, a)d) def. of semantics for substitutions
= b(id, a)d
(prf-assoc) awhere
A
(bwhere
B
c) = (a(p p, q) where
Ap
b) where
B
c
awhere
A
(bwhere
B
c)d = a(d, )
= a(d, b(d, ))
= a(p p, q)((d, ), b(d, ))
= a(p p, q) where
Ap
b)(d, )
= (a(p p, q) where
Ap
b) where
B
cd
Theorem 1. All of lemmata 6, 8, and theorems , and j are valid for the
extended calculus.
Note that we have dened a proof-irrelevant semantics for (
) that collapses
all elements of [A] to , which leads to a more ecient implementation of the
normalisation function. However, this semantics is not sound if
Irr
is extended
with singleton types interpreted analogously to C
1
, i.e., [Sing d X] = |{ {d} }
X
|,
because it does not model (sing-eq-el). (We have d = [Sing d X] for all
d [X], but not necessarily d = [X].) On the other hand,
Irr
without can
be extended to singleton types as explained in the following remark.
Remark 1 (Extending
Irr
by singleton types). Singleton types can be added
straightforwardly if we employ a proof-relevant semantics: the domain D is not
changed; in particular we have D, and it is readback as before, R
j
= ;
hence dom(Nf).
Enumerated types are modelled in a uniform way: [N
n
] = {(c
n
i
, c
n
i
) | i <
n} Ne; proof-irrelevance types [A] are interpreted as the irrelevant PER with
the same domain as the PER for A: [Prf X] = {(d, d
) | d, d
dom([X])}.
Reection and reication for Prf X are dened respectively as
Prf X
d =
X
d and
Prf X
d = .
With these denitions it is clear that the corresponding result for Lem. 8 is
still valid.
Since dom[Prf X] = dom[X], introduction and elimination of proofs can be
interpreted as follows
[a]d = ad and bwhere
B
td = b(d, td) ;
8 . Extended Martin-Lf Type Theory
this model is sound with respect to the calculus () extended with singleton
types; hence Thm. j is valid.
Remark 18. As was previously said we cannot use this PER model for proving
that there is no closed term in N
0
. Instead, one can build up a PER model, in
the sense of .z, of closed values, where [N
0
] = . By soundness (Thm. ) it
follows that there is no possible derivation of t: N
0
.
. Correctness of NbE
As in previous chapters we use logical relations to prove correctness of NbE.
The section is similar to Sec. .: as a corollary of the fundamental theorem
(Thm. 6) we show that a term is related to its denotation with respect to
some canonical environment; previously we prove, in Lem. , that if a term
is logically related with some semantic element, then its reication will be
judgmentally equal to the term. Composing these facts we obtain correctness.
As a consequence of having correctness and completeness for NbE, one gets
decidability for judgmentally equality: normalise both terms and check they
are syntactically the same.
Logical relations
Denition 6 (Logical relations). We dene simultaneously two families of
binary relations:
1. If then ( _ _ T) {A | A} T shall be a -indexed family
of relations between well-formed syntactic types A and type values X.
z. If A X T then ( _ : A _ [X]) {t | t: A} [X] shall
be a (, A, X)-indexed family of relations between terms t of type A and
values d in PER [X].
These relations are dened simultaneously by induction on X T.
1. Neutral types: X Ne.
a) A X T i for all
i
, Ap
i
= R
||
X.
b) t: A d [X] i A X T, and for all
i
, t p
i
=
R
||
X
d: Ap
i
.
z. Universe.
a) A U T i A = U.
b) t: A X [U] i A = U, and t X T.
. Singletons.
a) A Sing d X T i A = {a}
A
and a: A
d [X].
b) t: A d
[Sing d X] i A = {a}
A
and t: A
d [X],
and A
X T.
. Function spaces.
.. Correctness of NbE j
a) A Fun X F T i A = Fun A
B, and A
X T, and
B(p
i
, s) F d T for all
i
and s: A
p
i
d [X].
b) t: A f [Fun X F] i A = Fun A
B, A
X, and
App (t p
i
) s: B(p
i
, s) f d [F d] for all
i
and
s: A
p
i
d [X].
Calculus
Irr
with proof irrelevance We present next the denition of logical
relations for
Irr
; then we prove the technical results about logical relations for
both calculi.
Denition .
1. Sigma types.
a) A Sum(X, F) i A = A
and A
p
i
d [X], B
(p
i
, s) F d.
b) t: A d [Sum(X, F)] i A = A
and fst t: A
(id
, fst t) q
d [F (p
d)].
z. Natural numbers.
a) A Nat i A = Nat.
b) t: A d [Nat] i A Nat and for all
i
, t p
i
=
R
||
d: Nat.
. Finite types.
a) A N
n
i A = N
n
.
b) t: A d [N
n
] i A N
n
and for all
i
, t p
i
=
R
||
d: N
n
.
. Proof-irrelevance types.
a) A Prf X T i A = [A
] and A
X T.
b) t: A d [Prf X] i A Prf X.
Technical results
The following technical lemmata show that the logical relations are preserved
by judgmental equality, weakening of the judgement, and the equalities on the
corresponding PERs. These lemmata are proved simultaneously for types and
terms.
Lemma z (Closure under conversion). Let A X T and A = A
.
Then,
1. A
X T, and
z. if t: A d [X] and t = t
: A then t
: A
d [X].
Proof. By induction on X T.
1. Types; in all cases we use symmetry and transitivity to show the condi-
tions. We only show the case for Fun X F.
8o . Extended Martin-Lf Type Theory
a) X = Fun X
F:
A = Fun BC by denition (*)
B X
by denition
C(p
i
, s) F d T for all
i
by denition
and s: Bp
i
d [X
]
A
: A hypothesis ()
t p
i
= R
i
d: Ap
i
by inversion on (*) (**)
t p
i
= t
p
i
: Ap
i
by congruence on () ()
t
p
i
= R
i
d: Ap
i
by sym. and trans. on (**) and ()
z. Terms. As in the case for types, we use symmetry and transitivity. We
show only the case for singletons and functions.
a) X = Sing d X
:
A = {b}
B
by hypothesis (*)
B X
T by hypothesis
t: B d [X
] by hypothesis ()
A
= {b}
B
by sym. and trans. on (*)
t
: B d [X
] By i.h. on ()
b) X = Fun X
F:
A = Fun BC by hypothesis (*)
B X
by hypothesis
App t p
i
s: C(p
i
, s) f d [F d] by hypothesis
for all
i
, s: Bp
i
d [X
]
A
p
i
s: C(p
i
, s) by congruence on () ()
App t
p
i
s: C(p
i
, s) f d [F d] by i.h. on ()
Lemma (Monotonicity). Let
i
, then
1. if A X T, then Ap
i
X T; and
z. if t: A d [X], then t p
i
: Ap
i
d [X].
.. Correctness of NbE 81
Proof. By induction on X T. This property is trivial for the base cases; for
singletons is obtained by applying the i.h. We show two cases.
1. Let X = Fun X
F.
A = Fun BC by hypothesis (*)
B X
()
C(p
i
, s) F d T by hypothesis
for all
i
, s: Bp
i
d [X
]
Ap
i
= Fun (Bp
i
) (C(p
i
p, q)) by congruence on (*)
Bp
i
X by i.h. on ()
s: (Bp
i
) p
j
d [X], with
j
hypothesis
s: Bp
i+j
d [X] by rem. 11 and z ()
C(p
i+j
q, s) F d by hyp. using ()
C(p
i
p, q) (p
j
, s) F d By congruence and z
z. Prf X T. As mentioned earlier if A Prf X T then _: A _
[Prf X] is non-empty if and only if _: A is not empty.
t: A d [Prf X] hypothesis (*)
t: A by inversion on (*) ()
A Prf X T by inversion on (*) (**)
t p
i
: Ap
i
by weakening on ()
Ap
i
Prf X T by monotonicity for types on (**)
t p
i
: Ap
i
d [Prf X] by denition of log. rel.
We do not show proofs for the second part, since the most involved case is
dealt analogously to the case for Fun X
F.
Lemma (Closure under PERs). Let A X T, then
1. if X = X
T, then A X
T; and
z. if t: A d [X] and d = d
[X], then t: A d
[X].
Proof. By induction on X = X
.
A = {b}
B
by hypothesis (*)
B X T by hypothesis
t: B d [X] by hypothesis ()
t: B d
[X
.
A = Fun BC by hypothesis
B X
by hypothesis (*)
C(p
i
, s) F d T by hypothesis ()
for all
i
, s: Bp
i
d [X
]
B X
T By i.h. on (*)
B(p
i
, s) F
d T by i.h. on ()
z. Terms.
a) e = e
[Sing d X].
A = {b}
B
by hypothesis
B X T by hypothesis (*)
t: B d [X] by hypothesis ()
e
= d [X] by def. of e = e
[Sing d X] (**)
t: B e
[Fun X F].
A = Fun BC
B X (*)
App t p
i
s: C(p
i
, s) f d [F d] ()
for all
i
and s: Bp
i
d [X] . (**)
By i.h. on (*) and (**) and monotonicity
s: A
p
i
d
[X
] .
By i.h. on ()
App (t p
i
) s: B(p
i
, s) f
[F d
] .
c) d = d
[Sum(X, F)].
d = d
B by inversion on (**)
A
d [F p
d] by inversion on (**) ()
p
d = p
d = q
[F p
d] by denition of (*) ()
fst t: A
[F p
X
k [X].
Proof. By induction on X T. By induction on X T. For a better organisation
of the proof we show the proofs for each point separately.
1. A = R
||
X. We skip the part for the minimal elements in T.
a) Sing d X:
A
= R
||
X by ind. hyp.
t = R
||
X
d: A
by ind. hyp.
{a}
A
= {R
||
X
d}
R
||
X
by congruence and transitivity
b) Fun X F:
A
= R
||
X by ind. hyp.
B(p
i
, s) = R
||
(F d) (*)
for any
i
, s: A
p
i
d [X]
.A
q: A
p
X
(Var ||) by ind. hyp. ()
.A
B(p, q) =
R
|.A
|
((F (
X
(Var ||))) instantiating (*) on ()
.A
B = R
|.A
|
(F (
X
(Var ||))) by Lem. z.
z. t = R
||
X
d: A. We skip the part for the minimal elements in T.
a) d
[Sing d X]:
A = {b}
B
(*)
B X T
t: B d [X] ()
t = R
||
X
d: B by ind. hyp. in ()
t = R
||
X
d: {t}
B
by conversion and (sing-eq-i)
t = R
||
X
d: A by conversion
8 . Extended Martin-Lf Type Theory
b) f [Fun X F]:
.A
q: A
p
X
Var || [X] by ind. hyp. on the third part
d :=
X
Var || abbreviation
.A
App (t p) q: B(p, q)
f d [F d] by def. of the logical relation
.A
App (t p) q
R
|.A|
F d
f d: B(p, q) by ind. hyp.
.A
App (t p) q =
R
|.A|
F d
f d: B by (conv)
(App (t p) q) =
(R
|.A|
F d
f d): Fun A
B by congruence
t = (App (t p) q): Fun A
B by (eta)
t = R
||
Fun X F
f: Fun A
B by trans.
.
a) Sing d X:
A = {a}
B
by hypothesis
B X T by hypothesis
t: B d [X] by hypothesis
B X T by monotonicity
t p
i
: Bp
i
d [X] by monotonicity
Ap
i
= {ap
i
}
Bp
i by congruence
b) Fun X F:
s: A
p
i
d
: A
p
i
by ind. hyp. on (*)
App (t p
i
) s =
App ((R
||
d) p
i
) (R
||
(
X
d
)): B(p
i
, s) by congruence
R
||
Appd
X
d
=
App ((R
||
d) p
i
) (R
||
(
X
d
)) by denition
App (t p
i
) s: B(p
i
, s)
F d
App d
X
d
[F d
] by ind. hyp.
In order to nish the proof of soundness we have to prove that each well-
typed term (and each well-formed type) is logically related to its denotation;
with that aim we extend the denition of logical relations to substitutions and
prove the fundamental theorem of logical relations.
Denition 8 (Logical relation for substitutions).
.. Correctness of NbE 8
1. : d 1 always holds.
z. (, t): .A (d, d
)
X(d [F d]) i : d X,
A F d T, and t: A d
[F d].
By the way this relation is dened, the counterparts of z, , and are
easily proved by induction on the co-domain of the substitutions.
Remark 1j. If = : , and : d X, then : d X.
Remark zo. If : d X, then for any
i
, p
i
: d X.
Remark z1. If : d X, and d = d
X, then : d
X.
Theorem 6 (Fundamental theorem of logical relations). Let : d .
1. If A, then A Ad T;
z. if t: A, then t : A td [Ad]; and
. if : then : d .
Proof. We note that for terms we show only the cases when the last rule used
was the introductory rule, or the rule for introducing elements in singletons;
for the case of the conversion rule, we can conclude by i.h., and lemma z.
1. Types. We show only the case for (fun-f).
s: A
p
i
e [X] hypothesis (*)
p
i
: d By Lem. zo ()
( p
i
, s): .A (d, e) .A From (*) and ()
B( p
i
, s) B(d, e) T by ind. hyp. on .A B
and usingz and
z. Terms. We show the case for application (fun-el) and for (n
n
-e). The case
for abstraction (fun-i) is analogous to (fun-f).
a) (fun-el)
App t r: B(id, r) hypothesis
r : A rd [Ad] by ind. hyp. (*)
t : Fun AB td [Fun ABd] by ind. hyp. ()
App (t ) (r ): B(id, r ) by def. of log. rel.
td rd [B(d, rd)] for () with (*)
(App t r) : B(id, r )
App t rd [B(d, rd)] by Lem. z and Lem.
86 . Extended Martin-Lf Type Theory
b) (n
n
-e)
case
B
t
0
t
n1
t : B(id, t) hypothesis
t : N
n
td [N
n
] by inversion and i.h.
t = R
||
td: N
n
by Lem.
t
i
: B(, c
i
)
t
i
d [B(d, td)] by inversion and i.h.
If R
||
td c
i
:
(case B t
0
t
n1
c
i
) = t
i
: B(id, t) by subst.
(case B t
0
t
n1
c
i
) : B(id, t)
case
B
t
0
t
n1
t d [B(id, t)d] by Lem. z and
If R
||
td Ne:
.N
n
B( p, q) = R
||+1
B(d, Var ||)
t
i
= R
||
t
i
d: B(, c
i
) by Lem.
t
i
:= R
||
t
i
d abbreviation
t
:= R
||
B(d,c
i
)
td abbreviation
B
:= R
||+1
B(d, Var ||) abbreviation
e := case B
0
t
n1
t
abbreviation
(case B t
0
t
n1
t) =
e : B(, t) congruence
(case B t
0
t
n1
t) : B(, t)
B(d,td)
e B(d, td) by Lem. and
(case B t
0
t
n1
c
i
) : B(id, t)
case
B
t
0
t
n1
t d [B(id, t)d] by Lem. z and
. Substitutions. Only the proof for (ext-subs) is shown.
.A: (, t) hypothesis
: d by ind. hyp. (*)
t : (A) td [Ad] ()
(d, td)
by induction on as
follows:
.A
= (d
,
Ad
Var n) where n = ||, and d
.
.. Correctness of NbE 8
By an immediate induction on contexts we can check the following.
Lemma . If then id
.
Proof. By induction on ; we show only the inductive case. Let .A .
d :=
denition
id : d by inversion and i.h. (*)
.A id p: d from (*) by Rem. zo ()
.A p: d from () by Rem. 1j (**)
.A Ap Ad T by inversion and Thm. 6
.A q: Ap AdVar n [Ad] by Thm. 6
.A (p, q): .A
(d, AdVar n)
(e [Ae]) by Def. 8 ()
.A id : .A
.A
.A from () by Rem. 1j
Main results
Now we can dene concretely the normalisation function as the composi-
tion of reication with normalisation after evaluation under the canonical
environment. The following corollaries just instantiate previous lemmata and
theorems concluding correctness of NbE.
Denition o (Normalisation algorithm). Let A, and t: A.
nbe
(A) = R
||
A
nbe
A
(t) = R
||
A
T; and
z. t: A t
[A
],
Corollary j (Soundness of NbE). By way of Lem. , it follows immediately
1. A = nbe(A), and
z. t = nbe(t): A.
We have now a decision procedure for judgmental equality; for deciding
t = t
: A, put both terms in normal formal and check if they are syntactically
equal.
Corollary o. If A, and A
. Also if
t: A, and t
: A, we can decide t = t
: A.
88 . Extended Martin-Lf Type Theory
As a byproduct we can conclude that type constructors are injective; this
result is exploited in the next section where we introduce the type-checking
algorithm.
Remark zz. By expanding denitions, we easily check
1. nbe
(A)) (nbe
.A
(B)), and
z. nbe
({a}
A
) = {nbe
A
(a)}
nbe
(A)
.
Corollary 1 (Injectivity of Fun _ _ and of {_}
_
). If Fun AB = Fun A
, then
A = A
, and .A B = B
. Also {t}
A
= {t
}
A
, then A = A
, and
t = t
: A.
Main results for
Irr
The normalisation function is an homomorphism also for
constructors of
Irr
. Moreover, the type-constructor for dependent sums is also
injective.
Remark z.
1. nbe
(AB) = nbe
(A) nbe
.A
(B);
z. nbe
AB
(t), nbe
B(id,t)
(b));
. nbe(suc(t)) = suc(nbe(t)).
. nbe([A]) = [nbe(A)].
Corollary z. If AB = A
, then A = A
, and .A B = B
.
. Type-checking algorithm
In this section, we dene a couple of judgements that represent a bidirectional
type checking algorithm for terms in normal form; its implementation in
Haskell can be found in the appendix. The algorithm is similar to previous
ones [, ], in that it proceeds by analysing the possible types for each normal
form, and succeeds only if the types shape matches the one required by the
introduction rule of the term. The only dierence is introduced by the presence
of singleton types; now we should take into account that a normal form can
also have a singleton as its type.
This situation can be dealt in two possible ways; either one checks that
the deepest tag of the normalised type (see Def. z) has the form of the type
of the introductory rule; or one adds a rule for checking any term against
singleton types. The rst approach requires to have more rules (this is due to
the combination of singletons and a universe). We take the second approach,
which requires to compute the eta-long normal form of the type before type-
checking. We also note that the proof of completeness is more involved, because
now the algorithm is not only driven by the term being checked, but also by
the type.
Our algorithm depends on having a good normalisation function; note that
this function does not need to be based on normalisation by evaluation. Also
note that the second point asks for having correctness and completeness of the
normalisation function.
.. Type-checking algorithm 8j
Denition 1 (Good normalisation function).
1. nbe({a}
A
) = {nbe(a)}
nbe(A)
, and nbe(Fun AB) = Fun nbe(A)nbe(B) ;
z. nbe
(A) = nbe
(t) = nbe
A
(t
),
if and only if t = t
: A.
From these properties we can prove the injectivity of Fun which is crucial
for completeness of type checking -abstractions.
Type-checking
Sing
In this section, let V, V
, W, v, v
W if V {w}
W
V otherwise.
The predicates for type-checking are dened mutually inductively, together
with the function for inferring types.
Denition (Type-checking and type-inference). We dene three mutually
inductive algorithmic judgements
V in context , normal type V checks
v V in context , normal term v checks against type V
k V in context , the type of neutral term k is inferred as V.
All three judgements presuppose and maintain the invariant the input is a
well-formed context. The procedures V and v V expect their inputs
V and v in -normal form. Inference k V expects a neutral term k and
returns its principal type V in long normal form.
Well-formedness checking of types V.
U
V .V W
Fun V W
V v nbe(V)
{v}
V
k U
k
Type checking terms v V.
V U .V W U
Fun V W U
.V v W
v Fun V W
V U v nbe(V)
{v}
V
U
v V
= v: V
v {v
}
V
k V
= V
k V
V {w}
W
jo . Extended Martin-Lf Type Theory
Type inference k V.
.A
i
. . . . A
0
v
i
nbe(A
i
p
i+1
)
k V V = Fun V
W v V
W. By i.h. V
: U, and .V
W: U,
and using both derivations we can derive Fun V W: U.
consider V = U, and v = {v
}
V
. by i.h. on V
U, and
v
}
V
: U.
V = Fun V
W, and v = v
: we have .V
W. From this we
can conclude by i.h. .V
: Fun V
W.
V = {w}
W
: by hypothesis we know w: W, and v W, and
w = v: W; by the i.h. on the second one we get v: W; then
we can conclude using (sing-i).
v = k Ne, and V {w}
W
: let k V
, with V
=
Fun V W, hence we have a derivation k: Fun V W (using (sing-el)
if necessary) and v: V, hence by the rule (fun-el), we have
App k v: W(id, v). We conclude by conversion and correctness
of nbe(_).
In order to prove completeness we dene a lexicographic order on pairs of
terms and types, in this way we can make induction over the term, and the
type.
Denition . Let v, v
Nf, and A, A
, A
) is the
lexicographic order on Nf Type(). The corresponding orders are v v
i v
is an immediate sub-term of v
; and A
, i nbe(A
) {w}
nbe(A)
.
Theorem (Completeness of type-checking).
1. If V, then V.
z. If v: A, then v nbe(A).
. If k: A, and k V
, then nbe(A) = V
.
Proof. We prove simultaneously all the points. The rst point is by induction
on the structure of the type. In the last two points we use well-founded
induction on the order .
jz . Extended Martin-Lf Type Theory
1. Types:
Fun V
W; by inversion we know V
, and .V
W; hence by
i.h. we have respectively V
, and .V
W.
V = {v}
V
: by inversion we have V
, and v: nbe(V
), hence
by i.h. we have both V
, and v V
.
k, we have to show k. By lemma zj, we know k: U;
hence by i.h. we have k A, and A = U, hence k U.
z. Terms: We omit the trivial cases, e.g. (U, A); we have re-arranged the
order of the cases for the sake of clarity.
v = Fun V
W:
a) either A = U, V
: U, and .V
W: U; hence, by i.h.
we know both V
U, and .V
W U; hence we can
conclude Fun V W U.
b) Or A = {a}
A
, v: A
, and v = a: A
, hence by
i.h. we know v nbe(B), by conversion we also have
and transitivity of the equality nbe(a) = v: nbe(B), hence
v {nbe(a)}
nbe(B)
.
v = {v
}
V
:
a) V : U, and v
}
V
U
b) A = {a}
A
, with v: A
, and v = a: A
, hence by i.h.
we know v nbe(B). We can also derive nbe(a) =
v: nbe(B), hence v {nbe(a)}
nbe(B)
.
v = v
a) V = Fun A
B, and .A
) v
) v
nbe(B);
therefore v
Fun nbe(A
) nbe(B
).
b) Or A = {a}
A
, v: A
, and v = a: A
, hence by
i.h. we know v nbe(B), by conversion we also have
and transitivity of the equality nbe(a) = v: nbe(B), hence
v {nbe(a)}
nbe(B)
.
v Ne: then we do case analysis on nbe(A).
a) If nbe(A) = {w}
W
, then by soundness of nbe(_), and conversion
we have k: {w}
W
; and by inversion of singletons we have
k: W, and also k = w: W(). Clearly (k, W) (k, A),
hence we can apply the inductive hypothesis and conclude
k W; from that and (), we conclude k {w}
W
, i.e.,
k nbe(A).
b) If V {w}
W
, then V V. We use the last clause for concluding
k nbe(A); but we need to show that if k V
, then
V = V
.
.. Type-checking algorithm j
let us consider rst the case when V = {w}
W
; by inversion we have
derivations k: W, and k = w: W. Hence by i.h. we know
that V
= W, and W = {w}
W
.
Now we consider the case when V is not a singleton, and k = q p
i
;
this case is trivial because by inversion we know that V =
nbe((!i) p
i+1
).
the last case to consider is k = App k
, then V
) has rules (n
0
-tm) and (prf-tm); while () lacks those rules.
Denition (Type-checking and type-inference). -types.
V .V W
V W
V U .V W U
V W U
v V v
nbe(W(id
, v))
(v, v
) V W
k V W
fst k V
k V W
snd k nbe(W(id
, fst k))
Natural numbers.
Nat Nat U zero Nat
v Nat
suc(v) Nat
.Nat V k Nat v nbe(V (id
, zero))
v
, c
n
i
))
case
n
V v
0
v
n1
k nbe(V (id, k))
j . Extended Martin-Lf Type Theory
Proof types.
V
[V]
V U
[V] U
v V
[v] [V]
W
k [V] .V v nbe(Wp) .V.Vp vp = v(pp, q): Wpp
v where
W
k W
We do not show the proof for correctness, because nothing is to be gained
from it; suce it to say that we can prove correctness with respect to (
).
Theorem . The type-checking algorithm is sound with respect to the calculus
.
Proof. By simultaneous induction on the derivability of the type-checking
judgements.
It is clear that the given rules are not complete for checking (
), because
there is no rule for checking A. Note that it is not possible to have a
sound and complete type-checking algorithm with respect to (
), for it would
imply the decidability of type-inhabitation. Since type checking happens
always before normalisation, we can still use a good normalisation function
with respect to the calculus (
::= q | t | s | Fun t t
| App t t
| t
Substs ,
::= p | | , t |
| id .
In the next sections we introduce the formal systems corresponding to both
presentations of PTSs:
)
The rst family of type systems has an untyped notion of equality. It corres-
ponds to the equivalence and congruence closure of the reductions
and
x
. This equivalence relation on terms induces an equivalence relation on
contexts.
Beta-reduction
App (t) t
t id, t
Substitutions
()
x
( )
id
x
id
x
p , t
x
, t
x
, t
Congruence
(Fun AB)
x
Fun (A) (Bp, q)
t ()
x
(t )
t id
x
t
q , t
x
t
(t)
x
(t p, q)
(App t t
)
x
App (t ) (t
)
s
x
s
The typing rules of
, then
t: A. For
proving that result we need to prove the same property for substitutions; but
that is not possible because in the typing rule for the identity substitution the
target and source context should be syntactically equal.
Properties of
) A and C
x
s
.
z. If q: C, then there exists s S, and
A: s, = .A, and C
x
Ap.
.1. Formal systems 1o
(empty-ctx)
(ext-ctx)
A: s
, A
(fun-f)
A: s , A B: s
Fun AB: s
(s, s
, s
) R
(axiom)
c: s
(c, s) A
(fun-i)
Fun AB: s
, A t: B
t: Fun AB
(fun-el)
t: Fun AB r: A
App t r: Bid, r
(sub-tm)
A: s t: A :
t : A
(sub-sort)
A: s :
A: s
(conv)
t: A B: s A
x
B
t: B
(hyp)
A: s
, A q: Ap
Figure .1: Rules for contexts and terms
(id-subs)
id:
(empty-subs)
:
(fst-subs)
A: s
, A p:
(ext-subs)
: A: s t: A
, t: , A
(comp-subs)
: :
:
(conv-subs)
:
x
:
Figure .z: Rules for substitutions of
= .id, r.
1. If .A. t: s, then
id, r: s.
z. If .A. B: s and .A. t: B, then
id, r: B
id, r.
. If .A. : , then
id, r: .
Proof. See PtsCtxCnv.agda.
Lemma 61 (Context Conversion). Let
x
.
1.
x
.
z. If t: A, then
t: A.
. If : , then
: .
Proof.
1. See CtxEqSym in PtsCtxCnv.agda.
z. See ctxTerm in PtsCtxCnv.agda.
. See ctxSub in PtsCtxCnv.agda.
.1. Formal systems 1o
(empty-ctx)
e
(ext-ctx)
e
e
A: s
, A
e
(fun-f)
e
A: s , A
e
B: s
(s, s
, s
) R
e
Fun AB: s
(axiom)
(c, s) A
e
c: s
(fun-i)
e
Fun AB: s
, A
e
t: B
e
t: Fun AB
(fun-el)
e
t: Fun AB
e
r: A
e
App t r: Bid, r
(hyp)
e
A: s
, A
e
q: Ap
(conv)
e
t: A
e
A = B: s
e
t: B
(subs-tm)
e
A: s
e
:
e
t: A
e
t : A
(subs-sort)
e
:
e
A: s
e
A: s
Figure .: Typing rules for contexts and terms of
=
PTSs with typed equality (
=
)
In
=
equality is axiomatised as in Martin-Lf type theory, i.e. by a system of
axioms typeable under some context. To distinguish judgements of
from
those of
=
, we have a distinct turnstile (
e
) for the latter. The typing rules are
presented in Figs. . and .; axioms are shown in Figs. ., .6, and ..
For
=
we need to introduce an additional form of judgements, that of
conversion between contexts. It is enough to have reexivity for the empty
context (we skip that rule) and the following one for extended contexts:
(ext-eq-ctx)
e
=
e
A: s
e
B: s
e
A = B: s
e
.A =
.B
The notion of normal forms (and neutrals) is only important for
=
, be-
cause it is used in the model construction of Sec. .:
Ne k ::= q | q p
i+1
| App k v
Nf v, V, W ::= s | Fun V W | v | k .
Properties of
=
We have proved all the analogous results of
for
=
. For
proving inversion of typing, we introduce some predicates.
Denition 8.
e
t t
=
:
Figure .: Typing rules for substitutions of
=
(Fun AB) = Fun (A) (Bp, q)
c = c
t () = (t )
t id = t
q , t = t
(t) = (t p, q)
(App t t
) = App (t ) (t
)
App (t) r = t id, r
() = ( )
id =
id =
=
p , t =
, t = , t
Figure .: Axioms for terms and substitutions
1.
e
t t.
z. If
e
t = t
: A, then
e
t t
.
. If
e
t t
and
e
t
= t
: A, then
e
t t
.
e
a b This predicate indicates that either a and b are the same sort or
e
a b.
Lemma 6z (Inversion of typing).
1. If
e
s: C, then there exists (s, s
) A and
e
C s
.
z. If
e
q: C, then there exists s S,
e
and A Terms, such that
e
A: s,
= .A, and
e
C Ap.
. If
e
Fun AB: C, then there exist (s
0
, s
1
, s
2
) R,
e
A: s
0
, .A
e
B: s
1
,
and
e
C s
2
.
. If
e
t: C, then there exist A, B Terms, (s
0
, s
1
, s
2
) R,
e
A: s
0
,
.A
e
B: s
1
, .A
e
t: B, and
e
C Fun AB.
. If
e
App t r: C, then there exist A, B Terms,
e
t: Fun AB,
e
r: A,
and
e
C Bid, r,
.1. Formal systems 1o
(pts-refl)
e
t: A
e
t = t: A
(pts-sym)
e
t = t
: A
e
t
= t: A
(pts-trans)
e
t = t
: A
e
t
= t
: A
e
t = t
: A
(prod-eq)
e
A = B: s , A
e
C = D: s
(s, s
, s
) R
e
Fun AC = Fun BD: s
(lam-eq)
, A
e
t = t
: B
e
A: s , A
e
B: s
(s, s
, s
) R
e
t = t
: Fun AB
(app-eq)
e
t
0
= t
0
: Fun AB
e
t
1
= t
1
: A
e
App t
0
t
1
= App t
0
t
1
: Bid, t
1
(subs-eq)
e
A: s
e
t = t
: A
e
=
:
e
t = t
: A
(subs-eq-s)
e
t = t
: s
e
=
:
e
t = t
: s
(conv-eq)
e
t = t
: A
e
A = B: s
e
t = t
: B
Figure .6: Equality is a congruence for term
(s-refl)
e
:
e
= :
(s-sym)
e
=
:
e
= :
(s-trans)
e
=
:
e
:
e
=
:
(comp-eq)
e
=
:
e
=
:
e
=
:
(ext-eq)
e
A: s
e
=
:
e
t = t
: A
e
, t =
, t
: , A
Figure .: Equality is a congruence for substitutions
1o8 . Pure Type Systems
Proof. See EPtsGen.agda.
Using the same strategy as for
= .id, r.
1. If .A.
e
t: s, then
e
t
id, r: s.
z. If .A.
e
B: s and .A.
e
t: B, then
e
t
id, r: B
id, r.
. If .A.
e
: , then
id, r: .
. If .A.
e
t = t
: s, then
e
t
id, r = t
id, r: s.
. If .A.
e
B: s and .A.
e
t = t
: B, then
e
t
id, r = t
id, r: B
id, r.
6. If .A.
e
=
: , then
id, r =
id, r: .
Proof. See EPtsSubs.agda.
The only meta-theorem for
=
that we have not yet formalised in Agda is
context conversion; we present the proof.
Lemma 6 (Context conversion). Let .A.
e
J and
e
A = B: s, then
e
.A. =
.B. and .B.
e
J.
Proof. We prove the two points simultaneously; the rst, by induction on the
length of ; and the second, by induction on derivations. We show some cases.
1. (ext-ctx): The premises are .A.
e
and .A.
e
C: s; the conclusion is
.A..C
e
. By i.h. on the rst premise we have .B.
e
and
e
.A. = .B..
By i.h. on the second premise, .B.
e
C: s. From those three facts, we
conclude .A..C
e
, by (ext-ctx); and
e
.A..C = .B..C, by (ext-eq-ctx),
for applying this rule we deduce, by (refl), .A.
e
C = C: s.
z. (id-subs): the premise is .A.
e
; by i.h. we know .B.
e
and
e
.A. =
.B.. From the rst, we derive .B.
e
id: .B., and by (conv-subs) we
conclude .B.
e
id: .A..
Postulating context conversion, we have formally proved type validity and
equality validity. The predicate
e
A means that either A S or there exists
s S and
e
A: s.
Lemma 6 (Type validity). If
e
t: A, then
e
A.
Proof. See InvTy in EPtsValidity.agda.
Lemma 66 (Equality validity). If
e
t = t
: A, then
e
A,
e
t: A and and
e
t
: A.
Proof. See InvEqTy in EPtsValidity.agda.
.z. Equivalence between
and
=
1oj
.z Equivalence between
and
=
Now that we have formally introduced the two families of PTSs, we can pre-
cisely state the equivalence.
Theorem 6 (Equivalence between
and
=
[1o]).
1.
e
t: A i t: A.
z.
e
t = t
: A i t: A, t
: A, and t
x
t
.
This theorem was conjectured by Geuvers [j] for PTSs with (). Adams [j]
proved the equivalence for functional PTSs. Later, Herbelin and Siles [1o]
extended and formalised Adams result to semi-full systems; Siles nally
settled in his PhD thesis [1o] the equivalence for every PTS. Already in
Geuvers thesis it is recognised that the direction from
to
=
is easy; in
fact Adams proved that direction for every PTS. The key result to prove the
other implication depends on subject reduction for
=
: if
e
t: A and t
x
t
,
then
e
t
, then
x
.
. If
e
t: A, then t: A.
. If
e
: , then : .
. If
e
t = t
: A, then t: A, t
: A, and t
x
t
.
6. If
e
=
: , then : ,
: , and
x
.
Proof. See EPtsToPts.agda.
. Semantics for
=
The model of
=
are parameterised by the signature of the PTS. Given a
signature S = (S, A, R), let D
S
be the least solution for
D ODD[D D] D[D D] Var
DDS
.
Besides the convention for naming elements of D
S
inherited from previous
chapters, we also write s D for s S. In the following we omit the subscript
S from D
S
.
11o . Pure Type Systems
Denition j (Readback function).
R
j
s = s
R
j
(Fun X F) = Fun (R
j
X) (R
j+1
(F Var j))
R
j
(App dd
) = App (R
j
d) (R
j
d
)
R
j
(lamf) = (R
j+1
f(Var j))
R
j
(Var i) =
q if j i +1
q p
j(i+1)
if j > i +1
As in previous chapters, we identify in D the set of semantical neutral values
and semantical normal forms by taking the inverse image of R:
Ne =
iN
{d D | R
i
d Ne} and Nf =
iN
{d D | R
i
d Nf} .
Denoting types and sorts
Since our presentation of PTSs does not include (), we can base our interpret-
ation of sorts and types as we interpreted universes and types in Chap. : one
has a universe of types and a function [_] mapping elements of that universe to
subsets of the domain. The universe of types and the function [_] were intro-
duced following the schema of inductive-recursive denitions. A key result
for the normalisation algorithm was that types itself and the interpretation of
each type were saturated, cf. Lem. 16 and Lem. 8.
Let us analyse informally which elements of D should be in the subset
denoting types. By rule (axiom) we know that sorts are among the possible
types; so, S should be included in the universe types. Note also that terms typed
with a sort can also be types; which suggests to add any element of [s] to types,
for each s S. The denition of [s] D depends both on axioms and rules of
the system: axioms tell us that if (s
, s) A, then s
) A
s [s
]
s T
[s] T
(s, s
, s
) R d [s] f e [s
]
d T
Ne [d]
ge [f e], for all e [d]
lamg [Fun df]
The well-founded order over S gives us a way to reason about elements of T.
In fact, it induces a well-founded order over [s], for every s S, and over T:
minimal elements with respect of are elements in Ne and minimal
elements with respect to ,
s s
if s s
, and
for (s, s
, s
f.
a) for d = s: since S Nf, we only consider Fun d
,
Ne [d
]; therefore f (Var i) [s
1
] for every Var i. By i.h. on s
1
,
f (Var i) Nf. Therefore Fun d
f Nf.
b) for d = Fun d
f: if e [Fun d
we know Ne [d
];
therefore, for every Var i, g(Var i) [f (Var i)]. By i.h. on f (Var i)
we know g(Var i) Nf.
11z . Pure Type Systems
Corollary o. T is saturated: if d T, then there is some e T, such that
d [e].
Interpretation and Soundness The missing pieces of the model are the inter-
pretation of terms and the satisfaction of judgements by the model. As in
previous chapters, we introduce two functions _
s
_ and _
t
_.
_
t
_ : Terms D D
s
t
d = s
q
t
d = snd d
App t u
t
d = t
t
d u
t
d
t
t
d = lam(d
t
t
(d, d
))
t
t
d = t
t
(
s
d)
Fun AB
t
d = Fun (A
t
d) (e B(d, e))
_
s
_ : Substs D D
s
d =
id
s
d = d
(, t)
s
d = (
s
d, t
t
d)
p
s
d = fst d
s
d =
s
(
s
d)
Projections fst and snd are dened as in Chap. ; the evaluation operator _ _
is, as in Chap. , dened for semantical neutrals because we do not consider
():
d e =
f e if d = lamf
App de if d Ne
otherwise .
Remark z. Notice that if d [Fun X F] and e [X], then d e [F e].
Since the interpretation is given for pre-terms and pre-substitutions, we
can prove that the interpretation model the untyped equality.
Lemma 1. If t
x
t
and d D, then td = t
d.
Proof. By induction on t
x
t
d = td t
d
= t(d, t
d) = t(id, t
d) = t id, t
d
z. (fun-subs):
(Fun AB) d = Fun AB(d)
= Fun (A(d)) (e B(d, e))
= Fun (A(d)) (e B((p(d, e)), e))
= Fun (A(d)) (e B(p(d, e), q(d, e)))
= Fun (A(d)) (e B(p, q(d, e)))
The semantics of judgements uses the set T and the mapping [_] : T P(D).
If t: A, we want A
t
d T and, be that the case, t
t
d [A
t
d]. In the
following denition we state formally the validity of judgements in the model
and introduce, at the same time, the semantics of well-formed contexts.
.. Semantics for
=
11
Denition 6z (Validity).
1. a) ;
b) .
z. a) , A i A: s;
b) If d and d
) , A.
. =
i d i d
.
. t: A i
a) A is a top-sort, say s: and td [s], for all d .
b) A: s: A: s and td [Ad], for all d .
. : i , and d , for all d .
6. t = t
: A i t: A and td = t
d, for all d .
. =
: i : and d =
d, for all d .
Theorem z (Soundness of the model). If
e
J, then J.
Proof. By induction on
e
J; note that the last two items are proved by the
inductive hypothesis and using Lem. 1.
1. (empty-ctx): trivial.
z. (ext-ctx) .A
e
: by i.h. on
e
A: s.
. (axiom)
e
s
].
. (fun-f)
e
Fun AB: s
2
: by i.h. , A: s
0
; also by i.h. .A B: s
1
.
From the last two conditions we see that Fun Ad e B(d, e) [s
2
]
for any d .
. (fun-i)
e
t: Fun AB: by i.h. , A: s
0
, .A B: s
1
, and .A t: B.
The last condition implies t(d, e) [B(d, e)] for any d and
e [Ad]; therefore td [Fun ABd] for any d .
6. (fun-el)
e
App t r: B(id, r): by i.h. t: Fun AB and r: A; therefore
for any d , rd [Ad]. By Rem. z, td rd [B(d, rd)].
. (sub-tm)
e
t : A: by i.h. : . For d , then d ;
therefore by i.h. on
e
t: A, we have t(d) [A(d)].
8. (sub-sort)
e
A: s: as in the previous item.
j. (hyp) .A
e
q: Ap: (d, e) .A if d and e [Ad]; that is enough
to conclude, because Ap(d, e) = Ad and q(d, e) = e.
1o. (conv)
e
t: B: by i.h. td [Ad] for any d ; by i.h. Ad = Bd,
therefore td [Bd].
11. (ext-subs)
e
(, t): .A: for d , by i.h. d and td
[Ad].
11 . Pure Type Systems
1z. (comp-subs)
e
: : using the same reasoning as for (sub-tm).
1. (fst-subs) .A
e
p: : using the same reasoning as for (hyp).
By soundness we know that each typed term is interpreted as an element
of the denotation of the type; moreover we know that judgmentally equal
elements have the same denotation. As a corollary we know that they have the
same normal form.
Corollary (Completeness of normalisation). If t = t
: A and d ,
then R
j
(td) R
j
(t
: C,
then
e
A = A
: s
and , A
e
B = B
: s
: Ap
i
z. X = s S:
e
t: A d [X] i
a) if d Ne S:
e
t p
i
= R
||
d: s
b) if d = Fun X
F: there exists (s
0
, s
1
, s) R and
i.
e
t = Fun A
B: s
ii.
e
A
: s
0
X
[s
0
], and
iii.
e
Bp
i
, r: s
1
F e [s
1
], for all
e
r: A
p
i
e [X
].
. X = Fun X
F:
e
t: A d [Fun X
F] if and only if
a) there exists (s
0
, s
1
, s) R and
e
A = Fun A
B: s,
e
A
: s
0
X
[s
0
],
b) for all
i
and
e
r: A
p
i
d
[X],
e
App (t p
i
) r: B(p
i
, r)
d d
[F d
];
c) i. if d = lamf, then t = t
: A,
ii. if d Ne, then (t p
i
) = R
||
d: Ap
i
.
.. Correctness of Nbe 11
The following lemma is proved analogously as we did in previous chapters:
we use (sym) and (trans) on the main conditions of the denition of the logical
relation. We skip its proofs.
Lemma (Preservation of the logical relation by judgemental equality). If
e
t: A d [X] and
e
t = t
: A, then
e
t
: A d [X]. Moreover, if
e
t: A d [X] and
e
A = B: s, then
e
t: B d [X].
Lemma (Monotonicity of logical relations). If
e
t: A d [X] and
i
,
then
e
t p
i
: Ap
i
d [X].
Lemma 6 (Derivability of equality of reied elements). Let
e
t: A d [X]
and
i
, then
e
t p
i
= R
||
d: R
||
X. Conversely, if
e
A: s X [s],
k Ne and
e
t p
i
= R
||
k: Ap
i
, for all
i
, then
e
t: A k [X].
Proof. (By induction on X T.)
1. X Ne: both parts are obtained from the hypothesis, because those are
the condition to be logically related.
z. X = s S: by induction on d [s]: The rst part for d Ne and d S
are obtained directly by denition. Moreover the second part is trivial,
because the hypothesis is the main condition in the denition of the
logical relation.
We show only the rst part for d = Fun X
F: by i.h. on
e
A: s
0
X
[s
0
] we have
e
Ap
i
= R
||
X
: s
0
. By i.h. on
e
B(p
i
, r): s
1
F e [s
1
].
On the other hand we have
e
q p
j
= R
||
(Var ||): Ap
j
, for all
j
.A, so by i.h. on the second part, we know .A
e
q: Ap Var || [X
].
From which we conclude .A
e
B(p, q) = R
||
(F (Var ||)): s
1
. Using
(prod-eq) we conclude the equality.
. X = Fun X
F: For the rst part, we only show the case when d = lamf.
a) If d = lamf: by denition of the logical relation
e
t = t
: A. As
was shown in the previous point we have .A
e
q: A
p Var ||
[X
e
App ((t
e
t
: B f (Var ||)
[F (Var ||)]; by i.h. .A
e
t
= R
||+1
(f (Var ||)): B. By (cong-abs)
e
t
= (R
||+1
(f (Var ||))): Fun A
= R
||
(lamf): Fun A
B.
b) For the second point we only need to prove
e
App t r: B(p
i
, r)
k d
[F d
], for any
i
and
e
r: A
p
i
d
[X
]. By
Lem. 6j, d
Nf, therefore k d
= App k d
e
r p
j
= R
|
|
d
: A
p
i+j
,
for any
j
and also, from the main hypothesis and (conv-eq),
e
t p
i+j
= R
|
|
k: Fun (A
p
i+j
) (B(p
(i+j)+1
, q)), therefore we can
use (app-cong) to conclude
e
App (t p
i+j
) (r p
j
) = App (R
|
|
k) (R
|
|
d
): B(p
i+j
, r p
j
) .
We now introduce logical relations between substitutions and environments
modelling contexts. As in previous chapters, these relations are dened by
recursion on the codomain of substitutions.
116 . Pure Type Systems
Denition 6 (Logical relation for substitutions). If
e
and
e
, we dene a
logical relation
e
_: _ { |
e
: } {d | d }.
1.
e
: d .
z.
e
: .A (d, d
) .A i
e
p : d and
e
q : A(p )
d
[Ad].
By induction on the codomain of substitutions we can prove easily preserva-
tion of the relations by judgemental equality of substitutions and weakening.
Lemma . Let
e
: d .
1. If
e
=
: , then
e
: d .
z. If
i
, then
e
p
i
: d .
Proof. (By induction on
e
.)
1. The rst point is trivial for . For .A we can apply the i.h. on
e
p =
p
: and
e
p : d ; the other part is obtained by using
Lem. on
e
q = q
: A(p ) and
e
q : A(p ) d
[Ad].
z. The second part is also trivial for . The second part for .A is obtained
by using the i.h. and Lem. .
At this point we can dene an environment logically related with the
identity substitution.
Denition 6 (Canonical environment). By induction on
e
we dene an
environment
= .
z. For .A by (ext-ctx): let n = ||; then by i.h.
and
e
id:
. On the other
hand
e
q p
i
= R
||
(Var n): Ap
i
, for all
i
.A; so, by Lem. 6, we
have .A
e
q: Ap Var n [A
] and by Lem. .A
e
q id: A(p id)
Var n [A
]. So, we conclude .A
e
id: .A (
, Var n) .A.
Note that the formal statement of the fundamental theorem should have
changed the order of the quantication between logically related substitutions
and derivations.
Theorem 8 (Fundamental theorem of logical relations).
1. If s S, s is a top-sort,
e
t: s, and
e
: d , then
e
t : s
td [s].
z. If
e
t: A and
e
: d , then
e
t : A td [Ad],
providing A is not a top-sort.
. If
e
: and
e
: d , then
e
: d .
Proof. (By induction on typing derivations.)
.. Correctness of Nbe 11
1. The rst two points are shown by the following cases.
a)
e
s
) A we also have
s [s
e
(s ) p
i
= s: s
, for any
i
.
b)
e
Fun AB: s
3
by (fun-f): rst we need to prove that there exists
A
, B
: s
3
; we get this
by (fun-sub): A
= A and B
e
r: (A) p
i
e [Ad]; then, by denition of logical
relations for substitutions,
e
( p
i
, r): .A (d, e) .A. By
i.h. on .A
e
B: s
2
, we have
e
B( p
i
, r): s
2
B(d, e) [s
2
]; by
Lem. we conclude
e
B( p, q) (p
i
, r): s
2
B(d, e) [s
2
].
c)
e
t: Fun AB by (fun-i): The point (c)i is easily obtained by
using (abs-sub). The main point is proved in a similar way as
we proved the second condition in the previous rule. First, we
note App (t ( p, q)) p
i
r = t ( p
i
, r) by applying successively the
following rules (app-cong), (comp-subs), (beta), (ass-subs), (dist-subs),
(fst-subs), (snd-subs). Now let
i
and
e
r: (A) p
i
e
[Ad]; so by i.h. on .A
e
t: B we know
e
t ( p
i
, r): B(p
i
, r)
t(d, e) [(Bd) e], where td e = t(d, e).
d) .A
e
q: Aq by (hyp): by inversion on the hypothesis,
e
: d
, we know = (
, t) and d = (d
, e); since q (
, t) = t and
q(d
e [Ad
]
comes again from the hypothesis.
e)
e
t : A by (subs-tm): this is easily seen to hold by i.h. on both
premises.
f)
e
A: s by (subs-s): as in the previous point by i.h.
g)
e
t: B by (conv): we use the i.h. and Lem. .
z. For substitutions:
a)
e
: by (empty-subs): since d = and , then by deni-
tion of logical relations
e
: .
b)
e
id: by (id-subs): by using Lem. on the main hypothesis and
e
id = : .
c)
e
(, t): .A by (ext-subs): we apply the i.h. on both premises,
e
: and
e
t: A, to get, respectively,
e
: d
and
e
t : (A) td [Ad]. By using Lem. and
Lem. on them we conclude
e
p (, t ): d and
e
q (, t ): A() td [Ad].
d)
e
: by (comp-subs): by applying the i.h. twice: rst on
e
:
with the main hypothesis to get
e
: d ; and
then with that substitution we can apply the i.h. on
e
: to
get
e
(): (d) .
e) .A
e
p: by (fst-subs): by denition on logical relations d = (e, e
)
and
e
p : d .
118 . Pure Type Systems
Given a derivation
e
t: A, we can instantiate the fundamental theorem of
logical relations with the identity substitution and the canonical environment
dened in Def. 6; so we obtain
e
t id: Aid t
[A
]. By Lem. 6, we
conclude
e
t id = R
||
(t
(t) = R
||
(t
)
Theorem j (Correctness of NbE). If
e
t: A, then
e
t: A t
[A
]
and
e
t = nbe
(t): A.
Proof. By Thm. 8,
e
t id: Aid t
[A
] and by Lem. ,
e
t: A
t
[A
]
We deduce injectivity of Fun by inverting the equality judgement and using
the fundamental theorem of logical relations and the preservation of the logical
relations by judgemental equality.
Theorem 8o (Injectivity of Fun). If
e
Fun AB = Fun A
: C, then
e
A =
A
: s and .A
e
B = B
: s
.
Proof. If
e
Fun AB = Fun A
[s
[s
0
] and .A
e
B: s
1
B
.A
[s
1
.A
]. By
Lem. we also know
e
Fun A
: s Fun AB
: s
0
A
[s
0
] and .A
e
B: s
1
B
.A
[s
1
]. By
Lem. 6 on the corresponding related elements we conclude, by rules (sym)
and (trans),
e
A = A
: s
0
and .A
e
B = B
: s
1
.
. From
to
=
In this last section we prove subject reduction for
=
using correctness of
NbE; thus we can complete the equivalence proof between
and
=
.
Lemma 81.
1. If
e
t: A and t
x
t
, then
e
t: A t
[A
].
z. If
e
: and
x
, then
e
:
.
Proof. By Thm. j on the rst hypothesis
e
t: A t
[A
] and by
Lem. 1, t
= t
, therefore
e
t: A t
[A
].
Adams obtained, as a result of his proof method for the equivalence of
PTSs, subject reduction for PTSs with typed equality: If
e
t: A and t
x
t
,
then
e
t = t
, instead of t
itself.
Corollary 8z (Subject reduction for
=
). If
e
t: A and t
x
t
, then
e
t =
nbe
(t
): A.
.. From
to
=
11j
Finally we can prove the second part of Thm. 6; the formal proof of the
next theorem assumes as a postulate the last corollary. Since that corollary
depends on the results of the previous two sections, the next theorem only
applies to predicative PTSs.
Theorem 8.
1. If , then
e
.
z. If t: A, then
e
t: A.
. If : , then
e
: .
Proof. See PtsToEpts.agda. We explain the case for (conv): the premises are
t: A, B: s and A
x
B. By i.h. on the rst premise, we know
e
t: A,
and by i.h. on the second premise,
e
B: s. By type validity on
e
t: A, there
is a sort s
, such that
e
A: s
. By Thm. j
e
A = nbe(A): s
; therefore
by (conv),
e
t: nbe(A). From
e
B: s and A
x
B, by Cor. 8z we know
e
B = nbe
: A, and t
x
t
, then
e
t = t
: A.
Proof. By Thm. 8 we have
e
t: A and
e
t
(t
): A; and, by Thm. j
e
t
= nbe
(t
: M
t +t
: M
Axioms The axioms on the left column are those corresponding to the resolu-
tion of substitution; in the right column we list the equational theory for the
abelian monoid.
M = M t +0 = t
0 = 0 s +t = t +s
(t +t
) = (t ) + (t
) (r +s) +t = r + (s +t)
Remark z (Inversion).
1. if 0: A, then A = M; and
z. if s +t: A, then A = M, s: M, and t: M.
Remember that our decision procedure for equality consisted on normal-
ising terms and comparing syntactically equivalence of normal forms. It is
clear that we need to extend the set of normal forms of Chap. to include
the new constructors concerning the monoid. To deal with associativity, sums
are right-leaning; this accounts for the addition of a new non-terminal to the
grammar.
Denition 6 (Normal forms).
Lhs l ::= q | q p
i+1
| App l v
Ne k ::= l | l +k
Nf v, V, W ::= k | U | M | 0 | v | Fun V W
Note that two normal forms generated by this grammar can be syntactically
dierent, although judgementally equal. For example, q p+q and q+q p, say in
the context = M.M. Instead of complicating the denition of normal forms,
we will compare for syntactical equivalence terms which are in canonical form.
This canonical forms will be based on an order between constructors.
Denition 68 (Order between normal forms). We dene a total order on the
terminals of the grammar: q < q p
1
< . . . < q p
i
< q p
i+1
< . . . < App < + <
U < M < 0 < < Fun .
The order on normal forms is the induced lexicographic order using the
order on terminals. It is clear that a sum in normal form has the following
shape: l
0
+ (l
1
+ (. . . + l
n
) . . .). Such a sum is said to be in canonical form if
lighter terms are to the left: i j, implies l
i
l
j
. In general, for v Nf, v is in
canonical form if every sum occurring in v is in canonical form.
The following functions rearrange operands in a sum, by attening them
and ordering them by the order between terms.
Denition 6j. Let
k be a tuple of neutral terms. Let _ _ be the consing
operation for tuples: l k
0
, . . . , k
n1
= l, k
0
, . . . , k
n1
.
6.1. Commutativity in Martin-Lf type theory 1z
Merging of tuples
k =
k
k =
k
l
1
, . . . , l
n
l
1
, . . . , l
m
=
l
1
(l
2
, . . . , l
n
l
1
, l
2
, . . . , l
m
) if l
1
l
1
l
1
(l
1
, l
2
, . . . , l
n
l
2
, . . . , l
m
) otherwise
Flattening of neutrals
at k =
l if k l
l at k
if k l +k
Un-attening
unat
l =
l
0
if
l = l
0
l
0
+ unat l
1
, . . . , l
n
if
l = l
0
, l
1
, . . . , l
n
), then
v = v
: A.
NbE: correctness and completeness
We extend the semantic domain to interpret the new terms: D = . . . {M}
{0}
; an element d D
R
i
d
0
if n = 0
R
i
d
0
+ R
i
d
1
, . . . , d
n
otherwise
Note that we keep the readback function simple and the generated sums
are right-leaning (if the tuple is at). We need to adapt the denition of the
PERs for semantical neutral values and normal forms, to take into account the
symmetry of addition.
1z 6. Conclusion
Denition 1 (PER for neutrals, and normal forms).
d = d
Ne i R
i
d and R
i
d
),
for all i N;
d = d
Nf i R
i
d and R
i
d
),
for all i N.
We add a new PER over D to interpret the type M; accordingly we also add
a new clause to the universes U.
Denition z (Adapting the PER model).
PER for the monoid
Ne M and 0 = 0 M .
New clause for U
M = M U and [M] = M .
-expansion and normalisation
M
k = k
M
d = d M = M .
Remark z. It is easy to see that M is saturated; therefore Lem. 8 is valid in
the extended model.
To interpret the addition operation, we build tuples but removing occur-
rences of 0. Note that if the two arguments are at tuples, the result is also a
at tuple.
Denition .
0 d = d d 0 = d
d
0
, . . . , d
n1
d
0
, . . . , d
m1
= d
0
, . . . , d
n1
, d
0
, . . . , d
m1
d
0
, . . . , d
n1
d
= d
0
, . . . , d
n1
, d
d d
0
, . . . , d
m1
= d, d
0
, . . . , d
m1
d d
= d, d
d = td t
d
The following lemma is the key to prove soundness.
Lemma 86. The operator _ _ is associative and commutative with respect to
the PER M. Let c = c
, d = d
, e = e
M,
1. 0 d = d
M and d 0 = d
M.
z. d e = e
M,
. c (d e) = (c
) e
M, and
Proof.
6.1. Commutativity in Martin-Lf type theory 1z
1. By denition.
z. The only interesting case is when both d = d
Ne and e = e
Ne;
note also that it is enough to consider at tuples: d = d
0
, . . . , d
n
,
d
= d
0
, . . . , d
n
, e = e
0
, . . . , e
m
, and e
= e
0
, . . . , e
m
. In that
case for any i N and every element k of any of the tuples, R
i
k
is dened and is a neutral element. Therefore can(R
i
d
0
+ (R
i
d
1
+
(. . . (R
i
e
m1
+ R
i
e
m
) . . .))) has the same summands than can(R
i
e
0
+
(R
i
e
1
+ (. . . (R
i
d
n1
+ R
i
d
n
) . . .))) and in the same order.
. By an argument analogous to that of the previous point.
Remark z8. The model is sound, cf. Thm. . This is easy after proving Lem. 86.
By Rem. z, if t = t
: M, then can((R
i
(td))) can((R
i
(t
: A d
M, then t + t
: A
d d
M.
Proof. By induction on d, d
M. If d = 0, then we have t + t
= t
: A
and d d
= d
; therefore by Lem. z t +t
: A d d
= 0 is analogous. If d, d
p
i
= R
||
d
: Ap
i
; therefore, by rst using (conv) to type both equalities
with M, then using congruence of addition, and nally (conv) again to type the
additions with the original type Ap
i
, we get (t+t
) p
i
= R
||
(dd
): Ap
i
.
That is the condition for t +t
: A d d
M.
Remember that the fundamental theorem of logical relations states that
every term is logically related with its denotation. We recast it here only for
the monoid.
Theorem 8j. Let : d , then if t: M, then t : M td
M.
1z6 6. Conclusion
Proof. This theorem is proved by induction on derivations; we show the case
for t +t
: M t
d M. By
Lem. 88, t +t
: M td t
) : M t +t
d M.
Note that as a corollary of Lem. 8 and Thm. 8j with the canonical envir-
onment introduced in Def. j, we have correctness of normalisation.
Corollary jo. If t: A, then t = R
||
(
A
(t
)): A.
We change the denition of the normalisation function in order to get
canonical normal forms; the denition of the canonical environment remains
as in Def. j.
Denition 6. Let A and t: A.
nbe
(A) = can(R
||
(A
))
nbe
A
(t) = can(R
||
(
A
))
The normalised term can still be proved equal to its canonical normal form
by virtue of Rem. z6.
Corollary j1 (Correctness of NbE). If t: A, then t = nbe
A
(t): A.
6.z Further work
Correctness of Haskell implementation of NbE The correctness of the implement-
ation of the type-checking algorithm for Martin-Lf type theory presented in
Chap. depends on having a proof showing that the Haskell implementation
of NbE corresponds to the mathematical function for which we proved com-
pleteness and soundness. For that reason an implementation of a type-checker
using the method suggested in Chap. would be more trustworthy if one has
a proof of the computational correctness of the Haskell program. I know of
two papers that can be used to guide such a proof: Filinski and Rhode []
proved a similar result for untyped NbE and its implementation in an ML-like
language; Dybjer and Kuperberg [] also proved the correctness of a Haskell
implementation of NbE for untyped combinatory logic.
PTS with explicit substitutions It would be interesting to compare our present-
ation of PTS with explicit substitutions to PTS with those of Bloo and Muoz.
Moreover, it is needed to study more deeply the meta-theory of
and its
relationship with traditional PTS, that is with named variables and implicit
substitutions.
We expect that one can use analogous semantical methods as those that
we used to prove injectivity of Fun to get an equivalence result for
and
=
with () rule.
More abstract denition of NbE There is some smell of repetition among the
chapters of this thesis; this call for a deeper study to see if it is possible to
dene NbE more abstractly and prove the main properties (completeness and
soundness) without repeating over and over the same proofs each time a rule
6.z. Further work 1z
is added (or dropped). For example, Thierry Coquand suggested to consider
NbE
without rule (cong-abs); instead of redoing all the work from scratch, it
would be more interesting to have an abstract denition and extract the proof
for that system by using the appropiate parameters in the general framework.
One possibility for getting such an abstract result is to understand NbE in a
categorical setting.
Using NbE to ease the use of dependent types In Sec. 6.1 we discussed how
we can use NbE to decide equality for an abelian monoid and presented an
example of how it can simplify the burden for formalising a (fairly trivial)
proof. It will be interesting to have a proof-checker, even a prototype, with
several extensions like commutativity. Ideally one should formalise some
mathematical proof in such a system and in some other proof-assistant in order
to compare the de Bruijn factor [11] between both formalisations.
Bibliography
[1] Martin Abadi, Luca Cardelli, Pierre-Louis Curien and Jean Jacques
Lvy. Explicit substitutions. In: POPL o: Proceedings of the :th ACM
SIGPLAN-SIGACT symposium on Principles of programming languages.
San Francisco, California, United States: ACM, 1jjo, pp. 16. isbn:
o-8jj1--. doi: 10.1145/96709.96712 (cit. on pp. 11, 1).
[z] Andreas Abel, Klaus Aehlig and Peter Dybjer. Normalization by Evalu-
ation for Martin-Lf Type Theory with One Universe. In: Proceedings
of the rd Conference on the Mathematical Foundations of Programming
Semantics (MFPS XXIII), New Orleans, LA, USA, ::-: April oo. Ed.
by Marcelo Fiore. Elsevier, zoo, pp. 1j (cit. on pp. 1, 1).
[] Andreas Abel, Thierry Coquand and Peter Dybjer. Normalization by
Evaluation for Martin-Lf Type Theory with Typed Equality Judge-
ments. In: Proc. of the nd IEEE Symp. on Logic in Computer Science
(LICS oo). IEEE Computer Soc. Press, zoo, pp. 1z. doi: 10.1109/
LICS.2007.33 (cit. on pp. 1, 1).
[] Andreas Abel, Thierry Coquand and Peter Dybjer. On the Algebraic
Foundation of Proof Assistants for Intuitionistic Type Theory. In: Proc.
of the th Int. Symp. on Functional and Logic Programming, FLOPS oo8.
Ed. by Jacques Garrigue and Manuel V. Hermenegildo. Vol. j8j. Lect.
Notes in Comput. Sci. Springer, zoo8, pp. 1. isbn: j8--o-8j68-
o. doi: 10.1007/978-3-540-78969-7_2 (cit. on pp. 1, 88).
[] Andreas Abel, Thierry Coquand and Peter Dybjer. Verifying a Semantic
-Conversion Test for Martin-Lf Type Theory. In: Proc. of the th
Int. Conf. on Mathematics of Program Construction, MPC oo8. Ed. by
Philippe Audebaud and Christine Paulin-Mohring. Vol. 1. Lect.
Notes in Comput. Sci. Springer, zoo8, pp. zj6. isbn: j8--o-
oj-z. doi: 10.1007/978-3-540-70594-9_4 (cit. on pp. 1, 1).
[6] Andreas Abel, Thierry Coquand and Miguel Pagano. A Modular Type-
Checking Algorithm for Type Theory with Singleton Types and Proof
Irrelevance. In: TLCA. Ed. by Pierre-Louis Curien. Vol. 6o8. Lecture
Notes in Computer Science. Springer, zooj, pp. 1j. isbn: j8--6z-
ozzz-z. doi: 10.1007/978-3-642-02273-9_3 (cit. on p. 1).
[] Andreas Abel, Thierry Coquand and Miguel Pagano. A Modular Type-
Checking Algorithm for Type Theory with Singleton Types and Proof
Irrelevance. In: Logical Methods in Computer Science .z: (May zo11),
pp. 1. doi: 10.2168/LMCS-7(2:4)2011 (cit. on p. 1).
[8] Samson Abramsky and Achim Jung. Domain Theory. In: Handbook
of Logic in Computer Science. Oxford University Press, 1jj, pp. 1168
(cit. on p. z).
1zj
1o BIBLIOGRAPHY
[j] Robin Adams. Pure type systems with judgemental equality. In: Jour-
nal of Functional Programming 16.z (zoo6), pp. z1jz6. doi: 10.1017/
S0956796805005770 (cit. on pp. 1, 1oj).
[1o] Klaus Aehlig, Florian Haftmann and Tobias Nipkow. A Compiled
Implementation of Normalization by Evaluation. In: TPHOLs. Ed. by
Otmane At Mohamed, Csar Muoz and Sone Tahar. Vol. 1o.
Lecture Notes in Computer Science. Springer, zoo8, pp. j. isbn:
j8--o-1o6-. doi: 10.1007/978-3-540-71067-7_8 (cit. on p. 1).
[11] Klaus Aehlig and Felix Joachimski. Operational aspects of untyped
Normalisation by Evaluation. In: Mathematical Structures in Computer
Science 1. (zoo), pp. 8611. doi: 10.1017/S096012950400427X (cit.
on pp. 1, z).
[1z] Thorsten Altenkirch, Peter Dybjer, Martin Hofmann and Philip J. Scott.
Normalization by Evaluation for Typed Lambda Calculus with Cop-
roducts. In: Proc. of the :6th IEEE Symp. on Logic in Computer Science
(LICS oo:). IEEE Computer Soc. Press, zoo1, pp. o1o (cit. on
pp. 1, 61).
[1] Thorsten Altenkirch, Martin Hofmann and Thomas Streicher. Cat-
egorical Reconstruction of a Reduction Free Normalization Proof. In:
Category Theory and Computer Science. Ed. by David H. Pitt, David
E. Rydeheard and Peter Johnstone. Vol. j. Lecture Notes in Com-
puter Science. Springer, 1jj, pp. 18z1jj. isbn: -o-6o16- (cit.
on p. 1).
[1] David Aspinall. Subtyping with Singleton Types. In: Computer Science
Logic, 8th Int. Wksh., CSL . Ed. by Leszek Pacholski and Jerzy Tiuryn.
Vol. j. Lect. Notes in Comput. Sci. Springer, 1jj, pp. 11. isbn:
-o-6oo1-. doi: 10.1007/BFb0022243 (cit. on pp. z8, , 6, 8j).
[1] Steven Awodey and Andrej Bauer. Propositions as [Types]. In: J. Log.
Comput. 1. (zoo), pp. 1. doi: 10.1093/logcom/14.4.447
(cit. on pp. 61, 6z).
[16] Vincent Balat, Roberto Di Cosmo and Marcelo P. Fiore. Extensional
normalisation and type-directed partial evaluation for typed lambda
calculus with sums. In: Proc. of the :st ACM Symp. on Principles of
Programming Languages, POPL oo. Ed. by Neil D. Jones and Xavier
Leroy. ACM Press, zoo, pp. 66. isbn: 1-811-zj-X. doi: 10.1145/
964001.964007 (cit. on p. 61).
[1] Henk Barendregt. Lambda calculi with types. In: Handbook of Logic in
Computer Science. Ed. by Samson Abramsky, D. M. Gabbay and T. S. E.
Maibaum. Oxford University Press, 1jjz, pp. 11oj (cit. on p. ).
[18] Bruno Barras. Coq en Coq. Research Report RR-oz6. Projet COQ. IN-
RIA, 1jj6. url: http://hal.inria.fr/inria- 00073667/PDF/RR-
3026.pdf (cit. on p. 1).
[1j] Bruno Barras. Auto-validation dun systme de preuves avec familles
inductives. Thse de Doctorat. Universit Paris , Nov. 1jjj (cit. on
p. 1).
BIBLIOGRAPHY 11
[zo] Gilles Barthe and Morten Heine Srensen. Domain-free pure type
systems. In: J. Funct. Program. 1o. (zooo), pp. 1z. url: http:
//journals.cambridge.org/action/displayAbstract?aid=59753 (cit.
on p. 1o1).
[z1] Michael Beeson. Formalizing constructive mathematics: Why and
how? In: Constructive Mathematics. Ed. by Fred Richman. Vol. 8.
Lecture Notes in Mathematics. Springer Berlin / Heidelberg, 1j81,
pp. 161jo. doi: 10.1007/BFb0090733 (cit. on p. 1).
[zz] Michael J. Beeson. Problematic principles in constructive mathematics.
In: Logic Colloquium 8o. Vol. 1o8. Studies in Logic and the Foundations
of Mathematics. Amsterdam: North-Holland, 1j8o, pp. 11. doi:
10.1016/S0049-237X(09)70502-6 (cit. on p. ).
[z] Stefano Berardi. Type Dependence and Constructive Mathematics.
PhD thesis. Carnegie Mellon University and Torino University, 1j8j.
url: http://www.di.unito.it/~stefano/Berardi- PhDThesis.rtf
(cit. on p. ).
[z] Stefano Berardi. About the sets-as-propositions embedding of HOL in
CC. Feb. zoo (cit. on p. ).
[z] Ulrich Berger, Matthias Eberl and Helmut Schwichtenberg. Normal-
isation by Evaluation. In: Prospects for Hardware Foundations. Ed. by
Bernhard Mller and J. V. Tucker. Vol. 16. Lecture Notes in Com-
puter Science. Springer, 1jj8, pp. 111. isbn: -o-661-. doi:
10.1007/3-540-49254-2_4 (cit. on p. 1).
[z6] Ulrich Berger and Helmut Schwichtenberg. An Inverse of the Eval-
uation Functional for Typed lambda-calculus. In: Proceedings, Sixth
Annual IEEE Symposium on Logic in Computer Science, :-:8 July, ::,
Amsterdam, The Netherlands. IEEE Computer Society, 1jj1, pp. zo
z11. doi: 10.1109/LICS.1991.151645 (cit. on pp. 1z, 1, z, 1).
[z] Roel Bloo. Pure type systems with explicit substitution. In: Mathemat-
ical. Structures in Comp. Sci. 11.1 (zoo1), pp. 1j. issn: oj6o-1zj. doi:
10.1017/S096012950000325X (cit. on pp. 1o1, 1oz).
[z8] Ana Bove and Peter Dybjer. Dependent Types at Work. In: LerNet ALFA
Summer School. Ed. by Ana Bove, Lus Soares Barbosa, Alberto Pardo
and Jorge Sousa Pinto. Vol. zo. Lecture Notes in Computer Science.
Springer, zoo8, pp. jj. isbn: j8--6z-o1z-6. doi: 10.1007/978-
3-642-03153-3_2 (cit. on p. 6).
[zj] Kim Bruce and John C. Mitchell. PER models of subtyping, recursive
types and higher-order polymorphism. In: POPL : Proceedings of
the :th ACM SIGPLAN-SIGACT symposium on Principles of program-
ming languages. Albuquerque, New Mexico, United States: ACM, 1jjz,
pp. 16z. isbn: o-8jj1--8. doi: 10.1145/143165.143230 (cit. on
p. 6).
[o] Nicolaas Govert de Bruijn. AUTOMATH, a language for mathematics.
T.H. Department of Mathematics, Eindhoven University of Technology,
Nov. 1j68 (cit. on p. ).
1z BIBLIOGRAPHY
[1] Nicolaas Govert de Bruijn. Lambda calculus notation with nameless
dummies, a tool for automatic formula manipulation, with application
to the Church-Rosser theorem. In: Indagationes Mathematicae (Proceed-
ings) . (1jz), pp. 81 jz. issn: 18-z8. doi: 10.1016/1385-
7258(72)90034-0 (cit. on p. 11).
[z] Nicolaas Govert de Bruijn. Some extensions of Automath : the AUT- fam-
ily. Tech. rep. OAI Repository of the Technische Universiteit Eindhoven
(TU/e) (Netherlands), 1jj. url: http://library.tue.nl/csp/dare/
LinkToRepository.csp?recordnumber=597613 (cit. on p. ).
[] Felice Cardone and J. Roger Hindley. Lambda-Calculus and Combin-
ators in the zoth Century. In: Logic from Russell to Church. Ed. by
Dov M. Gabbay and John Woods. Vol. . Handbook of the History
of Logic. North-Holland, zooj, pp. z 81. doi: 10.1016/S1874-
5857(09)70018-4 (cit. on p. 1).
[] John Cartmell. Generalised algebraic theories and contextual categor-
ies. In: Annals of Pure and Applied Logic (1j86), pp. zzoj. doi: 10.
1016/0168-0072(86)90053-9 (cit. on p. 1).
[] Alonzo Church. A set of postulates for the foundation of logic. In: The
Annals of Mathematics .z (Apr. 1jz), pp. 666. doi: 10.2307/
2371045 (cit. on pp. 1, z).
[6] Alonzo Church. A Formulation of the Simple Theory of Types. In: J.
Symb. Logic .z (June 1jo), pp. 668 (cit. on pp. 1, z).
[] Thierry Coquand. An Algorithm for Type-Checking Dependent Types.
In: Proc. of the rd Int. Conf. on Mathematics of Program Construction,
MPC . Vol. z6. Sci. Comput. Program. 1. Elsevier, May 1jj6,
pp. 161 (cit. on pp. 1, 88, jo).
[8] Thierry Coquand. Type Theory. In: The Stanford Encyclopedia of Philo-
sophy. Ed. by Edward N. Zalta. Spring zo1o. zo1o (cit. on p. 1).
[j] Thierry Coquand and Peter Dybjer. Intuitionistic model constructions
and normalization proofs. In: Mathematical. Structures in Comp. Sci. .1
(1jj), pp. j. issn: oj6o-1zj. doi: 10.1017/S0960129596002150
(cit. on p. 1).
[o] Thierry Coquand, Peter Dybjer, Erik Palmgren and Anton Setzer. Type-
theoretic Foundations of Constructive Mathematics. Tech. rep. Types Sum-
mer School, zoo (cit. on p. ).
[1] Thierry Coquand and Gerard Huet. The calculus of constructions. In:
Inf. Comput. 6.z- (1j88), pp. j1zo. issn: o8jo-o1. doi: 10.1016/
0890-5401(88)90005-3 (cit. on p. ).
[z] Thierry Coquand, Randy Pollack and Makoto Takeyama. A Logical
Framework with Dependently Typed Records. In: Fundamenta Inform-
aticae 6.1-z (zoo), pp. 111 (cit. on pp. z8, , 6).
[] Judical Courant. Strong Normalization with Singleton Types. In:
Intersection Types and Related Systems (ITRS oo). Vol. o. Electr. Notes
in Theor. Comp. Sci. 1. Elsevier, zooz (cit. on p. 6o).
BIBLIOGRAPHY 1
[] Guy Cousineau, Pierre-Louis Curien and Michel Mauny. The categor-
ical abstract machine. In: Science of Computer Programming 8.z (1j8),
pp. 1 zoz. issn: o16-6z. doi: 10.1016/0167-6423(87)90020-7
(cit. on p. 18).
[] Guy Cousineau, Pierre-Louis Curien and Bernard Robinet, eds. Combin-
ators and Functional Programming Languages, Thirteenth Spring School of
the LITP, Val dAjol, France, May 6-:o, :8, Proceedings. Vol. zz. Lec-
ture Notes in Computer Science. Springer, 1j86. isbn: -o-118-
(cit. on p. 1).
[6] Karl Crary. A Syntactic Account of Singleton Types via Hereditary Sub-
stitution. In: th Int. Wksh. on Logical Frameworks and Meta-languages:
Theory and Practice (LFMTP oo). Ed. by James Cheney and Amy Felty.
ACM Press, zooj, pp. z1zj. isbn: j8-1-6o8-zj-1. doi: 10.1145/
1577824.1577829 (cit. on p. 6o).
[] Pierre-Louis Curien. Categorical combinators, sequential algorithms, and
functional programming. Progress in theoretical computer science. Birk-
huser, 1jj. isbn: j8o81668 (cit. on p. 1).
[8] H. B. Curry. Functionality in Combinatory Logic. In: Proceedings of
the National Academy of Sciences, U.S.A. zo (1j), pp. 8jo (cit. on
p. z).
[j] Haskell B. Curry. Modied basic functionality in combinatory logic. In:
Dialectica z.z (1j6j), pp. 8jz. issn: 16-861. doi: 10.1111/j.1746-
8361.1969.tb01183.x (cit. on p. z).
[o] Haskell B. Curry and Robert Feys. Combinatory logic. North-Holland
publishing Company, 1j8 (cit. on p. z).
[1] Peter Dybjer. Internal Type Theory. In: TYPES : Selected papers from
the International Workshop on Types for Proofs and Programs. London,
UK: Springer-Verlag, 1jj6, pp. 1zo1. isbn: -o-618o-j (cit. on
pp. j, o).
[z] Peter Dybjer. A General Formulation of Simultaneous Inductive-Recur-
sive Denitions in Type Theory. In: J. Symb. Logic 6.z (zooo), pp. z
j (cit. on pp. , 6j).
[] Peter Dybjer and Denis Kuperberg. Formal neighbourhoods, combin-
atory Bhm trees, and untyped normalization by evaluation. In: Ann.
Pure Appl. Logic 16.z (zo1z), pp. 1zz11. doi: 10.1016/j.apal.2011.
06.021 (cit. on p. 1z6).
[] Andrzej Filinski. Normalization by Evaluation for the Computational
Lambda-Calculus. In: TLCA. zoo1, pp. 1116. doi: 10.1007/3-540-
45413-6_15 (cit. on pp. 1, z).
[] Andrzej Filinski and Henning Korsholm Rohde. A Denotational Ac-
count of Untyped Normalization by Evaluation. In: FoSSaCS. Ed. by
Igor Walukiewicz. Vol. zj8. Lecture Notes in Computer Science. Sprin-
ger, zoo, pp. 16181. isbn: -o-z1zj8-1. doi: 10.1007/978-3-540-
24727-2_13 (cit. on pp. z6, 1z6).
1 BIBLIOGRAPHY
[6] Marcelo Fiore. Semantic analysis of normalisation by evaluation for
typed lambda calculus. In: PPDP o: Proceedings of the th ACM SIG-
PLAN international conference on Principles and practice of declarative
programming. Pittsburgh, PA, USA: ACM, zooz, pp. z6. isbn: 1-
811-z8-j. doi: 10.1145/571157.571161 (cit. on p. 1).
[] Daniel Fridlender and Miguel Pagano. PTS with Typed Equality and
Explicit Substitutions. Presentation at Types for Proofs and Programs
zo11. Sept. zo11 (cit. on p. 1).
[8] Franois Garillot and Benjamin Werner. Simple Types in Type Theory:
Deep and Shallow Encodings. In: Theorem Proving in Higher Order
Logics, TPHOLs oo. Ed. by Klaus Schneider and Jens Brandt. Vol. z.
Lect. Notes in Comput. Sci. Springer, zoo, pp. 688z. isbn: j8--
o-jo-. doi: 10.1007/978-3-540-74591-4_27 (cit. on p. z6).
[j] Herman Geuvers. Logics and Type Systems. PhD thesis. Katholieke
Universiteit Nijmegen, Sept. 1jj (cit. on pp. 1, 1oj).
[6o] Herman Geuvers. Proof assistants: History, ideas and future. English.
In: Sadhana (1 zooj), pp. z. issn: oz6-zjj. doi: 10.1007/
s12046-009-0001-5 (cit. on p. 6).
[61] Jean-Yves Girard. Une extension de linterpretation de Godel a lana-
lyse, et son application a lelimination des coupures dans lanalyse et
la theorie des types. In: Second Scandinavian Logic Symposium. Ed. by
Jens Erik Fenstad. Studies in Logic and the Foundations of Mathematics
6. North-Holland, 1j1, pp. 6jz (cit. on p. ).
[6z] Benjamin Grgoire and Xavier Leroy. A compiled implementation
of strong reduction. In: Proc. of the th ACM SIGPLAN Int. Conf. on
Functional Programming (ICFP o). Vol. . SIGPLAN Notices j. ACM
Press, Sept. zooz, pp. zz6. isbn: 1-811-8-8. doi: 10.1145/
581478.581501 (cit. on p. z).
[6] Robert Harper, Furio Honsell and Gordon Plotkin. A framework for
dening logics. In: Journal ofACM Press o.1 (1jj), pp. 118. issn:
ooo-11. doi: 10.1145/138027.138060 (cit. on p. ).
[6] Robert Harper and Frank Pfenning. On equivalence and canonical
forms in the LF type theory. In: ACM Trans. Comput. Logic 6.1 (zoo),
pp. 611o1. issn: 1zj-8. doi: 10.1145/1042038.1042041 (cit. on
p. 1).
[6] John Harrison. HOL Light: An Overview. In: TPHOLs. Ed. by Stefan
Berghofer, Tobias Nipkow, Christian Urban and Makarius Wenzel.
Vol. 6. Lecture Notes in Computer Science. Springer, zooj, pp. 6o
66. isbn: j8--6z-o8-z. doi: 10.1007/978- 3- 642- 03359- 9_4
(cit. on p. z).
[66] Leon Henkin. Completeness in the Theory of Types. In: The Journal
of Symbolic Logic 1 (1jo), pp. 81j1. issn: oozz81z. url: http :
//www.jstor.org/stable/2266967 (cit. on p. 1z).
[6] Arend Heyting. Intuitionism, an Introduction. rd ed. Amsterdam: North-
Holland, 1j1. isbn: o-zo-zzj-6 (cit. on p. ).
BIBLIOGRAPHY 1
[68] Roger J. Hindley. The Principal Type-Scheme of an Object in Com-
binatory Logic. In: Transactions of the American Mathematical Society
16 (1j6j), pp. zj6o. issn: ooozjj. url: http://www.jstor.org/
stable/1995158 (cit. on p. z).
[6j] William Howard. The formulae-as-types notion of construction. In: To
H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism.
Ed. by Haskell Curry, Jonathan Seldin and Roger Hindley. Academic
Press, 1j8o, pp. jjo. isbn: o1zjooz (cit. on pp. , ).
[o] Grard P. Huet. Cartesian closed Categories and Lambda- calculus. In:
Combinators and Functional Programming Languages. 1j8, pp. 1z1.
doi: 10.1007/3-540-17184-3_43 (cit. on p. z).
[1] Fairouz Kamareddine, Twan Laan and Rob Nederpelt. A Modern Per-
spective on Type Theory From its Origins Until Today. Vol. zj. Applied
Logic Series. Kluwer Academic Publishers, May zoo. isbn: 1ozozo
(cit. on p. 1).
[z] Delia Kesner. A Theory of Explicit Substitutions with Safe and Full
Composition. In: Logical Methods in Computer Science . (zooj). doi:
10.2168/LMCS-5(3:1)2009 (cit. on p. 11).
[] Stephen C. Kleene and John Barkley Rosser. The Inconsistency of
Certain Formal Logics. In: The Annals of Mathematics 6. (July 1j),
pp. 6o66 (cit. on p. z).
[] J. Lambek and P. J. Scott. Introduction to higher order categorical logic.
New York, NY, USA: Cambridge University Press, 1j88. isbn: o-z1-
6-j (cit. on pp. , z).
[] Daniel K. Lee, Karl Crary and Robert Harper. Towards a Mechanized
Metatheory of Standard ML. In: Proc. of the th ACM Symp. on Prin-
ciples of Programming Languages, POPL oo. Ed. by Martin Hofmann
and Matthias Felleisen. ACM Press, zoo, pp. 118. isbn: 1-jj-
-. doi: 10.1145/1190216.1190245 (cit. on p. ).
[6] Andreas Lh, Conor McBride and Wouter Swierstra. A Tutorial Imple-
mentation of a Dependently Typed Lambda Calculus. In: Fundamenta
Informaticae 1oz.z (zo1o), pp. 1zo. doi: 10.3233/FI-2010-304
(cit. on p. jo).
[] Zhaohui Luo. An Extended Calculus of Constructions. PhD thesis.
Department of Computer Science, University of Edinburgh, June 1jjo.
url: http://www.cs.rhul.ac.uk/~zhaohui/THESIS90.ps (cit. on p. 1).
[8] Zhaohui Luo. Computation and reasoning: a type theory for computer
science. International series of monographs on computer science. Clar-
endon Press, 1jj. isbn: j8o1j886 (cit. on pp. o, ).
[j] Odalric-Ambrym Maillard. Proof-irrelevance, strong-normalisation in
Type-Theory and PER. Tech. rep. Chalmers Institute of Technology, zoo6
(cit. on p. 61).
[8o] Per Martin-Lf. An Intuitonistic Theory of Types: Predicative Part.
English. In: ed. by H. E. Rose and J. C. Shepherdson. North-Holland
Pub. Co., 1j, pp. 118. isbn: o1o6z1 (cit. on pp. 1, o).
16 BIBLIOGRAPHY
[81] Per Martin-Lf. Intuitionistic Type Theory. Bibliopolis, 1j8 (cit. on
pp. , j).
[8z] Per Martin-Lf. On the Meanings of the Logical Constants and the
Justication of the Logical Laws. In: Nordic Journal of Philosophical
Logic 1.1 (1jj6), pp. 116o (cit. on p. ).
[8] Per Martin-Lf. An intuitionistic theory of types. In: Oxford logic
guides. reprinted version of an unpublished report from 1jz. Claren-
don Press, 1jj8. isbn: j8o1j8o1z (cit. on pp. 1, , j).
[8] The Agda Team. The Agda Wiki. url: http://wiki.portal.chalmers.
se/agda/ (cit. on p. ).
[8] The Coq development team. The Coq proof assistant reference manual.
Version 8.o. zoo. url: http://coq.inria.fr (cit. on p. ).
[86] Robin Milner. A theory of type polymorphism in programming. In:
Journal of Computer and System Sciences 1. (1j8), pp. 8. doi:
10.1016/0022-0000(78)90014-4 (cit. on p. ).
[8] Alexandre Miquel and Benjamin Werner. The Not So Simple Proof-
Irrelevant Model of CC. In: TYPES. Ed. by Herman Geuvers and Freek
Wiedijk. Vol. z66. Lecture Notes in Computer Science. Springer, zooz,
pp. zoz8. isbn: -o-1o1-X (cit. on p. 1o1).
[88] John C. Mitchell. A type-inference approach to reduction properties
and semantics of polymorphic expressions (summary). In: LFP 86: Pro-
ceedings of the :86 ACM conference on LISP and functional programming.
Cambridge, Massachusetts, United States: ACM, 1j86, pp. o81j.
isbn: o-8jj1-zoo-. doi: 10.1145/319838.319872 (cit. on p. z8).
[8j] John C. Mitchell. Type Systems for Programming Languages. In: Hand-
book of Theoretical Computer Science, Volume B: Formal Models and Semat-
ics (B). 1jjo, pp. 68 (cit. on p. 6).
[jo] John C. Mitchell. Foundations of programming languages. Cambridge,
MA, USA: MIT Press, 1jj6. isbn: o-z6z-1z1-o (cit. on p. 1).
[j1] John C. Mitchell and Eugenio Moggi. Kripke-style models for typed
lambda calculus. In: Annals of Pure and Applied Logic 1.1-z (1jj1),
pp. jj 1z. issn: o168-ooz. doi: 10.1016/0168-0072(91)90067-V
(cit. on p. 1).
[jz] Csar Muoz. Dependent types and explicit substitutions. Tech. rep. Insti-
tute for Computer Applications in Science and Engineering (ICASE),
1jjj (cit. on pp. 1o1, 1oz).
[j] Tobias Nipkow, Lawrence C. Paulson and Markus Wenzel. Isabelle/HOL
A Proof Assistant for Higher-Order Logic. Vol. zz8. LNCS. Springer,
zooz (cit. on p. z).
[j] Bengt Nordstrm, Kent Petersson and Jan M. Smith. Programming in
Martin Lfs Type Theory: An Introduction. Clarendon Press, Oxford,
1jjo (cit. on p. j).
[j] Nicolas Oury and Wouter Swierstra. The power of Pi. In: ICFP. Ed. by
James Hook and Peter Thiemann. ACM, zoo8, pp. jo. isbn: j8-1-
jj-j1j- (cit. on p. 1).
BIBLIOGRAPHY 1
[j6] Frank Pfenning. On a Logical Foundation for Explicit Substitutions.
In: TLCA. Ed. by Simona Ronchi Della Rocca. Vol. 8. Lecture Notes
in Computer Science. Slides available at http://www.cs.cmu.edu/~fp/
talks/rdp07-talk.pdf. Springer, zoo, p. 1. isbn: j8--o-zz-.
doi: 10.1007/978-3-540-73228-0_1 (cit. on p. 11).
[j] Randy Pollack. The Theory of LEGO. PhD thesis. Department of Com-
puter Science, University of Edinburgh, 1jj. url: http://homepages.
inf.ed.ac.uk/rpollack/export/thesis.ps.gz (cit. on p. 1).
[j8] John C. Reynolds. Towards a Theory of Type Structure. In: Lecture
Notes in Computer Science. Vol. 1j. New York: Springer-Verlag, 1j,
pp. o8z (cit. on p. ).
[jj] John C. Reynolds. What do types mean?: from intrinsic to extrinsic
semantics. In: New York, NY, USA: Springer-Verlag New York, Inc.,
zoo, pp. ojz. isbn: o-8-jj- (cit. on p. z).
[1oo] Giovanni Sambin and Jan M. Smith. Twenty-ve years of constructive
type theory: proceedings of a congress held in Venice, October :. Oxford
logic guides. Clarendon Press, 1jj8. isbn: j8o1j8o1z.
[1o1] Giovanni Sambin and Silvio Valentini. Building up a toolbox for
Martin-Lfs type theory: subset theory. In: Oxford logic guides. Clar-
endon Press, 1jj8, pp. zz1z. isbn: j8o1j8o1z (cit. on p. ).
[1oz] Dana Scott. Continuous Lattices. Tech. rep. Oxford University, 1j1
(cit. on p. z).
[1o] Natarajan Shankar and Sam Owre. Principles and Pragmatics of Sub-
typing in PVS. In: WADT : Selected papers from the :th International
Workshop on Recent Trends in Algebraic Development Techniques. Lon-
don, UK: Springer-Verlag, zooo, pp. z. isbn: -o-68j8-o (cit. on
p. ).
[1o] Vincent Siles. Investigation on the typing of equality in type systems.
PhD thesis. cole Polytechnique, Nov. zo1o. url: http://www.cse.
chalmers.se/~siles/papers/thesis.pdf (cit. on pp. 1, 1, 1o1, 1oj).
[1o] Vincent Siles and Hugo Herbelin. Equality Is Typable in Semi-full Pure
Type Systems. In: LICS. IEEE Computer Soc. Press, zo1o, pp. z1o.
isbn: j8-o-6j-11-. doi: 10.1109/LICS.2010.19 (cit. on pp. 1,
1oj).
[1o6] Michael B. Smyth and Gordon D. Plotkin. The Category-Theoretic Solu-
tion of Recursive Domain Equations. In: SIAM Journal on Computing
11. (1j8z), pp. 618. doi: 10.1137/0211062 (cit. on p. z).
[1o] Matthieu Sozeau. Subset Coercions in Coq. In: Types for Proofs and
Programs, Int. Wksh., TYPES oo6. Ed. by Thorsten Altenkirch and
Conor McBride. Vol. oz. Lect. Notes in Comput. Sci. Springer, zoo,
pp. zzz. isbn: j8--o-6-. doi: 10.1007/978-3-540-74464-
1_16 (cit. on p. ).
[1o8] Christopher A. Stone and Robert Harper. Extensional equivalence and
singleton types. In: ACM Trans. Comput. Logic . (zoo6), pp. 66zz.
issn: 1zj-8. doi: 10.1145/1183278.1183281 (cit. on p. 1).
18 BIBLIOGRAPHY
[1oj] Christopher A. Stone and Robert Harper. Extensional Equivalence and
Singleton Types. In: ACM Trans. Comput. Logic . (zoo6), pp. 66zz.
issn: 1zj-8. doi: 10.1145/1166109.1166112 (cit. on p. ).
[11o] Thomas Streicher. Correctness and Completeness of a Categorical
Semantics of the Calculus of Constructions. PhD thesis. Universitt
Passau, Passau, West Germany, June 1j8j (cit. on p. 1o1).
[111] Morten Heine Srensen and Pawe Urzyczyin. Lectures on the Curry-
Howard Isomorphism. Vol. 1j. Studies in Logic and the Foundations of
Mathematics. Elsevier, zoo6 (cit. on p. 1).
[11z] Alvaro Tasistro. Formulation of Martin-Lfs theory of types with explicit
substitutions. Published in [11]. 1jj (cit. on p. 11).
[11] Alvaro Tasistro. Substitution, Record Types and Subtyping in Type
Theory, with Applications to the Theory of Programming. PhD thesis.
Gteborg University and Chalmers Institute of Technology, 1jj (cit.
on p. 18).
[11] Jan Terlouw. Een nadere bewijstheoretische analyse van GSTTs. Tech. rep.
University of Nijmegen, 1j8j (cit. on p. ).
[11] Anne S. Troelstra. History of Constructivism in the Twentieth Century.
ITLI Prepublication Series ML-j1-o. University of Amsterdam, 1jj1
(cit. on p. ).
[116] Benjamin Werner. On the strength of proof-irrelevant type theories.
In: Logical Methods in Computer Science (zoo8) (cit. on p. ).
[11] Freek Wiedijk. The De Bruijn Factor. In: TPHOLs ooo: Supplemental
Proceedings. Ed. by M. Aargaard, J. Harrison and T. Schubert. OGI
Technical Report CSE oo-ooj. Oregon Graduate Institute, Portland,
USA. July zooo, pp. z1zo. url: http://www.cs.ru.nl/~freek/
factor/factor.pdf (cit. on p. 1z).
[118] Freek Wiedijk, ed. The Seventeen Provers of the World, Foreword by Dana
S. Scott. Vol. 6oo. Lecture Notes in Computer Science. Springer, zoo6.
isbn: -o-oo- (cit. on p. 6).
[11j] Freek Wiedijk. Formal Proof Getting Started. In: Notices of the Amer-
ican Mathematical Society (zoo8), pp. 1o811 (cit. on p. 6).
This thesis was typeset in pdfL
A
T
E
X.
The design is based on the memoir class, with some personal modications.
The body text is set on the typeface Johannes Kepler, designed by Christophe
Caignaert.
Mathematical content is set on Euler, by Hermann Zapf, and Computer
Modern, by Donald Knuth, as provided by the euler-vm package.
Programs are listed on Inconsolata by Raph Levien.
Rules and derivations are typeset using Paul Taylors prooftree and Didier
Rmys mathpartir.