1 / 34

David Evans cs.virginia/evans

Class 32: The Meaning of Truth. David Evans http://www.cs.virginia.edu/evans. CS200: Computer Science University of Virginia Computer Science. Menu. Lambda Calculus Review How to Prove Something is a Universal Computer Making “Primitives”. Lambda Calculus Review.

Download Presentation

David Evans cs.virginia/evans

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class 32: The Meaning of Truth David Evans http://www.cs.virginia.edu/evans CS200: Computer Science University of Virginia Computer Science

  2. Menu • Lambda Calculus Review • How to Prove Something is a Universal Computer • Making “Primitives” CS 200 Spring 2003

  3. Lambda Calculus Review term ::= variable |term term | (term)|  variable .term ( f. (( x.f (xx))( x. f (xx)))) (z.z) Parens are just for grouping, not like in Scheme -reduction (renaming) y. M v. (M [yv]) where v does not occur in M. -reduction (substitution) (x. M)N   M [ xN ] CS 200 Spring 2003

  4. 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)) ... CS 200 Spring 2003

  5. 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) ... CS 200 Spring 2003

  6. Be Very Afraid! • Some -calculus terms can be -reduced forever! • The order in which you choose to do the reductions might change the result! CS 200 Spring 2003

  7. 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 CS 200 Spring 2003

  8. Universal Language • Is Lambda Calculus a universal language? • Can we compute any computable algorithm using Lambda Calculus? • To prove it isn’t: • Find some Turing Machine that cannot be simulated with Lambda Calculus • To prove it is: • Show you can simulate every Turing Machine using Lambda Calculus CS 200 Spring 2003

  9. Simulating Every Turing Machine • A Universal Turing Machine can simulate every Turing Machine • So, to show Lambda Calculus can simulate every Turing Machine, all we need to do is show it can simulate a Universal Turing Machine CS 200 Spring 2003

  10. Simulating Computation z z z z z z z z z z z z z z z z z z z z • Lambda expression corresponds to a computation: input on the tape is transformed into a lambda expression • Normal form is that value of that computation: output is the normal form • How do we simulate the FSM? ), X, L ), #, R (, #, L 2: look for ( 1 Start (, X, R HALT #, 0, - #, 1, - Finite State Machine CS 200 Spring 2003

  11. Simulating Computation z z z z z z z z z z z z z z z z z z z z 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 ), X, L ), #, R (, #, L 2: look for ( 1 Start (, X, R HALT #, 0, - #, 1, - Finite State Machine CS 200 Spring 2003

  12. Making “Primitives”from Only Glue () CS 200 Spring 2003

  13. In search of thetruth? • 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: ifTMN M CS 200 Spring 2003

  14. Don’t search for T, search for if T  x (y. x)  xy. x F  x ( y. y)) if pca . pca CS 200 Spring 2003

  15. Finding the 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? CS 200 Spring 2003

  16. and and or? and x (y. ifxyF)) or x (y. ifxTy)) CS 200 Spring 2003

  17. Meaning of Life • Okay, so we know the meaning of truth. • Can we make the meaning of life also? CS 200 Spring 2003

  18. What is 42? 42 forty-two XXXXII CS 200 Spring 2003

  19. 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. CS 200 Spring 2003

  20. Meaning of Numbers pred (succ N)  N succ (pred N)  N succ (pred (succ N))  succ N CS 200 Spring 2003

  21. Meaning of Zero zero? zero  T zero? (succ zero)  F zero? (pred (succ zero))  T CS 200 Spring 2003

  22. Is this enough? • Can we define add with pred, succ, zero?and zero? add  xy.if(zero?x) y (add(predx)(succy)) CS 200 Spring 2003

  23. Can we define lambda terms that behave likezero, zero?, pred and succ? Hint: what if we had cons, car and cdr? CS 200 Spring 2003

  24. Numbers are Lists... zero?  null? pred  cdr succ   x . cons F x CS 200 Spring 2003

  25. Making Pairs • Remember PS2… (define (make-point x y) (lambda (selector) (if selector x y))) (define (x-of-point point) (point #t)) (define (y-of-point point) (point #f)) CS 200 Spring 2003

  26. cons and car cons x.y.z.zxy cons M N = (x.y.z.zxy)M N   (y.z.zMy)N   z.zMN carp.p T car (cons M N)  car(z.zMN)  (p.p T) (z.zMN)   (z.zMN) T   TMN   (x . y. x)MN   (y. M)N   M T  x . y. x CS 200 Spring 2003

  27. cdr too! cons xyz.zxy carp.p T cdrp.p F cdr consMN cdrz.zMN = (p.p F) z.zMN   (z.zMN) F   FMN   N CS 200 Spring 2003

  28. 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 CS 200 Spring 2003

  29. 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 CS 200 Spring 2003

  30. Counting 0 null 1 cons F 0 2 cons F 1 3 cons F 2 ... succ  x.consFx pred  x.cdrx CS 200 Spring 2003

  31. 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 CS 200 Spring 2003

  32. Arithmetic zero? null? succ  x. cons F x pred x.x F pred 1 = (x.x F) cons Fnull   (cons Fnull) F  (xyz.zxy Fnull) F   (z.z Fnull) F  FFnull   null  0 CS 200 Spring 2003

  33. 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 2: look for ( 1 • 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 #, 0, - #, 1, - Finite State Machine We have this, but we cheated using  to make recursive definitions! CS 200 Spring 2003

  34. Charge • Wednesday: show we can make recursion with Lambda Calculus • Friday: chance to ask questions before Exam 2 is handed out • The real meaning of life lecture is April 25 • Exam 2 covers through today • Office hours this week: • Wednesday, after class - 3:45 • Thursday 10am-10:45am; 4-5pm. CS 200 Spring 2003

More Related