nfas continued closure properties of regular languages
play

NFAs continued, Closure Properties of Regular Languages Lecture 5 - PowerPoint PPT Presentation

CS/ECE 374: Algorithms & Models of Computation, Fall 2018 NFAs continued, Closure Properties of Regular Languages Lecture 5 September 11, 2018 Chandra Chekuri (UIUC) CS/ECE 374 1 Fall 2018 1 / 31 Regular Languages, DFAs, NFAs


  1. CS/ECE 374: Algorithms & Models of Computation, Fall 2018 NFAs continued, Closure Properties of Regular Languages Lecture 5 September 11, 2018 Chandra Chekuri (UIUC) CS/ECE 374 1 Fall 2018 1 / 31

  2. Regular Languages, DFAs, NFAs Theorem Languages accepted by DFAs, NFAs, and regular expressions are the same. Chandra Chekuri (UIUC) CS/ECE 374 2 Fall 2018 2 / 31

  3. Regular Languages, DFAs, NFAs Theorem Languages accepted by DFAs, NFAs, and regular expressions are the same. DFAs are special cases of NFAs (trivial) NFAs accept regular expressions (we saw already) DFAs accept languages accepted by NFAs (today) Regular expressions for languages accepted by DFAs (later in the course) Chandra Chekuri (UIUC) CS/ECE 374 2 Fall 2018 2 / 31

  4. Part I Equivalence of NFAs and DFAs Chandra Chekuri (UIUC) CS/ECE 374 3 Fall 2018 3 / 31

  5. Equivalence of NFAs and DFAs Theorem For every NFA N there is a DFA M such that L ( M ) = L ( N ) . Chandra Chekuri (UIUC) CS/ECE 374 4 Fall 2018 4 / 31

  6. Formal Tuple Notation for NFA Definition A non-deterministic finite automata (NFA) N = ( Q , Σ , δ, s , A ) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q × Σ ∪ { ǫ } → P ( Q ) is the transition function (here P ( Q ) is the power set of Q ), s ∈ Q is the start state, A ⊆ Q is the set of accepting/final states. δ ( q , a ) for a ∈ Σ ∪ { ǫ } is a susbet of Q — a set of states. Chandra Chekuri (UIUC) CS/ECE 374 5 Fall 2018 5 / 31

  7. Extending the transition function to strings Definition For NFA N = ( Q , Σ , δ, s , A ) and q ∈ Q the ǫ reach ( q ) is the set of all states that q can reach using only ǫ -transitions. Definition Inductive definition of δ ∗ : Q × Σ ∗ → P ( Q ) : if w = ǫ , δ ∗ ( q , w ) = ǫ reach ( q ) if w = a where a ∈ Σ δ ∗ ( q , a ) = ∪ p ∈ ǫ reach ( q ) ( ∪ r ∈ δ ( p , a ) ǫ reach ( r )) if w = xa , δ ∗ ( q , w ) = ∪ p ∈ δ ∗ ( q , x ) ( ∪ r ∈ δ ( p , a ) ǫ reach ( r )) Chandra Chekuri (UIUC) CS/ECE 374 6 Fall 2018 6 / 31

  8. Formal definition of language accepted by N Definition A string w is accepted by NFA N if δ ∗ N ( s , w ) ∩ A � = ∅ . Definition The language L ( N ) accepted by a NFA N = ( Q , Σ , δ, s , A ) is { w ∈ Σ ∗ | δ ∗ ( s , w ) ∩ A � = ∅} . Chandra Chekuri (UIUC) CS/ECE 374 7 Fall 2018 7 / 31

  9. Simulating an NFA by a DFA Think of a program with fixed memory that needs to simulate NFA N on input w . What does it need to store after seeing a prefix x of w ? Chandra Chekuri (UIUC) CS/ECE 374 8 Fall 2018 8 / 31

  10. Simulating an NFA by a DFA Think of a program with fixed memory that needs to simulate NFA N on input w . What does it need to store after seeing a prefix x of w ? It needs to know at least δ ∗ ( s , x ) , the set of states that N could be in after reading x Is it sufficient? Chandra Chekuri (UIUC) CS/ECE 374 8 Fall 2018 8 / 31

  11. Simulating an NFA by a DFA Think of a program with fixed memory that needs to simulate NFA N on input w . What does it need to store after seeing a prefix x of w ? It needs to know at least δ ∗ ( s , x ) , the set of states that N could be in after reading x Is it sufficient? Yes, if it can compute δ ∗ ( s , xa ) after seeing another symbol a in the input. When should the program accept a string w ? Chandra Chekuri (UIUC) CS/ECE 374 8 Fall 2018 8 / 31

  12. Simulating an NFA by a DFA Think of a program with fixed memory that needs to simulate NFA N on input w . What does it need to store after seeing a prefix x of w ? It needs to know at least δ ∗ ( s , x ) , the set of states that N could be in after reading x Is it sufficient? Yes, if it can compute δ ∗ ( s , xa ) after seeing another symbol a in the input. When should the program accept a string w ? If δ ∗ ( s , w ) ∩ A � = ∅ . Key Observation: A DFA M that simulates N should keep in its memory/state the set of states of N Thus the state space of the DFA should be P ( Q ) . Chandra Chekuri (UIUC) CS/ECE 374 8 Fall 2018 8 / 31

  13. Subset Construction NFA N = ( Q , Σ , s , δ, A ) . We create a DFA M = ( Q ′ , Σ , δ ′ , s ′ , A ′ ) as follows: Q ′ = P ( Q ) Chandra Chekuri (UIUC) CS/ECE 374 9 Fall 2018 9 / 31

  14. Subset Construction NFA N = ( Q , Σ , s , δ, A ) . We create a DFA M = ( Q ′ , Σ , δ ′ , s ′ , A ′ ) as follows: Q ′ = P ( Q ) s ′ = ǫ reach ( s ) = δ ∗ ( s , ǫ ) Chandra Chekuri (UIUC) CS/ECE 374 9 Fall 2018 9 / 31

  15. Subset Construction NFA N = ( Q , Σ , s , δ, A ) . We create a DFA M = ( Q ′ , Σ , δ ′ , s ′ , A ′ ) as follows: Q ′ = P ( Q ) s ′ = ǫ reach ( s ) = δ ∗ ( s , ǫ ) A ′ = { X ⊆ Q | X ∩ A � = ∅} Chandra Chekuri (UIUC) CS/ECE 374 9 Fall 2018 9 / 31

  16. Subset Construction NFA N = ( Q , Σ , s , δ, A ) . We create a DFA M = ( Q ′ , Σ , δ ′ , s ′ , A ′ ) as follows: Q ′ = P ( Q ) s ′ = ǫ reach ( s ) = δ ∗ ( s , ǫ ) A ′ = { X ⊆ Q | X ∩ A � = ∅} δ ′ ( X , a ) = ∪ q ∈ X δ ∗ ( q , a ) for each X ⊆ Q , a ∈ Σ . Chandra Chekuri (UIUC) CS/ECE 374 9 Fall 2018 9 / 31

  17. Example No ǫ -transitions 0 , 1 0 , 1 1 q 0 q 1 Chandra Chekuri (UIUC) CS/ECE 374 10 Fall 2018 10 / 31

  18. Example No ǫ -transitions 0 , 1 0 , 1 { q 1 } {} 0 , 1 0 0 , 1 0 , 1 1 { q 0 } { q 0 , q 1 } 1 q 0 q 1 Chandra Chekuri (UIUC) CS/ECE 374 11 Fall 2018 11 / 31

  19. Incremental construction Only build states reachable from s ′ = ǫ reach ( s ) the start state of M 0 , 1 0 , 1 { q 3 } {} 0 , 1 q 1 0 � 0 q 0 q 3 1 { q 0 , q 1 } { q 2 , q 3 } � 1 q 2 δ ′ ( X , a ) = ∪ q ∈ X δ ∗ ( q , a ) Chandra Chekuri (UIUC) CS/ECE 374 12 Fall 2018 12 / 31

  20. Incremental algorithm Build M beginning with start state s ′ == ǫ reach ( s ) For each existing state X ⊆ Q consider each a ∈ Σ and calculate the state Y = δ ′ ( X , a ) = ∪ q ∈ X δ ∗ ( q , a ) and add a transition. If Y is a new state add it to reachable states that need to explored. To compute δ ∗ ( q , a ) - set of all states reached from q on string a Compute X = ǫ reach ( q ) Compute Y = ∪ p ∈ X δ ( p , a ) Compute Z = ǫ reach ( Y ) = ∪ r ∈ Y ǫ reach ( r ) Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2018 13 / 31

  21. Proof of Correctness Theorem Let N = ( Q , Σ , s , δ, A ) be a NFA and let M = ( Q ′ , Σ , δ ′ , s ′ , A ′ ) be a DFA constructed from N via the subset construction. Then L ( N ) = L ( M ) . Chandra Chekuri (UIUC) CS/ECE 374 14 Fall 2018 14 / 31

  22. Proof of Correctness Theorem Let N = ( Q , Σ , s , δ, A ) be a NFA and let M = ( Q ′ , Σ , δ ′ , s ′ , A ′ ) be a DFA constructed from N via the subset construction. Then L ( N ) = L ( M ) . Stronger claim: Lemma For every string w , δ ∗ N ( s , w ) = δ ∗ M ( s ′ , w ) . Proof by induction on | w | . Base case: w = ǫ . δ ∗ N ( s , ǫ ) = ǫ reach ( s ) . M ( s ′ , ǫ ) = s ′ = ǫ reach ( s ) by definition of s ′ . δ ∗ Chandra Chekuri (UIUC) CS/ECE 374 14 Fall 2018 14 / 31

  23. Proof continued Lemma For every string w , δ ∗ N ( s , w ) = δ ∗ M ( s ′ , w ) . Inductive step: w = xa (Note: suffix definition of strings) δ ∗ N ( s , xa ) = ∪ p ∈ δ ∗ N ( s , x ) δ ∗ N ( p , a ) by inductive defn of δ ∗ N Chandra Chekuri (UIUC) CS/ECE 374 15 Fall 2018 15 / 31

  24. Proof continued Lemma For every string w , δ ∗ N ( s , w ) = δ ∗ M ( s ′ , w ) . Inductive step: w = xa (Note: suffix definition of strings) δ ∗ N ( s , xa ) = ∪ p ∈ δ ∗ N ( s , x ) δ ∗ N ( p , a ) by inductive defn of δ ∗ N δ ∗ M ( s ′ , xa ) = δ M ( δ ∗ M ( s , x ) , a ) by inductive defn of δ ∗ M Chandra Chekuri (UIUC) CS/ECE 374 15 Fall 2018 15 / 31

  25. Proof continued Lemma For every string w , δ ∗ N ( s , w ) = δ ∗ M ( s ′ , w ) . Inductive step: w = xa (Note: suffix definition of strings) δ ∗ N ( s , xa ) = ∪ p ∈ δ ∗ N ( s , x ) δ ∗ N ( p , a ) by inductive defn of δ ∗ N δ ∗ M ( s ′ , xa ) = δ M ( δ ∗ M ( s , x ) , a ) by inductive defn of δ ∗ M By inductive hypothesis: Y = δ ∗ N ( s , x ) = δ ∗ M ( s , x ) Chandra Chekuri (UIUC) CS/ECE 374 15 Fall 2018 15 / 31

  26. Proof continued Lemma For every string w , δ ∗ N ( s , w ) = δ ∗ M ( s ′ , w ) . Inductive step: w = xa (Note: suffix definition of strings) δ ∗ N ( s , xa ) = ∪ p ∈ δ ∗ N ( s , x ) δ ∗ N ( p , a ) by inductive defn of δ ∗ N δ ∗ M ( s ′ , xa ) = δ M ( δ ∗ M ( s , x ) , a ) by inductive defn of δ ∗ M By inductive hypothesis: Y = δ ∗ N ( s , x ) = δ ∗ M ( s , x ) Thus δ ∗ N ( s , xa ) = ∪ p ∈ Y δ ∗ N ( p , a ) = δ M ( Y , a ) by definition of δ M . Chandra Chekuri (UIUC) CS/ECE 374 15 Fall 2018 15 / 31

  27. Proof continued Lemma For every string w , δ ∗ N ( s , w ) = δ ∗ M ( s ′ , w ) . Inductive step: w = xa (Note: suffix definition of strings) δ ∗ N ( s , xa ) = ∪ p ∈ δ ∗ N ( s , x ) δ ∗ N ( p , a ) by inductive defn of δ ∗ N δ ∗ M ( s ′ , xa ) = δ M ( δ ∗ M ( s , x ) , a ) by inductive defn of δ ∗ M By inductive hypothesis: Y = δ ∗ N ( s , x ) = δ ∗ M ( s , x ) Thus δ ∗ N ( s , xa ) = ∪ p ∈ Y δ ∗ N ( p , a ) = δ M ( Y , a ) by definition of δ M . Therefore, δ ∗ N ( s , xa ) = δ M ( Y , a ) = δ M ( δ ∗ M ( s , x ) , a ) = δ ∗ M ( s ′ , xa ) which is what we need. Chandra Chekuri (UIUC) CS/ECE 374 15 Fall 2018 15 / 31

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend