David Evans http://www.cs.virginia.edu/~evans 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
Lambda Calculus -reduction (renaming) y. M v. (M [y v]) 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
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
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
Example ( f. (( x.f (xx)) ( x. f (xx)))) (z.z) 19 April 2002 CS 200 Spring 2002
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)) ... 19 April 2002 CS 200 Spring 2002
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) ... 19 April 2002 CS 200 Spring 2002
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
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
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
Proof Show you can implement a Turing Machine using Lambda Calculus 19 April 2002 CS 200 Spring 2002
What do we need? Read/Write Infinite Tape Mutable Lists z z z z z z z z z z z z z z z z z z z z ), X, L ), #, R (, #, L 1 2: look for ( 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 Start (, X, R HALT #, 1, - #, 0, - Finite State Machine 19 April 2002 CS 200 Spring 2002
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
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
Making “Primitives” 19 April 2002 CS 200 Spring 2002
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
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
Finding the Truth if T M N T x . (y. x) F x . (y. y) if p . (c . (a . pca))) 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 Is the if necessary? 19 April 2002 CS 200 Spring 2002
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