Vous êtes sur la page 1sur 62

Single Final State for NFAs

Courtesy Costas Busch - RPI

Any NFA can be converted to an equivalent NFA with a single final state

Courtesy Costas Busch - RPI

a a b

Example
NFA

a a b b P

Equivalent NFA

P
3

Courtesy Costas Busch - RPI

NFA

In General

Equivalent NFA

P P P
Courtesy Costas Busch - RPI

Single final state


4

Extreme Case
NFA without final state

Add a final state Without transitions

Courtesy Costas Busch - RPI

Properties of Regular Languages

Courtesy Costas Busch - RPI

For regular languages we will prove that: Union: Concatenation: Star: Reversal: Complement: Intersection:

L1 and L2

L1 L2

L1L2 L1 *
R L1 Are regular Languages

L1
Courtesy Costas Busch - RPI

L1 L2

We say: Regular languages are closed under Union: Concatenation: Star: Reversal: Complement: Intersection:

L1 L2

L1L2 L1 *
R L1

L1
Courtesy Costas Busch - RPI

L1 L2

Regular language

L1

Regular language

L2

L M1 ! L1
NFA

L M 2 ! L2
NFA

M1

M2

Single final state

Single final state


9

Courtesy Costas Busch - RPI

Example
nu0

M1
a
b

L1 ! {a b}

M2 L2 ! _ a ba
b a

Courtesy Costas Busch - RPI

10

Union
NFA for

L1 L2 M1
P P

M2

Courtesy Costas Busch - RPI

11

Example
NFA for

L1 L2 ! {a b} {ba} L1 ! {a b}
a
b
P P
n

L2 ! {ba}
b

a
12

Courtesy Costas Busch - RPI

Concatenation
NFA for

L1L2 M1
P

M2
P

Courtesy Costas Busch - RPI

13

Example
NFA for

L1L2 ! {a b}{ba} ! {a bba}


n

L1 ! {a b}
a b P

L2 ! {ba}
b a P

Courtesy Costas Busch - RPI

14

Star Operation
NFA for L1 *

M1
P
P

P L1 *

P
Courtesy Costas Busch - RPI 15

Example
NFA for

L1* ! {a b} *
P

w ! w1w2 . wk wi L1 n

L1 ! {a b}
a

P P

Courtesy Costas Busch - RPI

16

Reverse
NFA for

L1

M1

L1 d M1

1. Reverse all transitions 2. Make initial state final state and vice versa
Courtesy Costas Busch - RPI 17

Example

M1
a

L1 ! {a b}

a
R L1

d M1
b

! {ba }

Courtesy Costas Busch - RPI

18

Complement

L1

M1

L1

d M1

1. Take the DFA that accepts L1 2. Make final states non-final, and vice-versa
Courtesy Costas Busch - RPI 19

Example

M1
a
a, b

L1 ! {a b}

a, b

a L1 ! {a, b} * {a b}
n

a, b

d M1

b
Courtesy Costas Busch - RPI

a, b
20

Intersection
DeMorgans Law:

L1 L2 ! L1 L2
regular regular regular regular regular
21

L1 , L2 L1 , L2 L1 L2 L1 L2 L1 L2

Courtesy Costas Busch - RPI

Example
n

L1 ! {a b} regular L2 ! {ab, ba} regular

L1 L2 ! {ab}
regular

Courtesy Costas Busch - RPI

22

Regular Expressions

Courtesy Costas Busch - RPI

23

Regular Expressions
Regular expressions describe regular languages

Example:

(a  b c) *
describes the language

_a, bca ! _P , a, bc, aa, abc, bca,...a *


Courtesy Costas Busch - RPI 24

Recursive Definition
Primitive regular expressions: Given regular expressions

, P, E

r1 and r2

r1  r2 r1 r2 r1 *
Are regular expressions

r1
Courtesy Costas Busch - RPI 25

Examples
A regular expression:

a  b c * (c  )

Not a regular expression:

a  b 

Courtesy Costas Busch - RPI

26

Languages of Regular Expressions

L r : language of regular expression r

Example

L ( a  b c) * ! _P , a, bc, aa, abc, bca,...a

Courtesy Costas Busch - RPI

27

Definition
For primitive regular expressions:

L ! L P ! _Pa L a ! _aa
Courtesy Costas Busch - RPI 28

Definition (continued)
For regular expressions r and r2 1

L r1  r2 ! L r1 L r2 L r1 r2 ! L r1 L r2 L r1 * ! L r1 * L r1 ! L r1
Courtesy Costas Busch - RPI 29

Example
Regular expression:

a  b a *

L a  b a * ! L a  b L a * ! L a  b L a * ! L a L b L a * ! _aa _ a _aa * b ! _a, ba_P , a, aa, aaa,...a ! _a, aa, aaa,..., b, ba, baa,...a
Courtesy Costas Busch - RPI 30

Example
Regular expression

r ! a  b * a  bb

L r ! _a, bb, aa, abb, ba, bbb,...a

Courtesy Costas Busch - RPI

31

Example
Regular expression

r ! aa * bb * b

L r ! {a b

2n 2m

b : n, m u 0}

Courtesy Costas Busch - RPI

32

Example
Regular expression

r ! (0  1) * 00 (0  1) *

L(r ) = { all strings with at least


two consecutive 0 }

Courtesy Costas Busch - RPI

33

Example
Regular expression

r ! (1  01) * (0  P )

L(r ) = { all strings without


two consecutive 0 }

Courtesy Costas Busch - RPI

34

Equivalent Regular Expressions


Definition: Regular expressions are equivalent if

r1 and r2 L(r1) ! L( r2 )

Courtesy Costas Busch - RPI

35

Example

L = { all strings without


two consecutive 0 }

r1 ! (1  01) * (0  P ) r2 ! (1* 011*) * (0  P )  1* (0  P ) L(r1 ) ! L(r2 ) ! L r1 and r2


are equivalent regular expr.
36

Courtesy Costas Busch - RPI

Regular Expressions and Regular Languages

Courtesy Costas Busch - RPI

37

Theorem
Languages Generated by Regular Expressions

Regular Languages

Courtesy Costas Busch - RPI

38

Theorem - Part 1
Languages Generated by Regular Expressions Regular Languages

1. For any regular expression r the language L(r ) is regular


Courtesy Costas Busch - RPI 39

Theorem - Part 2
Languages Generated by Regular Expressions Regular Languages

2. For any regular language L there is a regular expression r with L ( r ) ! L

Courtesy Costas Busch - RPI

40

Proof - Part 1

1. For any regular expression r the language L (r ) is regular

Proof by induction on the size of

Courtesy Costas Busch - RPI

41

Induction Basis
Primitive Regular Expressions: NFAs

, P, E

L( M1 ) ! ! L() L( M 2 ) ! {P} ! L(P )


a

regular languages

L( M 3 ) ! {a} ! L(a )
Courtesy Costas Busch - RPI 42

Inductive Hypothesis
Assume for regular expressions r and r2 1 that L(r1 ) and L(r2 ) are regular languages

Courtesy Costas Busch - RPI

43

Inductive Step
We will prove:

L r1  r2 L r1 r2 L r1 * L r1

Are regular Languages

Courtesy Costas Busch - RPI

44

By definition of regular expressions:

L r1  r2 ! L r1 L r2 L r1 r2 ! L r1 L r2 L r1 * ! L r1 * L r1 ! L r1
Courtesy Costas Busch - RPI 45

By inductive hypothesis we know: L(r1 ) and L(r2 ) are regular languages

We also know: Regular languages are closed under: Union Concatenation Star

L r1 L r2 L r1 L r2

L r1 *
Courtesy Costas Busch - RPI 46

Therefore:

L r1  r2 ! L r1 L r2 L r1 r2 ! L r1 L r2 L r1 * ! L r1 *
Courtesy Costas Busch - RPI 47

Are regular languages

And trivially:

L((r1 )) is a regular language

Courtesy Costas Busch - RPI

48

Proof Part 2

2. For any regular language L there is a regular expression r with L ( r ) ! L

Proof by construction of regular expression

Courtesy Costas Busch - RPI

49

Since L is regular take the NFA M that accepts it

L( M ) ! L

Single final state


Courtesy Costas Busch - RPI 50

From M construct the equivalent Generalized Transition Graph


in which transition labels are regular expressions

Example:

M
a
a, b
Courtesy Costas Busch - RPI

a
ab

51

Another Example:

b a q0 b q1 a, b

b q2

b a q0 b
Courtesy Costas Busch - RPI

q1 a  b q2
52

Reducing the states:

b a

q0 b

q1 a  b q2

bb * a q0 bb * ( a  b)

b q2
53

Courtesy Costas Busch - RPI

Resulting Regular Expression:

bb * a q0
bb * ( a  b)

q2

r ! (bb * a ) * bb * (a  b)b * L(r ) ! L( M ) ! L


Courtesy Costas Busch - RPI 54

Removing states:

In General e g d qi
a

q
b
f

qj

ae * d
g ceced d  **

ce * b

qi f  aeb b ae * *
Courtesy Costas Busch - RPI

qj
55

The final transition graph:

r1 r3

r4

q0

r2

qf

The resulting regular expression: r ! (r1  r2 r4 * r3 ) * r2 r4 * r ! r1 * r2 (r4  r3 r1 * r2 ) *

L(r ) ! L( M ) ! L
Courtesy Costas Busch - RPI 56

Theorem
If L ! L ( A) for some DFA A Then there is a regular expression R such that

L ! L(R)
Proof: (by induction on the size of R) Let As states be {1, 2, , n} for some integer n Construct a collection of regular expressions that describe progressively broader sets of paths in DFA A

57

Let R be the regex that represent the set of strings w such that w is the label of a path from state i to j in A, and that path has no intermediate state whos label is greater than k. Note: beginning & end points, i.e. i & j are not intermediate so they can be greater than k

(k ) ij

Courtesy Costas Busch - RPI

58

Inductive Definition
Basis: k = 0 Since all states are >= 1, restriction on the paths is that the path must have no intermediate states at all. If i j An arc from i to j ( 0) Depending of the DFA A Rij may be , a or

( 0) ij

! a1  a2  .  am

(If there are m symbols that label arcs from i to j)


59

Inductive Definition
If i = j all loops from i to itself legal paths of length 0

(0) ij

! P  a1  a2  .  am

(If there are m symbols that label arcs from i to i)

60

Inductive Definition
Induction: Suppose that there is a path from i to j that goes through no state with label higher than k. Consider two cases path does not go thru state k at all.

j
(k ) ij

!R

( k 1) ij

61

path goes thru state k at least once - More than once once

R R

( k 1) ik

(R
( k 1) ij

( k 1) * kk

R
( k 1) * kk

( k 1) kj

(k ) ij

!R

R

( k 1) ik

(R

) R

( k 1) kj

62

Vous aimerez peut-être aussi