Average Error: 32.7 → 0.0
Time: 1.2s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\frac{\mathsf{fma}\left(-1, \left|x\right|, x\right)}{x}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\frac{\mathsf{fma}\left(-1, \left|x\right|, x\right)}{x}
double code(double x) {
	return ((x / x) - ((1.0 / x) * sqrt((x * x))));
}
double code(double x) {
	return (fma(-1.0, fabs(x), x) / x);
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.7
Target0
Herbie0.0
\[\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 associate-*l/30.3

    \[\leadsto \frac{x}{x} - \color{blue}{\frac{1 \cdot \sqrt{x \cdot x}}{x}}\]
  4. Applied sub-div30.3

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

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

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

Reproduce

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