Average Error: 32.6 → 0
Time: 2.1s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\frac{x}{x} - \frac{\left|x\right| \cdot 1}{x}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\frac{x}{x} - \frac{\left|x\right| \cdot 1}{x}
double f(double x) {
        double r164820 = x;
        double r164821 = r164820 / r164820;
        double r164822 = 1.0;
        double r164823 = r164822 / r164820;
        double r164824 = r164820 * r164820;
        double r164825 = sqrt(r164824);
        double r164826 = r164823 * r164825;
        double r164827 = r164821 - r164826;
        return r164827;
}

double f(double x) {
        double r164828 = x;
        double r164829 = r164828 / r164828;
        double r164830 = fabs(r164828);
        double r164831 = 1.0;
        double r164832 = r164830 * r164831;
        double r164833 = r164832 / r164828;
        double r164834 = r164829 - r164833;
        return r164834;
}

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 associate-*l/30.3

    \[\leadsto \frac{x}{x} - \color{blue}{\frac{1 \cdot \sqrt{x \cdot x}}{x}}\]
  4. Simplified0

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

    \[\leadsto \frac{x}{x} - \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)))))