Pumping lemma for context-free languages

From testwiki
Jump to navigation Jump to search

Template:Short description In computer science, in particular in formal language theory, the pumping lemma for context-free languages, also known as the Bar-Hillel lemma,Template:Sfn is a lemma that gives a property shared by all context-free languages and generalizes the pumping lemma for regular languages.

The pumping lemma can be used to construct a refutation by contradiction that a specific language is not context-free. Conversely, the pumping lemma does not suffice to guarantee that a language is context-free; there are other necessary conditions, such as Ogden's lemma, or the Interchange lemma.

Formal statement

Template:Dark mode invert If a language L is context-free, then there exists some integer p≥1 (called a "pumping length")Template:Sfn such that every string s in L that has a length of p or more symbols (i.e. with |s|≥p) can be written as

s=uvwxy

with substrings u,v,w,x and y, such that

  1. |vx|≥1,
  2. |vwx|≤p, and
  3. uvnwxny∈L for all n≥0.

Below is a formal expression of the Pumping Lemma.

(∀L⊆Σ∗)(context free(L)⇒((∃p≥1)((∀s∈L)((|s|≥p)⇒((∃u,v,w,x,y∈Σ∗)(s=uvwxy∧|vx|≥1∧|vwx|≤p∧(∀n≥0)(uvnwxny∈L)))))))

Informal statement and explanation

The pumping lemma for context-free languages (called just "the pumping lemma" for the rest of this article) describes a property that all context-free languages are guaranteed to have.

The property holds for all strings in the language that are of length at least p, where p is a constant—called the pumping length—that varies between context-free languages.

Say s is a string of length at least p that is in the language.

The pumping lemma states that s can be split into five substrings, s=uvwxy, where vx is non-empty and the length of vwx is at most p, such that repeating v and x the same number of times (n) in s produces a string that is still in the language. It is often useful to repeat zero times, which removes v and x from the string (this is "pumping down"). This process of "pumping up" s with additional copies of v and x is what gives the pumping lemma its name.

Finite languages (which are regular and hence context-free) obey the pumping lemma trivially by having p equal to the maximum string length in L plus one. As there are no strings of this length the pumping lemma holds vacuously.

Usage of the lemma

The pumping lemma is often used to prove that a given language Template:Mvar is non-context-free, by showing that arbitrarily long strings Template:Mvar are in Template:Mvar that cannot be "pumped" without producing strings outside Template:Mvar.

For example, if S⊂ℕ is infinite but does not contain an (infinite) arithmetic progression, then L={an:n∈S} is not context-free. In particular, neither the prime numbers nor the square numbers are context-free.

For example, the language L={anbncn|n>0} can be shown to be non-context-free by using the pumping lemma in a proof by contradiction. First, assume that Template:Mvar is context free. By the pumping lemma, there exists an integer Template:Mvar which is the pumping length of language Template:Mvar. Consider the string s=apbpcp in Template:Mvar. The pumping lemma tells us that Template:Mvar can be written in the form s=uvwxy, where Template:Mvar, and Template:Mvar are substrings, such that |vx|≥1, |vwx|≤p, and uviwxiy∈L for every integer i≥0. By the choice of Template:Mvar and the fact that |vwx|≤p, it is easily seen that the substring Template:Mvar can contain no more than two distinct symbols. That is, we have one of five possibilities for Template:Mvar:

  1. vwx=aj for some j≤p.
  2. vwx=ajbk for some Template:Mvar and Template:Mvar with j+k≤p
  3. vwx=bj for some j≤p.
  4. vwx=bjck for some Template:Mvar and Template:Mvar with j+k≤p.
  5. vwx=cj for some j≤p.

In each case, uviwxiy does not contain equal numbers of each letter for any i≠1. Thus, uv2wx2y does not have the form aibici. This contradicts the definition of Template:Mvar. Therefore, our initial assumption that Template:Mvar is context free must be false.

In 1960, Scheinberg proved that L={anbnan|n>0} is not context-free using a precursor of the pumping lemma.Template:Sfn

While the pumping lemma is often a useful tool to prove that a given language is not context-free, there are languages that are not context-free, but still satisfy the condition given by the pumping lemma, for example L={bjckdl|j,k,l∈ℕ}∪{aibjcjdj|i,j∈ℕ,i≥1} For s=bjckdl with e.g. j≥1, choose vwx to consist only of b's, for aibjcjdj, choose vwx to consist only of a's. In both cases all pumped strings are still in L.Template:Sfn

To prove that a given language is context-free, it is sufficient to construct a pushdown automaton that accepts it.

Notes

Template:Reflist

References

Template:Refbegin

Template:Refend

Template:Formal languages and grammars