-2
$\begingroup$

This question already has an answer here:

I'm trying to understand the approach to constructing an grammar which accepts the language ${a^ib^j \mid i>0\ and \hspace{2.5mm}i\leq j \leq(2*i)}$ } Thanks.

$\endgroup$

marked as duplicate by Raphael Feb 3 at 20:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ What have you tried? Where did you get stuck? We do not want to just hand you the solution; we want you to gain understanding. However, as it is we do not know what your underlying problem is, so we can not begin to help. See here for tips on asking questions about exercise problems. If you are uncertain how to improve your question, why not ask around in Computer Science Chat? $\endgroup$ – Raphael Feb 3 at 20:50
3
$\begingroup$

Short answer: unfortunately, it can't be done.

It can be proven mathematically that this language isn't regular. The easiest way is a fooling set argument: the set $\{a^{3^i} \mid i \in \mathbb{N}\}$ is infinite, and for any two distinct strings $x$ and $y$ you take from this set, I can construct a suffix $z$ such that $xz$ is in your language and $yz$ is not.

Thus, it's utterly impossible to make a regular grammar for this language.

Note that this language is context-free; the following context-free grammar (CFG) recognizes it:

$$S \rightarrow aXb \mid aXbb \\ X \rightarrow aXb \mid aXbb \mid \varepsilon$$

(The distinction between $S$ and $X$ is just to ensure that $i > 0$; if you drop that requirement, you can do this in one line.)

EDIT: Thanks to Apass.Jack, here's a one-liner for you anyway!

$$S \rightarrow aSb \mid aSbb \mid ab \mid abb$$

$\endgroup$
  • $\begingroup$ Nice answer. Here is a oneliner. $S\rightarrow aSb \mid aSbb \mid ab\mid abb$ $\endgroup$ – Apass.Jack Jan 30 at 3:32
  • $\begingroup$ @Apass.Jack True, that works too! $\endgroup$ – Draconis Jan 30 at 3:32
  • $\begingroup$ Note that "problem dumps" such as this can often be answered by referring the asker to one of our reference questions. $\endgroup$ – Raphael Feb 3 at 20:50

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