convergence sequence of xor bit operation

71 Views Asked by At

Given positive integer $m$, we consider the integers up to $m$ bits.

Let $mask = 2^m - 1$ and consider sequence, $a_0 = 0, a_1 = 1$,

For $i \ge 2$,

$$a_i = (a_{i-2}) \oplus (a_{i-1}) \oplus (a_{i-1}>>1) \oplus ((a_{i-1}<<1) \land mask)$$

$\oplus$: is bit XOR operation;

$>>$: is bit shift operation; $>>1$ is equivalent of dividing 2

$<<$: is bit shift operation; $<<1$ is equivalent of multipling 2

$\land$: is bit and operation; $\land mask$ operation makes sure the resulting number is up to $m$ bits.

Prove/disprove that, for any positive integer $m$, there always exist $i>0$ such that $a_i = 0$.

Examples,

for $m=1$, ${\bf a} = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, ...]$

for $m=2$, ${\bf a} = [0, 1, 3, 1, 0, 1, 3, 1, 0, 1, ...]$

for $m=3$, ${\bf a} = [0, 1, 3, 5, 6, 4, 0, 4, 6, 5, ...]$

for $m=4$, ${\bf a} = [0, 1, 3, 5, 14, 0, 14, 5, 3, 1, ...]$

for $m=5$, ${\bf a} = [0, 1, 3, 5, 14, 16, 22, 1, 21, 20, 3, 16, 27, 16, 3, 20, 21, 1, 22, 16, 14, 5, 3, 1, 0, 1, ...]$

1

There are 1 best solutions below

1
On BEST ANSWER

I think the trick here is to recognise that you can play the sequence forwards as well as backwards. This is because:

$$a_{i-2} = a_i \oplus (a_{i-1}) \oplus (a_{i-1}>>1) \oplus ((a_{i-1}<<1) \land mask)$$

for $i\ge 2$ (i.e. you can interchange $a_i$ with $a_{i-2}$).

As the number of possible binary words of length $m$ is finite, which also means the number of pairs of those is finite, the sequence must at some point start repeating itself: let the first repetition (in lexicographic order) be $a_m=a_n, a_{m+1}=a_{n+1}$ (with $m<n$).

If $m=0$, we are done because $a_n=a_m=0$.

If $m>0$, then due to the property noted above we can prove that $a_{m-1}=a_{n-1}$ - which is a contradiction ($a_m=a_n$ was not the first repetition).