ebook img

Introduction to Lambda calculus PDF

53 Pages·2000·0.245 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Introduction to Lambda calculus

Introduction to Lambda Calculus Henk Barendregt Erik Barendsen Revised edition December 1998, March 2000 aaaaaa a Contents 1 Introduction 5 2 Conversion 9 3 The Power of Lambda 17 4 Reduction 23 5 Type Assignment 33 6 Extensions 41 7 Reduction Systems 47 Bibliography 51 3 Chapter 1 Introduction Some history Leibniz had as ideal the following. (1) Create a ‘universal language’ in which all possible problems can bestated. (2) Find a decision method to solve all the problems stated in the universal language. If one restricts oneself to mathematical problems, point (1) of Leibniz’ ideal is ful(cid:12)lled by taking some form of set theory formulated in the language of (cid:12)rst order predicate logic. This was the situation after Frege and Russell (or Zermelo). Point(2)ofLeibniz’idealbecameanimportantphilosophicalquestion. ‘Can one solve all problems formulated in the universal language?’ It seems not, but it is not clear how to prove that. This question became known as the Entscheidungsproblem. In 1936 the Entscheidungsproblem was solved in the negative independently by Alonzo Church and Alan Turing. In order to do so, they needed a formali- sation of the intuitive notion of ‘decidable’, or what is equivalent ‘computable’. Church and Turing did this in two di(cid:11)erent ways by introducing two models of computation. (1) Church (1936) invented a formal system called the lambda calculus and de(cid:12)ned the notion of computable function via this system. (2) Turing (1936/7) invented a class of machines (later to be called Turing machines) and de(cid:12)ned the notion of computable function via these machines. Also in 1936 Turingproved that bothmodelsare equally strong inthe sense that they de(cid:12)ne the same class of computable functions (see Turing (1937)). Based on the concept of a Turing machine are the present day Von Neu- mann computers. Conceptually these are Turing machines with random access registers. Imperative programming languages such as Fortran, Pascal etcetera as well as all the assembler languages are based on the way a Turing machine is instructed: by a sequence of statements. Functional programming languages, likeMiranda, MLetcetera, arebasedon the lambda calculus. An early (although somewhat hybrid) example of such a languageisLisp. Reduction machines arespeci(cid:12)callydesignedfortheexecution of these functional languages. 5 6 Introduction to Lambda Calculus Reduction and functional programming A functional program consists of an expression E (representing both the al- gorithm and the input). This expression E is subject to some rewrite rules. 0 Reduction consists of replacing a part P of E by another expression P accord- ing to the given rewrite rules. In schematic notation 0 E[P] !E[P ]; 0 provided that P ! P is according to the rules. This process of reduction will be repeated until the resulting expression has no more parts that can be (cid:3) rewritten. This so called normal form E of the expression E consists of the output of the given functional program. An example: (7+4)(cid:3)(8+5(cid:3)3) ! 11(cid:3)(8+5(cid:3)3) ! 11(cid:3)(8+15) ! 11(cid:3)23 ! 253: In this example the reduction rules consist of the ‘tables’ of addition and of multiplication on the numerals. Also symbolic computations can be done by reduction. For example (cid:12)rst of (sort (append (‘dog’, ‘rabbit’) (sort ((‘mouse’, ‘cat’))))) ! ! (cid:12)rst of (sort (append (‘dog’, ‘rabbit’) (‘cat’, ‘mouse’))) ! (cid:12)rst of (sort (‘dog’, ‘rabbit’, ‘cat’, ‘mouse’)) ! (cid:12)rst of (‘cat’, ‘dog’, ‘mouse’, ‘rabbit’) ! ‘cat’: The necessary rewrite rules for append and sort can be programmed easily in a few lines. Functions like append given by some rewrite rules are called combinators. Reduction systems usually satisfy the Church-Rosser property, which states that the normal form obtained is independent of the order of evaluation of subterms. Indeed, the (cid:12)rst example may be reduced as follows: (7+4)(cid:3)(8+5(cid:3)3) ! (7+4)(cid:3)(8+15) ! 11(cid:3)(8+15) ! 11(cid:3)23 ! 253; or even by evaluating several expressions at the same time: (7+4)(cid:3)(8+5(cid:3)3) ! 11(cid:3)(8+15) ! 11(cid:3)23 ! 253: Introduction 7 Application and abstraction The (cid:12)rst basic operation of the (cid:21)-calculus is application. The expression F (cid:1)A or FA denotes the data F considered as algorithm applied to the data A considered as input. This can be viewed in two ways: either as the process of computation FA or as the output of this process. The (cid:12)rst view is captured by the notion of conversion and even better of reduction; the second by the notion of models (semantics). The theory is type-free: it is allowed to consider expressions like FF, that is F applied to itself. This will be useful to simulate recursion. The other basic operation is abstraction. If M (cid:17) M[x] is an expression containing (‘depending on’) x, then (cid:21)x:M[x] denotes the function x 7! M[x]. Application and abstraction work together in the following intuitive formula. ((cid:21)x:2(cid:3)x+1)3 = 2(cid:3)3+1 (=7): That is, ((cid:21)x:2 (cid:3) x + 1)3 denotes the function x 7! 2 (cid:3) x + 1 applied to the argument 3 giving 2(cid:3)3+1 whichis 7. In general we have ((cid:21)x:M[x])N = M[N]. This last equation is preferably written as ((cid:21)x:M)N = M[x :=N]; ((cid:12)) where [x :=N] denotes substitution of N for x. It is remarkable that although ((cid:12)) is the only essential axiom of the (cid:21)-calculus, the resulting theory is rather involved. Free and bound variables Abstraction is said to bind the free variable x in M. E.g. we say that (cid:21)x:yx has x as bound and y as free variable. Substitution [x :=N] is only performed in the free occurrences of x: yx((cid:21)x:x)[x :=N](cid:17) yN((cid:21)x:x): b In calculus there is a similar variable binding. In R f(x;y)dx the variable x is a b bound and y is free. It does not make sense to substitute 7 for x: R f(7;y)d7; a b but substitution for y makes sense: R f(x;7)dx. a For reasons of hygiene it will always be assumed that the bound variables that occur in a certain expression are di(cid:11)erent from the free ones. This can be ful(cid:12)lled by renaming bound variables. E.g. (cid:21)x:x becomes (cid:21)y:y. Indeed, these expressions act the same way: ((cid:21)x:x)a = a= ((cid:21)y:y)a and in fact they denote the same intended algorithm. Therefore expressions that di(cid:11)er only in the names of bound variables are identi(cid:12)ed. 8 Introduction to Lambda Calculus Functions of more arguments Functionsofseveralargumentscanbeobtainedbyiterationofapplication. The idea is due to Scho(cid:127)n(cid:12)nkel (1924) but is often called currying, after H.B. Curry who introduced it independently. Intuitively, if f(x;y) depends on two argu- ments, one can de(cid:12)ne F = (cid:21)y:f(x;y); x F = (cid:21)x:F : x Then (Fx)y =F y = f(x;y): ((cid:3)) x This last equation shows that it is convenient to use association to the left for iterated application: FM (cid:1)(cid:1)(cid:1)M denotes ((cid:1)(cid:1)((FM )M )(cid:1)(cid:1)(cid:1)M ): 1 n 1 2 n The equation ((cid:3)) then becomes Fxy = f(x;y): Dually, iterated abstraction uses association to the right: (cid:21)x (cid:1)(cid:1)(cid:1)x :f(x ;:::;x ) denotes (cid:21)x :((cid:21)x :((cid:1)(cid:1)(cid:1)((cid:21)x :f(x ;:::;x ))(cid:1)(cid:1))): 1 n 1 n 1 2 n 1 n Then we have for F de(cid:12)ned above F = (cid:21)xy:f(x;y) and ((cid:3)) becomes ((cid:21)xy:f(x;y))xy = f(x;y): For n arguments we have ((cid:21)x (cid:1)(cid:1)(cid:1)x :f(x ;(cid:1)(cid:1)(cid:1);x ))x (cid:1)(cid:1)(cid:1)x = f(x ;:::;x ) 1 n 1 n 1 n 1 n by using n times ((cid:12)). This last equation becomes in convenient vector notation ((cid:21)~x:f[~x])~x= f[~x]; more generally one has ((cid:21)~x:f[~x])N~ = f[N~]: Chapter 2 Conversion In this chapter, the (cid:21)-calculus will be introduced formally. 2.1. Definition. The set of (cid:21)-terms (notation (cid:3)) is built up from an in(cid:12)nite 0 00 set of variables V = fv;v ;v ;:::g usingapplication and(function) abstraction. x2 V ) x2 (cid:3); M;N 2 (cid:3) ) (MN) 2(cid:3); M 2 (cid:3);x 2 V ) ((cid:21)xM) 2 (cid:3): In BN-form this is 0 variable ::= ‘v’jvariable ‘ ’ (cid:21)-term ::= variablej‘(’ (cid:21)-term (cid:21)-term ‘)’j‘((cid:21)’ variable (cid:21)-term ‘)’ 2.2. Example. The following are (cid:21)-terms. 0 v ; 0 (v v); 0 ((cid:21)v(v v)); 0 00 (((cid:21)v(v v))v ); 0 0 00 000 ((((cid:21)v((cid:21)v (v v)))v )v ): 2.3. Convention. (i) x;y;z;::: denote arbitrary variables; M;N;L;::: de- note arbitrary (cid:21)-terms. Outermost parentheses are not written. (ii) M (cid:17) N denotes that M and N are the same term or can be obtained from each other by renaming bound variables. E.g. ((cid:21)xy)z (cid:17) ((cid:21)xy)z; ((cid:21)xx)z (cid:17) ((cid:21)yy)z; ((cid:21)xx)z 6(cid:17) z; ((cid:21)xx)z 6(cid:17) ((cid:21)xy)z: (iii) We use the abbreviations FM (cid:1)(cid:1)(cid:1)M (cid:17)((cid:1)(cid:1)((FM )M )(cid:1)(cid:1)(cid:1)M ) 1 n 1 2 n 9 10 Introduction to Lambda Calculus and (cid:21)x (cid:1)(cid:1)(cid:1)x :M (cid:17) (cid:21)x ((cid:21)x ((cid:1)(cid:1)(cid:1)((cid:21)x (M))(cid:1)(cid:1))): 1 n 1 2 n The terms in Example 2.2 now may be written as follows. y; yx; (cid:21)x:yx; ((cid:21)x:yx)z; ((cid:21)xy:yx)zw: Note that (cid:21)x:yx is ((cid:21)x(yx)) and not (((cid:21)x:y)x). 2.4. Definition. (i) The set of free variables of M, notation FV(M), is de- (cid:12)ned inductively as follows. FV(x) = fxg; FV(MN) = FV(M)[FV(N); FV((cid:21)x:M) = FV(M)(cid:0)fxg: A variable in M is bound if it is not free. Note that a variable is bound if it occurs under the scope of a (cid:21). (ii) M is a closed (cid:21)-term (or combinator) if FV(M) = ;. The set of closed (cid:21)-terms is denoted by (cid:3)o. (iii) The result of substituting N for the free occurences of x in M, notation M[x :=N], is de(cid:12)ned as follows. x[x :=N] (cid:17) N; y[x :=N] (cid:17) y; if x 6(cid:17) y; (M M )[x :=N] (cid:17) (M [x:= N])(M [x :=N]); 1 2 1 2 ((cid:21)y:M )[x :=N] (cid:17) (cid:21)y:(M [x:= N]): 1 1 2.5. Example. Consider the (cid:21)-term (cid:21)xy:xyz: Then x and y are bound variables and z is a free variable. The term (cid:21)xy:xxy is closed. 2.6. Variable convention. If M ;:::;M occur in a certain mathematical 1 n context (e.g. de(cid:12)nition, proof), then in these terms all bound variables are chosen to be di(cid:11)erent from the free variables. Note that in the fourth clause of De(cid:12)nition 2.4 (iii) it is not needed to say ‘provided that y 6(cid:17) x and y 2= FV(N)’. By the variable convention this is the case. Now we can introduce the (cid:21)-calculus as formal theory.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.