Average Error: 32.5 → 0.0
Time: 13.7s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, -\frac{1}{x}, 1\right)}}\right) \cdot 2 + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, -\frac{1}{x}, 1\right)}}\right)\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, -\frac{1}{x}, 1\right)}}\right) \cdot 2 + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, -\frac{1}{x}, 1\right)}}\right)
double f(double x) {
        double r138727 = x;
        double r138728 = r138727 / r138727;
        double r138729 = 1.0;
        double r138730 = r138729 / r138727;
        double r138731 = r138727 * r138727;
        double r138732 = sqrt(r138731);
        double r138733 = r138730 * r138732;
        double r138734 = r138728 - r138733;
        return r138734;
}

double f(double x) {
        double r138735 = x;
        double r138736 = fabs(r138735);
        double r138737 = 1.0;
        double r138738 = r138737 / r138735;
        double r138739 = -r138738;
        double r138740 = 1.0;
        double r138741 = fma(r138736, r138739, r138740);
        double r138742 = exp(r138741);
        double r138743 = cbrt(r138742);
        double r138744 = log(r138743);
        double r138745 = 2.0;
        double r138746 = r138744 * r138745;
        double r138747 = r138746 + r138744;
        return r138747;
}

Error

Bits error versus x

Target

Original32.5
Target0
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;x \lt 0.0:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;0.0\\ \end{array}\]

Derivation

  1. Initial program 32.5

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
  2. Simplified30.9

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x\right|, \frac{-1}{x}, 1\right)}\]
  3. Using strategy rm
  4. Applied add-log-exp4.7

    \[\leadsto \color{blue}{\log \left(e^{\mathsf{fma}\left(\left|x\right|, \frac{-1}{x}, 1\right)}\right)}\]
  5. Simplified4.7

    \[\leadsto \log \color{blue}{\left(e^{\mathsf{fma}\left(\frac{-1}{x}, \left|x\right|, 1\right)}\right)}\]
  6. Using strategy rm
  7. Applied add-cube-cbrt0.0

    \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{fma}\left(\frac{-1}{x}, \left|x\right|, 1\right)}} \cdot \sqrt[3]{e^{\mathsf{fma}\left(\frac{-1}{x}, \left|x\right|, 1\right)}}\right) \cdot \sqrt[3]{e^{\mathsf{fma}\left(\frac{-1}{x}, \left|x\right|, 1\right)}}\right)}\]
  8. Applied log-prod0.0

    \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{fma}\left(\frac{-1}{x}, \left|x\right|, 1\right)}} \cdot \sqrt[3]{e^{\mathsf{fma}\left(\frac{-1}{x}, \left|x\right|, 1\right)}}\right) + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(\frac{-1}{x}, \left|x\right|, 1\right)}}\right)}\]
  9. Simplified0.0

    \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, \frac{-1}{x}, 1\right)}}\right) \cdot 2} + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(\frac{-1}{x}, \left|x\right|, 1\right)}}\right)\]
  10. Simplified0.0

    \[\leadsto \log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, \frac{-1}{x}, 1\right)}}\right) \cdot 2 + \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, \frac{-1}{x}, 1\right)}}\right)}\]
  11. Final simplification0.0

    \[\leadsto \log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, -\frac{1}{x}, 1\right)}}\right) \cdot 2 + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(\left|x\right|, -\frac{1}{x}, 1\right)}}\right)\]

Reproduce

herbie shell --seed 2019196 +o rules:numerics
(FPCore (x)
  :name "sqrt sqr"

  :herbie-target
  (if (< x 0.0) 2.0 0.0)

  (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))