(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))))
(t_1
(/
(+ (* x (+ (+ x -1.0) (+ 1.0 x))) (* (fma x x -1.0) -2.0))
(* x (fma x x -1.0)))))
(if (<= t_0 -0.5)
t_1
(if (<= t_0 5e-23)
(+ (* 2.0 (pow x -3.0)) (+ (/ 2.0 (pow x 5.0)) (/ 2.0 (pow x 7.0))))
t_1))))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 t_1 = ((x * ((x + -1.0) + (1.0 + x))) + (fma(x, x, -1.0) * -2.0)) / (x * fma(x, x, -1.0));
double tmp;
if (t_0 <= -0.5) {
tmp = t_1;
} else if (t_0 <= 5e-23) {
tmp = (2.0 * pow(x, -3.0)) + ((2.0 / pow(x, 5.0)) + (2.0 / pow(x, 7.0)));
} else {
tmp = t_1;
}
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))) t_1 = Float64(Float64(Float64(x * Float64(Float64(x + -1.0) + Float64(1.0 + x))) + Float64(fma(x, x, -1.0) * -2.0)) / Float64(x * fma(x, x, -1.0))) tmp = 0.0 if (t_0 <= -0.5) tmp = t_1; elseif (t_0 <= 5e-23) tmp = Float64(Float64(2.0 * (x ^ -3.0)) + Float64(Float64(2.0 / (x ^ 5.0)) + Float64(2.0 / (x ^ 7.0)))); else tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(N[(x * N[(N[(x + -1.0), $MachinePrecision] + N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(x * x + -1.0), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.5], t$95$1, If[LessEqual[t$95$0, 5e-23], N[(N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\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}\\
t_1 := \frac{x \cdot \left(\left(x + -1\right) + \left(1 + x\right)\right) + \mathsf{fma}\left(x, x, -1\right) \cdot -2}{x \cdot \mathsf{fma}\left(x, x, -1\right)}\\
\mathbf{if}\;t_0 \leq -0.5:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-23}:\\
\;\;\;\;2 \cdot {x}^{-3} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{7}}\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
| Original | 10.2 |
|---|---|
| Target | 0.3 |
| Herbie | 0.0 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -0.5 or 5.0000000000000002e-23 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.2
Applied egg-rr0.2
Applied egg-rr0.0
if -0.5 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 5.0000000000000002e-23Initial program 20.6
Taylor expanded in x around inf 0.7
Simplified0.7
Applied egg-rr0.1
Final simplification0.0
herbie shell --seed 2022209
(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))))