Average Error: 32.4 → 0.0
Time: 2.1s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[2 \cdot \log \left(\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)\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
2 \cdot \log \left(\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)
double f(double x) {
        double r150307 = x;
        double r150308 = r150307 / r150307;
        double r150309 = 1.0;
        double r150310 = r150309 / r150307;
        double r150311 = r150307 * r150307;
        double r150312 = sqrt(r150311);
        double r150313 = r150310 * r150312;
        double r150314 = r150308 - r150313;
        return r150314;
}

double f(double x) {
        double r150315 = 2.0;
        double r150316 = 1.0;
        double r150317 = x;
        double r150318 = r150316 / r150317;
        double r150319 = -r150318;
        double r150320 = fabs(r150317);
        double r150321 = 1.0;
        double r150322 = fma(r150319, r150320, r150321);
        double r150323 = exp(r150322);
        double r150324 = cbrt(r150323);
        double r150325 = log(r150324);
        double r150326 = r150315 * r150325;
        double r150327 = r150326 + r150325;
        return r150327;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 32.4

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

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

    \[\leadsto \color{blue}{\log \left(e^{\mathsf{fma}\left(-\frac{1}{x}, \left|x\right|, 1\right)}\right)}\]
  5. Using strategy rm
  6. 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)}\]
  7. 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)}\]
  8. Simplified0.0

    \[\leadsto \color{blue}{2 \cdot \log \left(\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. Final simplification0.0

    \[\leadsto 2 \cdot \log \left(\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)\]

Reproduce

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

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

  (- (/ x x) (* (/ 1 x) (sqrt (* x x)))))