Presentation is loading. Please wait.

Presentation is loading. Please wait.

David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.

Similar presentations


Presentation on theme: "David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth."— Presentation transcript:

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

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

3 14 April 2003CS 200 Spring 20033 Lambda Calculus Review ( f. (( x. f (xx)) ( x. f (xx)))) ( z.z) 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 ] Parens are just for grouping, not like in Scheme

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

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

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

7 14 April 2003CS 200 Spring 20037 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

8 14 April 2003CS 200 Spring 20038 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

9 14 April 2003CS 200 Spring 20039 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

10 14 April 2003CS 200 Spring 200310 Simulating Computation zzzzzzzzzzzzzzzzzzzz 1 Start HALT ), X, L 2: look for ( #, 1, -  ), #, R  (, #, L (, X, R #, 0, - Finite State Machine 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?

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

12 14 April 2003CS 200 Spring 200312 Making “Primitives” from Only Glue ( )

13 14 April 2003CS 200 Spring 200313 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

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

15 14 April 2003CS 200 Spring 200315 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?

16 14 April 2003CS 200 Spring 200316 and and or? and  x ( y. if x y F)) or  x ( y. if x T y))

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

18 14 April 2003CS 200 Spring 200318 What is 42? 42 forty-two XXXXII

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

20 14 April 2003CS 200 Spring 200320 Meaning of Numbers pred (succ N )  N N succ (pred N )  N N succ (pred (succ N ))  succ N

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

22 14 April 2003CS 200 Spring 200322 Is this enough? Can we define add with pred, succ, zero? and zero ? add  xy. if ( zero? x) y ( add ( pred x) ( succ y))

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

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

25 14 April 2003CS 200 Spring 200325 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))

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

27 14 April 2003CS 200 Spring 200327 cdr too! cons  xyz.zxy car  p.p T cdr  p.p F cdr cons M N cdr z.z MN = ( p.p F) z.z MN   ( z.z MN) F   FMN   N

28 14 April 2003CS 200 Spring 200328 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

29 14 April 2003CS 200 Spring 200329 Null and null? null  x. T null?  x.(x y. z. F) null? (cons M N)  x.(x y. z. F) z.z MN   ( z.z MN) ( y. z. F)   ( y. z. F) MN   F

30 14 April 2003CS 200 Spring 200330 Counting 0  null 1  cons F 0 2  cons F 1 3  cons F 2... succ  x.cons F x pred  x.cdr x

31 14 April 2003CS 200 Spring 200331 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

32 14 April 2003CS 200 Spring 200332 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  0

33 14 April 2003CS 200 Spring 200333 Lambda Calculus is a Universal Computer zzzzzzzzzzzzzzzzzzzz 1 Start HALT ), X, L 2: look for ( #, 1, -  ), #, R  (, #, L (, X, R #, 0, - Finite State Machine 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 We have this, but we cheated using  to make recursive definitions!

34 14 April 2003CS 200 Spring 200334 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.


Download ppt "David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth."

Similar presentations


Ads by Google