]> matita.cs.unibo.it Git - helm.git/blob - helm/papers/system_T/t.tex
ported to the IEEE latex8 style
[helm.git] / helm / papers / system_T / t.tex
1 \documentclass[times, 10pt,twocolumn, draft]{article}
2 \pagestyle{headings}
3 %\usepackage{graphicx}
4 \usepackage{amssymb,amsmath,mathrsfs,stmaryrd,amsthm}
5 %\usepackage{hyperref}
6 %\usepackage{picins}
7 \usepackage{latex8}
8 \usepackage{times}
9
10 \pagestyle{empty}
11
12
13 \newcommand{\semT}[1]{\ensuremath{\llbracket #1 \rrbracket}}
14 \newcommand{\sem}[1]{\llbracket \ensuremath{#1} \rrbracket}
15 \newcommand{\pair}[2]{<\!#1,#2\!>}
16 \newcommand{\canonical}{\bot}
17 \newcommand{\R}{~\mathscr{R}~}
18 \newcommand{\N}{\,\mathbb{N}\,}
19 \newcommand{\B}{\,\mathbb{B}\,}
20 \newcommand{\NT}{\,\mathbb{N}\,}
21 \newcommand{\NH}{\,\mathbb{N}\,}
22 \renewcommand{\star}{\ast}
23 \renewcommand{\vec}{\overrightarrow}
24 \newcommand{\one}{{\bf 1}}
25 \newcommand{\mult}{\cdot}
26 \newcommand{\ind}{Ind(X)}
27 \newcommand{\indP}{Ind(\vec{P}~|~X)}
28 \newcommand{\Xind}{\ensuremath{X_{ind}}}
29 \newcommand{\XindP}{\ensuremath{X_{ind}}}
30 \renewcommand{\|}{\ensuremath{\quad | \quad}}
31 \newcommand{\triUP}{\ensuremath{\Delta}}
32 \newcommand{\triDOWN}{\ensuremath{\nabla}}
33 \newcommand{\Rx}{\ensuremath{R_X}}
34
35 \newtheorem{thm}{Theorem}[subsection]
36
37 \title{Modified Realizability and Inductive Types}
38 \author{...}
39
40
41 \begin{document}
42 \maketitle
43 \thispagestyle{empty}
44
45 \begin{abstract}
46 ...
47 \end{abstract}
48
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 \Section{Introduction}
51 The characterization of the provable recursive functions of 
52 Peano Arithmetic as the terms of system T is a well known
53 result of G\"odel \cite{Godel58,Godel90}. Although several authors acknowledge 
54 that the functional interpretation of the Dialectica paper
55 is not among the major achievements of the author (see e.g. \cite{Girard87}), 
56 the result has been extensively investigated and there is a wide 
57 literature on the 
58 topic (see e.g. \cite{Troelstra,HS86,Girard87}, just to mention textbooks,
59 and the bibliography therein). 
60
61 A different, more neglected, but for many respects much more 
62 direct relation between Peano (or Heyting) Arithmetics and 
63 G\"odel System T is provided
64 by the so called {\em modified realizability}. Modified realizability
65 was first introduced by Kreisel in \cite{Kreisel59} - although it will take you
66 a bit of effort to recognize it in the few lines of paragraph 3.52 -
67 and later in \cite{Kreisel62} under the name of generalized realizability.
68 The name of modified realizability seems to be due to Troelstra 
69 \cite{Troelstra}
70 - who contested Kreisel's name but unfortunately failed in proposing 
71 a valid alternative; we shall reluctantly adopt this latter name 
72 to avoid further confusion. Modified realizability is a typed variant of 
73 realizability, essentially providing interpretations 
74 of $HA^{\omega}$ into itself: each theorem is realized by a typed function
75 of system T, that also gives the actual computational content extracted 
76 from the proof. 
77 In spite of the simplicity and the elegance of the proof, it is extremely
78 difficult to find a modern discussion of this result; the most recent
79 exposition we are aware of is in the encyclopedic work by
80 Troelstra \cite{Troelstra} (pp.213-229) going back to thirty years ago. 
81 Even modern introductory books
82 to Type Theory and Proof Theory devoting much space to system T
83 such as \cite{GLT} and \cite{TS} surprisingly leave out this simple and 
84 illuminating result. Both the previous textbooks
85 prefer to focus on higher order arithmetics and its relation with 
86 Girard's System $F$ \cite{Girard86}, but the technical complexity and
87 the didactical value of the two proofs is not comparable: when you 
88 prove that the Induction Principle is realized by the recursor $R$ 
89 of system $T$ you catch a sudden gleam of understanding in the 
90 students eyes; usually, the same does not happen when you show, say, 
91 that the ``forgetful'' interpretation of the higher order predicate defining
92 the natural numbers is the system $F$ encoding 
93 $\forall X.(X\to X) \to X \to X$ of $\N$. 
94 Moreover, after a first period of enthusiasm, the impredicative 
95 encoding of inductive types in Logical Frameworks has shown several 
96 problems and limitations (see e.g. \cite{Werner} pp.24-25) mostly
97 solved by assuming inductive types as a primitive logical notion
98 (leading e.g. form the Calculus of Constructions to the Calculus
99 of Inductive Constructions - CIC). Even the extraction algorithm of
100 CIC, strictly based on realizability principles, and in a first time
101 still oriented towards System F \cite{Paulin87,Paulin89} has been 
102 recently rewritten \cite{Letouzey04}
103 to take advantage of concrete types and pattern matching of ML-like
104 languages. Unfortunately, systems like the Calculus of Inductive 
105 Constructions are so complex, from the logical point of view, to 
106 substantially prevent a really neat theoretical exposition (at present, 
107 it does not
108 even exists a truly complete consistency proofs covering all aspects
109 of such systems); moreover, not everybody may be interested in all the features
110 offered by these frameworks, from polymorphism to types depending on 
111 proofs. Our program is to restart the analysis of logical systems with
112 primitive inductive types in a smooth way, starting form first order
113 logic and adding little by little small bits of logical power.
114 This paper is the first step in this direction.
115
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 \Section{G\"odel system T}
118 We shall use a variant of system T with three atomic types $\N$ (natural 
119 numbers), $\B$ (booleans) and $\one$ (a terminal object), and two binary
120 type constructors $\times$ (product) and $\to$ (arrow type).
121
122 The terms of the language comprise the usual simply typed lambda terms 
123 with explicit pairs, plus the following additional constants:
124 \begin{itemize}
125 \item $*:\one$, 
126 \item $true: \B$, $false:\B$, $D:A\to A \to \B \to A$ 
127 \item $O:\N$, $S:\N \to \N$, $R:A \to (A \to \N \to A) \to \N \to A$,
128 \end{itemize}
129 Redexes comprise $\beta$-reduction, projections, 
130 and type specific reductions as reported in table \ref{tab:tredex}
131
132 \begin{table}[!h]
133 \hrule\vspace{0.1cm}
134 \begin{tabular}{p{0.34\textwidth}r}
135   $\lambda x:U.M ~ N \leadsto M[N/x]$ & $(\beta)$ \\
136   $fst \pair{M}{N} \leadsto M$ & $(\pi_1)$ \\
137   $snd \pair{M}{N} \leadsto N$ & $(\pi_2)$ \\
138   $D~M~N~ true \leadsto M$ & $(D_{true})$ \\
139   $D~M~N~false \leadsto N$ & $(D_{false})$ \\
140   $R~M~F~ 0 \leadsto M$ & $(R_0)$ \\
141   $R~M~F~(S~n) \leadsto F~n~(R~M~F~n)$ & $(R_S)$ \\
142   $M \leadsto * ~~~~ $ for any M of type $\one$ & $(*)$
143 \end{tabular}\vspace{0.1cm}
144 \hrule
145 \caption{\label{tab:tredex}Reduction rules for System T}
146 \end{table}
147
148 Note that using the well known isomorpshims 
149 $\one \to A \cong A$, $A \to \one \cong \one$
150 and $A \times \one \cong A \cong \one\times A$ (see \cite{AL91}, pp.231-239)
151 we may always get rid of $\one$ (apart the trivial case).
152 The terminal object does not play a major role in our treatment, but 
153 it allows to extract better algorithms. In particular we use it 
154 to realize atomic proposition, and stripping out the terminal object using 
155 the above isomorphisms gives a simple way of just keeping the truly 
156 informative part of the algorithms.
157
158 \Section{Heyting's arithmetics}
159
160 {\bf Axioms}
161
162 \begin{itemize}
163 \item $nat\_ind: P(0) \to (\forall x.P(x) \to P(S(x))) \to \forall x.P(x)$ 
164 \item $ex\_ind: (\forall x.P(x) \to Q) \to \exists x.P(x) \to Q$
165 \item $ex\_intro: \forall x.(P \to \exists x.P)$
166 \item $fst: P \land Q \to P$
167 \item $snd: P \land Q \to Q$
168 \item $conj: P \to Q \to P \land Q$
169 \item $false\_ind: \bot \to Q$
170 \item $discriminate:\forall x.0 = S(x) \to \bot$
171 \item $injS: \forall x,y.S(x) = S(y) \to x=y$
172 \item $plus\_O:\forall x.x+0=x$
173 \item $plus\_S:\forall x,y.x+S(y)=S(x+y)$ 
174 \item $times\_O:\forall x.x\mult0=0$
175 \item $times\_S:\forall x,y.x\mult S(y)=x+(x\mult y)$ 
176 \end{itemize}
177
178 \noindent
179 {\bf Inference Rules}
180
181 say that ax:AX refers to the previous Axioms list...
182 \begin{table}[!h]
183 \hrule\vspace{0.1cm}
184 \begin{tabular}{p{0.34\textwidth}r}
185   $\Gamma, x:A, \Delta \vdash x:A$ & $(Proj)$\\
186   $\Gamma \vdash ax : AX$ & $(Const)$\\
187   $\frac{\Gamma,x:A \vdash M:Q}{\Gamma \vdash \lambda x:A.M: A \to Q}$ & 
188     $(\to_i)$\\
189   $\frac{\Gamma \vdash M: A \to Q \hspace{0.5cm}\Gamma \vdash N: A}
190         {\Gamma \vdash M N: Q}$ & $(\to_e)$\\
191   $\frac{\Gamma \vdash M:P}{\Gamma \vdash \lambda x:\N.M: \forall x.P}(*)$ &
192     $(\forall_i)$\\
193   $\frac{\Gamma \vdash M :\forall x.P}{\Gamma \vdash M t: P[t/x]}$ &
194     $(\forall_e)$
195 \end{tabular}\vspace{0.1cm}
196 \hrule
197 \caption{\label{tab:HArules}Inference rules}
198 \end{table}{lr}
199
200 %\[ 
201 %   (\land_i)\frac{\Gamma \vdash M:A \hspace{1cm}\Gamma \vdash N:B}
202 %   {\Gamma \vdash \pair{M}{N} : A \land B} 
203 %\hspace{2cm}
204 %   (\land_{el})\frac{\Gamma \vdash A \land B}{\Gamma \vdash A}
205 %\hspace{2cm}
206 %   (\land_{er})\frac{\Gamma \vdash A \land B}{\Gamma \vdash B}  
207 %\]
208
209
210 %\[ 
211 %   (\exists_i)\frac{\Gamma \vdash P[t/x]}{\Gamma \vdash \exists x.P}\hspace{2cm}
212 %   (\exists_e)\frac{\Gamma \vdash \exists x.P\hspace{1cm}\Gamma \vdash \forall x.P \to Q}
213 %{\Gamma \vdash Q} 
214 %\]
215
216 \Section{Extraction}
217
218 The formulae to types translation function $\sem{\cdot}$, see table
219 \ref{tab:formulae2types}, takes in input formulae in HA and returns 
220 types in T. In table \ref{tab:structproof} we the proofs to terms
221 function for structured proofs. Axiom translation is reported in table 
222 \ref{tab:axioms}. In table \ref{tab:canonical} we define how the
223 canoniac element is formed.
224
225 \begin{table}[!h]
226 \hrule\vspace{0.1cm}
227 \begin{tabular}{p{0.21\textwidth}p{0.21\textwidth}}
228  $\sem{A} = \one$ if A is atomic &
229  $\sem{A \land B} = \sem{A}\times \sem{B}$ \\
230  $\sem{A \to B} = \sem{A}\to \sem{B}$ &
231  $\sem{\forall x:\N.P} = \N \to \sem{P}$ \\
232  $\sem{\exists x:\N.P} = \N \times \sem{P}$ &
233 \end{tabular}\vspace{0.1cm}
234 \hrule
235 \caption{\label{tab:formulae2types}Formulae to types translation}
236 \end{table}
237
238 \begin{table}[!h]
239 \hrule\vspace{0.1cm}
240 \begin{tabular}{p{0.20\textwidth}p{0.20\textwidth}}
241  $\semT{M N} = \semT{M} \semT{N}$ &
242  $\semT{M t} = \semT{M} \semT{t}$ \\
243  \multicolumn{2}{l}{$\semT{\lambda x:A.M} = \lambda x:\sem{A}.\semT{M}$} \\
244  \multicolumn{2}{l}{$\semT{\lambda x:\N.M} = \lambda x:\N.\semT{M}$} 
245 \end{tabular}\vspace{0.1cm}
246 \hrule
247 \caption{\label{tab:structproof}Structured proofs}
248 \end{table}
249
250 \begin{table}[!h]
251 \hrule\vspace{0.1cm}
252 \begin{tabular}{l}%{0.47\textwidth}p{0.47\textwidth}}
253  $\sem{fst} = \pi_1$\\
254  $\sem{snd} = \pi_2$\\
255  $\sem{conj} = \lambda x:\sem{P}.\lambda y:\sem{Q}.\pair{x}{y}$\\
256  $\sem{false\_ind} = \canonical_{\sem{Q}}$\\
257  $\sem{discriminate} = \lambda \_:\N.\lambda \_:\one.\star$\\
258  $\sem{injS}= \lambda \_:\N. \lambda \_:\N.\lambda \_:\one.\star$\\
259  $\sem{plus\_O} = \sem{times\_O} = \lambda \_:\N.\star$\\
260  $\sem{nat\_ind} = R$ \\
261  $\sem{plus\_S} = \sem{times\_S} = \lambda \_:\N. \lambda \_:\N.\star$ \\
262  $\sem{ex\_intro} = \lambda x:\N.\lambda f:\sem{P}.\pair{x}{f}$ \\
263  $\sem{ex\_ind} = \lambda f:(\N \to \sem{P} \to \sem{Q}).$\\
264    $\qquad\lambda p:\N\times \sem{P}.f~(fst~p)~(snd~p)$ 
265 \end{tabular}\vspace{0.1cm}
266 \hrule
267 \caption{\label{tab:axioms}Axioms translation}
268 \end{table}
269
270 \begin{table}[!h]
271 \hrule\vspace{0.1cm}
272 \begin{tabular}{l}%p{0.23\textwidth}p{0.23\textwidth}}
273  $\canonical_\one = \lambda x:\one.x$ \\
274  $\canonical_N = \lambda x:\one.0$ \\
275  $\canonical_{U\times V} = \lambda x:\one.\pair{\canonical_{U}
276    x}{\canonical_{V} x}$ \\
277  $\canonical_{U\to V} = \lambda x:\one.\lambda \_:U. \canonical_{V} x$
278 \end{tabular}\vspace{0.1cm}
279 \hrule
280 \caption{\label{tab:canonical}Canonical element}
281 \end{table}
282
283
284 \Section{Realizability}
285 The realizability relation is a relation $f \R P$ where $f: \sem{P}$, and
286 $P$ is a closed formula.
287 In particular:
288 \begin{itemize}
289 \item $\neg (\star \R \bot)$
290 \item $* \R (t_1=t_2)$ iff $t_1=t_2$ is true ...
291 \item $\pair{f}{g} \R (P\land Q)$ iff $f \R P$ and $g \R Q$
292 \item $f \R (P\to Q)$ iff for any $m$ such that $m \R P$, $(f \,m) \R Q$
293 \item $f \R (\forall x.P)$ iff for any natural number $n$ $(f n) \R P[\underline{n}/x]$
294 \item $\pair{n}{g}\R (\exists x.P)$ iff $g \R P[\underline{n}/x]$
295 \end{itemize}
296 %We need to generalize the notion of realizability to sequents.
297 %Given a sequent $B_1, \ldots, B_n \vdash A$ with free variables in 
298 %$\vec{x} = x_1,\ldots, x_m$, we say that $f \R B1, \ldots, B_n \vdash A$ iff 
299 %forall natural numbers $n_1, \ldots, n_m$, 
300 %if forall $i \in {1,\ldots,n}$ 
301 %$m_i \R B_i[\vec{\underline{n}}/\vec{x}]$ then
302 %$$f <m_1, \ldots, m_n> \R A[\vec{\underline{n}}/\vec{x}]$$.
303 %
304 \noindent
305 We need to generalize the notion of realizability to sequents.\\
306 Let $\vec{x} = FV_{\N}( B_1, \ldots, B_n, P)$ a vector of variables of type
307 $\N$ that occur free in $B_1, \ldots, B_n, P$. Let $\vec{b:B}$ the vector
308 $b_1:B_1, \ldots, b_n:B_n$.\\ 
309 We say that $f \R B_1, \ldots, B_n \vdash A:P$ iff
310 $$\lambda \vec{x:\N}. \lambda \vec{b:B}.f \R 
311 \forall \vec{x}. B_1 \to \ldots \to B_n \to P$$
312 Note that $\forall \vec{x}. B_1 \to \ldots \to B_n \to P$ is a closed formula,
313 so we can use the previous definition of realizability on it.
314
315 \noindent
316 We proceed to prove that all axioms $ax:Ax$ are realized by $\sem{ax}$.
317
318 \begin{itemize}
319 \item $nat\_ind$. 
320   We must prove that the recursion schema $R$ realizes the induction principle.
321   To this aim we must prove that for any $a$ and $f$ such that $a \R P(0)$ and
322   $f \R \forall x.(P(x) \to P(S(x)))$, and any natural number $n$, $(R \,a \,f
323   \,n) \R P(\underline{n})$.\\ 
324   We proceed by induction on n.\\ 
325   If $n=O$, $(R \,a \,f \,O) = a$ and by hypothesis $a \R P(0)$.\\ 
326   Suppose by induction that
327   $(R \,a \,f \,n) \R P(\underline{n})$, and let us prove that the relation
328   still holds for $n+1$.  By definition 
329   $(R \,a \,f \,(n+1)) = f \,n \,(R \,a \,f \,n)$, 
330   and since $f \R \forall x.(P(x) \to P(S(x)))$,  
331   $(f n (R a f n)) \R P(S(\underline{n}))=P(\underline{n+1})$.
332
333 \item $ex\_ind$. 
334   We must prove that $$\underline{ex\_ind} \R (\forall x:(P x)
335   \to Q) \to (\exists x:(P x)) \to Q$$ Following the definition of $\R$ we have
336   to prove that given\\ $f~\R~\forall~x:((P~x)~\to~Q)$ and
337   $p~\R~\exists~x:(P~x)$, then $\underline{ex\_ind}~f~p \R Q$.\\ 
338   $p$ is a couple $\pair{n_p}{g_p}$ such that $g_p \R P[\underline{n_p}/x]$, while
339   $f$ is a function such that forall $n$ and for all $m \R P[\underline{n}/x]$
340   then $f~n~m \R Q$ (note that $x$ is not free in $Q$ so $[\underline{n}/x]$
341   affects only $P$).\\
342   Expanding the definition of $\underline{ex\_ind}$, $fst$
343   and $snd$ we obtain $f~n_p~g_p$ that we know is in relation $\R$ with $Q$
344   since $g_p \R P[\underline{n_p}/x]$.
345
346 \item $ex\_intro$.
347   We must prove that 
348   $$\lambda x:\N.\lambda f:\sem{P}.\pair{x}{f} \R \forall x.(P\to\exists x.P(x)$$
349   that leads to prove that for each n
350   $\underline{ex\_into}~n \R (P\to\exists x.P(x))[\underline{n}/x]$.\\
351   Evaluating the substitution we have 
352   $\underline{ex\_into}~n \R (P[\underline{n}/x]\to\exists x.P(x))$.\\
353   Again by definition of $\R$ we have to prove that given a 
354   $m \R P[\underline{n}/x]$ then $\underline{ex\_into}~n~m \R \exists x.P(x)$.
355   Expanding the definition of $\underline{ex\_intro}$ we have
356   $\pair{n}{m} \R \exists x.P(x)$ that is true since $m \R P[\underline{n}/x]$.
357
358 \item $fst$.
359   We have to prove that $\pi_1 \R P \land Q \to P$, that is equal to proving
360   that for each $m \R P \land Q$ then $\pi_1~m \R P$ .
361   $m$ must be a couple $\pair{f_m}{g_m}$ such that $f_m \R P$ and $g_m \R Q$.
362   So we conclude that $\pi_1~m$ reduces to $f_m$ that is in relation $\R$
363   with $P$.
364
365 \item $snd$. The same for $fst$.
366
367 \item $conj$. 
368   We have to prove that 
369   $$\lambda x:\sem{P}. \lambda y:\sem{Q}.\pair{x}{y}\R P \to Q \to P \land Q$$
370   Following the definition of $\R$ we have to show that 
371   for each $m \R P$ and for each $n \R Q$ then 
372   $(\lambda x:\sem{P}. \lambda y:\sem{Q}.\pair{x}{y})~m~n \R P \land Q$.\\
373   This is the same of $\pair{m}{n} \R P \land Q$ that is verified since 
374   $m \R P$ and $n \R Q$.
375
376
377 \item $false\_ind$. 
378   We have to prove that $\bot_{\sem{Q}} \R \bot \to Q$. 
379   Trivial, since there is no $m \R \bot$.
380
381 \item $discriminate$. 
382   Since there is no $n$ such that $0 = S n$ is true... \\
383   $\underline{discriminate}~n \R 0 = S~\underline{n} \to \bot$ for each n.
384
385 \item $injS$.
386   We have to prove that for each $n_1$ and $n_2$\\
387   $\lambda \_:\N. \lambda \_:\N.\lambda \_:\one.*~n_1~n_2 \R 
388   (S(x)=S(y)\to x=y)[n_1/x][n_2/y]$.\\
389   We assume that $m \R S(n_1)=S(n_2)$ and we have to show that 
390   $\lambda \_:\N. \lambda \_:\N.\lambda \_:\one.*~n_1~n_2~m$ that reduces to
391   $*$ is in relation $\R$ with $n_1=n_2$. Since in the standard model of 
392   natural numbers  $S(n_1)=S(n_2)$ implies $n_1=n_2$ we have that 
393   $* \R n_1=n_2$.
394
395 \item $plus\_O$. 
396   Since in the standard model for natural numbers $0$ is the neutral element
397   for addition $\lambda \_:\N.\star \R \forall x.x + 0 = x$.
398
399 \item $plus\_S$.
400   In the standard model of natural numbers the addition of two numbers is the 
401   operation of counting the second starting from the first. So
402   $$\lambda \_:\N. \lambda \_:\N. \star \R \forall x,y.x+S(y)=S(x+y)$$.
403
404 \item $times\_O$.
405   Since in the standard model for natural numbers $0$ is the absorbing element
406   for multiplication $\lambda \_:\N.\star \R \forall x.x \mult 0 = 0$.
407   
408 \item $times\_S$.
409   In the standard model of natural numbers the multiplications of two 
410   numbers is the operation of adding the first to himself a number of times
411   equal to the second number. So
412   $$\lambda \_:\N. \lambda \_:\N. \star \R \forall x,y.x+S(y)=S(x+y)$$.
413   
414 \end{itemize}
415
416
417 \noindent
418 {\bf example}\\
419 Let us prove the following principle of well founded induction:
420 \[(\forall m.(\forall p. p < m \to P~p) \to P~m) \to \forall n.P~n\]
421 In the following proof we shall make use of proof-terms, since we finally
422 wish to extract the computational content; we leave to reader the easy
423 check that the proof object describes the usual and natural proof
424 of the statement.
425
426 We assume to have already proved the following lemmas (having trivial
427 realizers):\\
428 \[L : \forall p, q.p < q \to q \le 0 \to \bot\]
429 \[M : \forall p,q,n.p < q \to q \le (S n) \to p \le n \]
430 Let us assume $h : \forall m.(\forall p. p < m \to P~p) \to P~m$.
431 We prove by induction on $n$ that $\forall q. q \le n \to P~q$.
432 For $n=0$, we get a proof of $P ~q$ by 
433 \begin{eqnarray}
434 B & \equiv & \lambda q.\lambda h_0:q \le 0. h ~q~ \nonumber\\
435 & & \quad (\lambda p.\lambda k:p < q. false\_ind ~(L~p~q~k~h_0)) \nonumber
436 \end{eqnarray}
437 In the inductive case, we must prove that, for any $n$, 
438 \[(\forall q. q \le n \to P~q) \to (\forall q. q \le S n \to P~q)\]
439 Assume $h_1: \forall q. q \le n \to P q$ and
440 $h_2: q \le S ~n$. Let us prove $\forall p. p < q \to P~p$.
441 If $h_3: p < q$ then $(M~ p~ q~ n~ h_3~ h_2): p \le n$, hence 
442 $h_1 ~p ~ (M~ p~ q~ n~ h_3~ h_2): P~p$.\\ 
443 In conclusion, the proof of the 
444 inductive case is
445 \begin{eqnarray}
446 I & \equiv & \lambda n.\lambda h_1:\forall q. q \le n \to P~ q.\lambda q.\lambda h_2:q \le S n. \nonumber\\
447  & & \quad h ~ q ~ (\lambda p.\lambda h_3:p < q.h_1 ~p~ (M~ p~ q~ n~ h_3~ h_2))
448  \nonumber
449 \end{eqnarray}
450 (where $h$ is free in I).
451 The full proof is
452 \begin{eqnarray}
453 & \lambda h:\forall m.(\forall p. p < m\to P~p)\to P~m.\lambda m. &\nonumber\\
454 & \quad nat\_ind ~B ~ I ~m~m~ (le\_n ~ m) & \nonumber
455 \end{eqnarray}
456
457 where $le\_n$ is a proof that $\forall n. n \le n$, and the free $P$ in the definition of $nat_{ind}$ is instantiated with $\forall m.m \le m \to P~m$.\\
458 Form the previous proof,after stripping terminal objects, 
459 and a bit of eta-contraction to make
460 the term more readable, we extract the following term (types are omitted):
461
462 \[R' \equiv \lambda f.\lambda m.
463 R~ (\lambda n.f ~n~ (\lambda q.*))~ 
464 (\lambda n\lambda g\lambda q.f ~q~g)~m ~m\]
465
466 The intuition of this operator is the following: supose to
467 have a recursive definition $h q = F[h]$ where $q:\N$ and 
468 $F[h]: A$. This defines a functional 
469 $f: \lambda q.\lambda g.F[g]: N\to(N\to A) \to A$, such that
470 (morally) $h$ is the fixpoint of $f$. For instance, 
471 in the case of the fibonacci function, $f$ is 
472 \begin{eqnarray}
473 fibo & \equiv & \lambda q. \lambda g. if~ q = 0~then~ 1~ else \nonumber\\
474 & & \quad if~ q = 1~ then~ 1~ else ~ g (q-1)+g (q-2) \nonumber
475 \end{eqnarray}
476
477 So $f$ build a new 
478 approximation of $h$ from the previous approximation $h$ taken
479 as input. $R'$ precisely computes the mth-approximation starting
480 from a dummy function $(\lambda q.*_A)$. Alternatively, 
481 you may look at $g$ as the ``history'' (curse of values) of $h$ 
482 for all values less or equal to $q$; then $f$ extend $g$ to
483 $q+1$.
484
485 Let's compute for example 
486 \begin{eqnarray} 
487 R'~fibo~2 & \leadsto & 
488   R~ (\lambda n.fibo ~n~ (\lambda q.*))~ 
489   (\lambda n\lambda g\lambda q.fibo ~q~g)~2 ~2\nonumber\\
490 & \leadsto & 
491   (\lambda n\lambda g\lambda q.fibo ~q~g)~1~
492   (R~ 
493     (\lambda n.fibo ~n~ (\lambda q.*))~
494     (\lambda n\lambda g\lambda q.fibo ~q~g)~1)~
495   2 \nonumber\\
496 & \leadsto &  
497   \lambda q.fibo ~q~
498   (R~ 
499     (\lambda n.fibo ~n~ (\lambda q.*))~
500     (\lambda n\lambda g\lambda q.fibo ~q~g)~1)~
501   2 \nonumber\\
502 & \leadsto &  
503   \lambda q.fibo ~q~
504   ((\lambda n\lambda g\lambda q.fibo ~q~g)~0~
505   (R~ 
506     (\lambda n.fibo ~n~ (\lambda q.*))~
507     (\lambda n\lambda g\lambda q.fibo ~q~g)~0))~
508   2 \nonumber\\
509 & \leadsto &  
510   \lambda q.fibo ~q~
511   (\lambda q.fibo ~q~
512   (R~ 
513     (\lambda n.fibo ~n~ (\lambda q.*))~
514     (\lambda n\lambda g\lambda q.fibo ~q~g)~0)
515   )2 \nonumber\\
516 & \leadsto &  
517   \lambda q.fibo ~q~
518   (\lambda q.fibo ~q~
519   (\lambda n.fibo ~n~ (\lambda q.*)))2
520   \nonumber\\
521 & \leadsto &  
522   fibo~2~(\lambda q.fibo ~q~ (\lambda n.fibo ~n~ (\lambda q.*))) \nonumber\\
523 & \leadsto &  
524   (\lambda q.fibo ~q~ (\lambda n.fibo ~n~ (\lambda q.*))) 1 + 
525   (\lambda q.fibo ~q~ (\lambda n.fibo ~n~ (\lambda q.*))) 0 \nonumber\\
526 & \leadsto &  
527   fibo ~1~ (\lambda n.fibo ~n~ (\lambda q.*)) + 
528   fibo ~0~ (\lambda n.fibo ~n~ (\lambda q.*)) \nonumber\\
529 & \leadsto &  
530   1 + 1 \nonumber
531 \end{eqnarray}
532 Note that the second argument of $fibo$ is always a method to calculate all the prvious values of $fibo$. DA CAPIRE (per me) come mai $\lambda n$ non viene usata...
533 CAPITA CON csc:
534
535 n non serve perche' c'e' una relazione logica di n con q,
536 in particolare $q <= Sn$ ... quindi $q < n$ (lemma M)...
537 e quindi posso usare come history $< n$ una history $< q$.
538 il $\lambda h2$ essendo $[[q <= Sn]]$ = 1 viene scartata.
539
540 se si spiega come array viene decente... forse. lunedi' provo a scrivere
541 meglio.
542
543 \Section{Inductive types}
544 The notation we will use is similar to the one used in 
545 \cite{Werner} and \cite{Paulin89} but we prefer
546 giving a label to each constructor and use that label instead of the
547 longer $Constr(n,\ind\{\ldots\})$ to indicate the $n^{th}$ constructor.
548 We adopt the vector notation to make things more readable.
549 $\vec{m}$ has to be intended as $m_1~\ldots~m_n$ where $n$ may
550 be equal to 0 (we use $m_1~\vec{m}$ when we want to give a
551 name to the first $m$ and assert $n>0$). If the vector notation is
552 used inside an arrow type it has a slightly different meaning, 
553 $A \to \vec{B} \to C$ is a shortcut for 
554 $A \to B_1 \to \ldots \to B_n \to C$.
555
556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
557 \SubSection{Extensions to the logic framework}
558 To talk about arbitrary inductive types (and not hard coded natural numbers) we
559 have to extend a bit our framework.
560
561 First we admit quantification over inductive types $T$, thus $\forall x:T.A$
562 and $\exists x:T.A$ are allowed. Then rules 4 and 5 of the $\sem{\cdot}$
563 definition are replaced by $\sem{\forall x:T.P} = T \to \sem{P}$ and
564 $\sem{\exists x:T.P} = T \times \sem{P}$.
565
566 For each inductive type we will describe the formation rules and the
567 corresponding induction principle schema.
568
569 Symmetrically we have to extend System T with arbitrary inductive types and 
570 we will see how theyr recursors are defined in the following sections. 
571
572 The definition of $\R$ is modified substituting each occurrence of $\N$ with 
573 a generic inductive type $T$.
574
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
576 \SubSection{Type definition}
577 $$\ind\{c_1:C(X); \ldots ; c_n:C(X)\}$$
578 $$C(X) ::= X \| T \to C(X) \| X \to C(X)$$
579 In the second case we mean $T \neq X$.
580
581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582 \SubSection{Induction principle}
583 The induction principle for an inductive type $X$ and a predicate $Q$ 
584 is a constant with the following type
585 $$\Xind:\vec{\triUP\{C(X), c\}} \to \forall t:X.Q(t)$$
586 $\triUP$ takes a constructor type $C(X)$ and a term $c$ (initially $c$ is a
587 constructor of X, and $c:C(X)$) and is defined by recursion as follows:
588 \begin{eqnarray}
589 \triUP\{X, c\} & = & Q(c) \nonumber\\
590 \triUP\{T \to C(X), c\} & = & 
591         \forall m:T.\triUP\{C(X),c~m\} \nonumber\\
592 \triUP\{X \to C(X), c\} & = & 
593         \forall t:X.Q(t) \to \triUP\{C(X), c~t\} \nonumber
594 \end{eqnarray}
595
596 %%%%%%%%%%%%%%%%%%%%%
597 \SubSection{Recursor}
598 %\SubSubSection{Type}
599 The type of the recursor $\Rx$ on an inductive type $X$ is
600 $$\Rx : \vec{\square\{C(X)\}} \to X \to \alpha$$
601 $\square$ is defined by recursion on the constructor type $C(X)$.
602 \begin{eqnarray}
603 \square\{X\} & = & \alpha \nonumber \\
604 \square\{T \to C(X)\} & = & T \to \square\{C(X)\}\nonumber \\
605 \square\{X \to C(X)\} & = & X \to \alpha \to \square\{C(X)\}\nonumber 
606 \end{eqnarray}
607 %\SubSubSection{Reduction rules}
608 We say that 
609 $$\Rx~\vec{f}~(c_i~\vec{m}) \leadsto
610 \triDOWN\{C(X)_i, f_i, \vec{m}\}$$
611 $\triDOWN$ takes a constructor type $C(X)$, a term $f$ 
612 (of type $\square\{C(X)\}$) and is defined by recursion as follows:
613 \begin{eqnarray}
614 \triDOWN\{X, f, \} & = & f\nonumber \\
615 \triDOWN\{T \to C(X), f, m_1~\vec{m}\} & = &
616         \triDOWN\{C(X), f~m_1, \vec{m}\}\nonumber \\
617 \triDOWN\{X \to C(X), f, m_1~\vec{m}\} & = & 
618         \triDOWN\{C(X), f~m_1~(\Rx~\vec{f}~m_1),
619         \vec{m}\}\nonumber
620 \end{eqnarray}
621 We assume $\Rx~\vec{f}~(c_i~\vec{m})$ is well typed, so in the first case we
622 can omit $\vec{m}$ since it is an empty sequence.
623
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625 \SubSection{Realizability of the induction principle}
626 Once we have inductive types and their induction principle we want to show that
627 the recursor $\Rx$ realizes $\Xind$, that is that $\Rx$ has type 
628 $\sem{\Xind}$ and is in relation $\R$ with $\Xind$. 
629
630 \begin{thm}$\Rx : \sem{\Xind}$\end{thm}
631 \begin{proof}
632 We have to compare the definition of $\square$ and $\triUP$
633 since they play the same role in constructing respectively the types of 
634 $\Rx$ and
635 $\Xind$. If we assume $\alpha = \sem{Q}$ and we apply the $\sem{\cdot}$
636 function to each right side of the $\triUP$ definition we obtain
637 exactly $\square$. The last two elements of the arrows $\Rx$ and
638 $\Xind$ are again the same up to $\sem{\cdot}$.
639 \end{proof}
640
641 \begin{thm}$\Rx\R \Xind$\end{thm}
642 \begin{proof}
643 To prove that $\Rx\R \Xind$ we must assume that for each $i$ index
644 of a constructor of $X$, $f_i \R \triUP\{C(X)_i, c_i\}$ and we
645 have to prove that for each $t:X$
646 $$\Rx~\vec{f}~t \R Q(t)$$
647 \noindent
648 We proceed by induction on the structure of $t$.
649 \\
650 The base case is when the
651 type of the head constructor of $t$ has no recursive arguments (i.e. the type
652 is generated using only the first two rules $C(X)$), so
653 $(\Rx~\vec{f}~(c_i~\vec{m}))$ reduces in one step to $(f_i~\vec{m})$.  $f_i$
654 realizes $\triUP\{C(X)_i, c_i\}$ by assumption and since we are in the base
655 case $\triUP\{C(X)_i, c_i\}$ is of the form $\vec{\forall t:T}.Q(c_i~\vec{t})$.
656 Thus $f_i~\vec{m} \R Q(c_i~\vec{m})$.
657 \\ 
658 In the induction step we have as induction hypothesis that for each recursive
659 argument $t_i$ of the head constructor $c_i$, $r_i\equiv
660 \Rx~\vec{f}~t_i \R Q(t_i)$. By the third rule of $\triDOWN$ we obtain the reduct
661 $f_i~\vec{m}~\vec{t~r}$ (here we write first all the non recursive arguments,
662 then all the recursive one. In general they can be mixed and the proof is
663 exactly the same but the notation is really heavier). We know by hypothesis
664 that $f_i \R \triUP\{C(X)_i, c_i\} \equiv \vec{\forall m:T}.\vec{\forall
665 t:X.Q(t)} \to Q(c_i~\vec{m}~\vec{t})$, thus $f_i~\vec{m}~\vec{t~r} \R
666 Q(c_i~\vec{m}~\vec{t})$.
667 \end{proof}
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
669 \Section{Strong normalization of extended system T}
670 Strong normalization for system T is a well know result\cite{GLT}
671 that can be easily extended to System T with this kind of inductive
672 types. The first thing we have to do is to extend the definition of
673 neutral term to the terms not of the form $<u,v>$, $\lambda x.u$,
674 $c_i~\vec{m}$.
675
676 In conformity with the demonstration we are extending we call $\nu(t)$
677 the length of the longest reduction path from $t$ and $\ell(t)$ the
678 number of symbols in the normal form of $t$.
679
680 For an inductive type  $\ind\{c_1:C(X); \ldots ; c_n:C(X)\}$
681 we have to prove that for each $i$, 
682 given a proper sequence of reducible arguments $\vec{m}$ and $\vec{f}$,
683 $(c_i~\vec{m})$ and $\Rx~\vec{f}~(c_i~\vec{m})$ are reducible.
684
685 First the simple case of constructors. If the constructor $c_i$ takes
686 no arguments then it is already in normal form. If it takes
687 $m_1,\ldots,m_n$ reducible arguments, then $\nu(c_i~\vec{m}) = max \{m_1,
688 \ldots,m_n\}$ and so $c_i~\vec{m}$ is strongly nomalizable thus
689 reducible for the definition of reducibility for base types. 
690
691 To show that $\Rx~\vec{f}~(c_i~\vec{m})$ is reducible we can use 
692 (\textbf{CR 3}) that states that if $t$ is neutral and every $t'$ obtained by
693 executing one redex of $t$ is reducible, then $t$ is reducible.
694
695 Now we have to show that each term that can be obtained by a
696 reduction step is reducible. We can procede induction on 
697 $\Sigma\nu(f_i) + \nu(c_i~\vec{m}) +
698 \ell(c_i~\vec{m})$ since we know by  hypothesis that $\vec{f}$ and
699 $(c_i~\vec{m})$ are reducible and consequently strongly normalizing.
700 \\
701 The base case is when $c_i$ takes no arguments and $\vec{f}$ are
702 normal. In this case the only redex we can compute is 
703 $$\Rx~\vec{f}~c_i~\leadsto~f_i$$ that is reducible by hypothesis.
704 \\
705 The interesting inductive case is when $\vec{m}$ and $\vec{f}$ are
706 normal, so the only reduction step we can execute is
707 $$\Rx~\vec{f}~(c_i~\vec{m})~\leadsto~f_i~\vec{m}~\vec{(\Rx~\vec{f}~n)}$$
708 where $\vec{n}$ are the recursive arguments of $c_i$ (here we wrote
709 the recursive calls as the last parameters of $f_i$ just to  lighten
710 notation). Since $\ell(n_j)$ is less than $\ell(c_i~\vec{m})$ for
711 every $j$ we can apply the inductive hypothesis and state that
712 $\Rx~\vec{f}~n_j$ is reducible.  Then by definition of reducibility of
713 the arrow types and by the hypothesis that $f_i$ and $\vec{m}$ are
714 reducible, we obtain that $$f_i~\vec{m}~\vec{(\Rx~\vec{f}~n)}$$ is
715 reducible.
716 \\
717 All other cases, when we execute a redex in $\vec{m}$ or $\vec{f}$,
718 are straightforward applications of the induction hypothesis.
719
720
721 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
722 \Section{Improving inductive types}
723 It is possible to parametrise inductive types over other inductive types
724 without much difficulties since the type $T$ in $C(X)$ is free. Both the
725 recursor and the induction principle are schemas, parametric over $T$.
726
727 Possiamo anche definire $X_{\vec{P}}\equiv Ind(P|X)={c_i : C(P|X)}$ e poi
728 fare variare $T$ su $\vec{P}$, ma non ottengo niente di meglio.
729
730 Credo anche che quantificare su eventuali variabili di tipo non cambi niente
731 visto che non abbiamo funzioni.
732
733 Se ammettiamo che i tipi dipendano da termini di tipo induttivo
734
735
736 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
737 \bibliographystyle{latex8}
738 %\bibliography{latex8}
739
740 \begin{thebibliography}{}
741 \bibitem{AL91}A.Asperti, G.Longo. Categories, Types and Structures. 
742 Foundations of Computing, Cambrdidge University press, 1991.
743 \bibitem{Girard86}G.Y.Girard. The system F of variable types, fifteen
744 years later. Theoretical Computer Science 45, 1986.
745 \bibitem{Girard87}G.Y.Girard. Proof Theory and Logical Complexity. 
746 Bibliopolis, Napoli, 1987.
747 \bibitem{GLT}G.Y.Girard, Y.Lafont, P.Tailor. Proofs and Types.
748 Cambridge Tracts in Theoretical Computer Science 7.Cambridge University
749 Press, 1989.
750 \bibitem{Godel58}K.G\"odel. \"Uber eine bisher noch nicht ben\"utzte Erweiterung
751 des finiten Standpunktes. Dialectica, 12, pp.34-38, 1958.
752 \bibitem{Godel90}K.G\"odel. Collected Works. Vol.II, Oxford University Press,
753 1990.
754 \bibitem{HS86}J.R.Hindley, J. P. Seldin. Introduction to Combinators and 
755 Lambda-calculus, Cambridge University Press, 1986.
756 \bibitem{Howard68}W.A.Howard. Functional interpretation of bar induction
757 by bar recursion. Compositio Mathematica 20, pp.107-124. 1958
758 \bibitem{Howard80}W.A.Howard. The formulae-as-types notion of constructions.
759 in J.P.Seldin and j.R.Hindley editors, to H.B.Curry: Essays on Combinatory 
760 Logic, Lambda calculus and Formalism. Acedemic Press, 1980.
761 \bibitem{Kleene45}S.C.Kleene. On the interpretation of intuitionistic 
762 number theory. Journal of Symbolic Logic, n.10, pp.109-124, 1945.
763 \bibitem{Kreisel59} G.Kreisel. Interpretation of analysis by means of
764 constructive functionals of finite type. In. A.Heyting ed. 
765 {\em Constructivity in mathematics}. North Holland, Amsterdam,1959.
766  \bibitem{Kreisel62} G.Kreisel. On weak completeness of intuitionistic 
767 predicatelogic. Journal of Symbolic Logic 27, pp. 139-158. 1962.
768 \bibitem{Letouzey04}P.Letouzey. Programmation fonctionnelle 
769 certifi\'ee; l'extraction
770 de programmes dans l'assistant Coq. Ph.D. Thesis, Universit\'e de 
771 Paris XI-Orsay, 2004.
772 \bibitem{Loef}P.Martin-L\"of. Intuitionistic Type Theory.
773 Bibliopolis, Napoli, 1984.
774 \bibitem{Paulin87}C.Paulin-Mohring. Extraction de programme dans le Calcul de
775 Constructions. Ph.D. Thesis, Universit\'e de 
776 Paris 7, 1987.
777 \bibitem{Paulin89}C.Paulin-Mohring. Extracting $F_{\omega}$ programs 
778 from proofs in the Calculus of Constructions. In proc. of the Sixteenth Annual 
779 ACM Symposium on 
780 Principles of Programming Languages, Austin, January, ACML Press 1989.
781 \bibitem{Sch}K.Sch\"utte. Proof Theory. Grundlehren der mathematischen 
782 Wissenschaften 225, Springer Verlag, Berlin, 1977.
783 \bibitem{Troelstra}A.S.Troelstra. Metamathemtical Investigation of 
784 Intuitionistic
785 Arithmetic and Analysis. Lecture Notes in Mathematics 344, Springer Verlag,
786 Berlin, 1973.
787 \bibitem{TS}A.S.Troelstra, H.Schwichtenberg. Basic Proof Theory.
788 Cambridge Tracts in Theoretical Computer Science 43.Cambridge University
789 Press, 1996.
790 \bibitem{Werner}B.Werner. Une Th\'eorie des Constructions Inductives.
791 Ph.D.Thesis, Universit\'e de Paris 7, 1994.
792
793
794 \end{thebibliography}
795
796 \end{document}
797