syntax rules for reducing lambda expressions
TRANSCRIPT
-
7/30/2019 Syntax Rules for Reducing Lambda Expressions
1/2
Syntax Rules for Reducing Lambda Expressions
In mathematics function application is written as f(2), but in the lambda calculus (and Lisp) function
application is written as (f 2). Appling a function is evaluation is -reduction.
Application has higher precedence than abstraction. Application is left-associative. So that
s t x (s t) x and (f a b c) (((f a) b) c)
(BTW: We see the same in arithmetic: 123 =4 (12)3
1(23) = 1(1) = 2)
As a lambda expression
(x. y. z.xyz) 1 2 3 (x. (y. (z.xyz))) 1 2 3
(y. (z.1yz)) 2 3
(z.12z)) 3
(z.1z)) 3
(13)
Abstraction is right-associative. So the scope of extends as far to the right as possible.So x.y.x y (x.(y.(x y))) and x.x z y.x y x.((x z) (y.(x y)))
Complicated Example
Considerm.n.a.b.m n a b bf.x.xf.x.f x First we introduce explicit parentheseseverywhere to avoid confusion
(m. n. a. b. m (n a b) b) f.x.xf.x.f x Application has higher precedence and itis right associative
m. n. a. b.(m (n a b) b) (f. x.x)f.(x. f x) Abstraction () is
left associative and extends as far as possible
Now we can start with the reduction:
m. n. a. b. (m (n a b) b) (f. x.x)f.(x. f x) Bind m to (f. x.x)=> n.a. b. (f. x.x) (n a b) b f.(x. f x)Bind n to f.(x. f x)=> a. b.(f. x.x) f.(x. f x) a b b Nothing bound to a and b=> a.b.(f. x.x) (.(x. f x) ) b b Bind f to a (we could have left the outer
parentheses
=> a.b. (f. x.x) (. a x) b Bind x to b=> a.b. f. x.x a b b Bind f to (a b) and discard since no f in
expression
=>
a.b.(x.x b)Bind x to b (identity)
=> a.b.b Done (did not have to removeparentheses)
-
7/30/2019 Syntax Rules for Reducing Lambda Expressions
2/2
Syntax Rules for Reducing Lambda Expressions 2
-reduction foridentity (identity (z.identity z))x.x(x.xz. x.xz) . . .(.) Introduce parentheses for scope of inner x.x x.x z.(x. xz) Bind x to z=> x.x(x.xz.z) Remove superfluous parentheses=> .(.z.z) Bind x to z.z=> (.z.z) Bind x to z.z=> z.z