theory of computation
play

Theory of Computation Course note based on Computability, Complexity, - PowerPoint PPT Presentation

Regular Languages (9) Theory of Computation Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker. course note


  1. Regular Languages (9) Theory of Computation Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker. course note prepared by Tyng–Ruey Chuang Institute of Information Science, Academia Sinica Department of Information Management, National Taiwan University Week 11, Spring 2008 1 / 27

  2. Regular Languages (9) About This Course Note ◮ It is prepared for the course Theory of Computation taught at the National Taiwan University in Spring 2008. ◮ It follows very closely the book Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, by Martin Davis, Ron Sigal, and Elaine J. Weyuker. Morgan Kaufmann Publishers. ISBN: 0-12-206382-1. ◮ It is available from Tyng-Ruey Chuang’s web site: http://www.iis.sinica.edu.tw/~trc/ and released under a Creative Commons “Attribution-ShareAlike 2.5 Taiwan” license: http://creativecommons.org/licenses/by-sa/2.5/tw/ 2 / 27

  3. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) Closure properties ◮ To show that the class of regular languages is closed under a large number of operations. ◮ To use deterministic or nondeterministic finite automata whenever necessary, as the two classes of automata are equivalent in expressiveness (Theorem 2.1). 3 / 27

  4. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) Nonrestarting dfa Definition. A dfa is called nonrestarting if there is no pair q , s for which δ ( q , s ) = q 1 where q 1 is the initial state. Theorem 4.1. There is an algorithm that will transform a given ˜ ˜ dfa M into a nonrestarting dfa M such that L ( M ) = L ( M ). 4 / 27

  5. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) Constructing a nonrestarting dfa from a dfa Proof of Theorem 4.1. From a dfa M , we can construct an ˜ equivalent nonrestarting dfa M by adding a new “returning initial” state q n +1 , and by redefining the transition function accordingly. 5 / 27

  6. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) Constructing a nonrestarting dfa from a dfa Proof of Theorem 4.1. From a dfa M , we can construct an ˜ equivalent nonrestarting dfa M by adding a new “returning initial” state q n +1 , and by redefining the transition function accordingly. ˜ That is, for M , we define ◮ the set of states ˜ Q = Q ∪ { q n +1 } ◮ the transition function ˜ δ by � δ ( q , s ) if q ∈ Q and δ ( q , s ) � = q 1 ˜ δ ( q , s ) = q n +1 if q ∈ Q and δ ( q , s ) = q 1 ˜ ˜ δ ( q n +1 , s ) = δ ( q 1 , s ) � F if q 1 �∈ F ◮ the set of final states ˜ F = F ∪ { q n +1 } if q 1 ∈ F 5 / 27

  7. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) Constructing a nonrestarting dfa from a dfa Proof of Theorem 4.1. From a dfa M , we can construct an ˜ equivalent nonrestarting dfa M by adding a new “returning initial” state q n +1 , and by redefining the transition function accordingly. ˜ That is, for M , we define ◮ the set of states ˜ Q = Q ∪ { q n +1 } ◮ the transition function ˜ δ by � δ ( q , s ) if q ∈ Q and δ ( q , s ) � = q 1 ˜ δ ( q , s ) = q n +1 if q ∈ Q and δ ( q , s ) = q 1 ˜ ˜ δ ( q n +1 , s ) = δ ( q 1 , s ) � F if q 1 �∈ F ◮ the set of final states ˜ F = F ∪ { q n +1 } if q 1 ∈ F ˜ ˜ To see that L ( M ) = L ( M ) we observe that M follows the same ˜ transitions as M except whenever M reenters q 1 , M enters q n +1 . � 5 / 27

  8. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) L ∪ ˜ L Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L . 6 / 27

  9. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) L ∪ ˜ L Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L . M be nonrestarting dfas that accept L and ˜ ˜ Proof. Let M and L ˜ respectively. M and M are distinct but use the same alphabet. ˇ ˜ We now construct a ndfa M by “merging” M and M but with a new initial state ˇ q 1 . 6 / 27

  10. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) L ∪ ˜ L Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L . M be nonrestarting dfas that accept L and ˜ ˜ Proof. Let M and L ˜ respectively. M and M are distinct but use the same alphabet. ˇ ˜ We now construct a ndfa M by “merging” M and M but with a ˇ new initial state ˇ q 1 . That is, we define M by ◮ the set of states ˇ Q = Q ∪ ˜ Q ∪ { ˇ q 1 } − { q 1 , ˜ q 1 } ◮ the transition function ˇ δ by � { δ ( q , s ) } if q ∈ Q − { q 1 } ˇ δ ( q , s ) = { ˜ q ∈ ˜ δ ( q , s ) } Q − { ˜ q 1 } if ˇ { δ ( q 1 , s ) } ∪ { ˜ δ (ˇ q 1 , s ) = δ (˜ q 1 , s ) } ◮ the set of final states � F ∪ ˜ q 1 ∈ ˜ F ∪ { ˇ q 1 } − { q 1 , ˜ q 1 } if q 1 ∈ F or ˜ F ˇ F = F ∪ ˜ F otherwise 6 / 27

  11. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) L ∪ ˜ L Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L . M be nonrestarting dfas that accept L and ˜ ˜ Proof. Let M and L ˜ respectively. M and M are distinct but use the same alphabet. ˇ ˜ We now construct a ndfa M by “merging” M and M but with a ˇ new initial state ˇ q 1 . That is, we define M by ◮ the set of states ˇ Q = Q ∪ ˜ Q ∪ { ˇ q 1 } − { q 1 , ˜ q 1 } ◮ the transition function ˇ δ by � { δ ( q , s ) } if q ∈ Q − { q 1 } ˇ δ ( q , s ) = { ˜ q ∈ ˜ δ ( q , s ) } Q − { ˜ q 1 } if ˇ { δ ( q 1 , s ) } ∪ { ˜ δ (ˇ q 1 , s ) = δ (˜ q 1 , s ) } ◮ the set of final states � F ∪ ˜ q 1 ∈ ˜ F ∪ { ˇ q 1 } − { q 1 , ˜ q 1 } if q 1 ∈ F or ˜ F ˇ F = F ∪ ˜ F otherwise ˇ Note that once a first transition has been selected, M is locked ˜ M ) = L ∪ ˜ ˇ into either M or M . Hence L ( L . � 6 / 27

  12. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) A ∗ − L Theorem 4.3. Let L ⊆ A ∗ be a regular language. Then A ∗ − L is regular. 7 / 27

  13. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) A ∗ − L Theorem 4.3. Let L ⊆ A ∗ be a regular language. Then A ∗ − L is regular. ¯ Proof. Let M be a dfa that accept L . Let dfa M be exactly like M except that it accepts precisely when M rejects. That is, the M ) = A ∗ − L . ¯ ¯ set of accepting states of M is Q − F . Then L ( � 7 / 27

  14. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) L 1 ∩ L 2 Theorem 4.4. If L 1 and L 2 are regular languages, then so is L 1 ∩ L 2 . 8 / 27

  15. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) L 1 ∩ L 2 Theorem 4.4. If L 1 and L 2 are regular languages, then so is L 1 ∩ L 2 . Proof. Let L 1 , L 2 ⊆ A ∗ . Then, by the De Morgan identity, we have L 1 ∩ L 2 = A ∗ − (( A ∗ − L 1 ) ∪ ( A ∗ − L 2 )) Theorem 4.2 and 4.3 then give the result. � 8 / 27

  16. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) ∅ and { 0 } Theorem 4.5. ∅ and { 0 } are regular languages. 9 / 27

  17. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) ∅ and { 0 } Theorem 4.5. ∅ and { 0 } are regular languages. Proof. ∅ is clearly the language accepted by any automaton whose set of accepting states is empty. 9 / 27

  18. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) ∅ and { 0 } Theorem 4.5. ∅ and { 0 } are regular languages. Proof. ∅ is clearly the language accepted by any automaton whose set of accepting states is empty. For { 0 } , we can construct a two-state dfa such that F = { q 1 } and δ ( q 1 , a ) = δ ( q 2 , a ) = q 2 for every symbol a ∈ A , the alphabet. Clearly this dfa accepts { 0 } . � 9 / 27

  19. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) Every finite subset of A ∗ is regular Theorem 4.5. Let u ∈ A ∗ . Then { u } is a regular language. 10 / 27

  20. Closure Properties (9.4) Regular Languages (9) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6) Every finite subset of A ∗ is regular Theorem 4.5. Let u ∈ A ∗ . Then { u } is a regular language. Proof. Theorem 4.4 proves the case for u = 0. For the other case, let u = a 1 a 2 . . . a l where l ≥ 1 , a 1 , a 2 , . . . a l ∈ A . We now construct a ( l + 1)–state ndfa M with initial state q 1 , accepting state q l +1 , and the transition function δ given by δ ( q i , a i ) = { q i +1 } , i = 1 , . . . , l δ ( q i , a ) = ∅ for a ∈ A − { a i } , i = 1 , . . . , l Clearly L ( M ) = { u } . � 10 / 27

Recommend


More recommend