David Evans http://www.cs.virginia.edu/~evans Class 37: Making Lists, Numbers and Recursion from Glue Alone CS200: Computer Science University of Virginia Computer Science David Evans http://www.cs.virginia.edu/~evans
Menu Review Making Numbers and Lists Lambda Calculus How to Prove Something is a Universal Computer Last time: The Meaning of Truth Making Numbers and Lists Making Recursive Definitions without define 22 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 ] 22 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 22 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 22 April 2002 CS 200 Spring 2002
Making “Primitives” 22 April 2002 CS 200 Spring 2002
The Meaning of Truth 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? 22 April 2002 CS 200 Spring 2002
and and or? and xy. if x y F or xy. if x T y 22 April 2002 CS 200 Spring 2002
Meaning of Life Okay, so we know the meaning of truth. Can we make the meaning of life also? 22 April 2002 CS 200 Spring 2002
What is 42? 42 forty-two XXXXII 22 April 2002 CS 200 Spring 2002
Meaning of Numbers “42-ness” is something who’s successor is “43-ness” “42-ness” is something who’s predecessor is “41-ness” “Zero” is special. It has a successor “one-ness”, but no predecessor. 22 April 2002 CS 200 Spring 2002
Meaning of Numbers pred (succ N) N succ (pred N) succ (pred (succ N)) succ N 22 April 2002 CS 200 Spring 2002
Meaning of Zero zero? zero T zero? (succ zero) F zero? (pred (succ zero)) 22 April 2002 CS 200 Spring 2002
Is this enough? add xy.if (zero? x) y (add (pred x) (succ y)) Can we define add with pred, succ, zero? and zero? add xy.if (zero? x) y (add (pred x) (succ y)) 22 April 2002 CS 200 Spring 2002
Can we define lambda terms that behave like zero, zero?, pred and succ? Hint: what if we had cons, car and cdr? 22 April 2002 CS 200 Spring 2002
zero? x = null? x pred x = cdr x succ x = cons F x Numbers are Lists... zero? x = null? x pred x = cdr x succ x = cons F x 22 April 2002 CS 200 Spring 2002
cons and car cons x.y.z.zxy car p.p T T x . y. x cons M N = (x.y.z.zxy) M N (y.z.zMy) N z.zMN car p.p T car z.zMN = (p.p T) z.zMN (z.zMN) T TMN (x . y. x) MN (y. M)N M T x . y. x 22 April 2002 CS 200 Spring 2002
cdr too! cons xyz.zxy car p.p T cdr p.p F cdr cons M N cdr z.zMN = (p.p F) z.zMN (z.zMN) F FMN (x . y. y) MN (y. y)N N 22 April 2002 CS 200 Spring 2002
Null and null? null x.T null? x.(x y.z.F) null? null x.(x y.z.F) (x. T) (x. T)(y.z.F) T 22 April 2002 CS 200 Spring 2002
Null and null? null x.T null? x.(x y.z.F) null? (cons M N) x.(x y.z.F) z.zMN (z.z MN)(y.z.F) (y.z.F) MN F 22 April 2002 CS 200 Spring 2002
Counting 0 null 1 cons F 0 2 cons F 1 3 cons F 2 ... succ x.cons F x pred x.cdr x 22 April 2002 CS 200 Spring 2002
42 = xy. (z. z xy) xy. y xy. (z. z xy) xy. y xy. (z. z xy) xy 42 = xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y xy.(z.z xy) xy. y x.T 22 April 2002 CS 200 Spring 2002
Arithmetic zero? null? succ x. cons F x pred x.x F pred 1 = (x.x F) cons F null (cons F null) F (xyz.zxy F null) F (z.z F null) F F F null null = 0 22 April 2002 CS 200 Spring 2002
Lambda Calculus is a Universal Computer 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 We have this, but we cheated using to make recursive definitions! 22 April 2002 CS 200 Spring 2002
Charge Progress Meetings today and tomorrow Wednesday: Friday: review Demonstrate and explain what you have done so far Explain your plans for finishing Wednesday: show we can make recursive definitions with Lambda Calculus computing and biology Friday: review 22 April 2002 CS 200 Spring 2002