Average Error: 32.6 → 0
Time: 1.3s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\frac{x}{x} - 1 \cdot \frac{\left|x\right| \cdot 1}{x}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\frac{x}{x} - 1 \cdot \frac{\left|x\right| \cdot 1}{x}
double f(double x) {
        double r242902 = x;
        double r242903 = r242902 / r242902;
        double r242904 = 1.0;
        double r242905 = r242904 / r242902;
        double r242906 = r242902 * r242902;
        double r242907 = sqrt(r242906);
        double r242908 = r242905 * r242907;
        double r242909 = r242903 - r242908;
        return r242909;
}

double f(double x) {
        double r242910 = x;
        double r242911 = r242910 / r242910;
        double r242912 = 1.0;
        double r242913 = fabs(r242910);
        double r242914 = 1.0;
        double r242915 = r242913 * r242914;
        double r242916 = r242915 / r242910;
        double r242917 = r242912 * r242916;
        double r242918 = r242911 - r242917;
        return r242918;
}

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. Using strategy rm
  3. Applied *-un-lft-identity32.6

    \[\leadsto \frac{x}{x} - \frac{1}{\color{blue}{1 \cdot x}} \cdot \sqrt{x \cdot x}\]
  4. Applied *-un-lft-identity32.6

    \[\leadsto \frac{x}{x} - \frac{\color{blue}{1 \cdot 1}}{1 \cdot x} \cdot \sqrt{x \cdot x}\]
  5. Applied times-frac32.6

    \[\leadsto \frac{x}{x} - \color{blue}{\left(\frac{1}{1} \cdot \frac{1}{x}\right)} \cdot \sqrt{x \cdot x}\]
  6. Applied associate-*l*32.6

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

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

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

Reproduce

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

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

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