# Function that is 1 for all positive integers but 0 at 0

A friend of mine had a simple question (at least to state) that I thought I would share: can you, without the use of indicator functions, find a(n) (elementary) function that satisfies

\begin{cases} f(n) = 1,& n \in \mathbb N \\ f(0) = 0. \end{cases}

I have been trying and playing around with trigonometric functions but the periodicity keeps bugging me with the zero on these attempts. I have not found a solution myself yet!

• What is the domain of the function supposed to be? – f'' May 31 '16 at 21:17
• I suppose the way it was stated to me, $\mathbb N$, but I have been working in the reals. I do not think the initial intend was to go beyond that. – Therkel May 31 '16 at 21:19
• No need to restrict $n$ to positive integers, as $~ g(n)=f(n^2) ~$ could replace any $f(n)$ that works – humn Jun 1 '16 at 2:22
• The real question is, is 0 a natural number ? – julien2313 Jun 1 '16 at 13:46
• @DmitryRubanovich Read the linked article about elementary functinos. In essense, it's arithmetic operations (+ – × ÷), exponentials, logarihtms and solutions to algebraic equations (such as $n$th roots), and any functions that can be expressed by a combination of these. – Frxstrem Jun 4 '16 at 17:41

No discontinuities, no stretching the definition of elementary functions, even works for negative integers:

$\frac{1}{2} (\cos{(2^{(x^2)}\pi)}+1)$

The key insight was to

construct a function that is a multiple of 2 for most integers, but not 0. $2^x$ satisfies this for positive integers, then $2^{(x^2)}$ makes that work for negative as well.

• This is a neat answer, but why does it have forty-four votes while $\sin(\pi x)/(\pi x)$ has five? :\ – DanielSank Jun 2 '16 at 6:46
• @DanielSank it might have something to do with the fact that that function is not defined for x = 0 – Olorin Jun 2 '16 at 13:08
• I am not at all competent enough to award the 'accepted answer' to anyone but the highest voted answer (i.e. the one the community liked the most), although my personal favorite is the one by @humn (collaborated with @Etoplay) for its simplistic nature. I absolutely loved the creativity all across the board! – Therkel Jun 2 '16 at 21:00

Neater version, thanks to Etoplay. (“Just put the abs below the fraction. ...”)

$\kern9em \llap{\color{black}{ f(n) ~~ = }} ~~~ \dfrac{ n }{ |n{-}1| + 1 }$

$\kern9em \llap{\color{black}{ f(0) ~~ = }} ~~~ \dfrac{ 0 }{ |0{-}1| + 1 } ~~=~~ \dfrac0{1{+}1} \color{black}{~~=~~0}$

$\kern9em \llap{\color{black}{ f \, ( \, n{=}1,2,3,\ldots\, ) ~~ = }} ~~~~ \dfrac{n}{ n{-}1 + 1 } ~~~=~~~~\, \dfrac{n}{n} \color{black}{\,~~~=~~1}$

(Can be made to work for all integers by replacing $n$ with $|n|$ in the formula, and for almost all reals — all but $~ 0 < |n| < \epsilon \,$— by replacing $1$ with an arbitrarily small $\epsilon$.)

Original solution, taking $\mathbb N$ to mean 1,2,3,... and acknowledging $~ |x| = \sqrt{x^2} ~$ as an elementary function:

$\kern5em \color{black}{ f(n)~=~ } \dfrac{ |3n{-}1| - 1 }{ 3n{-}2 }$

$\kern5em \color{black}{ f(0)~=~~~ } \dfrac{ |0{-}1| - 1 }{ 0-2 } ~~~=~~ \dfrac{1-1}{-2} \color{black}{~~=~~0}$

$\color{black}{ f(n{=}1,2,3,\ldots)~=~ } \dfrac{ (3n{-}1) - 1 }{ 3n-2 } ~~=~~ \dfrac{3n-2}{3n-2} \color{black}{~~=~~1}$

(This came from an intuition for $~ n{-}\frac12 ~$ that surprisingly trespassed $0/0$ for $~ n=1$. Haven't yet thought of a neat variation that works for all reals, such as $~ n = \frac23 ~$ and $~ 0 \ne n < \frac13 ~$ in this case.)

• Just put the abs below the fraction. You then have $\frac{2x}{|2x-1|+1}$ – Etoplay Jun 1 '16 at 9:57
• Why we allow abs function? abs is defined conditionally. By allowing functiones defined conditionally we can also use any conditional as well... – Luis Masuelli Jun 1 '16 at 16:58
• @LuisMasuelli abs is not defined conditionally; as described in the answer above, it can be defined as √ x^2 (pardon my lack of fancy markdown) – Tin Man Jun 1 '16 at 20:06
• @Amadeus9$\sqrt{x^2}$$\sqrt{x^2}$ – EKons Jun 2 '16 at 18:06
• @Amadeus9 It's actually LaTeX (rendered by MathJax), not Markdown. (I thought the names might help you with learning the syntax. ;) ) – jpmc26 Jun 2 '16 at 22:03

I think this one is the shortest and simplest so far:

$\frac{1}{2}((-1)^{2^x}+1)$

If you want it to work with negative values of $x$, just

change $x$ to $x^2$ in the formula.

P.S. I just noticed this is very similar to @Joe K's formula, but avoids using trigonometry. Basically

replacing $\cos(2^{x}\pi)$ with $(-1)^{2^{x}}$.

$0^0$ equals $1$. The Google calculator agrees with me.

If that's the case, then the function is:

$f(n) = 0^{0^n}$ satisfies all conditions, because $0^n$ with $n > 0$ will always equal 0.

• I'm not entirely convinced that $0^x$ is actually an elementary function; the linked Wikipedia page is ambiguous, but if you take exponentiation as "including the function $e^x$" or "satisfying $\frac{d}{dx}a^x = c\cdot a^x$, then $0^x$ is not elementary if you take $0^0=1$." – Milo Brandt May 31 '16 at 23:26
• $0^0$ is not equal to $1$. It is an indeterminate form. – Arcturus Jun 1 '16 at 2:05
• I don't think there's really a "correct answer" to the question of whether $0^0$ is defined or not. Some authors define it, and for those authors, it is defined; other authors do not define it, and for those authors, it is undefined. The question of whether or not it should be defined is something else. – Tanner Swett Jun 1 '16 at 2:34
• Link about $0^0$: "The discussion of 0^0 is very old. [...] Consensus has recently been built around setting the value of 0^0 = 1." – hvd Jun 1 '16 at 7:48
• $f(n) = 1 - 0^n$ could be considered simpler than $0^{0^n}$ and accomplishes the same purpose. However, it's the same key idea as this answer. – Paul Sinclair Jun 1 '16 at 16:43

$f(n) = 1 - 0^n$
$0^0 = 1$, $0^n$ for any positive $n$ is $0$.

• – Simon Buchan Jun 2 '16 at 2:07
• @SimonBuchan Limit of function in point is not always equal to value of function in that point. Truth is that actual value of 0/0 is undefined, but it is often considered to be 1 for sake of several disciplines. Fun fact: limit of n^n for n = 0 is 1. – Revolver_Ocelot Jun 2 '16 at 11:04
• See the comments on this similar answer for a discussion of whether $0^0=1$. – Kevin - Reinstate Monica Jun 2 '16 at 17:42
• @Revolver_Ocelot: yep, that is why I explictly stated which limit of 0^0 is relavant here, and it's 0^n (actually, 0 is only the limit from above, but w/e). 0^0 is actually "indeterminate", i.e. has multiple possible values depending on context. Your typo of 0/0 is actually similar: for n -> 0, n/0 is undefined, n/n = 1, 0/n = 0. – Simon Buchan Jun 3 '16 at 2:41
• @SimonBuchan - This isn't a problem about limits at all. It is the value of the function itself, not limits, that is needed here. While not universally accepted, defining $0^0 = 1, 0^n = 0$ when $n > 0$ is a widely-used convention with hundreds of years of precedence. Whether you agree with it is an argument for a different place. Business Cat's answer works perfectly under that convention. – Paul Sinclair Jun 3 '16 at 23:24

I don't know if it can be accepted as the function is non defined in $$0$$, but as you probably know

$${\sin \pi x \over \pi x}$$ is $$0$$ for each $$x \in \mathbb{N}$$

and

its limit for $$x \rightarrow 0$$ is $$1$$.

So:

$$1-{\sin \pi x \over \pi x}$$

could be a solution.

• But strictly speaking, the function is undefined at x = 0. – 200_success Jun 1 '16 at 17:12
• You could use $$f(x) = 1 - \lim_{t \to x} \frac{\sin \pi t}{\pi t}$$ instead. – Umberto P. Jun 1 '16 at 21:28
• Or just use $\mathop{\mathrm{sinc}}(\pi x)$. – user1502 Jun 2 '16 at 3:52
• This is the best answer. It's far simpler than the currently most upvoted answers. – DanielSank Jun 2 '16 at 7:00
• If we're taking 0/0 then we may as well just allow n/n and define 0/0 as 0 – Inazuma Jun 3 '16 at 9:52

There is a Sign Function that you can use it like this:

$$f(n) = |\mbox{sgn}(n)|$$

• That isn't an elementary function. – f'' Jun 1 '16 at 6:59
• @f'' As I know sgn(x) is as elementary as abs(x) or |x| and cos(x), and from OP's question (elementary) is optional ;). – shA.t Jun 1 '16 at 7:56
• If allowed to use abs, sign should also be allowed – Luis Masuelli Jun 1 '16 at 17:02
• Once you learn peano arithmetic you know the sign function is elementary. Incidentally this function is differentiable everywhere. (derivative at zero is twice the dirac delta function). – Joshua Jun 1 '16 at 17:42
• If you resort to dirac, it is not elementary. In the best case you use a limit for the dirac's delta. – Luis Masuelli Jun 1 '16 at 20:41

Anyone who has studied the maths behind the Discrete Fourier Transform should be able to figure out this one

Firstly we take the function that is 0 everywhere except where it is 1 at $n = 0$, then subtract it from 1

$f(n) = 1 - \operatorname{sinc} n = 1 - \frac{\sin \pi n}{\pi n}$

• Not elementary, Mr Watson – Hagen von Eitzen Jun 1 '16 at 9:28
• I thought trig was fair game? – 小太郎 Jun 1 '16 at 9:36
• @小太郎: Well, if you're allowed exponentials and imaginary numbers, I think this is still doable... – Phil H Jun 1 '16 at 10:44
• This is undefined at zero – miniBill Jun 1 '16 at 15:21
• The sinc function is in fact defined to be 1 at 0, since that's its limiting value – 小太郎 Jun 1 '16 at 15:47

$$f(x)= \left\lceil\frac{x}{1+x}\right\rceil$$

• This is not elementary unfortunately. – Puzzle Prime Jun 1 '16 at 12:01
• @PuzzlePrime I just wanna say, I like your username :P – Mr Pie Dec 16 '18 at 7:37

$\underset{\epsilon \to 0}{\lim} \frac{x^2}{x^2 + \epsilon}$

• Taking limits is not elementary – Hagen von Eitzen Jun 1 '16 at 9:28
• True. Though, for any particular value of epsilon, the function almost satisfies the requirements. – Owen Jun 1 '16 at 13:30

$$\tanh(cn)$$; where $$c$$ is large (i.e. 1E5) will give the desired answer numerically.

You can square it if you need the negative integers to also give +ve unity.

## protected by Community♦Jun 1 '16 at 15:45

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).