3 ms·
Are they even reals? Math classes were a while ago at this point, but I'm fairly convinced they're just rationals. Not trying to be pedantic, just wondering.
by perching_aix 1y ago
Are they even reals? Math classes were a while ago at this point, but I'm fairly convinced they're just rationals. Not trying to be pedantic, just wondering.
- jrvieira 1y agoYes, all floating numbers are rational. (It's also true that they are all reals but i get your point.)
- neepi 1y agoThey aren’t pure rational either. They are a subset of rational numbers.
- perching_aix 1y agoI think that's more of how one frames it, no? Like you won't be able to store any arbitrary rational in a float, as you'd need arbitrarily large storage for that. But all the numbers a float can store are rationals (so excluding all the fanciful IEEE-754 features of course).
- tialaramex 1y agoIt's not so much the need for arbitrary storage, the problem is that even easy rationals can't be expressed in the IEEE floats Take realistic::Rational::fraction(1, 3) ie one third. Floats can't represent that, but we don't need a whole lot of space for it, we're just storing the numerator and denominator. If we say we actually want f64, the 8 byte IEEE float, we get only a weak approximation, 6004799503160661/18014398509481984 because 3 doesn't go neatly into any power of 2. Edited: An earlier version of this comment provided the 32-bit fraction 11184811/33554432 instead of the 64-bit one.
- neepi 1y agoThey aren’t reals. They aren’t continuous and are bounded.
- MathMonkeyMan 1y agoAnd the operators +, -, *, and / lack some of the properties of addition, subtraction, multiplication, and division. Tom7 has a good video about this: https://www.youtube.com/watch?v=5TFDG-y-EHs https://www.youtube.com/watch?v=5TFDG-y-EHs
- jcranmer 1y agoFloats [if you ignore -0.0, infinities, and NaNs] are a subset of the rationals, themselves a subset of the real numbers. It's generally accurate to consider floats an acceptable approximation of the [extended] reals, since it's possible to do operations on them that don't exist for rational numbers, like sqrt or exp.
- perching_aix 1y ago> since it's possible to do operations on them that don't exist for rational numbers, like sqrt or exp This kinda sent me on a spin, for a moment I thought my whole life was a lie and these functions don't take rationals as inputs somehow. Then I realized you mean rather that they typically produce non-rationals, so the outputs will be approximated.
- ants_everywhere 1y agoI think the parent comment is saying it's confusing to associate floats with decimals like 0.123. Instead it's more accurate to think of them as being in scientific notation like 1.23E-1. In this notation it's clearer that they're sparsely populated because some of the 32 bits encode the exponent, which grows and shrinks very quickly. But yes rationals are reals. It's clear that you can't represent, say, all digits of pi in 32 bits, so the parent comment was not saying that 32 bit floats are all of the reals.
- perching_aix 1y agoYeah, that's fair. Personally, I like to think of them as a log compressed way of expressing fractional values, like how one would record in log with a camera to capture rich dark scenes while maintaining highlight detail. I think the bigger problem with floats is that the types and operations around them are pretty loose and permissive, although maybe I just don't appreciate how well the usual compromises work. Was pretty cool to dig into arbitrary precision math libraries a while back though, found some fun stuff in there. Also found out that my Android phone's Calculator app is not calculating in base 10, unlike Windows' Calculator...
- adastra22 1y agoWhich is what scientific notation is.
- taeric 1y agoFair, I was largely riffing off the theme in the post. That is, I took it as an implicit idea that floats represent real numbers. That said, I'd argue that they are neither reals nor rationals. They are scientific numbers with no syntax to indicate "repeated" tails. Would be like saying that you want someone to represent 1/3 using 6 digits with no bar notation. Best you can do is "0.33333" and that just isn't the same. Moving it so that you have 6 digits with 2 being exponent, you are stuck with "3.333e-01". Which is just different still.
- perching_aix 1y agoYeah, there's a similar comment in another subthread a bit below. The way I like to frame it, and this will almost certainly not be mathematically rigorous, is that every number a float (as in, the formats defined in IEEE-754) can hold can be sufficiently described as at most a rational, though they cannot represent all rationals, and cannot represent anything "higher" than rationals. That's why I prefer to say they're representing rationals. It's in the sense that they're all representing some rational, not any arbitrary rational. To do that would require infinite space. E.g. for one third, you'd need infinite binary digits (or even infinite decimal ones, as you say). It's just not how IEEE-754 floats work, as you mention. This launched me into a research on "perfect numerical accuracy" a while back, and there I did find schemes where you store the numerator and the denominator separately, freeing you from this specific problem. It's a fun topic.
- taeric 1y agoAh, I should have looked at more of the responses. This amusingly blew up on me well after I stopped watching. :D I don't tend to give much thought to real versus rational. Such that I still find it not that surprising to see people treat floats as reals. Especially since most languages make it hard to represent anything else. To that end, it will take me a bit to really internalize what you are saying here. I think I understand it. That said, my favorite for the craziness of "old is new" is that the literal "1/3" works to represent a rational in Common Lisp. Indeed, I had originally thought that they had some specific constants for common fractions defined. Nope, they just support rational literals. And I question if you need infinite space to represent repeated decimals. Strictly, you just need a way to indicate the repeating. No?