Transcript powerpoint
A Single Final State
for Finite Accepters
1
Observation
Any Finite Accepter (NFA or DFA)
can be converted to an equivalent NFA
with a single final state
2
a
Example
NFA
b
a
b
Equivalent NFA
a
a
b
b
3
NFA
In General
Equivalent NFA
Single
final state
4
Extreme Case
NFA without final state
Add a final state
5
Properties of Regular Languages
6
Properties
Take any regular languages L1 and L2
We will prove:
Union:
Concatenation:
Star:
Complement:
Intersection:
L1 L2
L1L2
L1 *
Are regular
Languages
L1
L1 L2
7
We Say
Regular Languages are closed:
– Under union:
L1 L2
– Under concatenation:
L1L2
– Under the star operation:
– Under complement:
– Under intersection:
L1 *
L1
L1 L2
8
For regular languages L1 and L2
take NFAs M1 and M 2 with
LM1 L1
LM 2 L2
M1
M2
Single final state
9
Example
M1
L1 a b
n
a
b
M2
L2 ba
b
a
10
Union
NFA for L1 L2
M1
M2
11
Example
n
NFA for L1 L2 a b b, a
n
L1 a b
a
b
L2 ba
b
a
12
Concatenation
NFA for L1L2
M2
M1
13
Example
NFA for
L1L2 a b ba a bba
n
L1 a b
a
n
b
n
L2 ba
b
a
14
Star Operation
NFA for L1 *
M1
15
Example
NFA for
n *
L1* a b
a
b
L1 a b
n
16
Complement
For the complement L of regular language L:
Take the DFA M that accepts L
M such that:
– Each final state of M is nonfinal in M
Construct
nonfinal
We have:
final
L M L M L
17
Example
a, b
a
L a b
n
b
a, b
a, b
a
L a b
n
b
a, b
18
Intersection
For regular languages L1 and L2 :
L1 L2 L1 L2
L1 L2
regular
regular
regular
regular
L1
L1
L1 L2 L1 L2
L2
L2
regular
L1 L2
19
Example
Regular languages:
L1 a b
k l
L2 b ba
m
k , l, m 0
The language
L1 L2 b b
m
is regular
20
Regular Expressions
21
Regular Expressions
Regular expressions
are another way of expressing
regular languages
Example:
( a b c) *
Stands for the language
a, bc* , a, bc, aa, abc, bca,...
22
Recursive Definition
Regular Expressions:
• Primitive regular expressions: , ,
• Given regular expressions r1 and r2
r1 r2
r1 r2
r1 *
r1
Are regular expressions
23
Examples
A regular expression
a b c * (c )
Not a regular expression
a b
24
Languages of Regular Expressions
Lr : language of regular expression r
Example
L(a b c) * , a, bc, aa, abc, bca,...
25
Definition
For primitive regular expressions:
L
L
La a
26
Definition (continued)
For regular expressions r1 and r2
Lr1 r2 Lr1 Lr2
Lr1 r2 Lr1 Lr2
Lr1 * Lr1 *
Lr1 Lr1
27
Example
Regular expression: a b a *
La b a * La b La *
La b La *
La Lb La *
a b a *
a, b , a, aa, aaa,...
a, aa, aaa,..., b, ba, baa,...
28
Example
Regular expression
r a b * a bb
Lr a, bb, aa, abb, ba, bbb,...
29
Example
Regular expression
Lr a b
r aa * bb * b
2n 2m
b : n, m 0
30
Example
Regular expression
r (0 1) * 00 (0 1) *
L(r ) = { all strings with at least
two consecutive 0 }
31
Example
Regular expression
r (1 01) * (0 )
L(r ) = { all strings without
two consecutive 0 }
32
Equivalent Regular Expressions
Definition:
Regular expressions r1
are equivalent if
and
r2
L(r1) L(r2 )
33
Example
L = { all strings with at least
two consecutive 0 }
r1 (1 01) * (0 )
r2 (1* 011*) * (0 ) 1* (0 )
L(r1) L(r2 ) L
r1 and r2
are equivalent
regular expr.
34
Regular Expressions
and
Regular Languages
35
Theorem
The class of languages
described by Regular expressions
is identical
to the Regular languages
36
In Other Words
• For any regular expression r
the language L(r ) is regular
• For any regular language L there is
a regular expression r with L(r ) L
37
Proof
First we prove:
• For any regular expression r
the language L(r ) is regular
38
Induction Basis
Primitive Regular Expressions: , ,
NFAs
L( M1) L()
L( M 2 ) {} L( )
regular
languages
L( M 3 ) {a} L(a)
39
Inductive Hypothesis
Assume
for regular expressions r1 and r2
that
L(r1) and L(r2 ) are regular languages
40
Inductive Step
We will prove that:
Lr1 r2
Lr1 r2
Lr1 *
Are regular
Languages
Lr1
41
By definition of regular expressions:
Lr1 r2 Lr1 Lr2
Lr1 r2 Lr1 Lr2
Lr1 * Lr1 *
Lr1 Lr1
42
By inductive hypothesis
L(r1) and L(r2 ) are regular languages
We know:
Regular languages
are closed under
L
r
L
r
1
2
union
concatenation Lr1 Lr2
star operation Lr1 *
43
Therefore:
Lr1 r2 Lr1 Lr2
Lr1 r2 Lr1 Lr2
Are regular
languages
Lr1 * Lr1 *
44
And trivially:
L((r1))
is a regular language
45
Proof - Second Part
Now we want to prove:
• For any regular language L there is
a regular expression r with L(r ) L
46
Since L is regular take the
NFA M that accepts it
L( M ) L
Single final state
47
From M Construct the equivalent
Generalized Transition Graph
labels of transitions
are regular expressions
Example:
M
a
c
a, b
a
c
ab
48
Another Example:
a
q0
b
b
q1 a, b
q2
b
b
b
a
q0
q1 a b q2
b
49
Reducing the states:
b
a
q0
b
q1 a b q2
b
bb * a
q0
b
bb * (a b)
q2
50
Resulting Regular Expression:
bb * a
q0
b
bb * (a b)
q2
r (bb * a) * bb * (a b)b *
L( r ) L( M ) L
51
In General
e
Removing states:
d
qi
c
qj
q
a
b
ae * d
ce * b
ce * d
qi
qj
ae * b
52
Obtaining the final regular expression:
r4
r1
r3
q0
r2
qf
r r1 * r2 (r4 r3r1 * r2 ) *
L( r ) L( M ) L
53