Lesson 3 Formalizing and Implementing Pure Lambda Calculus 1/15/02 Chapters 5.3, 6, 7.

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.
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.
Predicate Calculus Formal Methods in Verification of Computer Systems Jeremy Johnson.
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.
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.
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.
Simplifying a Variable Expression
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Functional Languages. Why? Referential Transparency Functions as first class objects Higher level of abstraction Potential for parallel execution.
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.
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.
Semantic Construction lecture 2. Semantic Construction Is there a systematic way of constructing semantic representation from a sentence of English? This.
© 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.
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.
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
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
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.
Chapter 3 Lesson 2 Solving Systems of Equations Algebraically.
A LISP interepreter for the Lambda Calculus Functional Programming
Lesson 10 Type Reconstruction
Chapter 2: Lambda Calculus
CS5205: Foundations in 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
ece 627 intelligent web: ontology and beyond
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.
Lesson 4 Typed Arithmetic Typed Lambda Calculus
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)
Write down all the laws of indices
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.
CSE S. Tanimoto Lambda Calculus
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Carlos Varela Rennselaer Polytechnic Institute September 8, 2015
Indicator 16 System of Equations.
Carlos Varela Rennselaer Polytechnic Institute September 6, 2019
Carlos Varela Rennselaer Polytechnic Institute September 10, 2019
Presentation transcript:

Lesson 3 Formalizing and Implementing Pure Lambda Calculus 1/15/02 Chapters 5.3, 6, 7

1/15/02Lesson 3: Formalizing Lambda2 Outline Operational semantics of the lambda calculus –substitution –alpha-conversion, beta reduction –evaluation Avoiding names -- deBruijn indices –substitution –evaluation Implementation in ML

1/15/02Lesson 3: Formalizing Lambda3 Abstract Syntax V is a countable set of variables T is the set of terms defined by t :: = x(x  V ) | x.t(x  V ) | t t

1/15/02Lesson 3: Formalizing Lambda4 Free variables The set of free variables of a term is defined by FV(x) = {x} FV( x.t) = FV(t) \ {x} FV(t1 t2) = FV(t1)  FV(t2) E.g. FV( x. y( y. xyu)) = {y,u}

1/15/02Lesson 3: Formalizing Lambda5 Substitution and free variable capture Define substitution naively by [x  s]x = s [x  s]y = y if y  x [x  s]( y.t) = ( y.[x  s]t) [x  s](t1 t2) = ([x  s]t1) ([x  s]t2) Then (1) [x  y]( x.x) = ( x.[x  y]x) = ( x.y) wrong! (2) [x  y]( y.x) = ( y.[x  y]x) = ( y.y) wrong! (1) only free occurrences should be repalced. (2) illustrates free variable capture.

1/15/02Lesson 3: Formalizing Lambda6 Renaming bound variables The name of a bound variable does not matter. We can change bound variable names, as long as we avoid free variables in the body: Thus x.x  y.y but x.y  y.y. Change of bound variable names is called  -conversion. To avoid free variable capture during substitution, we change bound variable names as needed.

1/15/02Lesson 3: Formalizing Lambda7 Substitution refined Define substitution [x  s]x = s [x  s]y = y if y  x [x  s]( y.t) = ( y.[x  s]t) if y  x and y  FV(s) [x  s](t1 t2) = ([x  s]t1) ([x  s]t2) When applying the rule for [x  s]( y.t), we change the bound variable y if necessary so that the side conditions are satisfied.

1/15/02Lesson 3: Formalizing Lambda8 Substitution refined (2) The rule [x  s]( y.t) = ( y.[x  s]t) if y  x and y  FV(s) could be replaced by [x  s]( y.t) = ( z.[x  s][y  z]t) where z  FV(t) and z  FV(s) Note that ( x.t) contains no free occurrences of x, so [x  s]( x.t) = x.t

1/15/02Lesson 3: Formalizing Lambda9 Operational semantics (call by value) Syntax: t :: = Terms x(x  V ) | x.t(x  V ) | t t v ::= x.t Values We could also regard variables as values: v ::= x | x.t

1/15/02Lesson 3: Formalizing Lambda10 Operational semantics: rules t1  t1’ t1 t2  t1’ t2 t2  t2’ v1 t2  v1 t2’ ( x.t1) v2  [x  v2] t1 evaluate function before argument evaluate argument before applying function

1/15/02Lesson 3: Formalizing Lambda11 Avoiding variables Managing bound variable names to avoid free variable capture is messy. We can avoid name clashes by eliminating variable names. De Bruijn indices are a device for replacing names with “addresses” of variables. x.x becomes.0 x.x( y.xy) becomes.0(.1 0) Index i refers to the i th nearest enclosing binder.

1/15/02Lesson 3: Formalizing Lambda12 Free variables This explains how to replace bound variables. What do we do with free variables? Assume an ordered context listing all free variables that can occur, and map free variables to their index in this context (counting right to left) Context: a, b a  1, b  0 x.a .2, x.b .1, x.b( y.a) .1(.3) Imagine virtual -binders for a and b around term.

1/15/02Lesson 3: Formalizing Lambda13 Substitution When substituting into a lambda term, the indices have to be adjusted: [x  z] ( y.x) in context x,y,z [1  0] (.2) = (.[2  1] 2) = (.1) shift(d,c) (k) = k if k < c k+d if k >= c shift(d,c) (.t) = (.shift(d,c+1)(t)) shift(d,c) (t1 t2) = (shift(d,c) (t1)) (shift(d,c) (t2))

1/15/02Lesson 3: Formalizing Lambda14 Substitution [j  s] k = s if k = j k otherwise [j  s] (.t) =.[j+1  shift(1,0)s] t [j  s] (t1 t2) = ([j  s] t1) ([j  s] t2) Beta-reduction (.t) v  shift(-1,0)([0  shift(1,0)(v)] t)

1/15/02Lesson 3: Formalizing Lambda15 Symbols                 