Hacker News new | ask | show | jobs
by WalterBright 3751 days ago
This overlooks the issue that for repeated calculations, such as numerical integration, the trouble comes from accumulated roundoff errors. Even 16 digits of precision can become 0 digits pretty quickly if you're not very careful.
3 comments

I agree, that's a poor answer by NASA director and chief engineer. Here is a better answer:

The precision used for calculations is dependent on the number of "steps" required to get to the final result. Roughly, for N repeated calculations you lose somewhere between sqrt(N) * eps to N * eps of precision (eps=2e-16 for IEEE64).

Here are some actual examples:

IEEE64 (~16 decimal digits) is OK for interplanetary navigation for few months, where relatively low accuracy is required.

With the same precision, you start to lose phase accuracy above 24 hours if you're simulating GPS constellations. You need quad precision or above for simulations > 24 hours.

For simulating planet trajectories and solar system stability (Lyapunov time of planets), IEEE64 is good for ~10 mya in the future (Neptune-Pluto Lyapunov time), IEEE128 for ~200-1000mya, above that it is recommended to use 256bit floats and above. This is assuming typically ~1000 steps per simulated orbit.

Fun fact: we know from simulations that Pluto trajectory is stable for >10G years, but unpredictable above >10M years because of chaotic (but stable) interaction with Neptune.

[1] https://en.wikipedia.org/wiki/Stability_of_the_Solar_System

Here are some actual examples:

Something to add to your list of examples: During the first Gulf war, 28 US soldiers died due to accumulated rounding errors in the Patriot Missile battery computers: https://www.ima.umn.edu/~arnold/disasters/patriot.html

(This was in fact a known issue, and operators had been instructed to reboot the computers every 8 hours. Unfortunately this instruction ignored the fact that, in the field, nobody wanted to be responsible for turning off their defensive systems for a minute.)

Yeah, that doesn't surprise me in the least, many high-tech military systems have MTBF/MTTF of a few hours at best. Also, that's what you get when you try to do radar time computations using 24-bit fixed point in Ada.

Back to astronomy, in many astronomy libraries (such as astropy library) computations regarding time are done using 2 doubles (about 106 bit precision). 1 double is not enough.

_brandmeyer_ also mentioned something important that I totally forgot - any trigonometric computation requires computing modulo-pi to an accuracy of 1 ulp, which requires storing PI to ~1144 bits for double precision (for numbers near pi) (see Kahan argument reduction paper).

Since Intel processsors don't reach the required precision for IEEE standard above pi/2, this modulo reduction is done in software to this day. gcc maintains a 1144 bit PI constant and does a 1144 bit modulo every time you compute a sine/cosine above pi.

TLDR - 344 decimal digits of PI are used. High-precision PI computation is surprisingly more common than we expect...

[1] http://docs.astropy.org/en/stable/time/index.html

[2] https://software.intel.com/en-us/blogs/2014/10/09/fsin-docum...

[3] https://gcc.gnu.org/gcc-4.3/changes.html

[4] http://www.csee.umbc.edu/~phatak/645/supl/Ng-ArgReduction.pd...

any trigonometric computation requires computing modulo-pi to an accuracy of 1 ulp

For the trigonometric function itself, sure. For any reasonable algorithm which uses the trigonometric function, no. If find yourself computing sin(10^6), you're not really trying to compute sin(10^6); you're trying to compute sin(x) for some value of x which you know lies between 10^6(1 - epsilon) and 10^6(1 + epsilon). So the extent to which trigonometric calculations can lose precision by not doing extra-precision argument reduction, that precision was already lost in computing the unreduced argument.

Disagreed, the answer isn't aimed at engineers or actually at any science-oriented people, it's directed at the general public who don't even care what IEEE is.
As a software engineer, though, I find this answer way more interesting. That one part in 10^15 ends up being ~an inch on the scale of the solar system is thoroughly unsurprising.
So don't use a lossy floating point representation and use arbitrary precision instead.

Just because π is estimated to 15 significant digits doesn't mean the entire calculation needs to be.

Arbitrary precision is not a valid answer: every multiplication doubles the number of mantissa bits. Starting with a 64-bit precision, after just 40 multiplications, you will have consumed 800 GB of RAM just for storing a single number, at which point you'll ask yourself: how many decimal digits do I really need? Which was the initial question...
Pi cannot be stored exactly even with arbitrary precision.
Right but there are several other much less precise constants/measurements than 16 digits of pi.

G, for example, is only known to 5 or 6 digits of precision.

Nevermind the mass of the rocket/satellite/probe, positions, the mass of earth, orbital perturbations not accounted for ... etc.

What NASA does do is know precisely the error bounds of any important number which is far more valuable than using arbitrary precision math for π.

A branch of physics used to be taught a long time ago called "numerical analysis" to deal with this issue.

We even used to be careful about the difference between 'precise and exact'.

Pi = acos(0) is absolutely exact. But computer don't know about symbolic calculus. So to put the value in a register we used tricks.

Pi as a the converging value at the infinite of the Taylor development is awesome. But computer don't know about infinite.

3.1415926535897932384626433832795028841971 is precise.... it has a lot of digit and people loves that.

In ana num 3.15159 +- 0.00001 is exact. It bounds your result. Hence you can estimate your error and its propagation.

Because we thought humans were smart we thought that 3.14159 would be so meaningful people would understand that a constant should be considered to be exact with the implicit meaning that 9 was the last significant digit and people would be wise to use upper and lower bounds to estimates their results.

Then Computer Science was taught in university.

People not understanding why they had to study math and physics to simply program 2 + 2 and thought, stop bothering us. We just compute TVA we don't send a rocket to mars. Why learn boring math (integration, derivation, Newton's methods for approximation, Taylos's development, Cauchy Suites, condition of converging Suites, Integration in the complex field to compute generalized integrals, simplex, LU/RU matrices ....)

Yes people loves recurrence. They cannot apply the reasoning to simple maths series.

And that's how we have funny stuff like a lot of coder not understanding why :

   1.198 * 10.10
   12.099799999999998
Yes ... why are computers' maths so odd. What can we do about it?

Having a look at HP Saturn opcode makes you wonder if the lack of solution is because it does not exists or because people forgot. http://www.hpcalc.org/details.php?id=1693

I can't speak for other nations, but they still teach numeric analysis in Chinese universities as an undergraduate course. In my university it is a required subject. Many of us have countless dreadful memories of Runge-Kutta method, Euler's method, Newton's method, rate of convergence, numerical stability and error margins, just to name a few of the dreads...
Yes, perturbation methods are still taught and are still recognized as important. The first math course I took during my graduate degree (Intro analytic methods) covered it, for example.
Same in Portugal
Taught to me at university. Far more important in the age of computers than before.
> at university

In which country though?

Physics? Numerical analysis is Mathematics. It's still active and very important, e.g., in solving PDEs using the finite element method.
Mathematics? The people trying to find solutions of an equation by solving them?

Mathematicians is a weird education I hardly understand. The last PhD I met from Mc Gill university ignored the existence of non euclidean geometry. His excuse? He was on formal proof.

I am sorry, I have a hard time with people that never were challenged to make equations spit their solutions in order to make something actually work in the real world with limited time and money.

It is the same difference I see between athletes and ergotherapists, or Einstein and Poincaré.

> He was on formal proof.

Wat?

>A branch of physics used to be taught a long time ago called "numerical analysis" to deal with this issue.

Freshmen engineers had to take a year-long Numerical Analysis and FORTRAN programming class at my undergrad university. We would learn various iteration methods for solving equations and the homeworks would be more problems to solve with a program or two to write too.

This stuff is still taught, it just might be out of a different department than physics.

When you watch Walter Lewin's physics lectures, he repeatedly says "measurement means nothing without stating the uncertainty".

see - Lec 01: Units, Dimensions, and Scaling Arguments | 8.01 Classical Mechanics (Walter Lewin) [1]

[1] https://www.youtube.com/watch?v=X9c0MRooBzQ#t=4m30s

Physics Works !

Numerical analysis is the cornerstone of the applied mathematics curriculum, and still very much taught. Any applied mathematician, physicist, or engineer will have at least some background in the subject, and anyone with a good graduate degree will usually have taken two or three courses (source: I TA'd one of the graduate numerical analysis courses at Berkeley for a couple years, it was a requirement for many engineering grad students).