170 likes | 182 Views
Class 27: Modeling Computation. David Evans http://www.cs.virginia.edu/evans. CS200: Computer Science University of Virginia Computer Science. Halting Problem.
E N D
Class 27: Modeling Computation David Evans http://www.cs.virginia.edu/evans CS200: Computer Science University of Virginia Computer Science
Halting Problem Define a procedure halts? that takes a procedure and an input evaluates to #t if the procedure would terminate on that input, and to #f if would not terminate. (define (halts? procedure input) … ) CS 200 Spring 2004
Informal Proof (define (contradict-halts x) (if (halts? contradict-halts null) (loop-forever) #t)) If contradict-halts halts, the if test is true and it evaluates to (loop-forever) - it doesn’t halt! If contradict-halts doesn’t halt, the if test if false, and it evaluates to #t. It halts! CS 200 Spring 2004
Proof by Contradiction • Show X is nonsensical. • Show that if you have A and B you can make X. • Show that you can make A. • Therefore, B must not exist. X = contradict-halts A = a Scheme interpreter that follows the evaluation rules B = halts? CS 200 Spring 2004
Virus Detection Problem Problem 7. Melissa Problem Input: A Word macro (like a program, but embedded in an email message) Output: true if the macro will forward the message to people in your address book; false otherwise. How can we show it is undecidable? CS 200 Spring 2004
Proof by Contradiction • Show X is nonsensical. • Show that if you have A and B you can make X. • Show that you can make A. • Therefore, B must not exist. X = halts? A = a Scheme interpreter that follows the evaluation rules B = is-virus? CS 200 Spring 2004
Undecidability Proof Suppose we could define is-virus? that decides the Melissa problem. Then: (define (halts? P input) (if (is-virus? ‘(begin (P input) virus-code)) #t #f)) Since it is a virus, we know virus-code was evaluated, and P must halt (assuming P wasn’t a virus). Its not a virus, so the virus-code never executed. Hence, P must not halt. CS 200 Spring 2004
Undecidability Proof Suppose we could define is-virus? that decides the Melissa problem. Then: (define (halts? P input) (is-virus? ‘(begin ((vaccinate P) input) virus-code)) Where (vaccinate P) evaluates to P with all mail commands replaced with print commands (to make sure (is-virus? P input) is false. CS 200 Spring 2004
Proof • If we had is-virus? we could define halts? • We know halts? is undecidable • Hence, we can’t have is-virus? • Thus, we know is-virus? is undecidable CS 200 Spring 2004
How convincing is our Halting Problem proof? (define (contradict-halts x) (if (halts? contradict-halts null) (loop-forever) #t)) If contradict-halts halts, the if test is true and it evaluates to (loop-forever) - it doesn’t halt! If contradict-halts doesn’t halt, the if test if false, and it evaluates to #t. It halts! This “proof” assumes Scheme exists and is consistent! CS 200 Spring 2004
Modeling Computation • For a more convincing proof, we need a more precise (but simple) model of what a computer can do • Another reason we need a model: Does (n) really make sense without this? CS 200 Spring 2004
How should we model a Computer? Colossus (1944) Cray-1 (1976) Apollo Guidance Computer (1969) CS 200 Spring 2004 IBM 5100 (1975)
Modeling Computers • Input • Without it, we can’t describe a problem • Output • Without it, we can’t get an answer • Processing • Need some way of getting from the input to the output • Memory • Need to keep track of what we are doing CS 200 Spring 2004
Modeling Input Punch Cards Altair BASIC Paper Tape, 1976 Engelbart’s mouse and keypad CS 200 Spring 2004
Simplest Input • Non-interactive: like punch cards and paper tape • One-dimensional: just a single tape of values, pointer to one square on tape 0 0 1 1 0 0 1 0 0 0 How long should the tape be? Infinitely long! We are modeling a computer, not building one. Our model should not have silly practical limitations (like a real computer does). CS 200 Spring 2004
Modeling Output • Blinking lights are cool, but hard to model • Output is what is written on the tape at the end of a computation Connection Machine CM-5, 1993 CS 200 Spring 2004
Charge • PS6 due Monday • Friday: • Finite state machines with infinite tape CS 200 Spring 2004