Average Error: 31.5 → 0
Time: 7.6s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[1 - \frac{\left|x\right|}{x}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
1 - \frac{\left|x\right|}{x}
double f(double x) {
        double r4679694 = x;
        double r4679695 = r4679694 / r4679694;
        double r4679696 = 1.0;
        double r4679697 = r4679696 / r4679694;
        double r4679698 = r4679694 * r4679694;
        double r4679699 = sqrt(r4679698);
        double r4679700 = r4679697 * r4679699;
        double r4679701 = r4679695 - r4679700;
        return r4679701;
}

double f(double x) {
        double r4679702 = 1.0;
        double r4679703 = x;
        double r4679704 = fabs(r4679703);
        double r4679705 = r4679704 / r4679703;
        double r4679706 = r4679702 - r4679705;
        return r4679706;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 31.5

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

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

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

Reproduce

herbie shell --seed 2019158 
(FPCore (x)
  :name "sqrt sqr"

  :herbie-target
  (if (< x 0) 2 0)

  (- (/ x x) (* (/ 1 x) (sqrt (* x x)))))