Consider the following figure:
From the diagram, we can conclude that not all languages are context free. Every context-free language (CFL) is also a context-sensitive and an unrestricted (recursively enumerable) language, but the converses do not hold: there exist context-sensitive and unrestricted languages that are not context free. The pumping lemma for CFLs gives a mechanical way to prove that certain languages are not context free.
Let G be a context-free grammar (CFG). Then there exists a constant n (depending on G) such that if a string W belongs to L(G) and its length satisfies |W| ≥ n, then W can be written as
\[ W = u v x y z \]
\[ u v^{\,i} x y^{\,i} z \in L(G). \]
This statement is the pumping lemma for context-free languages. Informally, it says that any sufficiently long string generated by a CFG contains a region that can be "pumped" (duplicated or removed) in two places while remaining in the language.
One standard proof uses grammars in Chomsky Normal Form (CNF). In CNF every internal node of a parse tree has exactly two children. If the parse tree for a string is tall enough (height greater than the number of variables in the grammar), then along some path from the root to a leaf a variable must repeat. The repeated variable yields two subtrees whose yields allow the decomposition \(W = u v x y z\) and the pumping property. The bound n can be chosen from the number of variables (nonterminals) of the grammar.
Show that \(L = \{\, a^{n} b^{n} c^{n} \mid n \ge 1 \,\}\) is not context free.
Step 1:
Assume \(L\) is context free. Let \(n\) be the pumping length provided by the lemma.
Step 2:
Choose
\[ W = a^{n} b^{n} c^{n}, \]
so \(|W| = 3n \ge n\). By the pumping lemma write
\[ W = u v x y z \]
with \(|v y| \ge 1\) and \(|v x y| \le n\).
Step 3 (case analysis):
Because \(|v x y| \le n\), the substring \(v x y\) lies entirely within a block of at most two consecutive symbol types among the three blocks \(a^{n}, b^{n}, c^{n}\). Therefore the possibilities are:
In every case, pumping changes the relative numbers or the order of symbols so the pumped string cannot remain of the form \(a^{m} b^{m} c^{m}\) for any \(m\). Concretely:
Thus for any allowed decomposition guaranteed by the pumping lemma, there exists \(i\) with \(u v^{\,i} x y^{\,i} z
otin L\). This contradiction proves \(L\) is not context free.
Show that \(L = \{\, a^{p} \mid p \text{ is a prime number} \,\}\) is not context free.
Step 1:
Assume \(L\) is context free and let \(n\) be the pumping length.
Step 2:
Choose a prime \(p > n\) and consider
\[ W = a^{p} \in L. \]
Write \(W = u v x y z\) with \(|v y| \ge 1\) and \(|v x y| \le n\).
Step 3:
By the pumping lemma \(u x z = u v^{\,0} x y^{\,0} z \in L\). Let
\[ |u x z| = q, \]
so \(q\) is a prime (since \(u x z \in L\)). Let
\[ |v y| = r \ge 1. \]
Now consider the string pumped with \(i = q\):
\[ |u v^{\,q} x y^{\,q} z| = q + q r = q(1+r). \]
Because \(r \ge 1\), the product \(q(1+r)\) is composite, so \(u v^{\,q} x y^{\,q} z
otin L\). This contradicts the pumping lemma requirement that all pumped strings lie in \(L\). Hence \(L\) is not context free.
Show that \(L = \{\, a^{n} b^{n} c^{n} \mid n \ge 0 \,\}\) is not context free.
The language in Example 1 started at \(n\ge 1\); allowing \(n=0\) only adds the empty string to the language and does not affect the pumping argument. The same proof as Example 1 applies: pick \(W = a^{n} b^{n} c^{n}\) with \(n\) at least the pumping length, apply the lemma, and analyse cases for where \(v\) and \(y\) lie. In every possible decomposition pumping produces a string not of the form \(a^{m} b^{m} c^{m}\). Therefore this language is also not context free.
Summary
The pumping lemma for CFLs is a standard tool to prove that particular languages are not context free. Its formal statement gives a decomposition and a pumping property for sufficiently long strings of any CFL. The usual method of proof by contradiction-choosing a long string and showing every valid decomposition yields a pumped string outside the language-works for many important non-CFLs such as \(\{a^{n}b^{n}c^{n}\}\) and the set of prime-length unary strings.
| 1. What is the Pumping Lemma for Context Free Languages (CFLs)? | ![]() |
| 2. How does the Pumping Lemma help in proving that a language is not context-free? | ![]() |
| 3. Can the Pumping Lemma be used to prove that a language is context-free? | ![]() |
| 4. What are the conditions that need to be satisfied for the Pumping Lemma to apply? | ![]() |
| 5. Can the Pumping Lemma be applied to all languages? | ![]() |
![]() | Explore Courses for Computer Science Engineering (CSE) exam |
![]() | Get EduRev Notes directly in your Google search |