knowledge

Theory of Computation: Lecture 5

Encoded decision problems, decidability of DFA emptiness and equivalence, diagonalization, HALT and ATM, and the boundary between decidable, recognizable, and unrecognizable languages.

Encoded Decision Problems

Turing machines can decide languages beyond finite memory, and Hilbert's tenth problem shows that some problems have no decider at all. To map that boundary systematically, turn the machines into data and ask decision questions about automata and Turing machines themselves. A Turing machine receives ordinary strings as input, but these questions are about structured objects: automata, graphs, pairs of machines, or a machine together with its input. To ask them with a Turing machine, the objects must first be written as strings.

Encoding. A finite representation of an object as a string. The notation O\langle O\rangle means "the encoding of object OO". For pairs, O1,O2\langle O_1,O_2\rangle means one string encoding both objects with enough delimiters to decode them.

Anything finite and discrete can be encoded as a binary string: states, transition tables, graph edges, formulas, and even Turing machines themselves.

Invalid encodings are harmless in decidability proofs. A decider may first check whether the input is a valid encoding and reject if it is not.

Decision problem. A yes/no problem viewed as a language of encodings. The language contains exactly the encodings of instances whose answer is yes.

ProblemLanguage form
Does DFA DD accept no strings?{DL(D)=}\{\langle D\rangle\mid L(D)=\varnothing\}
Do DFAs DD and DD' accept the same language?{D,DL(D)=L(D)}\{\langle D,D'\rangle\mid L(D)=L(D')\}
Does TM MM halt on input ww?{M,wM halts on w}\{\langle M,w\rangle\mid M\text{ halts on }w\}

High-level TM description. A finite algorithmic description that can be implemented by a Turing machine. By the Church-Turing thesis, it is enough to describe ordinary effective procedures such as parsing an encoding, simulating an automaton, or running a graph search.

The machine model is low-level; decidability proofs are usually written at the algorithm level.

Deciding DFA Properties

The first useful decision problems ask whether an encoded DFA has a property. These are easier than they may look because a DFA is a finite graph.

DFA emptiness problem.

EDFA={DD is a DFA and L(D)=}.E_{\mathrm{DFA}}=\{\langle D\rangle\mid D\text{ is a DFA and }L(D)=\varnothing\}.

A tempting algorithm enumerates all strings ϵ,0,1,00,01,10,11,\epsilon,0,1,00,01,10,11,\ldots and simulates DD on each one. If DD accepts some string, the algorithm rejects. But if L(D)=L(D)=\varnothing, no accepting string is ever found, so the algorithm runs forever. It is not a decider for EDFAE_{\mathrm{DFA}}.

The right algorithm does not search through infinitely many strings. It searches through finitely many states.

Reachability set. For a DFA D=(Q,Σ,δ,q0,F)D=(Q,\Sigma,\delta,q_0,F), the set RQR\subseteq Q of states reachable from q0q_0 by following zero or more transitions.

Emptiness criterion. A DFA has nonempty language if and only if some accepting state is reachable from q0q_0.

If qFq\in F is reachable, the path labels form a string accepted by DD. Conversely, if DD accepts some string, the run on that string ends in a reachable accepting state.

Emptiness is a graph question: ignore the infinite set of possible strings and ask whether an accepting vertex is reachable.

Recipe: deciding EDFAE_{\mathrm{DFA}}.

  1. Parse the input as D\langle D\rangle with D=(Q,Σ,δ,q0,F)D=(Q,\Sigma,\delta,q_0,F).
  2. Initialize R={q0}R=\{q_0\}.
  3. While there exist qRq\in R, aΣa\in\Sigma, and qQRq'\in Q\setminus R with δ(q,a)=q\delta(q,a)=q', add qq' to RR.
  4. When no new state can be added, accept iff RF=R\cap F=\varnothing.

The loop halts because QQ is finite and each successful iteration adds a new state.

01010,1q0q1q2
Nonempty: q2 is reachable from q0, so the DFA is rejected by E_DFA.
00110,1q0q1q2
Empty: the only accepting state is unreachable, so the DFA is accepted by E_DFA.

DFA equivalence problem.

EQDFA={D,DL(D)=L(D)}.EQ_{\mathrm{DFA}}=\{\langle D,D'\rangle\mid L(D)=L(D')\}.

Two DFAs differ exactly on the strings in the symmetric difference of their languages.

Symmetric difference. For languages AA and BB over the same alphabet,

AB=(AB)(AB).A\oplus B=(A\cap\overline{B})\cup(\overline{A}\cap B).

It contains exactly the strings that belong to one language but not the other. Therefore:

L(D)=L(D)L(D)L(D)=.L(D)=L(D')\quad\Longleftrightarrow\quad L(D)\oplus L(D')=\varnothing.

Regular languages are closed under complement, union, and intersection, so L(D)L(D)L(D)\oplus L(D') is regular. More concretely, for D=(Q,Σ,δ,q0,F)D=(Q,\Sigma,\delta,q_0,F) and D=(Q,Σ,δ,q0,F)D'=(Q',\Sigma,\delta',q_0',F') the product construction from Lecture 1 builds a DFA DD^\oplus with states Q×QQ\times Q', start state (q0,q0)(q_0,q_0'), and transition δ((q,q),a)=(δ(q,a),δ(q,a))\delta^\oplus((q,q'),a)=(\delta(q,a),\delta'(q',a)). Only the accepting set is new, the disagreement pairs where exactly one side accepts:

(F×(QF))((QF)×F).\big(F\times(Q'\setminus F')\big)\cup\big((Q\setminus F)\times F'\big).

If DD accepts the strings ending in 0 and DD' accepts the even-length strings, then 0 lies in their symmetric difference, so a disagreement pair is reachable and the two DFAs are not equivalent.

Recipe: deciding EQDFAEQ_{\mathrm{DFA}}.

  1. Parse the input as D,D\langle D,D'\rangle.
  2. Build the product DFA DD^\oplus for L(D)L(D)L(D)\oplus L(D').
  3. Run the decider for EDFAE_{\mathrm{DFA}} on D\langle D^\oplus\rangle.
  4. Accept iff L(D)=L(D^\oplus)=\varnothing.

A decider may call another decider as a subroutine. The only obligation is that every subroutine call halts.

Diagonalization

Decidable languages are not all languages. The reason is already visible at the level of size: there are only countably many machines but uncountably many languages.

Bijection. A function that is both injective and surjective. It pairs the elements of two sets with no duplicates and no omissions.

Countable set. A set that is finite or can be listed as a1,a2,a3,a_1,a_2,a_3,\ldots. Equivalently, it has a bijection with N\mathbb{N}.

The even numbers are countable by n2nn\mapsto 2n. The positive rationals are countable by listing them in a grid and skipping duplicates.

Diagonalization. A proof method that assumes a complete list and constructs an object that differs from the ii-th listed object at position ii. The constructed object cannot appear anywhere in the list.

Cantor's diagonal argument shows that the real numbers are uncountable: given a supposed list of decimal expansions, choose a new number whose ii-th digit differs from the ii-th digit of the ii-th listed real.

The same idea applies to languages. Fix an order

Σ={s1,s2,s3,}.\Sigma^*=\{s_1,s_2,s_3,\ldots\}.

Every language LΣL\subseteq\Sigma^* has a characteristic sequence χL{0,1}N\chi_L\in\{0,1\}^{\mathbb{N}}, where the ii-th bit is 11 iff siLs_i\in L. The same diagonal argument makes these sequences uncountable: given any list of them, flip the ii-th bit of the ii-th sequence to get one that is missing. So the set of all languages is uncountable.

Turing machines are countable because every machine has a finite encoding, and all finite strings can be listed by length. Since each TM recognizes at most one language, some languages are not Turing-recognizable.

There are more yes/no string problems than there are programs.

Diagonal language. List Σ\Sigma^* by length and read each string as a Turing machine, treating any string that is not a valid encoding as a fixed machine that rejects everything. This enumerates all Turing machines as M1,M2,M3,M_1,M_2,M_3,\ldots, and every machine appears as some MiM_i.

Tabulate how each machine behaves on each encoding: write A when it accepts, R when it rejects, and \infty when it loops forever. Row ii records MiM_i and column jj uses the input Mj\langle M_j\rangle, so the entry in row ii, column jj is the outcome of running MiM_i on Mj\langle M_j\rangle.

Machine on inputM1\langle M_1\rangleM2\langle M_2\rangleM3\langle M_3\rangleM4\langle M_4\rangle\cdots
M1M_1A\inftyRA\cdots
M2M_2R\boldsymbol{\infty}AA\cdots
M3M_3R\inftyR\infty\cdots
M4M_4A\inftyRA\cdots
\vdots\vdots\vdots\vdots\vdots\ddots

Only the diagonal matters, the bold entries where MiM_i runs on its own encoding Mi\langle M_i\rangle. Define

DIAG={MiMi does not accept Mi},\mathrm{DIAG}=\{\langle M_i\rangle\mid M_i\text{ does not accept }\langle M_i\rangle\},

where "does not accept" covers both rejecting and looping. So DIAG\mathrm{DIAG} collects exactly the encodings whose diagonal entry is not A, the R and \infty cases. Reading the diagonal above:

  • M1M_1 accepts M1\langle M_1\rangle (A), so M1DIAG\langle M_1\rangle\notin\mathrm{DIAG}.
  • M2M_2 loops on M2\langle M_2\rangle (\infty), so M2DIAG\langle M_2\rangle\in\mathrm{DIAG}.
  • M3M_3 rejects M3\langle M_3\rangle (R), so M3DIAG\langle M_3\rangle\in\mathrm{DIAG}.
  • M4M_4 accepts M4\langle M_4\rangle (A), so M4DIAG\langle M_4\rangle\notin\mathrm{DIAG}.

Equivalently, DIAG\mathrm{DIAG} is the complement of the diagonal: for every ii it is built to disagree with MiM_i at the single input Mi\langle M_i\rangle, turning accept into non-membership and reject-or-loop into membership.

Theorem: DIAG\mathrm{DIAG} is undecidable.

1. Assumption. Suppose some TM MM decides DIAG\mathrm{DIAG}.

2. Self-reference. Since the list contains every TM, M=MiM=M_i for some ii. Because MM decides DIAG\mathrm{DIAG}, L(Mi)=DIAGL(M_i)=\mathrm{DIAG}.

3. Diagonal question. Ask whether MiL(Mi)\langle M_i\rangle\in L(M_i).

If MiL(Mi)\langle M_i\rangle\in L(M_i), then MiDIAG\langle M_i\rangle\in\mathrm{DIAG}, so by definition MiM_i does not accept Mi\langle M_i\rangle, contradiction.

If MiL(Mi)\langle M_i\rangle\notin L(M_i), then MiM_i does not accept Mi\langle M_i\rangle, so MiDIAG=L(Mi)\langle M_i\rangle\in\mathrm{DIAG}=L(M_i), contradiction.

4. Conclusion. No decider for DIAG\mathrm{DIAG} exists.

The impossible machine would have to answer the opposite of its own answer on its own encoding.

The Halting and Acceptance Problems

The diagonal language is artificial, but it is useful because it can be used to prove natural machine-input problems undecidable.

Recipe: proving a language undecidable.

  1. Assume a decider. Suppose a TM decides the target language LL.
  2. Reduce from a known case. Use it as a subroutine to build a decider for a language already known to be undecidable, such as DIAG\mathrm{DIAG}.
  3. Derive the contradiction. That language has no decider, so the assumed decider for LL cannot exist.

Halting problem.

HALT={M,wM is a TM and M halts on input w}.\mathrm{HALT}=\{\langle M,w\rangle\mid M\text{ is a TM and }M\text{ halts on input }w\}.

Universal simulation. A TM can simulate another encoded TM step by step on an encoded input. Thus HALT\mathrm{HALT} is recognizable:

  1. On input M,w\langle M,w\rangle, simulate MM on ww.
  2. If the simulation ever reaches qacceptq_{\text{accept}} or qrejectq_{\text{reject}}, accept.

If MM loops on ww, this recognizer also loops. That is why it recognizes HALT\mathrm{HALT} but does not decide it.

Theorem: HALT\mathrm{HALT} is undecidable.

Assume, for contradiction, that HH decides HALT\mathrm{HALT}. Build a decider DD for DIAG\mathrm{DIAG}:

  1. On input M\langle M\rangle, run HH on M,M\langle M,\langle M\rangle\rangle.
  2. If HH rejects, then MM loops on M\langle M\rangle, so MM does not accept M\langle M\rangle; accept.
  3. If HH accepts, simulate MM on M\langle M\rangle until it halts. If MM accepts, reject; if MM rejects, accept.

DD halts on every input because HH halts, and in the third case HH has certified that the simulation of MM will halt. Moreover, DD accepts exactly the machines that do not accept their own encoding. Therefore DD decides DIAG\mathrm{DIAG}, contradiction.

The hard part is not noticing when a machine halts. It is proving in finite time that it never will.

Acceptance problem.

ATM={M,wM is a TM and M accepts w}.A_{\mathrm{TM}}=\{\langle M,w\rangle\mid M\text{ is a TM and }M\text{ accepts }w\}.

Theorem: ATMA_{\mathrm{TM}} is undecidable.

Assume, for contradiction, that HAH_A decides ATMA_{\mathrm{TM}}. Build a decider DD for DIAG\mathrm{DIAG}: on input M\langle M\rangle, run HAH_A on M,M\langle M,\langle M\rangle\rangle and output the opposite answer. Then DD always halts because HAH_A does, and DD accepts M\langle M\rangle exactly when MM does not accept M\langle M\rangle, which is exactly MDIAG\langle M\rangle\in\mathrm{DIAG}. So DD decides DIAG\mathrm{DIAG}, contradiction.

Unlike the halting reduction, this one needs no re-simulation: HAH_A reports acceptance directly, so DD only flips its answer.

The difference between HALT\mathrm{HALT} and ATMA_{\mathrm{TM}} is the event being tested:

LanguageYes whenNo when
HALT\mathrm{HALT}MM accepts or rejects wwMM loops on ww
ATMA_{\mathrm{TM}}MM accepts wwMM rejects or loops on ww

Recognizable and Unrecognizable Languages

The halting problem separates recognizability from decidability: HALT\mathrm{HALT} is recognizable but undecidable. To find a language that is not even recognizable, use complements.

Complement recognizability theorem. A language LL is decidable if and only if both LL and L\overline{L} are recognizable.

1. Decidable to recognizable. If LL is decidable, its decider recognizes LL. Swapping accept and reject gives a decider, hence a recognizer, for L\overline{L}.

2. Recognizable complements to decidable. Suppose M1M_1 recognizes LL and M2M_2 recognizes L\overline{L}. Construct a machine MM:

  1. On input ww, run M1M_1 and M2M_2 on ww in dovetailing fashion: one step of M1M_1, then one step of M2M_2, and repeat.
  2. If M1M_1 accepts, accept.
  3. If M2M_2 accepts, reject.

For every ww, either wLw\in L or wLw\in\overline{L}. Therefore one of the two recognizers eventually accepts, so MM halts on every input and decides LL.

Running recognizers "in parallel" means alternating finite pieces of their computations so neither one can starve the other.

Corollary. HALT\overline{\mathrm{HALT}} is not recognizable.

HALT\mathrm{HALT} is recognizable but undecidable. If HALT\overline{\mathrm{HALT}} were recognizable too, the complement recognizability theorem would imply that HALT\mathrm{HALT} is decidable, contradiction.

All languagesRegularDecidableRecognizableNotrecognizable
Known containment after HALT: regular languages are decidable, HALT is recognizable but not decidable, and complement HALT is not recognizable.

The strict containments now known are, writing P(Σ)\mathcal{P}(\Sigma^*) for the set of all languages:

RegularDecidableRecognizableP(Σ).\text{Regular}\subsetneq\text{Decidable}\subsetneq\text{Recognizable}\subsetneq\mathcal{P}(\Sigma^*).

Regular languages are decidable because a TM can simulate a DFA and halt. The containment is strict because languages such as equal numbers of 0s and 1s are decidable but not regular. Decidable languages are recognizable by definition, and the containment is strict because HALT\mathrm{HALT} is recognizable but undecidable. Finally, HALT\overline{\mathrm{HALT}} is a concrete language outside the recognizable languages.