Lecture 3: Closure Properties & Regular Expressions Jim Hook Tim Sheard Portland State University.
Properties of Regular Expressions
Transcript of Properties of Regular Expressions
![Page 1: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/1.jpg)
Costas Busch - LSU 1
Properties of Regular Languages
![Page 2: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/2.jpg)
Costas Busch - LSU 2
1L 2L
21LLConcatenation:
*
1LStar:
21 LL Union:
Are regular
Languages
For regular languages and
we will prove that:
1L
21 LL
Complement:
Intersection:
RL1Reversal:
![Page 3: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/3.jpg)
Costas Busch - LSU 3
We say Regular languages are closed under
21LLConcatenation:
Star:
21 LL Union:
1L
21 LL
Complement:
Intersection:
Reversal:
*
1L
RL1
![Page 4: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/4.jpg)
Costas Busch - LSU 4
a
b
b
aNFA
Equivalent
NFA
a
b
b
a
A useful transformation: use one accept state
2 accept states
1 accept state
![Page 5: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/5.jpg)
Costas Busch - LSU 5
NFA
Equivalent NFA
Single
accepting
state
In General
![Page 6: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/6.jpg)
Costas Busch - LSU 6
NFA without accepting state
Add an accepting state
without transitions
Extreme case
![Page 7: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/7.jpg)
Costas Busch - LSU 7
1LRegular language
11 LML
1M
Single accepting state
NFA 2M
2L
Single accepting state
22 LML
Regular language
NFA
Take two languages
![Page 8: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/8.jpg)
Costas Busch - LSU 8
}{1 baL n
a
b
1M
baL 2ab
2M
0n
Example
![Page 9: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/9.jpg)
Costas Busch - LSU 9
Union
NFA for 1M
2M
21 LL
21 LLw 21 or LwLw
![Page 10: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/10.jpg)
Costas Busch - LSU 10
a
b
ab
}{1 baL n
}{2 baL
}{}{21 babaLL n NFA for
Example
![Page 11: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/11.jpg)
Costas Busch - LSU 11
Concatenation
21LL
1M 2M
21LLw
NFA for
221121 and : LwLwwww
change to
regular state
![Page 12: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/12.jpg)
Costas Busch - LSU 12
NFA for
a
b ab
}{1 baL n}{2 baL
}{}}{{21 bbaababaLL nn
Example
![Page 13: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/13.jpg)
Costas Busch - LSU 13
Star Operation*L
Lwwwww ik :21
LML )(
NFA for
*Lwor w
M
![Page 14: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/14.jpg)
Costas Busch - LSU 14
**
1 }{ baL n
a
b
}{1 baL n
Example
NFA for
![Page 15: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/15.jpg)
Costas Busch - LSU 15
Reverse
RL
M
NFA for
M
1. Reverse all transitions
2. Make the initial state accept state
and the accept state initial state
LML )(RLML )(
![Page 16: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/16.jpg)
Costas Busch - LSU 16
}{1 baL n
a
b
1M
}{1
nR baL
a
b
1M
Example
![Page 17: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/17.jpg)
Costas Busch - LSU 17
Complement
1. Take the DFA that accepts L
M
LML )(
M
LML )(
2. Make accept states regular
and vice-versa
![Page 18: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/18.jpg)
Costas Busch - LSU 18
}{1 baL n
a
b
1M
ba,
ba,
}{*},{1 babaL n a
b
1M
ba,
ba,
Example
![Page 19: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/19.jpg)
Costas Busch - LSU 19
NFAs cannot be used for complement
Make accept states regular
and vice-versa
{})( ML
M M
)(}{)( MLML
** },{)( baML
NFA NFA
it is not the complement
![Page 20: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/20.jpg)
Costas Busch - LSU 20
Same example with DFAsMake accept states regular
and vice-versa
{})( ML
M M
)(},{)( * MLbaML
** },{)( baML
DFA DFA
ba, ba,
it is the complement
![Page 21: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/21.jpg)
Costas Busch - LSU 21
Intersection
1L regular
2L regular
We show 21 LL
regular
![Page 22: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/22.jpg)
Costas Busch - LSU 22
DeMorgan’s Law: 2121 LLLL
21 , LL regular, regular
21 , LL regular, regular
21 LL regular
21 LL regular
21 LL regular
![Page 23: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/23.jpg)
Costas Busch - LSU 23
Example
}{1 baL n
},{2 baabL
regular
regular
}{21 abLL
regular
![Page 24: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/24.jpg)
Costas Busch - LSU 24
1Lfor for 2LDFA
1M
DFA
2M
Construct a new DFA that accepts
Machine Machine
M 21 LL
M simulates in parallel and 1M 2M
Another Proof for Intersection Closure
![Page 25: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/25.jpg)
Costas Busch - LSU 25
States in M
ji pq ,
1M 2MState in State in
![Page 26: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/26.jpg)
Costas Busch - LSU 26
1M 2M
1q 2qa
transition
1p 2pa
transition
DFA DFA
11, pq a
New transition
MDFA
22, pq
![Page 27: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/27.jpg)
Costas Busch - LSU 27
0q
initial state
0p
initial state
New initial state
00 , pq
1M 2MDFA DFA
MDFA
![Page 28: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/28.jpg)
Costas Busch - LSU 28
iq
accept state
jp
accept states
New accept states
ji pq ,
kp
ki pq ,
1M 2MDFA DFA
MDFA
Both constituents must be accepting states
![Page 29: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/29.jpg)
Costas Busch - LSU 29
Example:
}{1 baL n
a
b
1M
0n
}{2mabL
b
b
2M
0q 1q 0p 1p
0m
2q2p
a
a
ba, ba,
ba,
![Page 30: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/30.jpg)
Costas Busch - LSU 30
00, pq
DFA for intersection
}{}{}{)( ababbaML mn
10, pqa
21, pq
b
ab11, pq
20, pq
a
12, pq
22, pq
b
ba,
a
b
ba,
b
a
M
![Page 31: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/31.jpg)
Costas Busch - LSU 31
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
![Page 32: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/32.jpg)
Costas Busch - LSU 32
00, pq
Automaton for intersection
}{}{}{ ababbaL mn
initial state
![Page 33: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/33.jpg)
Costas Busch - LSU 33
00, pq
Automaton for intersection
}{}{}{ ababbaL mn
10, pqa
add transition and new state
for symbol a 1M 2M
0q0qa
0p 1pa
00 , pq a
M
10 , pq
![Page 34: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/34.jpg)
Costas Busch - LSU 34
00, pq
Automaton for intersection
}{}{}{ ababbaL mn
10, pqa
21, pq
b
add transition and new state
for symbol b
1M 2M
0q1qb
0p 2p
00 , pq b
M
21, pq
b
![Page 35: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/35.jpg)
Costas Busch - LSU 35
Automaton for intersection
}{}{}{ ababbaL mn
00, pq 10, pqa
21, pq
b
ab11, pq
20, pq
a
12, pq
22, pq
b
ba,
a
b
ba,
b
a
Repeat until no new states can be added
![Page 36: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/36.jpg)
Costas Busch - LSU 36
Automaton for intersection
}{}{}{ ababbaL mn
add Accept state
00, pq 10, pqa
21, pq
b
ab11, pq
20, pq
a
12, pq
22, pq
b
ba,
a
b
ba,
b
a
accept state for
accept state for
1q1M
1p2M
![Page 37: Properties of Regular Expressions](https://reader033.fdocuments.in/reader033/viewer/2022051720/587638661a28ab68098b658d/html5/thumbnails/37.jpg)
Costas Busch - LSU 37
simulates in parallel and 1M 2M
accepts string w if and only if:
accepts string w1M
and accepts string w2M
)()()( 21 MLMLML
Intersection DFA :M