Average Error: 31.8 → 0
Time: 5.0s
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 r3644807 = x;
        double r3644808 = r3644807 / r3644807;
        double r3644809 = 1.0;
        double r3644810 = r3644809 / r3644807;
        double r3644811 = r3644807 * r3644807;
        double r3644812 = sqrt(r3644811);
        double r3644813 = r3644810 * r3644812;
        double r3644814 = r3644808 - r3644813;
        return r3644814;
}

double f(double x) {
        double r3644815 = 1.0;
        double r3644816 = 1.0;
        double r3644817 = x;
        double r3644818 = fabs(r3644817);
        double r3644819 = r3644818 / r3644817;
        double r3644820 = r3644816 * r3644819;
        double r3644821 = r3644815 - r3644820;
        return r3644821;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 31.8

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

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

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

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

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

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