3 ms·
If you search back to the comment that started this subthread you'll find it began: "Try 0.1 + 0.2 == 0.3 in some other language, then try it in Perl 6." Do y
by raiph 11y ago
If you search back to the comment that started this subthread you'll find it began:
"Try 0.1 + 0.2 == 0.3 in some other language, then try it in Perl 6."
Do you agree with all of the next sentence or not? Please start with a plain yes or no before getting in to details.
The three individual literal decimal numbers shown above are not integers, they're not binary fractions, they're not floats, they are rational numbers, they are exact numbers, they are easily stored exactly on a computer, and whether or not they are stored exactly on a computer is a choice made by a programming language.
- haberman 11y agoNo, because I think that "easily stored on a computer" is too vague and reductive. I apologize if I have been too unclear about my point. My point is that your position is unfair. Your position seems to be that rational arithmetic is an obvious choice that other languages have been too lazy or stupid to adopt as their default. My point is that rational arithmetic is a fine choice for many things, but it is not a strict improvement over other number representations. Yes it can handle 0.1 + 0.2 = 0.3, but your implied conclusion that it is an obvious "default" choice is not accurate. It is not as perfect, and floating point is not as bad, as you seem to think. Yes, doubles have lots of values they can't represent perfectly, but so do rationals. Like sqrt(2), sin(1), pi, or any calculations involving numbers like these. Yes rationals can represent lots of numbers perfectly, but if you're keeping everything exact these can start to take lots of memory. Some slides I found about Perl 6 indicate that Rat values lose precision if the denominator gets too big, to avoid using too much memory. If this is true, the Rat type shouldn't be thought of as an "exact" type any more than double -- it could cease to be exact even if you stay away from inherently non-rational number like I listed above. What I'm disagreeing with overall is the dichotomy you are trying to create of: double=approximate, Perl 6 number=exact. Neither of those are really very true. There are cases where double is exact and cases where Perl 6 is not exact.
- raiph 11y ago> "easily stored on a computer" is too vague and reductive. Fwiw, from the compiler source code: my role Rational[::NuT, ::DeT] does Real { has NuT $.numerator; has DeT $.denominator; > Your position seems to be that rational arithmetic is an obvious choice Yes. Rational storage and rational arithmetic is an obvious choice for storing and processing rational numbers. (Alongside the other obvious choice -- using floats.) > other languages have been too lazy or stupid I'm extolling what I consider a minor Perl 6 virtue. Where have I been negative toward other languages? > rational arithmetic is a fine choice for ... ... doing rational arithmetic. > it is not a strict improvement over other number representations. For representing Integers? Sure. Irrationals? Agreed. Complex numbers? Gotchya. Number crunching where absolute exactness is not necessary? Use floats. But if exactness is required and a formula only involves rational numbers (and integers) then rational storage and processing is a strict improvement over use of floats. > [rationals are] not as perfect, and floating point is not as bad, as you seem to think. When did I suggest floats are bad? The general number type in Perl 6 is a float. Floats are awesome! But floats are by design not exact for arbitrary rational numbers. Their awesomeness derives directly from them being inexact in this way. When did I suggest storing rationals is perfect? They use up more memory than floats and processing can become pathologically slow if the denominators get big enough. This problem derives directly from them being exact. > doubles have lots of values they can't represent perfectly, but so do rationals. Like sqrt(2), sin(1), pi Those are explicitly defined in mathematics as numbers that are not rational. Rational storage and arithmetic is for representing and processing numbers that are rational! One can't exactly store an irrational number. The Perl 6 compiler defines a constant for the irrational number `pi`: my constant pi = 3.14159_26535_89793_238e0; The 'e0' on the end means that `pi` is stored as a float. > Some slides I found about Perl 6 indicate that Rat values lose precision if the denominator gets too big, to avoid using too much memory. The numerator of a default rational (a non-parameterized Rat) can be arbitrarily large but if the denominator exceeds 64 bits (20 decimal digits) then the compiler converts the number to a float. If you don't like that then you can use a rational with a larger denominator, with the extreme being a FatRat that has an arbitrary sized denominator as well as arbitrary sized numerator. > If this is true, the Rat type shouldn't be thought of as an "exact" type any more than double I think that view misses something very important. This is indeed where the discussion could get interesting. We shall see. It seems we needed to get past a lot of misunderstanding first. > What I'm disagreeing with overall is the dichotomy you are trying to create of: double=approximate, Perl 6 number=exact. I've never said that. What I have said is that, for storing and processing rational numbers, doubles are approximate (and they are); that it's possible to be exact instead (and it is); and that Perl 6 returns True for the expression `0.1 + 0.2 == 0.3` because by default it processes rationals as exact rationals. > There are cases where double is exact Not for rational numbers (I'm ignoring silly examples like 1/1 and others that happen to work out because the denominator and numerators are powers of two or whatever). > and cases where Perl 6 is not exact. Not for rational numbers, if you choose to have them be exact.
- haberman 11y agoThis all started when you said: > Floats are storage formats for approximations of numbers. Floats are, by definition, not relevant if one wants to store an exact number exactly. This is setting up a dichotomy of float=approximate, and the implied contrast is that Perl 6 rationals are exact. Float is "by definition, not relevant if one wants to store an exact number exactly." You didn't say "an exact rational," you said "an exact number." Your implication is that other representations are relevant if one wants to store an exact number exactly. You don't say rational, so you imply that other representations can represent an arbitrary number exactly. If you try to advertise Perl 6 as "exact", in comparison to those messy floats, you're going to get people who are very unhappy when they find out that 2pi / 2 isn't exactly pi. And you're also shortchanging people who use eg. JavaScript doubles as exact integer indices every day. X/1 isn't a "silly" case, integers are extremely relevant across all kinds of calculations. People who want to truly understand this landscape need to understand the contrasts between various number representations and the pros and cons of each. No representation can represent every real number perfectly, so everyone is going to run up against inexactness in their calculations unless they know how to restrict the domain of their calculations to numbers that can be perfectly represented with their chosen number representation.
- raiph 11y ago> You didn't say "an exact rational," you said "an exact number." You were right the first time you said that. You're still right. I immediately said as much in my first response to you. I don't understand what more you could want. :< I do know what I want. I would like you to acknowledge that you are basically ignoring the direct context of my commentary, namely chubot's "0.1 can't be represented exactly [using a computer]" and natch's "wtf" about `0.1 + 0.2 == 0.3`.) > If you try to advertise Perl 6 as "exact" That would be absurd. > integers are extremely relevant across all kinds of calculations. In the context of discussing rational storage and arithmetic, integers seem to me to be primarily relevant to the extent one is talking of numerators and denominators and primarily irrelevant to the extent one is talking about floats. Do you disagree? > People who want to truly understand this landscape need to understand the contrasts between various number representations and the pros and cons of each. Sure. But one has to start somewhere within a confusing landscape and try not to get lost by paying attention to details that don't yet matter. In this case natch started with the issue of exact rational calculation, chubot's wording suggested that rationals couldn't ever be stored accurately on a computer, and I tried to get floats out of the conversation until we'd cleared that confusion up. But you immediately took issue with me omitting a qualification that I thought obvious from context ("rationals"), then followed that by ignoring (afaict) my acknowledgement of your correction, and then we ended up here, with disappointingly little light shone on the very issue we both find interesting. :< Perhaps our exchange was entirely futile. Who knows? And maybe we'll meet again and do better. Here's hoping. :)