Average Error: 32.1 → 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 r124210 = x;
        double r124211 = r124210 / r124210;
        double r124212 = 1.0;
        double r124213 = r124212 / r124210;
        double r124214 = r124210 * r124210;
        double r124215 = sqrt(r124214);
        double r124216 = r124213 * r124215;
        double r124217 = r124211 - r124216;
        return r124217;
}

double f(double x) {
        double r124218 = 2.0;
        double r124219 = 1.0;
        double r124220 = x;
        double r124221 = r124219 / r124220;
        double r124222 = -r124221;
        double r124223 = fabs(r124220);
        double r124224 = 1.0;
        double r124225 = fma(r124222, r124223, r124224);
        double r124226 = exp(r124225);
        double r124227 = cbrt(r124226);
        double r124228 = log(r124227);
        double r124229 = r124218 * r124228;
        double r124230 = r124229 + r124228;
        return r124230;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 32.1

    \[\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-exp5.1

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