Find a context-free grammar for the language $L=\{a^nb^m\mid 2n<m<3n\}$ [closed]

I need to find a context-free grammar for the following language which uses the alphabet $\{a, b\}$ $$L=\{a^nb^m\mid 2n<m<3n\}$$

closed as unclear what you're asking by David Richerby, Raphael♦Mar 28 '14 at 13:28

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• I tried many solutions by ended with nothing, getting more confused – Mohammed Isa Mar 28 '14 at 13:16
• This is a dump of a problem, not a question. If you have a specific question regarding the wording of the problem or about concrete steps in your own attempts at solving the problem, feel free to edit accordingly and we can reopen the question. See here for a relevant discussion. If you are uncertain how to improve your question, why not ask around in Computer Science Chat? – David Richerby Mar 28 '14 at 13:20
• start with the 'classical' CFG: $S \to aSb$. Consider expanding into one additional non-terminal B on the rhs instead ($S \to aSB$). How could the non-terminal help you reaching your goal ? To exclude the bounds of the range expressed by your inequality, for each bound observe by how many symbols you are off at maximum in any derivation your grammar admits. – collapsar Mar 28 '14 at 13:32
• The correct approach to write grammar for the language is write strings first. Understand n!=0 and 1. n should be >= 2. and for n=2.. possible strings are aabbbbb only for n=3 strings can be aaa bbb bbb b, aaa bbb bbb bb for n=4 strings can be aaaa bbbb bbbb b, aaaa bbbb bbbb bb, aaaa bbbb bbbb bbb So for a n=N no. of possible strings are N-1. So you need rules like. So rules should be whenever you add one a you should add two Xb (where X can be replace by b or ^) as Y --> aYXb Now In first rule I left S to add more as and bs. ... Now --CONTINU.. – Grijesh Chauhan Mar 28 '14 at 18:46
• Now with min length string that is aabbb start with m > 2n as S --> aaYbbb. Of-Course add X --> b | ^. And To remove Y from sentential from add Y --> a. – Grijesh Chauhan Mar 28 '14 at 18:48

Hint: Can you do $$L=\{a^nb^m\mid m=3n\}$$

Try it also for: $$L=\{a^nb^m\mid m=3n-1\}$$

Then you might want to be able not to always have that many $b$.

And there is a bit more to take care of.

Hint: Suppose $x_1,\ldots,x_n \in \{2,3\}$. Then $2n \leq x_1+\cdots+x_n \leq 3n$. You will need to be slightly more devious to exclude $2n$ and $3n$.

• You hint explains question but not helpful for writing grammar. I downvoted as I dislike it in answer section. – Grijesh Chauhan Mar 28 '14 at 18:59
• On the contrary, using this idea I can write a grammar for the language. – Yuval Filmus Mar 28 '14 at 20:10
• @YuvalFilmus Yes, ofcourse I knew that you can write a grammar for the language but I believe you have written this answer for other users. – Grijesh Chauhan Mar 29 '14 at 5:06
• @Grijesh My policy is not to give away answers. I stand by my stance that my hint contains one basic idea behind the solution. – Yuval Filmus Mar 29 '14 at 5:23
• Yuval I see. Yes I saw many of your answers and I got your idea. But I think this question is little bit hard at-least for new uses. So I request you to add some more details so that it can be helpful to write grammar for average users like me... And I saw two more users are disagree with this kind of hints in answer section on similar question Anyways answer is yours If I disagree I down-vote, If I like vote-up also. my downvotes are very less than up-votes – Grijesh Chauhan Mar 29 '14 at 5:55