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}\]

Error

Bits error versus x

Bits error versus y

Target

Original15.0
Target8.1
Herbie8.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

  1. Split input into 2 regimes
  2. if y < 4.7656810866124795e-307

    1. Initial program 15.3

      \[x \cdot \log \left(\frac{x}{y}\right)\]

    if 4.7656810866124795e-307 < y

    1. Initial program 14.7

      \[x \cdot \log \left(\frac{x}{y}\right)\]
    2. Taylor expanded around 0 0.6

      \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)}\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 41.8s)Debug log

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))))