SSK5204 - Chapter 4: Properties of Regular Languages
SSK5204 - Chapter 4: Properties of Regular Languages
SSK5204 - Chapter 4: Properties of Regular Languages
Closure properties
Example
(0+1)*101
Example
Complement
Example
(0+1)*101(0+1)*
NFA
DFA
NO!
0, 1
q0
q1
q2
(0+1)*10
q1
q2
(0+1)*
0, 1
q0
Intersection
Examples:
L = (0 + 1)*11
L = 1*
L L = 1*11
L = (0 + 1)*10
L = 1*
L L =
10
NFA
DFA
An example
1
M
r0
1
0
r1
s0
L = even number of 0s
r0, s0
1
1
s1
L = odd number of 1s
1
1
r1, s0
r0, s1
0
1
1
r1, s1
M and M
DFA for L L
(ri, sj)
accepting F for M
F for M
states
F F = {(ri, sj): ri F, sj F}
M and M
transitions
ri
si
14
a
a
rj
in M
sj
in M
ri, si
rj, sj
Reversal
wR = evac
15
LR = {tac, god}
(0+1)*101
101(0+1)*
16
How do we argue?
regular
expression
17
NFA
DFA
18
reversal ER
a (alphabet symbol)
E1 + E2
E1R + E2R
E1E2
E2RE1R
E1*
(E1R)*
19
A question
LDUP = {ww: w L}
regular
expression
20
NFA
DFA
A question
LDUP
L = {a, b}
= LL
21
NFA for L
NFA for L
q1
An example
L = 0*1 is regular
LDUP = {1, 01, 001, 0001, ...}
LDUP = {11, 0101, 001001, 00010001, ...}
= {0n10n1: n 0}
22
An example
0
01
001
0001
Non-regular languages
24
A non-regular language
An example
We reason by contradiction:
25
A non-regular language
imaginary DFA for L with n states
26
A non-regular language
0
M
0
0r1n+1
27
Pigeonhole principle
Suppose you are tossing n + 1 balls into n
bins. Then two balls end up in the same bin.
28
A non-regular language
0
M
0
0r1n+1
29
A non-regular language
0
M
0
0r1n+1
30
a1
ak
ak+1 an-1
an+1am
31
32
Arguing non-regularity
If L is regular, then:
34
you
choose z L
choose i
you win if uviw L
Arguing non-regularity
35
you
choose z L
choose i
you win if uviw L
Example
adversary
you
1 choose n
2 write z = uvw (|uv| n,|v| 1)
choose z L
choose i
you win if uviw L
L = {0n1n: n 0}
adversary
you
z = 0 n 1n
i=2
1 choose
write z = uvw
2 n
000000000000000111111111111111
0000000000000000000111111111111111
36
uv2w = 0n+k1n L
Example
LDUP = {0n10n1: n 0}
adversary
you
z = 0n10n1
i=2
1 choose
write z = uvw
2 n
uv2w = 0n+k10n1 L
000000000000001000000000000001
0000000000000000001000000000000001
37
38
S = {0, 1}
Example
L1 = {x: x has same number of 0s and 1s}
adversary
you
z = 0 n 1n
i=2
1 choose
write z = uvw
2 n
uv2w = 0n+k1n L3
00000000000000011111111111111
v
w
1 u
0000000000000000000111111111111111
39
Example
L2 = {x: x = 0m1n, m > n 0}
adversary
you
z = 0n+11n
i=0
1 choose
write z = uvw
2 n
uv0w
000000000000000111111111111111
00000000000111111111111111
40
= 0j+l1n+1 L2
Example
L3 = {x: x has same number of 01s and 11s}
adversary
you
1 choose
z = (01)n(11)n
nn = 1
z = 0111 L4
has too many 11s
z = 011
z = 010111
z = 010101111
z = (01)n1n
has n 01s and n 11s
Example
L3 = {x: x has same number of 01s and 11s}
adversary
you win!
z = (01)n1n
i=0
1 choose
write z = uvw
2 n
010101010101010111111111
010101010101010111111111
so uv0w L3
010101010101010111111111
or
or
42
u v
w
w
Example
L4 = {x: x has same number of 01s and 10s}
adversary
you
z = (01)n(10)n
1 choose
43
n=1
n=2
z = 0110
z = 01011010
n=3
z = 010101101010
Example
L4 = {x: x has same number of 01s and 10s}
is regular!
adversary
you
z = (01)n(10)n
i = 20
1 choose
write z = uvw
2 n
010101101010
u v
01010101101010
u v v
44
5 01 patterns
5 10 patterns
6 01 patterns
6 10 patterns
0101101010
4 01 patterns
4 10 patterns
Example
1
1
r0
q0
s0
1
0
one more 10
one more 01
r1
s1
Example
L4 = {x: x has different number of 0s than 1s}
adversary
1 choose
you
z=?
DFA minimization
47
Example
Smaller DFA
0
q0
1
0
q1
q2
q3
inputs:
e, 1, 11, 111
Pigeonhole principle
Suppose you are tossing n + 1 balls into n
bins, and Then two balls end up in the
same bin.
A smaller DFA
11, 111
ends in 111
52
1, 11
A smaller DFA
11, 111
ends in 111
53
e, 1
No smaller DFA!
(e, 11)
(1, 11)
(e, 111)
(1, 111)
we conclude that
1
0
q1
0
0
54
q2
q3
(11, 111)
DFA minimization
accept
0
q0
1
0
q1
q2
q3
0
0
minimal DFA
56
every pair of
states is
distinguishable
Distinguishable states
w1
w2
wk-1
wk
w1
w2
wk-1
wk
57
q1
0
(q0, q1)
distinguishable by 01
(q0, q2)
distinguishable by 1
(q0, q3)
distinguishable by e
(q1, q2)
distinguishable by 1
(q1, q3)
distinguishable by e
(q2, q3)
distinguishable by e
58
1
0
q2
q3
DFA is minimal
q3
(q0, q3)
distinguishable by e
(q1, q3)
distinguishable by e
(q2, q3)
distinguishable by e
(q1, q2)
distinguishable by 0
(q0, q2)
distinguishable by 0
(q0, q1)
indistinguishable
59
0
q01
1
0, 1
q2
0, 1
1
1
0, 1
0, 1
q1
q2
q3
indistinguishable
pairs can be merged
0, 1
q2
q01
1
q1
0, 1
q3
0, 1
(q0, q2)
distinguishable by e
(q1, q2)
distinguishable by e
(q0, q3)
distinguishable by e
(q1, q3)
distinguishable by e
(q0, q1)
indistinguishable
(q2, q3)
indistinguishable
60
0, 1
0, 1
q23
Rule 2:
q1
q1
a
q2
Rule 3:
61
q2
If q is accepting and q is
rejecting
Mark (q, q) as distinguishable
(x)
If (q1, q1) are marked,
Mark (q2, q2) as distinguishable
(x)
Unmarked pairs are
indistinguishable
Merge them into groups
q0
qe
1
0
q1
q0
q00
q01
1
q10
0
0
0
q11
q00
q01
q10
q11
62
q1
q0
qe
1
0
q1
q0
q00
q01
1
q10
q1
1
0
0
0
q11
q00
q01
q10
q11
x x x x x x
qe q0 q1 q00 q01 q10
63
q0
qe
1
0
q1
q0
q00
q01
1
q10
q1
1
0
0
0
q11
q00
q01
q10
q11
0 1
x x x x x x
qe q0 q1 q00 q01 q10
q0
qe
1
0
q1
q0
q00
q01
1
q10
q1
1
0
0
0
q11
q00
q01
0 1
q10
q11
x x x x x x
qe q0 q1 q00 q01 q10
q0
qe
1
0
q1
q0
q00
q01
1
q10
q1
1
0
0
0
q11
q00
q01
x x
q10
x
x
x x x x x x
q11
1
x x
x
66
q0
qe
1
0
q1
q0
q00
q01
1
q10
q1
1
0
0
0
q11
q00
q01
q10
q11
x x0 1
x
x x
x
x
x
x x x x x x
qe q0 q1 q00 q01 q10
q0
qe
1
0
q1
q0
q00
q01
1
q10
q1
1
0
0
0
q11
q00
1 x
q01
x x
q10
x
x
x x x x x x
q11
1
x x
x
q0
qe
1
0
q1
q0
q00
q01
1
q10
q1
1
0
0
0
q11
q00
q01
x x
q10
x
x
x x x x x x
q11
1
x x
x
69
qe
q10
q1
q11
q0
q1
x x
q00
q01
x x
q10
x
x
x x x x x x
q11
70
q01
qe
q10
q1
q11
B
C
q0
q1
q00
q01
q10
q11
A
x
A
x
A
x
x
A
x
A
x
x
B x
x A x
x x x x
71
q0
qe
1
0
q1
q0
q00
q01
1
q10
q1
1
0
q01
q00
q10
q11
q11
A
x
A
x
A
x
x
A
x
A
x
x
B x
x A x
x x x x
minimized DFA:
qA
1
0
qB
0
72
qC
1
0
qB
qC
qB
qC
1
e e
qA qB
73