4.1 Decidable Languages How do you show that a problem is decidable? you describe a TM that decides the problem How do you need to represent the problem to be decided? you need to represent the problem as a language What's the Membership Problem for DFAs? Does DFA B accept the input w? What's the language that represents the problem? A[DFA] = { | B is a DFA that accepts input w } Show that A[DFA] is Decidable. TM M decides A[DFA] M = "on input , where B is a DFA and w is a string: 1. simulate B on input w 2. if the simulation ends in an accept state, accept otherwise, reject" How do you encode an instance of the problem as a string? How do you simulate the execution of the DFA? What's the Membership Problem for NFAs? Does NFA B accept the input w? What's the language that represents the problem? A[NFA] = { | B is an NFA that accepts input w } Show that A[NFA] is Decidable. How is this a reduction? N = "on input , where B is an NFA and w is a string: 1. 2. 3. TM N decides A[NFA] N = "on input , where B is an NFA and w is a string: 1. convert NFA B to an equivalent DFA C using the subset construction 2. run the A[DFA] decider TM M on input 3. if M accepts, accept otherwise, reject" What's the Membership Problem for Regular Expressions? Does Regular Expression R generate the string w? What's the language that represents the problem? A[REX] = { | R is a regular expression that generates w } Classwork. You may work with a partner. Show that A[REX] is Decidable. P = "on input , where R is a regular expression and w is a string: 1. 2. 3. What's the Emptiness Problem for DFAs? Does DFA A reject all possible input strings? What's the language that represents the problem? E[DFA] = { | A is a DFA and L(A) = empty-set } Show that E[DFA] is Decidable. TM T decides E[DFA] T = "on input , where A is a DFA: 1. mark the start state of A 2. repeat step 3 until no new states get marked 3. for each transition in A: x -> y if state x is marked mark state y 4. if no accept state is marked, accept otherwise, reject" What's the Equivalence Problem for DFAs? Do two DFAs A and B recognize the same language? What's the language that represents the problem? EQ[DFA] = { | A and B are DFAs and L(A) = L(B) } Show that EQ[DFA] is Decidable. F = "on input , where A and B are DFAs: 1. 2. 3. TM F decides EQ[DFA] F = "on input , where A and B are DFAs: 1. construct DFA C from DFAs A and B C = (A intersect NOT B) union (NOT A intersect B) 2. run the E[DFA] decider TM T on input 3. if T accepts, accept otherwise, reject" What's the Membership Problem for CFGs? Does CFG G generate the string w? What's the language that represents the problem? A[CFG] = { | G is a CFG that generates w } What's wrong with this TM for deciding A[CFG]? X = "on input , where G is a CFG and w is a string: 1. list all possible derivations using grammar G 2. if any of these derivations generates w, accept otherwise, reject" How can you use the following statement to fix the problem? If G is a CFG in CNF, for any string w in L(G) of length n >= 1, exactly 2n-1 steps are required to derive w Show that A[CFG] is Decidable. TM S decides A[CFG] S = "on input , where G is a CFG and w is a string: 1. convert G to an equivalent grammar in CNF 2. list all derivations with 2n-1 steps where n is the length of w except if n = 0, list all derivations with 1 step 3. if any of these derivations generates w, accept otherwise, reject" What's the Emptiness Problem for CFGs? Does CFG G generate no strings at all? What's the language that represents the problem? E[CFG] = { | G is a CFG and L(G) = empty-set } Show that E[CFG] is Decidable. TM R decides E[CFG] R = "on input , where G is a CFG: 1. mark all terminal symbols in G 2. repeat step 3 until no new variables get marked 3. for each rule in G: A -> U1 U2 ... Uk if all symbols U1, ..., Uk are marked mark variable A 4. if the start symbol is not marked, accept otherwise, reject" Classwork. You may work with a partner. What's the Emptiness Problem for PDAs? What's the language that represents the problem? Show that the problem is Decidable. What's the Equivalence Problem for CFGs? Do two CFGs G and H recognize the same language? What's the language that represents the problem? EQ[CFG] = { | G and H are CFGs and L(G) = L(H) } Is the problem Decidable? Is every CFL a Decidable Language? Is every Decidable Language a CFL? How can you show that every CFL is a Decidable Language? How do you build a TM that decides a CFL A? since A is a CFL, there is a CFG G that generates A using G, build a TM M[G] that decides A M[G] = "on input w: 1. run the A[CFG] decider TM S on input 2. if S accepts, accept otherwise, reject" How are the 4 classes of languages related? regular context free decidable recognizable