| Alternative 1 | |
|---|---|
| Error | 9.6 |
| Cost | 960 |
\[\frac{1}{1 + x} + \left(\frac{-2}{x} + \frac{1}{x + -1}\right)
\]
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (+ (/ -2.0 x) (/ 1.0 (+ 1.0 x))) (/ 1.0 (+ x -1.0))))
(t_1 (- (* x x) x)))
(if (<= t_0 -200000000000.0)
(/ -2.0 x)
(if (<= t_0 4e-28)
(* 2.0 (pow x -3.0))
(/
(+ t_1 (* (+ 1.0 x) (+ x (* -2.0 (+ x -1.0)))))
(* t_1 (+ 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 = ((-2.0 / x) + (1.0 / (1.0 + x))) + (1.0 / (x + -1.0));
double t_1 = (x * x) - x;
double tmp;
if (t_0 <= -200000000000.0) {
tmp = -2.0 / x;
} else if (t_0 <= 4e-28) {
tmp = 2.0 * pow(x, -3.0);
} else {
tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / (t_1 * (1.0 + x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (((-2.0d0) / x) + (1.0d0 / (1.0d0 + x))) + (1.0d0 / (x + (-1.0d0)))
t_1 = (x * x) - x
if (t_0 <= (-200000000000.0d0)) then
tmp = (-2.0d0) / x
else if (t_0 <= 4d-28) then
tmp = 2.0d0 * (x ** (-3.0d0))
else
tmp = (t_1 + ((1.0d0 + x) * (x + ((-2.0d0) * (x + (-1.0d0)))))) / (t_1 * (1.0d0 + x))
end if
code = tmp
end function
public static double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
public static double code(double x) {
double t_0 = ((-2.0 / x) + (1.0 / (1.0 + x))) + (1.0 / (x + -1.0));
double t_1 = (x * x) - x;
double tmp;
if (t_0 <= -200000000000.0) {
tmp = -2.0 / x;
} else if (t_0 <= 4e-28) {
tmp = 2.0 * Math.pow(x, -3.0);
} else {
tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / (t_1 * (1.0 + x));
}
return tmp;
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x): t_0 = ((-2.0 / x) + (1.0 / (1.0 + x))) + (1.0 / (x + -1.0)) t_1 = (x * x) - x tmp = 0 if t_0 <= -200000000000.0: tmp = -2.0 / x elif t_0 <= 4e-28: tmp = 2.0 * math.pow(x, -3.0) else: tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / (t_1 * (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(Float64(Float64(-2.0 / x) + Float64(1.0 / Float64(1.0 + x))) + Float64(1.0 / Float64(x + -1.0))) t_1 = Float64(Float64(x * x) - x) tmp = 0.0 if (t_0 <= -200000000000.0) tmp = Float64(-2.0 / x); elseif (t_0 <= 4e-28) tmp = Float64(2.0 * (x ^ -3.0)); else tmp = Float64(Float64(t_1 + Float64(Float64(1.0 + x) * Float64(x + Float64(-2.0 * Float64(x + -1.0))))) / Float64(t_1 * Float64(1.0 + x))); end return tmp end
function tmp = code(x) tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)); end
function tmp_2 = code(x) t_0 = ((-2.0 / x) + (1.0 / (1.0 + x))) + (1.0 / (x + -1.0)); t_1 = (x * x) - x; tmp = 0.0; if (t_0 <= -200000000000.0) tmp = -2.0 / x; elseif (t_0 <= 4e-28) tmp = 2.0 * (x ^ -3.0); else tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / (t_1 * (1.0 + x)); end tmp_2 = 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[(-2.0 / x), $MachinePrecision] + N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[t$95$0, -200000000000.0], N[(-2.0 / x), $MachinePrecision], If[LessEqual[t$95$0, 4e-28], N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 + N[(N[(1.0 + x), $MachinePrecision] * N[(x + N[(-2.0 * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \left(\frac{-2}{x} + \frac{1}{1 + x}\right) + \frac{1}{x + -1}\\
t_1 := x \cdot x - x\\
\mathbf{if}\;t_0 \leq -200000000000:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-28}:\\
\;\;\;\;2 \cdot {x}^{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 + \left(1 + x\right) \cdot \left(x + -2 \cdot \left(x + -1\right)\right)}{t_1 \cdot \left(1 + x\right)}\\
\end{array}
Results
| Original | 9.6 |
|---|---|
| Target | 0.3 |
| Herbie | 0.9 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -2e11Initial program 0.0
Simplified0.0
Taylor expanded in x around 0 0
if -2e11 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 3.99999999999999988e-28Initial program 18.3
Simplified18.3
Taylor expanded in x around inf 2.1
Applied egg-rr1.6
if 3.99999999999999988e-28 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.9
Simplified0.9
Applied egg-rr0.9
Applied egg-rr0.9
Applied egg-rr0.5
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 9.6 |
| Cost | 960 |
| Alternative 2 | |
|---|---|
| Error | 15.6 |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Error | 15.7 |
| Cost | 584 |
| Alternative 4 | |
|---|---|
| Error | 15.7 |
| Cost | 584 |
| Alternative 5 | |
|---|---|
| Error | 10.4 |
| Cost | 448 |
| Alternative 6 | |
|---|---|
| Error | 56.4 |
| Cost | 192 |
| Alternative 7 | |
|---|---|
| Error | 31.2 |
| Cost | 192 |
| Alternative 8 | |
|---|---|
| Error | 61.9 |
| Cost | 64 |

herbie shell --seed 2022291
(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))))