theory of computer science
play

Theory of Computer Science C3. Regular Languages: Regular - PowerPoint PPT Presentation

Theory of Computer Science C3. Regular Languages: Regular Expressions Gabriele R oger University of Basel March 25, 2020 Gabriele R oger (University of Basel) Theory of Computer Science March 25, 2020 1 / 20 Theory of Computer Science


  1. Theory of Computer Science C3. Regular Languages: Regular Expressions Gabriele R¨ oger University of Basel March 25, 2020 Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 1 / 20

  2. Theory of Computer Science March 25, 2020 — C3. Regular Languages: Regular Expressions C3.1 Regular Expressions C3.2 Summary Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 2 / 20

  3. C3. Regular Languages: Regular Expressions Regular Expressions C3.1 Regular Expressions Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 3 / 20

  4. C3. Regular Languages: Regular Expressions Regular Expressions 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 Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 4 / 20

  5. C3. Regular Languages: Regular Expressions Regular Expressions Formalisms for Regular Languages ◮ DFAs, NFAs and regular grammars can all describe exactly the regular languages. ◮ Are there other concepts with the same expressiveness? ◮ Yes! � regular expressions Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 5 / 20

  6. C3. Regular Languages: Regular Expressions Regular Expressions 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 Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 6 / 20

  7. C3. Regular Languages: Regular Expressions Regular Expressions Concatenation of Languages and Kleene Star Concatenation ◮ For two languages L 1 (over Σ 1 ) and L 2 (over Σ 2 ), the concatenation of L 1 and L 2 is the language L 1 L 2 = { w 1 w 2 ∈ (Σ 1 ∪ Σ 2 ) ∗ | w 1 ∈ L 1 , w 2 ∈ L 2 } . Kleene star ◮ For language L define ◮ L 0 = { ε } ◮ L 1 = L ◮ L i +1 = L i L for i ∈ N > 0 ◮ The definition of Kleene star on L is L ∗ = � i ≥ 0 L i . Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 7 / 20

  8. C3. Regular Languages: Regular Expressions Regular Expressions Regular Expressions: Definition Definition (Regular Expressions) Regular expressions over an alphabet Σ are defined inductively: ◮ ∅ is a regular expression ◮ ε is a regular expression ◮ If a ∈ Σ, then a is a regular expression If α and β are regular expressions, then so are: ◮ ( αβ ) (concatenation) ◮ ( α | β ) (alternative) ◮ ( α ∗ ) (Kleene closure) German: regul¨ are Ausdr¨ ucke, Verkettung, Alternative, kleenesche H¨ ulle Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 8 / 20

  9. C3. Regular Languages: Regular Expressions Regular Expressions Regular Expressions: Omitting Parentheses omitted parentheses by convention: ◮ Kleene closure α ∗ binds more strongly than concatenation αβ . ◮ Concatenation binds more strongly than alternative α | β . ◮ Parentheses for nested concatenations/alternatives are omitted (we can treat them as left-associative; it does not matter). Example: ab ∗ c | ε | abab ∗ abbreviates (((( a ( b ∗ )) c ) | ε ) | ((( ab ) a )( b ∗ ))). Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 9 / 20

  10. C3. Regular Languages: Regular Expressions Regular Expressions Regular Expressions: Examples some regular expressions for Σ = { 0 , 1 } : ◮ 0 ∗ 10 ∗ ◮ ( 0 | 1 ) ∗ 1 ( 0 | 1 ) ∗ ◮ (( 0 | 1 )( 0 | 1 )) ∗ ◮ 01 | 10 ◮ 0 ( 0 | 1 ) ∗ 0 | 1 ( 0 | 1 ) ∗ 1 | 0 | 1 Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 10 / 20

  11. C3. Regular Languages: Regular Expressions Regular Expressions Regular Expressions: Language Definition (Language Described by a Regular Expression) The language described by a regular expression γ , written L ( γ ), is inductively defined as follows: ◮ If γ = ∅ , then L ( γ ) = ∅ . ◮ If γ = ε , then L ( γ ) = { ε } . ◮ If γ = a with a ∈ Σ, then L ( γ ) = { a } . ◮ If γ = ( αβ ), where α and β are regular expressions, then L ( γ ) = L ( α ) L ( β ). ◮ If γ = ( α | β ), where α and β are regular expressions, then L ( γ ) = L ( α ) ∪ L ( β ). ◮ If γ = ( α ∗ ) where α is a regular expression, then L ( γ ) = L ( α ) ∗ . Examples: blackboard Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 11 / 20

  12. C3. Regular Languages: Regular Expressions Regular Expressions Finite Languages Can Be Described By Regular Expressions Theorem Every finite language can be described by a regular expression. Proof. For every word w ∈ Σ ∗ , a regular expression describing the language { w } can be built from regular expressions a ∈ Σ by using concatenations. (Use ε if w = ε .) For every finite language L = { w 1 , w 2 , . . . , w n } , a regular expression describing L can be built from the regular expressions for { w i } by using alternatives. (Use ∅ if L = ∅ .) Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 12 / 20

  13. C3. Regular Languages: Regular Expressions Regular Expressions Regular Expressions Not More Powerful Than NFAs Theorem For every language that can be described by a regular expression, there is an NFA that accepts it. Proof. Let γ be a regular expression. We show the statement by induction over the structure of regular expressions. For γ = ∅ , γ = ε and γ = a , NFAs that accept L ( γ ) are obvious. . . . Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 13 / 20

  14. C3. Regular Languages: Regular Expressions Regular Expressions Regular Expressions Not More Powerful Than NFAs Theorem For every language that can be described by a regular expression, there is an NFA that accepts it. Proof (continued). For γ = ( αβ ), let M α and M β be NFAs that (by ind. hypothesis) accept L ( α ) and L ( β ). W.l.o.g., their states are disjoint. Construct NFA M for L ( γ ) by “daisy-chaining” M α and M β : ◮ states: union of states of M α and M β ◮ start states: those of M α ; if ε ∈ L ( α ), also those of M β ◮ end states: end states of M β ◮ state transitions: all transitions of M α and of M β ; additionally: for every transition to an end state of M α , an equally labeled transition to all start states of M β . . . Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 14 / 20

  15. C3. Regular Languages: Regular Expressions Regular Expressions Regular Expressions Not More Powerful Than NFAs Theorem For every language that can be described by a regular expression, there is an NFA that accepts it. Proof (continued). For γ = ( α | β ), by the induction hypothesis let M α = � Q α , Σ , δ α , S α , E α � and M β = � Q β , Σ , δ β , S β , E β � be NFAs that accept L ( α ) and L ( β ). W.l.o.g., Q α ∩ Q β = ∅ . Then the “union automaton” M = � Q α ∪ Q β , Σ , δ α ∪ δ β , S α ∪ S β , E α ∪ E β � accepts the language L ( γ ). . . . German: Vereinigungsautomat Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 15 / 20

  16. C3. Regular Languages: Regular Expressions Regular Expressions Regular Expressions Not More Powerful Than NFAs Theorem For every language that can be described by a regular expression, there is an NFA that accepts it. Proof (continued). For γ = ( α ∗ ), by the induction hypothesis let M α = � Q α , Σ , δ α , S α , E α � be an NFA that accepts L ( α ). If ε / ∈ L ( α ), add an additional state to M α that is a start and end state and not connected to other states. M α now recognizes L ( α ) ∪ { ε } . M is constructed from M α by adding the following new transitions: whenever M α has a transition from s to end state s ′ with symbol a , add transitions from s to every start state with symbol a . Then L ( M ) = L ( γ ). Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 16 / 20

  17. C3. Regular Languages: Regular Expressions Regular Expressions DFAs Not More Powerful Than Regular Expressions Theorem Every language accepted by a DFA can be described by a regular expression. Without proof. Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 17 / 20

  18. C3. Regular Languages: Regular Expressions Regular Expressions Regular Languages vs. Regular Expressions Theorem (Kleene) The set of languages that can be described by regular expressions is exactly the set of regular languages. This follows directly from the previous two theorems. Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 18 / 20

  19. C3. Regular Languages: Regular Expressions Summary C3.2 Summary Gabriele R¨ oger (University of Basel) Theory of Computer Science March 25, 2020 19 / 20

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