Skip to content

Decidability | Computer Science

flowchart TD
A[5_Decidability] --> B[Key Concepts]
A --> C[Core Principles]
A --> D[Practical Applications]
B --> E[Fundamental definitions]
C --> F[Design patterns]
D --> G[Real-world usage]

Decidability asks: can an algorithm give a definitive yes/no answer for every input? Some problems are fundamentally undecidable — no amount of cleverness or computing power can solve them for all cases. The halting problem is the canonical example: you cannot write a program that determines whether an arbitrary program will halt or loop forever.

Why the halting problem is undecidable: The proof is by diagonalisation — if such a program H existed, we could construct a program D that does the opposite of what H predicts, creating a paradox. This is similar to the liar’s paradox (“this statement is false”) but made rigorous through computation.

Reductions intuition: To prove a problem is undecidable, reduce a known undecidable problem to it. If A reduces to B and A is undecidable, then B is undecidable (because a decider for B would give a decider for A). This is the primary tool for proving undecidability results.

Theorem 5.1. The following languages are decidable:

  • A_{\mathrm{DFA} = \{\langle B, w \rangle : B \mathrm{ is a DFA that accepts w\}.
  • E_{\mathrm{DFA} = \{\langle B \rangle : B \mathrm{ is a DFA with L(B) = \emptyset\}.
  • \mathrm{EQ_{\mathrm{DFA} = \{\langle A, B \rangle : A, B \mathrm{ are DFAs with L(A) = L(B)\}.
  • A_{\mathrm{CFG} = \{\langle G, w \rangle : G \mathrm{ is a CFG that generates w\}.

Proof (for A_{\mathrm{DFA}). Simulate BB on input ww. This takes O(w)O(|w|) steps and always halts.

Proof (for E_{\mathrm{DFA}). Mark the start state. Repeatedly mark states reachable by Transitions from already-marked states. After no more states can be marked, check if any accept state Is marked. If not, L(B)=L(B) = \emptyset.

Proof (for \mathrm{EQ_{\mathrm{DFA}). Use the product construction to build a DFA for L(A)L(B)=(L(A)L(B))(L(A)L(B))L(A) \triangle L(B) = (L(A) \cap \overline{L(B)}) \cup (\overline{L(A)} \cap L(B)). Test if this DFA accepts any string (using the algorithm for E_{\mathrm{DFA}). \blacksquare

Additional decidable problems:

  • A_{\mathrm{REX} = \{\langle R, w \rangle : R \mathrm{ is a regex and w \in L(R)\} — convert RR to a DFA, then decide A_{\mathrm{DFA}.
  • E_{\mathrm{CFG} = \{\langle G \rangle : L(G) = \emptyset\} — test all derivations up to length 2V2^{|V|}.
  • \mathrm{INF_{\mathrm{CFL} = \{\langle G \rangle : L(G) \mathrm{ is infinite\} — check if any variable has a self-embedding derivation.

Theorem 5.2. A_{\mathrm{TM} = \{\langle M, w \rangle : M \mathrm{ is a TM and M \mathrm{ accepts w\} Is Turing-recognisable but undecidable.

Proof of recognisability. Simulate MM on ww. If MM accepts, accept. If MM rejects, reject. This recognises A_{\mathrm{TM}. \blacksquare

Proof of undecidability (by contradiction). Assume a decider HH for A_{\mathrm{TM} exists. Construct a TM DD that on input M\langle M \rangle:

  1. Run HH on M,M\langle M, \langle M \rangle \rangle.
  2. If HH accepts, reject.
  3. If HH rejects, accept.

Consider DD on input D\langle D \rangle:

  • If DD accepts D\langle D \rangle Then by construction DD rejects D\langle D \rangle. Contradiction.
  • If DD rejects D\langle D \rangle Then by construction DD accepts D\langle D \rangle. Contradiction.

Therefore HH cannot exist. \blacksquare

Theorem 5.2a. \overline{A_{\mathrm{TM}} is not Turing-recognisable.

Proof. If \overline{A_{\mathrm{TM}} were Turing-recognisable, then since A_{\mathrm{TM} is Also Turing-recognisable, A_{\mathrm{TM} would be decidable (run both recognisers in parallel; one Must accept). But A_{\mathrm{TM} is undecidable. Contradiction. \blacksquare

A reduction from language AA to language BB is a computable function ff that maps instances of AA to instances of BB such that wA    f(w)Bw \in A \iff f(w) \in B.

Theorem 5.3. If AmBA \leq_m B and BB is decidable, then AA is decidable.

Proof. To decide AA on input ww: compute f(w)f(w) Then decide BB on f(w)f(w). Since both steps are Computable, AA is decidable. \blacksquare

Corollary 5.4. If AmBA \leq_m B and AA is undecidable, then BB is undecidable.

Applications. Using reductions from A_{\mathrm{TM}We can prove many problems undecidable:

LanguageDescriptionReduction from
\mathrm{HALT_{\mathrm{TM}\{M, w : M \mathrm{ halts on w\}A_{\mathrm{TM}
E_{\mathrm{TM}{M:L(M)=}\{M : L(M) = \emptyset\}A_{\mathrm{TM}
\mathrm{REGULAR_{\mathrm{TM}\{M : L(M) \mathrm{ is regular\}A_{\mathrm{TM}
\mathrm{EQ_{\mathrm{TM}{M1,M2:L(M1)=L(M2)}\{M_1, M_2 : L(M_1) = L(M_2)\}E_{\mathrm{TM}

Example reduction. A_{\mathrm{TM} \leq_m \mathrm{HALT_{\mathrm{TM}.

Proof. Given M,w\langle M, w \rangleConstruct a TM M"M" that on input xx: simulates MM on ww. If MM accepts, accept. If MM rejects, loop. Then \langle M, w \rangle \in A_{\mathrm{TM} iff MM' halts on some input (any input), iff \langle M' \rangle \in \mathrm{HALT_{\mathrm{TM}. \blacksquare

Worked Example: $A_{\mathrm{TM} \leq_m E_{\mathrm{TM}$

Proof. Given M,w\langle M, w \rangleConstruct a TM MwM_w that on input xx:

  1. Simulate MM on ww.
  2. If MM accepts wwAccept xx.
  3. If MM rejects wwReject xx.

Then L(Mw)=ΣL(M_w) = \Sigma^* if MM accepts ww And L(Mw)=L(M_w) = \emptyset if MM does not accept ww.

Therefore: \langle M, w \rangle \in A_{\mathrm{TM} iff L(Mw)L(M_w) \neq \emptyset Iff \langle M_w \rangle \notin E_{\mathrm{TM}.

The reduction f(M,w)=Mwf(\langle M, w \rangle) = \langle M_w \rangle is computable. So if E_{\mathrm{TM} Were decidable, \overline{E_{\mathrm{TM}} would be decidable, and hence A_{\mathrm{TM} Would be decidable — contradiction. \blacksquare

Worked Example: $E_{\mathrm{TM} \leq_m \mathrm{EQ_{\mathrm{TM}$

Proof. Given M\langle M \rangleConstruct two TMs:

  • M1M_1: on any input, immediately rejects. So L(M1)=L(M_1) = \emptyset.
  • M2M_2: on any input, simulates MM and accepts iff MM accepts. So L(M2)=L(M)L(M_2) = L(M).

Then L(M)=L(M) = \emptyset iff L(M1)=L(M2)L(M_1) = L(M_2).

Therefore \langle M \rangle \in E_{\mathrm{TM} iff \langle M_1, M_2 \rangle \in \mathrm{EQ_{\mathrm{TM}. If \mathrm{EQ_{\mathrm{TM} were decidable, E_{\mathrm{TM} would be decidable — contradiction. \blacksquare

Theorem 5.5 (Rice’s Theorem). Every non-trivial property of the language recognised by a Turing Machine is undecidable.

A property PP is a set of Turing-recognisable languages. It is non-trivial if PP is neither Empty nor the set of all Turing-recognisable languages.

Proof (sketch). Let PP be a non-trivial property. Since PP is non-trivial, there exists a TM M0M_0 with L(M0)PL(M_0) \in P and a TM M1M_1 with L(M1)PL(M_1) \notin P. Given an arbitrary TM MM and input wwConstruct MwM_w that on input xx: first simulates MM on ww Then simulates M0M_0 on xx. If MM accepts ww Then L(Mw)=L(M0)PL(M_w) = L(M_0) \in P; if MM does not accept ww, L(Mw)=L(M_w) = \emptyset. If P\emptyset \notin P Then MwPM_w \in P iff MM accepts ww So deciding PP would decide ATMA_{\mathrm{TM}}. The case P\emptyset \in P is similar. \blacksquare

Corollary. The following are undecidable: “Does MM accept at least one string?”, “Is L(M)L(M) Finite?”, “Is L(M)L(M) regular?”, “Is L(M)L(M) context-free?”

  1. Reversing the direction of a many-one reduction. To prove BB is undecidable, you need AmBA \leq_m B where AA is known to be undecidable. This means “if BB is decidable, then AA is decidable” (contrapositive: AA undecidable implies BB undecidable). Reversing it to BmAB \leq_m A gives “if AA is decidable, then BB is decidable,” which tells you nothing about BB when AA is undecidable.

  2. Assuming all undecidable problems are “the same.” Undecidable problems have different degrees of unsolvability. The halting problem is Turing-complete, but there are problems that are not even Turing-recognisable (e.g., the complement of the halting problem). Reductions establish relative difficulty but not absolute equivalence.

  3. Confusing recognisability with decidability for co-RE languages. A language LL is decidable iff both LL and its complement L\overline{L} are recognisable. The halting problem is recognisable but its complement is not, so it is not decidable. Knowing only that LL is recognisable tells you nothing about L\overline{L}.

  4. Using Rice’s theorem incorrectly. Rice’s theorem applies to non-trivial properties of the language recognised by a TM, not properties of the TM itself. “Does this TM have 5 states?” is not a property of the language and is therefore decidable. “Does this TM accept a regular language?” is a property of the language and is undecidable by Rice’s theorem.

  5. Assuming oracles resolve undecidability. An oracle for the halting problem lets a TM decide the halting problem, but it cannot decide the halting problem relative to itself (the Turing jump). Oracles create a strict hierarchy — each level of oracle makes some problems decidable but introduces new undecidable problems at a higher level.