Average Error: 32.5 → 0
Time: 1.5s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[1 \cdot \frac{-\left|x\right|}{x} + 1\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
1 \cdot \frac{-\left|x\right|}{x} + 1
double f(double x) {
        double r152902 = x;
        double r152903 = r152902 / r152902;
        double r152904 = 1.0;
        double r152905 = r152904 / r152902;
        double r152906 = r152902 * r152902;
        double r152907 = sqrt(r152906);
        double r152908 = r152905 * r152907;
        double r152909 = r152903 - r152908;
        return r152909;
}

double f(double x) {
        double r152910 = 1.0;
        double r152911 = x;
        double r152912 = fabs(r152911);
        double r152913 = -r152912;
        double r152914 = r152913 / r152911;
        double r152915 = r152910 * r152914;
        double r152916 = 1.0;
        double r152917 = r152915 + r152916;
        return r152917;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.5

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

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

    \[\leadsto \color{blue}{\left(-\frac{1}{x}\right) \cdot \left|x\right| + 1}\]
  5. Using strategy rm
  6. Applied div-inv4.9

    \[\leadsto \left(-\color{blue}{1 \cdot \frac{1}{x}}\right) \cdot \left|x\right| + 1\]
  7. Applied distribute-rgt-neg-in4.9

    \[\leadsto \color{blue}{\left(1 \cdot \left(-\frac{1}{x}\right)\right)} \cdot \left|x\right| + 1\]
  8. Applied associate-*l*4.9

    \[\leadsto \color{blue}{1 \cdot \left(\left(-\frac{1}{x}\right) \cdot \left|x\right|\right)} + 1\]
  9. Simplified0

    \[\leadsto 1 \cdot \color{blue}{\frac{-\left|x\right|}{x}} + 1\]
  10. Final simplification0

    \[\leadsto 1 \cdot \frac{-\left|x\right|}{x} + 1\]

Reproduce

herbie shell --seed 2020064 +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)))))