The Burning Question… • We’ve looked at a number of regular languages The Pumping Lemma • I know that you are just dying to know… – Is there a language L that is not regular? – To answer this, we’ll use what is known as The Pumping Lemma. The Pumping Lemma The Pumping Lemma • Statement of the pumping lemma • The pumping lemma formalizes the idea that if a string from a RL is long enough, eventually at – Let L be a regular language. least one state on its FA will be have to be – Then there exists a constant n (which varies repeated on the path that accepts the string. for different languages), such that for every string x ∈ L with |x| ≥ n, x can be expressed – Implies that there is a Kleene star in there somewhere! as x = uvw such that: • Continually looping on this state will produce an 1. |v| > 0 infinite number of strings in the language 2. |uv| ≤ n 3. For all k ≥ 0, the string uv k w is also in L. The Pumping Lemma Pumping Lemma • What this means • Proof of the pumping lemma – Since L is regular, there is a FA M=(Q, Σ ,q 0 ,A, δ ) that – For a long enough string x in L: accepts L. • We can express x as the concatenation of three • Assume M has n states. smaller strings – Consider a string x with |x| = m ≥ n. • The middle string can be “pumped” (repeated) any • Express x = a 1 a 2 a 3 … a m where each a i ∈ Σ . number of times (including 0 = deleting) and the – Define p i to be the state M is in after reading i resulting string will be in L. characters: • p i = (q 0 , a 1 a 2 …a i ) ^ δ • p 0 = q 0 1
Pumping Lemma Pumping Lemma • Proof of the pumping lemma • Proof of pumping lemma – Since |x| ≥ n, and we only have n states, one • Then x = uvw – u = a 1 a 2 …a i state on it’s path must visited more than once. – v = a i+1 a i+2 …a j • There exists integers i and j, 0 ≤ i < j ≤ n such that – w = a j+1 a j+2 …a m p i = p j • Then x = uvw v = a i+1 a i+2 …a j – u = a 1 a 2 …a i – 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 – w = a j+1 a j+2 …a m Pumping Lemma Pumping Lemma • Proof of pumping lemma • So what good is the pumping lemma? – You can loop (pump) on the v loop 0 or more times and there will still be a path to the • It can be used to answer that burning accepting state. question: v = a i+1 a i+2 …a j – Is there a language L that is not regular? u = a 1 a 2 …a i w = a j+1 a j+2 …a m p 0 p i 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 • Assume that the language to be tested is regular out here? • 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!!!! 2
Pumping lemma Pumping Lemma • The Pumping Lemma game – To show that a language L is not regular • Assume L is regular • Choose an “appropriate” string x in L – In terms of n (number of states in DFA) • Express x = uvw following rules of pumping lemma • Show that uv k w is not in L, for some k • The above contradicts the Pumping Lemma • Our assumption that L is regular is wrong • L must not be regular Pumping lemma Pumping lemma • Example: • Example – L = {x ∈ {0,1} * | 0 i 1 i , i ≥ 0} – Let’s play! – Ex: 000111, 0011, ε , 00001111 • Assume that L is regular. – Then there is an FA, M that accepts L. – Let n be the number of states in M 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 3
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 Pumping Lemma Pumping Lemma • x = uvw = 0 n 1 n = 0 i 0 j 0 k 1 n i + j+k= n • x = uvw = 0 n 1 n – Let’s (un)pump! – 00 … 0 11 … 1 – By the Pumping Lemma • uv 0 w is also in L – Since |uv| ≤ n, uv must consists entirely of 0s • uv 0 w = uw = 0 i 0 k 1 n and, as such, v must also consist entirely of 0s. • Certainly n > i + k • v = 0 j for some j ≤ n • The length of the prefix of 0s is less than the suffix x • Thus uv 0 w ∉ L CONTRADICTION! 4
Pumping Lemma Non-regular languages • We arrived at a contradiction, • Informal notion of what regular languages – Thus our original assumption that L is regular must be can’t express: incorrect – Counting and comparing – Thus L is not regular. – Any operation that implies the use of a stack • Note that we need to find only 1 string x that fails • Pal in order for the proof by contradiction to work. • xx r – We can show x not to work by pumping 0 times • Questions? Pumping Lemma Pumping Lemma • Let’s try another example: • Another Example: – L = set of palindromes over {a,b} – L = set of palindromes over {a,b} • Strings that read the same forwards and backwards – Let’s play • “Madam I’m Adam” • Choose an appropriate string x ∈ L – Ex: aa, abba, abbbbba, ε – Let x = a n ba n – Let’s play! • Apply Pumping Lemma to x • Assume that L is regular. – x = uvw – Then there is an FA, M that accepts L. – |uv| ≤ n – Let n be the number of states in M – |v| > 0 Pumping Lemma Pumping Lemma • x = uvw = a n ba n = a i a j a k ba n i + j+k= n • x = uvw = a n ba n – Let’s pump! – aa … a b aa … a – By the Pumping Lemma • uv 2 w is also in L – Since |uv| ≤ n, uv must consists entirely of a • uv 2 w has more than n a’s and, as such, v must also consist entirely of a. • Number of a’s following b is still n • v = a j for some j ≤ n • Thus uv 2 w cannot be a palidrome • Thus uv 2 w ∉ L CONTRADICTION! 5
Pumping Lemma Pumping Lemma • We arrived at a contradiction, • Summary – Thus our original assumption that L is regular must be – The pumping lemma formalizes the idea that if incorrect a string is longer enough, eventually at least one state on the DFA will be have to be – Thus L is not regular. repeated on the path that accepts the string. – Continually looping on this state will produce • Note that we need to find only 1 string x that fails an infinite number of strings in the language in order for the proof by contradiction to work. – Used to show that languages are not regular – Has other uses as we’ll see next time. • Questions? Non-regular languages Next time • Venn-diagram of languages • Decision properties / algorithms for RLs Is there something Regular Languages • Problem Session… out here? YES • Questions? Finite Languages 6
Recommend
More recommend