If $L_1L_2$ is regular language, is $L_2L_1$ regular as well?

95 Views Asked by At

If $L_1L_2$ is regular language, is $L_2L_1$ regular as well?

I think the answer is no, but I'm not sure how to contradict.

2

There are 2 best solutions below

0
On

Let $L_1 = \{a^ib^j | i \ge j \ge 0\}$ and $L_2 = \{b^k c | k \ge 0\}$.

Now $L_1L_2$ is $\{a^i b^{j+k} c | i \ge j, j \ge 0, k \ge 0\}$, in which there is no relationship between $i$ and $j+k$, so that's equivalent to $\{a^ib^jc | i, j \ge 0\}$, which is the regular language $a^*b^*c$.

But $L_2L_1$ is $\{b^k c a^ib^j | i \ge j \ge 0, k \ge 0\}$ which is not regular (as can easily be seen by intersecting it with $ca^*b^*$).

(Example inspired by a comment from @TomKern.)

0
On

Also following @TomKern suggestion, here is a simpler example on a two-letter alphabet.

Let $L_1 = a^*$ and $L_2 = \{a^{n^2}b \mid n \geqslant 0\}$. Then $L_1L_2 = a^*b$ is regular, but $L_2L_1= \{a^{n^2}ba^m \mid n,m \geqslant 0\}$ is not regular since its intersection with the regular language $a^*b$ is equal to $L_2$, which is not regular.