Properties of Regular Languages

Download Report

Transcript Properties of Regular Languages

Properties of
Regular Languages
Costas Busch - LSU
1
For regular languages L1 and L 2
we will prove that:
Union: L1  L 2
Concatenation: L1 L 2
Star: L
*
1
Reversal: L1R
Complement:
Are regular
Languages
L1
Intersection: L1  L 2
Costas Busch - LSU
2
We say Regular languages are closed under
Union: L1  L 2
Concatenation: L1 L 2
Star: L
*
1
Reversal: L1R
Complement:
L1
Intersection: L1  L 2
Costas Busch - LSU
3
A useful transformation: use one accept state
NFA
a
2 accept states
b
a
b
Equivalent
NFA
a
b
1 accept state
a
b


Costas Busch - LSU
4
NFA
In General
Equivalent NFA



Costas Busch - LSU
Single
accepting
state
5
Extreme case
NFA without accepting state
Add an accepting state
without transitions
Costas Busch - LSU
6
Take two languages
Regular language L1
Regular language L 2
L  M 1   L1
NFA
L  M 2   L2
NFA M 2
M1
Single accepting state
Single accepting state
Costas Busch - LSU
7
Example
n0
n
L1  { a b }
M1
a
b
M2
L 2  ba 
b
Costas Busch - LSU
a
8
Union
NFA for L1  L 2
M1


w  L1  L 2
M2
w  L1 or w  L 2
Costas Busch - LSU
9
Example
n
NFA for L1  L 2  { a b }  {ba }
n
L1  { a b }
a


b
L 2  {ba }
b
a
Costas Busch - LSU
10
Concatenation
NFA for L1 L 2
change to
regular state
M2
M1

w  L1 L 2
w  w 1 w 2 : w 1  L1 and w 2  L 2
Costas Busch - LSU
11
Example
n
n
NFA for L1 L 2  { a b }{ ba }  { a bba }
n
L1  { a b }
L 2  {ba }
a
b

b
Costas Busch - LSU
a
12
Star Operation
NFA for L*
M


L( M )  L

w L
*
w  w1 w 2  w k : w i  L
or w  
Costas Busch - LSU
13
Example
NFA for L1  { a n b }*
*
n
L1  { a b }
a

b

Costas Busch - LSU
14
Reverse
NFA for L
R
M
M
L ( M )  L
L( M )  L
R
1. Reverse all transitions
2. Make the initial state accept state
and the accept state initial state
Costas Busch - LSU
15
Example
M1
a
n
L1  { a b }
b
M 1
a
L  {ba }
R
1
n
b
Costas Busch - LSU
16
Complement
M
M
L( M )  L
L ( M )  L
1. Take the DFA that accepts L
2. Make accept states regular
and vice-versa
Costas Busch - LSU
17
Example
M1
a,b
a
n
L1  { a b }
b
n
L1  { a , b } *  { a b }
a,b
M 1
a,b
a
b
Costas Busch - LSU
a,b
18
NFAs cannot be used for complement
Make accept states regular
and vice-versa
NFA M
NFA M 
L ( M )  { }  L ( M )
L ( M )  {}
L ( M )    { a , b}
*
*
Costas Busch - LSU
it is not the
complement
19
Same example with DFAs
Make accept states regular
and vice-versa
DFA M 
DFA M
a,b
a,b
*
L ( M )  { a , b}  L ( M )
L ( M )  {}
L ( M )    { a , b}
*
*
Costas Busch - LSU
it is the
complement
20
Intersection
L1 regular
We show
L 2 regular
L1  L 2
regular
Costas Busch - LSU
21
DeMorgan’s Law:
L1  L 2  L1  L 2
L1 , L 2
regular, regular
L1 , L 2
regular, regular
L1  L 2
regular
L1  L 2
regular
L1  L 2
regular
Costas Busch - LSU
22
Example
n
L1  { a b }
regular
L1  L 2  { ab }
L 2  { ab , ba } regular
Costas Busch - LSU
regular
23
Another Proof for Intersection Closure
Machine M 1
Machine M 2
DFA for L1
DFA for L 2
Construct a new DFA M that accepts L1  L 2
M simulates in parallel M 1 and M 2
Costas Busch - LSU
24
States in M
qi , p j
State in M 1
State in M 2
Costas Busch - LSU
25
DFA M 1
q1
DFA M 2
a
q2
a
p1
transition
p2
transition
DFA M
q1 , p1
a
q2 , p2
New transition
Costas Busch - LSU
26
DFA M 1
DFA M 2
q0
p0
initial state
initial state
DFA M
q0 , p0
New initial state
Costas Busch - LSU
27
DFA M 1
DFA M 2
pj
qi
accept state
pk
accept states
DFA M
qi , p j
qi , p k
New accept states
Both constituents must be accepting states
Costas Busch - LSU
28
Example:
n0
m0
n
m
L1  { a b }
L 2  { ab
}
M2
M1
a
b
q0
b
q1
p0
a,b
b
q2
a
p1
a
p2
a,b
a,b
Costas Busch - LSU
29
DFA M for intersection
L ( M )  { a b }  { ab }  { ab }
n
m
a,b
q0 , p0
a
b
q1 , p 2
b
q 0 , p1
q1 , p1
b
a
b
q0 , p2
a
q2 , p2
a
q 2 , p1
a
b
a,b
Costas Busch - LSU
30
Construction procedure for intersection
1. Build Initial State
2. For each new state and for each symbol
add transition to either an existing state
or create a new state and point to it
3. Repeat step 3 until no new states
are added
4. Designate accept states
Costas Busch - LSU
31
Automaton for intersection
L  { a b}  { ab }  { ab }
n
m
q0 , p0
initial state
Costas Busch - LSU
32
Automaton for intersection
L  { a b}  { ab }  { ab }
n
q0 , p0
a
m
q 0 , p1
add transition and new state
for symbol a
M2
M1
q0
a
q0
p0
a
p1
M
q0 , p0
Costas Busch - LSU
a
q 0 , p1
33
Automaton for intersection
L  { a b}  { ab }  { ab }
n
q0 , p0
a
m
q 0 , p1
b
M2
M1
q0
q1 , p 2
add transition and new state
for symbol b
Costas Busch - LSU
b
q1
p0
b
p2
M
q0 , p0
b
q1 , p 2
34
Automaton for intersection
L  { a b}  { ab }  { ab }
n
m
Repeat until no new states can be added
q0 , p0
a
b
q1 , p 2
b
q 0 , p1
q1 , p1
b
a
b
q0 , p2
a
a,b
q2 , p2
a
q 2 , p1
a
b
a,b
Costas Busch - LSU
35
Automaton for intersection
L  { a b}  { ab }  { ab }
n
m
q 1 accept state for M 1
p 1 accept state for M
q0 , p0
add Accept state
2
a
b
q1 , p 2
b
q 0 , p1
q1 , p1
b
a
b
q0 , p2
a
a,b
q2 , p2
a
q 2 , p1
a
b
a,b
Costas Busch - LSU
36
Intersection DFA M :
simulates in parallel M 1 and M 2
accepts string w
if and only if:
M 1 accepts string w
and M 2 accepts string w
L(M )  L(M 1)  L(M 2 )
Costas Busch - LSU
37