\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 -1.0871063920152996 \cdot 10^{-06}:\\
\;\;\;\;\frac{x \cdot \left(x - 1\right) + \left(1 + x\right) \cdot \left(x - 2 \cdot \left(x - 1\right)\right)}{{x}^{3} - x}\\
\mathbf{elif}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 1.6543612251060553 \cdot 10^{-24}:\\
\;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x - 1} + \frac{x - \left(1 + x\right) \cdot 2}{x \cdot \left(1 + x\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)))
-1.0871063920152996e-06)
(/
(+ (* x (- x 1.0)) (* (+ 1.0 x) (- x (* 2.0 (- x 1.0)))))
(- (pow x 3.0) x))
(if (<=
(+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (- x 1.0)))
1.6543612251060553e-24)
(+ (/ 2.0 (pow x 7.0)) (+ (/ 2.0 (pow x 5.0)) (/ 2.0 (pow x 3.0))))
(+ (/ 1.0 (- x 1.0)) (/ (- x (* (+ 1.0 x) 2.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))) <= -1.0871063920152996e-06) {
tmp = ((x * (x - 1.0)) + ((1.0 + x) * (x - (2.0 * (x - 1.0))))) / (pow(x, 3.0) - x);
} else if ((((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= 1.6543612251060553e-24) {
tmp = (2.0 / pow(x, 7.0)) + ((2.0 / pow(x, 5.0)) + (2.0 / pow(x, 3.0)));
} else {
tmp = (1.0 / (x - 1.0)) + ((x - ((1.0 + x) * 2.0)) / (x * (1.0 + x)));
}
return tmp;
}








Bits error versus x
Results
| Original | 9.6 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
| Alternative 1 | |
|---|---|
| Accuracy | 0.3 |
| Cost | 3586 |
| Alternative 2 | |
|---|---|
| Accuracy | 0.2 |
| Cost | 1796 |
| Alternative 3 | |
|---|---|
| Accuracy | 9.6 |
| Cost | 1408 |
| Alternative 4 | |
|---|---|
| Accuracy | 25.3 |
| Cost | 1472 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -1.0871063920153e-6Initial program 0.0
rmApplied sub-neg_binary64_31400.0
Applied associate-+l+_binary64_30800.0
Simplified0.0
rmApplied frac-sub_binary64_31560.0
Applied frac-add_binary64_31550.0
Simplified0.0
Simplified0.0
if -1.0871063920153e-6 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 1.65436e-24Initial program 19.5
rmApplied sub-neg_binary64_314019.5
Applied associate-+l+_binary64_308019.5
Simplified19.5
rmApplied *-un-lft-identity_binary64_314719.5
Applied *-un-lft-identity_binary64_314719.5
Applied times-frac_binary64_315319.5
Applied *-un-lft-identity_binary64_314719.5
Applied *-un-lft-identity_binary64_314719.5
Applied times-frac_binary64_315319.5
Applied distribute-lft-out--_binary64_309919.5
Applied *-un-lft-identity_binary64_314719.5
Applied *-un-lft-identity_binary64_314719.5
Applied times-frac_binary64_315319.5
Applied distribute-lft-out_binary64_309819.5
Simplified19.5
Taylor expanded around inf 0.4
Simplified0.4
if 1.65436e-24 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.6
rmApplied frac-sub_binary64_31560.6
Simplified0.6
Simplified0.6
Final simplification0.3
herbie shell --seed 2020338
(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))))