0
$\begingroup$

I was looking for a simple function that converts an integer in the following way:

If x < 0, f(x) = -1  If x = 0, f(x) = 0  If x > 0, f(x) = 1 

Is there a simple function that does this?

Edit: Sorry for the confusion of the word "simple" Perhaps I should have said a function that does not involve 'if logic' (bear with me, i'm not a mathmagician) but is within reason to replace the existing 'if logic' because it is not a large formula.

  • 0
    I will update my question to define simple.2012-10-18

5 Answers 5

0

You can use the Heaviside step function, in terms of which your $f(x)=2H(x)-1$ (with the convention, sometimes but not always used, that $H(0)=\frac 12$) but it is not really different from what you wrote.

  • 0
    The caption of the g$r$aph you mention reads *The Heaviside step function*, **using the half-ma$x$imum convention**, and the main text uses the, at least as common, convention that H(0)=1. Omitting these details from your answer is misleading (and I find rather odd, I must say, the dismissive tone of your last comment... are we trying to reach exact, helpful, non ambiguous answers or what?).2012-10-18
5

This is just a curiosity since it involves taking a limit, but how about \begin{equation} f(x)=\lim_{t \to \infty} \frac{2}{\pi} \arctan(tx). \end{equation} It does the right things, giving for example $f(0)=0$ as the limiting value of the constant $\arctan(t0)=0$, and working at nonzero $x$ by using the positive and negative asymptotes of $\arctan(tx)$, and dividing by the absolute value $\pi/2$ of the limit.

4

Maybe, $f(x):=\frac{|x|}{x}$ and $f(x)=0$ for $x=0$.

4

I wouldn't say that there's a simpler function other than what you've already posted, but it could be useful to know that this function is also referred to as the sign or signum function, written $sgn(x)$.

  • 0
    Thanks much for the sgn(x), not to find out if m$y$ lan$g$uage supports that out of the bo$x$ ;)2012-10-18
1

Slightly simpler: For $x=0$, set $f(x)=x$ ;otherwise set $f(x)=\dfrac{|x|}x$.