Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Reasons for Using Perl 6

by syphilis (Archbishop)
on Jan 02, 2018 at 13:10 UTC ( [id://1206539]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Reasons for Using Perl 6
in thread Reasons for Using Perl 6

Floating-point arithmetic is flawed and sucks

I disagree with that on both counts.
To me, it's incredibly naïve to complain about a base 2 approximation of 0.3 minus a base 2 approximation of 0.2 minus a base 2 approximation of 0.1 resulting in a minute non-zero value.

I've nothing against rational arithmetic - but note that when you've done your rational computations and you end up with a result of 132511/43, the first thing you're going to do (in order to gauge the magnitude of that value) is to convert it to an approximate floating point value.
And I would think (untested) that perl5's Math::GMPq module provides better rational arithmetic than perl6 ever will.

I can't see perl6's arithmetic model ever being a reason for me to use perl6. (I'd rather stay with perl5 - and do the arithmetic in XS space if accuracy is important.)

Cheers,
Rob

Replies are listed 'Best First'.
Re^5: Reasons for Using Perl 6
by Laurent_R (Canon) on Jan 02, 2018 at 16:02 UTC
    To me, it's incredibly naïve to complain about a base 2 approximation of 0.3 minus a base 2 approximation of 0.2 minus a base 2 approximation of 0.1 resulting in a minute non-zero value.
    I don't complain about that, and I am not naive enough to ignore that base 2 approximations of decimal non-integer numbers are not going to be accurate. I am complaining about the fact that we should still rely on base 2 approximations. It really should no longer be the case 18 years into the 21st century.

    Yes, I will probably convert 132511/43 into a FP approximate value only if I need it as a human to estimate the magnitude, but not if my aim is to store the value in a computer and if I am given the technical means to store it as a rational. This FP approximation has plagued us for almost half a century, I know we won't get rid of it overnight and that it will continue to plague us for quite a while, but I just hope it won't be for another half century. And for that to happen, we need to start somewhere. Perl 6's arithmetic model is a start.

    And I would think (untested) that perl5's Math::GMPq module provides better rational arithmetic than perl6 ever will.
    Maybe. Or maybe not. I just don't know.

    I was not saying that Perl 6's arithmetic model should be in itself a reason for you or for me to use Perl 6, I was only answering another monk who picked on that topic.

      Yes, I will probably convert 132511/43 into a FP approximate value only if I need it as a human to estimate the magnitude, but not if my aim is to store the value in a computer and if I am given the technical means to store it as a rational.
      The trouble with rationals is that the denominators keep growing. If you add 132511/43 and 27/67 and 1024/853, you've got 7577076638/2457493. Pretty soon you'll hit Perl6's built-in limit of 64 bits in the denominator, and it will switch to binary floating point automatically. Rationals do not solve the problem, but they do make things a lot more complicated.

      (Yes, I'm aware that you can sometimes cancel out common factors between the numerator and denominator. No, this does not solve your problem.)

        The trouble with rationals is that the denominators keep growing.
        Yes and no. It is true that there are cases where they do grow (but do you often add numbers like 132511/43 and 27/67 and 1024/853?), but there are many more cases where they don't. If you add or subtract many numbers in decimal format which most of us use everyday (monetary amount, physical measures made in the metric system, etc.) with, say two to five decimal places (or more), and the denominators will not grow and will often be a power of 10 (possibly multiplied by a power of 2 or a power of 5, something that can easily be brought back to a power of 10 by adjusting the numerator by the same factor). So in such cases, you'll never reach the 64-bit limit.

      It will continue to "plague" us as soon as we venture outside mere division and multiplication. What's the rational value of sqrt(2)? What's the rational value of sin(25)?

      Sure, you can use rational approximations instead of base 2 ones. For a fairly large expense.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

        Yes, Jenda, I know (and I said before) that the Rat type should be used for rational numbers, but would not help for irrational numbers. In whatever base, irrational numbers will be approximations. However, there are many many computer applications that would benefit from accuracy in simple additions or subtractions of rational numbers. For example most applications dealing with monetary amounts. So the Rat type doesn't solve all issues, I agree with that and never made any claim to the opposite, but it would solve many issues.
        What's the rational value of sqrt(2)? What's the rational value of sin(25)?
        If you want to deal with these things precisely, you can use Mathematica, or Python's Sympy.
        >>> sqrt(2) sqrt(2) >>> sqrt(2) * sqrt(6) 2*sqrt(3) >>> sin(pi*3/2) -1
        Notice, that's exactly -1. No approximation at all. Sympy knows a lot of mathematical identities. For mathematical work, Python is so far ahead of Perl that it's downright embarrassing. To claim that Perl6 is breaking new ground in this area is simply absurd.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1206539]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-24 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found