Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^5: Reasons for Using Perl 6

by Laurent_R (Canon)
on Jan 02, 2018 at 16:02 UTC ( #1206546=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^6: Reasons for Using Perl 6
by Jenda (Abbot) on Jan 03, 2018 at 14:45 UTC

    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.
        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.
        It doesn't solve any issues, because there's a hole drilled in the bottom of the Rat type. Your ship will eventually sink, it's just a question of when.
        > .3 - .2 - .1 0 # good > 3*10**-10 - 2*10**-10 - 1*10**-10 0 # good > 3*10**-20 - 2*10**-20 - 1*10**-20 -1.50463276905253e-36 # oops
        Monetary amounts? You will hit this error very fast if you start compounding interest.
      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.
        For mathematical work, Python is so far ahead of Perl that it's downright embarrassing.
        I agree that Python is ahead of Perl on that account and it's very unfortunate.
Re^6: Reasons for Using Perl 6
by Anonymous Monk on Jan 03, 2018 at 16:20 UTC
    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.
        If you add or subtract many numbers in decimal format which most of us use everyday...
        If what you really want is BigDecimal, why bother with a rational type at all?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1206546]
help
Chatterbox?
and nobody stirs...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-07-17 23:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (379 votes). Check out past polls.

    Notices?