The Python computer language has a built-in operation cmp(a,b)
that returns $-1$, $0$ or $1$, if $a, $a=b$ or $a>b$, respectively. I'd like to know if there is a mathematical operation or property that supports this Python operation.
A function that maps inequalities to $-1$, $0$, or $1$.
-
0@KevinCarlson, This type of function $f_b(a)$ has a name? I'd like to read about. I'm not familiarized with mathematical terminology. – 2012-08-04
2 Answers
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!
-
0Or, in terms of the Iverson bracket, \mathrm{cmp}(a,b)=[a > b]-[a < b] – 2012-08-04
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).
-
0No worries, Robert! – 2012-08-04