back

by hackandthink·3y ago·view on hn ↗
And we should switch to constructive reals in software.

IEEE floats suck and mathematicals reals are in general not computable.

4 comments
But equality over the constructible reals is not decidable either.

A constructible real number is essentially a suspendable computer program that outputs the next digit of the number whenever you ask for it, in finite time. With some work you can define operations like addition and multiplication of such objects. But if you try to define an equality test, you will find that the algorithm will correctly differentiate distinct numbers in finite time, but will not terminate on equal numbers (how many digits have to agree before you know they are the same?). Deciding equality here requires a halting oracle.

I've seen an advice to not use equality on floats, and instead use something like |x-y|<e. Probably translates to constructive reals as it needs to compute only some part of the numbers.
I've long held that floating point with a decimal exponent would help a lot more people feel like computing is something they can be a part of. That is, I think the non-professional programmer finds that

  0.1 + 0.2 != 0.3
is one of many little problems that adds up to them giving up the possibility of using software to put their skills on wheels. Like many reforms in computing, performance is used as an excuse to maintain the status quo of the priesthood. IBM is the only company in the industry that's taken this seriously, see

https://en.wikipedia.org/wiki/Decimal_floating_point

>I've long held that floating point with a decimal exponent

You mean IEEE745 Decimals?

Decimals also have serious pitfalls. For many applications they are just worse and lead to more problems.

In the end they are at least as confusing as floats. And switching to them as the default would make programs generally worse.

> Like many reforms in computing, performance is used as an excuse to maintain the status quo of the priesthood.

Very silly argument. Performance is not the issue.

Floats are useful because of their range. Even if input and output are small, intermediate results can easily be very large and exceed the representable decimals.

Every programmer has to learn that the computer does not understand real numbers and that expecting it to is entirely misguided. No different representation will change that.

You'd find plenty of unfriendly inequalities just like yours if you made the exponent decimal. e.g 1/3 + 1/3 + 1/3 != 1. The fundamental issue remains, which is that some rationals don't have exact representations in the (finite) floats, so there is some roundoff error. Sure, using decimals means that if you're only working with decimal literals and addition and subtraction and possibly multiplication you usually won't have any roundoff, but how often are you doing something that matters that won't add roundoff some other way?

Someone here said recently: It is rarely a good idea to compare finite representations of real numbers for equality. I am inclined to agree.

>IEEE floats

Having a fixed size datatype which can emulate the reals to a degree satisfying most applications is really amazing. They are one of the best designed datatypes.

You can also use just floats to calculate mathematical true results.