theory of computer science
play

Theory of Computer Science C2. Regular Languages: Finite Automata - PowerPoint PPT Presentation

Theory of Computer Science C2. Regular Languages: Finite Automata Gabriele R oger University of Basel March 23, 2020 Regular Grammars DFAs NFAs Summary Regular Grammars Regular Grammars DFAs NFAs Summary Overview Regular Languages


  1. Theory of Computer Science C2. Regular Languages: Finite Automata Gabriele R¨ oger University of Basel March 23, 2020

  2. Regular Grammars DFAs NFAs Summary Regular Grammars

  3. Regular Grammars DFAs NFAs Summary Overview Regular Languages Grammars & Grammars DFAs Regular NFAs Languages Automata & Regular Formal Languages Expressions Context-free Pumping Languages Lemma Minimal Automata Context-sensitive & Type-0 Languages Properties

  4. Regular Grammars DFAs NFAs Summary Repetition: Regular Grammars Definition (Regular Grammars) A regular grammar is a 4-tuple � Σ , V , P , S � with 1 Σ finite alphabet of terminals 2 V finite set of variables (with V ∩ Σ = ∅ ) 3 P ⊆ ( V × (Σ ∪ Σ V )) ∪ {� S , ε �} finite set of rules 4 if S → ε ∈ P , there is no X ∈ V , y ∈ Σ with X → yS ∈ P 5 S ∈ V start variable.

  5. Regular Grammars DFAs NFAs Summary Repetition: Regular Grammars Definition (Regular Grammars) A regular grammar is a 4-tuple � Σ , V , P , S � with 1 Σ finite alphabet of terminals 2 V finite set of variables (with V ∩ Σ = ∅ ) 3 P ⊆ ( V × (Σ ∪ Σ V )) ∪ {� S , ε �} finite set of rules 4 if S → ε ∈ P , there is no X ∈ V , y ∈ Σ with X → yS ∈ P 5 S ∈ V start variable. Rule X → ε is only allowed if X = S and S never occurs in the right-hand side of a rule.

  6. Regular Grammars DFAs NFAs Summary Repetition: Regular Grammars Definition (Regular Grammars) A regular grammar is a 4-tuple � Σ , V , P , S � with 1 Σ finite alphabet of terminals 2 V finite set of variables (with V ∩ Σ = ∅ ) 3 P ⊆ ( V × (Σ ∪ Σ V )) ∪ {� S , ε �} finite set of rules 4 if S → ε ∈ P , there is no X ∈ V , y ∈ Σ with X → yS ∈ P 5 S ∈ V start variable. Rule X → ε is only allowed if X = S and S never occurs in the right-hand side of a rule. How restrictive is this?

  7. Regular Grammars DFAs NFAs Summary Start Variable in Right-Hand Side of Rules For every type-0 language L there is a grammar where the start variable does not occur on the right-hand side of any rule. Theorem For every grammar G = � Σ , V , P , S � there is a grammar G ′ = � Σ , V ′ , P ′ , S � with rules P ′ ⊆ ( V ′ ∪ Σ) + × ( V ′ \ { S } ∪ Σ) ∗ such that L ( G ) = L ( G ′ ) .

  8. Regular Grammars DFAs NFAs Summary Start Variable in Right-Hand Side of Rules: Proof Proof. Let G = � Σ , V , P , S � be a grammar and S ′ �∈ V be a new variable. Construct rule set P ′ from P as follows: for every rule r ∈ P , add a rule r ′ to P ′ , where r ′ is the result of replacing all occurences of S in r with S ′ . for every rule S → w ∈ P , add a rule S → w ′ to P ′ , where w ′ is the result of replacing all occurences of S in w with S ′ . Then L ( G ) = L ( � Σ , V ∪ { S ′ } , P ′ , S � ).

  9. Regular Grammars DFAs NFAs Summary Start Variable in Right-Hand Side of Rules: Proof Proof. Let G = � Σ , V , P , S � be a grammar and S ′ �∈ V be a new variable. Construct rule set P ′ from P as follows: for every rule r ∈ P , add a rule r ′ to P ′ , where r ′ is the result of replacing all occurences of S in r with S ′ . for every rule S → w ∈ P , add a rule S → w ′ to P ′ , where w ′ is the result of replacing all occurences of S in w with S ′ . Then L ( G ) = L ( � Σ , V ∪ { S ′ } , P ′ , S � ). Note that the rules in P ′ are not fundamentally different from the rules in P . In particular: If P ⊆ V × (Σ ∪ Σ V ∪ { ε } ) then P ′ ⊆ V ′ × (Σ ∪ Σ V ′ ∪ { ε } ). If P ⊆ V × ( V ∪ Σ) ∗ then P ′ ⊆ V ′ × ( V ′ ∪ Σ) ∗ .

  10. Regular Grammars DFAs NFAs Summary Start Variable in Right-Hand Side of Rules: Example

  11. Regular Grammars DFAs NFAs Summary Epsilon Rules Theorem For every grammar G with rules P ⊆ V × (Σ ∪ Σ V ∪ { ε } ) there is a regular grammar G ′ with L ( G ) = L ( G ′ ) . Proof. Let G = � Σ , V , P , S � be a grammar s.t. P ⊆ V × (Σ ∪ Σ V ∪ { ε } ). Use the previous proof to construct grammar G ′ = � Σ , V ′ , P ′ , S � s.t. P ′ ⊆ V ′ × (Σ ∪ Σ( V ′ \ { S } ) ∪ { ε } ). Let V ε = { A | A → ε ∈ P ′ } . Let P ′′ be the rule set that is created from P ′ by removing all rules of the form A → ε ( A � = S ). Additionally, for every rule of the form B → xA with A ∈ V ε , B ∈ V ′ , x ∈ Σ we add a rule B → x to P ′′ . Then G ′′ = � Σ , V ′ , P ′′ , S � is regular and L ( G ) = L ( G ′′ ).

  12. Regular Grammars DFAs NFAs Summary Epsilon Rules: Example

  13. Regular Grammars DFAs NFAs Summary Questions Questions?

  14. Regular Grammars DFAs NFAs Summary DFAs

  15. Regular Grammars DFAs NFAs Summary Overview Regular Languages Grammars & Grammars DFAs Regular NFAs Languages Automata & Regular Formal Languages Expressions Context-free Pumping Languages Lemma Minimal Automata Context-sensitive & Type-0 Languages Properties

  16. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0

  17. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 ,

  18. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 ,

  19. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 ,

  20. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 ,

  21. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 , q 0 ,

  22. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 , q 0 ,

  23. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 , q 0 , q 0 ,

  24. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 , q 0 , q 0 ,

  25. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 , q 0 , q 0 , q 1 ,

  26. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 , q 0 , q 0 , q 1 ,

  27. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q 1 q 0 q 2 1 0 0 When reading the input 01100 the automaton visits the states q 0 , q 1 , q 0 , q 0 , q 1 , q 2 .

  28. Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q 1 q 0 q 2 1 0 0 0 states Q = { q 0 , q 1 , q 2 } input alphabet Σ = { 0 , 1 } transition function δ start state q 0 end states { q 2 }

  29. Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q 1 q 0 q 2 1 0 0 0 states Q = { q 0 , q 1 , q 2 } input alphabet Σ = { 0 , 1 } transition function δ start state q 0 end states { q 2 }

  30. Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q 1 q 0 q 2 1 0 0 0 states Q = { q 0 , q 1 , q 2 } input alphabet Σ = { 0 , 1 } transition function δ start state q 0 end states { q 2 }

  31. Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q 1 q 0 q 2 1 0 0 0 states Q = { q 0 , q 1 , q 2 } δ ( q 0 , 0 ) = q 1 input alphabet Σ = { 0 , 1 } δ ( q 0 , 1 ) = q 0 transition function δ δ ( q 1 , 0 ) = q 2 start state q 0 δ ( q 1 , 1 ) = q 0 end states { q 2 } δ ( q 2 , 0 ) = q 2 δ ( q 2 , 1 ) = q 0

  32. Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q 1 q 0 q 2 1 0 0 0 δ 0 1 states Q = { q 0 , q 1 , q 2 } δ ( q 0 , 0 ) = q 1 q 0 q 1 q 0 input alphabet Σ = { 0 , 1 } δ ( q 0 , 1 ) = q 0 q 1 q 2 q 0 transition function δ δ ( q 1 , 0 ) = q 2 q 2 q 2 q 0 start state q 0 δ ( q 1 , 1 ) = q 0 table form of δ end states { q 2 } δ ( q 2 , 0 ) = q 2 δ ( q 2 , 1 ) = q 0

  33. Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q 1 q 0 q 2 1 0 0 0 δ 0 1 states Q = { q 0 , q 1 , q 2 } δ ( q 0 , 0 ) = q 1 q 0 q 1 q 0 input alphabet Σ = { 0 , 1 } δ ( q 0 , 1 ) = q 0 q 1 q 2 q 0 transition function δ δ ( q 1 , 0 ) = q 2 q 2 q 2 q 0 start state q 0 δ ( q 1 , 1 ) = q 0 table form of δ end states { q 2 } δ ( q 2 , 0 ) = q 2 δ ( q 2 , 1 ) = q 0

  34. Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q 1 q 0 q 2 1 0 0 0 δ 0 1 states Q = { q 0 , q 1 , q 2 } δ ( q 0 , 0 ) = q 1 q 0 q 1 q 0 input alphabet Σ = { 0 , 1 } δ ( q 0 , 1 ) = q 0 q 1 q 2 q 0 transition function δ δ ( q 1 , 0 ) = q 2 q 2 q 2 q 0 start state q 0 δ ( q 1 , 1 ) = q 0 table form of δ end states { q 2 } δ ( q 2 , 0 ) = q 2 δ ( q 2 , 1 ) = q 0

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