Average Error: 32.0 → 0
Time: 1.7s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[-1 \cdot \frac{\left|x\right|}{x} + 1\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
-1 \cdot \frac{\left|x\right|}{x} + 1
double code(double x) {
	return ((x / x) - ((1.0 / x) * sqrt((x * x))));
}
double code(double x) {
	return ((-1.0 * (fabs(x) / x)) + 1.0);
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.0

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
  2. Simplified30.7

    \[\leadsto \color{blue}{\mathsf{fma}\left(-\frac{1}{x}, \left|x\right|, 1\right)}\]
  3. Using strategy rm
  4. Applied fma-udef4.3

    \[\leadsto \color{blue}{\left(-\frac{1}{x}\right) \cdot \left|x\right| + 1}\]
  5. Taylor expanded around 0 0

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

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

Reproduce

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