5

Is partial correctness decidable? i.e., is there a general algorithm that for any pair of formal specification and encoded TM, returns true if and only if, when the TM halts, it meets the specification?

I feel that the answer is likely no because of how complex the problem sounds. If the answer is no, please provide a proof or proof sketch.

3 Answers3

21

No, it is not decidable. Suppose the formal spec is "if the program halts, it must output 42". (This is a partial correctness requirement.) Suppose f() is any function that constitutes pure computation (it never outputs anything), and consider the following code:

y = f()
output 17

If f() halts, then this code violates the spec, otherwise this code obeys the spec. So determining whether this code satisfies partial correctness is as hard as determining whether f() halts. This is exactly the halting problem. Therefore, partial correctness is undecidable.

I've phrased this in terms of code, for ease of understanding, but you can convert this to an argument in terms of Turing machines if you prefer. The resulting argument can be made fully rigorous and formal.

D.W.
  • 167,959
  • 22
  • 232
  • 500
14

A well-known generalization of the undecidability of the Halting Problem is Rice's theorem, which says that "all non-trivial semantic properties of programs are undecidable".

Li-yao Xia
  • 1,128
  • 5
  • 6
2

Let $M$ be any TM.

Define $N$ as the TM that, on input $n\in\mathbb N$, runs $M$ for $n$ steps on empty input. We make $N$ accept if $M$ halts within those steps, and reject otherwise.

Note that $N$ always halts, no matter what are $M$ and $n$, since it only simulates a finite number of steps.

Consider the spec "$N$ rejects all $n$".

The partial correctness of $N$ w.r.t. the spec states that whenever $N$ halts, it rejects. But $N$ always halts, so partial correctness is equivalent to $N$ always rejecting. That, in turn, is equivalent to $M$ diverging on the empty input.

Therefore, if we could decide partial correctness (on $N$), we could decide the diverging problem (on $M$), hence the halting problem as well. But we know that is not possible, so partial correctness is also undecidable.

chi
  • 14,704
  • 1
  • 31
  • 40