\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\\
t_1 := \frac{\mathsf{fma}\left(\frac{1}{1 + x}, x, -2\right) - \log \left(e^{\frac{x}{1 - x}}\right)}{x}\\
\mathbf{if}\;t_0 \leq -13.837372505796882:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{2}{x \cdot x}\right)\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\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)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(t_1
(/ (- (fma (/ 1.0 (+ 1.0 x)) x -2.0) (log (exp (/ x (- 1.0 x))))) x)))
(if (<= t_0 -13.837372505796882)
t_1
(if (<= t_0 0.0) (/ (log1p (expm1 (/ 2.0 (* x x)))) x) t_1))))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)) - (2.0 / x)) + (1.0 / (x - 1.0));
double t_1 = (fma((1.0 / (1.0 + x)), x, -2.0) - log(exp((x / (1.0 - x))))) / x;
double tmp;
if (t_0 <= -13.837372505796882) {
tmp = t_1;
} else if (t_0 <= 0.0) {
tmp = log1p(expm1((2.0 / (x * x)))) / x;
} else {
tmp = t_1;
}
return tmp;
}




Bits error versus x
| Original | 9.7 |
|---|---|
| Target | 0.3 |
| Herbie | 0.6 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -13.837372505796882 or 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.6
Applied egg-rr0.6
Applied egg-rr0.6
if -13.837372505796882 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 19.0
Applied egg-rr31.6
Taylor expanded in x around inf 0.5
Applied egg-rr0.5
Final simplification0.6
herbie shell --seed 2022129
(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))))