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.

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Substitution & Evaluation Order cos 441 David Walker.
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
The lambda calculus David Walker CS 441. the (untyped) lambda calculus a language of functions e ::= x | \x.e | e1 e2 v ::= \x.e there are several different.
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.
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.
INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright © Instructors.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
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.
CS 312 Spring 2004 Lecture 18 Environment Model. Substitution Model Represents computation as doing substitutions for bound variables at reduction of.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
MinML: an idealized programming language CS 510 David Walker.
Describing Syntax and Semantics
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
Introduction Even though the syntax of Scheme is simple, it can be very difficult to determine the semantics of an expression. Hacker’s approach: Run it.
Prof. Fateman CS 164 Lecture 23
Functional Programming Element of Functional Programming.
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
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.
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.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Albert Gatt LIN3021 Formal Semantics Lecture 4. In this lecture Compositionality in Natural Langauge revisited: The role of types The typed lambda calculus.
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.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
Types and Programming Languages Lecture 6 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Principles of programming languages 9: Lambda calculus Isao Sasano Department of Information Science and Engineering.
Universal Types Report by Matthias Horbach. Contents Types of Polymorphism System F Basic Properties Erasure Impredicativity Parametricity.
Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11.
12/2/20151 GC16/3011 Functional Programming Lecture 2 The Lambda Calculus: A Simple Introduction.
CSE-321 Programming Languages -Calculus (II) POSTECH March 27, 2006 박성우.
Lesson2 Lambda Calculus Basics 1/10/02 Chapter 5.1, 5.2.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
-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
Lesson 3 Formalizing and Implementing Pure Lambda Calculus 1/15/02 Chapters 5.3, 6, 7.
CMSC 330: Organization of Programming Languages Lambda Calculus and Types.
CMSC 330: Organization of Programming Languages Operational Semantics.
CMSC 330: Organization of Programming Languages Lambda Calculus Introduction.
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.
CS 550 Programming Languages Jeremy Johnson
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Lambda Calculus CSE 340 – Principles of Programming Languages
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
Lesson2 Lambda Calculus Basics
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Announcements Quiz 6 HW7 due Tuesday, October 30
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
L Calculus.
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
CSE S. Tanimoto Lambda Calculus
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Presentation transcript:

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 says: “There may, indeed, be other applications of the system than its use as a logic.” –Dave says: “I’ll say”

Reading Pierce, Chapter 5

functions essentially every full-scale programming language has some notion of function –the (pure) lambda calculus is a language composed entirely of functions –we use the lambda calculus to study the essence of computation –it is just as fundamental as Turing Machines

syntax e ::= x(a variable) | \x.e(a function; in ML: fn x => e) | e e(function application) [ “\” will be written “ ” in a nice font]

syntax the identity function: \x.x 2 notational conventions: applications associate to the left (like in ML): “y z x” is “(y z) x” the body of a lambda extends as far as possible to the right: “\x.x \z.x z x” is “\x.(x \z.(x z x))”

terminology \x.e \x.x y the scope of x is the term e x is bound in the term \x.x y y is free in the term \x.x y

CBV operational semantics single-step, call-by-value OS: e --> e’ –values are v ::= \x.e –primary rule (beta reduction): –e [v/x] is the term in which all free occurrences of x in t are replaced with v –this replacement operation is called substitution –we will define it carefully later in the lecture (\x.e) v --> e [v/x]

operational semantics search rules: notice, evaluation is left to right e1 --> e1’ e1 e2 --> e1’ e2 e2 --> e2’ v e2 --> v e2’

Example (\x. x x) (\y. y)

Example (\x. x x) (\y. y) --> x x [\y. y / x]

Example (\x. x x) (\y. y) --> x x [\y. y / x] == (\y. y) (\y. y)

Example (\x. x x) (\y. y) --> x x [\y. y / x] == (\y. y) (\y. y) --> y [\y. y / y]

Example (\x. x x) (\y. y) --> x x [\y. y / x] == (\y. y) (\y. y) --> y [\y. y / y] == \y. y

Another example (\x. x x)

Another example (\x. x x) --> x x [\x. x x/x]

Another example (\x. x x) --> x x [\x. x x/x] == (\x. x x) (\x. x x) In other words, it is simple to write non terminating computations in the lambda calculus what else can we do?

We can do everything The lambda calculus can be used as an “assembly language” We can show how to compile useful, high- level operations and language features into the lambda calculus –Result = adding high-level operations is convenient for programmers, but not a computational necessity –Result = make your compiler intermediate language simpler

Let Expressions It is useful to bind intermediate results of computations to variables: let x = e1 in e2 Question: can we implement this idea in the lambda calculus? source = lambda calculus + let target = lambda calculus translate/compile

Let Expressions It is useful to bind intermediate results of computations to variables: let x = e1 in e2 Question: can we implement this idea in the lambda calculus? translate (let x = e1 in e2) = (\x.e2) e1

Let Expressions It is useful to bind intermediate results of computations to variables: let x = e1 in e2 Question: can we implement this idea in the lambda calculus? translate (let x = e1 in e2) = (\x. translate e2) (translate e1)

Let Expressions It is useful to bind intermediate results of computations to variables: let x = e1 in e2 Question: can we implement this idea in the lambda calculus? translate (let x = e1 in e2) = (\x. translate e2) (translate e1) translate (x) = x translate (\x.e) = \x.translate e translate (e1 e2) = (translate e1) (translate e2)

booleans we can encode booleans –we will represent “true” and “false” as functions named “tru” and “fls” –how do we define these functions? –think about how “true” and “false” can be used –they can be used by a testing function: “test b then else” returns “then” if b is true and returns “else” if b is false the only thing the implementation of test is going to be able to do with b is to apply it the functions “tru” and “fls” must distinguish themselves when they are applied

booleans the encoding: tru = \t.\f. t fls = \t.\f. f test = \x.\then.\else. x then else

booleans tru = \t.\f. t fls = \t.\f. f test = \x.\then.\else. x then else eg: test tru a b -->* (\t.\f. t) a b -->* a

booleans tru = \t.\f. t fls = \t.\f. f and = \b.\c. b c fls and tru tru -->* tru tru fls -->* tru

booleans tru = \t.\f. t fls = \t.\f. f and = \b.\c. b c fls and fls tru -->* fls tru fls -->* fls