240 likes | 374 Views
CSci 4011. INHERENT LIMITATIONS OF COMPUTER PROGAMS. QUIZ 1. A language is a:. set of strings. { w | M accepts w }. If M is a DFA, L(M) is the set. states. Let M = (Q, ,δ ,q 0 ,F). Q is the set of:. δ is the:. Transition function. a. b, a. q 0. q 1. NFA. DFA. DEF.
E N D
CSci 4011 INHERENT LIMITATIONS OF COMPUTER PROGAMS
QUIZ 1 A languageis a: set of strings. { w | M accepts w }. If M is a DFA, L(M) is the set states Let M = (Q,,δ,q0,F). Q is the set of: δ is the: Transition function a b,a q0 q1
NFA DFA DEF Regular Language Regular Expression
REGULAR OR NOT? Design a NFA for the language: {0n1n | 0 < n ≤2} {0n1n | 0 < n ≤k} {0n1n | n > 0}? n (For R a regexp, R2 means RR, and Rn means RR…R)
SOME LANGUAGES ARE NOT REGULAR! B = {0n1n | n ≥ 0} is NOT regular!
sk… s2k ∈ F sj 0.. 011111…11 Let M be a k-state DFA that recognizes B Consider the path M takes on 0k1k: s0 s1 s2… sisi+1 0000… 00.. There must be i < j ≤ k such that si= sj= q′ ∈ Q M accepts 0k-(j-i)1k B! So M does not recognize the language B.
REGULAR OR NOT? C = { w | w has equal number of 1s and 0s} NOT REGULAR D = { w | w has equal number of occurrences of 01 and 10} (0Σ*0) (1Σ*1) 1 0 ε
THE PUMPING LEMMA Let L be a regular language with |L| = Then there exists a length P such that if w L and |w| ≥ P then there exist xyz = w where: 1. |y| > 0 2. |xy| ≤ P 3. xyiz L for any i ≥ 0
THE PUMPING LEMMA Example: Let L = 0*1* ; P = 1 w = 011 ε x = y = 0 if w L and |w| ≥ P then w = xyz, where: z = 11 Let L = (0∪1)2*; P = 2 1. |y| > 0 2. |xy| ≤ P 3. xyiz L for any i ≥ 0 2 w = 1 1 x = y = 2 z = ε
q|w| Let M be a DFA that recognizes L Let P be the number of states in M Assume w L is such that |w| ≥ P 1. |y| > 0 2. |xy| ≤ P 3. xyiz L for any i ≥ 0 We show w = xyz y x z … q0 qi qj There must be j > i such that qi = qj
0,1 1 0 0 0 1 a c b d 1 L(M) = *001* 0001→ 001 → abcd 00001 →abcccd abccd
USING THE PUMPING LEMMA Use the pumping lemma to prove that B = {0n1n | n ≥ 0} is not regular Hint: Assume B is regular, and try pumping s = 0P1P If B is regular, s can be split into s = xyz, where for any i≥ 0, xyiz is also in B For every choice of xy with |xy| ≤ P and |y|>0, y must be a string of 0s. In this case xyyz has more 0s than 1s
GENERAL STRATEGY Proof by contradiction – assume L is regular Then there is a pumping length P Find a string w ∈ L with |w| ≥P Show that no matter how you choose xyz, w cannot be pumped! Conclude that L is not regular
Let PALINDROMES = { wwR | w ∈{0,1}* } Assume … pumping length P Find a w ∈PALINDROMES longer than P 0P1P1P0P Show that … w cannot be pumped: 2P P P w= 00…0011…1100…00 If w = xyz with |xy| ≤P then y = 0J for some J>0. Then xyyz = 0P+J12P0P PALINDROMES y xyyz = 00…00011…1100…00 > P P 2P
USING THE PUMPING LEMMA THE ADVERSARY
WHAT THE PUMPING LEMMA DOESN’T SAY - I For everyP, w L with |w| ≥ P there exist xyz=w, where: 1. |y| > 0 2. |xy| ≤ P 3. xyiz L for any i ≥ 0 Let L = 1*. L is regular. The string 10 cannot be pumped with P=1. You need to show that no matter what P is chosen, L has a string w, |w| ≥ P, that cannot be pumped.
WHAT THE PUMPING LEMMA DOESN’T SAY - II For every xyz=w, where: 1. |y| > 0 2. |xy| ≤ P: xyiz L for any i ≥ 0 Example: Let L = 10*1*. Picking w = 10P1P; x=ε; y=10P; z=1P Does not contradict pumping lemma! (you can pick x=1 y=0P z=1P.)
PUMPING DOWN C = { 0i1j | i > j ≥ 0} Assume … pumping length P Find a w ∈ Clonger than P 0P+11P Show that … w cannot be pumped: P P+1 w= 00…0011…11 If w = xyz with |xy| ≤P then y = 0J for some J ≥1. Then xy0z = xz = 0P+1-J1P C y xz = 0…0011…11 xyyz = 00…00011…11 P ≤P > P+1 P
CHOOSING WISELY Let BALANCED = { w | w has an equal # of 1s and 0s } Assume … there is a P Find a w ∈BALANCED longer than P (01)P 0P1P Show that w cannot be pumped: If w = xyz with |xy| ≤ P then y = 0J for some J>0. Then xyyz = 0P+J1P BALANCED
REUSING A PROOF Pumping a language can be lots of work… Let’s try to reuse that work! {0n1n : n ≥0} = BALANCED ∩ 0*1* If BALANCED is regular then so is {0n1n: n ≥0}
USING CLOSURE Prove: A is not regular ∩ A C = B (Not regular) (regular) or any of {¬, ∪, ∩, ・, R, *} If A is regular, then A ∩ C (= B) is regular. But B is not regular so neither is A.
Prove A = {0i1j : i j} is not regular using B = {0n1n : n ≥ 0} ¬A = B ∪{ strings that mix 0s and 1s } B = ¬A ∩ 0*1*
PUMPING NON-REGULAR LANGUAGES Let F = {aibjck | i, j, k ≥0 and i=1 ⇒j=k} F has pumping length 2! i = 0 i = 1 i = 2 F ∩ab*c* = {abncn| n ≥ 0} A non-regular language may still satisfy the pumping lemma.