~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to notes/typechecking/core.tex

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-08-05 06:38:12 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140805063812-io8e77niomivhd49
Tags: 2.4.0.2-1
* [6e140ac] Imported Upstream version 2.4.0.2
* [2049fc8] Update Build-Depends to match control
* [93dc4d4] Install the new primitives
* [e48f40f] Fix typo dev→doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
% Specification of agdaLight
2
 
% Author: Thierry Coquand
3
 
 
4
 
%\documentclass[12pt,a4paper]{amsart}
5
 
\documentclass[11pt]{article}
6
 
 
7
 
\newcommand{\mkbox}[1]{\ensuremath{#1}}
8
 
 
9
 
\newcommand{\pair}[1]{{\langle #1 \rangle}}
10
 
 
11
 
\usepackage{amsthm}
12
 
\newtheorem{theorem}{Theorem}[section]
13
 
\newtheorem{lemma}[theorem]{Lemma}
14
 
\newtheorem{corollary}[theorem]{Corollary}
15
 
\newtheorem{definition}[theorem]{Definition}
16
 
 
17
 
 
18
 
\usepackage{epsf}
19
 
\usepackage{epsfig}
20
 
%\usepackage{isolatin1}
21
 
%\usepackage{a4wide}
22
 
\usepackage{verbatim}
23
 
\usepackage{proof}
24
 
\usepackage{latexsym}
25
 
\usepackage{amssymb}
26
 
\usepackage{stmaryrd}
27
 
 
28
 
% evaluation
29
 
\newcommand{\evObj}[2]{\mkbox{#1{\downarrow}#2}}
30
 
\newcommand{\evTyp}[2]{\mkbox{#1{\uparrow}#2}}
31
 
\newcommand{\evPr}[2]{\mkbox{#1{\updownarrow}#2}}
32
 
 
33
 
%\documentstyle{article}
34
 
 
35
 
\setlength{\oddsidemargin}{0in} % so, left margin is 1in
36
 
\setlength{\textwidth}{6.27in} % so, right margin is 1in
37
 
\setlength{\topmargin}{0in} % so, top margin is 1in
38
 
\setlength{\headheight}{0in}
39
 
\setlength{\headsep}{0in}
40
 
\setlength{\textheight}{9.19in} % so, foot margin is 1.5in
41
 
\setlength{\footskip}{.8in}
42
 
 
43
 
% Definition of \placetitle
44
 
% Want to do an alternative which takes arguments
45
 
% for the names, authors etc. 
46
 
 
47
 
\def\fin{\enspace\vbox{\hrule\hbox{\vrule\kern4pt
48
 
\vbox{\kern4pt\kern4pt}\kern4pt\vrule}\hrule}} 
49
 
 
50
 
\def\ZZ{\hbox{\sf Z}}
51
 
\def\DD{\hbox{\sf D}}
52
 
\def\Ex{\hbox{\sf E}}
53
 
\def\FUN{\hbox{\sf Fun}}
54
 
\def\TOP{\nabla}
55
 
\def\TOT{{\cal T}}
56
 
\def\fun{\hbox{\sf fun}}
57
 
\def\SET{\hbox{\sf Set}}
58
 
\def\BSET{\hbox{\sf Bset}}
59
 
\def\EL{\hbox{\sf El}}
60
 
\def\PROOF{\hbox{\sf Prf}}
61
 
\def\NAT{\hbox{\sf Nat}}
62
 
\def\INTRO{\hbox{\sf intro}}
63
 
\def\ELIM{\hbox{\sf elim}}
64
 
\def\NATREC{\hbox{\sf natrec}}
65
 
\def\BOOLREC{\hbox{\sf boolrec}}
66
 
\def\LISTREC{\hbox{\sf listrec}}
67
 
\def\LIST{\hbox{\sf List}}
68
 
\def\ZERO{\hbox{\sf O}}
69
 
\def\SUCC{\hbox{\sf succ}}
70
 
\def\NIL{\hbox{\sf nil}}
71
 
\def\CONS{\hbox{\sf cons}}
72
 
\def\BOOL{\hbox{\sf Bool}}
73
 
\def\TRUE{\hbox{\sf true}}
74
 
\def\FALSE{\hbox{\sf false}}
75
 
\def\correct{\hbox{\sf correct}}
76
 
\def\fits{~\hbox{\sf fits}~}
77
 
\def\subtype{\sqsubseteq}
78
 
\def\fills{~\hbox{\sf fills}~}
79
 
\def\prop{o}
80
 
\newcommand\object[1]{{<}#1{>}}
81
 
\newcommand\env[1]{(#1)}
82
 
\def\spec{\sqsubseteq}
83
 
\def\Def{{\sf def}}
84
 
\def\Undef{{\sf undef}}
85
 
\def\cont{\hbox {\sf cont}}
86
 
\newcommand\coerce[2]{#1/#2}
87
 
\def\implies{\Longrightarrow}
88
 
\def\tel{\hbox {\sf tel}}
89
 
\def\case{\hbox {\sf case}}
90
 
\def\data{\hbox {\sf data}}
91
 
\def\rec{\hbox {\sf rec}}
92
 
\def\val{\hbox {\sf val}}
93
 
\def\CC{\hbox{\sf C}}
94
 
\def\hd{\hbox{\sf hd}}
95
 
\def\tl{\hbox{\sf tl}}
96
 
\def\Pos{\hbox{\sf Pos}}
97
 
\def\NN{\hbox{\sf N}}
98
 
\def\nat{\hbox{\sf nat}}
99
 
\def\add{\hbox{\sf add}}
100
 
\def\Pt{\hbox{\sf Pt}}
101
 
%global environments
102
 
\newcommand{\EnvDfn}[3]{\mkbox{#1+#2{=}#3}}
103
 
\newcommand{\EnvDcl}[4]{\mkbox{#1+#2{:}#3{=}#4}}
104
 
\newcommand{\EnvMty}{\mkbox{[]}}
105
 
 
106
 
% typed equality
107
 
\newcommand{\teq}[3]{\mkbox{#1=#2:#3}}
108
 
\newcommand{\subtyp}[2]{\mkbox{#1\sesubseteq #2}}
109
 
%\newcommand{\proj}[2]{\mkbox{\msf{proj}_{#1}#2}}
110
 
%\newcommand{\sig}[3]{\mkbox{<\!\!#1:#2\!\!>#3}}
111
 
\newcommand{\product}[3]{\{#1:#2\}#3}
112
 
\newcommand{\Adh}[1]{\bar{#1}}
113
 
\newcommand{\entails}{\vdash}
114
 
 
115
 
\newcommand{\covers}{\lhd}
116
 
\newcommand{\Cov}{\hbox{\sf Cov}}
117
 
\newcommand{\cover}{\lhd}
118
 
\def\cov{\hbox{\sf Cov}}
119
 
 
120
 
\newcommand{\arrow}{\mbox {$\rightarrow$}}
121
 
\newcommand{\inv}[1]{#1^{-1}}
122
 
\newcommand{\OO}{\hbox{\cal O}}
123
 
\newcommand{\MM}{\hbox{\cal M}}
124
 
\newcommand{\R}{\hbox{\bf R}} 
125
 
\newcommand{\RR}{\hbox{\bf R}} 
126
 
\newcommand{\LL}{\hbox{\bf L}} 
127
 
\newcommand{\Type}{\hbox{\bf Type}} 
128
 
\newcommand{\kind}{\hbox{\bf kind}} 
129
 
\newcommand{\Sig}{\hbox{\bf Sig}} 
130
 
\newcommand{\type}{\hbox{\bf type}} 
131
 
\newcommand{\sig}{\hbox{\bf sig}} 
132
 
\newcommand{\RType}{\hbox{\bf RType}} 
133
 
\newcommand{\Kind}{\hbox{\bf Kind}} 
134
 
 
135
 
%\newcommand{\nil}{\mbox{$<\!>$}}
136
 
%\newcommand{\abs}[1]{\mbox{$<\!#1\!>$}}
137
 
 
138
 
\newcommand{\nil}{\mbox{$\{\}$}}
139
 
\newcommand{\abs}[1]{\mbox{$\{#1\}$}}
140
 
\newcommand{\abst}[1]{\mbox{$\{\!|#1|\!\}$}}
141
 
%\newcommand{\lbr}{\lbrack\!\lbrack}
142
 
\newcommand{\lbr}{\mathopen{\lbrack\!\lbrack}}
143
 
%\newcommand{\rbr}{\rbrack\!\rbrack}
144
 
\newcommand{\rbr}{\mathopen{\rbrack\!\rbrack}}
145
 
%\newcommand{\sem}[1]{\mbox{$\lbr #1 \rbr$}}
146
 
%\newcommand{\sem}[1]{{\lbr #1 \rbr}}
147
 
%\newcommand{\typ}[1]{{(\!| #1 |\!)}}
148
 
\newcommand{\sem}[1]{#1}
149
 
\newcommand{\hypEl}[3]{#2{:}#3~[#1]}
150
 
\newcommand{\hypFa}[3]{#2{:}#3~[#1]}
151
 
\newcommand{\hypEq}[4]{#2=#3{:}#4~[#1]}
152
 
\newcommand{\hypSu}[3]{#2\subseteq #3~[#1]}
153
 
\newcommand{\hypTy}[2]{#2~\type~[#1]}
154
 
\newcommand{\hypKi}[2]{#2~\kind~[#1]}
155
 
\newcommand{\hypSi}[2]{#2~\sig~[#1]}
156
 
\newcommand{\typ}[1]{#1|}
157
 
\newcommand{\proj}[2]{\eta ~{#1}~{#2}}
158
 
\newcommand{\Fun}[2]{{\sf Fun}~{#1}~{#2}}
159
 
\newcommand{\Sum}[2]{{\sf Sum}~{#1}~{#2}}
160
 
\newcommand{\Elem}[1]{{\sf El}~{#1}}
161
 
\newcommand{\STAR}{*}
162
 
 
163
 
\begin{document}
164
 
 
165
 
 
166
 
\title{Presentation of core agda}
167
 
 
168
 
\author{Thierry Coquand and Makoto Takeyama}
169
 
\date{\today}
170
 
\maketitle
171
 
\title{}
172
 
 
173
 
\section*{Introduction}
174
 
 
175
 
 We present the typing system of core agda.
176
 
 
177
 
 The syntax of the core version is the one of pure lambda-calculus with constants
178
 
$$ M ~::=~ n~|~M~M~|~\lambda x.M~~~~~~~~~~n~::=~x~|~f~|~c$$
179
 
 
180
 
 There are two kind of constants: {\em primitive} $c$ or {\em defined} $f$. The definition
181
 
of $f$ may be {\em explicit}, of the form $f=M$, or {\em implicit}. It is then defined recursively
182
 
using pattern-matching equations.
183
 
 
184
 
 We can define a priori $\beta,\iota$ conversion on terms.
185
 
 
186
 
 The typing rules are essentially the one of Martin-L\"of Logical Framework. 
187
 
The difference with his presentation is that substitution is taken as granted on
188
 
$\lambda$ terms.
189
 
 
190
 
\section{The language}
191
 
 
192
 
 Defined constants $f$ are defined by equations (computation rules) of the form
193
 
$$f~x_1~\dots~x_n~(c~y_1~\dots~y_k)\rightarrow M$$
194
 
that we shall write
195
 
$$f~{\bf x}~(c~{\bf y})\rightarrow M$$
196
 
 
197
 
 Each constant has an arity $ar(f) = n+1,ar(c)=k$. We write $h,h',\dots$ for a constant $f$ or $c$
198
 
 
199
 
 We define {\em conversion} to be the equality generated by the usual $\beta$ rules and
200
 
the computation rules for constants, called $\iota$ rules. It is standard that $\beta,\iota$
201
 
reduction is confluent. We write $M = N$ to say that $M$ and $N$ are convertible.
202
 
 
203
 
 We assume given constants $\FUN,\SET,\EL$. We write $(x{:}A)\rightarrow B$ instead of
204
 
$\FUN~A~(\lambda x.B)$, and we write $A\rightarrow B$ for $\FUN~A~(\lambda x.B)$ if $x$
205
 
is not free in $B$. %Similarly we write $\lambda x{:}A.B$ for $\fun~A~(\lambda x.M)$.
206
 
We write $N(x=M)$ the result of substituting the free occurences of $x$ by $M$ in $N$
207
 
and may write it $N[M]$ if $x$ is clear from the context.
208
 
We consider terms up to $\alpha$-conversion.
209
 
 
210
 
\section{Typing rules}
211
 
 
212
 
 We have three syntactical categories, for {\em types} $A,B,\dots$, for
213
 
{\em terms} $M,N,\dots$ and for {\em contexts} $\Gamma,\Delta,\dots$ We have
214
 
a special type $\SET$ of (data) types, i.e. primitive types given with
215
 
constructors. The syntax is
216
 
$$\begin{array}{lclr}
217
 
A  & ::= & \SET~|~El~M~|~(x{:}A)\rightarrow A  & types \\
218
 
M & ::= & x~|~M~M~|~\lambda x.M & terms \\
219
 
\Gamma & ::= & ()~|~\Gamma,x{:}A & contexts
220
 
\end{array}$$
221
 
 
222
 
 There are five kinds of judgement $\Delta\vdash,~\Delta\vdash A,~\Delta\vdash M:A,~\Delta\vdash A_1=A_2$
223
 
and $\Delta\vdash M_1=M_2:A$.
224
 
The first $\Delta\vdash$ expresses that $\Delta$ is a correct context. 
225
 
 
226
 
 The typing rules are as follows:
227
 
 
228
 
\medskip
229
 
 {\em rules for contexts}
230
 
 
231
 
$$
232
 
\frac{}{\vdash}~~~~
233
 
\frac{\Gamma\vdash~~~~~\Gamma\vdash A}{\Gamma,x{:}A\vdash}
234
 
$$
235
 
 
236
 
 {\em rules for types}
237
 
 
238
 
$$
239
 
\frac{\Gamma\vdash}{\Gamma\vdash \SET}~~~~
240
 
\frac{\Gamma\vdash M:\SET}{\Gamma\vdash \EL~M}~~~~~~
241
 
\frac{\Gamma,x{:}A\vdash B}{\Gamma\vdash (x{:}A)\rightarrow B}
242
 
$$
243
 
 
244
 
 {\em rules for terms}
245
 
 
246
 
$$
247
 
\frac{\Gamma\vdash~~~~~(x{:}A)~\in~\Gamma}{\Gamma\vdash x{:}A}~~~~~~~~~
248
 
\frac{\Gamma,x{:}A\vdash M:B}{\Gamma\vdash \lambda x.M:(x{:}A)\rightarrow B}~~~~~~
249
 
\frac{\Gamma\vdash M:(x{:}A)\rightarrow B~~~~\Gamma\vdash N:A}{\Gamma\vdash M~N:B(x=N)}
250
 
$$
251
 
 
252
 
 {\em conversion rule}
253
 
 
254
 
$$
255
 
\frac{\Gamma\vdash M:A~~~~\Gamma\vdash A=B}{\Gamma\vdash M:B}
256
 
$$
257
 
 
258
 
\medskip
259
 
\medskip
260
 
 
261
 
 
262
 
 The general conversion rules are
263
 
 
264
 
$$
265
 
\frac{\Gamma\vdash A}{\Gamma\vdash A=A}~~~~~~
266
 
\frac{\Gamma\vdash A=B}{\Gamma\vdash B=A}~~~~~~
267
 
\frac{\Gamma\vdash A=B~~~\Gamma\vdash B=C}{\Gamma\vdash A=C}
268
 
$$
269
 
 
270
 
$$
271
 
\frac{\Gamma\vdash M:A}{\Gamma\vdash M=M:A}~~~~~
272
 
\frac{\Gamma\vdash M=N:A}{\Gamma\vdash N=M:A}~~~~
273
 
\frac{\Gamma\vdash M=N:A~~~~\Gamma\vdash N=P:A}{\Gamma\vdash M=P:A}
274
 
$$
275
 
 
276
 
$$
277
 
\frac{\Gamma\vdash M=N:A~~~~~\Gamma\vdash A = B}
278
 
     {\Gamma\vdash M=N:B}
279
 
$$
280
 
 
281
 
$$
282
 
\frac{\Gamma,x{:}A\vdash B~~~~~\Gamma\vdash M_1=M_2:A}
283
 
     {\Gamma\vdash B(x=M_1) = B(x=M_2)}
284
 
$$
285
 
 
286
 
\medskip
287
 
 
288
 
 The last rule expresses
289
 
that a family of types depends in an extensional way of its argument. 
290
 
It may be admissible, but it simplifies the metatheory to take
291
 
it as primitive. One could think
292
 
of including the substitution rule as well, for instance
293
 
the fact that $\Gamma\vdash B_1(x=M)=B_2(x=M)$
294
 
follows from $\Gamma\vdash M:A$ and $\Gamma,x{:}A\vdash B_1=B_2$.
295
 
As we shall see
296
 
below, the substitution rule is directly admissible. Furthermore, to include the substitution as a
297
 
rule may complicate some arguments, especially for proving {\em inversion} lemmas. It is
298
 
direct now that $\Gamma\vdash (x{:}A)\rightarrow B$ implies $\Gamma\vdash A$ and
299
 
$\Gamma,x{:}A\vdash B$. This would be a little more complicated to prove in presence of
300
 
a substitution rule.
301
 
 
302
 
 The conversion rules for type theory are
303
 
 
304
 
$$
305
 
\frac{}{\Gamma\vdash\SET=\SET}~~~~
306
 
\frac{\Gamma\vdash M_1=M_2:\SET}{\Gamma\vdash\EL~M_1=\EL~M_2}~~~~~~
307
 
\frac{\Gamma\vdash A_1=A_2~~~~~\Gamma,x{:}A_1\vdash B_1=B_2}{\Gamma\vdash (x{:}A_1)\rightarrow B_1 = (x{:}A_2)\rightarrow B_2}
308
 
$$
309
 
 
310
 
$$
311
 
\frac{\Gamma,x{:}A\vdash M_1=M_2:B}{\Gamma\vdash \lambda x.M_1=\lambda x.M_2:(x{:}A)\rightarrow B}
312
 
$$
313
 
 
314
 
$$
315
 
\frac{\Gamma,x{:}A\vdash B~~~~\Gamma\vdash N_1=N_2:(x{:}A)\rightarrow B~~~~\Gamma\vdash M_1=M_2:A}
316
 
     {\Gamma\vdash N_1~M_1 = N_2~M_2:B(x=M_1)}
317
 
$$
318
 
 
319
 
$$
320
 
\frac{\Gamma,x{:}A\vdash N:B~~~~~\Gamma\vdash M:A}
321
 
     {\Gamma\vdash (\lambda x.N)~M = N(x=M): B(x=M)}~~~~~~~
322
 
\frac{\Gamma\vdash A~~~~\Gamma\vdash M:(x{:}A)\rightarrow B}
323
 
     {\Gamma\vdash M = \lambda x.M~x : (x{:}A)\rightarrow B}
324
 
$$
325
 
 
326
 
 In this presentation of rules, we consider $\lambda$ terms up to  $\alpha$-conversion.
327
 
 
328
 
 This system is quite close to the substitution calculus of P. Martin-L\"of. We note
329
 
however that the following judgement is derivable
330
 
$$
331
 
A{:}\SET,P{:}A\rightarrow\SET\vdash \lambda x.\lambda x.x:(x{:}A)\rightarrow P~x\rightarrow P~x
332
 
$$
333
 
while it is not in the substitution calculus (as noticed by R. Pollack).
334
 
 
335
 
 
336
 
\begin{lemma}
337
 
If $\Gamma\vdash J$ then $\Gamma$ and all free variables of $J$ are declared in $\Gamma$.
338
 
\end{lemma}
339
 
 
340
 
 In particular, if $\vdash A$ then $A$ is closed and if $\vdash M:A$ then both $M$ and
341
 
$A$ are closed.
342
 
 
343
 
 
344
 
 Notice that, because of the conversion rule, the strengthening property, stating that
345
 
$\Gamma\vdash J$ follows from $\Gamma,x{:}A\vdash J$ if $x$ is not free in $J$, is not
346
 
clear {\em a priori}. It will be a consequence of the normalisation property. 
347
 
 
348
 
 
349
 
 If $\sigma$ is a substitution we define $\Delta\vdash\sigma:\Gamma$ to mean that $\Delta\vdash x\sigma:A\sigma$ for
350
 
all $x{:}A$ in $\Gamma$
351
 
 
352
 
\begin{lemma}
353
 
If $\Gamma\vdash J$ and $\Delta\vdash\sigma:\Gamma$ then $\Delta\vdash J\sigma$
354
 
\end{lemma}
355
 
 
356
 
\begin{proof}
357
 
We first prove the lemma in the case where $\sigma$ is a renaming by induction on
358
 
the proof of $\Gamma\vdash J$.
359
 
This contains {\em weakening}: if $\Gamma'\vdash$ and $x{:}A$ is in $\Gamma'$ whenever it is in
360
 
$\Gamma$ and if $\Gamma\vdash J$ then $\Gamma'\vdash J$. After weakening is proved, it is
361
 
direct to prove the lemma in the general case by induction on
362
 
the proof of $\Gamma\vdash J$.
363
 
\end{proof}
364
 
 
365
 
 
366
 
\begin{corollary}
367
 
If $\Gamma,x{:}A\vdash J$ and $\Gamma\vdash M:A$
368
 
then $\Gamma\vdash J(x=M)$.
369
 
\end{corollary}
370
 
 
371
 
 
372
 
 
373
 
\begin{corollary}
374
 
If $\Gamma\vdash A=B$ then $\Gamma\vdash A$ and $\Gamma\vdash B$. If $\Gamma\vdash M_1=M_2:A$ then
375
 
$\Gamma\vdash M_1:A$ and $\Gamma\vdash M_2:A$. If $\Gamma\vdash M:A$
376
 
then $\Gamma\vdash A$. If
377
 
$\Gamma\vdash M=N:A$ then $\Gamma\vdash A$.
378
 
\end{corollary}
379
 
 
380
 
 As a remark we can notice that the extensionality property for terms is derivable.
381
 
 
382
 
\begin{lemma}
383
 
If $\Gamma,x{:}A\vdash N:B$ and $\Gamma\vdash M_1=M_2:A$ then
384
 
$\Gamma\vdash N(x=M_1) = N(x=M_2)\in B(x=M_1)$.
385
 
\end{lemma}
386
 
 
387
 
\begin{lemma}
388
 
If $\Gamma\vdash (x{:}A_1)\rightarrow B_1=(x{:}A_2)\rightarrow B_2$ then $\Gamma\vdash A_1=A_2$
389
 
and $\Gamma,x{:}A_1\vdash B_1=B_2$.
390
 
\end{lemma}
391
 
 
392
 
 We write $M\rightarrow M'$ if we get $M'$ from $M$ by one step of $\beta,\iota$ reduction.
393
 
 
394
 
\begin{corollary}\label{red}
395
 
If $\Gamma\vdash M:A$ and $M\rightarrow M'$ then $\Gamma\vdash M':A$
396
 
\end{corollary}
397
 
 
398
 
\begin{corollary}\label{conv}
399
 
If $\Gamma\vdash M:A$ and $\Gamma\vdash M':A$ and $M=M'$ then
400
 
$\Gamma\vdash M=M':A$
401
 
\end{corollary}
402
 
 
403
 
\begin{proof}
404
 
This is direct from Corollary \ref{red} and the Church-Rosser property of
405
 
$\beta,\iota$ reduction.
406
 
\end{proof}
407
 
 
408
 
 We have also a notion of signature $\Sigma$ which is a list of type declaration
409
 
$f:A$ or $c:A$. If $h:A$ is in the signature we should add the rule
410
 
$$
411
 
\frac{}{\Gamma\vdash h:A}
412
 
$$
413
 
 
414
 
 Any type is of the form $(x_1{:}A_1)\rightarrow\dots\rightarrow (x_n{:}A_n)\rightarrow \SET$
415
 
or $(x_1{:}A_1)\rightarrow\dots\rightarrow (x_n{:}A_n)\rightarrow \EL~M$. We write it
416
 
$\Delta\rightarrow\SET$ or $\Delta\rightarrow\EL~M$ where $\Delta$ is the context
417
 
$x_1{:}A_1,\dots,x_n{:}A_n$. Similarly we may write $\lambda\Delta.M$ instead of
418
 
$\lambda x_1.\dots.\lambda x_n.M$.
419
 
 
420
 
 We have an alternative presentation for typing terms and infering the types with rules
421
 
 
422
 
$$
423
 
\frac{(x{:}A)~\in~\Gamma}{\Gamma\vdash x\downarrow A}~~~~~~~~~
424
 
\frac{\Gamma\vdash M\downarrow (x{:}A)\rightarrow B~~~~\Gamma\vdash N\uparrow A}
425
 
     {\Gamma\vdash M~N\downarrow B(x=N)}
426
 
$$
427
 
and
428
 
$$
429
 
\frac{\Gamma,x{:}A\vdash M\uparrow B}{\Gamma\vdash \lambda x.M\uparrow (x{:}A)\rightarrow B}~~~~
430
 
\frac{\Gamma\vdash M\downarrow A~~~~\Gamma\vdash A = B}{\Gamma\vdash M\uparrow B}
431
 
$$
432
 
 
433
 
 The rules for types can then be replaced by
434
 
$$
435
 
\frac{}{\Gamma\vdash \SET\downarrow}~~~~
436
 
\frac{\Gamma\vdash M\downarrow\SET}{\Gamma\vdash \EL~M\downarrow}~~~~~~
437
 
\frac{\Gamma\vdash A\downarrow~~~~~\Gamma,x{:}A\vdash B\downarrow}{\Gamma\vdash (x{:}A)\rightarrow B\downarrow}
438
 
$$
439
 
%and the rules for checking contexts are
440
 
%$$
441
 
%\frac{\Gamma\downarrow~~~~\Gamma\vdash A\downarrow}{\Gamma,x{:}A\downarrow}
442
 
%$$
443
 
\begin{theorem}
444
 
If $M$ is in $\beta$-normal form and $\Gamma\vdash M{:}A$ then $\Gamma\vdash M\uparrow A$.
445
 
\end{theorem}
446
 
 
447
 
 
448
 
\section{Models}
449
 
 
450
 
 We assume given a model $\DD$ with a subset $E\subseteq \DD$ of {\em existing} elements. 
451
 
We may write $\Ex~u$ for $u\in E$.
452
 
We have an interpretation
453
 
$M\rho\in\DD$ for each environment $\rho:V\rightarrow\DD$.
454
 
If ${\bf u}$ is a sequence of elements
455
 
$u_1,\dots,u_k$ we write $\Ex~{\bf u}$ for $u_1\in E\wedge\dots\wedge u_k\in E$. If ${\bf u}$
456
 
and ${\bf v}$ are sequences of the same length $u_1,\dots,u_k$ and $v_1,\dots,v_k$
457
 
we write ${\bf u} = {\bf v}$ for $u_1=v_1,\dots,u_k=v_k$.
458
 
We assume that we have an interpretation $h\in\DD$ for each constant $h$ in the signature.
459
 
 
460
 
 
461
 
\medskip
462
 
 
463
 
 $f~{\bf u}~(c~{\bf v}) = M({\bf x} = {\bf u},{\bf y}={\bf v})$ if $\Ex~{\bf u}$ and $\Ex~{\bf v}$
464
 
and  $f~{\bf x}~(c~{\bf y}) = M$
465
 
 
466
 
\medskip
467
 
 
468
 
 $(\lambda x.M)\rho~u = M(\rho,x=u)$ if $\Ex~u$
469
 
 
470
 
\medskip
471
 
 
472
 
$\Ex~(c~{\bf u})$ if $\Ex~{\bf u}$
473
 
 
474
 
\medskip
475
 
 
476
 
 $x\rho = \rho(x)$
477
 
 
478
 
\medskip
479
 
 
480
 
 $(M~N)\rho = M\rho~(N\rho)$
481
 
 
482
 
\medskip
483
 
 
484
 
 $M(x=N)\rho = M(\rho,x=N\rho)$
485
 
 
486
 
\medskip
487
 
 
488
 
 $M\rho = M\nu$ if $\rho(x) = \nu(x)$ for all free variables $x$ of $M$
489
 
 
490
 
\medskip
491
 
 
492
 
 We assume also that we have a special element $\TOP\in\DD$ such that
493
 
 
494
 
\medskip
495
 
 
496
 
 $\Ex~\TOP$ 
497
 
 
498
 
\medskip
499
 
 
500
 
$\TOP~u = \TOP$ if $\Ex~u$
501
 
 
502
 
\medskip
503
 
 
504
 
$f~{\bf u}~\TOP = \TOP$ whenever $\Ex~{\bf u}$.
505
 
 
506
 
\medskip
507
 
 
508
 
\medskip
509
 
 
510
 
%\begin{lemma}
511
 
%If $\Ex~(M\rho)$ and $M\rightarrow M'$ then $M\rho = M'\rho$ in $\DD$.
512
 
%If $M=N$ and $\Ex~(M\rho)$ and $\Ex~(N\rho)$ then $M\rho = N\rho$ in $\DD$.
513
 
%\end{lemma}
514
 
 
515
 
A {\em totality} on $\DD$
516
 
is a PER, partial equivalence relation, on $\DD$, that is a subset $X\subseteq \DD$ with
517
 
an equivalence relation $=_X$, such that $\Ex~u$ if $u\in X$ and $\nabla\in X$. We write
518
 
$u_1=u_2\in X$ instead of $u_1=_X u_2$.
519
 
We let $\TOT$ be the collection of all totality.
520
 
 
521
 
\begin{lemma}
522
 
If $X\in\TOT$ is a totality and $F:X\rightarrow\TOT$ such that
523
 
$F(u_1)=F(u_2)$ if $u_1= u_2\in X$ we define $\Pi(X,F)$ to be the set
524
 
$ \{v\in\DD~|~u_1= u_2\in X\Rightarrow v~u_1 = v~u_2\in {F(u_1)}\}$
525
 
with the equivalence relation $v_1{=}v_2\in {\Pi(X,F)}$ iff $v_1~u{=}~ v_2~u\in {F(u)}$ for
526
 
all $u\in X.$ Then $\Pi(X,F)$ is a totality.
527
 
\end{lemma}
528
 
 
529
 
\begin{proof}
530
 
We have $\nabla\in X$. If $v\in\Pi(X,F)$  then  $v~\nabla\in F(\nabla)$ and so $\Ex~(v~\nabla)$ and
531
 
$\Ex~v$ holds. If $u\in X$ then $\Ex~u$ so that $\nabla~u =\nabla\in F(u)$. This shows $\nabla\in \Pi(X,F)$.
532
 
\end{proof}
533
 
 
534
 
 We assume give a totality $S\in\TOT$ together with a function $Y:S\rightarrow\TOT$ which
535
 
is {\em extensional}, that is such that $Y(s_1) = Y(s_2)$ if $s_1= s_2\in S$
536
 
 
537
 
 
538
 
 We define now $T\in\TOT$ and an extensional function $X{:}T\rightarrow\TOT$.
539
 
 
540
 
\medskip
541
 
 
542
 
 (1) $\SET=\SET\in T$ and $X(\SET) = S$
543
 
 
544
 
\medskip
545
 
 
546
 
 (2) $\FUN~U_1~F_1 = \FUN~U_2~F_2\in T$ if $U_1=U_2\in T$ and $F_1~u_1=F_2~u_2\in T$ whenever $u_1=u_2\in X(U_1)$. We
547
 
define then $X(\FUN~U_1~F_1)=X(\FUN~U_2~F_2)$ to be $\Pi(X(U_1),\lambda u.X(F_1~u))$
548
 
 
549
 
\medskip
550
 
 
551
 
 (3) $\EL~u_1=\EL~u_2\in T$ if $u_1=u_2\in S$ and $X(\EL~u_1) = X(\EL~u_2) = Y(u_1)$
552
 
 
553
 
\medskip
554
 
 
555
 
 If $\Delta$ is a context $x_1{:}A_1,\dots,x_k{:}A_k$ we write $\rho\Vdash\Delta$ to
556
 
express that $A_i\rho\in\TOT$ and $\rho(x_i)\in X(A_i\rho)$ for $i=1,\dots,k$ and
557
 
we write $\rho_1=\rho_2\Vdash\Delta$ to express that $A_i\rho_1=A_i\rho_2$ and
558
 
$x_i\rho_1 = x_i\rho_2\in A_i\rho_1$ for $i=1,\dots,k$.
559
 
 
560
 
 For the next theorem, we assume $A\rho\in T$ and $h\in X(A\rho)$ for all
561
 
constant $h{:}A$ in the given signature $\Sigma$.
562
 
 
563
 
\begin{lemma}
564
 
If $x$ is not declared in $\Delta$ and all the free variables of $A$ are declared
565
 
in $\Delta$ and $\rho\Vdash\Delta$ and $A\rho\in T$ and $u\in X(A\rho)$ then
566
 
$(\rho,x=u)\Vdash \Delta,x{:}A$.
567
 
\end{lemma}
568
 
 
569
 
 The next result states the soundness of PER semantics for the type system.
570
 
 
571
 
\begin{theorem}\label{sem}
572
 
  Assume $\rho_1=\rho_2\Vdash\Delta$. If $\Delta\vdash A$ then $A\rho_1=A\rho_2\in T$. If
573
 
$\Delta\vdash M{:}A$ then $A\rho_1=A\rho_2\in T$ and $M\rho_1=M\rho_2\in X(A\rho_1)$.
574
 
\end{theorem}
575
 
 
576
 
\begin{corollary}
577
 
If $\vdash A$ then $\Ex~A()$. If $\vdash M:A$ then $\Ex~M()$.
578
 
\end{corollary}
579
 
 
580
 
 
581
 
\section{Strong normalisation and decidability of equality}
582
 
 
583
 
 If we specialise Corollary \ref{sem} to the strict filter domain, we get
584
 
 
585
 
\begin{theorem}
586
 
If $\vdash A$ then $A$ is strongly normalisable. If $\vdash M:A$ then $M$
587
 
is strongly normalisable.
588
 
\end{theorem}
589
 
 
590
 
 In order to get decidability of conversion, we first define the $\eta$-expansion
591
 
$\eta~A~M$ in a syntactical way.
592
 
$$
593
 
\eta~\SET~M = M~~~~~
594
 
\eta~(\EL~M')~M = M~~~~
595
 
\eta~(\FUN~A~F)~M = \lambda x.\eta~(F~(\eta~A~x))~(M~(\eta~A~x))
596
 
$$
597
 
 
598
 
\begin{lemma}\label{exp}
599
 
If $\Gamma\vdash M:A$ then $\Gamma\vdash M = \eta~A~M:A$
600
 
\end{lemma}
601
 
 
602
 
\begin{proof}
603
 
This is clear if $A$ is $\SET$ or of the form $\EL~M'$ because in this case
604
 
$\eta~A~M = M$ and $\Gamma\vdash M:A$ implies $\Gamma\vdash M = M :A$.
605
 
 
606
 
 If $A$ is $(x{:}B)\rightarrow C$ then we have
607
 
$\eta~A~M = \lambda x.\eta~(C[\eta~B~x])~(M~(\eta~B~x))$. We have $\Gamma,x:B\vdash M~x:C$.
608
 
By induction on $A$ we have furthermore
609
 
$\Gamma,x:B\vdash x = \eta~B~x:B$ and so $\Gamma,x:B\vdash C = C[\eta~B~x]$ and
610
 
hence $\Gamma\vdash A = (x:B)\rightarrow C[\eta~B~x]$ and 
611
 
 $\Gamma,x:B\vdash M~x = M~(\eta~B~x):C[\eta~B~x].$ By induction on $A$
612
 
we deduce 
613
 
$$\Gamma,x:B\vdash M~x = \eta~(C[\eta~B~x])~(M~(\eta~B~x)):C[\eta~B~x]$$
614
 
and so
615
 
$$\Gamma\vdash \lambda x.M~x = \lambda x.\eta~(C[\eta~B~x])~(M~(\eta~B~x)):(x:B)\rightarrow C[\eta~B~x]$$
616
 
Since $\Gamma\vdash A = (x:B)\rightarrow C[\eta~B~x]$ we deduce
617
 
$$\Gamma\vdash \lambda x.M~x = \lambda x.\eta~(C[\eta~B~x])~(M~(\eta~B~x)):A$$
618
 
and since $\Gamma\vdash M = \lambda x.M~x:A$ we have finally
619
 
$\Gamma\vdash M = \eta~A~M:A$ \end{proof}
620
 
 
621
 
We recall that $M_1=M_2$ means that $M_1$ and $M_2$ are $\beta,\iota$ convertible.
622
 
The intuition between the next statement is clear: if we work with the $\eta$ expansion
623
 
of the terms, we don't need the $\eta$ rule. For a precise proof, we rely on
624
 
the soundness of  a particular PER model for our type system.
625
 
 
626
 
\begin{lemma}\label{betaiota}
627
 
If $\vdash M_1=M_2:A$ then $\eta~A~M_1 = \eta~A~M_2$
628
 
\end{lemma}
629
 
 
630
 
\begin{proof}
631
 
For the proof we use the following PER model. The domain $D$ is the set of all terms, with
632
 
$\beta,\iota$-conversion as equality. The PER $\SET$ is interpreted by the conversion: we
633
 
have $M_1=M_2:\SET$ iff $M_1=M_2$, and for any $M$ the PER $\EL~M$ is also the conversion.
634
 
We can then define $A_1=A_2$ and if it is the case when we have $M_1=M_2\in A_1$.
635
 
This is the case if $A_1=A_2=\SET$ or $A_1=A_2=\EL~M$ for some $M$ or
636
 
if $A_1=(x:B_1)\rightarrow C_1,~A_2=(x:B_2)\rightarrow C_2$ and $B_1 = B_2$
637
 
and $M_1=M_2\in B_1$ implies $C_1[M_1] = C_2[M_2]$. 
638
 
For instance all terms are in $\SET\rightarrow\SET$ but we have
639
 
$f=\lambda x.f~x\in\SET\rightarrow\SET$, and not all terms are
640
 
in $(\SET\rightarrow\SET)\rightarrow\SET$.
641
 
We have then
642
 
$N_1=N_2\in (x:B_1)\rightarrow C_1$ iff $M_1=M_2\in B_1$ implies
643
 
$N_1~M_1=N_2~M_2\in C_1[M_1]$.
644
 
We then show by induction that if $A$ is a type that
645
 
 
646
 
\medskip
647
 
 
648
 
 $\eta~A~M$ is of type $A$ for any $M$
649
 
 
650
 
\medskip
651
 
 
652
 
 $M_1=M_2\in A$ iff $\eta~A~M_1=\eta~A~M_2$
653
 
 
654
 
\medskip
655
 
 
656
 
 By interpretation in this model we have that if $\vdash M_1=M_2:A$ then $A$
657
 
is a type and $M_1=M_2\in A$. This is equivalent to  $\eta~A~M_1=\eta~A~M_2$.
658
 
\end{proof}
659
 
 
660
 
 
661
 
 In presence of constant, we interpret $h$ by $\eta~A~h$ if $h$ is declared of type
662
 
$A$. If $h=f$ is a defined constant, we need then to check that $\eta~A~f$ satisfies
663
 
the same equality as $f$. For instance, we have
664
 
(to simplify the notations, we write simply $X$ instead of $\EL~X$ if $X:\SET$)
665
 
$$
666
 
\NATREC:(C{:}\NAT\rightarrow\SET)\rightarrow C~\ZERO\rightarrow ((n{:}\NAT)\rightarrow C~n~\rightarrow C~(\SUCC~n))
667
 
                \rightarrow (n{:}\NAT)\rightarrow C~n
668
 
$$
669
 
with the equation
670
 
$$
671
 
\NATREC~C~a~b~(\SUCC~n) = b~n~(\NATREC~C~a~b)
672
 
$$
673
 
The $\eta$-expanded form of $\NATREC$ is 
674
 
$$\NATREC^*=\lambda C.\lambda a.\lambda b.\lambda n.\NATREC~(\lambda x.C~x)~a~(\lambda x.\lambda y.b~x~y)~n$$
675
 
and we can check that we have
676
 
$$
677
 
\begin{array}{ccl}
678
 
\NATREC^*~C~a~b~(\SUCC~n) & = & \NATREC~(\lambda x.C~x)~a~(\lambda x.\lambda y.b~x~y)~(\SUCC~n) \\
679
 
                          & = & b~n~(\NATREC~(\lambda x.C~x)~a~(\lambda x.\lambda y.b~x~y)~n) \\
680
 
                          & = & b~n~(\NATREC^*~C~a~b~n)
681
 
\end{array}
682
 
$$
683
 
 
684
 
 
685
 
 
686
 
\begin{theorem}
687
 
If $\vdash M_1:A$ and $\vdash M_2:A$ then $\vdash M_1=M_2:A$ iff
688
 
$\eta~A~M_1=\eta~A~M_2$
689
 
\end{theorem}
690
 
 
691
 
\begin{proof}
692
 
This follows from Lemmas \ref{exp} and \ref{betaiota} and Corollary \ref{conv}.
693
 
\end{proof}
694
 
 
695
 
\begin{corollary}
696
 
Assume $\Delta\vdash M_1:A$ and $\Delta\vdash M_2:A$. We have $\Delta\vdash M_1=M_2:A$ iff
697
 
$\eta~(\Delta\rightarrow A)~(\lambda\Delta.M_1)=\eta~(\Delta\rightarrow A)~(\lambda\Delta.M_2)$
698
 
\end{corollary}
699
 
 
700
 
\begin{proof}
701
 
We have $\Delta\vdash M_1=M_2:A$ iff $\vdash \lambda\Delta.M_1 = \lambda\Delta.M_2:\Delta\rightarrow A$.
702
 
\end{proof}
703
 
 
704
 
\begin{corollary}
705
 
If $A$ is in $\beta$-normal form then $\vdash A$ is decidable. If $\vdash A$ and $M$ is
706
 
in $\beta$-normal form then $\vdash M:A$ is decidable.
707
 
\end{corollary}
708
 
 
709
 
\section{Representation of type theory}
710
 
 
711
 
 We add the primitive constants
712
 
$$
713
 
\BOOL:\SET,~~~~\NAT:\SET,~~~~\LIST:\SET\rightarrow\SET,~~~~\TRUE:\BOOL,~~~~\FALSE:\BOOL,~~~
714
 
\ZERO:\NAT,~~~~\SUCC:\NAT\rightarrow\NAT
715
 
$$ 
716
 
 It is convenient to give the typing rules
717
 
$$
718
 
\frac{\Gamma\vdash A:\SET}{\Gamma\vdash \NIL:\EL~(\LIST~A)}~~~~~~~
719
 
\frac{\Gamma\vdash A:\SET}{\Gamma\vdash \CONS:\EL~A\rightarrow \EL~(\LIST~A)\rightarrow \EL~(\LIST~A)}
720
 
$$
721
 
 We add also $\BOOLREC,\NATREC,\LISTREC$ with computation rules
722
 
$$
723
 
\begin{array}{lcl}
724
 
\BOOLREC~C~a~b~\TRUE = a & & \BOOLREC~C~a~b~\FALSE = b \\
725
 
\NATREC~C~a~b~\ZERO = a  & & \NATREC~C~a~b~(\SUCC~n) = b~n~(\NATREC~C~a~b~n) \\
726
 
\LISTREC~A~C~a~b~\NIL = a  & & \LISTREC~A~C~a~b~(\CONS~x~xs) = b~x~xs~(\LISTREC~A~C~a~b~xs)
727
 
\end{array}
728
 
$$
729
 
and types
730
 
$$
731
 
\begin{array}{lcl}
732
 
\BOOLREC:& & (C{:}\BOOL\rightarrow\SET)\rightarrow C~\TRUE\rightarrow C~\FALSE
733
 
                \rightarrow (b{:}\BOOL)\rightarrow C~b \\
734
 
\NATREC:& & (C{:}\NAT\rightarrow\SET)\rightarrow C~\ZERO\rightarrow ((n{:}\NAT)\rightarrow C~n~\rightarrow C~(\SUCC~n))
735
 
                \rightarrow (n{:}\NAT)\rightarrow C~n \\
736
 
\LISTREC:& & (A:\SET)\rightarrow (C{:}\LIST~A\rightarrow\SET)\rightarrow \\
737
 
 & &  C~\NIL\rightarrow ((x{:}A)\rightarrow (xs:\LIST~A)\rightarrow C~xs~\rightarrow C~(\CONS~x~xs)) \rightarrow \\
738
 
 & & (xs{:}\LIST~A)\rightarrow C~xs 
739
 
\end{array}
740
 
$$
741
 
 
742
 
 
743
 
 
744
 
 In this system, we show that the constants $\BOOLREC,\NATREC,\LISTREC$ are total.
745
 
 
746
 
\begin{theorem}
747
 
If $A$ is in $\beta$-normal form then $\vdash A$ is decidable. If $\vdash A$ and $M$ is
748
 
in $\beta$-normal form then $\vdash M:A$ is decidable.
749
 
\end{theorem}
750
 
 
751
 
\section{A simple module system}
752
 
 
753
 
 As a simple module system, we can take contexts as interface. We have the typing rules
754
 
$$
755
 
\frac{\Gamma,x:A\vdash\Delta}{\Gamma\vdash x:A,\Delta}
756
 
$$
757
 
$$
758
 
\frac{\Gamma\vdash M:A~~~~~~\Gamma\vdash {\bf M}:\Delta(x=M)}
759
 
     {\Gamma\vdash M,{\bf M}:(x:A,\Delta)}
760
 
$$
761
 
 
762
 
 If we have $\Gamma\vdash {\bf M}:\Delta$ we can extend the context $\Gamma$ to
763
 
$\Gamma,\Delta$. Intuitively, we hide the definitions of the variables declared
764
 
in $\Delta$, but we still have access to their types.
765
 
 
766
 
 This a simple, but robust, notion of modular construction of terms.
767
 
 
768
 
\section{Defined constants}
769
 
 
770
 
 A {\em small} type is a type which does not contain $\SET$. If $\Delta\vdash A$
771
 
and $A$ is a small type, we can always introduce a new primitive constant
772
 
$c:\Delta\rightarrow\SET$ such that $c~{\bf M}$  is ``equivalent'' to $A[{\bf M}]$ if
773
 
${\bf M}$ is an instance of $\Delta$. We introduce also two constants
774
 
$$
775
 
\frac{\Gamma\vdash {\bf M}:\Delta~~~~~\Gamma\vdash N:A[{\bf M}]}{\Gamma\vdash \INTRO~N:c~{\bf M}}~~~~
776
 
\frac{\Gamma\vdash {\bf M}:\Delta~~~~~\Gamma\vdash P:c~{\bf M}}{\Gamma\vdash \ELIM~P:A[{\bf M}]}
777
 
$$
778
 
with the computation rule $\ELIM~(\INTRO~N) = N$.
779
 
 
780
 
 This is an example of a uniform extension of the Logical Framework in a way that 
781
 
preserves strong normalisation. A special case is the addition of a $\Pi$ operation
782
 
where $\Delta$
783
 
is the context $X:\SET,Y:\EL~A\rightarrow\SET$ and $A$ is $(x{:}\EL~X)\rightarrow\EL~(Y~x)$.
784
 
 
785
 
\section{Sigma types}
786
 
 
787
 
 We can extend the Logical Framework with sigma types. The proofs of strong normalisation
788
 
and decidability of type-checking extend without problems. 
789
 
 
790
 
 The new typing rules are
791
 
$$
792
 
\frac{\Gamma,x{:}A\vdash B}{\Gamma\vdash (x{:}A)\times B}~~~~~~~
793
 
\frac{\Gamma\vdash M:A~~~~~\Gamma\vdash N:B(x=M)}{\Gamma\vdash M,N:(x{:}A)\times B}~~~
794
 
\frac{\Gamma\vdash P:(x{:}A)\times B}{\Gamma\vdash P.1:A}~~~
795
 
\frac{\Gamma\vdash P:(x{:}A)\times B}{\Gamma\vdash P.2:B(x=P.1)}
796
 
$$
797
 
and the new conversion rules are
798
 
$$
799
 
\frac{\Gamma\vdash A_1=A_2~~~~~\Gamma,x{:}A_1\vdash B_1=B_2}
800
 
     {\Gamma\vdash (x{:}A_1)\times B_1 = (x{:}A_2)\times B_2}
801
 
$$
802
 
$$
803
 
\frac{\Gamma,x:A\vdash B~~~\Gamma\vdash M_1=M_2:A~~~~~\Gamma\vdash N_1=N_2:B(x=M_1)}
804
 
     {\Gamma\vdash (M_1,N_1) = (M_2,N_2):(x:A)\times B}$$
805
 
$$
806
 
\frac{\Gamma\vdash M:A~~~~~\Gamma\vdash N:B(x=M)}
807
 
     {\Gamma\vdash (M,N).1 = M:A}$$
808
 
$$
809
 
\frac{\Gamma,x:A\vdash B~~~~\Gamma\vdash M:A~~~~~\Gamma\vdash N:B(x=M)}
810
 
     {\Gamma\vdash (M,N).2 = N:B(x=M)}$$
811
 
$$
812
 
\frac{\Gamma\vdash P:(x{:}A)\times B}{\Gamma\vdash P = (P.1,P.2):(x{:}A)\times B}
813
 
$$
814
 
 
815
 
 The types are interfaces and can be thought of as (generalised) context. We need a system
816
 
of pattern notations, so that we can write
817
 
$\lambda (x,y).M:((x:A)\times B)\rightarrow C$ if $x{:}A,y{:}B\vdash M:C$.
818
 
When we instanciate a given interface $x_1{:}A_1,\dots,x_k{:}A_k$ by elements
819
 
$M_1,\dots,M_k$ the typing rules are that $M_i:A_i[M_1,\dots,M_{i-1}]$. Intuitively,
820
 
during the instantiation we have access to the values of $x_1,\dots,x_k$. But
821
 
these values are hidden outside the module.
822
 
 
823
 
\section{Sorts}
824
 
 
825
 
 In order to represent the collection of all ``Bishop'' sets (sets with an equivalence
826
 
relation), we can introduce a new type $\SET_1$, with a new type forming operation
827
 
$$\frac{\Gamma\vdash M:\SET_1}{\Gamma\vdash \EL_1~M}$$
828
 
In combination with sigma types, and defined constants, one can then represent
829
 
for instance the collection of all Bishop sets as a constant
830
 
$\BSET:\SET_1$ with rules
831
 
$$
832
 
\frac{\Gamma\vdash A:\SET~~~~\Gamma\vdash R:A\rightarrow A\rightarrow\SET~~~~
833
 
      \Gamma\vdash M:equiv~A~R}
834
 
     {\Gamma\vdash \INTRO~(A,R,M):\BSET}
835
 
$$
836
 
$$
837
 
\frac{\Gamma\vdash P:\BSET}
838
 
     {\Gamma\vdash \ELIM~P:(A{:}\SET)\times (R{:}A\rightarrow A\rightarrow\SET)\times equiv~A~R}
839
 
$$
840
 
 
841
 
 In this way, we keep the structure of the types close to simple type
842
 
theory. The new atomic types are of the form $\SET_1$ or $\EL_1~M$. 
843
 
 
844
 
\section{Extension with bar recursion}
845
 
 
846
 
 Using the filter domain model for strong normalisation, it can be shown, using
847
 
impredicative means, that the constant for bar recursion, or for modified
848
 
bar recursion are totals.
849
 
 
850
 
 We write $a:l$ for $\CONS~a~l$
851
 
We define $\lambda l.|l|:\LIST~A\rightarrow \NAT$, and  $\hat{l}:\NAT\rightarrow A$ if $l:\LIST~A$
852
 
 
853
 
 $|\NIL| = \ZERO~~~~~~|a:l| = \SUCC~|l|$
854
 
 
855
 
 $\NIL:x = x:\NIL~~~~~~~(a:l):x = a:(l:x)$
856
 
 
857
 
 $\widehat{\NIL}~n = \ZERO~~~~~~~\widehat{a:l}~\ZERO = a~~~~~\widehat{a:l}~(\SUCC~n) = \widehat{l}~n$
858
 
 
859
 
 We introduce then $\Phi,\Psi$ with the equations
860
 
 
861
 
 $\Phi~y~g~h~s = \Psi~y~g~h~s~(y~|s|<\hat{s})$
862
 
 
863
 
 $\Psi~y~g~h~s~\TRUE = g~s$
864
 
 
865
 
 $\Psi~y~g~h~s~\FALSE = h~s~(\lambda x.\Phi~y~g~h~(s:x))$
866
 
 
867
 
where
868
 
 
869
 
 $y:(\NAT\rightarrow A)\rightarrow\NAT$
870
 
 
871
 
 $h:\LIST~ A\rightarrow (A\rightarrow B)\rightarrow B$
872
 
 
873
 
 $g:\LIST~A\rightarrow B$
874
 
 
875
 
 It can then be shown that $\Phi,\Psi$ are total. 
876
 
 
877
 
\section{Proof irrelevance}
878
 
 
879
 
 We add two new constants $\PROOF$ and $\ZERO$ with the rules
880
 
 
881
 
$$
882
 
\frac{\Gamma\vdash A:\SET}{\Gamma\vdash \PROOF~A}~~~~~~
883
 
\frac{\Gamma\vdash M:\PROOF~A}{\Gamma\vdash \ZERO: \PROOF~A}~~~~~
884
 
\frac{\Gamma\vdash A_1=A_2:\SET}{\Gamma\vdash \PROOF~A_1 = \PROOF~A_2}
885
 
$$
886
 
 
887
 
$$
888
 
\frac{\Gamma\vdash M_1:\PROOF~A~~~~~\Gamma\vdash M_2:\PROOF~A}{\Gamma\vdash M_1=M_2:\PROOF~A}
889
 
$$
890
 
 
891
 
 Conversion is still decidable and type-checking for terms in $\beta$-normal
892
 
form which do not contain $\ZERO.$ 
893
 
 
894
 
 Another reading of $\Gamma\vdash \ZERO:\PROOF~A$ is $\Gamma\vdash A~\TRUE$. We know
895
 
that $A$ has a proof but the proof has been hidden.
896
 
 
897
 
 
898
 
 
899
 
 
900
 
 Notice that the strengthening property does not hold for this system.
901
 
 
902
 
 The PER model extends directly to this system by interpreting $\ZERO$
903
 
by $\nabla$ and letting $\PROOF~u$ be the set $\EL~u$ with the universal
904
 
equivalence relation. So strong normalisation still holds for this system.
905
 
 
906
 
 This is also a semantics for the following rule.
907
 
$$
908
 
\frac{\Gamma\vdash M:\EL~A}{\Gamma\vdash M:\PROOF~A}
909
 
$$
910
 
 
911
 
 For proving the decidability of convertibility, we update the
912
 
definition of $\eta~A~M$ by taking $\eta~(\PROOF~M')~M = \ZERO$. It is then still
913
 
the case that $\vdash M_1=M_2:A$ iff $\eta~A~M_1=\eta~A~M_2$ if
914
 
$\vdash M_1:A$ and $\vdash M_2:A$.
915
 
 
916
 
\begin{theorem}
917
 
If $A$ is in $\beta$-normal form and does not contain $\ZERO$
918
 
then $\vdash A$ is decidable. If $\vdash A$ and $M$ is
919
 
in $\beta$-normal form and does not contain $\ZERO$ then $\vdash M:A$ is decidable.
920
 
\end{theorem}
921
 
 
922
 
 
923
 
 
924
 
\begin{thebibliography}{9}
925
 
 
926
 
\bibitem{Type}
927
 
B. Nordstr\"om, K. Petersson, J. Smith.
928
 
\newblock{{\em Programming in Martin-L\"of's Type Theory.}}
929
 
\newblock{Oxford Science Publications, 1990.}
930
 
 
931
 
 
932
 
 
933
 
\end{thebibliography}
934
 
 
935
 
\end{document}
936