Class 33: Learning to Count CS200: Computer Science

Slides:



Advertisements
Similar presentations
Class 21: Imperative Programming University of Virginia cs1120 David Evans.
Advertisements

Cs1120 Fall 2009 David Evans Lecture 16: Power Analysis.
David Evans CS200: Computer Science University of Virginia Computer Science Class 30: Models of Computation.
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 39: Lambda Calculus.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 16: Quicker Sorting.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 40: Computing with Glue and Photons.
David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 2: Modeling Computers.
Cs3102: Theory of Computation Class 20: Busy Beavers Spring 2010 University of Virginia David Evans Office hours: I am not able to hold my Thursday morning.
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
Lecture 20: λ Calculus λ Calculus & Computability Yan Huang Dept. of Comp. Sci. University of Virginia.
Class 37: Computability in Theory and Practice cs1120 Fall 2011 David Evans 21 November 2011 cs1120 Fall 2011 David Evans 21 November 2011.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
David Evans CS200: Computer Science University of Virginia Computer Science Class 38: Fixed Points and Biological Computing.
Lecture 31: Laziness University of Virginia cs1120 Fall 2009 David Evans.
Lecture 8: The Meaning of Life, Searching for Truth and The Stuff Primitives are Made Of (and a smattering of Quantum Physics) David Evans
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 10: Puzzling Pegboards.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 12: QuickSorting Queen’s University,
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Mutation M. C. Escher, Day and.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
Class 7: List Procedures David Evans cs1120 Fall 2009.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 14: P = NP?
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
David Evans CS150: Computer Science University of Virginia Computer Science Class 32: Computability in Theory and Practice.
David Evans CS200: Computer Science University of Virginia Computer Science Class 26: Halting Problem It is plain at any.
Cs3102: Theory of Computation (aka cs302: Discrete Mathematics II) Spring 2010 University of Virginia David Evans.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 8: Cons car cdr sdr wdr.
(Thunking about Thunks)
Lecture 4: Metacircles Eval Apply David Evans
Lecture 6: Lambda Calculus
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Class 22: Inheritance CS150: Computer Science University of Virginia
Class 27: Universal Turing Machines CS150: Computer Science
Lecture 13: Quicksorting CS200: Computer Science
Class 30: Models of Computation CS200: Computer Science
Lecture 7: List Recursion CS200: Computer Science
Lecture 37: A Universal Computer
Lambda Calculus Revisited
Class 19: Think Globally, Mutate Locally CS150: Computer Science
Lecture 8: Recursion Practice CS200: Computer Science
Lecture 16: Quickest Sorting CS150: Computer Science
Lecture 6: Programming with Data CS150: Computer Science
Lecture 21: Inheritance CS200: Computer Science University of Virginia
Lecture 11: All Sorts CS200: Computer Science University of Virginia
David Evans Lecture 9: The Great Lambda Tree of Infinite Knowledge and Ultimate Power CS200: Computer Science University.
Lecture 28: Types of Types
Class 36: The Meaning of Truth CS200: Computer Science
Lecture 13: Cost of Sorts CS150: Computer Science
Lecture 22: P = NP? CS200: Computer Science University of Virginia
Lecture 24: Metalinguistics CS200: Computer Science
Class 37: Making Lists, Numbers and Recursion from Glue Alone
Lecture 27: In Praise of Idleness CS200: Computer Science
Lecture 26: The Metacircular Evaluator Eval Apply
Class 33: Making Recursion M.C. Escher, Ascending and Descending
Lecture 9: The Great Lambda Tree of Knowledge and Power
Class 31: Universal Turing Machines CS200: Computer Science
Lecture 10: Fixed Points ad Infinitum M.C. Escher, Moebius Ants
Class 34: Models of Computation CS200: Computer Science
Cs1120 Fall 2009 David Evans Lecture 10: Fracturing Fractals cs1120 Fall 2009 David Evans
Class 26: Modeling Computing CS150: Computer Science
Lecture 14: Mocking Mockingbirds
Lecture 15: Crazy Eddie and the Fixed Points Background
Lecture 15: Quicker Sorting CS150: Computer Science
Lecture 11: Sorting Grounds and Bubbles
Lecture 8: Recursing Lists CS150: Computer Science
Lecture 25: The Metacircular Evaluator Eval Apply
Presentation transcript:

David Evans http://www.cs.virginia.edu/evans Class 33: Learning to Count CS200: Computer Science University of Virginia Computer Science David Evans http://www.cs.virginia.edu/evans

Universal Computation z z z z z z z z z z z z z z z z z z z z ), X, L 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 ), #, R (, #, L 1 2: look for ( Start (, X, R HALT #, 1, - #, 0, - Finite State Machine To prove Lambda Calculus is as powerful as a UTM, we must show we can make everything we need to simulate any TM. 23 January 2004 CS 200 Spring 2004

Making “Primitives” from Only Glue () 23 January 2004 CS 200 Spring 2004

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 23 January 2004 CS 200 Spring 2004

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

Finding the Truth if T M N 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? 23 January 2004 CS 200 Spring 2004

and and or? and  x (y. if x y F)) or  x (y. if x T y)) 23 January 2004 CS 200 Spring 2004

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 23 January 2004 CS 200 Spring 2004

42 forty-two XLII What is 42? cuarenta y dos 23 January 2004 CS 200 Spring 2004

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. 23 January 2004 CS 200 Spring 2004

Meaning of Numbers pred (succ N)  N succ (pred N) succ (pred (succ N))  succ N 23 January 2004 CS 200 Spring 2004

Meaning of Zero zero? zero  T zero? (succ zero)  F zero? (pred (succ zero)) 23 January 2004 CS 200 Spring 2004

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)) 23 January 2004 CS 200 Spring 2004

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

zero?  null? pred  cdr succ   x . cons F x Numbers are Lists... 23 January 2004 CS 200 Spring 2004

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)) 23 January 2004 CS 200 Spring 2004

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 (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 23 January 2004 CS 200 Spring 2004

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   N 23 January 2004 CS 200 Spring 2004

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 23 January 2004 CS 200 Spring 2004

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 23 January 2004 CS 200 Spring 2004

Counting 0  null 1  cons F 0 2  cons F 1 3  cons F 2 ... succ  x.cons F x pred  x.cdr x 23 January 2004 CS 200 Spring 2004

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 23 January 2004 CS 200 Spring 2004

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 23 January 2004 CS 200 Spring 2004

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! 23 January 2004 CS 200 Spring 2004

Way to Keep Going ( 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))  ... This should give you some belief that we might be able to do it. We won’t cover the details of why this works in this class. (CS655 sometimes does.) 23 January 2004 CS 200 Spring 2004

Charge Monday: Review session for Exam 2 Tuesday Office Hours Exam 2 covers through today There will definitely be a question that requires understanding the answer to question 5 on the PS7 comments! Tuesday Office Hours 1-2pm and 4-5pm Exam 2 out Wednesday 23 January 2004 CS 200 Spring 2004