1 / 17

David Evans cs.virginia/evans

Class 27: Modeling Computation. David Evans http://www.cs.virginia.edu/evans. CS200: Computer Science University of Virginia Computer Science. Halting Problem.

Download Presentation

David Evans cs.virginia/evans

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class 27: Modeling Computation David Evans http://www.cs.virginia.edu/evans CS200: Computer Science University of Virginia Computer Science

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. How should we model a Computer? Colossus (1944) Cray-1 (1976) Apollo Guidance Computer (1969) CS 200 Spring 2004 IBM 5100 (1975)

  13. 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

  14. Modeling Input Punch Cards Altair BASIC Paper Tape, 1976 Engelbart’s mouse and keypad CS 200 Spring 2004

  15. 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

  16. 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

  17. Charge • PS6 due Monday • Friday: • Finite state machines with infinite tape CS 200 Spring 2004

More Related