Average Error: 32.7 → 0.0
Time: 1.9s
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 r170252 = x;
        double r170253 = r170252 / r170252;
        double r170254 = 1.0;
        double r170255 = r170254 / r170252;
        double r170256 = r170252 * r170252;
        double r170257 = sqrt(r170256);
        double r170258 = r170255 * r170257;
        double r170259 = r170253 - r170258;
        return r170259;
}

double f(double x) {
        double r170260 = 2.0;
        double r170261 = 1.0;
        double r170262 = x;
        double r170263 = r170261 / r170262;
        double r170264 = -r170263;
        double r170265 = fabs(r170262);
        double r170266 = 1.0;
        double r170267 = fma(r170264, r170265, r170266);
        double r170268 = exp(r170267);
        double r170269 = cbrt(r170268);
        double r170270 = log(r170269);
        double r170271 = r170260 * r170270;
        double r170272 = r170271 + r170270;
        return r170272;
}

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.5

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