Expression that tests equality

39 Views Asked by At

I am not trying to solve any specific problem (I am just curious). I want to define a function $f(a,b)$ that outputs $1$ when $a=b$, and $0$ otherwise. I want to actually define it with an equation, because just defining that $f(a,b)=1$ if $a=b$ and $f(a,b)=0$ otherwise is too easy (this type of function probably has a name but as I lack knowledge I don't know what to call it). I came up with this:

$$f(a,b)=\dfrac{1+(-1)^{\Bigg\lceil\dfrac{\vert a-b\vert}{\vert a-b\vert+1}\Bigg\rceil}}{2}$$

It works with complex numbers.

Is there a more efficient way of doing this, or a way of expanding the domain of the function beyond complex numbers?