1

Let $f(x) = \sqrt{1+x} - \sqrt{1-x}$ where $\vert x \vert \le 1$
Would this mean that if $\vert x \vert \lt \epsilon$ where $\epsilon$ is the machine epsilon we would get $f(x) = 0?$ which would mean a loss of significant digits?

I'm thinking of using the binomial expansions of $(1+x)^\frac{1}{2}$ and $(1-x)^\frac{1}{2}$ and then taking the difference which would leave just the terms swith odd powers.

Is there another way to rewrite the function (besides the binomial expansions) to avoid this problem of losing significant digits?

user137481
  • 2,605

1 Answers1

2

The usual trick with radicals is to multiply and divide by the conjugate expression: $$\begin{align}f(x)&=\frac{(\sqrt{1+x}-\sqrt{1-x})(\sqrt{1+x}+\sqrt{1-x})}{\sqrt{1+x}+\sqrt{1-x}}\\& =\frac{(1+x)-(1-x)}{\sqrt{1+x}+\sqrt{1-x}}\\&=\frac{2x}{\sqrt{1+x}+\sqrt{1-x}}\end{align}$$ which avoids cancellation (and even shows that for $x\approx 0$, we have $f(x)\approx x$).