



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Theory of computation
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




M = "On input {B, w), where B is a DFA and w is a string:
PROOF We mention just a few implementation details of this proof. For those of you familiar with writing programs in any standard programming language, imagine how you would write a program to carry out the simulation. First, let's examine the input (B, w). It is a representation of a DFA B together with a string w. One reasonable representation of B is simply a list of its five components, Q, E, 6, go, and F. When M receives its input, M first checks on whether it properly represents a DFA B and a string w. If not, M rejects. Then M carries out the simulation in a direct way. It keeps track of B's current state and B's current position in the input w by writing this information down on its tape. Initially, B's current state is go and B's current input position is the leftmost symbol of w. The states and position are updated according to the spec- ified transition function. When M finishes processing the last symbol of w, M accepts the input if B is in an accepting state; M rejects the input if B is in a nonaccepting state.
We present a TM , N that decides nfa- We could design N to operate like M, simulating an NFA instead of a DFA. Instead, we'll do it differently to illus- trate a new idea: have N use M as a subroutine. Because M is designed to work with DFAs, N first converts the NFA it receives as input to a DFA before passing it toM.
N = "On input (I?, w) where B is an NFA, and w is a string:
Let Arex = {(R, w) | R is a regular expression that generates string w}.
The following TM P decides P = "On input (jR, w) where R is a regular expression and w is a string:
Now we turn to a different kind of problem concerning finite automata: empti- ness testing for the language of a finite automaton. In the preceding theorems we had to test whether a finite automaton accepts a particular string. In the next proof we must test whether a finite automaton accepts any strings at all. Let -Edfa = {(-4)| A is a DFA and L(A) = 0}.
A DFA accepts some string if and only if reaching an accept state from the start state by traveling along the arrows of the DFA is possible. To test this condition we can design a TM T that uses a marking algorithm.
T = "On input (A) where A is a DFA:
To prove this theorem we construct a new DFA C from A and B, where C accepts only those strings that are accepted by either A or B but not by both. Thus, if A and B recognize the same language, C will accept nothing. The language of C is L{C) = (l(A) n L{B)\ U (Til) n L(B).
gives a Turing machine that is an recognizer, but not a decider, for cfg- To make this Turing machine into a decider we need to ensure that the al- gorithm tries only finitely many derivations. If G were in Chomsky normal form, any derivation of w has 2n โ 1 steps, where n is the length of w. In that case checking only derivations with 2n โ 1 steps to determine whether G generates w would be sufficient. Only finitely many such derivations exist. We can convert G to Chomsky normal form
PROOF The TM for Cfg follows. S = "On input (G, w), where G is a CFG and w is a string:
The problem of testing whether a CFG generates a particular string is related to the problem of compiling programming languages. The algorithm in TM S is very inefficient and would never be used in practice, but it is easy to describe and we aren't concerned with efficiency here. Hence everything we say about the decidability of problems concerning CFGs applies equally well to PDAs. Let's turn now to the emptiness testing problem for the language of a CFG. As we did for DFAs, we can show that the problem of testing whether a CFG generates any strings at all is decidable. Let E cfg = {{G)\ G is a CFG and L[G) = 0}.
To find an algorithm for this problem we might attempt to use TM, S. It states that we can test whether a CFG generates some particular string w. To determine whether L(G) = 0 the algorithm might try going through all possible tu's, one by one. But there are infinitely many w's to try, so this method could end up running forever. We need to take a different approach. In order to test whether the language of a grammar is empty, we need to test whether the start variable can generate a string of terminals. The algorithm does so by solving a more general problem. It determines/or each variable whether that variable is capable of generating a string of terminals.
When the algorithm has determined that a variable can generate some string of terminals, the algorithm keeps track of this information by placing a mark on that variable. First, the algorithm marks all the terminal symbols in the grammar. Then, it scans all the rules of the grammar. If it ever finds a rule that permits some variable to be replaced by some string of symbols all of which are already marked, the algorithm knows that this variable can be marked, too. The algorithm continues in this way until it cannot mark any additional variables. The TM R implements this algorithm.
PROOF R = "On input (G), where G is a CFG:
Let A be a CFL. Our objective is to show that A is decidable.
One (bad) idea is to convert a PDA for A directly into a TM. That isn't hard to do because simulating a stack with the TM's more versatile tape is easy. The PDA for A may be nondeterministic, but that seems okay because we can convert it into a nondeterministic TM and we know that any nondeterministic TM can be converted into an equivalent deterministic TM. Yet, there is a difficulty. Some branches of the PDA's computation may go on forever, reading and writing the stack with- out coming to a halt. The simulating TM then would also have some nonhalting branches in its computation, and so the TM would not be a decider. A different idea is necessary. Instead, we prove this theorem with the TM,S.
PROOF Let G be a CFG for A and design a TM, Mq that decides A. We build a copy of G into Me- It works as follows.