The Python computer language has a built-in operation cmp(a,b) that returns $-1$, $0$ or $1$, if $a<b$, $a=b$ or $a>b$, respectively. I'd like to know if there is a mathematical operation or property that supports this Python operation.
|
|
|||||||
|
|
You could do something manipulating the signum function. For instance, define your function: $\operatorname{cmp}:\mathbb{R}^{2}\to\{-1,0,1\}$, as follows: $$\operatorname{cmp}(x,y)=\operatorname{sgn}\left(x-y\right)$$ And as pointed out by the wikipedia article, the signum function is defined as: $$\operatorname{sgn}(x)=\begin{cases}1 & \text{ if } x\gt0 \\ 0 & \text{ if } x=0 \\ -1 & \text{ if } x\lt0\end{cases}$$ Hope this helps! |
|||||||
|
|
If you're willing to let $0/0=0$, then $$\frac{a-b}{|a-b|}$$ works. Kevin Carlson was just saying that you could simply define a function to have such a property and that would be sufficient. There's no reason to limit yourself to a single symbolic expression that covers the whole number line. Functions are more flexible than that. (I can delete this section if you want Kevin, I'd hate to steal your answer). |
|||
|
|