CS200: Computer Science, Spring 2002

Notes: 22 April 2002
Schedule
 Today and tomorrow: Problem Set 8 (Progress Meetings)
 Monday, 29 April: Problem Set 8 (Final)
 Monday, 6 May: Final Due (will be handed out Monday 29 April)
Lambda Calculus
Lambda Calculus Term Grammar
term ::= variable  term term  ( term )  λ variable . termRules
Alpha Reduction: (renaming variables)λ y . M ⇒_{α} λ v . M [y → v]) where v does not occur in M.We can can change the name of a lambda variable, but replacing all occurances of the variable in the body term with a new name that does not appear in the body term.Beta Reduction: (substitution)
(λ x . M) N ⇒_{β} M [ x → N ]Making "Primitives" out of nothing but Glue
T ≡ λ x (λ y . x)
F ≡ λ xy . y
if ≡ λ pca . pca
cons ≡ λ xy . (λ z . zxy)
car ≡ λ p . p T
cdr ≡ λ p . p F
null ≡ λ p . T
null? ≡ λ x . (x λ y . λ z . F)0 ≡ null
1 ≡ cons F null
2 ≡ cons 1 null
succ ≡ λ x . cons F x
pred ≡ λ x cdr x
zero? ≡ null?
Fixed Points
What is a fixed point?
All Lambda Calculus Terms Have Fixed PointsFor any Lambda Calculus term F, there exists a Lambda Calculus Term X such that FX = X.YOperatorProof: W = λ x. F(xx)
X = WW
X = (λ x. F (xx)) (λ x. F (xx))
⇒_{β} F ((λ x. F (xx)) (λ x. F (xx))) = FXY ≡ λ f. (λ x.f (xx)) (λ x.f (xx))The YOperator calculates the fixed point of any Lambda Calculus term!Try this in Scheme:
Why do we need the lambda (y) to make this work in Scheme?(define Y (lambda (f) ((lambda (x) (f (lambda (y) ((x x) y)))) (lambda (x) (f (lambda (y) ((x x) y))))))) (define f (lambda (g) (lambda (n) (if (= n 0) 1 (* n (g ( n 1))))))) ((Y f) 5)Hint: In LazyScheme, it would work with:
How do the evaluation rules of regular Scheme differ from those of Lambda Calculus?(define Y (lambda (f) ((lambda (x) (f (x x))) (lambda (x) (f (x x))))))
University of Virginia Department of Computer Science CS 200: Computer Science 
David Evans evans@virginia.edu Using these Materials 