Lambda Calculus CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University

Slides:



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

- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
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
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
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.
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.
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
CS5205: Foundation in Programming Languages Lecture 1 : Overview
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Functional Programming Element of Functional Programming.
Functional Languages. Why? Referential Transparency Functions as first class objects Higher level of abstraction Potential for parallel execution.
Semantics CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
CMSC 330: Organization of Programming Languages Lambda Calculus Introduction λ.
The Relational Model: Relational Calculus
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.
© 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.
Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11.
Semantics CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
-Calculus Kangwon National University 임현승 Programming Languages These slides are based on the slides by Prof. Sungwoo Park at POSTECH.
Fall 2008Programming Development Techniques 1 Topic 17 Assignment, Local State, and the Environment Model of Evaluation Section 3.1 & 3.2.
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.
Hindley-Milner Type Inference CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우.
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
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
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
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)
Amazing fact #3: -calculus is Turing-complete!
Announcements Quiz 6 HW7 due Tuesday, October 30
Carlos Varela Rennselaer Polytechnic Institute September 8, 2017
Announcements Exam 2 on Friday, November 2nd Topics
L Calculus.
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
CSE S. Tanimoto Lambda Calculus
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:

Lambda Calculus CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University

Adam Doupé, Principles of Programming Languages Lambda Calculus Language to express function application –Ability to define anonymous functions –Ability to "apply" functions Functional programming derives from lambda calculus –ML –Haskell –F# –Clojure 2

Adam Doupé, Principles of Programming Languages History Frege in 1893 studied the use of functions in logic Schönfinkel, in the 1920s, studied how combinators, a specific type of function, could be applied to formal logic Church introduced lambda calculus in the 1930s Original system was shown to be logically inconsistent in 1935 by Kleene and Rosser In 1936, Church published the lambda calculus that is relevant to computation Refined further –Type systems, … 3 Adapted from Jesse Alama:

Adam Doupé, Principles of Programming Languages Syntax Everything in lambda calculus is an expression (E) E → ID E → λ ID. E E → E E E → (E) 4

Adam Doupé, Principles of Programming Languages Examples E → ID E → λ ID. E E → E E E → (E) x λ x. x x y λ λ x. y λ x. y z foo λ bar. (foo (bar baz)) 5

Adam Doupé, Principles of Programming Languages Ambiguous Syntax How to parse x y z 6 Exp z z x x y y x x z z y y

Adam Doupé, Principles of Programming Languages Ambiguous Syntax How to parse λ x. x y 7 Exp x x y y λ λ x x x x x x λ λ y y

Adam Doupé, Principles of Programming Languages Disambiguation Rules E → E E is left associative –x y z is (x y) z –w x y z is ((w x) y) z λ ID. E extends as far to the right as possible, starting with the λ ID. –λ x. x y is λ x. (x y) –λ x. λ x. x is λ x. ( λ x. x) 8

Adam Doupé, Principles of Programming Languages Examples (λ x. y) x is the same as λ x. y x –No! –(λ x. y) x λ x. (x) y is the same as –λ x. ((x) y) λ a. λ b. λ c. a b c –λ a. (λ b. (λ c. ((a b) c))) 9

Adam Doupé, Principles of Programming Languages Semantics Every ID that we see in lambda calculus is called a variable E → λ ID. E is called an abstraction –The ID is the variable of the abstraction (also metavariable) –E is called the body of the abstraction E → E E –This is called an application 10

Adam Doupé, Principles of Programming Languages Semantics λ ID. E defines a new anonymous function –This is the reason why anonymous functions are called "Lambda Expressions" in Java 8 (and other languages) –ID is the formal parameter of the function –Body is the body of the function E → E 1 E 2, function application, is similar to calling function E 1 and setting its formal parameter to be E 2 11

Adam Doupé, Principles of Programming Languages Example Assume that we have the function + defined and the constant 1 λ x. + x 1 –Represents a function that adds one to its argument (λ x. + x 1) 2 –Represents calling the original function by supplying 2 for x and it would "reduce" to (+ 2 1) = 3 How can + function be defined if abstractions only accept 1 parameter? 12

Adam Doupé, Principles of Programming Languages Currying Technique to translate the evaluation of a function that takes multiple arguments into a sequence of functions that each take a single argument Define adding two parameters together with functions that only take one parameter: –λ x. λ y. ((+ x) y) –(λ x. λ y. ((+ x) y)) 1 λ y. ((+ 1) y) –(λ x. λ y. ((+ x) y)) (λ y. ((+ 10) y)) 20 ((+ 10) 20) = 30 13

Adam Doupé, Principles of Programming Languages Free Variables A variable is free if it does not appear within the body of an abstraction with a metavariable of the same name x free in λ x. x y z? y free in λ x. x y z? x free in (λ x. (+ x 1)) x? z free in λ x. λ y. λ z. z y x? x free in (λ x. z foo) (λ y. y x)? 14

Adam Doupé, Principles of Programming Languages Free Variables x is free in E if: –E = x –E = λ y. E 1, where y != x and x is free in E 1 –E = E 1 E 2, where x is free in E 1 –E = E 1 E 2, where x is free in E 2 and every occurrence of 15

Adam Doupé, Principles of Programming Languages Examples x free in x λ x. x ? x free in (λ x. x y) x ? x free in λ x. y x ? 16

Adam Doupé, Principles of Programming Languages Combinators An expression is a combinator if it does not have any free variables λ x. λ y. x y x combinator? λ x. x combinator? λ z. λ x. x y z combinator? 17

Adam Doupé, Principles of Programming Languages Bound Variables If a variable is not free, it is bound Bound by what abstraction? –What is the scope of a metavariable? 18

Adam Doupé, Principles of Programming Languages Bound Variable Rules If an occurrence of x is free in E, then it is bound by λ x. in λ x. E If an occurrence of x is bound by a particular λ x. in E, then x is bound by the same λ x. in λ z. E –Even if z == x –λ x. λ x. x Which lambda expression binds x? If an occurrence of x is bound by a particular λ x. in E 1, then that occurrence in E 1 is tied by the same abstraction λ x. in E 1 E 2 and E 2 E 1 19

Adam Doupé, Principles of Programming Languages Examples (λ x. x (λ y. x y z y) x) x y –(λ x. x (λ y. x y z y) x) x y (λ x. λ y. x y) (λ z. x z) –(λ x. λ y. x y) (λ z. x z) (λ x. x λ x. z x) –(λ x. x λ x. z x) 20

Adam Doupé, Principles of Programming Languages Equivalence What does it mean for two functions to be equivalent? –λ y. y = λ x. x ? –λ x. x y = λ y. y x ? –λ x. x = λ x. x ? 21

Adam Doupé, Principles of Programming Languages α-equivalence α-equivalence is when two functions vary only by the names of the bound variables E 1 = α E 2 We need a way to rename variables in an expression –Simple find and replace? –λ x. x λ y. x y z Can we rename x to foo? Can we rename y to bar? Can we rename y to x? Can we rename x to z? 22

Adam Doupé, Principles of Programming Languages Renaming Operation E {y/x} –x {y/x} = y –z {y/x} = z, if x ≠ z –(E 1 E 2 ) {y/x} = (E 1 {y/x}) (E 2 {y/x}) –(λ x. E) {y/x} = (λ y. E {y/x}) –(λ z. E) {y/x} = (λ z. E {y/x}), if x ≠ z 23 Material courtesy of Peter Selinger

Adam Doupé, Principles of Programming Languages Examples (λ x. x) {foo/x} (λ foo. (x) {foo/x}) (λ foo. (foo)) –((λ x. x (λ y. x y z y) x) x y) {bar/x} (λ x. x (λ y. x y z y) x) {bar/x} (x) {bar/x} (y) {bar/x} (λ x. x (λ y. x y z y) x) {bar/x} (x) {bar/x} y (λ x. x (λ y. x y z y) x) {bar/x} bar y (λ bar. (x (λ y. x y z y) x) {bar/x}) bar y (λ bar. (bar (λ y. x y z y) {bar/x} bar)) bar y (λ bar. (bar (λ y. (x y z y) {bar/x} ) bar)) bar y (λ bar. (bar (λ y. (bar y z y)) bar)) bar y 24

Adam Doupé, Principles of Programming Languages α-equivalence For all expressions E and all variables y that do not occur in E –λ x. E = α λ y. (E {y/x}) λ y. y = λ x. x ? ((λ x. x (λ y. x y z y) x) x y) = ((λ y. y (λ z. y z w z) y) y x) ? 25

Adam Doupé, Principles of Programming Languages Substitution Renaming allows us to replace one variable name with another However, our goal is to reduce (λ x. + x 1) 2 to (+ 1 2), which replaces x with the expression 2 –Can we use renaming? We need another operator, called substitution, to replace a variable by a lambda expression –E[x→N], where E and N are lambda expressions and x is a name 26

Adam Doupé, Principles of Programming Languages Substitution Seems simple, right? (+ x 1) [x→2] –(+ 2 1) (λ x. + x 1) [x→2] –(λ x. + x 1) (λ x. y x) [y→ λ z. x z] –(λ x. (λ z. x z) x) –(λ w. (λ z. x z) w) 27

Adam Doupé, Principles of Programming Languages Substitution Operation E [x→N] –x [x→N] = N –y [x→N] = y, if x ≠ y –(E 1 E 2 ) [x→N] = (E 1 [x→N]) (E 2 [x→N]) –(λ x. E) [x→N] = (λ x. E) –(λ y. E) [x→N] = (λ y. E [x→N]) if x ≠ y and y is not a free variable in N –(λ y. E) [x→N] = (λ y'. E {y'/y} [x→N]) if x ≠ y, y is a free variable in N, and y' is a fresh variable name 28

Adam Doupé, Principles of Programming Languages Examples (λ x. x) [x→foo] (λ x. x) –(+ 1 x) [x→2] (+[x→2] 1[x→2] x[x→2]) (+ 1 2) –(λ x. y x) [y→λ z. x z] (λ w. (y x){w/x} [y→λ z. x z]) (λ w. (y w) [y→λ z. x z]) (λ w. (y [y→λ z. x z] w [y→λ z. x z]) (λ w. (λ z. x z) w) 29

Adam Doupé, Principles of Programming Languages Examples (x (λ y. x y)) [x→y z] –(x [x→y z] (λ y. x y) [x→y z]) –((y z) (λ y. x y) [x→y z]) –(y z) (λ q. (x y){q/y}[x→y z]) –(y z) (λ q. (x q)[x→y z]) –(y z) (λ q. ((y z) q)) 30

Adam Doupé, Principles of Programming Languages Execution Execution will be a sequence of terms, resulting from calling/invoking functions Each step in this sequence is called a β-reduction –We can only β-reduce a β-redux (expressions in the application form) –(λ x. E) N β-reduction is defined as: –(λ x. E) N β-reduces to –E[x→N] β-normal form is an expression with no reduxes Full β-reduction is reducing all reduxes regardless of where they appear 31

Adam Doupé, Principles of Programming Languages Examples (λ x. x) y –x[x→y] –y–y (λ x. x (λ x. x)) (u r) –(x (λ x. x))[x→(u r)] –(u r) (λ x. x) 32

Adam Doupé, Principles of Programming Languages Examples (λ x. y) ((λ z. z z) (λ w. w)) –(λ x. y) (z z)[z→(λ w. w)] –(λ x. y) ((λ w. w) (λ w. w)) –(λ x. y) (w)[w→(λ w. w)] –(λ x. y) (λ w. w) –y[x→(λ w. w)] –y–y 33

Adam Doupé, Principles of Programming Languages Examples (λ x. x x) –(x x)[x→(λ x. x x)] –(λ x. x x) (λ x. x x) –(x x)[x→(λ x. x x)] –(λ x. x x) (λ x. x x) –…–… 34

Adam Doupé, Principles of Programming Languages Boolean Logic T = (λ x. λ y. x) F = (λ x. λ y. y) and = (λ a. λ b. a b F) and T T –(λ a. λ b. a b (λ x. λ y. y)) 35

Adam Doupé, Principles of Programming Languages and T T (λ a. λ b. a b (λ x. λ y. y)) (λ x. λ y. x) (λ x. λ y. x) (λ b. a b (λ x. λ y. y))[a →(λ x. λ y. x)] (λ x. λ y. x) (λ b. (λ x. λ y. x) b (λ x. λ y. y)) (λ x. λ y. x) ((λ x. λ y. x) b (λ x. λ y. y))[b→(λ x. λ y. x)] (λ x. λ y. x) (λ x. λ y. x) (λ x. λ y. y) (λ y. x)[x →(λ x. λ y. x)] (λ x. λ y. y) (λ y. (λ x. λ y. x)) (λ x. λ y. y) (λ x. λ y. x)[y→(λ x. λ y. y)] (λ x. λ y. x) T 36

Adam Doupé, Principles of Programming Languages and T F (λ a. λ b. a b F) T F (λ b. a b F)[a→T] F (λ b. T b F) F (T b F)[b→F] (T F F) (λ x. λ y. x) F F (λ y. x)[x→F] F (λ y. F) F F[y→F] F 37

Adam Doupé, Principles of Programming Languages and F T (λ a. λ b. a b F) F T F T F F 38

Adam Doupé, Principles of Programming Languages and F F (λ a. λ b. a b F) F F F F F F 39

Adam Doupé, Principles of Programming Languages not not T = F not F = T not = (λ a. a F T) not T –(λ a. a F T) T –T F T –F–F not F –(λ a. a F T) F –F F T –T–T 40

Adam Doupé, Principles of Programming Languages If Branches if c then a else b if c a b if T a b = a if F a b = b if = (λ a. a) 41

Adam Doupé, Principles of Programming Languages Examples if T a b –(λ a. a) T a b –T a b –a–a if F a b –(λ a. a) F a b –F a b –b–b 42

Adam Doupé, Principles of Programming Languages Church's Numerals 0 = λ f. λ x. x 1 = λ f. λ x. f x 2 = λ f. λ x. f f x 3 = λ f. λ x. f f f x 4 = λ f. λ x. f f f f x –λ f. λ x. (f (f (f (f x)))) 4 a b –a a a a b 43

Adam Doupé, Principles of Programming Languages Successor Function succ = λ n. λ f. λ x. f (n f x) 0 = λ f. λ x. x succ 0 –(λ n. λ f. λ x. f (n f x)) 0 –λ f. λ x. f (0 f x) –λ f. λ x. f ((λ f. λ x. x) f x) –λ f. λ x. f x 1 = λ f. λ x. f x succ 0 = 1 44

Adam Doupé, Principles of Programming Languages Successor Function succ = λ n. λ f. λ x. f (n f x) 1 = λ f. λ x. f x succ 1 –(λ n. λ f. λ x. f (n f x)) 1 –λ f. λ x. f (1 f x) –λ f. λ x. f ((λ f. λ x. f x) f x) –λ f. λ x. f f x 2 = λ f. λ x. f f x succ 1 = 2 succ n = n

Adam Doupé, Principles of Programming Languages Addition add 0 1 = 1 add 1 2 = 3 add = λ n. λ m. λ f. λ x. n f (m f x) add 0 1 –(λ n. λ m. λ f. λ x. n f (m f x)) 0 1 –(λ m. λ f. λ x. 0 f (m f x)) 1 –λ f. λ x. 0 f (1 f x) –λ f. λ x. 0 f (f x) –λ f. λ x. f x 46

Adam Doupé, Principles of Programming Languages Addition add = λ n. λ m. λ f. λ x. n f (m f x) add 1 2 –(λ n. λ m. λ f. λ x. n f (m f x)) 1 2 –(λ m. λ f. λ x. 1 f (m f x)) 2 –λ f. λ x. 1 f (2 f x) –λ f. λ x. 1 f (f f x) –λ f. λ x. (f f f x) –3–3 47

Adam Doupé, Principles of Programming Languages Multiplication mult 0 1 = 0 mult 1 2 = 2 mult 2 5 = 10 mult = λ n. λ m. m (add n) 0 mult 0 1 –(λ n. λ m. m (add n) 0) 0 1 –(λ m. m (add 0) 0) 1 –1 (add 0) 0 –add 0 0 –0–0 48

Adam Doupé, Principles of Programming Languages Multiplication mult 1 2 –(λ n. λ m. m (add n) 0) 1 2 –(λ m. m (add 1) 0) 2 –2 (add 1) 0 –(add 1) ((add 1) 0) –(add 1) (add 1 0) –(add 1) (1) –(add 1 1) –2–2 49

Adam Doupé, Principles of Programming Languages Turing Complete? We have Boolean logic –Including true/false branches We have arithmetic What does it mean for lambda calculus to be Turing complete? 50

Adam Doupé, Principles of Programming Languages Factorial n! –fact(0) = 1 –fact(n) = n * fact(n-1) int fact(int n) { if (n == 0) { return 1; } return n * fact(n-1); } 51

Adam Doupé, Principles of Programming Languages Factorial (assuming that we have definitions of the iszero and pred functions) fact = (λ n. if (iszero n) (1) (mult n (fact (pred n))) However, we cannot write this function! 52

Adam Doupé, Principles of Programming Languages Y Combinator Y = (λ x. λ y. y (x x y)) (λ x. λ y. y (x x y)) Y foo –(λ x. λ y. y (x x y)) (λ x. λ y. y (x x y)) foo –(λ y. y ((λ x. λ y. y (x x y)) (λ x. λ y. y (x x y)) y)) foo –foo ((λ x. λ y. y (x x y)) (λ x. λ y. y (x x y)) foo) –foo (Y foo) –foo (foo (Y foo)) –foo (foo (foo (Y foo))) –…–… 53

Adam Doupé, Principles of Programming Languages Recursion fact = (λ n. if (iszero n) (1) (mult n (fact (pred n))) fact = Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) fact 1 –Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) 1 –(λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) 1 –(λ n. if (iszero n) (1) (mult n ((Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred n))) 1 –if (iszero 1) (1) (mult 1 ((Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred 1)) –if F (1) (mult 1 ((Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred 1)) –mult 1 ((Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred 1) –mult 1 (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred 1) –mult 1 (λ n. if (iszero n) (1) (mult n ((Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred n))) (pred 1) –mult 1 (λ n. if (iszero n) (1) (mult n ((Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred n))) 0 –mult 1 (if (iszero 0) (1) (mult 0 ((Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred 0))) –mult 1 if T (1) (mult 0 ((Y (λ f. λ n. if (iszero n) (1) (mult n (f (pred n))) (pred 0))) –mult 1 1 –1–1 54

Adam Doupé, Principles of Programming Languages Turing Complete Boolean Logic Arithmetic Loops 55

PRINCIPLES OF PROGRAMMING LANGUAGES Fall