Average Error: 32.8 → 0
Time: 865.0ms
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[1 + \left(-\frac{1 \cdot \left|x\right|}{x}\right)\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
1 + \left(-\frac{1 \cdot \left|x\right|}{x}\right)
double f(double x) {
        double r156802 = x;
        double r156803 = r156802 / r156802;
        double r156804 = 1.0;
        double r156805 = r156804 / r156802;
        double r156806 = r156802 * r156802;
        double r156807 = sqrt(r156806);
        double r156808 = r156805 * r156807;
        double r156809 = r156803 - r156808;
        return r156809;
}

double f(double x) {
        double r156810 = 1.0;
        double r156811 = 1.0;
        double r156812 = x;
        double r156813 = fabs(r156812);
        double r156814 = r156811 * r156813;
        double r156815 = r156814 / r156812;
        double r156816 = -r156815;
        double r156817 = r156810 + r156816;
        return r156817;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.8

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

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

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

Reproduce

herbie shell --seed 2020056 
(FPCore (x)
  :name "sqrt sqr"
  :precision binary64

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

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