Skip to content

Local Taylor covers at 0, -inf, +inf - #1633

Open
obround wants to merge 16 commits into
mainfrom
taylor-near-zero
Open

Local Taylor covers at 0, -inf, +inf#1633
obround wants to merge 16 commits into
mainfrom
taylor-near-zero

Conversation

@obround

@obround obround commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Herbie samples uniformly over floating-point numbers, which means that on many benchmarks, a large fraction of sampled points are "extremely close to zero" or "extremely close to the infinities" (i.e., "oversampling"). This results in Herbie "overfitting" candidates to perform better very close to 0, -inf, +inf rather than on ranges people tend to spend more time thinking about. Additionally, for many functions, one term of its Taylor series is accurate enough to be within 1 ULP for certain intervals near 0, -inf, +inf.

This PR adds Taylor covers for univariate scalar functions at 0, -inf, +inf. Provided $f(x) \approx a_0 x^{k_0} + a_1 x^{k_1}$, we can use the interval below to say that $a_0 x^{k_0}$ is a good approximation near $0$.

$$ \left| x \right| \leq \left( \left| \frac{a_0}{a_1} \varepsilon \right| \right)^{1/(k_1 - k_0)} $$

At the infinities, expand using $1/x$ or $-1/x$. This is not rigorous, but in practice (on Herbie benchmarks), it tends to always be safe and match the sound Lagrange bound.

Once an interval is determined, covered regions are removed from the search sample, allowing Herbie to spend more effort finding improvements in the harder middle of the input range. Final test accuracy is still measured across the full domain (since this is not a sound bound, I figured it wouldn't be appropriate to affect the test set).

Checks each cover against the original expression before using it, and keeps both covered and uncovered results so harmful or unnecessarily expensive covers can be rejected. This allows the Pareto curve to not lose its tail (more on this below).

Main: https://nightly.cs.washington.edu/reports/herbie/1785132595:main:f8cc7197/
Taylor covers: https://nightly.cs.washington.edu/reports/herbie/1785133546:taylor-near-zero:204f87bd/

Adding up all the changes on the nightly runs of main and taylor-near-zero, we get a +82.8% improvement.

Some interesting findings:

  • Taylor covers used to regress the tail of the Pareto curve with fewer cheap alternatives by always wrapping every alternative in a covered version. However, on the univariate scalar benchmarks, for 72/140 tests, main had a useful alternative within 1 bit of the best result. To preserve that, we preserve the uncovered alternative in addition to the covered one.
  • Taylor covers do encourage higher-order Taylor polynomials (tested with order limit 6): mean order rose from 0.890 to 1.038 across the univariate suite when comparing main to taylor-near-zero. Still, doesn't seem like increasing the Taylor order limit past 2 is worthwhile.
  • There seemed to be a reporting bug in history.rkt closely related to this branch (so it's addressed here); I'll open a separate issue for that.

@obround
obround requested a review from pavpanchekha July 27, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant