-3

I am trying to understand why is it impossible to write a program H that can check whether another program P on a specific input I will halt or not (Halting problem), but i am unable to get a clear idea of it.

Though intuition says that if this program H tries to run a program P which is not going to halt, then H itself will go into a loop. But i dont think this is the idea behind the proof.

Can anybody explain the proof in simple layman terms?

ArnonZ
  • 3,822
  • 4
  • 32
  • 42
  • 3
    Have you read any of the numerous existing expositions on the topic? If so, which, and what was unclear about it to you? –  Apr 19 '15 at 09:19

2 Answers2

4

The idea behind the proof is by contradiction.

Assume there is a Halting Problem Machine M that solves the Halting problem, and yields 0 if some input program won't finish, and 1 if it will. M is guaranteed to finish.

Create a new machine H.
H runs M with the input of H (itself), and if M answers 1 - get into endless loop, otherwise - stop.

Now, what will happen if you run M on input H?
If the answer is 1 - than it is wrong, since H runs M, and will get to infinite loop.
If the answer is 0 - it is also wrong, since H will stop.

So, it is contradicting the assumption that M is correct - and thus there is no such M.


Intuitively - it is like saying there is no such thing as an oracle, because if "you" tell me you're an oracle, I ask you - which arm am I going to raise?
Then, I will wait for your answer - and do the opposite - which contradicts the claim that the oracle is indeed an oracle.

amit
  • 175,853
  • 27
  • 231
  • 333
  • [Pet peeve](http://math.stackexchange.com/a/319926) of mine: This is not really a proof by contradiction (though almost always presented as one). Like other diagonal arguments, it *directly and constructively*, for any total TM, creates a program such that the total TM accepts said program iff the program diverges. The assumption that this total TM decides the halting problem is only used *after* this construction to conclude "no TM decides HP", but that can also be derived from "for all TMs, there is a program in HP rejected by the TM or vice versa". –  Apr 19 '15 at 10:27
  • Or you will raise the *predicted* arm and become psychedelically trapped in endless loop of *no free will*. – artur grzesiak Apr 20 '15 at 06:17
3

Turing used proof by contradiction for this (aka reduction to absurdity):

The idea is to assume there is actually such a machine H that given any program p and an input i will tell us weather p stops.

Given such H, we can modify it and create a new machine.
We'll add another part after H's output such that if H outputs yes, our machine will loop infinitely,
and if H outputs no, our new machine will halt.
We'll call our new machine H+.

Now, the paradox occurs when we feed H+ to itself (as both program p and input i).

That's because if H+ does halt, we get a yes answer (from the H part), but then it loops forever.
However, if H+ doesn't halt, we get a no answer (from the H part), but then it halts.


This is explained very nicely in this computerphile episode.

ArnonZ
  • 3,822
  • 4
  • 32
  • 42