














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Explore the mathematical system of lambda calculus, focusing on variables, functions, function parameters, and substitution. Learn about pure lambda calculus, its completeness, and its application in real programming languages.
Typology: Papers
1 / 22
This page cannot be seen from the preview
Don't miss anything!















Lambda Calculus
Is Pure Lambda Calculus complete?
True = λ t. (λ f. t) False = λ t. (λ f. f)
c0 = λ s. (λ z. z) c1 = λ s. (λ z. (s (s z))) c2 = λ s. (λ z. (s (s (s z)))) …
The Applied Lambda Calculus
x + y, x + 2*y + z
λ x. (x+y), λz. (x + 2*y + z)
(λ x. (x+y)) 3 = 3 + y Symbolic evaluation of mathematical expressions
Exercises: translate Lambda Calculus
int dummy(int x) { return x; } What if x is a float or string?
(lambda (f) (lambda (g) (lambda (x) (f (g x))))) int dummy(int (f)(...), int (g)(...), int x) { return f(g(x)); }** C: does not allow functions to return functions
int f1(int (g)(...)) { return g(g); } int f2(int x) { return x + 1; }* int main() { return f2(3); } ==>? int main() { return f1(f2); } ==>? int main() { return f1(f1); } ==>?
Programming With Lambda Calculus
plus(x,y,z) = x + y + z λ x. λ y. λ z. x + y + z
Given functions f(x) and g(x), return function f ° g (x) λ f. λ g. λ x. f (g x)
Higher-Order Functions Functions that either take a function as parameter or return
Functions as first-class objects
Lambda calculus examples
(λ f. λ g. λ x. f (g x)) ( λ y. y+1) (λ z. zz)*
Higher-Order functions and Functions as first-class objects
Lisp implementation (((lambda (f) (lambda (g) (lambda (x) (f (g x))))) (lambda (y) (+ y 1))) (lambda (z) (* z z)))
int compose (int (f)(int), int (g)(int), int x) { return f(g(x)); } int plus1 (int y) { return y + 1; } int square (int z) { return z * z; } int main() { int x = 50; printf(“%d”, compose(plus1,square,x)); }
Variable Binding Bound and Free variables Each λ x.M declares a new local variable x
there is no λx in the expression M, or x appears outside all λx declarations in M
λ x => λ y. (z1*x+z2 y) λ y => (z1x+z2 *y)
Variable Binding
Rename bound variables to avoid conflict Functions with and without names
Equality of Lambda Terms
λ x. (x + y) = λ z. (z + y) But λ x. (x + y) ≠ λ y. (y + y)
(λ x. λ y. (x + y)) z1 = λ y. (z1+y) But (λ x. λ y. (x + y)) y ≠ λ y. (y + y)
Evaluation of Lambda-terms
where [t 2 /x]t 1 involves renaming as needed Rename bound variables in t 1 if they appear free in t 2 α-conversion: λ x. M => λ y. [y/x]M (y is not free in M) Replaces all free occurrences of x in t 1 with t 2
Each reducible expression is called a redex
An expression that cannot be further reduced
Final result (if there is one) is uniquely determined
Additional Exercises
Non-terminating Reductions
(λ x. x x) (λ x. x x) =>(λ y. y y) (λ x. x x) =>(λ x. x x) (λ x. x x) …
Pure lambda terms without free variables
Yf => f(Yf)
Yf = ( λ f. ( λ x. f (x x)) ( λ x. f (x x))) f => ( λ x. f (x x)) ( λ x. f (x x)) => f (( λ x. f (x x)) ( λ x. f (x x))) => f (Yf)