First off, I am sorry if I pose my question in a clumsy manner, as I believe I am unaware of the technical expressions.

I suppose the title requires explanation:

Simply put, I am asking whether there is a function $f(x,y)$ that indicates whether or not $x>y$, $x<y$ or $ x=y$ is true and then returns a fixed constant ( say $a$, $b$ or $c$) value unique to each case ( i.e. in each of the 3 cases the function should return a different constant value).


$f(x,y) = 0$ iff ( =if and only if) $x=y$

$f(x,y) = 1$ iff $x>y$

$f(x,y) = -1$ iff $ x<y$

I have tried several functions, but all seem to have problems. For example I tried the obvious

$ f(x,y ) =\frac{x - y}{| x- y|}$,

which breaks down when $x=y$ and I then tried ( in an attempt to make the result at $x=y$ finite)

$ f(x,y) = e^{-\frac{x - y}{| x- y|}}$.

This has a similar problem for $\frac{x - y}{| x- y|}$ can be both positive and negative infinity,when $x = y$ or better(?) as $x$ approaches $y$.

In fact, maybe asking for the existence of such a function is a bit to broad. Apart from that, of course such a function exists, one can simply define one. So I ask, can you find such a function. Further find such a function that can be expressed using more or less simple operations ( addition, multiplication, exponentiation,...).

Any help would be greatly appreciated. Also any pointers towards technical problems in my question, would be equally appreciated!

  • 1
    $\begingroup$ Such a function can't be continuous, and since a/|a| only spits out two values, rather than three, and those values are constrained, I'm pretty sure the answer is no. That said, maybe someone will come up with something I never thought of. Or maybe a proof is possible. $\endgroup$ – Alfred Yerger Dec 25 '17 at 16:12
  • $\begingroup$ @ Alfred Yerger I see. Perhaps I should have specified the domain of f. Do you think the answer changes if x and y are integers. If x and y are restricted to the naturals numbers, surely continuity can't be an issue...? $\endgroup$ – wittbluenote Dec 25 '17 at 16:14
  • 1
    $\begingroup$ It certainly opens up possibilities, but then you could just define it piecewise, and I don't think that's what you want either. You want a formula, I think. $\endgroup$ – Alfred Yerger Dec 25 '17 at 16:15
  • $\begingroup$ @ Alfed Yerger Yes, that is exactly what I want ! $\endgroup$ – wittbluenote Dec 25 '17 at 16:16
  • $\begingroup$ Certainly, there are some obvious properties of $f(x,y)$. Surely, $f(kx, ky)= f(x,y)$ and $f(k+x, k+y)= f(x,y)$, where k is any real positive number. I guess this isn't all to helpful though... $\endgroup$ – wittbluenote Dec 25 '17 at 16:25

The function you want is discontinuous, yet you want it written using "simple" functions or operations, which are all continuous wherever they are defined. (So their composition will be continuous wherever it is defined.)

It all hangs on which "simple" functions or operations you allow. I've already suggested $\operatorname{ceil}(x)=\lceil x \rceil$ and $\operatorname{floor}(x)=\lfloor x\rfloor$ in the comments; I've seen the other answer with the function 'signum'... That is the point: unless you allow at least one of your "simple" functions to be discontinuous, there is no solution. Once you allow one, then we can talk about how to use it for your particular purpose.

Update: You are asking whether we can do the same while restricting to only whole numbers. I think we can do the following way, to start with:

$$f(n)=\frac{2n+1}{|2n+1|}=\begin{cases}1 & n \ge 0 \\ -1 & n \lt 0\end{cases}, n\in\mathbb Z$$

Now you proceed with $\operatorname{sgn}(n)=\frac{f(n)+f(n-1)}{2}$ and then follow up as in @vadim123's answer... Or, directly put $pf(x-y)+qf(x-y-1)+r=\begin{cases} p+q+r & x\gt y \\ -p-q+r & x\lt y \\ p-q+r & x=y\end{cases}$. Then, solve:

$$\begin{align} p+q+r & =a \\ -p-q+r & =b \\ p-q+r & =c \end{align}$$

to get $q=\frac{a-c}{2}$, $p=\frac{c-b}{2}$ and $r=\frac{a+b}{2}$, so the final formula is:


  • $\begingroup$ Thanks! I see. So there is a mismatch. The one function would continuous and the other is discontinuous. Does changing the domain help ( i.e. naturals)? $\endgroup$ – wittbluenote Dec 25 '17 at 16:42
  • $\begingroup$ Normally that would be a separate question. I will need to think about it. The argument about continuity cannot be used there... $\endgroup$ – user491874 Dec 25 '17 at 16:45
  • $\begingroup$ @wittbluenote I've updated my answer. $\endgroup$ – user491874 Dec 25 '17 at 16:52
  • $\begingroup$ Thanks a lot! I think this should work! Can't we now use the fact that $|{x} |= \sqrt{x^2}$ to make the function continuous? $\endgroup$ – wittbluenote Dec 25 '17 at 16:58
  • $\begingroup$ Is $\sqrt{x^2} $ continuous for all real x? $\endgroup$ – wittbluenote Dec 25 '17 at 17:01

Are you familiar with characteristic functions? Put $$ \chi_E(x,y) = \begin{cases} 1 & (x,y)\in E \\ 0 & (x,y)\in E^c \end{cases}. $$ The function you are looking for is $$ f(x,y) = a\chi_{x>y}(x,y) + b\chi_{x<y}(x,y) + c\chi_{x=y}(x,y). $$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.