The question is whether the language bin(n)bin(2^(k+1) * n + 1)^R
is context-free. I take bin(n)
to mean the binary representation of the natural number n
without any leading zeroes.
Suppose bin(n') = x
. Here, x
is a finite string of binary digits beginning with 1
. Let us determine what bin(2^(k+1) * n + 1) looks like. First, note that multiplying a number by two adds a zero to the end of that number's binary representation; just the same as multiplying by ten when using decimal. Multiplying by 2^(k+1) will add k+1 zeroes. Because k is a natural number, at least one zero must be added. Adding one to this number will flip the least significant bit over to 1 from 0. The end result is that bin(2^(k+1) * n + 1) = x(0^k)1
.
The language bin(n)bin(2^(k+1) * n + 1)^R
consists of strings of the form x(x(0^k)1)^R
. We can distribute the ^R
by reversing each of the concatenated substrings and the order of concatenation to see that these strings are of the form x1(0^k)(x^R)
. We notice the outermost component of these strings begin with an arbitrary binary string x
and end with x^R
; we can handle this with a context-free grammar in the same we can handle languages of palindromes. The innermost component is 1(0^k)
, which describes the regular language 10*
; we can certainly handle that in a CFG. A CFG that works is the following:
S := 0S0 | 1S1 | T
T := T0 | 1
The main insight in deriving this is in determining the form of (bin(2^(k+1) * x + 1)^R
.