Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having trouble constructing a grammar for


So I need to construct a grammar for the language wherein the number of a's does not equal the number of b's. The farthest I've attempted is splitting the language into


but I don't know where to go from there. What makes this problem challenging is that no order is specified so I don't even know where to begin.

Thus, the second part of my questions is if there is any general rule I should follow when dealing with languages that don't stipulate an order.

share|cite|improve this question
up vote 2 down vote accepted

Hint: The first step in your grammar should decide whether $n_{\mathtt{a}} > n_{\mathtt{b}}$ or $n_{\mathtt{a}} < n_{\mathtt{b}}$, and then the two "halves" of your grammar will then construct appropriate strings. This related question might help you.

share|cite|improve this answer
Thank you. The related question helped immensely. – user77435 May 12 '13 at 18:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.