Given two real numbers $a$ and $b$, is there any formula which would give $1$ if $a=b$ and $0$ if not ? (I am not talking about conditional expressions). Thanks.
Edit : Everything is allowed.
(It's taken me long enough to write this ... I bet some of these appear in other answers.)
Edit: Because, of course, one has to get the parity of the last one backwards. Fixed.
Edit: Added limit to contour integral because, sadly, not all pairs of reals have integer differences. And more:
The classic one: $0^{|a-b|}$ ...
Edit: In case you consider $|.|$ as conditional choose $$0^\sqrt{(a-b)^2}$$ instead.
This one would do, if you allow limits:
$$\lim_{n\to\infty} \exp (-n|a-b|)$$
You could also compute
$$2-\mathrm{Card} \;\{a,b\}$$
Or
$$1-\int_{a-b}^{e(a-b)} \frac{\mathrm{d}x}{x}$$
but I don't think it's very clean to rely on $\int_0^0 f(x) \mathrm dx=0$ when $f$ is not defined at $x=0$.
Another limit: taking $\frac{2}{\pi}\arctan (b-a)$ you get a number in $]-1,1[$, hence you can use the limit $\lim_{n\to\infty} (1-x^2)^n$, which is $1$ if $x=0$ and $0$ if $x\in [-1,1]\backslash\{0\}$. All in all:
$$\lim_{n\to\infty} \left[1-\left(\frac{2}{\pi}\arctan (a-b)\right)^2\right]^n$$
How about this where $\lfloor x\rfloor$ is the floor function of $x$:
$\min\{\left\lfloor 2^x\right\rfloor, \left\lfloor 2^{-x}\right\rfloor\}$.
You can even get rid of the min function by recasting this as
$\frac{\left\lfloor 2^x\right\rfloor+ \left\lfloor 2^{-x}\right\rfloor-\mid \left\lfloor 2^x\right\rfloor- \left\lfloor 2^{-x}\right\rfloor\mid}{2}$
Edit: As ASKASK correctly pointed out (thanks), the question asked for an indicator of equality between $a$ and $b$ rather than an input of $x$ being $0$. To make the adjustment, $x$ in the post can be replaced by $a-b$.
$\left\lfloor\frac{1}{1+(a-b)^2}\right\rfloor$, where $\lfloor x\rfloor$ - floor function and $a$ and $b$ - real numbers.
$$ \left|\{a\}\cap\{b\}\right| $$
Where $|\cdot|$ denotes the order (number of elements) of a set.
One can come up with many similar examples. For example, $\left|\{(a,b)\}\cap\Delta\right|$, where $\Delta=\{(x,x)\;\colon\;x\in\mathbb R\}\subset\mathbb R\times\mathbb R$.
I would use this, but it maybe it is already too conditinal for you:
The indicator function is often used in such cases, so the function takes only two values, $0,1$ in such a way that $$ 1_M(x)=\begin{cases}0,x\text{ is not element of } M \\1,x\text{ is element of } M \end{cases} $$ where M is any set which we choose. So in your case we would take $\{a\}:=M\subset\mathbb{R}$ and get $$ 1_{\{a\}}(x)=\begin{cases}0,x\text{ is not element of } \{a\} \\1,x\text{ is element of } \{a\} \end{cases} $$ meaning $1_{\{a\}}(x)$ equals only $1$ if and only if $x=a$ or in you case $1_{\{a\}}(b)=1$ with $b=a$. Although technically it actually says that it is only an element of an $1$-element set.
Just this: $$ \{a=b\} $$
It evaluates to 1 if the condition inside the curly brackets is true and to 0 if it isn't.
a == b
is already 1 if they're equal and 0 otherwise. – user2357112 Oct 27 '15 at 20:06a == b
. All the answers you've gotten are notational differences or ways to complicate things. None of this will help you; you need to analyze your problem from a higher-level perspective. – user2357112 Oct 27 '15 at 20:47sete
orcmove
on x86). None of the formulas below is likely to be faster. – Jean-Claude Arbaut Oct 28 '15 at 09:41