TITLE: Examining cycles in a sequence
QUESTION [5 upvotes]: I am looking at a problem in Engel's problem solving strategies:

Start with an $n$-tuple $S=(a_0,a_1,\ldots, a_{n-1})$ of nonnegative integers.
Define the operation $T(S):=(|a_0-a_1|, |a_1-a_2|,\ldots, |a_{n-1}-a_0|)$.
Now consider the sequence $S, T(S), T(T(S)),\ldots$.
For instance, if we take $n=4$ and $S=(0,3,10,13)$, we get
$(0,3,10,13)\mapsto (3,7,3,13)\mapsto (4,4,10,10)\mapsto(0,6,0,6)\mapsto(6,6,6,6)\mapsto(0,0,0,0)$.

Prove that, for $n\neq 2^r,$ we get (up to some exceptions) a cycle containing just two numbers: $0$, and evenly often some number $a>0$.

Let $n\neq 2^r$ and let $c(n)$ be the cycle length. Prove that $c(2n)=2c(n)$ up to some exceptions.

Prove that, for odd $n$, $S=(0,0,\ldots,0,1,1)$ always lies on a cycle.



The problem does not elaborate on what the 'exceptions' are.
Some given hints/progress I've made:

The sequences $S$ and $tS$ have the same 'life expectancy', where $tS$ denotes multiplication of each element by $t\in \mathbb{N}$.
This is because $T(tS)=tT(S)$, so $T^k(tS)=0 \iff tT^k(S)=0 \iff T^k(S)=0$.

For $n=2^r$, we always reach $(0,\ldots, 0)$.
Note that in mod 2, $|a-b|\equiv a+b$.
So $T(a_0,a_1,\ldots,a_{n-1})\equiv (a_0+a_1,a_1+a_2,\ldots,a_{n-1}+a_0)$, and $T^2(S)\equiv (a_0+a_2,a_1+a_3,\ldots)$ etc.
Continuing on, we see that these indices $a_i$ present in each slot has a structure identical to the parity of Pascal's triangle, where applying $T$ takes us to the next row in the triangle.
So for $n=2^r$, via the property of Pascal's triangle that the $2^r-1$'th row is entirely odd, we will reach $(\sum a_i, \sum a_i, \ldots, \sum a_i)$, which then maps to $(0, 0,\ldots,0)$ in mod 2.
Therefore after each $2^r$ steps we can extract a common factor of 2 from the $n$-tuple.
Further let $\max S$ denote the maximal element of $S$. Observing that $\max S\geq\max T(S)$, a descent argument will show that the eventually we must reach all $0$'s.

A suggestion from the book: given the sequence $(a_0,a_1,\ldots,a_{n-1})$, assign the polynomial $p(x)=a_{n-1}+\ldots+a_0x^{n-1}$ with coefficients in mod 2, and $x^n=1$.
Then the polynomial $(1+x)p(x)$ belongs to $T(S)$.


EDIT:
the book includes a table of $c(n)$ values, which were computer generated. The first few values on the table are:
$c(3)=3, c(5)=15, c(7)=7, c(9)=63, c(11)=341, c(13)=819, c(15)=15, c(17)=255, c(19)=9709...$.
There seem to be various patterns in here, for instance, $c(2^k+1)=2^{2k}-1$.

REPLY [2 votes]: I will note  some simple observations here:

As long as $S$ does not contain a $0$, $\max(T(S))<\max(S)$. Proof: $|a_i-a_{i+1}|<\max\{a_i,a_{i+1}\}\le \max(S)$

$T(S)$ will contain an even number of uneven elements. Proof: $$( a_1+a_2)+(a_2+a_3)+\cdots +(a_{n-1}+a_n)+(a_n+a_1)\\\equiv 2 (a_1+\cdots + a_n)\equiv 0 \pmod 2$$

If S contains only $0$ and $a>0$ then the number of $a$ in $T(S)$  must be even. Proof: $\frac 1 a S$ contains only $0$ and $1$. $a T(\frac 1 a S)$ is equal to $T(S)$ and the number of odd elements in $T(\frac 1 a S)$ is even as we stated before.

The cycle length depends not only on the length of the tuple but depend on its actual values:


Example:
iterate([0,0,1,0,0,1])
1 [0, 0, 1, 0, 0, 1]
2 [0, 1, 1, 0, 1, 1]
3 [1, 0, 1, 1, 0, 1]
4 [1, 1, 0, 1, 1, 0]
5 [0, 1, 1, 0, 1, 1]

cycle length = 3


iterate([0,0,1,0,1,1])
1 [0, 0, 1, 0, 1, 1]
2 [0, 1, 1, 1, 0, 1]
3 [1, 0, 0, 1, 1, 1]
4 [1, 0, 1, 0, 0, 0]
5 [1, 1, 1, 0, 0, 1]
6 [0, 0, 1, 0, 1, 0]
7 [0, 1, 1, 1, 1, 0]
8 [1, 0, 0, 0, 1, 0]
9 [1, 0, 0, 1, 1, 1]
10 [1, 0, 1, 0, 0, 0]
11 [1, 1, 1, 0, 0, 1]

cycle length = 6


Here is now the sketch of the proof for 1
I will demonstrate the simple idea using an example.
Assume that we start with the tuple
4  0  0  2  1 4  2  4  0  3

this tuple has the maximum value $4$ and at least on value different to $0$ and the maximum. Now we select a range that contains one of these values
4  0  0 <2 1> 4  2  4  0  3

Now we extend this range to the left and to the right before we reach $0$ or the maximum $4$.
Our range has the following property:

it contains only values smaller than the maximum
its value most left is different to $0$ and the maximum
the value left to its most left value is $0$ or the maximum
its value most right value is different to $0$ and the maximum
the value right to its most right value is $0$ or the maximum

Now we apply the function
4  0  0 <2  1> 4  2  4  0  3
4  0  2 <1  3> 2  2  4  3  1
Now we again extend the range to the right and to the left and stop before we reach $0$ or the maximum $4$.
4  0  0 <2  1> 4  2  4  0  3
4  0 <2  1  3  2  2> 4  3  1  

The new range again has the 5 properties, these are the invariants. The new range will always be larger then the old range, because

the right index never decreases
the left index will be increased by at least 1

Both follows from the fact the $0<\left|a_i-a_{i+1}\right|<\max$, if one of $a_i,a_{i+1}$ is in $\{0,\max\}$ and the other is not in  $\{0,\max\}$.
To be more precise:
if $l_1$ is  the left index before the iteration and $r_1$ the right index before the iteration then we have:

$a_{l_1} \in \{1,\ldots, \max-1\}$
$a_{l_1-1} \in \{0, \max\}$
$a_{r_1} \in \{1,\ldots, \max-1\}$
$a_{r_1+1} \in \{0, \max\}$
$a_i \in \{0,\ldots,\max-1\},\; \forall i: l_1\le i \le r_1$

After the iteration we  have
$$T_{l_1-1}(S)=\left|a_{l_1-1}-a_{l_1}
\right| \in \{1,\ldots,\max-1\}$$
$$T_{r_1}(S)=\left|a_{r_1}-a_{r_1+1}
\right| \in \{1,\ldots,\max-1\}$$
$$T_{i}(S)=\left|a_{i}-a_{i+1}
\right| \in \{0,\ldots,\max-1\}, \forall i: l_1\le i\lt r_1$$
and so we have
the new left index $l_2 \le l_1-1$ and the new right index $r_2\ge r_1$
We must take care that the tuple must be view in a cyclic way, so we have to go "around the corner" when the left index reaches $1$ or the right index reaches $n-1$.
So if we proceed we get
4  0  0 <2  1> 4  2  4  0  3
4  0 <2  1  3  2  2> 4  3  1  
4 <2  1  2  1  0  2  1  2  3>

and after the next step  the maximum 4 vanished.
4  0  0 <2  1> 4  2  4  0  3
4  0 <2  1  3  2  2> 4  3  1  
4 <2  1  2  1  0  2  1  2  3>
2  1  1  1  1  2  1  1  1  1

Now we have a new maximum (2) and we can continue with the procedure. So after a finite number of steps we end either with $(0,0,\ldots,0)$ or with a tuple containing only $0$ and $a$.
We already showed in a previous part of this post that the number of position with values not $0$ must be even.