Regular Language Properties
Regular Language Properties
Languages
1
Topics
1) How to prove whether a given
language is regular or not?
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?
5
How to prove languages are
not regular?
The tool used for proving that a
language is not regular is the Pumping
Lemma.
6
The Pumping Lemma
Theorem 1: (the Pumping Lemma for regular languages):
Let 𝐿 be a regular language. Then there exists a constant
𝑛 (which depends on 𝐿) such that for every 𝑤 ∈ 𝐿,
where
𝑤 ≥ 𝑛, there exists strings 𝑥, 𝑦, and 𝑧 such
that
i. 𝑤𝑥𝑦= 𝑥𝑦𝑧,
≤ 𝑛,
ii. 𝑦 ≥ 1, and
iii.for all 𝑘 ≥ 0, 𝑥𝑦 𝑘 𝑧 ∈
iv. 𝐿.
7
Proof of the Pumping Lemma
Theorem 1: Let 𝐿 be a regular language. Then there exists a constant 𝑛 (which
depends on 𝐿) such that for every 𝑤 ∈ 𝐿, where 𝑤 ≥ 𝑛, there exists strings 𝑥, 𝑦,
and 𝑧 such that (i) 𝑤 = 𝑥𝑦𝑧, (ii) 𝑥𝑦≤ 𝑛, (iii) 𝑦 ≥ 1, and (iv) for all 𝑘 ≥ 0, 𝑥𝑦 𝑘 𝑧
∈ 𝐿.
8
Proof of the Pumping Lemma
Theorem 1: Let 𝐿 be a regular language. Then there exists a constant 𝑛 (which
depends on 𝐿) such that for every 𝑤 ∈ 𝐿, where 𝑤 ≥ 𝑛, there exists strings 𝑥, 𝑦,
and 𝑧 such that (i) 𝑤 = 𝑥𝑦𝑧, (ii) 𝑥𝑦≤ 𝑛, (iii) 𝑦 ≥ 1, and (iv) for all 𝑘 ≥ 0, 𝑥𝑦 𝑘 𝑧
∈ 𝐿.
9
Proof of the Pumping Lemma
Theorem 1: Let 𝐿 be a regular language. Then there exists a constant 𝑛 (which
depends on 𝐿) such that for every 𝑤 ∈ 𝐿, where 𝑤 ≥ 𝑛, there exists strings 𝑥, 𝑦,
and 𝑧 such that (i) 𝑤 = 𝑥𝑦𝑧, (ii) 𝑥𝑦≤ 𝑛, (iii) 𝑦 ≥ 1, and (iv) for all 𝑘 ≥ 0, 𝑥𝑦 𝑘 𝑧
∈ 𝐿.
𝑦
𝑥 𝑧
Start 𝑞0
𝑞
The second occurrence of state 𝑞 must occur
within the first 𝑛 symbols of 𝑤, so 𝑥𝑦≤ 𝑛.
Also, 𝑦 ≥ 1.
It must be possible to repeat the “𝑦-loop” 0 or
more
times, and the resulting string will still be
accepted.
Therefore, 𝑥𝑦 𝑘 𝑧 ∈ 𝐿, for any 𝑘 ≥ 0.
10
Using the Pumping Lemma
To show that a language 𝐿 is not regular, show that
the conditions of the Pumping Lemma do not
hold.
Formally, the Pumping Lemma says:
∃𝑛
∷ (∀𝑤: 𝑤 ∈ 𝐿 ∧ 𝑤 ≥𝑛
∷ (∃𝑥, 𝑦, 𝑧: 𝑥𝑦𝑧 = 𝑤 ∧ 𝑥𝑦 ≤ 𝑛 ∧ 𝑦 ≥ 1
∷ ∀𝑘: 𝑘 ≥ 0 ∷ 𝑥𝑦 𝑘 𝑧 ∈ 𝐿 ))
11
Using the Pumping Lemma
Toshow that a language 𝐿 is not regular, show that
the conditions of the Pumping Lemma do not
hold.
The negation of the Pumping Lemma is:
∀𝑛
∷ (∃𝑤: 𝑤 ∈ 𝐿 ∧ 𝑤 ≥𝑛
∷ (∀𝑥, 𝑦, 𝑧: 𝑥𝑦𝑧 = 𝑤 ∧ 𝑥𝑦 ≤ 𝑛 ∧ 𝑦 ≥ 1
∷ ∃𝑘: 𝑘 ≥ 0 ∷ 𝑥𝑦 𝑘 𝑧 ∉ 𝐿 ) )
12
Using the Pumping Lemma
∀𝑛 No matter what 𝑛 is…
13
Using the Pumping Lemma: Example
true for 𝐿.
The proof is like a game with an adversary:
The adversary makes the “∀” choices.
We make the “∃” choices.
14
Using the Pumping Lemma: Example
∀𝑛
2 ∷ (∃𝑤: 𝑤 ∈ 𝐿 ∧ 𝑤 ≥𝑛
𝐿 = 0𝑖 | 𝑖 ≥ 1
∷ (∀𝑥, 𝑦, 𝑧: 𝑥𝑦𝑧 = 𝑤 ∧ 𝑥𝑦 ≤ 𝑛 ∧ 𝑦 ≥
Assume 𝐿 is regular (this will be a proof 1
by contradiction). ∷ ∃𝑘: 𝑘 ≥ 0 ∷ 𝑥𝑦 𝑘 𝑧 ∉ 𝐿 )
Select any 𝑛.
Let 𝑤 = 0𝑛 .
2
15
Using the Pumping Lemma: Example
(Reminder) 𝐿=
2
0𝑖 | 𝑖 ≥ 1
Let 𝑘 = 2. This means that 𝑥𝑦 𝑘 𝑧 has 𝑛 2 + 𝑦 0s.
𝑤 has 𝑛 2 0s, and any entry in 𝐿 longer than 𝑤 must
have at least 𝑛 + 1 2 0s.
𝑛 2 < 𝑛 2 + 1 ≤ 𝑛 2 + 𝑦 ≤ 𝑛 2 + 𝑛 < 𝑛 2 + 2𝑛 + 1.
The length The length of The length The length of = 𝑛 + 1 2 , the length
of 𝑤 (in 𝐿) 𝑥𝑦 2 𝑧 if 𝑦 = 1. of 𝑥𝑦 2 𝑧 𝑥𝑦 2 𝑧 if 𝑦 = 𝑛. of the next string in 𝐿.
16
Using the Pumping Lemma: 2nd Example
17
Using the Pumping Lemma: 2nd Example
18
Closure properties of Regular
Languages
19
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
20
RLs are closed under union
IF L and M are two RLs THEN:
q0 qi qF2 q0 qi qF2
…
…
qFk qFk
23
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.
24
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)
25
Example: Intersection
0 0
1 0
A B [A,C] [A,D]
0, 1 1
1 1
0
0
1 [B,C] [B,D]
0
1
0
C D
26
RLs are closed under set
difference
Closed under intersection
We observe: Closed under
L-M=L∩M complementation
27
Example:DFA for Difference 0
0
1 0
A B [A,C] [A,D]
0, 1 1
1 1
0
0
1 [B,C] [B,D]
0
1
0
C D
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
Same idea:
RS is a regular expression whose
language is LM.
R* is a regular expression whose language
is L*.
32
Homomorphisms
Substitute each symbol in ∑ (main alphabet)
by a corresponding string in T (another
alphabet)
h: ∑--->T*
Example:
Let ∑={0,1} and T={a,b}
Let a homomorphic function h on ∑ be:
h(0)=ab, h(1)=
If w=10110, then h(w) = abab = abab
In general,
h(w) = h(a1) h(a2)… h(an)
33
Given a DFA for L, how to convert it into an FA for h(L)?
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
37
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.
38
Example: Testing Membership
01011
Next
symbol
0 0,1
1 1
A B C
Start 0
Current
state
39
Example: Testing Membership
01011
Next
symbol
0 0,1
1 1
A B C
Start 0
Current
state
40
Example: Testing Membership
01011
Next
symbol
0 0,1
1 1
A B C
Start 0
Current
state
41
Example: Testing Membership
01011
Next
symbol
0 0,1
1 1
A B C
Start 0
Current
state
42
Example: Testing Membership
01011
Next
symbol
0 0,1
1 1
A B C
Start 0
Current
state
43
Example: Testing Membership
01011
Next
symbol
0 0,1
1 1
A B C
Start 0
Current
state
44
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
47
Equivalence & Minimization of
DFAs
48
Applications of interest
Comparing two DFAs:
L(DFA1) == L(DFA2)?
49
When to call two states in a DFA
“equivalent”?
Past doesn’t matter - only future does!
52
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
53
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
54
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
55
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
56
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
57
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
58
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
59
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….
60
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
61
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
62
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?
63
Putting it all together …
64
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?
66