Is the language {$a^{i}b^{j}c^{k} ~|~ i \neq j, i \neq k, j \neq k$} context-free or not?

I realized that I have encountered almost all variants of this question with different conditions about the relationship between i, j, and k, but not this one.

My guess is that it is not context-free, but do you have a proof?

  • 11
    $\begingroup$ @Sariel: I hope that it is not a homework problem, because I do not know how to solve it. $\endgroup$ Commented Sep 30, 2010 at 19:57
  • 3
    $\begingroup$ It looks like a homework problem, since some of the other variants that I mention are sufficiently easy to be homework problems. But this variant is not a homework problem. I would be glad if anyone can give me a link to any course site where this particular problem has been assigned as a homework, though. $\endgroup$
    – Cem Say
    Commented Sep 30, 2010 at 19:58
  • 2
    $\begingroup$ Can you explain why the standard techniques don't work? $\endgroup$ Commented Sep 30, 2010 at 23:01
  • 3
    $\begingroup$ @Tsuyoshi... Yeh. You are right. Its harder than it looks. $\endgroup$ Commented Oct 1, 2010 at 0:46
  • 3
    $\begingroup$ Curiously, this language (and the use of Ogden's Lemma) can be found in Example 6.3 (p. 130) in the classical version of Hopcroft and Ullman's "Introduction to Automata Theory, Languages and Computation". $\endgroup$ Commented Sep 24, 2011 at 7:41

2 Answers 2


Ogden's lemma should work:

For a given $p$ choose $a^i b^p c^k$ and mark all the $b$'s (and nothing else).

$i$ and $k$ are chosen such that for every choice of how many $b$'s are actually pumped there is one pumping exponent such that the number of $b$'s is equal to $i$ and one where it is equal to $k$.

That is $i$ and $k$ have to be from the set $\bigcap_{1 \leq n \leq p} \lbrace p-n + m*n \mid m \in \mathbb{N}_0\rbrace$.

I am quite sure but too lazy to formally prove that this set is infinite.

  • 6
    $\begingroup$ Assuming that IN_0 means the set of nonnegative integers, the mentioned set is infinite because it contains p+im for i=0, 1, 2, …, where m is the least common multiple of {1, …, p}. $\endgroup$ Commented Oct 1, 2010 at 0:28
  • 11
    $\begingroup$ Those who did not know Ogden’s lemma (like me) may find Wikipedia helpful. $\endgroup$ Commented Oct 1, 2010 at 0:32
  • 3
    $\begingroup$ @Tsuyoshi: Yes, you're right. I didn't see this simple representation yesterday night. $\endgroup$ Commented Oct 1, 2010 at 6:30
  • 1
    $\begingroup$ This answer is featured on the community blog. $\endgroup$ Commented Oct 27, 2011 at 12:05
  • $\begingroup$ A similar proof is presented in this answer on cs.se. $\endgroup$ Commented Jan 2, 2014 at 18:44

If the relation between the three restrictions is "OR", then the language is CFL. The solution uses the fact that CFLs are closed under union. Clearly, the following are CFLs: $L_1=\{a^ib^jc^k \mid i\ne j,\ k\ge 0\}$, $L_2=\{a^ib^jc^k \mid i\ne k,\ j\ge 0\}$, $L_3=\{a^ib^jc^k \mid j\ne k,\ i\ge 0\}$ (if one is not convinced, one can look on $L_i$ as concatenation of CFL and regular language. For instance, $L_1$ is $\{a^ib^j\mid i\ne j \}$ concatenated to $\{c\}^*$.

The desired language is the union of the above $L=L_1\cup L_2\cup L_3$. So, it is CFL.

  • 5
    $\begingroup$ This is wrong. For example, $aabcc\in L_1$ and hence in your $L$, but $aabcc\notin\lbrace a^ib^jc^k~|~i\neq j,i\neq k,j\neq k\rbrace$. $\endgroup$ Commented May 26, 2011 at 7:45
  • 4
    $\begingroup$ You assume that »the relation between the three restrictions is "OR"«, but this is not the intended meaning. All of the restrictions have to hold (cf. Dave Clarke's counterexample), and then the language is not context-free (cf. the answer above). $\endgroup$
    – DaniCL
    Commented May 26, 2011 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.