Finding function to return number sign

101 Views Asked by At

My question is two-folded.

Both parts pertain to the fact that I want to find an arithmetic function $f(x) $ that returns $-1$ or $1$ when $x < 0$ or $x > 0$. I don't really care about $f(0) $. But I want this function to calculate the sign of $x $ purely out of arithmetics and elementary functions.

I do not know if $|x|$ is an elementary function but I came up with $f(x) = \frac{x}{|x|} $. Now this works fine. Nonetheless, if I rewrite $|x| = \sqrt{x^2} $ and substitute back, I get $f(x) = \frac{x}{\sqrt{x^2}} = \sqrt{\frac{x^2}{x^2}}$ which obviously no longer works. Why on Earth does this not work?

Also, is there any other way, using only arithmetic operations, exponentiation (with rational exponents) and elementary functions, to get the function I wanted?

Please notice I am not interested in the obvious

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

As this is defined piecewise.

Thanks in advance.

2

There are 2 best solutions below

2
On BEST ANSWER

Note that:

  • $x>0 \implies x+|x|>0$
  • $x\leq0 \implies x+|x|=0$

Therefore:

  • $x>0\implies\lceil{x+|x|}\rceil\geq1$ and integer
  • $x\leq0\implies\lceil{x+|x|}\rceil=0$

Therefore:

  • $x>0\implies2^{\lceil{x+|x|}\rceil}\geq2$ and even
  • $x\leq0\implies2^{\lceil{x+|x|}\rceil}=1$

Therefore:

  • $x>0\implies\cos(\pi\cdot2^{\lceil{x+|x|}\rceil})=1$
  • $x\leq0\implies\cos(\pi\cdot2^{\lceil{x+|x|}\rceil})=-1$

Therefore you can use $f(x)=\cos(\pi\cdot2^{\lceil{x+|x|}\rceil})$

1
On

You mentioned that $\sqrt{x^2}=|x|$, which is correct.

Then $x\neq\sqrt{x^2}$! So there is something not right when you write $$f(x)=\frac{x}{\sqrt{x^2}}=\sqrt{\frac{x^2}{x^2}}$$