\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 -5.4337115324627003 \lor \neg \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \le 0.0\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(1 \cdot x - \left(x + 1\right) \cdot 2, x - 1, \left(\left(x + 1\right) \cdot x\right) \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}\\
\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))) <= -5.4337115324627) || !((((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= 0.0))) {
VAR = (fma(((1.0 * x) - ((x + 1.0) * 2.0)), (x - 1.0), (((x + 1.0) * x) * 1.0)) / (((x + 1.0) * x) * (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.6 |
|---|---|
| Target | 0.3 |
| Herbie | 0.5 |
if (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) < -5.4337115324627 or 0.0 < (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) Initial program 0.7
rmApplied frac-sub0.8
Applied frac-add0.5
Simplified0.7
if -5.4337115324627 < (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) < 0.0Initial program 18.9
Taylor expanded around inf 0.7
Simplified0.7
rmApplied cube-mult0.7
Applied associate-/r*0.3
Final simplification0.5
herbie shell --seed 2020091 +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))))