0

So I have a question:

Give a CFG for $\{a^i b^j : 2 i<j\}$

And this is my approach:

$S\to AB$

$A\to aAb\mid \varepsilon$

$B\to b \mid bB$

A confirmation, or correction, along with how you tested(and tips for testing future of my problems) will be greatly appreciated thanks.

Ran G.
  • 20,684
  • 3
  • 60
  • 115
Gaak
  • 51
  • 2
  • 4
  • See answer here: http://stackoverflow.com/questions/15559324/construct-grammar-given-the-following-language-an-bm-n-m-0-1-2-n-2/15578641#15578641 – Ran G. Apr 06 '13 at 18:21
  • 2
    and here: http://cs.stackexchange.com/questions/9804/context-free-grammar-for-language-l-aibj-mid-i-j-ge-0-i-ne-2j – Ran G. Apr 06 '13 at 18:24
  • 1
    and a bit more sophisticated variant here: http://cs.stackexchange.com/questions/9831/context-free-grammar-for-language-l so I recommend to close this question since it is essentially a duplicate. – Ran G. Apr 06 '13 at 18:27
  • @RanG. I am asking if my approach is right, which is unique compared to others. If yes, great. If no, why, so I can learn. – Gaak Apr 06 '13 at 18:34
  • 1
    Gaak, your approach doesn't work. To understand how the correct grammar works, please see the links. Do compare your approach to the grammars given there - this will surely give you insights regarding what is wrong with your answer and how to amend it. Use the search feature to find other examples (since many users asked this very similar question before you - a lot of information already exists on this site, and it is redundant to re-iterate it from scratch.) – Ran G. Apr 06 '13 at 18:43
  • 1
    The question metioned by @RanG. isn't an exact match, but your problem is solved by one part of the solution. – vonbrand Apr 06 '13 at 19:28

1 Answers1

0

You can derive $aabbb$ which is not in the language, so your grammar is wrong.

How did I find this? I observed that $A \Rightarrow^* a^ib^i$ and $B \Rightarrow^* b^j$ for all $i \geq 0$, $j > 0$. It's clear that this is wrong, and I looked for the smallest counter-example.

You need to ensure that more than double as many $b$'s as $a$'s are generated.

Raphael
  • 72,336
  • 29
  • 179
  • 389