Properties of Regular Languages: Reading: Chapter 4
Properties of Regular Languages: Reading: Chapter 4
Properties of Regular Languages: Reading: Chapter 4
Languages
Reading: Chapter 4
1
Topics
1) How to prove whether a given
language is regular or not?
3) Minimization of DFAs
2
Some languages are not
regular
When is a language is regular?
if we are able to construct one of the
following: DFA or NFA or -NFA or regular
expression
When is it not?
If we can show that no FA can be built for a
language
3
How to prove languages are
not regular?
What if we cannot come up with any FA?
A) Can it be language that is not regular?
B) Or is it that we tried wrong approaches?
Rationale…
Let {p0,p1,… pk} be the sequence of states that the
DFA should have visited after consuming the first k
symbols in w which is 0k
But there are only k states in the DFA!
==> at least one state should repeat somewhere
along the path (by ++ Principle)
==> Let the repeating state be pi=pJ for i < j
==> We can fool the DFA by inputing 0(k-(j-i))1k and
still get it to accept (note: k-(j-i) is at most k-1).
==> DFA accepts strings w/ unequal number of 0s
and 1s, implying that the DFA is wrong!
6
The Pumping Lemma for
Regular Languages
What it is?
The Pumping Lemma is a property
of all regular languages.
How is it used?
A technique that is used to show that
a given language is not regular
7
Pumping Lemma for Regular
Languages
Let L be a regular language
11
The Purpose of the Pumping
Lemma for RL
To prove that some languages cannot
be regular.
12
How to use the pumping
lemma?
Think of playing a 2 person game
Role 1: We claim that the language cannot be
regular
13
How to use the pumping
lemma? (The Steps)
1. (we) L is not regular.
2. (adv.) Claims that L is regular and gives you
a value for N as its P/L constant
3. (we) Using N, choose a string w L s.t.,
1. |w| ≥ N,
2. Using w as the template, construct other words
wk of the form xykz and show that at least one
such wk L
=> this implies we have successfully broken the
pumping lemma for the language, and hence that the
adversary is wrong.
(Note: In this process, we may have to try many values of k,
starting with k=0, and then 2, 3, .. so on, until wk L ) 14
Note: We don’t have any control over N, except that it is positive.
We also don’t have any control over how to split w=xyz,
but xyz should respect the P/L conditions (1) and (2).
3. Using N, we construct
our template string w
4. Demonstrate to the
adversary, either
through pumping up or
down on w, that some
string wk L
(this should happen
regardless of w=xyz) 15
Note: This N can be anything (need not necessarily be the #states in the DFA.
It’s the adversary’s choice.)
Example of using the Pumping Lemma to
prove that a language is not regular
Let Leq = {w | w is a binary string with equal number
of 1s and 0s}
Your Claim: Leq is not regular
Proof:
adv.
By contradiction, let Leq be regular
P/L constant should exist adv.
Let N = that P/L constant
you
Consider input w = 0N1N
(your choice for the template string)
you
By pumping lemma, we should be able to break
w=xyz, such that:
1) y≠
2) |xy|≤N
3) For all k≥0, the string xykz is also in L 16
Template string w = 0N1N = 00 …. 011 … 1
N N
Proof…
Because |xy|≤N, xy should contain only 0s you
(This and because y≠ , implies y=0+)
Therefore x can contain at most N-1 0s
Also, all the N 1s must be inside z
By (3), any string of the form xykz Leq for all k≥0
Setting k=0 is Case k=0: xz has at most N-1 0s but has N 1s
referred to as
“pumping down” Therefore, xy0z Leq
This violates the P/L (a contradiction)
18
Example 3: Pumping Lemma
Claim: L = { 0i | i is a perfect square} is not regular
Proof:
By contradiction, let L be regular.
P/L should apply
Let N = P/L constant
Choose w=0N2
By pumping lemma, w=xyz satisfying all three rules
By rules (1) & (2), y has between 1 and N 0s
By rule (3), any string of the form xykz is also in L for all k≥0
Case k=0:
#zeros (xy0z) = #zeros (xyz) - #zeros (y)
N – N ≤ #zeros (xy0z) ≤ N2 - 1
2
(Notice that the above should hold for all possible N values of N>0. Therefore,
this completes the proof.)
20
Closure properties of Regular
Languages
21
Closure properties for Regular
Languages (RL) This
Thisisisdifferent
different
from
fromKleene
Kleene
closure
Closure property: closure
If a set of regular languages are combined using
an operator, then the resulting language is also
regular
Regular languages are closed under:
Union, intersection, complement, difference
Reversal
Kleene closure
Concatenation Now, lets prove all of this!
Homomorphism
Inverse homomorphism
22
RLs are closed under union
IF L and M are two RLs THEN:
q0 qi qF2 q0 qi qF2
…
…
qFk qFk
25
DFA construction for L ∩ M
AL = DFA for L = {QL, ∑ , qL,FL, δL }
AM = DFA for M = {QM, ∑ , qM,FM, δM }
Build AL ∩ M = {QLx QM,∑, (qL,qM), FLx FM,δ}
such that:
δ((p,q),a) = (δL(p,a), δM(q,a)), where p in QL, and q in
QM
This construction ensures that a string w will
be accepted if and only if w reaches an
accepting state in both input DFAs.
26
DFA construction for L ∩ M
DFA for L DFA for M
qF1 pF1
a a
q0 qi qj qF2 p0 pi pj pF2
…
DFA for LM
(qF1 ,pF1)
a
(qi ,pi) (qj ,pj)
…
(q0 ,p0)
27
RLs are closed under set
difference
Closed under intersection
We observe: Closed under
L-M=L∩M complementation
28
RLs are closed under reversal
Reversal of a string w is denoted by wR
E.g., w=00111, wR=11100
Reversal of a language:
LR = The language generated by
29
-NFA Construction for LR
New -NFA for LR
DFA for L
qF1
q0 qi
a
qj qF2 q’0 New start
state
…
Make the
old start state
as the only new qFk
final state
h(a)
…
qFk
Inverse homomorphism
Let h: ∑--->T*
Let M be a language over alphabet T
Yes
Decision
Input problem
(generally solver
a question)
No
36
Membership question
Decision Problem: Given L, is w in L?
Possible answers: Yes or No
Approach:
1. Build a DFA for L
2. Input w to the DFA
3. If the DFA ends in an accepting state,
then yes; otherwise no.
37
Emptiness test
Decision Problem: Is L=Ø ?
Approach:
On a DFA for L:
1. From the start state, run a reachability test, which
returns:
1. success: if there is at least one final state that is
reachable from the start state
2. failure: otherwise
2. L=Ø if and only if the reachability test fails
X FINITE
0
X q6 1
INFINITE
X
0
to this
due
1
40
Equivalence & Minimization of
DFAs
41
Applications of interest
Comparing two DFAs:
L(DFA1) == L(DFA2)?
42
When to call two states in a DFA
“equivalent”?
Past doesn’t matter - only future does!
45
Table Filling Algorithm - step
by step
A =
0 1
B =
0 1 0
A C E G C =
1 0 1
0 1 D =
1 1 0 E X X X X =
B D F H
1 0 F X =
0
G X =
1. Mark X between accepting vs. non-accepting state
H X =
A B C D E F G H
46
Table Filling Algorithm - step
by step
A =
0 1
B =
0 1 0
A C E G C X =
1 0 1
0 1 D X =
1 1 0 E X X X X =
B D F H
1 0 F X =
0
G X X =
1. Mark X between accepting vs. non-accepting state
H X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
47
Table Filling Algorithm - step
by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X =
1 1 0 E X X X X =
B D F H
1 0 F X =
0
G X X X =
1. Mark X between accepting vs. non-accepting state
H X X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
48
Table Filling Algorithm - step
by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
1 1 0 E X X X X =
B D F H
1 0 F X X =
0
G X X X X =
1. Mark X between accepting vs. non-accepting state
H X X = X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
49
Table Filling Algorithm - step
by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
1 1 0 E X X X X =
B D F H
1 0 F X X X =
0
G X X X = X =
1. Mark X between accepting vs. non-accepting state
H X X = X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
50
Table Filling Algorithm - step
by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
1 1 0 E X X X X =
B D F H
1 0 F X X X =
0
G X X X = X X =
1. Mark X between accepting vs. non-accepting state
H X X = X X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
51
Table Filling Algorithm - step
by step
A =
0 1
B =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
1 1 0 E X X X X =
B D F H
1 0 F X X X =
0
G X X X = X X =
1. Mark X between accepting vs. non-accepting state
H X X = X X X X =
2. Look 1- hop away for distinguishing states or strings A B C D E F G H
52
Table Filling Algorithm - step
by step
A =
0 1
B = =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
1 1 0 E X X X X =
B D F H
1 0 F X X X X X =
0
G X X X = X X =
. Mark X between accepting vs. non-accepting state
H X X = X X X X =
. Pass 1: A B C D E F G H
Look 1- hop away for distinguishing states or strings
. Pass 2:
Look 1-hop away again for distinguishing states or strings
continue….
53
Table Filling Algorithm - step
by step
A =
0 1
B = =
0 1 0
A C E G C X X =
1 0 1
0 1 D X X X =
1 1 0 E X X X X =
B D F H
1 0 F X X X X X =
0
G X X X = X X =
. Mark X between accepting vs. non-accepting state
H X X = X X X X =
. Pass 1: A B C D E F G H
Look 1- hop away for distinguishing states or strings
. Pass 2:
Look 1-hop away again for distinguishing states or strings Equivalences:
continue…. • A=B
• C=H
• D=G
54
Table Filling Algorithm - step
by step
0 1 0 1
0 1 0 0 1
A C E G A C E
1 0 1 1 0
0 1 0
1 1 0 1
B D F H D F
1 0 1 0
0
Equivalences:
• A=B
• C=H
• D=G
55
Table Filling Algorithm –
special case
A =
0 1
B =
0 1 0
A C E G C =
1 0 1
0 1 D =
1 1 0 E ? =
B D F H
1 F =
0
0 G =
H =
A B C D E F G H
Q) What happens if the input DFA
has more than one final state?
Can all final states initially be treated
as equivalent to one another?
56
Putting it all together …
57
Are Two DFAs Equivalent?
Unified DFA DFA1
q0 …
Is q0 ≡ q0’?
: if yes, then DFA1≡DFA2
DFA2 : else, not equiv.
q0’ …
Simplification of DFAs
How to remove unreachable states?
59