Semidecidability

“Better to keep your mouth shut and be thought a fool
than to open it and remove all doubt.”
—The semidecider motto (and counterproductive for students in a class!)

For some formal language, it can be easier to show a string is a member of the language than to show it is not. This leads to the definition of semidecidable languages, which includes all decidable languages and more:

Language classes

Semidecidability

Definition

A language is semidecidable if it is the language of some TM.

(That is, if it is the set of strings accepted by some Turing Machine.)

The following are all equivalent ways of saying that a language LL is semidecidable:

  • LL is the language of some TM MM.
  • There exists a TM MM such that MM accepts ww iff wLw\in L
  • There exists a TM MM such that MM accepts every string in LL, and does not accept (rejects or runs forever) any string not in LL.
  • There exists a TM MM that never lies about whether its input is in LL, and if the input is in the language then MM can (eventually) figure this out.

Given a formal language LL, we can ask whether LL is decidable or not. We can also ask whether LL is semidecidable or not. Since all decidable languages are semidecidable, there are three possible outcomes:

  1. LL is decidable.
  2. LL is undecidable but semidecidable.
  3. LL is undecidable and not semidecidable.

Language classes

Examples

Example

We previously showed that

ATM={ M,w  M a TM, wL(M) }A_\mathrm{TM} = \{\ \langle M, w\rangle\ |\ M \mathrm{~a~TM},\ w\in L(M)\ \}

is not decidable, but it is semidecidable.

Proof: We can semidecide the language using a TM that implements the following algorithm:

def semidecide_Atm(M, w):
       return simulate(M, w)

That is, there is a machine (the semidecider) that takes as input the code for a Turing Machine MM and a string ww, simulates running MM on input ww (using the techniques of a Universal Turing Machine), and reports the result.

If M,wATM\langle M,w\rangle \in A_\mathrm{TM} then running MM on input ww will eventually halt and accept, and so the semidecider will report that.

If M,w∉ATM\langle M,w\rangle \not\in A_\mathrm{TM} then running MM on input ww will eventually halt and reject (and the semidecider will report that) or it will run forever (and the semidecider will run forever). In either case, the semidecider will not accept.

semidecide_Atm is not a decider (because it isn’t guaranteed to always return an answer), but it is a valid semidecider because it accepts all and only elements of ATMA_\mathrm{TM}.

Example

The set

Acceptsϵ={ M,w  ϵL(M) }\mathit{Accepts}{-}\epsilon = \{\ \langle M, w\rangle\ |\ \epsilon\in L(M)\ \}

of Turing Machines (programs) that halt and except when given an empty string as input (an initially blank tape) is semidecidable. (It’s not decidable, but we won’t prove that until later.)

Proof: We can semidecide the language using a TM that implements the following algorithm:

def semidecide_Accepts_eps(M):
      return simulate(M, "")

That is, there is a machine (the semidecider) that takes as input the code for a Turing Machine MM, simulates running MM on an empty string, and reports the result.

If MAcceptsϵ\langle M\rangle \in \mathit{Accepts}{-}\epsilon then running MM on ϵ\epsilon will eventually halt and accept, and so the semidecider will report that.

If M∉Acceptsϵ\langle M\rangle \not\in \mathit{Accepts}{-}\epsilon then running MM on ϵ\epsilon will eventually halt and reject (and the semidecider will report that) or it will run forever (and the semidecider will run forever). In either case, the semidecider will not accept.

Thus semidecide_Atm accepts all and only elements of Acceptsϵ\mathit{Accepts}{-}\epsilon.

Example

The set of Turing Machines

NETM={ M,w  ϵL(M) }\mathit{NE}_\mathrm{TM} = \{\ \langle M, w\rangle\ |\ \epsilon\in L(M)\ \}

is semidecidable. (It’s not decidable, but we won’t prove that until later.)

Proof: It’s a little less obvious how to figure whether a given TM accepts some string without knowing the string in advance. The problem is that if we simulate the TM on any specific string (e.g., the empty string), the TM might run forever, but had we tried a different string the TM could have halted and accepted immediately.

The trick is to check a string for only a few steps, and then try something else. More specifically, we can enumerate all possible input strings (since they’re countable), and write code that tries a few strings for a few steps each, and then a larger set of strings for a larger number of steps each, and so on. If there is any specific string that can be accepted in any finite number of steps, this strategy will eventually try it for enough steps, see the TM accept, and report the machine as having a nonempty language.

That is, we can semidecide the language using a TM that implements the following algorithm:

def semidecide_NEtm(M):
    n = 0
    while True:
        n += 1
        for w in first_n_strings(n):
            if simulate_n_steps(M, w, n):
              return True

Thus semidecide_NEtm accepts all and only elements of NETM\mathit{NE}_\mathrm{TM}.

Non-Semidecidable Languages

We can show a language is semidecidable by constructing a semidecider. But how can we prove a language is not semidecidable, i.e., that no such semidecider exists?

One way is to use a mapping reduction (as described later), but in some cases we can use the following shortcut:

Theorem

If LL is semidecidable and its complement LcL^c is semidecidable, then LL is decidable.

Proof:
Suppose LL and LcL^c are semidecidable.

Then there are Turing Machines M1M_1 and M2M_2 that semidecide LL and LcL^c respectively.

Given an input wΣw\in\Sigma^*, there is a TM that simulates running both M1M_1 and M2M_2 on ww in parallel. (It can simulate one step of M1M_1, then one step of M2M_2, then another step of M1M_1, then another step of M2M_2, and so on.)

Since M1M_1 and M2M_2 are semideciders, if wLw\in L then M1M_1 will eventually halt and accept ww, and if wLcw\in L^c then M2M_2 will eventually halt and accept ww.

So we just run the machines in parallel and wait for one to accept, which is guaranteed to happen in a finite amoutn of time. If M1M_1 accepts, then we know wLw\in L, and if M2M_2 accepts, then we know wLcw\in L^c so w∉Lw\not\in L.

Thus LL is decidable.

Corollary

If LL is semidecidable but not decidable, then LcL^c is not even semidecidable.

Proof: Suppose LL is semidecidable but not decidable.

If LcL^c were semidecidable, by the above theorem LL would be decidable, but it’s not.

So LcL^c can’t be semidecidable.

Example

Since we know that

ATM={ M,w  wL(M) }A_\mathrm{TM} = \{\ \langle M, w\rangle\ |\ w\in L(M)\ \}

is semidecidable but not decidable, its complement

¬ATM={ M,w  w∉L(M) }\lnot A_\mathrm{TM} = \{\ \langle M, w\rangle\ |\ w\not\in L(M)\ \}

is not even semidecidable.