# 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)$$

• $\operatorname{med}(0,x,1) \:$ is quite clever. $\;\;\;$
– user57159
May 10, 2013 at 23:41
• @Ricky Demer Is it valid though? Could other people understand it without explanation? May 10, 2013 at 23:47
• Using the median is clever, but it just adds additional work for the reader. Just use $\max$ and $\min$. "Official" should really be replaced with "well-defined." However, I think most people will recognize $\max$ and $\min$ and you probably need not define either of those functions. May 10, 2013 at 23:53
• Alternatively, write out three more letters for $\:\operatorname{median}(0,x,1)\;$. $\;\;\;$
– user57159
May 10, 2013 at 23:57
• $x-\lfloor x \rfloor$ floor function.
– user366820
Nov 18, 2019 at 5:20

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.