Complexity and Computability Theory I Lecture 5 Rina
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter 2002 -2003 Rina Zviel-Girshin @ASC
Overview ü Equivalence of the nondeterministic model to the deterministic model revisited ü Examples ü Closures of regular languages Rina Zviel-Girshin @ASC 2
DFA construction algorithm Let A be an NFA where A = (QA, , A, q 0 A, FA). We construct a DFA M equivalent to A, where M = ( Q, , , q 0, F). • Q = P(QA) • = • For each R in Q and in (R, ) is A A • q 0 = E(q 0 A) • F = { R Q | there exists r R such that r FA} Rina Zviel-Girshin @ASC 3
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 Zviel-Girshin @ASC 4
Explanation • The initial state in M is the set which includes only E(q 0 A). • 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 Zviel-Girshin @ASC 5
Formal proof • We prove that L(M)=L(A). • First we show that for each word w *, A’(q 0 A, w) = ’(q 0, w). • We use induction. Rina Zviel-Girshin @ASC 6
A’(q 0 A, w) = ’(q 0, w) • Induction basis: w= . A’(q 0 A, ) = P A’(q 0 A, . . ) = P P = ’(q 0, ). • Induction hypothesis: Assume that theorem is true for some word w: A’(q 0 A, w) = ’(q 0, w) • Induction step: Proof that theorem is true for w. A’(q 0 A, w ) = ’A( A’(q 0 A, w), ) by induction hypothesis ’A( ’(q 0, w), ) by definition of ’( ’(q 0, w), )= ’( q 0, w ). Rina Zviel-Girshin @ASC 7
L(M)=L(A) w L(A) A’(q 0 A, w)=P and P FA by definition of F A’(q 0 A, w) =P and P F by the previous theorem ’(q 0, w) =P and P F w L(M) Rina Zviel-Girshin @ASC 8
Example Convert a given nondeterministic finite automaton to a deterministic finite automaton. A: Rina Zviel-Girshin @ASC 9
Example Using the algorithm we construct the following automaton: M: Rina Zviel-Girshin @ASC 10
Example Convert a given nondeterministic finite automaton to a deterministic finite automaton. B: Rina Zviel-Girshin @ASC 11
Example Using the algorithm we construct the following states: M: Rina Zviel-Girshin @ASC 12
Example M: Rina Zviel-Girshin @ASC 13
Example Some states of this automaton are unreachable from q 0. After elimination of all unreachable states in M the resulting automaton is: Rina Zviel-Girshin @ASC 14
Theorem • 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 Zviel-Girshin @ASC 15
Constructive proof Let EM be NFA with -transitions where EM = (QEM, , EM, q 0 EM, FEM). We will construct an NFA without -transitions ND which is equivalent to EM, where ND= (Q, , , q 0, F). • Q= QEM • = • 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 Zviel-Girshin @ASC 16
Constructive proof • q 0 =q 0 EM • F: – if E(q 0 EM ) F = (the empty word does not belong to L(EM)) then F= FEM – else (the empty word belongs to L(EM)) F= FEM {q 0 EM} Rina Zviel-Girshin @ASC 17
Example • Build a NFA without -transitions which is equivalent to a given NFA with -transitions. 0 1 2 q 0 q 1 q 2 Rina Zviel-Girshin @ASC 18
0 1 2 q 0 q 1 q 2 (q 0, 0)={q 0, q 1, q 2} (q 0, 1)={q 1, q 2} (q 0, 2)={q 2} (q 1, 0)=? (q 2, 0)=? (q 1, 1)={q 1, q 2} (q 2, 1)=? (q 1, 2)={q 2} (q 2, 2)={q 2} 0 1 2 q 0 q 1 0, 1 q 2 1, 2 0, 1, 2 Rina Zviel-Girshin @ASC 19
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 Zviel-Girshin @ASC 20
Example • Build a DFA equivalent to a given NFA. EM: 0 1 2 q 0 q 1 q 2 Rina Zviel-Girshin @ASC 21
Example • The NFA M without -transitions: M: 0 1 2 q 0 q 1 0, 1 q 2 1, 2 0, 1, 2 Rina Zviel-Girshin @ASC 22
Example • A DFA D equivalent to M: 0 q 0, 1, 2 D: 0 q 0 1 1 q 1, 2 1 2 0, 1, 2 0 2 2 q 2 2 Rina Zviel-Girshin @ASC 0, 1 23
Closure of regular languages Theorem: The class of languages accepted by finite automata is closed under: • union • concatenation • Kleene (star) closure. Rina Zviel-Girshin @ASC 24
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 Zviel-Girshin @ASC 25
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 Zviel-Girshin @ASC 26
Union Rina Zviel-Girshin @ASC 27
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 Zviel-Girshin @ASC 28
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 Zviel-Girshin @ASC 29
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 Zviel-Girshin @ASC 30
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 Zviel-Girshin @ASC 31
Concatenation Rina Zviel-Girshin @ASC 32
Concatenation • We construct M that simulates M 1 for a while • Then M "jumps" nondeterministically from a final state of M 1 to the initial state of M 2 • And then M will simulate M 2 for the rest of the input. Rina Zviel-Girshin @ASC 33
Concatenation M = ( Q, , , q 0, F) where • Q=Q 1 Q 2 • • = 1 2 • q 0=q 01 • {for each state f F 1 (f, )=q 02} • F= F 2 Rina Zviel-Girshin @ASC 34
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 Zviel-Girshin @ASC 35
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 Zviel-Girshin @ASC 36
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 . Rina Zviel-Girshin @ASC 37
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 38
Any Questions? Rina Zviel-Girshin @ASC 39
- Slides: 39