Difference between the two regular expression

I came across a question to create a regular expression to check whether there are even number of b's in a string of language {a,b}. The expression I came up with is (a+ba*b)*. However I found the solution online to be a*(ba*ba*). Is there any difference? If any where?

Also I know that (a+b)* is equivalent to (a*b*)*. So my solution comes out to be (a*(ba*b))*. So why that extra a*?

• I think you'll need to edit the question, as I can't tell what you are asking. 1. (a+b)* is not equivalent to (a*b*). Please double-check all your statements. Proof-read the formatted output, and consider using Markdown to typeset your notation more clearly. 2. What have you tried? Have you tried to look for a string that is accepted by your expression but not by the other one, or vice versa? Have you taken a look at closure properties, to see how to compute the set difference between two regexps? (continued) – D.W. Sep 3 '15 at 21:33
• 3. Please use typesetting to reduce ambiguity. Does (a+ba*b)* mean (a+(ba*b))* or ((a+b)a*b)*? 4. I can't tell what "check whether for even number of b's in a language of {a,b}" means. Can you please edit to rewrite that? Thank you! – D.W. Sep 3 '15 at 21:33

• In fact $(a+ba^*b)^*$ does correctly represent an even number of $b$'s. The expression has a repeated alternative between a single $a$ and a sequence of two $b$'s with an arbitrary numbers of $a$'s in between. The star allows zero iterations. Also $a^*(ba^*b)^*$ is indeed wrong, but it will match $a$'s between $b$'s. The reason it is wrong is that we cannot end with the letter $a$ unless we only have $a$'s. – Hendrik Jan Sep 5 '15 at 22:53