\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\begin{array}{l}
\mathbf{if}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq -30.927103867772345:\\
\;\;\;\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \sqrt[3]{\frac{1}{\left(x - 1\right) \cdot \left(\left(x - 1\right) \cdot \left(x - 1\right)\right)}}\\
\mathbf{elif}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 0:\\
\;\;\;\;\left(\frac{\frac{2}{x}}{x \cdot x} + \frac{2}{{x}^{5}}\right) + \frac{2}{{x}^{7}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\left(x - 1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\
\end{array}(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
:precision binary64
(if (<=
(+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (- x 1.0)))
-30.927103867772345)
(+
(- (/ 1.0 (+ 1.0 x)) (/ 2.0 x))
(cbrt (/ 1.0 (* (- x 1.0) (* (- x 1.0) (- x 1.0))))))
(if (<= (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) 0.0)
(+ (+ (/ (/ 2.0 x) (* x x)) (/ 2.0 (pow x 5.0))) (/ 2.0 (pow x 7.0)))
(/
(+ (* (- x 1.0) (- x (* (+ 1.0 x) 2.0))) (* x (+ 1.0 x)))
(* (- x 1.0) (* x (+ 1.0 x)))))))double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
double tmp;
if ((((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= -30.927103867772345) {
tmp = ((1.0 / (1.0 + x)) - (2.0 / x)) + cbrt(1.0 / ((x - 1.0) * ((x - 1.0) * (x - 1.0))));
} else if ((((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= 0.0) {
tmp = (((2.0 / x) / (x * x)) + (2.0 / pow(x, 5.0))) + (2.0 / pow(x, 7.0));
} else {
tmp = (((x - 1.0) * (x - ((1.0 + x) * 2.0))) + (x * (1.0 + x))) / ((x - 1.0) * (x * (1.0 + x)));
}
return tmp;
}




Bits error versus x
Results
| Original | 9.6 |
|---|---|
| Target | 0.2 |
| Herbie | 0.4 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -30.927103867772345Initial program 0.0
rmApplied add-cbrt-cube_binary64_25010.0
Applied add-cbrt-cube_binary64_25010.0
Applied cbrt-undiv_binary64_24990.0
if -30.927103867772345 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 18.8
Taylor expanded around inf 0.7
Simplified0.7
rmApplied cube-mult_binary64_24950.7
Applied associate-/r*_binary64_24090.3
if 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 1.3
rmApplied frac-sub_binary64_24741.3
Applied frac-add_binary64_24730.8
Final simplification0.4
herbie shell --seed 2021032
(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))))