$f(x) = 0$ when $x$ is $0$, and $1$ otherwise I've been trying to create a function that will return $0$ when $x$ is $0$, and for any other $x$ value it should return $1$. I've searched for a pre-existing function online too and wasn't able to find one.

Do you know of any function that can do this?
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 &amp; x = 0 \\ 1 &amp; x \neq 0 \end{cases} $$

For many applications &mdash; most applications, I expect &mdash; 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 &amp; x = 0 \\ 0 &amp; 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$)
Paw88789's answer worked great for what I'm trying to do; the only issue was that it didn't work for all &quot;numbers&quot;; some imaginary numbers would cause division by 0. Luckily tonight I was able to create a function that produced the desired result for all real, imaginary, and complex numbers.
$f(x) = \left \lceil \frac{1}{2\Gamma \left ( \left | x \right | \right )} \right \rceil$
*Note the absolute value inside of Gamma, as it's easy to go unnoticed