A function whose value is either one or zero
Define $f: \mathbb{R} \rightarrow \{0,1\}$ via $$ f(x) = \begin{cases} 0 &\text{ if } x = 0\\ 1 &\text{ if } x \neq 0. \end{cases} $$
If you are programming, this can be accomplished with a single if-then-else statement. This will surely be more efficient to compute than any "algebra formula" (by which I take you to mean "non-piecewise formula"), since if clauses are built into the language at a very low level.
The function $f: \mathbb{R} \rightarrow \{0,1\}$ defined via $$ f(x) = \lim_{n \rightarrow \infty} \sqrt[n]{x^2} $$ satisfies $f(0) = 0$ and $f(x) = 1$ for all $x \neq 0$. This is entirely useless for programming, but it is the simplest function I can think of that avoids a piecewise definition.
I think that the most compact way to write this is using the Iverson Bracket:
$f: \mathbb{R} \to \{{0,1}\}$
$$ f(x) = [x \neq 0]$$