Average Error: 15.0 → 8.1
Time: 41.8s
Precision: 64
Internal Precision: 384
\[x \cdot \log \left(\frac{x}{y}\right)\]
↓
\[\begin{array}{l}
\mathbf{if}\;y \le 4.7656810866124795 \cdot 10^{-307}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right)\\
\end{array}\]
Target
| Original | 15.0 |
|---|
| Target | 8.1 |
|---|
| Herbie | 8.1 |
|---|
\[\begin{array}{l}
\mathbf{if}\;y \lt 1.2973149052617803 \cdot 10^{-303}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{1}{\log x - \log y}}\\
\end{array}\]
Derivation
- Split input into 2 regimes
if y < 4.7656810866124795e-307
Initial program 15.3
\[x \cdot \log \left(\frac{x}{y}\right)\]
if 4.7656810866124795e-307 < y
Initial program 14.7
\[x \cdot \log \left(\frac{x}{y}\right)\]
Taylor expanded around 0 0.6
\[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)}\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(FPCore (x y)
:name "Data.HyperLogLog.Type:size from hyperloglog-0.3.4, B"
:herbie-target
(if (< y 1.2973149052617803e-303) (* x (log (/ x y))) (/ x (/ 1 (- (log x) (log y)))))
(* x (log (/ x y))))