uxarray.utils.computing.diff_of_products#
- uxarray.utils.computing.diff_of_products(a, b, c, d)#
Kahan’s accurate a*b - c*d using two_prod and two_sum.
Naive evaluation of
a*b - c*dloses all significant bits when the two products are nearly equal (catastrophic cancellation). This routine computes each product exactly viatwo_prod, subtracts the rounded high parts, then folds the residual low parts back in. The result has rounding error bounded by one ulp of the true value regardless of cancellation.This is the core operation that makes cross products accurate: every component of
a x bis a difference of two products of exactly this form.- Parameters:
- Returns:
hi (float) – High-order part of the accurate result.
lo (float) – Low-order correction term; hi + lo equals the accurate value.
References
Higham, N. J. (2002). Accuracy and Stability of Numerical Algorithms (2nd ed.). Society for Industrial and Applied Mathematics. https://doi.org/10.1137/1.9780898718027
Jeannerod, C.-P., Louvet, N., and Muller, J.-M. (2013). Further analysis of Kahan’s algorithm for the accurate computation of 2 × 2 determinants. Mathematics of Computation, 82, 2245-2264. https://doi.org/10.1090/S0025-5718-2013-02679-8