Average Error: 32.6 → 0
Time: 7.8s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[1 - \frac{1 \cdot \left|x\right|}{x}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
1 - \frac{1 \cdot \left|x\right|}{x}
double f(double x) {
        double r86856 = x;
        double r86857 = r86856 / r86856;
        double r86858 = 1.0;
        double r86859 = r86858 / r86856;
        double r86860 = r86856 * r86856;
        double r86861 = sqrt(r86860);
        double r86862 = r86859 * r86861;
        double r86863 = r86857 - r86862;
        return r86863;
}

double f(double x) {
        double r86864 = 1.0;
        double r86865 = 1.0;
        double r86866 = x;
        double r86867 = fabs(r86866);
        double r86868 = r86865 * r86867;
        double r86869 = r86868 / r86866;
        double r86870 = r86864 - r86869;
        return r86870;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.6

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

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

    \[\leadsto 1 - \frac{1}{x} \cdot \color{blue}{{\left(\left|x\right|\right)}^{1}}\]
  5. Applied pow15.1

    \[\leadsto 1 - \color{blue}{{\left(\frac{1}{x}\right)}^{1}} \cdot {\left(\left|x\right|\right)}^{1}\]
  6. Applied pow-prod-down5.1

    \[\leadsto 1 - \color{blue}{{\left(\frac{1}{x} \cdot \left|x\right|\right)}^{1}}\]
  7. Simplified0

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

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

Reproduce

herbie shell --seed 2019199 +o rules:numerics
(FPCore (x)
  :name "sqrt sqr"

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

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