10.07.2015 Views

Decidability for non standard conversions in typed lambda calculus

Decidability for non standard conversions in typed lambda calculus

Decidability for non standard conversions in typed lambda calculus

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Decidability</strong> <strong>for</strong> Non-Standard Conversions<strong>in</strong> Typed Lambda-Calculi


Thèse de doctorat de l’université de Toulouse III - Paul SabatierInstitut de Recherche en In<strong>for</strong>matique de ToulouseÉcole Doctorale Mathématiques, In<strong>for</strong>matique et Télécommunications de Toulouse.Spécialité <strong>in</strong><strong>for</strong>matiqueDirigée en cotutelle / Ko-BetreuungDissertation an der Fakultät für Mathematik, In<strong>for</strong>matik und Statistik derLudwig-Maximilian-Universität München.<strong>Decidability</strong> <strong>for</strong> Non-Standard Conversions<strong>in</strong> Typed Lambda-CalculiFreiric BarralThèse pour obtenir le grade de docteur d’université.Dissertation zur Erlangung des Grades e<strong>in</strong>es Doktors derNaturwissenschaften.Supervisors:Prof. Dr. Mart<strong>in</strong> HofmannProf. Dr. Sergeï SolovievFirst external reviewer: Prof. Dr. Olivier DanvySecond external reviewer: Prof. Dr. Pierre DamphousseFirst exam<strong>in</strong>er:Prof. Dr. Rolf HennickerSecond exam<strong>in</strong>er: Prof. Dr. Hans Jürgen OhlbachDate of the oral exam<strong>in</strong>ation: 6 June 2008Munich, April 2008


ContentsAcknowledgements 1Introduction 31 Prelim<strong>in</strong>aries 111.1 Notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.2 Monads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Simply Typed λ-Calculus 152.1 System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.2 Normalization by Evaluation . . . . . . . . . . . . . . . . . . . . . . . 192.2.1 In<strong>for</strong>mal Description . . . . . . . . . . . . . . . . . . . . . . . 192.2.2 Normal Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.2.3 Name Generation Environment . . . . . . . . . . . . . . . . . 252.3 Formalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282.3.1 Name Generation Interpretation . . . . . . . . . . . . . . . . . 282.3.2 Monadic logical relation . . . . . . . . . . . . . . . . . . . . . 352.3.3 Correctness . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432.3.4 Completeness . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Conversions βη . . . . . . . . . . . . . . . . . . . . . . . . . . 51Completeness Lemma . . . . . . . . . . . . . . . . . . . . . . . 543 Generalized Applications 573.1 From Sequent Calculus to Λ J . . . . . . . . . . . . . . . . . . . . . . 583.2 Extended Conversions and Normal Forms . . . . . . . . . . . . . . . . 603.3 In<strong>for</strong>mal Description . . . . . . . . . . . . . . . . . . . . . . . . . . . 653.3.1 Several Attempts . . . . . . . . . . . . . . . . . . . . . . . . . 663.3.2 The B<strong>in</strong>d<strong>in</strong>g Variable Problem . . . . . . . . . . . . . . . . . . 683.4 Formalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694 Sums 754.1 System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.2 Extended Conversion and Normal Forms . . . . . . . . . . . . . . . . 80


viContents4.3 In<strong>for</strong>mal Description . . . . . . . . . . . . . . . . . . . . . . . . . . . 854.3.1 Several Attempts . . . . . . . . . . . . . . . . . . . . . . . . . 864.3.2 The B<strong>in</strong>d<strong>in</strong>g Variable Problem . . . . . . . . . . . . . . . . . . 874.3.3 Toward Completeness . . . . . . . . . . . . . . . . . . . . . . . 894.3.4 Normal Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . 914.4 Formalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935 Inductive Types 995.1 System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005.1.1 Types and Schemas . . . . . . . . . . . . . . . . . . . . . . . . 1005.1.2 Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1015.1.3 Reductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025.2 Extended Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . 1065.2.1 General Results . . . . . . . . . . . . . . . . . . . . . . . . . . 1065.2.2 Inductive Type Schemas as Functors . . . . . . . . . . . . . . 1075.3 Ma<strong>in</strong> Theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1095.3.1 Adjournment . . . . . . . . . . . . . . . . . . . . . . . . . . . 1095.3.2 Convergence of βηι 2 χ ◦ . . . . . . . . . . . . . . . . . . . . . . 1105.3.3 Pre-adjusted Adjournment . . . . . . . . . . . . . . . . . . . . 1125.3.4 Convergence of βηι 2 χ . . . . . . . . . . . . . . . . . . . . . . . 116Conclusion 121Index 122Bibliography 125Résumé 133Zusammenfassung 135Abstract 137


Acknowledgements 1My first thanks go to my supervisors Mart<strong>in</strong> Hofmann and Sergeï Soloviev.The faculty of Mart<strong>in</strong> Hofmann to quickly understand my ideas as well as hisability to always abstract the essential concepts, has been impressive.Sergeï Soloviev, <strong>in</strong> spite of the distance, has always been beh<strong>in</strong>d me, provid<strong>in</strong>gme with an <strong>in</strong>estimable guidance <strong>in</strong> my <strong>in</strong>tellectual <strong>for</strong>mation, and cont<strong>in</strong>uallysupport<strong>in</strong>g me <strong>in</strong> this sometimes morally exhaust<strong>in</strong>g enterprise.Helmut Schwichtenberg, is the man without whom this works would never havebeen possible, he supplied me both with the necessary f<strong>in</strong>ancial support and a stimulat<strong>in</strong>gresearch environment.I gratefully acknowledge the fund<strong>in</strong>g of the Graduierten Kolleg <strong>in</strong> der In<strong>for</strong>matikwhich allowed me to concentrate on my research and to participate to numerous<strong>in</strong>terest<strong>in</strong>g conferences.Thanks to Andreas Abel who has proof read significant parts of this thesis, s<strong>in</strong>cetheir foetusial versions. His careful read<strong>in</strong>gs is the cause of many technical correctionsand improvements. I want to thank Olivier Danvy and Pierre Damphousse tohave agreed to be my reviewers. The review of Olivier Danvy has led to many styleimprovements and bibliographical precisions. Of course, the rema<strong>in</strong><strong>in</strong>g errors andimprecisions are m<strong>in</strong>e and only m<strong>in</strong>e.My thanks go as well to David Chemouil who <strong>in</strong>troduced me <strong>in</strong> the field ofmodular rewrit<strong>in</strong>g, and to Ralph Matthes to have presented me the Λ J Calculus asthe ”simplest <strong>calculus</strong> with permutative <strong>conversions</strong>”.My colleagues and friends of the underground sem<strong>in</strong>ar, beside actively undergo<strong>in</strong>gmy talks have proved me that their is a life beyond the Ph.D: Diana Ratiu, LucaChiarab<strong>in</strong>i, Basil Karadais, Bogomil Kovachev, Markus Sauerman, Stefan Schimanskiand Trifon Trifonov.Special thanks to my wife Oksana.


2 Introduction


IntroductionThis thesis is concerned with the decidability of the theory of <strong>typed</strong> λ-calculi. Typedλ-calculi are <strong>for</strong>mal systems to explore the notion of computation, and as such, arefundamental tools <strong>in</strong> computer science. However, the study of the theory of the λ-<strong>calculus</strong> does not reduce solely to computer science. Its deep connections with logicand its mathematical clarity, have settled the basis of a fertile <strong>in</strong>teraction betweencomputer science, logic and mathematics. Understand<strong>in</strong>g the motivations of thetheory of λ-calculi leads one naturally to a detour by the study of its connectionswith logic and mathematics. We beg<strong>in</strong> with a brief history of the genesis of the λ-<strong>calculus</strong>, aimed at underl<strong>in</strong><strong>in</strong>g its strong <strong>in</strong>teraction with the development of logic.Orig<strong>in</strong>sThe λ-<strong>calculus</strong> comes from the attempt <strong>in</strong> the 1930s by Alonzo Church first <strong>in</strong> [25],and <strong>in</strong> a corrected version <strong>in</strong> [25] to build an alternative <strong>for</strong>malisation of mathematicswhose fundamental build<strong>in</strong>g blocks are functions. Soon, however his twostudents, Kleene and Rosser, prove his system <strong>in</strong> [59] to be <strong>in</strong>consistent, suffer<strong>in</strong>gfrom the same paradox, discovered <strong>in</strong> 1902 by Russell, which affects the foundationsof mathematics <strong>in</strong> terms of set theory.Church, Kleene and Rosser then give up this fundamental attempt and turn tothe study of computability with a tool at the basis of Church’s system of logic;this tool is nowadays known as the un<strong>typed</strong> λ-<strong>calculus</strong>. This m<strong>in</strong>imalist languagewith three symbols (two parentheses and a Greek letter) and a denumerable stockof variables will prove to have a high expressive power, it will even be proven to beTur<strong>in</strong>g complete, which is to say, accord<strong>in</strong>g to the Church-Tur<strong>in</strong>g thesis, that theun<strong>typed</strong> λ-<strong>calculus</strong> is the most expressive programm<strong>in</strong>g language, it can implementany computable functions.Among the numerous results obta<strong>in</strong>ed by Church <strong>for</strong> the λ-<strong>calculus</strong>, probably themost famous is the undecidability of convertibility of terms [26] <strong>in</strong> the un<strong>typed</strong> λ-<strong>calculus</strong>, i.e.,, whether two programs compute the same function. The subject of thisthesis tackles the opposite consideration, to f<strong>in</strong>d effectively computable proceduresto decide equality between terms. We will have there<strong>for</strong>e to restra<strong>in</strong> this equality<strong>for</strong> certa<strong>in</strong> classes of programs. The restriction used is a partial labell<strong>in</strong>g of the


4 Introductionλ-terms follow<strong>in</strong>g certa<strong>in</strong> rules, the terms which can not be labelled are ruled out ofthe system, this technique is known as typ<strong>in</strong>g.The theory of (ramified) types appears orig<strong>in</strong>ally <strong>in</strong> the work of Russell andWhitehead [93] to cure the set-theoretical foundations crisis of mathematics of thebeg<strong>in</strong>n<strong>in</strong>g of the century. This theory is roughly a way to classify propositionalsentences <strong>in</strong>to a hierarchy to avoid self-references which are at the heart of manyparadoxes (among them the paradox of Russell) underm<strong>in</strong><strong>in</strong>g the naïve set theoryof Cantor, considered then to be the only possible foundation of mathematics. Thistheory has <strong>in</strong>spired Church and Curry to develop <strong>typed</strong> versions of λ-calculi andcomb<strong>in</strong>atory logic (an analog to the λ-<strong>calculus</strong> where the explicit handl<strong>in</strong>g of abstractionand variable is abandoned and replaced by the use of primitive functionalcomb<strong>in</strong>ators).The work of Church and Curry, one work<strong>in</strong>g on the λ-<strong>calculus</strong>, the other oncomb<strong>in</strong>atory logic, are tightly <strong>in</strong>terleaved. They give <strong>in</strong> the same period their first<strong>for</strong>mulations of a functional theory of types, Curry <strong>in</strong> [36], Church <strong>in</strong> [27]. For anice exposition, the reader is <strong>in</strong>vited to consult [83].Logical MotivationIn 1934 <strong>in</strong> [44], Gentzen <strong>in</strong>vented two <strong>for</strong>mal systems to write deductions, naturaldeduction and sequent <strong>calculus</strong>, and proves his Hauptsatz <strong>for</strong> the sequent <strong>calculus</strong>.The Hauptsatz shows how it is possible to br<strong>in</strong>g deductions <strong>in</strong>to a normal <strong>for</strong>m,which are deductions of a simpler structure. Although sequent <strong>calculus</strong> is important<strong>in</strong> its own right (<strong>in</strong> particular <strong>in</strong> proof theory), we will focus on natural deduction,which has a much clearer relationship with programm<strong>in</strong>g.Prawitz, <strong>in</strong> 1965 <strong>in</strong> [77], rehabilitated natural deduction by prov<strong>in</strong>g an equivalentof the Hauptsatz <strong>for</strong> this system, the normalization of detour elim<strong>in</strong>ation (whichcorresponds to the β-reduction of the <strong>lambda</strong>-<strong>calculus</strong>).After Curry had noted a correspondence between his comb<strong>in</strong>atory logic andthe logic as <strong>for</strong>mulated by Hilbert, Howard, <strong>in</strong> 1969, extended this correspondencebetween natural deduction and λ-<strong>calculus</strong>. After hav<strong>in</strong>g circulated <strong>in</strong><strong>for</strong>mally <strong>for</strong>ten years and deeply <strong>in</strong>fluenced the community the manuscript of Howard [53] iseventually published. The correspondence po<strong>in</strong>ted out by Howard which relates<strong>for</strong>mulas and types, and proofs and terms is even an isomorphism, because thedetour elim<strong>in</strong>ation of proof <strong>in</strong> natural deduction corresponds to reductions <strong>in</strong> theλ-<strong>calculus</strong>.This isomorphism, known as the Curry-Howard isomorphism, provides a <strong>for</strong>malisationof the Brower-Heyt<strong>in</strong>g-Kolmogorov <strong>in</strong>terpretation of proofs as constructionsand marks the beg<strong>in</strong>n<strong>in</strong>g of a fertile period of <strong>in</strong>terplay between (ma<strong>in</strong>ly <strong>in</strong>tuitionistic)logic and computer science.It has given rise <strong>in</strong> turn to a bundle of logical systems based on the λ-<strong>calculus</strong>,<strong>in</strong>terpret<strong>in</strong>g the logical connectives as types, and proofs as terms; <strong>for</strong> example, the


Introduction 5type theory of Mart<strong>in</strong>-Löf [67], Girard/Reynolds System F [47; 79], the Calculusof Constructions of Coquand and Huet [33; 32], or the extension of the latter with<strong>in</strong>ductive types, the Calculus of Inductive Constructions [34].All these systems, <strong>for</strong>mulated us<strong>in</strong>g natural deduction, were proved stronglynormaliz<strong>in</strong>g follow<strong>in</strong>g a variation of the method of reducibility predicate orig<strong>in</strong>ally<strong>in</strong>troduced by Tait <strong>in</strong> [85] to prove a weak normalization <strong>for</strong> a <strong>calculus</strong> with comb<strong>in</strong>atorsand recursion operators.This change of perspective suggests to consider new <strong>conversions</strong>. Already <strong>in</strong> thesem<strong>in</strong>al works of Prawitz, other <strong>conversions</strong> than the traditional η or β-reductionare present, the so called permutative reduction or π-conversion <strong>for</strong> sum type andexistential type. They are needed <strong>in</strong> natural deduction <strong>in</strong> the presence of disjunctionor existential quantifiers <strong>in</strong> order to obta<strong>in</strong> normal <strong>for</strong>ms of deductions which satisfythe sub<strong>for</strong>mula property.Categorical MotivationThe real shift from a set-theoretical foundation to a functional foundation of mathematicshas been successfully achieved by category theory. In this light it is not surpris<strong>in</strong>gthat category theory had an important impact on both logic and λ-<strong>calculus</strong>.The works of Lambek and Scott [60; 61; 62; 63] are particularly illum<strong>in</strong>at<strong>in</strong>g, whereit is shown that there is an isomorphism between Cartesian Closed Categories andthe theory of λ-calculi, and that categories are deductive systems with an equivalencerelation on proofs. The categorical analysis of proofs and their equality hass<strong>in</strong>ce then been pursued (<strong>in</strong> particular <strong>in</strong> the works [66] of Mann, and [72] of M<strong>in</strong>ts).The π-<strong>conversions</strong> of Prawitz, mentioned above, have a very natural mean<strong>in</strong>g <strong>in</strong>category theory, they hold <strong>in</strong> fact automatically, if type <strong>for</strong>mers are <strong>in</strong>terpreted us<strong>in</strong>guniversal properties, e.g., × is <strong>in</strong>terpreted as categorical product, =⇒ as exponentialobject, etc. But other <strong>non</strong>-<strong>standard</strong> <strong>conversions</strong> hold as well. The categorical <strong>in</strong>terpretationgives us <strong>in</strong> fact extensional models of λ-calculi, and hence all the possible<strong>conversions</strong> we might want to add.We may not want to have such a powerful conversion relation (which correspondsto an extensional equality). For example <strong>in</strong> the case of <strong>in</strong>ductive types, extensionalequality is known to be undecidable. Still, the categorical perspective can be aguidel<strong>in</strong>e, if we want to strengthen the conversion relation, as it implies categoricalproperties to hold directly <strong>in</strong> our <strong>calculus</strong>. The question could now be whatproperties do we want to have <strong>in</strong> our <strong>calculus</strong>?Programm<strong>in</strong>g Motivation and ApplicationsAs already mentioned, the λ-<strong>calculus</strong> turns out to be a powerful tool to study computability.Its high level of abstraction as opposed to other model of computationsuch as Von Neumann models make it a convenient paradigmatic programm<strong>in</strong>g lan-


6 Introductionguage to concentrate on the program <strong>in</strong>dependently of the mach<strong>in</strong>e the program isto be implemented on. Its <strong>in</strong>fluence had spread over the whole computer sciencecommunity (see [12]). In particular, functional languages are implementations ofthe λ-<strong>calculus</strong> with some primitives added.Although far from the fundamental considerations of Russell, the advent of typesystems <strong>in</strong> programm<strong>in</strong>g languages has analogously structured values and programs<strong>in</strong> order to <strong>for</strong>bid <strong>in</strong>coherences.Experience shows that a great number of bugs can be detected automatically bya pass of type <strong>in</strong>ference be<strong>for</strong>e actually runn<strong>in</strong>g the program. However the ga<strong>in</strong> oftyp<strong>in</strong>g is not limited to bug elim<strong>in</strong>ation. It allows <strong>for</strong> example <strong>for</strong> optimization: ifwe know by typ<strong>in</strong>g that a program can be trans<strong>for</strong>med <strong>in</strong> another one respect<strong>in</strong>g thesame specification and that this later is more efficient (although maybe less natural<strong>for</strong> human eyes), why not take the later? Two examples are partial <strong>typed</strong> directedevaluation and de<strong>for</strong>estation. In fact these two are examples of extended <strong>conversions</strong>as we will consider throughout this thesis.Another nice application of strengthened conversion relation is the ability todecide provable isomorphisms between types. Two types are isomorphic if theycarry the same <strong>in</strong><strong>for</strong>mation organized differently, i.e.,, if there exists function <strong>for</strong>thand back between this two types such that their composition is the identity. Acharacterisation of provable isomorphisms <strong>in</strong> a Cartesian closed category is first givenby Soloviev <strong>in</strong> [84] and <strong>in</strong>dependently by Bruce, Di Cosmo and Longo <strong>in</strong> [22]. Rittri<strong>in</strong> [82] uses isomorphisms <strong>for</strong> retrieval methods <strong>in</strong> a library of programs (see [35] <strong>for</strong>a detailed exposition). Another application is the design of algorithms to be appliedgenerically to a class of isomorphic datatypes, an example of an implementation isdescribed <strong>in</strong> the paper of Atanassow and Jeur<strong>in</strong>g [6].Maybe the greatest outcome of the advent of types <strong>in</strong> programm<strong>in</strong>g and logicis the possibility to express <strong>in</strong> a same uni<strong>for</strong>m framework, thanks to the Curry-Howard isomorphism, programs, properties thereof and checkable proofs. In suchenvironment, on the one hand, proofs of properties of programs can be checkedautomatically and correctness of programs reaches a higher level of confidence, andon the other hand parts of proofs can be seen as programs which allow <strong>for</strong> moreautomation of <strong>for</strong>mal proofs. For such a proof assistant to be convenient, it shouldobviously do as much as possible of these automations to assist the user <strong>in</strong> theobvious part and let him concentrate on the tedious part. A possible solution toachieve this goal is once aga<strong>in</strong> to strengthen the decidable conversion relation ofsuch proof assistants.State of the ArtThe m<strong>in</strong>imal theory of every λ-<strong>calculus</strong> is a computational equality <strong>for</strong> functions, theβ-equality, two terms are equal if they reduce through β-reductions to a same third,where β-reduction is an evaluation step <strong>for</strong> a program applied to an argument, which


Introduction 7substitute this argument to the first <strong>for</strong>mal parameter of the program. In particular,this equality identifies programs at different states of their evaluation.Another conversion, traditionally not considered as a computational one, is η-conversion, this equality identifies terms with ”dummy” abstractions: <strong>for</strong> each functionalprogram p 1 of one argument, one can construct another program p 2 tak<strong>in</strong>gone argument and apply<strong>in</strong>g the program p 1 to this argument. In λ-<strong>calculus</strong> notations,one writes that p 2 is def<strong>in</strong>ed by λx.p 1 x. So p 1 and p 2 are essentially the sameprogram, and η-equality identifies them.The β- together with η-equality lead to an extensional equality <strong>for</strong> the simply<strong>typed</strong> λ-<strong>calculus</strong>. Two terms of the simply <strong>typed</strong> λ-<strong>calculus</strong> are equal with respectto βη-equality if and only if their <strong>in</strong>terpretations are the same <strong>in</strong> an extensionalmodel. Roughly, programs which <strong>for</strong> the same argument return the same result areidentified. Moreover, this equality is decidable <strong>for</strong> the simply <strong>typed</strong> λ-<strong>calculus</strong>.This extensional equality is much harder to decide as soon as one wants toextend or generalise the system. There is no problem <strong>in</strong> add<strong>in</strong>g a product type,or unit type (see <strong>for</strong> example the book Proof and Types of Girard, Lafont, Taylor[48]). Add<strong>in</strong>g sum types is already much more problematic, and design<strong>in</strong>g a decid<strong>in</strong>galgorithm is a <strong>non</strong> trivial task, if obta<strong>in</strong>ed by reduction based normalization as byGhani (see [45]), or reduction free normalization ; an algorithm is implicitly present<strong>in</strong> a constructive proof of Altenkirch et al. [4], and a type directed Normalizationalgorithm is obta<strong>in</strong>ed <strong>in</strong> [9] by Balat, us<strong>in</strong>g a call-by-value <strong>in</strong>terpretation and controloperators (where although some strong h<strong>in</strong>ts are given to justify the algorithm, thecorrectness is not rigorously proven). For <strong>in</strong>ductive types, it is even known thatextensional equality is undecidable ([76], or [51]). This problem of undecidabilityleads one to consider a conversion relation stronger than merely β, but still weakerthan the extensional one.Permutative reductions com<strong>in</strong>g directly from logic <strong>in</strong> the tradition of Prawitzare such an example. A proof <strong>for</strong> strong normalization has been given <strong>in</strong>itially byPrawitz <strong>in</strong> [78] <strong>for</strong> second-order natural deduction, but needed some supplementarydetails to be complete. This completion of the proof has be given only recently byTatsuta and M<strong>in</strong>ts <strong>in</strong> [87] and [86]. Other proofs of strong normalization <strong>for</strong> systemswith permutative conversion have been studied by Joachimski and Matthes <strong>in</strong> [55]<strong>for</strong> a generalisation of the simply <strong>typed</strong> λ-<strong>calculus</strong> called Λ J and the sum type andby David and Nour <strong>for</strong> classical natural deduction with disjunction <strong>in</strong> [75] and byMatthes <strong>for</strong> second-order natural deduction [70].These permutative <strong>conversions</strong>, although be<strong>in</strong>g a real improvement on the mereβ-(or βη-)<strong>conversions</strong> seem to be <strong>in</strong> some cases too weak (why tak<strong>in</strong>g permutativeconversion <strong>for</strong> sum type when one can have extensional equality?) or maybe toostrong (<strong>in</strong> case of <strong>in</strong>ductive types).Another possibility, <strong>in</strong>spired by category theory, is to design the conversion relation<strong>in</strong> order to obta<strong>in</strong> certa<strong>in</strong> properties to be decidable, <strong>for</strong> example classes ofisomorphisms, see Barthes and Pons [15], or Chemouil [23].


8 IntroductionThe λ-calculi with the reductions we propose to add are an <strong>in</strong>stance of higherorderrewrite systems whose general theory is there<strong>for</strong>e relevant <strong>for</strong> us. Significantresults <strong>for</strong> extend<strong>in</strong>g <strong>typed</strong> λ-<strong>calculus</strong> by higher order rewrite systems have beenobta<strong>in</strong>ed by Blanqui us<strong>in</strong>g the General Schema [21], and Walukiewicz-Chrzaszcz↩[92] us<strong>in</strong>g a higher order version of the recursive path order<strong>in</strong>g. Nonetheless, the<strong>conversions</strong> (oriented as rewrite rules) we will discuss <strong>for</strong> <strong>in</strong>ductive type are notcaptured by these two frameworks.The work of Matthes [68] extends system F to allow primitive recursion onmonotone <strong>in</strong>ductive types, by replac<strong>in</strong>g the syntactical strict positivity condition bya monotonicity witness obligation packed <strong>in</strong>to the <strong>in</strong>ductive def<strong>in</strong>ition. Abel, Uustaluand Matthes then extend iteration to nested <strong>in</strong>ductive types <strong>in</strong> [1]. Although notconsidered, add<strong>in</strong>g <strong>conversions</strong> to such systems would be the natural cont<strong>in</strong>uationof these works.Related WorkDisregard<strong>in</strong>g the question of decidability, there is a too large field of study devotedto equality of functional programs to be able to give an exhaustive account. Maybean <strong>in</strong>fluential paper is the one of Backus [8], where some equational laws are stated<strong>for</strong> an algebra of programs. It was further developed by Bird [20] and Meertens[71], who developed a computational approach, <strong>for</strong> program trans<strong>for</strong>mation, nowknown as the Bird-Meertens <strong>for</strong>malism. Malcolm develop<strong>in</strong>g the work of Hag<strong>in</strong>o [49]generalises the result of Bird and Meertens <strong>for</strong> arbitrary datatypes by categoricalconsiderations [64]. The recent developments and applications of trans<strong>for</strong>mationalmethod abound ; Wadler, <strong>for</strong> example, presents certa<strong>in</strong> proofs of equality as a resultof the abstraction theorem of Reynolds [91].OverviewAn equality is decidable when one has an algorithm to decide it. This statementof the obvious leads us not only to study proofs of decidability but to study thedecid<strong>in</strong>g algorithms as well. We focus essentially on normalization algorithms. Thepr<strong>in</strong>ciple is to first select a set of normal <strong>for</strong>ms <strong>for</strong> which we have a decidable equality(syntactical equality <strong>for</strong> example) and to design an algorithm which map every termsto a convertible normal <strong>for</strong>m.The traditional way of normaliz<strong>in</strong>g a term system is to consider a conversionrelation as generated by a rewrite system and to take as normal <strong>for</strong>ms the irreducibleterms: normalization then boils down to reduction.Algorithms follow<strong>in</strong>g these reduction strategy <strong>for</strong> normalization, also called reductionbasedalgorithms, are however not the only possibility, we will see <strong>in</strong> particular examplesof a class of reduction-free algorithm, called normalization by evaluation.


Introduction 9The pr<strong>in</strong>ciple is to evaluate the <strong>in</strong>terpretation of the term we want to normalize <strong>in</strong>a suitable model or language, and to def<strong>in</strong>e a function which gives back a normal<strong>for</strong>m from a value.After some prelim<strong>in</strong>aries <strong>in</strong> the first chapter, the second chapter describes thenormalization by evaluation algorithm <strong>for</strong> the simplest <strong>typed</strong> system, the simply<strong>typed</strong> <strong>calculus</strong>. While normalization by evaluation <strong>for</strong> the simply <strong>typed</strong> λ-<strong>calculus</strong>is well known, special care is taken here to handle variables properly but still <strong>in</strong> an<strong>in</strong>tuitive way.The third chapter is concerned with the study of the simplest system, admitt<strong>in</strong>gadditional <strong>conversions</strong>, the Λ J -<strong>calculus</strong>, which generalises the λ-<strong>calculus</strong> with anotion of double substitution.Even <strong>for</strong> simple type systems where extensional equality is decidable such asthe simply <strong>typed</strong> λ-<strong>calculus</strong> enriched by sum type, the algorithms to decide theequality are quite <strong>in</strong>tricate. The fourth chapter presents a simple algorithm to decideconversion of a <strong>calculus</strong> with strong sums. The algorithm <strong>in</strong> these three chaptershave all been implemented <strong>in</strong> the functional programm<strong>in</strong>g language Haskell.The fifth chapter studies some possible conversion relations <strong>for</strong> <strong>in</strong>ductive types.


10 Introduction


Chapter 1Prelim<strong>in</strong>aries1.1 NotationsWe <strong>in</strong>troduce here notations used throughout this thesis.Notation 1 (b<strong>in</strong>der). The use a dot to separate a b<strong>in</strong>der of a variable from its scopemeans that the scope has to be extended as much as it is syntactically possible to theleft. For example <strong>in</strong> λx.rs, x is bound <strong>in</strong> r and s.Notation 2 (set-theoretic notations). We will write A + B <strong>for</strong> the disjo<strong>in</strong>t unionof the sets A and B, the <strong>in</strong>jection of an element a ∈ A (resp. b ∈ B) <strong>in</strong>to A + Bwill be written ι A a (resp. ι B b).The function space between the sets A and B will be written A → B. To dist<strong>in</strong>guishwith the λ-abstraction of syntactic term which is just written with a s<strong>in</strong>gle<strong>lambda</strong> λ, the abstraction at the semantic level (<strong>in</strong> the pseudo-programm<strong>in</strong>g languageused to describe the algorithms) is written with a bold <strong>lambda</strong> . The function applicationof a function f to an element a will sometimes be written as a syntacticapplication, i.e., we will use the notation fa, <strong>in</strong>stead of the more traditional notationf(a).The cartesian product of the sets A and B is written A × B.Moreover we allow pattern match<strong>in</strong>g <strong>in</strong> semantic abstraction. For example ifwe are abstract<strong>in</strong>g over a cartesian product, we will write: (v1, v2).p <strong>in</strong>stead ofwrit<strong>in</strong>g v.p and us<strong>in</strong>g projections <strong>in</strong> the body p of the algorithm. Similarly, if weare abstract<strong>in</strong>g over the element of a one element set {⊥}, we will write ⊥.p.Notation 3 (list of syntactic expressions). We will use the appropriate vector notation−→ e = e 1 , . . . , e n <strong>for</strong> f<strong>in</strong>ite lists of syntactic expressions. The empty list will bewritten ε. With<strong>in</strong> more complex type and term expressions it is to be unfolded asfollows:


12 1. Prelim<strong>in</strong>ariestypes(ρ, −→ ρ ) → σ ::= ρ → −→ ρ → σε → σ ::= σabstractionsλ(x, −→ x ).r ::= λx.λ −→ x .rλε.r ::= rapplicationsr(s, −→ s ) ::= (rs) −→ srε ::= rcompositionr σ→τ ◦ s −→ ρ →σ ::= λ −→ x ρ .r(s −→ x )1.2 MonadsWe will describe algorithms which depend <strong>in</strong> an essential way on the order of evaluation.The use of monads allows to both fix the order of evaluation and provideatomic operations to structure these algorithms <strong>in</strong> a pure functional sett<strong>in</strong>g. Anotheradvantage is that they have a direct mathematical mean<strong>in</strong>g, and avoid to relyon a particular programm<strong>in</strong>g language. We present here the monads we will use <strong>in</strong>a set-theoretic version.There exists several equivalent def<strong>in</strong>ition of monads (see [65]), we give here adef<strong>in</strong>ition convenient to describe computations.Def<strong>in</strong>ition 1.1 (Monad). A monad M is a triple 〈M, ν, ⋆〉 where M maps everyset A to a set MA, ν is a family of functions ν A : A → MA, and ⋆ is a familyof functions ⋆ A,B : MA × (A → MB) → MB (application of ⋆ is written <strong>in</strong> <strong>in</strong>fixnotation), such that:ν A (a) ⋆ A,B f = fam ⋆ A,A ν A = m(beta)(eta)(m ⋆ A,B f) ⋆ B,C g = m ⋆ A,C (a.f(a) ⋆ B,C g) (assoc)The family of functions ν is called the unit of the monad, and the family of functions⋆ is called the multiplication of the monad.


1.2 Monads 13Notation 4. We will <strong>in</strong> the follow<strong>in</strong>g omit to write the <strong>in</strong>dices of the family ⋆ andν.Example 1 (Identity Monad). The triple 〈I, id, ; 〉 where I maps every set A to itselfIA = A, id is the identity function, and ; is def<strong>in</strong>ed by a; f = f(a) is a monad andis called the identity monad.To express our algorithms we will need two k<strong>in</strong>d of monads ; a state readermonad, and an exception monad. The state reader monad will be used to expresscomputations shar<strong>in</strong>g a same environment.Def<strong>in</strong>ition 1.2 (State reader Monad).set operator St E (−) def<strong>in</strong>ed by:Given a set E, a state reader monad is aSt E (A) ::= E → Atogether with the family of functions ν : A → St E (A) and ⋆ : St E (A) × (A →St(B)) → St E (B) def<strong>in</strong>ed by:ν(a)(e) ::= a(m ⋆ f)(e) ::= f(m(e))eOne checks easily (one needs functional extensionality) that <strong>for</strong> a given set E, M isa monad <strong>in</strong> the sense of def<strong>in</strong>ition 1.1.Remark 1. The state monad ST E = E → A × E is a more general monad. We donot need here the full generality of the state monad because our computations willnot need to modify the environment (so that the computation does not need to returnthe environment e ∈ E <strong>in</strong> addition to a value a ∈ A, but merely a value <strong>in</strong> A).The exception monad is used to express computations which may fail. In thiscase, special values are returned which detail the cause of the failure.Def<strong>in</strong>ition 1.3 (Exception Monad).operator − ⊥(E) def<strong>in</strong>ed by:Given a set E, an exception monad is a setA ⊥(E) ::= E + Awhere E + A is the disjo<strong>in</strong>t union of E and A. together with the family of functionsν : A → A ⊥(E) and ⋆ : A ⊥(E) × (A → B ⊥(E) ) → B ⊥(E) def<strong>in</strong>ed by:ν(a) ::= ι A aι A a ⋆ f ::= f(a)ι E e ⋆ f ::= ι E ewhere ι A (resp. ι E ) is the ca<strong>non</strong>ical <strong>in</strong>jection from A (resp. E) <strong>in</strong> E + A.


14 1. Prelim<strong>in</strong>ariesIn the def<strong>in</strong>ition above the value e ∈ E stands <strong>for</strong> the exceptional value and thevalue a ∈ A as the normal value (as a mnemonic, the right value is on the rightside).When the set E <strong>in</strong>volved <strong>in</strong> the def<strong>in</strong>ition of the exception monad above is a oneelement set {∗}, there is no <strong>in</strong><strong>for</strong>mation associated with the exception, we will justwrite A ⊥ <strong>for</strong> A ⊥({∗}) . This monad is called the partiality monad.The two basic operations associated to handle exception are throw<strong>in</strong>g an exceptionand catch<strong>in</strong>g/handl<strong>in</strong>g an exception. For commodity we give the def<strong>in</strong>itionhere:Def<strong>in</strong>ition 1.4 (throw and catch). The functions throw : E → A ⊥(E) and catch :A ⊥(E) → (E → A ⊥(E) ) → A ⊥(E) associated with an exception monad − ⊥(E) aredef<strong>in</strong>ed as follows:throw e ::= ι E e{mcatch mh ::=heif m = ι A aif m = ι E e<strong>for</strong> m ∈ A ⊥(E) , and h ∈ E → A ⊥(E) .Apart of the follow<strong>in</strong>g chapter (2) where we use only one state reader monad, wewill use mostly a comb<strong>in</strong>ations of the monads above. Although comb<strong>in</strong><strong>in</strong>g monadsdoes not present any difficulty <strong>in</strong> simple cases, there is no ca<strong>non</strong>ical way to comb<strong>in</strong>etwo monads <strong>in</strong>to a new one (Some authors propose abstract methods [57; 56; 46], butthese are <strong>in</strong>eluctably partial solutions). We will refra<strong>in</strong> to describe here the (simple)comb<strong>in</strong>ations we use, and postpone the def<strong>in</strong>itions to the concerned chapters.


Chapter 2Simply Typed λ-CalculusIn this chapter we handle the simply <strong>typed</strong> <strong>calculus</strong> and devise a normalization byevaluation algorithm <strong>for</strong> it.This system is certa<strong>in</strong>ly the simplest, the most studied and the best-known ofthe <strong>typed</strong> λ-calculi. This will give us the opportunity to expla<strong>in</strong> <strong>in</strong><strong>for</strong>mally thealgorithm. Then, the notion of freshness <strong>for</strong> variables is <strong>for</strong>malised via monadsand from these considerations, a rigorous and orig<strong>in</strong>al treatment follows <strong>in</strong> the lastsection.2.1 SystemDef<strong>in</strong>ition 2.1 (types). Given a ground type o, the set of types Ty of the simply<strong>typed</strong> λ-<strong>calculus</strong> is def<strong>in</strong>ed <strong>in</strong>ductively by:Ty ∋ ρ, σ ::= o | ρ → σWe will work throughout this thesis with <strong>typed</strong> λ-calculi à la Church, i.e., werequire a b<strong>in</strong>der to assign a type to the variable it b<strong>in</strong>ds. While our algorithmsextend without difficulty to λ-calculi à la Curry (i.e., b<strong>in</strong>ders do not assign typeto variable), proofs are generally simpler <strong>in</strong> <strong>typed</strong> λ-calculi à la Church ; anotheradvantage to work with λ-calculi à la Church is their direct relationship to naturaldeduction by the so-called Curry-Howard isomorphism (see the logical motivationsection of the <strong>in</strong>troduction, p.4).Def<strong>in</strong>ition 2.2 (terms). Given a countable <strong>in</strong>f<strong>in</strong>ite set of term variables Var, theset of terms Tm of the simply <strong>typed</strong> λ-<strong>calculus</strong> is def<strong>in</strong>ed <strong>in</strong>ductively by:Tm ∋ r, s ::= x | λx ρ .r | rswhere x is a variable (x ∈ Var), and ρ is a type (ρ ∈ Ty).


16 2. Simply Typed λ-CalculusA term r, can conta<strong>in</strong> a same subterm s at different places, <strong>in</strong> this cases we willspeak about the different occurrences of the subterm s <strong>in</strong> r. An occurrence of avariable x is free <strong>in</strong> a term r if it does not appear <strong>in</strong> a subterm of r of the <strong>for</strong>mλx ρ .t, otherwise the occurrence of x is said to be bound (it is bound by the b<strong>in</strong>derλ of the smallest subterm λx ρ .t conta<strong>in</strong><strong>in</strong>g x). A variable x is said to be free <strong>in</strong> aterm r, if there is free occurrence of x <strong>in</strong> r.Notation 5. For readability, we will sometimes omit to write the type of the boundvariable (i.e., we will write λx.t <strong>in</strong>stead of λx ρ .t) if it is clear from the context orirrelevant.A term is closed if the set of its free variables is empty. The set of free variablesof a term can be simply computed:Def<strong>in</strong>ition 2.3 (Set of free variables of a term).FV(r) of a term r <strong>in</strong>ductively as follows:We def<strong>in</strong>e the set of free variablesFV(x) ::= xFV(λx.r) ::= FV(r) \ {x}FV(rs) ::= FV(r) ∪ FV(s)Typ<strong>in</strong>g contexts associate types to variables, they will be used <strong>in</strong> the def<strong>in</strong>itionof typ<strong>in</strong>g below to associate a type to each free variable of a term,Def<strong>in</strong>ition 2.4 (typ<strong>in</strong>g context). We def<strong>in</strong>e a typ<strong>in</strong>g context as a f<strong>in</strong>ite set ofpairs (x : ρ) of a variable and a type such that <strong>for</strong> two pairs (x : ρ) and (y : σ) <strong>in</strong> asame typ<strong>in</strong>g context, x ≠ y.The typ<strong>in</strong>g relation associates types to terms, under the precondition that freevariables <strong>in</strong> the term have already been assigned some types.Def<strong>in</strong>ition 2.5 (typ<strong>in</strong>g). The typ<strong>in</strong>g relation is a ternary relation between contexts,terms and types and is def<strong>in</strong>ed <strong>in</strong>ductively by(x : ρ) ∈ ΓΓ, x : ρ ⊢ r : σΓ ⊢ r : ρ → σ Γ ⊢ s : ρΓ ⊢ x : ρ (Var) Γ ⊢ λx ρ .r : ρ → σ (→I) Γ ⊢ rs : σ(→E)Notation 6. We will write Tm ρ Γ<strong>for</strong> the set of terms r typable with type ρ <strong>in</strong> contextGamma (i.e., Γ ⊢ r : ρ) and Tm ρ <strong>for</strong> the set of terms r of type ρ such that thereexists a context Γ with r ∈ Tm ρ Γ .Be<strong>for</strong>e giv<strong>in</strong>g the theory, i.e., the <strong>conversions</strong> of the simply <strong>typed</strong> λ-<strong>calculus</strong>, weneed to def<strong>in</strong>e substitution. To avoid a phenomena known as capture of variable (afree variable <strong>in</strong> a term become bound when the term is substituted), this substitutionhas to be done modulo renam<strong>in</strong>g of bound variables. In a first step we def<strong>in</strong>e a


2.1 System 17contextual substitution which does not avoid capture of variables, this will allow usto def<strong>in</strong>e <strong>in</strong> a second step both renam<strong>in</strong>g of bound variables (or α-conversion) anda correct notion of substitution.Def<strong>in</strong>ition 2.6 (contextual substitution). Given a list of dist<strong>in</strong>ct variables −→ x =x 1 , . . . , x n and of terms −→ r = r 1 , . . . , r n of same length, the effect of the contextualsubstitution [ −→ x / −→ r ] is def<strong>in</strong>ed by <strong>in</strong>duction on Tm as follows:{x[ −→ xr/ −→ i if x = x i ∧ x i ∈ −→ x ,r ] =x otherwise{(λx.r)[ −→ xλx.r[/ −→ r ] =x 1,...,x i−1 ,x i+1 ,...,x n/r1 ,...,r i−1 ,r i+1 ,...,r n] if x = x i ∧ x i ∈ −→ xλx.r[ −→ x / −→ r ]otherwise(rs)[ −→ x / −→ r ] =(r[ −→ x / −→ r ])(s[ −→ x / −→ r ])In the above def<strong>in</strong>ition, a capture of variable can happen <strong>in</strong> the second clause, ifthe bound variable x of the term λx.r occurs free <strong>in</strong> one of the term r j ∈ −→ r be<strong>in</strong>gactually substituted <strong>in</strong> λx.r, (if x ∈ FV(r j ) and x j ∈ FV(λx.r) <strong>for</strong> r j ∈ −→ r ).In the follow<strong>in</strong>g we will def<strong>in</strong>e <strong>conversions</strong> on λ-terms expressed as axioms. These<strong>conversions</strong> are the smallest congruence relations conta<strong>in</strong><strong>in</strong>g these axioms. A congruencerelation is an equivalence relation which is contextually closed (terms differ<strong>in</strong>gby convertible subterms will be convertible). We make this notion precise with thefollow<strong>in</strong>g def<strong>in</strong>ition.Def<strong>in</strong>ition 2.7 (Contextual closure and equivalence).closed if the follow<strong>in</strong>g rules holdA relation = R is contextuallyr = R srt = R st (R-AppL)Structural rules:r = R str = R ts (R-AppR)r = R sλx.r = R λx.s (R-ξ)The α-conversion expresses that the choice of the precise names of <strong>for</strong>mal parametersof a function has no <strong>in</strong>fluence on the actual mean<strong>in</strong>g or behaviour of thisfunction.Def<strong>in</strong>ition 2.8 (α-conversion).The axiom of α-conversion is given byλx.r = α λy.r[ x /y] y ∉ FV(r) (α)We can now def<strong>in</strong>e a capture avoid<strong>in</strong>g substitution.


18 2. Simply Typed λ-CalculusDef<strong>in</strong>ition 2.9 (correct substitution). Given a list of dist<strong>in</strong>ct variables −→ x =x 1 , . . . , x n and of terms −→ s = s 1 , . . . , s n of same length, the effect of the correctsubstitution { −→ x / −→ s } is def<strong>in</strong>ed as follows:r{ −→ x / −→ s } = r ′ [ −→ x / −→ s ]where r = α r ′ and if a variable y occurs free <strong>in</strong> s i , then no occurrence of x i appearswith<strong>in</strong> a subterm of r ′ of the <strong>for</strong>m λy.t.The correct substitution is thus a well-def<strong>in</strong>ed function only if λ-terms are consideredup to α-conversion.Remark 2. A well established practice <strong>in</strong> the literature is to just ignore the differencebetween terms and terms modulo α-conversion and not <strong>in</strong>troduce new notations todist<strong>in</strong>guish these two classes. It is safe <strong>in</strong> general, because most notions, properties ordef<strong>in</strong>itions are equivalently def<strong>in</strong>ed on a particular term or on a class of terms moduloα-conversion (as typ<strong>in</strong>g), or make only sense modulo α-conversion (as substitution).We will follow this practice here because it improves readability and the ma<strong>in</strong> concernof this work is the decidability of conversion and not the renam<strong>in</strong>g of bound variables.However, we will study algorithms which produce genu<strong>in</strong>e syntactic terms, not classof terms, and will underl<strong>in</strong>e abuses of notations where the difference is sensitive.The theory = βη of the simply <strong>typed</strong> λ-<strong>calculus</strong> Λ is def<strong>in</strong>ed as the union of theconversion = β and = η below. These <strong>conversions</strong> are understood between terms,typable with the same type <strong>in</strong> a same context.Notation 7. We will write Γ ⊢ r = R s : ρ, if the terms r and s are R-convertibleand typable <strong>in</strong> the context Γ with type ρ and just r = R s if the context Γ and thetype ρ are already clear from the context or if their mentions is irrelevant.The computational part of the conversion is given by the β-conversion.Def<strong>in</strong>ition 2.10 (β-conversion).The axiom of β-conversion is given by(λx.r)s = β r{ x /s}(β)The axiom of η-conversion is the axiom of extensionality <strong>for</strong> the simply <strong>typed</strong>λ-<strong>calculus</strong>.Def<strong>in</strong>ition 2.11 (η-conversion).The axiom of η-conversion is given byr = η λx.rx (x ∉ FV(r)) (η)Because the def<strong>in</strong>ition of β-conversion uses substitution, the β and βη conversionare only def<strong>in</strong>ed on classes of terms convertible by α-conversion. These <strong>conversions</strong>are extended to terms by stat<strong>in</strong>g that terms <strong>in</strong> convertible classes are convertible.


2.2 Normalization by Evaluation 192.2 Normalization by Evaluation2.2.1 In<strong>for</strong>mal DescriptionGiven a term language Tm, i.e., a term algebra generated from variables and (possiblyb<strong>in</strong>d<strong>in</strong>g) symbols, with an equality or conversion relation = E between terms,generated by contextual closure from a set of equations E, normal <strong>for</strong>ms are considered<strong>in</strong> an abstract way as representatives of each equivalence class modulo = Ewith certa<strong>in</strong> desirable property.Because here we are <strong>in</strong>terested <strong>in</strong> the decidability of the conversion relation, thisproperty will be the decidability of conversion between terms considered as normal<strong>for</strong>ms.Focus<strong>in</strong>g on a normalization function rather than on normal <strong>for</strong>ms, an abstractdef<strong>in</strong>ition of normalization function could be <strong>for</strong>mulated as followsDef<strong>in</strong>ition 2.12 (Normalization Function). Given a decidable equality ≡⊆= E anormalization function is a function nf : Tm → Tm with the follow<strong>in</strong>g property:r = E nf(r),r = E s ⇔ nf(r) ≡ nf(s).If the function nf term<strong>in</strong>ates then it provides a decision algorithm of the conversionrelation = E , because ≡ is decidable.Remark that ≡⊆= E trivially implies nf(r) ≡ nf(s) ⇒ r = E s. This allows usto use a modified <strong>for</strong>mulation of this def<strong>in</strong>ition, provided by the follow<strong>in</strong>g (easy)lemma:Lemma 1. Given a decidable equality ≡⊆= E , a function nf : Tm → Tm is anormalization function if and only if:r = E nf(r),r = E s ⇒ nf(r) ≡ nf(s).(i)(ii)The essential idea of Normalization by Evaluation is to def<strong>in</strong>e a semantics of ourlanguage Tm conta<strong>in</strong><strong>in</strong>g enough <strong>in</strong><strong>for</strong>mation to be able to extract a term nf(r) fromthe <strong>in</strong>terpretation of a term r, such that nf is a normalization function.For this, one needs a function ↓, called reify, from the semantics to the termlanguage.For the ↓ function to be able to produce terms, the semantics should alreadyconta<strong>in</strong> some piece of syntax; this is called a residualiz<strong>in</strong>g semantics.In this <strong>in</strong>troductory section, we expose <strong>in</strong><strong>for</strong>mally the Normalization by Evaluationalgorithm <strong>for</strong> the simply <strong>typed</strong> λ-<strong>calculus</strong> with βη-equality. It has been firstdesigned by Ulrich Berger and Helmut Schwichtenberg [19].The semantics is given by the <strong>standard</strong> set-theoretic <strong>in</strong>terpretation with theground type <strong>in</strong>terpreted as the set of terms of ground type.


20 2. Simply Typed λ-CalculusDef<strong>in</strong>ition 2.13 (Type Interpretation).ρ, by <strong>in</strong>duction on ρ ∈ Ty:We def<strong>in</strong>e the <strong>in</strong>terpretation ρ of a typeo ::= Tm oρ → σ ::= ρ → σwhere Tm o is the set of all (closed and open) terms of ground type o, and ρ → σis the full function space between the set ρ and σ.The <strong>in</strong>terpretation of types Ty of the simply <strong>typed</strong> <strong>lambda</strong> <strong>calculus</strong> Λ is then:Ty = ⋃ρρ∈TyTo def<strong>in</strong>e the <strong>in</strong>terpretation of terms we need first to def<strong>in</strong>e the auxiliary notionof valuation.Def<strong>in</strong>ition 2.14 (Valuation). Given a context Γ, we def<strong>in</strong>e a valuation on Γ(η Γ) to be a partial function η : Var → Ty ⊥such that <strong>for</strong> x : ρ ∈ Γ, we haveη(x) is def<strong>in</strong>ed and η(x) ∈ ρ. Given a context Γ, a valuation η on Γ, a variabley ∉ Γ and an element a ∈ σ, we def<strong>in</strong>e a valuation (η, y ↦→ a) on Γ ∪ {(y : σ)},called the extension of η by y ↦→ a by,{a if x = y,(η, y ↦→ a)(x) ::=η(x) otherwise.Remark 3. Valuation functions are partial functions represented as total functionsfrom the set of variables Var <strong>in</strong>to the set Ty ⊥= Ty + {⋆}, i.e., the <strong>in</strong>terpretationof types extended with an element ⋆ play<strong>in</strong>g the rôle of an undef<strong>in</strong>ed value. In thefollow<strong>in</strong>g, whenever we will use a valuation applied to some variable, this variablewill belong to the doma<strong>in</strong> of def<strong>in</strong>ition of the valuation and the result will there<strong>for</strong>ebe def<strong>in</strong>ed. And although, strictly speak<strong>in</strong>g we should do a case dist<strong>in</strong>ction on theresult to know wheither it is def<strong>in</strong>ed (an alternative would be to use an exceptionmonad as presented <strong>in</strong> def<strong>in</strong>ition 1.3), we will consider it to be an element of Ty.After hav<strong>in</strong>g def<strong>in</strong>ed the <strong>in</strong>terpretation of a type as a set, we now def<strong>in</strong>e the<strong>in</strong>terpretation of a term simply as an element of the <strong>in</strong>terpretation of its type:Def<strong>in</strong>ition 2.15 (Term Interpretation). We def<strong>in</strong>e the <strong>in</strong>terpretation r η of aterm r, whenever there is a context Γ, such that Γ ⊢ r : ρ and η is a valuation on Γ,to be an element of ρ, by the follow<strong>in</strong>g <strong>in</strong>ductive def<strong>in</strong>ition:x η ::= η(x)λx ρ .r η (v) ::= r η,x↦→vrs η ::= r η (s η )


2.2 Normalization by Evaluation 21The reify function ↓ from the <strong>in</strong>terpretation of the types Ty to the term languageTm will be def<strong>in</strong>ed by simultaneous <strong>in</strong>duction on the types as a function ↓ ρfrom the <strong>in</strong>terpretation ρ of a type ρ to the set of terms Tm ρ of type ρ togetherwith a function ↑ ρ called reflect 1 from Tm ρ to ρ.Def<strong>in</strong>ition 2.16 (Reify ↓ and Reflect ↑). The functions ↓ ρ : ρ → Tm ρ and↑ ρ : Tm ρ → ρ are def<strong>in</strong>ed by simultaneous <strong>in</strong>duction on ρ ∈ Ty by:↑ o e ::= e(↑ ρ→σ e)(a) ::= ↑ σ e(↓ ρ a)↓ o e ::= e↓ ρ→σ f ::= λx ρ . ↓ σ (f(↑ ρ x)) (x new)The function ↓ at arrow type creates a variable x and returns an abstractionwith respect to this variable. In<strong>for</strong>mally, the condition ”x new” ensures that thisabstraction b<strong>in</strong>ds only occurrences correspond<strong>in</strong>g to this created variable x. Themathematical <strong>for</strong>malisation is somewhat technical and we will deal with it later on.Remark and notation 1. The <strong>in</strong>terpretations of the types are disjo<strong>in</strong>t, hence thefunction ↓: Ty → Tm def<strong>in</strong>ed by ↓= ⋃ ρ∈Ty ↓ ρ is well def<strong>in</strong>ed.On the contrary, sets of terms typable by different types are not disjo<strong>in</strong>t (a variable,<strong>for</strong> example, can be <strong>typed</strong> with all types). Hence eras<strong>in</strong>g the type ρ <strong>in</strong> ↑ ρ doesnot <strong>for</strong>mally make sense.However, to improve readability, we will <strong>in</strong> both cases, sometimes write ↓ and ↑<strong>in</strong>stead of ↓ ρ and ↑ ρ when the type ρ is clear from the context .Notation 8. For a given type ρ, we have ↑ ρ x ∈ ρ, hence ↑ can be considered asa valuation function on any context Γ. We will not <strong>in</strong>troduce a new notation <strong>in</strong> thiscase.For example <strong>for</strong> a <strong>typed</strong> term Γ ⊢ r : σ, <strong>in</strong> r ↑ , ↑ shall denote the valuationdef<strong>in</strong>ed on all variables x such that x : ρ ∈ Γ by ↑ σ x.We are now <strong>in</strong> position to def<strong>in</strong>e the normalization function nf.Def<strong>in</strong>ition 2.17 (The nf function).The function nf : Tm → Tm is def<strong>in</strong>ed by:nf(r) ::=↓ r ↑For now, we want to give a justification that nf is <strong>in</strong>deed a normalization function,we want to verify (i) r = βη nf(r) and (ii) r = βη s ⇒ nf(r) ≡ nf(s) where ≡⊆ βη issyntactical equality.1 One f<strong>in</strong>d also the names quote and unquote <strong>for</strong> ↓ and ↑ <strong>in</strong> the literature.


22 2. Simply Typed λ-CalculusJustification of r = βη nf(r)To justify r = βη nf(r) we will present <strong>in</strong><strong>for</strong>mally a proof due to Mart<strong>in</strong> Hofmann[52], which uses a logical relation. The idea is to relate a term r of type τ and avalue a of the <strong>in</strong>terpretation of τ by a logical relation R τ ⊆ Tm τ × τ, such thatx R τ ↑ xr R τ a ⇒ r = βη ↓ aBecause R is a logical relation (logical relations are presented <strong>in</strong> more detail <strong>in</strong>the next section), the so-called basic lemma holds:Lemma 2 (Basic Lemma). Given a term r <strong>typed</strong> by Γ ⊢ r : ρ with free variables−→ x :−→ σ ∈ Γ, we have:∀ −→ s R −→ σ−→ b ⇒ r−→ x [ −→ s ] R r −→x ↦→−→ bIn particular <strong>for</strong> −→ b = −→ ↑ x, we get the desired result: r =↓ r ↑ .In more detail, the logical relation R can be def<strong>in</strong>ed byDef<strong>in</strong>ition 2.18 (Logical Relation R). We def<strong>in</strong>e a logical relation R = ⋃ R ρwith R ρ ⊆ Tm ρ × ρ def<strong>in</strong>ed by <strong>in</strong>duction on the type ρ by:r R o ar R ρ→σ a::= r = βη a::= ∀ s R ρ b, rs R σ abLemma 3. The follow<strong>in</strong>g implications hold:r R τ a ⇒ r = βη ↓ a (1)r = βη s ⇒ r R τ ↑ s (2)Proof. By <strong>in</strong>duction on the type τ• Case ι, obvious• Case ρ → σ (1),We want to show r = βη ↓ ρ→σ aBy def<strong>in</strong>ition:↓ ρ→σ a = λx ρ . ↓ a ↑ x(x new)By <strong>in</strong>duction hypothesis of (2) on ρ, x R ρ ↑ x, so by def<strong>in</strong>ition of r R ρ→σ a,we have rx R σ a ↑ x and by <strong>in</strong>duction hypothesis of (1) on σ, rx = βη ↓ a ↑ x.F<strong>in</strong>ally r = βη λx ρ .rx = λx. ↓ a ↑ x =↓ a.


2.2 Normalization by Evaluation 23• case ρ → σ (2),Given t R ρ a we want to show rt R σ (↑ ρ→σ s)(a)By def<strong>in</strong>ition:(↑ ρ→σ s)(a) =↑ σ (s ↓ ρ a)Now by <strong>in</strong>duction hypothesis of (1) on ρ, t = βη ↓ ρ a, so rt = βη s ↓ a, and by<strong>in</strong>duction hypothesis of (2) on σ, rt R σ ↑ σ s ↓ a.Justification of r = βη s ⇒ nf(r) ≡ nf(s)To justify r = βη s ⇒ nf(r) ≡ nf(s) with ≡⊆ βη, the traditional argument uses thesoundness of the <strong>in</strong>terpretation with respect to the equality = βη , i.e., that <strong>for</strong> a givenvaluation function η (on a context typ<strong>in</strong>g r and s):r = βη s ⇒ r η = s ηAs ↓ is a function from the <strong>in</strong>terpretation to the term language, it follows that ↓(r η ) ≡↓ (s η ) where ≡ is the syntactical equality, which is decidable and conta<strong>in</strong>ed<strong>in</strong> the conversion relation = βη . By tak<strong>in</strong>g the valuation η to be ↑, we obta<strong>in</strong> theresult:r = βη s ⇒↓ (r ↑ ) ≡↓ (s ↑ )However, if the <strong>in</strong>terpretation is not a model of our term language <strong>in</strong> the sensethat two βη-equal terms are not <strong>in</strong>terpreted by the same element, this argumentdoes not apply directly and needs to be adapted.It will be <strong>in</strong> particular the case of our <strong>in</strong>terpretation when deal<strong>in</strong>g with the newvariable problem.Remark 4. The normalization by evaluation algorithm is often referred to be reductionfree because, as <strong>in</strong> the argument above one can avoid any reference to rewrit<strong>in</strong>gtheory.However, <strong>for</strong> the function nf to be term<strong>in</strong>at<strong>in</strong>g one need the evaluation of the<strong>in</strong>terpretation itself to term<strong>in</strong>ate.More generally one can see normalization by evaluation as a way to focus onthe study of the rewrit<strong>in</strong>g theory of the <strong>in</strong>terpretation of a language <strong>in</strong>stead of therewrit<strong>in</strong>g theory of the language itself. The work of Klaus Aehlig and Felix Joachimski(see [2]) use a two level <strong>lambda</strong> <strong>calculus</strong>, where the <strong>in</strong>terpretation itself is asyntactic <strong>lambda</strong> <strong>calculus</strong>, and this allows them to carry out a f<strong>in</strong>e-gra<strong>in</strong>ed rewrit<strong>in</strong>ganalysis of the rewrit<strong>in</strong>g <strong>in</strong>volved <strong>in</strong> the NbE algorithm.


24 2. Simply Typed λ-Calculus2.2.2 Normal FormsAs we are only <strong>in</strong>terested <strong>in</strong> the correctness of our algorithm this <strong>in</strong>troduction couldend here but there is another <strong>in</strong>terest<strong>in</strong>g question, namely:How does the terms produced by the NbE algorithm look like?Let us call NF (<strong>for</strong> set of normal <strong>for</strong>m) the subset of terms which are results ofthe function nf. Hence nf is a function from Tm to NF. Because nf(r) is def<strong>in</strong>ed as↓ (r ↑ ), the function ↓ applied to a value r ↑ should only produce terms <strong>in</strong> NF.Then by analys<strong>in</strong>g the algorithm we can as well restrict the doma<strong>in</strong> of ↑. Wenote that <strong>in</strong> the first step of the evaluation of nf, we apply ↑ only to variables, thenif the variable is of arrow type, we apply ↑ to an application of a variable to a termresult<strong>in</strong>g from ↓, i.e., a normal <strong>for</strong>m N ∈ NF. It is easy to see that <strong>in</strong> fact thedoma<strong>in</strong> of ↑ is a set of neutral term Ne given byNe ∋ n ::= x | n Nwhere N ∈ NF is a normal <strong>for</strong>m.Let us write NF ρ (resp. Ne ρ ) the set of normal terms (resp. neutral terms)typable with type ρ. The function ↓ at base type is the identity, and at arrow type<strong>in</strong>volves the term abstraction over a recursively obta<strong>in</strong>ed result of ↓, i.e., a term <strong>in</strong>NF, and it is easy to see that NF τ , the set of normal <strong>for</strong>ms of type τ, verifies:{r ∈ NF τ r ∈o ,if τ = o⇔r = λx.s ∧ s ∈ NF σ , if τ = ρ → σNow we want to restrict the <strong>in</strong>terpretation. As the function ↑ is the identity atbase type, the <strong>in</strong>terpretation at base type o should at least conta<strong>in</strong> the doma<strong>in</strong> of↑, i.e., neutral terms of base type Ne o . It is <strong>in</strong> fact sufficient to take:o = Ne oTo summarise we have <strong>in</strong><strong>for</strong>mally shown that the set NF of normal <strong>for</strong>ms givenby the NbE algorithm is <strong>in</strong>ductively def<strong>in</strong>ed by:Def<strong>in</strong>ition 2.19 (Λ-normal <strong>for</strong>m).(x : ρ) ∈ ΓΓ ⊢ Ne x : ρΓ ⊢ Ne n : ρ → σΓ ⊢ Ne nN : σΓ ⊢ NF N : ρΓ ⊢ Ne n : oΓ ⊢ NF n : oΓ, x : ρ ⊢ NF N : σΓ ⊢ NF λx.N : σA more precise specification <strong>for</strong> the function ↑, ↓ and nf can now be given withthe follow<strong>in</strong>g doma<strong>in</strong> and codoma<strong>in</strong>:↑ ρ : Ne ρ → o↓ ρ : o → NF ρnf : Tm → NF


2.2 Normalization by Evaluation 25The normal <strong>for</strong>ms <strong>in</strong> NF are known under the name of long normal <strong>for</strong>ms. Thesenormal <strong>for</strong>ms are obta<strong>in</strong>ed as the irreducible terms if one orients the <strong>conversions</strong> asreductions as follows,(λx.r)s −→ β r{ x /s}r −→ η λx.rx(x ∉ FV(r))with the further requirement that <strong>in</strong> the η-reduction the term r is not an abstractionand is not <strong>in</strong> applicative position.This def<strong>in</strong>ition of long normal <strong>for</strong>ms first appeared <strong>in</strong> the works of Gerard Huet[54].This agreement of normal <strong>for</strong>ms obta<strong>in</strong>ed by reductions and by the NbE algorithmis <strong>in</strong>deed no accidental coïncidence. In [17], Ulrich Berger extracts a normalizationalgorithm from a reduction based normalization proof; the extractedalgorithm is the NbE algorithm presented above. This extraction has been recently<strong>for</strong>malized <strong>in</strong> different proof assistant (Coq, Isabelle, m<strong>in</strong>log), the <strong>in</strong>terested readercan consult [18]. In [30] and [31], Thierry Coquand and Peter Dybjer show thatthe proof of correctness of their NbE normalization function is <strong>in</strong> fact an optimizedversion of a <strong>standard</strong> proof of normalization of <strong>in</strong>tuitionistic type theory.2.2.3 Name Generation EnvironmentLet us return to the problem of the ”new” variable.It appears <strong>in</strong> the evaluation of nf(r) =↓ r ↑ , <strong>in</strong> each recursive call of ↓ at arrowtype:↓ ρ→σ f = λx. ↓ σ f(↑ ρ x)x newThe term ↓ σ f(↑ ρ x) can conta<strong>in</strong> free variables which are either free variables of ror which have been created by other recursive calls of ↓. The side condition ”x new”means that x should be different from these variables.These two situations are exposed <strong>in</strong> the example below:Example 2. A newly created variable should be different from one occurr<strong>in</strong>g free <strong>in</strong>r. Let r be the term y with the typ<strong>in</strong>g y : o → o ⊢ y : o → onf(r) =↓ y ↑=↓ (↑ o→o y)= λx. ↓ o (↑ o→o y)(↑ o x) x new= λx. ↓ o (↑ o→o y)(x) x new= λx.(↑ o→o y)(x)= λx. ↑ o y ↓ o x= λx. ↑ o yx= λx.yx


26 2. Simply Typed λ-CalculusA newly created variable should be different from already created variables. Let r bethe term λy.y with the typ<strong>in</strong>g ⊢ λy.y : (o → o) → o → onf(r) =↓ λy.y ↑= λx. ↓ o→o (λy.y ↑ (↑ o→o x)) x new= λx. ↓ o→o (↑ o→o x)= λx.λy. ↓ o ((↑ o→o x) ↑ o y) y new= λx.λy.(↑ o→o x)y= λx.λy. ↑ o x(↓ o y)= λx.λy.xySaid <strong>in</strong><strong>for</strong>mally, <strong>in</strong> the expressionλx. ↓ σ f(↑ ρ x)x newthe function f already ”conta<strong>in</strong>s” the necessary <strong>in</strong><strong>for</strong>mation (i.e., the variables alreadyused) to compute the new variable x. However f is a function, and to extractthis <strong>in</strong><strong>for</strong>mation, one has to apply f to an argument, but we are precisely look<strong>in</strong>g<strong>for</strong> an appropriate argument of f.To solve this dilemma, a possible solution is to record along the evaluation of↓ r ↑ which variables have been used (those free <strong>in</strong> r and those already created bya call of ↓ at arrow type).In fact, all we need to create new variables, is to have at hand a set of variables,which does not conta<strong>in</strong> the already used variables. Hence, we do not even need torecord all the used variables, but merely a set of unused ones. This weaker solutioncan read <strong>in</strong><strong>for</strong>mally as follows:• We beg<strong>in</strong> the evaluation of ↓ r ↑ with a denumerable set e = e r of variablesnot conta<strong>in</strong><strong>in</strong>g those free <strong>in</strong> r,• when evaluat<strong>in</strong>g ↓ at arrow type, we first pick a new variable x from e, andcont<strong>in</strong>ue the computation with the set e \ {x}.We can see <strong>in</strong> this <strong>in</strong><strong>for</strong>mal exposition that the set e acts exactly like an environment.The computation <strong>for</strong> the function ↓ at arrow type needs to read a value, afresh variable x, from e and run some subcomputations <strong>in</strong> an updated environmente x (without this fresh variable).After this <strong>in</strong><strong>for</strong>mal description it is now time to give a <strong>for</strong>mal specification:


2.2 Normalization by Evaluation 27Def<strong>in</strong>ition 2.20 (Name Generation Environment). We def<strong>in</strong>e a set of name generationenvironment or set of environment <strong>for</strong> short, as a set E together with anupdate function (−) − : E → Var → E and an access function new : E → Var.The extension of the update function e − : V → E to a function from a list ofvariables e : L(V ) → E is def<strong>in</strong>ed <strong>in</strong> a ca<strong>non</strong>ical way bye x,−→x ::= (e x ) −→ xe ε ::= e.The function (−) − and new have moreover to satisfy the follow<strong>in</strong>g property <strong>for</strong>all e ∈ E:∀ −→ x , x ≠ new(e x,−→x ) (†)An environment e ∈ E is meant to be a denumerable set of variables, the updatefunction − x applied to an environment e is meant to remove a variable x from e,and new(e) to pick a variable from e.An explanation <strong>for</strong> the condition (†) is given after hav<strong>in</strong>g <strong>in</strong>troduced the follow<strong>in</strong>gnotation.Notation 9. The condition that the new function applied to an environment e ∈ Eshould never return a given variable x can be expressed by:∀ −→ x , x ≠ new(e −→x )We will abbreviate this condition by x ∉ e. In the same way we will abbreviate <strong>for</strong>a given set of variable X, ∀ x ∈ X, x ∉ e by X ∉ e.With this notation, the condition (†) reads:x ∉ e xThis means that once a variable x has been removed from an environment e withthe function (−) − , x can not be picked out anymore.Return<strong>in</strong>g to the NbE algorithm, the <strong>in</strong>itialisation step <strong>for</strong> a term r consists <strong>in</strong>f<strong>in</strong>d<strong>in</strong>g an environment e r such that the new function will never give back a variableamong those free <strong>in</strong> r.∀ x ∈ FV(r), x ∉ e rIn fact <strong>for</strong> an arbitrary given e, e FV(r) does the job.Example 3. This name generation environment has been implemented by UlrichBerger <strong>in</strong> [17] with <strong>in</strong>dexed variables, i.e., of the <strong>for</strong>m x k where k ∈ N, and isessentially as follows.


28 2. Simply Typed λ-CalculusThe set of environment E is taken to be N, and a natural number k is a code<strong>for</strong> the sequence x k , x k+1 , . . .. The <strong>in</strong>itialisation part consists to look <strong>for</strong> the higher<strong>in</strong>dex k of the variables of the <strong>for</strong>m x k occurr<strong>in</strong>g <strong>in</strong> r. Because <strong>for</strong> all k ′ k + 1,x k ′ is not free <strong>in</strong> r, k r = k + 1 is a code <strong>for</strong> a sequence of fresh variables <strong>for</strong> r andwe only need to propagate a natural number <strong>in</strong>stead of a set of variables.The implementation isk x j::= max(k, j + 1)new(k) ::= x kk r ::= 0 (FV(r))In particular, the use of <strong>in</strong>dexed variables by Berger corresponds to de Bruijn levelswhere an <strong>in</strong>dex of a variable corresponds to the number of <strong>lambda</strong> abstraction <strong>in</strong> thesyntax tree of the term, from the occurrence of this variable to the root of the tree.Remark 5. In an impure functional programm<strong>in</strong>g language, the concept of environment,sequence of <strong>in</strong>structions and assignment are primitive. The implementationis then easy, it suffices to def<strong>in</strong>e such an e <strong>in</strong> the global environment and update itwith an assignment <strong>in</strong>struction e := e x , which will update the environment be<strong>for</strong>efurther computations.However this would take us a step further away from a mathematical <strong>for</strong>malisation.It is why we prefer to stick to a pure functional programm<strong>in</strong>g language sett<strong>in</strong>g,where the primitive notion of function has a direct counterpart <strong>in</strong> a mathematicalsett<strong>in</strong>g. We will then implement impure functional concept such as environments (<strong>in</strong>the <strong>for</strong>malization section of chapter 2, 3 and 4) or exceptions (<strong>in</strong> the <strong>for</strong>malizationsection of chapter 3 and 4) with<strong>in</strong> our functional sett<strong>in</strong>gs with the help of monads.Rest now to redesign the NbE algorithm to propagate <strong>in</strong> an adequate way thisenvironment e through the computation.2.3 Formalization2.3.1 Name Generation InterpretationWe will be guided by the fact that this notion of computation <strong>in</strong> environment isnaturally captured by a state reader monad.The basic idea is that if a computation which produces a value <strong>in</strong> some set Aneeds to access an environment then we will have to pass this environment as asupplementary argument to the function correspond<strong>in</strong>g to this computation, henceone can replace these set A <strong>in</strong> the specification of the function by a function spaceSt E (A) = E → A from the set of environments E to A. The set A has been replacedby the state reader monad St E over A.


2.3 Formalization 29In particular, <strong>in</strong> the computation of the function ↓ τ , an environment e should beavailable <strong>in</strong> order to be able to pick a fresh variable x from it. The specification of↓ τ hence becomesτ → St E (NF τ ) = τ → E → NF τ .Notice also that the specification of the operation new : E → Var now reads:new : St E (Var)The update operation (−) − : E → Var → E <strong>for</strong> a name generation environmentE extends to an update function on elements of the monad St E (A).Def<strong>in</strong>ition 2.21 (update <strong>for</strong> the Name Generation Monad). We def<strong>in</strong>e an updatefunction (−) − : St E (A) → Var → St E (A) operation by extend<strong>in</strong>g the updateoperation <strong>for</strong> the name generation monad by:m v (e) ::= m(e v )A First TryTo def<strong>in</strong>e correctly the function ↓ ρ→σ we have to first take a fresh variable from theenvironment and then pass an updated environment to the subcomputation <strong>in</strong> thebody of the function.Maybe the first solution com<strong>in</strong>g to m<strong>in</strong>d is to def<strong>in</strong>e the function ↓ ρ→σ as follows:↓ ρ→σ f = e.(v.λv(↓ f ↑ v)e v )(new(e))or <strong>in</strong> monadic notation↓ ρ→σ f = new ⋆ v.(↓ f ↑ v) v ⋆ r.ν(λv.r)There is still a problem with this def<strong>in</strong>ition: the function ↑ τ has here the samespecification as be<strong>for</strong>e, i.e., Tm → τ, and at arrow type a computation of ↑ ρ→σconta<strong>in</strong>s a subcomputation of ↓ ρ , which require an argument e ∈ E, but we donot have this argument at this po<strong>in</strong>t. What would be the second argument of thefunction ↓ ρ <strong>in</strong> this case?↑ ρ→σ r(a) =↑ σ r(↓ ρ (a)??)An arbitrary environment e ∈ E does not fit because we do still need to know whichare the variables used <strong>in</strong> a. One could then th<strong>in</strong>k of simply add<strong>in</strong>g an environmentas argument to the function ↑. Alas, this simple solution alone does not work; thisnotion of environment <strong>for</strong> names has to be <strong>in</strong>corporated <strong>in</strong>to the <strong>in</strong>terpretation.


30 2. Simply Typed λ-CalculusModify<strong>in</strong>g the InterpretationBy analogy with programm<strong>in</strong>g we can th<strong>in</strong>k of the application of a monad to a set asthe <strong>in</strong>terpretation of a type together with computational content. We will developtwo different ways to <strong>in</strong>tegrate such a computational type <strong>in</strong>to the <strong>in</strong>terpretation ofthe simply <strong>typed</strong> λ-<strong>calculus</strong>, differ<strong>in</strong>g <strong>in</strong> the <strong>in</strong>tended strategy of evaluation of the<strong>in</strong>terpreted terms.Follow<strong>in</strong>g the work of Nick Benton, John Hughes and Eugenio Moggi <strong>in</strong> [16], wewill call our first modified <strong>in</strong>terpretation the Algol <strong>in</strong>terpretation and the second thecall-by-value <strong>in</strong>terpretation.The idea to use a monadic <strong>in</strong>terpretation <strong>in</strong> conjunction with NbE is due tothe works of Andrzej Fil<strong>in</strong>ski and Peter Dybjer, [40] and [43]. There, they showthat, <strong>in</strong> calculi possibly extended with constants, NbE actually provides normalizationfunctions <strong>for</strong> different evaluation strategies, the normalization is proved correctand complete with respect to an equivalence def<strong>in</strong>ed via the <strong>in</strong>terpretation (whatis called Algol <strong>in</strong>terpretation here is called call-by-name <strong>in</strong>terpretation there). Herewe are concerned with βη-<strong>conversions</strong>, and these evaluation strategies does not <strong>in</strong>general correspond exactly with βη-<strong>conversions</strong>. As we will see, <strong>in</strong> the case of theAlgol <strong>in</strong>terpretation the NbE algorithm provides already a normalization functionwith respect to βη-<strong>conversions</strong>. But it is even true <strong>in</strong> the case of the call-by-value<strong>in</strong>terpretation, it is a somewhat surpris<strong>in</strong>g result because, <strong>in</strong> this case, the <strong>in</strong>terpretationis unsound <strong>for</strong> βη-<strong>conversions</strong> (two βη-convertible terms may have a different<strong>in</strong>terpretation) and the last sections of this chapter are devoted to prove this.In the follow<strong>in</strong>g def<strong>in</strong>itions of <strong>in</strong>terpretations, a valuation on a context Γ is def<strong>in</strong>edas be<strong>for</strong>e as a partial function from the set of variables to the <strong>in</strong>terpretation of types,such that a <strong>typed</strong> variable x : ρ <strong>in</strong> Γ is mapped to an element of the <strong>in</strong>terpretationρ of the type ρ. As remarked <strong>in</strong> section (2.2.2), one only needs neutral terms ofground type <strong>in</strong> the <strong>in</strong>terpretations of ground type.One can allow computational effects only at base type as <strong>in</strong> the programm<strong>in</strong>glanguage idealised Algol (see [80] or [81]). For us it will mean that the monad onlyappear <strong>in</strong> the <strong>in</strong>terpretation of ground type:


2.3 Formalization 31Def<strong>in</strong>ition 2.22 (Algol <strong>in</strong>terpretation).the type byThe Algol <strong>in</strong>terpretation alg is given ono alg ::= St E (Ne o )ρ → σ alg ::= ρ alg → σ algGiven a valuation η on Γ, a <strong>typed</strong> term Γ ⊢ r : ρ is <strong>in</strong>terpreted as an element ofρ alg byx algηrs algηλx.r algη::= η(x)::= r algη s algη::= a.r algη,x↦→aOne can th<strong>in</strong>k of the <strong>in</strong>terpretation of a λ-term as a program <strong>in</strong> a call-by-valuesett<strong>in</strong>g. In this case, a program takes a value as argument and produces a computation(the monad appears <strong>in</strong> the codoma<strong>in</strong> of the <strong>in</strong>terpretation of function spaces).Hence the <strong>in</strong>terpretation is:Def<strong>in</strong>ition 2.23 (call-by-value <strong>in</strong>terpretation). val is def<strong>in</strong>ed on the types byThe call-by-value <strong>in</strong>terpretationo val ::= Ne oρ → σ val ::= ρ val → St E (σ val )Given a valuation η on Γ, a <strong>typed</strong> term Γ ⊢ r : ρ is <strong>in</strong>terpreted as an element ofSt E (ρ val ) byx valηλx.r valηrs valη::= ν(η(x))::= ν(a.r valη,x↦→a)::= r valη⋆ f.s valη⋆ a.faWe present the call-by-name <strong>in</strong>terpretation although we will not further analyseit. In a call by name sett<strong>in</strong>g a program is expected to take as argument a computationand to produce another computation (the monad appears both <strong>in</strong> the doma<strong>in</strong>and codoma<strong>in</strong> of the <strong>in</strong>terpretation of function spaces), hence this last <strong>in</strong>terpretationis:


32 2. Simply Typed λ-CalculusDef<strong>in</strong>ition 2.24 (call-by-name <strong>in</strong>terpretation). name is def<strong>in</strong>ed on type byThe call-by-name <strong>in</strong>terpretationo name ::= Ne oρ → σ name ::= St E (ρ name ) → St E (σ name )Given a valuation η on Γ, a <strong>typed</strong> term Γ ⊢ r : ρ is <strong>in</strong>terpreted as an element ofSt E (ρ name ) byλx.r nameηx nameηrs nameη::= η(x)(m) ::= m ⋆ a.r name::= r nameηη,x↦→a⋆ f.fs nameηSeveral SolutionsIn the work us<strong>in</strong>g NbE, <strong>for</strong> the most part, the usual solution is to chose what we havecalled the Algol <strong>in</strong>terpretation. The immediate advantage is that this <strong>in</strong>terpretationprovides a Henk<strong>in</strong> Model. By well known results (see <strong>for</strong> example [73]), we knowthat this <strong>in</strong>terpretation is sound <strong>for</strong> the βη-conversion, which means that <strong>for</strong> anarbitrary valuation η on Γ, terms r and s βη-convertible, their <strong>in</strong>terpretations areequal r algη = s algη . Hence the argument exposed <strong>in</strong> the <strong>in</strong><strong>for</strong>mal presentation toprove r = βη s ⇒ nf(r) ≡ nf(s) is directly applicable.Choos<strong>in</strong>g this <strong>in</strong>terpretation, the NbE algorithm reads <strong>in</strong> a monadic style asfollows:Code 1 (Algol NbE). The function ↓ τ : τ → St E (NF τ ) and ↑ τ : St E (Ne τ ) → τare def<strong>in</strong>ed simultaneously.↓ o r = r↓ ρ→σ f = new ⋆ v.(↓ f ↑ ν(v)) v ⋆ t.ν(λv.t)↑ o F = F↑ ρ→σ F (a) = ↑ σ (F ⋆ r. ↓ ρ a ⋆ s.ν(rs))Code 2. Given an environment e r such that FV(r) ∉ e r the normalization functionnf : Tm → NF is def<strong>in</strong>ed bynf(r) =↓ r ↑◦ν e rHowever when deal<strong>in</strong>g with sum type, we will need to def<strong>in</strong>e the function ↑ at sumtype. But to def<strong>in</strong>e the result of ↑ ρ 0+ρ 1m <strong>for</strong> m of type M(Tm ρ0 +ρ 1), we need first toknow if the term ”conta<strong>in</strong>ed” <strong>in</strong> m corresponds to a left <strong>in</strong>jection, a right <strong>in</strong>jection,or if we don’t know yet. In this sett<strong>in</strong>g, the only possibility to extract a term froman element m ∈ M(Tm ρ0 +ρ 1) is to apply the function ↑ and this should be done at


2.3 Formalization 33a structurally smaller type, i.e., either at ρ 0 or ρ 1 . But to know whether it is ρ 0or ρ 1 , we are once aga<strong>in</strong> faced to the problem of analys<strong>in</strong>g the term conta<strong>in</strong>ed <strong>in</strong>m ∈ M(Tm ρ0 +ρ 1). We didn’t f<strong>in</strong>d any natural solution to this problem, which leadsus to the second solution proposal, the call-by-value <strong>in</strong>terpretation.Remark 6. A ref<strong>in</strong>ed analysis that monadic values F ∈ MTm occurr<strong>in</strong>g <strong>in</strong> the AlgolNbE algorithm are term families which when applied to environments only differ bytheir bound variables.Hence we can extract the fresh variables from such a monadic value F ∈ Tmby apply<strong>in</strong>g it to an arbitrary environment FV(F e). Now that we know the freshvariables, we can extract a term from F , by apply<strong>in</strong>g it to an environment e ′ updatedwith these fresh variables: F e ′FV(F e) .Disregard<strong>in</strong>g that this solution does not seem very natural, we will have to threadexceptions <strong>for</strong> the treatment of sum types <strong>in</strong>to the NbE algorithm and this is notevident with the Algol <strong>in</strong>terpretation.As already mentioned, the call-by-value <strong>in</strong>terpretation already appeared <strong>in</strong> thepaper [43] of Andrzej Fil<strong>in</strong>ski and [40] with Peter Dybjer. In these papers, they basedthe name generation <strong>in</strong>terpretation on a state monad. They are then able to def<strong>in</strong>ean extension of NbE <strong>for</strong> sum type <strong>in</strong> the sett<strong>in</strong>g of the call-by-value <strong>in</strong>terpretation.In this sense the works of Andrzej Fil<strong>in</strong>ski and Peter Dybjer can be seen as the closestto ours. The first difference is that they used a state pass<strong>in</strong>g monad ST E A = E →E × A whereas we use simply a state reader monad St E A = E → A. At first, thisseems to be a m<strong>in</strong>or difference, but it will simplify the proof of correctness as wewill not have to deal with adm<strong>in</strong>istrative product types <strong>in</strong> the <strong>in</strong>terpretation. Thesecond and more important difference is that they proved correctness of NbE <strong>for</strong>terms which have the same call-by-value <strong>in</strong>terpretation. We will prove correctness<strong>for</strong> terms which are βη equal.The ma<strong>in</strong> advantage of this <strong>in</strong>terpretation is to simplify the type of the argumentof the reflect function ↑. In the Algol <strong>in</strong>terpretation an argument of ↑ τ has typeM(Ne τ ), and <strong>in</strong> the call-by-value <strong>in</strong>terpretation it has the type Ne τ . This directaccess to the term argument of the reflect function ↑ will allow us to extend quitenaturally the NbE algorithm to sum type <strong>in</strong> chapter 4.The algorithm <strong>for</strong> the call-by-value <strong>in</strong>terpretation reads:Code 3 (call-by-value NbE). The function ↓ τ : τ val → St E (Ne τ ) and ↑ τ : Ne τ →τ val are def<strong>in</strong>ed simultaneously by:↓ o r = ν(r)↓ ρ→σ f = new ⋆ v.(f ↑ v⋆ ↓) v ⋆ t.ν(λv.t)↑ o r = r↑ ρ→σ r(a) = (↓ ρ a) ⋆ s.ν(↑ σ rs)


34 2. Simply Typed λ-CalculusCode 4. Given an environment e r such that FV(r) ∉ e r the normalization functionnf is def<strong>in</strong>ed bynf(r) = (r val↑ ⋆ ↓)e rA problem of the call-by-value <strong>in</strong>terpretation is that it does not generally providea sound <strong>in</strong>terpretation, i.e., we can have r = βη s but r valη ≠ s valη <strong>for</strong> a givenvaluation η. It is <strong>in</strong> particular the case of our set theoretical <strong>in</strong>terpretation with thestate reader monad as shown <strong>in</strong> the follow<strong>in</strong>g example:Example 4 (unsoundness of call-by-value <strong>in</strong>terpretation). Let η be a valuation withη(z) = f ∈ o → o val , η(z ′ ) = a ∈ o val ,z : o → o, z ′ : o ⊢ (λxy.x)(zz ′ ) = β λy.zz ′ : o → othe <strong>in</strong>terpretation of these terms are(λxy.x)(zz ′ ) valηλy.zz ′ valη= λxy.x valη ⋆ g.zz ′ valη ⋆ a.ga by def<strong>in</strong>ition 2.23= ν(b.λy.x valη,x↦→b) ⋆ g.zz ′ valη ⋆ a.ga by def<strong>in</strong>ition 2.23= (g.zz ′ valη= zz ′ valη= zz ′ valη⋆ a.ga)(b.λy.x valη,x↦→b) by def<strong>in</strong>ition 1.1⋆ a.(b.λy.x valη,x↦→b)a)⋆ a.λy.x valη,x↦→a= (z valval ⋆ (g.z ′ valη ⋆ b.gb)) ⋆ a.λy.x valη,x↦→a by def<strong>in</strong>ition 2.23= (z valval ⋆ (g.z ′ valη ⋆ b.gb)) ⋆ a.c.x valη,x↦→a,y↦→c by def<strong>in</strong>ition 2.23= (ν(f) ⋆ (g.ν(a) ⋆ b.gb)) ⋆ a.ν(c.ν(a)) by def<strong>in</strong>ition 2.23= (g.ν(a) ⋆ b.gb)f) ⋆ a.ν(c.ν(a)) by def<strong>in</strong>ition 1.1= (g.(b.gb)a)f) ⋆ a.ν(c.ν(a)) by def<strong>in</strong>ition 1.1= fa ⋆ a.ν(c.ν(a))= ν(c.zz ′ valη )ece ′= ν(c.fa) see computations aboveAnd <strong>for</strong> two environments e, e ′ ∈ E, such that e ≠ e ′ and an element c ∈ o val , wehave(λxy.x)(zz ′ ) valη ece ′ = (fa ⋆ a.ν(c.ν(a)))ece ′= (c.ν(fae))ce ′ by def<strong>in</strong>ition 1.2= fae by def<strong>in</strong>ition 1.2λy.zz ′ valη ece ′ = ν(c.fa)ece ′= (c.fa)ce ′ by def<strong>in</strong>ition 1.2= fae ′


2.3 Formalization 35As soon as E as more than one element, it is obviously possible to f<strong>in</strong>d a functionf <strong>in</strong> o → o val = Tm → (E → Tm) such thatfae ≠ fae ′For the completeness property, which relied on the soundness of the <strong>in</strong>terpretation<strong>in</strong> the <strong>in</strong><strong>for</strong>mal presentation, we have seen <strong>in</strong> the example above that the settheoretical equality is unsuitable. We will have to provide a coarser equality relation<strong>in</strong> section 2.3.4 which we will prove to be sound with respect to βη.In contrast the soundness property does not need much adaptation. We will haveto take <strong>in</strong>to account the name generation monad and adapt the correctness lemmato this sett<strong>in</strong>g <strong>in</strong> section 2.3.3.In these two proofs we will make use of the concept of logical relation, a class ofrelations which relate the mean<strong>in</strong>gs of terms <strong>in</strong> a structured way. We have alreadymentioned this concept <strong>in</strong> the <strong>in</strong>troduction, the next section is devoted to it and itsextension to our monadic sett<strong>in</strong>gs.2.3.2 Monadic logical relationThe work of Andrzej Fil<strong>in</strong>ski was aga<strong>in</strong> a great source of <strong>in</strong>spiration. In [42], Kripkerelations are used to show the completeness and correctness of a normalization byevaluation algorithm <strong>in</strong> a call-by-name sett<strong>in</strong>g. In [41], Fil<strong>in</strong>ski def<strong>in</strong>es a monadiclogical relation <strong>in</strong> a call-by-value sett<strong>in</strong>g, notably extended <strong>for</strong> sum types, to implementrigorously and efficiently effects layered <strong>in</strong> a functional programm<strong>in</strong>g language.This monadic logical relation is similar to our def<strong>in</strong>ition 2.29 (ours withoutsum types). One difference is that we use general <strong>typed</strong> applicative structures aswe want to handle syntactical applications and not only set-theoretical applications.Another difference is that <strong>in</strong> these syntactical application structures we need to consideropen terms, and there<strong>for</strong>e use Kripke applicative structures. An example ofa <strong>for</strong>malized proof of correctness of an NbE algorithm us<strong>in</strong>g a Kripke applicativestructure can be found <strong>in</strong> the work of Catar<strong>in</strong>a Coquand [28; 29]. The book ofMitchell [73] is a nice <strong>in</strong>troduction of the concept of Kripke relations that we havereworked <strong>in</strong> the context of monadic <strong>in</strong>terpretation.As already mentioned, a logical relation relates the ”mean<strong>in</strong>gs” of terms <strong>in</strong> astructured way. Here mean<strong>in</strong>g has to be understood <strong>in</strong> an extended sense. Logicalrelations do not only allow to relate two different values of an <strong>in</strong>terpretation, but aswell to relate a term and a value <strong>in</strong> the <strong>in</strong>terpretation (so that a term can be seenas the ”mean<strong>in</strong>g” of itself).Accord<strong>in</strong>gly, <strong>in</strong> a first step, we have to capture the similarity shared by the termand semantical structures. This is the rôle of (<strong>typed</strong>) applicative structures.


36 2. Simply Typed λ-CalculusDef<strong>in</strong>ition 2.25 (Typed applicative structure). A <strong>typed</strong> applicative structure A isa pair 〈{A ρ }, {App ρ,σ }〉, where {A ρ } is a family of sets A ρ <strong>in</strong>dexed by types ρ ∈ Tyand {App ρ,σ } is a family of application functions App ρ,σ : A ρ→σ → A ρ → A σ<strong>in</strong>dexed by pair of types ρ, σ ∈ Ty. We will write A <strong>for</strong> ⋃ ρ∈Ty AρThe two follow<strong>in</strong>g examples show how the term and semantical structures canbe both captured by <strong>typed</strong> applicative structures.Example 5 (Set of terms typable <strong>in</strong> a given context). Given a context Γ, the pair〈{A ρ }, {App ρ,σ }〉 where A σ = {r | Γ ⊢ r : σ}, and App ρ,σ rs = rs is a <strong>typed</strong> applicativestructure.Example 6 (Type <strong>in</strong>terpretation). The pair 〈{A ρ }, {App ρ,σ }〉 where {A ρ } = ρis the type <strong>in</strong>terpretation as given <strong>in</strong> def<strong>in</strong>ition (2.22) and App ρ,σ fa = f(a) is theset-theoretic function application, is an applicative structure.An applicative structure can be seen as a special case of <strong>typed</strong> applicative structureswhere the <strong>in</strong>dexed family of sets {A ρ } has been shrunk down to one uniqueset.Example 7 (Un<strong>typed</strong> λ-<strong>calculus</strong>). The pair 〈{A ρ }, {App ρ,σ }〉 where A σ = Tm, andApp ρ,σ rs = rs is a <strong>typed</strong> applicative structure.One can def<strong>in</strong>e a generalisation of applicative structure to monads by requir<strong>in</strong>gthat the application operator has a monadic result.Def<strong>in</strong>ition 2.26 (Monadic applicative structure). A monadic applicative structureover a monad M is a tuple 〈{A ρ }, {MApp ρ,σ }〉 where {A ρ } is a family of setsA ρ <strong>in</strong>dexed by types ρ ∈ Ty and {MApp ρ,σ } is a family of application functionsMApp ρ,σ : A ρ→σ → A ρ → MA σ <strong>in</strong>dexed by pair of types ρ, σ ∈ Ty.Remark 7. Monadic applicative structures are a generalisation of <strong>typed</strong> applicativestructures, as a <strong>typed</strong> applicative structure is just a monadic applicative relation overthe identity monad.Notation 10. We will write a·ρ,σ b (or a·b when the types are clear from the context)<strong>for</strong> MApp ρ,σ a b.Example 8 (call-by-value type <strong>in</strong>terpretation). The pair 〈{A ρ }, {·ρ,σ }〉 where {A ρ } =ρ val is the call-by-value <strong>in</strong>terpretation of types as given <strong>in</strong> def<strong>in</strong>ition (2.23) and·ρ,σ fa = f(a) is the set-theoretic function application, is a monadic applicative structure.Just like <strong>for</strong> <strong>in</strong>terpretation we need to def<strong>in</strong>e the auxiliary notion of valuation todef<strong>in</strong>e the mean<strong>in</strong>g of terms <strong>in</strong> an applicative structures.


2.3 Formalization 37Def<strong>in</strong>ition 2.27 (Valuation). A valuation η <strong>in</strong> an applicative structure〈{A ρ }, {·ρ,σ }〉 is a partial function from Var to A = ⋃ ρ∈Ty Aρ .Given a context Γ, a valuation η on Γ, written η Γ, is a valuation such that<strong>for</strong> x : ρ ∈ Γ, η(x) is def<strong>in</strong>ed and η(x) ∈ A ρ .Given a context Γ, a valuation η on Γ, a variable y ∉ Γ and an element a ∈ A σ ,we def<strong>in</strong>e a valuation (η, y ↦→ a) on Γ ∪ {(y : σ)}, called the extension of η by y ↦→ aby,{ a if x = y, and(η, y ↦→ a)(x) ::=η(x) otherwise.A mean<strong>in</strong>g function is a compatible function from the term structure to themonadic applicative structure <strong>in</strong> the follow<strong>in</strong>g sense.Def<strong>in</strong>ition 2.28 (call-by-value acceptable mean<strong>in</strong>g functions). Given a monadM and an applicative structure A = 〈{A ρ }, {·ρ,σ }〉, a partial function val : Tm ×(Var ⇁ A) ⇁ MA from terms and valuation to A is an acceptable call-by-valuemean<strong>in</strong>g function <strong>in</strong> A ifand∀ Γ, Γ ⊢ r : ρ ∧ η Γ ⇒ r valηx valηrs valη= ν(η(x))= r valη⋆ f.s valη⋆ a.f·a∈ MA ρTerms can be seen as the mean<strong>in</strong>g of themselves because substitution is an acceptablemean<strong>in</strong>g function <strong>in</strong> syntactical applicative structure. Substitution is a welldef<strong>in</strong>ed function only <strong>for</strong> classes of terms modulo α-<strong>conversions</strong>, but this is not aproblem because quotients of syntactic applicative structures by the α-conversionare aga<strong>in</strong> applicative structures.Example 9 (substitution). In the applicative structure of terms modulo α-conversion〈Tm/= α, ·〉, the function : Tm × (Var → Tm ⊥ ) → Tm/= αdef<strong>in</strong>ed by r η =r{ FV(r) /η(FV(r))} is an acceptable mean<strong>in</strong>g function.We def<strong>in</strong>e now a generalisation of logical relation <strong>for</strong> monadic applicative structures,as a pair of family relations; one <strong>for</strong> the normal mean<strong>in</strong>g and one <strong>for</strong> themonadic mean<strong>in</strong>g.


38 2. Simply Typed λ-CalculusDef<strong>in</strong>ition 2.29 (monadic logical relation). Given monadic applicative structuresA = 〈{A ρ }, {·ρ,σ }〉 and B = 〈{B ρ }, {·ρ,σ }〉 over monads M A and M B , a monadiclogical relation is a pair 〈R, S〉, where R and S are family of relations R τ ⊆ A τ ×B τand S τ ⊆ MA τ × MB τ <strong>in</strong>dexed by a type τ such that the follow<strong>in</strong>g property holds:f R ρ→σ g ⇔ ∀ a R ρ b, f·a S σ g·b (2.1)a R b ⇒ ν(a) S ν(b)m S ρ m ′ ∧ f R ρ→σ f ′ ⇒ m ⋆ a.f·a S σ m ′ ⋆ a.f ′·a(unit)(mult)Notation 11. For two valuations η and δ on a context Γ, η Γ and δ Γ, wewill write η R δ if their values are related <strong>for</strong> all variables <strong>in</strong> Γ, i.e., ∀ (x, ρ) ∈Γ, η(x) R ρ δ(x).Admissibility is a technical requirement to be able to relate mean<strong>in</strong>g of abstractionterms.Def<strong>in</strong>ition 2.30 (admissibility). Let A val <strong>in</strong> A and B val <strong>in</strong> B be call-by-valueacceptable mean<strong>in</strong>g functions, a monadic logical relation R is admissible <strong>for</strong> A valand B val if given elements −→ a and −→ b of A and B with −→ a R −→ b , the follow<strong>in</strong>gproperty holds:∀ a R ρ b, Ar val −→ x ,x↦→−→ a ,aS σ Br val−→ x ,x↦→−→ b ,b⇒ Aλx.r val −→ x ↦→−→ aS ρ→σ Bλx.r val−→ x ↦→−→ b(adm)The basic lemma is the fundamental tool provided by the approach with logicalrelations. It allows one to relate mean<strong>in</strong>g of terms as soon as the mean<strong>in</strong>g of theirfree variables are related. The follow<strong>in</strong>g lemma is its extension to our monadicsett<strong>in</strong>gs.Lemma 4 (basic lemma). Given monadic applicative structure A and B over monadsM A and M B , call-by-value acceptable mean<strong>in</strong>g function A val <strong>in</strong> A and B val<strong>in</strong> B, an admissible monadic logical relation 〈R, S〉, and a <strong>typed</strong> term Γ ⊢ r : ρ, withvaluation η and δ on Γ (η Γ and δ Γ), the follow<strong>in</strong>g holds:η R δ ⇒ Ar valηS ρ Br valδProof. By <strong>in</strong>duction on Γ ⊢ r : ρ,case x, by def<strong>in</strong>ition of mean<strong>in</strong>g functions Ax valη = ν A (η(x)) and Bx valδ =ν B (δ(x)), by hypothesis, η(x) R δ(x), and by (unit), ν A (η(x)) S ν B (δ(x)),case λx.r, by <strong>in</strong>duction hypothesis, we have:∀ η, x ↦→ a R δ, x ↦→ b, Ar valη,x↦→a S Br valδ,x↦→b,and by admissibility (adm) of R, we obta<strong>in</strong>:Aλx.r valηS Bλx.r valδ


2.3 Formalization 39case rs, given η R δ, by <strong>in</strong>duction hypothesis on s, we have:As valηS ρ Bs valδ ,by (mult), given f R ρ→σ f ′ , we have:As valηhence by def<strong>in</strong>ition,f.As valη⋆ A a.f·a S σ Bs valδ⋆ B a.f ′·a⋆ A a.f·a R (ρ→σ)→σ f ′ .Bs valδthe x<strong>in</strong>duction hypothesis on r gives:Ar valηS ρ→σ Br valδand by (mult) aga<strong>in</strong>,Ar valη⋆ A f.As valη⋆ A a.f·a S σ Br valδwhich is equivalent by the def<strong>in</strong>ition of rs val to:Ars valηS σ Brs valδ⋆ B a.f ′·a,⋆ B f ′ .Bs valδ⋆ B a.f ′·aIn the next sections, <strong>in</strong> the proofs of the ma<strong>in</strong> lemmata, i.e., correctness (10) andcompleteness (19), we will need to extend a context with a new variable whose typewill only be known <strong>in</strong> the <strong>in</strong>duction step.In particular we would like to be able to see the whole set of terms typable <strong>in</strong>arbitrary contexts as an applicative structure. In an ord<strong>in</strong>ary applicative structuresthis is not possible: there is no way to <strong>for</strong>bid the application between two terms <strong>typed</strong><strong>in</strong> <strong>in</strong>compatible contexts (i.e., conta<strong>in</strong><strong>in</strong>g a same variable with different types), whichcould lead to an untypable term.There<strong>for</strong>e we def<strong>in</strong>e a weak 2 variant of Kripke applicative structures.Def<strong>in</strong>ition 2.31 (Kripke applicative structure).a tuple 〈W, , 〈{A ρ w}, {·ρ,σw }〉〉 where:• W is a set of ”possible worlds” partially ordered by .A Kripke applicative structure is• 〈{A ρ w}, {·ρ,σw }〉 is a family of <strong>typed</strong> applicative structure <strong>in</strong>dexed by worlds w ∈Wsuch that <strong>for</strong> two worlds w w ′ the follow<strong>in</strong>g properties hold:∀ f ∈ A ρ→σwA ρ w ⊆ A ρ w ′a ∈ A ρ w, ·ρ,σw fa = ·ρ,σwfa ′2 In a general def<strong>in</strong>ition the relation between sets A ρ w and A ρ w ′ with w w′ does not need to bean <strong>in</strong>clusion, but merely the existence of an <strong>in</strong>jective transition functions.


40 2. Simply Typed λ-CalculusWe are now able to encompass typable terms <strong>in</strong> arbitrary contexts <strong>in</strong> an applicativestructure.Example 10 (Set of typable terms). The tuple 〈W, , 〈{A ρ w}, {·ρ,σw }〉〉 where Wis the set Con of typ<strong>in</strong>g contexts Γ, is the <strong>in</strong>clusion relation between contexts,A ρ Γ is the set Tmρ Γof well <strong>typed</strong> terms of type ρ <strong>in</strong> context Γ, and ·ρ,σΓis syntacticapplication, is a Kripke applicative structure.In the same way that Kripke applicative structures are families of applicativestructures <strong>in</strong>dexed by a partial order, we def<strong>in</strong>e a Kripke monadic applicative structureto be a family of monadic applicative structures.Def<strong>in</strong>ition 2.32 (Kripke monadic applicative structure). A Kripke monadic applicativestructure over a monad M is a tuple 〈W, , 〈{A ρ w}, {·ρ,σw }〉〉 where:• W is a set of ”possible worlds” partially ordered by .• 〈{A ρ w}, {·ρ,σw }〉 is a family of monadic <strong>typed</strong> applicative structures <strong>in</strong>dexed byworlds w ∈ W such that <strong>for</strong> two worlds w w ′ the follow<strong>in</strong>g properties hold:∀ f ∈ A ρ→σwA ρ w ⊆ A ρ w ′, a ∈ A ρ w, ·ρ,σw fa = ·ρ,σwfa ′One can def<strong>in</strong>e a notion of Kripke relation enriched over a monad.Given Kripke monadic ap-Def<strong>in</strong>ition 2.33 (Kripke monadic logical relation).plicative structuresA = 〈W, , 〈{A ρ w}, {·ρ,σw }〉〉andB = 〈W, , 〈{B ρ w}, {·ρ,σw }〉〉over monads M A and M B , a Kripke monadic logical relation is a pair 〈I, J 〉, whereI and J are families of relations I τ w ⊆ A τ w × B τ w and J τ w ⊆ MA τ w × MB τ w <strong>in</strong>dexedby type τ ∈ Ty and world w ∈ W , such that the follow<strong>in</strong>g property holds:f Iw ρ→σ g ⇔ ∀ w ′ w, ∀ a I ρ wb, fa J σ ′ w ′ gb (comp)a Iw ρ b ⇒ ∀ w ′ w, a I ρ wb (mono)′a I w b ⇒ ν(a) J w ν(b)(unit)m J ρ w m ′ ∧ fI ρ→σw f ′ ⇒ m ⋆ a.f·a J σ w m ′ ⋆ a.f ′·a (mult)We extend the def<strong>in</strong>ition of admissibility <strong>for</strong> call-by-value acceptable mean<strong>in</strong>gfunctions.


2.3 Formalization 41Def<strong>in</strong>ition 2.34 (admissibility). Let A val <strong>in</strong> A and B val <strong>in</strong> B be call-by-valueacceptable mean<strong>in</strong>g functions, a monadic logical relation 〈I, J 〉 is admissible <strong>for</strong>A val and B val , if given elements −→ a and −→ b of A and B with −→ −→a I w b , thefollow<strong>in</strong>g property holds:∀ w ′ w, ∀ a I ρ w ′b, Ar val −→ x ,x↦→−→ a ,aJ σ w ′Brval −→ x ,x↦→−→ b ,b⇒ Aλx.r val −→ x ↦→−→ aJ ρ→σwBλx.r val−→ x ↦→−→ b(adm)The basic lemma valid <strong>for</strong> Kripke logical monadic relation reads as follows.Lemma 5 (basic lemma <strong>for</strong> Kripke monadic logical relation). Given Kripke monadicapplicative structures A and B over M A and M B , call-by-value acceptable mean<strong>in</strong>gfunction A val <strong>in</strong> A and B val <strong>in</strong> B, a Kripke admissible monadic logical relation〈I, J 〉, and a <strong>typed</strong> term Γ ⊢ r : ρ, with valuation η and δ on Γ (η Γ and δ Γ),the follow<strong>in</strong>g property holds, <strong>for</strong> an arbitrary w ∈ W:η I w δ ⇒ ∀ w ′ w, Ar valη J w ′ Br valδProof. By <strong>in</strong>duction on r ∈ Tm ρ ,case x, by hypothesis, η(x) I w δ(x), by monotonicity this holds <strong>for</strong> w ′ w, η(x) I w ′ δ(x),and by (unit) we have:∀ w ′ w, Ax valη J w ′ Bx valδ ,case rs, by <strong>in</strong>duction hypothesis on s, ∀ w ′ w, As valη J ρ wBs val′ δ ,by (mult), given w ′ w and f I ρ→σwf ′ we have′As valη ⋆ a.f·a J σ w ′ Bsval δ ⋆ a.f ′·a, (2.2)and hence by the comprehension property (comp):f.As valη⋆ a.f·a I (ρ→σ)→σwf ′ .Bs valδ⋆ a.f ′·a,hence by monotonicity (mono), this holds <strong>for</strong> w ′ w,f.As valη⋆ a.f·a I (ρ→σ)→σw ′f ′ .Bs valδ ⋆ a.f ′·a, (∗)by IH on r, ∀ w ′ w, Ar valηJ ρ→σw ′Br valδ ,by the multiplication property (mult), given w ′ w and g I w(ρ→σ)→σhaveg ′ , weAr valη ⋆ f.g·f J σ w ′ Brval δ ⋆ f.g ′·f, (∗∗)


42 2. Simply Typed λ-Calculustak<strong>in</strong>g g and g ′ as given <strong>in</strong> (∗) we obta<strong>in</strong>:Ar valη⋆ f.As valη ⋆ a.f·a Jw σ ′ Brval δ ⋆ f.Bs valδ ⋆ af·a,which by def<strong>in</strong>ition of acceptable mean<strong>in</strong>g functions is equivalent to:Ars valη Jw σ ′ Brsval δ ,case λx.r, let us assume w ′′ w ′ w and a I w ′′ b, by hypothesis η I w δ, and bymonotonicity (mono) we have also, η I w ′′ δ, by <strong>in</strong>duction hypothesis on r, wehave:Ar valη,x↦→a J w ′′by admissibility (adm),Br valδ,x↦→b,Aλx.r valη J w ′ Bλx.r valδ .As <strong>in</strong> the <strong>non</strong>-monadic case, the basic lemma holds automatically between <strong>in</strong>terpretations(as opposed to acceptable mean<strong>in</strong>g functions) related by a logical relation,because the admissibility property is immediately verified.Lemma 6 (admissibility of <strong>in</strong>terpretation). Let A val <strong>in</strong> A and B val <strong>in</strong> B be callby-value<strong>in</strong>terpretations, a monadic logical relation 〈I, J 〉 between A val and B valis admissible.Proof. Assume Ar val −→ x ,x↦→−→ a ,aJw σ ′show:Brval −→ x ,x↦→−→ b ,b<strong>for</strong> all a I ρ w ′b and w ′ w, we have toAλx.r val −→ x ↦→−→ aJ ρ→σwBλx.r val−→ x ↦→−→ b.The hypothesis Ar val −→ x ,x↦→−→ a ,aJ σ w Br val−→ x ,x↦→−→ b ,bvalid <strong>for</strong> all a I ρ w b and w ′ w, impliesthat by comprehension (comp),a.Ar val −→ x ,x↦→−→ a ,aI ρ→σwb.Br val−→ x ,x↦→−→ b ,b,by the unit property (unit), we have then:ν(a.Ar val −→ x ,x↦→−→ a ,a) J σ w ν(b.Br val−→ x ,x↦→−→ b ,b),which by def<strong>in</strong>ition of λx.r val is equivalent to:Aλx.r val −→ x ↦→−→ aJ ρ→σwBλx.r val−→ x ↦→−→ b.


2.3 Formalization 432.3.3 CorrectnessIn order to prove the correctness we need to modify the logical relation presented <strong>in</strong>the <strong>in</strong><strong>for</strong>mal exposition to take <strong>in</strong>to account the reader monad St E used to generatefresh names <strong>for</strong> variables. The follow<strong>in</strong>g relation between the term and the call-byvaluetype <strong>in</strong>terpretation applicative structures, will turn out to be a Kripke monadiclogical relation between substitution and term <strong>in</strong>terpretation.Def<strong>in</strong>ition 2.35 (Correctness relation R). We def<strong>in</strong>e a family of relation R ρ Γ ⊆Tm ρ Γ / = α× ρ val <strong>in</strong>dexed by type ρ and context Γ by <strong>in</strong>duction on ρ ∈ Ty as follows:r R o Γ a ::= Γ ⊢ r = βη a : or R ρ→σΓa ::= ∀ Γ ′ Γ, ∀ s R ρ Γ ′ b, rs S σ Γ ′ abwhere S σ Γis def<strong>in</strong>ed byr S σ Γ m ::= ∀ e, FV(r) ∉ e, r R σ Γ meRemark 8. Notice that <strong>in</strong> the clause Γ ⊢ r = βη a : o, the βη-conversion hasbeen implicitly extended between classes of terms modulo α-conversion and genu<strong>in</strong>esyntactical terms. This can be made explicit as follows: <strong>in</strong> case r is a class of termsmodulo α-conversion and a is a term, r = βη a holds if and only if the class r isβη-convertible to a class r ′ <strong>for</strong> which a is a representative.Lemma 7. 〈R, S〉 is a Kripke monadic logical relation between the Kripke applicativestructure 〈Con, , 〈{Tm ρ Γ / = α}, {·ρ,σΓ}〉〉 whose set of worlds are contexts and applicationis just syntactic application and the <strong>typed</strong> applicative structure 〈ρ val , ·ρ,σ 〉whose application is set-theoretic functional application.Proof. The comprehension property (comp) is verified by def<strong>in</strong>ition. The monotonicityproperty (mono) can be shown to hold by an easy <strong>in</strong>duction on the typeρ of R ρ . The unit property (unit) obviously holds. We show the multiplicationproperty (mult), i.e.,:r R ρ→σΓf ∧ s S ρ Γ m ⇒ rs Sσ Γ m ⋆ f.On the one hand by unfold<strong>in</strong>g the def<strong>in</strong>ition of rR ρ→σΓf, we obta<strong>in</strong>, given s, a and esuch that FV(rs) ∉ e:∀ Γ ′ Γ, s R ρ Γa ⇒ rs R σ ′ Γ ′ fae, (⋆)on the other hand, by unfold<strong>in</strong>g the def<strong>in</strong>ition of s S ρ Γenvironment e ′ such that FV(s) ∉ e ′ , thatm, we obta<strong>in</strong>, given ans R ρ Γ me′ ,


44 2. Simply Typed λ-Calculus<strong>in</strong> particular <strong>for</strong> an e such that FV(rs) ∉ e, FV(s) ∉ e holds, and hence we haves R ρ Γ me,by us<strong>in</strong>g (⋆), with Γ ′ := Γ and a := me, we obta<strong>in</strong>:∀ e, FV(rs) ∉ e, rs R σ Γ f(me)e.which is the def<strong>in</strong>ition of:rs SΓ σ m ⋆ f.By its def<strong>in</strong>ition, the call-by-value <strong>in</strong>terpretation verifies the property to be anacceptable mean<strong>in</strong>g function, moreover from example (9), we have seen that substitutionis an acceptable mean<strong>in</strong>g function.However substitution is not an <strong>in</strong>terpretation, so that lemma (6), only valid whenthe logical relation relates two <strong>in</strong>terpretations, does not apply here and we have toshow that the relation R is an admissible logical relation.We need first the follow<strong>in</strong>g technical lemma:Lemma 8. Given a <strong>typed</strong> term Γ ⊢ s : σ the follow<strong>in</strong>g propositions hold:r{ s /x} −→ s S τ Γ m ⇒ (λx σ .r)s −→ s S τ Γ m (2.3)r{ s /x} −→ s R τ Γ a ⇒ (λx σ .r)s −→ s R τ Γ a (2.4)Proof. We prove proposition (2.3) and (2.4) simultaneously by <strong>in</strong>duction on S Γ andR Γ ,proposition (2.3), by hypothesis, given e such that FV(r{ s /x} −→ s ) ∉ e, we have:r{ s /x} −→ s R τ Γ me,hence by I.H. on R <strong>for</strong> (2.4), (λxr)s −→ s R τ Γme, and we have proved∀ e, FV(r{ s /x} −→ s ) ∉ e ⇒ (λxr)s −→ s R τ Γ me,but FV(r{ s /x} −→ s ) ⊆ FV((λx.r x )s −→ s ), henceFV((λx.r)s −→ s ) ∉ e ⇒ FV(r{ s /x} −→ s ) ∉ eand f<strong>in</strong>ally∀ e, FV((λx.r)s −→ s ) ∉ e ⇒ (λxr)s −→ s R τ Γ mewhich is equivalent to(λxr)s −→ s SΓ τ m


2.3 Formalization 45proposition (2.4),case o, clearly r{ s /x} −→ s = βη (λx.r)s −→ s , and we have to check that Γ is a validtyp<strong>in</strong>g context <strong>for</strong> (λxr)s −→ s but this follows easily because as s is typable<strong>in</strong> Γ ′ , the free variables of s (possibly not occurr<strong>in</strong>g <strong>in</strong> r{ s /x} −→ s ) are <strong>in</strong> Γ,case ρ → σ, by hypothesis <strong>for</strong> Γ ′ Γ and t R ρ Γ ′r{ s /x} −→ s t S σ Γ ′ ab,and by <strong>in</strong>duction hypothesis on σ, we haveb we have:(λxr)s −→ s t S σ Γ ′ab.Corollary 1 (admissibility). Given a <strong>typed</strong> term r of type σ with free variables−→ x :−→ ρ , x : ρ, and terms s of type−→ ρ and values−→ a ∈−→ ρ such that−→ s RΓ−→ a , then:∀ s R ρ Γ a, r{−→ s ,s / −→ x ,x} S σ Γ r−→ x ,x↦→−→ a ,a⇒ λx.r{ −→ s / −→ x } S ρ→σΓλx.r−→ x ↦→−→ aProof. Given a term s of type ρ and a value a ∈ ρ, such that s R ρ Γa andr{ −→ s ,s / −→ x ,x} SΓ σ r−→ x ,x↦→ −→ , and an environment e with a ,a FV(λx.r{−→ s / −→ x }) ∉ e, we haveto show that:λx.r{ −→ s / −→ x } R ρ→σΓλx.r−→ x ↦→−→ ae,i.e.,, by unfold<strong>in</strong>g the def<strong>in</strong>ition of R ρ→σΓand λx.r we have to show:∀ Γ ′ Γ, ∀ s R ρ Γ ′ a, (λx.r{ −→ s / −→ x })s S σ Γ ′ r−→ x ,x↦→ −→ a ,a .But this last proposition is obta<strong>in</strong>ed by <strong>in</strong>duction on −→ s us<strong>in</strong>g the previous lemma(8) from the hypothesis r{ −→ s ,s / −→ x ,x} SΓ σ ′ r−→ x ,x↦→ −→ as s is typable <strong>in</strong> Γ follows froma ,as R ρ Γa. ′Lemma 9 (Basic lemma). Given a <strong>typed</strong> term {x 1 : ρ 1 , . . . , x n : ρ n } ⊢ r : ρ, <strong>typed</strong>terms −→ s = s 1 , . . . , s n with Γ ⊢ s i : ρ i , and values −→ a = a 1 , . . . , a n with a i ∈ ρ i , thefollow<strong>in</strong>g proposition hold:−→ s RΓ−→ a ⇒ r{−→ s / −→ x } S Γ r val −→ x ↦→−→ aProof. As R is an admissible monadic logical relation, we can apply lemma (13)After this prelim<strong>in</strong>ary work, we arrive at the core of the proof with the follow<strong>in</strong>glemma:


46 2. Simply Typed λ-CalculusLemma 10 (correctness). For terms r, s, value a, and an environment e such thatFV(r) ∉ e, the follow<strong>in</strong>g properties hold:Γ ⊢ r = βη s : ρ ⇒ r R ρ Γ ↑ρ s (1)r R ρ Γ a ⇒ Γ ⊢ r = βη (↓ ρ a)e : ρ (2)Proof. We show (1) and (2) by simultaneous <strong>in</strong>duction on the type ρ ∈ Ty of r.case o, by def<strong>in</strong>ition,case ρ → σ,(1), given Γ ⊢ r = s : ρ → σ, we have to show:∀ Γ ′ Γ, ∀ t R ρ Γ ′ a, rt S σ Γ ′ (↑ρ→σ s)(a),that is, given t R ρ Γ ′ a and e such that FV(rt) ∉ e,rt R σ Γ ′(↑ρ→σ s)(a)e.By <strong>in</strong>duction hypothesis (2) on ρ, given an e such that FV(t) ∉ e, we havet = βη (↓ a)e, and hence rt = βη s((↓ a)e).By <strong>in</strong>duction hypothesis (1) on σ, given an e such that FV(rt) ∉ e wehave, rt R σ Γ ↑ s((↓ a)e).But ↑ s((↓ a)e) is equal to((↓ ρ a) ⋆ t.η(↑ σ st))e,and by def<strong>in</strong>ition of ↑ at arrow type, this last term is equal to:(↑ ρ→σ s)(a)e,and FV(rt) ∉ e implies FV(t) ∉ e.(2) We have to show <strong>for</strong> e with FV(r) ∉ e:r R ρ Γ f ⇒ r = βη↓ (f)e.By def<strong>in</strong>ition of R at arrow type:r R ρ→σ f ≡ ∀ Γ ′ Γ, ∀ s R ρ Γ ′ a, rs S σ Γ ′ fa.Let us take x = new(e), by <strong>in</strong>duction hypothesis (1) on ρ, x R ρ Γ,x:ρ ↑ x,and hencerx S σ Γ,x:ρ f ↑ x.


2.3 Formalization 47By def<strong>in</strong>ition, ∀ e ′ , FV(rx) ∉ e ′ ⇒ rx R σ Γ,x:ρ f(↑ x)e′ , and this holds <strong>in</strong>particular <strong>for</strong> e ′ = e x .By <strong>in</strong>duction hypothesis (2) on σ, we have rx = βη (↓ f(↑ x)e x )e x . So wehave:λx.rx = βη λx.(↓ f(↑ x)e x )e x = λx.(f ↑ x⋆ ↓)e x .This last term typable <strong>in</strong> Γ is equal tonew ⋆ v.(f ↑ v⋆ ↓) v ⋆ t.ν(λv.t)e =↓ (f)e.Lemma 11. For a term r, and an environment e such that FV(r) ∉ er = βη (r ↑ ⋆ ↓)eProof. By part (1) of lemma (10) we havex R ↑ x.Because R is a logical relation, we have by the fundamental lemma:r S r ↑ .By def<strong>in</strong>ition, ∀ e, FV(r) ∉ e, r R r ↑ e. Now by the second part of the previouslemma given a e ′ such that FV(r) ∉ e ′ we have:r = (↓ r ↑ e)e ′ ,and so it holds <strong>in</strong> particular <strong>for</strong> e = e ′ , i.e.,:r = βη (↓ (r ↑ e))e = (r ↑ ⋆ ↓)e.2.3.4 CompletenessIn this section we prove the completeness of the NbE algorithm, that normal <strong>for</strong>msof terms βη-convertible are themselves α-convertible, that is:Γ ⊢ r = βη s : ρ ⇒ ∀ e ∌ Γ, Γ ⊢ (r ↑ ⋆ ↓)e = α (s ↑ ⋆ ↓)e : ρ.The idea is to def<strong>in</strong>e a relation J Γ such that the two follow<strong>in</strong>g conditions areprovablea J ρ Γ b ⇒ ∀ e ∌ Γ, Γ ⊢ (a⋆ ↓)e = α (b⋆ ↓)e : ρ (1)Γ ⊢ r = βη s : ρ ⇒ r ↑ J ρ Γ s ↑ (2)


48 2. Simply Typed λ-CalculusIn fact, to prove the first condition above <strong>in</strong>volv<strong>in</strong>g α-conversion, we will use<strong>in</strong>duction on the structure of terms. A problem here is that α-conversion is aboutbound variables only, if it says that the terms λx.x and λy.y are equivalent, it saysnoth<strong>in</strong>g about their immediate subterms x and y (see footnote 3, <strong>in</strong> the proof oftheorem (19), p. 56). As a consequence the needed <strong>in</strong>duction pr<strong>in</strong>ciple will havenecessarily to be a generalisation of α-conversion, it should enable us to compareterms up to renam<strong>in</strong>g of their free variables. Although, we would never argue that ”αconversionis easy”, the approach here is related to the paper of Thorsten Altenkirch[3].Def<strong>in</strong>ition 2.36 (Variables renam<strong>in</strong>g, context renam<strong>in</strong>g). A renam<strong>in</strong>g of variablesis a substitution where the terms substituted <strong>for</strong> are variables. Given lists of variables−→ x = x1 , . . . , x n , and −→ y = y 1 , . . . , y n , the effect of a renam<strong>in</strong>g { −→ y / −→ x } on a contextΓ is def<strong>in</strong>ed componentwise:∅{ −→ y / −→ x } ::= ∅{({x : ρ} ∪ Γ){ −→ y{y/ −→ i : ρ} ∪ Γ{ −→ y /x } ::=−→ x } if x = x i <strong>for</strong> x i ∈ −→ x{x : ρ} ∪ Γ{ −→ y / −→ x } otherwiseWe <strong>in</strong>troduce now a notation to compare term up to renam<strong>in</strong>g of their freevariables, this is a generalisation of α-conversion to renam<strong>in</strong>g.Notation 12. The renam<strong>in</strong>g { −→ y / −→ x } from a context Γ = {x 1 : ρ 1 , . . . , x n : ρ n } <strong>in</strong>tothe context Γ ′ = {y 1 : ρ 1 , . . . , y n : ρ n }, will be simply written Γ; Γ ′ although <strong>for</strong>mallyΓ and Γ ′ are unordered sets of pairs.We will write Γ; Γ ′ ⊢ r = α r ′ : ρ where Γ; Γ ′ is the renam<strong>in</strong>g given above if Γ ⊢ r : ρand Γ ′ ⊢ r : ρ if Γ ′ { −→ y / −→ x } = Γ and r = r ′ { −→ y / −→ x }With this notation the α-conversion between well <strong>typed</strong> terms r and r ′ of typeρ <strong>in</strong> a context Γ can be expressed as Γ; Γ ⊢ r = α r ′ : ρ (i.e., the renam<strong>in</strong>g is theidentity).The generalisation of condition (1) <strong>for</strong> which we can use <strong>in</strong>duction on the structureof terms reads:a J ρ Γ,Γ ′ b ⇒ ∀ (e, e ′ ) ∌ (Γ, Γ ′ ), Γ; Γ ′ ⊢ (a⋆ ↓)e = α ((b⋆ ↓)e ′ ) : ρ (1’).The <strong>in</strong>clusion relation on contexts <strong>in</strong>duces a relation on context renam<strong>in</strong>g:Def<strong>in</strong>ition 2.37 (order on contexts renam<strong>in</strong>gs). The partial order on contextrenam<strong>in</strong>g is the least symmetric transitive relation such that:Γ; Γ ′ Γ, (x : ρ); Γ ′ , (y : ρ)


2.3 Formalization 49We def<strong>in</strong>e below a pair of relations I and J , relat<strong>in</strong>g values of the <strong>in</strong>terpretations,I <strong>for</strong> normal values and J <strong>for</strong> monadic values. We will show that these relations<strong>for</strong>m a logical relation and are partial equivalence relations (i.e., symmetric andtransitive).Def<strong>in</strong>ition 2.38 (completeness relation). We def<strong>in</strong>e a family of logical relationsI ρ Γ,Γ⊆ ρ × ρ and J ρ ′ Γ,Γ⊆ St ′ E ρ × St E ρ <strong>in</strong>dexed by a type ρ and a contextΓ ∈ Con <strong>in</strong>ductively by:r I o Γ,Γ ′s ::= Γ; Γ′ ⊢ r = α r ′ : of I ρ→σΓ,Γ ′ g ::= ∀ ∆; ∆ ′ Γ; Γ ′ , ∀ a I ρ ∆,∆ ′ b, fa J σ ∆,∆ ′ fbm J ρ Γ,Γ ′ m ′ ::= ∀ e, e ′ , (Γ, Γ ′ ) ∉ (e, e ′ ), me I ρ Γ,Γ ′ m ′ e ′Lemma 12. The pair of relations 〈I, J 〉 <strong>for</strong>ms a Kripke monadic logical relation on(two copies of) the <strong>typed</strong> applicative structure 〈ρ, ·〉 where · is syntactic application.Proof. The comprehension property (comp) is verified by def<strong>in</strong>ition. The monotonicityproperties (mono) and the unit property (unit) obviously hold.We show the multiplication property (mult), i.e.,:f I ρ→σΓ,Γ ′ f ′ ∧ m J ρ Γ,Γ ′ m ′ ⇒ m ⋆ f J σ Γ,Γ ′ m′ ⋆ f ′On the one hand by def<strong>in</strong>ition of f I ρ→σΓ,Γ ′ f ′ , we obta<strong>in</strong> <strong>in</strong> particular <strong>for</strong> a I ρ Γ,Γ ′ a ′ :fa J σ Γ,Γ ′ f ′ a ′ .which implies by the def<strong>in</strong>ition of J <strong>for</strong> e, e ′ such that Γ, Γ ′ ∉ e, e ′ :fae I σ Γ,Γ ′ f ′ a ′ e ′ .On the other hand, by unfold<strong>in</strong>g the def<strong>in</strong>ition of m J ρ Γ,Γ ′above, we obta<strong>in</strong>:m ′ , <strong>for</strong> e, e ′ and Γ; Γ ′ asme I ρ Γ,Γm ′ e ′ .′And hence we havef(me)e I ρ Γ,Γf ′ (m ′ e ′ )e ′ .′which is the def<strong>in</strong>ition of:(m ⋆ f) J ρ Γ,Γ(m ′ ⋆ f ′ ).′


50 2. Simply Typed λ-CalculusLemma 13 (basic lemma).µ I Γ,Γ ′ ν ⇒ r µ J Γ,Γ ′ r νProof. (I, J ) <strong>for</strong>ms a logical relation as shown <strong>in</strong> lemma (12), and the admissibilityproperty holds immediately <strong>for</strong> <strong>in</strong>terpretation as shown <strong>in</strong> lemma (6).Lemma 14 (symmetry). I is a symmetric relation:∀ ab, a I Γ,Γ ′ b ⇒ b I Γ,Γ ′ aProof. Remark first that symmetry of I ρ Γ,Γ ′ implies symmetry of J ρ Γ,Γ ′ :∀ m m ′ , m J Γ,Γ ′ m ′ ⇒ m ′ J Γ,Γ ′ mThe proof is by <strong>in</strong>duction on the type ρ ∈ Ty:case ρ = o, follows from symmetry of = α ,case ρ → σ, we want to show:f I ρ→σΓ,Γ ′By def<strong>in</strong>ition,g ⇒ g I ρ→σΓ,Γ ′ff I ρ→σΓ,Γ ′ g ⇔ ∀ ∆, ∆ ′ Γ, Γ ′ , ∀ a I ρ ∆,∆ ′ b, faJ σ ∆,∆ ′ gbg I ρ→σΓ,Γ ′ f ⇔ ∀ ∆, ∆ ′ Γ, Γ ′ , ∀ b I ρ ∆,∆ ′ a, gbJ σ ∆,∆ ′ fa.By <strong>in</strong>duction hypothesis on ρ we have:b I ρ ∆,∆ ′ a ⇒ a I ρ ∆,∆ ′ bby hypothesis this implies fa J∆,∆ σ ′havefa J σ ∆,∆ ′ gb ⇒ gb J σ ∆,∆ ′ fa.gb and by <strong>in</strong>duction hypothesis on σ, weLemma 15 (transitivity). I is a transitive relation:∀ a b c, a I Γ,Γ ′ b ∧ b I Γ,Γ ′ c ⇒ a I Γ,Γ ′ cProof. Remark first that transitivity of I ρ Γ,Γimplies transitivity of J ρ ′ Γ,Γ: ′∀ m m ′ m ′′ , m J Γ,Γ ′ m ′ ∧ m ′ J Γ,Γ ′ m ′′ ⇒ m J Γ,Γ ′ m ′′The proof is by <strong>in</strong>duction on the type ρ ∈ Ty:


2.3 Formalization 51case ρ = o, follows from transitivity of = α ,case ρ → σ, we want to showf I ρ→σΓ,Γ ′g ∧ g I ρ→σΓ,Γ ′h ⇒ f I ρ→σΓ,Γ ′hBy def<strong>in</strong>ition,f I ρ→σΓ,Γg ⇔ ∀ ∆, ∆ ′ Γ, Γ ′ , ∀ a I ρ ′ ∆,∆b, fa J σ ′ ∆,∆ ′ gb, andg I ρ→σΓ,Γh ⇔ ∀ ∆, ∆ ′ Γ, Γ ′ , ∀ a I ρ ′ ∆,∆b, ga J σ ′ ∆,∆ hb ′By symmetry, a I ρ ∆,∆b, implies b I ρ ′ ∆,∆a, by <strong>in</strong>duction hypothesis on ρ,′a I ρ ∆,∆a, and hence fa J σ ′ ∆,∆ ga and ga J σ ′ ∆,∆ ′ hb, and by <strong>in</strong>duction hypothesison σ, fa J∆,∆ σ hb. This concludes the proof.′Conversions βηOn the one hand the fact that 〈I, J 〉 <strong>for</strong>ms a logical relation ensures that the<strong>in</strong>terpretation of a term is related with itself, i.e., the restriction of the relation Jto the <strong>in</strong>terpretation of terms is reflexive. On the other hand, the restriction of apartial equivalence relation R on those elements where R is reflexive ({x | xRx})is an equivalence relation. In particular, the restriction of the <strong>in</strong>terpretation to thesubset where J is reflexive, is already enough to <strong>in</strong>terpret terms. On this restrictionthe relation J is an equivalence relation and can be seen as coarser equality thanthe set-theoretic equality.We will now prove that, if we consider this latter equality as the actual equalityon the <strong>in</strong>terpretation, the <strong>in</strong>terpretation of terms is sound with respect to the βηconversion,(i.e., r = βη s ⇒ rJ s).The follow<strong>in</strong>g technical lemma relates semantical valuation and syntactical substitutionand will be needed to relate the <strong>in</strong>terpretation of β-convertible terms.Lemma 16 (substitution). Given a <strong>typed</strong> term Γ s ⊢ s : σ, two valuations η and δ onΓ s , (i.e., η Γ s , and δ Γ s ), a <strong>typed</strong> term Γ s , x : ρ, Γ r ⊢ r : σ, and two valuations η ′and δ ′ on Γ r (i.e., η ′ Γ r , and δ ′ Γ r ). Moreover, given contexts Γ, Γ ′ , ∆, ∆ ′ withη I Γ,Γ ′ δ, an environment e such that Γ ∉ e, ∆; ∆ ′ Γ; Γ ′ and η ′ I ∆,∆ ′ δ ′ we have:r η,x↦→sη e,η ′ J ∆,∆ ′ r{s /x} δ,δ ′Remark that an environment e is present <strong>in</strong> the left hand side of the relation abovebut not <strong>in</strong> the right hand side. This will allow to relate the terms of the algorithmwhich are not syntactically equal but only α-convertible.


52 2. Simply Typed λ-CalculusProof. By <strong>in</strong>duction on the typ<strong>in</strong>g derivation of r, we have to show <strong>for</strong> ∆, ∆ ′ ∉ d, d ′r η,x↦→sη e,η ′d I ∆,∆ ′ r{s /x} δ,δ ′d ′case r = x, As the variables of the doma<strong>in</strong> of the valuation δ ′ do not occur <strong>in</strong> s, wehave immediately that s δ = s δ,δ ′ and we have to prove:s η e I ∆,∆ ′ s δ d ′By the basic lemma, we already have s η J Γ,Γ ′ s δ , which means by def<strong>in</strong>itionthat <strong>for</strong> e and e ′ with Γ, Γ ′ ∉ e, e ′ we have:s η e I Γ,Γ ′ s δ e ′ ,In particular <strong>for</strong> ∆ ′ Γ ′ , and d ′ such that ∆ ′ ∉ d ′ we have Γ ′ ∉ d ′ , so that wehave s η e I Γ,Γ ′ s δ d ′ . And by monotonicity, we obta<strong>in</strong> f<strong>in</strong>ally:s η e I ∆,∆ ′ s δ d ′ ,case r = r ′ s ′ , We have to show:r ′ η,x↦→sη e,η ′d(s′ η,x↦→sη e,η ′d)d I ∆,∆ ′ r′ { s /x} δ,δ ′d ′ (s ′ { s /x} δ,δ ′d ′ )d ′By <strong>in</strong>duction hypothesis on s ′ , <strong>for</strong> d, d ′ such that ∆, ∆ ′ ∉ d, d ′ we haves ′ η,x↦→sη e,η ′d I ∆,∆ ′ s′ { s /x} δ,δ ′d ′By <strong>in</strong>duction hypothesis on r ′ , we haver ′ η,x↦→sη e,η ′ I ∆,∆ ′ r′ { s /x} δ,δ ′But because r is <strong>in</strong> applicative position it is of arrow type and by unfold<strong>in</strong>g thedef<strong>in</strong>ition we have <strong>for</strong> E, E ∆, ∆ ′ , a I E,E ′ b and f, f ′ such that E, E ′ ∉ f, f ′ :r ′ η,x↦→sη e,η ′af I E,E ′ r′ { s /x} δ,δ ′bf ′Tak<strong>in</strong>g ∆, ∆ ′ <strong>for</strong> E, E ′ , and s ′ η,x↦→sη e,η ′ d and s ′ { s /x} δ,δ ′d ′ <strong>for</strong> a and b, andd, d ′ <strong>for</strong> f, f ′ yields the result.case r = λy.r ′ , First remark that λy.r is of arrow type, say ρ → σ, so that we haveto prove <strong>for</strong> E, E ′ ∆, ∆ ′ and a I ρ E,E ′ b:λy.r ′ ρ→σ η,x↦→sη e,η ′da JE,E ′which simplifies <strong>in</strong>tor ′ η,x↦→sη e,η ′ ,y↦→a J ρ→σE,E ′λy.r ′ { s /x} δ,δ ′d ′ bλy.r ′ { s /x} δ,δ ′ ,y↦→bBy monotonicity (mono), η ′ I ∆,∆ ′ δ ′ ⇒ η ′ I E,E ′ δ ′ and hence η ′ , y ↦→ a I E,E ′ δ ′ , y ↦→b. One can then apply the <strong>in</strong>duction hypothesis on r ′ , which yields the result.


2.3 Formalization 53Corollary 2 (β-conversion). Given a <strong>typed</strong> term Γ s ⊢ s : σ, two valuations η andδ on Γ s , (i.e., η Γ s , and δ Γ s ), a <strong>typed</strong> term Γ s , x : ρ ⊢ r : σ. Moreover, givencontexts Γ, Γ ′ with η I Γ,Γ ′ δ, we have:(λx.r)s η J Γ,Γ ′r{ s /x} δProof. Given e, e ′ such that Γ, Γ ′ ∉ e, e ′ , we have to prove:(λx.r)s η e I Γ,Γ ′ r{ s /x} δ e ′which is equivalent tor η,x↦→sη ee I Γ,Γ ′ r{ s /x} δ e ′By <strong>in</strong>stantiat<strong>in</strong>g the previous lemma (16) with ∆, ∆ ′ = Γ, Γ ′ , η = η and δ = δ, wehave:r η,x↦→sη e J Γ,Γ ′r{ s /x} δand <strong>in</strong> particular, we get the result:r η,x↦→sη ee I Γ,Γ ′ r{ s /x} δ e ′Lemma 17 (η-conversion). Given a <strong>typed</strong> term Γ r ⊢ r : σ, two valuations η and δon Γ r , (i.e., η Γ r and δ Γ r ). Moreover, given contexts Γ, Γ ′ with η I Γ,Γ ′ δ, wehave:r η J ρ→σΓ,Γ ′λx.rx δProof. We have to show, given e, e ′ such that Γ, Γ ′ ∉ e, e ′ , and ∆, ∆ ′ Γ, Γ ′ andaI ∆,∆ ′b, d, d ′ such that ∆, ∆ ′ ∉ d, d ′ , that:r η ead J ∆,∆ ′ λx.rx δ e ′ bd ′which simplifies <strong>in</strong>tor η ead J ∆,∆ ′ r δ d ′ bd ′By the basic lemma (13),r η J ρ→σΓ,Γ ′r δ


54 2. Simply Typed λ-CalculusBy def<strong>in</strong>ition, <strong>for</strong> e, e ′ such that Γ, Γ ′ ∉ e, e ′ , we haver η e I ρ→σΓ,Γ ′ r δ e ′But <strong>for</strong> ∆ Γ, ∆ ∉ d ′ implies Γ ∉ d ′ , so that we have r η e I ρ→σΓ,Γ ′turn we have, <strong>for</strong> ∆, ∆ ′ Γ, Γ ′ , and a I ∆,∆ ′ b:r δ d ′ . And <strong>in</strong>r η ea J σ ∆,∆ ′r δd ′ bAnd f<strong>in</strong>ally,r η ead I σ ∆,∆ ′ r δd ′ bd ′Lemma 18. Given two <strong>typed</strong> terms Γ ⊢ r : τ and Γ ⊢ s : τ, two valuation η and δon Γ (i.e., η Γ and δ Γ), and two contexts ∆, ∆ ′ , we have:Γ ⊢ r = βη s : τ ⇒ ∀ η I ∆,∆ ′ δ, r η J τ ∆,∆ ′ s δProof. By <strong>in</strong>duction on the relation Γ ⊢ r = βη s : τ,The case of reflexivity is the basic lemma. (13) The cases of β-conversion, η-conversion, reflexivity, symmetry and transitivity have already been handled <strong>in</strong>lemma (14)(15)(17) and corollary (2).Rest the structural rules:Γ ⊢ tr = βη ts : ρ ⇒ ∀ η I ∆,∆ ′ δ, tr η J ρ ∆,∆ ′ ts δΓ ⊢ rt = βη st : ρ ⇒ ∀ η I ∆,∆ ′ δ, rt η J ρ ∆,∆st ′ δΓ ⊢ λx ρ .r = βη λx ρ .s : σ ⇒ ∀ η I ∆,∆ ′ δ, λx ρ .r η J ρ→σ∆,∆λx ρ .s ′δThey all follow from the <strong>in</strong>duction hypothesis on r and s and use of the basic lemma<strong>for</strong> t <strong>in</strong> the two first cases.Completeness LemmaIn the <strong>in</strong><strong>for</strong>mal presentation the reify function ↓ is a function from the <strong>in</strong>terpretationto the set of terms and the function reflect is a function from the set of termsto the <strong>in</strong>terpretation. The follow<strong>in</strong>g lemma states a similar result <strong>for</strong> the call-byvalue<strong>in</strong>terpretation when the set of terms is quotiented by α-conversion, and the(restriction of the) <strong>in</strong>terpretation by the partial equivalence relation I or J .Lemma 19 (Completeness). Given a, b ∈ ρ, r ∈ Tm ρ , and e, e ′ ∈ E the follow<strong>in</strong>gpropositions hold:m J ρ Γ,Γ ′ m ′ ⇒ ∀ e, e ′ , (Γ, Γ ′ ) ∉ (e, e ′ ), Γ; Γ ′ ⊢ (m⋆ ↓)e = α (m ′ ⋆ ↓)e ′ : ρ (1’)Γ; Γ ′ ⊢ r = α r ′ : ρ ⇒ ↑ ρ r I Γ,Γ ′ ↑ ρ r ′ (2’)


2.3 Formalization 55Proof. By simultaneous <strong>in</strong>duction on the type ρ ∈ Ty,case ρ = o (1’),by def<strong>in</strong>ition of ↓ o , we have:(m⋆ ↓ o ) = (m ⋆ ν) = m.By def<strong>in</strong>ition of J o Γ,Γ ′, <strong>for</strong> e, e′ such that Γ, Γ ′ ∉ e, e ′ we have me I o Γ,Γ ′ me′ , andby def<strong>in</strong>ition aga<strong>in</strong>:Γ, Γ ′ ⊢ r = α r ′ : ocase ρ = o (2’),follows from the def<strong>in</strong>ition as ↑ o is the identity.case ρ → σ (1’),show that:given m J ρ→σΓ,Γ ′m ′ , and e, e ′ such that Γ, Γ ′ ∉ e, e ′ we want toΓ; Γ ′ ⊢ (m⋆ ↓)e = α (m ′ ⋆ ↓)e ′ : ρBy <strong>in</strong>duction hypothesis (2’) on ρ, <strong>for</strong> x ρ , y ρ ∉ Γ, Γ ′ we have:↑ ρ x I Γ,x ρ ;Γ ′ ,y ρ↑ρ yIn particular, <strong>for</strong> e, e ′ such that Γ, Γ ′ ∉ e, e ′ one can take new(e) and new(e ′ )<strong>for</strong> x and y.By hypothesis, this impliesme ↑ ρ x J σ Γ,x ρ ;Γ ′ ,y ρm′ e ′ ↑ ρ yAs Γ, Γ ′ ∉ e, e ′ implies (Γ, x : ρ; Γ ′ , y : ρ) ∉ e x , e ′y , we obta<strong>in</strong> by <strong>in</strong>ductionhypothesis (1’) on σ,Γ, x : ρ; Γ ′ , y : ρ ⊢ (me ↑ ρ x⋆ ↓)e x = α (m ′ e ′ ↑ ρ y⋆ ↓)e ′y : ρWe can abstract on both sides to obta<strong>in</strong>:Γ; Γ ′ ⊢ λx ρ .(me ↑ ρ x⋆ ↓)e x = α λy ρ ((m ′ e ′ ↑ ρ y⋆ ↓)e ′y ) : ρWith a bit of computation, one can see that the left hand side is equal to:λx.(me(↑ x)⋆ ↓ σ )e x = λx.(me(↑ x)⋆ ↓ σ ) x eand by choos<strong>in</strong>g new(e) <strong>for</strong> x,λx.(me(↑ x)⋆ ↓ σ )e x = α (m⋆ ↓)e= ((me(↑ x)⋆ ↓ σ ) x ⋆ t.ν(λx.t))e= (m ⋆ f.(f(↑ x)⋆ ↓ σ ) x ⋆ t.ν(λx.t))e


56 2. Simply Typed λ-CalculusBy an analogous computation (and choos<strong>in</strong>g new(e ′ ) <strong>for</strong> y) the right hand sideis α-equal to (m ′ ⋆ ↓)e ′ 3 .case ρ → σ, (2’)Under the hypothesisΓ; Γ ′ ⊢ r = α r ′ : ρ → σwe want to show, given ∆, ∆ ′ Γ, Γ ′ and a I ρ ∆,∆ ′(↑ ρ→σ r)a J σ ∆,∆ ′ (↑ρ→σ s)b.b that:By (unit), we have ν(a) J ρ ∆,∆ν(b), and by <strong>in</strong>duction hypothesis (1’) on ρ we′obta<strong>in</strong>, <strong>for</strong> d, d ′ such that ∆, ∆ ′ ∉ d, d ′ :∆; ∆ ′ ⊢ ν(a)⋆ ↓ ρ d = α (ν(b)⋆ ↓ ρ d ′ ) : ρwhich can be simplified <strong>in</strong>toand hence∆; ∆ ′ ⊢ (↓ ρ a)d = α (↓ ρ b)d ′ : ρ∆; ∆ ′ ⊢ r(↓ ρ a)d = α r(↓ ρ b)d ′ : σBy <strong>in</strong>duction hypothesis (2’) on σ,↑ r(↓ ρ a)d I ∆,∆ ′ ↑ r(↓ ρ b)d ′but ↑ σ r(↓ ρ a)d =↓ ρ a ⋆ s.ν(↑ σ rs)d = (↑ ρ→σ r)ad, and analogously ↑ σ r(↓ ρb)d ′ = (↑ ρ→σ r)bd ′ , and the last relation is equivalent to:(↑ ρ→σ r)ad I ∆,∆ ′ (↑ ρ→σ r)bd ′And we have proved(↑ ρ→σ r)a J σ ∆,∆ ′ (↑ρ→σ s)b.Corollary 3. Given two <strong>typed</strong> terms Γ ⊢ r : τ and Γ ⊢ s : τ, we have:Γ ⊢ r = βη s : τ ⇒ r ↑ J τ Γ,Γ s ↑Proof. Follows from the lemma (18) with η ::= δ ::=↑, as the previous lemma (3)states that ↑ I Γ,Γ ↑.Theorem 1. Given two <strong>typed</strong> terms Γ ⊢ r : τ and Γ ⊢ s : τ, we have:Γ ⊢ r = βη s : τ ⇒ ∀ e, Γ ∉ e ⇒ Γ ⊢ (r ↑ ⋆ ↓)e = (s ↑ ⋆ ↓)e : τProof. Follows from the previous corollary (3) and the completeness lemma (19)3 Notice that we needed a more general <strong>in</strong>duction pr<strong>in</strong>ciple than the first proposal (1), becausewe had to prove a conclusion of the <strong>for</strong>m λx.r = α λy.s where x and y may be different, and neededto apply the <strong>in</strong>duction hypothesis on r and s.


Chapter 3Generalized ApplicationsBy the Curry-Howard isomorphism, the system of natural deduction NJ <strong>for</strong> m<strong>in</strong>imallogic is <strong>in</strong> one-to-one correspondence with the simply <strong>typed</strong> λ-<strong>calculus</strong> Λ. Theextensional conversion βη of the λ-<strong>calculus</strong> corresponds to equivalence of proofs <strong>in</strong>natural deduction (<strong>in</strong> particular β-reduction corresponds to detour elim<strong>in</strong>ation).It is well known however that the correspondence between sequent <strong>calculus</strong> andnatural deduction is not one-to-one: <strong>for</strong> one proof <strong>in</strong> natural deduction there is <strong>in</strong>general several proofs <strong>in</strong> the sequent <strong>calculus</strong>.Although <strong>in</strong><strong>for</strong>mally cut elim<strong>in</strong>ation corresponds to detour elim<strong>in</strong>ation, and henceto β-reduction, even the correspondence between cut-free derivation and β-normalterms is not one-to-one, just as above: <strong>for</strong> one detour-free proof <strong>in</strong> natural deductionthere is <strong>in</strong> general several cut-free proofs <strong>in</strong> the sequent <strong>calculus</strong>.Because η-conversion equates more derivations <strong>in</strong> natural deduction, the situationis even more complicated with this conversion.Nevertheless, Jan Von Plato designed <strong>in</strong> [90] a system of natural deduction wherederivations are <strong>in</strong> one-to-one correspondence with cut-free sequent proofs.In [55], Felix Joachimski and Ralph Matthes designed a λ-<strong>calculus</strong> Λ J whosenormal <strong>for</strong>ms with respect to β-reduction and certa<strong>in</strong> permutative reductions (orπ-reductions) are exactly the derivations of the system of Von Plato, and they showits strong normalization.Beside detour elim<strong>in</strong>ation and permutative reduction, one can consider other<strong>conversions</strong> <strong>in</strong> this <strong>calculus</strong>. The class of terms modulo these extra <strong>conversions</strong> is<strong>in</strong> one-to-one correspondence with the normal <strong>for</strong>ms of the simply <strong>typed</strong> λ-<strong>calculus</strong>.Ralph Matthes used these generalised conversion relation <strong>in</strong> [69] to prove an <strong>in</strong>terpolationresult and show some of its applications.Here we will discuss a def<strong>in</strong>ition of normal <strong>for</strong>ms <strong>for</strong> the <strong>calculus</strong> Λ J with theseextended <strong>conversions</strong>. These normal <strong>for</strong>ms are not unique representatives of theclasses of terms modulo the extended <strong>conversions</strong>. But normal terms belong<strong>in</strong>g tothe same class are mutually convertible thanks to a decidable conversion (which wehave called here circular conversion). We will then describe a normalization function


58 3. Generalized Applicationsus<strong>in</strong>g normalization by evaluation. This provides a decision procedure <strong>for</strong> the wholetheory of the Λ J -<strong>calculus</strong>, which is, to the best of our knowledge, a new result.This provides <strong>in</strong> turn a notion of normal proofs <strong>for</strong> the sequent <strong>calculus</strong> whichcorrespond modulo circular <strong>conversions</strong> to normal proofs <strong>in</strong> natural derivation.3.1 From Sequent Calculus to Λ JThe <strong>for</strong>mula we consider are the types of the simply <strong>typed</strong> <strong>calculus</strong> as def<strong>in</strong>ed <strong>in</strong>chapter 2. We restate the def<strong>in</strong>ition of the set Ty of type here <strong>for</strong> completeness:Ty ∋ ρ, σ ::= o | ρ → σ.A sequent is a pair Γ ⊢ ρ of the context Γ, which is a multiset of <strong>for</strong>mulae, and the<strong>for</strong>mula ρ. Just as <strong>in</strong> natural deduction, contexts could have been presented as lists,but <strong>in</strong> this case we would have needed the structural rule of exchange to identifysequents differ<strong>in</strong>g <strong>in</strong> the order of their contexts.For convenience we will use Kleene’s version of the sequent <strong>calculus</strong> LJ [58].Def<strong>in</strong>ition 3.1 (LJ).(Var)Γ, ρ ⊢ ρΓ, ρ ⊢ σ(⊢→)Γ ⊢ ρ → σThe axioms and <strong>in</strong>ference rules of LJ are:Γ, ρ → σ ⊢ ρ Γ, ρ → σ, σ ⊢ τ (→⊢)Γ, ρ → σ ⊢ τΓ ⊢ ρΓ, ρ ⊢ σ (Cut)Γ ⊢ σKleene’s version has the advantage, thanks to the <strong>for</strong>mulation of the rule (→⊢)above, to be strictly cumulative, which means that if the sequent Γ ⊢ ρ appears <strong>in</strong>the conclusion of a rule, then Γ is already a sub-multiset of the antecedents of thepremises of the rule (<strong>for</strong> details, the reader may wish to consult the comprehensivetextbook of Helmut Schwichtenberg and Anne S. Troelstra, Basic Proof Theory [88]).To a statement Γ ⊢ ρ we can assign a λ-term t so that t is well-<strong>typed</strong> <strong>in</strong> contextΓ with type ρ, i.e., Γ ⊢ t : ρ (and hence t is a proof <strong>in</strong> natural deduction), <strong>in</strong> thefollow<strong>in</strong>g way:(Var)Γ, x : ρ ⊢ x : ρΓ, x : ρ ⊢ r : σ(⊢→)Γ ⊢ λx ρ .r : ρ → σΓ, y : ρ → σ ⊢ r : ρ Γ, y : ρ → σ, x : σ ⊢ s : τ (→⊢)Γ, y : ρ → σ ⊢ s{ yr /x} : τΓ ⊢ r : ρ Γ, x : ρ ⊢ s : σ (Cut)Γ ⊢ s{ r /x} : σThe notations s{ r /x} and s{ yr /x} <strong>in</strong> the rule (→⊢) and (Cut) are not term<strong>for</strong>mation rules but notations on the meta-level <strong>for</strong> substitution. It is a reason whythe simply <strong>typed</strong> λ-<strong>calculus</strong> cannot be used to faithfully model proofs of the sequent<strong>calculus</strong>.


3.1 From Sequent Calculus to Λ J 59Example 11. Obviously, after hav<strong>in</strong>g decorated a sequent proof with λ-terms, tak<strong>in</strong>gthe last decorated statement <strong>in</strong> the proof provides a derivation <strong>in</strong> natural deduction.But this translation from sequent <strong>calculus</strong> to natural deduction is not one-to-one.The two follow<strong>in</strong>g decorated sequent <strong>calculus</strong> derivations provide the same derivation(where z : ρ → σ ∈ Γ):Γ, x : ρ ⊢ r : σ Γ, x : ρ, y : τ ⊢ s : υΓ, x : ρ ⊢ s{ zr /y} : υΓ ⊢ λx ρ .s{ zr /y} : ρ → υ(→⊢)(⊢→)Γ, x : ρ, y : τ ⊢ s : υΓ ⊢ r : σ Γ, y : τ ⊢ λx ρ .s : υ (⊢→)Γ ⊢ λx ρ (→⊢).s{ zr /y} : ρ → υTo have a faithful notation system <strong>for</strong> the sequent <strong>calculus</strong>, it is possible to workwith explicit substitution. The notation −{ − /x} would then be a term constructor.This approach has been studied by Herbel<strong>in</strong> <strong>in</strong> [50].The idea <strong>in</strong> [55] is that if one excludes the cut-rule, one does not need to considergeneral substitution but only the one occurr<strong>in</strong>g <strong>in</strong> the rule (→⊢): −{ −− /x}. Theterm constructor correspond<strong>in</strong>g to an explicit substitution of this <strong>for</strong>m is called ageneralised application and is noted r(s, x σ .t) <strong>in</strong>stead of t{ rs /x}.Now, <strong>in</strong> the assignment of λ-terms to sequent derivations, one can replace the<strong>standard</strong> application of the λ-<strong>calculus</strong> by this generalised application <strong>in</strong> the rule(→⊢):Γ, y : ρ → σ ⊢ s : ρ Γ, y : ρ → σ, x : σ ⊢ t : τ (→⊢)Γ, y : ρ → σ ⊢ y(s, x σ .t) : τThe cut-rule allows us to substitute the variable y <strong>in</strong> the above rule by an arbitraryterm, giv<strong>in</strong>g rise to the Λ J <strong>calculus</strong>:Λ J ∋ r, s, t ::= x | λx ρ .r | r(s, x σ .t)Hence one can annotate sequents of derivations <strong>in</strong> the sequent <strong>calculus</strong> with termsof the Λ J -<strong>calculus</strong>, just <strong>in</strong> the same way as with terms of Λ. The cut-free derivationscorrespond to terms whose subterms <strong>in</strong> applicative position are assumptions(a variable y):NF ΛJ∋ r, s, t ::= x | λx ρ .r | y(s, x σ .t)This latter terms are normal <strong>for</strong>ms <strong>for</strong> the β and permutative reductions 1 :(λx ρ .r)(s, y σ .t) −→ β t{ r{s /x} /y}r(s, x σ .t)(s ′ , x ′τ .t ′ ) −→ π r(s, x σ .t(s ′ , x ′τ .t ′ ))1 The permutative reductions allows to recover the sub<strong>for</strong>mula property, i.e., the type of anysubterm of a term r of type ρ is either the type of a free variable or a syntactic subtype of ρ.


60 3. Generalized ApplicationsReplac<strong>in</strong>g <strong>in</strong>ductively the explicit substitutions r(s, x σ .t) by actual substitutionst{ rs /x}, provides a translation − Λ from Λ J to Λ. This translation justifies the aboverules as a <strong>standard</strong> β-conversion and a substitution lemma:t{ (λxρ .r)s/y} = β t{ r{s /x} /y}t ′ { (t{rs /x})s ′ /x ′ } = π t ′ { (ts′ ){ rs /x} /x ′ }The terms of Λ J can as well be used to annotate propositions of a natural deductionsystem which provides a syntax-directed typ<strong>in</strong>g system as follows:Def<strong>in</strong>ition 3.2 (Typ<strong>in</strong>g). The typ<strong>in</strong>g relation is a ternary relation between contexts,terms and types and is def<strong>in</strong>ed <strong>in</strong>ductively by the follow<strong>in</strong>g rules:x : ρ ∈ ΓΓ ⊢ x : ρ (Var)Γ ⊢ r : ρ → σ Γ ⊢ s : ρ Γ, x : σ ⊢ t : τΓ ⊢ r(s, x σ .t) : τ(→E)Γ, x : ρ ⊢ r : σΓ ⊢ λx ρ .r : ρ → σ (→I)In the term<strong>in</strong>ology used <strong>for</strong> natural deduction, the rule (→E) is called an elim<strong>in</strong>ationrule, and the rule (→I) an <strong>in</strong>troduction rule. The premiss carry<strong>in</strong>g the symbol → <strong>in</strong>the elim<strong>in</strong>ation rule is called the major premiss, the other premises are called m<strong>in</strong>orpremises. By analogy, we will say that <strong>in</strong> the term r(s, x.t), r is a major premissand s and t are m<strong>in</strong>or premises.Typed terms of Λ J are not <strong>in</strong> a one-to-one correspondence with derivations ofsequent <strong>calculus</strong>, <strong>for</strong> one derivation <strong>in</strong> Λ J there exists several sequent derivationswith cut. In the decoration of the sequent <strong>calculus</strong> proofs, each rule of the sequent<strong>calculus</strong> (except (Cut)) is associated to a different term <strong>for</strong>mation rule of the Λ J -<strong>calculus</strong>. Hence <strong>for</strong> a normal Λ J derivation with respect to −→ β and −→ π reductionsthere exists one and only one cut-free sequent derivation.As <strong>in</strong> the previous chapter we will often omit the type of the bound variables toimprove readability.3.2 Extended Conversions and Normal FormsThere are more <strong>conversions</strong> to be considered than only = β and = π . We have at handa translation − Λ from Λ J to the simply <strong>typed</strong> λ-<strong>calculus</strong> Λ. Because βπ-normal<strong>for</strong>ms of Λ J correspond to only one cut-free sequent derivation whereas β-normal<strong>for</strong>ms of Λ may correspond to several cut-free sequents derivations, one can def<strong>in</strong>ethe miss<strong>in</strong>g <strong>conversions</strong> between terms r and s of Λ J such that the translations of rand s <strong>in</strong> Λ are the same (modulo β-equality).


3.2 Extended Conversions and Normal Forms 61We will give the <strong>conversions</strong> <strong>in</strong> <strong>for</strong>m of axioms; the correspond<strong>in</strong>g <strong>conversions</strong> arethen obta<strong>in</strong>ed as the smallest congruence, a contextually closed equivalence relation,conta<strong>in</strong><strong>in</strong>g the given axiom(s).Def<strong>in</strong>ition 3.3 (Contextual closure).follow<strong>in</strong>g rules holdA relation = R is contextually closed if ther = R r ′r(s, x.t) = R r ′ (s, x.t) (R-AppL1) s = R s ′r(s, x.t) = R r(s ′ , x.t) (R-AppL2)t = R t ′r(s, x.t) = R r(s, x.t ′ ) (R-AppR)r = R sλx.r = R λx.s (R-ξ)We first give the axiom <strong>for</strong> the β-conversion; read from left to right this conversioncorresponds to a computation step of the <strong>calculus</strong>.Def<strong>in</strong>ition 3.4 (β-conversion).The axiom of β-conversion is def<strong>in</strong>ed by:(λx.r)(s, y.t) = β t{ r{s /x} /y} (β)Remark 9. We gloss over the notions of free, bound variables, set of free variableFV(r) of a term r, α-conversion and substitution which are similarly def<strong>in</strong>ed as theywere <strong>in</strong> the simply <strong>typed</strong> λ-<strong>calculus</strong> <strong>in</strong> chapter 2 (the only difference be<strong>in</strong>g that <strong>in</strong>the term r(s, x.t) the variable x is bound <strong>in</strong> t) and just remark that the substitutionused here is a variable capture avoid<strong>in</strong>g one where α-conversion may be needed.The π-conversion permutes general applications if they <strong>for</strong>m a particular pattern(the major premiss of a general application is itself a general application). Butif the π-conversion is read as a substitution lemma <strong>for</strong> the correspond<strong>in</strong>g explicitsubstitution, then <strong>in</strong> the general case one has to pull out a general application <strong>in</strong> anarbitrary context. Hence we def<strong>in</strong>e our general notion of permutative conversion asfollows:Def<strong>in</strong>ition 3.5 (π e -conversion).is def<strong>in</strong>ed by:The axiom of extensional permutative conversionr{ s(t,y.u) /x} = π e s(t, y.r{ u /x}) y ∉ FV(r)Moreover one can def<strong>in</strong>e a conversion between terms of Λ J such that their translations<strong>in</strong> the simply <strong>typed</strong> λ-<strong>calculus</strong> Λ are not only β- but η-equal as well, thisleads to the follow<strong>in</strong>g conversion 2 .2 we rem<strong>in</strong>d the reader that the dot b<strong>in</strong>d as far as syntactically possible to the left, so that theaxiom η has to be read as r = η λz ρ .(r(z, y.y))


62 3. Generalized ApplicationsDef<strong>in</strong>ition 3.6. The axiom of η-conversion is def<strong>in</strong>ed byr = η λz ρ .r(z, y.y) z /∈ FV(r) (η)Remark 10. A characteristic of the Λ J -<strong>calculus</strong> is that we only need to def<strong>in</strong>e η-conversion on variables. An η-conversion of a λ-abstraction can already be achievedwith a β-conversion just as <strong>for</strong> the simply <strong>typed</strong> λ-<strong>calculus</strong>. And an η-conversion ofa generalised application r(s, x.t) boils down modulo permutative conversion (3.5) toan (η)-conversion of its m<strong>in</strong>or premiss s.We can give a local version of the π e -conversion. This will help us to justify thestructure of the term outputted by the NbE-algorithm, the normal <strong>for</strong>ms.Lemma 20 (π e -conversion (local version)). The π e -conversion can be def<strong>in</strong>ed by thefollow<strong>in</strong>g axioms:r(s, x.r ′ )(s ′ , x ′ .t ′ ) = π e1r(s, x.r ′ (s ′ , x ′ .t ′ )) (x ∉ FV(s ′ ), x ∉ FV(t ′ )) (π e 1)r(r ′ (s ′ , x ′ .t ′ ), x.t) = π e2r ′ (s ′ , x ′ .r(t ′ , x.t)) (x ′ ∉ FV(r), x ′ ∉ FV(t)) (π e 2)λx.r(s, y.t) = π e3r(s, y.λx.t) (x ∉ FV(r), x ∉ FV(s)) (π e 3)r(s, x.t) = is t (x ∉ FV(t)) (is)r(s, x.r ′ (s ′ , x ′ .t ′ )) = π e4r ′ (s ′ , x ′ .r(s, x.t ′ )) (x ∉ FV(r ′ ), x ∉ FV(s ′ ),x ′ ∉ FV(r), x ′ ∉ FV(s)) (π e 4)r(s, x.r(s, x ′ .t ′ )) = π e5r(s, x ′ .t ′ { x′ /x}) (x ∉ FV(r), x ∉ FV(s)) (π e 5)The first four <strong>conversions</strong> (π e 1 to π e 4) are just <strong>in</strong>stantiations of the general π e -conversion. Their contextual closure is a special case of the general π e -conversionwhere the substitution <strong>in</strong>volved only concerns one unique variable. The axiom (π e 5)allows to take <strong>in</strong>to account the case when <strong>in</strong> the π e -conversion the substitutionconcerns multiple occurrences of the same variable. The last conversion (is) handlesthe case where the variable to be substituted <strong>for</strong> <strong>in</strong> the general π e -conversion doesnot actually occur <strong>in</strong> the term.We will describe the normal <strong>for</strong>ms of this system by giv<strong>in</strong>g some sensible criteria.First we want our normal <strong>for</strong>ms to correspond to cut-free sequent derivations, so thatthey should at least be some restrictions of the π-normal <strong>for</strong>ms as given <strong>in</strong> section2, i.e., normal <strong>for</strong>ms <strong>for</strong> the β-, π e 1-reduction (oriented from left to right):NF ΛJ ∋ N, N 0 , N 1 ::= x | λx.N | y(N 0 , x.N 1 )The conversion (π e 2), read from left to right, pulls out the application on the righthand side of the term. This is already the effect of the π-reduction, so that we keepthis direction. The normal <strong>for</strong>ms will not be allowed to have an application as the


3.2 Extended Conversions and Normal Forms 63m<strong>in</strong>or premiss s of another application r(s, x.t). To achieve this, we have to redef<strong>in</strong>eour normal <strong>for</strong>ms as follows:PNF ΛJ ∋ P ::= x | λx.N∋ N ::= P | y(P, x.N)NF ΛJThe rule (π e 3) says that a λ-abstraction can be moved <strong>in</strong>side a generalised application.It seems reasonable to move it as deep as possible, <strong>in</strong> order to <strong>in</strong>troducevariables just be<strong>for</strong>e their uses. To that effect, we def<strong>in</strong>e the deepest λ condition,DL(X, r) <strong>for</strong> a set of variables X and a term r, to be true if r is a variable or aλ-abstraction and if r is a generalised application (r(s, y.t)) by the follow<strong>in</strong>g:DL(X, (r(s, y.t))) :⇔ X ∩ (FV(r) ∪ FV(s)) ≠ ∅ ∧ DL(X ∪ {y}, t)We impose the condition DL({x}, N), <strong>in</strong> case of the abstraction λx.N.Immediate SimplificationFor the conversion (is), known as immediate simplification, we follow Prawitz [78]by simplify<strong>in</strong>g unused arguments and impose the condition x ∈ FV(N 1 ) <strong>in</strong> case ofthe application y(N 0 , x.N 1 ).The rule (π e 4) is somewhat problematic because by itself it creates a loop, whateverorientation one chooses <strong>for</strong> it, and we will come back to it later, together withthe last rule (π e 5).Conversion η and Normal FormsIn contrast with the <strong>conversions</strong> β and π e , the η-conversion requires us to considerthe types of the term <strong>in</strong>volved.The rule of η-conversion oriented as an expansion (i.e., from left to right <strong>in</strong> thedef<strong>in</strong>ition above) expands a term of arrow type <strong>in</strong>to a generalised application. Consideredtogether with the β conversion oriented <strong>in</strong> a reduction from left to right, onehas to impose restrictions on η-expansion to prevent <strong>in</strong>f<strong>in</strong>ite sequence of reductions.Namely an η-expansion should not expand a term <strong>in</strong> abstraction <strong>for</strong>m nor the majorpremiss r of a generalised application r(s, x.t).To obta<strong>in</strong> normal <strong>for</strong>ms <strong>for</strong> the η-conversion, it suffices to restrict the <strong>for</strong>mationof pure normal <strong>for</strong>ms <strong>for</strong> variables to those of ground type. Hence a f<strong>in</strong>al step isto <strong>in</strong>corporate typ<strong>in</strong>g <strong>in</strong> our normal <strong>for</strong>ms, they will have to verify the follow<strong>in</strong>gdef<strong>in</strong>ition.


64 3. Generalized ApplicationsDef<strong>in</strong>ition 3.7 (Λ J -normal <strong>for</strong>m). The set NF ΛJ of Λ J -normal <strong>for</strong>ms is def<strong>in</strong>ed<strong>in</strong>ductively together with the set PNF ΛJ of pure normal <strong>for</strong>ms as follows:(x : o) ∈ ΓΓ ⊢ PNF x : oΓ, x : ρ ⊢ NF N : σΓ ⊢ PNF λx.N : ρ → σΓ ⊢ PNF P : ρΓ ⊢ NF P : ρΓ, y : ρ → σ ⊢ PNF P : ρ Γ, y : ρ → σ, x : σ ⊢ NF N : τΓ ⊢ NF y(P, x.N) : τ<strong>in</strong> the clause with conclusion Γ ⊢ PNF λx.P : ρ → σ, we impose the conditionDL({x}, P ) which is true if P is not an generalised elim<strong>in</strong>ation and def<strong>in</strong>ed otherwiseby:DL(X, (r(s, y.t))) :⇔ X ∩ (FV(r) ∪ FV(s)) ≠ ∅ ∧ DL(X ∪ {y}, t)and <strong>in</strong> the clause with conclusion Γ ⊢ NF y(P, x.N) : τ, we have the condition x ∈FV(N).Circular ConversionsLet us come back to the <strong>conversions</strong> (π e 4) and (π e 5).In normal terms as given above, these circular <strong>conversions</strong> concern occurrencesof lists of generalised applications of the <strong>for</strong>m:x 0 (P 0 , y 0 .x 1 (P 1 , y 1 .x 2 (P 2 , y 2 . . .))(where it may be the case that x i = x j and P i = P j ). The conversion (π e 4) identifiesthose such lists where some generalised applications have been permuted, whereas(π e 5) identifies those where some generalised applications have been duplicated.A (decidable) test <strong>for</strong> the conversion (π e 4) and (π e 5) can be done a posteriori onthese normal <strong>for</strong>ms.Notation 13. We will call the <strong>conversions</strong> (π e 4) and (π e 5) circular permutative conversionand write π e c <strong>for</strong> their union.Remark 11 (variations on normal <strong>for</strong>ms). One could further impose conditionson normal <strong>for</strong>ms: If one does not want to allow <strong>for</strong> repetition, i.e., one <strong>for</strong>bidsx i = x j and r i = π e cr j <strong>in</strong> a list of generalised applications, then one has only tocheck <strong>for</strong> permutation of these generalised applications and the class of convertiblenormal <strong>for</strong>ms even becomes f<strong>in</strong>ite. But then a test of <strong>in</strong>equality modulo = π e chas tobe <strong>in</strong>corporated <strong>in</strong> the <strong>for</strong>mulation of normal <strong>for</strong>ms.


3.3 In<strong>for</strong>mal Description 653.3 In<strong>for</strong>mal DescriptionWe use normalization by evaluation as a normaliz<strong>in</strong>g procedure. First we have togive a suitable <strong>in</strong>terpretation. In this <strong>in</strong><strong>for</strong>mal description our <strong>in</strong>terpretation of theΛ J <strong>calculus</strong> is a <strong>standard</strong> set-theoretical one with the ground type <strong>in</strong>terpreted as theset of variables:Def<strong>in</strong>ition 3.8 (Type Interpretation).ρ, by <strong>in</strong>duction on ρ ∈ TyWe def<strong>in</strong>e the <strong>in</strong>terpretation ρ of a typeo ::= Varρ → σ ::= ρ → σ,where ρ → σ is the full function space between the set ρ and σ.The <strong>in</strong>terpretation of types Ty of the <strong>typed</strong> <strong>lambda</strong> <strong>calculus</strong> with generalisedapplication Λ J is then:Ty ::= ⋃ρ.ρ∈TyTo def<strong>in</strong>e the <strong>in</strong>terpretation of terms we need first to def<strong>in</strong>e the auxiliary notionof valuation.Def<strong>in</strong>ition 3.9 (Valuation). Given a context Γ, we def<strong>in</strong>e a valuation on Γ tobe a partial function η : Var → Ty ⊥such that <strong>for</strong> x : ρ ∈ Γ, η(x) is def<strong>in</strong>ed andη(x) ∈ ρ. Given a context Γ, a valuation η on Γ, a variable y ∉ Γ and an elementa ∈ σ, we def<strong>in</strong>e a valuation (η, y ↦→ a) on Γ ∪ {(y : σ)}, called the extension of ηby y ↦→ a by,{a if x = y,(η, y ↦→ a)(x) ::=η(x) otherwise.Remark 12. Valuation functions are partial functions represented as total functionsfrom the set of variables Var <strong>in</strong>to the set Ty ⊥= Ty + {⋆}, i.e., the <strong>in</strong>terpretationof types extended with an element ⋆ play<strong>in</strong>g the rôle of an undef<strong>in</strong>ed value. In thefollow<strong>in</strong>g, whenever we will use a valuation applied to some variable, this variablewill belong to the doma<strong>in</strong> of def<strong>in</strong>ition of the valuation and the result will there<strong>for</strong>ebe def<strong>in</strong>ed. And although, strictly speak<strong>in</strong>g we should do a case dist<strong>in</strong>ction on theresult to know wheither it is def<strong>in</strong>ed (an alternative would be to use an exceptionmonad as presented <strong>in</strong> def<strong>in</strong>ition 1.3), we will consider it to be an element of Ty.The <strong>in</strong>terpretation of a term is an element of the <strong>in</strong>terpretation of its type.


66 3. Generalized ApplicationsDef<strong>in</strong>ition 3.10 (Term Interpretation). We def<strong>in</strong>e the <strong>in</strong>terpretation r η of aterm r, whenever there is a context Γ, such that Γ ⊢ r : ρ and η is a valuation on Γ,to be an element of ρ, by the follow<strong>in</strong>g <strong>in</strong>ductive def<strong>in</strong>ition:x η =η(x)λx.r η (a) =r η,x↦→ar(s, x.t) η =t η,x↦→rη (s η ))In the normalization algorithm exposed below we will regularly use exceptions.While a purely functional semantics of exceptions is used <strong>in</strong> the next section, weprefer to expla<strong>in</strong> them <strong>in</strong><strong>for</strong>mally <strong>in</strong> this section. Let be given a value e of typeE, an exception carry<strong>in</strong>g the exceptional value e can be thrown with the throw(e)operator. Given a handl<strong>in</strong>g function h of type E → T , if an exception is thrownwith throw(e) <strong>in</strong>side a program p of type T , such an exception e can be caught withthe operator catch(p)(h) and evaluated to h(e).3.3.1 Several AttemptsLet us write nf <strong>for</strong> the normaliz<strong>in</strong>g function we will describe. In the chapter onsimply <strong>typed</strong> λ-<strong>calculus</strong>, this function was given by apply<strong>in</strong>g the reify function ↓ tothe <strong>in</strong>terpretation of a term t with the function reflect ↑ as valuation, nf(t) =↓ t ↑ .The pr<strong>in</strong>ciple here is still the same and we will start from the algorithm of thelast chapter and modify it to produce normal terms of Λ J . The only syntactical differencebetween Λ J and Λ is <strong>in</strong> applications, generalised applications <strong>for</strong> the <strong>for</strong>mer,simple applications <strong>for</strong> the latter. The only place where syntactical applicationswere created <strong>in</strong> the NbE algorithm of the last chapter was <strong>in</strong> the def<strong>in</strong>ition of thefunction ↑ at arrow type:(↑ ρ→σ r)(a) ::=↑ σ r(↓ ρ a)Because a generalised application of the <strong>for</strong>m r(s, z.z) translates to a simpleapplication r Λ s Λ , to get a generalised application <strong>in</strong>stead of a simple application, wecould just replace this def<strong>in</strong>ition with the follow<strong>in</strong>g:(↑ ρ→σ r)(a) ::=↑ σ r((↓ ρ a), z.z)However there is a problem with this def<strong>in</strong>ition. Let us call the pair of term(r, s) <strong>in</strong> a generalised application r(s, x.t), a pseudo-application. If we identify λ-terms with programs, the term r can be seen as a subprogram of t with arguments.The system Λ J can be considered as a simple programm<strong>in</strong>g language allow<strong>in</strong>g tofactorise out subprograms occurr<strong>in</strong>g with the same argument, i.e., to move out severaloccurrences of a generalised application (r, s) to a same more external position.


3.3 In<strong>for</strong>mal Description 67Example 12. Consider the term T ::= t{ y /r(s,x.t ′ )}{ y′ /r(s,x.t ′ )} with two subtermr(s, x.t ′ ) and r(s, x.t ′′ ), where all variables of r and s are free <strong>in</strong> T . T can beconverted to T ′ = r(s, x.t{ y /t ′ }{ y′ /t ′′ }).In this latter term the pseudo-application (r, s) has been factorized out to theexterior of the term, and the variable x bound to this pseudo-application is thenused twice.The normalization function should per<strong>for</strong>m this factorisation of pseudo-applications,but it is not the case us<strong>in</strong>g the algorithm of the last chapter modified as above. Toallow the algorithm to deliver factorized terms, we use the follow<strong>in</strong>g idea.When normaliz<strong>in</strong>g a term t, if we know that a pseudo-application (r, s) will actuallyoccur <strong>in</strong> the normalized term, then one can beg<strong>in</strong> by <strong>in</strong>troduc<strong>in</strong>g a generalizedapplication, the normalized function nf would then read:nf(t) = r(s, z. ↓ t ↑ )Of course we have now to modify the function ↑ so that it does not <strong>in</strong>troduce asecond time the pseudo application (r, s). This can be achieved <strong>in</strong> this particularcase by def<strong>in</strong><strong>in</strong>g ↑ to be{(↑ ρ→σ zif t = r and ↓ ρ a = st)(a) ::=↑ σ t((↓ ρ a), z.z) otherwiseTo know if a pseudo-application will actually occur <strong>in</strong> a normalized term, onecan use the NbE algorithm itself. We use environments ɛ associat<strong>in</strong>g a pseudoapplicationsto a variable. This environment ɛ is a partial function. In the environmentɛ, a pseudo application (r, s) can be associated with no variable, <strong>in</strong> this casethe result of the application ɛ(r, s) of the environment to the pseudo-application isundef<strong>in</strong>ed, and is set to the element ⋆. Thus an environment is implemented as atotal function ɛ : Tm × Tm → Var ⊥ where Var ⊥ = Var ∪ {⋆} is the extension of theset Var by the element ⋆.F<strong>in</strong>ally, we modify once aga<strong>in</strong> the function ↑ ρ→σ t so that applied to a value a, itcont<strong>in</strong>ues the computation if the pseudo-application (t, ↓ a) is <strong>in</strong> the environment,or else <strong>in</strong>terrupt the computation and return this pseudo-application as exception.Thus a first run of the NbE-algorithm <strong>in</strong> an empty environment may return a pseudoapplication as exception, <strong>in</strong> this case we run the NbE-algorithm anew <strong>in</strong> an updatedenvironment where the pseudo-application got <strong>in</strong> the first run is associated to a newvariable. This has to be repeated until no more exceptions are thrown, i.e., until anormal <strong>for</strong>m is produced.Hence the f<strong>in</strong>al def<strong>in</strong>ition of the function ↑ at arrow type is as follows:{(↑ ρ→σ zif ɛ(t, ↓ ρ a) = zt)(a) ::=throw(t, ↓ ρ a) if ɛ(t, ↓ ρ a) = ⊥


68 3. Generalized ApplicationsRemark 13. As one needs to run the NbE algorithm <strong>for</strong> each creation of a pseudoapplication,the implementation is particularly <strong>in</strong>efficient. One could easily optimizeit, <strong>for</strong> example one could use cont<strong>in</strong>uations which would reta<strong>in</strong> the computation doneso far and avoid to do the same computation several times. The advantage of thisuse of exceptions is that it provides a simpler framework to reason about the program.Transpos<strong>in</strong>g a reason<strong>in</strong>g done <strong>for</strong> a simple program to its optimized version shouldbe simpler than carry<strong>in</strong>g it out directly <strong>for</strong> the optimized program.3.3.2 The B<strong>in</strong>d<strong>in</strong>g Variable ProblemThe problem is just a bit more complicated than expla<strong>in</strong>ed above because the NbEalgorithm can generate subterms with new bound variables as <strong>in</strong> the def<strong>in</strong>ition of ↓at arrow type:↓ ρ→σ f ::= λx. ↓ f ↑ x(x new)If we only catch exceptions at the top-level, we would then possibly catch apseudo-application with a variable which is not yet bound.To prevent this situation, we will catch exceptions as soon as new variables are<strong>in</strong>troduced, i.e., just after a λ. This will allow us to compare the free variables ofthe pseudo-application thrown as exception and the variable bound at this λ. Ifthe bound variable does not occur free <strong>in</strong> the pseudo-application, then this pseudoapplicationis thrown further, otherwise a generalized application is created at thispo<strong>in</strong>t.We are now <strong>in</strong> position to write a first version of our algorithm. Similarly to thecase of the simply <strong>typed</strong> λ-<strong>calculus</strong>, it is possible to restrict both the doma<strong>in</strong> of thefunction ↑ and the codoma<strong>in</strong> of the function ↑ to respectively variables and purenormal <strong>for</strong>ms.We shall <strong>in</strong>troduce the function doAGA? which produces normal <strong>for</strong>ms from purenormal <strong>for</strong>ms, and f<strong>in</strong>ally observe that the doma<strong>in</strong> of the environments can be restrictedto those pseudo-applications whose first component is a variables and secondcomponent a pure normal <strong>for</strong>m.


3.4 Formalization 69Code 5 (↑ and ↓). Let ɛ 0 ∈ Var × PNF → Var ⊥ be an environment. The reifyfunction ↓ ρ : (Var × PNF → Var ⊥ ) → ρ → PNF and reflect function ↑ ρ : (Var ×PNF → Var ⊥ ) → Var → ρ are def<strong>in</strong>ed simultaneously by <strong>in</strong>duction on the type ρ:↑ ρ→σɛ 0↓ o ɛ 0x ::=x↓ ρ→σɛ 0f ::=λx.doAGA? ((ɛ. ↓ σ ɛ f(↑ ρ ɛ x)), {x}) ɛ 0 x new↑ o ɛ 0x ::=xx(a) ::=let P :=↓ ρ ɛ 0a <strong>in</strong>catch(↑ σ ɛ 0ɛ 0 (x, P ))(⊥.throw(x, P ))together with the function doAGA? : ((Var × PNF → Var ⊥ ) → PNF) × P(Var) →(Var × PNF → Var ⊥ ) → NF which <strong>in</strong>serts generalized application when needed:doAGA? (f, X)ɛ 0 ::= catch(fɛ 0 ){throw(x, P )(x, P ).(x,Px(P, y.doAGA?(f, ({y} ∪ X))(ɛ )↦→y 0 ))if x ∉ X and X ∩ FV(P ) = ∅otherwiseThe auxiliary function doAGA? (<strong>for</strong> ”do A Generalized Application”) <strong>in</strong>troduces generalizedapplications as soon as the bound variables of a pseudo-application arebound.The normalization function <strong>for</strong> a term r is obta<strong>in</strong>ed by apply<strong>in</strong>g the functiondoAGA? to ɛ ↓ ɛ ρ r ↑ɛand all free variables of r <strong>in</strong> the empty environment (i.e., theenvironment everywhere undef<strong>in</strong>ed t.⊥).Def<strong>in</strong>ition 3.11 (normalization function).nf : Tm → Tm by :We def<strong>in</strong>e the normalization functionnf(t) = doAGA?(ɛ ↓ ɛ ρ r ↑ɛ, FV(t))(t.⊥)3.4 FormalizationWe now precisely def<strong>in</strong>e the notions we have let <strong>in</strong><strong>for</strong>mal <strong>in</strong> the previous sections:the environment needed to generate new names, the environment associat<strong>in</strong>gpseudo-applications to variables and the handl<strong>in</strong>g of exceptions conta<strong>in</strong><strong>in</strong>g pseudoapplications.To be correctly threaded through the NbE-algorithm both of theseenvironments and the exceptions have to be <strong>in</strong>corporated <strong>in</strong> the <strong>in</strong>terpretation. Tocapture this notion <strong>in</strong> pure functional sett<strong>in</strong>gs, we will use a comb<strong>in</strong>ation of monads(a reader monad <strong>for</strong> each environment, and an exception or error monad <strong>for</strong>exceptions).


70 3. Generalized ApplicationsName Generation EnvironmentThe name generation is dealt with as <strong>in</strong> the first chapter by def<strong>in</strong><strong>in</strong>g a name generationenvironment. We restate the def<strong>in</strong>ition here.Def<strong>in</strong>ition 3.12 (Name Generation Environment). We def<strong>in</strong>e a set of name generationenvironment or set of environment <strong>for</strong> short, as a set E together with anupdate function (−) − : E → Var → E and an access function new : E → Var. Theextension of e − : V → E to a function from a list of variables e − : L(V ) → E isdef<strong>in</strong>ed <strong>in</strong> a ca<strong>non</strong>ical way bye x,−→x ::= (e x ) −→ xe ε ::= e.The function (−) − and new have moreover to satisfy the follow<strong>in</strong>g property <strong>for</strong> alle ∈ E:∀ −→ x , x ≠ new(e x,−→x ) (†)Notation 14. The condition that the new function applied to an environment e ∈ Eshould never return a given variable x can be expressed by:∀ −→ x , x ≠ new(e −→x )We will abbreviate this condition by x ∉ e. In the same way we will abbreviate <strong>for</strong>a given set of variable X, ∀ x ∈ X, x ∉ e by X ∉ e.Postdiction EnvironmentWe call the environment associat<strong>in</strong>g a pseudo-application to a variable a postdictionenvironment because on the one hand, this environment can be seen as an oracle predict<strong>in</strong>g<strong>in</strong> a run of the NbE algorithm with which variables a pseudo-application hasto be replaced, but on the other hand these predictions are obta<strong>in</strong>ed from previousruns of the NbE-algorithms.Def<strong>in</strong>ition 3.13 (Postdiction Environment). We def<strong>in</strong>e the postdiction environmentP as the set Var × PNF → Var ⊥ together with an update function(−) − : P → ((Var × PNF) × Var) → P def<strong>in</strong>ed by:{ɛ (x,P )↦→y (x ′ , P ′ y if x = x ′ and P = π e) ::=cP ′ɛ(x ′ P ′ ), otherwise


3.4 Formalization 71Interpretation MonadWe will now def<strong>in</strong>e the monad used <strong>in</strong> the <strong>in</strong>terpretation, a computation should takeplace <strong>in</strong> a name environment E and a postdiction environment P(= (Var × PNF) →Var ⊥ ), and it can be aborted by rais<strong>in</strong>g an exception conta<strong>in</strong><strong>in</strong>g a pair of a variableand a pure normal <strong>for</strong>m. Hence the specification of a computation with result with<strong>in</strong>a set A is:TA ::= St E (St P (A ⊥(Var×PNF) )) = E → ((Var × PNF) → Var ⊥ ) → (Var × PNF + A)The unit and multiplication of the monad of the <strong>in</strong>terpretation are def<strong>in</strong>ed quitenaturally from the def<strong>in</strong>ition of the unit and multiplication of its monad components.Def<strong>in</strong>ition 3.14 (Interpretation monad T ::= St E ◦St P ◦− ⊥(Ne) ).of) the <strong>in</strong>terpretation monad T is def<strong>in</strong>ed byThe (set operatorTA ::= St E (St P (A ⊥(Ne) )) (= E → (Ne → Var ⊥ ) → Ne + A)Given m ∈ TA and f ∈ A → TB, we def<strong>in</strong>e the unit ν : A → TA and multiplication⋆ : TA → (A → TB) → TB of the <strong>in</strong>terpretation monad by:ν TA ::= ν St E◦ ν St P◦ ν A ⊥(Ne)(m ⋆ T f)(e)(ɛ) ::= m(e)(ɛ) ⋆ − ⊥(E)λa.f(a)(e)(ɛ)The update operations <strong>for</strong> the name environment monad and the postdictionmonad extend component-wise to the <strong>in</strong>terpretation monad.Def<strong>in</strong>ition 3.15 (update <strong>for</strong> the Name Generation Monad). We def<strong>in</strong>e an updatefunction (−) − : T(A) → Var → T(A) operation by extend<strong>in</strong>g the update operation<strong>for</strong> the name generation monad by:m v (e) ::= m(e v )Def<strong>in</strong>ition 3.16 (update <strong>for</strong> the Postdiction Monad). We def<strong>in</strong>e an update function(−) − : St P(A) → (Ne × Var) → St P(A) operation by extend<strong>in</strong>g the update operation<strong>for</strong> postdiction environment by:m (x,P )↦→y (ɛ) ::= m(ɛ (x,P )↦→y )This update operation extends <strong>in</strong> turn <strong>in</strong>to an operation (−) − : TA → (Ne × Var) →TA to the <strong>in</strong>terpretation monad just <strong>in</strong> the same way by:m (x,P )↦→y (e)(ɛ) ::= m(e)(ɛ (x,P )↦→y )


72 3. Generalized ApplicationsT:The <strong>in</strong>terpretation is a call by value <strong>in</strong>terpretation <strong>for</strong> computations <strong>in</strong> the monadDef<strong>in</strong>ition 3.17 (<strong>in</strong>terpretation). The call-by-value <strong>in</strong>terpretation of the Λ J -<strong>calculus</strong> is given on types byo ::= Varτ 1 → τ 2 ::= ρ → T(σ)Given a valuation η on a context Γ (η Γ), the <strong>in</strong>terpretation of a <strong>typed</strong> termΓ ⊢ t : τ is the monadic value t η ∈ T(τ) def<strong>in</strong>ed by:x η::= ν(η(x))r(s, x.t) η::= r η⋆ f.s η⋆ a.fa ⋆ v.t η,x↦→vλx.r η::= ν(a.r η,x↦→a)Code 6 (call-by-value NbE).are def<strong>in</strong>ed simultaneously by:The function ↓ τ : τ → T(PNF τ ) and ↑ τ : Var τ → τ↓ o x ::= ν(x)↓ ρ→σ f ::= new ⋆ x.doAGA?(f(↑ ρ x)⋆ ↓ σ , {x}) x ⋆ e.ν(λx.e)↑ o x ::= x↑ ρ→σ x(a) ::= k ɛ.(↓ ρ a)kɛ ⋆ P.{throw(x, P )if ɛ(x, P ) = ⊥(↑ σ y)ɛ if ɛ(x, P ) = ywhere the auxiliary function doAGA? : T(PNF) → P(Var) → T(NF) is def<strong>in</strong>ed bydoAGA?(f, X) ::= catchf(x, P ). if ({x} ∪ FV(P )) ∩ X = ∅ then throw(x, P )else new ⋆ y.doAGA?(f x,P ↦→y , X ∪ {y}) y ⋆ t.if y ∉ FV(t)then ν(t)else ν(x(p, y.t))The normalization function is obta<strong>in</strong>ed by apply<strong>in</strong>g the function doAGA? tor ↑ ⋆ ↓ τ <strong>in</strong> an <strong>in</strong>itial name environment e r conta<strong>in</strong><strong>in</strong>g the variables free <strong>in</strong> r, and anempty postdiction environment (i.e., the function everywhere undef<strong>in</strong>ed n.⊥)Code 7. Given a <strong>typed</strong> term Γ ⊢ r : τ, the normalization of the term r is given by:nf τ (r) ::= doAGA?(r ↑ ⋆ ↓ τ , e r )(n.⊥)


3.4 Formalization 73The claims of this section state the correctness and completeness of the algorithm(6) above.Claim 1 (Correctness).r = βη nf(r)Claim 2 (Completeness).r = βη s =⇒ nf(r) = cc nf(s)The results <strong>in</strong> the previous chapter (2) were developed to be a basis to provethese results. A first exploration lead us to use logical monadic relations whosemonadic part itself is def<strong>in</strong>ed <strong>in</strong>ductively. This monadic part has to encompass thenotion of fresh variables, as <strong>in</strong> the previous chapter, but also the notion of attemptsneeded to run the NbE until no exceptions are raised (the base case correspond<strong>in</strong>gto a monadic value return<strong>in</strong>g directly a value, and the step case correspond<strong>in</strong>g to amonadic value return<strong>in</strong>g an exception.) For time reason, we have let a <strong>for</strong>mal study<strong>for</strong> further research. The conceptual simplicity of the approach us<strong>in</strong>g exceptionsallowed us to implement the NbE algorithm <strong>in</strong> the pure functional language Haskellwithout us<strong>in</strong>g any primitive operators and we are confident that proofs of the claims(3) and (4) above will <strong>for</strong> the same reason be feasible.


74 3. Generalized Applications


Chapter 4SumsThis section is dedicated to the study of the extension of the simply <strong>typed</strong> λ-<strong>calculus</strong>by sum types and to the design of a decision algorithm <strong>for</strong> its theory.Although the extension itself is seem<strong>in</strong>gly simple (after all we are only add<strong>in</strong>g thepossibility to do case analysis <strong>in</strong>to the system), the study of its theory is extremelycomplex. For a general <strong>in</strong>troduction of the difficulties encountered, the reader mayconsult [39]. These difficulties depend on which k<strong>in</strong>d of rules one wants to addbesides β-reduction. For the extension by permutative conversion, the system isproved strongly normaliz<strong>in</strong>g <strong>in</strong> [38] by a CPS-translation, <strong>in</strong> [75] by a variant of thereducibility candidate method, and <strong>in</strong> [55] by an orig<strong>in</strong>al syntax directed characterisationof the strong normalizable terms. For the extension to a full extensionalsystem, the permutation of <strong>in</strong>dependent case expressions prevents the design of areasonable system with the confluence and strong normalization property. Nevertheless,Neil Ghani proposes a proof of decidability entirely based on rewrit<strong>in</strong>g theory[45].Another way, is to use normalization by evaluation. The first algorithm of normalizationby evaluation <strong>for</strong> a system with sum types is given by Olivier Danvy <strong>in</strong>[37], us<strong>in</strong>g cont<strong>in</strong>uation and control operators. Andrzej Fil<strong>in</strong>ski presents an algorithm<strong>in</strong> [43], as well based on cont<strong>in</strong>uations and control operators, but <strong>in</strong> a monadicsett<strong>in</strong>g, which is of particular <strong>in</strong>terest to us.In [4], Thorsten Altenkirch, Peter Dybjer, Mart<strong>in</strong> Hofmann and Phil Scott proveconstructively the existence of an NbE algorithm, able to decide the whole extensionaltheory of a simply <strong>typed</strong> <strong>lambda</strong> extended with sum types, and hence a directprogram extraction from a <strong>for</strong>malisation of the proof should provide the algorithm.An algorithm <strong>for</strong> an extension by a Boolean type together with the proof of itscorrectness and completeness is given <strong>in</strong> [5]. The challenge to give a practical NbEalgorithm <strong>for</strong> a system with general sum types, and <strong>for</strong> a conversion stronger thanmerely beta was first taken on by V<strong>in</strong>cent Balat and Olivier Danvy <strong>in</strong> [11]. Thisapproach us<strong>in</strong>g cont<strong>in</strong>uations and control operators is then further pursued by V<strong>in</strong>centBalat <strong>in</strong> [9] and his coauthors Roberto Di Cosmo, and Marcelo Fiore <strong>in</strong> [10]. In


76 4. Sumsthese latter works, the algorithm is optimized and the set of normal <strong>for</strong>ms result<strong>in</strong>gfrom the algorithm is further constra<strong>in</strong>ed, and this allows to design an algorithm <strong>for</strong>the whole extensional conversion of the <strong>calculus</strong>.Our work is based both on the approach developed by Altenkrich and his coauthorsand Balat and his coauthors, we will present an algorithm based on normalizationby evaluation <strong>for</strong> the normalization of terms <strong>in</strong> a system with sum types andextensional <strong>conversions</strong>. However, our algorithm is based on the notion of exceptions,which we consider as a much simpler framework than cont<strong>in</strong>uations (exceptions canbe seen as trivial cont<strong>in</strong>uations).Moreover we do not use any control operators or imperative effects such as assignment.Although <strong>for</strong> the commodity of a first exposition we will use a pseudoprogramm<strong>in</strong>g language where exceptions are a built-<strong>in</strong> feature, we will eventuallygive the algorithm <strong>in</strong> a pure functional style, i.e., <strong>in</strong> a monadic sett<strong>in</strong>g <strong>in</strong> the cont<strong>in</strong>uationof Fil<strong>in</strong>ski [43], but <strong>for</strong> a stronger conversion relation.4.1 SystemIn this first section we present the system Λ + , which is an extension of the simply<strong>typed</strong> λ-<strong>calculus</strong>, Λ, by sum type. A sum type of two types ρ and σ will be <strong>in</strong>terpretedas a disjo<strong>in</strong>t union of the <strong>in</strong>terpretations of ρ and σ. We do not considerproduct type, which could be <strong>in</strong>terpreted as a cartesian product, because on the onehand, the essential difficulties are related to sum types and product types wouldnot <strong>in</strong>troduce much more, and on the other hand a presentation <strong>in</strong>clud<strong>in</strong>g productswould be heavier.Types and termsThe sum type constructor collates two types <strong>in</strong> a new one.Def<strong>in</strong>ition 4.1 (Types).Given a base type oTy ∋ ρ, σ ::= o | ρ → σ | ρ + σThe sum type comes equipped with two dist<strong>in</strong>ct <strong>in</strong>jection constants and a caseanalysis operator. A simple example is the type of Boolean, which can be seen asa sum type of two copies of the unit type. In this case, an <strong>in</strong>jection from the unittype can be seen as a constant, either true or false. The case analysis operator wouldthen be simply an if operator. In general, the sum type is built from two types withmore than one <strong>in</strong>habitant, the particular <strong>in</strong>habitant is then relevant and the caseanalysis operator <strong>in</strong>troduces a b<strong>in</strong>d<strong>in</strong>g <strong>in</strong> each branch which allows to use it.


4.1 System 77Def<strong>in</strong>ition 4.2 (Terms). Given a countable <strong>in</strong>f<strong>in</strong>ite set of terms variables Var, theset of terms Tm of the simply <strong>typed</strong> λ-<strong>calculus</strong> with sum type is def<strong>in</strong>ed <strong>in</strong>ductivelyby:Tm ∋ r, s, t ::= x | λx ρ .r | rs | <strong>in</strong> i r | case(r, x ρ .s, y σ .t)where x ∈ VarRemark and notation 2. We have chosen to express our system <strong>in</strong> Church style,which means that types of bound variables are explicitly given at the b<strong>in</strong>d<strong>in</strong>g symbol.The dot after a variable <strong>in</strong> a branch of a case term b<strong>in</strong>ds the variable <strong>in</strong> the branch,hence this variable is written with its type. However, <strong>for</strong> readability, we will allowus to omit these types when they are clear from the context.Notation 15. Because a term conta<strong>in</strong><strong>in</strong>g case symbol case ( can become ) very large, wex · s,will use sometimes an alternative vertical notation case r, <strong>for</strong> case(r, x.s, y.t).y · tTyp<strong>in</strong>gThe extension of the typ<strong>in</strong>g system from the Λ-<strong>calculus</strong> to the Λ + is def<strong>in</strong>ed asfollows:Def<strong>in</strong>ition 4.3 (Typ<strong>in</strong>g). The typ<strong>in</strong>g relation is a ternary relation between contexts,terms and types and is def<strong>in</strong>ed <strong>in</strong>ductively by(x : ρ) ∈ ΓΓ ⊢ x : ρ(Var)Γ, x : ρ ⊢ r : σΓ ⊢ λx ρ .r : ρ → σ (→I) Γ ⊢ r : ρ → σ Γ ⊢ s : ρΓ ⊢ rs : σ(→E)Γ ⊢ r : ρ iΓ ⊢ <strong>in</strong> i r : ρ 0 + ρ 1(+I)Γ ⊢ r : ρ 0 + ρ 1 Γ, x 0 : ρ 0 ⊢ s 0 : σ Γ, x 1 : ρ 1 ⊢ s 1 : σΓ ⊢ case(r, x ρ 00 .s 0 , x ρ 11 .s 1 ) : σ(+E)In the term<strong>in</strong>ology of natural deduction, the typ<strong>in</strong>g rules are separated <strong>in</strong>to twoclasses: those where a type constructor (here → or +) appears <strong>in</strong> a premise arecalled elim<strong>in</strong>ation rules, whereas the ones where the type constructor appears <strong>in</strong> theconclusion are called <strong>in</strong>troduction rules. The premiss of an elim<strong>in</strong>ation rule carry<strong>in</strong>gthe elim<strong>in</strong>ated type constructor is called a major premiss, and the others are calledm<strong>in</strong>or premises.


78 4. SumsConversionsWe will def<strong>in</strong>e the theory of the Λ + -<strong>calculus</strong>, as a list of axioms. The actual <strong>conversions</strong>are obta<strong>in</strong>ed from these axioms as the smallest congruence relation on the termstructure conta<strong>in</strong><strong>in</strong>g these axioms, i.e., a relation which is an equivalence relationand closed under term <strong>for</strong>mation rules.We beg<strong>in</strong> by def<strong>in</strong><strong>in</strong>g what is the contextual closure of an arbitrary relation <strong>in</strong>the Λ + -<strong>calculus</strong>. The name of the conversion R <strong>in</strong> the def<strong>in</strong>ition below can be <strong>for</strong>example β, η, π or a comb<strong>in</strong>ation of those.Def<strong>in</strong>ition 4.4 (Contextual closure).follow<strong>in</strong>g rules hold.A relation = R is contextually closed if ther = R srt = R st (R-AppL)r = R str = R ts (R-AppR)r = R sλx.r = R λx.s (R-ξ)r = R s<strong>in</strong> 0 r = R <strong>in</strong> 0 s (R-Inj0)r = R s<strong>in</strong> 1 r = R <strong>in</strong> 1 s (R-Inj1)r = R scase(r, x ρ 00 .s 0 , x ρ 11 .s 1 ) = R case(s, x ρ 00 .s 0 , x ρ 11 .s 1 ) (R-Case1)s 0 = R s ′ 0case(r, x ρ 00 .s 0 , x ρ 11 .s 1 ) = R case(r, x ρ 00 .s ′ 0, x ρ 11 .s 1 ) (R-Case2)s 1 = R s ′ 1case(r, x ρ 00 .s 0 , x ρ 11 .s 1 ) = R case(r, x ρ 00 .s 0 , x ρ 11 .s ′ 1) (R-Case3)The axioms <strong>for</strong> β-<strong>conversions</strong> are def<strong>in</strong>ed as usual.Def<strong>in</strong>ition 4.5 (β-conversion).The axioms of the β-conversion are given by:(λx.r)s = β r{ s /x} (β → )case(<strong>in</strong> i r, x 0 .s 0 , x 1 .s 1 ) = β s i { r /x i } (β + )As mentioned <strong>in</strong> the <strong>in</strong>troduction, the theory augmented by permutative conversionhas already been studied by several authors. This theory allows to identify moreterms than the β-conversion alone and is useful <strong>in</strong> a natural deduction <strong>for</strong>mulationof logic with disjunction because they allow to recover a variant of the sub<strong>for</strong>mulaproperty (see [88] or [48] <strong>for</strong> details).


4.1 System 79Def<strong>in</strong>ition 4.6 (π-conversion).given by( )(xcase(case r, 0 · s 0 ,, yx 1 · s 0 .t 0 , y 1 .t 1 ) = π case r,1The axioms of the permutative conversion arex 0 · case(s 0 , y 0 .t 0 , y 1 .t 1 ),x 1 · case(s 1 , y 0 .t 0 , y 1 .t 1 ))(π 1 )case(r, x 0 .s 0 , x 1 .s 1 )t = π case(r, x 0 .s 0 t, x 1 .s 1 t) (π 2 )where <strong>in</strong> the axiom π 2 , neither x 0 nor x 1 occurs free <strong>in</strong> t.Consider<strong>in</strong>g the type derivations as natural deduction proofs, a permutative conversionpermutes an elim<strong>in</strong>ation rule <strong>in</strong> a major premiss of an elim<strong>in</strong>ation rule upwardover the m<strong>in</strong>or premiss. For example, the second rule above reads with <strong>typed</strong>erivation as follows (with neither x 0 nor x 1 occurr<strong>in</strong>g free <strong>in</strong> t):Γ ⊢ r : ρ 0 + ρ 1 Γ, x 0 : ρ 0 ⊢ s 0 : σ → τ Γ, x 1 : ρ 1 ⊢ s 1 : σ → τΓ ⊢ case(r, x ρ 00 .s 0 , x ρ 11 .s 1 ) : σ → τΓ ⊢ case(r, x ρ 00 .s 0 , x ρ 11 .s 1 )t : τ(+-E)Γ ⊢ t : σ(→-E)= πΓ, x 0 : ρ 0 ⊢ s 0 : σ → τ Γ, x 0 : ρ 0 ⊢ t : σΓ ⊢ r : ρ 0 + ρ 1 Γ, x 0 : ρ 0 ⊢ s 0 t : τΓ ⊢ case(r, x ρ 00 .s 0 t, x ρ 11 .s 1 t) : τΓ, x 1 : ρ 1 ⊢ s 1 : σ → τ Γ, x 1 : ρ 1 ⊢ t : σΓ, x 1 : ρ 1 ⊢ s 1 t : τTo sum up, given a term r, the π-conversion pulls out to the exterior of the terma test term s of a case-subterm case(s, x.t, y.u) only if it occurs <strong>in</strong> certa<strong>in</strong> position ofthe term r. This occurrence conditions of the case-subterm can be relaxed, lead<strong>in</strong>gto the generalisation π e below of the π conversion. We will call the π e the extensionalpermutative conversion, because together with the η-conversion, it providesan extensional conversion relation.The axiom of the extensional permutative con-Def<strong>in</strong>ition 4.7 (π e -conversion).version is given by:r{ case(s,y 0.t 0 ,y 1 .t 1) /x} = π e case(s, y 0 .r{ t 0 /x}, y 1 .r{ t 1 /x}) (π)where neither y 0 nor y 1 occurs free <strong>in</strong> r.Remark 14. We use a capture avoid<strong>in</strong>g substitution <strong>in</strong> the def<strong>in</strong>ition of the π e -conversion <strong>for</strong> sum type above so that the free variables of s can not be bound <strong>in</strong>r.We def<strong>in</strong>e now the η-<strong>conversions</strong>.


80 4. SumsDef<strong>in</strong>ition 4.8 (η-conversion).η + are given byThe axioms of η-conversion, the axioms η → andr = η→ λx.rx (η → )r = η+ case(r, x 0 .<strong>in</strong> 0 x 0 , x 1 .<strong>in</strong> 1 x 1 ) (η + )where <strong>in</strong> the axiom η → , x does not occur free <strong>in</strong> r.The η + -conversion is the analogue of the η → -conversion <strong>for</strong> sum types. It takes anarbitrary terms of sum types and converts it to a term <strong>in</strong>volv<strong>in</strong>g the term constructor<strong>for</strong> sum type, i.e., <strong>in</strong>jections.Remark 15. A difference with the Λ J -system is that it is possible to present the η + -and π-conversion <strong>in</strong> a unique rule:r{ s /x} = ηπ case(s, x.r{ <strong>in</strong> 0 x/x}, x.r{ <strong>in</strong> 1 x/x})In this case, we have to make sure that <strong>in</strong> the typ<strong>in</strong>g derivation of r{ s /x}, the terms is <strong>typed</strong> with a sum type <strong>for</strong> the right hand side to be well-<strong>typed</strong>. To the contrary,check<strong>in</strong>g the applicability of the π e -conversion is syntactical 1 .The existence of a strongly normaliz<strong>in</strong>g and confluent rewrit<strong>in</strong>g system generat<strong>in</strong>gthis theory is <strong>in</strong> fact very unlikely (the only work based on rewrit<strong>in</strong>g theory todecide this theory [45] does not devise a strongly normaliz<strong>in</strong>g system). It is probably<strong>for</strong> this reason that until very recently, the scientific community has only focused onsome sub-<strong>conversions</strong> of the whole theory.4.2 Extended Conversion and Normal FormsIn the def<strong>in</strong>ition of the π e -conversion above, because of the substitution <strong>in</strong>volvedthere, we have to consider the term at an arbitrary depth. We give here a localdecomposition of this conversion. Apart from the fact that it is always <strong>in</strong>terest<strong>in</strong>gto give a local characterisation of a global phenomena, this decomposition will helpus to expla<strong>in</strong> difficulties <strong>in</strong>herent to the extensional <strong>calculus</strong> with sum types and tojustify the normal <strong>for</strong>m of the term as computed by the NbE algorithm.1 Only <strong>in</strong> the case the variable x does not actually occurs <strong>in</strong> the term r of the left hand side ofthe π e -conversion rule above, we have to check that the term case(s, y 0 .t 0 , y 1 .t 1 ) to be substituted<strong>for</strong> is typable.


4.2 Extended Conversion and Normal Forms 81Lemma 21 (π e -conversion (local version)). The extensional permutative conversioncan be def<strong>in</strong>ed by the follow<strong>in</strong>g axioms( ( ) ) ()xcase case r, 0 · s 0 , y, 0 · t 0 ,x=x 1 · s 1 y 1 · t π e1case r, 0 · case(s 0 , y 0 .t 0 , y 1 .t 1 ),1 x 1 · case(s 1 , y 0 .t 0 , y 1 .t 1 )where x 0 , x 1 ∉ FV(t 0 , t 1 )case(r, x 0 .s 0 , x 1 .s 1 )t = π e2case(r, x 0 .s 0 t, x 1 .s 1 t)where (x 0 , x 1 ∉ FV(t))t case(r, x 0 .s 0 , x 1 .s 1 ) = π e3case(r, x 0 .t s 0 , x 1 .t s 1 )<strong>in</strong> i case(r, x 0 .s 0 , x 1 .s 1 ) = π e4case(r, x 0 .<strong>in</strong> i s 0 , x 1 .<strong>in</strong> i s 1 )λx.case(r, x 0 .s 0 , x 1 .s 1 ) = π e5case(r, x 0 .λx.s 0 , x 1 .λx.s 1 )where x ∉ FV(r)(ycase(r, x 0 .case(s, y 0 .t 0 , y 1 .t 1 ), x 1 .u) = π e6case s, 0 · case(r, x 0 .t 0 , x 1 .u),y 1 · case(r, x 0 .t 1 , x 1 .u)where y 0 , y 1 ∉ FV(u), x 0 ∉ FV(s)()ycase(r, x 0 .u, x 1 .case(s, y 0 .t 0 , y 1 .t 1 )) = π e7case s, 0 · case(r, x 0 .u, x 1 .t 0 ),y 1 · case(r, x 0 .u, x 1 .t 1 )where y 0 , y 1 ∉ FV(u), x 1 ∉ FV(t)case(r, x 0 .case(r, x 0 .s 0 , x 1 .s 1 ), x 1 .t) = π e8case(r, x 0 .s 0 , x 1 .t)case(r, x 0 .s, x 1 .case(r, x 0 .t 0 , x 1 .t 1 )) = π e9case(r, x 0 .s, x 1 .t 1 )r = is case(s, x 0 .r, x 1 .r)where x i ∉ FV(r)The seven first <strong>conversions</strong> (π e 1 to π e 7) above are just <strong>in</strong>stantiation of the generalπ-conversion. The structural closure of these rule generates the general π e -conversionwhere substitution is restricted to one occurrence of a variable. The conversion π e 8and π e 9 handles the case of multiple occurrences whereas the conversion is handlesthe case of zero occurrence.We will follow the scheme of the last chapter and describe progressively thenormal <strong>for</strong>ms of our system, i.e., we will give some sensible criteria based on thelocal def<strong>in</strong>ition of the π e -conversion. Whereas the NbE algorithm is not based onrewrit<strong>in</strong>g theory, these normal <strong>for</strong>ms can be understood, up to a certa<strong>in</strong> stage, asthe irreducible terms of a rewrit<strong>in</strong>g system obta<strong>in</strong>ed by orient<strong>in</strong>g the <strong>conversions</strong>above.The normal <strong>for</strong>ms that we will eventually present are essentially the same as <strong>in</strong>the works [9] of Balat and [4] of Altenkirch, Dybjer, Hofmann and Scott. In [4] anormal <strong>for</strong>m is not merely a term but a set of terms where terms that are convertiblewith the <strong>conversions</strong> that create circularity are identified. Although, this shortensthe presentation we prefer to stick to a more syntactical presentation of normal <strong>for</strong>ms)


82 4. Sumsas <strong>in</strong> [9].First we want our normal <strong>for</strong>ms to be a restriction of the exist<strong>in</strong>g normal <strong>for</strong>ms<strong>for</strong> the traditional permutative conversion (given as π <strong>in</strong> the system section or π1eand π2 e <strong>in</strong> the alternative def<strong>in</strong>ition of π e -conversion above) <strong>in</strong> order to reta<strong>in</strong> thesub<strong>for</strong>mula property. The set of normal <strong>for</strong>ms NF Λ+ <strong>for</strong> permutative <strong>conversions</strong> πand β-<strong>conversions</strong> are def<strong>in</strong>ed <strong>in</strong>ductively together with a set of neutral terms Ne Λ+as follows:Ne Λ+ ∋ n ::= x | nNNF Λ+ ∋ N ::= n | λx.N | <strong>in</strong> i N | case(n, x 1 .N 1 , x 0 .N 0 )The rule π3, e read from left to right, trans<strong>for</strong>ms an application term t case(r, x 0 .s 0 , x 1 .s 1 )<strong>in</strong> a case term case(r, x 0 .t s 0 , x 1 .t s 1 ). This is already the effect of the traditional permutativeconversion π, so that we keep this direction. Similarly, the rule π4 e move<strong>in</strong>jections <strong>in</strong> i case(r, x 0 .s 0 , x 1 .s 1 ) <strong>in</strong>side a case term case(r, x 0 .<strong>in</strong> i s 0 , x 1 .<strong>in</strong> i s 1 ). Thenormal <strong>for</strong>ms NF need once more to be split and are def<strong>in</strong>ed simultaneously withneutral <strong>for</strong>ms Ne and PNF.Ne Λ+ ∋ n ::= x | nPPNF Λ+ ∋ P ::= n | λx.N | <strong>in</strong> i PNF Λ+ ∋ N, N 0 , N 1 ::= P | case(n, x 1 .N 1 , x 0 .N 0 )The conversion π e 5 says that a λ-abstraction can be moved <strong>in</strong>side a case term. Wechoose just as <strong>in</strong> the last chapter to move the b<strong>in</strong>ders λ as deep as possible <strong>in</strong> orderto <strong>in</strong>troduce variables just be<strong>for</strong>e their uses. For that we need to def<strong>in</strong>e a conditionwhich express that a λ is already at the deepest possible position.For example <strong>for</strong> the term λz.case(r, x.s, y.t) this condition should state that thevariable z should occur <strong>in</strong> r, otherwise λz could be moved <strong>in</strong> front of s and t.However, to check whether the variable z occurs <strong>in</strong> r is not enough, <strong>for</strong> if the terms is itself a case term, say s = case(r ′ , x ′ .s ′ , y ′ .t ′ ), and neither z nor x occurs <strong>in</strong> r ′then we could move λz <strong>in</strong> a more <strong>in</strong>ternal position as follows:1. first move the term r ′ to the outside by convert<strong>in</strong>g<strong>in</strong>toλz.case(r, x.case(r ′ , x ′ .s ′ , y ′ .t ′ ), y.t)λz.case(r ′ , x ′ .case(r, x.s ′ , y.t), y ′ .case(r, y ′ .t ′ , y.t))2. and now we can move λz <strong>in</strong>side by convert<strong>in</strong>g<strong>in</strong>toλz.case(r ′ , x ′ .case(r, x.s ′ , y.t), y ′ .case(r, y ′ .t ′ , y.t))case(r ′ , x ′ .λz.case(r, x.s ′ , y.t), y ′ .λz.case(r, y ′ .t ′ , y.t))


4.2 Extended Conversion and Normal Forms 83There<strong>for</strong>e we def<strong>in</strong>e the deepest λ condition DL(X, r), <strong>for</strong> a set of variables X anda term r, this condition is true if r is a variable or a λ-abstraction and if r is a caseterm case(n, x 0 .N 0 , x 1 .N 1 ), it is def<strong>in</strong>ed as follows:DL(X, case(n, x 0 .N 0 , x 1 .N 1 )) ::= X ∩ FV(n) ≠ ∅ ∧ DL(X ∪ x 0 , N 0 ) ∧ DL(X ∪ x 1 , N 1 )Conversion η and prenormal <strong>for</strong>msAs already noticed, η-<strong>conversions</strong> require to consider the types of the term <strong>in</strong>volved.The rule of η-<strong>conversions</strong>, oriented as expansions (i.e., from left to right <strong>in</strong> thedef<strong>in</strong>ition above), expand a term r <strong>in</strong>to an abstraction or a case term accord<strong>in</strong>gwhether the type of r is an arrow type or a sum type.Considered together with the β-conversion oriented <strong>in</strong> a reduction from left toright, one has to impose restrictions on the η → -expansion to prevent <strong>in</strong>f<strong>in</strong>ite sequenceof reductions. Namely an η → -expansion should not expand a λ-abstraction nor themajor premiss r of an application rs. Similarly an η + -expansion should not expandan <strong>in</strong>jection term <strong>in</strong> i r nor the major premiss r of a case term case(r, x.s, y.t).To obta<strong>in</strong> normal <strong>for</strong>ms <strong>for</strong> the η-conversion, it suffices to restrict the <strong>for</strong>mationof pure normal <strong>for</strong>ms <strong>for</strong> neutral terms to those of ground type. We will need tofurther restrict these normal <strong>for</strong>ms <strong>in</strong> the next section and call prenormal <strong>for</strong>ms thenormal <strong>for</strong>ms obta<strong>in</strong>ed at this stage.Def<strong>in</strong>ition 4.9 (prenormal <strong>for</strong>ms). We def<strong>in</strong>e by simultaneous <strong>in</strong>duction threerelations − ⊢ Ne − : −, − ⊢ PNF − : −, and − ⊢ NF − : − between context, term andtype,Γ ⊢ Ne x : ρΓ ⊢ Ne n : ρ → σΓ ⊢ Ne nP : σΓ ⊢ PNF P : ρΓ ⊢ Ne n : oΓ ⊢ PNF n : oΓ, x : ρ ⊢ NF N : σΓ ⊢ PNF λx.N : ρ → σΓ ⊢ PNF P : ρ iΓ ⊢ PNF <strong>in</strong> i P : ρ 0 + ρ 1Γ ⊢ PNF P : ρΓ ⊢ NF P : ρΓ ⊢ Ne n : ρ 0 + ρ 1 Γ, x : ρ i ⊢ NF N i : σΓ ⊢ NF case(n, x 0 .N 0 , x 1 .N 1 ) : σ<strong>in</strong> the rule with conclusion Γ ⊢ PNF λx.N : ρ → σ we impose the conditionDL({x}, N) (deepest λ)which is true if N is not a case term and otherwise def<strong>in</strong>ed by:DL(X, case(n, x 0 .N 0 , x 1 .N 1 )) ::= X ∩ FV(n) ≠ ∅ ∧ DL(X ∪ x 0 , N 0 ) ∧ DL(X ∪ x 1 , N 1 )


84 4. SumsThe condition (deepest λ) ensures that the case are <strong>in</strong>troduced as soon as possible,i.e., as soon as variables occurr<strong>in</strong>g <strong>in</strong> the term to be tested are available, whichmeans just after a b<strong>in</strong>d<strong>in</strong>g symbols or at the top-level.Notation 16. We will write Ne ρ Γ (resp. NFρ Γ and PNFρ Γ) <strong>for</strong> the set of terms r suchthat Γ ⊢ Ne r : ρ (resp. Γ ⊢ NF r : ρ and Γ ⊢ PNF r : ρ) and Ne ρ (resp. NF ρ and PNF ρ )<strong>for</strong> the set of terms r such that there exists a context Γ and r ∈ Ne ρ Γ (resp. r ∈ NFρ Γand r ∈ PNF ρ Γ ).Circular Conversions and Immediate SimplificationTo design a decision algorithm <strong>for</strong> the whole conversion relation, one has to face afirst problem, namely the <strong>in</strong>herent circularity of the π e -conversion.As one can see <strong>in</strong> the follow<strong>in</strong>g example, this circularity problem cannot be solvedby the orientation of the rewrite relation alone.Example 13. In the example below the term on the right hand side is obta<strong>in</strong>ed bypull<strong>in</strong>g out the two occurrences of the subterm r ′ thanks to the conversion π6 e and π7,ethen the term is simplified by us<strong>in</strong>g π8 e or π9, e and by reduc<strong>in</strong>g the generated β-redex:case(r,x · case(r ′ , x ′ .s ′ , y ′ .t ′ ),y · case(r ′ , x ′ .s ′′ , y ′ .t ′′ )with x ′ , y ′ ∉ FV(r) and x, y ∉ FV(r ′ ).)= case(r ′ ,x ′ · case(r, x.s ′ , y.s ′′ ),y ′ · case(r, x.t ′ , y.t ′′ )The two terms of the example above have exactly the same structure, and althoughit may be possible to break this circularity, e.g. by <strong>in</strong>troduc<strong>in</strong>g an orderon terms (<strong>for</strong> example <strong>in</strong>duced by the variables they conta<strong>in</strong>), it seems artificial toselect one of these terms as more normal than the other. In terms of programm<strong>in</strong>gif we have to do two tests which are <strong>in</strong>dependent from each other, there is no reasonto choose to do a particular one first.Hence, the normal <strong>for</strong>ms can no longer be unique, their equality is no longersyntactic but has to be tested with respect to this <strong>conversions</strong> (i.e., π e 6 to π e 9).Notation 17. Due to this circularity, we will call the <strong>conversions</strong> π e 6 to π e 9 circularpermutative conversion and write π e c <strong>for</strong> their union as relations.)r = π e cs ::= r = π e6s ∨ r = π e7s ∨ r = π e8s ∨ r = π e9sA second problem is that the NbE algorithm tends to produce terms which are<strong>in</strong> expanded <strong>for</strong>m, i.e., the π e -conversion is oriented from left to right. In particularthis means that if x does not actually occur <strong>in</strong> r, the term r{ case(s,x 0.t 0 ,x 1 .t 1) /x} isconverted <strong>in</strong>to case(s, x 0 .r, x 1 .r) (is-conversion) .Seen as a reduction from left to right this would lead immediately to an <strong>in</strong>f<strong>in</strong>iteloop. Besides, it does not make any sense to <strong>in</strong>troduce superfluous test term as s


4.3 In<strong>for</strong>mal Description 85above.Hence the normal <strong>for</strong>ms will have to be irreducible terms <strong>for</strong> the <strong>in</strong>verse reduction(oriented from right to left) known from Prawitz [78] as immediate simplificationreduction.case(s, x 0 .r, x 1 .r) −→ is r(x 0 , x 1 ∉ FV(r))We will deal with these <strong>conversions</strong> <strong>in</strong> more detail after hav<strong>in</strong>g def<strong>in</strong>ed a firstversion of the normalization algorithm <strong>for</strong> the prenormal <strong>for</strong>ms def<strong>in</strong>ed above.4.3 In<strong>for</strong>mal DescriptionTo expla<strong>in</strong> the algorithm, we will proceed <strong>in</strong><strong>for</strong>mally as <strong>in</strong> the chapter on the simply<strong>typed</strong> λ-<strong>calculus</strong> (2.2.1).First we need an <strong>in</strong>terpretation, we take the <strong>standard</strong> set theoretical <strong>in</strong>terpretationwhere a sum type is <strong>in</strong>terpreted as a disjo<strong>in</strong>t union of its components and theground type is <strong>in</strong>terpreted as the set of neutral term Ne o :Def<strong>in</strong>ition 4.10 (Type Interpretation).ρ, by <strong>in</strong>duction on ρ ∈ Ty:We def<strong>in</strong>e the <strong>in</strong>terpretation ρ of a typeo ::= Ne oρ → σ ::= ρ → σρ + σ ::= ρ + σwhere ρ → σ is the full function space between the set ρ and σ, and ρ +σis the disjo<strong>in</strong>t union of the set ρ and σ.The <strong>in</strong>terpretation of types Ty of the <strong>typed</strong> <strong>lambda</strong> <strong>calculus</strong> with sum typesΛ + is then:Ty = ⋃ρρ∈TyTo def<strong>in</strong>e the <strong>in</strong>terpretation of terms we need first to def<strong>in</strong>e the auxiliary notionof valuation.Def<strong>in</strong>ition 4.11 (Valuation). Given a context Γ, we def<strong>in</strong>e a valuation on Γ tobe a partial function η : Var → Ty ⊥such that <strong>for</strong> x : ρ ∈ Γ, we have η(x) isdef<strong>in</strong>ed and η(x) ∈ ρ. Given a context Γ, a valuation η on Γ, a variable y ∉ Γand an element a ∈ σ, we def<strong>in</strong>e a valuation (η, y ↦→ a) on Γ ∪ {(y : σ)}, calledthe extension of η by y ↦→ a by,{a if x = y,(η, y ↦→ a)(x) ::=η(x) otherwise.


86 4. SumsRemark 16. Valuation functions are partial functions represented as total functionsfrom the set of variables Var <strong>in</strong>to the set Ty ⊥= Ty + {⋆}, i.e., the <strong>in</strong>terpretationof types extended with an element ⋆ play<strong>in</strong>g the rôle of an undef<strong>in</strong>ed value. In thefollow<strong>in</strong>g, whenever we will use a valuation applied to some variable, this variablewill belong to the doma<strong>in</strong> of def<strong>in</strong>ition of the valuation and the result will there<strong>for</strong>ebe def<strong>in</strong>ed. And although, strictly speak<strong>in</strong>g we should do a case dist<strong>in</strong>ction on theresult to know wheither it is def<strong>in</strong>ed (an alternative would be to use an exceptionmonad as presented <strong>in</strong> def<strong>in</strong>ition 1.3), we will consider it to be an element of Ty.The <strong>in</strong>terpretation of a <strong>typed</strong> term is an element of the <strong>in</strong>terpretation of its type.Def<strong>in</strong>ition 4.12 (Term Interpretation). F<strong>in</strong>ally, we def<strong>in</strong>e the <strong>in</strong>terpretation r ηof a term r, whenever there is a context Γ, such that Γ ⊢ r : ρ and η is a valuatio<strong>non</strong> Γ, to be an element of ρ, by the follow<strong>in</strong>g <strong>in</strong>ductive def<strong>in</strong>ition:x η ::= η(x)λx ρ .r η (v) ::= r η,x↦→vrs η ::= r η (s η )<strong>in</strong> i r η ::= ι i r η{case(r, x ρ .s, y σ s.t) η ::= η,x↦→a if r η = ι 0 a,if r η = ι 1 a4.3.1 Several Attemptst η,y↦→aWe want now to def<strong>in</strong>e a reify function ↓, from the <strong>in</strong>terpretation of types to theset of terms. As previously, we will def<strong>in</strong>e it <strong>in</strong>ductively on the type simultaneouslywith a function ↑ from the terms to the <strong>in</strong>terpretation.Let us try to extend to sum types the def<strong>in</strong>ition which was given <strong>in</strong> chapter 2 <strong>for</strong>ground and arrow types. An element of the <strong>in</strong>terpretation of a sum type is either aleft <strong>in</strong>jection or a right <strong>in</strong>jection, and hence the function ↓ can be directly extendedby:↓ ρ0 +ρ 1ι i a ::= <strong>in</strong> i ↓ ρi aThe first difficulty comes when try<strong>in</strong>g to extend the function ↑ at sum type. Letus look at the problem with an example:Example 14 (the unsolvable problem). Let us assume we want to normalize theterm xy of sum type with the follow<strong>in</strong>g typ<strong>in</strong>g:by ↓ xy ↑ .x : o → o + o, y : o ⊢ xy : o + o


4.3 In<strong>for</strong>mal Description 89f is evaluated <strong>in</strong> the environment ɛ 0 , the result is either a term or an exception ⊥(n)conta<strong>in</strong><strong>in</strong>g a neutral term n. In case of an exception ⊥(n), the set of free variablesof n is compared to X, and if there is no variable <strong>in</strong> common then the exception isthrown further up, else a case term is created whose test term is the neutral term nand each branch is the result of the evaluation of doAcase? <strong>for</strong> the same function f,but <strong>in</strong> an updated environment (<strong>in</strong> each branch the neutral term n is now associatedeither with <strong>in</strong> 0 x or <strong>in</strong> 1 x <strong>for</strong> a new variable x).Remark 17. In the algorithm above, the l<strong>in</strong>e <strong>in</strong> the function doAcase?:if FV(n) ∩ X = ∅ then throw(n)ensures that if a neutral term n thrown as an exception and conta<strong>in</strong><strong>in</strong>g a variablex that has not been bound either by a λ-abstraction λx directly be<strong>for</strong>e the doAcase?function or by a b<strong>in</strong>d<strong>in</strong>g <strong>in</strong> a case expression x· after this function, will be thrownupper <strong>in</strong> the computation tree. This ensures that neutral terms of sum type arecaptured at the uppermost b<strong>in</strong>d<strong>in</strong>g possible, just after their creation by a b<strong>in</strong>d<strong>in</strong>g or atthe top-level. This is not a trivial idea, as we could just have caught every exceptionalneutral terms after the function doAcase?, and create a new case dist<strong>in</strong>ction operatorat this level.This latter approach would still yield a correct algorithm <strong>in</strong> the sense that theresult is convertible with the term given as <strong>in</strong>put <strong>in</strong> the normalization function.The advantage to create dist<strong>in</strong>ction operator as soon as possible is that it allowsto further constra<strong>in</strong> the set of normal <strong>for</strong>ms, and this is essential if we are after adecision algorithm. This idea to create dist<strong>in</strong>ction operator as soon as possible firstappears explicitly <strong>in</strong> the works of V<strong>in</strong>cent Balat [9], and his coauthors, Roberto DiCosmo and Marcelo Fiore [10], with an implementation with controls operators andan election of a best prompt (uppermost b<strong>in</strong>d<strong>in</strong>g).The normalization function <strong>for</strong> a term r is obta<strong>in</strong>ed by apply<strong>in</strong>g the functiondoAcase? to ɛ ↓ ɛ ρ r ↑ɛand all free variables of r <strong>in</strong> an empty environment, i.e., thefunction undef<strong>in</strong>ed everywhere t.⊥.Code 9 (Normalization function).def<strong>in</strong>ed by:The normalization function nf : Tm → NF isnf(Γ ⊢ r : ρ) ::= doAcase?(ɛ ↓ ρ ɛ r ↑ɛ, FV(t))(t.⊥)4.3.3 Toward CompletenessAlthough the algorithm we have just presented is sound <strong>in</strong> the sense that the resultof our algorithm is βη-equal to the <strong>in</strong>itial term, it is not yet complete. In particulartwo terms which are βη-equal can be normalized to syntactically different terms.As expla<strong>in</strong>ed <strong>in</strong> the <strong>in</strong>troduction, the syntactical equality is not suitable to identify


90 4. Sumsterms which only differ <strong>in</strong> the order of <strong>in</strong>dependent case elim<strong>in</strong>ations. What we needis an equality test based on the circular conversion (conversion π e 6 to π e 9) and theimmediate simplification (is).First, let us consider the immediate simplification conversion:case(r, x 0 .s, x 1 .s) −→ is s (x 0 , x 1 ∉ FV(r)) (is)Whether the test term r <strong>in</strong> the rule above is a left or a right <strong>in</strong>jection is irrelevant,because the two branches of the alternative are anyway the same. We call suchterms redundant.The reduction (is) above erases the whole term r, and hence the variables itconta<strong>in</strong>s. A consequence is that this reduction does not preserve prenormal <strong>for</strong>msbecause it can break the deepest λ condition (deepest λ).Example 16. Suppose the follow<strong>in</strong>g term is a prenormal <strong>for</strong>m,λx.case(t{ case(r,x 0.s,x 1 .s) /z}, y 0 .t 0 , y 1 .t 1 )with x ∈ FV(r) but x ∉ FV(s) and x ∉ FV(t). An immediate simplification reductionleads to the follow<strong>in</strong>g term:λx.case(t{ s /z}, y 0 .t 0 , y 1 .t 1 )but this term does no longer verify the deepest λ condition (deepest λ) because x ∉t{ r /z}.To avoid these redundancies we want to def<strong>in</strong>e the set of normal <strong>for</strong>ms as arestriction of the set of prenormal <strong>for</strong>ms. But as the example above shows, this cannot be achieved by merely fir<strong>in</strong>g the immediate simplification reductions (is) from aterm <strong>in</strong> prenormal <strong>for</strong>m. To def<strong>in</strong>e the set of normal <strong>for</strong>ms, we will <strong>in</strong>tegrate a testof redundancy directly <strong>in</strong> the <strong>in</strong>ductive def<strong>in</strong>ition of prenormal <strong>for</strong>ms.Among the circular <strong>conversions</strong>, let us consider the conversion π e 8 and π e 9.case(r, x 0 .case(r, x 0 .s 0 , x 1 .s 1 ), x 1 .t) = π e8case(r, x 0 .s 0 , x 1 .t)case(r, x 0 .s, x 1 .case(r, x 0 .t 0 , x 1 .t 1 )) = π e9case(r, x 0 .s, x 1 .t 1 )If we consider λ-terms as programs, the term s 1 <strong>in</strong> the conversion π e 8 and the termt 0 <strong>in</strong> the conversion π e 9 are superfluous, they will never be used whatever value r isevaluated to. We call such terms junk terms. And although we do not want to selecta normal <strong>for</strong>m between two terms which differ only <strong>in</strong> the order of <strong>in</strong>dependent test,we do want to elim<strong>in</strong>ate such junk terms from normal <strong>for</strong>ms.We will def<strong>in</strong>e the normal <strong>for</strong>ms as a restriction of the prenormal <strong>for</strong>ms by <strong>in</strong>troduc<strong>in</strong>gtwo conditions, one to avoid redundancy (redundancy freeness) and oneto avoid junk (junk freeness).


4.3 In<strong>for</strong>mal Description 91These two conditions require an equality test between two occurrences of a subterm,but us<strong>in</strong>g syntactical equality <strong>for</strong> this equality test is not enough. For example,if the terms r and r ′ only differ by the order of <strong>in</strong>dependent case elim<strong>in</strong>ation (i.e.,r = π e cr ′ ), we still want to elim<strong>in</strong>ate the junk term s 1 <strong>in</strong> the termcase(r, x 0 .case(r ′ , x 0 .s 0 , x 1 .s 1 ), x 1 .t),or remove the redundancy <strong>in</strong> the termcase(r, x 0 .r ′ , x 1 .t)(if x 0 ∉ FV(s) and x 1 ∉ FV(t)).This equality has <strong>in</strong>deed to be tested modulo circular <strong>conversions</strong>.The work of Thorsten Altenkirch and his coauthors [4] avoids this test of modulocircular <strong>conversions</strong> altogether by def<strong>in</strong><strong>in</strong>g a normal <strong>for</strong>m, which identifies termsdiffer<strong>in</strong>g <strong>in</strong> the order of <strong>in</strong>dependent case elim<strong>in</strong>ations (<strong>in</strong>dependent case elim<strong>in</strong>ationsare grouped together <strong>in</strong>to a b<strong>in</strong>ary function from a set of neutral terms). To keepthe presentation simple, we prefer a more syntactical presentation to this elegantsolution, and there<strong>for</strong>e follow the way of V<strong>in</strong>cent Balat [9] and his coauthors [10]and use a test modulo circular permutative <strong>conversions</strong>.4.3.4 Normal FormsWe now def<strong>in</strong>e the normal <strong>for</strong>ms of our system. Eventually, the goal of design<strong>in</strong>gnormal <strong>for</strong>ms is to obta<strong>in</strong> a set of representatives <strong>for</strong> each class of terms moduloβη. The considerations <strong>in</strong> the last sections lead to the follow<strong>in</strong>g def<strong>in</strong>ition of normal<strong>for</strong>ms.


92 4. SumsDef<strong>in</strong>ition 4.13 (normal <strong>for</strong>ms). We def<strong>in</strong>e by simultaneous <strong>in</strong>duction three relations− ⊢ Ne − : −, − ⊢ PNF − : −, and − ⊢ NF − : − between context, term andtype,(x, ρ) ∈ ΓΓ ⊢ Ne x : ρΓ ⊢ Ne n : ρ → σΓ ⊢ Ne nP : σΓ ⊢ PNF P : ρΓ ⊢ Ne n : oΓ ⊢ PNF n : oΓ, x : ρ ⊢ NF N : σΓ ⊢ PNF λx.N : ρ → σΓ ⊢ PNF P : ρ iΓ ⊢ PNF <strong>in</strong> i P : ρ 0 + ρ 1Γ ⊢ PNF P : ρΓ ⊢ NF P : ρΓ ⊢ Ne n : ρ 0 + ρ 1 Γ, x i : ρ i ⊢ NF N i : σΓ ⊢ NF case(n, x 0 .N 0 , x 1 .N 1 ) : σ<strong>in</strong> the rule with conclusion Γ ⊢ PNF λx.N : ρ → σ we impose the conditionDL({x}, N), (deepest λ)where <strong>for</strong> a set of variables X and normal <strong>for</strong>m N, DL(X, N) is true if N is not acase term and otherwise def<strong>in</strong>ed by:DL(X, case(n, x 0 .N 0 , x 1 .N 1 )) ::= X ∩ FV(n) ≠ ∅ ∧ DL(X ∪ x 0 , N 0 ) ∧ DL(X ∪ x 1 , N 1 )<strong>in</strong> the rule with conclusion Γ ⊢ NF case(n, x 0 .N 0 , x 1 .N 1 ) : σ, we impose the conditionRF(case(n, x 0 .N 0 , x 1 .N 1 )) ::= x 0 ∉ FV(N 0 ) ∧ x 1 ∉ FV(N 1 ) ⇒ Γ ⊢ N 0 ≠ π e cN 1 : σ(redundancy freeness)and the conditionJF Γ (∅, case(n, x 0 .N 0 , x 1 .N 1 ))(junk freeness)where JF Γ (Ne, x, N) is true if N is not a case term and otherwise def<strong>in</strong>ed by:JF Γ (Ne, case(n, x 0 .N 0 , x 1 .N 1 )) ::= ∀ n ′ ∈ Ne, Γ ⊢ Ne n ≠ π e cn ′ : σ ∧ JF Γ,xi (Ne, N i )(4.1)To produce such normal <strong>for</strong>ms, the first change <strong>in</strong> the algorithm is that the newcondition of redundancy freeness has to be checked where the algorithm produces acase term case(n, x.N 0 , x.N 1 ) by test<strong>in</strong>g if x occurs <strong>in</strong> N 0 or N 1 and if N 0 = π e cN 1 .The auxiliary function doAcase? is changed accord<strong>in</strong>gly.The second change concerns the environment ɛ associat<strong>in</strong>g a neutral term to an<strong>in</strong>jection of a variable x, <strong>in</strong> 0 x or <strong>in</strong> 1 x. These environment should now be def<strong>in</strong>edon the set of neutral terms up to circular permutative <strong>conversions</strong>, and hence the


4.4 Formalization 93update operation has to be changed to:{ɛ n↦→<strong>in</strong> i x <strong>in</strong>i x if s =s =π e cnɛ(s) otherwiseCode 10 (NbE <strong>for</strong> sum types). Let ɛ 0 ∈ Ne → (Var + Var) ⊥ be an environment.The reify function ↓ ρ : (Ne → (Var + Var) ⊥ ) → ρ → PNF and reflect function↑ ρ : (Ne → (Var + Var) ⊥ ) → Ne → ρ are def<strong>in</strong>ed simultaneously by <strong>in</strong>duction on thetype ρ:↓ o ɛ 0n ::= n↓ ρ→σɛ 0f ::= λx.doAcase?(ɛ ↓ σ ɛ f(↑ ρ ɛ x), {x})ɛ 0↓ ρ 0+ρ 1ɛ 0ι i c ::= <strong>in</strong> i ↓ ρ iɛ 0c↑ o ɛ 0n ::= n↑ ρ→σɛ 0n ::= v. ↑ σ ɛ 0(n ↓ ρ ɛ 0v)↑ ρ+σɛ 0n ::={let <strong>in</strong> i x = (catch ɛ 0 (n) throw(n)) <strong>in</strong>ι i ↑ ρ iɛ 0xwhere doAcase? is def<strong>in</strong>ed bydoAcase?(f, X)ɛ 0 ::= catch (fɛ 0 )n.if FV(n) ∩ X = ∅ then throw(n)else let N 0 = doAcase?(f, X ∪ {x})ɛ 0n↦→<strong>in</strong> 0 x <strong>in</strong>let N 1 = doAcase?(f, X ∪ {x})ɛ 0n↦→<strong>in</strong> 1 x <strong>in</strong>if x ∉ FV(N 0 ) ∧ N 0 = π e cN 1 then N 0else case(n, x.N 0 , x.N 1 )The auxiliary function doAcase? has to be applied at the top-level to catch exceptionconta<strong>in</strong><strong>in</strong>g neutral terms with only free variables.Code 11 (Normalization function).nf(Γ ⊢ r : ρ) = doACase?(ɛ ↓ ɛ ρ r ↑ɛ, t.⊥, FV(t))4.4 FormalizationWe return now to the notions we have let <strong>in</strong><strong>for</strong>mal <strong>in</strong> the previous sections: the namegeneration environment needed to generate new names, the environment associat<strong>in</strong>gvariables to neutral terms and the handl<strong>in</strong>g of exceptions. This section is verysimilar to the correspond<strong>in</strong>g one of the last chapter. We use a reader monad <strong>for</strong>each environment and an exception monad to handle the exceptions.


94 4. SumsName Generation EnvironmentThe def<strong>in</strong>ition of the name generation environment here is the same as <strong>in</strong> the chapterhandl<strong>in</strong>g the simply <strong>typed</strong> λ-<strong>calculus</strong> (2), we restate it here.Def<strong>in</strong>ition 4.14 (Name Generation Environment). We def<strong>in</strong>e a set of name generationenvironment or set of environment <strong>for</strong> short, as a set E together with anupdate function (−) − : E → Var → E and an access function new : E → Var.The extension of e − : V → E to a function from a list of variables e : L(V ) → Eis def<strong>in</strong>ed <strong>in</strong> a ca<strong>non</strong>ical way bye x,−→x ::= (e x ) −→ xe ε ::= e.The function (−) − and new have moreover to satisfy the follow<strong>in</strong>g property <strong>for</strong>all e ∈ E:∀ −→ x , x ≠ new(e x,−→x ) (†)Notation 18. The condition that the new function applied to an environment e ∈ Eshould never return a certa<strong>in</strong> variable x can be expressed by:∀ −→ x , x ≠ new(e −→x )We will abbreviate this condition by x ∉ e. In the same way we will abbreviate <strong>for</strong>a given set of variables X, ∀ x ∈ X, x ∉ e by X ∉ e.Postdiction EnvironmentThe second environment we will use, associates <strong>in</strong>jections of a variable to neutralterms of sum type. It comes with an update operation def<strong>in</strong>ed up to the circular<strong>conversions</strong> π e c.Def<strong>in</strong>ition 4.15 (Postdiction Environment). We def<strong>in</strong>e the set P of postdictionenvironment as the set Ne → (Var + Var) ⊥ together with an update function (−) − :P → (Ne × Var) → P:{ɛ n↦→<strong>in</strong> i x n ′ <strong>in</strong> i x if n = π e::=cn ′ɛ(n ′ ) otherwiseInterpretation MonadWe will now def<strong>in</strong>e the monad used <strong>in</strong> the <strong>in</strong>terpretation, a computation shouldtake place <strong>in</strong> the name generation environment E and the postdiction environment


4.4 Formalization 95P(= Ne → (Var+Var) ⊥ ), and it can be aborted by throw<strong>in</strong>g an exception conta<strong>in</strong><strong>in</strong>ga neutral term. Hence the computation type TA <strong>for</strong> a result type A is:T ::= St E (St P (A ⊥(Ne) )) = E → (Ne → (Var + Var) ⊥ ) → Ne + AThe unit and multiplication of the monad of the <strong>in</strong>terpretation are def<strong>in</strong>ed quitenaturally from the def<strong>in</strong>ition of the unit and multiplication of its monad components.Def<strong>in</strong>ition 4.16 (Interpretation monad T ::= St E ◦St Ne→(Var+Var)⊥ ◦− ⊥(Ne+ )).(set operator of) the <strong>in</strong>terpretation monad T is def<strong>in</strong>ed byTheTA ::= St E (St Ne→(Var+Var)⊥ (A ⊥(Ne+ )))(= E → (Ne → (Var + Var) ⊥ ) → A ⊥(Ne+ ))Given m ∈ TA and f ∈ A → TB, we def<strong>in</strong>e the unit ν : A → TA and multiplication⋆ : TA → (A → TB) → TB of the <strong>in</strong>terpretation monad by:ν T a ::= ν St E(ν St Ne→(Var+Var) ⊥ (ν A ⊥(Ne +) a))m ⋆ T f(e)(s) ::= m(e)(s) ⋆ − ⊥(Ne +) λa.f(a)(e)(s)The update operation <strong>for</strong> the name environment monad and the postdictionmonad extend to the <strong>in</strong>terpretation monad.The update operations <strong>for</strong> the name environment monad and the postdictionmonad extends component-wise to the <strong>in</strong>terpretation monad.Def<strong>in</strong>ition 4.17 (update <strong>for</strong> the Postdiction Monad). We def<strong>in</strong>e an update function(−) − : St P(A) → (Ne × (Var + Var)) → St P(A) operation by extend<strong>in</strong>g the updateoperation <strong>for</strong> postdiction environment by:m n↦→<strong>in</strong> i x (ɛ) ::= m(ɛ n↦→<strong>in</strong> i nx )This update operation extends <strong>in</strong> turn <strong>in</strong>to an operation (−) − : TA → (Ne × (Var +Var)) → TA to the <strong>in</strong>terpretation monad just <strong>in</strong> the same way by:m n↦→<strong>in</strong> i x (e)(ɛ) ::= m(e)(ɛ n↦→<strong>in</strong> i x )Def<strong>in</strong>ition 4.18 (update <strong>for</strong> the Name Generation Monad). We def<strong>in</strong>e an update(−) − : T(A) → Var → T(A) operation by extend<strong>in</strong>g the update operation <strong>for</strong> thename generation monad by:m v (e) ::= m(e v )The <strong>in</strong>terpretation is a call by value <strong>in</strong>terpretation <strong>for</strong> computations <strong>in</strong> the monadT:


96 4. SumsDef<strong>in</strong>ition 4.19 (<strong>in</strong>terpretation). The call-by-value <strong>in</strong>terpretation of the Λ + -<strong>calculus</strong> is given on types byo ::= Neτ 1 → τ 2 ::= ρ → T(σ)τ 1 + τ 2 ::= σ 0 + σ 1 Given a valuation η on a context Γ (η Γ), the <strong>in</strong>terpretation of a <strong>typed</strong> termΓ ⊢ t : τ is the monadic value t η ∈ T(τ) def<strong>in</strong>ed by:x η::= ν(η(x))rs η::= r η⋆ λf.s η⋆ λa.faλx.r η::= ν(λa.r η,x↦→a)case(r, x ρ .s 0 , y σ .s 1 ) η::= r η⋆ λ(ι i c).s i η,x↦→c<strong>in</strong> i t η::= t η⋆ λc.ν(ι i c)Code 12 (call-by-value NbE). The function ↓ τ : τ → T(PNF τ ) and ↑ τ : Ne τ →St P (τ ⊥(Ne)) are def<strong>in</strong>ed simultaneously by:↓ o n ::= ν(n)↓ ρ→σ f ::= new ⋆ x.doAcase?(ν St E(↑ ρ x) ⋆ f⋆ ↓ σ , {x}) x ⋆ e.ν(λx.e)↓ ρ0 +ρ 1ι i c ::=↓ ρi c ⋆ e.ν(<strong>in</strong> i e)↑ o n ::= ν(n)↑ ρ→σ n ::= ν(v. ↓ ρ v ⋆ P.ν(↑ σ (nP )))⎧⎨ case ɛ(n) of↑ ρ+σ n ::= ɛ. ⊥ ⇒ throw(n)⎩ι i x ⇒ (↑ ρ ix)ɛ ⋆ v.ν(ι i v)where the auxiliary function doAcase? is def<strong>in</strong>ed bydoAcase?(f, X) ::= catchfn. ifelseFV(n) ∩ X = ∅ then throw(n)new ⋆ x.doAcase?(upd(f, n, x, L), X ∪ {x}) x ⋆ t1.doAcase?(upd(f, n, x, R), X ∪ {x}) x ⋆ t2.if x ∉ FV(t1) ∧ t1 = π e ct2then ν(t1)else ν(case(n, x.t1, x.t2))


4.4 Formalization 97Code 13 (Normalization function).is def<strong>in</strong>ed by:The normalization function nf : Tm τ Γ → NF τ Γnf τ (r) = doAcase?(ν(↑ Γ) ⋆ −→ a .r−→ x →−→ a⋆ ↓ τ )e r (n.⊥)where the multiplication ⋆ of the <strong>in</strong>terpretation monad is extended to a list ofmonadic values by:( −→ m, m) ⋆ ( −→ a , a).m ′ ::= −→ m ⋆ −→ a .m ⋆ a.m ′ε ⋆ ε.m ′ ::= m ′The claims of this section state the correctness and completeness of the algorithm(6) above.Claim 3 (Correctness).r = βη nf(r)Claim 4 (Completeness).r = βη s =⇒ nf(r) = cc nf(s)The results <strong>in</strong> the previous chapter (2) were developed to be a basis to provethese results. A first exploration lead us to use logical monadic relations whosemonadic part itself is def<strong>in</strong>ed <strong>in</strong>ductively. This monadic part has to encompass thenotion of fresh variables, as <strong>in</strong> the previous chapter, but also the notion of attemptsneeded to run the NbE until no exceptions are raised (the base case correspond<strong>in</strong>gto a monadic value return<strong>in</strong>g directly a value, and the step case correspond<strong>in</strong>g to amonadic value return<strong>in</strong>g an exception.) For time reason, we have let a <strong>for</strong>mal study<strong>for</strong> further research. The conceptual simplicity of the approach us<strong>in</strong>g exceptionsallowed us to implement the NbE algorithm <strong>in</strong> the pure functional language Haskellwithout us<strong>in</strong>g any primitive operators and we are confident that proofs of the claims(3) and (4) above will <strong>for</strong> the same reason be feasible.


98 4. Sums


Chapter 5Inductive TypesParametric <strong>in</strong>ductive types can be seen as functions tak<strong>in</strong>g type parameters as argumentsand return<strong>in</strong>g an <strong>in</strong>stantiated <strong>in</strong>ductive type. Correspond<strong>in</strong>gly given functionsbetween parameters one can construct by iteration a copy function between thecorrespond<strong>in</strong>g <strong>in</strong>stantiated <strong>in</strong>ductive types which corresponds to the change of parametersalong these functions. This suggests the question whether this constructiondef<strong>in</strong>es a functor.Inductive types are traditionally <strong>in</strong>terpreted as universal objects. This meansthat functions which verify the same recursive or iterative equations are equal. Althoughthis <strong>in</strong>terpretation is very useful when prov<strong>in</strong>g <strong>for</strong> example the correctness ofa function with respect to its specification, or <strong>for</strong> trans<strong>for</strong>mations of programs, it is avery strong requirement known to be undecidable (see [76]). The implementation of<strong>in</strong>ductive type as universal object is there<strong>for</strong>e not possible. The commonly adoptedsolution has been to design system where only the existential part of the universalproperty is reta<strong>in</strong>ed. This already, allows to def<strong>in</strong>e functions from <strong>in</strong>ductive types byiteration or recursion. This <strong>in</strong>terpretation presupposes also a positive answer to theprevious question ; that parametric <strong>in</strong>ductive types are <strong>in</strong>deed functors. However,it is not the case with respect to the equality generated from <strong>standard</strong> reductions.We <strong>in</strong>vestigate a m<strong>in</strong>imal type system with <strong>in</strong>ductive types and show by means ofmodular rewrit<strong>in</strong>g techniques that reductions to make this construction a functoron a subcategory of the system can already be safely added while preserv<strong>in</strong>g thedecidability of the <strong>in</strong>ternal conversion relation.


100 5. Inductive Types5.1 System5.1.1 Types and SchemasDef<strong>in</strong>ition 5.1 (types). Given a countable set TVar of type variables and Constof constructors, the set Ty of types is def<strong>in</strong>ed simultaneously together with the setKT−→ ρ ,−→ σ (α) of constructor types over α with type parameters −→ ρ , −→ σ :Ty ∋ ρ, σ ::= α | ρ → σ | µα ( −−−−−−−→ c : κ−→ ρ ,−→ σ (α))KT−→ ρ ,−→ σ (α) ∋ κ−→ ρ ,−→ σ (α) ::= −→ ρ → −−−−−−→ ( −→ σ i → α) 1<strong>in</strong> → αwhere α ∈ TVar, −→ c ⊆ Const, −→ σ = −→ σ 1 , · · · , −→ σ n . We assume α ∉ FV( −→ ρ , −→ σ ), wherethe set of free variable FV(ρ) of a type ρ is def<strong>in</strong>ed by:FV(α) ::= αFV(ρ → σ) ::= FV(ρ) ∪ FV(σ)FV(µα ( −−−−−−−→ c : κ−→ ρ ,−→ σ (α))) ::= FV(κ−→ ρ ,−→ σ (α)) \ {α}The types with → as ma<strong>in</strong> symbol are called arrow or functional types, thosewith the b<strong>in</strong>d<strong>in</strong>g symbol µ are called <strong>in</strong>ductive types. We require the list of constructorsc −−−−−−−→ : κ−→ ρ ,−→ σ (α) of an <strong>in</strong>ductive type to be <strong>non</strong> empty. We assume moreoverthat the names of constructors are uniquely determ<strong>in</strong>ed by their <strong>in</strong>ductive type andthat the constructors with<strong>in</strong> an <strong>in</strong>ductive type are different. With<strong>in</strong> the def<strong>in</strong>itionof constructor type above, the types ρ ∈ −→ ρ and −→ σ i<strong>for</strong> the types of the arguments of a constructor, they are called respectively parametricoperators, and recursive operators (0-recursive if −→ σ is empty and 1-recursiveotherwise).Parametric and recursive operator verify the so-called strict positivity condition(<strong>in</strong>ductive type can not occur <strong>in</strong> the doma<strong>in</strong> of the type of an argument of theirconstructor). It is a syntactical condition frequently used to ensure good propertyof the system such as term<strong>in</strong>ation or well-foundation of <strong>in</strong>ductive predicate def<strong>in</strong>edover <strong>in</strong>ductive types. With this restriction, the <strong>in</strong>ductive types that can be expressed<strong>in</strong> the system correspond essentially to well-founded trees (arbitrary branch<strong>in</strong>g andof f<strong>in</strong>ite depth).Note that we have fixed a particular order on the arguments of a constructor(first parametric and then recursive), it doesn’t <strong>in</strong>fluence the expressivity of thesystem and simplifies the presentation.→ α ∈ −−−−−−→ ( −→ σ i → α) 1<strong>in</strong> standNotation 19. A constructor type κ(α) has always the <strong>for</strong>m −→ τ → α. We shallwrite κ − (α) <strong>for</strong> the list of types −→ τ . For µ = µα ( −−−−−−−→ c : κ−→ ρ ,−→ σ (α)), we will write c k :κ−→ ρ ,−→ σ (α) ∈ µ if c k : κ−→ ρ ,−→ σ (α) ∈ −−−−−−−→ c : κ−→ ρ ,−→ σ (α)


5.1 System 101To expla<strong>in</strong> the <strong>in</strong>terpretation of parametric <strong>in</strong>ductive type as functor of theirparameter, we need to s<strong>in</strong>gle out the follow<strong>in</strong>g notion of Schema of Inductive Type.Def<strong>in</strong>ition 5.2 (Schema of Inductive Type). Given a list of variables −→ k <strong>for</strong> <strong>in</strong>ductivetype constructors, type variables −→ π , −→ θ , α (with α ∉ −→ π ∪ −→ θ ), and constructortypes −−−−−→ κ −→π −→ , θ(α), we def<strong>in</strong>e a schema of <strong>in</strong>ductive type S byS −→π ,−→ θ( −→ k ) ::= µα( −−−−−−−−→ k : κ −→π ,−→ θ(α))Each <strong>in</strong>ductive type µα ( −−−−−−−→ c : κ−→ ρ ,−→ σ (α)) is obta<strong>in</strong>ed by <strong>in</strong>stantiation of the constructorvariables −→ k and type parameters −→ π , −→ θ of a schema of <strong>in</strong>ductive typeµα( −−−−−−−−→ k : κ −→π −→ , θ(α)).We now give representative examples of schema and <strong>in</strong>ductive types def<strong>in</strong>able <strong>in</strong>our system.Example 17. A schema can concern the name of the constructors only,N = µα(k 1 : α, k 2 : α → α)(schema of the natural numbers),it can have a type variable <strong>in</strong> a parametric operatorL π = µα(k 1 : α, k 2 : π → α → α)(schema of list)or type variables <strong>in</strong> both parametric and 1-recursive operator:T π,θ = µα(k 1 : α, k 2 : π → (θ → α) → α)(schema of tree),Instantiations of these schemas may be N = N(0, s) = µα(0 : α, s : α → α (naturalnumbers), N ′ = N(0 ′ , s ′ ) (a “copy” of N), L(N ′ ) = L N ′(nil, cons) (lists over N ′ with<strong>standard</strong> names of constructors), T(N, N) = T N,N (leaf, node) (<strong>in</strong>f<strong>in</strong>itely branch<strong>in</strong>gtree over N), T N,N ′(leaf ′ , node ′ ) etc.5.1.2 TermsThe terms of our systems are those of the simply <strong>typed</strong> λ-<strong>calculus</strong> extended byconstructor constants from Const and iteration operators (iterators) ⦇ −→ t ⦈ µ,τ <strong>for</strong> an<strong>in</strong>ductive type µ and a type τ (µ stands <strong>for</strong> the source and τ <strong>for</strong> the target type).The set of terms Tm is generated by the follow<strong>in</strong>g gram-Def<strong>in</strong>ition 5.3 (Terms).mar:Tm ∋ r, s, t ::= x | λx τ r | (r s) | c k | ⦇ −→ t ⦈ µ,τwith x ∈ Var, c k ∈ Const and τ, µ ⊆ Ty.


102 5. Inductive TypesDef<strong>in</strong>ition 5.4 (Typ<strong>in</strong>g).the typ<strong>in</strong>g relation is def<strong>in</strong>ed by(x, ρ) ∈ ΓΓ ⊢ x : ρ (Var)Γ, x : ρ ⊢ r : σΓ ⊢ λx ρ .r : ρ → σ (→I) Γ ⊢ s : ρ Γ ⊢ r : ρ → σΓ ⊢ rs : σ(→E)(c k : κ−→ ρ ,−→ σ (α) ∈ µ) Γ ⊢ −→ r : κ − −→ ρ ,−→ σ(µ)Γ ⊢ c k−→ r : µ(µI)µα ( −−−−−−−→ c : κ−→ ρ ,−→ σ (α)) = µΓ ⊢ ⦇ −→ t ⦈ µ,τ : µ → τΓ ⊢ −−−−−−−→ t : κ−→ ρ ,−→ σ (τ)(µE)An argument of a constructor is called parameter argument if its type is a parametricoperator and recursive argument if its type is a recursive operator.Example 18. Let be given the follow<strong>in</strong>g <strong>in</strong>ductive types µ = N, L(ρ), T(ρ, σ) obta<strong>in</strong>edby <strong>in</strong>stantiation of the schema <strong>in</strong> the previous example on types ρ and σ, and a typeτ to be the “target-type” <strong>in</strong> the typ<strong>in</strong>g rule (µE) above. The types of the iteratorterms −→ t (step types) must be:• τ and τ → τ <strong>in</strong> case of N;• τ and ρ → τ → τ <strong>in</strong> case of lists L(ρ);• τ and ρ → (σ → τ) → τ <strong>in</strong> case of trees T(ρ, σ).Their particularly simple <strong>for</strong>m is due to the use of iteration (as opposed to primitiverecursion where the step type should conta<strong>in</strong> also the types of the arguments of theconstructor).5.1.3 ReductionsTo def<strong>in</strong>e a capture avoid<strong>in</strong>g substitution, we beg<strong>in</strong> by def<strong>in</strong><strong>in</strong>g a contextual substitution,which will allow us to def<strong>in</strong>e renam<strong>in</strong>g of bound variables (α-conversion).


5.1 System 103Def<strong>in</strong>ition 5.5 (contextual substitution). Given a list of dist<strong>in</strong>ct variables −→ x =x 1 , . . . , x n and of terms −→ r = r 1 , . . . r n of same length, the effect of the contextualsubstitution [ −→ x / −→ r ] is def<strong>in</strong>ed by <strong>in</strong>duction on Tm as follows:{x[ −→ xr/ −→ i if x = x i ∧ x i ∈ −→ x ,r ] ::=x otherwise{(λx.r)[ −→ xλx.r[/ −→ r ] ::=x 1,...,x i−1 ,x i+1 ,...x n/r1 ,...,r i−1 ,r i+1 ,...,r n] if x = x i ∧ x i ∈ −→ xλx.r[ −→ x / −→ r ]otherwise(rs)[ −→ r / −→ x ] ::=(r[ −→ r / −→ x ])(s[ −→ r / −→ x ])⦇ −→ t ⦈ µ,τ [ −→ s / −→ y ] ::= ⦇ −−−−→ t[ −→ s / −→ y ]⦈ µ,τThe α-conversion is a congruence on the terms, i.e., an equivalence relationcontextually closed, we def<strong>in</strong>e there<strong>for</strong>e here the notion of contextual closure.Def<strong>in</strong>ition 5.6 (contextual closure). A conversion relation = R is contextuallyclosed if the follow<strong>in</strong>g rules hold:r = R srt = R st (= R-AppL)r = R str = R ts (= R-AppR)r = R sλx.r = R λx.s (= R-ξ)t = R t ′⦇ −→ r , t, −→ s ⦈ µ,τ = α ⦇ −→ r , t ′ , −→ s ⦈ µ,τ (= R-It)Def<strong>in</strong>ition 5.7 (α-conversion). The α-conversion = α is the smallest congruencerelation generated from the follow<strong>in</strong>g axiom:λx.r = α λy.r[ x /y]y ∉ FV(r)Now that we have def<strong>in</strong>ed α-conversion, we are able to def<strong>in</strong>e correct (or captureavoid<strong>in</strong>g) substitution.Def<strong>in</strong>ition 5.8 (correct substitution). Simultaneous (correct) substitution of terms−→ s to variables−→ −→y <strong>in</strong> a term t, t{ s / −→ y } is def<strong>in</strong>ed by:r{ −→ x / −→ s } = r ′ [ −→ x / −→ s ]where r = α r ′ and no bound variable of r ′ is free <strong>in</strong> a term s ∈ −→ sWe will now def<strong>in</strong>e the reductions of the systems which are relations betweenterms typable with a same type <strong>in</strong> a same context. As a rule of thumb, to lightennotations, we will neither precise the type nor the context <strong>in</strong>volved if they can beeasily <strong>in</strong>ferred.


104 5. Inductive TypesWe def<strong>in</strong>e the relation of β-reduction by the fol-Def<strong>in</strong>ition 5.9 (β-reduction).low<strong>in</strong>g rule:(λx τ . r) s ↦−→ β r{ s /x} (↦−→ β )We def<strong>in</strong>e the relation of η-expansion by the fol-Def<strong>in</strong>ition 5.10 (η-expansion).low<strong>in</strong>g rule:r ↦−→ η λx ρ . r x (↦−→ η )where r : ρ → σ, r is not an abstraction, x ∉ FV(r).The condition that r is not an abstraction rules out a source of <strong>non</strong>-term<strong>in</strong>ation.The usual restriction stat<strong>in</strong>g that r should not appear <strong>in</strong> applicative position (thiswould also causes <strong>non</strong>-term<strong>in</strong>ation) is <strong>in</strong>corporated <strong>in</strong> the def<strong>in</strong>ition of one-stepreduction below.We will def<strong>in</strong>e two variants of the reduction <strong>for</strong> iteration; first the traditionalone:Def<strong>in</strong>ition 5.11 (ι-reduction). Let µ ≡ µα ( c −−−−−−−→ : κ−→ ρ ,−→ σ (α)), c k : κ−→ ρ ,−→ σ (α) ∈ µ, andκ ≡ −→ ρ → ( −→ σ i → α) 1<strong>in</strong> → α over α <strong>in</strong> µ. Given a term c−→k p−→ r , where−→ p (withp i of type ρ i ) denotes the parameter arguments and −→ r (with r i of type −→ σ i → µ)the recursive arguments, and the terms −→ t of step type −−−−−→κ−→ ρ ,−→ σ (τ), the ι-reduction isdef<strong>in</strong>ed by:(ι)⦇ −→ t ⦈ µ,τ (c kµ−→ p−→ r ) ↦−→ι t k−→ p−−−−−−−−→(⦇ −→ t ⦈ µ,τ ◦ r) = t k−→ p−−−−−−−−−−−−−→(λ −→ x .⦇ −→ t ⦈ µ,τ (r −→ x )) .This reduction may create β-redexes. Obvious redexes appear if the iterationterms t k above is an abstraction λ −→ y .s. Moreover if an abstracted variable y ∈ −→ ycorrespond<strong>in</strong>g to a 1-recursive argument is <strong>in</strong> applicative position <strong>in</strong>side this iterationterm, this too will produce subsequent a β-redex (it will be substituted by a termλ −→ x ⦇ −→ t ⦈ µ,τ (r −→ x ) ∈ −−−−−−−−−−−−−→(λ −→ x .⦇ −→ t ⦈ µ,τ (r −→ x )) ).S<strong>in</strong>ce our system is equipped with η-expansion, one can require functional iterationterms to be abstractions and 1-recursive variables <strong>in</strong>side iteration terms to beapplied as a pre-condition and then def<strong>in</strong>e a modified ι-reduction carry<strong>in</strong>g out allthese adm<strong>in</strong>istrative β-reductions <strong>in</strong> one step.We beg<strong>in</strong> by def<strong>in</strong><strong>in</strong>g sets of terms It( −→ y ) where variables −→ y , meant to correspondto 1-recursive arguments <strong>in</strong> an iteration term, are <strong>in</strong> applicative position.Def<strong>in</strong>ition 5.12. Let <strong>typed</strong> variables −→ y = y −→ σ 1 →τ1 , . . . , y −→ σ n→τn be given, we def<strong>in</strong>e<strong>in</strong>ductively the set of terms It( −→ y ) where these variables always appear applied to amaximal number of argumentsIt( −→ y ) ∋ t ::= (y i−→ t ) τ | x | λz.t | tt | ⦇ −→ t ⦈ | c k−→ t (x ∉−→ y )


5.1 System 105To carry out adm<strong>in</strong>istrative reductions due to variables correspond<strong>in</strong>g to 1-recursive argument <strong>in</strong> applicative position, we need to def<strong>in</strong>e first a modified substitution.Def<strong>in</strong>ition 5.13 (Modified substitution). The effect of modified simultaneous substitutiont〈 u•r −→/ −→ y 〉 of variables −→ y by compositions of −→ u and −→ r (with u i : µ i → τ,r i : −→ σ i → µ i ) <strong>in</strong>to a term t ∈ It( −→ y ), is def<strong>in</strong>ed recursively on It( −→ y ):−→ −→y i t 〈 u•r / −→ y 〉 ::= u(r −−−−−→t〈 u•r −→/ −→ y 〉)x〈 u•r/ −→ −→ y 〉 ::= x(λz.t)〈 u•r −→/ −→ y 〉 ::= λz.t〈 u•r −→/ −→ y 〉(tt)〈 u•r −→/ −→ y 〉 ::= t〈 u•r −→/ −→ y 〉t〈 u•r −→/ −→ y 〉⦇ −→ t ⦈〈 u•r −→/ −→ y 〉 ::= ⦇ −−−−−→t〈 u•r −→/ −→ y 〉⦈−→ −→ −−−−−→c k t 〈 u•r / −→ y 〉 ::= c k t〈 u•r −→/ −→ y 〉(At the third l<strong>in</strong>e α-conversion may be needed.)(the essential case)where z ∉ −→ y and z ∉ F V ( −−→ u • r)Def<strong>in</strong>ition 5.14 (ι 2 -reduction). Let µ ≡ µα ( c −−−−−−−→ : κ−→ ρ ,−→ σ (α)), c k : κ−→ ρ ,−→ σ (α) ∈ µ, andκ ≡ −→ ρ → ( −→ σ i → α) 1<strong>in</strong> → α over α <strong>in</strong> µ. Let a term c−→k p−→ r be given, where−→ p (pi of type ρ i ) denote the parameter arguments and −→ r (r i of type −→ σ i → µ)the recursive arguments. Let the terms −→ t of step-type (iteration terms) be fullyη-expanded externally, i.e., t k = λ −→ x ρ−−−→ y −→ σ i →τ .s k , and moreover s k ∈ It( −−−→y −→ σ i →τi ). Underthese conditions the ι 2 -reduction is def<strong>in</strong>ed by:⦇. . . , λ −→ x −→ y .s k ⦈, . . . (c k−→ p−→ r ) ↦−→ι s k { −→ p / −→ x }〈 −−−→ ⦇t⦈•r/ −→ y 〉Example 19 (multiplication by 2). Although primitive recursion is encodable <strong>in</strong> oursystem, <strong>for</strong> sake of simplicity we present here functions def<strong>in</strong>able us<strong>in</strong>g iteration,• the multiplication by 2 of natural numbers:×2 ::= ⦇0, λx.s(sx)⦈the associated ι 2 -reduction <strong>for</strong> the term s t is:(×2)(s t) −→ ι2 s(s(×2 t))• the po<strong>in</strong>twise multiplication by two of a list of natural numbermap×2 ::= ⦇nil, λxy.cons(×2 x)y⦈the associated ι 2 -reduction <strong>for</strong> the term cons a l is:map×2(cons a l) −→ ι2 cons (×2 a) (map×2 l)


106 5. Inductive Types• the selection of even branches <strong>in</strong> a tree can be def<strong>in</strong>ed as:sel2 ≡ ⦇leaf, λxy.node x (λz.y(×2 z))⦈the associated ι 2 -reduction <strong>for</strong> the term node t f is:sel2(node t f) −→ ι2 node t (λz.sel2(f(×2 z)))The reductions def<strong>in</strong>ed above rewrite redex appear<strong>in</strong>g at the exterior of the term,these reductions are extended to subterms via a contextual closure <strong>in</strong>corporat<strong>in</strong>g theusual restriction on applicative position <strong>in</strong> η-expansion.Def<strong>in</strong>ition 5.15 (One-step Reduction).as the smallest relation such that:The One-step reduction −→ R is def<strong>in</strong>edr ↦−→ R r ′r −→ R r ′ (R-Ax)r −→ R r ′ r ̸↦−→ η r ′rs −→ R r ′ s(R-AppL)s −→ R s ′rs −→ R rs ′ (R-AppR)r −→ R r ′λx.r −→ R λx.r ′ (R-ξ)t −→ R t ′⦇ −→ r , t, −→ s ⦈ −→ R ⦇ −→ r , t ′ , −→ s ⦈ (R-Rec)R can be <strong>for</strong> example β, η, ι, ι 2 .Notation 20. The transitive closure of −→ R will be written −→ +R , its reflexive transitiveclosure −→ R , its <strong>in</strong>verse relation ←− R . The composition {(r, s) | ∃ t, r −→ R∗t ∧ t −→ S s} of two reduction relations −→ R and −→ S will be written −→ R ; −→ Stheir union {(x, y) | x −→ R y ∨x −→ S y} will be denoted by −→ RS . Alternativelywe will use the name of the relations so that R, R + , R ∗ , R −1 , R; S, RS will stand <strong>for</strong>+ ∗−→ R , −→ R , −→ R , ←− R , (−→ R ; −→ S ), −→ RS respectively. The reduction relationR \ S stands <strong>for</strong> the set of pair (r, s) ∈ R but (r, s) ∉ S.The R-derivations (sequences of terms such that two successive terms are <strong>in</strong> a∞one step reduction relation −→ R ) will be denoted by d, e.... The expression t −→ Rwill denote an <strong>in</strong>f<strong>in</strong>ite derivation beg<strong>in</strong>n<strong>in</strong>g at t.5.2 Extended Conversions5.2.1 General ResultsThe rewrit<strong>in</strong>g system generated from β, η and ι reductions has been proven to beconvergent, i.e., strongly normaliz<strong>in</strong>g and confluent, <strong>in</strong> numerous works (<strong>for</strong> example[23]) and we will not repeat the proof here.Theorem 2. The reduction βηι is convergent.


5.2 Extended Conversions 107The system with the alternative ι-reduction ι 2 is proved convergent us<strong>in</strong>g a (particularlysimple) embedd<strong>in</strong>g (i.e.,, a reduction preserv<strong>in</strong>g encod<strong>in</strong>g of a system with<strong>in</strong>another).Theorem 3. 1. The system equipped with βηι 2 -reduction is embeddable <strong>in</strong> he oneequipped with βηι-reduction,2. the reduction βηι 2 is convergent.Proof. 1. The embedd<strong>in</strong>g is the identity on terms and one βηι 2 -reduction is simulatedby one ι-reduction followed by several β-reductions.2. The embedd<strong>in</strong>g (1) above means that <strong>for</strong> each reduction <strong>in</strong> βηι 2 there existsa sequence of reductions <strong>in</strong> βηι, hence βηι 2 is strongly normaliz<strong>in</strong>g, otherwiseβηι would not be strongly normaliz<strong>in</strong>g.If t is a normal <strong>for</strong>m <strong>in</strong> βηι, then t is a normal <strong>for</strong>m <strong>in</strong> βηι 2 (the reductions ofβηι 2 apply on redexes of βηι under some restrictions). If t is a normal <strong>for</strong>m <strong>in</strong>βηι 2 , then t is a normal <strong>for</strong>m <strong>in</strong> βηι. The set of normal <strong>for</strong>m <strong>for</strong> βηι and βηι 2+are the same. Moreover −→ βηι2 is a subrelation of βηι, hence the set of normal<strong>for</strong>m of a term t are the same <strong>in</strong> the two systems, hence βηι 2 is confluent.5.2.2 Inductive Type Schemas as FunctorsWe will now def<strong>in</strong>e a subcategory I of the whole system <strong>for</strong> which we will provethe functorial laws of <strong>in</strong>ductive types to be decidable. The set of object I 0 of thiscategory I will be <strong>in</strong>ductive types and the set I 1 of arrows is constituted of identityterms, iterators, and compositions thereof.Def<strong>in</strong>ition 5.16. The subset I 0 is the set of all <strong>in</strong>ductive types µα ( −−−−−−−→ c : κ−→ ρ ,−→ σ (α)).The subset of typable terms I 1 : ρ → σ <strong>for</strong> ρ, σ ∈ I 0 is def<strong>in</strong>ed as follows:I 1 ∋ a, a ′ ::= λx µ .x | ⦇ −→ t ⦈ | a ◦ a ′


108 5. Inductive TypesDef<strong>in</strong>ition 5.17 (Instantiation of schemas and copy of <strong>in</strong>ductive type).The <strong>in</strong>stantiationfunction Cp 0 S : Const |−→ k | × I |−→ π |+| −→ θ |0 → I 0 <strong>for</strong> a schema of <strong>in</strong>ductive typeS = µα( −−−−−−−−→ k : κ −→π −→ , θ(α)) is def<strong>in</strong>ed by:Cp 0 S( −→ c , −→ ρ , −→ σ ) ::= µα( −−−−−−−→ c : κ−→ ρ ,−→ σ (α)).If moreover, given <strong>in</strong>ductive types −→ ρ ′ , −→ σ ′ there exists terms f, f ′ <strong>in</strong> I 1 , with typ<strong>in</strong>gf i : ρ i → ρ ′ i and f i ′ : σ i ′ → σ i , we def<strong>in</strong>e the copy function Cp 1 S tak<strong>in</strong>g these termsand the relabell<strong>in</strong>g function l : −→ c ↦→ −→ c ′ as arguments by:Cp 1 S(l, −→ f , −→ f ′ ) := ⦇ −→ t ⦈ : Cp 0 S( −→ c , −→ ρ , −→ σ ) → Cp 0 S( −→ l(c),−→ ρ ′ , −→ σ ′ )with t k ∈ −→ t given by:t k ::= λ −→ x ρ−−−→ y −→ σ i →ϕ ′ · c ′ k−−−→−−−−−−−→◦ x (f) λ −→ z .y −−−→ ◦ z (f ′ )where the function ◦ x (f k ) which returns a β-reduced <strong>for</strong>m of f k x is def<strong>in</strong>ed recursively:• ◦ x (λx µ .x) = x• ◦ x (⦇ −→ t ⦈) = ⦇ −→ t ⦈x• ◦ x (a ◦ a ′ ) = ◦ x (a){ ◦x(a′ ) /x}With the notation of the def<strong>in</strong>ition above and given constructor names −→ c ′′ , types−→ ρ ′′ , −→ σ ′′ , relabell<strong>in</strong>g functions l ′ : −→ c ′ → −→ c ′′ , and terms g : −→ ρ → −→ ρ ′′ ∈ I 1 and g ′ : −→ σ ′′ →−→ σ ∈ I1 , the follow<strong>in</strong>g equalities are provable:Cp 1 S(l, −→ g , −→ g ′ ) ◦ Cp 1 S(l, −→ f , −→ f ′ ) = Cp 1 S(l ′ ◦ l, −−→ g ◦ f, −−−→ f ′ ◦ g ′ )Cp 1 S(id, −→ id , −→ id ) = id Cp 0SThis means that with respect to an extensional model the pair (Cp 0 S, Cp 1 S) def<strong>in</strong>es afunctor. This result is well known, and a categorical proof (of a generalisation of thisresult) can be found <strong>for</strong> example <strong>in</strong> Varmo Vene’s doctoral thesis ([89]). However,these equalities do not hold w.r.t. the conversion relation. We shall extend thereduction relation <strong>in</strong> order to obta<strong>in</strong> a functor w.r.t. the conversion relation whilepreserv<strong>in</strong>g confluence and strong normalization of the underly<strong>in</strong>g rewrite system.In the follow<strong>in</strong>g we will lighten the notation and omit all unnecessary material.By analogy with category theory we will write Cp S <strong>in</strong>stead of Cp 0 S, Cp 1 S and oftenjust Cp when S will be clear from the context. In the same way we will not writethe relabell<strong>in</strong>g functions which we will not consider as part of the <strong>calculus</strong>.


5.3 Ma<strong>in</strong> Theorems 109Def<strong>in</strong>ition 5.18 (χ-reductions).The χ-reductions are given by:Cp( −→ g , −→ g ′ )(Cp( −→ f , −→ f ′ )t) ↦−→ χ◦ Cp( −−→ g ◦ f, −−−→ f ′ ◦ g ′ )tCp( −→ id , −→ id )t ↦−→ χid tExample 20. The function map×2 of the previous example can be written as Cp L (×2).The χ ◦ -reduction <strong>for</strong> the composition of two functions map×2 states that doubl<strong>in</strong>gevery element of a list from a list where every element has already been doubledshould reduce to doubl<strong>in</strong>g the double of every element of the <strong>in</strong>itial list.Cp L (×2)Cp L (×2)t −→ χ◦ Cp L (×2 ◦ ×2)tThe function sel2 of the previous example can be written as Cp T (id, ×2). The χ ◦ -reduction <strong>for</strong> the composition of two functions sel2 states that select<strong>in</strong>g even branchesfrom a tree where one has already selected even branches should reduce to select<strong>in</strong>gthe even branches of the even branches of this tree.Cp T (id, ×2)(Cp T (id, ×2)t) −→ χ◦ Cp T (id, ×2 ◦ ×2)tAn advantage is, <strong>for</strong> example, <strong>for</strong> a function ×4, <strong>in</strong> order to prove that we haveCp T (id, ×2)(Cp T (id, ×2)t) = Cp T (id, ×4)t orCp L (×2)Cp L (×2) = Cp L (×4),one only has to prove ×2 ◦ ×2 = ×4.Remark 18. The restriction of the function Cp to functions generated by iteratorsor compositions thereof is clearly a limitation of our results. Although our resultsare still <strong>in</strong>terest<strong>in</strong>g <strong>in</strong> themselves, an extension to the the general case is a topic ofcurrent research.5.3 Ma<strong>in</strong> TheoremsIn this sections we will derive the convergence of the system augmented by the χ ◦and the χ id reductions by us<strong>in</strong>g modular properties of abstract reduction systems.5.3.1 AdjournmentDef<strong>in</strong>ition 5.19 (Adjournment). Given two reduction relations S and R, we saythat S is adjournable w.r.t. R <strong>in</strong> a derivation d, ifd = t −→ S −→ R ∞−→ RS ⇒ ∃ e = t −→ R ∞−→ RSIf S is adjournable w.r.t. to R <strong>in</strong> all derivation d, then we say that S is adjournablew.r.t. to R.


110 5. Inductive TypesRemark 19. S is adjournable w.r.t. R <strong>in</strong> particular <strong>in</strong> the case: −→ S ; −→ R ⊆−→ R; −→ RS . The notion of adjournability is traditionally expressed with this weakercondition (where d is not taken <strong>in</strong>to account) (cf. [7]).Lemma 22 (Adjournment). If R and S are strongly normaliz<strong>in</strong>g and S is adjournablew.r.t. to R then RS is strongly normaliz<strong>in</strong>g.Proof. Let us suppose that there is an <strong>in</strong>f<strong>in</strong>ite RS-derivation beg<strong>in</strong>n<strong>in</strong>g from a termt. As R and S are strongly normaliz<strong>in</strong>g, this derivation consists of an alternation off<strong>in</strong>ite R- and S-derivations. In particular the derivation is of the <strong>for</strong>mt −→ X t ′ −→ S −→ R ∞−→ RSwith an <strong>in</strong>itial fragment X = R ∗ or X = R ∗ S + . We can adjourn the derivationfollow<strong>in</strong>g t ′ to obta<strong>in</strong> a derivationt −→ X t ′ −→ R ∞−→ RSThe iteration of this process will <strong>in</strong>f<strong>in</strong>itely <strong>in</strong>crease the number of R-reductions <strong>in</strong>the beg<strong>in</strong>n<strong>in</strong>g, preserv<strong>in</strong>g the <strong>in</strong>f<strong>in</strong>ite tail and we shall have a contradiction with theassumption that R is strongly normaliz<strong>in</strong>g.5.3.2 Convergence of βηι 2 χ ◦Theorem 4 (Strong normalization of χ ◦ ). The χ ◦ -reduction is strongly normaliz<strong>in</strong>gand adjournable with respect to βηι 2 -reduction.To ease the exposition we will need to s<strong>in</strong>gle out a particular occurrence of asubterm t ′ of a term t, we will then use the notation C[t ′ ] <strong>for</strong> the term t, <strong>in</strong> thisnotation C is called a context.This notation can be def<strong>in</strong>ed <strong>for</strong>mally by add<strong>in</strong>g an extra symbol [] to the def<strong>in</strong>itionof terms, this symbol [] called a hole can be considered as a special variablenot allowed to be bound.Def<strong>in</strong>ition 5.20 (context).grammar:A context with multiple occurrences K is given by theK, L ::= [] | x | λx τ K | (K L)A simple context C (or just context) is a context with multiple occurrences K wherethe symbol [] occurs once and only once. The notation C[t] is an abbreviation <strong>for</strong>the contextual substitution C[ [] /t] of a term t <strong>in</strong> the simple context C.


5.3 Ma<strong>in</strong> Theorems 111Proof. S<strong>in</strong>ce χ ◦ is strongly normaliz<strong>in</strong>g (by a simple argument on the size of theterm), it rema<strong>in</strong>s to show that χ ◦ is adjournable w.r.t. βηι 2 . It is adjournable ifand only if it is adjournable w.r.t. all <strong>in</strong>f<strong>in</strong>ite derivations d =−→ χ◦ −→ βηι2 d ′ . Weconsider the reduction −→ βηι2 follow<strong>in</strong>g the first −→ χ◦ -segment <strong>in</strong> d.Let us consider a χ ◦ -reduction followed by a ι 2 -reduction. In this case, theadjournment of χ ◦ -reduction with respect to traditional ι-reduction is not possible.C[Cp−→−→g −→ , g ′ (Cp−→ −→ f , f ′c k p−→ r )] −→χ◦ C[Cp −→ −−−→ g◦f,c−→f ′ ◦g ′ k p−→ r ]−−−−−−−−−→ −−−−−−−−−−−−→−→ ι2 C[c k ◦ x (g ◦ f){ p /x} λ −→ z .(y −−−−−−→ ◦ z (f ′ ◦ g ′ ))〈 −−−−−−−−−−→Cp −−→ −−−→g◦f, f ′ ◦g ′•r / −→ y 〉]−−−−−→ −−−−−−−−−−−−−−−−−−−→≡ C[c k ◦ p (g ◦ f) λz.Cp −→ −−−→ g◦f,(r −−−−−−→ ◦f ′ ◦g ′ z (f ′ ◦ g ′ ))]It can be adjourned as follows:C[Cp −→g ,−→ g ′ (Cp−→ f ,−→ f ′c k−→ p−→ r )]−→ ι2≡−→ ι2≡−→ β−→ χ◦−−−−−−−→ −−−−−−−−−→C[Cp −→g −→ , g ′ (c k ◦ x (f){ p /x} λ −→ z .(y −−−→ ◦ z (f ′ ))〈 −−−−−−−→ Cp −→f −→, f′ •r / −→ y 〉)]−−−→ −−−−−−−−−−−−−−−−→C[Cp −→g −→ , g ′ (c k ◦ p (f) λ −→ z .(Cp−→ −→ f , f ′(r −−−→ ◦ z (f ′ ))))]−−−−−−−−−→ −−−−−−−→C[c k ◦ x (g){ ◦p(f) /x} λ −→ z .y −−−→ ◦ z (g ′ −−−−−−−−−−−−−−−−−−−−−−−−−→)〈 Cp −→ −→g , g′ •(λ−→ −−−→z .(Cp −→f −→, f′ (r◦ z(f ′ )))) / −→ y 〉]−−−−−→ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−→C[c k ◦ p (g ◦ f) λ −→ z .Cp −→g −→ , g ′ ((λ −→ z .(Cp−→ −→ f , f ′(r −−−→ ◦ z (f ′ )))) −−−→ ◦ z (g ′ ))]−−−−−→ −−−−−−−−−−−−−−−−−−−−−−−−→C[c k ◦ p (g ◦ f) λ −→ z .Cp −→g −→ , g ′ (Cp−→ −→ f , f ′(r −−−−−−→ ◦ z (f ′ ◦ g ′ )))]−−−−−→ −−−−−−−−−−−−−−−−−−−→C[c k ◦ p (g ◦ f) λz.Cp −→ −−−→ g◦f,(r −−−−−−→ ◦f ′ ◦g ′ z (f ′ ◦ g ′ ))]For the other cases, the adjournment method works without complication. (Wewill abbreviate <strong>in</strong> the follow<strong>in</strong>g Cp −→g −→ , g ′ (Cp−→ −→ f , f ′t) and Cp −→ −−−→ g◦f,t by Lf ′ ◦g ′ χ◦ (t) andR χ◦ (t)):1. For β-conversion:(a) For C ≡ C[(λx · p[L χ◦ (t)]) q], we haveC −→ χ◦ C[(λx · p[R χ◦ (t)]) q] −→ β→ C[p[R χ◦ (t)]{ q /x}]In this case, we can adjourn χ ◦ byC −→ β→ C[p[L χ◦ (t)]{ q /x}] −→ χ◦ C[p[R χ◦ (t)]{ q /x}](b) For C ≡ C[(λx · p) q[L χ◦ (t)]], we haveC −→ χ◦ C[(λx · p) q[R χ◦ (t)]] −→ β→ C[p{ q[Rχ◦(t)] /x}]In this case, we can adjourn χ ◦ byC −→ β→ C[p{ q[Lχ◦ (t)] /x}]∗−→ χ◦ C[p{ q[Rχ◦ (t)] /x}]


112 5. Inductive Types2. For η-conversion, there is no <strong>in</strong>terest<strong>in</strong>g overlap with χ ◦ -conversion as we havethe follow<strong>in</strong>g facts about a χ ◦ -redex L χ◦ ():• Cp−→ f ,−→ f ′ and Cp −→g ,−→ g ′ are iterators ;• and t and L χ◦ (t) <strong>in</strong>habit an <strong>in</strong>ductive type.Theorem 5 (Strong normalization of βηι 2 χ ◦ ). The reduction βηι 2 χ ◦ is stronglynormaliz<strong>in</strong>g.Proof. As the reductions βηι 2 and χ ◦ are strongly normaliz<strong>in</strong>g and χ ◦ is adjournablewith respect the reduction βηι 2 , we can apply the adjournment lemma (22).By Newman’s lemma (see [74] <strong>for</strong> the orig<strong>in</strong>al proof), a strongly normaliz<strong>in</strong>g andlocally confluent system is confluent, so we need only to check local confluence.Theorem 6 (Confluence of βηι 2 χ ◦ ). The reduction βηιχ ◦ is confluent.Proof. As βηι 2 χ ◦ -conversion is strongly normaliz<strong>in</strong>g, it is enough to show that βηι 2 χ-conversion is locally confluent, by Newman’s Lemma. As βηι 2 - and χ ◦ -<strong>conversions</strong>are both confluent, the proof is by verification (case analysis) that ←− χ◦ ; −→ βηι2 ⊆∗∗←− βηι2 χ ◦; −→ βηι2 χ ◦.Theorem 7 (Convergence of βηι 2 χ ◦ ). The reduction βηι 2 χ ◦ is convergent.Proof. The reduction βηι 2 χ ◦ is strongly normaliz<strong>in</strong>g by theorem (5) and convergentby theorem (6).5.3.3 Pre-adjusted AdjournmentWe would like to be able to adjourn χ id -reduction w.r.t. ι 2 -reduction.there is a difficulty, let us consider an example:However,Example 21. Try<strong>in</strong>g to adjourn directly the follow<strong>in</strong>g derivation, where node is theconstructor <strong>for</strong> arbitrary branch<strong>in</strong>g tree:Cp−→ id ,−→ id(node p x) −→ χid node p x −→ βηι node p ′ xresults <strong>in</strong> first apply<strong>in</strong>g a ι 2 -contraction and then a χ id -contraction:Cp−→ −→ id , id(node p x) −→ ι2 node x λz.yz{ p /x}〈 Cp−→ id , −→ id •x /y〉≡ node p λz.Cp−→ −→ id , id(xz)node p λz.xz,−→ χidand there is no way to close the <strong>for</strong>k with the <strong>in</strong>itial derivation.


5.3 Ma<strong>in</strong> Theorems 113The solution is to <strong>in</strong>corporate some η-expansion <strong>in</strong> the first derivation be<strong>for</strong>eapply<strong>in</strong>g the adjournment lemma.Def<strong>in</strong>ition 5.21 (<strong>in</strong>sertability). Given two reduction relation R, T , with T ⊂ R,T is said to be <strong>in</strong>sertable <strong>in</strong> R if there exists a relation S on the support of R withT ⊆ S and the two follow<strong>in</strong>g conditions hold:S −1 ; (R \ T ) ⊆ R + ; S −1S −1 ; R ⊆ T ∗ ; S −1S R + S T ∗ R\TSRSLemma 23 (<strong>in</strong>sertion). Given two reduction relations R, T such that T is <strong>in</strong>sertable<strong>in</strong> R and T is strongly normaliz<strong>in</strong>g. If there exists an <strong>in</strong>f<strong>in</strong>ite derivation d from tand an object t ′ with t → T t ′ , then there exists an <strong>in</strong>f<strong>in</strong>ite derivation d ′ from t ′ .Proof. As T is strongly normaliz<strong>in</strong>g, d conta<strong>in</strong>s <strong>in</strong>f<strong>in</strong>itely many R \ T -reductions(possibly <strong>in</strong>terleaved with f<strong>in</strong>ite sequences of T -reductions). As T is <strong>in</strong>sertable <strong>in</strong> Rthere exists a relation S with (t, t ′ ) ∈ T ⊆ S, and we can construct a derivation d ′where every reduction R \ T of d are repercussed along S by a R + -reduction <strong>in</strong> d ′ .Hence R + conta<strong>in</strong>s <strong>in</strong>f<strong>in</strong>itely many R + -reductions (possibly <strong>in</strong>terleaved with f<strong>in</strong>itesequences of T ∗ -reductions) and is there<strong>for</strong>e <strong>in</strong>f<strong>in</strong>iteDef<strong>in</strong>ition 5.22 (Conditional Adjournment). Let R, S be reduction relations, an<strong>in</strong>f<strong>in</strong>ite derivation d = t −→ S −→ ∞R −→ RS beg<strong>in</strong>n<strong>in</strong>g with t and P a predicate on theterms. Then S is adjournable w.r.t. R <strong>in</strong> d under condition P, ifd = t −→ S −→ R ∞−→ RS ∧P(t) ⇒ ∃ e = t −→ R ∞−→ RS ,S is adjournable w.r.t. R under condition P, if S is adjournable w.r.t. R <strong>in</strong> d undercondition P <strong>for</strong> all d.We now <strong>in</strong>troduce the notion of realisation of a condition by a reduction relationT , which says that start<strong>in</strong>g from some term t we will always f<strong>in</strong>d after a f<strong>in</strong>ite numberof reductions from T a term t ′ satisfy<strong>in</strong>g the condition.Def<strong>in</strong>ition 5.23 (realization). Let T be a reduction relation and P a predicate onthe terms. T realises P <strong>for</strong> t if ∃ t ′ , t → ∗ T t′ ∧ P(t ′ ). T realizes P if T realizes P <strong>for</strong>all terms.Lemma 24 (pre-adjusted adjournment). Given reductions relations R, S, T withS, T ⊆ R, S is adjournable with respect to R under condition P and T is <strong>in</strong>sertable<strong>in</strong> R, strongly normaliz<strong>in</strong>g and realizes P, then S is adjournable w.r.t. R.


114 5. Inductive TypesProof. Given a derivation d = t −→ S −→ R ∞−→ RS beg<strong>in</strong>n<strong>in</strong>g with t,• either P(t) and then S is adjournable w.r.t. R <strong>in</strong> d• or as T realizes P, ∃ t ′ , t → + T t′ ∧ P(t ′ ). But T is <strong>in</strong>sertable and stronglynormaliz<strong>in</strong>g so by lemma 23, there exists an <strong>in</strong>f<strong>in</strong>ite derivation from t ′ . Hence,as T ⊆ R S is adjournable w.r.t. R.we def<strong>in</strong>e the rewrite rule <strong>for</strong> un-Def<strong>in</strong>ition 5.24 (unrestricted η-expansion η).restricted η-expansion η by:t ↦−→ η λx ρ .tx if t : ρ → σThe one step reduction reduction relation −→ η is def<strong>in</strong>ed as the contextual closureof ↦−→ ηLemma 25 (weak condition <strong>for</strong> <strong>in</strong>sertability). In the def<strong>in</strong>ition of the <strong>in</strong>sertability,if the relation S is the transitive reflexive closure of a reduction relation T ′ , weestablish some sufficient condition <strong>for</strong> T to be <strong>in</strong>sertable. Given reduction relationsR, T, T ′ , if the relation T ′ verifies the two conditions:T ′−1 ; R \ T ⊆ R ∗ ; (R \ T ); R ∗ ; (T ′−1 ) ∗T ′R ∗ R\TR\T T ′∗R ∗ T ′−1 ; T ⊆ R ∗ ; (T ′−1 ) ∗T ′ RT ∗ T ′∗then T is <strong>in</strong>sertable:(T ′−1 ) ∗ ; R \ T ⊆ R + ; (T ′−1 ) ∗ (T ′−1 ) ∗ ; R ⊆ T ∗ ; (T ′−1 ) ∗T ′∗ R\TR + T ′∗T ′∗ RT ∗ T ′∗Proof. cf lemma 6.4 <strong>in</strong> [23].Lemma 26. η-expansion is <strong>in</strong>sertable.


5.3 Ma<strong>in</strong> Theorems 115Proof. Take the transitive reflexive closure of η as relation S <strong>in</strong> the def<strong>in</strong>ition of<strong>in</strong>sertability 5.21.By lemma 25, it is enough to show:←− η ; R\ −→ η ⊆ R ∗ ; R\ −→ η ; R ∗ ; ←− ∗ η ∧ ←− η ; −→ η ⊆ R ∗ ; ←− ∗ ηThe proof is simple and we will only discuss the critical cases (why we take thereflexive transitive closure of η <strong>in</strong>stead of merely η <strong>for</strong> S).• <strong>for</strong> β, there are two <strong>non</strong> trivial cases:C[(λx.r)(λy.sy)]ηC[(λx.r)s] βC[r{ s /x}]β∗ηC[r{ (λy.sy) /x}]As the subterm s can be substituted <strong>in</strong> an applicative position, this case illustratesthe need <strong>for</strong> η to expand a term <strong>in</strong> applicative position. Remark alsothat the variable x can occur several times <strong>in</strong> r or not occurs at all, so thatwe need to take the reflexive transitive closure of η.C[λz.((λxy.r)s)z]ηC[(λxy.r)s] βC[λy.r{ s /x}]β∗ηC[λz.(λy.(r{ s /x}))z]This case illustrates the need <strong>for</strong> the η-expansion to be applicable to a subterm<strong>in</strong> abstraction <strong>for</strong>m.• <strong>for</strong> ι 2 , the situation is similar to β, the η can take place <strong>in</strong> a parameter argument:<strong>for</strong> −→ p = p 0 , . . . , p i , . . . , p n (i ∈ [0, . . . , n]) we write −→ p ′ <strong>for</strong> p 0 , . . . , λx.p i x, . . . , p n .C[⦇ −−−−→ λ −→ x −→ −→y .t⦈c k p′ −→ r ]ηι 2C[⦇ −−−−→ λ −→ x −→ y .t⦈c−→k p−→ r ] C[t k { −→ p ′ / −→ x }〈 −−−−−−−−→⦇λ −→ x −→ y .t⦈•r / −→ y 〉] ι 2∗ηC[t k { −→ p / −→ x }〈 −−−−−−−−→⦇λ −→ x −→ y .t⦈•r / −→ y 〉]


116 5. Inductive Typesor <strong>in</strong> a recursive argument: <strong>for</strong> −→ r = r 0 , . . . , r i , . . . , r n (i ∈ [0, . . . , n]) we write−→ r′<strong>for</strong> r 0 , . . . , λx.r i x, . . . , r n .C[⦇ −−−−→ λ −→ x −→ y .t⦈c−→ −→k p r ′ ]ηC[⦇ −−−−→ λ −→ x −→ y .t⦈c−→k p−→ r ] ι 2ι 2C[t k { −→ p / −→ x }〈 −−−−−−−−→⦇λ −→ x −→ y .t⦈•r / −→ y 〉]C[t k { −→ p / −→ x }〈⦇λ −−−−−−−−→ −→ x −→ y .t⦈•r ′ / −→ y 〉]or <strong>in</strong> the iterator: <strong>for</strong> −→ t = t 0 , . . . , t i , . . . , t n (i ∈ [0, . . . , n]) we note −→ t ′ :=t 0 , . . . , λz.t i z, . . . , t n . The <strong>non</strong> trivial case is i = k:C[⦇ −−−−−→ λ −→ x −→ y .t ′ ⦈c−→k p−→ r ]ηι 2C[⦇ −−−−→ λ −→ x −→ y .t⦈c−→k p−→ r ] C[λz.(t k { −→ p / −→ x }〈⦇λ −−−−−−−−→ −→ x −→ y .t ′ ⦈•r / −→ y 〉)z] ι 2C[t k { −→ p / −→ x }〈 −−−−−−−−→⦇λ −→ x −→ y .t⦈•r / −→ y 〉]∗η∗η5.3.4 Convergence of βηι 2 χ1. χ id -reduction is strongly normal-Theorem 8 (Strong Normalization of χ id ).iz<strong>in</strong>g,2. χ id -reduction is adjournable with respect to βηι 2 χ ◦ under the condition that1-recursive arguments −→ r = r 1 . . . r n of a constructor c −→ p −→ r of type µ are fullyeta-expansed externally, i.e., r i = r ′ i = λ−→ x .(r ′ i−→ x ) µ .proof of theorem 8. We will abbreviate Cp−→ id ,−→ idt by L χid (t)1. For ι 2 -conversion:(a) For C ≡ C[Cp−→ id ,−→ id(c k−→ p−→ r )], by η-<strong>in</strong>sertion we can put the terms−→ r<strong>in</strong> full externally eta-expansed <strong>for</strong>m. We will write r <strong>for</strong> a term r fullyη-expansed externally. We can then always adjournC[Cp−→ id ,−→ id(c k−→ p−→ r )] −→χid C[c k−→ p−→ r ] −→βηι · · ·


5.3 Ma<strong>in</strong> Theorems 117byC[Cp−→ −→ id , id(c−→ −→k p r )] −→ι2 C[(c−→ −−−−−→k x λ −→ z .y −→ z ){ −→ p / −→ x }〈 −−−−−−−→ Cp−→ −→ id , id•r / −→ y 〉]≡ C[c−→ −−−−−−−−−−−→k p λ −→ z .Cp−→ −→ id , id(r −→ z )]−→ ∗ β −→ χ idC[c k−→ p−→ r ](b) For C ≡ C[⦇. . . , λ −→ x −→ y .t r [L χid (s)], . . .⦈ (c k−→ p−→ r )] and−→ t ∈ I t(y−−−→ −→ σi →τ ) (oneremarks that I t(y −−−→ −→ σi →τ ) is stable under ←− χid ), we have three possibilities:i. Either r ≠ k and then we haveC[⦇. . . , λ −→ x −→ y .t r [L χid (s)], . . .⦈ (c−→k p−→ r )]χ idι 2C[⦇. . . , λ −→ x −→ y .t r [s], . . .⦈ (c−→k p−→ r )] C[t k { −→ p /−→ x } 〈 −−−−−−−−−−−−−−−−−−−−−−→(⦇...,λ −→ x −→ y .t r[L χid (s)],...⦈•ri R) / −→ y 〉]∗ι 2χ idC[t k { −→ p / −→ x } 〈 −−−−−−−−−−−−−−−−−−→(⦇...,λ −→ x −→ y .t r[s],...,⦈•ri R) / −→ y 〉]with as many χ id -<strong>conversions</strong> as there are variables −→ y occurr<strong>in</strong>g <strong>in</strong>t k .ii. or r = k, and then• either L χid (s) is a strict subterm <strong>in</strong> t r [L χid (s)]:C[⦇. . . , λ −→ x −→ y .t r [L χid (s)], . . .⦈ (c−→k p−→ r )]χ idι 2C[⦇. . . , λ −→ x −→ y .t r [s], . . .⦈ (c−→k p−→ r )]C[t r [L χid (s)] { −→ p /−→ x } 〈 −−−−−−−−−−−−−−−−−−−−−−→(⦇...,λ −→ x −→ y .t r[L χid (s)],...⦈•ri R) / −→ y 〉]+ι 2χ idC[t r [s] { −→ p / −→ x } 〈 −−−−−−−−−−−−−−−−−→(⦇...,λ −→ x −→ y .t r[s],...⦈•ri R) / −→ y 〉]with as many χ id -<strong>conversions</strong> as there are variable −→ y occurr<strong>in</strong>g<strong>in</strong> t k plus one <strong>for</strong> the L χid (s) occurr<strong>in</strong>g already <strong>in</strong> t r be<strong>for</strong>e ι 2 -reduction.• or L χid (s) is not a strict subterm but the whole term itself. Let usthere<strong>for</strong>e rewrite the orig<strong>in</strong>al term as C[⦇. . . , λ −→ x −→ y .L χid (s), . . .⦈ c k−→ p−→ r ].Then we haveC −→ χid C[⦇. . . , λ −→ x −→ y .s, . . .⦈ c k−→ p−→ r ] −→ι2 C[s](because L χid (s) <strong>in</strong>habits necessarily an <strong>in</strong>ductive type, there<strong>for</strong>ecan’t be of functional type and accept arguments, and hence


118 5. Inductive Types−→ x ,−→ y ,−→ p ,−→ r are the empty lists). In this case, we can adjourn χidbyC −→ ι2 C[L χid (s)] −→ χid C[s] .(c) For C ≡ C[⦇. . . , λ −→ x −→ y .t k , . . .⦈ (c k. . . , p r [L χid (s)], . . . −→ r )], we have:C −→ χid C[⦇. . . , λ −→ x −→ y .t k , . . .⦈ (c k . . . p r [s] . . . −→ r )]C[t k { ...pr[s]... / −→ x } 〈 −−−−−−−−−−→(⦇λ −→ x −→ y . −→ t ⦈•r i/ ) −→ y 〉 .−→ ι2In this case, we can adjourn χ id byC −→ ι2 C[t k { ...pr[Lχ id (s)]... / −→ x } 〈 −−−−−−−−−−−−→(⦇λ −→ x −→ y . −→ t ⦈•ri R) / −→ y 〉C[t k { ...pr[s]... / −→ x } 〈 −−−−−−−−−−−−→(⦇λ −→ x −→ y . −→ t ⦈•ri R) / −→ y 〉 .−→ χid(d) For C ≡ C[⦇. . . , λ −→ x −→ y .t k , . . .⦈ (c k−→ p . . . rr [L χid (s)] . . .)] (writ<strong>in</strong>g a <strong>for</strong> thenumber of recursive arguments), we have:C −→ χid C[⦇. . . , λ −→ x −→ y .t k , . . .⦈ (c−→k p . . . rr [L χid (s)] . . .)]−→ ι2 C[t k { −→ p / −→ x } 〈 ...(⦇λ−→ x −→ y . −→ t ⦈•r r[s]) .../ −→ y 〉 .In this case, we can adjourn χ id by2. For β-conversion:C −→ ι2 C[t k { −→ p / −→ x }〈 ...(⦇λ−→ x −→ y . −→ t ⦈•r r[L χid (s)]) .../ −→ y 〉−→ χid C[t k { −→ p / −→ x } 〈 ...(⦇−→ t ⦈•r r[s]) ... / −→ y 〉 .(a) For C ≡ C[(λx · p[L χid (t)]) q], we haveC −→ χid C[(λx · p[t]) q] −→ β→ C[p[t]{ q /x}].In this case, we can adjourn χ id byC −→ β→ C[p[L χid (t)]{ q /x}] −→ χid C[p[t]{ q /x}].(b) For C ≡ C[(λx · p) q[L χid (t)]], we haveC −→ χid C[(λx · p) q[t]] −→ β→ C[p{ q[t] /x}].In this case, we can adjourn χ id byC −→ β→ C[p{ q[Lχ id (t)] /x}]∗−→ χ C[p{ q[t] /x}].3. For η-conversion, there is no <strong>in</strong>terest<strong>in</strong>g overlap with χ id -conversion as we havethe follow<strong>in</strong>g facts about a χ id -redex L χid (t):


Conclusions 119• L χid is a recursor ;• and t and L χid (t) <strong>in</strong>habit an <strong>in</strong>ductive type.4. For χ ◦ -conversion The only <strong>non</strong> trivial case is:C[Cp−→ −→ f , f ′(Cp−→ −→ id , idt)] −→ χid C[Cp−→ −→ f , f ′(t)]In this case we can adjourn byC[Cp−→ f ,−→ f ′(Cp−→ id ,−→ idt)]−→ χ◦ C[Cp−→ f ,−→ f ′t]Theorem 9 (Strong Normalization of βηι 2 χ). The reduction βηι 2 χ is strongly normaliz<strong>in</strong>g.Proof. Obviously the eta expansion η realizes the condition that 1-recursive argumentsoccurr<strong>in</strong>g <strong>in</strong> an iteration term are totally expansed externally. (the terms tobe expansed are neither <strong>in</strong> application position nor λ-abstraction). Moreover the etaexpansion η is <strong>in</strong>sertable by lemma (26). Theorem (8) sates that χ id -reduction isadjournable with respect to βηι 2 χ ◦ under the condition that 1-recursive arguments−→ r = r1 . . . r n of a constructor c −→ p −→ r of type µ are fully eta-expansed externally, i.e.,r i = r ′ i = λ−→ x .(r ′ i−→ x ) µ . Hence we can conclude by lemma (24), that χ id is adjournablewith respect to βηι 2 χ ◦ . F<strong>in</strong>ally as both βηι 2 χ ◦ and χ id are strongly normaliz<strong>in</strong>g wecan apply lemma (22) to conclude that βηι 2 χ is strongly normaliz<strong>in</strong>g.Theorem 10 (Confluence of βηι 2 χ). The reduction βηιχ is confluent.proof of theorem 10. As βηιχ-conversion is strongly normaliz<strong>in</strong>g, it is enough, byNewman’s Lemma to show that βηιχ-conversion is locally confluent. As βηιχ ◦ -and χ id -<strong>conversions</strong> are both confluent, The proof is a verification by case analysisthat ←− χid ; −→ βηιχ◦ ⊆ −→ ∗ ∗βηιχ ; ←− βηιχ .Theorem 11 (Convergence of βηι 2 χ). The reduction βηι 2 χ is convergent.Proof. The reduction βηι 2 χ is strongly normaliz<strong>in</strong>g by theorem (9) and confluentby theorem (10).


120 Conclusions


ConclusionsThis work allowed us to study several decid<strong>in</strong>g algorithms <strong>for</strong> the theories of <strong>typed</strong>λ-<strong>calculus</strong>. We have gathered our conclusions and suggestions <strong>for</strong> further work underthe follow<strong>in</strong>g themes.Reduction based versus reduction free normalizationAt the heart of the thesis is the opposition between reduction (or rewrit<strong>in</strong>g) drivenand reduction free algorithms. While the conceptual simplicity of rewrit<strong>in</strong>g theoryis attractive to understand the computational behaviour of normalization, reductionfree algorithms provides decidability results, where application of rewrit<strong>in</strong>g theory isnot obvious. The two approaches are related and we have tried to expla<strong>in</strong> the latter<strong>in</strong> terms of the <strong>for</strong>mer. However the relationship between the two approaches hasnot yet been enough explored. For example one could further explore the extractionof reduction proofs which as shown <strong>in</strong> [18] can produce reduction free algorithm.As shown <strong>in</strong> this thesis, there is several possible NbE algorithms <strong>for</strong> a same systemaccord<strong>in</strong>g to the model of computation used (call-by-value, call-by-name, Algol-like).Does there exist a proof (or several different proofs) from which these algorithmscan be extracted? The extraction method used <strong>in</strong> [18] was modified realizability,does a different method (e.g., functional <strong>in</strong>terpretation) give a different algorithm?Fresh variablesWe have developed a monadic <strong>for</strong>malisation of fresh variables generation <strong>for</strong> the NbEalgorithm. We believe that this <strong>for</strong>malisation is natural <strong>in</strong> the sense that it followsclosely an <strong>in</strong>tuitive description of what it means <strong>for</strong> a variable to be fresh. Thistreatment reduces the gap between <strong>in</strong><strong>for</strong>mal description and actual mathematical<strong>for</strong>malisation of the algorithm. The ma<strong>in</strong> change between <strong>in</strong><strong>for</strong>mal description to apure functional implementation is to pass from simple type to monadic ones. We areconscious that the simplicity of our solution is due to its specialization <strong>for</strong> a s<strong>in</strong>gleproblem, namely the generation of fresh names <strong>in</strong> NbE algorithm. Nevertheless an<strong>in</strong>terest<strong>in</strong>g question is how this approach <strong>in</strong>corporates or relates <strong>in</strong> the broad bodyof research concern<strong>in</strong>g <strong>for</strong>malisation of system with names and b<strong>in</strong>d<strong>in</strong>gs (nom<strong>in</strong>alreason<strong>in</strong>g).


122 ConclusionsSequent <strong>calculus</strong> and natural deductionApply<strong>in</strong>g the normalization by evaluation <strong>for</strong> the <strong>calculus</strong> Λ J allowed us to tightlyrelate cut-free derivations <strong>in</strong> sequent <strong>calculus</strong> and natural deduction. Normal <strong>for</strong>ms<strong>for</strong> permutative conversion <strong>in</strong> the Λ J <strong>calculus</strong> can be seen as a notation <strong>for</strong> cutfreeproof of the sequent <strong>calculus</strong>. Further restrictions on normal <strong>for</strong>ms <strong>in</strong> the Λ J -<strong>calculus</strong> can be seen as def<strong>in</strong><strong>in</strong>g normal <strong>for</strong>ms among cut-free proofs. These restrictednormal <strong>for</strong>ms are <strong>in</strong> turn isomorphic to long normal <strong>for</strong>ms <strong>in</strong> the simply <strong>typed</strong>λ-<strong>calculus</strong> modulo certa<strong>in</strong> decidable <strong>conversions</strong>. This sharpens previous resultsrelat<strong>in</strong>g sequent <strong>calculus</strong> and natural deduction.Normalization by evaluation <strong>for</strong> λ-<strong>calculus</strong> with extensionalpermutative <strong>conversions</strong>We have given a purely functional algorithm <strong>for</strong> decid<strong>in</strong>g extensional <strong>conversions</strong> ofterms <strong>in</strong> a system with generalized applications Λ J and one with sum types Λ + . Asalready advocated, algorithms described <strong>in</strong> a pure functional style are much closerto a mathematical <strong>for</strong>malisation. In an imperative sett<strong>in</strong>gs proofs are much more<strong>in</strong>volved as one has to take <strong>in</strong>to account the existence of a global state, <strong>in</strong>fluenc<strong>in</strong>gthe behaviour of primitive operations. Hence proofs of correctness and completeness<strong>for</strong> these algorithms should be feasible. The <strong>conversions</strong> of these systems are verysimilar, and so are the NbE algorithms we have described. This suggests to carryout the proofs of correctness and completeness <strong>for</strong> the simplest system Λ J -<strong>calculus</strong>and then adapt them <strong>for</strong> the Λ + -<strong>calculus</strong>. This is still work <strong>in</strong> progress.Functoriality of <strong>in</strong>ductive typesOur studies show that functorial laws are admissible <strong>for</strong> a subcategory of the systemwith <strong>in</strong>ductive types, <strong>in</strong> the sense that properties derived from these laws, ifexpressed as equalities are decidable. Although these results are already <strong>in</strong>terest<strong>in</strong>g<strong>in</strong> themselves, an obvious direction <strong>for</strong> further research is the study of the generalcase, both <strong>for</strong> reduction based and reduction free algorithms.


Indexχ-reduction, 109ι 2 -reduction, 105π e c, see circular permutative conversionη-expansion, 104unrestricted η-expansion, 114is-conversion, see permutative conversion,immediate simplificationπ e -conversion, see extensional permutativeconversionη → -conversion, 80η + -conversion, 80acceptable call-by-value mean<strong>in</strong>g function,37adjournable, 109under condition, 113admissibility, 38Algol <strong>in</strong>terpretation, 30call-by-name <strong>in</strong>terpretation, 32call-by-value <strong>in</strong>terpretation, 30catch, 14constructor types, 100context, 110context with multiple occurrences, 110contextualsubstitution, 103contextual closure, 103convergence, 106copy function, 108extension of a valuation, see valuationfree variables, 16<strong>in</strong>ductive types, 100<strong>in</strong>sertable, 113<strong>in</strong>stantiation function , 108<strong>in</strong>terpretation, 20iterators, 101Kripke applicative structure, 39Kripke monadic applicative structure, 40Kripke monadic logical relation, 40modified substitution, 105monad, 12exception, 13identity, 13partiality, 14state, 13state reader, 13monadic logical relation, 38multiplication, see monadname generation environment, 27parameter argument, 102parametric operators, 100permutative conversion, 79circular, 64, 84extensional, 61, 79, 81immediate simplification, 63, 85postdiction environment, 70, 94pseudo-application, 66, 67quote, see reifyrealisation, 113recursive argument, 102recursive operators, 1000-recursive, 1001-recursive, 100reflect, 21, 69, 93


124 Indexreify, 19, 21, 69, 93schema, 101strict positivity condition, 100substitutioncontextual, 17correct, 18, 103throw, see catchtype parameters, 100<strong>typed</strong> applicative structure, 36monadic, 36typ<strong>in</strong>g, 4typ<strong>in</strong>g context, 16typ<strong>in</strong>g relation, 16unit, see monadunquote, see reflectvaluation, 20


Bibliography[1] Andreas Abel, Ralph Matthes, and Tarmo Uustalu. Iteration schemes <strong>for</strong>higher-order and nested datatypes. Theoretical Computer Science, 333(1–2):3–66, 2005.[2] Klaus Aehlig and Felix Joachimski. Operational aspects of un<strong>typed</strong> normalizationby evaluation. Mathematical Structures <strong>in</strong> Computer Science, 14(4):587–611, August 2004.[3] Thorsten Altenkirch. α-conversion is easy. Under Revision, 2002.[4] Thorsten Altenkirch, Peter Dybjer, Mart<strong>in</strong> Hofmann, and Phil Scott. Normalizationby evaluation <strong>for</strong> <strong>typed</strong> <strong>lambda</strong> <strong>calculus</strong> with coproducts. In 16thAnnual IEEE Symposium on Logic <strong>in</strong> Computer Science, pages 303–310, 2001.[5] Thorsten Altenkirch and Tarmo Uustalu. Normalization by evaluation <strong>for</strong> λ →,2 .In Yukiyoshi Kameyama and Peter J. Stuckey, editors, Proc. of 7th Int. Symp.on Functional and Logic Programm<strong>in</strong>g, FLOPS 2004 (Nara, Japan, 7–9 Apr.2004), volume 2998 of Lecture Notes <strong>in</strong> Computer Science, pages 260–275.Spr<strong>in</strong>ger, Berl<strong>in</strong>, 2004.[6] Frank Atanassow and Johan Jeur<strong>in</strong>g. Inferr<strong>in</strong>g type isomorphisms generically.In Dexter Kozen and Carron Shankland, editors, MPC, volume 3125 of LectureNotes <strong>in</strong> Computer Science, pages 32–53. Spr<strong>in</strong>ger, 2004.[7] Leo Bachmair and Nachum Dershowitz. Commutation, trans<strong>for</strong>mation, andterm<strong>in</strong>ation. In Jörg H. Siekmann, editor, CADE, volume 230 of Lecture Notes<strong>in</strong> Computer Science, pages 5–20. Spr<strong>in</strong>ger, 1986.[8] John Backus. Can programm<strong>in</strong>g be liberated from the von Neumann style?A functional style and its algebra of programs. Communications of the ACM,21(8):613–641, August 1978. Reproduced <strong>in</strong> Selected Repr<strong>in</strong>ts on Dataflow andReduction Architectures, ed. S. S. Thakkar, IEEE, 1987, pages 215–243, and<strong>in</strong> ACM Tur<strong>in</strong>g Award Lectures: The First Twenty Years, ACM Press, 1987,pages 63–130.


126 Bibliography[9] V<strong>in</strong>cent Balat. Une étude des sommes <strong>for</strong>tes : isomorphismes et <strong>for</strong>mes normales.PhD thesis, Université Paris 7, 2002.[10] V<strong>in</strong>cent Balat, Roberto Di Cosmo, and Marcelo Fiore. Extensional normalisationand type-directed partial evaluation <strong>for</strong> <strong>typed</strong> <strong>lambda</strong> <strong>calculus</strong> with sums.ACM SIGPLAN Notices, 39(1):64–76, January 2004.[11] V<strong>in</strong>cent Balat and Olivier Danvy. Memoization <strong>in</strong> type-directed partial evaluation.In Don Batory, Charles Consel, and Walid Taha, editors, Proceed<strong>in</strong>gsof the 2002 ACM SIGPLAN/SIGSOFT Conference on Generative Programm<strong>in</strong>gand Component Eng<strong>in</strong>eer<strong>in</strong>g, GPCE 2002, number 2487 <strong>in</strong> Lecture Notes<strong>in</strong> Computer Science, pages 78–92, Pittsburgh, Pennsylvania, October 2002.ACM, Spr<strong>in</strong>ger.[12] Henk Barendregt. The impact of the <strong>lambda</strong> <strong>calculus</strong> on logic and computerscience. Bullet<strong>in</strong> of Symbolic Logic, 3(2):181–215, 1997.[13] Freiric Barral, David Chemouil, and Sergei Soloviev. Non-<strong>standard</strong> reductionsand categorical models <strong>in</strong> <strong>typed</strong> <strong>lambda</strong>-<strong>calculus</strong>. Logitcheskie Issledovaniya(Studies <strong>in</strong> logic), 12:300–315, December 2005. Moscow, Nauka.[14] Freiric Barral and Sergei Soloviev. Inductive type schemas as functors. In DimaGrigoriev, John Harrison, and Edward A. Hirsch, editors, CSR, volume 3967 ofLecture Notes <strong>in</strong> Computer Science, pages 35–45. Spr<strong>in</strong>ger, 2006.[15] Gilles Barthe and Olivier Pons. Type isomorphisms and proof reuse <strong>in</strong> dependenttype theory. In F. Honsell and M. Miculan, editors, Proc. of 4th Int. Conf.on Found. of Software Science and Computation Structures, FoSSaCS’01, Genova,Italy, 2–6 Apr. 2001, volume 2030 of Lecture Notes <strong>in</strong> Computer Science,pages 57–71. Spr<strong>in</strong>ger, Berl<strong>in</strong>, 2001.[16] Nick Benton, John Hughes, and Eugenio Moggi. Monads and effects. In GillesBarthe, Peter Dybjer, Luis P<strong>in</strong>to, and João Saraiva, editors, APPSEM, volume2395 of Lecture Notes <strong>in</strong> Computer Science, pages 42–122. Spr<strong>in</strong>ger, 2000.[17] Ulrich Berger. Program extraction from normalization proofs. In Marc Bezemand Jan Friso Groote, editors, Typed Lambda Calculi and Applications, LectureNotes <strong>in</strong> Computer Science, pages 91–106, Utrecht, The Netherlands, March1993. Spr<strong>in</strong>ger.[18] Ulrich Berger, Stefan Berghofer, Pierre Letouzey, and Helmut Schwichtenberg.Program extraction from normalization proofs. Studia Logica, 82(1):25–49,2006.


Bibliography 127[19] Ulrich Berger and Helmut Schwichtenberg. An <strong>in</strong>verse of the evaluation functional<strong>for</strong> <strong>typed</strong> λ-<strong>calculus</strong>. In R. Vemuri, editor, Proceed<strong>in</strong>gs 6’th Symposiumon Logic <strong>in</strong> Computer Science (LICS’91), pages 203–211. IEEE Computer SocietyPress, Los Alamitos, 1991.[20] Richard S. Bird. An <strong>in</strong>troduction to the theory of lists. In M. Broy, editor, Logicof Programm<strong>in</strong>g and Calculi of Discrete Design, pages 3–42. Spr<strong>in</strong>ger, 1987.[21] Frédéric Blanqui. Théorie des Types et Récriture. PhD thesis, Université ParisXI Orsay, 2001.[22] Kim B. Bruce, Roberto Di Cosmo, and Giuseppe Longo. Provable isomorphismsof types. Mathematical Structures <strong>in</strong> Computer Science, 2(2):231–247, June1992.[23] David Chemouil. Types <strong>in</strong>ductifs, isomorphismes et récriture extensionnelle.Thèse de doctorat, Université Paul Sabatier, Toulouse, September 2004.[24] David Chemouil and Sergei Soloviev. Remarks on isomorphisms of simple <strong>in</strong>ductivetypes. In Mathematics, Logic and Computation , E<strong>in</strong>dhoven, pages 1–19,Electronic Notes <strong>in</strong> Theoretical Computer Science 85, 7, July 2003. Elsevier,.[25] Alonzo Church. A set of postulates <strong>for</strong> the foundations of logic. Annals ofMathematics, 33:346–366, 1932.[26] Alonzo Church. An unsolvable problem <strong>in</strong> elementary number theory. Amer.J. Math., 58:345–363, 1936.[27] Alonzo Church. A simple theory of types. Journal of Symbolic Logic, 5:56–68,1940.[28] Catar<strong>in</strong>a Coquand. A mach<strong>in</strong>e assisted semantical analysis of simply <strong>typed</strong>λ–<strong>calculus</strong>. Programm<strong>in</strong>g Methodology Group, Chalmers University of Technologyand University Göteborg, 1993.[29] Catar<strong>in</strong>a Coquand. A <strong>for</strong>malised proof of the soundness and completeness ofa simply <strong>typed</strong> <strong>lambda</strong>-<strong>calculus</strong> with explicit substitutions. Higher-Order andSymbolic Computation, 14(1):57–90, 2002.[30] Thierry Coquand and Peter Dybjer. Intuitionistic model constructions andnormalization proofs. In International Workshop TYPES’93, Nijmegen, TheNetherlands, May 1993.[31] Thierry Coquand and Peter Dybjer. Intuitionistic model constructions andnormalization proofs. Mathematical Structures <strong>in</strong> Computer Science, 7:73–94,1997.


128 Bibliography[32] Thierry Coquand and Gérard Huet. Constructions - A higher order proof system<strong>for</strong> mechaniz<strong>in</strong>g mathematics. In B. Buchberger, editor, Eurocal 85, Volume 1,volume 203 of Lecture Notes <strong>in</strong> Computer Science, pages 151–184. Spr<strong>in</strong>ger,Berl<strong>in</strong>-Heidelberg-New York, 1985.[33] Thierry Coquand and Gérard Huet. The Calculus of Constructions. In<strong>for</strong>mationand Computation, 76:96–120, 1988.[34] Thierry Coquand and Christ<strong>in</strong>e Paul<strong>in</strong>. Inductively def<strong>in</strong>ed types (prelim<strong>in</strong>aryversion). In P. Mart<strong>in</strong>-Löf and G. M<strong>in</strong>ts, editors, Proc. of Int. Conf. onComputer Logic, COLOG’88, Tall<strong>in</strong>n, USSR, 12–16 Dec 1988, volume 417 ofLecture Notes <strong>in</strong> Computer Science, pages 50–66. Spr<strong>in</strong>ger, Berl<strong>in</strong>, 1990.[35] Roberto Di Cosmo. Isomorphisms of Types: from λ–<strong>calculus</strong> to <strong>in</strong><strong>for</strong>mationretrieval and language design. PTCS. Birkhäuser, Boston, 1995.[36] Haskell. B. Curry. Functionality <strong>in</strong> comb<strong>in</strong>atory logic. In Proceed<strong>in</strong>gs of theNational Academy of Sciences, U.S.A., volume 20, pages 584–590, 1934.[37] Olivier Danvy. Type-directed partial evaluation. In Guy L. Steele Jr., editor,Proceed<strong>in</strong>gs of the Twenty-Third Annual ACM Symposium on Pr<strong>in</strong>ciples of Programm<strong>in</strong>gLanguages, pages 242–257, St. Petersburg Beach, Florida, January1996. ACM, ACM Press.[38] Philippe de Groote. Strong norm of classical natural deduction with disjunction.In S. Abramsky, editor, Typed Lambda Calculi and Applications, volume 2044of Lecture Notes <strong>in</strong> Computer Science, pages 182–196. Spr<strong>in</strong>ger, 2001.[39] Daniel J. Dougherty and Ramesh Subrahmanyam. Equality between functionals<strong>in</strong> the presence of coproducts. In<strong>for</strong>mation and Computation, 157(1-2):52–83,2000.[40] Peter Dybjer and Andrzej Fil<strong>in</strong>ski. Normalization and partial evaluation. InGilles Barthe, Peter Dybjer, Luis P<strong>in</strong>to, and João Saraiva, editors, APPSEM,volume 2395 of Lecture Notes <strong>in</strong> Computer Science, pages 137–192. Spr<strong>in</strong>ger,2000.[41] Andrzej Fil<strong>in</strong>ski. Represent<strong>in</strong>g layered monads. In Annual ACM Symposiumon Pr<strong>in</strong>ciples of Programm<strong>in</strong>g Languages, pages 175–188, 1999.[42] Andrzej Fil<strong>in</strong>ski. A semantic account of type-directed partial evaluation. InGopalan Nadathur, editor, International Conference on Pr<strong>in</strong>ciples and Practiceof Declarative Programm<strong>in</strong>g, Lecture Notes <strong>in</strong> Computer Science, pages 378–395, Paris, France, September 1999. Spr<strong>in</strong>ger. Extended version available astechnical report BRICS RS-99-17.


Bibliography 129[43] Andrzej Fil<strong>in</strong>ski. Normalization by evaluation <strong>for</strong> the computational <strong>lambda</strong><strong>calculus</strong>.In Samson Abramsky, editor, Typed Lambda Calculi and Applications,volume 2044 of Lecture Notes <strong>in</strong> Computer Science, pages 151–165. Spr<strong>in</strong>ger,May 2001.[44] Gerhard Gentzen. Investigations <strong>in</strong>to logical deductions. In M. E. Szabo, editor,The Collected Papers of Gerhard Gentzen, pages 68–131. North-Holland,Amsterdam, 1934.[45] Neil Ghani. ßn-equality <strong>for</strong> coproducts. In Mariangiola Dezani-Ciancagl<strong>in</strong>i andGordon D. Plotk<strong>in</strong>, editors, TLCA, volume 902 of Lecture Notes <strong>in</strong> ComputerScience, pages 171–185. Spr<strong>in</strong>ger, 1995.[46] Neil Ghani and Christoph Lüth. Compos<strong>in</strong>g monads us<strong>in</strong>g coproducts. Intl.Conference on Functional Programm<strong>in</strong>g 2002, 37(9):133–144, 2002.[47] Jean-Yves Girard. Interprétation functionelle et élim<strong>in</strong>ation des coupures del’arithmétique d’ordre supérieur. PhD thesis, Université Paris VII, 1972.[48] Jean-Yves Girard, Paul Taylor, and Yves Lafont. Proofs and Types. CambridgeUniversity Press, 1989.[49] Tatsuya Hag<strong>in</strong>o. A <strong>typed</strong> <strong>lambda</strong> <strong>calculus</strong> with categorical type constructors.In David H. Pitt, Axel Poigné, and David E. Rydeheard, editors, CTCS, volume283 of Lecture Notes <strong>in</strong> Computer Science, pages 140–157. Spr<strong>in</strong>ger, 1987.[50] Hugo Herbel<strong>in</strong>. A λ-<strong>calculus</strong> structure isomorphic to Gentzen-style sequent<strong>calculus</strong> structure. In L. Pacholski and J. Tiuryn, editors, Computer ScienceLogic. 8th Workshop, CSL’94. Kazimierz, Poland, September 1994, volume 933of Lecture Notes <strong>in</strong> Computer Science, pages 61–75. Spr<strong>in</strong>ger, 1995.[51] Mart<strong>in</strong> Hofmann. Extensional concepts <strong>in</strong> <strong>in</strong>tensional type theory. PhD thesis,University of Ed<strong>in</strong>burgh, 1995.[52] Mart<strong>in</strong> Hofmann. Nbe with a logical relation. Unpublished work, 1999.[53] W.A. Howard. The <strong>for</strong>mulae–as–types notion of construction. In J.P. Seld<strong>in</strong> andJ.R. H<strong>in</strong>dley, editors, To H.B. Curry: Essays on Comb<strong>in</strong>atory Logic, LambdaCalculus and Formalism, pages 479–490. Academic Press, 1980.[54] Gérard Huet. A unification algorithm <strong>for</strong> <strong>typed</strong> λ–<strong>calculus</strong>. Theoretical ComputerScience, 1:27–57, 1975.[55] Felix Joachimski and Ralph Matthes. Short proofs of normalisation <strong>for</strong> thesimply-<strong>typed</strong> λ-<strong>calculus</strong>, permutative <strong>conversions</strong> and Gödel’s T . To appear:Archive <strong>for</strong> Mathematical Logic, 2002.


130 Bibliography[56] Mark P. Jones and Luc Duponcheel. Compos<strong>in</strong>g monads. Research ReportYALEU/DCS/RR-1004, Department of Computer Science, Yale University, December1993.[57] David J. K<strong>in</strong>g and Philip Wadler. Comb<strong>in</strong><strong>in</strong>g monads. In John Launchburyand Patrick M. Sansom, editors, Functional Programm<strong>in</strong>g, Workshops <strong>in</strong> Comput<strong>in</strong>g,pages 134–143. Spr<strong>in</strong>ger, 1992.[58] Stephen C. Kleene. Permutability of <strong>in</strong>ferences <strong>in</strong> Gentzen’s calculi LK and LJ.Memoirs of the American Mathematical Society No. 10, pp. 1–26, Providence,1952.[59] Stephen C. Kleene and J. B. Rosser. The <strong>in</strong>consistency of certa<strong>in</strong> <strong>for</strong>mal logics.Ann. of Math. (2), 36:630–636, 1935.[60] Joachim Lambek. Deductive systems and categories. I. syntactic <strong>calculus</strong> andresiduated categories. Math. Systems Theory, 2:287–318, 1968.[61] Joachim Lambek. Deductive systems and categories: II: Standard constructionsand closed categories. In Category theory, homology theory and their applications,number 86 <strong>in</strong> Lecture Notes <strong>in</strong> Mathematics, pages 76–122. Spr<strong>in</strong>ger,1969.[62] Joachim Lambek. Deductive systems and categories III: Cartesian closed categories,<strong>in</strong>tuitionist propositional <strong>calculus</strong>, and comb<strong>in</strong>atory logic. In Toposes,Algebraic Geometry and Logic, pages 57–82. 1981. Lecture Notes <strong>in</strong> Mathematics274.[63] Joachim Lambek and Philip J. Scott. Introduction to higher order categoricallogic, volume 7 of Cambridge Studies <strong>in</strong> Advanced Mathematics. CambridgeUniversity Press, 1986.[64] Grant Malcolm. Data structures and program trans<strong>for</strong>mation. Science of ComputerProgramm<strong>in</strong>g, 14(2–3):255–279, 1990.[65] Ernest G. Manes. Algebraic Theories, volume 26 of Graduate Texts <strong>in</strong> Mathematics.Spr<strong>in</strong>ger, New York, 1976.[66] Christopher R. Mann. The connection between equivalence of proofs andCartesian closed categories. Proceed<strong>in</strong>gs of the London Mathematical Society,21(3):289–310, 1975.[67] Per Mart<strong>in</strong>-Löf. Intuitionistic Type Theory. Bibliopolis, 1984.[68] Ralph Matthes. Extensions of System F by Iteration and Primitive Recursio<strong>non</strong> Monotone Inductive Types. PhD thesis, Mathematisches Institut derUniversität München, 1998.


Bibliography 131[69] Ralph Matthes. Interpolation <strong>for</strong> Natural Deduction with Generalized Elim<strong>in</strong>ations.In R. Kahle, P. Schröder-Heister, and R. Stärk, editors, Proof Theory <strong>in</strong>Computer Science, volume 2183 of Lecture Notes <strong>in</strong> Computer Science, pages153–169. Spr<strong>in</strong>ger, 2001.[70] Ralph Matthes. Non-strictly positive fixed po<strong>in</strong>ts <strong>for</strong> classical natural deduction.ANNALSPAL: Annals of Pure and Applied Logic, 133, 2005.[71] Lambert Meertens. Algorithmics: Towards programm<strong>in</strong>g as a mathematicalactivity. In J. W. de Bakker, M. Hazew<strong>in</strong>kel, and J. K. Lenstra, editors,Proc. CWI Symposium on Mathematics and Computer Science, pages 289–334.North-Holland, 1986.[72] Grigory E. M<strong>in</strong>ts. Closed categories and the theory of proofs. Journal of SovietMathematics, 15(1):45–62, 1981.[73] John C. Mitchell. Foundations <strong>for</strong> Programm<strong>in</strong>g Languages. MIT Press, Cambridge,MA, 1996.[74] Maxwell H.A. Newman. On theories with a comb<strong>in</strong>atorial def<strong>in</strong>ition of “equivalence”.Annals of Mathematics, 43(2):223–243, 1942.[75] Karim Nour and René David. A short proof of the strong normalization ofclassical natural deduction with disjunction. The Journal ofSymbolic Logic,68(4):1277–1288, December 2003.[76] Mitsuhiro Okada and Phillip J. Scott. A note on rewrit<strong>in</strong>g theory on <strong>for</strong> uniquenessof iteration. Theory and Applications of Categories, 6(4):47–64, 1999.[77] Dag Prawitz. Natural Deduction: a Proof-Theoretical Study, volume 3 of ActaUniversitatis Stockholmiensis. Stockholm Studies <strong>in</strong> Philosophy. Almqvist &Wiksell, Stockholm, 1965.[78] Dag Prawitz. Ideas and results <strong>in</strong> proof theory. In J.E. Fenstad, editor, Proceed<strong>in</strong>gsof the Second Scand<strong>in</strong>avian Logic Symposium, pages 235–307. North–Holland, Amsterdam, 1971.[79] John C. Reynolds. Towards a theory of type structure. In B. Rob<strong>in</strong>et, editor,Programm<strong>in</strong>g Symposium, volume 19 of Lecture Notes <strong>in</strong> Computer Science,pages 408–425, Berl<strong>in</strong>, 1974. Spr<strong>in</strong>ger.[80] John C. Reynolds. The essence of ALGOL. In J. W. de Bakker and J. C.van Vliet, editors, Algorithmic Languages, pages 345–372. IFIP, North-Holland,Amsterdam, 1981.[81] John C. Reynolds. Design of the programm<strong>in</strong>g language <strong>for</strong>sythe. Technicalreport, Carnegie Mellon University, July 22 1996.


132 Bibliography[82] Mikael Rittri. Retriev<strong>in</strong>g library identifiers via equational match<strong>in</strong>g of types.In M. E. Stickel, editor, Proceed<strong>in</strong>gs of the 10th International Conference onAutomated Deduction, volume 449 of LNAI, pages 603–617, Berl<strong>in</strong>, Heidelberg,1990. Spr<strong>in</strong>ger.[83] Jonathan P. Seld<strong>in</strong>. The logic of Curry and Church, 2006. To appear <strong>in</strong> theHandbook of the History of Logic, volume 5, edited by Dov Gabbay and JohnWoods, to be published by Elsevier.[84] Sergei V. Soloviev. The category of f<strong>in</strong>ite sets and cartesian closed categories.Journal of Soviet Mathematics, 22(3):1387–1400, 1983.[85] William W. Tait. Intensional <strong>in</strong>terpretations of functionals of f<strong>in</strong>ite type i. TheJournal of Symbolic Logic, 32(2):198–212, 1967.[86] Makoto Tatsuta. Second order permutative <strong>conversions</strong> with Prawitz’s strongvalidity. Progress <strong>in</strong> In<strong>for</strong>matics, 2:41–56, 2005.[87] Makoto Tatsuta and Grigori M<strong>in</strong>ts. A simple proof of second-order strongnormalization with permutative <strong>conversions</strong>. Ann. Pure Appl. Logic, 136(1-2):134–155, 2005.[88] Anne S. Troelstra and Helmut Schwichtenberg. Basic Proof Theory. CambridgeUniversity Press, 1996.[89] Varmo Vene. Categorical Programm<strong>in</strong>g with Inductive and Co<strong>in</strong>ductive Types.PhD thesis (Diss. Math. Univ. Tartuensis 23), Dept. of Computer Science, Univ.of Tartu, August 2000.[90] Jan von Plato. Natural deduction with general elim<strong>in</strong>ation rules. Archive <strong>for</strong>Mathematical Logic, 40(7):541–567, 2001.[91] Phil Wadler. Theorems <strong>for</strong> free! In Proc. 1989 ACM Conf. on Lisp andFunctional Programm<strong>in</strong>g, pages 347–359, 1989.[92] Daria Walukiewicz-Chrzaszcz. ↩Term<strong>in</strong>ation of rewrit<strong>in</strong>g <strong>in</strong> the <strong>calculus</strong> of construction.Under consideration <strong>for</strong> publication <strong>in</strong> J.Functional Programm<strong>in</strong>g.[93] Alfred North Whitehead and Bertrand Russell. Pr<strong>in</strong>cipia Mathematica. CambridgeUniversity Press, Cambridge, England, first edition, 1910–1913. Threevolumes.


Résumé 133Décidabilité pour Conversions Non-Standardsen Lambda-Calculs TypésFreiric BarralThèse soutenue à Munich, le 6 Ju<strong>in</strong> 2008.Directeurs : Prof. Dr. Mart<strong>in</strong> Hofmann et Prof. Dr. Sergeï Soloviev.Résumé : Cette thèse étudie la décidabilité des <strong>conversions</strong> des <strong>lambda</strong>-calculstypés a<strong>in</strong>si que les algorithmes permettant cette décidabilité. Notre étude prend enconsideration des <strong>conversions</strong> qui vont au-delà des traditionnelles <strong>conversions</strong> quesont les <strong>conversions</strong> beta, eta ou encore les <strong>conversions</strong> permutatives (encoreappelées <strong>conversions</strong> commutatives). Pour décider ces <strong>conversions</strong> deux classesd’algorithmes s’opposent, ceux basés sur la récriture où le but est de décomposer etd’orienter les <strong>conversions</strong> af<strong>in</strong> d’obtenir un système convergent, l’algorithme revientalors à récrire les termes jusqu’à ce qu’ils atteignent une <strong>for</strong>me irréductible et lesalgorithmes dits « libres de réduction » ou la conversion est décidée par un détourdans un métalangage ; tout au long de cette thèse, nous nous ef<strong>for</strong>çons d’expliquercette deuxième classe grâce à la première.Mots-clés : <strong>lambda</strong>-calcul typé, conversion, réduction, décidabilité, normalisationpar evaluation.Discipl<strong>in</strong>e : In<strong>for</strong>matique Théorique.Institut de recherche en In<strong>for</strong>matique deToulouse118 route de Narbonne,31 062 Toulouse Cedex 4,FranceLudwig-Maximilians-UniversitätMünchen,In<strong>for</strong>matik Institut,Lehr- und Forschungse<strong>in</strong>heitTheoretische In<strong>for</strong>matik,Oett<strong>in</strong>genstraße 67,80 538 München,Allemagne


134 Résumé


Zusammenfassung 135Entscheidbarkeit für Nicht-Standard Konversionen<strong>in</strong> Getypten Lambda-KalkülenFreiric BarralDoktorarbeit verteidigt <strong>in</strong> München am 6. Juni 2008.Betreuer: Prof. Dr. Mart<strong>in</strong> Hofmann und Prof. Dr. Sergeï Soloviev.Zusammenfassung: Diese Arbeit befasst sich mit der Entscheidbarkeit vonKonversionen <strong>in</strong> getypten Lambda-Kalkülen, und den Algorithmen, die dieseEntscheidbarkeit ermöglichen. Unsere Studie betrachtet Konversionen, die über dietraditionelle beta, eta oder permutative Konversionen (auch kommutativeKonversionen genannt) h<strong>in</strong>aus gehen. Um diese Konversionen zu entscheiden, gibtes zwei ganz verschiedene Klassen von Algorithmen, die zum E<strong>in</strong>satz kommenkönnen: die auf Termersetzungssystem basierende Algorithmen, wobei das Ziel ist,die Konversionen zu zerlegen und zu orientieren um e<strong>in</strong> konvergentes System zuerhalten, und die so genannte ”reduktionsfreien“ Algorithmen, die die Konversionrekursiv durch e<strong>in</strong> Umweg <strong>in</strong> e<strong>in</strong>er Meta-Sprache entscheiden. Wir bemühen uns <strong>in</strong>dieser Arbeit, die zweite Klasse mit Hilfe der erste zu erklären.Schlüsselwörter: getypter <strong>lambda</strong>-Kalkül, Konversion, Reduktion,Entscheidbarkeit, Normalisierung durch Auswertung.Fachgebiet: Theoretische In<strong>for</strong>matik.Institut de recherche en In<strong>for</strong>matique deToulouse118 route de Narbonne,31 062 Toulouse Cedex 4,FrankreichLudwig-Maximilians-UniversitätMünchen,In<strong>for</strong>matik Institut,Lehr- und Forschungse<strong>in</strong>heitTheoretische In<strong>for</strong>matik,Oett<strong>in</strong>genstraße 67,80 538 München,Deutschland


136 Zusammenfassung


Abstract 137<strong>Decidability</strong> <strong>for</strong> Non-Standard Conversions<strong>in</strong> Typed Lambda-CalculiFreiric BarralThesis defended <strong>in</strong> Munich on 6 June 2008.Supervisors: Prof. Dr. Mart<strong>in</strong> Hofmann and Prof. Dr. Sergeï Soloviev.Abstract: This thesis studies the decidability of <strong>conversions</strong> <strong>in</strong> <strong>typed</strong><strong>lambda</strong>-calculi, along with the algorithms allow<strong>in</strong>g <strong>for</strong> this decidability. Our studytakes <strong>in</strong> consideration <strong>conversions</strong> go<strong>in</strong>g beyond the traditional beta, eta, orpermutative <strong>conversions</strong> (also called commutative <strong>conversions</strong>). To decide these<strong>conversions</strong>, two classes of algorithms compete, the algorithms based on rewrit<strong>in</strong>g,where the goal is to decompose and orient the conversion so as to obta<strong>in</strong> aconvergent system, these algorithms then boil down to rewrite the terms until theyreach an irreducible <strong>for</strong>ms; and the “reduction free” algorithms where theconversion is decided recursively by a detour via a meta-language. Throughout thisthesis, we strive to expla<strong>in</strong> the latter thanks to the <strong>for</strong>mer.Keywords: <strong>typed</strong> <strong>lambda</strong> <strong>calculus</strong>, conversion, reduction, decidability,normalization by evaluation.Field: Theoretical Computer Science.Institut de recherche en In<strong>for</strong>matique deToulouse118 route de Narbonne,31 062 Toulouse Cedex 4,FranceLudwig-Maximilians-UniversitätMünchen,In<strong>for</strong>matik Institut,Lehr- und Forschungse<strong>in</strong>heitTheoretische In<strong>for</strong>matik,Oett<strong>in</strong>genstraße 67,80 538 München,Germany


138 Abstract

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!