Class 32 The Meaning of Truth CS 200

  • Slides: 14
Download presentation
Class 32: The Meaning of Truth CS 200: Computer Science David Evans University of

Class 32: The Meaning of Truth CS 200: Computer Science David Evans University of Virginia 7 April 2004 CS 200 Spring 2004 http: //www. cs. virginia. edu/evans Computer Science

Menu • Lambda Calculus Review • How to Prove Something is a Universal Computer

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

Lambda Calculus Review term : : = variable |term | (term)| variable. term Parens

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

Alyssa P. Hacker’s Answer ( f. (( x. f (xx)))) ( z. z) (

Alyssa P. Hacker’s Answer ( f. (( x. f (xx)))) ( z. z) ( x. ( z. z)(xx)) ( z. z) ( x. ( z. z)(xx)) ( x. ( z. z)(xx)) . . . 7 April 2004 CS 200 Spring 2004 4

Ben Bitdiddle’s Answer ( f. (( x. f (xx)))) ( z. z) ( x.

Ben Bitdiddle’s Answer ( f. (( x. f (xx)))) ( z. z) ( x. ( z. z)(xx)) ( x. xx) . . . 7 April 2004 CS 200 Spring 2004 5

Be Very Afraid! • Some -calculus terms can be -reduced forever! • The order

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 April 2004 CS 200 Spring 2004 6

Take on Faith (until CS 655) • All ways of choosing reductions that reduce

Take on Faith (until CS 655) • 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 if there is one. – This is normal order reduction – corresponds to normal order (lazy) evaluation 7 April 2004 CS 200 Spring 2004 7

Universal Language • Is Lambda Calculus a universal language? – Can we compute any

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 7 April 2004 CS 200 Spring 2004 8

Simulating Every Turing Machine • A Universal Turing Machine can simulate every Turing Machine

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 7 April 2004 CS 200 Spring 2004 9

Simulating Computation z z z z ), X, L ), #, R (, #,

Simulating Computation z z z z ), X, L ), #, R (, #, L 2: look for ( 1 Start (, X, R #, 1, - HAL T #, 0, - Finite State Machine 7 April 2004 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? CS 200 Spring 2004 10

Simulating Computation z z z z ), X, L ), #, R (, #,

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

Making “Primitives” from Only Glue ( ) 7 April 2004 CS 200 Spring 2004

Making “Primitives” from Only Glue ( ) 7 April 2004 CS 200 Spring 2004 12

In search of the truth? • What does true mean? • True is something

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 7 April 2004 CS 200 Spring 2004 13

Charge • Remember: if you have team requests for PS 8, I must receive

Charge • Remember: if you have team requests for PS 8, I must receive them before midnight tonight! • Friday: finish discovering truth (and proving lambda calculus is as powerful as a Turing Machine) • Monday: Review session for Exam 2 7 April 2004 CS 200 Spring 2004 14