Вы находитесь на странице: 1из 50

1

Single Final State

for NFAs and DFAs
2
Observation

Any Finite Automaton (NFA or DFA)

can be converted to an equivalent NFA

with a single final state
3
a
b
b
a
NFA
Equivalent NFA

a
b
b
a
Example
4
NFA
In General
Equivalent NFA
Single
final state

5
Extreme Case

NFA without final state
Without transitions
6
Some Properties of
Regular Languages

7
Properties
1
L
2
L
2 1
L L
Concatenation:
*
1
L
Star:
2 1
L L Union:
Are regular
Languages
For regular languages and
we will prove that:
8
We Say:
Regular languages are closed under
2 1
L L
Concatenation:
*
1
L
Star:
2 1
L L Union:
9
1
L Regular language
( )
1 1
L M L =
1
M
Single final state
NFA
2
M
2
L
Single final state
( )
2 2
L M L =
Regular language
NFA
10
Example
} {
1
b a L
n
=
a
b
1
M
{ } ba L =
2
a
b
2
M
11
Union
NFA for
1
M
2
M
2 1
L L

12
Example

a
b
a
b

} {
1
b a L
n
=
} {
2
ba L =
} { } {
2 1
ba b a L L
n
=
NFA for
13
Concatenation

NFA for
2 1
L L
1
M
2
M

14
Example

NFA for
a
b
a
b
} {
1
b a L
n
=
} {
2
ba L =
} { } }{ {
2 1
bba a ba b a L L
n n
= =

15
Star Operation
NFA for
*
1
L
1
M

*
1
L e

16
Example

NFA for * } { *
1
b a L
n
=
a
b
} {
1
b a L
n
=

17
Regular Expressions

18
Regular Expressions
Regular expressions
describe regular languages

Example:

describes the language

* ) ( c b a +
{ } { } ,... , , , , , * , bca abc aa bc a bc a =
19
Recursive Definition
o , , C
( )
1
1
2 1
2 1
*
r
r
r r
r r

+
Are regular expressions
Primitive regular expressions:
2
r
1
r
Given regular expressions and
20
Examples
( ) ) ( * C + + c c b a
A regular expression:
( ) + +b a
Not a regular expression:
21
Languages of Regular Expressions

: language of regular expression

Example

( ) r L r
( ) { } ,... , , , , , * ) ( bca abc aa bc a c b a L = +
22
Definition

For primitive regular expressions:
( )
( ) { }
( ) { } a a L
L
L
=
=
C = C

23
Definition (continued)

For regular expressions and

1
r
2
r
( ) ( ) ( )
2 1 2 1
r L r L r r L = +
( ) ( ) ( )
2 1 2 1
r L r L r r L =
( ) ( ) ( )* *
1 1
r L r L =
( ) ( ) ( )
1 1
r L r L =
24
Example
Regular expression:
( ) * a b a +
( ) ( ) * a b a L + ( ) ( ) ( ) * a L b a L + =
( ) ( ) * a L b a L + =
( ) ( ) ( ) ( ) ( )* a L b L a L =
{ } { } ( ) { } ( )* a b a =
{ }{ } ,... , , , , aaa aa a b a =
{ } ,... , , ,..., , , baa ba b aaa aa a =
25
Example

Regular expression

( ) ( ) bb a b a r + + = *
( ) { } ,... , , , , , bbb ba abb aa bb a r L =
26
Example

Regular expression ( ) ( ) b bb aa r * * =
( ) } 0 , : {
2 2
> = m n b b a r L
m n
27
Example

Regular expression * ) 1 0 ( 00 * ) 1 0 ( + + = r
) (r L
= { all strings with at least
two consecutive 0 }
28
Example

Regular expression
) 0 ( * ) 01 1 ( + + = r
) (r L
= { all strings without
two consecutive 0 }
29
Equivalent Regular Expressions

Definition:

Regular expressions and

are equivalent if
1
r
2
r
) ( ) (
2 1
r L r L =
30
Example

L = { all strings with at least
two consecutive 0 }
) 0 ( * ) 01 1 (
1
+ + = r
) 0 ( * 1 ) 0 ( * *) 011 * 1 (
2
+ + + = r
L r L r L = = ) ( ) (
2 1
1
r
2
r and
are equivalent
regular expr.
31
Regular Expressions
and
Regular Languages

32
Theorem
Languages
Generated by
Regular Expressions
Regular
Languages
=
33
Theorem - Part 1
r
) (r L
1. For any regular expression
the language is regular
Languages
Generated by
Regular Expressions
Regular
Languages
_
34
Theorem - Part 2
Languages
Generated by
Regular Expressions
Regular
Languages
_
L
r
L r L = ) (
2. For any regular language there is
a regular expression with
35
Proof - Part 1
r
) (r L
1. For any regular expression
the language is regular
Proof by induction on the size of
r
36
Induction Basis
Primitive Regular Expressions: o , , C
NFAs
) ( ) (
1
C = C = L M L
) ( } { ) (
2
L M L = =
) ( } { ) (
3
a L a M L = =
regular
languages
37
Inductive Hypothesis

Assume
for regular expressions and
that
and are regular languages

1
r
2
r
) (
1
r L ) (
2
r L
38
Inductive Step
We will prove:

( )
( )
( )
( ) ( )
1
1
2 1
2 1
*
r L
r L
r r L
r r L

+
Are regular
Languages
39
By definition of regular expressions:

( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )
1 1
1 1
2 1 2 1
2 1 2 1
* *
r L r L
r L r L
r L r L r r L
r L r L r r L
=
=
=
= +
40
) (
1
r L ) (
2
r L
By inductive hypothesis we know:
and are regular languages

Regular languages are closed under
( ) ( )
( ) ( )
( ) ( )*
1
2 1
2 1
r L
r L r L
r L r L union
concatenation
star
We also know:
41
Therefore:
( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )* *
1 1
2 1 2 1
2 1 2 1
r L r L
r L r L r r L
r L r L r r L
=
=
= +
Are regular
languages
42
And trivially:

)) ((
1
r L
is a regular language
43
Proof Part 2
L
r
L r L = ) (
2. For any regular language there is
a regular expression with
Proof by construction of regular expression
44
Since is regular take the
NFA that accepts it

L
M
L M L = ) (
Single final state
45
From construct the equivalent
Generalized Transition Graph
transition labels
are regular expressions
M
Example:
a
b a,
c
M
a
b a +
c
46
Another Example:
b a +
a
b
b
0
q
1
q
2
q
b a,
a
b
b
0
q
1
q
2
q
b
b
47
Reducing the states:
b a +
a
b
b
0
q
1
q
2
q
b
0
q
2
q
b
a bb*
) ( * b a bb +
48
Resulting Regular Expression:

0
q
2
q
b
a bb*
) ( * b a bb +
* ) ( * * ) * ( b b a bb a bb r + =
L M L r L = = ) ( ) (
49
In General
Removing states:
i
q
q
j
q
a
b
c
d
e
i
q
j
q
d ae* b ce*
d ce*
b ae*
50
Obtaining the final regular expression:
0
q
f
q
1
r
2
r
3
r
4
r
* ) * ( *
2 1 3 4 2 1
r r r r r r r + =
L M L r L = = ) ( ) (