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

Error

Bits error versus x

Bits error versus y

Target

Original14.7
Comparison7.7
Herbie8.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

  1. Split input into 2 regimes.
  2. if y < 1.3990722684524318e-275

    1. Initial program 15.3

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

    if 1.3990722684524318e-275 < y

    1. Initial program 14.1

      \[x \cdot \log \left(\frac{x}{y}\right)\]
    2. Using strategy rm
    3. Applied div-inv 14.1

      \[\leadsto x \cdot \log \color{blue}{\left(x \cdot \frac{1}{y}\right)}\]
    4. Applied log-prod 0.6

      \[\leadsto x \cdot \color{blue}{\left(\log x + \log \left(\frac{1}{y}\right)\right)}\]
    5. Applied distribute-lft-in 0.7

      \[\leadsto \color{blue}{x \cdot \log x + x \cdot \log \left(\frac{1}{y}\right)}\]
    6. Applied simplify 0.7

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

Runtime

Time bar (total: 15.3s) Debug log

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