{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Definition\n\nLet $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]].\nThen $\\tilde x - \\tilde y = (x - y)(1 + \\delta)$ with\n$$\\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}).$$\n*Catastrophic cancellation* is the case $\\abs{x - y} \\ll \\abs{x} + \\abs{y}$.\nThen the relative error $\\delta$ of the computed difference can be much larger than the relative errors of the inputs.\n\n## Remarks\n\nExample: $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} \u003c 0.004$.\nHere the factor $(\\abs{x} + \\abs{y})/\\abs{x - y}$ is about $300$.\nNon-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.\nThe factor $(\\abs{x} + \\abs{y})/\\abs{x - y}$ is the relative [[condition number|AB3S6MHJ8X]] of subtraction.\nBy 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.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "defines": "TJPNYW7J8E",
    "kind": "definition",
    "msc": [
      "65G50"
    ],
    "name": "Catastrophic cancellation",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Catastrophic_cancellation"
      }
    ],
    "tag": "49MX22EDS7",
    "uses": [
      "CPN6SD3BTV",
      "AB3S6MHJ8X"
    ]
  },
  "kind": "definition",
  "link": "https://tamnd.github.io/math2/node/49MX22EDS7/",
  "links": [
    {
      "field": "defines",
      "target": "TJPNYW7J8E"
    },
    {
      "field": "uses",
      "target": "CPN6SD3BTV"
    },
    {
      "field": "uses",
      "target": "AB3S6MHJ8X"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/49MX22EDS7.md",
  "msc": [
    "65G50"
  ],
  "name": "Catastrophic cancellation",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/49M/49MX22EDS7.md",
  "status": null,
  "tag": "49MX22EDS7",
  "uri": "m2://49MX22EDS7",
  "url": "https://tamnd.github.io/math2/wiki/catastrophic-cancellation-definition/",
  "writing": {
    "tag": "49MX22EDS7",
    "kind": "definition",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      },
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
