

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The halting problem, a classic problem in computer science that asks whether there exists an algorithm to determine if a given program will halt when given a specific input. A proof by contradiction that such an algorithm does not exist.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


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 doesn’t halt when given X P X HAL T If P doesn’t halt on X then (no op) If P halts on 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
if P doesn’t halt on P then (no op) If P halts on P then while 9 < 10 do End (loops)