\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\begin{array}{l}
\mathbf{if}\;\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \le -0.033504988994731283 \lor \neg \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \le 1.7156110759 \cdot 10^{-8}\right):\\
\;\;\;\;\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{\frac{2}{x \cdot x}}{x}\right)\right)\\
\end{array}double code(double x) {
return (((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)));
}
double code(double x) {
double temp;
if ((((((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= -0.03350498899473128) || !((((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= 1.715611075902776e-08))) {
temp = (((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)));
} else {
temp = fma(2.0, (1.0 / pow(x, 7.0)), fma(2.0, (1.0 / pow(x, 5.0)), ((2.0 / (x * x)) / x)));
}
return temp;
}




Bits error versus x
Results
| Original | 10.0 |
|---|---|
| Target | 0.3 |
| Herbie | 0.1 |
if (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) < -0.03350498899473128 or 1.715611075902776e-08 < (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) Initial program 0.0
if -0.03350498899473128 < (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) < 1.715611075902776e-08Initial program 19.7
Taylor expanded around inf 0.7
Simplified0.7
rmApplied unpow30.7
Applied associate-/r*0.2
Final simplification0.1
herbie shell --seed 2020049 +o rules:numerics
(FPCore (x)
:name "3frac (problem 3.3.3)"
:precision binary64
:herbie-target
(/ 2 (* x (- (* x x) 1)))
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))))