Download Undecidable Problems, Halting Problem - Lecture Slides | CS 1120 and more Study notes Computer Science in PDF only on Docsity!
Greg Humphreys http://www.cs.virginia.edu/~humper CS150: Computer Science University of Virginia Computer Science
Class 25:
Undecidable
Problems
Influenza Virus www.giantmicrobes.com CS150 Spring 6002: Lecture 25: Undecidable Problems (^2)
Menu
- Review:
- Undecidability
- Halting Problem
- How do we prove a problem is undecidable?
- What do we do when faced with an undecidable problem? CS150 Spring 6002: Lecture 25: Undecidable Problems (^3)
Problem Classes if P! NP:
Simulating Universe: O ( n^3 ) Smileys Find Best: NP-Complete^ "( n ) P "( n ) 3SAT Decidable Undecidable find proof halts? NP CS150 Spring 6002: Lecture 25: Undecidable Problems (^4)
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) … ) CS150 Spring 6002: Lecture 25: Undecidable Problems (^5)
Informal Proof
(define (boned x) (if (halts? boned null) (loop-forever) #t)) If halts? says that boned halts, it doesn’t halt! If halts? says that boned doesn’t halt, it halts! CS150 Spring 6002: Lecture 25: Undecidable Problems (^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 = boned A = a Scheme interpreter that follows the evaluation rules B = halts?
CS150 Spring 6002: Lecture 25: Undecidable Problems (^7)
“Evaluates to 23” Problem
Input: A procedure P and input I
Output: true if evaluating (P I )
would result in 23; false otherwise.
Is “Evaluates to 23” decidable? CS150 Spring 6002: Lecture 25: Undecidable Problems (^8)
Undecidability Proof
Suppose we could define evaluates-to-23? that decides it. Then we could define halts?:
(define (halts? P I)
(if (evaluates-to-23?
‘(begin (P I) 23))
#t
#f))
Since it evaluates to 23, we know (P I) must halt. The only way it could not evaluate to 23 is if (P I) doesn’t halt. (Note: assumes (P I) cannot produce an error.) CS150 Spring 6002: Lecture 25: Undecidable Problems (^9)
Hello-World? Problem
Input: A procedure P and input I
Output: true if evaluating (P I )
would print out “Hello World!”;
false otherwise.
Is Hello-World? decidable?
CS150 Spring 6002: Lecture 25: Undecidable Problems (^10)
Undecidability Proof
Suppose we could define hello-world? that decides it. Then we could define halts?:
(define (halts? P I)
(if (hello-world?
‘(begin (P I)
(print “Hello World!”))
#t
#f))
Hmm -- does this work? CS150 Spring 6002: Lecture 25: Undecidable Problems
Be careful...
11
(define (whoopsie)
(begin
(print “hello, world”)
(loop-forever)))
> (halts? whoopsie null)
#t
CS150 Spring 6002: Lecture 25: Undecidable Problems (^12)
Easy Fix
(define (halts? P I)
(if (hello-world?
‘(begin ((remove-prints P) I)
(print “Hello World!”))
#t
#f))
CS150 Spring 6002: Lecture 25: Undecidable Problems (^19)
“Solving” Undecidable Problems
- No perfect solution exists:
- Undecidable means there is no procedure that:
- Always gives the correct answer
- Always terminates
- Must give up one of these to “solve” undecidable problems
- Giving up #2 is not acceptable in most cases
- Must give up # CS150 Spring 6002: Lecture 25: Undecidable Problems (^20)
Actual is-virus? Programs
- Give the wrong answer sometimes
- “False positive”: say P is a virus when it isn’t
- “False negative”: say P is safe when it is
- Database of known viruses: if P matches one of these, it is a virus
- Clever virus authors can make viruses that change each time they propagate - A/V software ~ finite-proof-finding - Emulate program for a limited number of steps; if it doesn’t do anything bad, assume it is safe CS150 Spring 6002: Lecture 25: Undecidable Problems (^21)
Proof Recap
- 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 CS150 Spring 6002: Lecture 25: Undecidable Problems (^22)
How convincing is our
Halting Problem proof?
(define (boned x) (if (halts? boned null) (loop-forever) #t)) This “proof” assumes Scheme exists and is consistent! If halts? says that boned halts, it doesn’t halt! If halts? says that boned doesn’t halt, it halts! CS150 Spring 6002: Lecture 25: Undecidable Problems (^23)
Charge
- Scheme is very complicated (requires more than 1 page to define): - Unlikely we could prove it is consistent
- To have a convincing proof, we need a simpler programming model in which we can write boned - Next week: Turing’s model