# 灾难性抵消

**灾难性抵消**（catastrophic cancellation）是指两个相近的数相减时有效数字的丢失：即使每个数都是良好的近似，它们的差仍可能是真实差值的不良近似，因为高位数字相互抵消，剩下的数字携带的是输入的舍入误差。在数值分析中，这一现象被理解为近似值相减的固有属性，而非浮点等特定算术的缺陷；即使减法本身精确执行，它也可能发生。<sup>[1](https://graphsearch.epfl.ch/en/concept/19985542)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 两个相近数的良好近似相减，可能得到原数之差的很差近似；该效应是近似输入相减的固有属性，而非浮点运算特有。<sup>[1](https://graphsearch.epfl.ch/en/concept/19985542)</sup> |
| 误差界 | 若输入的相对误差为 δ₁ 和 δ₂，则差的相对误差以 max\{|δ₁|, |δ₂|\}·(|x|+|y|)/|x−y| 为界，当 x 趋近 y 时该界无界增长。<sup>[2](https://www.cmor-faculty.rice.edu/~caam553/repo/public_html/caam453.pdf)</sup> |
| 典型量级 | IEEE 单精度约携带 7 位十进制有效数字，双精度约 16 位；将大多数这些数位都一致的两个数相减，结果中相应的准确位数就所剩无几。<sup>[3](https://cs357.cs.illinois.edu/textbook/notes/rounding.html)</sup> |
| 良性情形 | 两个精确已知的 IEEE 浮点数相减，带保护位时相对误差不超过一个 ulp；结果是精确的。<sup>[4](https://math.nyu.edu/inmemoriam/donev/Teaching/NMI-Fall2010/Lecture1.handout.pdf)</sup> |
| 精确情形 | Sterbenz 引理：对浮点数 x, y ≥ 0 且 y/2 ≤ x ≤ 2y，减法 x − y 是精确的。<sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC8905452/)</sup> |
| 标准补救 | 通过代数改写消除减法，例如对小 z 将 1 − √(1−z) 计算为 z/(1+√(1−z))。<sup>[6](https://www.cs.cornell.edu/courses/cs4220/2026sp/lec/2026-02-02.html)</sup> |
| 术语 | 威廉·卡汉（William Kahan）于 1960 年首创该术语。<sup>[7](https://www.astesj.com/v06/i01/p57/)</sup> |

## 机制

浮点系统以固定数量的有效数字表示实数：IEEE 单精度约 7 位十进制数字，双精度约 16 位。<sup>[3](https://cs357.cs.illinois.edu/textbook/notes/rounding.html)</sup> 当两个量级相近的存储数相减时，高位有效数字相互抵消。结果中剩下的数字主要是输入中已有的舍入误差，因此结果的准确位数远少于任一操作数。<sup>[8](https://stat243.berkeley.edu/fall-2024/units/unit8-numbers.html)</sup>

该效应的大小可由误差界推出。若 \( \hat{x} = x(1+\delta_1) \) 和 \( \hat{y} = y(1+\delta_2) \) 是 x 和 y 的浮点近似，则计算所得的差的相对误差满足

\[
\frac{|\mathrm{fl}(\hat{x}-\hat{y})-(x-y)|}{|x-y|}
\le \max\{|\delta_1|,|\delta_2|\}\,\frac{|x|+|y|}{|x-y|}.
\]

当 x 与 y 接近时，因子 (|x|+|y|)/|x−y| 很大，因此即使每个输入的精度在几个 ulp 之内，相对误差也可能远超机器精度。<sup>[2](https://www.cmor-faculty.rice.edu/~caam553/repo/public_html/caam453.pdf)</sup> 同一因子也作为加法的条件数出现，即对 f(x, y) = x + y，\( \kappa(f(x,y)) = (|x|+|y|)/|x+y| \)；当 x + y = 0 且 x, y ≠ 0 时，加法是不适定的。<sup>[9](https://relate.cs.illinois.edu/course/cs450-s18/f/lectures/01-lecture.pdf)</sup>

一个计算实例具体展示了这种损失。在四位十进制算术中，计算 1.234667 与 1.23446 的差会将操作数存为 1.235 和 1.234，二者都是合理的近似。计算所得的差为 1 × 10<sup>−3</sup>，但真实差值为 2.07 × 10<sup>−4</sup>，这个值四位算术本可精确表示；计算结果完全不准。<sup>[10](https://www.sciencedirect.com/science/article/pii/B9780444642073000068)</sup> 在一个演示系统中，x = 2.25 舍入为 2.5，y = 2 是精确的，此时 x − y 的计算相对误差为 1，意味着答案中没有一位数字正确，而期望的误差应在机器 epsilon 量级。<sup>[2](https://www.cmor-faculty.rice.edu/~caam553/repo/public_html/caam453.pdf)</sup>

损失可以是彻底的。在 SIAM 教材的例子中，x = 3.141592653589793（π 的 16 位近似）与 y = 3.141592653585682（精确到 12 位）相差 4.111 × 10<sup>−12</sup>。以 IEEE 单精度格式存储时，两数舍入为同一值，因此所有位都抵消，计算所得的差恰好为零，精度完全丧失。<sup>[11](https://epubs.siam.org/doi/abs/10.1137/1.9780898718072.ch11)</sup>

## 良性抵消与灾难性抵消

并非所有相近数相减都有害。若两个操作数是精确已知的浮点数，带保护位的减法产生的相对误差不超过一个 ulp；这称为良性抵消，结果是精确的。<sup>[4](https://math.nyu.edu/inmemoriam/donev/Teaching/NMI-Fall2010/Lecture1.handout.pdf)</sup> Sterbenz 引理使这一点更精确：对满足 y/2 ≤ x ≤ 2y 的非负浮点数，减法 x − y 是精确的，因为差值本身可在该格式中表示。<sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC8905452/)</sup> 相比之下，灾难性抵消发生在操作数不精确时，此时相近数相减将已存在的误差放大为很大的相对误差。<sup>[4](https://math.nyu.edu/inmemoriam/donev/Teaching/NMI-Fall2010/Lecture1.handout.pdf)</sup>

康奈尔 CS 4220 的讲义将责任相应地归位：若 x 与 y 接近，减法本身不引入舍入误差，因为 fl(x̂ − ŷ) = x̂ − ŷ；问题在于 x̂ 和 ŷ 中已存在的近似误差。<sup>[6](https://www.cs.cornell.edu/courses/cs4220/2026sp/lec/2026-02-02.html)</sup> 将 x² − y² 改写为 (x − y)(x + y) 之所以有益，原因相同：它用良性抵消取代了灾难性抵消。<sup>[12](https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/02Numerics/Double/paper.pdf)</sup>

## 出现场景

**一元二次方程求根公式。** 标准例子是计算二次方程的较小根。对小 z 计算 x = 1 − √(1−z) 会将两个相近的数相减；代数等价的公式 x = z/(1+√(1−z)) 则完全避免了减法。<sup>[6](https://www.cs.cornell.edu/courses/cs4220/2026sp/lec/2026-02-02.html)</sup> 对一般二次方程 ax² + bx + c = 0，标准建议是用一元二次方程求根公式计算绝对值较大的根，再由乘积关系 x₁x₂ = c/a（韦达定理）求出另一根，后者不涉及相近量相减。<sup>[13](https://people.math.ethz.ch/~grsam/NCSE21/NumCSE_Lecture_Document.pdf)</sup><sup> • </sup><sup>[14](https://nzdr.ru/data/media/biblio/kolxoz/M/MN/Higham%20N.%20Accuracy%20and%20stability%20of%20numerical%20algorithms%20%28SIAM%2C%201996%29%28ISBN%200898713552%29%28718s%29_MN_.pdf)</sup>

**方差计算。** 朴素公式 \( s^{2} = \sum x_{i}^{2} - n\bar{x}^{2} \) 将两个很大且相近的平方和相减，可能丢失计算中的全部信息，因为有意义的数字正是未被准确存储的那些；平移或增量形式的公式可避免该减法。<sup>[8](https://stat243.berkeley.edu/fall-2024/units/unit8-numbers.html)</sup>

**函数求值。** 在零附近绘制 f(x) = (1 − cos x)/x² 会显示该数学函数基本保持在 0.5，而直接浮点求值并非如此，因为对小 x，1 − cos x 发生抵消。<sup>[15](https://introcs.cs.princeton.edu/java/91float/)</sup> 数值微分同样受害，因为它将两个非常接近的函数值相减；随着步长 h 缩小，抵消误差增大而截断误差减小，产生一个远高于精度阈值的总误差最小值。<sup>[16](https://computacion.fcaglp.unlp.edu.ar/Manuales/Online/fnotes/ch4-6.html)</sup>

**科学计算。** 在动力学计算中，用特征向量 y 构造矩阵–向量乘积应产生 λy，但当特征值 λ 与碰撞频率或大的微观速率常数相比很小时，灾难性抵消使乘积完全不准。<sup>[10](https://www.sciencedirect.com/science/article/pii/B9780444642073000068)</sup> 2023 年一项数学生物学研究记录了一个模型，其常微分方程的数值方法因灾难性浮点误差而严重失败，并通过保持不变量的模型重构加以修复。<sup>[17](https://arxiv.org/abs/2304.02365)</sup>

## 避免方法

一般策略是在数学等价的公式中选择不做相近量相减的那个。<sup>[3](https://cs357.cs.illinois.edu/textbook/notes/rounding.html)</sup> 技术包括：有理化以消除减法（如一元二次方程求根公式和 √(x²+1) − 1 的例子），<sup>[3](https://cs357.cs.illinois.edu/textbook/notes/rounding.html)</sup><sup> • </sup><sup>[6](https://www.cs.cornell.edu/courses/cs4220/2026sp/lec/2026-02-02.html)</sup> 将 x² − y² 因式分解为 (x − y)(x + y)，<sup>[12](https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/02Numerics/Double/paper.pdf)</sup> 以及重构模型使易发生抵消的表达式根本不出现。<sup>[17](https://arxiv.org/abs/2304.02365)</sup> 当操作数是可精确表示的浮点数时，Sterbenz 引理保证减法无害，这正是 FastTwoSum 等无误差变换算法的基础，后者能精确恢复一次加法的舍入误差。<sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC8905452/)</sup><sup> • </sup><sup>[18](https://www.researchgate.net/publication/277297921_Accurate_floating-point_summation)</sup>

## References

1. [Catastrophic cancellation, EPFL Graph Search](https://graphsearch.epfl.ch/en/concept/19985542)
2. [CAAM 453/553 Numerical Analysis I, Rice University (M. Embree)](https://www.cmor-faculty.rice.edu/~caam553/repo/public_html/caam453.pdf)
3. [Rounding, CS 357 Textbook, University of Illinois](https://cs357.cs.illinois.edu/textbook/notes/rounding.html)
4. [Numerical Methods I, Lecture 1, A. Donev, Courant Institute, NYU](https://math.nyu.edu/inmemoriam/donev/Teaching/NMI-Fall2010/Lecture1.handout.pdf)
5. [Stochastic rounding: implementation, error analysis and applications (Mikaitis, 2022)](https://pmc.ncbi.nlm.nih.gov/articles/PMC8905452/)
6. [CS 4220: Numerical Analysis, Cornell University](https://www.cs.cornell.edu/courses/cs4220/2026sp/lec/2026-02-02.html)
7. [Bounded Floating Point: Identifying and Revealing Floating-Point Error, ASTESJ](https://www.astesj.com/v06/i01/p57/)
8. [Numbers on a computer, Stat 243, UC Berkeley](https://stat243.berkeley.edu/fall-2024/units/unit8-numbers.html)
9. [CS 450: Numerical Analysis lecture slides, E. Solomonik, University of Illinois](https://relate.cs.illinois.edu/course/cs450-s18/f/lectures/01-lecture.pdf)
10. [Numerical methods, ScienceDirect (chapter on cancellation in kinetic calculations)](https://www.sciencedirect.com/science/article/pii/B9780444642073000068)
11. [Numerical Computing with IEEE Floating Point Arithmetic, Chapter 11: Cancellation, SIAM](https://epubs.siam.org/doi/abs/10.1137/1.9780898718072.ch11)
12. [Numerical Computation Guide (D. Harder, University of Waterloo)](https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/02Numerics/Double/paper.pdf)
13. [NumCSE Lecture Document, ETH Zürich](https://people.math.ethz.ch/~grsam/NCSE21/NumCSE_Lecture_Document.pdf)
14. [N. J. Higham, Accuracy and Stability of Numerical Algorithms, SIAM](https://nzdr.ru/data/media/biblio/kolxoz/M/MN/Higham%20N.%20Accuracy%20and%20stability%20of%20numerical%20algorithms%20%28SIAM%2C%201996%29%28ISBN%200898713552%29%28718s%29_MN_.pdf)
15. [Floating Point, Introduction to Programming in Java, Princeton](https://introcs.cs.princeton.edu/java/91float/)
16. [FP errors, floating-point notes (UNLP)](https://computacion.fcaglp.unlp.edu.ar/Manuales/Online/fnotes/ch4-6.html)
17. [Reisch, C. and Ranocha, H. (2023). Modeling still matters: a surprising instance of catastrophic floating point errors in mathematical biology and numerical methods for ODEs. arXiv:2304.02365](https://arxiv.org/abs/2304.02365)
18. [Rump, S. M., Ogita, T., Oishi, S. Accurate floating-point summation](https://www.researchgate.net/publication/277297921_Accurate_floating-point_summation)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Arithmetic and number systems › Computational arithmetic › Floating-point and mixed-precision arithmetic

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/catastrophic-cancellation

English original: https://www.edgepedia.org/catastrophic-cancellation
