[Math] Are languages regular if their concatenation is regular

formal-languagesregular-language

Let $A, B \subset \Sigma^*$ be languages.

If the concatenation product $AB$ is regular, are $A$ and $B$ necessarily regular?

I'm inclined to think this is true since the regular language $AB$ has a regular expression and then somehow the regular expression must be comprised of two parts giving regular expression for $A$ and $B$ but don't see how to prove this rigorously.

Best Answer

This is not necessarily true. Let $\Sigma = \{0, 1\}$, $A = \{0^n1^n \mid n \ge 0\}$, $B = \Sigma^*$. Then $AB = \Sigma^*$, which is regular. But $A$ is not regular.

This shows that one cannot necessarily split the regular expression of $AB$ into one for $A$ and another for $B$.

If you want a counterexample in which both $A$ and $B$ are not regular, let \begin{align} A &= \{w \in \Sigma^* \mid \#_0(w) \ge \#_1(w)\},\\ B &= \{w \in \Sigma^* \mid \#_0(w) \le \#_1(w)\}, \end{align} where $\#_0(w)$ is the number of occurrences of $0$ in $w$. Then $AB = \Sigma^*$.