CMSC 28000 — Lecture 21

Decidability

Recall that we have the two notions of decidable and recognizable languages. These form language classes.

Definition 21.1. The class of (Turing-)recognizable languages is the class of languages that can be recognized by a Turing machine. This class is also called the class of recursively enumerable languages.

The class of (Turing-)decidable languages is the class of languages that can be decided by a Turing machine. This class is also called the class of recursive languages.

As you might guess, the alternate terminology (which is still used) is due to equivalent notions in the world of recursive functions.

Now, we're finally able to return to the idea of decision problems that we started the class off with. Recall that a decision problem is just a function that maps an input to Yes or No. Then, we observe that everything that we do on real computers and Turing machines can be interpreted as a string of bits. We now understand that these are just words, which makes our decision problem a language membership problem: is this word in the language or not?

Example 21.2. Suppose we wanted to know whether a given undirected graph is connected. An undirected graph is connected if every node can be reached from every other node. In other words, we want a Turing machine that decides the language $$ L = \{ \langle G \rangle \mid \text{$G$ is a connected undirected graph} \}. $$

Note that since $L$ is a language, it isn't a set of graphs, but a set of encodings of graphs as strings. We distinguish objects (like graphs or DFAs or Turing machines) from their encodings as strings by using the angled brackets $\langle \cdot \rangle$. So here, we would consider $G$ to be a graph and $\langle G \rangle$ the encoding of a graph.

Now, we need to consider a proper encoding for graphs. Recall that a graph is a pair $G = (V,E)$, where $V$ is a set of nodes or vertices and $E$ is a set of edges, which are pairs of vertices. Then we can encode a graph $G = (V,E)$ by as follows: $$ \langle G \rangle = (v_1,v_2,\dots,v_n)((v_{e_1,1},v_{e_1,2}),(v_{e_2,1},v_{e_2,2}),\dots,(v_{e_m,1},v_{e_m,2})). $$ where $v_i \in V$ are vertices. This particular encoding is a list of all of the vertices in the graph followed by a list of all of the edges. Now, it is not too difficult to see how a Turing machine can decide $L$.

  1. Select the first node of $G$ and mark it.
  2. Repeat the following until no new nodes are marked:
  3. For each node in $G$, mark it if it is in an edge with a node that is already marked.
  4. Scan all nodes of $G$ to see if they are all marked. If they are, accept; otherwise, reject.

Now, we'll be revisiting some properties of regular and context-free languages. While we'll see that a lot of problems are decidable, there are some very surprising examples of problems which are undecidable. Many decidability properties that we'll be discussing were shown by Rabin and Scott in 1959 and Bar-Hillel, Perles, and Shamir in 1961.

Membership

The simplest problem we can ask about a language device and a word is whether the word belongs in the language. Again, this is the language membership problem: Given a device $A$ and a word $w$, is $w \in L(A)$?

We define the following language for the DFA acceptance problem: $$ A_{DFA} = \{\langle B, w \rangle \mid \text{$B$ is a DFA that accepts $w$}\}.$$

Theorem 21.3. $A_{DFA}$ is a decidable language.

The idea of the proof is rather simple: we simply simulate $B$ on the input string $w$. How does would a Turing machine do this? The machine would need to keep track of two things:

  1. The current state of $B$, and
  2. The current location in the word $w$.

Then the machine accepts the input if and only if $B$ is in an accepting state when the last symbol of $w$ is processed. Otherwise, it rejects.

We can ask the same question for NFAs: $$ A_{NFA} = \{\langle B, w \rangle \mid \text{$B$ is an NFA that accepts $w$}\}.$$

Theorem 21.4. $A_{NFA}$ is a decidable language.

Here, we can take advantage of the theorem we just proved above. We can construct a Turing machine that does the following on the input $\langle B,w \rangle$, where $B$ is an NFA and $w$ is an input word:

  1. Convert $B$ into a DFA $B'$ via subset construction.
  2. Run the Turing machine from Theorem 21.3 on the input $\langle B', w \rangle$ to check if $w \in L(B')$.
  3. If the TM accepts, accept. Otherwise, reject.

This machine demonstrates two ideas. The first is that we can use other Turing machines as subroutines like a typical programmer would think of doing. The second is that we are able to convert NFAs to DFAs, so we don't need to consider DFAs and NFAs separately anymore.

Now, we'll turn our attention to context-free languages. As you might expect, things can get a bit more complicated, especially as grammars are fairly different objects from finite automata and we don't have many of the same nice properties of regular languages to rely on. In the case of a grammar, rather than acceptance, we have the problem of whether a grammar generates a particular string. Thus, we have the following language $$ A_{CFG} = \{\langle G, w \rangle \mid \text{$G$ is a CFG that generates $w$}\}.$$

Theorem 21.5. $A_{CFG}$ is a decidable language.

This is obviously decidable; we even gave an efficient algorithm for it (CYK)! So we can pretend that we have a CYK Turing machine.

If you don't like that answer, we can do the more naïve way and check every derivation with $2n-1$ steps. Such a Turing machine operates as follows:

  1. On input $\langle G,w \rangle$, where $G$ is a CFG and $w$ is a string, transform $G$ into an equivalent grammar $G'$ in Chomsky normal form.
  2. List all derivations with $2n-1$ steps, where $n = |w|$, unless $n = 0$, in which case list all derivations with 1 step.
  3. If any of these derivations generate $w$, accept; otherwise, reject.

Emptiness

Another common problem you can ask is whether your language device actually describes any strings at all. This is the emptiness problem: Given a device $A$, is $L(A) = \emptyset$?

We will consider the following language $$ E_{DFA} = \{ \langle A \rangle \mid \text{$A$ is a DFA and $L(A) = \emptyset$}\}. $$

Theorem 21.6. $E_{DFA}$ is a decidable language.

To solve this problem, we simply treat it like a graph problem. A DFA accepts a word if there is an accepting state that is reachable from the initial state. Then we can use a similar idea to the graph connectedness algorithm from last week for this problem. The TM looks like this:

  1. Mark the initial state of $A$.
  2. Repeat until no new states get marked:
    Mark any state that has a transition coming into it from any state that is already marked.
  3. If no accepting state is marked, accept. Otherwise, reject.

We can also show that the emptiness problem for CFGs is also decidable. Again, it'll look a bit different from what we've done with DFAs. First, here's the language $$E_{CFG} = \{\langle G \rangle \mid \text{$G$ is a CFG and $L(G) = \emptyset$} \}.$$

Theorem 21.7. $E_{CFG}$ is a decidable language.

In a way, we can apply the same kind of idea from the DFA case. Of course, a grammar isn't a graph, so it's not exactly the same. However, in essence, what we want to do is check that there's a derivation that will generate some terminal beginning from the start variable. To do this, we check each variable to see if it can generate a string of terminals. We begin by marking terminals and determining whether each variable can generate a string of variables and terminals that are all marked. Once the algorithm is finished, we can simply check whether the start variable is marked or not.

  1. On input $\langle G \rangle$ where $G$ is a CFG, mark all terminal symbols in $G$.
  2. Repeat until no new variables get marked:
    Mark any variable $A$ where $G$ has a rule $A \to U_1 U_2 \cdots U_k$ and each symbol $U_1, \dots, U_k$ has already been marked.
  3. If the start variable is not marked, accept; otherwise reject.

Containment

Another common problem is if we have two language devices, whether we can compare them somehow. The most basic variant of these is asking whether one is contained in the other. This is the containment problem: Given two devices $A$ and $B$, is $L(A) \subseteq L(B)$?

Consider the following language, $$ C_{DFA} = \{ \langle A,B \rangle \mid \text{$A$ and $B$ are DFAs and $L(A) \subseteq L(B)$} \}.$$ Of course, this is another decidable property, so we have the following theorem.

Theorem 21.8. $C_{DFA}$ is a decidable language.

Again, we make use of the machine that we constructed in the previous theorem. First, let's consider what it means for $L(A)$ to be contained in $L(B)$. We want to check whether every word in $L(A)$ is also in $L(B)$. However, an equivalent way of checking this property is to check whether there are any words in $L(A)$ that are not in $L(B)$. So we construct a DFA $C$ such that $$ L(C) = L(A) \cap \overline{L(B)}$$ and check whether or not $L(C) = \emptyset$. Luckily, we've just shown how to check the emptiness of a DFA.

  1. On input $\langle A,B \rangle$, construct the DFA $C$ as described above.
  2. Run the TM from Theorem 21.6 on the input $\langle C \rangle$ to check if $L(C) = \emptyset$.
  3. If the machine accepts, accept. Otherwise, reject.

Solving containment lets us solve other similar problems. For instance, we can solve the equality problem: Given two devices $A$ and $B$, is $L(A) = L(B)$?

Theorem 21.9. The language $$EQ_{DFA} = \{ \langle A,B \rangle \mid \text{$A$ and $B$ are DFAs and $L(A) = L(B)$} \}.$$ is a decidable language.

Of course, we have the opportunity to make use of the machine that we constructed in the previous theorem. Recall that for two sets $S$ and $T$, $S = T$ if and only if $S \subseteq T$ and $T \subseteq S$. This fact combined with the containment machine we constructed gives us a rather simple algorithm for checking equality.

  1. On input $\langle A,B \rangle$, run the TM from the previous theorem on the input $\langle A,B \rangle$ to check if $L(A) \subseteq L(B)$ and run it again on $\langle B,A \rangle$ to check if $L(B) \subseteq L(A)$.
  2. If both machines accept, accept. Otherwise, reject.

Then this allows us to solve the universality problem: Given a device $A$, does $L(A) = \Sigma^*$? Again, this is fairly straightforward based on the results we've already shown. One approach is to construct a simple DFA that recognizes $\Sigma^*$ and test whether $\Sigma^* \subseteq L(A)$. Another approach is the check whether $\overline{L(A)} = \emptyset$.

But what about context-free languages? Suppose we have two context-free grammars $G_1$ and $G_2$. Then $L(G_1) \subseteq L(G_2)$ if and only if $L(G_1) \cap \overline{L(G_2)} = \emptyset$, just as above. But there's a problem with this: context-free languages aren't closed under intersection and complement, so we're not guaranteed to end up with a context-free language after this process.

Maybe we can try something more clever? Unfortunately, even if we tried harder, we won't be able to solve this problem, as it turns out to be our first encounter with an undecidable problem. And since containment for CFGs is undecidable, this means that equality and universality are also going to be undecidable.

Well, that's the claim at least, but can we prove it?

Undecidability and regular languages

So this tells us that some surprisingly fundamental problems about context-free languages are undecidable. This leads to an interesting question: Are there any known undecidable problems about finite automata? The answer is, there are very few examples, but yes!