MIT 18.404 — Lecture 7
Decision Problems for Automata and Grammars
By the end of this lecture, we will have gone over all content necessary for PSET #2 and our quiz next week.
§ Encodings
Definition. Given any object (e.g., an automaton, a graph, a string), let denote an encoding of into . Furthermore, let denote an encoding of into a single string.
Remark. Note that should probably not just be the concatenation of and . The encoding must be such that one can read the binary string and recognize that it must be an encoding of two objects, not just for some random .
The details of the encoding are not important—their only purpose is to let us take anything as binary input to a TM.
§ Algorithms on Automata
Turing machines are really strong—they can even run algorithms that answer questions about algorithms!
Problem. Consider the language . Show that is decidable.
Solution: Recall that it suffices to define a TM decider for which . Here's what does on input .
Check that is of the form for some DFA and some string .
Simulate on . (This takes finite time, because is a DFA that takes a finite string as input.)
In the end, return Accept if returns Accept, and return Reject otherwise.
And this works, obviously.
We're really abstracting away the details here. But because of the Church-Turing thesis—an algorithm is a Turing machine—we should have confidence that working at such a high level of abstraction will not cause any issues.
Remark. In case you're not convinced, here's a sketch of how we might implement “simulate on ” in a TM.
Use three tapes to hold each of , the current state , and with its head at the current position.
At each step, do the following:
Read the symbol at tape 3.
Scan the transition table on tape 1 for the entry whose state matches tape 2 and whose symbol is .
Write the target state onto tape 2 and advance the tape 3 head.
When all of has been read, scan on tape 1 for the state on tape 2.
Perhaps the individual steps above are more believably implementable by a TM.
Problem. Consider the language . Show that is decidable.
Solution: Just take a TM decider that, on input , does the following:
Check that takes form , then convert the NFA to a DFA , then simulate on as in the previous problem.
Problem. Consider the language . Show that is decidable.
Solution: This is a path-finding problem—it asks the following:
Question. Is there a path from the start state to any accept state?
So we can just return Accept if and only if BFS from the start state finds no accept state.
Problem. Consider the language . Show that is decidable.
Solution: This one is less obvious. Recall from our “closure property constructions” from Lecture 1 that
for some DFA , where is constructible from the DFAs and .
Then we just consider a TM that constructs the DFA , then runs the algorithm used for .
§ Algorithms on Grammars and Turing Machines
Answering questions about grammars is a little harder. Here's a useful fact that we'll assume without proof.
Theorem. (Chomsky Normal Form) Any CFG can be expressed as a CFG in which all rules look like or . Furthermore, there is a TM-executable algorithm for converting any CFG into such a form.
Problem. Consider the language . Show that is decidable.
Solution: First check that input takes form . Then convert into Chomsky Normal Form.
The point is that any derivation of must apply a rule exactly times. So it is now feasible to search through all derivations of length and Accept if and only if any derivation yields .
Here's an interesting corollary to the above point.
Theorem. (CFLs are Decidable) Every context-free language is decidable.
Proof: We must show that if is a CFL generated by a CFG , then there is a TM that decides . Well, just take to be the TM that, on input , searches through the length- derivations using the Chomsky Normal Form of .
Problem. Consider the language . Show that is decidable.
For example, the CFG with only one rule should be in .
Solution: Construct the CFG that results from replacing every terminal in with . (So becomes , say.) Then just run the algorithm used for to check whether generates , and Accept if and only if it does not.
… except, the algorithm for now must search through all derivations of length . What does that mean?!
The reason for this confusion is that Chomsky Normal Form permits one more kind of rule: , where is the start variable. So all the algorithm is doing is determining whether is in the Chomsky Normal Form of .
And that's really unsatisfying—all the nontrivial work is offloaded to the conversion of into Chomsky Normal Form. But we don't have time to present a better proof; maybe next lecture.
It turns out that, unlike with DFAs, the following languages are not decidable.
.
.
But if we replace “decidable” with “Turing-recognizable”, we find…
Problem. Show that is Turing-recognizable.
Solution: After checking that input takes form , just simulate on . In particular,
If halts and accepts, then return Accept.
If halts and rejects, then return Reject.
If never halts… well, then this Turing machine won't halt, either.
This just works.