Average Error: 33.0 → 4.9
Time: 2.3s
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 ((double) (((double) (x / x)) - ((double) (((double) (1.0 / x)) * ((double) sqrt(((double) (x * x))))))));
}
double code(double x) {
	return ((double) log(((double) exp(((double) fma(((double) -(((double) (1.0 / x)))), ((double) fabs(x)), 1.0))))));
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 33.0

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

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

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

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

Reproduce

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