Slides 01 1 Type-Free λ-Calculus The λ-calculus is a family of prototype programming languages invented by the logician, Alonzo Church, in the 1930's.

Slides:



Advertisements
Similar presentations
10 October 2006 Foundations of Logic and Constraint Programming 1 Unification ­An overview Need for Unification Ranked alfabeths and terms. Substitutions.
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.
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.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Introduction to Computability Theory
Foundations of Programming Languages: Introduction to Lambda Calculus
CS5371 Theory of Computation
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 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Catriel Beeri Pls/Winter 2004/5 type reconstruction 1 Type Reconstruction & Parametric Polymorphism  Introduction  Unification and type reconstruction.
Slides 09 1 Counting the Inhabitants of a Type Given a type , how many closed -terms in  - normal form can receive the type  in TA ? There exists an.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
Normal forms for Context-Free Grammars
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Monadic Predicate Logic is Decidable Boolos et al, Computability and Logic (textbook, 4 th Ed.)
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Slides 04 1 Deducibility in TA λ Definition (2A9) Let  be a type-context. If there is a TA -deduction of a formula  ' ↦ M:  for some  '   we shall.
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
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.
Slides 05 1 The Principal-Type Algorithm In general a typable term has an infinite set of types in TA. For example, it is possible to assign to I  x 
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
Introduction to the λ-Calculus and Functional Programming Languages Arne Kutzner Hanyang University 2015.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
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.
Logic Circuits Chapter 2. Overview  Many important functions computed with straight-line programs No loops nor branches Conveniently described with circuits.
Lexicografie computationala Feb., 2012 Anca Dinu University of Bucharest.
Advanced Topics in Propositional Logic Chapter 17 Language, Proof and Logic.
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.
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.
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11.
Naïve Set Theory. Basic Definitions Naïve set theory is the non-axiomatic treatment of set theory. In the axiomatic treatment, which we will only allude.
Lambda Calculus CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Λ-Calculus & Intuitionistic Logic Project Aims Cartesian Closed Categories Correspondence between CCC & λ unit, →, × 1© CHUANGJIE XU 2010.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CS321 Functional Programming 2 © JAS The λ Calculus This is a formal system to capture the ideas of function abstraction and application introduced.
Comp 205: Comparative Programming Languages The Untyped λ-calculus representing values Lecture notes, exercises, etc., can be found at:
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.
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
A LISP interepreter for the Lambda Calculus Functional Programming
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
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Programming Languages and Compilers (CS 421)
Announcements Quiz 6 HW7 due Tuesday, October 30
Announcements Exam 2 on Friday, November 2nd Topics
L Calculus.
Class 31: Universal Turing Machines CS200: Computer Science
CSE S. Tanimoto Lambda Calculus
Presentation transcript:

Slides 01 1 Type-Free λ-Calculus The λ-calculus is a family of prototype programming languages invented by the logician, Alonzo Church, in the 1930's. Main features:  functional: they are based on the notion of function and include notation for function- application and abstraction.  higher-order: they give a systematic notation for functions whose input and output values may be other functions.

Slides 01 2 Notation for Functions The crux of the λ-calculus is the mechanism of λ-abstraction. The expression λx. M is the general form that functions take in the system. To specify a function we say what is its formal parameter, here x, and what is its result, here M.

Slides 01 3 In mathematical texts we might talk about the function f given by f(x) = M In the λ-calculus we have an anonymous notation for the function which introduces the function without giving it a name (like f). The parameter x is a formal parameter and so we would expect that the function λx. λy. xy would be indistinguishable from λu. λv. uv for instance.

Slides 01 4 How do we associate actual parameters with the formals? We form applications (λx. M) N To evaluate these applications, we pass the parameter: we substitute the actual parameter for the formal, which we denote [N/x]M Here is an example in a familiar setting: (λx. x + 1)5 → [5/x](x+1) = = 6 As for the binding constructs of logic, the quantifiers, we have to be careful about how we define substitution.

Slides 01 5 λ-terms Definition (1A1) An infinite sequence of term- variables is assumed to be given. Then linguistic expression called λ-terms are defined as follows: i.each term-variable is a λ-term, called an atomic term or atom; ii.if M and N are λ-terms then (MN) is a λ-term called an application; iii.if x is a term-variable and M is a λ-term then (λx.M) is a λ-term called a λ-abstract or abstraction or abstract. A composite λ-term is a λ-term that is not an atom.

Slides 01 6 Notation Term-variables are denoted by lower-case letters u, v, w, x, y, z, with or without subscripts. Arbitrary λ-terms are denoted by upper-case letters L, M, N, P, Q, R, S, T, with or without subscripts. Parentheses and repeated λ's will often be omitted, for example: λxyz.M ≡ (λx.(λy.(λz.M))) MNPQ ≡ (((MN)P)Q)

Slides 01 7 Definition (1A2) The length, |M|, of a λ-term M is the number of occurrences of variables in M: |x| = 1, |MN| = |M| + |N|, |λx.M| = 1 + |M|. Example: |(λxyz.x(yz))(λx.x)| = 8 Note: We shall usually call "λ-term" just "term".

Slides 01 8 Definition (1A3) The subterms of a term M are defined by induction on |M| as follows: i. an atom is a subterm of itself; ii.if M ≡ λx.P, its subterms are M and all subterms of P; iii.if M ≡ PQ, its subterms are all the subterms of P, all those of Q, and M itself. Example: The subterms of M ≡ (λx.yx)(λz.x(yx)) are x, y, yx, λx.yx, x(yx), λz.x(yx) and M itself.

Slides 01 9 Definition (1A5) An occurrence of λx is called an abstractor, and the occurrence of x in it is called a binding occurrence of x. All the occurrences of terms in M, other than binding occurrences of variables, are called components of M. Let λx.P be a component of a term M. The displayed component P is called the body of λx.P or the scope of the abstractor λx. The covering abstractors of a component R of M are the abstractors in M whose scopes contain R.

Slides Definition (1A6) A non-binding variable- occurrence x in a term M is said to be bound in M iff it is in the scope of an occurrence of λx in M, otherwise it is free in M. A variable x is said to be bound in M iff M contains an occurrence of λx; and x is said to be free in M iff M contains a free occurrence of x. The set of all variables free in M is denoted by FV(M).

Slides Warning Two distinct concepts have been defined: free/bound occurrences and free/bound variables. A variable x may be both free and bound in M, for example, if M ≡ x(λx.x), but a particular occurrence of x in M cannot be both free and bound. x is said to be bound in λx.y even though its only occurrence in the term is a binding occurrence.

Slides Substitution Definition (1A7) [N/x]M is the result of substituting N for each free occurrence of x in M and making any changes of bound variables needed to prevent variables free in N from becoming bound in [N/x]M. More precisely, we define for all N, x, P, Q and all y ≢ x i.[N/x]x ≡ N, ii.[N/x]y ≡ y,

Slides iii.[N/x](PQ) ≡ (([N/x]P)([N/x]Q)), iv.[N/x]( λx.P) ≡ λx.P, v.[N/x](λy.P) ≡ λy.Pif x ∉ FV(P), vi.[N/x] (λy.P) ≡ λy.[N/x]P if x ∈ FV(P) and y ∉ FV(N), vii.[N/x] (λy.P) ≡ λz.[N/x][z/y]P if x ∈ FV(P) and y ∈ FV(N). (In (vii) z is the first variable in the sequence given in (1A1) which does not occur free in NP.)

Slides Example: [λx.xy/u](λy.uuy) ≡ λz.[λx.xy/u][z/y]uuy ≡ λz.[λx.xy/u]uuz ≡ λz.(λx.xy)(λx.xy)z

Slides  -conversion Definition (1A8) Let y ∉ FV(M); then we say λx.M ≡  λy.[y/x]M, and the act of replacing an occurrence of λx.M in a term by λy.[y/x]M is called a change of bound variables. If P changes to Q by a finite (perhaps empty) series of changes of bound variables we say P  -converts to Q or P ≡  Q.

Slides Simple properties of  -conversion a.P ≡  Q ⇒ |P| = |Q| b.P ≡  Q ⇒ FV(P) = FV(Q)

Slides Bound-variable clash Definition (1A9) A term M has a bound- variable clash iff M contains an abstractor λx and a (free, bound or binding) occurrence of x that is not in its scope. Examples of terms with bound-variable clashes: x(λx.N), λx.λy.λx.N, (λx.P)(λx.Q). Lemma Every term can be  -converted to a term without bound-variable clashes.

Slides Combinator Definition (1A10) A closed term or combinator is a term in which no variable occurs free. Example: Curry's fixed-point combinator Y ≡ λx.(λy.x(yy))(λy.x(yy))

Slides β-reduction Definition (1B1) A β-redex is any term ( λx.M)N; its contractum is [N/x]M and its rewrite rule is ( λx.M)N ⊳ 1β [N/x]M. If P contains a β-redex-occurrence R ≡ ( λx.M)N and Q is the result of replacing this by [N/x]M, we say P β-contracts to Q, denoted as P ⊳ 1β Q, and we call the triple a β-contraction of P.

Slides Example: (λxy.x)xy ⊳ 1β (λy.x)y ⊳ 1β x is a β-contraction of (λxy.x)xy. Lemma (1B1.1) P ⊳ 1β Q ⇒ FV(P) ⊇ FV(Q).

Slides Definition (1B2) A β-reduction of a term P is a finite or infinite sequence of β- contractions with the form,,... where P 1 ≡  P and Q i ≡  P i+1 for i = 1,2,.... (The empty sequence is allowed.) We say a finite reduction is from P to Q iff either it has n ≥ 1 contractions and Q n ≡  Q or it is empty and P ≡  Q. A reduction from P to Q is said to terminate or end at Q. If there is a reduction from P to Q we say P β-reduces to Q, or P ⊳ β Q.

Slides Definition (1B3) The length of a β-reduction is the number of its β-contractions (finite or ∞). A reduction with maximal length is one that continues as long as there are redexes to contract (i.e. one that either is infinite or ends at a term containing no redexes). Example: A β-reduction with maximal length:,.

Slides Definition (1B4) If we can change P to Q by a finite sequence of β-reductions and reversed β-reductions, we say P β-converts to Q, or P is β-equal to Q, or P = β Q. A reversed β-reduction is also called a β-expansion.

Slides Example: For any term F, YF = β F(YF)

Slides Church-Rosser Theorem for β (1B5) i.If M ⊳ β P and M ⊳ β Q then there exists T such that P ⊳ β T, Q ⊳ β T. M PQ T

Slides ii.If P = β Q then there exists T such that P ⊳ β T, Q ⊳ β T. Q P T

Slides β-normal forms Definition (1B6) A β-normal form is a term that contains no β-redexes. The class of all β-normal forms is called β-nf. We say a term M has β-normal form N iff M ⊳ β N and N ∈ β-nf.

Slides Example: (λxy.x)xy ⊳ β x x is a β-nf of (λxy.x)xy

Slides A reduction can be thought of as a computation and a β-normal form (β-nf) as its result. One main aim when designing a type- theory is to give it the property that every computation can be pursued to a result, i.e. that every term with a type has a β-nf. In general, terms do not necessarily have β-nf. For example, ( λx.xx)(λx.xx) does not have a β-nf. Neither has Y.

Slides By the Church-Rosser Theorem (1B5), we have NF-Uniqueness Lemma (1B7) Modulo  -conversion, a term M has at most one β-nf. Notation: If M has a β-nf it will be called M *β.

Slides Definition (1B8) The leftmost β-redex-occurrence in a term P is the β-redex-occurrence whose leftmost parenthesis is to the left of all the parentheses in all the other β- redex-occurrences in P. The leftmost β-reduction of a term P is a β- reduction of P with maximal length, say,,..., such that R i is the leftmost β-redex-occurrence in P i for all i ≥ 1 (and P 1  -converts to P and P i+1  -converts to Q i for all i ≥ 1).

Slides Leftmost-reduction Theorem (1B9) A term M has a β-nf M *β iff the leftmost β- reduction of M is finite and ends at M *β. Example: The leftmost β-reduction of the fixed-point combinator Y is infinite, so Y has no β-nf.

Slides Lemma (1B10) Every β-nf N can be expressed uniquely in the form N ≡ λx 1...x m.yN 1...N n (m ≥ 0, n ≥ 0), where N 1,..., N n are β-nf's. And if N is closed then y ∈ {x 1,..., x m }. Special cases:  an atom (m=n=0): N ≡ y  an application (m=0,n≥1): N ≡ yN 1...N n  an abstraction (m≥1): N ≡ λx 1...x m.P  an abstracted atom (m≥1,n=0): N ≡ λx 1...x m.y