(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 -5700627.715827315)
(+ t_0 (- (exp (- (log1p x))) (/ 2.0 x)))
(if (<= t_1 1.247041458181733e-6)
(+
(/ 2.0 (pow x 5.0))
(+ (/ 2.0 (pow x 7.0)) (+ (/ 2.0 (pow x 3.0)) (/ 2.0 (pow x 9.0)))))
(fma -2.0 (+ x (pow x 3.0)) (/ -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 <= -5700627.715827315) {
tmp = t_0 + (exp(-log1p(x)) - (2.0 / x));
} else if (t_1 <= 1.247041458181733e-6) {
tmp = (2.0 / pow(x, 5.0)) + ((2.0 / pow(x, 7.0)) + ((2.0 / pow(x, 3.0)) + (2.0 / pow(x, 9.0))));
} else {
tmp = fma(-2.0, (x + pow(x, 3.0)), (-2.0 / x));
}
return tmp;
}
function code(x) return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0))) end
function code(x) t_0 = Float64(1.0 / Float64(x - 1.0)) t_1 = Float64(Float64(Float64(1.0 / Float64(1.0 + x)) - Float64(2.0 / x)) + t_0) tmp = 0.0 if (t_1 <= -5700627.715827315) tmp = Float64(t_0 + Float64(exp(Float64(-log1p(x))) - Float64(2.0 / x))); elseif (t_1 <= 1.247041458181733e-6) tmp = Float64(Float64(2.0 / (x ^ 5.0)) + Float64(Float64(2.0 / (x ^ 7.0)) + Float64(Float64(2.0 / (x ^ 3.0)) + Float64(2.0 / (x ^ 9.0))))); else tmp = fma(-2.0, Float64(x + (x ^ 3.0)), Float64(-2.0 / x)); end return tmp end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -5700627.715827315], N[(t$95$0 + N[(N[Exp[(-N[Log[1 + x], $MachinePrecision])], $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1.247041458181733e-6], N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 / N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 9.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(x + N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision]]]]]
\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 -5700627.715827315:\\
\;\;\;\;t_0 + \left(e^{-\mathsf{log1p}\left(x\right)} - \frac{2}{x}\right)\\
\mathbf{elif}\;t_1 \leq 1.247041458181733 \cdot 10^{-6}:\\
\;\;\;\;\frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{3}} + \frac{2}{{x}^{9}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-2, x + {x}^{3}, \frac{-2}{x}\right)\\
\end{array}




Bits error versus x
| Original | 9.9 |
|---|---|
| Target | 0.3 |
| Herbie | 0.7 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -5700627.71582731511Initial program 0.0
Applied add-exp-log_binary640.0
Applied 1-exp_binary640.0
Applied div-exp_binary640.0
Simplified0.0
if -5700627.71582731511 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 1.2470414581817e-6Initial program 19.8
Taylor expanded in x around inf 1.2
Simplified1.2
if 1.2470414581817e-6 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.0
Taylor expanded in x around 0 0.5
Simplified0.5
Final simplification0.7
herbie shell --seed 2022131
(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))))