Halting Problem - Computing Science

Download Report

Transcript Halting Problem - Computing Science

Halting Problem
Introduction to Computing
Science and Programming I
Alan Turing

Alan Turing 1912-1954


“Father” of modern computing science
1936
Turing Machine
 Church-Turing thesis
 Halting Problem


1950: Turing Test
Turing Machine

A Turing machine is a very simple
theoretical “computer” with a couple basic
elements.



An infinitely long tape broken up into cells
that can each store a single symbol from a
finite set of symbols
A head that can read or write one symbol at a
time from the tape
A state diagram that tells the head what to
do, move left/right, print a symbol
Church-Turing Thesis


This thesis proves has to do with
comparing what problems can be solved
by different types of computer.
It proves that a Turing Machine could
theoretically be created that can do
anything any digital computer can do.
Halting Problem



An important question of computing
science is “Are there problems that cannot
be solved?”
There are, and probably the most famous
of these is the halting problem described
by Turing.
He was thinking in terms of Turing
machines (there were no computers), but
it is easy to extend the idea.
Halting Problem

Halting problem


Can we write a program that will look at any
computer program and its input and decide if the
program will halt (not run infinitely)?
A practical solution might be to run the program and
if it halts you have your answer. If after a given
amount of time it doesn’t halt, guess that it won’t
halt. However, you wouldn’t know if the program
would eventually halt.
Halting Problem



As it turns out the problem is undecidable.
For a problem to be undecidable you just
have to prove that there is one case it
can’t produce an answer for.
The case that Turing came up with that
can never be solved involves giving a
program itself as input.
Halting Problem

Let’s assume we’re given a function
halts(prog,input) that is supposed to tell
us if the program prog will halt if given the
input. The function will return True if it
halts, False otherwise.
Halting Problem

Using the halts function the following program can be written that
reads in a program, given as a filename) from the user. It then calls
the halts function to decide if the program will halt given itself as
input.
prog = raw_input("Program file name: ")
if halts(prog, prog):
while True:
print "looping“
else:
print "done"
Halting Problem


It may not make sense to give a program itself
as input, but that isn’t important here.
What could happen?



If halts(prog,prog) returns True, that means the
program will halt when given itself as input.
However, in this case the program would go into an
infinite loop. Therefore the program doesn’t halt.
If halts(prog,prog) returns False, that means that it
wouldn’t halt, but in that case the program does halt.
This contradiction is unavoidable thus proving that
the halting problem is undecidable. No function can
always correctly decide if a program will halt.
Turing Test


The Turing test was formulated as a way to answer the
question, “Can machines think?”
The basic idea is that there is a sort of judge who
converses with a computer and a person. However, this
is indirect. The judge writes down questions and the
computer and the person, who are hidden from the
judge, return typewritten answers. If the judge couldn’t
consistently identify which set of answers were from the
person, than the computer could “think”.

Turing predicted that computers could pass this test with 30% of
humans as the judge by the year 2000.