I was taught that if you can create a DFA to accept a language, then the grammar that is generating the language is regular.


A DFA is a finite automata that accepts a language and also rejects the strings that aren't a part of the language.

It says if we replace $x$ with $c$ where $c \in \{0,1\}^+$, then $L$ is regular.

But the DFA should reject the string $abbaaaba$ since it doesn't fit the $wxw^R$ criteria and that isn't happening, so how is it regular?


In $\{wxw^R|w,x\in\{0,1\}^+\}$, we're free to choose $x$ to be any non-empty sequence, including all but the first and last characters of $wxw^R$. So we might as well limit $w$ to be a single symbol; it won't change anything.

So $L$ is exactly the same as $L' = \{axa|a\in\{0,1\}\land x\in\{0,1\}^+\}$ which is evidently regular.

Here's a more formal proof, in case the above was too telegraphic. Suppose we have

$$L = \{wxw^R|w,x\in\{0,1\}^+\}$$


$$\{0,1\}^+ \equiv \{0,1\} \cup \{aw | a \in \{0,1\} \land w \in \{0,1\}^+$$

which just says that $w^+$ is either exactly one symbol or one symbol concatenated with $w^+$. Also observe that if $a$ is a symbol and $w$ is a sequence of symbols, then $a^R\equiv a$ and $(aw)^R\equiv w^Ra$. So we can rewrite $L$ as a union:

$$L = \{axa|a\in\{0,1\}\land x\in\{0,1\}^+\} \cup \{awxw^Ra|a\in\{0,1\}\land w,x\in\{0,1\}^+\}$$

Now, looking at the two sets in that union, we can see that

$$\{awxw^Ra|a\in\{0,1\}\land w,x\in\{0,1\}^+\} \subset \{axa|a\in\{0,1\}\land x\in\{0,1\}^+\}$$


$$\{wxw^R|w,x\in\{0,1\}^+\} \subset \{0,1\}^+$$

and since for any sets $A$ and $B$

$$B \subset A \implies A = A \cup B$$

We can simplify the definition of $L$ to

$$L = \{axa|a\in\{0,1\}\land x\in\{0,1\}^+\}$$

which is clearly a regular language.

| cite | improve this answer | |
  • $\begingroup$ Why does limiting $w$ to a single symbol not change anything? Recognizing whether $u=v^R$ is not the same as recognizing the same single symbol! $\endgroup$ – Eric_ Jan 22 '16 at 10:20
  • $\begingroup$ @Eric_: the original question is a bit of mathematical sleight of hand, a kind of optical illusion. You see the $w^R$ and think that it means something, but what is really going on is in the $x$. Or, in other words, it was a trick question, and you (like many others) fell into the trap. Anyway, I added a more formal justification of my original statement and fixed the grammar a bit. $\endgroup$ – rici Jan 22 '16 at 16:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.