Average Error: 32.3 → 4.4
Time: 1.9s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\log \left(e^{\mathsf{fma}\left(-\frac{1}{x}, \left|x\right|, 1\right)}\right)\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\log \left(e^{\mathsf{fma}\left(-\frac{1}{x}, \left|x\right|, 1\right)}\right)
double code(double x) {
	return ((x / x) - ((1.0 / x) * sqrt((x * x))));
}
double code(double x) {
	return log(exp(fma(-(1.0 / x), fabs(x), 1.0)));
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.3
Target0
Herbie4.4
\[\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. Simplified30.6

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

    \[\leadsto \color{blue}{\log \left(e^{\mathsf{fma}\left(-\frac{1}{x}, \left|x\right|, 1\right)}\right)}\]
  5. Final simplification4.4

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

Reproduce

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