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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 32.3

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
  2. Using strategy rm
  3. Applied add-cube-cbrt32.3

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

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

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

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

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

Reproduce

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