University of Virginia, Department of Computer Science
cs150: Computer Science — Spring 2007
cs150  Spring 2007

## cs150: Notes 39

#### Schedule

• Friday, 27 April (midnight): Qualify for Project Presentation
• Monday, 30 April: Project Presentations (Problem Set 9)
• Monday, 7 May: Last day to turn in Final Exam (out Monday, 30 April)

Slides: [PPT], [PDF]

What is a calculus?

Lambda Calculus is a set of rules for manipulating symbols. They can be given meanings that map well to computation.

Lambda Calculus Term Grammar

term ::= variable
term ::= term term
term ::= ( term )
term ::= λ variable . term

Rules

Alpha Reduction: (renaming variables)

λ y . Mα λ v . M [y |→ v]) where v does not occur in M.
We can change the name of a lambda variable by 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 ]
All computation can be modeled using Beta Reduction!

Examples

I ≡ λ x . x
C ≡ λ x .y . yx)

CII = (λx.(λy. yx)) (λx.x) (λx.x)

→β

λ f . ((λ x . f (xx)) (λ x . f (xx)))

→β

(Note: you may need some more space to finish this one.)

Making "Primitives" out of nothing but Glue

T

F

if

cons ≡ λ xy .z . zxy)

car

cdr

null ≡ λ p . T
null? ≡ λ x . (x λ y . λ z . F)

zero?null?
predcdr
succ ≡ λ x . cons F x

0null
1succ 0cons F null
2