(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 -13.837372505796882)
(+ t_0 (/ (- x (+ 2.0 (* x 2.0))) (fma x x x)))
(if (<= t_1 0.0)
(/ (/ (/ 2.0 x) x) x)
(+ t_0 (/ (log (exp (- -2.0 x))) (fma x x 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 <= -13.837372505796882) {
tmp = t_0 + ((x - (2.0 + (x * 2.0))) / fma(x, x, x));
} else if (t_1 <= 0.0) {
tmp = ((2.0 / x) / x) / x;
} else {
tmp = t_0 + (log(exp((-2.0 - x))) / fma(x, x, 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 <= -13.837372505796882) tmp = Float64(t_0 + Float64(Float64(x - Float64(2.0 + Float64(x * 2.0))) / fma(x, x, x))); elseif (t_1 <= 0.0) tmp = Float64(Float64(Float64(2.0 / x) / x) / x); else tmp = Float64(t_0 + Float64(log(exp(Float64(-2.0 - x))) / fma(x, x, 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, -13.837372505796882], N[(t$95$0 + N[(N[(x - N[(2.0 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[(N[(2.0 / x), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision], N[(t$95$0 + N[(N[Log[N[Exp[N[(-2.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[(x * x + x), $MachinePrecision]), $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 -13.837372505796882:\\
\;\;\;\;t_0 + \frac{x - \left(2 + x \cdot 2\right)}{\mathsf{fma}\left(x, x, x\right)}\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\frac{\frac{\frac{2}{x}}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;t_0 + \frac{\log \left(e^{-2 - x}\right)}{\mathsf{fma}\left(x, x, x\right)}\\
\end{array}




Bits error versus x
| Original | 9.7 |
|---|---|
| Target | 0.3 |
| Herbie | 0.7 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -13.837372505796882Initial program 0.0
Applied frac-sub_binary640.0
Simplified0.0
Simplified0.0
if -13.837372505796882 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 19.0
Taylor expanded in x around inf 1.0
Applied cube-mult_binary641.0
Applied associate-/r*_binary640.5
Applied associate-/r*_binary640.5
if 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 1.2
Applied frac-sub_binary641.3
Simplified1.3
Simplified1.3
Applied add-log-exp_binary641.9
Applied add-log-exp_binary641.9
Applied sum-log_binary641.9
Applied add-log-exp_binary641.9
Applied diff-log_binary641.9
Simplified1.7
Final simplification0.7
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))))