in reply to Irrational numbers

One possible application would be for programs that have to deal with very wild ranges of values, without loss of any precision. The example I have in mind is programs such as the Kerbal Space Program:

The KSP simulation fudges the calculations around the N-body problem in order to ensure that the simulation can be run at a pace that makes the game play possible.

Performing those calculations using your lazy lists would be so slow that it would make the game impossible to play.

And there is one reason why no one uses such representations.

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

Floating point reals are used to calculate real trajectories; like those that took men to the moon and the Voyager missions on their grand tour passed Jupiter, Saturn, Uranus and Neptune; and to allow the Deep Space Network to still find them and receive their signals after 35 years and 10 billion miles.

Seems good enough to me.


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.

RIP Neil Armstrong


Comment on Re: Irrational numbers
Re^2: Irrational numbers
by grondilu (Pilgrim) on Dec 18, 2012 at 01:27 UTC

    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.

      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.

      RIP Neil Armstrong

        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.

      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'
      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.

        RIP Neil Armstrong