1

Is the language $\{wxw^Rx^R \mid w,x \in \{0,1\}^* \}$ context-free

My thoughts, Let $x = \epsilon$ and we get $ww^R$, which is context-free. Hence the given language must be context-free.

Am I right?

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
  • 1
    You don't get to choose $X$. – Watercrystal Feb 19 '21 at 20:36
  • In question, $WXW^R$ whether is it regular or not.... We chose X as everything except 1st and last symbol and proved it regular? Why can't we chose here? – Munish Chaturvedi Feb 19 '21 at 20:50
  • That language is not regular. The notation $L = {WXW^rX^r \mid W, X \in {0, 1}^\ast}$ says that $L$ consists of all strings of the given form for all allowed choices of $W$ and $X$. – Watercrystal Feb 19 '21 at 21:10
  • In this [https://cs.stackexchange.com/questions/50689/is-wxwr-a-regular-language], accepted answer actually used the concept: "Because there is little restriction to x. We can consider that x is almost the whole word with the exception of the first and the last symbol". So he chose x. Also, This WXW^R is regular. Can you elaborate your thoughts on Why the Language I asked in Question is NOT CFL? – Munish Chaturvedi Feb 19 '21 at 21:38
  • Oh sorry, yeah I made a mistake there, the language is indeed regular. However, they did not choose $X$ in the way you want to do it -- they produced a new, equivalent way to express the language. That is not what you do: Consider for example $W = 0, X = 1$: That means the string $WXW^rX^r = 0101$ is in your $L$, but it is not of the form $WW^r$. You essentially want to fix $X$ in a way that produces a different language. – Watercrystal Feb 19 '21 at 21:56
  • Okay! Thanks :) – Munish Chaturvedi Feb 20 '21 at 08:30

1 Answers1

0

Denote your language by $L$, and consider $$ L' = L \cap 10^*1110^*10^*10^+11. $$ Any word in $L'$ is of the form $$ 10^a1110^b10^c10^d11, $$ where $d > 0$. Also, it is of the form $wxw^Rx^R$. Since both $wx$ and $w^Rx^R$ contain the same number of $1$'s, necessarily \begin{align} wx &= 10^a1110^{b_1} \\ w^Rx^R &= 0^{b_2}10^c10^d11 \end{align} where $b_1 + b_2 = b$. We see that $x^R$ ends with $110$ (since $d>0$), and so $x$ starts with $110$. Hence $w = 10^a1$ and $x=110^{b_1}$, implying that $w^Rx^R = 10^a10^{b_1}11$. This shows that $b_2 = 0$ hence $b_1 = b$, and furthermore $c = a$ and $d = b$. That is, the word is of the form $$ 10^a1110^b10^a10^b11, $$ where $b > 0$. Conversely, every word of this form is in $L'$ (take $w = 10^a1$ and $x = 110^b$).

Let $h\colon \{1,2,3,4,5\} \to \{0,1\}$ be the homomorphism given by $h(1) = 1$ and $h(2) = h(3) = h(4) = h(5) = 0$, and let $d\colon \{1,2,3,4,5\} \to \{2,3,4,5\}$ be the homomorphism that deletes $1$. Then $$ d(h^{-1}(L') \cap 12^*1113^*14^*15^*11) \cup \{2^n4^n : n \geq 0\} = \{2^n3^m4^n5^m : n,m \geq 0\}. $$ The latter language is well-known not to be context-free. Since all our operations preserve being context-free, we conclude that $L$ is also not context-free.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
  • Thank You, Sir. I liked how you converted the given language to the well-known CSL. Also, Learnt new approach to solve problems of this kind. – Munish Chaturvedi Feb 21 '21 at 09:43