Define $$ s(x) = \max(xa + b, \max(xa + c,d) + e, f) $$ where $a,b,c,d,e,f > 0$ real numbers and $x > 0$.
I am trying to differentiate $s$ w.r.t. $x$. Is the following formula true? $$ s'(x) = a\mathbb{1}_{xa + b > \max(xa + c,d) + e}\mathbb{1}_{xa + b > f} + a\mathbb{1}_{\max(xa + c,d) + e > xa + b}\mathbb{1}_{\max(xa + c,d) + e > f}\mathbb{1}_{xa+c > d}. $$ Here, $\mathbb{1}$ is the indicator function.
The formula is almost correct, except that
The derivative can be computed as follows.
$$\begin{aligned} s(x) &= \max(xa + b, \max(xa + c+e,d+e), f)\\ &= \max(xa + b, xa + c+e, d+e, f)\\ &= \max(\max(xa + b, xa + c+e), \max(d+e, f))\\ &= \max(xa + g, h)\\ \end{aligned}$$ where $g=\max(b,c+e)$, $\ h=\max(d+e,f)$ are positive real numbers.
Hence $$s'(x)=a1_{xa+g>h}$$ except at point $\frac{h-g}a$ $s(x)$ is not differentiable when $h>g$.