1.4 Nonregular Languages How do you prove a language is Regular? construct DFA, NFA, or regular expression What happens when you try to build a machine that recognizes the language? B = { a^n b^n | n >= 0 } use states to count the a's ??? number of a's is unbounded number of states must be finite When you try to build a machine and you fail, have you proven the language is not regular? success in building machine proves language is regular failure proves nothing How do you prove a language is not regular? The Pumping Lemma For Regular Languages What's Pumping? strings in regular languages can be pumped (if they are long enough) pumping means section of string can be repeated a*b* aaaaabbb a b* a abbbbbba How do you know that all regular languages have the pumping property? Suppose you give a string s of length n as input to a DFA with p states where n is at least as big as p. How many states does the machine enter while processing the input? the machine enters n+1 (at least p+1) states If the machine has only p states but the machine enters at least p+1 states while processing the input, what must be true about the sequence of states that the machine enters? there's a repeated state somewhere in the first p+1 states Suppose the machine accepts the string s and suppose you divide s into three parts, where x is the part before the repeated state is first entered, y is the part between the two times the repeated state is entered, and z is the part after the second time the repeated state is entered. Since the machine accepts the string s and s is the concatenation of xyz, will the machine also accept the string xyyz? What other strings will the machine accept? the machine will accept x(y^i)z for each i >= 0 Can you say anything about the length of the y part of the string? the machine must use at least one arrow when processing y so y must be at least length 1 Since the repeated state occurs within the first p+1 states of the execution, can you say anything about the length of the x and y parts of the string combined? the length of xy is at most p What's the Pumping Lemma? if A is a regular language then there is a number p (the pumping length) where if s is any string in A with length at least p then s can be divided into s = xyz where three conditions are true 1. for each i >= 0, x(y^i)z is in A 2. length of y > 0 3. length of xy <= p Using the Pumping Lemma How can you use the Pumping Lemma to show a language is not regular? pumping lemma says if a language is regular, it can be pumped show the language can't be pumped, then it can't be regular What are the standard steps for using the Pumping Lemma to prove a language B is not regular? 1. assume B is regular (proof by contradiction) 2. find a string s in B with length at least p that cannot be pumped 3. state (by the pumping lemma) that strings in B with length at least as long as the pumping length p can be pumped 4. show that no matter how you divide s into xyz, s cannot be pumped Prove language C is not regular using the pumping lemma. C = { a^n b^2n | n >= 0 } The proof is by contradiction. Assume C is regular. Let p be the pumping length given by the pumping lemma. Choose s to be the string a^p b^(2p). Since s is in C and s is longer than p, by the pumping lemma, s can be split into xyz where the string xyyz is in C. (the hard way) Consider three cases: 1. y contains only a's then xyyz has extra a's but no extra b's and is not in C 2. y contains only b's then xyyz has extra b's but no extra a's and is not in C 3. y contains both a's and b's then xyyz has some b's before a's and is not in C s cannot be pumped no matter how it is divided. So the assumption is wrong and C is not regular. (the easy way) Since the length of xy must be no more than p, y must contain only a's. Then xyyz has extra a's but no extra b's and is not in C. So the assumption is wrong and C is not regular. Are you allowed to choose a specific value for p when using the pumping lemma? no, the lemma doesn't claim to be true for any value of p Are you allowed to choose a specific string s when using the pumping lemma? yes, as long as s is at least as long as p Are you allowed to choose a specific division of s into x, y, and z when using the pumping lemma? no, the lemma doesn't claim to work for any division Can you use the Pumping Lemma to show that a language is regular? no pumping lemma says if a language is regular it can be pumped it does not say if a language can be pumped, it is regular When you try to prove a language is not regular using the pumping lemma and you fail, have you proven the language is regular? no never use the pumping lemma to prove a language is regular Suppose you try to prove a language is not regular using the pumping lemma and you discover a string that can be pumped. What have you proven? nothing Classwork (You may work with a partner.) Prove language D is not regular using the pumping lemma. D = { a^n b a^n | n >= 0 }