# How can I accurately compute $\sqrt{x + 2} −\sqrt{x}$ when $x$ is large?

How can the values of the function $f(x) = \sqrt{x + 2} −\sqrt{x}$ be computed accurately when $x$ is large?

I have tried using Matllab. I am not able to understand when $x$ will be large.

• Do you mean $\;\; f(x) \: = \: \sqrt{x+2}-\sqrt{x} \;\;$? $\;\;\;\;\;$ – user57159 Sep 1 '14 at 22:08
• Well, $\sqrt{x+2}-\sqrt{x}\approx 2f^\prime(x)$, though this is a pretty useless statement. – user122283 Sep 1 '14 at 22:10
• For more such examples, see Loss of significance error. – user147263 Sep 1 '14 at 23:58

## 4 Answers

If directly computing $\sqrt{x+2}-\sqrt{x}$ is giving you problems, you can instead try using

$\sqrt{x+2}-\sqrt{x} = \dfrac{(\sqrt{x+2}-\sqrt{x})(\sqrt{x+2}+\sqrt{x})}{\sqrt{x+2}+\sqrt{x}} = \dfrac{(x+2)-x}{\sqrt{x+2}+\sqrt{x}} = \dfrac{2}{\sqrt{x+2}+\sqrt{x}}$.

For large $x$, this is approximately $\dfrac{2}{\sqrt{x}+\sqrt{x}} = \dfrac{1}{\sqrt{x}}$.

EDIT: I just tried this for $x = 10^{18}$ using MATLAB R2013b.

For $\sqrt{x+2}-\sqrt{x}$ it gives $0$, but for $\dfrac{2}{\sqrt{x+2}+\sqrt{x}}$, it gives $1.0000 \times 10^{-9}$.

• I think the three radicals on the "approximately" line should contain $\:x\hspace{-0.03 in}+\hspace{-0.04 in}1\:$ rather than $x$. $\hspace{1.23 in}$ – user57159 Sep 2 '14 at 22:17
• $\frac{1}{\sqrt{x}}$ is a decent approximation of $\frac{2}{\sqrt{x+2}+\sqrt{x}}$. But of course, $\frac{1}{\sqrt{x+1}}$ is better. – JimmyK4542 Sep 2 '14 at 22:22

Recall that when $t$ is small, $\sqrt{1+t}\approx 1 + t/2$. It follows that, for $x$ large and positive, $$f(x)= \sqrt{x}(\sqrt{1+2/x}-1)\approx 1/\sqrt{x},$$ in the sense that $f(x)\sqrt{x}\rightarrow 1$ as $x\rightarrow \infty$.

• I think you need to double check that, if you start with $$y = f(x + 2) - f(x)$$ and make the substitution $$f(x) = 1 + (x - 1)/2$$ then you get $$y=1$$, which is probably not what you intended. The main problem is using that for large values of $x$, you really can't ignore expansion terms of low degree. – DanielV Sep 2 '14 at 0:07
• @DanielV I am not sure what your point is, the approximation I give is just the first order Taylor expansion around $t=0$, which is completely precise in the sense stated. – Jonas Dahlbæk Sep 2 '14 at 6:11
• @user161825 : $\:$ You used the wrong expression for $\hspace{.03 in}f(x)$. $\;\;\;\;$ – user57159 Sep 2 '14 at 22:27
• @RickyDemer So I did, thank you. – Jonas Dahlbæk Sep 3 '14 at 6:17

In fact, an asymptotic expansion of $f(x) = \sqrt{x+a} - \sqrt{x}$ about $x = \infty$ is $$f(x) \approx \frac{a}{2} x^{-1/2} - \frac{a^2}{8} x^{-3/2} + \frac{a^3}{16} x^{-5/2} - \frac{5a^4}{128} x^{-7/2} + \frac{7a^5}{256} x^{-9/2} - \frac{21a^6}{1024} x^{-11/2} + \cdots.$$ We can calculate this via the generalized binomial theorem $$(a+x)^r = \sum_{k=0}^\infty \binom{r}{k} a^k x^{r-k},$$ for $r = 1/2$, so that in particular, \begin{align*} \binom{1/2}{k} &= \frac{(1/2)(1/2-1)\cdot \ldots \cdot(1/2-k+1)}{k!} \\ &= \frac{1(-1)(-3)\cdot \ldots \cdot(3-2k)}{2^k k!} \\ &= (-1)^{k-1} \frac{(2k-2)!}{2^{2k-1} k! (k-1)!} \\ &= \frac{(-1)^{k-1}}{2^{2k-1}k } \binom{2k-2}{k-1}, \quad k = 1, 2, \ldots,\end{align*} and $\binom{1/2}{0} = 1$.

This is a variant of heropup's answer; hopefully the useful technique it illustrates justifies the partial duplication.

We may factor $\sqrt{x+2} -\sqrt{x} = \sqrt{x}( \sqrt{1 + 2/x} - 1).$ Now if $x \to \infty,$ then $|2/x| < 1,$ so we can compute $\sqrt{1 + 2/x}$ via the binomial theorem, to get $$\sqrt{1+ 2/x} - 1 = \sum_{n = 1}^{\infty} {{1/2} \choose n } \dfrac{2^n}{x^n} = \sum_{n = 1}^{\infty} (-1)^{n-1}\dfrac{(2n-3)\cdot (2n - 5) \cdots 3 \cdot 1 }{n!} x^{-n},$$ so that $$\sqrt{x+2} - \sqrt{x} = \sum_{n = 1}^{\infty} (-1)^{n-1}\dfrac{(2n-3)\cdot (2n - 5) \cdots 3 \cdot 1 }{n!} x^{-\frac{2n-1}{2}}.$$

Of course this is the same series as in heropup's answer, derived in essentially the same way. But one thing we see, by applying the binomial theorem to $1 + 2/x,$ is that this series converges for $|2/x| < 1,$ i.e. for $x > 2,$ which might be helpful. (And of course one can use the usual theory of Taylor series to estimate the rate of convergence, if necessary.)

The general technique this illustrates is doing a division by the term that is going to infinity, so that instead one has a term which is going to zero.