160 likes | 293 Views
COSC 3340: Introduction to Theory of Computation. University of Houston Dr. Verma Lecture 24. Decidability of Languages related to Finite Automata. The following are all Turing decidable : Dw = {< M , w > | DFA M accepts w } Nw = {< M , w > | NFA M accepts w }
E N D
COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 24 UofH - COSC 3340 - Dr. Verma
Decidability of Languages related to Finite Automata The following are all Turing decidable: • Dw = {<M, w> | DFA M accepts w} • Nw = {<M, w> | NFA M accepts w} • De = {<M> | DFA M satisfies L(M) = } • Da = {<M> | DFA M satisfies L(M) = * } • DD = {<M, M'> | DFAs M and M' satisfy L(M) = L(M’) } Very useful UofH - COSC 3340 - Dr. Verma
Dw = {<M, w> | DFA M accepts w} We only need to present a TM T that decides Dw. T = “On input <M, w>, where M is a DFA and w isa string: • Simulate M on input w. • If simulation ends in an accept state, accept. If it ends in a non-accepting state, reject.” • When T receives its input, T first checks on whether it properly represents a DFA M and a string w. If not, T rejects. UofH - COSC 3340 - Dr. Verma
Dw = {<M, w> | DFA M accepts w} (contd.) • T carries out the simulation in a direct way keeping track of M’s current state and position in the input w. • When T finishes processing the last symbol of w, it decides according to step 2 above. UofH - COSC 3340 - Dr. Verma
Nw = {<M, w> | NFA M accepts w} We can use the previous machine to simulate M with a small adjustment. TM N = “On input <M, w>, where M is a NFA, and w is a string: • Convert NFA M to an equivalent DFA C using the procedure for this conversion discussed in earlier slides. • Run TM T from previous slide(s) on input <C, w>. • If T accepts, accept; otherwise reject.” • Running TM T in stage 2 means incorporating T into the design of N as a sub-procedure. UofH - COSC 3340 - Dr. Verma
De = {<M> | DFA M satisfies L(M) = } • A DFA accepts some string iff reaching an accept state from the start state by traveling along the arrows of the DFA is possible. • TM T = “On input <M> where M is a DFA • Mark the start state of M. • Repeat until no new states get marked. • Mark any state that has a transition coming into it from any state that is already marked. • If no accept state is marked, accept; otherwise reject.” UofH - COSC 3340 - Dr. Verma
Da = {<M> | DFA M satisfies L(M) = * } • Given DFA M construct DFA M' such that L(M') = * - L(M). • To get M' just exchange final and non-final states of M. • Then ask whether L(M') = (i.e. use the TM of previous slide). If L(M') = then L(M) = * otherwise not. UofH - COSC 3340 - Dr. Verma
DD = {<M, M'> | DFAs M and M' satisfy L(M) = L(M’) } • We use De to prove this theorem. • We construct a new DFA C from M and M’, where C accepts only those string that are accepted by either M or M’ but not both. Thus, if M and M’ recognize the same language, C will accept nothing. The language of C is L(C) = (L(M) L(M’)) (L(M) L(M’)) This is sometimes called symmetric difference of L(M) and L(M’) _____ _____ UofH - COSC 3340 - Dr. Verma
DD = {<M, M'> | DFAs M and M' satisfy L(M) = L(M’) } (contd.) F = “On input <M, M'>, where M and M‘ are DFAs: • Construct DFA C as described. • Run TM T from De on input <C>. • If T accepts, accept. If T rejects, reject.” L(M) L(M’) UofH - COSC 3340 - Dr. Verma
Turing Decidability of languages related to CFLs • Gw = {< G, w > | CFG G generates w} • Pw = {<M, w> | PDA M accepts w} • Ge = {<G> | CFG G satisfies L(G) = } What about these? • Ga = {<G> | CFG G satisfies L(G) = * } • GG = {<G, G'> | CFGs G and G' satisfy L(G) = L(G')} • Tw = {<M, w> | TM M accepts w} UofH - COSC 3340 - Dr. Verma
Gw = {< G, w > | CFG G generates w} • One idea is to use G to go through all derivations. This idea does not work, as infinitely many derivations may have to be tried. • This idea gives a Turing Machine that is a recognizer, but not a decider, for Gw. • To make a machine that is a decider we need to ensure that algorithm tries only finitely many derivations. UofH - COSC 3340 - Dr. Verma
Gw = {< G, w > | CFG G generates w} (contd.) • TM S = “On input <G, w>, where G is a CFG and w is a string: • Convert G to an equivalent grammar in Chomsky Normal Form. • List all derivations with 2n-1 steps, where n is the length of w, except if n = 0, then instead list all derivations with 1 step. • If any of these derivations generate w, accept; if not reject.” UofH - COSC 3340 - Dr. Verma
Pw = {<M, w> | PDA M accepts w} • Let M be a PDA that represents a CFL A. • One idea for this is to convert PDA M into a TM N, which could be nondeterministic, then converting N to a deterministic TM. • Problem: The simulating TM then would also have some non-halting branches in its computation, and so the TM would not be decider. • A different idea is necessary so we prove this using Gw proof. UofH - COSC 3340 - Dr. Verma
Pw = {<M, w> | PDA M accepts w} (contd.) • Let M be a PDA and G be a CFG for CFL A. Now design TM Mg that decides Pw. G is obtained via the method discussed before. • Mg = “On input <M,w>: 0. Construct G equivalent to M. • Run TM S (from Gw proof) on input <G, w> • If S accepts, accept; if S rejects, reject. UofH - COSC 3340 - Dr. Verma
Ge = {<G> | CFG G satisfies L(G) = } • To do this algorithm we might use the same TM as we used in Gw proof. This does not work. Why? • We need to test whether the start variable can generate a string of terminals. • It should determine for each variable whether that variable is capable of generating a string of terminals. UofH - COSC 3340 - Dr. Verma
Ge = {<G> | CFG G satisfies L(G) = } (contd.) • TM R = “On input <G>, where G is a CFG • Mark all terminals symbols in G. • Repeat until no new variables get marked: • Mark any variable A where G has a rule A U1U2…Uk and each symbol U1…Uk has already been marked. • If the start symbol is not marked, accept; otherwise reject [Needs to be adjusted for empty string] UofH - COSC 3340 - Dr. Verma