david evans cs.virginia/evans
DESCRIPTION
Class 33: Learning to Count. David Evans http://www.cs.virginia.edu/evans. CS200: Computer Science University of Virginia Computer Science. Universal 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 - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/1.jpg)
David Evanshttp://www.cs.virginia.edu/evans
CS200: Computer ScienceUniversity of VirginiaComputer Science
Class 33:Learning to Count
![Page 2: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/2.jpg)
23 January 2004 CS 200 Spring 2004 2
Universal Computationz z z z z z z z z z z z z z z zz z z z
1
Start
HALT
), X, L
2: look for (
#, 1, -
), #, R
(, #, L
(, X, R
#, 0, -
Finite State Machine
Read/Write Infinite TapeMutable Lists
Finite State MachineNumbers to keep track of state
ProcessingWay of making decisions (if)Way to keep going
To prove Lambda Calculus is as powerful as a UTM, we must show we can make everything we need to simulate any TM.
![Page 3: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/3.jpg)
23 January 2004 CS 200 Spring 2004 3
Making “Primitives”from Only Glue ()
![Page 4: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/4.jpg)
23 January 2004 CS 200 Spring 2004 4
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
![Page 5: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/5.jpg)
23 January 2004 CS 200 Spring 2004 5
Don’t search for T, search for if
T x (y. x) xy. x
F x ( y. y))if pca . pca
![Page 6: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/6.jpg)
23 January 2004 CS 200 Spring 2004 6
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?
![Page 7: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/7.jpg)
23 January 2004 CS 200 Spring 2004 7
and and or?
and x (y. if x y F))
or x (y. if x T y))
![Page 8: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/8.jpg)
23 January 2004 CS 200 Spring 2004 8
Lambda Calculus is a Universal Computer?
z z z z z z z z z z z z z z z zz z z z
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
![Page 9: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/9.jpg)
23 January 2004 CS 200 Spring 2004 9
What is 42?
42forty-two
XLIIcuarenta y dos
![Page 10: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/10.jpg)
23 January 2004 CS 200 Spring 2004 10
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.
![Page 11: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/11.jpg)
23 January 2004 CS 200 Spring 2004 11
Meaning of Numberspred (succ N)
Nsucc (pred N)
Nsucc (pred (succ N))
succ N
![Page 12: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/12.jpg)
23 January 2004 CS 200 Spring 2004 12
Meaning of Zerozero? zero
T zero? (succ zero)
F zero? (pred (succ zero))
T
![Page 13: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/13.jpg)
23 January 2004 CS 200 Spring 2004 13
Is this enough?
• Can we define add with pred, succ, zero? and zero?
add xy.if (zero? x) y
(add (pred x) (succ y))
![Page 14: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/14.jpg)
23 January 2004 CS 200 Spring 2004 14
Can we define lambda terms that behave likezero, zero?, pred and succ?
Hint: what if we had cons, car and cdr?
![Page 15: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/15.jpg)
23 January 2004 CS 200 Spring 2004 15
Numbers are Lists...
zero? null?pred cdr succ x . cons F x
![Page 16: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/16.jpg)
23 January 2004 CS 200 Spring 2004 16
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))
![Page 17: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/17.jpg)
23 January 2004 CS 200 Spring 2004 17
cons and carcons x.y.z.zxy
cons M N = (x.y.z.zxy) M N (y.z.zMy) N
z.zMN
car p.p Tcar (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
![Page 18: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/18.jpg)
23 January 2004 CS 200 Spring 2004 18
cdr too!cons xyz.zxy
car p.p Tcdr p.p F
cdr cons M Ncdr z.zMN = (p.p F) z.zMN
(z.zMN) F
FMN
N
![Page 19: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/19.jpg)
23 January 2004 CS 200 Spring 2004 19
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
![Page 20: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/20.jpg)
23 January 2004 CS 200 Spring 2004 20
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
![Page 21: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/21.jpg)
23 January 2004 CS 200 Spring 2004 21
Counting
0 null1 cons F 0
2 cons F 1
3 cons F 2
...
succ x.cons F x
pred x.cdr x
![Page 22: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/22.jpg)
23 January 2004 CS 200 Spring 2004 22
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
![Page 23: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/23.jpg)
23 January 2004 CS 200 Spring 2004 23
Arithmeticzero? null?succ x. cons F xpred 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
![Page 24: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/24.jpg)
23 January 2004 CS 200 Spring 2004 24
Lambda Calculus is a Universal Computer
z z z z z z z z z z z z z z z zz z z z
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, butwe cheated using to make recursive definitions!
![Page 25: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/25.jpg)
23 January 2004 CS 200 Spring 2004 25
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))
(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 mightbe able to do it. We won’t cover the details of whythis works in this class. (CS655 sometimes does.)
![Page 26: David Evans cs.virginia/evans](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815a8e550346895dc80454/html5/thumbnails/26.jpg)
23 January 2004 CS 200 Spring 2004 26
Charge
• Monday: Review session for Exam 2– 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