Larry Crane
GRAPHIC_ARTS
GRAPHIC_ARTS_194_WORKSHEET
{\displaystyle {\begin{aligned}{\tilde {x}}-{\tilde {y}}&=x(1+\delta _{x})-y(1+\delta
_{y})=x-y+x\delta _{x}-y\delta _{y}\\&=x-y+(x-y){\frac {x\delta _{x}-y\delta _{y}}{x-y}}\\
&=(x-y){\biggr (}1+{\frac {x\delta _{x}-y\delta _{y}}{x-y}}{\biggr )}.\end{aligned}}}
Thus, the relative error of the exact difference
−
y
{\displaystyle {\tilde {x}}-{\tilde {y}}}
of the approximations from the difference
{\displaystyle x-y}
of the true values is
|
−
y
.{\displaystyle \left|{\frac {x\delta _{x}-y\delta _{y}}{x-y}}\right|.}which can be
arbitrarily large if the true values
{\displaystyle x}
and
{\displaystyle y}
are close.== In numerical algorithms ==
Subtracting nearby numbers in floating-point arithmetic does not always cause catastrophic
cancellation, or even any error—by the Sterbenz lemma, if the numbers are close enough
the floating-point difference is exact.But cancellation may amplify errors in the inputs that
arose from rounding in other floating-point arithmetic.=== Example: Difference of squares
===
Given numbers
{\displaystyle x}
and
{\displaystyle y}
, the naive attempt to compute the mathematical function
x
{\displaystyle x^{2}-y^{2}}
by the floating-point arithmetic
fl
fl
fl
2
)
{\displaystyle \operatorname {fl} (\operatorname {fl} (x^{2})-\operatorname {fl}
(y^{2}))}
is subject to catastrophic cancellation when
{\displaystyle x}
and
{\displaystyle y}
are close in magnitude, because the subtraction can expose the rounding errors in the
squaring.The alternative factoring
{\displaystyle (x+y)(x-y)}
evaluated by the floating-point arithmetic
fl
fl
fl
{\displaystyle \operatorname {fl} (\operatorname {fl} (x+y)\cdot \operatorname {fl} (x-
y))}
,
avoids catastrophic cancellation because it avoids introducing rounding error leading into
the subtraction.For example, if
29
1.0000000018626451
{\displaystyle x=1+2^{-29}\approx 1.0000000018626451}
and
30
1.0000000009313226
{\displaystyle y=1+2^{-30}\approx 1.0000000009313226}
then the true value of the difference
x
{\displaystyle x^{2}-y^{2}}
is
2
29
30
−
31
1.8626451518330422
10
{\displaystyle 2^{-29}\cdot (1+2^{-30}+2^{-31})\approx 1.8626451518330422\times
10^{-9}}
.In IEEE 754 binary64 arithmetic, evaluating the alternative factoring
(
x
{\displaystyle (x+y)(x-y)}
gives the correct result exactly (with no rounding), but evaluating the naive expression
2
−
{\displaystyle x^{2}-y^{2}}
gives the floating-point number
29
=
1.8626451
4923095703125
10
{\displaystyle 2^{-29}=1.8626451{\underline {4923095703125}}\times 10^{-9}}
of which less than half the digits are correct and the other (underlined) digits reflect the
missing terms
2
59
60
{\displaystyle 2^{-59}+2^{-60}}
, lost due to rounding when calculating the intermediate squared values.=== Example:
Complex arcsine ===
When computing the complex arcsine function, one may be tempted to use the logarithmic
formula directly:
arcsin
log
2
−
.{\displaystyle \arcsin(z)=i\log {\bigl (}{\sqrt {1-z^{2}}}-iz{\bigr )}.}However, suppose
{\displaystyle z=iy}
for
y
{\displaystyle y\ll 0}
.Then
2
≈
{\displaystyle {\sqrt {1-z^{2}}}\approx -y}
and
{\displaystyle iz=-y}
; call the difference between them
ε
{\displaystyle \varepsilon }
—a very small difference, nearly zero.