Single Final State for NFAs and DFAs Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single.
Download
Report
Transcript Single Final State for NFAs and DFAs Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single.
Single Final State
for NFAs and DFAs
1
Observation
Any Finite Automaton (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
Without transitions
5
Some Properties of
Regular Languages
6
Properties
For regular languages
we will prove that:
Union:
Concatenation:
Star:
L1
and
L2
L1 L2
L1L2
Are regular
Languages
L1 *
7
We Say:
Regular languages are closed under
Union:
Concatenation:
Star:
L1 L2
L1L2
L1 *
8
Regular language
L1
LM1 L1
NFA
M1
Single final state
Regular language
L2
LM 2 L2
NFA
M2
Single final state
9
Example
M1
a
L1 {a b}
n
b
M2
L2 ba
b
a
10
NFA for
L1 L2
Union
M1
M2
11
Example
NFA for
L1 L2 {a b} {ba}
n
L1 {a b}
n
a
b
L2 {ba}
b
a
12
Concatenation
NFA for
L1L2
M1
M2
13
Example
NFA for
L1L2 {a b}{ba} {a bba}
n
L1 {a b}
n
n
L2 {ba}
a
b
b
a
14
Star Operation
NFA for L1 *
L1 *
M1
15
Example
NFA for
L1* {a b} *
n
L1 {a b}
n
a
b
16
Regular Expressions
17
Regular Expressions
Regular expressions
describe regular languages
Example:
( a b c) *
describes the language
a, bc* , a, bc, aa, abc, bca,...
18
Recursive Definition
Primitive regular expressions:
Given regular expressions
r1
, ,
and r2
r1 r2
r1 r2
r1 *
Are regular expressions
r1
19
Examples
A regular expression:
a b c * (c )
Not a regular expression:
a b
20
Languages of Regular Expressions
L r :
language of regular expression
r
Example
L(a b c) * , a, bc, aa, abc, bca,...
21
Definition
For primitive regular expressions:
L
L
La a
22
Definition (continued)
For regular expressions r1 and r2
Lr1 r2 Lr1 Lr2
Lr1 r2 Lr1 Lr2
Lr1 * Lr1 *
Lr1 Lr1
23
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,...
24
Example
Regular expression
r a b * a bb
Lr a, bb, aa, abb, ba, bbb,...
25
Example
Regular expression
Lr {a b
r aa * bb * b
2n 2m
b : n, m 0}
26
Example
Regular expression
r (0 1) * 00 (0 1) *
L(r ) = { all strings with at least
two consecutive 0 }
27
Example
Regular expression
r (1 01) * (0 )
L(r ) = { all strings without
two consecutive 0 }
28
Equivalent Regular Expressions
Definition:
Regular expressions
are equivalent if
r1
and
r2
L(r1) L(r2 )
29
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
and r2
are equivalent
regular expr.
r1
30
Regular Expressions
and
Regular Languages
31
Theorem
Languages
Generated by
Regular Expressions
Regular
Languages
32
Theorem - Part 1
Languages
Generated by
Regular Expressions
Regular
Languages
1. For any regular expression r
the language L(r ) is regular
33
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
34
Proof - Part 1
1. For any regular expression r
the language L(r ) is regular
Proof by induction on the size of
r
35
Induction Basis
Primitive Regular Expressions:
, ,
NFAs
L( M1 ) L()
L( M 2 ) {} L( )
regular
languages
L( M 3 ) {a} L(a)
36
Inductive Hypothesis
Assume
for regular expressions r1 and r2
that
L(r1) and L(r2 ) are regular languages
37
Inductive Step
We will prove:
Lr1 r2
Lr1 r2
Lr1 *
Lr1
Are regular
Languages
38
By definition of regular expressions:
Lr1 r2 Lr1 Lr2
Lr1 r2 Lr1 Lr2
Lr1 * Lr1 *
Lr1 Lr1
39
By inductive hypothesis we know:
L(r1) and L(r2 ) are regular languages
We also know:
Regular languages are closed under
union
Lr1 Lr2
concatenation Lr1 Lr2
star
Lr1 *
40
Therefore:
Lr1 r2 Lr1 Lr2
Lr1 r2 Lr1 Lr2
Are regular
languages
Lr1 * Lr1 *
41
And trivially:
L((r1))
is a regular language
42
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
43
Since L is regular take the
NFA M that accepts it
L( M ) L
Single final state
44
From M construct the equivalent
Generalized Transition Graph
transition labels
are regular expressions
Example:
M
a
c
a, b
a
c
ab
45
Another Example:
a
q0
b
b
q1 a, b
q2
b
b
b
a
q0
q1 a b q2
b
46
Reducing the states:
b
a
q0
b
q1 a b q2
b
bb * a
q0
b
bb * (a b)
q2
47
Resulting Regular Expression:
bb * a
q0
b
bb * (a b)
q2
r (bb * a) * bb * (a b)b *
L( r ) L( M ) L
48
In General
e
Removing states:
d
qi
c
qj
q
a
b
ae * d
ce * b
ce * d
qj
qi
ae * b
49
Obtaining the final regular expression:
r4
r1
r3
q0
r2
qf
r r1 * r2 (r4 r3r1 * r2 ) *
L( r ) L( M ) L
50