Functions for boolean operators, that return 1 or 0

94 Views Asked by At

Are there any purely mathematical expressions that are equivalent to boolean operators and return $1$ or $0$?

For example: $a > b$

Is there any $f(a, b)$ for which if $a>b$, $f(a,b)=1$ and if $a < b$, $f(a,b)=0$? Can you express such a function with a simple expression and with no branches/multiple definitions ?

3

There are 3 best solutions below

2
On BEST ANSWER

Using the absolute value, for example, a possible expression is $f(a,b)=\frac12\Big(1+\frac{a-b}{|a-b|}\Big)$. If you don't like the absolute value this can be rewritten as $f(a,b)=\frac12\left(1+\frac{a-b}{\sqrt{(a-b)^2}}\right)$.

0
On

You could use an Iverson Bracket: $$f(x,y) = [x>y]$$

2
On

$H(a-b)$, where $H$ stands for the Heaviside step function (the primitive of the Dirac $\delta$).

Also, $H(x)=\frac{sgn(x)+1}{2}=\lim_{a\to\infty}\frac{e^{ax}}{e^{ax}+1}$.