Review: Formalization of Double-Word Arithmetic, and Comments on "Tight and Rigorous Error Bounds for Basic Building Blocks of Double-Word Arithmetic"¶
Citation
- Muller, J.-M., & Rideau, L. (2022). Formalization of double-word arithmetic, and comments on "Tight and rigorous error bounds for basic building blocks of double-word arithmetic". ACM Transactions on Mathematical Software, 48(1), Article 9, 1–24.
- DOI
Abstract¶
Recently, a complete set of algorithms for manipulating double-word numbers (some classical, some new) was analyzed [16]. We have formally proven all the theorems given in that article, using the Coq proof assistant. The formal proof work led us to: (i) locate mistakes in some of the original paper proofs (mistakes that, however, do not hinder the validity of the algorithms), (ii) significantly improve some error bounds, and (iii) generalize some results by showing that they are still valid if we slightly change the rounding mode. The consequence is that the algorithms presented in [16] can be used with high confidence, and that some of them are even more accurate than what was believed before. This illustrates what formal proof can bring to computer arithmetic: beyond mere (yet extremely useful) verification, correction, and consolidation of already known results, it can help to find new properties. All our formal proofs are freely available.
Reference [16] is Joldes, Muller and Popescu (2017). This paper proves all of its 15 algorithms in Coq, with the Flocq library, under the same assumptions: radix 2, precision \(p\), rounding to nearest and an unlimited exponent range (p. 3).
Why testing is not enough¶
The authors argue that "with this class of algorithms, testing is a doubtful option": the inputs with errors close to the bound are "extremely rare", so "even when performing millions of random tests, one may miss the worst case by a very significant margin" (p. 2). For AccurateDWPlusDW, random tests rarely show errors above about \(2.5u^2\) (p. 6, Figure 1). Property 2.2 then builds an input whose relative error is \(3u^2 - 11u^3 + O(u^4)\), which shows that the published bound \(3u^2/(1 - 4u)\) is asymptotically optimal under ties-to-even (p. 5).
What changed¶
"All error bounds claimed in [16] are correct", but a lemma used for the three double-word products (Lemma 5.2 of [16]) is wrong, and the paper replaces it (pp. 6, 9). The formal proofs also improve three bounds (p. 8, Table 1; p. 9):
| algorithm | bound in [16] | bound proven here | condition |
|---|---|---|---|
| AccurateDWPlusDW | \(3u^2 + 13u^3\) | unchanged | |
| DWTimesFP2 | \(3u^2\) | unchanged | |
| DWTimesDW1 | \(7u^2\) | \(\tfrac{11}{2}u^2/(1 + u)^2 < 5.5u^2\) | \(p \ge 6\), any tie-breaking rule (Theorem 2.7) |
| DWTimesDW1 | \(7u^2\) | \(5u^2/(1 + u)^2 < 5u^2\) | ties-to-even (Theorem 2.7) |
| DWTimesDW2 | \(6u^2\) | \(5u^2/(1 + u)^2 < 5u^2\) | \(p \ge 5\) (Theorem 2.8) |
The Coq development declares the tie-breaking rule of rounding to nearest as an arbitrary function, "to formalize more general results and to clearly locate places when the ties-to-even tie breaking rule is necessary" (p. 17). The bound of DWTimesDW1 is the case where the rule matters: the largest error the authors observed with ties-to-zero is \(5.4907u^2\), above the ties-to-even bound (p. 8, Table 1).
Relevance to Hifuku¶
The float-float library of Hifuku's WGSL kernels takes its error bounds from this paper where it improves on Joldes et al. (2017).
- The WGSL specification does not name a tie-breaking rule, so the library
uses the bound that holds for any rule. For
ff_mul, which is DWTimesDW1 and becomes DWTimesDW2 when a compiler contracts it to an fma, that is the larger of \(5.5u^2/(1 + u)^2\) and \(5u^2/(1 + u)^2\): \(5.5u^2/(1 + u)^2\). - For
ff_add, AccurateDWPlusDW, the bound \(3u^2/(1 - 4u)\) of Joldes et al. stands, and Property 2.2 shows that it cannot be lowered. - The tests cannot confirm the bounds. By the authors' argument, random inputs almost never reach the worst case. The library's tests use the bounds as a ceiling: an error above the bound shows that the device or its compiler broke an error-free transform, which is the failure the tests exist to detect. A result below the bound shows nothing about how tight the bound is.