News for hackers. Stuff that matters.
Re:High Performance Correctly Rounded Math Libraries for 32-... by brandmeyer on Thursday August 26, 2021 @04:58PM (#28320651)
> Things are much harder with 64 bits, unfortunately.

Solved and published over 15 years ago. The underlying methods were published over 20 years ago (V. Lef`evre, J.M. Muller, and A. Tisserand. Towards correctly rounded transcendentals. and Lefvre's associated PhD thesis).

https://hal-ens-lyon.archives-ouvertes.fr/ensl-01529804/file...

The Correctly Rounded Math Library (CRLIBM) is available for several languages.

Re:High Performance Correctly Rounded Math Libraries for 32-... by bsder on Thursday August 26, 2021 @05:21PM (#28320974)
That's a bit glib. I don't believe that the bounds are fully proven for all the transcendentals (and I believe that exponentiation is only "proven" over restricted subdomains).

Single precision floating point is a small enough domain that it can be fully enumerated--you can prove that everything rounds correctly and find the problematic cases. 24-bits just isn't that large to modern computers.

Double precision floating point is still too large to fully enumerate. So, there could be an exception lurking in there that goes out a long way.

In reality, it seems that rounding requires about 2n + log2 n bits and never 3n bits (I don't think we've ever found an exception to this). However, if you can prove that, you should submit it as it would be a significant advance in the world of mathematics.

Re:High Performance Correctly Rounded Math Libraries for 32-... by adgjlsfhk1 on Thursday August 26, 2021 @05:37PM (#28321191)
In general, there shouldn't be a rule like 3n bits. For random functions, 1 in 8^n values should require more than 3n bits. Since n bit inputs give 2^n possible values, this implies that for bit length n, there is a 4^-n chance that any given function will require more than 3n bits.
Re:High Performance Correctly Rounded Math Libraries for 32-... by bsder on Thursday August 26, 2021 @05:54PM (#28321430)
Except that this isn't the case. We know empirically because we have enumerated the single precision space completely.

So, the problem isn't bounded by simple probabilities. There are other properties involved that cause it to diverge from the "naive" probabilistic estimates. What those properties are we don't know yet.

The "rounding" problem is called the "Table Maker's Dilemma" and it descends into some pretty fundamental transcendental number theory.

This is not an "easy" problem. Proof that PI was transcendental is relatively modern (1885).

Re:High Performance Correctly Rounded Math Libraries for 32-... by tmyklebu on Thursday August 26, 2021 @10:22PM (#28323645)
If you're just looking for hard-to-round inputs, you can also enumerate the double precision space completely with some cleverness and modest patience.

Elkies [0] computes a piecewise linear approximation to his (number-theoretic) function of interest and does a lattice reduction on each piece to filter out the vast majority of the space. The same approach, works almost everywhere on all of the transcendental functions I've tried, and I believe the CRlibm group uses it.

[0] https://arxiv.org/pdf/math/0005139.pdf

Re:High Performance Correctly Rounded Math Libraries for 32-... by bsder on Friday August 27, 2021 @05:32PM (#28333199)
Oooh, that's an interesting take.
Re:High Performance Correctly Rounded Math Libraries for 32-... by adgjlsfhk1 on Thursday August 26, 2021 @06:00PM (#28321511)
This doesn't contradict what I said. I said that the odds of a function needing more than 3n digits was 4^-n. For single precision, that means you would expect almost all functions to be OK with 3n bits (1 in 2^46 wouldn't be).
Re:High Performance Correctly Rounded Math Libraries for 32-... by vyodaiken on Thursday August 26, 2021 @08:10PM (#28322686)
if it was a randomly selected function, which it is not.
Re:High Performance Correctly Rounded Math Libraries for 32-... by stephencanon on Thursday August 26, 2021 @08:21PM (#28322791)
In practice the low-order bits of transcendental functions are pretty much indistinguishable from random for _most_ inputs. You do have to be very careful close to especially nice values though, because this falls apart catastrophically there (e.g. logarithms close to 1)--it should be pretty obvious from the Taylor expansions why this happens. The good news is that when this does happen, almost by construction you usually don't end up very close to an exact halfway point for rounding.
Re:High Performance Correctly Rounded Math Libraries for 32-... by klyrs on Thursday August 26, 2021 @09:50PM (#28323433)
> In practice the low-order bits of transcendental functions are pretty much indistinguishable from random for _most_ inputs.

In my experience, low order bits of transcendental functions make terrible rng sources (even discounting their runtime). Your example of the logarithm is great -- for large inputs, you need large changes to flip even low order bits.

Re:High Performance Correctly Rounded Math Libraries for 32-... by adgjlsfhk1 on Thursday August 26, 2021 @05:11PM (#28320832)
CRLIBM is great, but it is significantly slower than alternatives since it requires very high internal precision. The cool thing with this paper is that it gives correct rounding without as much of a cost for 32 bit.