In
floating-point arithmetic
In computing, floating-point arithmetic (FP) is arithmetic on subsets of real numbers formed by a ''significand'' (a Sign (mathematics), signed sequence of a fixed number of digits in some Radix, base) multiplied by an integer power of that ba ...
, the Sterbenz lemma or Sterbenz's lemma
is a theorem giving conditions under which floating-point differences are computed exactly.
It is named after Pat H. Sterbenz, who published a variant of it in 1974.
The Sterbenz lemma applies to
IEEE 754
The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point arithmetic originally established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard #Design rationale, add ...
, the most widely used floating-point number system in computers.
Proof
Let
be the radix of the floating-point system and
the precision.
Consider several easy cases first:
* If
is zero then
, and if
is zero then
, so the result is trivial because floating-point negation is always exact.
* If
the result is zero and thus exact.
* If
then we must also have
so
. In this case,
, so the result follows from the theorem restricted to
.
* If
, we can write
with
, so the result follows from the theorem restricted to
.
For the rest of the proof, assume
without loss of generality.
Write
in terms of their positive integral significands
and minimal exponents
:
Note that
and
may be subnormal—we do not assume
.
The subtraction gives:
Let
.
Since
we have:
*
, so
, from which we can conclude
is an integer and therefore so is
; and
*
, so
.
Further, since
, we have
, so that
which implies that
Hence
so
is a floating-point number.
Note: Even if
and
are normal, ''i.e.'',
, we cannot prove that
and therefore cannot prove that
is also normal.
For example, the difference of the two smallest positive normal floating-point numbers
and
is
which is necessarily subnormal.
In floating-point number systems without
subnormal numbers, such as CPUs in nonstandard flush-to-zero mode instead of the standard gradual underflow, the Sterbenz lemma does not apply.
Relation to catastrophic cancellation
The Sterbenz lemma may be contrasted with the phenomenon of
catastrophic cancellation
In numerical analysis, catastrophic cancellation is the phenomenon that subtracting good approximations to two nearby numbers may yield a very bad approximation to the difference of the original numbers.
For example, if there are two studs, one L ...
:
* The Sterbenz lemma asserts that if
and
are sufficiently close floating-point numbers then their difference
is computed exactly by floating-point arithmetic
, with no rounding needed.
* The phenomenon of catastrophic cancellation is that if
and
are approximations to true numbers
and
—whether the approximations arise from prior rounding error or from series truncation or from physical uncertainty or anything else—the error of the difference
from the desired difference
is inversely proportional to
. Thus, the closer
and
are, the worse
may be as an approximation to
, even if the subtraction itself is computed exactly.
In other words, the Sterbenz lemma shows that subtracting nearby floating-point numbers is exact, but if the numbers one has are approximations then even their exact difference may be far off from the difference of numbers one wanted to subtract.
Use in numerical analysis
The Sterbenz lemma is instrumental in proving theorems on error bounds in numerical analysis of floating-point algorithms.
For example,
Heron's formula
In geometry, Heron's formula (or Hero's formula) gives the area of a triangle in terms of the three side lengths Letting be the semiperimeter of the triangle, s = \tfrac12(a + b + c), the area is
A = \sqrt.
It is named after first-century ...
for the area of triangle with side lengths
,
, and
, where
is the semi-perimeter, may give poor accuracy for long narrow triangles if evaluated directly in floating-point arithmetic.
However, for
, the alternative formula
can be proven, with the help of the Sterbenz lemma, to have low
forward error for all inputs.
References
{{reflist
Computer arithmetic
Floating point
Numerical analysis