Average Error: 32.1 → 0
Time: 1.5s
Precision: binary64
\[\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}
(FPCore (x) :precision binary64 (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))
(FPCore (x) :precision binary64 (- 1.0 (* 1.0 (/ (fabs x) x))))
double code(double x) {
	return ((double) ((x / x) - ((double) ((1.0 / x) * ((double) sqrt(((double) (x * x))))))));
}
double code(double x) {
	return ((double) (1.0 - ((double) (1.0 * (((double) fabs(x)) / x)))));
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program Error: 32.1 bits

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
  2. SimplifiedError: 4.7 bits

    \[\leadsto \color{blue}{1 - \frac{1}{x} \cdot \left|x\right|}\]
  3. Using strategy rm
  4. Applied div-invError: 4.7 bits

    \[\leadsto 1 - \color{blue}{\left(1 \cdot \frac{1}{x}\right)} \cdot \left|x\right|\]
  5. Applied associate-*l*Error: 4.7 bits

    \[\leadsto 1 - \color{blue}{1 \cdot \left(\frac{1}{x} \cdot \left|x\right|\right)}\]
  6. SimplifiedError: 0 bits

    \[\leadsto 1 - 1 \cdot \color{blue}{\frac{\left|x\right|}{x}}\]
  7. Final simplificationError: 0 bits

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

Reproduce

herbie shell --seed 2020205 
(FPCore (x)
  :name "sqrt sqr"
  :precision binary64

  :herbie-target
  (if (< x 0.0) 2.0 0.0)

  (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))