The Halting Problem and its Contradiction, Study notes of Computer Science

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

Pre 2010

Uploaded on 11/08/2009

koofers-user-37b
koofers-user-37b 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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)
oQuestion – does P halt when given X?
oP 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
T
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)
pf2

Partial preview of the text

Download The Halting Problem and its Contradiction and more Study notes Computer Science in PDF only on Docsity!

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

T

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

P P

HAL

T

if P doesn’t halt on P then (no op) If P halts on P then while 9 < 10 do End (loops)

P