Average Error: 32.3 → 0
Time: 4.3s
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 r195014 = x;
        double r195015 = r195014 / r195014;
        double r195016 = 1.0;
        double r195017 = r195016 / r195014;
        double r195018 = r195014 * r195014;
        double r195019 = sqrt(r195018);
        double r195020 = r195017 * r195019;
        double r195021 = r195015 - r195020;
        return r195021;
}

double f(double x) {
        double r195022 = 1.0;
        double r195023 = 1.0;
        double r195024 = x;
        double r195025 = fabs(r195024);
        double r195026 = r195025 / r195024;
        double r195027 = r195023 * r195026;
        double r195028 = r195022 - r195027;
        return r195028;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.3

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

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

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

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

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

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