Pumping lemma for regular languages

From HandWiki
Short description: A lemma that defines a property of regular languages
For every long enough string in a regular language, there must be a middle section (y) that can be repeated (or pumped) any number of times to produce a string still in the language.

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.

Specifically, the pumping lemma says that for any regular language [math]\displaystyle{ L }[/math] there exists a constant [math]\displaystyle{ p }[/math] such that any string [math]\displaystyle{ w }[/math] in [math]\displaystyle{ L }[/math] with length at least [math]\displaystyle{ p }[/math] can be split into three substrings [math]\displaystyle{ x }[/math], [math]\displaystyle{ y }[/math] and [math]\displaystyle{ z }[/math] ([math]\displaystyle{ w = xyz }[/math], with [math]\displaystyle{ y }[/math] being non-empty), such that the strings [math]\displaystyle{ xz, xyz, xyyz, xyyyz, ... }[/math] constructed by repeating [math]\displaystyle{ y }[/math] zero or more times are still in [math]\displaystyle{ L }[/math]. This process of repetition is known as "pumping". Moreover, the pumping lemma guarantees that the length of [math]\displaystyle{ xy }[/math] will be at most [math]\displaystyle{ p }[/math], imposing a limit on the ways in which [math]\displaystyle{ w }[/math] may be split.

Languages with a finite number of strings vacuously satisfy the pumping lemma by having [math]\displaystyle{ p }[/math] equal to the maximum string length in [math]\displaystyle{ L }[/math] plus one. By doing so, zero strings in [math]\displaystyle{ L }[/math] have length greater than [math]\displaystyle{ p }[/math].

The pumping lemma is useful for disproving the regularity of a specific language in question. It was first proven by Michael Rabin and Dana Scott in 1959,[1] 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.[2][3]

Formal statement

Let [math]\displaystyle{ L }[/math] be a regular language. Then there exists an integer [math]\displaystyle{ p \geq 1 }[/math] depending only on [math]\displaystyle{ L }[/math] such that every string [math]\displaystyle{ w }[/math] in [math]\displaystyle{ L }[/math] of length at least [math]\displaystyle{ p }[/math] ([math]\displaystyle{ p }[/math] is called the "pumping length")[4] can be written as [math]\displaystyle{ w = xyz }[/math] (i.e., [math]\displaystyle{ w }[/math] can be divided into three substrings), satisfying the following conditions:

  1. [math]\displaystyle{ |y| \geq 1 }[/math]
  2. [math]\displaystyle{ |xy| \leq p }[/math]
  3. [math]\displaystyle{ (\forall n \geq 0) ( xy^nz \in L ) }[/math]

[math]\displaystyle{ y }[/math] is the substring that can be pumped (removed or repeated any number of times, and the resulting string is always in [math]\displaystyle{ L }[/math]). (1) means the loop [math]\displaystyle{ y }[/math] 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 [math]\displaystyle{ p }[/math] characters. [math]\displaystyle{ |x| }[/math] must be smaller than [math]\displaystyle{ p }[/math] (conclusion of (1) and (2)), but apart from that, there is no restriction on [math]\displaystyle{ x }[/math] and [math]\displaystyle{ z }[/math].

In simple words, for any regular language [math]\displaystyle{ L }[/math], any sufficiently long string [math]\displaystyle{ w }[/math] (in [math]\displaystyle{ L }[/math]) can be split into 3 parts. i.e. [math]\displaystyle{ w = xyz }[/math] , such that all the strings [math]\displaystyle{ xy^nz }[/math] for [math]\displaystyle{ n \geq 0 }[/math] are also in [math]\displaystyle{ L }[/math].

Below is a formal expression of the Pumping Lemma.

[math]\displaystyle{ \begin{array}{l} (\forall L\subseteq \Sigma^*) \\ \quad (\mbox{regular}(L) \Rightarrow \\ \quad ((\exists p\geq 1) ( (\forall w\in L) ((|w|\geq p) \Rightarrow \\ \quad ((\exists x,y,z \in \Sigma^*) (w=xyz \land (|y|\geq 1 \land |xy|\leq p \land (\forall n\geq 0)(xy^nz\in L)))))))) \end{array} }[/math]

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 [math]\displaystyle{ L = \{a^n b^n : n \geq 0\} }[/math] over the alphabet [math]\displaystyle{ \Sigma = \{a, b\} }[/math] can be shown to be non-regular as follows:

  1. Let [math]\displaystyle{ w, x, y, z, p }[/math], and [math]\displaystyle{ n }[/math] be as used in the formal statement for the pumping lemma above.
  2. Assume that some constant [math]\displaystyle{ p }[/math] exists as required by the lemma.
  3. Let [math]\displaystyle{ w }[/math] in [math]\displaystyle{ L }[/math] be given by [math]\displaystyle{ w = a^p b^p }[/math], which is a string longer than [math]\displaystyle{ p }[/math].
  4. By the pumping lemma, there must exist a decomposition [math]\displaystyle{ w = xyz }[/math] with [math]\displaystyle{ |xy| \leq p }[/math] and [math]\displaystyle{ |y| \geq 1 }[/math] such that [math]\displaystyle{ xy^iz }[/math] in [math]\displaystyle{ L }[/math] for every [math]\displaystyle{ i \geq 0 }[/math].
  5. Since [math]\displaystyle{ |xy| \leq p }[/math], the string [math]\displaystyle{ y }[/math] only consists of instances of [math]\displaystyle{ a }[/math].
  6. Because [math]\displaystyle{ |y| \geq 1 }[/math], it contains at least one instance of the letter [math]\displaystyle{ a }[/math].
  7. Pumping y to give [math]\displaystyle{ xy^2z }[/math] gives a word with more instances of the letter [math]\displaystyle{ a }[/math] than the letter [math]\displaystyle{ b }[/math], since some instances of [math]\displaystyle{ a }[/math] but none of [math]\displaystyle{ b }[/math] were added.
  8. Therefore, [math]\displaystyle{ xy^2z }[/math] is not in [math]\displaystyle{ L }[/math] which contradicts the Pumping lemma.
  9. Therefore, [math]\displaystyle{ L }[/math] can not be regular.

The proof that the language of balanced (i.e., properly nested) parentheses is not regular follows the same idea. Given [math]\displaystyle{ p }[/math], there is a string of balanced parentheses that begins with more than [math]\displaystyle{ p }[/math] left parentheses, so that [math]\displaystyle{ y }[/math] will consist entirely of left parentheses. By repeating [math]\displaystyle{ y }[/math], 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

Proof idea: Whenever a sufficiently long string xyz is recognized by a finite automaton, it must have reached some state ([math]\displaystyle{ q_s = q_t }[/math]) twice. Hence, after repeating ("pumping") the middle part [math]\displaystyle{ y }[/math] arbitrarily often (xyyz, xyyyz, ...) the string will still be recognized.

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 [math]\displaystyle{ p }[/math]. For a string of length at least [math]\displaystyle{ p }[/math], let [math]\displaystyle{ q_0 }[/math] be the start state and let [math]\displaystyle{ q_1, ..., q_p }[/math] be the sequence of the next [math]\displaystyle{ p }[/math] states visited as the string is emitted. Because the FSA has only [math]\displaystyle{ p }[/math] states, within this sequence of [math]\displaystyle{ p+1 }[/math] visited states there must be at least one state that is repeated. Write [math]\displaystyle{ q_s }[/math] for such a state. The transitions that take the machine from the first encounter of state [math]\displaystyle{ q_s }[/math] to the second encounter of state [math]\displaystyle{ q_s }[/math] match some string. This string is called [math]\displaystyle{ y }[/math] in the lemma, and since the machine will match a string without the [math]\displaystyle{ y }[/math] portion, or with the string [math]\displaystyle{ y }[/math] repeated any number of times, the conditions of the lemma are satisfied.

For example, the following image shows an FSA.

An automat accepting the language a(bc)*d.svg

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 [math]\displaystyle{ q_1 }[/math] is a repeated state. Since the substring bc takes the machine through transitions that start at state [math]\displaystyle{ q_1 }[/math] and end at state [math]\displaystyle{ q_1 }[/math], that portion could be repeated and the FSA would still accept, giving the string abcbcd. 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 [math]\displaystyle{ x }[/math] portion a, a [math]\displaystyle{ y }[/math] portion bc and a [math]\displaystyle{ z }[/math] 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 [math]\displaystyle{ L }[/math] is regular, then there exists a number [math]\displaystyle{ p \geq 1 }[/math] (the pumping length) such that every string [math]\displaystyle{ uwv }[/math] in [math]\displaystyle{ L }[/math] with [math]\displaystyle{ |w| \ge p }[/math] can be written in the form

[math]\displaystyle{ uwv = uxyzv }[/math]

with strings [math]\displaystyle{ x }[/math], [math]\displaystyle{ y }[/math] and [math]\displaystyle{ z }[/math] such that [math]\displaystyle{ |xy| \le p }[/math], [math]\displaystyle{ |y| \ge 1 }[/math] and

[math]\displaystyle{ uxy^izv }[/math] is in [math]\displaystyle{ L }[/math] for every integer [math]\displaystyle{ i \geq 0 }[/math].[5]

From this, the above standard version follows a special case, with both [math]\displaystyle{ u }[/math] and [math]\displaystyle{ v }[/math] 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.

Converse of lemma not true

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:

[math]\displaystyle{ \begin{matrix}L & = & \{uvwxy : u,y \in \{0,1,2,3\}^*; v,w,x \in \{0,1,2,3\} \land (v=w \lor v=x \lor x=w)\} \\ & & \cup \ \{w : w \in \{0,1,2,3\}^*\land \text {precisely } \tfrac 1 7 \text{ of the characters in }w \text{ are 3's}\}\end{matrix} }[/math].

In other words, [math]\displaystyle{ L }[/math] contains all strings over the alphabet [math]\displaystyle{ \{0,1,2,3\} }[/math] 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 [math]\displaystyle{ p = 5 }[/math]. 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.

  • If the duplicate characters are separated by 0 characters, or 1, pump one of the other two characters in the string, which will not affect the substring containing the duplicates.
  • If the duplicate characters are separated by 2 or 3 characters, pump 2 of the characters separating them. Pumping either down or up results in the creation of a substring of size 3 that contains 2 duplicate characters.
  • The second condition of [math]\displaystyle{ L }[/math] ensures that [math]\displaystyle{ L }[/math] is not regular: Consider the string [math]\displaystyle{ (013)^{3m}(012)^i }[/math]. This string is in [math]\displaystyle{ L }[/math] exactly when [math]\displaystyle{ i=4m }[/math] and thus [math]\displaystyle{ L }[/math] is not regular by the Myhill–Nerode theorem.

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.

See also

Notes

  1. Rabin, Michael; Scott, Dana (Apr 1959). "Finite Automata and Their Decision Problems". IBM Journal of Research and Development 3 (2): 114–125. doi:10.1147/rd.32.0114. Archived from the original on December 14, 2010. https://web.archive.org/web/20101214122150/http://www.cse.chalmers.se/~coquand/AUTOMATA/rs.pdf.  Here: Lemma 8, p.119
  2. "On formal properties of simple phrase structure grammars", Zeitschrift für Phonetik, Sprachwissenschaft und Kommunikationsforschung 14 (2): 143–172, 1961 
  3. John E. Hopcroft; Rajeev Motwani; Jeffrey D. Ullman (2003). Introduction to Automata Theory, Languages, and Computation. Addison Wesley.  Here: Sect.4.6, p.166
  4. Berstel, Jean; Lauve, Aaron; Reutenauer, Christophe; Saliola, Franco V. (2009). Combinatorics on words. Christoffel words and repetitions in words. CRM Monograph Series. 27. Providence, RI: American Mathematical Society. p. 86. ISBN 978-0-8218-4480-9. 
  5. Savitch, Walter (1982). Abstract Machines and Grammars. p. 49. ISBN 978-0-316-77161-0. https://archive.org/details/abstractmachines0000savi/page/49. 

References

de:Pumping-Lemma#Reguläre Sprachen