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 nonzero value.
I don't complain about that, and I am not naive enough to ignore that base 2 approximations of decimal noninteger 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.
 [reply] 

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.
 [reply] [d/l] [select] 

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.
 [reply] 






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.  [reply] [d/l] 


 [reply] 

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 64bit limit.
 [reply] 


