Skip to content

improve compensated summation in ias15#890

Open
cristicoz wants to merge 1 commit into
hannorein:mainfrom
cristicoz:main
Open

improve compensated summation in ias15#890
cristicoz wants to merge 1 commit into
hannorein:mainfrom
cristicoz:main

Conversation

@cristicoz
Copy link
Copy Markdown

@cristicoz cristicoz commented Mar 7, 2026

standard Kahan summation is susceptible to cancelation. this method with one extra operation protects against cancelation

@hannorein hannorein closed this Mar 7, 2026
@hannorein hannorein reopened this Mar 7, 2026
@hannorein
Copy link
Copy Markdown
Owner

Thanks a lot. Did you run any tests which show an improvement in the accuracy?

@cristicoz
Copy link
Copy Markdown
Author

cristicoz commented Mar 8, 2026

I didn't test with REBOUND but did extensive testing with an 8th order "leap frog" type integrator using extended precision and it does reduce the secular energy drift. Now I use an algorithm based on 2Sum ( main...cristicoz:rebound:v2 ) that eliminated the secular energy drift but does significally increase the integration time (with 8 operations). I think that you are more qualified to decide if it worth's the cost

Using a synthetic test I get the following results (time is relative to the naive method, the methods with 2 at the end are the new methods) :

2Sin method, tests = 1 length = 1286796350
Naive exact = 0 error = 1.05272316038019E-10 time = 0
Kahan exact = 0 error = 3.10739715209118E-13 time = 1313
Kahan2 exact = 0 error = 2.1924076374222E-17 time = 1411
Neumaier exact = 0 error = 1.70606001339062E-24 time = 3746
Neumaier2 exact = 1 error = 0 time = 2735

@hannorein
Copy link
Copy Markdown
Owner

Thanks. I think this is a bit too experimental at the moment and would require more testing before I can merge it in.

@cristicoz
Copy link
Copy Markdown
Author

cristicoz commented Mar 10, 2026

No problem, just trying to help. Since I cannot find any references, this is my (2 cents) explanation : cancellation only happens when adding numbers with different signs. Even thaw standard Kahan has guard bits, there is a small asymmetry when integrating periodical functions: half of the period will experience cancellation effects and half will not. How big is the asymmetry is hard to estimate but my guess would be around 0.5 ulp per step when cancelation occurs.

@hannorein
Copy link
Copy Markdown
Owner

Thanks. If you write up in a paper or, please let me know. I'd be very interested. I'll leave this PR open so I don't forget about it.

@cristicoz
Copy link
Copy Markdown
Author

I did some research (and wrote a double double library in the meantime, which helped me test my idea) and I think I can explain a bit better what I meant earlier. The cancellation effect that I was talking about seems to refer to what is known in the literature as "ill conditioned". Kahan summation is good as long as you don't have this kind of input (big and small numbers and alternating signs).

My modification to Kahan is basically the use of 2 fused EFT's (fast2Sum) to mitigate this. And in the case of the second version is again 2 fused EFT's (1 fast2Sum and 1 2Sum).

Unfortunately, I cannot find anything about this type of "fused" EFT's in the literature, but using my double double library (on Github), I see a performance close to Klein (second order) with a speed close to Kahan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants