Sign up ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

1 Answer 1

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.