costas busch - rpi1 single final state for nfas. costas busch - rpi2 any nfa can be converted to an...

56
Costas Busch - RPI 1 Single Final State for NFAs

Post on 19-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 1

Single Final State for NFAs

Page 2: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 2

Any NFA can be converted

to an equivalent NFA

with a single final state

Page 3: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 3

a

b

b

aNFA

Equivalent NFA

a

b

b

a

Example

Page 4: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 4

NFAIn General

Equivalent NFA

Singlefinal state

Page 5: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 5

Extreme Case

NFA without final state

Add a final stateWithout transitions

Page 6: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 6

Properties of Regular Languages

Page 7: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 7

1L 2L

21LLConcatenation:

*1LStar:

21 LL Union:

Are regularLanguages

For regular languages and we will prove that:

1L

21 LL

Complement:

Intersection:

RL1Reversal:

Page 8: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 8

We say: Regular languages are closed under

21LLConcatenation:

*1LStar:

21 LL Union:

1L

21 LL

Complement:

Intersection:

RL1Reversal:

Page 9: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 9

1LRegular language

11 LML

1M

Single final state

NFA 2M

2L

Single final state

22 LML

Regular language

NFA

Page 10: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 10

Example

}{1 baL na

b

1M

baL 2ab

2M

0n

Page 11: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 11

UnionNFA for

1M

2M

21 LL

Page 12: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 12

Example

a

b

ab

}{1 baL n

}{2 baL

}{}{21 babaLL n NFA for

Page 13: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 13

Concatenation

NFA for 21LL

1M 2M

Page 14: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 14

Example NFA for

a

b ab

}{1 baL n}{2 baL

}{}}{{21 bbaababaLL nn

Page 15: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 15

Star OperationNFA for *1L

1M

*1L

Page 16: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 16

Example

NFA for *}{*1 baL n

a

b

}{1 baL n

1

21

Lw

wwww

i

k

Page 17: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 17

Reverse

RL1

1M

NFA for

1M

1. Reverse all transitions

2. Make initial state final state and vice versa

1L

Page 18: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 18

Example

}{1 baL na

b

1M

}{1nR baL

a

b

1M

Page 19: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 19

Complement

1. Take the DFA that accepts 1L

1M1L

1M1L

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

Page 20: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 20

Example

}{1 baL n

a

b

1M

ba,

ba,

}{*},{1 babaL n a

b

1M

ba,

ba,

Page 21: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 21

Intersection

DeMorgan’s Law: 2121 LLLL

21 , LL regular

21 , LL regular

21 LL regular

21 LL regular

21 LL regular

Page 22: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 22

Example

}{1 baL n

},{2 baabL

regular

regular

}{21 abLL

regular

Page 23: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 23

Regular Expressions

Page 24: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 24

Regular ExpressionsRegular expressions describe regular languages

Example:

describes the language

*)( cba

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

Page 25: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 25

Recursive Definition

,,

1

1

21

21

*

r

r

rr

rr

Are regular expressions

Primitive regular expressions:

2r1rGiven regular expressions and

Page 26: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 26

Examples

)(* ccbaA regular expression:

baNot a regular expression:

Page 27: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 27

Languages of Regular Expressions : language of regular expression

Example

rL r

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

Page 28: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 28

Definition

For primitive regular expressions:

aaL

L

L

Page 29: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 29

Definition (continued)

For regular expressions and

1r 2r

2121 rLrLrrL

2121 rLrLrrL

** 11 rLrL

11 rLrL

Page 30: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 30

ExampleRegular expression: *aba

*abaL *aLbaL *aLbaL *aLbLaL

*aba ,...,,,, aaaaaaba

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

Page 31: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 31

Example

Regular expression bbabar *

,...,,,,, bbbbaabbaabbarL

Page 32: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 32

Example

Regular expression bbbaar **

}0,:{ 22 mnbbarL mn

Page 33: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 33

Example

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

)(rL = { all strings with at least two consecutive 0 }

Page 34: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 34

Example

Regular expression )0(*)011( r

)(rL = { all strings without two consecutive 0 }

Page 35: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 35

Equivalent Regular Expressions

Definition:

Regular expressions and

are equivalent if

1r 2r

)()( 21 rLrL

Page 36: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 36

Example L= { all strings without

two consecutive 0 }

)0(*)011(1 r

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

LrLrL )()( 211r 2rand

are equivalentregular expr.

Page 37: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 37

Regular Expressionsand

Regular Languages

Page 38: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 38

Theorem

LanguagesGenerated byRegular Expressions

RegularLanguages

Page 39: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 39

Theorem - Part 1

r)(rL

1. For any regular expression

the language is regular

LanguagesGenerated byRegular Expressions

RegularLanguages

Page 40: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 40

Theorem - Part 2

LanguagesGenerated byRegular Expressions

RegularLanguages

Lr LrL )(

2. For any regular language there is

a regular expression with

Page 41: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 41

Proof - Part 1

r)(rL

1. For any regular expression

the language is regular

Proof by induction on the size of r

Page 42: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 42

Induction BasisPrimitive Regular Expressions: ,,

NFAs

)()( 1 LML

)(}{)( 2 LML

)(}{)( 3 aLaML

regularlanguages

a

Page 43: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 43

Inductive Hypothesis

Assume for regular expressions andthat and are regular languages

1r 2r

)( 1rL )( 2rL

Page 44: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 44

Inductive StepWe will prove:

1

1

21

21

*

rL

rL

rrL

rrL

Are regular Languages

Page 45: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 45

By definition of regular expressions:

11

11

2121

2121

**

rLrL

rLrL

rLrLrrL

rLrLrrL

Page 46: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 46

)( 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 47: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 47

Therefore:

** 11

2121

2121

rLrL

rLrLrrL

rLrLrrL

Are regularlanguages

Page 48: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 48

And trivially:

))(( 1rL is a regular language

Page 49: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 49

Proof – Part 2

Lr LrL )(

2. For any regular language there is

a regular expression with

Proof by construction of regular expression

Page 50: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 50

Since is regular take the NFA that accepts it

LM

LML )(

Single final state

Page 51: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 51

From construct the equivalentGeneralized Transition Graph in which transition labels are regular

expressions

M

Example:

a

ba,

cM

a

ba

c

Page 52: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 52

Another Example:

ba a

b

b

0q 1q 2q

ba,a

b

b

0q 1q 2q

b

b

Page 53: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 53

Reducing the states:

ba a

b

b

0q 1q 2q

b

0q 2q

babb*

)(* babb

Page 54: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 54

Resulting Regular Expression:

0q 2q

babb*

)(* babb

*)(**)*( bbabbabbr

LMLrL )()(

Page 55: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 55

In GeneralRemoving states:

iq q jqa b

cde

iq jq

dae* bce*dce*

bae*

Page 56: Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state

Costas Busch - RPI 56

The final transition graph:

0q fq

1r

2r

3r4r

*)*(* 213421 rrrrrrr

LMLrL )()(

The resulting regular expression: