Average Error: 32.4 → 0
Time: 1.5s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[-1 \cdot \left(1 \cdot \frac{\left|x\right|}{x}\right) + 1\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
-1 \cdot \left(1 \cdot \frac{\left|x\right|}{x}\right) + 1
double f(double x) {
        double r139352 = x;
        double r139353 = r139352 / r139352;
        double r139354 = 1.0;
        double r139355 = r139354 / r139352;
        double r139356 = r139352 * r139352;
        double r139357 = sqrt(r139356);
        double r139358 = r139355 * r139357;
        double r139359 = r139353 - r139358;
        return r139359;
}

double f(double x) {
        double r139360 = -1.0;
        double r139361 = 1.0;
        double r139362 = x;
        double r139363 = fabs(r139362);
        double r139364 = r139363 / r139362;
        double r139365 = r139361 * r139364;
        double r139366 = r139360 * r139365;
        double r139367 = 1.0;
        double r139368 = r139366 + r139367;
        return r139368;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.4

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

    \[\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 neg-mul-14.9

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

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

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

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

Reproduce

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