Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
Rina Overview Equivalence of the nondeterministic model to the deterministic model revisited Examples Closures of regular languages
Rina DFA construction algorithm Let A be an NFA where A = (Q A, , A, q 0A, F A ). We construct a DFA M equivalent to A, where M = ( Q, , , q 0, F). Q = P(Q A ) = For each R in Q and in (R, ) is q 0 = E(q 0A ) F = { R Q | there exists r R such that r F A } AA
Rina Explanation Create all the subsets of set of states of A. Those will become the states of M. The alphabet remains the same. The transition function : for each state m in M and a letter find what are the states qi..qj in A included in m for each qi m find a set R of states which you can reach in A using -closure, letter and -closure unite all the sets R you reach one set : S the next state of m on in M is S.
Rina Explanation The initial state in M is the set which includes only E(q 0A ). The final states in M - all the sets in which at least one state is final (accepting) state in A. Eliminate all the unreachable states in M - states to which the is no path from the initial state of M. The automaton you have is deterministic automaton equivalent to A.
Rina Formal proof We prove that L(M)=L(A). First we show that for each word w *, A ’(q 0A,w) = ’(q 0,w). We use induction.
Rina A ’(q 0A,w) = ’(q 0,w) Induction basis: w= . A ’(q 0A, ) = P A ’(q 0A, .. .. ) = P P = ’(q 0, ). Induction hypothesis: Assume that theorem is true for some word w: A ’(q 0A,w) = ’(q 0,w) Induction step: Proof that the theorem is true for w . A ’(q 0A, w ) = ’ A ( A ’(q 0A, w), ) by induction hypothesis ’ A ( ’(q 0, w), ) by definition of ’( ’(q 0, w), )= ’( q 0, w ).
Rina L(M)=L(A) w L(A) A ’(q 0A,w)=P and P F A by definition of F A ’(q 0A,w) =P and P F by the previous theorem ’(q 0,w) =P and P F w L(M)
Rina Example Convert a given nondeterministic finite automaton to a deterministic finite automaton. A:
Rina Example Using the algorithm we construct the following automaton: M:
Rina Example Convert a given nondeterministic finite automaton to a deterministic finite automaton. B:
Rina Example Using the algorithm we construct the following states: M:
Rina Example M:
Rina Example Some states of this automaton are unreachable from q0. After elimination of all unreachable states in M the resulting automaton is:
Rina Theorem Every NFA with -transitions has an equivalent NFA without -transitions. Proof idea: We give a constructive proof - by giving an algorithm to build a NFA without - transitions which is equivalent to a given NFA.
Rina Constructive proof Let EM be NFA with -transitions where EM = (Q EM, , EM, q 0EM, F EM ). We will construct an NFA without -transitions ND which is equivalent to EM, where ND= (Q, , , q 0, F). Q= Q EM = For each q in Q and in (q, ) is E( EM (E(q), )= EM (q, … .. ) (This means you have to add new edges to automaton ND)
Rina Constructive proof q 0 =q 0EM F: –if E(q 0EM ) F = (the empty word does not belong to L(EM)) then F= F EM –else (the empty word belongs to L(EM)) F= F EM {q 0EM }
Rina Example Build a NFA without -transitions which is equivalent to a given NFA with -transitions. q1 1 2 q2 q0 0
Rina (q0,0)={q0,q1,q2} (q0,1)={q1,q2} (q0,2)={q2} q1 1 2 q2 q0 0 (q1,0)=? (q1,1)={q1,q2} (q1,2)={q2} (q2,0)=? (q2,1)=? (q2,2)={q2} q1 1 q0 0 2 q2 0,11,2 0,1,2
Rina A NFA without -transitions We use an NFA without -transitions to construct a DFA that is equivalent to a given NFA with -transitions. Basic construction idea: –We are given an NFA EM with -transitions –Build an NFA M without -transitions –Build a DFA D equivalent to M.
Rina Example Build a DFA equivalent to a given NFA. q1 1 2 q2 q0 0 EM:
Rina Example The NFA M without -transitions: M: q1 1 q0 0 2 q2 0,11,2 0,1,2
Rina Example A DFA D equivalent to M: D: 0 q0,1,2 q0 2 q q1, 0,1,2 0 0,1 2
Rina Closure of regular languages Theorem: The class of languages accepted by finite automata is closed under: union concatenation Kleene (star) closure.
Rina Basic proof idea Proof by construction: In each case we will construct an automaton M that accepts the appropriate language. We will use non-deterministic models.
Rina Union Let M 1 recognize L 1 where M 1 = (Q 1, , 1, q 01, F 1 ) and M 2 recognize L 2 where M 2 = (Q 2, , 2, q 02, F 2 ). Construct M to recognize L 1 L 2, where M = ( Q, , , q 0, F).
Rina Union
Rina Union We construct M in a way that uses nondeterminism to “guess” whether the input word w is in L 1 or L 2 and then process the string exactly as the corresponding automaton (M 1 or M 2 ).
Rina Union M = ( Q, , , q 0, F) where Q=Q 1 Q 2 {q 0 } = 1 2 { (q 0, )=q 01, (q 0, )=q 02 } q 0 F=F 1 F 2
Rina Proof We gave the formal proof during the last lecture. The basic idea of the proof is: if w *, then ’(q 0,w)=q for some q F iff either ’(q 01,w)=q for some q F 1 or ’(q 02,w)=q for some q F 2 Hence M accepts w iff M 1 accepts w or M 2 accepts w.
Rina Concatenation Let M 1 recognize L 1 where M 1 = (Q 1, , 1, q 01, F 1 ) and M 2 recognize L 2 where M 2 = (Q 2, , 2, q 02, F 2 ). Construct M to recognize L 1 L 2, where M = ( Q, , , q 0, F).
Rina Concatenation
Rina Concatenation We construct M that simulates M1 for a while Then M "jumps" nondeterministically from a final state of M1 to the initial state of M2 And then M will simulate M2 for the rest of the input.
Rina Concatenation M = ( Q, , , q 0, F) where Q=Q 1 Q 2 = 1 2 {for each state f F1 (f, )=q 02 } q 0 =q 01 F= F 2
Rina Proof The basic proof idea is: if w *, then ’(q 0,w)=q for some q F iff w=uv and ’(q 01,u)=f for some f F 1 and ’(q 02,v)=q for some q F 2. Hence M accepts w iff M 1 accepts u and M 2 accepts v.
Rina Kleene star Let M 1 recognize L 1 where M 1 = (Q 1, , 1, q 01, F 1 ). Construct M to recognize L 1 *, where M = ( Q, , , q 0, F).
Rina Kleene (star) closure We will construct M in a way similar to concatenation. M simulates M 1 on w all the way plus it has an option to go back to q 01. M also excepts .
38 Kleene (star) closure M = ( Q, , , q 0, F) where Q=Q 1 {q 0 } = 1 (q 0, )=q 01 {for each state f F (f, )=q 01 } q 0 =q 0 F= {q 0 } F 1
Rina Any Questions?