Algorithms CSCI 235, Spring 2019 Lecture 37 The Halting Problem
Existence of Noncomputable Functions Noncomputable functions cannot be solved by any computer program. The set of all possible programs is countable. The set of all possible functions is uncountable. Therefore, if we try to match up each function with a program that computes it, we will always leave some functions out. These left-over functions are noncomputable.
Automatic Program Testing Every program must be extensively tested to make sure that it runs properly under a variety of conditions. Testing can be very time consuming. It would be nice if we could automate the testing. To automate testing, we could write a program that reads in other programs and reports back some information about that program.
Checking for Infinite Loops It would be very useful to write a program to report whether or not a piece of code contains an infinite loop. Examples of infinite loops:
The Halting Problem We would like to write a program that reads in other programs. If the input program halts on all inputs (e.g. it has no infinite loops) our program should output: "Halts on all inputs." Otherwise, our program should output: "Does not halt on all inputs." The problem of writing such a program is called: Turing's Halting Problem
Testing for loops To write our program, we could list known cases of infinite loops and check for them: Case 1: Our language has only while loops and recursion is not allowed. Other cases:
Does it always halt? Testing all possible examples would be difficult. Input(x) while x > 1 do if (x div 2) * 2 = x {e.g. x is even} x <- x div 2 else x <- 3* x + 1 write(x) What happens when x starts as 17? Does this always halt?
Its harder than it sounds Theorem: No finite program can be written that will check other programs and halt in a finite time giving a solution to Turing's halting problem. Proof (by contradiction): Assume that such a program exists Show that this assumption leads to impossible consequences. Therefore the program cannot exist.
Assume halt( ) program exists Assume there exists a program, halt( ), that takes 2 inputs, a program and an input to that program and tests to see whether the the program halts for that input. halt(p, x) ... {Code to compute whether p halts} if ... then return "Halts" else return "Does not halt"
Showing that halt( ) cannot exist In class we will show that the existence of halt( ) leads to a logical contradiction, and therefore it cannot exist. If we can show that halt( ) cannot exist, then the more general "halts on all inputs" cannot exist (because we could construct halt( ) from it).
Other non-computable functions Other non-computable problems: Showing that 2 programs are equivalent (for each input they give the same output Determining whether a given output will occur for some input. Determining the correctness of a program Almost every problem related the the behavior of a program.
The Turing Test In 1950, Alan Turing proposed the following test for determining whether a machine can demonstrate intelligence: A human judge engages in a natural language conversation with one human and one machine, each of which try to appear human. The conversation occurs via text messaging, so the judge cannot see the person/machine with which he is conversing. If the judge cannot reliably tell which is which, then the machine is said to pass the test.