Average Error: 9.9 → 0.1
Time: 4.3s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\frac{\frac{2}{x}}{\mathsf{fma}\left(x, x, -1\right)} \]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{2}{x}}{\mathsf{fma}\left(x, x, -1\right)}
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x) :precision binary64 (/ (/ 2.0 x) (fma x x -1.0)))
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 / x) / fma(x, x, -1.0);
}

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 egg9.9

    \[\leadsto \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{1 + x}\right) + \frac{-2}{x}} \]
  3. Applied egg26.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 egg0.1

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

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

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))))