I am wondering what the correct derivative of the $clip(x,min\_value, max\_value)$ function is, where the $clip(\cdot)$ function clips $x$ to the range $[min\_value, max\_value]$.
For convenience, take $f(\cdot) = clip(\cdot)$, $a = min\_value$, and $b = max\_value$. Then, the function can be defined as:
$f(\cdot) = \left\{\begin{matrix} a\ \text{if}\ x \leq a\\ b\ \text{if}\ x \geq b\\ x\ \text{else} \end{matrix}\right.$
Inspired by this graphic, stemming from a research paper, I defined the derivative of the $clip(\cdot)$ function as follows:
$f'(\cdot) = \left\{\begin{matrix} 0\ \text{if}\ x \leq a\\ 0\ \text{if}\ x \geq b\\ 1\ \text{else} \end{matrix}\right.$
Thus, at $a (= min\_value)$, we have $f'(a) = 0$.
However, equivalently to $f(\cdot) = clip(\cdot)$, we could take $g(\cdot) = clip(\cdot)$ and use the following definition:
$g(\cdot) = \left\{\begin{matrix} a\ \text{if}\ x < a\\ b\ \text{if}\ x > b\\ x\ \text{else} \end{matrix}\right.$
In this case, I'd define $g'(\cdot)$ as follows:
$g'(\cdot) = \left\{\begin{matrix} 0\ \text{if}\ x < a\\ 0\ \text{if}\ x > b\\ 1\ \text{else} \end{matrix}\right.$
In this case, we would get $g'(a) = 1$.
So, if I did not make an error somewhere, two effectively identical function definitions, $f(\cdot)$ and $g(\cdot)$, lead to two distinct derivatives. Now, I was wondering whether I made an error somewhere or, if not, which derivative (i.e. $f'(\cdot)$ or $g'(\cdot)$) to prefer.