(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 (fma -2.0 x -2.0)) (fma x x x)))
(if (<= t_1 0.0)
(/ (/ (/ 2.0 x) x) x)
(+ t_0 (/ (- x (* (+ 1.0 x) 2.0)) (* x (+ 1.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 <= -13.837372505796882) {
tmp = t_0 + ((x + fma(-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 + ((x - ((1.0 + x) * 2.0)) / (x * (1.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 <= -13.837372505796882) tmp = Float64(t_0 + Float64(Float64(x + fma(-2.0, 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(Float64(x - Float64(Float64(1.0 + x) * 2.0)) / Float64(x * Float64(1.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, -13.837372505796882], N[(t$95$0 + N[(N[(x + N[(-2.0 * x + -2.0), $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[(x - N[(N[(1.0 + x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] / N[(x * N[(1.0 + x), $MachinePrecision]), $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 + \mathsf{fma}\left(-2, x, -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{x - \left(1 + x\right) \cdot 2}{x \cdot \left(1 + x\right)}\\
\end{array}




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.837372505796882Initial program 0.0
Applied frac-sub_binary640.0
Simplified0.0
Simplified0.0
Applied sub-neg_binary640.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
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))))