3

I'm trying to figure out how to avoid catastrophic cancellation for the following expression $$\sqrt{1+x} - 1$$ for $x$ being a number very close to $0$.

Of course, the answer would come to $0$ unless the expression is changed around.

Any help is appreciated! Thanks!

Blue
  • 83,939

3 Answers3

12

You could use $$\sqrt{1+x}-1=\frac{x}{\sqrt{1+x}+1}$$

6

If you want accurate results without computing any square root, you could use $[n,n]$ Padé approximants.

These could be $$\sqrt{1+x}-1\sim \frac{2 x}{x+4}$$ $$\sqrt{1+x}-1\sim \frac{4 x (x+2)}{x (x+12)+16}$$

  • 1
    I'd like to point out that these equivalences are with the limit as $x\to0$, not $x\to\infty$ as you might usually expect from $\sim$. – Jam Jan 19 '20 at 15:53
  • @Jam. I totally agree with you. In the question, it is specified "for $x$ being a number very close to $0$". – Claude Leibovici Jan 19 '20 at 16:06
5

If $x$ is seriously small, e.g. $\ x < 10^{-14}$, and you don't care too much about terms of order $O(10^{-28})$ then why not use:

$$\sqrt{1+x}\approx1+\frac{x}{2}$$

Adam Rubinson
  • 24,300