Find a function comparing two variables that is equal to 1 when they are equal and 0 when they are not

99 Views Asked by At

I am trying to find a function that compares two variables. When these two variables are equal, the function should equal 1. For any other value, the function should equal 0. Is there a way to do this without using logic arguments?

My naive attempt to do this uses floor and ceiling notation (possibly incorrectly) where I end up using logic to get my result. Here is my best attempt:

min[max[1+x-y,0],max[1+y-x,0]]

Hand Drawing

Is there a way to write this as a function without the floor/ceiling max/min logic?

1

There are 1 best solutions below

10
On BEST ANSWER

$$f(x,y)=\begin{cases}1&x=y\\ 0&x\neq y \end{cases}$$