Languages
1
Equivalence of Machines
Definition:
if L M 1 L M 2
2
Example of equivalent machines
NFA M1
0
L M1 {10} *
q0 q1
1
FA M2 0,1
0
L M 2 {10} *
q0 q1 1 q2
1
0
3
We will prove:
Languages
Regular
accepted
Languages
by NFAs
Languages
accepted
by FAs
NFAs and FAs have the
same computation power
4
We will show:
Languages
accepted Regular
Languages
by NFAs
Languages
accepted Regular
Languages
by NFAs
5
Proof-Step 1
Languages
accepted Regular
Languages
by NFAs
Languages
accepted Regular
Languages
by NFAs
FA M
q0
8
Convert NFA to FA
a
NFA M
q0 a q1 q2
b
FA M
q0 a
q1, q2
9
Convert NFA to FA
a
NFA M
q0 a q1 q2
b
FA M
q0 a
q1, q2
b
10
Convert NFA to FA
a
NFA M
q0 a q1 q2
b
a
FA M
q0 a
q1, q2
b
11
Convert NFA to FA
a
NFA M
q0 a q1 q2
b
b a
FA M
q0 a
q1, q2
b
12
Convert NFA to FA
a
NFA M
q0 a q1 q2
b
b a
FA M
q0 a
q1, q2
b
a, b
13
Convert NFA to FA
a
NFA M
q0 a q1 q2
b
L M L(M )
a
FA M b
q0 a
q1, q2
b
a, b
14
NFA to FA: Remarks
We want to convert it
to an equivalent FA M
With L M L(M )
15
If the NFA has states
q0 , q1, q2 ,...
16
Procedure NFA to FA
17
Example
M a
NFA
q0 a q1 q2
b
FA M
q0
18
Procedure NFA to FA
2. For every FA’s state {qi , q j ,..., qm }
FA M
q0 a
q1, q2
q0 , a q1, q2
20
Procedure NFA to FA
21
Example
M a
NFA
q0 a q1 q2
b
b a
FA M
q0 a
q1, q2
b
a, b
22
Procedure NFA to FA
3. For any FA state {qi , q j ,..., qm }
23
Example
M a
NFA
q0 a q1 q2 q1 F
b
a
FA M b
q0 a
q1, q2
b q1, q2 F
a, b
24
Theorem
Take NFA M
L M L M
25
Proof
L M L M
L M L M AND L M L M
26
First we show: L M L M
27
w L(M )
M: q0 w qf
w 1 2 k
1 2 k
M: q0 qf
28
i
qi qj
denotes
i
qi qj
29
We will show that if w L(M )
w 1 2 k
1 2 k
M: q0 qf
then
1 2 k
M:
{q0 } {q f ,}
w L(M )
30
More generally, we will show that if in M:
(arbitrary string) v a1a2 an
a1 a2 an
M: q0 qi qj ql qm
then
a1 a2 an
M:
{q0} {qi ,} {q j ,} {ql ,} {qm ,}
31
Proof by induction on |v|
Induction Basis: v a1
a1
M: q0 qi
a1
M:
{q0 } {qi ,}
a1 a2 ak
M:
{q0} {qi ,} {q j ,} {qc ,} {qd ,}
33
Induction Step: | v | k 1
v a1a2 ak ak 1 vak 1
v
a1 a2 ak
M: q0 qi qj qc qd
v
a1 a2 ak
M:
{q0} {qi ,} {q j ,} {qc ,} {qd ,}
v 34
Induction Step: | v | k 1
v a1a2 ak ak 1 vak 1
v
a1 a2 ak ak 1
M: q0 qi qj qc qd qe
v
a1 a2 ak ak 1
M:
{q0} {qi ,} {q j ,} {qc ,} {qd ,} {qe ,}
v 35
Therefore if w L(M )
w 1 2 k
1 2 k
M: q0 qf
then
1 2 k
M:
{q0 } {q f ,}
w L(M )
36
We have shown: L M L M
(proof is similar)
37
Single Accepting
State for NFAs
38
Any NFA can be converted
to an equivalent NFA
39
Example
a
NFA
a b
a Equivalent NFA
a b
b
40
In General
NFA
Equivalent NFA
Single
accepting
state
41
Extreme Case
42
Properties of
Regular Languages
43
For regular languages L1 and L2
we will prove that:
Union: L1 L2
Concatenation: L1L2
Star: L1 * Are regular
Languages
Reversal: R
L1
Complement: L1
Intersection: L1 L2
44
We say: Regular languages are closed under
Union: L1 L2
Concatenation: L1L2
Star: L1 *
Reversal: R
L1
Complement: L1
Intersection: L1 L2
45
Regular language L1 Regular language L2
L M1 L1 L M 2 L2
NFA M1 NFA M2
46
Example
M1
n0
a
n
L1 {a b} b
M2
a
L2 ba b
47
Union
NFA for L1 L2
M1
M2
48
Example
n
NFA for L1 L2 {a b} {ba}
n
L1 {a b}
a
b
L2 {ba}
b a
49
Concatenation
M1 M2
50
Example
n n
NFA for L1L2 {a b}{ba} {a bba}
n
L1 {a b}
a L2 {ba}
b b a
51
Star Operation
NFA for L1 *
L1 *
M1
52
Example
n w w1w2 wk
NFA for L1* {a b} * wi L1
n
L1 {a b}
a
b
53
Reverse
R
NFA for L1
L1 M1 M1
Homework 2
54
Complement
L1 M1 L1 M1
Homework 2
55
Intersection
L1 regular
We show L1 L2
L2 regular regular
56
DeMorgan’s Law: L1 L2 L1 L2
L1 , L2 regular
L1 , L2 regular
L1 L2 regular
L1 L2 regular
L1 L2 regular
57
Example
n
L1 {a b} regular
L1 L2 {ab}
L2 {ab, ba} regular regular
58
Another Proof for Intersection Closure
Machine M1 Machine M2
FA for L1 FA for L2
qi , p j
State in M1 State in M2
60
FA M1 FA M2
q1 a q2 p1 a p2
transition transition
FA M
q1, p1 a q2 , p2
transition
61
FA M1 FA M2
q0 p0
initial state initial state
FA M
q0 , p0
Initial state
62
FA M1 FA M2
qi pj pk
FA M
qi , p j qi , pk
accept states
n0 m0
L1 {a b} n m
L2 {ab }
M1 M2
a b
q0 b q1 p0 a p1
a, b b a
q2 p2
a, b a, b
64
Automaton for intersection
n n
L {a b} {ab } {ab}
a, b
q0 , p0 a q0 , p1 b q1, p1 a q2 , p2
b a b a
q1, p2 b q0 , p2 q2 , p1
a b
a, b
65
M simulates in parallel M1 and M 2
M accepts string w if and only if
L ( M ) L ( M1 ) L ( M 2 )
66