You are on page 1of 66

NFAs accept the Regular

Languages

1
Equivalence of Machines

Definition:

Machine M1 is equivalent to machine M 2

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

Proof: Every FA is trivially an NFA

Any language L accepted by a FA


is also accepted by an NFA
6
Proof-Step 2

Languages
accepted  Regular
Languages
by NFAs

Proof: Any NFA can be converted to an


equivalent FA

Any language L accepted by an NFA


is also accepted by a FA
7
Convert NFA to FA
a
NFA M
q0 a q1  q2
b

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 are given an NFA M

We want to convert it
to an equivalent FA M 

With L M   L(M )
15
If the NFA has states

q0 , q1, q2 ,...

the FA has states in the powerset

,  q0  ,  q1 ,  q1, q2  ,  q3 , q4 , q7  ,....

16
Procedure NFA to FA

1. Initial state of NFA: q0

Initial state of FA:  q0 

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 }

Compute in the NFA


 *  qi , a  ,
 *  q j , a ,  {qi , qj ,..., qm
}
...
Add transition to FA
 {qi , q j ,..., qm }, a   {qi , qj ,..., qm
}
19
Exampe
M a
NFA
q0 a q1  q2
b
 * (q0 , a )  {q1, q2 }

FA M
 q0  a
 q1, q2 

   q0  , a    q1, q2 
20
Procedure NFA to FA

Repeat Step 2 for all letters in alphabet,


until
no more transitions can be added.

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 }

If q j is accepting state in NFA

Then, {qi , q j ,..., qm }


is accepting state in FA

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

Apply procedure to obtain FA M

Then M and M are equivalent :

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  

Take arbitrary: w L(M )

We will prove: w  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 ,}

Is true by construction of M:


32
Induction hypothesis: 1 | v | k
v  a1a2 ak
a1 a2 ak
M: q0 qi qj qc qd

a1 a2 ak
M:
{q0} {qi ,} {q j ,} {qc ,} {qd ,}

33
Induction Step: | v | k  1
v  a1a2 ak ak 1  vak 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  vak 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  

We also need to show: L M   L M  

(proof is similar)

37
Single Accepting
State for NFAs

38
Any NFA can be converted

to an equivalent NFA

with a single accepting state

39
Example
a
NFA
a b

a Equivalent NFA

a b

b 

40
In General
NFA

Equivalent NFA
 Single
 accepting

state
41
Extreme Case

NFA without accepting state

Add an accepting state


without transitions

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

Single accepting state Single aceepting state

46
Example
M1
n0
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

NFA for L1L2

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

Construct a new FA M that accepts L1  L2

M simulates in parallel M1 and M 2


59
States in M

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

accept state accept states

FA M
qi , p j qi , pk

accept states

Both constituents must be accepting states


63
Example:

n0 m0
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

M1 accepts string w and


M 2 accepts string w

L ( M )  L ( M1 )  L ( M 2 )

66

You might also like