I have N vectors $x_1, x_2,...,x_N$ (all of equal length) and would like to compute the sum of absolute differences between consecutive vectors as well as between $x_N$ and $x_1$:
$|x_1 - x_2| + |x_2 - x_3| + ... + |x_{N-1} - x_N| + |x_N - x_1|$
and wonder about the best way to formulate this in mathematical terms. A straightforward way would be:
$\sum_{i=1}^{N-1} |x_i - x_{i+1}| + |x_N - x_1|$.
Is there a more compact way to express this? Or to be more precise, is there a way to express that without the need for $|x_N - x_1|$ by a smarter indexing?
As was already mentioned in the comments, using modular arithmetic is probably the way to go. We can denote the ring of integers modulo $N$ as \begin{equation} \mathbb{Z}/N\mathbb{Z}=\{0,1,2,\ldots,N-1\}. \end{equation} These numbers can be seen as all possible remainders when dividing by $N$.
Your sum can now be written down as \begin{equation} \sum_{i\in \mathbb{Z}/N\mathbb{Z}} |x_{i+1}-x_{i+2}| = |x_1 -x_2|+\ldots+|x_N-x_1|. \end{equation}