1
$\begingroup$

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\}$$

$\endgroup$

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.

  • $\begingroup$ I tried many solutions by ended with nothing, getting more confused $\endgroup$ – Mohammed Isa Mar 28 '14 at 13:16
  • 3
    $\begingroup$ 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? $\endgroup$ – David Richerby Mar 28 '14 at 13:20
  • $\begingroup$ 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. $\endgroup$ – collapsar Mar 28 '14 at 13:32
  • 1
    $\begingroup$ 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.. $\endgroup$ – Grijesh Chauhan Mar 28 '14 at 18:46
  • $\begingroup$ 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. $\endgroup$ – Grijesh Chauhan Mar 28 '14 at 18:48
1
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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$.

$\endgroup$
  • $\begingroup$ You hint explains question but not helpful for writing grammar. I downvoted as I dislike it in answer section. $\endgroup$ – Grijesh Chauhan Mar 28 '14 at 18:59
  • $\begingroup$ On the contrary, using this idea I can write a grammar for the language. $\endgroup$ – Yuval Filmus Mar 28 '14 at 20:10
  • $\begingroup$ @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. $\endgroup$ – Grijesh Chauhan Mar 29 '14 at 5:06
  • $\begingroup$ @Grijesh My policy is not to give away answers. I stand by my stance that my hint contains one basic idea behind the solution. $\endgroup$ – Yuval Filmus Mar 29 '14 at 5:23
  • $\begingroup$ 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 $\endgroup$ – Grijesh Chauhan Mar 29 '14 at 5:55

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