Finding a non-piecewise function that maps all $\mathbb{Z}\setminus \{0\}$ to $0$ and $0$ to $1$

43 Views Asked by At

I am trying to devise a function that maps $\mathbb{Z} \setminus \{0\}$ to $0$ and maps $0$ to $1$ that is not a piecewise function.

If $\mathbb{Z} \setminus \{0\}$ to $0$ and maps $0$ to $1$ is not possible then a function $\mathbb{N} \setminus \{0\}$ to $0$ and maps $0$ to $1$ could possibly work too.

Any help is much appreciated (I am really stuck on this one), thanks in advance for the help!

(Context: This is for a program I am trying to write without if statements)

2

There are 2 best solutions below

2
On BEST ANSWER

You could take $\left\lfloor \frac{1}{n^2+1} \right\rfloor$.

If you want to avoid using floats and the floor function, but you are willing to use the absolute value, you can consider $\frac{1-\left|n\right|+\left|\left|n\right|-1\right|}{2}$

0
On

Take $0^{n^2}$, accepting $0^0=1$. (Strictly speaking, $|n|$ is somewhat piecewise ...)