Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Which one of the following languages is CFL and what is the grammar for it? Can we use pumping lemma for the not CFL?

\begin{align*} L_1 &= \{a^mb^ma^n \mid m,n \geq 0\}\\ L_2 &= \{a^mb^ma^n \mid m \geq n \geq 0\} \end{align*}

share|cite|improve this question

It’s very easy to write a context-free grammar that generates $L_1$. You might start with a production $S\to PA$ and add productions ensuring that $P$ generates $\{a^nb^n:n\ge 0\}$ and $A$ generates $a^*$.

Yes, you can use the pumping lemma for context-free languages to show that $L_2$ is not context-free; the proof is very similar to the usual example of such a proof, the proof that $\{a^nb^nc^n:n\ge 0\}$ is not context-free.

share|cite|improve this answer
Thank you Brian for your hints. – Jesun Apr 26 '13 at 13:12
@user1176123: You’re welcome; if you get completely stuck, feel free to ask me to expand the hints. – Brian M. Scott Apr 26 '13 at 13:14
@ Brian M. Scott: for $L_2$, I am assuming a string $s = a^p b^p a^p$ , where p is the pumping length. Then I am arguing that s can be composed of xuyvw. Now 2 cases: 1. u and v may only contain one symbol: not both prefix a's and b's or b's and suffix a's. Then $xu^2yv^2z$ either violates $a^m b^m$ or no of b becomes less than no of a. Is the argument correct? For case 2: is it violating the order? Thanks in advance. – Jesun Apr 27 '13 at 2:38
@user1176123: Yes, that’s correct: if $uyv$ contains both symbols, then $xu^2yv^2z$ contains two separate blocks of $b$’s. If $uyv$ is contained in the first $a$ block or the $b$ block, then $xu^2yv^2z$ doesn’t have the same number of $a$’s in its first block as it has $b$’s, and if it’s contained in the second $a$ block, then $xu^2yv^2z$ has too long a second $a$ block. – Brian M. Scott Apr 27 '13 at 2:47
@ Brian M. Scott: Thank you very much for your help – Jesun Apr 27 '13 at 3:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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