Sub topic 16
GATE patterns: a checklist for decidability questions
This chapter assumes you know the definitions of recursive and recursively enumerable (RE) languages. It also assumes you know the closure properties, the undecidability of A_TM and the halting problem, many-one reductions, and Rice's theorem. Here you combine them into a fixed order of checks for the statement-style questions GATE asks. Work through the checks in order. Most questions are settled within the first two or three.
The checklist
- Identify the model and the question. Decide whether the input is a DFA, a CFG or PDA, a linear bounded automaton (LBA), or a Turing machine. Then decide what is asked: membership, emptiness, finiteness, universality, equivalence, or a property of the language.
- Look up the decidability table below. Finite-state and context-free inputs have fixed answers.
- If the input is a TM and the question is about its language, test Rice's theorem.
- If the question is about languages, apply closure properties and the rule "RE and co-RE means recursive".
- If the question is about a reduction
A ≤m B, check the direction before drawing any conclusion.
Step 2: the lookup table
D means decidable and U means undecidable. Each column describes the input as given to the algorithm.
| Problem | DFA / regular | CFG / PDA | TM |
|---|---|---|---|
| Is w in L? | D | D | U (A_TM) |
| Is L empty? | D | D | U (E_TM) |
| Is L finite? | D | D | U |
| Is L = Σ*? | D | U | U |
| Is L1 = L2? | D | U | U |
| Is L1 ⊆ L2? | D | U | U |
| Is L1 ∩ L2 empty? | D | U | U |
| Is L regular? | trivially yes | U | U |
| Is the CFG ambiguous? | not applicable | U | not applicable |
Some further facts help with the table:
- For CFGs, the question "is L(G) ∩ R empty?" is decidable when R is regular, because CFLs are closed under intersection with regular languages.
- For LBAs, membership is decidable because the configuration count is finite, but emptiness is undecidable.
- Context-sensitive languages are decidable, so every CSL is recursive.
- Every CFL is recursive, and every regular language is recursive.
The halting version of the same table looks like this:
- "Does M halt on w?" is undecidable.
- "Does M halt on w within k steps?" is decidable by simulating k steps.
- "Does M halt on every input?" is undecidable.
Step 3: Rice's theorem screen
Rice's theorem applies to sets of the form {⟨M⟩ : L(M) has property P}. The property must be non-trivial, meaning some TM languages have it and some do not. Run two tests.
- The property must be about L(M), not about M's code or its running behavior.
- It must be non-trivial.
| Statement about ⟨M⟩ | Rice applies? | Verdict |
|---|---|---|
| L(M) is empty | yes | undecidable |
| L(M) is finite | yes | undecidable |
| L(M) contains ε | yes | undecidable |
| L(M) is regular | yes | undecidable |
| L(M) is recursive | yes | undecidable |
| L(M) is recursively enumerable | trivial property | decidable (always yes) |
| M has at most 5 states | about M, not L(M) | decidable |
| M halts on w within 100 steps | about M's behavior | decidable |
| M ever writes a blank | about M's behavior | undecidable here, but needs a direct reduction |
The trap rows are the trivial one ("L(M) is RE") and the syntactic ones. A property can be non-trivial and still not fall under Rice if it concerns M and not L(M).
Rice's theorem only shows undecidability. It does not tell you whether the set is RE. For example, {⟨M⟩ : L(M) = ∅} is not RE, but its complement is RE. The set {⟨M⟩ : L(M) ≠ ∅} is RE because a machine can dovetail over all inputs and accept when any one is accepted.
Step 4: closure and the RE/co-RE rule
| Operation | Recursive | RE |
|---|---|---|
| Union, intersection | closed | closed |
| Concatenation, Kleene star, reversal | closed | closed |
| Complement | closed | not closed |
| Set difference | closed | not closed |
| Homomorphism | not closed | closed |
The central rule is that L is recursive exactly when both L and its complement are RE. Three consequences follow:
- If L is RE but not recursive, its complement is not RE. A_TM and the halting language are examples.
- If L is undecidable, at least one of L and its complement is not RE.
- A language can be undecidable and have an RE complement, which is the case for E_TM.
The rule is constructive. Given two semi-deciders, run them in lock-step. Exactly one of them must eventually accept, and that settles the answer.
from itertools import count
def decide(accepts_L, accepts_co_L, w):
"""accepts_*(w, steps) is True once that semi-decider
has accepted w within `steps` steps."""
for steps in count(1):
if accepts_L(w, steps):
return True
if accepts_co_L(w, steps):
return False
# Toy semi-deciders for L = strings of even length.
# Each "needs" len(w) + 1 steps before it can answer.
in_L = lambda w, s: len(w) % 2 == 0 and s >= len(w) + 1
in_co_L = lambda w, s: len(w) % 2 == 1 and s >= len(w) + 1
for w in ["", "ab", "abc", "abcd"]:
print(repr(w), decide(in_L, in_co_L, w))
# '' True, 'ab' True, 'abc' False, 'abcd' TrueRecursive languages are not closed under homomorphism because every RE language is a homomorphic image of some recursive language. This is a favorite option in "which is not closed" questions.
Step 5: reduction direction
Suppose A ≤m B, meaning a computable function maps instances of A to instances of B and preserves membership. The valid inferences are:
| Given | Conclusion |
|---|---|
| B decidable | A decidable |
| A undecidable | B undecidable |
| B RE | A RE |
| A not RE | B not RE |
The reverse readings are invalid. Knowing that A is decidable says nothing about B. Knowing that B is undecidable says nothing about A. To prove a new problem undecidable, reduce a known undecidable problem to it, never the other way round.
A related point concerns the Post Correspondence Problem (PCP). PCP is undecidable but RE: a search over index sequences finds a match if one exists. Its complement is not RE.
Common traps
- A subset of a decidable language need not be decidable. Σ* is decidable, and it contains undecidable subsets.
- A language being finite makes it regular and decidable. "Given a TM, is its language finite?" is a different statement and is undecidable.
- "L is undecidable" does not imply "L is not RE". Check which of L and its complement is RE.
- A nondeterministic TM accepts the same languages as a deterministic one, and so does a multi-tape TM. A decider on one model has an equivalent decider on the others.
- A TM that never halts on some inputs can still define a recursive language, because a different machine for the same language may always halt.
Exercise
Consider the sets S1 = {⟨M⟩ : L(M) is regular}, S2 = {⟨M⟩ : M has fewer than 10 states}, and S3 = {⟨M⟩ : L(M) is RE}. Which are decidable?
Show answer
S2 and S3. S1 is a non-trivial property of L(M), so Rice's theorem makes it undecidable. S2 is a syntactic property of M that can be checked by reading the encoding. S3 is a trivial property, since every TM language is RE, so the answer is always yes.
Exercise
L1 is recursive and L2 is RE but not recursive. For each of L1 ∩ L2, L1 ∪ L2 and the complement of L2, state the strongest claim you can make.
Show answer
L1 ∩ L2 and L1 ∪ L2 are both RE, since RE is closed under union and intersection. The complement of L2 is not RE: if it were, L2 would be both RE and co-RE, hence recursive, which contradicts the assumption.
Exercise
Given CFGs G1 and G2, is L(G1) ∩ L(G2) = ∅ decidable? What if G2 is replaced by a DFA?
Show answer
For two CFGs it is undecidable, because PCP reduces to it. With a DFA in place of G2 it is decidable: build the product of a PDA and the DFA, giving a CFL, then test that CFL for emptiness.
Exercise
A ≤m B and B is RE. B is also not recursive. What can you conclude about A?
Show answer
Only that A is RE. A could be recursive or not recursive, because a reduction to a hard problem puts no lower bound on the difficulty of A. Inferences only run from "B easy" to "A easy" or from "A hard" to "B hard".