[
https://issues.apache.org/jira/browse/NUMBERS-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17364471#comment-17364471
]
Gilles Sadowski commented on NUMBERS-163:
-----------------------------------------
bq. I picture fma and the dot2s/sum2s algorithms that we use for
LinearCombination and Summation as separate but complementary functions. FMA is
a single, well-defined operation that produces a highly accurate double value
from 3 inputs.
It seems that there is a misunderstanding: I was considering the name "FMA" as
an abstraction for {{a . b + c}} where {{a}}, {{b}} and {{c}} are *reals*. If
the values are {{double}} values, it could be implemented with {{Math.fma}}
(without loss of accuracy IIUC) or with a plain {{a * b + c}}, or with
something in-between like the algorithms which Alex and you had been testing.
Both the {{LinearCombination}} (abstraction of a sum of products) and the
{{Summation}} (abstraction of a sum) can be defined in terms of the {{FMA}}
abstraction. My question was about whether the respective current
_implementations_ of {{LinearCombination}} and {{Summation}} (or the new
{{Sum}}) could achieve better accuracy than calls to {{FMA}} (as I've
illustrated in the previous comment).
bq. draft PR containing the {{Sum}} class
If there is
{code}
public static Sum of(final double a, final double b) {
return new Sum(a).add(b);
}
{code}
and
{code}
public Sum add(final double t) {
final double newSum = sum + t;
comp += ExtendedPrecision.twoSumLow(sum, t, newSum);
sum = newSum;
return this;
}
{code}
why provide
{code}
public static Sum of(final double a, final double b, final double c) {
return new Sum(a)
.add(b)
.add(c);
}
{code}
?
> Summation and LinearCombination Accumulators
> --------------------------------------------
>
> Key: NUMBERS-163
> URL: https://issues.apache.org/jira/browse/NUMBERS-163
> Project: Commons Numbers
> Issue Type: New Feature
> Reporter: Matt Juntunen
> Priority: Major
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> It would be useful to have simple accumulator classes in {{Summation}} and
> {{LinearCombination}} to perform extended precision operations on arbitrary
> collections of values without requiring conversion to {{double[]}}. Ex:
> {code:java}
> Summation.Accumulator sum= Summation.accumulator(1d);
> sum.add(x)
> .add(y)
> .add(z)
> .add(w);
> double sumResult = sum.get();
> LinearCombination.Accumulator comb = LinearCombination.accumulator(1d);
> comb.add(x, scale)
> .add(y, scale)
> .add(z, scale)
> .add(w, scale);
> double combResult = comb.get();
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)