Average Error: 32.6 → 0
Time: 1.3s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\frac{x}{x} - \frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1} \cdot \left|x\right|}{x}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\frac{x}{x} - \frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1} \cdot \left|x\right|}{x}
double f(double x) {
        double r124822 = x;
        double r124823 = r124822 / r124822;
        double r124824 = 1.0;
        double r124825 = r124824 / r124822;
        double r124826 = r124822 * r124822;
        double r124827 = sqrt(r124826);
        double r124828 = r124825 * r124827;
        double r124829 = r124823 - r124828;
        return r124829;
}

double f(double x) {
        double r124830 = x;
        double r124831 = r124830 / r124830;
        double r124832 = 1.0;
        double r124833 = sqrt(r124832);
        double r124834 = 1.0;
        double r124835 = r124833 / r124834;
        double r124836 = fabs(r124830);
        double r124837 = r124833 * r124836;
        double r124838 = r124837 / r124830;
        double r124839 = r124835 * r124838;
        double r124840 = r124831 - r124839;
        return r124840;
}

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 add-sqr-sqrt32.6

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

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

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

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

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

Reproduce

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