Theory of Computation Course note based on Computability, Complexity, - - PowerPoint PPT Presentation

theory of computation
SMART_READER_LITE
LIVE PREVIEW

Theory of Computation Course note based on Computability, Complexity, - - PowerPoint PPT Presentation

Regular Languages (9) Theory of Computation Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker. course note


slide-1
SLIDE 1

Regular Languages (9)

Theory of Computation

Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science, 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker.

course note prepared by Tyng–Ruey Chuang

Institute of Information Science, Academia Sinica Department of Information Management, National Taiwan University

Week 11, Spring 2008

1 / 27

slide-2
SLIDE 2

Regular Languages (9)

About This Course Note

◮ It is prepared for the course Theory of Computation taught at

the National Taiwan University in Spring 2008.

◮ It follows very closely the book Computability, Complexity,

and Languages: Fundamentals of Theoretical Computer Science, 2nd edition, by Martin Davis, Ron Sigal, and Elaine

  • J. Weyuker. Morgan Kaufmann Publishers. ISBN:

0-12-206382-1.

◮ It is available from Tyng-Ruey Chuang’s web site:

http://www.iis.sinica.edu.tw/~trc/ and released under a Creative Commons “Attribution-ShareAlike 2.5 Taiwan” license: http://creativecommons.org/licenses/by-sa/2.5/tw/

2 / 27

slide-3
SLIDE 3

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Closure properties

◮ To show that the class of regular languages is closed under a

large number of operations.

◮ To use deterministic or nondeterministic finite automata

whenever necessary, as the two classes of automata are equivalent in expressiveness (Theorem 2.1).

3 / 27

slide-4
SLIDE 4

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Nonrestarting dfa

  • Definition. A dfa is called nonrestarting if there is no pair q, s for

which δ(q, s) = q1 where q1 is the initial state. Theorem 4.1. There is an algorithm that will transform a given dfa M into a nonrestarting dfa ˜ M such that L( ˜ M ) = L(M ).

4 / 27

slide-5
SLIDE 5

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Constructing a nonrestarting dfa from a dfa

Proof of Theorem 4.1. From a dfa M , we can construct an equivalent nonrestarting dfa ˜ M by adding a new “returning initial” state qn+1, and by redefining the transition function accordingly.

5 / 27

slide-6
SLIDE 6

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Constructing a nonrestarting dfa from a dfa

Proof of Theorem 4.1. From a dfa M , we can construct an equivalent nonrestarting dfa ˜ M by adding a new “returning initial” state qn+1, and by redefining the transition function accordingly. That is, for ˜ M , we define

◮ the set of states ˜

Q = Q ∪ {qn+1}

◮ the transition function ˜

δ by ˜ δ(q, s) = δ(q, s) if q ∈ Q and δ(q, s) = q1 qn+1 if q ∈ Q and δ(q, s) = q1 ˜ δ(qn+1, s) = ˜ δ(q1, s)

◮ the set of final states ˜

F = F if q1 ∈ F F ∪ {qn+1} if q1 ∈ F

5 / 27

slide-7
SLIDE 7

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Constructing a nonrestarting dfa from a dfa

Proof of Theorem 4.1. From a dfa M , we can construct an equivalent nonrestarting dfa ˜ M by adding a new “returning initial” state qn+1, and by redefining the transition function accordingly. That is, for ˜ M , we define

◮ the set of states ˜

Q = Q ∪ {qn+1}

◮ the transition function ˜

δ by ˜ δ(q, s) = δ(q, s) if q ∈ Q and δ(q, s) = q1 qn+1 if q ∈ Q and δ(q, s) = q1 ˜ δ(qn+1, s) = ˜ δ(q1, s)

◮ the set of final states ˜

F = F if q1 ∈ F F ∪ {qn+1} if q1 ∈ F To see that L(M ) = L( ˜ M ) we observe that ˜ M follows the same transitions as M except whenever M reenters q1, ˜ M enters qn+1.

  • 5 / 27
slide-8
SLIDE 8

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L ∪ ˜ L

Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L.

6 / 27

slide-9
SLIDE 9

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L ∪ ˜ L

Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L.

  • Proof. Let M and

˜ M be nonrestarting dfas that accept L and ˜ L

  • respectively. M and

˜ M are distinct but use the same alphabet. We now construct a ndfa ˇ M by “merging” M and ˜ M but with a new initial state ˇ q1.

6 / 27

slide-10
SLIDE 10

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L ∪ ˜ L

Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L.

  • Proof. Let M and

˜ M be nonrestarting dfas that accept L and ˜ L

  • respectively. M and

˜ M are distinct but use the same alphabet. We now construct a ndfa ˇ M by “merging” M and ˜ M but with a new initial state ˇ

  • q1. That is, we define

ˇ M by

◮ the set of states ˇ

Q = Q ∪ ˜ Q ∪ {ˇ q1} − {q1, ˜ q1}

◮ the transition function ˇ

δ by ˇ δ(q, s) = {δ(q, s)} if q ∈ Q − {q1} {˜ δ(q, s)} if q ∈ ˜ Q − {˜ q1} ˇ δ(ˇ q1, s) = {δ(q1, s)} ∪ {˜ δ(˜ q1, s)}

◮ the set of final states

ˇ F = F ∪ ˜ F ∪ {ˇ q1} − {q1, ˜ q1} if q1 ∈ F or ˜ q1 ∈ ˜ F F ∪ ˜ F

  • therwise

6 / 27

slide-11
SLIDE 11

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L ∪ ˜ L

Theorem 4.2. If L and ˜ L are regular languages, then so is L ∪ ˜ L.

  • Proof. Let M and

˜ M be nonrestarting dfas that accept L and ˜ L

  • respectively. M and

˜ M are distinct but use the same alphabet. We now construct a ndfa ˇ M by “merging” M and ˜ M but with a new initial state ˇ

  • q1. That is, we define

ˇ M by

◮ the set of states ˇ

Q = Q ∪ ˜ Q ∪ {ˇ q1} − {q1, ˜ q1}

◮ the transition function ˇ

δ by ˇ δ(q, s) = {δ(q, s)} if q ∈ Q − {q1} {˜ δ(q, s)} if q ∈ ˜ Q − {˜ q1} ˇ δ(ˇ q1, s) = {δ(q1, s)} ∪ {˜ δ(˜ q1, s)}

◮ the set of final states

ˇ F = F ∪ ˜ F ∪ {ˇ q1} − {q1, ˜ q1} if q1 ∈ F or ˜ q1 ∈ ˜ F F ∪ ˜ F

  • therwise

Note that once a first transition has been selected, ˇ M is locked into either M or ˜ M . Hence L( ˇ M ) = L ∪ ˜ L.

  • 6 / 27
slide-12
SLIDE 12

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

A∗ − L

Theorem 4.3. Let L ⊆ A∗ be a regular language. Then A∗ − L is regular.

7 / 27

slide-13
SLIDE 13

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

A∗ − L

Theorem 4.3. Let L ⊆ A∗ be a regular language. Then A∗ − L is regular.

  • Proof. Let M be a dfa that accept L. Let dfa

¯ M be exactly like M except that it accepts precisely when M rejects. That is, the set of accepting states of ¯ M is Q − F. Then L( ¯ M ) = A∗ − L.

  • 7 / 27
slide-14
SLIDE 14

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L1 ∩ L2

Theorem 4.4. If L1 and L2 are regular languages, then so is L1 ∩ L2.

8 / 27

slide-15
SLIDE 15

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L1 ∩ L2

Theorem 4.4. If L1 and L2 are regular languages, then so is L1 ∩ L2.

  • Proof. Let L1, L2 ⊆ A∗. Then, by the De Morgan identity, we have

L1 ∩ L2 = A∗ − ((A∗ − L1) ∪ (A∗ − L2)) Theorem 4.2 and 4.3 then give the result.

  • 8 / 27
slide-16
SLIDE 16

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

∅ and {0}

Theorem 4.5. ∅ and {0} are regular languages.

9 / 27

slide-17
SLIDE 17

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

∅ and {0}

Theorem 4.5. ∅ and {0} are regular languages.

  • Proof. ∅ is clearly the language accepted by any automaton whose

set of accepting states is empty.

9 / 27

slide-18
SLIDE 18

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

∅ and {0}

Theorem 4.5. ∅ and {0} are regular languages.

  • Proof. ∅ is clearly the language accepted by any automaton whose

set of accepting states is empty. For {0}, we can construct a two-state dfa such that F = {q1} and δ(q1, a) = δ(q2, a) = q2 for every symbol a ∈ A, the alphabet. Clearly this dfa accepts {0}.

  • 9 / 27
slide-19
SLIDE 19

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Every finite subset of A∗ is regular

Theorem 4.5. Let u ∈ A∗. Then {u} is a regular language.

10 / 27

slide-20
SLIDE 20

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Every finite subset of A∗ is regular

Theorem 4.5. Let u ∈ A∗. Then {u} is a regular language.

  • Proof. Theorem 4.4 proves the case for u = 0. For the other case,

let u = a1a2 . . . al where l ≥ 1, a1, a2, . . . al ∈ A. We now construct a (l + 1)–state ndfa M with initial state q1, accepting state ql+1, and the transition function δ given by δ(qi, ai) = {qi+1}, i = 1, . . . , l δ(qi, a) = ∅ for a ∈ A − {ai}, i = 1, . . . , l Clearly L(M ) = {u}.

  • 10 / 27
slide-21
SLIDE 21

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Every finite subset of A∗ is regular

Theorem 4.5. Let u ∈ A∗. Then {u} is a regular language.

  • Proof. Theorem 4.4 proves the case for u = 0. For the other case,

let u = a1a2 . . . al where l ≥ 1, a1, a2, . . . al ∈ A. We now construct a (l + 1)–state ndfa M with initial state q1, accepting state ql+1, and the transition function δ given by δ(qi, ai) = {qi+1}, i = 1, . . . , l δ(qi, a) = ∅ for a ∈ A − {ai}, i = 1, . . . , l Clearly L(M ) = {u}.

  • Corollary 4.7. Every finite subset of A∗ is regular.
  • 10 / 27
slide-22
SLIDE 22

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Characterizations of Regular Languages

We now show that the class of regular languages can be characterized as the class of all languages obtained from finite languages using the operations ∪, ·, ∗ a finite number of times. We will see that there are other characterizations of regular languages as well.

11 / 27

slide-23
SLIDE 23

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Definitions of L1 · L2 and L∗

  • Definition. Let L1, L2 ⊆ A∗. Then we write

L1 · L2 = L1L2 = {uv | u ∈ L1 and v ∈ L2}. .

  • Definition. Let L ⊆ A∗. Then we write

L∗ = {u1u2 . . . un | n ≥ 0, u1, u2, . . . , un ∈ L}. . Note that, for L∗,

◮ 0 ∈ L∗ ◮ The notation of A∗ is consistent with the definition of L∗.

12 / 27

slide-24
SLIDE 24

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L · ˜ L

Theorem 5.1. If L, ˜ L are regular languages, then L · ˜ L is regular.

13 / 27

slide-25
SLIDE 25

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L · ˜ L

Theorem 5.1. If L, ˜ L are regular languages, then L · ˜ L is regular.

  • Proof. Let M and

˜ M be dfas that accept L and ˜ L respectively. The two are distinct but use the same alphabet. We now construct a ndfa ˙ M by “gluing together” the two dfas.

13 / 27

slide-26
SLIDE 26

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L · ˜ L

Theorem 5.1. If L, ˜ L are regular languages, then L · ˜ L is regular.

  • Proof. Let M and

˜ M be dfas that accept L and ˜ L respectively. The two are distinct but use the same alphabet. We now construct a ndfa ˙ M by “gluing together” the two dfas. We define

◮ the set of states ˙

Q = Q ∪ ˜ Q

◮ the transition function ˙

δ by ˙ δ(q, s) =    {δ(q, s)} if q ∈ Q − F {δ(q, s)} ∪ {˜ δ(˜ q1, s)} if q ∈ F {˜ δ(q, s)} if q ∈ ˜ Q

◮ the set of final states

˙ F = F ∪ ˜ F if 0 ∈ ˜ L ˜ F if 0 ∈ ˜ L

13 / 27

slide-27
SLIDE 27

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L · ˜ L

Theorem 5.1. If L, ˜ L are regular languages, then L · ˜ L is regular.

  • Proof. Let M and

˜ M be dfas that accept L and ˜ L respectively. The two are distinct but use the same alphabet. We now construct a ndfa ˙ M by “gluing together” the two dfas. We define

◮ the set of states ˙

Q = Q ∪ ˜ Q

◮ the transition function ˙

δ by ˙ δ(q, s) =    {δ(q, s)} if q ∈ Q − F {δ(q, s)} ∪ {˜ δ(˜ q1, s)} if q ∈ F {˜ δ(q, s)} if q ∈ ˜ Q

◮ the set of final states

˙ F = F ∪ ˜ F if 0 ∈ ˜ L ˜ F if 0 ∈ ˜ L Clearly, L · ˜ L = L( ˙ M ), so that L · ˜ L is regular. .

13 / 27

slide-28
SLIDE 28

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L∗

Theorem 5.2. If L is a regular languages, then so is L∗.

14 / 27

slide-29
SLIDE 29

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L∗

Theorem 5.2. If L is a regular languages, then so is L∗.

  • Proof. Let M be a nonrestarting dfa that accept L. We now

construct a “looping” ndfa ˜ M with the same states and initial state as M , and accepting state q1. The transition function ˜ δ is defined as follows: ˜ δ(q, s) = {δ(q, s)} if δ(q, s) ∈ F {δ(q, s)} ∪ {q1} if δ(q, s) ∈ F

14 / 27

slide-30
SLIDE 30

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

L∗

Theorem 5.2. If L is a regular languages, then so is L∗.

  • Proof. Let M be a nonrestarting dfa that accept L. We now

construct a “looping” ndfa ˜ M with the same states and initial state as M , and accepting state q1. The transition function ˜ δ is defined as follows: ˜ δ(q, s) = {δ(q, s)} if δ(q, s) ∈ F {δ(q, s)} ∪ {q1} if δ(q, s) ∈ F That is, whenever M would enter an accepting state, ˜ M will enter either the corresponding accepting state or the initial state. Clearly, L∗ = L( ˜ M ), so that L∗ is a regular language. .

14 / 27

slide-31
SLIDE 31

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Kleene’s Theorem

Theorem 5.3. A language is regular if and only if it can be

  • btained from finite languages by applying the three operators

∪, ·, ∗ a finite number of times.

15 / 27

slide-32
SLIDE 32

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Kleene’s Theorem

Theorem 5.3. A language is regular if and only if it can be

  • btained from finite languages by applying the three operators

∪, ·, ∗ a finite number of times.

  • Proof. (⇐

=) Every finite language is regular. The three operators build regular languages from regular languages. Therefore, by induction on the number of applications of ∪, ·, ∗, any language

  • btained from finite languages by applying these operators a finite

number of times is regular.

15 / 27

slide-33
SLIDE 33

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Kleene’s Theorem

Theorem 5.3. A language is regular if and only if it can be

  • btained from finite languages by applying the three operators

∪, ·, ∗ a finite number of times.

  • Proof. (⇐

=) Every finite language is regular. The three operators build regular languages from regular languages. Therefore, by induction on the number of applications of ∪, ·, ∗, any language

  • btained from finite languages by applying these operators a finite

number of times is regular. (= ⇒) Let L = L(M ) where M is a dfa with states q1, . . . , qn. As usual, q1 is the initial state, F the set of accepting states, δ the transition function, and A = {s1, . . . , sm} the alphabet.

15 / 27

slide-34
SLIDE 34

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Kleene’s Theorem

Theorem 5.3. A language is regular if and only if it can be

  • btained from finite languages by applying the three operators

∪, ·, ∗ a finite number of times.

  • Proof. (⇐

=) Every finite language is regular. The three operators build regular languages from regular languages. Therefore, by induction on the number of applications of ∪, ·, ∗, any language

  • btained from finite languages by applying these operators a finite

number of times is regular. (= ⇒) Let L = L(M ) where M is a dfa with states q1, . . . , qn. As usual, q1 is the initial state, F the set of accepting states, δ the transition function, and A = {s1, . . . , sm} the alphabet. We define the sets Rk

i,j, for all i, j > 0, k ≥ 0, as follows:

Rk

i,j = {x ∈ A∗

| δ∗(qi, x) = qj and, as it moves across x, M passes through no state ql with l > k}

15 / 27

slide-35
SLIDE 35

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Kleene’s Theorem, Continued

Proof (continued). We observe that R0

i,i

= {0} R0

i,j

= {a ∈ A | δ(qi, a) = qj}, for i = j Now, to process any string of length > 1, M will pass through some intermediate state ql, l ≥ 1. We can write Rk+1

i,j

= Rk

i,j ∪ (Rk i,k+1 · (Rk k+1,k+1)∗ · Rk k+1,j)

In addition, Rk

i,j is regular for for all i, j, k. This is proved by an

induction on k. For k = 0, R0

i,j is finite hence regular. Assuming

the result known for k, (⇐ =) yields the result for k + 1. Finally, we note that L(M ) =

  • qj∈F

Rn

1,j

and we conclude the proof.

  • 16 / 27
slide-36
SLIDE 36

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Regular Expressions

For an alphabet A = { s1, s2, . . . , sk }, we define the corresponding alphabet A = { s1, s2, . . . sk, 0, ∅, ∪, ·, ∗, (, ) }. The class of regular expressions on A is then defined to be the subset of A∗ determined by the following:

  • 1. ∅, 0, s1, s2, . . . sk are regular expressions.
  • 2. If α and β are regular expressions, then so is (α ∪ β).
  • 3. If α and β are regular expressions, then so is (α · β).
  • 4. If α is a regular expression, then so is α∗.
  • 5. No expression is regular unless it can be generated using a

finite number of applications of 1–4.

17 / 27

slide-37
SLIDE 37

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Semantics of Regular Expressions

For each regular expression γ, we define a corresponding regular language γ by recursion according to the following rules: si = {si} = {0} ∅ = ∅ (α ∪ β) = α ∪ β (α · β) = α · β α∗ = α∗ When γ = L, we say that the regular expression γ represents L.

18 / 27

slide-38
SLIDE 38

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Regular Expressions, Examples

(a · (b∗ ∪ c∗)) = {ab[n] | n ≥ 0} ∪ {ac[m] | m ≥ 0} (0 ∪ (a · b)∗) = {(ab)[n] | n ≥ 0} ((c∗ · b∗)) = {c[m]b[n] | m, n ≥ 0}

19 / 27

slide-39
SLIDE 39

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Finite Subsets of A∗

Theorem 5.4. For every finite subset L of A∗, there is a regular expressions γ on A such that γ = L.

20 / 27

slide-40
SLIDE 40

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Finite Subsets of A∗

Theorem 5.4. For every finite subset L of A∗, there is a regular expressions γ on A such that γ = L.

  • Proof. We need only to consider the following:

◮ If L = ∅, then L = ∅. ◮ If L = 0, then L = 0. ◮ If L = {x}, where x = si1si2 . . . sil, then

L = (si1 · (si2 · (si3 . . . sil) . . .)).

◮ If L has more than one elements. Assuming the result is

known for languages of k elements, let L have k + 1 elements. Then we can write L = L1 ∪ {x}, where x ∈ A∗ and L1 contains k elements. By induction hypothesis, there is a regular expression α such that α = L1. By the above, there is regular expression β such that β = {x}. Then we have (α ∪ β) = L1 ∪ {x} = L 20 / 27

slide-41
SLIDE 41

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Kleene’s Theorem — Second Version

Theorem 5.5. A language L ⊆ A∗ is regular if and only if there is a regular expression γ on A such that γ = L.

21 / 27

slide-42
SLIDE 42

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Kleene’s Theorem — Second Version

Theorem 5.5. A language L ⊆ A∗ is regular if and only if there is a regular expression γ on A such that γ = L.

  • Proof. (⇐

=) For any regular expression γ, the regular language γ is built up from finite languages by applying ∪, ·, ∗ a finite number of times, so γ is regular by the Kleene’s theorem.

21 / 27

slide-43
SLIDE 43

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Kleene’s Theorem — Second Version

Theorem 5.5. A language L ⊆ A∗ is regular if and only if there is a regular expression γ on A such that γ = L.

  • Proof. (⇐

=) For any regular expression γ, the regular language γ is built up from finite languages by applying ∪, ·, ∗ a finite number of times, so γ is regular by the Kleene’s theorem. (= ⇒) If a regular language L is finite, then by Theorem 5.4, there is a regular expression γ such that γ = L. Otherwise, by Kleene’s theorem, L can be obtained from certain finite languages by a finite of applications of ∪, ·, ∗. Starting with regular expressions representing these finite languages, we then build up a regular expression representing L by simply indicating each use of the operations ∪, ·, ∗ by writing ∪, ·,

∗, respectively, and punctuating with ( and ).

  • 21 / 27
slide-44
SLIDE 44

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Pigeon-Hole Principle

Pigeon-Hole Principle. If n + 1 objects are distributed among n sets, then at least one of the sets must contain at least two

  • bjects.
  • 22 / 27
slide-45
SLIDE 45

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Pumping Lemma

Theorem 6.1. Let L = L(M ), where M is a dfa with n states. Let x ∈ L, where |x| ≥ n. Then we can write x = uvw, where v = 0 and uv[i]w ∈ L for all i = 0, 1, 2, 3, . . ..

  • Proof. Since x has at least n symbols, M must go through at least

n state transitions. Including the initial state, this requires M to visit at least n + 1 states. We conclude that M must visit at least

  • ne state q more than once. Then we can write x = uvw, where

δ∗(q1, u) = q, δ∗(q, v) = q, δ∗(q, w) ∈ F. However, the loop starting and ending at q can be repeated any number of times and M still reachs the accepting states. It is clear that δ∗(q1, uv[i]w) = δ∗(q1, uvw) ∈ F. Hence uv[i]w ∈ L. 23 / 27

slide-46
SLIDE 46

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Applications of The Pumping Lemma, I

Theorem 6.2. Let M be a dfa with n states. Then, if L(M ) = ∅, there is a string x ∈ L(M ) such that |x| < n.

  • Proof. Let x be a string in L(M ) of the shortest possible length.

Suppose |x| ≥ n. By the pumping lemma, x = uvw, where v = 0 and uw ∈ L(M ). Since |uw| < |x|, this is a contradiction. Thus |x| < n.

  • 24 / 27
slide-47
SLIDE 47

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Applications of The Pumping Lemma, I

Theorem 6.2. Let M be a dfa with n states. Then, if L(M ) = ∅, there is a string x ∈ L(M ) such that |x| < n.

  • Proof. Let x be a string in L(M ) of the shortest possible length.

Suppose |x| ≥ n. By the pumping lemma, x = uvw, where v = 0 and uw ∈ L(M ). Since |uw| < |x|, this is a contradiction. Thus |x| < n.

  • This theorem shows how to test a given dfa M to see whether the

language it accepts is empty! We need only “run” M on all strings

  • f length less than the number of states of M . If none is accepted,

we then conclude L(M ) = ∅.

24 / 27

slide-48
SLIDE 48

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Applications of The Pumping Lemma, II

Theorem 6.4. Let M be a dfa with n states. Then, L(M ) is infinite if and only if L(M ) contains a string x such that n ≤ |x| < 2n.

  • Proof. (=

⇒) Let L(M ) be infinite. Then L(M ) must contain strings of length ≥ 2n. Let x ∈ L(M ), where x has the shortest possible length ≥ 2n. We write x = x1x2, where |x1| = n and |x2| ≥ n. By using the pigeon-hole principle, we can write x1 = uvw, where δ∗(q1, u) = q, δ∗(q, v) = q, with 1 ≤ |v| ≤ n, δ∗(q, wx2) ∈ F. Thus uwx2 ∈ L(M ), and |x| > |uwx2| ≥ |x2| ≥ n. Since x is a shortest string of L(M ) with length at least 2n, we conclude n ≤ |uwx2| < 2n.

25 / 27

slide-49
SLIDE 49

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Applications of The Pumping Lemma, II, Continued

Proof (Theorem 6.4). (⇐ =) Let x ∈ L(M ) with n ≤ |x| < 2n. By the pumping lemma, we can write x = uvw, where v = 0 and uv[i]w ∈ L(M ) for all i. This shows that L(M ) is infinite.

  • Theorem 6.4 shows how to test a given dfa M to see whether the

language it accepts is finite! We need only run M on all strings x such that n ≤ |x| < 2n, where M has n states. L(M ) is infinite just in case M accepts at least one of these strings.

26 / 27

slide-50
SLIDE 50

Regular Languages (9) Closure Properties (9.4) Kleene’s Theorem (9.5) The Pumping Lemma and Its Application (9.6)

Applications of The Pumping Lemma, III

The pumping lemma also provides us a technique for showing that given languages are not regular. For example, L = {a[n]b[n] | n > 0} is not regular. Suppose it is, then L = L(M ), where M is a dfa and has m states. We will derive a contradiction by showing that there is a word x ∈ L, with |x| > m, such that there is no way of writing x = uvw, with v = 0, so that {uv[i]w | i ≥ 0} ⊆ L. Let x = a[m]b[m]. If we write x = uvw, with v = 0, then either v = a[l1], or v = a[l1]b[l2], or v = b[l2], with l1, l2 ≤ m. However, in each case, uvvw ∈ L, contradicting the pumping lemma, so there can be no such dfa M . We just show that L is not regular.

27 / 27