Class 36 The Meaning of Truth CS 200

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

Class 36: The Meaning of Truth CS 200: Computer Science David Evans University of Virginia 19 April 2002 CS 200 Spring 2002 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” 19 April 2002 CS 200 Spring 2002 2

Lambda Calculus term : : = variable |term | (term)| variable. term -reduction (renaming)

Lambda Calculus term : : = variable |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 3

Some Simple Functions I x. x C xy. yx Abbreviation for x. ( y.

Some Simple Functions I x. x C xy. yx Abbreviation for x. ( y. yx) CII = ( x. ( y. yx)) ( x. x) ( y. y ( x. x)) ( x. x) x. x =I 19 April 2002 CS 200 Spring 2002 4

Evaluating Lambda Expressions • redex: Term of the form ( x. M)N Something that

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 5

Example ( f. (( x. f (xx)))) ( z. z) 19 April 2002 CS

Example ( f. (( x. f (xx)))) ( z. z) 19 April 2002 CS 200 Spring 2002 6

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)) . . . 19 April 2002 CS 200 Spring 2002 7

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) . . . 19 April 2002 CS 200 Spring 2002 8

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! 19 April 2002 CS 200 Spring 2002 9

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 is there is one. – This is normal order reduction – corresponds to normal order (lazy) evaluation 19 April 2002 CS 200 Spring 2002 10

Church-Turing Thesis • Any mechanical computation can be performed by Lambda Calculus reduction rules

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 11

Proof • Show you can implement a Turing Machine using Lambda Calculus 19 April

Proof • Show you can implement a Turing Machine using Lambda Calculus 19 April 2002 CS 200 Spring 2002 12

What do we need? z z z z z ), X, L ), #,

What do we need? z z z z z ), X, L ), #, R (, #, L 2: look for ( 1 Start (, X, R #, 1, - HAL T #, 0, - Finite State Machine 19 April 2002 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 2002 13

Lambda Calculus Summary so Far • Rules for substitution • Rules for reduction (only

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 14

Lambda Calculus Intuition • Lambda expression corresponds to a computation • Normal form is

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 15

Making “Primitives” 19 April 2002 CS 200 Spring 2002 16

Making “Primitives” 19 April 2002 CS 200 Spring 2002 16

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 19 April 2002 CS 200 Spring 2002 17

Don’t search for T, search for if T x ( y. x) xy. x

Don’t search for T, search for if T x ( y. x) xy. x F xy. y if pca 19 April 2002 CS 200 Spring 2002 18

Finding the Truth T x. ( y. x) F x. ( y. y) if

Finding the Truth T x. ( y. x) F x. ( y. y) if p. ( c. ( a. pca))) Is the if necessary? if T M N (( pca) ( xy. x)) M N ( ca. ( x. ( y. x)) ca)) M N ( x. ( y. x)) M N ( y. M )) N M 19 April 2002 CS 200 Spring 2002 19

Charge • Schedule Progress Meetings Now! • For your meeting be prepared – To

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 20