Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: Reasons for Using Perl 6

by Jenda (Abbot)
on Dec 23, 2017 at 03:31 UTC ( #1206093=note: print w/replies, xml ) Need Help??

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

  • "Math that works" is what? An attempt to circumvent the restrictions of the computer computational model at the expense of making actual computation insanely slow? I guess that might mean it works, but is it useful? Or do you mean something else?
  • And that's a good thing why?
  • Which was one of the reasons the implementation took almost twenty years already and the result is still prohibitively slow.
  • mkay

Enoch was right!
Enjoy the last years of Rome.

Replies are listed 'Best First'.
Re^3: Reasons for Using Perl 6
by Laurent_R (Canon) on Dec 23, 2017 at 19:03 UTC
    Floating-point arithmetic is flawed and sucks, and has sucked for probably 40+ years by now (which is really a very long period when speaking about modern technologies). It is actually outrageous that this hasn't been fixed over such a long period. Experienced programmers know it and have been accustomed to live with that. Does that mean that we should accept this flaw? I don't think so. IMHO, we should get rid of that flaw, we need a flexit.

    Consider this in Python:

    >>> .3 - .2 - .1 -2.7755575615628914e-17
    The result is very small, but it should really be 0.

    It's not better in Perl 5:

    $ perl -E 'say .3 - .2 - .1;' -2.77555756156289e-17
    Of course, neither Python nor Perl 5 is responsible for that, it is the FP arithmetic of the underlying architecture which sucks.

    Does this mean we can't do anything about it? Yes, we can, Perl 6 has this right:

    > say .3 - .2 - .1; 0 > printf "%.50f\n", .3 - .2 - .1; 0.00000000000000000000000000000000000000000000000000
    Getting an accurate result for such a simple calculation is not anecdotal. It is a real and major improvement. You can compare non integers for equality and get the correct result. Don't do that with most other programming languages.

    Yes, this improvement comes with a cost. So long as we have hardware that is inaccurate, we'll need to work around it with software, and this is bound to be somewhat slower. Personally, I think that accuracy is more important than speed.

    If speed was the only criteria, none of us would use Perl, we would all write our programs in C, nay, probably in assembly. But we don't. So, most of the time, speed is not the most important factor for us.

    Well, sometimes, speed matters. And I probably would not argue for accuracy if that meant that computation was really "insanely slow," as you claim. But it is not insanely slow; it is just somewhat slower, as shown in my earlier post above, and this speed issue could just be solved with a faster CPU. And, as I said earlier, there are performance enhancements almost every week (and some very big ones should be there very soon).

      And, as I said earlier, there are performance enhancements almost every week (and some very big ones should be there very soon).
      Given the history of Perl 6 over the last couple decades, I'm not sure that anything which even remotely hints at "it'll be there Real Soon Now" is going to be effective at changing the minds of its non-fans.
        Yeah, fair enough, I get your point. ;-)

        To be a bit more specific, let me just outline the work done on performance. I'll split this work into two tracks.

        Just about every week, someone from the core development team improves the speed of this or that specific feature (actually, often 3 or 4 features per week). Of course such a change does not improve the speed of programs not using that specific feature. But, with time, many features are improved and it becomes increasingly likely that your specific program will benefit from one of these feature performance enhancement.

        Then, there is also more in-depth work going on on the Rakudo compiler / MoarVM optimizer (including JIT optimizing). This can significantly improve performance of almost any program running long enough for the real time optimizer to kick in. Needless to say, this type of thing is pretty complicated and needs heavy testing. As far as I know, very good results have already been achieved, but they haven't found their way yet into packaged production releases. So, at this point, you would probably need to download development programs and to build Rakudo / Moar VM and related environment to be able to test these improvements. I don't have any specific information, but I hope these enhancements will probably make their way into a production release relatively soon (but I don't know when).

        You can get more detailed information on these subjects here:

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

        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.

      Real world programming tends to involve functions. For instance, trigonometric functions are very common. How exactly does Perl 6 do it right? What is the domain of accurate calculations? Say, can it do simple interest calculations accurately?

      Perl and speed aren't mutually exclusive. You can have a low-level module or Inline::C doing the heavy lifting and still benefit from rapid prototyping or other comforts that Perl allows.

        Perl 6 is using the Rat type to represent rational numbers, such as 1/3, 23/7, .564, etc. With such numbers, calculations made with the four basic operators are generally accurate. This is because the Rat type represents rationals with two integers, one for the numerator and one for the denominator.

        When using irrational numbers, such as square root of 2, or trigonometric functions, then Perl 6 is forced to use floating-point arithmetic and suffers from the same drawbacks as other programming languages.

        So Perl 6 can do simple interest calculations accurately, but for compound interest calculations, it would fall back on floating-point arithmetic (and its flaws) for most common cases (although it is often possible to work around this if needed).

        I agree with your point about Perl and speed not being necessarily mutually exclusive. Even though I am dealing with huge volumes of data (so speed is important to me), I have never needed to actually use things such as Inline::C at $work.

Re^3: Reasons for Using Perl 6
by Ultimatt (Acolyte) on Jan 02, 2018 at 09:50 UTC
    Without wanting to really move you from your strong opinions strongly held about Perl 6, is perf -especially numeric- actually prohibitively slow still? Have you done any numeric work in Perl 6 in say the last six months to a year? I'd gently suggest it's really not that bad anymore. Rational maths is always going to be slower than floating point due to hardware support. Comparing like for like though Im not sure the difference is so big its something that would stop me. At least if I was using something as slow as Perl 5 for numeric work to begin with perf is clearly not what I cared about! For the P6 advent this year I did a bit of a write up on my personal long wait for perf, its really not what it once was

      It's all nice and dandy, including the funny "next Christmas" remarks ... it's just ten years too late. The language would have an infinitely better chance if you did a few search&replaces in the source code and documentation, removed all references to Perl whatsoever, made one or two more ad hoc changes to the use of special characters and operators, found a few people nobody knows and have them released it elsewhere under a new name and hope nobody notices it's not something new, but rather a project started some 18 years ago originally supposed to be finished about 15 years ago.

      Enoch was right!
      Enjoy the last years of Rome.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1206093]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-07-17 23:03 GMT
Find Nodes?
    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.