More on Lambda Calculus

Slides:



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

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
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
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.
CS5205: Foundation in Programming Languages Lecture 1 : Overview
Prof. Fateman CS 164 Lecture 23
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
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.
Introduction to the λ-Calculus and Functional Programming Languages Arne Kutzner Hanyang University 2015.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
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.
Lesson 4 Typed Arithmetic Typed Lambda Calculus 1/21/02 Chapters 8, 9, 10.
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.
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.
Lesson2 Lambda Calculus Basics 1/10/02 Chapter 5.1, 5.2.
-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
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
CSE 5317/4305 L12: Higher-Order Functions1 Functional Languages and Higher-Order Functions Leonidas Fegaras.
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
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
Lecture 6: Lambda Calculus
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.
Lambda Calculus Revisited
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Typed Arithmetic Expressions
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)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Amazing fact #3: -calculus is Turing-complete!
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.
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Lecture 10: Fixed Points ad Infinitum M.C. Escher, Moebius Ants
Language semantics Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Lazy Evaluation CSCE 314: Programming Languages Dr. Dylan Shell
CSE S. Tanimoto Lambda Calculus
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Programming Languages
Amazing fact #3: -calculus is Turing-complete!
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:

More on Lambda Calculus

Non-terminating reduction (x. x x) (x. x x)  (x. x x) (x. x x)  … (x. f (x x)) (x. f (x x))  f ((x. f (x x)) (x. f (x x)))  … (x. x x y) (x. x x y)  (x. x x y) (x. x x y) y  …

Term may have both terminating and non-terminating reduction sequences (u. v. v) ((x. x x)(x. x x))  v. v (u. v. v) ((x. x x)(x. x x))  (u. v. v) ((x. x x)(x. x x))  …

Reduction strategies Normal-order reduction: choose the left-most, outer-most redex first Applicative-order reduction: choose the left- most, inner-most redex first (u. v. v) ((x. x x)(x. x x))  v. v Normal-order reduction will find normal form if exists leftmost: whose lambda is left to any other outermost: not contained in any other innermost: not contain any other (u. v. v) ((x. x x)(x. x x))  (u. v. v) ((x. x x)(x. x x))  …

Reduction strategies – examples Normal-order Applicative-order (x. x x) ((y. y) (z. z))  ((y. y) (z. z)) ((y. y) (z. z))  (z. z) ((y. y) (z. z))  (y. y) (z. z)  z. z (x. x x) ((y. y) (z. z))  (x. x x) (z. z)  (z. z) (z. z)  z. z

Reduction strategies – examples Applicative-order may not be as efficient as normal-order when the argument is not used. Normal-order Applicative-order (x. p) ((y. y) (z. z))  p (x. p) ((y. y) (z. z))  (x. p) (z. z)  p

Reduction strategies Similar to (but subtly different from) evaluation strategies in language theories Call-by-name (like normal-order) ALGOL 60 Call-by-need (“memorized version” of call-by-name) Haskell, R, … Call-by-value (like applicative-order) C, … … arguments are not evaluated, but directly substituted into function body called “lazy evaluation” called “eager evaluation”

Main points till now Syntax: notation for defining functions “Pure”: without adding any additional syntax (Terms) M, N ::= x | x. M | M N Semantics (reduction rules) (x. M) N  [N/x]M () Next: programming in “pure” -calculus Encoding data and operators

Programming in -calculus Encoding Boolean values and operators True  x. y. x False  x. y. y

Programming in -calculus Encoding Boolean values and operators True  x. y. x False  x. y. y not  b. b False True not True  True False True  False not False  False False True  True

Programming in -calculus Encoding Boolean values and operators True  x. y. x False  x. y. y not  b. b False True and  b. b’. b b’ False and True b * True b False  b and False b * False b False  False

Programming in -calculus Encoding Boolean values and operators True  x. y. x False  x. y. y not  b. b False True and  b. b’. b b’ False or  b. b’. b True b’ or True b * True True b  True or False b * False True b  b

Programming in -calculus Encoding Boolean values and operators True  x. y. x False  x. y. y not  b. b False True and  b. b’. b b’ False or  b. b’. b True b’ if b then M else N  b M N Not unique encoding

Programming in -calculus Encoding Boolean values and operators True  x. y. x False  x. y. y not  b. b False True and  b. b’. b b’ False or  b. b’. b True b’ if b then M else N  b M N not’  b. x. y. b y x not’ True  x. y. True y x  x. y. y = False not’ False  x. y. False y x  x. y. x = True

Programming in -calculus Church numerals 0  f. x. x (the same as False!) 1  f. x. f x 2  f. x. f (f x) n  f. x. fn x

Programming in -calculus Church numerals 0  f. x. x (the same as False!) 1  f. x. f x 2  f. x. f (f x) n  f. x. fn x succ  n. f. x. f (n f x) succ n  f. x. f (n f x) = f. x. f ((f. x. fn x) f x)  f. x. f (fn x) = f. x. fn+1 x = n+1

Programming in -calculus Church numerals 0  f. x. x 1  f. x. f x 2  f. x. f (f x) n  f. x. fn x succ  n. f. x. f (n f x) succ’  n. f. x. n f (f x)

Programming in -calculus Church numerals 0  f. x. x 1  f. x. f x 2  f. x. f (f x) n  f. x. fn x succ  n. f. x. f (n f x) iszero  n. x. y. n (z. y) x iszero 0  x. y. 0 (z. y) x = x. y. (f. x. x) (z. y) x  x. y. (x. x) x  x. y. x = True iszero 1  x. y. 1 (z. y) x = x. y. (f. x. f x) (z. y) x  x. y. (x. (z. y) x) x  x. y. ((z. y) x)  x. y. y = False iszero (succ n) * False

Programming in -calculus Church numerals 0  f. x. x 1  f. x. f x 2  f. x. f (f x) n  f. x. fn x succ  n. f. x. f (n f x) iszero  n. x. y. n (z. y) x add  n. m. f. x. n f (m f x) mult  n. m. f. n m f

Programming in -calculus Booleans Natural numbers Pairs Lists Trees Recursive functions … Read supplementary materials on course website