1 / 19

Chapter 3 Properties of Finite Automata and Regular Expressions

Chapter 3 Properties of Finite Automata and Regular Expressions. 3.1 Minimization of Finite Automata.

paiva
Télécharger la présentation

Chapter 3 Properties of Finite Automata and Regular Expressions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3 Properties of Finite Automata and Regular Expressions 3.1 Minimization of Finite Automata For a given regular language L, it is possible to construct infinitely many finite state automata to accept L. The reason is that based on a given DFA M 1, there would be a loop in the transition diagram. So we can construct a new DFA M 2 to have more states and L(M 1) = L(M 2) = L. And from DFA M 2 , we can construct a DFA M 3 with even more states and L(M 3) = L. Consider example 1, given a DFA M 1, we can construct a DFA M 2 to have more states and L(M 1) = L(M 2)= L.

  2. 0 0 0 0 0 q 0 q 0 0 1 1 1 1 1 q t 1 M 1 q 1 q 3 M 2 0 1 0 1 0 0, 1 q 2 q h q g q f Example 1: The following two DFA’s M 1 and M 2 are equivalent. Both machines accept the set {0 n|n>0} over the alphabet ={0, 1}. The states q 1, q 2, and q 3 of the machine M 2 are equivalent, we can combine these 3 states into one state as q t in the machine M 1. The states q g and q h of the machine M 2 are equivalent, we can combine these 2 states into one state as q f in the machine M 1.

  3. For a given regular language L, it is possible to find a DFA M with minimum number of states such that L(M)=L. Usually, we first find a DFA M accepting L. Then find equivalent states of M and reduce the number of states in M to get a new DFA with minimum number of states. Definition 1: Two states p and q of a DFA M are equivalent, if for all strings  in * both the states (p, ) and (q, ) are in F or both are not in F. Two states p and q are distinguishable, if they are not equivalent. Lemma 1: If states p 1 and q 1 of a DFA M are distinguishable, and there is a symbol a in  such that p2= (p1, a) and q2=(q2, a). Then p 2 and q 2are distinguishable.

  4. Using lemma 1, we can easily design an algorithm to find all equivalent states in a DFA and convert to a DFA with minimum number of states. Here we may get into a problem that whether or not all the DFAs with minimum number of states accepting the same set are unique up to graph isomorphic. We shall solve the problem later in this section. For a given DFA M=(Q, , , q 0, F), where Q={q 0, q 1, …, q n-1 }, let D[i, j]= 0 denote the states q i and q j are distinguishable, and D[i, j]= 1 denote the states q i and q j are equivalent. Let the constants distinguishable = 0 and equivalent = 1.

  5. Algorithm : Step 1: do D[i, j] equivalent, for 1 i, j  n Step 2: for q iF and q j F, do D[i, j]  D[j, i] distinguishable Step 3: continue  false for i  j and D[i, j] = distinguishable do for a   do If qk = (qi, a) and ql=(qj, a), and D[k, l] = equivalent, then D[k, l] = D[l, k]  distinguishable continue  true Step 4: if continue = true then goto step 3

  6. 0 0 0 0 0 q 0 q 0 D[i, j] q 0 0 1 1 1 1 1 q 1 0 q t 1 q 1 q 3 q 2 0 1 0 1 0 1 0 0, 1 q 2 q 3 0 1 1 q g 0 0 0 0 q h 0 0 0 0 1 q h q g q f q 0 q 1 q 2 q 3 q g Example 2: Consider the following DFA M. q 1, q 2, and q 3 are equivalent q g and q h are equivalent

  7. Program : for(i=0; i<n; i++) for(j=0; j<n; j++) D[i][j]=1; for(i=0; i<n; i++) for(j=0; j<n; j++) if(inF(i)&& !inF(j)) { D[i][j]=0; D[j][i]=0;} continue = TRUE; while(continue) { continue = FALSE; for(i=0; i<n; i++) for(j=0; j<n; j++)for(a=0; a<=1; a++) if((i != j) && D[i][j]==0){k= delta(i,a); l= delta(j,a); if(D[k][l]==1) { D[k][l]=0; D[l][k]=0; continue = TRUE;}}}

  8. How do we know that all the DFA’s with minimum number of states accepting the same set are unique up to graph isomorphic? We shall prove the Myhill-Nerode theorem to show that there is a unique DFA with minimal states. The proof of the Myhill-Nerode theorem is based on the equivalence relation RL. The set of equivalence classes of RL forms the set of the states of the DFA with minimum number of states. We shall define 2 equivalence relations RL and RM in order to prove the Myhill-Nerode theorem.

  9. Definition 2: Let L be a language over an alphabet , define a relation RL by that for strings x and y in *, x RL y, if for all strings z in *, we have that both xz and yz are in L or both are not in L. The relation RL is an equivalent relation, since for x, y and z in *, we have (1) x RL x, (2) x RL y implies y RL x, and (3) x RL y and y RL z implies x RL z.

  10. Example 3: Let L be a language over an alphabet  = {0, 1}, L={ 0 n | n > 0}. Find the equivalence classes of RL. Solution : The equivalence classes of RL are : [0] = { 0n | n > 0 }, [] = {}, [1] = * \ {0n | n  0 }. There are 3 equivalence classes of RL.

  11. 02 RL 03 , since (1) If z = 0k , for some k 0, then 02 z, 03 z  L. (2) If z contains at least one 1, then 02 z, 03 z  L. Therefore, [0]={0n | n > 0 }

  12. Example 4: Let L be a language over an alphabet  = {0, 1}, L={ 0 n 1 n | n  0 }. Find the equivalence classes of RL. Solution : The equivalence classes of RL are : [0n] = { 0n 0 m 1 m | m  0 }, n = 1, 2, …, [01] = { 0 m 1 m | m > 0 } = L \{}, [] = {}, [1] = * \  n > 0{0n 0 m 1 m | m  0 } \ L. There are infinitely many equivalence classes of RL.

  13. 02RL 031 1RL 041 2 RL 051 3 …, since (1) If z = 1 2 , then 02 z = 02 1 2 ,031 1z = 031 3 , 041 2 z = 041 4 ,051 3 z =051 5 …  L. (2) If z  1 2 , then 02 z,031 1z, 041 2 z,051 3 z …  L. Therefore, [02]={02 0m1 m | m  0 }

  14. Definition 3: Let M be a DFA, define a relation R M by that for strings x and y in *, x R M y, if (q 0, x) = (q 0, y). The relation R M is an equivalent relation, since for x, y and z in *, we have (1) x R M x, (2) x R M y implies y R M x, and (3) x R M y and y R M z implies x R M z.

  15. 0 0 0 q 0 q 1 1 1 1 q t 0, 1 q f Example 5: Given a DFA M as follows, Find the equivalence classes of R M. Solution : The equivalence classes of RM are : [q 0] = {}, [q 1] = {0}, [q f] = {0n | n > 1 }, [q t] = * \ {0n | n > 0 }.

  16. Lemma 2: Let L be a regular language and L = L(M) for some DFA M = (Q, , , q 0, F). Then for a given equivalence class [q] of R M , there is an equivalence class [] of R L such that [q]  []. And each equivalence class [] of the relation R L is a finite union of equivalence classes of R M. Proof : If [q], where [q] is an equivalence classes of RM, and [] is an equivalence class of RL. If x[q], then (q 0, x) = q = (q 0, ). For any string y  *, we have that (q 0, xy) =(q 0, y)= (q, y) = p. If p  F, then xy, y L. Otherwise xy, y L Therefore, x R L. So, we have that x [] and [q]  [].

  17. Suppose that [] is an equivalence class of RL. It is obvious that if (q 0, ) F, then x [] (q 0, x) F. And if (q 0, )  F, then x [] (q 0, x)  F. The set S={(q 0, x) | x [] } is finite. And we have that either SF= or S  F. Therefore, the equivalence class [] of R L is a finite union of the equivalence classes [q] of R M, where q  S={(q 0, x) | x [] }. Now, we can say that the number of equivalence classes of R L is less than or equal to that of R M. And the equivalence classes of R M is a refinement of the equivalence classes of R L .

  18. Theorem 1(The Myhill-Nerode Theorem): Let L be a regular language. Then there is a DFA M = (Q, , , q 0, F), where Q = {[] | [] is an equivalence class of R L}, q 0 = [], F = {[] | [] is an equivalence class of R L and []  L}, and ([], a)=[a] for a   such that L(M)=L and the number of the states is minimum among all DFAs accepting L. And we have that the minimal DFA is unique up to graph isomorphic. Proof : By lemma 2, we have that the number of equivalence classes of R L is finite. Let Q be the set of equivalence classes of R L. Let F, q 0 and  be defined as those in the theorem. We have that  L iff  L(M), since (q 0 , )=([], )=[ ] =[]  F.

  19. 0 0 [] [0] 1 1 M [1] 0, 1 Example 6: Let L be a language over an alphabet  = {0, 1}, L={ 0 n | n > 0}. Find a DFA M such that L(M)=L. Solution : The equivalence classes of RL are : [0] = { 0n | n > 0 }, [] = {}, [1] = * \ {0n | n  0 }. By theorem 1, we have that the DFA M is as follows.

More Related