Average Error: 14.7 → 8.3
Time: 15.3s
Precision: 64
Internal precision: 128
\[x \cdot \log \left(\frac{x}{y}\right)\]
⬇
\[\begin{array}{l}
\mathbf{if}\;y \le 1.3990722684524318 \cdot 10^{-275}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \log x + \log y \cdot \left(-x\right)\\
\end{array}\]
Target
| Original | 14.7 |
| Comparison | 7.7 |
| Herbie | 8.3 |
\[ \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 < 1.3990722684524318e-275
Initial program 15.3
\[x \cdot \log \left(\frac{x}{y}\right)\]
if 1.3990722684524318e-275 < y
Initial program 14.1
\[x \cdot \log \left(\frac{x}{y}\right)\]
- Using strategy
rm
Applied div-inv 14.1
\[\leadsto x \cdot \log \color{blue}{\left(x \cdot \frac{1}{y}\right)}\]
Applied log-prod 0.6
\[\leadsto x \cdot \color{blue}{\left(\log x + \log \left(\frac{1}{y}\right)\right)}\]
Applied distribute-lft-in 0.7
\[\leadsto \color{blue}{x \cdot \log x + x \cdot \log \left(\frac{1}{y}\right)}\]
Applied simplify 0.7
\[\leadsto x \cdot \log x + \color{blue}{\log y \cdot \left(-x\right)}\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(3593274562 2159623088 2841659272 4106180814 3668320207 1771069398)'
(FPCore (x y)
:name "Data.HyperLogLog.Type:size from hyperloglog-0.3.4, B"
:target
(if (< y 1.2973149052617803e-303) (* x (log (/ x y))) (/ x (/ 1 (- (log x) (log y)))))
(* x (log (/ x y))))