1 \documentclass[a4paper]{article}
4 \usepackage{amssymb,amsmath,mathrsfs}
8 \newcommand{\sem}[1]{[\![ #1 ]\!]}
9 \newcommand{\R}{\;\mathscr{R}\;}
10 \newcommand{\N}{\,\mathbb{N}\,}
11 \newcommand{\NT}{\,\mathbb{N}\,}
12 \newcommand{\NH}{\,\mathbb{N}\,}
13 \renewcommand{\star}{\ast}
14 \newcommand{\one}{\mathbb{1}}
15 \renewcommand{\times}{\cdot}
16 \newcommand{\ind}{Ind(X)}
17 \title{Modified Realizability and Inductive Types}
28 \section{Introduction}
29 The characterization of the provable recursive functions of
30 Peano Arithmetic as the terms of system T is a well known
31 result of G\"odel \cite{Godel58,Godel90}. Although many authors acknowledge
32 that the functional interpretation of the Dialectica paper
33 is not among the major achievements of the author (see e.g. \cite{Girard87}),
34 the result has been extensively investigated and there is a wide
36 topic (see e.g. \cite{Howard68,Troelstra,Girard87}.
38 A different, more neglected, but for many respects much more
39 direct relation between Peano (or Heyting) Arithmetics and
40 G\"odel System T is provided
41 by the so called {\em modified realizability}. Modified realizability
42 was first introduced by Kreisel in \cite{Kreisel59} - although it will take you
43 a bit of effort to recognize it in the few lines of paragraph 3.52 -
44 and later in \cite{Kreisel62} under the name of generalized realizability.
45 The name of modified realizability seems to be due to Troelstra
47 - who contested Kreisel's name but unfortunately failed in proposing
48 a valid alternative; we shall reluctantly adopt this latter name
49 to avoid further confusion. Modified realizability is a typed variant of
50 realizability, essentially providing interpretations
51 of $HA^{\omega}$ into itself: each theorem is realized by a typed function
52 of system T, that also gives the actual computational content extracted
54 In spite of the simplicity and the elegance of the proof, it is extremely
55 difficult to find a modern discussion of this result; the most recent
56 exposition we are aware of is in the encyclopedic (typewritten!) work by
57 Troelstra \cite{Troelstra} (pp.213-229). Even modern introductory books
58 to Type Theory and Proof Theory devoting much space to system T
59 such as \cite{GLT} and \cite{TS} surprisingly leave out this simple and
60 illuminating result. Both \cite{GLT} and \cite{TS}
61 prefer to focus on higher order arithmetics and its relation with
62 Girard's System $F$ \cite{Girard86}, but the technical complexity and
63 the didactical value of the two proofs is not comparable: when you
64 prove that the Induction Principle is realized by the recursor $R$
65 of system $T$ you catch a sudden gleam of intelligence in the
66 students eyes; usually, the same does not happen when you show, say,
67 that the ``forgetful'' intrepretation of the higher order predicate defining
68 the natural numbers is the system $F$ encoding
69 $\forall X.(X\to X) \to X \to X$ of $\N$.
70 Moreover, after a first period of enthusiasm, the impredicative
71 encoding of inductive types in Logical Frameworks has shown several
72 problems and limitations (see e.g. \cite{Werner} pp.24-25) mostly
73 solved by assuming inductive types as a primitive logical notion
74 (leading e.g. form the Calculus of Constructions to the Calculus
75 of Inductive Constructions - CIC). Even the extraction algorithm of
76 CIC, strictly based on realizability principles, and in a first time
77 still oriented towards System F \cite{Paulin87,Paulin89} has been
78 recently rewritten \cite{Letouzey04}
79 to take advantage of concrete types and pattern matching of ML-like
80 languages. Unfortunately, systems like the Calculus of Inductive
81 Constructions are so complex, from the logical point of view, to
82 substantially prevent a really neat theoretical exposition (at present,
84 even exists a truly complete consistency proofs covering all aspects
85 of such systems); moreover, not eveybody may be interested in all the features
86 offered by these frameworks, from polymorphism to types depending on
87 proofs. Our program is to restart the analysis of logical systems with
88 primitive inductive types in a smooth way, starting form first order
89 logic and adding little by little small bits of logical power.
90 This paper is the first step in this direction.
99 \section{Heyting's arithmetics}
105 \item $nat\_ind: P(0) \to (\forall x.P(x) \to P(S(x))) \to \forall x.P(x)$
106 \item $ex\_ind: (\forall x.P(x) \to Q) \to \exists x.P(x) \to Q$
107 \item $ex\_intro: \forall x.(P \to \exists x.P)$
108 \item $fst: P \land Q \to P$
109 \item $snd: P \land Q \to Q$
110 \item $conj: P \to Q \to P \land Q$
111 \item $false\_ind: \bot \to Q$
112 \item $discriminate:\forall x.0 = S(x) \to \bot$
113 \item $injS: \forall x,y.S(x) = S(y) \to x=y$
114 \item $plus\_O:\forall x.x+0=x$
115 \item $plus\_S:\forall x,y.x+S(y)=S(x+y)$
116 \item $times\_O:\forall x.x\times0=0$
117 \item $times\_S:\forall x,y.x\times S(y)=x+(x\times y)$
121 {\bf Inference Rules}
124 (\to_i)\frac{\Gamma,x:A \vdash M:Q}{\Gamma \vdash \lambda x:A.M: A \to Q} \hspace{2cm}
125 (\to_e)\frac{\Gamma \vdash M: A \to Q \hspace{1cm}\Gamma \vdash N: A}
126 {\Gamma \vdash M N: Q}
130 % (\land_i)\frac{\Gamma \vdash M:A \hspace{1cm}\Gamma \vdash N:B}
131 % {\Gamma \vdash <M,N> : A \land B}
133 % (\land_{el})\frac{\Gamma \vdash A \land B}{\Gamma \vdash A}
135 % (\land_{er})\frac{\Gamma \vdash A \land B}{\Gamma \vdash B}
139 (\forall_i)\frac{\Gamma \vdash M:P}{\Gamma \vdash
140 \lambda x:\N.M: \forall x.P}(*) \hspace{2cm}
141 (\forall_e)\frac{\Gamma \vdash M :\forall x.P}{\Gamma \vdash M t: P[t/x]}
146 % (\exists_i)\frac{\Gamma \vdash P[t/x]}{\Gamma \vdash \exists x.P}\hspace{2cm}
147 % (\exists_e)\frac{\Gamma \vdash \exists x.P\hspace{1cm}\Gamma \vdash \forall x.P \to Q}
153 We have to extend systeem T with inductive types (and they recursors).
155 \item $\sem{A} = 1$ if A is atomic
156 \item $\sem{A \land B} = \sem{A}\times \sem{B}$
157 \item $\sem{A \to B} = \sem{A}\to \sem{B}$
158 \item $\sem{\forall x:T.P} = T \to \sem{P}$
159 \item $\sem{\exists x:T.P} = T \times \sem{P}$
163 For any type T of system T $\bot_T: 1 \to T$ is inuctively defined as follows:
165 \item $\bot_1 = \lambda x:1.x$
166 \item $\bot_N = \lambda x:1.0$
167 \item $\bot_{U\times V} = \lambda x:1.<\bot_{U} x,\bot_{V} x>$
168 \item $\bot_{U\to V} = \lambda x:1.\lambda \_:U. \bot_{V} x$
172 \item $\sem{nat\_ind} = R$
173 \item $\sem{ex\_ind} = (\lambda f:(\N \to \sem{P} \to \sem{Q}).
174 \lambda p:\N\times \sem{P}.f (fst \,p) (snd \,p)$.
175 \item $\sem{ex\_intro} = \lambda x:\N.\lambda f:\sem{P}.<x,f>$
176 \item $\sem{fst} = \pi_1$
177 \item $\sem{snd} = \pi_2$
178 \item $\sem{conj} = \lambda x:\sem{P}.\lambda y:\sem{Q}.<x,y>$
179 \item $\sem{false\_ind} = \bot_{\sem{Q}}$
180 \item $\sem{discriminate} = \lambda \_:\N.\lambda \_:1.\star$
181 \item $\sem{injS}= \lambda \_:\N. \lambda \_:\N.\lambda \_:1.\star$
182 \item $\sem{plus\_O} = \sem{times\_O} = \lambda \_:\N.\star$
183 \item $\sem{plus\_S} = \sem{times_S} = \lambda \_:\N. \lambda \_:\N.\star$
186 In the case of structured proofs:
188 \item $\sem{M N} = \sem{M} \sem{N}$
189 \item $\sem{\lambda x:A.M} = \lambda x:\sem{A}.\sem{M}$
190 \item $\sem{\lambda x:\N.M} = \lambda x:\N.\sem{M}$
191 \item $\sem{M t} = \sem{M} \sem{t}$
194 \section{Realizability}
195 The realizability relation is a relation $f \R P$ where $f: \sem{P}$.
198 \item $\neg (\star \R \bot)$
199 \item $* \R (t_1=t_2)$ iff $t_1=t_2$ is true ...
200 \item $<f,g> \R (P\land Q)$ iff $f \R P$ and $g \R Q$
201 \item $f \R (P\to Q)$ iff for any $m$ such that $m \R P$, $(f \,m) \R Q$
202 \item $f \R (\forall x.P)$ iff for any natural number $n$ $(f n) \R P[\underline{n}/x]$
203 \item $<n,g> \R (\exists x.P)$ iff $g \R P[\underline{n}/x]$
207 We proceed to prove that all axioms $ax:Ax$ are realized by $\sem{ax}$.
211 We must prove that the recursion schema $R$ realizes the induction principle.
212 To this aim we must prove that for any $a$ and $f$ such that $a \R P(0)$ and
213 $f \R \forall x.(P(x) \to P(S(x)))$, and any natural number $n$, $(R \,a \,f
214 \,n) \R P(\underline{n})$.\\
215 We proceed by induction on n.\\
216 If $n=O$, $(R \,a \,f \,O) = a$ and by hypothesis $a \R P(0)$.\\
217 Suppose by induction that
218 $(R \,a \,f \,n) \R P(\underline{n})$, and let us prove that the relation
219 still holds for $n+1$. By definition
220 $(R \,a \,f \,(n+1)) = f \,n \,(R \,a \,f \,n)$,
221 and since $f \R \forall x.(P(x) \to P(S(x)))$,
222 $(f n (R a f n)) \R P(S(\underline{n}))=P(\underline{n+1})$.
225 We must prove that $$\underline{ex\_ind} \R (\forall x:(P x)
226 \to Q) \to (\exists x:(P x)) \to Q$$ Following the definition of $\R$ we have
227 to prove that given\\ $f~\R~\forall~x:((P~x)~\to~Q)$ and
228 $p~\R~\exists~x:(P~x)$, then $\underline{ex\_ind}~f~p \R Q$.\\
229 $p$ is a couple $<n_p,g_p>$ such that $g_p \R P[\underline{n_p}/x]$, while
230 $f$ is a function such that forall $n$ and for all $m \R P[\underline{n}/x]$
231 then $f~n~m \R Q$ (note that $x$ is not free in $Q$ so $[\underline{n}/x]$
233 Exapanding the definition of $\underline{ex\_ind}$, $fst$
234 and $snd$ we obtain $f~n_p~g_p$ that we know is in relation $\R$ with $Q$
235 since $g_p \R P[\underline{n_p}/x]$.
239 $$\lambda x:\N.\lambda f:\sem{P}.<x,f> \R \forall x.(P\to\exists x.P(x)$$
240 that leads to prove that foreach n
241 $\underline{ex\_into}~n \R (P\to\exists x.P(x))[\underline{n}/x]$.\\
242 Evaluating the substitution we have
243 $\underline{ex\_into}~n \R (P[\underline{n}/x]\to\exists x.P(x))$.\\
244 Again by definition of $\R$ we have to prove that given a
245 $m \R P[\underline{n}/x]$ then $\underline{ex\_into}~n~m \R \exists x.P(x)$.
246 Expanding the definition of $\underline{ex\_intro}$ we have
247 $<n,m> \R \exists x.P(x)$ that is true since $m \R P[\underline{n}/x]$.
250 Wehave to prove that $\pi_1 \R P \land Q \to P$, that is equal to proving
251 that for each $m \R P \land Q$ then $\pi_1~m \R P$ .
252 $m$ must be a couple $<f_m,g_m>$ such that $f_m \R P$ and $g_m \R Q$.
253 So we conclude that $\pi_1~m$ reduces to $f_m$ that is in relation $\R$
256 \item $snd$. The same for $fst$.
259 We have to prove that
260 $$\lambda x:\sem{P}. \lambda y:\sem{Q}.<x,y> \R P \to Q \to P \land Q$$
261 Following the definition of $\R$ we have to show that
262 foreach $m \R P$ and foreach $n \R Q$ then
263 $(\lambda x:\sem{P}. \lambda y:\sem{Q}.<x,y>)~m~n \R P \land Q$.\\
264 This is the same of $<m,n> \R P \land Q$ that is verified since
265 $m \R P$ and $n \R Q$.
269 We have to prove that $\bot_{\sem{Q}} \R \bot \to Q$.
270 Trivial, since there is no $m \R \bot$.
272 \item $discriminate$.
273 Since there is no $n$ such that $0 = S n$ is true... \\
274 $\underline{discriminate}~n \R 0 = S~\underline{n} \to \bot$ for each n.
277 We have to prove that for each $n_1$ and $n_2$\\
278 $\lambda \_:\N. \lambda \_:\N.\lambda \_:1.*~n_1~n_2 \R
279 (S(x)=S(y)\to x=y)[n_1/x][n_2/y]$.\\
280 We assume that $m \R S(n_1)=S(n_2)$ and we have to show that
281 $\lambda \_:\N. \lambda \_:\N.\lambda \_:1.*~n_1~n_2~m$ that reduces to
282 $*$ is in relation $\R$ with $n_1=n_2$. Since in the standard model of
283 natural numbers $S(n_1)=S(n_2)$ implies $n_1=n_2$ we have that
287 Since in the standard model for natural numbers $0$ is the neutral element
288 for addition $\lambda \_:\N.\star \R \forall x.x + 0 = x$.
291 In the standard model of natural numbers the addition of two numbers is the
292 operation of counting the second starting from the first. So
293 $$\lambda \_:\N. \lambda \_:\N. \star \R \forall x,y.x+S(y)=S(x+y)$$.
296 Since in the standard model for natural numbers $0$ is the absorbing element
297 for multiplication $\lambda \_:\N.\star \R \forall x.x \times 0 = x$.
300 In the standard model of natural numbers the multiplications of two
301 numbers is the operation of adding the first to himself a number of times
302 equal to the second number. So
303 $$\lambda \_:\N. \lambda \_:\N. \star \R \forall x,y.x+S(y)=S(x+y)$$.
307 \section{Inductive types}
308 The notation we wwill use is similar to the one used in
309 \cite{Werner} and \cite{Paulin89} but we prefer
310 giving a label to each contructor and use that label instead of the
311 longer $Constr(n,\ind\{\ldots\})$ to indicate the $n^{th}$ constructor.
312 We adopt the vector notation to make things more readable.
313 $\overrightarrow{m}$ has to be intended as $m_1~\ldots~m_n$ where $n$ may
314 be equal to 0 (we use $m_1~\overrightarrow{m}$ when we want to give a
315 name to the first $m$ and assert $n>0$). If the vector notation is
316 used inside an arrow type it has a slightly different meaning,
317 $A \to \overrightarrow{B} \to C$ is a shortcut for
318 $A \to B_1 \to \ldots \to B_n \to C$
320 \subsection{Type definition}
321 $$\ind\{c_1:C(X); \ldots ; c_n:C(X)\}$$
324 \forall m:T.C(X) \quad | \quad
326 In the second case we need $(X \notin FV(T))$, while in the third we
327 need that POS(X,t) holds.
328 POS(X,t) is true iff t = X (POS has a meaning only for Higher Order...).
331 \subsection{Induction principle}
332 The induction principle for an inductive type $X$ and a predicate $Q$
333 is a constant with the following type
334 $$X_{ind}:\overrightarrow{\vartriangle\{C(X), c\}} \to \forall t:X.Q(x)$$
335 $\vartriangle$ takes a constructor type and the is defined by recursion on $C(X)$.
337 \vartriangle\{C(X), c\} & = & Q(c) \nonumber\\
338 \vartriangle\{\forall t:T.C(X), c\} & = &
339 \forall m:T.\vartriangle\{C(X),c~m\} \nonumber\\
340 \vartriangle\{t \to C(X), c\} & = &
341 \forall t:X.Q(t) \to \vartriangle\{C(X), c~t\} \nonumber
345 \subsection{Recursor}
347 The type of the recursor $R_X$ on an inductive type $X$ is
348 $$R_X : \overrightarrow{\square\{C(X)\}} \to X \to \alpha$$
349 $\square$ is defined by recursion on the contructor type $C(X)$.
351 \square\{X\} & = & \alpha \nonumber \\
352 \square\{\forall m:T.C(X)\} & = & T \to \square\{C(X)\}\nonumber \\
353 \square\{t \to C(X)\} & = & X \to \alpha \to \square\{C(X)\}\nonumber
355 \subsubsection{Reduction rules}
357 $$R_X~\overrightarrow{f}~(c_i~\overrightarrow{m}) \leadsto
358 \triangledown\{C(X)_i, f_i, \overrightarrow{m}\}$$
359 $\triangledown$ is defined by recursion on the constructor type $C(X)$.
361 \triangledown\{X, f, \overrightarrow{m}\} & = & f\nonumber \\
362 \triangledown\{\forall m:T.C(X), f, m_1~\overrightarrow{m}\} & = &
363 \triangledown\{C(X), f~m_1, \overrightarrow{m}\}\nonumber \\
364 \triangledown\{t \to C(X), f, m_1~\overrightarrow{m}\} & = &
365 \triangledown\{C(X), f~m_1~(R_X~\overrightarrow{f}~m_1),
366 \overrightarrow{m}\}\nonumber
369 \subsection{$R_X : \sem{X_{ind}}$ and $R_X\R X_{ind}$}
370 We have to compare the definition of $\square$ and $\vartriangle$
371 since thay play the same role in constructing respectively $R_X$ and
372 $X_{ind}$. If we assume $\alpha = \sem{Q}$ and we apply the $\sem$
373 function to each righ side of the $\vartriangle$ definition we obtain
374 exactly $\square$. The last two elements of the arrows $R_X$ and
375 $X_{ind}$ are again the same up to $\sem$.
377 questa non va bene, il caso base e' se il tipo del costruttore usa
378 solo le prime 2 regole di delta, quello induttivo se usa ANCHE la
381 To prove that $R_X\R X_{ind}$ we must assume that for each $i$ index
382 of a constructor of $X$, $f_i \R \vartriangle\{C(X)_i, c_i\}$ and we
383 have to proove that for each $t:X$
384 $$R_X~\overrightarrow{f}~t \R Q(t)$$.
385 We proceede by induction on the type of the head constructor $c_i$ in $t$.
386 The first base case is $c_i=X$ that, according to $\triangledown$,
388 step to $f_i$ and by hypothesis we have $f_i \R \vartriangle\{X,
389 c_i\}$. Unfolding $\vartriangle$ we have $f_i \R Q(c_i)$. The second
390 base case is $c_i=\overrightarrow{\forall t:T}.X$ and is analoug to
392 The inductive step is when we have one or more recursive aruments in
393 $c_i$ and the induction hypothesis is that for each recursve argument
394 $m$, $R_X~\overrightarrow{f}~m \R X \to Q$. Since $f_i \R
395 \vartriangle\{C(X)_i, c_i\}$ and
396 $R_X~\overrightarrow{f}~(c_i~\overrightarrow{m})$ reduces to
397 $f_i~\overrightarrow{...}$
404 \begin{thebibliography}{}
405 \bibitem{Girard86}G.Y.Girard. The system F of variable types, fifteen
406 years later. Theoretical Computer Science 45, 1986.
407 \bibitem{Girard87}G.Y.Girard. Proof Theory and Logical Complexity.
408 Bibliopolis, Napoli, 1987.
409 \bibitem{GLT}G.Y.Girard, Y.Lafont, P.Tailor. Proofs and Types.
410 Cambridge Tracts in Theoretical Computer Science 7.Cambridge University
412 \bibitem{Godel58}K.G\"odel. \"Uber eine bisher noch nicht ben\"utzte Erweiterung
413 des finiten Standpunktes. Dialectica, 12, pp.34-38, 1958.
414 \bibitem{Godel90}K.G\"odel. Collected Works. Vol.II, Oxford University Press,
416 \bibitem{Howard68}W.A.Howard. Functional interpretation of bar induction
417 by bar recursion. Compositio Mathematica 20, pp.107-124. 1958
418 \bibitem{Howard80}W.A.Howard. The formulae-as-types notion of constructions.
419 in J.P.Seldin and j.R.Hindley editors, to H.B.Curry: Essays on Combinatory
420 Logic, Lambda calculus and Formalism. Acedemic Press, 1980.
421 \bibitem{Kreisel59} G.Kreisel. Interpretation of analysis by means of
422 constructive functionals of finite type. In. A.Heyting ed.
423 {\em Constructivity in mathematics}. North Holland, Amsterdam,1959.
424 \bibitem{Kreisel62} G.Kreisel. On weak completeness of intuitionistic
425 predicatelogic. Journal of Symbolic Logic 27, pp. 139-158. 1962.
426 \bibitem{Letouzey04}P.Letouzey. Programmation fonctionnelle
427 certifi\'ee; l'extraction
428 de programmes dans l'assistant Coq. Ph.D. Thesis, Universit\'e de
429 Paris XI-Orsay, 2004.
430 \bibitem{Loef}P.Martin-L\"of. Intuitionistic Type Theory.
431 Bibliopolis, Napoli, 1984.
432 \bibitem{Paulin87}C.Paulin-Mohring. Extraction de programme dans le Calcul de
433 Constructions. Ph.D. Thesis, Universit\'e de
435 \bibitem{Paulin89}C.Paulin-Mohring. Extracting $F_{\omega}$ programs
436 from proofs in the Calculus of Constructions. In proc. of the Sixteenth Annual
438 Principles of Programming Languages, Austin, January, ACML Press 1989.
439 \bibitem{Sch}K.Sch\"utte. Proof Theory. Grundlehren der mathematischen
440 Wissenschaften 225, Springer Verlag, Berlin, 1977.
441 \bibitem{Troelstra}A.S.Troelstra. Metamathemtical Investigation of
443 Arithmetic and Analysis. Lecture Notes in Mathematics 344, Springer Verlag,
445 \bibitem{TS}A.S.Troelstra, H.Schwichtenberg. Basic Proof Theory.
446 Cambridge Tracts in Theoretical Computer Science 43.Cambridge University
448 \bibitem{Werner}B.Werner. Une Th\'eorie des Constructions Inductives.
449 Ph.D.Thesis, Universit\'e de Paris 7, 1994.
452 \end{thebibliography}