CSE 341 -- S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
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 Amazing fact #3: -calculus is Turing-complete! But the -calculus is too weak, right? No multiple arguments! No numbers or arithmetic! No booleans or.
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.
CSC321: Programming Languages14-1 Programming Languages Tucker and Noonan Chapter 14: Functional Programming 14.1 Functions and the Lambda Calculus 14.2.
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
Type Systems and Object- Oriented Programming John C. Mitchell Stanford University.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
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.
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
Chapter 10 :: Functional Languages
1 SML fn x => e e 1 e 2 0, 1, 2,..., +, -,... true, false, if e then e else e patterns datatypes exceptions structures functors fun f x = e variables.
CMSC 330: Organization of Programming Languages Lambda Calculus Introduction λ.
Cs7100(Prasad)L8Proc1 Procedures. cs7100(Prasad)L8Proc2 Primitive procedures  etc User-defined procedures –Naming a sequence of operations.
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.
© 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.
Types and Programming Languages Lecture 6 Simon Gay Department of Computing Science University of Glasgow 2006/07.
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
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Lesson 3 Formalizing and Implementing Pure Lambda Calculus 1/15/02 Chapters 5.3, 6, 7.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Copyright © 2009 Elsevier Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott.
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
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.
Functional Programming
Chapter 2: Lambda Calculus
CS5205: Foundations in Programming Languages
Functional Programming
CS 550 Programming Languages Jeremy Johnson
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Lecture 6: Lambda Calculus
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
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.
Carlos Varela Rennselaer Polytechnic Institute September 6, 2016
Lesson2 Lambda Calculus Basics
The Metacircular Evaluator
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
Programming Languages and Compilers (CS 421)
FP Foundations, Scheme In Text: Chapter 14.
Announcements Quiz 6 HW7 due Tuesday, October 30
Carlos Varela Rennselaer Polytechnic Institute September 8, 2017
L Calculus.
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
CSE S. Tanimoto Lambda Calculus
Programming Languages
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:

CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages really come from? Historical Context Syntax of the Lambda Calculus Examples Alpha reduction, Beta reduction Simulating multiple arguments: “Currying” Combinators True, False, and the IF-THEN-ELSE construct Church numerals Church’s Y combinator; recursion; Factorial Church’s Thesis

CSE S. Tanimoto Lambda Calculus 2 Historical Context Like Alan Turing, another mathematician, Alonzo Church, was very interested, during the 1930s, in the question “What is a computable function?” He developed a formal system known as the pure lambda calculus, in order to describe programs in a simple and precise way. Today the Lambda Calculus serves as a mathematical foundation for the study of functional programming languages, and especially for the study of “denotational semantics.” Reference:

CSE S. Tanimoto Lambda Calculus 3 Syntax of the Lambda Calculus expr ::= var expr ::= var. expr expr ::= expr expr expr ::= ( expr ) var ::= x | y | z | f | n var ::= var

CSE S. Tanimoto Lambda Calculus 4 Examples xA variable by itself x.xAn identity function x.x yThe identity function applied to y x. y.yA function that returns the identify function

CSE S. Tanimoto Lambda Calculus 5 Constants in Lambda Calculus Constants can be added to the syntax of the Lambda Calculus: e.g., 0, 1, 2, … However, in principle they are not necessary, because certain expressions can be used to represent them. 0 = x. y.yA fn that returns an ident. fun. 1 = x. y. (x y)A fn that applies a given fn. 1 time. 2 = x. y. (x (x y))A fn that applies a given fn. twice. Etc. These are called Church numerals. Other, symbolic, constants can also be added with the understanding that they, too, can be represented by some arbitrary L.C. expressions. E.g., Apple = x. y.y ( x. y.y)

CSE S. Tanimoto Lambda Calculus 6 The Successor Function Arithmetic operations can be defined using Lambda Calculus primitives. As an example, here is the function to return one plus a given number. SUCCESSOR(x) = x. y. z. (y (x y z))

CSE S. Tanimoto Lambda Calculus 7 Booleans in Lambda Calculus Boolean constants can be added to the syntax of the Lambda Calculus: i.e., true, false However, in principle they are not necessary, because certain expressions can be used to represent them. False = 0 = x. y.yA fn that returns an ident. fun. True = x. y.xA fn that returns its “first arg.”

CSE S. Tanimoto Lambda Calculus 8 Evaluation of Expressions Alpha conversion: Renaming of a bound variable and its bound occurrences. x. y.y   x. z.z

CSE S. Tanimoto Lambda Calculus 9 Evaluation of Expressions Beta reduction: Application of a function to an expression by means of a substitution of the expression for all bound occurrences of the argument variable in the body of the function. x.x y   y Beta reduction must not be permitted to do variable capture. If capture would occur, use alpha conversion first to rename variables. When as many beta reductions as possible have been applied, the resulting expression is in normal form.

CSE S. Tanimoto Lambda Calculus 10 Simulating multiple arguments As defined, a Lambda Calculus function can only take one argument. However, the effect of allowing multiple arguments to a function can be obtained using “currying”. ( x. y. (+ x y)) 3 5 A 2-parameter function is simulated with two 1- parameter functions. The result of applying the first function is another function. This new function accepts the second argument and produces the result of the simulated 2-parameter function. More parameters can be handled similarly.

CSE S. Tanimoto Lambda Calculus 11 Combinators A combinator is a function in the Lambda Calculus having no free variables. x. y. (x y) is a combinator x. y. (x z)is not a combinator Combinators can serve nicely as modular building blocks for more complex expressions. The Church numerals and simulated booleans are examples of useful combinators.

CSE S. Tanimoto Lambda Calculus 12 Conditionals in Lambda Calculus IF-THEN-ELSE: x. y. z. ((x y) z) Example evaluation of a conditional (a case where the condition is true). if true then apple else pear x. y. z. ((x y) z) true apple pear x. y. z. ((x y) z) x. y.x apple pear y. z. (( x. y.x y) z) apple pear z. (( x. y.x apple ) z) pear (( x. y.x apple ) pear) ( y. apple ) pear) apple

CSE S. Tanimoto Lambda Calculus 13 Conditionals in Lambda Calculus Example evaluation of a conditional (a case where the condition is false). if false then apple else pear x. y. z. ((x y) z) false apple pear x. y. z. ((x y) z) x. y.y apple pear y. z. (( x. y.y y) z) apple pear z. (( x. y.y apple ) z) pear (( x. y.y apple ) pear) ( y.y pear) pear

CSE S. Tanimoto Lambda Calculus 14 Recursion in Lambda Calculus Recursion is not directly supported in the Lambda Calculus. However, it can be simulated using Church’s Y combinator: Y = ( x. ( y. x (y y)) ( y. x (y y))) This has the unusual property of being a “fixed-point” combinator: Y f   f (Y f) Here   means reduces via some number of beta reduction steps.

CSE S. Tanimoto Lambda Calculus 15 Factorial in the Lambda Calculus Define H as follows, to represent 1 step of recursion. Note that ISZERO, MULT, and PRED represent particular combinators that accomplish these functions. H = ( f. n.(ISZERO n) 1 (MULT n (f (PRED n)))) Then we can create FACTORIAL = Y H = ( x. ( y. x (y y)) ( y. x (y y))) ( f. n.(ISZERO n) 1 (MULT n (f (PRED n)))) Reference:

CSE S. Tanimoto Lambda Calculus 16 Comment The use of the Lambda Calculus to express recursion in this manner is more a theoretical exercise to show the power of combinators. Few programmers would want to write software directly in the pure Lambda Calculus!

CSE S. Tanimoto Lambda Calculus 17 Church’s Thesis If a function can be computed, then it can be expressed in the pure lambda calculus. Also, Turing Machines and the Lambda Calculus have equivalent expressive power, in terms of which functions can or cannot be expressed.

CSE S. Tanimoto Lambda Calculus 18 Concluding Remarks It is easy to implement a lambda calculus system in Lisp (esp. Scheme) or ML. The LET construct in these languages provides a binding method similar to that of LAMBDA, except for a change in order. Both Lisp and ML themselves can be viewed as extensions of the Lambda Calculus. Functional abstraction is an important programming concept not only in theory, but also in practice.