Average Error: 32.6 → 0
Time: 10.8s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[1 - 1 \cdot \frac{\left|x\right|}{x}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
1 - 1 \cdot \frac{\left|x\right|}{x}
double f(double x) {
        double r3948890 = x;
        double r3948891 = r3948890 / r3948890;
        double r3948892 = 1.0;
        double r3948893 = r3948892 / r3948890;
        double r3948894 = r3948890 * r3948890;
        double r3948895 = sqrt(r3948894);
        double r3948896 = r3948893 * r3948895;
        double r3948897 = r3948891 - r3948896;
        return r3948897;
}

double f(double x) {
        double r3948898 = 1.0;
        double r3948899 = 1.0;
        double r3948900 = x;
        double r3948901 = fabs(r3948900);
        double r3948902 = r3948901 / r3948900;
        double r3948903 = r3948899 * r3948902;
        double r3948904 = r3948898 - r3948903;
        return r3948904;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.6

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (x)
  :name "sqrt sqr"

  :herbie-target
  (if (< x 0.0) 2.0 0.0)

  (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))