bu cs 332 theory of computation
play

BU CS 332 Theory of Computation Lecture 5: Reading: More on - PowerPoint PPT Presentation

BU CS 332 Theory of Computation Lecture 5: Reading: More on pumping Sipser Ch 1.3 Regular expressions Regular expressions = regular languages Mark Bun February 5, 2020 More on Pumping 2/5/2020 CS332 Theory of Computation 2


  1. BU CS 332 – Theory of Computation Lecture 5: Reading: • More on pumping Sipser Ch 1.3 • Regular expressions • Regular expressions = regular languages Mark Bun February 5, 2020

  2. More on Pumping 2/5/2020 CS332 ‐ Theory of Computation 2

  3. Pumping Lemma (Formal) 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/5/2020 CS332 ‐ Theory of Computation 3

  4. General Strategy for proving is not regular Proof by contradiction: assume is regular. Then there is a pumping length . 1. Find with 2. Show that cannot be pumped 3. Conclude must not have been regular 2/5/2020 CS332 ‐ Theory of Computation 4

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

  6. Reusing a Proof Pumping a language can be lots of work… Let’s try to reuse that work! How might we show that has an equal # of s and s = is not regular? 0 𝑜 1 𝑜 𝑜 � 0 � = 𝐶𝐵𝑀𝐵𝑂𝐷𝐹𝐸 ∩ 𝑥 all 0 s in 𝑥 appear before all 1 s � 2/5/2020 CS332 ‐ Theory of Computation 6

  7. Using Closure Properties If is not regular, we can show a related language is not regular ∩ = (not regular) (regular) , R , * any of , , or, for one language, By contradiction: If is regular, then is regular. But is not regular so neither is ! 2/5/2020 CS332 ‐ Theory of Computation 7

  8. Example � � Prove is not regular � � using nonregular language and regular language all s in appear before all s 2/5/2020 CS332 ‐ Theory of Computation 8

  9. Regular Expressions 2/5/2020 CS332 ‐ Theory of Computation 9

  10. Regular Expressions • A different way of describing regular languages • A regular expression expresses a (possibly complex) language by combining simple languages using the regular operations “Simple” languages: for some Regular operations: Union: Concatenation: ∗ Star: � … � | and � � 2/5/2020 CS332 ‐ Theory of Computation 10

  11. 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/5/2020 CS332 ‐ Theory of Computation 11

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

  13. Simplifying Notation • Omit symbol: • Omit many parentheses, since union and concatenation are associative: = = • Order of operations: Evaluate star, then concatenation, then union ∗ ∗ 2/5/2020 CS332 ‐ Theory of Computation 13

  14. Examples Let 1. contains exactly one 2. has length at least 3 and its third symbol is 3. every odd position of is 2/5/2020 CS332 ‐ Theory of Computation 14

  15. Syntactic Sugar • For alphabet , the regex represents � ∗ • For regex , the regex Not captured by regular expressions: Backreferences 2/5/2020 CS332 ‐ Theory of Computation 15

  16. Equivalence of Regular Expressions, NFAs, and DFAs 2/5/2020 CS332 ‐ Theory of Computation 16

  17. 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/5/2020 CS332 ‐ Theory of Computation 17

  18. Regular expression ‐ > NFA Theorem 1: Every regex has an equivalent NFA Proof: Induction on size of a regex Base cases: 2/5/2020 CS332 ‐ Theory of Computation 18

  19. Regular expression ‐ > NFA Theorem 1: Every regex has an equivalent NFA Proof: Induction on size of a regex Inductive step: � � � � ∗ � 2/5/2020 CS332 ‐ Theory of Computation 19

  20. Example ∗ to an NFA Convert 2/5/2020 CS332 ‐ Theory of Computation 20

  21. Example 2/5/2020 CS332 ‐ Theory of Computation 21

Recommend


More recommend