26

It's fairly simple to understand why the halting problem is undecidable for impure programs (i.e., ones that have I/O and/or states dependent on the machine-global state); but intuitively, it seems that a pure program's halting on an ideal computer would be decidable through e.g. static analysis.

Is this in fact the case? If not, what are some counterexamples or papers disproving this claim?

Jules
  • 632
  • 6
  • 19

4 Answers4

38

Here is a proof of undecidability by reduction from the Halting problem.

Reduction: Given a machine $M$ and an input $x$, build a new Turing Machine $H$ which does not read any input, but writes $M$ and $x$ on the tape and simulates $M$ on $x$ until $M$ halts.

The behaviour of this new machine $H$ is independent of the input tape, so it is a pure Turing Machine on which only static analysis is applicable. If static analysis were sufficient, then it could show whether $H$ halts, which would show whether $M$ halts on $x$, which would solve the halting problem for impure machines, which we know is undecidable, and therefore your problem is undecidable too.

8bittree
  • 103
  • 3
Lieuwe Vinkhuijzen
  • 4,457
  • 18
  • 28
16

No it is not, and moreover it does not depend on I/O.

Simple counterexample: write a program to find a perfect odd number (this is an open problem: we do not know yet whether one exists) - it does not take any input and does not perform any impure tasks; it may halt when it finds one, or may work infinitely (in the case such a number does not exist). Now if static analysis was powerful enough to determine the halting case it would be used to answer this (and many more questions) where halting would mean positive existence of such a number and not halting would mean there is no such number, but unfortunately static analysis is not that powerful.

psmears
  • 481
  • 3
  • 8
Evil
  • 9,525
  • 11
  • 32
  • 53
2

The classical proof by diagonalization is a pure machine, not only it is a pure Turing Machine, but it does not rely on "Open Problems".

In example, a Turing machine that executes the Collatz Conjecture has unkown halting status, but that relies on our ignorance about the Collatz Conjecture, one day we might proove that Collatz was right and then we would became able to decide the Halting status of the conjecture (Either for some inputs does not halt, or Always halts).

So the Collatz Conjecture could already answer your question (Temporarily at least), but it relies on something we don't know. Instead the classical proof is a solved problem: we already know that's undecideable.

CoffeDeveloper
  • 314
  • 1
  • 9
0

Just for the record, the standard proof of the undecideability of the halting problem relies on the same idea as quines: that it's possible to write a program some sub-term of which evaluates to the source code for the whole program. Then, if there was a function halts that, given source code for a program, returned True if that program halted on all input and False otherwise, this would be a legal program:

prog() = if halts "prog" then prog() else ()

where "prog" would be some expression that evaluated to the source code for prog; however, you can quickly see that prog halts (for all inputs) iff it doesn't halt, which is a contradiction. Nothing in this proof relies on I/O in any way (do you need I/O to write a quine?).

By the way, you might want to look in to "dialog-based I/O" for further evidence that I/O is entirely irrelevant to your problem (basically, programs that do I/O can be reduced to programs that take input as (explicit) functional arguments and return output as (explicit) additional results in a lazy language). Unfortunately, I can't find a reasonable, un-biased (or pro-dialog) page on the web right now.