You've already defined your function (assuming you've also chosen its domain).
One of the main ways to "create" a function is simply by specifying its values at all points, and your description has done so.
Typical notation for a function created by the sort of description you give is a definition by cases:
$$ f(x) := \begin{cases} 0 & x = 0 \\ 1 & x \neq 0 \end{cases} $$
For many applications — most applications, I expect — this is one of the best descriptions of said function. If need be, name it with a letter, and continue on with whatever you're doing.
The complementary function
$$ g(x) := \begin{cases} 1 & x = 0 \\ 0 & x \neq 0 \end{cases} $$
which is related to your function by $f(x) = 1 - g(x)$ comes up often enough in some contexts to have been given a name and notation: e.g.
- The Kronecker delta. A few different notations exist depending on the setting; e.g. $\delta_x$, $\delta[x]$, or $\delta_{x,0}$.
- The Iverson bracket. This would be notated $[x = 0]$. This notation is, IMO, indispensable for doing complicated calculations with summations.
x == 0 computes this function in C and C++, and many other programming languages allow similar.
Some applications might want to represent such a function in particular ways. For example, if one only cares about the value of $g(x)$ when $x$ is an integer, but strongly prefers to work with analytic functions (e.g. because you're studying a sequence using complex analysis), one has the fact that
$$ g(x) = \mathop{\mathrm{sinc}}(\pi x) $$
holds whenever $x$ is an integer.
(if you're unfamiliar with it, $\mathop{\mathrm{sinc}}(z)$ is the continuous extension of $\sin(z) / z$)
x==0?0:1or something likeif x=0 then 0 else 1, which both seem pretty easy to me. – hmakholm left over Monica Jun 13 '16 at 22:17Piecewise[{{0,x=0}},1]and then multiply by $5$ to your heart's content. Example here. – hmakholm left over Monica Jun 13 '16 at 23:05return x != 0, or evenreturn !!xwould work, since in C there is no distinction between ints and booleans, but in other languages that make the distinction, you can go withreturn x == 0 ? 0 : 1as Henning Makholm suggested. – Pedro A Jun 13 '16 at 23:46x/((x*(1/2+(1/π)*atan(|x|)-1/2))/(atan(x)/π))which is not true but ironically is a way to write sign() function where output is -1 for all negative X values and +1 for all positive X values and undefined for 0. This is pretty interesting and can likely be utilized. For starters, it can be simplified toatan(x)/atan(|x|)=sgn(x)which is pretty neat, granted, off the top of my head, both atan()s can be removed fully.... lol – Albert Renshaw Dec 05 '22 at 02:57