Sub topic 5
Decidable versus Semi-Decidable Languages
This chapter assumes finite automata, context-free languages, Turing machines, basic set theory, and proof by contradiction.
A language is a set of strings over an alphabet. A Turing machine can process an input string in three relevant ways: accept it, reject it, or run forever.
Decidable languages
A language is decidable, or recursive, if some Turing machine always halts and gives the correct answer for every input.
The machine is called a decider. It accepts strings in the language and rejects strings outside it. Because it always halts, the answer is eventually known.
For example, the language
L = { a^(2n) : n ≥ 0 }
contains strings made only of a symbols whose length is even. A decider can scan the input, check every symbol, count the length, and then accept or reject.
Semi-decidable languages
A language is semi-decidable, or recursively enumerable (RE), if some Turing machine accepts every string in the language. For a string outside the language, the machine may reject or may run forever.
Such a machine is called a recognizer. Acceptance confirms membership, but failure to receive an answer does not confirm non-membership.
| Machine type | Input in the language | Input outside the language |
|---|---|---|
| Decider | Halts and accepts | Halts and rejects |
| Recognizer | Halts and accepts | Rejects or loops forever |
Every decidable language is semi-decidable. A decider is already a recognizer, because it accepts every member. The reverse is not always true.
def decider_a_even(word):
"""Decide whether word contains an even number of a symbols."""
return all(symbol == "a" for symbol in word) and len(word) % 2 == 0
def recognizer_a_even(word):
"""Recognize the same language, but loop on nonmembers."""
if decider_a_even(word):
return True
while True:
pass
print(decider_a_even("aaaa")) # True
print(decider_a_even("aaa")) # False
print(recognizer_a_even("aaaa")) # True
# Calling recognizer_a_even("aaa") never returns.The example uses a simple decidable language, so its recognizer can be written easily. More important examples include the acceptance problem
A_TM = { <M, w> : machine M accepts input w }.
A universal Turing machine can simulate M on w. If M accepts, the simulator accepts. If M rejects or loops, the simulator might never accept. Therefore, A_TM is semi-decidable but not decidable.
The complement test
The complement of a language L, written L̅, contains all strings not in L.
A key theorem is:
Lis decidable if and only if bothLandL̅are semi-decidable.- If both a language and its complement have recognizers, run the two recognizers in alternating steps. One must eventually accept.
- A semi-decidable language can have a complement that is not semi-decidable.
GATE decision pattern
For closure questions, remember that decidable languages are closed under union, intersection, complement, and difference. RE languages are closed under union and intersection, but not generally under complement or difference.
Exercise
If L and its complement are both semi-decidable, is L decidable?
Show answer
Yes. Run both recognizers by dovetailing their steps. One eventually accepts, so the combined machine always halts and decides L.