0% found this document useful (0 votes)
10 views67 pages

Lec 05

This document discusses minimizing deterministic finite automata (DFAs). It defines DFA equivalence and describes how to identify equivalent states. It then explains the table-filling algorithm for minimizing a DFA by recursively discovering distinguishable state pairs and merging equivalent states.

Uploaded by

Manikandan K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views67 pages

Lec 05

This document discusses minimizing deterministic finite automata (DFAs). It defines DFA equivalence and describes how to identify equivalent states. It then explains the table-filling algorithm for minimizing a DFA by recursively discovering distinguishable state pairs and merging equivalent states.

Uploaded by

Manikandan K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

CS 208: Automata Theory and Logic

DFA Equivalence and Minimization

Ashutosh Trivedi

b a a

start A ∀x(La (x) → ∃y.(x < y) ∧ Lb (y))


B

b
Department of Computer Science and Engineering,
Indian Institute of Technology Bombay.

Ashutosh Trivedi – 1 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
DFA Equivalence and Minimization

1. Let A = (Q, Σ, δ, q0 , F) be a DFA.


2. Recall the definition of extended transition function δ̂.
3. Let L(A, q) be the languages {w : δ̂(q, w) ∈ F}
4. Recall the language of A is defined as L(A) = L(A, q0 ).
5. Two states q1 , q2 ∈ Q are equivalent if L(A, q1 ) = L(A, q2 ).
6. We say that two DFAs A1 and A2 are equivalent iff L(A1 ) = L(A2 ).

Theorem (DFA Equivalence)


For every DFA there exists a unique (up to state naming) minimal DFA.

Ashutosh Trivedi – 2 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
DFA Equivalence and Minimization

1. Let A = (Q, Σ, δ, q0 , F) be a DFA.


2. Recall the definition of extended transition function δ̂.
3. Let L(A, q) be the languages {w : δ̂(q, w) ∈ F}
4. Recall the language of A is defined as L(A) = L(A, q0 ).
5. Two states q1 , q2 ∈ Q are equivalent if L(A, q1 ) = L(A, q2 ).
6. We say that two DFAs A1 and A2 are equivalent iff L(A1 ) = L(A2 ).

Theorem (DFA Equivalence)


For every DFA there exists a unique (up to state naming) minimal DFA.

How to minimize DFAs?

Ashutosh Trivedi – 2 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
How to minimize a DFA?

Two observations:
– Removing unreachable states: removing states unreachable from the
start state does not change the language accepted by a DFA.

Ashutosh Trivedi – 3 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
How to minimize a DFA?

Two observations:
– Removing unreachable states: removing states unreachable from the
start state does not change the language accepted by a DFA.
– Merging equivalent states: merging equivalent states does not change
the language accepted by a DFA.

Ashutosh Trivedi – 3 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
How to minimize a DFA?

Two observations:
– Removing unreachable states: removing states unreachable from the
start state does not change the language accepted by a DFA.
– Merging equivalent states: merging equivalent states does not change
the language accepted by a DFA.
Algorithms:
1. Breadth-first search or depth-first search (to identify reachable states)
2. table-filling algorithm (by E. F. Moore) (other algorithms exist due to
Hopcroft and Brzozowski)

Ashutosh Trivedi – 3 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Table-filling algorithm
– Two states are distinguishable if they are not equivalent.
– Formally, two states q1 , q2 are distinguishable, if there exists a string
w ∈ Σ∗ such that exactly one of δ̂(q1 , w) and δ(q2 , w) is an accepting
state.
– Table-filling algorithm is recursive discovery of distinguishable pairs.

Ashutosh Trivedi – 4 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Table-filling algorithm
– Two states are distinguishable if they are not equivalent.
– Formally, two states q1 , q2 are distinguishable, if there exists a string
w ∈ Σ∗ such that exactly one of δ̂(q1 , w) and δ(q2 , w) is an accepting
state.
– Table-filling algorithm is recursive discovery of distinguishable pairs.
– Basis: Pair (p, q) is distinguishable if p ∈ F and q 6∈ F.

Ashutosh Trivedi – 4 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Table-filling algorithm
– Two states are distinguishable if they are not equivalent.
– Formally, two states q1 , q2 are distinguishable, if there exists a string
w ∈ Σ∗ such that exactly one of δ̂(q1 , w) and δ(q2 , w) is an accepting
state.
– Table-filling algorithm is recursive discovery of distinguishable pairs.
– Basis: Pair (p, q) is distinguishable if p ∈ F and q 6∈ F. why?

Ashutosh Trivedi – 4 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Table-filling algorithm
– Two states are distinguishable if they are not equivalent.
– Formally, two states q1 , q2 are distinguishable, if there exists a string
w ∈ Σ∗ such that exactly one of δ̂(q1 , w) and δ(q2 , w) is an accepting
state.
– Table-filling algorithm is recursive discovery of distinguishable pairs.
– Basis: Pair (p, q) is distinguishable if p ∈ F and q 6∈ F. why?
– Induction: Pair (p, q) is distinguishable if states δ(p, a) and δ(q, a) are
distinguishable for some a ∈ Σ.

Ashutosh Trivedi – 4 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Table-filling algorithm
– Two states are distinguishable if they are not equivalent.
– Formally, two states q1 , q2 are distinguishable, if there exists a string
w ∈ Σ∗ such that exactly one of δ̂(q1 , w) and δ(q2 , w) is an accepting
state.
– Table-filling algorithm is recursive discovery of distinguishable pairs.
– Basis: Pair (p, q) is distinguishable if p ∈ F and q 6∈ F. why?
– Induction: Pair (p, q) is distinguishable if states δ(p, a) and δ(q, a) are
distinguishable for some a ∈ Σ. why?

Ashutosh Trivedi – 4 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Table-filling algorithm
– Two states are distinguishable if they are not equivalent.
– Formally, two states q1 , q2 are distinguishable, if there exists a string
w ∈ Σ∗ such that exactly one of δ̂(q1 , w) and δ(q2 , w) is an accepting
state.
– Table-filling algorithm is recursive discovery of distinguishable pairs.
– Basis: Pair (p, q) is distinguishable if p ∈ F and q 6∈ F. why?
– Induction: Pair (p, q) is distinguishable if states δ(p, a) and δ(q, a) are
distinguishable for some a ∈ Σ. why?

TABLE -F ILLING A LGORITHM:


1. D ISTINGUISHABLE = {(p, q) : p ∈ F and q 6∈ F}.
2. Repeat while no new pair is added
2.1 for every a ∈ Σ

add (p, q) to D ISTINGUISHABLE if (δ(p, a), δ(q, a)) ∈ D ISTINGUISHABLE.

3. Return D ISTINGUISHABLE.
Ashutosh Trivedi – 4 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Correctness of Table-Filling Algorithm
Theorem
If two states are not distinguished by table-filling algorithm, then they are
equivalent.

Ashutosh Trivedi – 5 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Correctness of Table-Filling Algorithm
Theorem
If two states are not distinguished by table-filling algorithm, then they are
equivalent.

– The proof is by contradiction.

Ashutosh Trivedi – 5 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Correctness of Table-Filling Algorithm
Theorem
If two states are not distinguished by table-filling algorithm, then they are
equivalent.

– The proof is by contradiction.


– Assume that there is a pair (p, q) that is not distinguished by the
algorithm, but they are not equivalent, i.e. they are indeed
distinguishable (it is just that algorithm did not find them).
– Let us call such pair (p, q) a bad pair.

Ashutosh Trivedi – 5 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Correctness of Table-Filling Algorithm
Theorem
If two states are not distinguished by table-filling algorithm, then they are
equivalent.

– The proof is by contradiction.


– Assume that there is a pair (p, q) that is not distinguished by the
algorithm, but they are not equivalent, i.e. they are indeed
distinguishable (it is just that algorithm did not find them).
– Let us call such pair (p, q) a bad pair.
– There must be a string w ∈ Σ∗ that distinguishes a bad pair (p, q). Let
us take shortest such distinguishing string w among any bad pair, and
consider corresponding bad pair (p, q).

Ashutosh Trivedi – 5 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Correctness of Table-Filling Algorithm
Theorem
If two states are not distinguished by table-filling algorithm, then they are
equivalent.

– The proof is by contradiction.


– Assume that there is a pair (p, q) that is not distinguished by the
algorithm, but they are not equivalent, i.e. they are indeed
distinguishable (it is just that algorithm did not find them).
– Let us call such pair (p, q) a bad pair.
– There must be a string w ∈ Σ∗ that distinguishes a bad pair (p, q). Let
us take shortest such distinguishing string w among any bad pair, and
consider corresponding bad pair (p, q).
– Notice that w can not be  (Why?)

Ashutosh Trivedi – 5 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Correctness of Table-Filling Algorithm
Theorem
If two states are not distinguished by table-filling algorithm, then they are
equivalent.

– The proof is by contradiction.


– Assume that there is a pair (p, q) that is not distinguished by the
algorithm, but they are not equivalent, i.e. they are indeed
distinguishable (it is just that algorithm did not find them).
– Let us call such pair (p, q) a bad pair.
– There must be a string w ∈ Σ∗ that distinguishes a bad pair (p, q). Let
us take shortest such distinguishing string w among any bad pair, and
consider corresponding bad pair (p, q).
– Notice that w can not be  (Why?)
– Let w be of the form ax. Since p and q are distinguishable, we know that
exactly one of δ̂(p, ax) and δ̂(q, ax) is accepting.
– Then p0 = δ(p, a) and q0 = δ(q, a) are also distinguished by string x.

Ashutosh Trivedi – 5 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Correctness of Table-Filling Algorithm
Theorem
If two states are not distinguished by table-filling algorithm, then they are
equivalent.

– The proof is by contradiction.


– Assume that there is a pair (p, q) that is not distinguished by the
algorithm, but they are not equivalent, i.e. they are indeed
distinguishable (it is just that algorithm did not find them).
– Let us call such pair (p, q) a bad pair.
– There must be a string w ∈ Σ∗ that distinguishes a bad pair (p, q). Let
us take shortest such distinguishing string w among any bad pair, and
consider corresponding bad pair (p, q).
– Notice that w can not be  (Why?)
– Let w be of the form ax. Since p and q are distinguishable, we know that
exactly one of δ̂(p, ax) and δ̂(q, ax) is accepting.
– Then p0 = δ(p, a) and q0 = δ(q, a) are also distinguished by string x.
– if (p0 , q0 ) were discovered by table-filling algorithm and (p, q) must have
been discovered as well.

Ashutosh Trivedi – 5 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Correctness of Table-Filling Algorithm
Theorem
If two states are not distinguished by table-filling algorithm, then they are
equivalent.

– The proof is by contradiction.


– Assume that there is a pair (p, q) that is not distinguished by the
algorithm, but they are not equivalent, i.e. they are indeed
distinguishable (it is just that algorithm did not find them).
– Let us call such pair (p, q) a bad pair.
– There must be a string w ∈ Σ∗ that distinguishes a bad pair (p, q). Let
us take shortest such distinguishing string w among any bad pair, and
consider corresponding bad pair (p, q).
– Notice that w can not be  (Why?)
– Let w be of the form ax. Since p and q are distinguishable, we know that
exactly one of δ̂(p, ax) and δ̂(q, ax) is accepting.
– Then p0 = δ(p, a) and q0 = δ(q, a) are also distinguished by string x.
– if (p0 , q0 ) were discovered by table-filling algorithm and (p, q) must have
been discovered as well.
– If (p0 , q0 ) were not discovered by table-filling algorithm, then (p0 , q0 ) is a
bad pair with a shorter distinguishing string. Ashutosh Trivedi – 5 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Minimization of DFAs

– Let A be a DFA with no unreachable state.


– Let ≡A ⊆ Q × Q be the state equivalence relation (computed by, say
table-filling algorithm).
– Note that ≡A is an equivalence relation.
– Let us write [q] for the equivalence class of the state q.

Ashutosh Trivedi – 6 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Minimization of DFAs

– Let A be a DFA with no unreachable state.


– Let ≡A ⊆ Q × Q be the state equivalence relation (computed by, say
table-filling algorithm).
– Note that ≡A is an equivalence relation.
– Let us write [q] for the equivalence class of the state q.
– Given a DFA A and ≡A we can minimize A to the DFA
A≡ = (Q0 , Σ0 , δ 0 , q00 , F0 ), called Quotient Automata, where
– Q0 = {[q] : q ∈ Q},
– Σ0 = Σ,
– δ 0 ([q], a) = δ(q, a) for all a ∈ Σ,
– q00 = [q0 ], and
– F0 = {[q] : q ∈ F}.

Ashutosh Trivedi – 6 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Minimization of DFAs

– Let A be a DFA with no unreachable state.


– Let ≡A ⊆ Q × Q be the state equivalence relation (computed by, say
table-filling algorithm).
– Note that ≡A is an equivalence relation.
– Let us write [q] for the equivalence class of the state q.
– Given a DFA A and ≡A we can minimize A to the DFA
A≡ = (Q0 , Σ0 , δ 0 , q00 , F0 ), called Quotient Automata, where
– Q0 = {[q] : q ∈ Q},
– Σ0 = Σ,
– δ 0 ([q], a) = δ(q, a) for all a ∈ Σ,
– q00 = [q0 ], and
– F0 = {[q] : q ∈ F}.

Theorem
A≡ is the minimum and unique (up to state renaming) DFA equivalent to A.

Ashutosh Trivedi – 6 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Proof of Minimality
Theorem
A≡ is the minimum and unique (up to state renaming) DFA equivalent to A.

Proof.
– The proof is by contradiction.
– Assume that there is a DFA B whose size is smaller than A≡ and
accepts that same language.
– Compute equivalent states of A≡ and B using table-filling algorithm.
– The initial states of both DFAs must be equivalent. (Why?)
– After reading any string w from their initial states, both DFAs will go
to states that are equivalent. (Why?)
– For every state of A≡ there is an equivalent state in B.
– Since the number of states of B are less than that of A≡ , there must be
at least two states p, q of A≡ that are equivalent to some state of B.
– Hence p and q must be equivalent, a contradiction.

Ashutosh Trivedi – 7 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
DFA Equivalence and Minimization

Myhill-Nerode Theorem

Pumping Lemma

Ashutosh Trivedi – 8 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Myhill-Nerode Theorem

– Given a languages L, two strings u, v ∈ L are equivalent if for all


strings w ∈ Σ we have that u.w ∈ L iff v.w ∈ L.
– Let ≡L ⊆ Σ∗ × Σ∗ be such string-equivalence relation.
– Note that ≡L is an equivalence relation.
– Consider the equivalence classes of ≡L .
– When there are only finitely mane classes?

Ashutosh Trivedi – 9 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Myhill-Nerode Theorem

John Myhill Anil Nerode

Theorem (Myhill-Nerode Theorem)


A language L is regular if and only if there exists a string-equivalence relation ≡L
with finitely many classes.

Ashutosh Trivedi – 10 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Myhill-Nerode Theorem

John Myhill Anil Nerode

Theorem (Myhill-Nerode Theorem)


A language L is regular if and only if there exists a string-equivalence relation ≡L
with finitely many classes.
Moreover, the number of states in the minimum DFA accepting L is equal to the
number of equivalence classes in ≡L .
Ashutosh Trivedi – 10 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Myhill-Nerode Theorem

Theorem (Myhill-Nerode Theorem)


A language L is regular if and only if there exists a string-equivalence relation ≡L
with finitely many classes.

Proof.
The proof is in two parts.
– If L is regular, then a string-equivalence relation ≡L with finitely
many classes can be given by states of DFA accepting L.

Ashutosh Trivedi – 11 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Myhill-Nerode Theorem

Theorem (Myhill-Nerode Theorem)


A language L is regular if and only if there exists a string-equivalence relation ≡L
with finitely many classes.

Proof.
The proof is in two parts.
– If L is regular, then a string-equivalence relation ≡L with finitely
many classes can be given by states of DFA accepting L. How?

Ashutosh Trivedi – 11 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Myhill-Nerode Theorem

Theorem (Myhill-Nerode Theorem)


A language L is regular if and only if there exists a string-equivalence relation ≡L
with finitely many classes.

Proof.
The proof is in two parts.
– If L is regular, then a string-equivalence relation ≡L with finitely
many classes can be given by states of DFA accepting L. How?
– If there is a string-equivalence relation ≡L with finitely many classes,
one can find a DFA accepting L.

Ashutosh Trivedi – 11 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Myhill-Nerode Theorem

Theorem (Myhill-Nerode Theorem)


A language L is regular if and only if there exists a string-equivalence relation ≡L
with finitely many classes.

Proof.
The proof is in two parts.
– If L is regular, then a string-equivalence relation ≡L with finitely
many classes can be given by states of DFA accepting L. How?
– If there is a string-equivalence relation ≡L with finitely many classes,
one can find a DFA accepting L. How?

Ashutosh Trivedi – 11 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem (Myhill-Nerode Theorem)


A language L is regular if and only if there exists a string-equivalence relation ≡L
with finitely many classes.

Ashutosh Trivedi – 12 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem (Myhill-Nerode Theorem)


A language L is regular if and only if there exists a string-equivalence relation ≡L
with finitely many classes.

Equivalently,

A language L is nonregular if and only if there exists an infinite subset M of Σ∗


where any two elements of M are distinguishable with respect to L.

Ashutosh Trivedi – 12 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Ashutosh Trivedi – 13 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. The proof is by contradiction.
2. Assume that L is regular.

Ashutosh Trivedi – 13 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. The proof is by contradiction.
2. Assume that L is regular.
3. By Myhill-Nerode theorem, there is a string-equivalence relation ≡L
over L with finitely equivalence classes.

Ashutosh Trivedi – 13 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. The proof is by contradiction.
2. Assume that L is regular.
3. By Myhill-Nerode theorem, there is a string-equivalence relation ≡L
over L with finitely equivalence classes.
4. Let us consider the set of strings {0, 00, 000, . . . , 0i , . . .}.

Ashutosh Trivedi – 13 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. The proof is by contradiction.
2. Assume that L is regular.
3. By Myhill-Nerode theorem, there is a string-equivalence relation ≡L
over L with finitely equivalence classes.
4. Let us consider the set of strings {0, 00, 000, . . . , 0i , . . .}.
5. It must be the case that some two string 0m and 0n , with m 6= n are
mapped to same equivalence class.

Ashutosh Trivedi – 13 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. The proof is by contradiction.
2. Assume that L is regular.
3. By Myhill-Nerode theorem, there is a string-equivalence relation ≡L
over L with finitely equivalence classes.
4. Let us consider the set of strings {0, 00, 000, . . . , 0i , . . .}.
5. It must be the case that some two string 0m and 0n , with m 6= n are
mapped to same equivalence class.
6. It implies that for all strings w ∈ Σ∗ we have that 0m .w ∈ L iff 0n .w ∈ L.

Ashutosh Trivedi – 13 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. The proof is by contradiction.
2. Assume that L is regular.
3. By Myhill-Nerode theorem, there is a string-equivalence relation ≡L
over L with finitely equivalence classes.
4. Let us consider the set of strings {0, 00, 000, . . . , 0i , . . .}.
5. It must be the case that some two string 0m and 0n , with m 6= n are
mapped to same equivalence class.
6. It implies that for all strings w ∈ Σ∗ we have that 0m .w ∈ L iff 0n .w ∈ L.
7. However, 0m 1m ∈ L but 0n 1m 6∈ L, a contradiction.
8. Hence L is not regular.

Ashutosh Trivedi – 13 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.

Ashutosh Trivedi – 14 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. From Myhill-Nerode theorem, a language L is nonregular if and only
if there exists an infinite subset M of Σ∗ where any two elements of M
are distinguishable with respect to L.

Ashutosh Trivedi – 14 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. From Myhill-Nerode theorem, a language L is nonregular if and only
if there exists an infinite subset M of Σ∗ where any two elements of M
are distinguishable with respect to L.
2. Consider the set M = {0i : i ≥ 0}.

Ashutosh Trivedi – 14 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Myhill-Nerode Theorem

Theorem
The language L = {0n 1n : n ≥ 0} is not regular.

Proof.
1. From Myhill-Nerode theorem, a language L is nonregular if and only
if there exists an infinite subset M of Σ∗ where any two elements of M
are distinguishable with respect to L.
2. Consider the set M = {0i : i ≥ 0}.
3. Since any two string in M are distinguishable with respect to L (i.e.
0m 0n ∈ L but 0n 1m 6∈ L for n 6= m), it follows from Myhill-Nerode
theorem that L is a non-regular language.

Ashutosh Trivedi – 14 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Some languages are not regular!

The following languages are regular or non-regular?


– The language {0n 1n : n ≥ 0}
– The set of strings having an equal number of 0’s and 1’s
– The set of strings with an equal number of occurrences of 01 and 10.
– The language {ww : w ∈ {0, 1}∗ }
– The language {ww : w ∈ {0, 1}∗ }
– The language {0i 1j : i > j}
– The language {0i 1j : i ≤ j}
– The language of palindromes of {0, 1}

Ashutosh Trivedi – 15 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Some languages are not regular!

The following languages are regular or non-regular?


– The language {0n 1n : n ≥ 0}
– The set of strings having an equal number of 0’s and 1’s
– The set of strings with an equal number of occurrences of 01 and 10.
– The language {ww : w ∈ {0, 1}∗ }
– The language {ww : w ∈ {0, 1}∗ }
– The language {0i 1j : i > j}
– The language {0i 1j : i ≤ j}
– The language of palindromes of {0, 1}

Ashutosh Trivedi – 15 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
DFA Equivalence and Minimization

Myhill-Nerode Theorem

Pumping Lemma

Ashutosh Trivedi – 16 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Pumping Lemma

Theorem (Pumping Lemma for Regular Languages)


For every regular language L there exists a constant p (that depends on L)

Ashutosh Trivedi – 17 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Pumping Lemma

Theorem (Pumping Lemma for Regular Languages)


For every regular language L there exists a constant p (that depends on L)
such that
for every string w ∈ L of length greater than p,
there exists an infinite family of strings belonging to L.

Ashutosh Trivedi – 17 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Pumping Lemma

Theorem (Pumping Lemma for Regular Languages)


For every regular language L there exists a constant p (that depends on L)
such that
for every string w ∈ L of length greater than p,
there exists an infinite family of strings belonging to L.

Why?

Ashutosh Trivedi – 17 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Pumping Lemma

Theorem (Pumping Lemma for Regular Languages)


For every regular language L there exists a constant p (that depends on L)
such that
for every string w ∈ L of length greater than p,
there exists an infinite family of strings belonging to L.

Why? Think: Regular expressions, DFAs

Ashutosh Trivedi – 17 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Pumping Lemma

Theorem (Pumping Lemma for Regular Languages)


For every regular language L there exists a constant p (that depends on L)
such that
for every string w ∈ L of length greater than p,
there exists an infinite family of strings belonging to L.

Why? Think: Regular expressions, DFAs Formalize our intuition!

Ashutosh Trivedi – 17 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Pumping Lemma

Theorem (Pumping Lemma for Regular Languages)


For every regular language L there exists a constant p (that depends on L)
such that
for every string w ∈ L of length greater than p,
there exists an infinite family of strings belonging to L.

Why? Think: Regular expressions, DFAs Formalize our intuition!

If L is a regular language, then


there exists a constant (pumping length) p such that
for every string w ∈ L s.t. |w| ≥ p
there exists a division of w in strings x, y, and z s.t. w = xyz such that
1. |y| > 0,
2. |xy| ≤ p, and
3. for all i ≥ 0 we have that xyi z ∈ L.

Ashutosh Trivedi – 17 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
A simple observation about DFA
0 1
1

start E O

computation string computation string

start E . start E .

0 0

E . E .

1 0

O . E .

0 1

E . O .
Ashutosh Trivedi – 18 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
A simple observation about DFA

Image source: Wikipedia

– Let A = (S, Σ, δ, s0 , F) be a DFA.


– For every string w ∈ Σ∗ of the length greater than or equal to the
number of states of A, i.e. |w| ≥ |S|, we have that
– the unique computation of A on w re-visits at least one state after
reading first |S| letters !
Ashutosh Trivedi – 19 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Pumping Lemma
Theorem (Pumping Lemma for Regular Languages)
If L is a regular language, then there exists a constant (pumping length) p such
that for every string w ∈ L s.t. |w| ≥ p there exists a division of w in strings x, y,
and z s.t. w = xyz such that
1. |y| > 0,
2. |xy| ≤ p, and
3. for all i ≥ 0 we have that xyi z ∈ L.

Ashutosh Trivedi – 20 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Pumping Lemma
Theorem (Pumping Lemma for Regular Languages)
If L is a regular language, then there exists a constant (pumping length) p such
that for every string w ∈ L s.t. |w| ≥ p there exists a division of w in strings x, y,
and z s.t. w = xyz such that
1. |y| > 0,
2. |xy| ≤ p, and
3. for all i ≥ 0 we have that xyi z ∈ L.

– Let A be the DFA accepting L and p be the set of states in A.


– Let w = (a1 a2 . . . ak ) ∈ L be any string of length ≥ p.
– Let s0 a1 s1 a2 s2 . . . ak sk be the run of w on A.
– Consider first n + 1 states—at least one state must occur twice.
– Let i be the index of first state that the run revisits and let j be the
index of second occurrence of that state, i.e. si = sj ,
– Let x = a1 a2 . . . ai−1 and y = ai ai+1 . . . aj−1 , and z = aj aj+1 . . . ak .
– notice that |y| > 0 and |xy| ≤ n
– Also, notice that for all i ≥ 0 the string xyi z is also in L.
Ashutosh Trivedi – 20 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Pumping Lemma

Theorem (Pumping Lemma for Regular Languages)


L ∈ Σ∗ is a regular language
=⇒
there exists p ≥ 1 such that
for all strings w ∈ L with |w| ≥ p we have that
there exists x, y, z ∈ Σ∗ with w = xyz, |y| > 0, |xy| ≤ p such that
for all i ≥ 0 we have that
xyi z ∈ L.

Ashutosh Trivedi – 21 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Pumping Lemma

Theorem (Pumping Lemma for Regular Languages)


L ∈ Σ∗ is a regular language
=⇒
there exists p ≥ 1 such that
for all strings w ∈ L with |w| ≥ p we have that
there exists x, y, z ∈ Σ∗ with w = xyz, |y| > 0, |xy| ≤ p such that
for all i ≥ 0 we have that
xyi z ∈ L.

Pumping Lemma (Contrapositive)


For all p ≥ 1 we have that
there exists a string w ∈ L with |w| ≥ p such that
for all x, y, z ∈ Σ∗ with w = xyz, |y| > 0, |xy| ≤ p we have that
there exists i ≥ 0 such that
xyi z 6∈ L
=⇒
L ∈ Σ∗ is not a regular language.
Ashutosh Trivedi – 21 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Pumping Lemma

How to show that a language L is non-regular.


1. Let p be an arbitrary number (pumping length).
2. (Cleverly) Find a representative string w of L of size ≥ p.
3. Try out all ways to break the string into xyz triplet satisfying that
|y| > 0 and |xy| ≤ n. If the step 3 was clever enough, there will be
finitely many cases to consider.
4. For every triplet show that for some i the string xyi z is not in L, and
hence it yields contradiction with pumping lemma.

Ashutosh Trivedi – 22 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Pumping Lemma

Theorem
Prove that the language L = {0n 1n } is not regular.

Ashutosh Trivedi – 23 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Pumping Lemma

Theorem
Prove that the language L = {0n 1n } is not regular.

Proof.
1. State the contrapositive of Pumping lemma.
2. Let p be an arbitrary number.
3. Consider the string 0p 1p ∈ L. Notice that |0p 1p | ≥ p.

Ashutosh Trivedi – 23 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Pumping Lemma

Theorem
Prove that the language L = {0n 1n } is not regular.

Proof.
1. State the contrapositive of Pumping lemma.
2. Let p be an arbitrary number.
3. Consider the string 0p 1p ∈ L. Notice that |0p 1p | ≥ p.
4. Only way to break this string in xyz triplets such that |xy| ≤ p and
y 6= ε is to choose y = 0k for some 1 ≤ k ≤ p.

Ashutosh Trivedi – 23 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Applying Pumping Lemma

Theorem
Prove that the language L = {0n 1n } is not regular.

Proof.
1. State the contrapositive of Pumping lemma.
2. Let p be an arbitrary number.
3. Consider the string 0p 1p ∈ L. Notice that |0p 1p | ≥ p.
4. Only way to break this string in xyz triplets such that |xy| ≤ p and
y 6= ε is to choose y = 0k for some 1 ≤ k ≤ p.
5. For each such triplet, there exists an i (say i = 0) such that xyi z 6∈ L.
6. Hence L is non-regular.

Ashutosh Trivedi – 23 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Proving a language Regular

Proving Regularity
Pumping Lemma is necessary but not sufficient condition for regularity.

Ashutosh Trivedi – 24 of 24
Ashutosh Trivedi DFA Equivalence and Minimization
Proving a language Regular

Proving Regularity
Pumping Lemma is necessary but not sufficient condition for regularity.

Consider the language

L = {#an bn : n ≥ 1} ∪ {#k w : k 6= 1, w ∈ {a, b}∗ }.

Verify that this language satisfies the pumping condition, but is not
regular!

Ashutosh Trivedi – 24 of 24
Ashutosh Trivedi DFA Equivalence and Minimization

You might also like