Average Error: 32.0 → 0
Time: 1.5s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\left(-1\right) \cdot \frac{\left|x\right|}{x} + 1\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\left(-1\right) \cdot \frac{\left|x\right|}{x} + 1
double f(double x) {
        double r199201 = x;
        double r199202 = r199201 / r199201;
        double r199203 = 1.0;
        double r199204 = r199203 / r199201;
        double r199205 = r199201 * r199201;
        double r199206 = sqrt(r199205);
        double r199207 = r199204 * r199206;
        double r199208 = r199202 - r199207;
        return r199208;
}

double f(double x) {
        double r199209 = 1.0;
        double r199210 = -r199209;
        double r199211 = x;
        double r199212 = fabs(r199211);
        double r199213 = r199212 / r199211;
        double r199214 = r199210 * r199213;
        double r199215 = 1.0;
        double r199216 = r199214 + r199215;
        return r199216;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.0

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

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

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

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

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

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

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

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

Reproduce

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