Average Error: 32.4 → 0
Time: 4.4s
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 r88325 = x;
        double r88326 = r88325 / r88325;
        double r88327 = 1.0;
        double r88328 = r88327 / r88325;
        double r88329 = r88325 * r88325;
        double r88330 = sqrt(r88329);
        double r88331 = r88328 * r88330;
        double r88332 = r88326 - r88331;
        return r88332;
}

double f(double x) {
        double r88333 = 1.0;
        double r88334 = 1.0;
        double r88335 = x;
        double r88336 = fabs(r88335);
        double r88337 = r88336 / r88335;
        double r88338 = r88334 * r88337;
        double r88339 = r88333 - r88338;
        return r88339;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.4

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

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

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

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

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

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