Contents
Pumping lemma for regular languages
In the theory of formal languages, the pumping lemma for regular languages is a lemma that describes an essential property of all regular languages. Informally, it says that all sufficiently long strings in a regular language may be pumped—that is, have a middle section of the string repeated an arbitrary number of times—to produce a new string that is also part of the language. The pumping lemma is useful for proving that a specific language is not a regular language, by showing that that the language does not have the property. Specifically, the pumping lemma says that for any regular language L, there exists a constant p such that any string w in L with length at least p can be split into three substrings x, y and z (w = xyz, with y being non-empty), such that the strings are also in L. The process of repeating y zero or more times is known as "pumping". Moreover, the pumping lemma guarantees that the length of xy will be at most p, thus giving a "small" substring xy that has the desired property. Languages with a finite number of strings vacuously satisfy the pumping lemma by having p equal to the maximum string length in L plus one. By doing so, zero strings in L have length greater than p. The pumping lemma was first proven by Michael Rabin and Dana Scott in 1959, and rediscovered shortly after by Yehoshua Bar-Hillel, Micha A. Perles, and Eli Shamir in 1961, as a simplification of their pumping lemma for context-free languages.
Formal statement
Let L be a regular language. Then there exists an integer p \geq 1 depending only on L such that every string w in L of length at least p (p is called the "pumping length") can be written as w = xyz (i.e., w can be divided into three substrings), satisfying the following conditions: y is the substring that can be pumped (removed or repeated any number of times, and the resulting string is always in L). (1) means the loop y to be pumped must be of length at least one, that is, not an empty string; (2) means the loop must occur within the first p characters. |x| must be smaller than p (conclusion of (1) and (2)), but apart from that, there is no restriction on x and z. In simple words, for any regular language L, any sufficiently long string w (in L) can be split into 3 parts. i.e. w = xyz, such that all the strings xy^nz for n \geq 0 are also in L. Below is a formal expression of the pumping lemma.
Use of the lemma to prove non-regularity
The pumping lemma is often used to prove that a particular language is non-regular: a proof by contradiction may consist of exhibiting a string (of the required length) in the language that lacks the property outlined in the pumping lemma. Example: The language over the alphabet can be shown to be non-regular as follows: The proof that the language of balanced (i.e., properly nested) parentheses is not regular follows the same idea. Given p, there is a string of balanced parentheses that begins with more than p left parentheses, so that y will consist entirely of left parentheses. By repeating y, a string can be produced that does not contain the same number of left and right parentheses, and so they cannot be balanced.
Proof of the pumping lemma
For every regular language there is a finite state automaton (FSA) that accepts the language. The number of states in such an FSA are counted and that count is used as the pumping length p. For a string of length at least p, let q_0 be the start state and let be the sequence of the next p states visited as the string is emitted. Because the FSA has only p states, within this sequence of p+1 visited states there must be at least one state that is repeated. Write q_s for such a state. The transitions that take the machine from the first encounter of state q_s to the second encounter of state q_s match some string. This string is called y in the lemma, and since the machine will match a string without the y portion, or with the string y repeated any number of times, the conditions of the lemma are satisfied. For example, the following image shows an FSA. The FSA accepts the string: abcd. Since this string has a length at least as large as the number of states, which is four (so the total number of states that the machine passes through to scan abcd would be 5), the pigeonhole principle indicates that there must be at least one repeated state among the start state and the next four visited states. In this example, only q_1 is a repeated state. Since the substring bc takes the machine through transitions that start at state q_1 and end at state q_1, that portion could be repeated and the FSA would still accept, giving the string abc****bcd. Alternatively, the bc portion could be removed and the FSA would still accept giving the string ad. In terms of the pumping lemma, the string abcd is broken into an x portion a, a y portion bc and a z portion d. As a side remark, the problem of checking whether a given string can be accepted by a given nondeterministic finite automaton without visiting any state repeatedly, is NP hard.
General version of pumping lemma for regular languages
If a language L is regular, then there exists a number p \geq 1 (the pumping length) such that every string uwv in L with |w| \ge p can be written in the form with strings x, y and z such that |xy| \le p, |y| \ge 1 and From this, the above standard version follows a special case, with both u and v being the empty string. Since the general version imposes stricter requirements on the language, it can be used to prove the non-regularity of many more languages.
Invalidity of the lemma converse
While the pumping lemma states that all regular languages satisfy the conditions described above, the converse of this statement is not true: a language that satisfies these conditions may still be non-regular. In other words, both the original and the general version of the pumping lemma give a necessary but not sufficient condition for a language to be regular. For example, consider the following language: In other words, L contains all strings over the alphabet {0,1,2,3} with a substring of length 3 including a duplicate character, as well as all strings over this alphabet where precisely 1/7 of the string's characters are 3's. This language is not regular but can still be "pumped" with p = 5. Suppose some string s has length at least 5. Then, since the alphabet has only four characters, at least two of the first five characters in the string must be duplicates. They are separated by at most three characters. The Myhill–Nerode theorem provides a test that exactly characterizes regular languages. The typical method for proving that a language is regular is to construct either a finite state machine or a regular expression for the language.
This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.
Wikipedia® is a registered trademark of the
Wikimedia Foundation, Inc.
Bliptext is not
affiliated with or endorsed by Wikipedia or the
Wikimedia Foundation.