nathan brunelle department of computer science university of virginia njb2b/theory theory of...
TRANSCRIPT
Nathan Brunelle
Department of Computer Science
University of Virginia
www.cs.virginia.edu/~njb2b/theory
Theory of ComputationCS3102 – Spring 2014
A tale of computers, math, problem solving, life, love and tragic death
MidtermTake home? Vote now.
Date:1. During the week before Spring break (out March 3, due March 6)?• Don’t have to worry over the break
2. After Spring break (4 days within March 16-23)?• 1 more week of content but 2 more weeks to solve problems• I will hold Skype/Google Hangout office hours over the break
Think about it, vote on Thursday.
Pumping LemmaGoal: Give a sufficient condition for showing non-regularity
Consider that L is an infinite regular languageLet M be a DFA, L(M)=L
Let’s say M has p statesThere must be someString w in L s.t. |w|>p
By the pigeon-hole principle:Some state was visited at least twice!Taking that loop another time must giveanother string in the language.
M
1
8
12
20
p
3x2
Pumping LemmaIf L is a regular language then there is some number p (called pumping length) where if w is a string in L s.t. |w|>p then w can be divided into 3 pieces: w=xyz which satisfy:
1. For each i≥0, L2. |y|>03. |xy|≤p
Example: Consider:By condition 3 we know:Thus for i=2 we have more a’s than b’s,so L cannot be regular
M
1
8
12
20
p
3
zxy i x
y
z
ℕnba nn |{ }ppba
ay
Pumping Lemma1. For each i≥0, L2. |y|>03. |xy|≤p
Show: is not regular
Consider By condition 3 we know y , this leaves 4 cases:4. y5. y6. y7. y
zxy i
}|{ *wwwR
pp baab )()( )(ba
)(ab*)(abbaab *)(aabb )(
Problem: in all of these I only change the first half!
I needed to “remember” the first half of the string.
Pumping Lemma1. For each i≥0, L2. |y|>03. |xy|≤p
Show: is not regular
Consider where q is a prime greater than py may have only a’s, let y= where m≤pFor i=p+1 we have Clearly, p(m+1) is not prime
zxy i
qa
}prime is |{ nan
ma)1( mpi azxy
For let then
So
7a3ay 2417 ay
)13(728424 aaaaxyz
Pumping Lemma1. For each i≥0, L2. |y|>03. |xy|≤p
Consider: This language is pumpable but not regular3 cases:4. If then let x=ε, y=a5. If then let x=ε, y=c6. If then let x=ε, y=cThus every string is pumpable
Nonregular: Then use pumping Lemma!
zxy i
}1|{ kjibac kji
kjbajjbca
1, ibac jji
}{}1|{ ** nnkji bcabcakjibac
Myhill-Nerode TheoremGives a necessary and sufficient condition for regularity!
Idea: If two strings terminate in the same state in a DFA then their membership must be equivalent for any suffix.
If and meet at state q then for any string , ends in the samestate as
We say and haveno distinguishing extensions
M1w
2w
qx
1w 2w
x xw1
xw2
2w1w
Myhill-Nerode TheoremRecall Equivalence Relation:A relation ~ is called an equivalence relation if:Reflexive:Symmetric:Transitive:
The relation if and have no distinguishing extensions in language L forms an equivalence relation.
Recall Equivalence Class:For equivalence relation ~, equivalence class
Myhill Nerode Theorem: L is regular iff has a finite number of equivalence classes under relation
xx ~
xyyx ~~ zyzyyx ~~~
21 ~ ww L 1w 2w
}~|{][ baba
L~
*
Myhill-Nerode Theorem
Myhill Nerode Theorem: L is regular iff has a finite number of equivalence classes under relation
Given a finite set of equivalence classes, construct a DFA:
Each equivalence class becomes a state:
If character takes a string from equivalence class to then add a transition from the state for to the state for .
Accept states are those for equivalence classes of strings in the language.
DE~
*
][0 q
][ 1w ][ 2w
][ 1w][ 2w
Myhill-Nerode Theorem
Extra Credit: Use the Myhill-Nerode Theorem to show the following languages are non-regular:
}|{ *wwwR }prime is |{ nan ℕnba nn |{ }
Language ReversalTheorem: The regular languages are closed under reversal.Proof: Construction.Given a regular language L, show that the language is also regular.Let M be a DFA for L, construct M’ to be a NFA for L:
}|{ LwwL RR
M M’
q0
ε
ε
HalfLetShow that HALF preserves regularity.e.g. if “RingoStarr” is in L, then “Ringo” is in HALF(L)
Let M be a DFA for language L
Intuition: follow the transitions of M for string v. “Check” that there is a path from v to an accept state that consumes |v| characters.
How do we do this “check”?
}|||| s.t. ,|{)( * LvwwvwvvLHALF
M
v
w
HalfLetShow that HALF preserves regularity.
Intuition: follow the transitions of M for string v. “Check” that there is a path from v to an accept state that consumes |v| characters.
How do we do this “check”? Use the machine for LR
}|||| s.t. ,|{)( * LvwwvwvvLHALF
M
v
w
M’
ε
ε
Σ
ΣΣ
ΣΣ
F={(q,q)}
DoubleLetShow that DOUBLE preserves regularity.e.g. if “BamBam” is in L, then “Bam” is in DOUBLE(L)
Let M be a DFA for language L
Intuition: Run L on w, in parallel non-deterministically “guess” the end state in machine M on w and check if starting from that guess puts the machine in an accept state
}|{)( LwwwLDOUBLE
M
w
M
w
“Guess”
DoubleLetIntuition: Run L on w, in parallel non-deterministically “guess”
the end state in machine M on w and check if starting from that guess puts the machine in an accept state
}|{)( LwwwLDOUBLE
M
…
Accept if:•M ends in state •M ends in an accept state
} '|)', {( FqqF
M M
M2 MM1
εε
ε
||Q