Average Error: 32.6 → 0
Time: 990.0ms
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 code(double x) {
	return ((x / x) - ((1.0 / x) * sqrt((x * x))));
}
double code(double x) {
	return (1.0 - (1.0 * (fabs(x) / x)));
}

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. Simplified31.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(-\frac{1}{x}, \left|x\right|, 1\right)}\]
  3. Taylor expanded around 0 0

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

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

Reproduce

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