(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 -50.0)
t_0
(if (<= t_0 2e-19)
(* 2.0 (+ (pow x -3.0) (pow x -5.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 / (1.0 + x)) + (-2.0 / x)) + (1.0 / (x + -1.0));
double tmp;
if (t_0 <= -50.0) {
tmp = t_0;
} else if (t_0 <= 2e-19) {
tmp = 2.0 * (pow(x, -3.0) + pow(x, -5.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(Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(-2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) tmp = 0.0 if (t_0 <= -50.0) tmp = t_0; elseif (t_0 <= 2e-19) tmp = Float64(2.0 * Float64((x ^ -3.0) + (x ^ -5.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[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -50.0], t$95$0, If[LessEqual[t$95$0, 2e-19], N[(2.0 * N[(N[Power[x, -3.0], $MachinePrecision] + N[Power[x, -5.0], $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 := \left(\frac{1}{1 + x} + \frac{-2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_0 \leq -50:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-19}:\\
\;\;\;\;2 \cdot \left({x}^{-3} + {x}^{-5}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-2, x + {x}^{3}, \frac{-2}{x}\right)\\
\end{array}
| Original | 10.4 |
|---|---|
| Target | 0.4 |
| Herbie | 0.4 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -50Initial program 0.0
if -50 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 2e-19Initial program 20.6
Taylor expanded in x around inf 0.9
Simplified0.9
Applied egg-rr0.2
if 2e-19 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.3
Taylor expanded in x around 0 1.3
Simplified1.3
Final simplification0.4
herbie shell --seed 2022190
(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))))