Apology • Office Hours Yesterday Decision Properties of Regular Languages • Last week’s homework The Pumping Lemma Announcement Announcement • RIT Career Fair • CS Student Meeting – Thursday, Oct 3 rd 1pm – 7pm • Wednesday, Oct 2 nd – Friday, Oct 4 th 9am – 5pm (interviews) • 5-6pm • 08-1250 • Clark Gym • www.rit.edu/co-op/careers • Followed by free pizza in Building 10 (outside of ICLs) Homework Before We Start • Homework #3 Due Today • Any questions? • Homework #4 – 5.16d,e – 5.20b,e (Use the Pumping Lemma) • n 0 (x) = number of 0’s in x • n 1 (x) = number of 1’s in x – Given the RE (a*(a + b + abb)*)* • Find a FA with minimal number of states that accepts the language described. • Go through entire process: NDFA- Λ -> NDFA -> FA -> MFA 1
Decision Properties Non-regular languages • Given regular languages, specified in any one of • And then there’s the question: the four means, can we develop algorithms that – Is there a language L that is not regular? answer the following questions: 1. Is the language empty? 2. Is the language finite? 3. Is a given string in the language? 4. Given 2 languages, are there strings that are in both? 5. Is the language a subset of another regular language? 6. Is the language the same as another regular language? Additional tools The Pumping Lemma • Minimal finite automata • The pumping lemma formalizes the idea that if a string from a RL is long enough, eventually at – Create a finite automata with the minimum least one state on its FA will be have to be number of possible states repeated on the path that accepts the string. • Pumping Lemma – Implies that there is a Kleene star in there somewhere! – Defines necessary properties for strings in a • Continually looping on this state will produce an regular language infinite number of strings in the language – Can be used to show that languages are not regular – Will consider next week The Pumping Lemma The Pumping Lemma • Statement of the pumping lemma • What this means – Let L be a regular language. – For a long enough string x in L: – Then there exists a constant n (which varies • We can express x as the concatenation of three for different languages), such that for every smaller strings string x ∈ L with |x| ≥ n, x can be expressed • The middle string can be “pumped” (repeated) any as x = uvw such that: number of times (including 0 = deleting) and the 1. |v| > 0 resulting string will be in L. 2. |uv| ≤ n 3. For all k ≥ 0, the string uv k w is also in L. 2
Pumping Lemma Pumping Lemma • Proof of the pumping lemma • Proof of the pumping lemma – Since L is regular, there is a FA M=(Q, Σ ,q 0 ,A, δ ) that – Since |x| ≥ n, and we only have n states, one accepts L. state on it’s path must visited more than once. • Assume M has n states. • There exists integers i and j, 0 ≤ i < j ≤ n such that – Consider a string x with |x| = m ≥ n. p i = p j • Express x = a 1 a 2 a 3 … a m where each a i ∈ Σ . • Then x = uvw – Define p i to be the state M is in after reading i – u = a 1 a 2 …a i characters: – v = a i+1 a i+2 …a j • p i = δ * (q 0 , a 1 a 2 …a i ) – w = a j+1 a j+2 …a m • p 0 = q 0 Pumping Lemma Pumping Lemma • Proof of pumping lemma • Proof of pumping lemma • Then x = uvw – You can loop (pump) on the v loop 0 or more – u = a 1 a 2 …a i times and there will still be a path to the – v = a i+1 a i+2 …a j accepting state. – w = a j+1 a j+2 …a m v = a i+1 a i+2 …a j v = a i+1 a i+2 …a j u = a 1 a 2 …a i w = a j+1 a j+2 …a m p 0 p i u = a 1 a 2 …a i w = a j+1 a j+2 …a m p 0 p i Pumping Lemma Pumping Lemma • So what good is the pumping lemma? • Test for finiteness – First stab • Let’s revisit the question: • The pumping lemma tells us that if there is a string x – Given a specification of a regular language, is with length greater than the number of states that language finite? accepted by an FA, M, then L(M) is infinite. • Let’s test all strings of length >= number of states. • Will give us a “yes”, L(M) is finite but • For L(M) infinite, the algorithm will never stop. 3
Pumping Lemma Pumping Lemma • Test for infiniteness • Using the pumping lemma to prove things – Given an FA M, L(M) is infinite if there is a – Always involves proof by contradiction string x accepted by M such that • If X then Y • n ≤ |x| ≤ 2n • Assume Y is false • n = number of states in M • Arrive at a contradiction to a known true fact (including X) • Must conclude that our assumption is false thus Y is – Let’s prove using the Pumping Lemma true. Pumping Lemma Pumping Lemma • Test for infiniteness • Test for infiniteness – Given an FA M, L(M) is infinite if there is a – Since L(M) is infinite, there is a string that have string x accepted by M such that length of at least 2n. Let z be the smallest such string. • n ≤ |x| ≤ 2n • n = number of states in M – By the pumping lemma • z = uvw – Assume that no such x exists. • |v| > 0 • |uv| ≤ n Pumping Lemma Pumping Lemma • Test for infiniteness • Test for infiniteness – Also by the pumping lemma – We came to a contradiction • uv 0 w = uw ∈ L(M) – Thus our original assumption that there is no x – Since |z| = |uvw| ≥ 2n and |v| ≥ 0 then such that n ≤ |x| ≤ 2n is false. • |uw| > 2n – Thus we proved that there is such an x. – Since |z| = |uvw| ≥ 2n and |v| ≤ n then • |uw| ≥ n – So either • n ≤ |uw| < 2n This contradicts our orig. assumption • 2n > |uw| > |z| This contradicts z being smallest 4
Pumping Lemma Pumping Lemma • Test for infiniteness • Questions – How does this help us? – Algorithm for testing if L(M) is infinite. • Systematically generate all strings of length between n and 2n where n is the number of states of M • Test each string generated • If at least 1 is accepted, then L(M) is infinite • Otherwise L(M) is finite. Non-regular languages Pumping lemma • The real strength of the pumping lemma is • Venn-diagram of languages proving that languages are not regular Is there – Proof by contradiction something Regular Languages out here? • Assume that the language to be tested is regular • Use the pumping lemma to come to a contradiction • Original assumption about the language being regular is false Finite • You cannot prove a language to be regular Languages using the Pumping Lemma!!!! Pumping lemma Pumping lemma • The Pumping Lemma game • Example: – To show that a language L is not regular – L = {x ∈ {0,1} * | 0 i 1 i , i ≥ 0} • Assume L is regular – Ex: 000111, 0011, Λ , 00001111 • Choose an “appropriate” string x in L – Let’s play! • Express x = uvw following rules of pumping lemma • Assume that L is regular. • Show that uv k w is not in L, for some k – Then there is an FA, M that accepts L. • The above contradicts the Pumping Lemma – Let n be the number of states in M • Our assumption that L is regular is wrong • L must not be regular 5
Pumping lemma Pumping lemma • Example: • x = uvw = 0 n 1 n – L = {x ∈ {0,1} * | 0 i 1 i , i ≥ 0} – 00 … 0 11 … 1 – Let’s play • Choose an appropriate string x ∈ L – Since |uv| ≤ n, uv must consists entirely of 0s – Let x = 0 n 1 n • Apply Pumping Lemma to x and, as such, v must also consist entirely of 0s. – x = uvw • v = 0 j for some j ≤ n – |uv| ≤ n – |v| > 0 Pumping lemma Pumping lemma • x = uvw = 0 n 1 n = 0 i 0 j 0 k 1 n i + j+k= n • We arrived at a contradiction, – Thus our original assumption that L is regular must be – Let’s pump! incorrect – By the Pumping Lemma – Thus L is not regular. • uv 2 w is also in L • Note that we need to find only 1 string x that fails • uv 2 w = 0 i 0 2j 0 k 1 n in order for the proof by contradiction to work. • Certainly i + 2j + k ≠ n – The key is finding the x that won’t work • uv 2 w has more 0’s that 1’s • Thus uv 2 w ∉ L CONTRADICTION! • Questions? Pumping Lemma Pumping Lemma • Let’s try another example: • Another Example: – L = {x ∈ {0,1} * | 0 i x, |x| ≤ i} – L = {x ∈ {0,1} * | 0 i x, |x| ≤ i} – Ex: 0001, 0010, Λ , 0000101 – Let’s play • Choose an appropriate string x ∈ L – Let’s play! – Let x = 0 n 1 n • Assume that L is regular. • Apply Pumping Lemma to x – Then there is an FA, M that accepts L. – x = uvw – Let n be the number of states in M – |uv| ≤ n – |v| > 0 6
Recommend
More recommend