Elements of Lambda Calculus Functional Programming Academic Year 2005-2006 Alessandro Cimatti

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.
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.
INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright © Instructors.
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.
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.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
CS5205: Foundation in Programming Languages Lecture 1 : Overview
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
CMSC 330: Organization of Programming Languages Lambda Calculus Introduction λ.
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.
Lambda Calculus1 The Untyped Lambda-Calculus Hossein Hojjat University of Tehran Formal Methods Laboratory.
Lexicografie computationala Feb., 2012 Anca Dinu University of Bucharest.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
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.
Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11.
Lesson2 Lambda Calculus Basics 1/10/02 Chapter 5.1, 5.2.
Lambda Calculus CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Lesson 3 Formalizing and Implementing Pure Lambda Calculus 1/15/02 Chapters 5.3, 6, 7.
CS383 Programming Languages Quiz Which one of the following is NOT a part of doing an inductive proof? a.Clearly state the induction hypothesis.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L04Ext-1 September 21, 2006http:// Some more thoughts.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
CS321 Functional Programming 2 © JAS The λ Calculus This is a formal system to capture the ideas of function abstraction and application introduced.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L03-1 September 14, 2006http:// -calculus: A Basis for.
A LISP interepreter for the Lambda Calculus Functional Programming
Programming Languages Third Edition
Chapter 2: Lambda Calculus
CS5205: Foundations in Programming Languages
Introduction to the λ-Calculus and Functional Programming Languages
CS 550 Programming Languages Jeremy Johnson
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Lambda Calculus CSE 340 – Principles of Programming Languages
Carlos Varela Rennselaer Polytechnic Institute September 5, 2017
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
Carlos Varela Rennselaer Polytechnic Institute September 6, 2016
Lesson2 Lambda Calculus Basics
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
Programming Languages and Compilers (CS 421)
Scoping and Binding of Variables
Announcements Quiz 6 HW7 due Tuesday, October 30
Carlos Varela Rennselaer Polytechnic Institute September 8, 2017
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Announcements Exam 2 on Friday, November 2nd Topics
L Calculus.
Class 31: Universal Turing Machines CS200: Computer Science
CSE S. Tanimoto Lambda Calculus
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
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:

Elements of Lambda Calculus Functional Programming Academic Year Alessandro Cimatti

Foundations Lambda calculus –Invented by Church in 1932 –Model of computation –All computable functions –As powerful as Turing machine Main ideas –Extremely simple –Functions as objects –Computations as sequences of reductions Basis for many functional languages –LISP, SCHEME, ML

Syntax Expressions (also called λ-terms) have the following syntax e is either –x a variable –λx.e a lambda abstraction –e1 e2 application Notation –for variables we use x, y, z, w –for expressions we use e, e’, e1, e2,...

Conventions Parentheses used to avoid ambiguities –x y z can be interpreted either as (x y) z or as x (y z) Two conventions to avoid too many parentheses –applications associate to the left, i.e. e e1 e2... eN stands for (... ((e e1) e2)... eN) –bodies of lambdas extended as much as possible λx.λy.e1 e2 e3 stands for λx.(λy.((e1 e2) e3)) rather than λx.((λy. (e1 e2)) e3) Nested lambdas may be collapsed together –λx1.(λx2.(...(λxN.e)...)) can be written as λx1x2...xN.e

Scope In λx.e, e is the scope of λx An occurrence of a variable x is bound when it occurs in the body of an abstraction λx.e An occurrence is said to be free if it appears in a position where it is not bound by an enclosing abstraction of x Examples –x y –λy.x y –λx.x –(λx.x x)(λx.x x) –(λx.x)y –(λx.x)x

Free variables The set of free variables in e, denoted as FV(e), is defined as –FV(x) = { x } –FV(e1 e2) = FV(e1) U FV(e2) –FV(λx.e) = FV(e) – { x } e is a closed λ-term iff FV(e) is empty

Alpha Renaming λ-terms are equivalent up to renaming of bound variables –all occurrences of x are replaced by y The rule of α-conversion –λx.e ≡α λy.[y/x]e –provided that y is not free in e For instance, –λx.x ≡α λy.y –λx.y x ≡α λz.y z But not –λx.y x ≡α λy.y y

Substitution No problem when free variables are replaced by term that does not clash –[λz.z w / x] λy.x = λy.λz.z w However, there may be a problem if there is name capture/clash –[λz.z w / x] λx.x is not the same as λx.λz.z w –[λz.z w / x] λw.x is not the same as λw.λz.z w

Definition of Substitution [e’/x]x = e’ [e’/x]y = y [e’/x](e1 e2) = ([e’/x]e1) ([e’/x] e2) [e’/x](λx.e) = λx.e [e’/x](λy.e) = λy.e if x not in FV(e) [e’/x](λy.e) = λy.[e’/x]e if x in FV(e), y not in FV(e’) [e’/x](λy.e) = λz.[e’/x][z/y]e if x in FV(e), y in FV(e’)

Beta Reduction An application whose LHS is an abstraction –An expression of the form ((λx. e1) e2) –is called redex (reducible expression) A redex evaluates to the body of the abstraction with parameter substitution Examples –(λx.(x y)) z → β z y –(λx. y) z → β y –(λx.x x) y → β y y –(λx.x x) (λx.x x) → β (λx.x x) (λx.x x) Beta-reduction –(λx. e1) e2 → β [e2/x]e1

Properties of Beta Reduction If e1 → β e2, then –(e e1) → β (e e2) –(e1 e) → β (e2 e) –(λx.e1) → β (λx.e2) The transitive closure of → β –e1 → β e2 → β... → β en –e1 reduces to en The induced equivalence relation is denoted ≡β

β-Normal Form A λ-term is in β-normal form if it does not have any redex as subexpression –meaning: there is no way to apply beta reduction A λ-term e has a β-normal form if for some e’ –e ≡β e’ –e’ is a β-normal form Some λ-terms do not have any normal form: –(λx.xx)(λx.xx) → β [(λx.xx)/x]xx = (λx.xx)(λx.xx) Intuition? –loop for ever

Properties of Lambda Calculus If e has a normal form, then this is unique (up to renaming) The β-reduction satisfies the so-called Church-Rosser property –if e reduces to e1 and e reduces to e2 –then there exists e3 such that –e1 reduces to e3 and e2 reduces to e3 Confluence