Lambda Calculus
-
Author
rafaelferreira -
Category
Science
-
view
223 -
download
0
Embed Size (px)
Transcript of Lambda Calculus
-
rafael de f. ferreira (@rafaeldff)
lambda calculus
-
David Hilbert
2
Wir mssen wissen. Wir werden wissen.
We must know.We will know.
-
3
Alonzo Church
-
Syntax
4
t ::= x x. t t t
terms: variable
abstraction application
-
Example expressions
5
x x y x. x x. y
(x. x) y (x. x x) z (x. x x) (x. x x) (f. (x. f (y. x x y)) (x. f (y. x x y)))
-
Example expressions
6
(x. x) yvariable
abstraction
variable
application
-
Substitution
7
[yz](x. (x. y x)) y=
(x. (x. z x)) z
-
Semantics
8
(x. t1) t2 [xt2]t1 beta reduction
redex
-
Semantics - examples
9
(x. x) y y
-
Semantics - examples
10
(x. x) (y. y y) (y. y y)
-
Semantics - examples
11
(x.(z.x z)) y (z.y z)
-
12
Church Booleans
-
booleans
13
(t. (f. t))
(t. (f. f))
(b. (t. (f. b t f))
true
false
if
-
booleans - example
14
if false (x. x) (z. z)
(b. (t. (f. b t f)) false (x. x) (z. z)
(t. (f. false t f)) (x. x) (z. z)
(f. false (x. x) f) (z. z)
false (x. x) (z. z)
=
-
booleans - example
15
false (x. x) (z. z)
(t. (f. f)) (x. x) (z. z)
(f. f) (z. z) (z. z)
=
-
booleans - example
16
if false (x. x) (z. z) * (z. z)
-
17
Church Numerals
-
numerals
18
s. z. z
s. z. s z
s. z. s (s z)
s. z. s (s (s z))
c0
c1
c2
c3
-
numerals
19
succ = n. s. z. s (n s z)
-
numerals
20
succ c1
(n. s. z. s (n s z)) c1
s. z. s ((s. z. s z) s z) s. z. s ((z. s z) z) s. z. s (s z) = c2
=
=
-
numerals
21
plus = m. n. s. z. m s (n s z)
-
booleans - example
22
plus c0 c1 * c1 plus c1 c1 * c2 plus c2 c2 * c4
-
23
Recursion
-
recursion
24
= (x. x x) (x. x x)
-
recursion
25
= (x. x x) (x. x x) (x. x x) (x. x x) (x. x x) (x. x x) (x. x x) (x. x x)
-
recursion
26
Y = f. (x. f (y. x x y)) (x. f (y. x x y))
-
recursion
27
Y = f. (x. f (y. x x y)) (x. f (y. x x y))
Y f = f (Y f) for all f
-
recursion
28
g = fct. n if (eq n c0) c1 (times n (fct (pred n)))
factorial = Y g
Y f = f (Y f) for all f
-
Propositions as TypesPhilip Wadler
Introduction to Lambda Calculus
Barendregt, Barendsen