Use . A halting algorithm checks that a word consists of three consecutive blocks in the correct order and compares their lengths, so is a decidable language. If it were a context-free language, apply the pumping lemma for context-free languages to . The segment containing both pumped pieces has length at most , so it cannot meet both the and blocks. Pumping down therefore changes at least one block count but leaves another equal to , or destroys the required block order. Either way the resulting word is not in , a contradiction. Thus is a decidable language but not a context-free language.
The context-free languages and have context-free grammars , , , and , , , respectively.
Their intersection is . Suppose satisfied the pumping lemma for context-free languages with length . In a decomposition with and , the window cannot meet both the and blocks. Pumping down changes at least one count and leaves at least one count unchanged. Thus the three counts are unequal, or the word order is invalid, contrary to the pumping lemma for context-free languages. Hence CFLs are not closed under intersection.
The pumping lemma for context-free languages states that every context-free language has a pumping length such that every with can be written
with , , and for every integer .
This language is not context-free. Let be a proposed pumping length and choose with . In any pumping decomposition of the unary word , pumping once more increases its length by an integer with . But
so the pumped length is not a power of three, contrary to the pumping lemma for context-free languages. This is also an instance of the fact that a unary context-free language is regular, whereas the powers of three are not ultimately periodic.
This language is not context-free. Suppose it were, and define the homomorphism
Then closure under inverse homomorphism and intersection of a context-free language with a regular language would make
context-free. The equality holds because the midpoint of a square with four nonempty alternating runs must lie between its second and third runs.
Apply the pumping lemma for context-free languages to . A pumpable window of length at most meets at most two adjacent blocks. Pumping changes at least one block but cannot reach its equal-count partner two blocks away, so either the counts or the counts cease to agree. This contradiction proves the claim.
The pumping lemma for context-free languages states that for every context-free language there is a pumping length such that every with can be written
with
The language is not context-free. Suppose it had pumping length in the pumping lemma for context-free languages, and apply the lemma to . Write with , , and for every .
Let and be the respective numbers of s and s in . If , pumping with or destroys equality of the two block lengths. Hence a valid decomposition would require . Pumping with would then produce , where . But
so is not a square number. This contradiction proves the square-count language is not context-free.
A parse tree has the start variable at its root; the ordered children of a variable spell the right side of the production used at that occurrence, and its leaves, read left to right, spell the derived word.
For a grammar in Chomsky normal form with variables, take pumping length . A parse tree for a word of length at least has a root-to-leaf path containing one variable twice. The yield can therefore be written
where , , and replacing the subtree between the repeated variables zero, one, or several times proves
This is the pumping lemma for context-free languages. Without Chomsky normal form but with no epsilon or unit productions, use the maximum production length to choose a larger exponential ; bounded branching and the same repeated-variable argument apply.
The language is not context free. A pumped window of bounded length cannot alter all three long blocks equally, so pumping breaks one of the required equalities.
A context-free grammar is a quadruple consisting of finite nonterminal and terminal alphabets, a set of productions with one nonterminal on the left, and a start symbol . A context-free language is a language generated by such a grammar.
The pumping lemma for context-free languages says that there is a pumping length such that every in the language with can be written
with , , and in the language for every integer .
The language in (i) is not context-free. If it were, pump
The substring , having length at most , cannot meet both the - and -blocks. If pumping changes the number of 's or 's, those two counts cease to agree. If it changes neither, it changes the number of 's while the outer counts remain , so the middle count ceases to be . Every permitted decomposition therefore fails, contradicting the pumping lemma.
Assume that is context-free and let be its pumping length. Apply the pumping lemma for context-free languages to
Write , with and . The substring meets at most two of the three constant-letter blocks.
If and affect only the first block, only the middle block, or only the last block, pumping down immediately makes the final block length differ from the minimum of the first two lengths. If they meet the first and second blocks, pumping down decreases at least one of those block lengths while leaving the final length , again violating the defining minimum.
It remains that they meet the second and third blocks. Let pumping change their lengths by and , respectively. Pumping down fails unless . If , pumping up gives lengths
whose last entry is not . Thus some pumping exponent always leaves , contradicting the lemma. Hence
A type-2 rule is with one nonterminal on the left; a type-2 grammar and its language are context-free languages. The required repetition criterion is the pumping lemma for context-free languages.
It is not context-free. Intersecting it with the regular language would give , which violates the pumping lemma for context-free languages. Context-free languages are closed under intersection with regular languages.