# Provide “regular” grammar for this language {${a^ib^j \mid i>0\ and \hspace{2.5mm}i\leq j \leq(2*i)}$} [duplicate]

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.

• 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? – Raphael Feb 3 '19 at 20:50

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

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