Suppose we are working with a machine that does arithmetical calculations with a relative accuracy of $\xi, |\xi| \leq \xi '$. We want to calculate $a^2 - b^2$ in the following two ways; $(A);$ $a^2 - b^2 = (a - b)(a+b)$ and $(B)$; $a^2 - b^2 = a \times a - b \times b$. Suppose $a$ and $b$ are machine numbers. Show that the relative error of the result using method $A$ is at most $3\xi'$ and $\frac{1 + (a^2 + b^2)}{|a^2 - b^2|}\xi'$ using method $B$.

The first part (method $(A)$) is not so difficult but I am making a mistake in the second part. Let's start by calculating $a \times a$. This should be equal to $a^2(1+\xi) = a^2 + a^2\xi$. Similarly, $b \times b = b^2 + b^2\xi$. Substracting these two terms gives $(a^2 + a^2\xi - b^2 + b^2\xi)(1+\xi)$ which is equal to $a^2 + a^2\xi - b^2 - b^2\xi + a^2\xi + a^2\xi^2 - b^2\xi - b^2\xi^2$. If we ignore the terms involving $\xi^2$ then we get $a^2 - b^2 + 2\xi(a^2 - b^2)$ and so the relative error is at most $2\xi'$. Obviously this is not even close to the answer I am supposed to be getting but I am not sure where I went wrong.

For the second part of the question, we assume that $a$ and $b$ are not machine numbers. Show that the relative errors are given by $\frac{3 + 2(a^2 + b^2)}{|a^2 - b^2|}\xi$ and $\frac{1 + 3(a^2 + b^2)}{|a^2 - b^2|}$ respectively. I am not really sure what happens when $a$ and $b$ are not machine numbers, besides the fact that we have some sort of extra approximation error that we need to calculate, however I can't find any info on how to do this.

  • $\begingroup$ I got the following relative errors for method A, B with $a$ and $b$ machine numbers and method A and B for $a$ and $b$ no machine numbers. But maybe I did some mistakes. $$3 \xi$$ $$\left({{b^2+a^2}\over{\left| b^2-a^2\right| }}+1\right)\xi$$ $$\left({{\left| b\right| +\left| a\right| }\over{\left| \left| b\right| - \left| a\right| \right| }}+4\right)\xi$$ $$\left({{3\,\left(b^2+a^2\right)}\over{\left| b^2-a^2\right| }}+1\right)\xi$$ $\endgroup$ – miracle173 Jan 27 '14 at 2:06

You have to use different $\xi$ with absolute value bounded by the same $\xi'$. I use the symbols $\oplus$ and $\odot$ for the machine operations. We get $$(a \odot a )\ominus (b \odot b) = \\ (a^2(1+\xi_1) - b^2(1+\xi_2)) (1+\xi_3) = \\ a^2-b^2+a^2(\xi_1+\xi_3+\xi_1\xi_3)-b^2(\xi_1+\xi_2+\xi_1\xi_2) $$ so the relative error is $$\left|\frac{a^2(\xi_1+\xi_3+\xi_1\xi_3)-b^2(\xi_2+\xi_3+\xi_2\xi_3)}{a^2-b^2}\right|\le \\ \frac{a^2(|\xi_1|+|\xi_1||\xi_3|)+b^2(|\xi_2|+|\xi_2||\xi_3|)+|a^2-b^2||\xi_3|}{|a^2-b^2|} \le\\ \frac{a^2(\xi'+\xi'^2)+b^2(\xi'+\xi'^2)+|a^2-b^2|\xi'}{|a^2-b^2|} \approx \\ \left(\frac{(a^2+b^2)}{|a^2-b^2|}+1\right)\xi' $$ if one ignores the quadratic terms.

If $a$ and $b$ are not machine numbers you have rounding errors. You have to calculate $$(\Box a \ominus \Box b)\otimes (\Box a \oplus \Box b)$$ or $$(\Box a \odot \Box a )\ominus (\Box b \odot \Box b) $$ where the function $\Box$ is defined as $\Box a=a(1+\xi_a)$ and $\Box b= b(1+\xi_b)$

  • $\begingroup$ This is very clear. Thanks! :) $\endgroup$ – user119470 Jan 26 '14 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.