How to compute the derivative of the maximum of multiple linear functions?

40 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

The formula is almost correct, except that

  • $s(x)$ might not be differentiable at one point.
  • if $b=c+e$, $s'(x)$ is eventually $1$. However, the RHS is eventually $0$.

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$.