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

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
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 39: Lambda Calculus.
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.
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
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.
Prof. Fateman CS 164 Lecture 23
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Lecture 20: λ Calculus λ Calculus & Computability Yan Huang Dept. of Comp. Sci. University of Virginia.
Functional Languages. Why? Referential Transparency Functions as first class objects Higher level of abstraction Potential for parallel execution.
CMSC 330: Organization of Programming Languages Lambda Calculus Introduction λ.
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.
Patterns in OCaml functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are.
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.
Principles of programming languages 9: Lambda calculus Isao Sasano Department of Information Science and Engineering.
CSE-321 Programming Languages -Calculus (II) POSTECH March 27, 2006 박성우.
-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
Lesson 3 Formalizing and Implementing Pure Lambda Calculus 1/15/02 Chapters 5.3, 6, 7.
CMSC 330: Organization of Programming Languages Lambda Calculus and Types.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L04Ext-1 September 21, 2006http:// Some more thoughts.
CMSC 330: Organization of Programming Languages Lambda Calculus Introduction.
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우.
CS321 Functional Programming 2 © JAS The λ Calculus This is a formal system to capture the ideas of function abstraction and application introduced.
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 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
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.
Lambda Calculus Revisited
CS 320 Principles of Programming Languages
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)
Announcements Quiz 6 HW7 due Tuesday, October 30
Carlos Varela Rennselaer Polytechnic Institute September 8, 2017
Announcements Exam 2 on Friday, November 2nd Topics
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Class 31: Universal Turing Machines CS200: Computer Science
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:

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

History  Formal mathematical system  Simplest programming language  Intended for studying functions, recursion  Invented in 1936 by Alonzo Church ( )

Warning  May seem trivial and/or irrelevant now  May remind you of brainf*^&brainf*^&  Had a tremendous influence in PLs  λ -calculus  Lisp  everything  Context in the early 60s:  Assembly languages  Cobol  Unstructured programming

4 What is Calculus? Calculus is a branch of mathematics that deals with limits and the differentiation and integration of functions of one or more variables

5 Real Definition  A calculus is just a bunch of rules for manipulating symbols.  People can give meaning to those symbols, but that’s not part of the calculus.  Differential calculus is a bunch of rules for manipulating symbols. There is an interpretation of those symbols corresponds with physics, slopes, etc.

Syntax M ::= x(variable) | λ x.M (abstraction) | MM (application) Nothing else!  No numbers  No arithmetic operations  No loops  No etc. Symbolic computation

Syntax reminder λx.M  function(x) { M } LM, e.g. λx.N y  apply L to M LM anonymous functions

Terminology – bound variables λx.M The binding operator λ binds the variable x in the λ-term x.M M is called the scope of x x is said to be a bound variable

Terminology – free variables Free variables are all symbols that aren’t bound (duh) FV(x) = {x} FV(MN) = FV(M) U FV(N) FV(x.M) = FV(M) − x

Renaming of bound variables λx.M = λy.([y/x]M) if y not in FV(M) α-conversion i.e. you can replace x with y aka “renaming”

Operational Semantics  Evaluating function application: ( λ x.e 1 ) e 2  Replace every x in e 1 with e 2  Evaluate the resulting term  Return the result of the evaluation  Formally: “ β -reduction” (aka “substitution”)  ( λ x.e 1 ) e 2 → β e 1 [e 2 /x]  A term that can be β -reduced is a redex (reducible expression)  We omit β when obvious

Note again  Computation = pure symbolic manipulation  Replace some symbols with other symbols

Scoping etc.  Scope of λ extends as far to the right as possible  λ x. λ y.xy is λ x.( λ y.(x y))  Function application is left-associative  xyz means (xy)z  Possible syntactic sugar for declarations  ( λ x.N)M is let x = M in N  ( λ x.(x + 1))10 is let x=10 in (x+1)

Multiple arguments  λ( x,y).e ???  Doesn’t exist  Solution: λ x. λ y.e [remember, ( λ x.( λ y.e))]  A function that takes x and returns another function that takes y and returns e  ( λ x. λ y.e) a b → ( λ y.e[a/x]) b → e[a/x][b/y]  “Currying” after Curry: transformation of multi-arg functions into higher-order functions  Multiple argument functions are nothing but syntactic sugar

Boolean Values and Conditionals  True = λx.λy.x  False = λx.λy.y  If-then-else = λa.λb.λc. a b c = a b c  For example:  If-then-else true b c →(λx.λy.x) b c→(λy.b) c→b  If-then-else false b c →(λx.λy.y) b c→(λy.y) c→c

Boolean Values and Conditionals  If True M N = (λa.λb.λc.abc) True M N  (λb.λc.True b c) M N  (λc.True M c) N  True M N = (λx.λy.x) M N  (λy.M) N  M If

Numbers…  Numbers are counts of things, any things. Like function applications!  0 = λf. λx. x  1 = λf. λx. (f x)  2 = λf. λx. (f (f x))  3 = λf. λx. (f (f (f x)))  …  N = λf. λx. (f N x) Church numerals

Successor  succ = λn. λf. λx. f (n f x)  Want to try it on succ(1)?  λn. λf. λx. f (n f x) (λf. λx. (f x))  λf. λx. f ((λf. λx. (f x)) f x)  λf. λx. f (f x) 1 2 !

There’s more  Reading materials

Recursion ??? (λn. (if (zero? n) 1 (* n (f (sub1 n))))) ??? Free variable

Recursion – The Y Combinator Y = λt. (λx. t (x x)) (λx. t (x x)) Y a = λt. (λx. t (x x)) (λx. t (x x)) a = (λx. a (x x)) (λx. a (x x)) = a ((λx. a (x x)) (λx. a (x x))) = a (Y a) Y a = a applied to itself! Y a = a (Y a) = a (a (Y a)) = a (a (a (Y a))) =...

Factorial again λn. (if (zero? n) 1 (* n (f (sub1 n)))) λf.λn. (if (zero? n) 1 (* n (f (sub1 n)))) Now it’s bound! F Y F

Does it work? (Y F) 2 = F (Y F) 2 = λf.λn.(if (zero? n) 1 (* n (f (sub1 n)))) ((λt.(λx.t (x x)) (λx.t (x x)) (λf.λn.(if (zero? n) 1 (* n (f (sub1 n))))) 2 = if (zero? 2) 1 (* 2 (Y F (sub1 2))) = (* 2 (Y F (sub1 2))) = (* 2 (Y F 1)) =... = (* 2 1) = 2 F takes one function and one number as arguments F (Y F)