Sipser Exercise 2.23

Theorem: The language is context-free.


Proof:

\begin{align} S &\rightarrow X_0 X_1 \mid X_1 X_0 \ X_0 &\rightarrow 0X0 \mid 0X1 \mid 1X0 \mid 1X1 \mid 0 \ X_1 &\rightarrow 0Y0 \mid 0Y1 \mid 1Y0 \mid 1Y1 \mid 1 \end{align}

  • The index of the is
  • The index of the start of is .

So the index of the with respect to is . So and differ in the 'th spot, and .


Claim: Every word in can be generated by :

Consider some word . We can write , where and (note the length of is even). Then there is some index such that the corresponding positions in and are unequal, that is, . Let and with . There are characters in before , so label and , note . At this point can be written .

Note we have . Therefore, we have characters left in the string, an odd number. This odd-length remainder is symmetric about . So we can split the remaining odd length string around the middle again. That is, let and .

Now we can write where and . This is the concatenation of two binary strings symmetric about and , one of which is 1 and the other 0. Then, this string can be generated by .