# Halting - X then while 9< 10 do End(loops • Build one...

This preview shows pages 1–2. Sign up to view the full content.

HALTING PROBLEM – given a syntactically correct program P and an input string of characters X. (X may or may not be a valid input for P – it doesn't matter) o Question – does P halt when given X? o P may loop forever or halt So, is there an algorithm for the Halting Problem? By way of contradiction, we assume that there exists an algorithm, here called Q, which examines (P, X) to report if P halts or does not halt on input X: input: string X and program P (Note: P is just another string of characters to Q.) Q: P halts when given X …Now, build another program, Q', by changing 2 statements of Q: Lemma 1. If Q exists, then Q' exists P halts on X if and only if Q prints "P halts on X"; P halts on X if and only if Q' loops forever; P does not halt on X if and only if Q' halts on (P, X) 1 P X HAL P doesn’t halt when given X P X HAL If P doesn’t halt on X then (no op) If P halts on

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: X then while 9 < 10 do End (loops) • Build one more program, S: o S reads a program P and duplicates P o Then, S calls Q' with (P, P) as input o P cannot accept itself as input if and only if S halts o That is, P accepts itself as input if and only if S loops forever S: Q': • Lemma 2 : If Q' exists, then S exists • • Theorem 3 : If Q exists, then S halts on input P o iff Q' halts on (P,P) o iff Q' writes out "P does not halt on P" o iff P does not halt on P • • Since S is a syntactically correct program, we can replace P with S in Theorem 3. • Theorem 3' : If Q exists, then S halts on input S o iff Q' halts on (S, S) o iff Q' writes out "S does not halt on S" o iff S does not halt on S A contradiction: Thus, Q can not exist. 2 P P HAL if P doesn’t halt on P then (no op) If P halts on P then while 9 < 10 do End (loops) P...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Halting - X then while 9< 10 do End(loops • Build one...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online