lambda calculus History 11/28/13 Jianguo Lu A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion.

Similar documents
Lambda Calculus. Adrian Groza. Department of Computer Science Technical University of Cluj-Napoca

Fundamentals and lambda calculus

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

CMSC 330: Organization of Programming Languages. Lambda Calculus

Fundamentals and lambda calculus. Deian Stefan (adopted from my & Edward Yang s CSE242 slides)

Introduction to the Lambda Calculus

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility

CMSC 330: Organization of Programming Languages

Chapter 5: The Untyped Lambda Calculus

CMSC 330: Organization of Programming Languages. Lambda Calculus

Part I. Historical Origins

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

Pure Lambda Calculus. Lecture 17

1 Scope, Bound and Free Occurrences, Closed Terms

Introduction to Lambda Calculus. Lecture 7 CS /08/09

A Tutorial Introduction to the Lambda Calculus

Lambda Calculus. Lambda Calculus

Lambda Calculus. Lecture 4 CS /26/10

Last class. CS Principles of Programming Languages. Introduction. Outline

Type Systems Winter Semester 2006

CMSC 330: Organization of Programming Languages

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08

CITS3211 FUNCTIONAL PROGRAMMING

Lambda Calculus. Variables and Functions. cs3723 1

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.

CMSC 330: Organization of Programming Languages

Activity. CSCI 334: Principles of Programming Languages. Lecture 4: Fundamentals II. What is computable? What is computable?

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004

Recursive Definitions, Fixed Points and the Combinator

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

Lecture 5: The Untyped λ-calculus

A Quick Overview. CAS 701 Class Presentation 18 November Department of Computing & Software McMaster University. Church s Lambda Calculus

INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors.

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus

Lambda Calculus and Extensions as Foundation of Functional Programming

dynamically typed dynamically scoped

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur

Concepts of programming languages

Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators

> module Lambda where > import Data.List -- I need some standard list functions

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete

Computer Science 203 Programming Languages Fall Lecture 10. Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus

Introduction to the Lambda Calculus. Chris Lomont

Introduction to the λ-calculus

CIS 500 Software Foundations Fall September 25

Functional Programming

The Untyped Lambda Calculus

CMSC330. Objects, Functional Programming, and lambda calculus

CSCI.4430/6969 Programming Languages Lecture Notes

λ calculus is inconsistent

COMP 4161 NICTA Advanced Course. Advanced Topics in Software Verification. Toby Murray, June Andronick, Gerwin Klein

CMSC 330: Organization of Programming Languages

301AA - Advanced Programming

CS522 - Programming Language Semantics

COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples:

An Introduction to the Lambda Calculus

Grades. 10% - participation & exercises. 90% - term paper

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010

Lambda Calculus-2. Church Rosser Property

10.6 Theoretical Foundations

The Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements

CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

Formal Semantics. Aspects to formalize. Lambda calculus. Approach

VU Semantik von Programmiersprachen

Introductory Example

3.1 λ-calculus: Syntax

Constraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Chapter 5: The Untyped Lambda Calculus

Lexicografie computationala Feb., 2012

CSE 505: Concepts of Programming Languages

Recursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion

Programming Language Concepts: Lecture 19

Untyped Lambda Calculus

Formal Systems and their Applications

Elixir, functional programming and the Lambda calculus.

Functional Programming

Lecture 9: More Lambda Calculus / Types

- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.

Untyped Lambda Calculus

(Func&onal (Programming (in (Scheme)))) Jianguo Lu

Lambda Calculus and Type Inference

The Untyped Lambda Calculus

Lambda expressions, functions and binding

CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008.

Lecture #3: Lambda Calculus. Last modified: Sat Mar 25 04:05: CS198: Extra Lecture #3 1

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped)

Programming Languages. Dr. Philip Cannata 1

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21

Advanced Topics in Programming Languages Lecture 3 - Models of Computation

Plan. Syntax Substitution Operational Semantics ( with contexts!) Evaluations strategies Equality

Simple Lisp. Alonzo Church. John McCarthy. Turing. David Hilbert, Jules Richard, G. G. Berry, Georg Cantor, Bertrand Russell, Kurt Gödel, Alan

Denotational Semantics; Lambda Calculus Basics Section and Practice Problems Week 4: Tue Feb 13 Fri Feb 16, 2018

Programming Languages

The Untyped Lambda Calculus

CS 6110 S14 Lecture 1 Introduction 24 January 2014

Functional Programming Languages (FPL)

The Typed λ Calculus and Type Inferencing in ML

Transcription:

lambda calculus Jianguo Lu 1 History Lambda calculus A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion. Introduced by Alonzo Church in 1930s. The calculus can be used to cleanly define what a computable func:on is. Lambda calculus influenced Lisp. It is the smallest universal programming language Smallest: simple syntax and transforma:on rule Universal: any computable func:on can be expressed and evaluated using this formalism. Equivalent to Turing machine (Church- Turing Thesis) 2 1

Lambda calculus syntax Syntax variable <expr> ::= <variable> lambda abstrac:on <expr> ::= λ <variable>. <expr> lambda applica:on <expr> ::= <expr> <expr> Example lambda abstrac:on: λx. x*x f(x)=x*x lambda applica:on: (λx. x*x) 3 f(3) Whether the following are λ expressions? x λx.x xy x.x (λx.x)xy λx.xx 3 Correspondence to java program int f ( int x) { return x - 2;} λ x. - x 2 int f ( int x, int y ) { return x - y;} λ x. λ y. - x y int f ( int x, int y ) { return x - y;} f(2,3) (λ x. λ y. - x y) 2 3 Two nota:onal conven:ons The scope of λ extends as far as possible to the right λ x. - x 2 is λ x. ( - x 2) λx. xx is λx.(xx) Associa:on to the le] (λx. λy. x y) 2 3 is ((λx. λy. x y) 2) 3 How to reduce (calculate) f(2, 3), or (λx. λy. x y) 2 3? Alpha, beta, eta conversions 4 2

β reduc:on β Rule (λx. E) E E[E /x] (λx.x)3 x[3/x] =3 (λx. x*x) 3 (x*x)[3/x] 3*3 (λx. λy. x-y) 5 2 (λy. 2-y) 5 2-5 Notice the left association convention (λx. λy. x-y) 5 2 (λy. 5-y) 2 5-2 (λx.xx)(λy. y) (xx)[λy.y/x] = (λy.y)(λy.y) y[λy.y/y] = λy.y (λx.λy.yx) 3 (λx.x) (λy.yx) [3/x] (λx.x) (λy.y3) (λx.x) (λx.x)3 3 (λx.λy.xy) y (λy.xy) [y/x] (λy.yy)? 5 s allow us to rename bound variables. A bound name x in the lambda abstrac:on (λx.e) may be subs:tuted by any other name y, as long as there are no free occurrences of y in e: λx. λy.xy λx. λz.xz λx. λy.xy λz. λy.zy (λx. λy. x y ) y (λ x. λz. x z) y (λ z. x z) [y/x] β reduc6on (λ z. y z) = y η reduc6on 6 3

η reduc:on λ x. f x f η reduc:ons allow one to remove redundant lambdas. Suppose that f is a closed expression (i.e., there are no free variables in f). Then: (λ x. f x) y f y β reduc6on So, (λ x. f x ) behaves the same as f! η reduc:on says, whenever x does not occur free in f, we can rewrite (λ x. f x ) as f. 7 More example λ x y.e is a shorthand notation for λx. λy.e (λ x y. x y) (λ x. x y) (λ a b. a b) (λ x z. x z) (λ x. x y) (λ a b. a b) (λ z. (λ x. x y) z) (λ a b. a b) (λ x. x y) (λ a b. a b) (λ a b. a b) y (λ b. y b) y η reduction 8 4

There can be more than one path of reduc:ons (λ x y. x y) (λ x. x y) (λ a b. a b) (λ x z. x z) (λ x. x y) (λ a b. a b) (λ z. (λ x. x y) z) (λ a b. a b) (λ z. z y) (λ a b. a b) (λ a b. a b) y (λ b. y b) y η reduction 9 Normal form A lambda expression is in normal form if it can no longer be reduced by beta or eta reduc6on rules. Not all lambda expressions have normal forms! Ω = (λ x. x x) (λ x. x x) [ (λ x. x x) / x ] ( x x ) = (λ x. x x) (λ x. x x) β reduc6on (λ x. x x) (λ x. x x) β reduc6on (λ x. x x) (λ x. x x) β reduc6on... Reduc:on of a lambda expression to a normal form is analogous to a Turing machine hal6ng or a program termina6ng. 10 5

Church- Rosser Theorem There is only one normal form for any Lambda term, if it exists if term a can be reduced to both b and c, then there must be a further term d to which both b and c can be reduced. d is possibly equal to either b or c 11 Arithme:cs Numbers 0 λsz.z 1 λ sz.s(z) 2 λsz.s(s(z)) 3 λsz.s(s(s(z))) Successor func:on S λwyx.y(wyx) S0= (λwyx.y(wyx)) (λsz.z) =λ yx.y((λ sz.z)yx) =λ yx.y(x) =1 S1= 2 Plus + λmn.msn + 2 3 = (λ mn.msn) 2 3 = 2 S 3 = λsz.s(s(z)) S 3 =S(S(3)) =5 12 6