Transcript slides
Class 36:
The Meaning
of Truth
CS200: Computer Science
University of Virginia
Computer Science
David Evans
http://www.cs.virginia.edu/~evans
Menu
• Lambda Calculus Review
• How to Prove Something is a Universal
Computer
• Making “Primitives”
19 April 2002
CS 200 Spring 2002
2
Lambda Calculus
term ::= variable |term term | (term)| variable . term
-reduction
(renaming)
y. M v. (M [y v])
where v does not occur in M.
-reduction
(substitution)
(x. M)N M [ x N ]
19 April 2002
CS 200 Spring 2002
3
Some Simple Functions
I x.x
C xy.yx
Abbreviation for x.(y. yx)
CII = (x.(y. yx)) (x.x) (x.x)
(y. y (x.x)) (x.x)
x.x (x.x)
x.x
=I
19 April 2002
CS 200 Spring 2002
4
Evaluating Lambda Expressions
• redex: Term of the form (x. M)N
Something that can be -reduced
• An expression is in normal form if it
contains no redexes (redices).
• To evaluate a lambda expression, keep
doing reductions until you get to normal
form.
19 April 2002
CS 200 Spring 2002
5
Example
( f. (( x.f (xx))
( x. f (xx))))
(z.z)
19 April 2002
CS 200 Spring 2002
6
Alyssa P. Hacker’s Answer
( f. (( x.f (xx)) ( x. f (xx)))) (z.z)
(x.(z.z)(xx)) ( x. (z.z)(xx))
(z.z) ( x.(z.z)(xx)) ( x.(z.z)(xx))
(x.(z.z)(xx)) ( x.(z.z)(xx))
(z.z) ( x.(z.z)(xx)) ( x.(z.z)(xx))
(x.(z.z)(xx)) ( x.(z.z)(xx))
...
19 April 2002
CS 200 Spring 2002
7
Ben Bitdiddle’s Answer
( f. (( x.f (xx)) ( x. f (xx)))) (z.z)
(x.(z.z)(xx)) ( x. (z.z)(xx))
(x.xx) (x.(z.z)(xx))
(x.xx) (x.xx)
(x.xx) (x.xx)
...
19 April 2002
CS 200 Spring 2002
8
Be Very Afraid!
• Some -calculus terms can be -reduced
forever!
• The order in which you choose to do the
reductions might change the result!
19 April 2002
CS 200 Spring 2002
9
Take on Faith (until CS655)
• All ways of choosing reductions that reduce
a lambda expression to normal form will
produce the same normal form (but some
might never produce a normal form).
• If we always apply the outermost lambda
first, we will find the normal form is there is
one.
– This is normal order reduction – corresponds to
normal order (lazy) evaluation
19 April 2002
CS 200 Spring 2002
10
Church-Turing Thesis
• Any mechanical computation can be
performed by Lambda Calculus reduction
rules
• There is a Lambda Calculus term
equivalent to every Turing Machine
19 April 2002
CS 200 Spring 2002
11
Proof
• Show you can implement a Turing
Machine using Lambda Calculus
19 April 2002
CS 200 Spring 2002
12
What do we need?
z z
z
z
z
z
z
z
z
z
z
z
z
z
z
z z
z
z
z
), X, L
), #, R
(, #, L
2:
look
for (
1
Start
(, X, R
#, 1, -
HALT
#, 0, -
Finite State Machine
19 April 2002
Read/Write Infinite Tape
Mutable Lists
Finite State Machine
Numbers to keep track of state
Processing
Way of making decisions (if)
Way to keep going
CS 200 Spring 2002
13
Lambda Calculus
Summary so Far
• Rules for substitution
• Rules for reduction (only -reduction
does real work: substitution)
• Normal form (no more reductions
possible)
• On faith: if you do outermost -reduction
first, you find the normal form if there is
one
19 April 2002
CS 200 Spring 2002
14
Lambda Calculus Intuition
• Lambda expression corresponds to a
computation
• Normal form is that value of that
computation
• But...can we do useful computations
without primitives?
19 April 2002
CS 200 Spring 2002
15
Making “Primitives”
19 April 2002
CS 200 Spring 2002
16
In search of the truth?
• What does true mean?
• True is something that when used as the
first operand of if, makes the value of the
if the value of its second operand:
if T M N M
19 April 2002
CS 200 Spring 2002
17
Don’t search for T, search for if
T x (y. x)
xy. x
F xy. y
if pca . pca
19 April 2002
CS 200 Spring 2002
18
Finding the Truth
T x . (y. x)
F x . (y. y)
if p . (c . (a . pca)))
Is the if necessary?
if T M N
((pca . pca) (xy. x)) M N
(ca . (x.(y. x)) ca)) M N
(x.(y. x)) M N
(y. M )) N M
19 April 2002
CS 200 Spring 2002
19
Charge
• Schedule Progress Meetings Now!
• For your meeting be prepared
– To demonstrate and explain what you have
done so far
– To explain your plans for finishing
19 April 2002
CS 200 Spring 2002
20