Average Error: 32.7 → 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 r127678 = x;
        double r127679 = r127678 / r127678;
        double r127680 = 1.0;
        double r127681 = r127680 / r127678;
        double r127682 = r127678 * r127678;
        double r127683 = sqrt(r127682);
        double r127684 = r127681 * r127683;
        double r127685 = r127679 - r127684;
        return r127685;
}

double f(double x) {
        double r127686 = 2.0;
        double r127687 = 1.0;
        double r127688 = x;
        double r127689 = r127687 / r127688;
        double r127690 = -r127689;
        double r127691 = fabs(r127688);
        double r127692 = 1.0;
        double r127693 = fma(r127690, r127691, r127692);
        double r127694 = exp(r127693);
        double r127695 = cbrt(r127694);
        double r127696 = log(r127695);
        double r127697 = r127686 * r127696;
        double r127698 = r127697 + r127696;
        return r127698;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 32.7

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

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

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