Top Banner
2/14/14 Costas Busch - RPI 1 Regular Languages, Regular Expressions, and Pumping Lemma
97

Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

Jul 09, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 1

Regular Languages, Regular Expressions, and Pumping Lemma

Page 2: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 2

Non Turing-Acceptable

Turing-Acceptable

decidable

Context-sensitive

Context-free

Regular

The Chomsky Hierarchy

Page 3: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 3

Standard Representations of Regular Languages

Regular Languages

DFAs

NFAs Regular Expressions

Page 4: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 4

When we say: We are given a Regular Language

We mean:

L

Language is in a standard representation

L

(DFA, NFA, or Regular Expression)

Page 5: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 5

1L 2L

21LLConcatenation:

*1LStar:

21 LL ∪Union:

Are regular Languages

For regular languages and we will prove that:

1L

21 LL ∩

Complement:

Intersection:

RL1Reversal:

Page 6: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 6

We say: Regular languages are closed under

21LLConcatenation:

*1LStar:

21 LL ∪Union:

1L

21 LL ∩

Complement:

Intersection:

RL1Reversal:

Page 7: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 7

1LRegular language

( ) 11 LML =

1M

Single accepting state

NFA 2M

2L

Single accepting state

( ) 22 LML =

Regular language

NFA

Take two languages

Page 8: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 8

}{1 baL n=a

b

1M

{ }baL =2ab2M

0≥n

Example

Page 9: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 9

Union NFA for

1M

2M

21 LL ∪

λ

λ

Page 10: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 10

ab

ab

λ

λ

}{1 baL n=

}{2 baL =

}{}{21 babaLL n ∪=∪NFA for

Example

Page 11: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 11

Concatenation NFA for 21LL

1M 2Mλ

Page 12: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 12

NFA for

ab ab

}{1 baL n=}{2 baL =

}{}}{{21 bbaababaLL nn ==

λ

Example

Page 13: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 13

Star Operation NFA for *1L

1M

λ

λ

*1L∈λλ λ

1

21

Lwwwww

i

k

=

Page 14: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 14

NFA for *}{*1 baL n=

ab

}{1 baL n=

λ

λ

λ

λ

Example

Page 15: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 15

Reverse RL1

1MNFA for

ʹ′1M

1. Reverse all transitions

2. Make initial state accepting state and vice versa

1L

Page 16: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 16

}{1 baL n=a

b

1M

}{1nR baL =

ab

ʹ′1M

Example

Page 17: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 17

Complement

1. Take the DFA that accepts 1L

1M1L ʹ′1M1L

2. Make accepting states non-final, and vice-versa

Page 18: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 18

}{1 baL n=

ab

1M

ba,

ba,

}{*},{1 babaL n−= a

b

ʹ′1M

ba,

ba,

Example

Page 19: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 19

Intersection

1L regular

2L regular We show 21 LL ∩

regular

Page 20: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 20

DeMorgan’s Law: 2121 LLLL ∪=∩

21 , LL regular

21 , LL regular

21 LL ∪ regular

21 LL ∪ regular

21 LL ∩ regular

Page 21: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 21

Example

}{1 baL n=

},{2 baabL =

regular

regular }{21 abLL =∩

regular

Page 22: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 22

1Lfor for 2LDFA 1M

DFA

2M

Construct a new DFA that accepts

Machine Machine

M 21 LL ∩

M simulates in parallel and 1M 2M

Another Proof for Intersection Closure

Page 23: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 23

States in M

ji pq ,

1M 2MState in State in

Page 24: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 24

1M 2M

1q 2qa

transition 1p 2pa

transition

DFA DFA

11, pq a

New transition

MDFA

22, pq

Page 25: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 25

0q

initial state 0p

initial state

New initial state

00, pq

1M 2MDFA DFA

MDFA

Page 26: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 26

iq

accept state

jp

accept states

New accept states

ji pq ,

kp

ki pq ,

1M 2MDFA DFA

MDFA

Both constituents must be accepting states

Page 27: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 27

Example:

}{1 baL n=

ab

1M

0≥n

}{2mabL =

b

b

2M

0q 1q 0p 1p

0≥m

2q 2pa

a

ba, ba,

ba,

Page 28: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 28

00, pq

Automaton for intersection

}{}{}{ ababbaL nn =∩=

10, pqa

21, pq

b

ab 11, pq

20, pq

a

12, pq

22, pq

b

ba,

a

b

ba,

b

a

Page 29: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 29

M simulates in parallel and 1M 2M

M accepts string w if and only if:

accepts string w1Mand accepts string w2M

)()()( 21 MLMLML ∩=

Page 30: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 30

Regular Languages and Regular Expressions

Page 31: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 31

Regular Expressions Regular expressions describe regular languages Example: describes the language

*)( cba ⋅+

{ } { },...,,,,,*, bcaabcaabcabca λ=

Page 32: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 32

Recursive Definition αλ,,∅

( )11

21

21

*rrrrrr

+

Are regular expressions

Primitive regular expressions:

2r1rGiven regular expressions and

Page 33: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 33

Examples

( ) )(* ∅+⋅⋅+ ccbaA regular expression:

( )++ baNot a regular expression:

Page 34: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 34

Languages of Regular Expressions : language of regular expression Example

( )rL r

( ) { },...,,,,,*)( bcaabcaabcacbaL λ=⋅+

Page 35: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 35

Definition For primitive regular expressions:

( )

( ) { }

( ) { }aaL

L

L

=

=

∅=∅

λλ

Page 36: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 36

Definition (continued) For regular expressions and

1r 2r

( ) ( ) ( )2121 rLrLrrL ∪=+

( ) ( ) ( )2121 rLrLrrL =⋅

( ) ( )( )** 11 rLrL =

( )( ) ( )11 rLrL =

Page 37: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 37

Example Regular expression: ( ) *aba ⋅+

( )( )*abaL ⋅+ ( )( ) ( )*aLbaL +=

( ) ( )*aLbaL +=

( ) ( )( ) ( )( )*aLbLaL ∪=

{ } { }( ) { }( )*aba ∪=

{ }{ },...,,,, aaaaaaba λ=

{ },...,,,...,,, baababaaaaaa=

Page 38: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 38

Example Regular expression

( ) ( )bbabar ++= *

( ) { },...,,,,, bbbbaabbaabbarL =

Page 39: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 39

Example Regular expression ( ) ( ) bbbaar **=

( ) }0,:{ 22 ≥= mnbbarL mn

Page 40: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 40

Example Regular expression *)10(00*)10( ++=r

)(rL = { all strings containing substring 00 }

Page 41: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 41

Example Regular expression )0(*)011( λ++=r

)(rL = { all strings without substring 00 }

Page 42: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 42

Equivalent Regular Expressions Definition: Regular expressions and are equivalent if

1r 2r

)()( 21 rLrL =

Page 43: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 43

Example L = { all strings without substring 00 }

)0(*)011(1 λ++=r

)0(*1)0(**)011*1(2 λλ +++=r

LrLrL == )()( 211r 2rand

are equivalent regular expressions

Page 44: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 44

Regular Expressions and

Regular Languages

Page 45: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 45

Theorem

Languages Generated by Regular Expressions

Regular Languages =

Page 46: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 46

Languages Generated by Regular Expressions

Regular Languages

Languages Generated by Regular Expressions

Regular Languages

Proof:

Page 47: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 47

Proof - Part 1

r)(rL

For any regular expression the language is regular

Languages Generated by Regular Expressions

Regular Languages

Proof by induction on the size of r

Page 48: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 48

Induction Basis Primitive Regular Expressions: αλ,,∅Corresponding NFAs

)()( 1 ∅=∅= LML

)(}{)( 2 λλ LML ==

)(}{)( 3 aLaML ==

regular languages

a

Page 49: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 49

Inductive Hypothesis Suppose that for regular expressions and , and are regular languages

1r 2r)( 1rL )( 2rL

Page 50: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 50

Inductive Step We will prove: ( )

( )

( )

( )( )1

1

21

21

*

rL

rL

rrL

rrL

+

Are regular Languages

Page 51: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 51

By definition of regular expressions: ( ) ( ) ( )

( ) ( ) ( )

( ) ( )( )

( )( ) ( )11

11

2121

2121

**

rLrL

rLrL

rLrLrrL

rLrLrrL

=

=

=⋅

∪=+

Page 52: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 52

)( 1rL )( 2rLBy inductive hypothesis we know: and are regular languages

Regular languages are closed under: ( ) ( )( ) ( )( )( )*1

21

21

rLrLrLrLrL ∪Union

Concatenation

Star

We also know:

Page 53: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 53

Therefore:

( ) ( ) ( )

( ) ( ) ( )

( ) ( )( )** 11

2121

2121

rLrL

rLrLrrL

rLrLrrL

=

=⋅

∪=+

Are regular languages

)())(( 11 rLrL = is trivially a regular language (by induction hypothesis)

End of Proof-Part 1

Page 54: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 54

Using the regular closure of these operations, we can construct recursively the NFA that accepts

M)()( rLML =

Example: 21 rrr +=)()( 11 rLML =

)()( 22 rLML =

)()( rLML =

λ

λ

Page 55: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 55

For any regular language there is a regular expression with

Proof - Part 2

Languages Generated by Regular Expressions

Regular Languages

Lr LrL =)(

We will convert an NFA that accepts to a regular expression

L

Page 56: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 56

Since is regular, there is a NFA that accepts it

LM

LML =)(

Take it with a single final state

Page 57: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 57

From construct the equivalent Generalized Transition Graph in which transition labels are regular expressions

M

Example:

aba,

cM

a

ba +

c

Corresponding Generalized transition graph

Page 58: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 58

Another Example:

ba +a

b

b0q 1q 2q

ba,a

b

b0q 1q 2q

b

bTransition labels are regular expressions

Page 59: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 59

Reducing the states: ba +

ab

b0q 1q 2q

b

0q 2q

babb*

)(* babb +

Transition labels are regular expressions

Page 60: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 60

Resulting Regular Expression:

0q 2q

babb*

)(* babb +

*)(**)*( bbabbabbr +=

LMLrL == )()(

Page 61: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 61

In General Removing a state:

iq q jqa b

cde

iq jq

dae* bce*dce*

bae*

Page 62: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 62

0q fq

1r

2r

3r4r

*)*(* 213421 rrrrrrr +=

LMLrL == )()(

The resulting regular expression:

By repeating the process until two states are left, the resulting graph is

Initial graph Resulting graph

End of Proof-Part 2

Page 63: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 63

Non-regular languages

(Pumping Lemma)

Page 64: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 64

Regular languages ba* acb +*

...etc*)( bacb ++

Non-regular languages }0:{ ≥nba nn

}*},{:{ bavvvR ∈

Page 65: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 65

Non Turing-Acceptable

Turing-Acceptable

decidable

Context-sensitive

Context-free

Regular

The Chomsky Hierarchy

Page 66: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 66

How can we prove that a language is not regular?

L

Prove that there is no DFA or NFA or RE that accepts L

Difficulty: this is not easy to prove (since there is an infinite number of them)

Solution: use the Pumping Lemma !!!

Page 67: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 67

The Pumping Lemma

Page 68: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 68

Take an infinite regular language L

There exists a DFA that accepts L

mstates

(contains an infinite number of strings)

Page 69: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 69

mw ≥||(number of states of DFA)

then, at least one state is repeated in the walk of w

q...... ...... 1σ 2σ kσ

Take string with Lw∈

kw σσσ 21=Walk in DFA of

Repeated state in DFA

Page 70: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 70

Take to be the first state repeated q

q....

w

There could be many states repeated

q.... ....

Second

occurrence First

occurrence

Unique states

One dimensional projection of walk :

1σ 2σ kσiσ jσ1+iσ 1+jσ

Page 71: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 71

q.... q.... ....

Second

occurrence First

occurrence 1σ 2σ kσiσ jσ1+iσ 1+jσ

wOne dimensional projection of walk :

ix σσ 1= jiy σσ 1+= kjz σσ 1+=

xyzw =We can write

Page 72: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 72

zyxw =

q... ...

x

y

z

In DFA:

...

...

1σ kσiσ1+iσjσ

1+jσ

contains only first occurrence of q

Page 73: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 73

Observation: myx ≤||length number of states of DFA

Since, in no state is repeated (except q)

xy

Unique States

q...

x

y

...

1σ iσ1+iσjσ

Page 74: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 74

Observation: 1|| ≥ylength

Since there is at least one transition in loop

q

y

...

1+iσjσ

Page 75: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 75

We do not care about the form of string z

q...

x

y

z

...

z may actually overlap with the paths of and x y

Page 76: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 76

The string is accepted

zxAdditional string:

q... ...

x z

...

Do not follow loop y

...

1σ kσiσ1+iσjσ

1+jσ

Page 77: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 77

The string is accepted

zyyx

q... ... ...

x z

Follow loop 2 times

Additional string:

y

...

1σ kσiσ1+iσjσ

1+jσ

Page 78: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 78

The string is accepted

zyyyx

q... ... ...

x z

Follow loop 3 times

Additional string:

y

...

1σ kσiσ1+iσjσ

1+jσ

Page 79: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 79

The string is accepted

zyx iIn General:

...,2,1,0=i

q... ... ...

x z

Follow loop times i

y

...

1σ kσiσ1+iσjσ

1+jσ

Page 80: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 80

Lzyx i ∈Therefore: ...,2,1,0=i

Language accepted by the DFA

q... ... ...

x z

y

...

1σ kσiσ1+iσjσ

1+jσ

Page 81: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 81

In other words, we described:

The Pumping Lemma !!!

Page 82: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 82

The Pumping Lemma: •  Given a infinite regular language L

•  there exists an integer m

•  for any string with length Lw∈ mw ≥||

•  we can write zyxw =

•  with and myx ≤|| 1|| ≥y

•  such that: Lzyx i ∈ ...,2,1,0=i

(critical length)

Page 83: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 83

In the book:

Critical length = Pumping length m p

Page 84: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 84

Applications of

the Pumping Lemma

Page 85: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 85

Observation: Every language of finite size has to be regular

Therefore, every non-regular language has to be of infinite size (contains an infinite number of strings)

(we can easily construct an NFA that accepts every string in the language)

Page 86: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 86

Suppose you want to prove that An infinite language is not regular

1. Assume the opposite: is regular

2. The pumping lemma should hold for

3. Use the pumping lemma to obtain a contradiction

L

L

L

4. Therefore, is not regular L

Page 87: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 87

Explanation of Step 3: How to get a contradiction

2. Choose a particular string which satisfies the length condition

Lw∈

3. Write xyzw =4. Show that Lzxyw i ∉=ʹ′ for some 1≠i

5. This gives a contradiction, since from pumping lemma Lzxyw i ∈=ʹ′

mw ≥||

1. Let be the critical length for m L

Page 88: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 88

Note: It suffices to show that only one string gives a contradiction

Lw∈

You don’t need to obtain contradiction for every Lw∈

Page 89: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 89

Theorem: The language }0:{ ≥= nbaL nn

is not regular

Proof: Use the Pumping Lemma

Example of Pumping Lemma application

Page 90: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 90

Assume for contradiction that is a regular language L

Since is infinite we can apply the Pumping Lemma

L

}0:{ ≥= nbaL nn

Page 91: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 91

Let be the critical length for

Pick a string such that: w Lw ∈

mw ≥||and length

mmbaw =We pick

m

}0:{ ≥= nbaL nn

L

Page 92: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 92

with lengths

From the Pumping Lemma:

1||,|| ≥≤ ymyx

babaaaaabaxyz mm ............==

mkay k ≤≤= 1,

x y z

m m

we can write zyxbaw mm ==

Thus:

=w

Page 93: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 93

From the Pumping Lemma: Lzyx i ∈

...,2,1,0=i

Thus:

mmbazyx =

Lzyx ∈2

mkay k ≤≤= 1,

Page 94: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 94

From the Pumping Lemma:

Lbabaaaaaaazxy ∈= ...............2

x y z

km + m

Thus:

Lzyx ∈2

mmbazyx =

y

Lba mkm ∈+

mkay k ≤≤= 1,

Page 95: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 95

Lba mkm ∈+

}0:{ ≥= nbaL nnBUT:

Lba mkm ∉+

CONTRADICTION!!!

1≥k

Page 96: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 96

Our assumption that is a regular language is not true

L

Conclusion: L is not a regular language

Therefore:

END OF PROOF

Page 97: Regular Languages, Regular Expressions, and Pumping Lemma · 2014-02-14 · Regular Languages, Regular Expressions, and Pumping Lemma . 2/14/14 Costas Busch - RPI 2 Non Turing-Acceptable

2/14/14 Costas Busch - RPI 97

Regular languages

Non-regular language }0:{ ≥nba nn

)( **baL