What is the most numerical method of dividing sums or differences?

Consider the operation (a-b)/(c-d), where a, b, cand d- floating point numbers (namely, doubleof the type in C ++). And (a-b), and (c-d)- pairs ( sum- correction), as in the Kahan summation algorithm . In short, the specific of these pairs ( sum- correction) are that which sumcontains great importance as to what is in correction. More precisely, it correctioncontains something that was not included in sumthe summation due to numerical restrictions (53 bits of the mantissa in the type double).

What is the numerically most accurate way to calculate (a-b)/(c-d), given the above feature of numbers?

Bonus question: it would be better to get the result in the same way as ( sum- correction), as in the Kahan summation algorithm. So, find (e-f)=(a-b)/(c-d), not just e=(a-b)/(c-d).

+4
source share
2 answers

The div2 Dekker Algorithm (1971) is a good approach.

This requires an algorithm mul12(p,q)that can accurately calculate the pair u+v = p*q. Dekker uses a method known as Veltkamp splitting, but if you have access to a function fma, then a much simpler method

u = p*q
v = fma(p,q,-u)

( , ):

r   = a/c
u,v = mul12(r,c)
s   = (a - u - v - b + r*d)/c

r+s (a-b)/(c-d).

UPDATE: -, ..

s = ((((a-u)-v)-b)+r*d)/c

, , rr r (.. r + rr = a/c ), , u+v = r*c , rr*c = a-u-v , (a-u-v-b)/c (a-b)/c.

r*d - :

(a-b)/(c-d) = (a-b)/c * c/(c-d) = (a-b)/c *(1 + d/(c-d)) 
            = [a-b + (a-b)/(c-d) * d]/c

r (a-b)/(c-d), [...], , (a-u-v-b+r*d)/c (a-b)/(c-d)

+4

, ,

(a - b) / (c - d) = a/b (1 - b/a) / (1 - c/d) ~ a/b (1 - b/a + c/d)
0

Source: https://habr.com/ru/post/1651151/


All Articles