Closure Properties
Once you have a small collection of non-context-free languages you can often use closure properties of CFL like this:
Assume L∈CFL. Then, by closure property X (together with Y), L′∈CFL. This contradicts L′∉CFL which we know to hold, therefore L∉CFL.
This is often shorter (and often less error-prone) than using one of the other results that use less prior knowledge. It is also a general concept that can be applied all kinds of class of objects.
Example 1: Intersection with Regular Languages
We note L(e) the regular language specified by any regular expression e.
Let L={w∣w∈{a,b,c}∗,|w|a=|w|b=|w|c}. As
L∩L(a∗b∗c∗)={anbncn∣n∈N}∉CFL
and CFL is closed under intersection with regular languages, L∉CFL.
Example 2: (Inverse) Homomorphism
Let L={(ab)2ncmd2n−m(aba)n∣m,n∈N}. With the homomorphism
ϕ(x)=⎧⎩⎨aεbx=ax=bx=c∨x=d
we have ϕ(L)={a2nb2na2n∣n∈N}.
Now, with
ψ(x)={aabbx=a∨x=cx=bandL1={xnbnyn∣x,y∈{a,c}∧n∈N},
we get L1=ψ−1(ϕ(L))).
Finally, intersecting L1 with the regular language L2=L(a∗b∗c∗) we get the language L3={anbncn∣n∈N}.
In total, we have L3=L2∩ψ−1(ϕ(L)).
Now assume that L was context-free. Then, since CFL is closed against homomorphism, inverse homomorphism, and intersection with regular sets, L3 is context-free, too. But we know (via Pumping Lemma, if need be) that L3 is not context-free, so this is a contradiction; we have shown that L∉CFL.
Interchange Lemma
The Interchange Lemma [1] proposes a necessary condition for context-freeness that is even stronger than Ogden's Lemma. For example, it can be used to show that
{xyyz∣x,y,z∈{a,b,c}+}∉CFL
which resists many other methods. This is the lemma:
Let L∈CFL. Then there is a constant cL such that for any integer n≥2, any set Qn⊆Ln=L∩Σn and any integer m with n≥m≥2 there are k≥|Qn|cLn2 strings zi∈Qn with
- zi=wixiyi for i=1,…,k,
- |w1|=|w2|=⋯=|wk|,
- |y1|=|y2|=⋯=|yk|,
- m≥|x1|=|x2|=⋯=|xk|>m2 and
- wixjyi∈Ln for all (i,j)∈[1..k]2.
Applying it means to find n,m and Qn such that 1.-4. hold but 5. is violated. The application example given in the original paper is very verbose and is therefore left out here.
At this time, I do not have a freely available reference and the formulation above is taken from a preprint of [1] from 1981. I appreciate help in tracking down better references. It appears that the same property has been (re)discovered recently [2].
Other Necessary Conditions
Boonyavatana and Slutzki [3] survey several conditions similar to Pumping and Interchange Lemma.
- An “Interchange Lemma” for Context-Free Languages by W. Ogden, R. J. Ross and K. Winklmann (1985)
- Swapping Lemmas for Regular and Context-Free Languages by T. Yamakami (2008)
- The interchange or pump (DI)lemmas for context-free languages by R. Boonyavatana and G. Slutzki (1988)