in reply to Re: Irrational numbers

It might indeed have a big cost in performance, though it's not so obvious. When adding two real numbers, there would be no computation whatsoever until an actual approximation of the result is requested. It could require lots of memory though, since there is a creation of a new closure (with all its context) for each arithmetic operation.

« Another is: how would you ever decide when to stop calling for more digits... »

This really is not an issue. It's like entering a drugstore and complaining about how there is too much choice. Accuracy would only affect numerical comparison and approximations. You can use a fixed value if you want. It depends on what you want to do with your numbers. The important thing is that it won't affect the way the calculations are done. Or in other words, it won't affect the result, only the way you show it.

Say you have a spaceship in a circular orbit around the sun with about an hundred thousands of millions of meters radius. That's about 150e9 meters. And you want to compute the position to a precision of the millimiter, because you worry about space debris for instance, or because you need to do some very advanced docking, or whatever). That would involve using angles as small as 6e-15 radians. So you'll need about 15 decimals of pi for you calculations. You wouldn't have to worry about that with an exact definition of pi. You would just make the calculations, and request a result with a millimeter precision. At no point you would have to worry about changing the definition of pi.

Replies are listed 'Best First'.
Re^3: Irrational numbers
by BrowserUk (Pope) on Dec 18, 2012 at 10:13 UTC
Say you have a spaceship in a circular orbit around the sun ... and request a result with a millimeter precision.

Sorry, but your misunderstandings are legion.

It would be impossible to pre-calculate such an encounter, regardless of the precision of the calculations.

The gravitational field of the Sun is neither uniform nor constant; and we do not yet have, and never will have, an accurate mapping of it; nor any way to produce one.

For a start, in order to produce such a map, it would be necessary to have an identifiable reference point or line, but the Sun's surface and its interior rotate at different speeds; and the surface rotates at different speeds relative to latitude, with the poles rotating almost 50% faster than the equator. The surface is constantly changing so there is no way to denote a fixed reference point.

In addition, solar radiation has a profound affect upon small craft in orbit around the Sun; and it is entirely unpredictable.

These, and many other factors, are why all long distance space flights have in-transit correction burns built into them. Not to correct for inaccuracies in precalculations; but rather to correct for the unknowable and unpredictable affects of gravitational perturbations and variable solar pressures.

And that is why all docking maneuvers in space require either manual corrections or programmed, active corrections using vehicle to vehicle sensing during final approach.

The polite assessment of your idea is that it is a solution looking for a problem to solve. If implemented, it would at best be, an unnecessary drain on computing resources; at worst, completely pointless.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

I was thinking of a model from which you could compare differences or something. Even if there is no such thing as a perfect circle or sphere in real life, it's still a very useful concept because it provides a reference frame for observation.

And for docking, I was still thinking of the Kerbal Space Program. Not an actual physical spaceship.

PS. Also, the sun happens to be almost perfectly spherical.

I was thinking of a model from which you could compare differences or something.

And how could we possibly measure millimetric differences in actual orbits in order to compare them against your perfect model?

And for docking, I was still thinking of the Kerbal Space Program. Not an actual physical spaceship.

So you are going to calculate the positions of the simulated spacecraft within your game, to millimetric accuracy, despite that you would need a screen the size of the Earth's orbit around the Sun in order to notice the difference?

PS. Also, the sun happens to be almost perfectly spherical.

I can only assume that you state this in connection with the Sun's gravity?

The variability of the Sun's gravity is not due to the shape of the Sun; but rather to density changes caused by the convection currents that cause the constant churning of the gas.

Look up the Variability of solar IRradiance and Gravity Oscillations (VIRGO) instrument on the SOHO spacecraft; reference g-mode waves.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Irrational numbers
by tobyink (Abbot) on Dec 18, 2012 at 10:20 UTC

A 64 bit float already gives you almost 20 significant figures; which should be sufficient for this use case.

Besides which, the metre itself is defined with reference to the speed of light, which has not been measured to a precision of anywhere near 20 significant figures.

perl -E'sub Monkey::do{say\$_,for@_,do{(\$monkey=[caller(0)]->[3])=~s{::}{ }and\$monkey}}"Monkey say"->Monkey::do'
Re^3: Irrational numbers
by Anonymous Monk on Dec 18, 2012 at 15:05 UTC
It might indeed have a big cost in performance, though it's not so obvious.

You are competing against something that the hardware can do in as little as one cpu cycle. No matter what you do, it will have a huge performance penalty, percentage wise.

You are competing against something that the hardware can do in as little as one cpu cycle.

It is actually much worse than that these days. Most physical simulation games lend themselves very nicely to being programmed for GPUs, in which case he would be competing with not just 1 FP calc per cycle, but dozens or even hundreds of FP multiply-add calculations per cycle.

And a single call to his closure-based lazy irrationals would take hundreds of cycles per digit.

Even if he dropped into C and avoided Perl's sub call overheads; calculating each digit using a polynomial -- Taylor series or similar -- will still take dozens of cycles.

We are talking 2 or 3 (even 4!) orders of magnitude slower calculations in order to achieve accuracy that simply isn't required.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.