2

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.

RGS
  • 9,719
  • 2
    Hint: you assumed that $x = \sqrt{x^2}$. That's only valid if $x \ge 0$. As for the function itself, it's commonly known as the sign function. – dxiv Nov 15 '16 at 08:44
  • 2
    $\frac{x}{\sqrt{x^2}}\neq \sqrt{\frac{x^2}{x^2}}$. In general $\sqrt{ab}\neq\sqrt{a}\cdot \sqrt{b}$. These are only guaranteed true when they are all positive numbers. – JMoravitz Nov 15 '16 at 08:44
  • @dxiv but that function, with such an obvious definition, is branched which is something I am looking to avoid – RGS Nov 15 '16 at 08:48
  • If by "branched" you mean defined piecewise, then that's hard to avoid. Your $x / |x|$ comes close, but you'll need a separate case to define it at $0$. – dxiv Nov 15 '16 at 08:51
  • 1
    You can also try $$f(x)=\lim_{n\to\infty}\frac 2{\pi}\arctan{n x}$$ – polfosol Nov 15 '16 at 10:12

2 Answers2

3

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

barak manos
  • 43,109
1

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

yoyostein
  • 19,608