Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11.

Slides:



Advertisements
Similar presentations
Substitution & Evaluation Order cos 441 David Walker.
Advertisements

The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Elements of Lambda Calculus Functional Programming Academic Year Alessandro Cimatti
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
1 Introduction to Computability Theory Lecture5: Context Free Languages Prof. Amos Israeli.
Foundations of Programming Languages: Introduction to Lambda Calculus
CS5371 Theory of Computation
6. Introduction to the Lambda Calculus. © O. Nierstrasz PS — Introduction to the Lambda Calculus 6.2 Roadmap  What is Computability? — Church’s Thesis.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
From Chapter 4 Formal Specification using Z David Lightfoot
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
Attribute Grammars Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 17.
10/12/20151 GC16/3C11 Functional Programming Lecture 3 The Lambda Calculus A (slightly) deeper look.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
Parsing Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 3.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Context Free Grammars. Context Free Languages (CFL) The pumping lemma showed there are languages that are not regular –There are many classes “larger”
Copyright © Curt Hill Quantifiers. Copyright © Curt Hill Introduction What we have seen is called propositional logic It includes.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
Types and Programming Languages Lecture 6 Simon Gay Department of Computing Science University of Glasgow 2006/07.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Principles of programming languages 9: Lambda calculus Isao Sasano Department of Information Science and Engineering.
Standardizing RPAL AST’s Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 10.
Writing RPAL Programs Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 13.
Lesson2 Lambda Calculus Basics 1/10/02 Chapter 5.1, 5.2.
A Problem That Is Complete for PSPACE (Polynomial Space) BY TEJA SUDHA GARIGANTI.
Lambda Calculus CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
The RPAL Functional Language Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 12.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Lesson 3 Formalizing and Implementing Pure Lambda Calculus 1/15/02 Chapters 5.3, 6, 7.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
CMSC 330: Organization of Programming Languages Operational Semantics.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L03-1 September 14, 2006http:// -calculus: A Basis for.
1 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5.
Chapter 2: Lambda Calculus
Programming Language Concepts
Lambda Calculus CSE 340 – Principles of Programming Languages
Building AST's for RPAL Programs
Introduction to Parsing (adapted from CS 164 at Berkeley)
Carlos Varela Rennselaer Polytechnic Institute September 5, 2017
More on Lambda Calculus
Corky Cartwright January 18, 2017
Programming Language Principles
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
Finite Automata and Formal Languages
Programming Language Principles
Announcements Quiz 6 HW7 due Tuesday, October 30
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Announcements Exam 2 on Friday, November 2nd Topics
L Calculus.
Theory of Computation Lecture #
Recursion and Fixed-Point Theory
CSE S. Tanimoto Lambda Calculus
Programming Languages
COMPILER CONSTRUCTION
Carlos Varela Rennselaer Polytechnic Institute September 6, 2019
Presentation transcript:

Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11

Lambda Calculus To obtain the "value" of an RPAL program: 1.Transduce RPAL source to an AST. 2.Standardize the AST into ST. 3.Linearize the ST into a lambda- expression. 4.Evaluate the lambda-expression, using the CSE machine (more later)

First, need some theory. RPAL’s flattener grammar: use bracket tree notation: RPAL→E E→ => E E → => ' ' V '.' E → => x → => i → => s →'true'=> 'true' →'false'=> 'false'... end RPAL.

Result of Tree Flattening: a string An Applicative Expression (AE), or well-formed formula (WFF). The interpretation of the AE is ambiguous. Need parentheses to disambiguate.

Disambiguation Rules 1.Function application is left associative. 2.If an expression of the form x.M occurs in a larger expression, then M is extended as far as possible (i.e. to the end of the entire expression or to the next unmatched right parenthesis).

Example: x. y.+xy 2 3 is equivalent to x.( y.+xy 2 3) Must be parenthesized to obtain the intended expression: ( x. y.+xy) 2 3.

Definition Let M and N be - expressions. An occurrence of x in a - expression is free if it can be proved so via the following three rules: 1.The occurrence of x in - expression "x" is free. 2.Any free occurrence of x in either M or N is free in M N. 3.Any free occurrence of x in M is free in y.M, if x and y are different.

Practical, Equivalent Definition An occurrence of x in M is free if the path from x to the root of M includes no node with x on its left. Definition: An occurrence of x in a - expression M is said to be bound if it is not free in M.

Examples: a- a occurs free x- x occurs free a x-a and x both occur free ( x.ax)x-a occurs free; x occurs both free and bound ( x. y.x+y) y 3 - first occurrence of y is not free, second occurrence is free, in the entire expression.

More definitions Definition: In an expression of the form x.M, x is the bound variable, and M is the body. Definition: The scope of an identifier x, in an expression of the form x.M, consists of all free occurrences of x in M.

Axiom Delta Let M and N be AE's that do not contain - expressions. Then M =>  N if Val(M) = Val(N). We say that M and N are delta-convertible, pronounced “M delta reduces to N”. Val: Value obtained from ordinary evaluation. Example: +35 =>  8.

Axiom Alpha Let x and y be names, and M be an AE with no free occurrences of y. Then, in any context, x.M =>  y.subst[y,x,M] subst[y,x,M] means "substitute y for x in M". Axiom Alpha used to rename the bound variable. Example: x.+x3 =>  y.+y3

Axiom Beta Let x be a name, and M and N be AE's. Then, in any context, ( x.M) N =>  subst[N,x,M]. Called a "beta-reduction", used to apply a function to its argument. Pronounced “beta reduces to”. Need to define the “subst” function.

Definition (subst): Let M and N be AE's, and x be a name. Then subst[N,x,M], also denoted as [N/x]M, means: 1.If M is an identifier, then 1.1. if M=x, then return N if M is not x, then return M. 2.If M is of the form X Y, then return ([N/x]X) ([N/x]Y).

Definition (subst[N,x,M], cont’d) 3.If M is of the form y.Y, then 3.1. if y=x then return y.Y if y is not x then if x does not occur free in Y, then return y.Y if y does not occur free in N, then return y.[N/x]Y if x occurs free in Y, and y occurs free in N, then return w.[N/x] ([w/y]Y), for any w that does not occur free in either N or Y.

Examples [3/x]( x.+x2) = x.+x2 (by 3.1) [3/x]( y.y) = y.y (by 3.2.1) [3/x]( y.+xy) = y.[3/x](+xy) = y.+3y (by and 2) [y/x]( y.+xy) = z.[y/x]([z/y](+xy)) = z.[y/x](+xz) = z.+yz (by 3.2.3, 2, and 2)

Definition An AE M is said to be "directly convertible“ to an AE N, denoted M => N, if one of these three holds: M =>  N, M =>  N, M =>  N. Definition: Two AE's M and N are said to be equivalent if M =>* N.

Definition An AE M is in normal form if either 1.M does not contain any ’s, or 2.M contains at least one, and 2.1. M is of the form X Y, X and Y are in normal form, and X is not a -expression M is of the form x.N, and N is in normal form. Shorter version: M is in normal form if no beta-reductions apply.

Definition Given an AE M, a reduction sequence on M is a finite sequence of AE's E 0, E 1,..., E n, such that M = E 0 => E 1... => E n. Definition: A reduction sequence is said to terminate if its last AE is in normal form.

Definitions Two AE's M and N are be congruent if M  * N. A reduction sequence is in normal order if in each reduction, the left-most is reduced. A reduction sequence is PL order if for each beta-reduction of the form ( x.M) N =>  subst[N,x,M], N is normal form, unless N is a -expression.

Examples Normal Order: ( y.y)[( x.+x3)2] =>  ( x.+x3) 2 =>  (+23) =>  5 PL order: ( y.y)[( x.+x3)2] =>  ( y.y)(+23) =>  ( y.y)5 =>  5

PL Order “faster” than Normal Order PL Order: ( x.x+x+x) (( y.y+1)2) =>  ( x.x+x+x) 3 =>  Cost: 2  ’s. Normal Order: ( x.x+x+x) (( y.y+1)2) =>  (( y.y+1)2) + (( y.y+1)2) + (( y.y+1)2) => , ,  Cost: 4  ’s.

PL Order “riskier” than Normal Order Normal Order: ( x.1) ( ( x.x x) ( x.x x) ) =>  1 Terminates. PL Order: ( x.1) ( ( x.x x) ( x.x x) ) =>  ( x.1) ( ( x.x x) ( x.x x) )... Doesn’t terminate !

Theorem (Church-Rosser) 1.All sequences of reductions on an AE that terminate, do so on congruent AE's. 2.If there exists a sequence of reductions on an AE that terminates, then reduction in normal order also terminates.

Conclusions 1.Some AE's can be reduced to normal form, but some cannot. Still stuck with the classic halting problem. 2.If an AE can be reduced to normal form, then that normal form is unique to within a choice of bound variables. 3.If a normal form exists, a reduction to (some) normal form can be obtained in a finite number of steps using normal order.

Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11