# how did they get this answer for the words that don't have bba and abb?

I am looking at the answer in solution manual which asked , all the words that don't have both substring bba and abb.

and the answer was a*(baa*)*b+b*(a*ab)*a*

and I'm like wait a minute is that right ? but that can't make abb, which is in the language. So it's gotta wrong.

so I came up with my own , would this be all the words that don't have both substring bba and abb ?

(b+^)(ab+a)*+b*


^ is an empty string by the way

The textbook's answer does appear to be incorrect, as you note it does not generate $abb$ (and just to rule out an alternative interpretation of the exercise - "all strings that include neither $abb$ nor $bba$ - it does generate $bba$).

However your answer is also incorrect unfortunately - it doesn't generate $bba$.

There are a couple of reasonably sensible ways to get a correct answer (of course there's always many many techniques, and different people prefer different ones).

The first is the "intuition" approach, break the problem into the two parts, "the strings that don't have $bba$" and "the strings that don't have $abb$", then combine. With this method you have to then think about how such strings would look, and convince yourself that you haven't missed any cases.

The very formal method is to construct the expression from smaller, verifiable building blocks. In this case, we can easily construct a DFA for the strings that do contain $abb$ and one for the strings that contain $bba$, then we can use the intersection construction to get a DFA for the intersection of the two languages, take the complement DFA, then convert this to a regular expression.

What they seem to have done, and messed up or made a typo in one part, is the formal-but-not-quite-as-silly-as-option-2 method, where we make the two small DFAs, take their complements separately, convert each to a regular expression, then combine. I'll do the half that they seem to have gotten wrong (the bit that allows $abb$ but not $bba$, which is the first half of their expression).

The initial DFA is:

Taking the complement we get:

This second DFA recognises all the strings that don't contain $bba$. Now we convert this to a regular expression using the normal state elimination algorithm. If you haven't seen this yet, it will appear shortly in whatever course you're studying, or you can look over this explanation, but for the moment (and for the sake of keeping this answer on track!) hopefully it's acceptable that there is an algorithm for doing this conversion. In principle this algorithm can result in slightly different regular expressions depending on the order you eliminate the states, so if you have a go at it, you may not end up with quite the same regular expression (if you try one particular order, you get a real mess).

After all that we get the regular expression: $$(a+ba)^{\ast}b^{\ast}$$

If we then proceed and do the DFA for strings containing $abb$, take its complement and derive the regular expression, we get (picking the right elimination ordering) the same as their second half, $b^{\ast}(a^{\ast}ab)^{\ast}a^{\ast}$, and combine them and get the final answer: $$(a+ba)^{\ast}b^{\ast}+b^{\ast}(a^{\ast}ab)^{\ast}a^{\ast}$$

Do not have substrings bba and abb:

Regular Expression= ^+b+ bbb*+(a+ba)(a+ba)*(^+b)

L={^, a, b, aa, ab, ba, bb, aaa, aab, aba, baa, bab, bbb, aaaa, aaab, abaa, baaa, baab, baba, bbbb,...}

• This regular expression generates strings not containing $a$s. And strings starting with $b$, and at least one $a$ separating additional $b$s, if any. What about, say, $bbab$? $ab$, $abb$? – greybeard Aug 21 '20 at 0:23
• Thanks greybeard for pointing out the missing strings. Pl. check the corrected regular expression: Regular Expression= ^+b+ bbb*+(a+ba)(a+ba)*(^+b) L={^, a, b, aa, ab, ba, bb, aaa, aab, aba, baa, bab, bbb, aaaa, aaab, abaa, baaa, baab, baba, bbbb,...} – Ankit Rajpal Aug 22 '20 at 6:08
• (I think the list should show abab.) The first part looks redundant - $b^*$ covers strings not containing $a$s* nicely. Same for $(a+ba)(a+ba)^*$: why not allow the empty string once more? Now, I see *strings not containing $a$s*, and *strings not containing $bb$ - what about $abb$ and $bba$ (not containing "the other one")? – greybeard Aug 22 '20 at 9:50
• Yes..abab will also be accepted by the given regular expression. I don't see any reason of including empty string again. The question says that both abb and bba should not occur as a substring and the given regular expression is satisfying this requirement. – Ankit Rajpal Aug 23 '20 at 10:35
• I am under the impression you read words that don't have both substring $bba$ and $abb$ different from David Richerby(&me): may contain each, but not contain both of $bba$ and $abb$. (So, the list should include each - didn't check the three symbol strings.) – greybeard Aug 23 '20 at 10:54

These are incorrect R.E we generate bba from the 2nd part

I think b*+a*(ab)a+a*(ba)a+a*ba(a+ab)a+a*ab(a+ab)a may be correct R.E.

• $bba$ doesn't contain both of $bba$ and $abb$, so it should match the regular expression. I think you've misunderstood the question. – David Richerby Feb 23 '17 at 13:07

It is a very simple RE. {a*(ba+a)*(b+^) + (b *) } Where ^ is null. JazakAllah :)

• It is b* in the last. – Sheikh Ahsan Ali Dec 4 '19 at 13:52