---
tag: 49MX22EDS7
kind: definition
name: Catastrophic cancellation
msc: [65G50]
defines: TJPNYW7J8E
uses: [CPN6SD3BTV, AB3S6MHJ8X]
sources:
  - url: https://en.wikipedia.org/wiki/Catastrophic_cancellation
---

## Definition

Let $x, y$ be real numbers with $x \ne y$, and let $\tilde x = x(1 + \delta_1)$ and $\tilde y = y(1 + \delta_2)$ be approximations of them with relative errors $\delta_1, \delta_2$, for example [[round-off errors|CPN6SD3BTV]].
Then $\tilde x - \tilde y = (x - y)(1 + \delta)$ with
$$\delta = \frac{x \delta_1 - y \delta_2}{x - y}, \qquad \abs{\delta} \le \frac{\abs{x} + \abs{y}}{\abs{x - y}} \max(\abs{\delta_1}, \abs{\delta_2}).$$
*Catastrophic cancellation* is the case $\abs{x - y} \ll \abs{x} + \abs{y}$.
Then the relative error $\delta$ of the computed difference can be much larger than the relative errors of the inputs.

## Remarks

Example: $x = 1.2341$, $y = 1.2259$ rounded to three significant digits give $\tilde x = \tilde y = 1.23$, so $\tilde x - \tilde y = 0$ while $x - y = 0.0082$; the relative error is $\abs{\delta} = 1$, although $\abs{\delta_1}, \abs{\delta_2} < 0.004$.
Here the factor $(\abs{x} + \abs{y})/\abs{x - y}$ is about $300$.
Non-example: for $x = 1.2341$ and $y = -1.2259$ the factor is $1$, so the relative error of $\tilde x - \tilde y$ is at most the larger input error; nothing cancels.
The factor $(\abs{x} + \abs{y})/\abs{x - y}$ is the relative [[condition number|AB3S6MHJ8X]] of subtraction.
By the Sterbenz lemma, if $x$ and $y$ are floating-point numbers with $y/2 \le x \le 2y$, then $x - y$ is a floating-point number, so the subtraction itself adds no error.
