Average Error: 31.9 → 0
Time: 4.0s
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 r4441901 = x;
        double r4441902 = r4441901 / r4441901;
        double r4441903 = 1.0;
        double r4441904 = r4441903 / r4441901;
        double r4441905 = r4441901 * r4441901;
        double r4441906 = sqrt(r4441905);
        double r4441907 = r4441904 * r4441906;
        double r4441908 = r4441902 - r4441907;
        return r4441908;
}

double f(double x) {
        double r4441909 = 1.0;
        double r4441910 = x;
        double r4441911 = fabs(r4441910);
        double r4441912 = r4441911 / r4441910;
        double r4441913 = r4441909 - r4441912;
        return r4441913;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 31.9

    \[\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 2019129 
(FPCore (x)
  :name "sqrt sqr"

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

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