Average Error: 31.8 → 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 r176477 = x;
        double r176478 = r176477 / r176477;
        double r176479 = 1.0;
        double r176480 = r176479 / r176477;
        double r176481 = r176477 * r176477;
        double r176482 = sqrt(r176481);
        double r176483 = r176480 * r176482;
        double r176484 = r176478 - r176483;
        return r176484;
}

double f(double x) {
        double r176485 = -1.0;
        double r176486 = 1.0;
        double r176487 = x;
        double r176488 = fabs(r176487);
        double r176489 = r176488 / r176487;
        double r176490 = r176486 * r176489;
        double r176491 = r176485 * r176490;
        double r176492 = 1.0;
        double r176493 = r176491 + r176492;
        return r176493;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 31.8

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

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

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

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

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