Given $n$, what function returns $0$ for $n < 1$, but $1$ for all else?

227 Views Asked by At

I'm looking for a simple operation that returns $0$ if $n$ is less than $1$, but $1$ for anything greater than or equal to $1$. What does the trick?

5

There are 5 best solutions below

0
On BEST ANSWER

If you are okay including the $\operatorname{Floor}$ function then let

$$f(n)=\left\lfloor4\dfrac{\tan^{-1}(n)+\pi}{5\pi}\right\rfloor$$

Explanation: $-\dfrac{\pi}{2}< \tan^{-1}(n)<\dfrac{\pi}{2}$ for all $n$. We also notice that $\tan^{-1}$ is increasing, and $\tan^{-1}(1)=\dfrac{\pi}{4}$.

If $n\ge1$ then $1 \le 4\dfrac{\tan^{-1}(n)+\pi}{5\pi} \le \dfrac{6}{5}<2$, so $f(n)=1$.

If $n<1$ then $-\dfrac{\pi}{2}<\tan^{-1}(n) <\dfrac{\pi}{4}$ giving $\dfrac{2}{5} < 4\dfrac{\tan^{-1}(n)+\pi}{5\pi} < 1$. So $f(n)=0$.

2
On

$f(n) = \begin{cases} 0 \text{ if $n$ < 1} \\ 1 \text{ if $n \geq 1$} \end{cases}$ is probably the function you want.

0
On

$f(n) = \frac{1}{2}\left(\frac{|n - 1|}{n-1}+ 1\right)$

Sadly undefined at $n=1$, but if you only care about integer $n$, change the instances of "$n-1$" to "$n - \frac{1}{2}$".

0
On

This is a modification of the example by DavidP:

$$f(n) =\frac{|3^n-2|+3^n-2}{2(3^n-2)}$$

0
On

BRICfan's answer is perfectly correct, and is the standard way of defining your function. As others have pointed out, you can express this as an equation using things like the floor function, but these are really quite artificial and useless for practical purposes. Equations are just one way of expressing functions. In this case, a pretty useless way of expressing them.

You may be interested to know that there is a named function for (almost exactly) what you want, the Heaviside function (see http://en.wikipedia.org/wiki/Heaviside_step_function ). Your function is H(x-1) where H is the Heaviside function. It is defined in the same notation as BRICfan used, and is really just a shorthand for his answer. There is no simpler or more useful answer than BRICfan gave, all I am doing is providing a commonly accepted name for his answer.