3
$\begingroup$

What is a function to returns $-1$ if number is negative, $1$ if positive, and zero if number is equal to 0?

for example:

$$ f(-8) = -1 $$ $$ f(8) = 1 $$ $$ f(0) = 0 $$

for $$x < 0$$ maybe?

$$ f(x) = (-x-(-x-1))\cdot-1 $$

$\endgroup$
  • $\begingroup$ The Heaviside step function almost satisfies your requirements. $\endgroup$ – David Simmons May 19 '13 at 20:08
  • $\begingroup$ Not exactly. By using it, $$H(-3) = 0,H(3) = 1$$ $\endgroup$ – Assembly May 19 '13 at 21:19
  • 1
    $\begingroup$ The idea, I think, is to use $2H(x) - 1$. But it's a much better idea (IMO) to just say what you mean, like in Trevor's answer. $\endgroup$ – Ben Millwood May 19 '13 at 21:33
8
$\begingroup$

This function is the $\text{sgn}$ (sign) function. You can write it as $$\text{sgn}(x)=\begin{cases}\frac x{|x|} &x\neq 0\\ 0 & x=0\end{cases}$$

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Nice, and quick! $\;+ \;\ddot\smile$ $\endgroup$ – amWhy May 19 '13 at 20:10
  • $\begingroup$ Thanks very much. What do you think about my first solution too bad or acceptable to a begginer to math? I will to accept your question. $\endgroup$ – Assembly May 19 '13 at 20:16
  • 1
    $\begingroup$ I'm sorry but I still can't give my up vote because I'm < 15 reputation. $\endgroup$ – Assembly May 19 '13 at 20:17
  • 1
    $\begingroup$ It's a bit hard to understand your suggestion, because there is no $=$ symbol (you may want to use parenthesis for the $-1$ and \cdot for the multiplication). But the problem is that the function is not continuous, so you cannot represent it as a multiplication and addition like that, because that would be continuous. Note that it simplifies to $-(-x+(x+1))=-(x-x+1)=-1$, which is not the function you want. $\endgroup$ – Asaf Karagila May 19 '13 at 20:26
  • 1
    $\begingroup$ @AsafKaragila:If I increment my thanks-counter to you,an integer overflow may happens. Better say nothing! joke answer. Thank you again. $\endgroup$ – Assembly May 19 '13 at 21:04
11
$\begingroup$

As pointed out in the other answers, this function goes by various names. However, if your question is just "what is such a function?" then the answer is that it is the function you have defined. Note that

$$f(x) = \begin{cases} -1 & \text{if } x<0\\ 1 & \text{if } x>0\\ 0 & \text{if } x=0 \end{cases}$$

is a perfectly valid definition of a function on $\mathbb{R}$, because it uniquely specifies what $f(x)$ is for every real number $x$. Definitions by cases are just as good as any other kind of definition, and I think it is confusing to hide the distinction between the three cases (negative, positive, and zero) by some algebraic trick.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ I have a question. In the Asaf Karagila's answer,he show the function and an equation to how should x be computed. In your answer,you show also the result what value of x according to condition. How they are this called? function definition and declaration or something like this? $\endgroup$ – Assembly May 19 '13 at 20:43
  • 1
    $\begingroup$ @Assembly, whereas I presented a slightly more compact form (which lumped the non-zero cases together) that required a small computation, Trevor is using constant functions and simply defined by three cases rather than two cases like myself. This is "definition by cases", and as long the cases are non-overlapping the definition is fine. $\endgroup$ – Asaf Karagila May 19 '13 at 20:58
  • $\begingroup$ @AsafKaragila: Thanks again. $\endgroup$ – Assembly May 19 '13 at 21:02
  • 1
    $\begingroup$ (Aside: the cases should be complete as well as non-overlapping! That is to say, you should make sure you don't accidentally specify a value for any particular $x$ twice, and you should make sure you specify at least one value for each $x$.) $\endgroup$ – Ben Millwood May 19 '13 at 21:35
  • 1
    $\begingroup$ @TrevorWilson: Thanks very much $\endgroup$ – Assembly May 19 '13 at 21:39
3
$\begingroup$

Your function is exactly the signum function

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.