I’m pretty sure I’ve actually got one, but it has 42 construction rules and doesn’t generalize well. How can I do it with fewer construction rules?
The language is {a,b}* where the number of a’s is five times the number of b’s.
I know that for a language {a^n (concatenate) b^m; m = 5n} it would just be
S = aSbbbbb | λ
But when the characters can be in any order, I’m lost.
First of all, observe that if a sentence has 5 times as many characters as the other, it’ll always look something like
aaabaabaaaaa. So one sentence can beaaaaaboraaabaa. Another observation is that whenever we add ab, we must add fiveacharacters.The following grammar indeed has five times as many
acharacters asbcharacters:We start with
Swhich can either by empty (which satisfies the requirement) orA.The rule for
Aproduces at least 5acharacters and aB. Now forB, we can either placeband stop there (by choosing the empty string forS) or by starting again (by choosingAforS). This guarantees that we’re always placing 5 times as manyacharacters asbcharacters.Lastly, this grammar can easily be generalized to a grammar than needs to contain
ntimes as many characters of one as the other (by straightforwardly extending ruleA).