Lect 05

Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

XJCO2321 Formal Languages and

Finite Automata

05: Properties of Regular


Languages
For regular languages L1 and L2
we will prove that:
Union: L1  L2
Concatenation: L1L2
Star: L* Are regular
1
Languages
Reversal: LR
1

Complement: L1
Intersection: L1  L2
Based on slides by Costas Busch 2
We say Regular languages are closed under

Union: L1  L2
Concatenation: L1L2
*
Star: L1

Reversal: LR
1

Complement: L1
Intersection: L1  L2
Based on slides by Costas Busch 3
A useful transformation: use one accept state

NFA
a
b 2 accept states
a
b

Equivalent
NFA
a
1 accept state
a b

b 

Based on slides by Costas Busch 4
In General
NFA

Equivalent NFA
 Single
 accepting

state
Based on slides by Costas Busch 5
Extreme case

NFA without accepting state

Add an accepting state


without transitions

Based on slides by Costas Busch 6


Take two languages

Regular language L1 Regular language L2

L(M1 ) = L1 L(M 2 ) = L2

NFA M1 NFA M2

Single accepting state Single accepting state

Based on slides by Costas Busch 7


Example

M1
n0
a
L1 = {a b} n
b

M2
L2 = ba b a

Based on slides by Costas Busch 8


Union
NFA for L1  L2
M1

 M2

w  L1  L2 w  L1 or w  L2
Based on slides by Costas Busch 9
Example

NFA for L1  L2 = {a b}  {ba}


n

L1 = {a b}n
a
b

 L2 = {ba}
b a
Based on slides by Costas Busch 10
Concatenation
NFA for L1L2
change to
regular state
M1 M2

w  L1 L2 w = w1w2 : w1  L1 and w2  L2

Based on slides by Costas Busch 11


Example

NFA for L1L2 = {a b}{ba} = {a bba}


n n

L1 = {a b} n

a L2 = {ba}
b  b a

Based on slides by Costas Busch 12


Star Operation
NFA for L*
M
 change to
regular state
L( M ) = L


w = w1w2  wk : wi  L
w L *
or w = 
Based on slides by Costas Busch 13
Example

NFA for L = {a nb}*


*
1

L1 = {a b}
n
a
 b


Based on slides by Costas Busch 14
Reverse
R
NFA for L
M M

L( M ) = L L( M ) = LR

1. Reverse all transitions

2. Make the initial state accept state


and the accept state initial state
Based on slides by Costas Busch 15
Example

M1
a
L1 = {a b} n
b

M 1
a
L = {ba }
R
1
n
b

Based on slides by Costas Busch 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
Based on slides by Costas Busch 17
Example

M1
a a, b

L1 = {a b} n b a, b

M 1
a a, b
L1 = {a, b} − {a b} * n

b a, b

Based on slides by Costas Busch 18


NFAs cannot be used for complement
Make accept states regular
and vice-versa

NFA M NFA M 

L( M ) = {} L( M ) = { }  L( M )
it is not the
L( M ) =  = {a, b}
* *
complement

Based on slides by Costas Busch 19


Same example with DFAs
Make accept states regular
and vice-versa
DFA M DFA M 
a, b a, b

L( M ) = {} L( M ) = {a, b}* = L( M )
it is the
L( M ) =  = {a, b}
* *
complement

Based on slides by Costas Busch 20


Intersection

L1 regular

we show L1  L2
L2 regular regular

Based on slides by Costas Busch 21


DeMorgan’s Law: L1  L2 = L1  L2

L1 , L2 regular, regular

L1 , L2 regular, regular

L1  L2 regular

L1  L2 regular
L1  L2 regular
Based on slides by Costas Busch 22
Example

L1 = {a b} n regular
L1  L2 = {ab}
L2 = {ab, ba} regular regular

Based on slides by Costas Busch 23


Another Proof for Intersection Closure

Machine M1 Machine M2
DFA for L1 DFA for L2

Construct a new DFA M that accepts L1  L2

M simulates in parallel M1 and M2


Based on slides by Costas Busch 24
States in M

qi , p j

State in M1 State in M2

Based on slides by Costas Busch 25


DFA M1 DFA M2

q1 a q2 p1 a p2
transition transition

DFA M

q1, p1 a q2 , p2
New transition
Based on slides by Costas Busch 26
DFA M1 DFA M2

q0 p0
initial state initial state

DFA M

q0 , p0
New initial state
Based on slides by Costas Busch 27
DFA M1 DFA M2

qi pj pk

accept state accept states

DFA M
qi , p j qi , pk

New accept states

Both constituents must be accepting states


Based on slides by Costas Busch 28
Example:

n0 m0
L1 = {a b} n
L2 = {ab } m

M1 M2
a b
q0 b q1 p0 a p1
a, b b a
q2 p2
a, b a, b
Based on slides by Costas Busch 29
DFA M for intersection

L( M ) = {a b}  {ab } = {ab}
n m

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
Based on slides by Costas Busch 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 2 until no new states


are added

4. Designate accept states


Based on slides by Costas Busch 31
Automaton for intersection

L = {a b}  {ab } = {ab}
n m

q0 , p0

initial state

Based on slides by Costas Busch 32


Automaton for intersection

L = {a b}  {ab } = {ab}
n m

q0 , p0 a q0 , p1
add transition and new state
for symbol a M1 M2

q0 a q0 p0 a p1

q0 , p0 a q0 , p1

Based on slides by Costas Busch 33


Automaton for intersection

L = {a b}  {ab } = {ab}
n m

q0 , p0 a q0 , p1

b M1 M2

q0 b q1 p0 b p2
q1, p2

add transition and new state M


for symbol b b
q0 , p0 q1 , p2

Based on slides by Costas Busch 34


Automaton for intersection

L = {a b}  {ab } = {ab}
n m

Repeat until no new states can be added 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

Based on slides by Costas Busch 35


Automaton for intersection

L = {a b}  {ab } = {ab}
n m

q1 accept state for M 1


a, b
p1 accept state for M 2 add Accept state

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

Based on slides by Costas Busch 36


Intersection DFA M:

simulates in parallel M1 and M2

accepts string w if and only if:

M1 accepts string w
and M2 accepts string w

L ( M ) = L ( M1 )  L ( M 2 )
Based on slides by Costas Busch 37
Follow-Up / Further Reading
• Read Chapter 1.2 of Sipser
• Read Chapter 2.5 of Wilson

Based on slides by Costas Busch 38

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy