Relevant definitions:
If $\tilde a$ is an approximation of $a$, then the absolute error of $a$ is
$$ |\tilde a – a| $$
and the relative error of $a$ is
$$ \frac{| \tilde a – a|}{a} .$$
Statement of the Problem:
Consider the function $f(x) = \sqrt{x+1} – 1$. Assume that we have a good implementation of square root, so that if $y = \sqrt{x}$, then the relative error in $\sqrt{x}$ is no bigger than the relative error in $x$ or $y$. That is, $\sqrt{x}$ can be computed as accurately as possible, given the scheme we are using for representing numbers on the computer.
Using double precision, roughly how accurately can a computer calculate $f(1)$? Give the absolute and relative error.
Where I Am:
I'm not sure what is being asked of me here. We have that using double precision numbers is roughly equivalent to working with $16$ significant digits in base $10$. Now, computing $f(1)$ to $16$ significant digits is
$$ f(1) = \sqrt{1+1} – 1 = \sqrt{2} – 1 \approx 0.414213562373095. $$
So, am I just being asked to compute
$$ |\tilde a – a| = |0.414213562373095 – (\sqrt{2} – 1) | $$
for the absolute error, and
$$ \frac{|\tilde a – a|}{a} = \frac{|0.414213562373095 – (\sqrt{2} – 1) |}{\sqrt{2} – 1} $$
for the relative error?
If so, any method of computing it would involve, well, a computer that itself is likely only accurate enough to compute $f(1)$ to $16$ significant digits, so it seems somewhat pointless. Otherwise, just presenting the above results as a solution seems incomplete (and rather pointless in itself).
Perhaps someone more familiar with numerical analysis could help me out here.
Best Answer
The point is that you computed $\sqrt 2$ to $16$ decimal digits, so the relative error is about $10^{-16}$. When you subtracted $1$ the difference has only $15$ decimal digits, so the relative error is about $10^{-15}$. This is not much of a loss in this case, but if you were to subtract an exact $1.41421$ from $\sqrt 2$ you would lose six digits and the relative error would increase by a factor of about a million. Yes, you are being asked to compute just what you say. I suspect that there is another exercise coming with much worse cancellation. You will then be shown the advantage of removing the cancellation analytically.