costas busch - lsu1 regular expressions. costas busch - lsu2 regular expressions regular expressions...

36
Costas Busch - LSU 1 Regular Expressions

Upload: alicia-porter

Post on 19-Jan-2016

260 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 1

Regular Expressions

Page 2: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 2

Regular ExpressionsRegular expressions describe regular languages

Example:

describes the language

*)( cba

,...,,,,,*, bcaabcaabcabca

Page 3: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 3

Recursive Definition

,,

1

1

21

21

*

r

r

rr

rr

Are regular expressions

Primitive regular expressions:

2r1rGiven regular expressions and

Page 4: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 4

Examples

)(* ccbaA regular expression:

baNot a regular expression:

Page 5: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 5

Languages of Regular Expressions : language of regular expression

Example

rL r

,...,,,,,*)( bcaabcaabcacbaL

Page 6: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 6

Definition

For primitive regular expressions:

aaL

L

L

Page 7: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 7

Definition (continued)

For regular expressions and

1r 2r

2121 rLrLrrL

2121 rLrLrrL

** 11 rLrL

11 rLrL

Page 8: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 8

ExampleRegular expression: *aba

*abaL *aLbaL *aLbaL *aLbLaL

*aba ,...,,,, aaaaaaba

,...,,,...,,, baababaaaaaa

Page 9: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 9

Example

Regular expression bbabar *

,...,,,,, bbbbaabbaabbarL

Page 10: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 10

Example

Regular expression bbbaar **

}0,:{ 22 mnbbarL mn

Page 11: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 11

Example

Regular expression *)10(00*)10( r

)(rL = { all strings containing substring 00 }

Page 12: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 12

Example

Regular expression )0(*)011( r

)(rL = { all strings without substring 00 }

Page 13: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 13

Equivalent Regular Expressions

Definition:

Regular expressions and

are equivalent if

1r 2r

)()( 21 rLrL

Page 14: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 14

Example L= { all strings without substring 00 }

)0(*)011(1 r

)0(*1)0(**)011*1(2 r

LrLrL )()( 211r 2rand

are equivalentregular expressions

Page 15: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 15

Regular Expressionsand

Regular Languages

Page 16: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 16

Theorem

LanguagesGenerated byRegular Expressions

RegularLanguages

Page 17: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 17

LanguagesGenerated byRegular Expressions

RegularLanguages

LanguagesGenerated byRegular Expressions

RegularLanguages

Proof:

Page 18: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 18

Proof - Part 1

r)(rL

For any regular expression

the language is regular

LanguagesGenerated byRegular Expressions

RegularLanguages

Proof by induction on the size of r

Page 19: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 19

Induction BasisPrimitive Regular Expressions: ,,Corresponding NFAs

)()( 1 LML

)(}{)( 2 LML

)(}{)( 3 aLaML

regularlanguages

a

Page 20: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 20

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

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

Page 21: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 21

Inductive StepWe will prove:

1

1

21

21

*

rL

rL

rrL

rrL

Are regular Languages

Page 22: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 22

By definition of regular expressions:

11

11

2121

2121

**

rLrL

rLrL

rLrLrrL

rLrLrrL

Page 23: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 23

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

Regular languages are closed under:

*1

21

21

rL

rLrL

rLrL Union

Concatenation

Star

We also know:

Page 24: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 24

Therefore:

** 11

2121

2121

rLrL

rLrLrrL

rLrLrrL

Are regularlanguages

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

End of Proof-Part 1

Page 25: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 25

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

M)()( rLML

Example: 21 rrr )()( 11 rLML

)()( 22 rLML

)()( rLML

Page 26: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 26

For any regular language there is a regular expression with

Proof - Part 2

LanguagesGenerated byRegular Expressions

RegularLanguages

Lr LrL )(

We will convert an NFA that accepts to a regular expression

L

Page 27: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 27

Since is regular, there is aNFA that accepts it

LM

LML )(

Take it with a single accept state

Page 28: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 28

From construct the equivalentGeneralized Transition Graphin which transition labels are regular

expressions

M

Example:

a

ba,

cM

a

ba

c

CorrespondingGeneralized transition graph

Page 29: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 29

Another Example:

ba a

b

b

0q 1q 2q

ba,a

b

b

0q 1q 2q

b

bTransition labels are regular expressions

Page 30: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 30

Reducing the states:

ba a

b

b

0q 1q 2q

b

0q 2q

babb*

)(* babb

Transition labels are regular expressions

Page 31: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 31

Resulting Regular Expression:

0q 2q

babb*

)(* babb

*)(**)*( bbabbabbr

LMLrL )()(

Page 32: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 32

In GeneralRemoving a state:

iq q jqa b

cde

iq jq

dae* bce*dce*

bae*

2-neighbors

Page 33: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 33

iq jq

dae* bce*dce*

bae*

iq q jqa b

cde

kq

f g

kq

fge*

dge*

fae*

bge*fce*

This can be generalized to arbitrary number of neighbors to q

3-neighbors

Page 34: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 34

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 35: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 35

Standard Representations of Regular Languages

Regular Languages

DFAs

NFAsRegularExpressions

Page 36: Costas Busch - LSU1 Regular Expressions. Costas Busch - LSU2 Regular Expressions Regular expressions describe regular languages Example: describes the

Costas Busch - LSU 36

When we say: We are given a Regular Language

We mean:

L

Language is in a standard representation

L

(DFA, NFA, or Regular Expression)