Average Error: 32.9 → 0.0
Time: 2.0s
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 r125497 = x;
        double r125498 = r125497 / r125497;
        double r125499 = 1.0;
        double r125500 = r125499 / r125497;
        double r125501 = r125497 * r125497;
        double r125502 = sqrt(r125501);
        double r125503 = r125500 * r125502;
        double r125504 = r125498 - r125503;
        return r125504;
}

double f(double x) {
        double r125505 = 2.0;
        double r125506 = 1.0;
        double r125507 = x;
        double r125508 = r125506 / r125507;
        double r125509 = -r125508;
        double r125510 = fabs(r125507);
        double r125511 = 1.0;
        double r125512 = fma(r125509, r125510, r125511);
        double r125513 = exp(r125512);
        double r125514 = cbrt(r125513);
        double r125515 = log(r125514);
        double r125516 = r125505 * r125515;
        double r125517 = r125516 + r125515;
        return r125517;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 32.9

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
  2. Simplified31.0

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

    \[\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 2019354 +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)))))