sign(a² - b * c) * sqrt(abs(a² - b * c))
浮点算术,因为它遭受了(从大多数到最小问题):
cancellation n时cancellation n时,这同时使
a² ~= b * c
sign
因子不稳定由于方形/乘积在两个术语之间放大任何差异流flow/下水流问题(即使您需要很大的数字才能发生,所以我认为这不是一个特别大的问题)
sqrt
)等公共浮点数据类型。 background
当研究
a²
b * c
该代码基本上是针对使用mpmath
`rnorm->a`
dampsq->b`
`Xxnorm->c`
这个问题看起来与存在补偿快速算法的准确计算相似,例如,如所提出
Borgesc.f.,arxiv:2103.08694
,无论如何,我对浮点数数学数学的这种深层理论并不特别熟悉,因此我无法将算法转换为
scipy
减法而不是加法
绝对术语 符号前firactor # Distinguish between
# r1norm = ||b - Ax|| and
# r2norm = rnorm in current code
# = sqrt(r1norm^2 + damp^2*||x - x0||^2).
# Estimate r1norm from
# r1norm = sqrt(r2norm^2 - damp^2*||x - x0||^2).
# Although there is cancellation, it might be accurate enough.
if damp > 0:
r1sq = rnorm**2 - dampsq * xxnorm
r1norm = sqrt(abs(r1sq))
if r1sq < 0:
r1norm = -r1norm
是一个数字问题。
没有诉诸更广泛的类型,一个改进时,当:确定sign(a² - b * c) * sqrt(abs(a² - b * c))
hypot(a, b) = sqrt(a² + b²)