3

I was wondering how to properly (or correctly if only one correct definition exists) define the $clip(x,min\_value, max\_value)$ function, which clips $x$ to the range $[min\_value, max\_value]$.

For convenience, take $f(\cdot) = clip(\cdot)$, $a = min\_value$, and $b = max\_value$. I am considering two candidate definitions:

1:

$f(\cdot) = \left\{\begin{matrix} a\ \text{if}\ x \leq a\\ b\ \text{if}\ x \geq b\\ x\ \text{else} \end{matrix}\right.$

or 2:

$f(\cdot) = \left\{\begin{matrix} a\ \text{if}\ x < a\\ b\ \text{if}\ x > b\\ x\ \text{else} \end{matrix}\right.$

Hence, as I see it, the important detail here is whether to use the $\leq$ and $\geq$ operators or the $<$ and $>$ operators alternatively.

I am wondering which of the two versions above is correct/preferred and if there is any paper I can cite for its definition. The difference might seem trivial at first glance, but it of course has implications for defining the derivative of the function in the next step.

Daniel B.
  • 133

1 Answers1

1

Both are correct and exactly identical. In particular $f(a)=a$ and $f(b)=b$ for both your proposed definitions.

Parcly Taxel
  • 103,344
  • So do I see it correctly that I can choose either definition (since they are equivalent), but depending on my choice I will get distinct derivatives $f'$ (which will be justified by my choice of definition for $f$)? – Daniel B. Jan 08 '21 at 23:25
  • 2
    You will not get different derivatives. The functions are identical, so the derivatives will be identical. Perhaps your method for determining the derivative is wrong? – MPW Jan 08 '21 at 23:27
  • Might be. I intended to make a "piecewise" derivative, one for each case (i.e. for x < a, x > b, and else, respectively). But I think I'll better make a separate question out of it then. – Daniel B. Jan 08 '21 at 23:30