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




Bits error versus x
| Original | 10.1 |
|---|---|
| Target | 0.3 |
| Herbie | 0.5 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -17.6395332904432216Initial program 0.0
if -17.6395332904432216 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 1.2570223e-16Initial program 20.2
Taylor expanded in x around inf 0.9
Simplified0.9
Applied cube-mult_binary640.9
Applied associate-/r*_binary640.5
if 1.2570223e-16 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.2
Applied expm1-log1p-u_binary645.8
Taylor expanded in x around 0 1.1
Simplified1.1
Final simplification0.5
herbie shell --seed 2022088
(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))))