Catastrophic cancellation 2026-10-14
Catastrophic cancellation occurs when subtraction of nearly equal approximations removes their matching leading digits and exposes earlier roundoff error. The subtraction can itself be exact on the stored operands: the information may already have been lost while obtaining them. Goldberg distinguishes this from cancellation of accurately known quantities, which can be harmless.[ref]
For , consider the single real-valued function
The rationalization of a square-root difference proves equality in exact arithmetic. The two evaluations use the same input , but the direct version first forms a value near one and then subtracts one. The rearranged version keeps the small input in its numerator and divides by a denominator near two.
Figure 1.
Direct and rationalized evaluation of a small square-root difference against a high-precision reference for the same binary64 inputs
. Details.
For binary64 x = 1e-16, the rounded sum 1.0 + x is one, so sqrt(1.0 + x) - 1.0 is zero. The rationalized evaluation returns approximately . A 100-digit Decimal calculation using the exact stored input gives relative errors of one and about respectively. At x = 1e-12, the direct result is about , with relative error ; the rearranged result is about , with relative error .
The plot uses Decimal.from_float(x) to preserve the binary input exactly, computes at 100 decimal digits, and verifies the reference at 160 digits. Exact conversion of a stored binary value is documented by Python.[ref] Each error is , with the computed result converted exactly to Decimal before comparison. Hence the curves measure evaluation error for one common input, rather than a mixture of input conversion error and evaluation error. The plotted interval is far above the subnormal number range.
The original problem is well conditioned with respect to relative changes in . Using the derivative and rationalization of a square-root difference, its relative condition number is
It tends to one as tends to zero. The direct evaluation instead introduces the intermediate difference with ; an error of order unit roundoff in is large relative to . This is a failure of the chosen algorithm's accuracy despite a small condition number for the same real-valued function. The rationalized evaluation avoids that intermediate catastrophic cancellation, retaining relative accuracy near the unit roundoff scale throughout the plotted interval. Recognizing this structure can improve a calculation far more than merely printing extra digits.
For a standard normal random variable , its standard normal distribution function is
The change of variables and the symmetric distribution of the standard normal random variable give the second expression. For with , standardization of a normal random variable then gives
In particular, the intervals within one, two, and three standard deviations have calculated probabilities about , , and . These values depend on a normal distribution; they are not universal coverage guarantees for an arbitrary random variable. This is the direct connection between a Gaussian function area and the familiar central intervals.
For a small upper-tail probability, use the complementary error function directly:
Computing this as instead can lose the tail to catastrophic cancellation. The Gaussian tail bound gives another useful estimate without requiring an exact error function value.
Floating-point arithmetic Created 2026-10-14 Updated 2026-10-14
Floating-point arithmetic represents a real number by a sign, a fixed number of significant digits, and a scale. It trades exactness for a compact representation spanning many orders of magnitude. The picture shows the essential compromise: with the same precision, large numbers have wider gaps between representable neighbors. Thus accuracy is naturally relative to magnitude, rather than a fixed distance along the number line.
Figure 1.
Eight normalized four-bit binary values in each of three intervals, with gaps doubling from one eighth to one half
. Details.
In radix , an integer at least two, a nonzero normalized value has the positional notation
where the digits and exponent are integers. The parenthesized factor is the significand; counts all its significant digits, including the leading digit. Normalization means , so the same value has one such representation. The allowed exponents satisfy . Finite precision restricts the available digits, while the exponent bounds restrict the range. Zero needs a separate representation. This scales a digit string in positional notation by a power of its base.[ref]
For positive normalized values in , increasing the last digit by one gives the constant neighbor spacing
At the next scale, the spacing is multiplied by . In the binary numeral system with , the values in are ; those in are ; those in are . The respective gaps are , , and . Although absolute resolution deteriorates with magnitude, stays between and . This scale invariance is why floating-point arithmetic suits both microscopic and astronomical calculations.
The IEEE 754 binary64 format uses the binary numeral system with , including an implicit leading one for normalized values, and normal exponents . Its 64 stored binary digits comprise one sign digit, 11 exponent digits and 52 trailing significand digits. Subnormal numbers extend the range toward zero with a different leading-digit rule. In rounding to nearest, an operation returns the representable value closest to its exact result; a tie goes to the value whose last significant binary digit is even. Machine epsilon describes the gap just above one, whereas unit roundoff bounds a single relative rounding error in the normal range. These format and rounding rules are presented in MIT's floating-point lecture.[ref]
Even an ordinary terminating decimal can require rounding in the binary numeral system. The rational number has the repeating positional notation . Every finite binary fraction has a reduced denominator that is a power of two, so the factor five in prevents an exact finite binary representation. In binary64, the exact stored values of three decimal literals and their computed sum are
The exact sum of the first two stored rational numbers is , halfway between two binary64 values. The even-last-digit tie rule rounds it upward. The printed result is 0.30000000000000004, one step above stored 0.3, so 0.1 + 0.2 == 0.3 is false. Both conversion of the inputs and rounding of the addition matter here.
To reproduce the table on a Python installation using binary64, inspect exact fractions rather than only their printed decimal representations:
import sys
assert (sys.float_info.radix, sys.float_info.mant_dig) == (2, 53)
for value in (0.1, 0.2, 0.3, 0.1 + 0.2):
    print(repr(value), value.as_integer_ratio())
print(0.1 + 0.2 == 0.3)  # False
Python's as_integer_ratio() returns a pair of integers whose quotient equals the stored finite value exactly.[ref] Exact rational numbers are also useful for checking floating-point arithmetic: a short decimal printout can hide the approximation being made.
Historically, David Goldberg's March 1991 ACM Computing Surveys paper explained representation, rounding and catastrophic cancellation together with the IEEE standard's design choices. Oracle provides an authorized edited reprint. Its enduring lesson is practical: use the spacing to understand roundoff error, and inspect intermediate values when mathematically equivalent algorithms behave differently.[ref]
For a nonzero real vector , choose with and put . When , the Householder reflection
satisfies : every component except the first becomes zero. Here is the first Cartesian basis vector. The calculation is short:
If , the vector is already at the selected target, so the identity matrix suffices.
In floating-point arithmetic, a customary choice is
Then , avoiding subtraction of nearly equal positive quantities in the first component. Either sign can be valid in exact arithmetic; the numerical choice protects the construction from catastrophic cancellation. [ref]
For , this choice gives and . Dividing by its Euclidean norm gives , exactly the normal in the geometric example.
Singular perturbation Created 2026-09-24 Updated 2026-10-14
A singular perturbation is a parameter-dependent problem whose limiting problem changes qualitatively as the parameter tends to zero. In an ordinary differential equation, a small coefficient of the highest derivative can reduce the order of the limiting differential equation, preventing it from satisfying all the original boundary conditions. Different length or time scales often require different asymptotic expansions.[ref]
Consider the boundary value problem
This second-order differential equation is exactly solvable. Setting gives the first-order linear differential equation , so . One integration and the two boundary conditions give
Both boundary conditions hold for every positive . For numerical evaluation, write the same ratio as , where evaluates the exponential function minus one without catastrophic cancellation near . Keep the denominator for finite : at it is approximately , rather than exactly one.
Setting gives . The outer solution selected by the right boundary condition is therefore , which fails the left boundary condition. The exact exponential function shows how that mismatch is repaired: the solution rises from zero to almost one within a boundary layer of width , using Big O notation. For each fixed , , while always. This pointwise convergence fails to be uniform convergence to the outer solution on , since for every .
Figure 1.
Exact solutions with a shrinking left boundary layer
. The exact normalized profiles at , , and satisfy both boundary conditions. The dashed outer solution misses the left boundary condition. Colored dots mark , where most of the initial rise has already occurred. Details.
The coefficient is small, but its product with the second derivative need not be small. Direct differentiation gives
At with fixed , these derivatives grow as and respectively as . Consequently and have exactly equal magnitudes and opposite signs. Even away from the boundary layer, their magnitudes remain equal in this example; both become exponentially small at each fixed positive . The outer expansion neglects an exponentially small transient there, rather than establishing that one derivative term is smaller than the other everywhere.
To predict the width without knowing the exact solution, suppose an order-one change occurs over distance . The derivative scales are and . The dominant balance gives . The resulting inner variable makes the boundary layer visible at a fixed scale. This is the useful feature of singular perturbation: an apparently disappearing term identifies the missing structure when one measures its derivatives on the appropriate scale.