[Shootout-list] n-body anomalies

Jon Harrop jon@ffconsultancy.com
Fri, 6 May 2005 01:48:05 +0100


On Friday 06 May 2005 01:29, Greg Buchholz wrote:
> --- Jon Harrop <jon@ffconsultancy.com> wrote:
> > On Thursday 05 May 2005 03:44, Greg Buchholz wrote:
> > >     Just a few questions about the n-body test.  It looks like we're
> > > mostly computing the amount of round-off error in simulating our
> > > algorithm, correct?
> >
> > Do you mean most of the code or most of the time is spent computing
> > round-off error?
>
>     Both?  It looks to me like it is computing the energy of the bodies
> before the simulation, performing the simulation, calculating the final
> energy, and comparing how well the energy was conserved.  Assuming the
> physics is correct, the only energy lost from the system is from
> round-off error.

Yes, I believe that is correct.

> Using rational numbers instead of doubles would have resulted in zero
> difference in the two answers.

The algorithm features sqrt, which cannot be represented exactly in rational 
arithmetic, so switching to rational arithmetic would not produce zero error. 
It would also take a prohibitively long time. You could accumulate a symbolic 
answer but that is essentially just writing down the problem, rather than 
giving the answer.

These are the reasons that real scientific computing often uses floating 
point. Many of the numbers found in such programs are theoretically 
irrational.

Arguably, the answer should not be the round-off error but something more 
interesting like the time until the next eclipse. Personally, I'd rather see 
an n-body simulation with n >> 5, like n = 10^5.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists