Herbie: Find and fix floating-point accuracy problems
herbie.uwplse.org
herbie.uwplse.org
(For clarification, I work at the University of Utah, so Pavel is the head honcho over Herbie here.)
I was interested in how the percentage accuracy metric is computed, but the link from the tutorial was dead. I was wondering if it could be useful to supply a bit more information. The example I was thinking of is linked from the math.js complex sqrt example, where the fastest version is rated more accurate than the original, because it avoids some catastrophic cancellation, but does not even use all the inputs to the problem. (Maybe that's not as bad as it sounds? I didn't get deep into the FP semantics but on the surface it sounded like something you'd be unhappy about if you blindly copy-and-pasted it into your product or library.) It seemed like % accuracy was hiding an important property that you might want to know about, which once you got into the details, you'd have an "aha, but no thanks" moment about. I'm not sure what metrics would make that clearer at an earlier point, but it's sort of an interesting problem.
Another question -- I see that you can restrict the ranges of the inputs to get improved answers. Another very common fact you might know about an expression is that one input is expected to be much larger than the other. Could Herbie take that as another assumption, and could it help? Maybe as a suggestion as to what ratios between inputs are most important when evaluating accuracy, or as a runtime test to break it into cases? Which it looks like you are already doing for ranges of specific variables (I guess the search space increases pretty fast when you start considering relationships between the inputs.)
Very cool work -- both esoteric and practical all at once!
sqrt(-.16666…)
It did correctly mark this as 0% accurate, but I’m kinda curious as to where it came from.
It does have a 1.1x speedup apparently. None of the other (more accurate) options provide a speedup. Maybe there aren’t any value options that provide a speedup, but the tool allows increasingly reduced accuracy (down to zero) until it finds a speedup?
----
ADDED LATER: I think I have the answer. Herbie seems to always assume x = 0, but there are a fixed set of transformations to get around that fact. Currently it only tries f(x), 1/f(x) and 1/-f(x) [1].
[1] https://github.com/herbie-fp/herbie/blob/b4a4bb4c61749912a64...
> Maybe there aren’t any value options that provide a speedup, but the tool allows increasingly reduced accuracy (down to zero) until it finds a speedup?
AFAIK Herbie works by trying a bunch of transformations to get candidate expressions and evaluate them to get the pareto frontier. So if there is a single constant expression generated, it will always be available as the worst alternative.
double code(double x) { return pow(fma(x, 9.0, -6.0), -0.5); }
It labeled this as having a slowdown.
There is a reason a big part of numerics (the mathematical disciplíne) is about dealing with it.
0.1 + 0.2 = 0.3
In Excel and Google Sheets, this returns false: 2.03 - 0.03 - 2 = 0 0.1000000000000000056 + 0.2000000000000000111 != 0.2999999999999999889It's really nice, as they explain you can't drop this in instead of the floating point arithmetic in a serious language because the performance isn't what you want. However in human terms, for a product like the calculator - it's easily fine.
This tool is about improving the number of digits that are correct.
Trying to use exact equality is going to fail on most equations even if you have millions of correct digits.
Esp., where subnormal numbers come into play.
inv(A) - (other stuff)
So, it only makes sense if A is much easier to solve than (A-UBU’).