I am trying to create a context free grammar in [Extended Backus–Naur form][1], which starts with a non-empty sequence of `a`'s and is followed by a non-empty sequence of `b`'s. With the special condition that the number of `b`'s has to be **unequal** to the number of `a`'s.

Thus, the grammar should generate words like:

* `aaaabbb`
* `aaabb`
* `abbb`

---

So basically I could do something like this:

$\ G=(N,T,P,S)$

$\ N = \{S\}$

$\ T = \{a,b\}$

$\ P = \{S=aa(S|\epsilon)b\}$

But then the words would always have $\ 2n$ `a`'s and n `b`'s:

* `aab`
* `aaaabb`
* `aaaaaabbb`

So how is it possible to make the number of `a`'s **uncorrelated** of the number of `b`'s, without being equal?

# Update
[This question][2] was suggested as a duplicate. But it's not quite what I want. So I posted my own solution as an [answer][3] below.


  [1]: https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form
  [2]: https://cs.stackexchange.com/questions/9804/context-free-grammar-for-language-l-aibj-mid-i-j-ge-0-i-ne-2j
  [3]: https://cs.stackexchange.com/a/116381/111222