L Calculus.

Slides:



Advertisements
Similar presentations
Cs776 (Prasad)L4Poly1 Polymorphic Type System. cs776 (Prasad)L4Poly2 Goals Allow expression of “for all types T” fun I x = x I : ’a -> ’a Allow expression.
Advertisements

Elements of Lambda Calculus Functional Programming Academic Year Alessandro Cimatti
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Catriel Beeri Pls/Winter 2004/5 functional-language 1 Substitution Semantics of FL – a simple functional language FL is EL + (non-recursive) function creation.
Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from G. Klein, NICTA.
Foundations of Programming Languages: Introduction to Lambda Calculus
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.
1 Scheme Scheme is a functional language. Scheme is based on lambda calculus. lambda abstraction = function definition In Scheme, a function is defined.
School of Computing and Mathematics, University of Huddersfield CHA2545 Last Lecture LECTURE: LAMBDA CALCULUS SEMANTICS TUTORIAL: Revision.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
ISBN Chapter 15 Functional Programming Languages.
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.
1 COMP313A Functional Programming (1). 2 Main Differences with Imperative Languages Say more about what is computed as opposed to how Pure functional.
1 Programming Languages and Paradigms Functional Programming.
1 ML fun x -> e e 1 e 2 0, 1, 2,..., +, -,... true, false, if e then e else e patterns datatypes exceptions structures functors let f x = e variables These.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
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.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11.
-Calculus Kangwon National University 임현승 Programming Languages These slides are based on the slides by Prof. Sungwoo Park at POSTECH.
Lambda Calculus CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
CS321 Functional Programming 2 © JAS The λ Calculus This is a formal system to capture the ideas of function abstraction and application introduced.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
A LISP interepreter for the Lambda Calculus Functional Programming
Operational Semantics of Scheme
Programming Languages Third Edition
Chapter 2: Lambda Calculus
CS5205: Foundations in Programming Languages
Functional Programming
CS 550 Programming Languages Jeremy Johnson
CS 3304 Comparative Languages
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Lambda Calculus CSE 340 – Principles of Programming Languages
Carlos Varela Rennselaer Polytechnic Institute September 5, 2017
More on Lambda Calculus
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Corky Cartwright January 18, 2017
Your turn (Review) What does a lambda expression return when it is evaluated? the value of a lambda expression is a procedure What three things are in.
Carlos Varela Rennselaer Polytechnic Institute September 6, 2016
Lesson2 Lambda Calculus Basics
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
Programming Languages and Compilers (CS 421)
FP Foundations, Scheme In Text: Chapter 14.
The Metacircular Evaluator
Announcements Quiz 6 HW7 due Tuesday, October 30
Carlos Varela Rennselaer Polytechnic Institute September 8, 2017
Extended Introduction to Computer Science
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Announcements Exam 2 on Friday, November 2nd Topics
Programming Languages and Compilers (CS 421)
Class 31: Universal Turing Machines CS200: Computer Science
CSE S. Tanimoto Lambda Calculus
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Programming Languages
Lecture 2 מבוא מורחב.
Chapter 15 Functional Programming 6/1/2019.
Carlos Varela Rennselaer Polytechnic Institute September 8, 2015
Carlos Varela Rennselaer Polytechnic Institute September 6, 2019
Carlos Varela Rennselaer Polytechnic Institute September 10, 2019
Presentation transcript:

l Calculus

Church’s l Calculus: Brief History One of a number of approaches to a mathematical challenge at the time (1930): Constructibility (What does it mean for an object, e.g. a natural number, to be constructible?) aka "effective computability", "computability" Work in parallel included: Turing's work on Turing machines Gödel's work on general recursive functions

History (continued) In late 30's, Church, Kleene and Turing showed equivalence of their respective notions. Led to Church's thesis: notion of a computable function should be identified with the notion of a general recursive function.

Church's Lambda Calculus: Formally specifies the difference between functions and forms. Form: specifies operations that are to be applied to the parameters of the form (with corresponding free variables and constants). e.g. of a form: a X2 + X + Y X, Y: parameters a: free variable (not parameter to form) 2: constant

Forms Note: if actual arguments are applied to form, there is no way to specify their bindings. P, Q ® a X2 + X + Y P ® X & Q ® Y ? P ® Y & Q ® X ?

l Functions Lambda function resolves ambiguity and defines difference between functions and forms: (l x. (ly . a x2 + x + y)) function with two parameters, x & y, where first actual is to be bound to x and second to y. Curried interpretation: function of x which yields a function of y which... Two interesting characteristics of lambda calculus: 1) Church defined argument substitution assuming static scope. (and actuals bound by l were to be unique throughout form)

l Functions 2) Form can only contain applications of other functions, not their definitions. instances of other formal parameters bound to other lambdas cannot exist in a given lambda function. functions cannot be used as arguments or function values because a function would appear where a form or object is expected.

McCarthy’s LISP McCarthy's LISP (1958-1960) - First language to be based on Lambda Calculus - Two major differences: 1) LISP used dynamic scope so: (Define poly (l (X Y) (+ (+ (* a (* X X)) X) Y) ) ) (Define p1 (l (a) (poly 2 3) ) ) (Define p2 (l (a) (poly 4 5) ) ) (p1 10) (p2 20) "a" has different bindings in poly when called by p1, p2. - so LISP maintained "a-list"

(continue) McCarthy's LISP 2) LISP (many versions before Scheme, ML) allowed functions as arguments. quoted lambda expressions were passed as "funargs." (pass-by-name definitions) each time funarg was referenced it caused evaluation of actual parameter's lambda definition in its defining scope. Note: Scheme, ML, Haskell allow functions as arguments they evaluate to themselves. McCarthy has suggested that the reason LISP used dynamic scope was that he did not fully understand the Lambda Calculus of Church during the development of LISP...

l Expressions <exp> ::= <constant> built-in constant | <variable> variable names | <exp> <exp> applications | l <variable> . <exp> lambda abstractions

l Abstractions Purpose is to denote new functions: (lx . + x 1) That function of x which adds x to 1

Free and Bound Variables ( lx . + x y ) -- x is bound (by the l) but y is free lx . + ( ( ly . + y z ) 7 ) x -- x & y are bound; z is free + x ( ( lx . + x 1 ) 4 ) -- first x is free; second is bound… Occurrence of variable is bound if an enclosing l expression binds it, and it is free otherwise.

Conversions, BAH! Beta (b): (abstraction and reduction) reduction: applying l abstraction to an argument, making new instance of abstraction body, and substituting argument for free occurrence of formal abstraction: going the opposite way Alpha (a): changing names consistent formal parameter name change in l expression. Eta (h): elimination of redundant l abstractions

Substitution E[M/x] -- expression E with all free occurrences of x replaced by M x [M/x] = M c [M/x] = c, where c is variable or constant other than x (E F)[M/x] = E [M/x] F[M/x] (lx.E)[M/x] = lx.E (because no free occurrences of x) (ly.E)[M/x] where y is not x = ly.E[M/x] if x does not occur free in E or y does not occur free in M = lz.(E[z/y]) [M/x] otherwise where z is new variable not free in E or M

Conversions Summary b: (lx . E) M E[M/x] a: if y is not free in E then (lx . E) (ly . E[y/x]) h: if x is not free in E and E denotes a function then (lx . E x) E when applied left to right ( ), b and h rules are called reductions b a h

Beta Reduction Reducing an expression: (lx . 3) x 3 (lx . + 4 x) 5 9 (lx . (ly . - y x)) 4 5 (ly . - y 4) 5 - 5 4 1 (lf . f 3) (lx . + x 1) (lx . + x 1) 3 + 3 1 4 function argument

Alpha Conversion Ought to be equivalent... (lx . + 1 x) & (ly . + 1 y) and, indeed… (lx . + 1 x) (ly . + 1 y) ...as long as newly introduced name does not occur freely in body of original lambda expression. a

Eta Conversion Ought to be equivalent... (lx . + 1 x) & (+ 1) and, indeed… (lx . + 1 x) (+ 1) In general… (lx . F x) F …provided x is not free in F and F is a function h h

Normal Form e.g. ( lx . 3 ) ( D D ) Def: When an expression contains no reducible expressions (redexes). There may be more than one route to normal form for an expression E e.g. ( + ( * 3 4 ) ( * 7 8 )) Not every expression has a normal form e.g. ( D D ) where D is ( lx . x x ) produces ( D D ) Some reductions may reach normal form while others do not e.g. ( lx . 3 ) ( D D ) OK not OK

Normal Form (CRT) (CRT-I): If E1 E2 then there exists an E such that E1 E and E2 E --- in words: two expressions that can be converted to each other share a common normal form. Corollary: No expression can be convereted to two distinct normal forms (CRT-II): If E1 E2 and E2 is in normal form, then there exists a normal order reduction sequence from E1 to E2. --- Normal order reduction: reduce leftmost, outermost redex first

l Calculus Utility Supports expression of recursion! Y H = H ( Y H ) Y: a fixed point combinator: takes a function H and produces a fixed point of H See Peyton-Jones, section 2.4.1 Supports typed, untyped and polymorphic systems Underlies denotational semantics...