1

Is this illustration of the haling problem correct?

function halts(func) {
  // Insert code here that returns "true" if "func" halts and "false" otherwise.
}

function deceiver() {
  if(halts(deceiver))
    while(true) { }
}

If so, why do so many descriptions involve a function which takes two arguments, where one is the program and the other is the same program as program input?

E.g.:

Assume we have a function Halts(P, W) that halts if program P halts on input W. Then we write this perfectly-valid Python function:

    def K(P):
        if (Halts(P, P)):
            while True: pass # run forever
        else:
            return 42 # halt!

Now, what happens when we call K(K)? If Halts(K,K) is True, then K(K) hangs (runs forever) If Halts(K,K) is False, then K(K) halts So either way, Halts(K,K) is wrong. Thus, the Halts function cannot exist!

Robin Andrews
  • 3,514
  • 11
  • 43
  • 111
  • Please check the [help/on-topic] to see what questions you can ask. You might want to delete this question and ask it on https://cs.stackexchange.com/ instead, but check the help pages there first. – Progman Aug 29 '21 at 16:39

1 Answers1

0

The two input parameters are just a trick for the construction of the proof by contradiction, showing the non-existence of an algorithm for the halting problem.

There are a lot of sketches for the proof online, e.g. https://www.youtube.com/watch?v=macM_MtS_w4

andi-ko
  • 11
  • 1