bu cs 332 theory of computation
play

BU CS 332 Theory of Computation Lecture 6: Reading: NFAs > - PowerPoint PPT Presentation

BU CS 332 Theory of Computation Lecture 6: Reading: NFAs > Regular expressions Sipser Ch 1.3, Context free grammars 2.1, 2.3 Pumping lemma for CFLs Mark Bun February 10, 2020 Regular Expressions Syntax A regular


  1. BU CS 332 – Theory of Computation Lecture 6: Reading: • NFAs ‐ > Regular expressions Sipser Ch 1.3, • Context ‐ free grammars 2.1, 2.3 • Pumping lemma for CFLs Mark Bun February 10, 2020

  2. Regular Expressions – Syntax A regular expression is defined recursively using the following rules: 1. , , and are regular expressions for every 2. If � and � are regular expressions, then so are ∗ � , � , and � � � Examples: (over ) ∗ ∗ ∗ ∗ 2/10/2020 CS332 ‐ Theory of Computation 2

  3. Regular Expressions – Semantics the language a regular expression describes 1. 2. 3. for every � � � � � � � � ∗ ∗ 6. � � ∗ ∗ � � Example: 2/10/2020 CS332 ‐ Theory of Computation 3

  4. Regular Expressions Describe Regular Languages Theorem: A language is regular if and only if it is described by a regular expression Theorem 1: Every regular expression has an equivalent NFA Theorem 2: Every NFA has an equivalent regular expression 2/10/2020 CS332 ‐ Theory of Computation 4

  5. NFA ‐ > Regular expression Theorem 2: Every NFA has an equivalent regex Proof idea: Simplify NFA by “ripping out” states one at a time and replacing with regexes 01*0 0 0 1 2/10/2020 CS332 ‐ Theory of Computation 5

  6. Generalized NFAs • Every transition is labeled by a regex • One start state with only outgoing transitions • Only one accept state with only incoming transitions • Start state and accept state are distinct ∗ 𝑡 𝑏 2/10/2020 CS332 ‐ Theory of Computation 6

  7. Generalized NFA Example ∗ 𝑡 𝑏 𝑡 𝑏 2/10/2020 CS332 ‐ Theory of Computation 7

  8. NFA ‐ > Regular expression 𝑙 � 2 states NFA GNFA 𝑙 states 𝑙 � 1 states GNFA … 2 states GNFA Regex 2/10/2020 CS332 ‐ Theory of Computation 8

  9. NFA ‐ > GNFA ε ε ε NFA ε • Add a new start state with no incoming arrows. • Make a unique accept state with no outgoing arrows. 2/10/2020 CS332 ‐ Theory of Computation 9

  10. GNFA ‐ > Regular expression Idea: While the machine has more than 2 states, rip one out and relabel the arrows with regexes to account for the missing state ∗ 1 2 3 3 1 2/10/2020 CS332 ‐ Theory of Computation 10

  11. GNFA ‐ > Regular expression Idea: While the machine has more than 2 states, rip one out and relabel the arrows with regexes to account for the missing state ∗ 1 2 3 3 1 2/10/2020 CS332 ‐ Theory of Computation 11

  12. GNFA ‐ > Regular expression Idea: While the machine has more than 2 states, rip one out and relabel the arrows with regexes to account for the missing state ∗ 1 2 3 3 1 2/10/2020 CS332 ‐ Theory of Computation 12

  13. GNFA ‐ > Regular expression Idea: While the machine has more than 2 states, rip one out and relabel the arrows with regexes to account for the missing state 2 1 3 1 2 3 4 3 1 2/10/2020 CS332 ‐ Theory of Computation 13

  14. Example 2/10/2020 CS332 ‐ Theory of Computation 14

  15. 2/10/2020 CS332 ‐ Theory of Computation 15

  16. 2/10/2020 CS332 ‐ Theory of Computation 16

  17. Context ‐ Free Grammars 2/10/2020 CS332 ‐ Theory of Computation 17

  18. Some History An abstract model for two distinct problems Rules for parsing natural languages 2/10/2020 CS332 ‐ Theory of Computation 18

  19. Some History An abstract model for two distinct problems Specification of syntax and compilation for programming languages 1977 ACM Turing Award citation (John Backus) For profound, influential, and lasting contributions to the design of practical high ‐ level programming systems, notably through his work on FORTRAN, and for seminal publication of formal procedures for the specification of programming languages. 2/10/2020 CS332 ‐ Theory of Computation 19

  20. Context ‐ Free Grammar (Informal) Example Grammar Derivation 2/10/2020 CS332 ‐ Theory of Computation 20

  21. Context ‐ Free Grammar (Informal) Example Grammar 𝐻 𝐹 → 𝐹 � 𝑈 𝐹 → 𝑈 𝑈 → 𝑈 � 𝐺 𝑈 → 𝐺 𝐺 → �𝐹� 𝐺 → 𝑏 𝐺 → 𝑐 Derivation 𝑀�𝐻� � 2/10/2020 CS332 ‐ Theory of Computation 21

  22. Socially Awkward Professor Grammar <PHRASE> → <FILLER><PHRASE> <PHRASE> → <START><END> <FILLER> → LIKE <FILLER> → UMM <START> → YOU KNOW <START> → ε <END> → WHOOPS <END> → SORRY <END> → $#@! 2/10/2020 CS332 ‐ Theory of Computation 22

  23. Socially Awkward Professor Grammar <PHRASE> → <FILLER><PHRASE> | <START><END> <FILLER> → LIKE | UMM <START> → YOU KNOW | ε <END> → WHOOPS | SORRY | $#@! 2/10/2020 CS332 ‐ Theory of Computation 23

  24. Context ‐ Free Grammar (Formal) A CFG is a 4 ‐ tuple • is a finite set of variables • is a finite set of terminal symbols (disjoint from ) • is a finite set of production rules of the form , ∗ where and • is the start symbol Example: where 2/10/2020 CS332 ‐ Theory of Computation 24

  25. Context ‐ Free Grammar (Formal) A CFG is a 4 ‐ tuple = variables = terminals = rules = start • We say (“ yields ”) if is a rule of the grammar ∗ • We say (“ derives ”) if or there exists a ⇒ sequence such that � � ∗ ∗ • Language of the grammar: ⇒ Example: where � � 2/10/2020 CS332 ‐ Theory of Computation 25

  26. CFG Examples Give context ‐ free grammars for the following languages 1. The empty language 2. Strings of properly nested parentheses 3. Strings with equal # of ’s and ’s 2/10/2020 CS332 ‐ Theory of Computation 26

  27. Pumping Lemma II: Pump Harder 2/10/2020 CS332 ‐ Theory of Computation 27

  28. Non context ‐ free languages? • Could it be the case that every language is context ‐ free? 2/10/2020 CS332 ‐ Theory of Computation 28

  29. Pumping Lemma for regular languages Let be a regular language. Then there exists a “pumping length” such that For every where , can be split into three parts where: 1. 2. 𝑗  3. for all 2/10/2020 CS332 ‐ Theory of Computation 29

  30. Pumping Lemma for context ‐ free languages Let be a context ‐ free language. Then there exists a “pumping length” such that For every where , can be split into five parts where: Example: ∗ � 1. 2. 𝑗  𝑗 3. for all 2/10/2020 CS332 ‐ Theory of Computation 30

  31. Pumping Lemma for context ‐ free languages Let be a context ‐ free language. Then there exists a “pumping length” such that For every where , can be split into five parts where: Example: ∗ � 1. 2. 𝑗  𝑗 3. for all 2/10/2020 CS332 ‐ Theory of Computation 31

  32. Pumping Lemma as a game 1. YOU pick the language 𝑀 to be proved non context ‐ free. 2. ADVERSARY picks a possible pumping length 𝑞 . 3. YOU pick 𝑥 of length at least 𝑞 . 4. ADVERSARY divides 𝑥 into 𝑣 , 𝑤 , 𝑦 , 𝑧 , 𝑨 , obeying rules of the Pumping Lemma: | 𝑤𝑧 | � 0 and | 𝑤𝑦𝑧 | � 𝑞 . 5. YOU win by finding 𝑗 � 0 , for which 𝑣𝑤 𝑗 𝑦𝑧 𝑗 𝑨 is not in 𝑀 . If regardless of how the ADVERSARY plays this game, you can always win, then is non context ‐ free 2/10/2020 CS332 ‐ Theory of Computation 32

  33. Pumping Lemma example � � � Claim: is not regular Proof: Assume is regular with pumping length 1. Find with 2. Show that cannot be pumped If = with | | , then… 2/10/2020 CS332 ‐ Theory of Computation 33

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