How to use a clamp function / median in mathematical notation?
I'm writing some mathematical equations that describe some computations in my program and it's pretty important that it's written correctly. At one point, it clamps or truncates a value, $x$, into the range $[0, 1]$.
How would i best denote this in official mathematical notation? My best attempt so far is $$ \operatorname{max}(0, \operatorname{min}(x, 1)) $$ But is $\operatorname{min}$ and $\operatorname{max}$ even allowed?
Also, i made the observation that it is also the median value, so could maybe something like this be written? $$ \operatorname{med}(0, x, 1) $$
Solution 1:
There's no such thing as one "official mathematical notation". There are a bunch of basic conventions that most authors follows, and each field has its own special ways of expressing things. The best advice is usually to follow what other people in your field are doing. I.e., if there are publications which deal with algorithms similar to the one you've written, I'd check to see what notation those use.
If there's no precedent that you can follow, try to pick a notation which is easy to understand and doesn't put unnecessary burden on the reader. For example, while it's correct that the median of $\{0,x,1\}$ is $x$ clamped to $[0,1]$, most people will probably stare at that for a while before they realize what's going on. $\max(0,\min(x,1))$ is much better - most people will instantly recognize that as a clamping operation.
If you use a particular operation like clamping a lot, it'd probably be best to simply define your own syntax for expressing it. One idea would be overload the syntax used to restrict functions to a certain subset of their domain, which is $\left.f\right|_D$. You could similarly define $\left.x\right|_{[a,b]}$ to mean $x$ restricted to the set $[a,b]$. If you do that, make sure though that you define it cleary at the beginning, and maybe repeat the definition the first few times you use it.