Average Error: 32.6 → 0
Time: 6.5s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\mathsf{fma}\left(1, -\frac{\left|x\right|}{x}, 1\right)\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\mathsf{fma}\left(1, -\frac{\left|x\right|}{x}, 1\right)
double f(double x) {
        double r70676 = x;
        double r70677 = r70676 / r70676;
        double r70678 = 1.0;
        double r70679 = r70678 / r70676;
        double r70680 = r70676 * r70676;
        double r70681 = sqrt(r70680);
        double r70682 = r70679 * r70681;
        double r70683 = r70677 - r70682;
        return r70683;
}

double f(double x) {
        double r70684 = 1.0;
        double r70685 = x;
        double r70686 = fabs(r70685);
        double r70687 = r70686 / r70685;
        double r70688 = -r70687;
        double r70689 = 1.0;
        double r70690 = fma(r70684, r70688, r70689);
        return r70690;
}

Error

Bits error versus x

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. Simplified4.7

    \[\leadsto \color{blue}{1 - \frac{1}{x} \cdot \left|x\right|}\]
  3. Using strategy rm
  4. Applied add-cube-cbrt4.7

    \[\leadsto \color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}} - \frac{1}{x} \cdot \left|x\right|\]
  5. Applied prod-diff31.4

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{1} \cdot \sqrt[3]{1}, \sqrt[3]{1}, -\left|x\right| \cdot \frac{1}{x}\right) + \mathsf{fma}\left(-\left|x\right|, \frac{1}{x}, \left|x\right| \cdot \frac{1}{x}\right)}\]
  6. Simplified31.4

    \[\leadsto \color{blue}{\mathsf{fma}\left(1, -\frac{\left|x\right|}{x}, 1\right)} + \mathsf{fma}\left(-\left|x\right|, \frac{1}{x}, \left|x\right| \cdot \frac{1}{x}\right)\]
  7. Simplified0

    \[\leadsto \mathsf{fma}\left(1, -\frac{\left|x\right|}{x}, 1\right) + \color{blue}{0}\]
  8. Final simplification0

    \[\leadsto \mathsf{fma}\left(1, -\frac{\left|x\right|}{x}, 1\right)\]

Reproduce

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