Average Error: 32.7 → 0
Time: 1.2s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\frac{x}{x} - 1 \cdot \frac{\left|x\right|}{x}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\frac{x}{x} - 1 \cdot \frac{\left|x\right|}{x}
double f(double x) {
        double r124019 = x;
        double r124020 = r124019 / r124019;
        double r124021 = 1.0;
        double r124022 = r124021 / r124019;
        double r124023 = r124019 * r124019;
        double r124024 = sqrt(r124023);
        double r124025 = r124022 * r124024;
        double r124026 = r124020 - r124025;
        return r124026;
}

double f(double x) {
        double r124027 = x;
        double r124028 = r124027 / r124027;
        double r124029 = 1.0;
        double r124030 = fabs(r124027);
        double r124031 = r124030 / r124027;
        double r124032 = r124029 * r124031;
        double r124033 = r124028 - r124032;
        return r124033;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.7

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
  2. Using strategy rm
  3. Applied div-inv32.7

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

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

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

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

Reproduce

herbie shell --seed 2020062 +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)))))