Directional derivative of the function $ f(\mathbf{x})=\sum_{i=1}^{n-1}\left|x_{i+1}-x_{i}\right| $ Problem: Consider the function
$$
f(\mathbf{x})=\sum_{i=1}^{n-1}\left|x_{i+1}-x_{i}\right|, \quad \mathbf{x}=\left(x_{1}, \cdots, x_{n}\right)^{T}
$$
on $\mathbb{R}^{n}$ with $n \geq 2 .$ For any vector $\mathbf{v}=\left(v_{1}, \cdots, v_{n}\right)^{T}$, find the directional derivative $D_{\mathbf{v}} f(\mathbf{x})$
One can easily see that for any $h( \neq 0)\in \mathbb R$,
$$\frac{f(\mathbf x+h\mathbf v)-f(\mathbf x)}{h} \leq f(\mathbf v)$$ from triangular inequality. But how to find the limit $$\lim_{h \rightarrow 0 }\frac{f(\mathbf x+h\mathbf v)-f(\mathbf x)}{h}$$
 A: I would attack this as follows, heuristically.
The expression you wish to evaluate is
$$D_{\mathbf{v}}f(\mathbf{x}) = \lim_{h \to 0} \frac1{h} \sum_{i=1}^{n-1}\left [\left |x_{i+1}-x_i + h (v_{i+1}-v_i) \right |- \left |x_{i+1}-x_i \right | \right ]$$
Assume $h > 0$ and $x_{i+1} \ne x_i$ for all $i \in {1,2,\cdots,n-1}$.  The way through this is to recognize that there exists a value of $h$, say, $h_0$, less than the minimum value of $| x_{i+1}-x_i |$ over all value of $i$.  (This is because, if $\mathbf{v}$ is a direction vector, then the maximum absolute value of the distance between adjacent components is $1$.)   In this way, we may write
$$\left |x_{i+1}-x_i + h (v_{i+1}-v_i) \right | = \left |x_{i+1}-x_i \right | + h \left |v_{i+1}-v_i \right |$$
for all $0 \lt h \lt h_0$.  In this case, the directional derivative you seek is simply
$$D_{\mathbf{v}}f(\mathbf{x}) = \sum_{i=1}^{n-1} \left |v_{i+1}-v_i \right | $$
If, in contrast, there exists a value of $i$ such that $x_{i+1} = x_i$, then no such $h_0$ exists and accordingly the directional derivative does not exist.
