Average Error: 9.9 → 0.1
Time: 3.3s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\frac{2}{\mathsf{fma}\left(x, x, -1\right)} \cdot \frac{1}{x} \]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{2}{\mathsf{fma}\left(x, x, -1\right)} \cdot \frac{1}{x}
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x) :precision binary64 (* (/ 2.0 (fma x x -1.0)) (/ 1.0 x)))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	return (2.0 / fma(x, x, -1.0)) * (1.0 / x);
}

Error

Bits error versus x

Target

Original9.9
Target0.3
Herbie0.1
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)} \]

Derivation

  1. Initial program 9.9

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Applied egg-rr9.9

    \[\leadsto \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{1 + x}\right) - \frac{2}{x}} \]
  3. Applied egg-rr26.0

    \[\leadsto \color{blue}{\frac{\left(\left(x - 1\right) + \left(1 + x\right)\right) \cdot x - \mathsf{fma}\left(x, x, -1\right) \cdot 2}{\mathsf{fma}\left(x, x, -1\right) \cdot x}} \]
  4. Taylor expanded in x around 0 0.3

    \[\leadsto \frac{\color{blue}{2}}{\mathsf{fma}\left(x, x, -1\right) \cdot x} \]
  5. Applied egg-rr0.1

    \[\leadsto \color{blue}{\frac{2}{\mathsf{fma}\left(x, x, -1\right)} \cdot \frac{1}{x}} \]
  6. Final simplification0.1

    \[\leadsto \frac{2}{\mathsf{fma}\left(x, x, -1\right)} \cdot \frac{1}{x} \]

Reproduce

herbie shell --seed 2022125 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2.0 (* x (- (* x x) 1.0)))

  (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))