More Properties of Regular Languages We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.

Download Report

Transcript More Properties of Regular Languages We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.

More Properties
of
Regular Languages
1
We have proven
Regular languages are closed under:
Union
Concatenation
Star operation
Reverse
2
Namely, for regular languages
Union
L1  L2
Concatenation
L1L2
Star operation

L1
Reverse
R
L1
L1
and
L2
:
Regular
Languages
3
We will prove
Regular languages are closed under:
Complement
Intersection
4
Namely, for regular languages
Complement
Intersection
L1
and
L2 :
L1
L1  L2
Regular
Languages
5
Complement
Theorem: For regular language L
the complement L is regular
Proof:
Take DFA that accepts L and make
• nonfinal states final
• final states nonfinal
Resulting DFA accepts L
6
Example:
L  L ( a * b)
a
q0
b
q1
a, b
a, b
q2
L  L(a * a * b(a  b)(a  b)*)
a, b
a
q0
b
q1
a, b
q2
7
Intersection
Theorem: For regular languages
the intersection
Proof:
L1
L1  L2
and L2
is regular
Apply DeMorgan’s Law:
L1  L2  L1  L2
8
L1 , L2
regular
L1 , L2
regular
L1  L2
regular
L1  L2
regular
L1  L2
regular
9
Standard Representations
of
Regular Languages
10
Standard Representations
of Regular Languages
Regular Languages
DFAs
NFAs
Regular
Grammars
Regular
Expressions
11
When we say:
We mean:
We are given
a Regular Language
L
Language L is in a standard
representation
12
Elementary Questions
about
Regular Languages
13
Membership Question
Question:
Answer:
Given regular language L
and string w
how can we check if w 
L?
Take the DFA that accepts L
and check if w is accepted
14
DFA
w
w L
DFA
w
w L
15
Question:
Answer:
Given regular language L
how can we check
if L is empty: ( L  ) ?
Take the DFA that accepts
L
Check if there is a path from
the initial state to a final state
16
DFA
L
DFA
L
17
Question:
Given regular language
how can we check
if L is finite?
Answer: Take the DFA that accepts
L
L
Check if there is a walk with cycle
from the initial state to a final state
18
DFA
L is infinite
DFA
L is finite
19
Question: Given regular languages L1 and
how can we check if L1  L2 ?
Answer:
Find if
L2
( L1  L2 )  ( L1  L2 )  
20
( L1  L2 )  ( L1  L2 )  
and
L1  L2  
L1
L2 L
2
L1  L2
L1  L2  
L2
L1 L1
L2  L1
L1  L2
21
( L1  L2 )  ( L1  L2 )  
L1  L2  
L1
or
L1  L2  
L2
L2
L1  L2
L1
L2  L1
L1  L2
22
Non-regular languages
23
{a b : n  0}
n n
Non-regular languages
{ww : w {a, b}*}
R
Regular languages
a *b
b*c  a
b  c ( a  b) *
etc...
24
How can we prove that a language
is not regular?
L
Prove that there is no DFA that accepts
L
Problem: this is not easy to prove
Solution: the Pumping Lemma !!!
25
The Pigeonhole Principle
26
4 pigeons
3 pigeonholes
27
A pigeonhole must
contain at least two pigeons
28
n pigeons
...........
m pigeonholes
nm
...........
29
The Pigeonhole Principle
n pigeons
m pigeonholes
nm
There is a pigeonhole
with at least 2 pigeons
...........
30
The Pigeonhole Principle
and
DFAs
31
DFA with
b
q1
4 states
b
b
a
q2 b
a
q3
b
q4
a
32
In walks of strings:
b
q1
no state
is repeated
a
aa
aab
b
b
a
q2
a
a
q3
b
q4
a
33
In walks of strings:
a state
is repeated
aabb
bbaa
abbabb
abbbabbabb...
b
q1
b
b
a
q2
a
a
q3
b
q4
a
34
If the walk of string
w has length | w |  4
then a state is repeated
b
q1
b
b
a
q2
a
a
q3
b
q4
a
35
Pigeonhole principle for any DFA:
If in a walk of a string w
transitions  states of DFA
then a state is repeated
b
q1
b
b
a
q2
a
a
q3
b
a
q4
36
In other words for a string
w:
a
transitions are pigeons
q
states are pigeonholes
b
q1
b
b
a
q2
a
a
q3
b
a
q4
37
In general:
A string
w has length  number of states
A state
q must be repeated in the walk w
walk of
w
......
q
......
38
The Pumping Lemma
39
Take an infinite regular language L
DFA that accepts
L
m
states
40
Take string
w with w L
There is a walk with label
w:
.........
walk
w
41
If string
w has length | w |  m number
of states
then, from the pigeonhole principle:
a state
q is repeated in the walk w
......
walk
q
w
......
42
Write
w x y z
y
......
x
q
......
z
43
Observations:
length
length
| x y |  m number
of states
| y | 1
y
......
x
q
......
z
44
Observation:
The string
x z is accepted
y
......
x
q
......
z
45
Observation:
The string
is accepted
xyyz
y
......
x
q
......
z
46
Observation:
The string
is accepted
xyyyz
y
......
x
q
......
z
47
In General:
The string
is accepted
i
xy z
i  0, 1, 2, ...
y
......
x
q
......
z
48
In other words, we described:
The Pumping Lemma !!!
49
The Pumping Lemma:
• Given a infinite regular language
• there exists an integer
• for any string
• we can write
• with
L
m
w L with length | w |  m
w x y z
| x y |  m and | y |  1
• such that:
xy z  L
i
i  0, 1, 2, ...
50
Applications
of
the Pumping Lemma
51
Theorem: The language L  {a nb n : n  0}
is not regular
Proof:
Use the Pumping Lemma
52
L  {a b : n  0}
n n
Assume for contradiction
that L is a regular language
Since L is infinite
we can apply the Pumping Lemma
53
L  {a b : n  0}
n n
Let
m be the integer in the Pumping Lemma
Pick a string
w such that: w  L
length
Example:
pick
| w| m
wa b
m m
54
Write:
a b xyz
m m
From the Pumping Lemma
it must be that: length | x
y |  m, | y | 1
m
Therefore:
m m
a b
m
 a...aa...a...ab...b
x
y  a , k 1
y
z
k
55
x y za b
y  a , k 1
m m
We have:
From the Pumping Lemma:
k
xy z  L
i
i  0, 1, 2, ...
Thus:
xy z  L
2
xy z  xyyz  a
2
m k m
b
 L
56
Therefore:
BUT:
a
m k m
b L
L  {a b : n  0}
n n
a
m k m
b L
CONTRADICTION!!!
57
Therefore:
Our assumption that L
is a regular language is not true
Conclusion: L is not a regular language
58
Non-regular languages
{a b : n  0}
n n
Regular languages
a *b
b*c  a
b  c ( a  b) *
etc...
59