48

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!

Fabich
  • 7,165
  • 2
  • 35
  • 59
Therkel
  • 685
  • 1
  • 6
  • 13
  • 1
    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
  • 5
    No need to restrict $n$ to positive integers, as $~ g(n)=f(n^2) ~$ could replace any $f(n)$ that works – humn Jun 01 '16 at 02:22
  • 1
    The real question is, is 0 a natural number ? – julien2313 Jun 01 '16 at 13:46
  • The discrete Dirac impulse is not considered an elementary function, is it? Even though its continuous form can be expressed as one. – vsz Jun 01 '16 at 19:43
  • @vsz: The dirac delta isn't even considered a function. –  Jun 02 '16 at 03:55
  • @Hurkyl : although it can be d̶i̶s̶g̶u̶i̶s̶e̶d̶ expressed as one. – vsz Jun 02 '16 at 04:03
  • What you wrote in the question is already a function. So what exactly are you asking to produce? A function stated in terms of some operations? Which operations are allowed? Again, by stating the values of f at each point in f's domain you already defined f as a function. Can you, please, clarify a little what you are asking about? – Dmitry Rubanovich Jun 04 '16 at 14:33
  • 1
    @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 04 '16 at 17:41
  • @Frxstrem, ah. I see. It probably would have caught my attention sooner, if it said "formally elementary". I took the word to be used as a plain-English word rather than a formal term (despite the provided link). – Dmitry Rubanovich Jun 05 '16 at 13:16

11 Answers11

85

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.

Joe K
  • 1,098
  • 7
  • 7
  • 3
    This is a neat answer, but why does it have forty-four votes while $\sin(\pi x)/(\pi x)$ has five? :\ – DanielSank Jun 02 '16 at 06:46
  • 19
    @DanielSank it might have something to do with the fact that that function is not defined for x = 0 – Olorin Jun 02 '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 02 '16 at 21:00
  • 1
    Alternate form: $cos^2(πx^2)$ – Albert Renshaw Jan 07 '20 at 04:17
67

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&hairsp;—&hairsp;all but $~ 0 < |n| < \epsilon \,$—&hairsp;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.)

humn
  • 21,899
  • 4
  • 60
  • 161
  • 2
    Just put the abs below the fraction. You then have $\frac{2x}{|2x-1|+1}$ – Etoplay Jun 01 '16 at 09:57
  • 2
    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 01 '16 at 16:58
  • 4
    @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 Wizard Jun 01 '16 at 20:06
  • Nice improvement, @Etoplay, now featured in the solution – humn Jun 01 '16 at 22:32
  • 2
    @Amadeus9$\sqrt{x^2}$$\sqrt{x^2}$ – EKons Jun 02 '16 at 18:06
  • 1
    @Amadeus9 It's actually LaTeX (rendered by MathJax), not Markdown. (I thought the names might help you with learning the syntax. ;) ) – jpmc26 Jun 02 '16 at 22:03
  • @jpmc26 Ah, makes sense, thanks. That's why I used the generic "markdown" - note the lack of capitalization. – Tin Wizard Jun 02 '16 at 22:18
59

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}}$.

Thomas Ayoub
  • 189
  • 1
  • 1
  • 7
Puzzle Prime
  • 6,964
  • 31
  • 62
29

Although there has been some discussion about this:

$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.

Adnan
  • 749
  • 6
  • 13
  • 1
    Your problem is not a problem. Google is correct in this case. – user3294068 May 31 '16 at 21:37
  • 15
    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
  • 22
    $0^0$ is not equal to $1$. It is an indeterminate form. – Arcturus Jun 01 '16 at 02:05
  • 8
    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 01 '16 at 02:34
  • 6
    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 01 '16 at 07:48
  • For non-integer, be aware of n = -1 ;). – shA.t Jun 01 '16 at 07:59
  • $0^0^{+}=1$, For 0^{-} we have a problem. – Olba12 Jun 01 '16 at 10:52
  • @Olba12 Yes, that is correct. Luckily, OP has stated that $n\in \mathbb{N}$, which only contains positive integers. – Adnan Jun 01 '16 at 10:57
  • Oh i am sorry, I really liked your answer. My comment did not have anything with your answer, instead a "contribution" to the discussion with $0^0$. :) – Olba12 Jun 01 '16 at 11:00
  • @Olba12 Oh I didn't know, I'm glad you liked the answer :) – Adnan Jun 01 '16 at 11:05
  • 7
    $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 01 '16 at 16:43
  • 1
    @Eridan - the term "indeterminate form" refers to how the function behaves under limits. It places no restriction on the value of the function at the point. A function does not have to be continuous to be defined. Thus there is no contradiction between defining $0^0 = 1$ and $0^0$ being an indeterminate form. – Paul Sinclair Jun 01 '16 at 16:50
  • I prefer to disagree 0^0=1. Such result is isolated from divide-by-zero jokes which lead to think stuff like 2=1 – Luis Masuelli Jun 01 '16 at 16:52
  • Say: a=b=1 -> aa = ab -> aa-bb = ab-bb -> (a+b)(a-b) = b(a-b) -> (a+b)(a-b)(a-b)^(-1) = b(a-b)(a-b)^(-1) -> (a+b)(a-b)^(1 + -1) = b(a-b)^(1 + -1) -> (a+b)(0)^(0) = b(0)^(0). If we equate 0^0=1, then we break the real numbers by saying a+b=b, which makes 2=1, 3=2, 4=3, 1=3 by transitivity... and every possible linear transform over the numbers making numbers totally meaningless with such definition. – Luis Masuelli Jun 01 '16 at 16:55
  • 1
    @LuisMasuelli - Only if one is so criminally sloppy in one's mathematics that similar mistakes would be made no matter how $0^0$ is handled (as your example includes with $(a-b)^{-1}$). But this is not the place to argue which is better. The disagreement was acknowleged in the post itself. Cases one way or another should be given in a more appropriate forum. – Paul Sinclair Jun 01 '16 at 17:06
  • Does not work. 0^0 != 1 with this generator. The reduction rule in algebra says you may do this if you got here from cumulative roundoff. This isn't cumulative roundoff as we can simplify 0^0^n to 0^0 for all n not zero. – Joshua Jun 01 '16 at 17:37
  • 2
    @Joshua: what on earth are you talking about? Anyway, it works fine: as you say, 0^0^n is 0^0, which is 1, for all positive n; and 0^0^0 is 0^1 which is 0, for n = 0. There are no "rules in algebra" about statements meaning one thing only if you "got here from cumulative roundoff", whatever that means. – Nick Matteo Jun 01 '16 at 17:55
  • 1
    There are paths to 0^0 for which the answer is zero, and 0^n where 0 is constant and n is variable is the most important of them. – Joshua Jun 01 '16 at 18:37
  • In combinatorial and algebraic settings, it’s very natural to consider $0^0 = 1$ — essentially, anywhere that one’s considering the function $x^n$, with $n$ taking integer values. But in analytic settings, where one’s considering $x^y$ with real or even complex values of $y$, then it is much more natural to take $0^0$ to be either 0 or undefined. This is I think the general reason why different authors make the choices they do. – Peter LeFanu Lumsdaine Jun 02 '16 at 19:47
  • 1
    @ΈρικΚωνσταντόπουλος - What does "has 2 items" have to do with anything? Indeed, what does that even mean? I only discovered Business Cat's post after I added the comment. So I upvoted his post as well. But in any case, it is only a minor variant of this answer, and this one was first of the two. – Paul Sinclair Jun 03 '16 at 23:27
  • 1
    @PeterLeFanuLumsdaine - In analytic situations, $1$ is almost always the natural choice for $0^0$ as well. Only in rare occasions do you have use for anything else. For a smooth path $(x(t), y(t))$ with $x > 0$ everywhere and converging to $(0,0)$ to have $x^y$ converge to anything other than $1$, you have to have $x' = 0$ at the limit. That is, you only get divergence or values other than $1$ by coming in tangent to the $y$-axis. – Paul Sinclair Jun 03 '16 at 23:37
  • 1
    @ΈρικΚωνσταντόπουλος - so you are making a completely pointless complaint with no relevance to the question, based on an arbitrary and nonsensical division of the calculation that you've come up with?? – Paul Sinclair Jun 04 '16 at 13:58
  • In my opinion 0^0 should be 1, it makes logical since, but even further it would be very useful if it were 1 as the delta function would become closed form, being simply $0^x$ – Albert Renshaw Jan 07 '20 at 04:22
15

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

Business Cat
  • 1,914
  • 13
  • 23
  • 1
  • 6
    @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 02 '16 at 11:04
  • 1
    See the comments on this similar answer for a discussion of whether $0^0=1$. – Kevin Jun 02 '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 03 '16 at 02:41
  • 1
    @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 03 '16 at 23:24
10

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.

Mr Pie
  • 6,682
  • 1
  • 25
  • 88
N74
  • 101
  • 2
  • 3
    But strictly speaking, the function is undefined at _x_ = 0. – 200_success Jun 01 '16 at 17:12
  • 1
    You could use $$f(x) = 1 - \lim_{t \to x} \frac{\sin \pi t}{\pi t}$$ instead. – Umberto P. Jun 01 '16 at 21:28
  • Or just use $\mathop{\mathrm{sinc}}(\pi x)$. –  Jun 02 '16 at 03:52
  • This is the best answer. It's far simpler than the currently most upvoted answers. – DanielSank Jun 02 '16 at 07:00
  • 6
    If we're taking 0/0 then we may as well just allow n/n and define 0/0 as 0 – Inazuma Jun 03 '16 at 09:52
  • This wonderfully clean solution is undersold! It not only works for all integers but also is clearly both elementary and well defined when seen as a power series. Why not edit the following into the answer? $~\require{begingroup}\begingroup\def\T#1#2{{(\pi x)^#1\over #2!}} 1{-}{\sin \pi x \over \pi x} = \T23 - \T45 + \T67 + \cdots \endgroup$ – humn Jun 06 '16 at 00:05
  • This is called sinc actually, and it is defined at 0: https://en.wikipedia.org/wiki/Sinc_function – Ernest_Galbrun Jun 08 '16 at 14:56
  • @Hurkyl I have seen $\sin(\cdot)$ and $\mbox{sinh}(\cdot)$.... but what is $\mbox{sinc}(\cdot)$? Oh wait... I figured it out from an answer below, though why is the $\text{c}$ there? Does that stand for circumference or something, I'm guessing? – Mr Pie Dec 16 '18 at 07:39
7

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

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

Mr Pie
  • 6,682
  • 1
  • 25
  • 88
shA.t
  • 211
  • 3
  • 7
  • That isn't an elementary function. – f'' Jun 01 '16 at 06:59
  • 2
    @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 01 '16 at 07:56
  • 4
    If allowed to use abs, sign should also be allowed – Luis Masuelli Jun 01 '16 at 17:02
  • 2
    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 01 '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 01 '16 at 20:41
  • @Joshua Peano arithmetic doesn't deal with negative numbers and I've never heard the sign function mentioned in the same context as it. Perhaps you are thinking of the successor function? – N. Virgo Jun 02 '16 at 00:25
  • @Nathaniel: The sign function appears when you carry out the procedure to construct the natural numbers from the Peano numbers. The construct thereof is a natural number N is composed of { sign, P } where P is the Peano number with the same absolute value as N. The sign function just returns the sign component thereof. – Joshua Jun 02 '16 at 15:05
  • @Joshua, do you mean 'integer' when you write 'natural number'? (There is disagreement about whether or not 0 is natural, but universal useage requires that natural numbers be non-negative. I think you are using 'Peano number' for what most people would call 'natural number'.) Certainly it is possible to code integers as pairs as you have indicated, although one has to decide what to make of 0; but the usual mathematical construction is to declare integers to be equivalence classes of pairs of natural numbers, under the relation by which $(a, b) \sim (c, d)$ if and only if $a + d = b + c$. – LSpice Jun 03 '16 at 19:49
  • Oops yeah I meant integer. Anyway I've only ever seen it done as I described. – Joshua Jun 04 '16 at 01:24
5

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}$

小太郎
  • 153
  • 2
  • 4
    Not elementary, Mr Watson – Hagen von Eitzen Jun 01 '16 at 09:28
  • I thought trig was fair game? – 小太郎 Jun 01 '16 at 09:36
  • @小太郎: Well, if you're allowed exponentials and imaginary numbers, I think this is still doable... – Phil H Jun 01 '16 at 10:44
  • 2
    This is undefined at zero – miniBill Jun 01 '16 at 15:21
  • 2
    The sinc function is in fact defined to be 1 at 0, since that's its limiting value – 小太郎 Jun 01 '16 at 15:47
  • Sync is not for discrete fourier but continuous fourier iirc – Luis Masuelli Jun 01 '16 at 17:01
  • @HagenvonEitzen the currently most upvoted answer has an exponential function of a power function inside a cosine. That's in no way more elementary than $\sin(\pi x)/(\pi x)$. – DanielSank Jun 02 '16 at 06:58
  • This wonderfully clean solution could be presented better. It not only works for all integers but also is clearly both elementary and well defined when seen as a power series. Why not tone down the easily misinterpreted first sentence and add the following? $~\require{begingroup}\begingroup\def\T#1#2{\frac{(\pi n)^#1}{#2!}} 1{-}{\sin \pi n \over \pi n} = \T23 - \T45 + \T67 + \cdots \endgroup$ – humn Jun 06 '16 at 00:05
  • @DanielSank There is no more or less elementary, there is only elementary or not elementary. That a f unction expression is complicated does not mean it is not elementary. – Hagen von Eitzen Jun 06 '16 at 13:26
  • @HagenvonEitzen Quite true, and the function in this answer fits the definition of elementary functions. – DanielSank Jun 06 '16 at 13:45
  • @DanielSank But strictly speaking, $\frac{\sin x}x$ is only elementary as a function defined on $\Bbb C\setminus{0}$. Or we accept that removing removable discontinuities is allowed. Admittedly, the term "elementary" seem to lack an absolute definition (for example, Wolfram Research accepts the Lambert $W$ function as elementary ...) – Hagen von Eitzen Jun 06 '16 at 16:35
2

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

Mr Pie
  • 6,682
  • 1
  • 25
  • 88
1

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

Owen
  • 1,479
  • 13
  • 17
1

$\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.

Mr Pie
  • 6,682
  • 1
  • 25
  • 88
Andrew
  • 21
  • 1