# Finding a regular expression of a language

Our alphabet is {a,b} and we need to find a regular expression for the language of all words of the form $$a^*b^*$$, whose length is a multiple of 3.

Obviously $$(aaa)^*(bbb)^*$$ is one of the options, but I just can't formalize more options.

Any help will be appreciated.

• "aabbbb" for example. The length is 6 (divisible by 3) but this is not of the form $(aaa)^*(bbb)^*$ – Asher Castro May 25 at 13:21
• "bbbaaa" is just another obvious form like I noted above. But what about other forms? How can I formalize them? – Asher Castro May 25 at 14:12

You have to put your triplets, and use Kleene star: $$(aaa)^*(bbb)^*$$
Now, add cases where number of $$a$$ is not divisible by 3, say aabbbb, as alternative. $$(aaa)^*(bbb)^* + (aaa)^*aab(bbb)^* + (aaa)^*abb(bbb)^*$$
• these are not of the form $a^*b^*$. – Ran G. May 25 at 15:25
• So, can I just take out the wrong ones from his answer? Does $((aaa)∪(aab)∪(abb)∪(bbb))^*$ cover all the options? – Asher Castro May 25 at 15:48
• So how about: $((aaa)^*+(bbb)^*)^*+((aaa)^*abb(bbb)^*)+((aaa)^*aab(bbb)^*)$ ? Does this cover all the cases, including the case of $(aaa)^*(bbb)^*$ ? – Asher Castro May 25 at 16:27