3

I'm taking a theoretical CS class and we just discussed the halting problem. In my understanding, the reason that the problem cannot be solved is that if there is a program Halt that tells us whether a not a program halts, and you write another program Proof such that

function Proof (program, input) 

if (Halt(program, input)) loop infinitely; 
else return 1

To me, the crux of the problem is that the if condition is for the program to loop infinitely, which is the fail condition for Halt.

This is the part I am not sure about:

Say you had a program to check if another program returns the number 4 on a certain input. Let's call this program FourCheck. Then, we could write another program ProofFour such that

ProofFour(program, input) 

if(FourCheck(program, input) return 5; 
else return 4; 

In this case, we could call ProofFour(ProofFour,input). If FourCheck() returns true, then ProofFour returns 5, making FourCheck()'s output incorrect. If FourCheck returns false, then ProofFour returns 4, again making FourCheck()'s output incorrect.

Hence, would it be correct to assume that you could essentially have no program to check other programs, because you could always construct a program similar to Proof() and ProofFour() that essentially inverts the output of your checker program.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Darvish Kamalia
  • 817
  • 1
  • 7
  • 19
  • 1
    I think you answered your own question. – ThomasMcLeod Oct 29 '14 at 01:44
  • Is it always possible to "invert" the output of a program? – Scott Hunter Oct 29 '14 at 01:49
  • 5
    This question appears to be off-topic because it should be asked on http://cstheory.stackexchange.com/ – Kijewski Oct 29 '14 at 01:56
  • 6
    You cannot write a program that decides `Halt or not Halt` for all programs, which is what the counter example demonstrates. It doesn't mean you cannot write a program that decides `Halt or not Halt` for a ***certain*** program. – jxh Oct 29 '14 at 02:17
  • For any program, you can always 'check it' just by running the program and seeing what it returns -- with the caveat that some programs might never return at all, of course. – Jeremy Friesner Mar 08 '18 at 15:06
  • In some cases, it is possible to prove that a program will halt using [termination analysis](https://en.wikipedia.org/wiki/Termination_analysis). – Anderson Green Jun 16 '19 at 15:32

1 Answers1

-1
ProofFour(program, input) 

if(FourCheck(program, input)) return 5; 
else return 4; 

With the above quoted program, your call to ProofFour(ProofFour,input) is ill-formed: The first Prooffour is OK, since it takes a program and an input as its input, but the second Prooffour should have two arguments. This means you need to supply a pair input for the second Prooffour, as this: ProofFour(ProofFour,(someprog, input)) When you use this well-defined form, it's hard (if not impossible) to explain why it's impossible to create a FourCheck().

Now I change it a little bit:

ProofFour(input)

if(FourCheck(ProofFour, input)) return 5; 
else return 4;

This is well-defined form. The ProofFour in the program is just a pointer to the program text. Now it is clear that Fourcheck can not check the program ProofFour.

Robin Hsu
  • 4,164
  • 3
  • 20
  • 37