Upload
others
View
19
Download
0
Embed Size (px)
Citation preview
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Formal Language and Automata Theory(CS21004)
Soumyajit DeyCSE, IIT Kharagpur
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Announcements
The slide is just a short summary
Follow the discussion and the boardwork
Solve problems (apart from those we dish out in class)
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Table of Contents
1 Pumping Lemma
2 Minimization
3 Myhill-Nerode Theorem
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Languages that are not regular
L = {anbn | n ≥ 0} = {ǫ, ab, aabb, aaabbb, · · · }
needs to remember number of a-sand match with b-s.Infinite number of possibilities
cannot remember with finite number of states
We further provide a formal arguement
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Languages that are not regular
Let a DFA with k states accept L. consider some n >> k
starting from initial state i , anbn leads to the acceptstate f
some state must have been visited more than once, letit be p
Let anbn = uvw , j = |v | > 0 where
δ̂(i , u) = p, δ̂(p, v) = p, δ̂(p,w) = f
Hence δ̂(i , uw) = f
uw = an−jbn /∈ L
Similarly, δ̂(i , uv3w) = f but uv3w = an+2jbn /∈ L
♠ Such a DFA does not exist
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Pumping Lemma for Regular Languages
Let L be a regular language. Then there exists an integerp ≥ 1 such that every string w in L of length at least p (p iscalled the ”pumping length”) can be written as w = xyz
(i.e., w can be divided into three substrings), satisfying thefollowing conditions:
|y | ≥ 1
|xy | ≤ p
∀i ≥ 0, xy iz ∈ L
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Pumping Lemma for Regular Languages : general
version
Let L be a regular language. Then there exists an integerp ≥ 1 such that every string uwv in L with |w | ≥ p can bewritten as uwv = uxyzv such that
|y | ≥ 1
|xy | ≤ p
∀i ≥ 0, uxy izv ∈ L
standard version is a special case with u, v being empty.Since the general version imposes stricter requirements onthe language, it can be used to prove the non-regularity ofmany more languages, such as {ambncn : m ≥ 1, n ≥ 1}
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Pumping Lemma for Regular Languages
Necessary but not sufficient condition
Cannot be used to prove language as regular
There are non-regular languages which satisfy thelemma
Violation can be used to prove language as non-regular
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Pumping Lemma Ex
{a2n| n ≥ 0}.
Let this be accepted by a k state DFA. Choose n suchthat n >> k
Thus 2n > k . Hence we may decompose the string a2n
to parts of length i , j , l such that 2n = i + j + l and theintermediate j symbols form a cycle in the DFA
The DFA will accept a2n+j
Note, i + j ≤ k < n ⇒ j < n
2n + j < 2n + n < 2n + 2n = 2n+1
♠ such a DFA cannot exist
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Pumping Lemma Ex
We can show using Pumping Lemma
{anbm | n ≥ m} is not regular
{an! | n ≥ 0} is not regular
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
More examples of languages not regular
Alternate lines of argument :
A = {w | na(w) = nb(w)} ⇒ if A is regular thanA ∩ L(a∗b∗) = {anbn | n ≥ 0} is regular
{anbm | n ≥ m} is regular⇒ AR = {bman | n ≥ m} is regular⇒ C = AR [a 7→ b, b 7→ a] = {ambn | n ≥ m} is regular⇒ A ∩ C = {anbn | n ≥ 0} is regular
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
More examples of languages not regular
U ⊆ N is an ultimately periodic set, i.e. ∃n ≥ 0,∃p > 0, ∀m ≥ n, m ∈ U iff m+ p ∈ U. We call p is theperiod of U. Every such U is regular
Ex. {0, 3, 7, 9, 19, 20, 23, 26, 29, 32, 35, · · · } :(n = 20, p = 3), (n = 21, p = 6) : n, p need not beunique
Let A ⊆ {a}∗. A is regular iff {m | am ∈ A} isultimately periodic
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Table of Contents
1 Pumping Lemma
2 Minimization
3 Myhill-Nerode Theorem
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Equivalence of FAs
When we convert NFA to DFA,
We ignore unreachable states, keep them you simplyhave a larger DFA for the same language !!
Even some reachable states can be merged preservinglanguage equivalence !!
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Examplea, b
a b a
a, b
Apply standard NFA to DFA conversion, remove unreachable states
b
a b
b
b
b
b
a
a
a
a
a
a
a
a
a
b
b
b
b
Accept states can be merged !
Not all such cases are as obviousSoumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Example
a
bb b
a
a,b
a,b
a,b
a
0
2
1 3
4
5
a,b a,ba,b
6 7 8
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Example
a
b
a,b
a,b
a,b a,ba,b
a,b
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
How to decide which states to collapse
Intuitively two states are mergeable if they behavesimilarly (in terms of language acceptance) for the sameinput string
Starting from respective states, with the same inputstring, either both lead to respective final states or nonelead to respective final states
Turns out to be a necessary and sufficient condition
Such relations among state pairs are equivalence
relations
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Equivalence relation on states
∀p, q ∈ Q, p ≈ q iff
∀x ∈ Σ∗ [δ̂(p, x) ∈ F ⇔ δ̂(q, x) ∈ F ]
reflexive, symmetric, transitive
for any state p, [p] = {q | p ≈ q}
by definition, equivalence classes are mutually exclusiveand exhaustive : every state is in exactly oneclass/partition,
p ≈ q ⇔ [p] = [q]
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Quotient Automaton M/ ≈ for DFA M
Given M = (Q,Σ, δ, s,F ), M/ ≈def= (Q ′,Σ, δ′, s ′,F ′)
Q ′ = {[p] | p ∈ Q}
δ′([p], a) = [δ(p, a)]
s ′ = [s]
F ′ = {[p] | p ∈ F}
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Is δ′ well defined ??
If p, q,∈ [p], is δ′([p], a) = [δ(p, a)] = δ′([q], a) = [δ(q, a)] ?For any a ∈ Σ, y ∈ Σ∗
δ̂(δ(p, a), y) ∈ F ⇔ δ̂(p, ay) ∈ F by definition of δ̂
⇔ δ̂(q, ay) ∈ F since p ≈ q
⇔ δ̂(δ(q, a), y) ∈ F by definition of δ̂
Hence, δ(p, a) ≈ δ(q, a) by definition of ≈. So,[δ(p, a)] = [δ(q, a)]
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
p ∈ F ⇔ [p] ∈ F ′
p ∈ F ⇒ [p] ∈ F ′ by definition of F ′. What about the otherdirection, i.e. [p] ∈ F ′ ⇒ p ∈ F ??
What is there to prove ??
Note that you have [p], that does not specify any p butthe overall equivalence class.
Need to show that all elements of the class are in F
rather than one specific member.
Prove that any such equivalence class is either subset ofF or disjoint.
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
[p] ∈ F ′ ⇒ p ∈ F
[p] ∈ F ′ ⇒ ∃x ∈ [p], x ∈ F
⇒ δ̂(x , ǫ) = x ∈ F by defn. of δ̂
⇒ ∀q ≈ x , δ̂(q, ǫ) ∈ F by defn. of ≈
⇒ ∀q ≈ x , δ̂(q, ǫ) = q ∈ F by defn. of δ̂
⇒ ∀q ∈ [p], q ∈ F ∀q ≈ x ∈ [p], q ∈ [p]
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Prove the following
∀x ∈ Σ∗, δ̂′([p], x) = [δ̂(p, x)]
L(M/ ≈) = L(M)
M/ ≈ cannot be collapsed any further
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Here is an algorithm for computing the collapsing relation ≈for a given DFA M with no inaccessible states. Thealgorithm will mark (unordered) pair of states {p, q}. A pair{p, q} will be marked as soon as a reason is discovered whyp and q are not equivalent.
1 Write down a table of all pairs {p, q}, initiallyunmarked.
2 Mark {p, q} if p ∈ F and q 6∈ F of vice versa.
3 Repeat the following until no more changes occur:If there exists an unmarked pair {p, q} such that{δ(p, a), δ(q, a)} is marked for some a ∈ Σ, then mark{p, q}.
4 When done, p ≈ q iff {p, q} is not marked.
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Table of Contents
1 Pumping Lemma
2 Minimization
3 Myhill-Nerode Theorem
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
DFA : isomorphism
Two deterministic finite automataM = (QM ,Σ, δM , sM ,FM), N = (QN ,Σ, δN , sN ,FN), areisomorphic iff ∃f , f : QM → QN such that
f (sM) = sN
∀p ∈ QM , a ∈ Σ, f (δM(p, a)) = δN(f (p), a)
p ∈ FM iff f (p) ∈ FN
One is just the renamed version of another. Note,M/ ≡, N/ ≡ are also isomorphic. ⇒ We should be able todefine a minimal automata directly from the language itself.All other possible minimal automata will be isomorphic withthis.
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Myhill-Nerode Relations
Let R ⊆ Σ∗ be regular with DFA M = (Q,Σ, δ, s,F ) for R .M does not have any unreachable states. A relation ≡M onΣ∗ defined as
x ≡M y ⇔ δ̂(s, x) = δ̂(s, y)
≡M is an equivalence relation. Other properties of ≡M
1 ∀x , y ∈ Σ∗, a ∈ Σ, x ≡ y ⇒ xa ≡ ya : right congruence(show this)
2 ≡M refines R : x ≡M y ⇒ (x ∈ R ⇔ y ∈ R) – every≡M -class has either all its elements in R or none of itselements in R , i.e. R is a union of ≡M -classes
3 The no. of ≡M classes is finite ( = no. of states in M ?)
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Myhill-Nerode Relations
Any equivalence relation on Σ∗ which is a right congruenceof finite index refining a regular set R is called aMyhill-Nerode Relation
Just like M →≡M we can ≡→ M≡
Let ≡ be an arbitrary Myhill-Nerode Relation on Σ∗ for someR ⊆ Σ∗, i.e. ≡ is some equivalence Relation on Σ∗ which isalso right congruence of finite index refining a regular set R
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
≡→ M≡
DFA M≡ = (Q,Σ, δ, s,F )
Q = {[x ] | x ∈ Σ∗} (is finite, why ?)
s = [ǫ]
F = {[x ] | x ∈ R}
δ([x ], a) = [xa] (y ∈ [x ] ⇒ [xa] = [ya] by rightcongruence)
Can show
x ∈ R ⇔ [x ] ∈ F : The ‘⇒’ is by defn of F , for ⇐,y ∈ [x ] ∈ F ⇒ x ∈ F ⇒ y ∈ R by refinement
δ̂([x ], y) = [xy ] : by induction
L(M≡) = R
≡M≡is identical to ≡
M≡Mis isomorphic to M
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Myhill-Nerode Theorem
Let R ⊆ Σ∗. The following statements are equivalent:
R is regular
there exists a Myhill-Nerode relation for R
the relation ≡R creates a finite partitioning of Σ∗
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)
Formal Languageand Automata
Theory (CS21004)
Soumyajit DeyCSE, IITKharagpur
Pumping Lemma
Minimization
Myhill-NerodeTheorem
Pumping Lemma Minimization Myhill-Nerode Theorem
Example application
Consider R = {anbn|n ≥ 0} ⊆ Σ∗. Let R be regular with aMyhill-Nerode relation ≡ on Σ∗ for R
Let am ≡ ak for any m 6= k
By right congruence ambk ≡ akbk
Note x ≡ y ⇒ [x ∈ R ⇔ y ∈ R ] , i.e. an equivalencepartition is either inside R or outside R , but cannotspan across
But now we have one equivalence partition containingambk , akbk where ambk /∈ R , akbk ∈ R .
Hence, it is not the case that ak ≡ am
The relation ≡ creates an infinite partitioning of Σ∗
♠ R is not regular
Soumyajit Dey CSE, IIT Kharagpur Formal Language and Automata Theory (CS21004)