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

theory of computer science
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Theory of Computer Science

  • C3. Regular Languages: Regular Expressions

Gabriele R¨

  • ger

University of Basel

March 25, 2020

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 1 / 20

slide-2
SLIDE 2

Theory of Computer Science

March 25, 2020 — C3. Regular Languages: Regular Expressions

C3.1 Regular Expressions C3.2 Summary

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 2 / 20

slide-3
SLIDE 3
  • C3. Regular Languages: Regular Expressions

Regular Expressions

C3.1 Regular Expressions

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 3 / 20

slide-4
SLIDE 4
  • C3. Regular Languages: Regular Expressions

Regular Expressions

Overview

Automata & Formal Languages Languages & Grammars Regular Languages Regular Grammars DFAs NFAs Regular Expressions Pumping Lemma Minimal Automata properties Context-free Languages Context-sensitive & Type-0 Languages

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 4 / 20

slide-5
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 5 / 20

slide-6
SLIDE 6
  • C3. Regular Languages: Regular Expressions

Regular Expressions

Overview

Automata & Formal Languages Languages & Grammars Regular Languages Regular Grammars DFAs NFAs Regular Expressions Pumping Lemma Minimal Automata properties Context-free Languages Context-sensitive & Type-0 Languages

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 6 / 20

slide-7
SLIDE 7
  • C3. Regular Languages: Regular Expressions

Regular Expressions

Concatenation of Languages and Kleene Star

Concatenation ◮ For two languages L1 (over Σ1) and L2 (over Σ2), the concatenation of L1 and L2 is the language L1L2 = {w1w2 ∈ (Σ1 ∪ Σ2)∗ | w1 ∈ L1, w2 ∈ L2}. Kleene star ◮ For language L define

◮ L0 = {ε} ◮ L1 = L ◮ Li+1 = LiL for i ∈ N>0

◮ The definition of Kleene star on L is L∗ =

i≥0 Li.

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 7 / 20

slide-8
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 8 / 20

slide-9
SLIDE 9
  • C3. Regular Languages: Regular Expressions

Regular Expressions

Regular Expressions: Omitting Parentheses

  • mitted 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 9 / 20

slide-10
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 10 / 20

slide-11
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 11 / 20

slide-12
SLIDE 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 = {w1, w2, . . . , wn}, a regular expression describing L can be built from the regular expressions for {wi} by using alternatives. (Use ∅ if L = ∅.)

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 12 / 20

slide-13
SLIDE 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

  • f regular expressions.

For γ = ∅, γ = ε and γ = a, NFAs that accept L(γ) are obvious. . . .

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 13 / 20

slide-14
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 14 / 20

slide-15
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 15 / 20

slide-16
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 16 / 20

slide-17
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 17 / 20

slide-18
SLIDE 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¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 18 / 20

slide-19
SLIDE 19
  • C3. Regular Languages: Regular Expressions

Summary

C3.2 Summary

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 19 / 20

slide-20
SLIDE 20
  • C3. Regular Languages: Regular Expressions

Summary

Summary

◮ Regular expressions are another way to describe languages. ◮ All regular languages can be described by regular expressions, and all regular expressions describe regular languages. ◮ Hence, they are equivalent to finite automata.

Gabriele R¨

  • ger (University of Basel)

Theory of Computer Science March 25, 2020 20 / 20