\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 -4353305.628193324:\\
\;\;\;\;\frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)\\
\mathbf{elif}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 0:\\
\;\;\;\;-2 \cdot \left(-{x}^{-3}\right)\\
\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)))
-4353305.628193324)
(- (/ 1.0 (+ 1.0 x)) (- (/ 2.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 (- (pow x -3.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))) <= -4353305.628193324) {
tmp = (1.0 / (1.0 + x)) - ((2.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 * -pow(x, -3.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 | 10.0 |
|---|---|
| Target | 0.3 |
| Herbie | 0.6 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -4353305.6281933244Initial program 0.0
rmApplied associate-+l-_binary64_10360.0
Simplified0.0
if -4353305.6281933244 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 19.3
rmApplied add-exp-log_binary64_113920.4
Simplified20.4
Taylor expanded around -inf 64.0
Simplified0.8
if 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 1.4
rmApplied frac-sub_binary64_11101.5
Applied frac-add_binary64_11090.8
Final simplification0.6
herbie shell --seed 2021019
(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))))