\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{1}{x - 1}\\
t_1 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + t_0\\
\mathbf{if}\;t_1 \leq -5.505135275469517:\\
\;\;\;\;t_0 + \left(e^{-\mathsf{log1p}\left(x\right)} - \frac{2}{x}\right)\\
\mathbf{elif}\;t_1 \leq 2.538941946223991 \cdot 10^{-11}:\\
\;\;\;\;\frac{2}{{x}^{5}} + \left(\frac{\frac{2}{x \cdot x}}{x} + \frac{2}{{x}^{7}}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 + \left(\left(1 - x\right) + \frac{-2}{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
(let* ((t_0 (/ 1.0 (- x 1.0))) (t_1 (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) t_0)))
(if (<= t_1 -5.505135275469517)
(+ t_0 (- (exp (- (log1p x))) (/ 2.0 x)))
(if (<= t_1 2.538941946223991e-11)
(+ (/ 2.0 (pow x 5.0)) (+ (/ (/ 2.0 (* x x)) x) (/ 2.0 (pow x 7.0))))
(+ t_0 (+ (- 1.0 x) (/ -2.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 t_0 = 1.0 / (x - 1.0);
double t_1 = ((1.0 / (1.0 + x)) - (2.0 / x)) + t_0;
double tmp;
if (t_1 <= -5.505135275469517) {
tmp = t_0 + (exp(-log1p(x)) - (2.0 / x));
} else if (t_1 <= 2.538941946223991e-11) {
tmp = (2.0 / pow(x, 5.0)) + (((2.0 / (x * x)) / x) + (2.0 / pow(x, 7.0)));
} else {
tmp = t_0 + ((1.0 - x) + (-2.0 / x));
}
return tmp;
}




Bits error versus x
Results
| Original | 9.2 |
|---|---|
| Target | 0.3 |
| Herbie | 0.4 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -5.5051352754695166Initial program 0.0
Applied add-exp-log_binary640.0
Applied 1-exp_binary640.0
Applied div-exp_binary640.0
Simplified0.0
if -5.5051352754695166 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 2.5389419462e-11Initial program 18.7
Taylor expanded in x around inf 0.6
Simplified0.6
Applied unpow3_binary640.6
Applied associate-/r*_binary640.2
if 2.5389419462e-11 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.1
Taylor expanded in x around 0 1.2
Simplified1.2
Final simplification0.4
herbie shell --seed 2021224
(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))))