Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Halting Problem.

Similar presentations


Presentation on theme: "The Halting Problem."— Presentation transcript:

1 The Halting Problem

2 Acceptance Problem The Problem: Given a DFA M and an input string x does M accept on input x? We can express this problem with the predicate

3 The Acceptance Problem is decidable
In order to show that this problem is decidable we have to create a TM capable of simulating the running of a DFA with input x. This task is seemingly hard but we can instruct a Turing Machine to perform it. The TM should accept if the DFA on input x accepts, else it should reject.

4 Simulating the running of a DFA
The TM will have three tapes: one for the input, one for the states and one for the transitions. The start state will be denoted by a special symbol, (say being bold). The final states should also be denoted with special symbols (say underlined). The TM will also have unique accept and reject states (denoting whether the DFA accepts or rejects respectively).

5 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

6 Simulating the running of a DFA
Find the Bold symbol (the start state) in the States tape and place the cursor there. Search in the Transitions tape for the pair state-input symbols currently shown in the corresponding tapes. When a match is found, the next box is going to give the next current state. Search in the states tape for that symbol. Also move input cursor to the right and start over. If the input tape reads a blank symbol (the whole input is consumed), check whether the current symbol in the states tape is underlined (if it is an accept state). If yes accept, else reject.

7 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

8 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

9 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

10 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

11 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

12 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

13 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

14 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

15 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

16 Simulating the running of a DFA
States Transitions 1 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

17 Simulating the running of a DFA
States Transitions 1 Accept! 1 | 1 1 | 1 | 1 1 1 Input 0, 1 1 1 0, 1

18 Halting Problem The Problem: Given a Turing Machine M and an input string x does M halt on input x? Importance: If a machine doesn’t stop then we don’t know for sure if it is going to accept on the given input or not (we can’t distinguish between the case where it loops for ever and where it just takes a long time to run).

19 The predicate Halt The predicate for the halting problem is:
We again need to define a Turing Machine that simulates the running of M on input x.

20 Universal Turing Machine
We can create a Turing machine U that takes a pair of numbers (<M>, x) as input and then simulates M running on input x: If M accepts on x then U accepts on (<M>, x) If M rejects on x then U rejects on (<M>, x) If M loops on x then U loops on (<M>, x) This machine is called a Universal Turing Machine. It works in a similar way as the TM which simulates a DFA running on input x.

21 The predicate Halt is not computable
Using the Turing Machine U (as we did for the DFA) to decide Halt is impossible: observe that U can loop for some input! It turns out that the Halting Problem is not computable: there is no Turing Machine that takes as input the pair (<M>, x) and decides if M is going to accept on input x.

22 Predicate Halt is not computable
We will prove that the predicate is not computable.

23 Predicate H is not computable
Suppose that there is a TM HTM that decides H: HTM(<M>) accepts if H(<M>) = 1, HTM(<M>) rejects if H(<M>) = 0

24 Predicate H is not computable
Take the machine H’TM which does the following: halts on input M if HTM(<M>) rejects loops on input M if HTM(<M>) accepts (change HTM so that it loops in the accept state under any tape symbol). H’TM on input M: halts if M(<M>) loops loops if M(<M>) halts.

25 Predicate H is not computable
Run H’TM on input the machine H’TM itself. H’TM (<H’TM>) is going to halt if H’TM (<H’TM >) loops. H’TM (<H’TM>) is going to loop if H’TM (<H’TM >) halts. Contradiction! Reminder: H’TM (<M>) halts if M(<M>) loops loops if M(<M>) halts

26 Self Reference Run H’TM on input the machine H’TM itself.
This method is called “self-reference”. Occurs when something refers to itself. It may lead to a paradox. Example: The barber’s paradox In a village, the inhabitants who do not shave themselves are shaved by the barber. Question: Who shaves the barber?

27 Important Facts Church-Turing Thesis implies that any other machine or program can do exactly whatever a Turing Machine can do. There is no machine or program that can decide whether or not a machine or program is going to halt. Computers CANNOT decide the halting problem.

28 Halting problem for C++ programs
Suppose that there is a C++ program Halt that takes as input another C++ program p and decides whether this program is going to halt or not (outputs true if p halts, else false). Create a new C++ program Halt’ by adding the following code to Halt: while ( Halt(p) == true) a=1; This makes Halt’(p) to run forever if p halts and vice versa.

29 Halting problem for C++ programs
Since Halt’ is a proper C++ program ,we can give it as input to Halt’ (self-reference): If Halt’(Halt’) halts then Halt(Halt’) = false so Halt’(Halt’) is going to run forever. If Halt’(Halt’) runs forever then Halt(Halt’) = true so Halt’(Halt’) is going to halt. Contradiction!!!

30 Other Undecidable Problems
The halting problem is one out of a long list of undecidable problems which includes: TOTAL(<M>): does M halt on any input? EQ(<M1>,<M2>): Are M1 and M2 equivalent? EMPTY(<M>): Is L(M) empty? WRITE(<M>, x, b): Does M while running on input x ever write a ‘b’ on its tape? etc...

31 Undecidability The general way to prove that a problem P is undecidable is by contradiction: Suppose that P was decidable. Then, there is a Turing Machine M that decides P. Create a new Turing Machine M’ that decides Halt using M as a black box . But Halt is undecidable, thus M shouldn’t exist and P shouldn’t be decidable.

32 Reducibility The middle step is called reducibility.
Turing Machine for Halt Problem Tranformation Turing Machine for P Accept Input for P in correct format <M>, x Reject

33 WRITE(<M>, x, b) is undecidable.
WRITE(<M>, x, b): Does M on input x ever write b on its tape? Halt(<M>,x): Does M halt on input x? Problem transformation: Choose a symbol that doesn’t belong in the tape alphabet of M, say the symbol $. Now create a new TM M’ from M adding a new accept state and transitions from M’s old halt (accept and reject) states that write a $ on the tape.

34 WRITE(<M>, x, b) is undecidable.
WRITE(<M>, x, b): Does M on input x ever write b on its tape? Halt(<M>,x): Does M halt on input x? Problem transformation: M’ M A a→$,L A R a→$,L

35 WRITE(<M>, x, b) is undecidable.
WRITE(<M>, x, b): Does M on input x ever write b on its tape? Halt(<M>,x): Does M halt on input x? Run the Turing Machine for WRITE with input <M’>, x, $: If it accepts then a $ was written on the tape. But this is only possible if M on input x halts. If it doesn’t then no $ was written on the tape. But that means that M on input x didn’t halt.


Download ppt "The Halting Problem."

Similar presentations


Ads by Google