Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
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
L1
L1
and
L2
:
Regular
Languages
R
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:
a
q0
L L ( a * b)
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
nm
...........
29
The Pigeonhole Principle
n
pigeons
m
pigeonholes
nm
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
In walks of strings:
a state
is repeated
aabb
bbaa
abbabb
abbbabbabb...
b
q1
b
b
a
q2
a
a
q3
b
q4
a
35
If string
w
has length
| w | 4:
Then the transitions of string w
are more than the states of the DFA
Thus, a state must be repeated
b
q1
b
b
a
q2
a
a
q3
b
q4
a
36
In general, for any DFA:
String
w
has length
A state
q
must be repeated in the walk of
walk of
number of states
w
w
......
q
......
Repeated state
37
In other words for a string
w:
a
transitions are pigeons
q
states are pigeonholes
walk of
w
......
q
......
Repeated state
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
of DFA
then, from the pigeonhole principle:
a state
q
is repeated in the walk
......
walk
q
w
w
......
42
Let
q
be the first state repeated
......
walk
q
w
......
43
Write
w x y z
y
......
x
q
......
z
44
Observations:
length
length
| x y | m number
of states
of DFA
| y | 1
y
......
x
q
......
z
45
Observation:
The string
is accepted
xz
y
......
x
q
......
z
46
Observation:
The string
is accepted
xyyz
y
......
x
q
......
z
47
Observation:
The string
is accepted
xyyyz
y
......
x
q
......
z
48
In General:
The string
is accepted
i
xy z
i 0, 1, 2, ...
y
......
x
q
......
z
49
In General:
i
x y z ∈L
i 0, 1, 2, ...
The original language
y
......
x
q
......
z
50
In other words, we described:
The Pumping Lemma !!!
51
The Pumping Lemma:
• Given a infinite regular language
• there exists an integer
• for any string
• we can write
• with
w L
L
m
with length
| w| m
w x y z
| x y | m and | y | 1
• such that:
xy z L
i
i 0, 1, 2, ...
52
Applications
of
the Pumping Lemma
53
Theorem: The language L {a nb n : n 0}
is not regular
Proof:
Use the Pumping Lemma
54
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
55
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
We pick
| w| m
wa b
m m
56
Write:
a b xyz
m m
From the Pumping Lemma
it must be that length | x
y | m, | y | 1
m
xyz a b
m m
a...aa...aa...ab...b
x
Thus:
m
y
y a , k 1
z
k
57
x y za b
y a , k 1
m m
k
From the Pumping Lemma:
xy z L
i
i 0, 1, 2, ...
Thus:
xy z L
2
58
x y za b
y a , k 1
m m
k
From the Pumping Lemma:
xy z L
2
mk
m
xy z a...aa...aa...aa...ab...b L
2
x
Thus:
a
y
y
z
m k m
b L
59
a
BUT:
m k m
b L
k ≥1
L {a b : n 0}
n n
a
m k m
b L
CONTRADICTION!!!
60
Therefore:
Our assumption that L
is a regular language is not true
Conclusion: L is not a regular language
61
Non-regular language
{a b : n 0}
n n
Regular languages
62