Average Error: 9.7 → 0.1
Time: 6.6s
Precision: binary64
Cost: 6976
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\frac{\frac{2}{x + -1}}{\mathsf{fma}\left(x, x, x\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 -1.0)) (fma x x 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 / (x + -1.0)) / fma(x, x, x);
}
function code(x)
	return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0)))
end
function code(x)
	return Float64(Float64(2.0 / Float64(x + -1.0)) / fma(x, x, x))
end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(x * x + x), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{2}{x + -1}}{\mathsf{fma}\left(x, x, x\right)}

Error

Target

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

Derivation

  1. Initial program 9.7

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

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

    \[\leadsto \frac{\color{blue}{2}}{\left(x \cdot \left(1 + x\right)\right) \cdot \left(x + -1\right)} \]
  4. Applied egg-rr0.1

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

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

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

Alternatives

Alternative 1
Error0.9
Cost968
\[\begin{array}{l} t_0 := \frac{2}{x \cdot x} \cdot \frac{1}{x + -1}\\ \mathbf{if}\;x \leq -16375921.992846377:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.8168229154669971:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error1.1
Cost840
\[\begin{array}{l} t_0 := \frac{2}{\left(x + -1\right) \cdot \left(x \cdot x\right)}\\ \mathbf{if}\;x \leq -16375921.992846377:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.8168229154669971:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error15.2
Cost712
\[\begin{array}{l} t_0 := \frac{-2}{x \cdot x}\\ \mathbf{if}\;x \leq -16375921.992846377:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.8168229154669971:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.3
Cost704
\[\frac{2}{\left(x \cdot \left(x + 1\right)\right) \cdot \left(x + -1\right)} \]
Alternative 5
Error15.8
Cost584
\[\begin{array}{l} t_0 := \frac{-2}{x \cdot x}\\ \mathbf{if}\;x \leq -16375921.992846377:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.1340352893459627 \cdot 10^{-14}:\\ \;\;\;\;\frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error15.6
Cost448
\[\frac{2}{x \cdot \left(x + -1\right)} \]
Alternative 7
Error10.5
Cost448
\[-1 + \left(1 - \frac{2}{x}\right) \]
Alternative 8
Error56.4
Cost192
\[\frac{-1}{x} \]
Alternative 9
Error30.6
Cost192
\[\frac{-2}{x} \]

Error

Reproduce

herbie shell --seed 2022318 
(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))))