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$ Sep 30 '10 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
    Sep 30 '10 at 19:58
  • 2
    $\begingroup$ Can you explain why the standard techniques don't work? $\endgroup$ Sep 30 '10 at 23:01
  • 3
    $\begingroup$ @Tsuyoshi... Yeh. You are right. Its harder than it looks. $\endgroup$ Oct 1 '10 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$ Sep 24 '11 at 7:41

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.

  • 5
    $\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$ Oct 1 '10 at 0:28
  • 11
    $\begingroup$ Those who did not know Ogden’s lemma (like me) may find Wikipedia helpful. $\endgroup$ Oct 1 '10 at 0:32
  • 2
    $\begingroup$ @Tsuyoshi: Yes, you're right. I didn't see this simple representation yesterday night. $\endgroup$ Oct 1 '10 at 6:30
  • 1
    $\begingroup$ This answer is featured on the community blog. $\endgroup$ Oct 27 '11 at 12:05
  • $\begingroup$ A similar proof is presented in this answer on cs.se. $\endgroup$ Jan 2 '14 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$ May 26 '11 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
    May 26 '11 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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