\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.041063994557665934 \lor \neg \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \le 0.0\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}}{x \cdot 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 VAR;
if ((((((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= -0.041063994557665934) || !((((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= 0.0))) {
VAR = (((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)));
} else {
VAR = fma(2.0, (1.0 / pow(x, 7.0)), fma(2.0, (1.0 / pow(x, 5.0)), ((2.0 / x) / (x * x))));
}
return VAR;
}




Bits error versus x
Results
| Original | 9.9 |
|---|---|
| Target | 0.3 |
| Herbie | 0.4 |
if (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) < -0.041063994557665934 or 0.0 < (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) Initial program 0.7
if -0.041063994557665934 < (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) < 0.0Initial program 19.5
Taylor expanded around inf 0.6
Simplified0.6
rmApplied cube-mult0.6
Applied associate-/r*0.2
Final simplification0.4
herbie shell --seed 2020106 +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))))