\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\begin{array}{l}
\mathbf{if}\;x \le -108.8867958097667:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)\\
\mathbf{elif}\;x \le 129.8241176321693:\\
\;\;\;\;\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 ((x <= -108.88679580976668)) {
temp = fma(2.0, (1.0 / pow(x, 7.0)), fma(2.0, (1.0 / pow(x, 5.0)), (2.0 / pow(x, 3.0))));
} else {
double temp_1;
if ((x <= 129.8241176321693)) {
temp_1 = (((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)));
} else {
temp_1 = fma(2.0, (1.0 / pow(x, 7.0)), fma(2.0, (1.0 / pow(x, 5.0)), ((2.0 / (x * x)) / x)));
}
temp = temp_1;
}
return temp;
}




Bits error versus x
Results
| Original | 9.9 |
|---|---|
| Target | 0.2 |
| Herbie | 0.1 |
if x < -108.88679580976668Initial program 20.3
Taylor expanded around inf 0.4
Simplified0.4
if -108.88679580976668 < x < 129.8241176321693Initial program 0.0
if 129.8241176321693 < x Initial program 19.1
Taylor expanded around inf 0.5
Simplified0.5
rmApplied unpow30.5
Applied associate-/r*0.1
Final simplification0.1
herbie shell --seed 2020065 +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))))