Distance between two elements in periodic sequence

208 Views Asked by At

I have a sequence $C$ of length $T$, composed by consecutive numbers from $0$ to $T-1$. For example: $C = (0,1,2,3,4,5)$. By repeating it over time, I get the periodic sequence:

$S = (0,1,2,3,4,5,0,1,2,3,4,5,0,\dotsc)$, whose period is $T$, in this case $T=6$. $S$ can be thought to be created by going around the circle defined by $C$:

$S$ can be thought to be created by going around the circle defined by $C$.

I have an algorithm that creates another sequence, $S_a$, picking elements from $S$ following this equation:

$S_a(i) = S(i \cdot K)$, where $K$ is a constant parameter of the algorithm, chose such that $K$ and $T$ are coprime. This is the same as doing $$ S_a(i) = C((i \cdot K) \bmod T) $$

When I want to calculate the distance $D$ between the position of elements $S_a(i)$ and $S_a(i-1)$ in the original sequence $C$, thought as a "circular distance" between the elements, but taken always in the same direction, lets say clockwise. I would go like:

$$ D = \begin{cases} T - S_a(i-1) + S_a(i) & \text{if $S_a(i) \leq S_a(i-1)$}, \\ S_a(i) - S_a(i-1) & \text{else}. \end{cases} $$

I need two things:

  1. A notation for $D$ that expresses the idea of “circular distance” around $C$.
  2. A one-line expression for the calculation of that distance. I'm actually trying to get an expression for $D$ in terms of $K$ and $T$. Intuitively, I think it's $D = \operatorname{rem}(K,T)$ but I want to prove it. It comes to modular arithmetic and I'm weak on that topic.

Can anyone, please, help me with that?

Thanks in advance for your help.

(And I apologize in advance should this be a duplicate but I couldn't find the answer)