Is the language, $a^nb^mc^k$, where $n\not=m$ and $m\not=k $ in CFL or not? When the condition is changed to $n\not=m ~\|~ m\not=k $, it can be shown that the language is the union of 2 CFLs. However when $n\not=m$ and $m\not=k $ that approach seems to not work.
1 Answers
No, $L=\{a^nb^mc^k\mid n\neq m,m\neq k\}$ is not context-free.
A proof by Ogden's lemma
Assume $L$ is context-free.
Let $p$ be the constant given by Ogden's lemma. Let $s=a^{p+p!}b^pc^{p+p!}\in L$. Let us mark all $b$s in $s$. Ogden's lemma tells that $s=uvwxy$ for some strings $u$, $v$, $w$, $x$, and $y$, such that
- $vx$ has at least one marked position,
- $vwx$ has at most $p$ marked positions, and
- $uv^{i}wx^{i}y\in L$ for all $i\geq0$.
There are several cases.
- If $v$ or $x$ contains different symbols, then $uv^2wx^2y\notin L$, since it contains symbols in the wrong order.
- Otherwise, all symbols in $v$ are the same and all symbols in $x$ are the same.
Since only $b$s are marked, either $v$ or $x$ must contain $b$.Suppose $v$ contains $b$. Then $v$ only contains $b$s. So $vx$ does not contain $a$. Let $q= \#_b(vx)\le p$. Let $i=\frac{p!}q+1$. Consider $s'=uv^iwx^iy$.
- $\#_a(s')=\#_a(s)=p+p!$
- $\#_b(s')=\#_b(s) + \#_b(vx)^{i-1}=p + q(i-1) = p + p!$
Hence $s'\notin L$..
Otherwise, $x$ contains $b$. This case is symmetric to the case above.
So, in all cases, $uv^iwx^iy\not\in L$ for some $i$. This contradicts Ogden's lemma.
Hence, $L$ is not context-free.
Two exercises.
Exercises 1. Show that $L$ satisfies the common version of the pumping lemma for regular languages. Hence, $L$ also satisfies the common version of pumping lemma for context-free languages. However, $L$ does not satisfy the stronger version of pumping lemma for regular languages.
Exercises 2. Show that $\{a^nb^mc^k\mid n\neq k,m\neq k\}$ is not context-free.
- 39,205
- 4
- 34
- 93