| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13700 |
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (+ 1.0 x)))
(t_1 (/ 1.0 (+ x -1.0)))
(t_2 (- t_0 t_1))
(t_3 (/ 1.0 t_2)))
(if (<= x -240.0)
(-
(*
(+ (/ 1.0 (pow x 2.0)) (+ (/ 1.0 (pow x 6.0)) (/ 1.0 (pow x 4.0))))
2.0))
(if (<= x 380000.0)
(* t_2 (* (- (* t_2 (* t_0 t_3)) (* t_1 (* t_2 t_3))) t_3))
(/ -2.0 (pow x 2.0))))))double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
double code(double x) {
double t_0 = 1.0 / (1.0 + x);
double t_1 = 1.0 / (x + -1.0);
double t_2 = t_0 - t_1;
double t_3 = 1.0 / t_2;
double tmp;
if (x <= -240.0) {
tmp = -(((1.0 / pow(x, 2.0)) + ((1.0 / pow(x, 6.0)) + (1.0 / pow(x, 4.0)))) * 2.0);
} else if (x <= 380000.0) {
tmp = t_2 * (((t_2 * (t_0 * t_3)) - (t_1 * (t_2 * t_3))) * t_3);
} else {
tmp = -2.0 / pow(x, 2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (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) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = 1.0d0 / (1.0d0 + x)
t_1 = 1.0d0 / (x + (-1.0d0))
t_2 = t_0 - t_1
t_3 = 1.0d0 / t_2
if (x <= (-240.0d0)) then
tmp = -(((1.0d0 / (x ** 2.0d0)) + ((1.0d0 / (x ** 6.0d0)) + (1.0d0 / (x ** 4.0d0)))) * 2.0d0)
else if (x <= 380000.0d0) then
tmp = t_2 * (((t_2 * (t_0 * t_3)) - (t_1 * (t_2 * t_3))) * t_3)
else
tmp = (-2.0d0) / (x ** 2.0d0)
end if
code = tmp
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
public static double code(double x) {
double t_0 = 1.0 / (1.0 + x);
double t_1 = 1.0 / (x + -1.0);
double t_2 = t_0 - t_1;
double t_3 = 1.0 / t_2;
double tmp;
if (x <= -240.0) {
tmp = -(((1.0 / Math.pow(x, 2.0)) + ((1.0 / Math.pow(x, 6.0)) + (1.0 / Math.pow(x, 4.0)))) * 2.0);
} else if (x <= 380000.0) {
tmp = t_2 * (((t_2 * (t_0 * t_3)) - (t_1 * (t_2 * t_3))) * t_3);
} else {
tmp = -2.0 / Math.pow(x, 2.0);
}
return tmp;
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
def code(x): t_0 = 1.0 / (1.0 + x) t_1 = 1.0 / (x + -1.0) t_2 = t_0 - t_1 t_3 = 1.0 / t_2 tmp = 0 if x <= -240.0: tmp = -(((1.0 / math.pow(x, 2.0)) + ((1.0 / math.pow(x, 6.0)) + (1.0 / math.pow(x, 4.0)))) * 2.0) elif x <= 380000.0: tmp = t_2 * (((t_2 * (t_0 * t_3)) - (t_1 * (t_2 * t_3))) * t_3) else: tmp = -2.0 / math.pow(x, 2.0) return tmp
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0))) end
function code(x) t_0 = Float64(1.0 / Float64(1.0 + x)) t_1 = Float64(1.0 / Float64(x + -1.0)) t_2 = Float64(t_0 - t_1) t_3 = Float64(1.0 / t_2) tmp = 0.0 if (x <= -240.0) tmp = Float64(-Float64(Float64(Float64(1.0 / (x ^ 2.0)) + Float64(Float64(1.0 / (x ^ 6.0)) + Float64(1.0 / (x ^ 4.0)))) * 2.0)); elseif (x <= 380000.0) tmp = Float64(t_2 * Float64(Float64(Float64(t_2 * Float64(t_0 * t_3)) - Float64(t_1 * Float64(t_2 * t_3))) * t_3)); else tmp = Float64(-2.0 / (x ^ 2.0)); end return tmp end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0)); end
function tmp_2 = code(x) t_0 = 1.0 / (1.0 + x); t_1 = 1.0 / (x + -1.0); t_2 = t_0 - t_1; t_3 = 1.0 / t_2; tmp = 0.0; if (x <= -240.0) tmp = -(((1.0 / (x ^ 2.0)) + ((1.0 / (x ^ 6.0)) + (1.0 / (x ^ 4.0)))) * 2.0); elseif (x <= 380000.0) tmp = t_2 * (((t_2 * (t_0 * t_3)) - (t_1 * (t_2 * t_3))) * t_3); else tmp = -2.0 / (x ^ 2.0); end tmp_2 = tmp; end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 / t$95$2), $MachinePrecision]}, If[LessEqual[x, -240.0], (-N[(N[(N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), If[LessEqual[x, 380000.0], N[(t$95$2 * N[(N[(N[(t$95$2 * N[(t$95$0 * t$95$3), $MachinePrecision]), $MachinePrecision] - N[(t$95$1 * N[(t$95$2 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{1}{1 + x}\\
t_1 := \frac{1}{x + -1}\\
t_2 := t_0 - t_1\\
t_3 := \frac{1}{t_2}\\
\mathbf{if}\;x \leq -240:\\
\;\;\;\;-\left(\frac{1}{{x}^{2}} + \left(\frac{1}{{x}^{6}} + \frac{1}{{x}^{4}}\right)\right) \cdot 2\\
\mathbf{elif}\;x \leq 380000:\\
\;\;\;\;t_2 \cdot \left(\left(t_2 \cdot \left(t_0 \cdot t_3\right) - t_1 \cdot \left(t_2 \cdot t_3\right)\right) \cdot t_3\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{{x}^{2}}\\
\end{array}
Results
if x < -240Initial program 29.4
Taylor expanded in x around inf 0.7
Simplified0.7
[Start]0.7 | \[ -\left(2 \cdot \frac{1}{{x}^{6}} + \left(2 \cdot \frac{1}{{x}^{4}} + 2 \cdot \frac{1}{{x}^{2}}\right)\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-82 [=>]0.7 | \[ -\color{blue}{\left(2 \cdot \frac{1}{{x}^{4}} + \left(2 \cdot \frac{1}{{x}^{6}} + 2 \cdot \frac{1}{{x}^{2}}\right)\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.7 | \[ -\left(2 \cdot \frac{1}{{x}^{4}} + \left(\color{blue}{\frac{1}{{x}^{6}} \cdot 2} + 2 \cdot \frac{1}{{x}^{2}}\right)\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-23 [=>]0.7 | \[ -\left(2 \cdot \frac{1}{{x}^{4}} + \color{blue}{2 \cdot \left(\frac{1}{{x}^{6}} + \frac{1}{{x}^{2}}\right)}\right)
\] |
Applied egg-rr0.7
if -240 < x < 3.8e5Initial program 0.1
Applied egg-rr0.1
Applied egg-rr0.1
Simplified0.1
[Start]0.1 | \[ \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}} \cdot \left(\left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right)\right)\right) \cdot \frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.1 | \[ \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{\frac{1}{\color{blue}{x + 1}} - \frac{1}{x + -1}} \cdot \left(\left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right)\right)\right) \cdot \frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [<=]0.1 | \[ \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{\frac{1}{x + 1} - \frac{1}{x + -1}} \cdot \left(\left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \color{blue}{\left(\left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) + 0\right)}\right)\right) \cdot \frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [<=]0.1 | \[ \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{\frac{1}{x + 1} - \frac{1}{x + -1}} \cdot \left(\left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \color{blue}{\left(0 + \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right)\right)}\right)\right) \cdot \frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-108 [=>]0.1 | \[ \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{\frac{1}{x + 1} - \frac{1}{x + -1}} \cdot \left(\left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \color{blue}{\left(\left(\frac{1}{1 + x} + 0\right) - \frac{1}{x + -1}\right)}\right)\right) \cdot \frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.1 | \[ \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{\frac{1}{x + 1} - \frac{1}{x + -1}} \cdot \left(\left(\frac{1}{\color{blue}{x + 1}} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{1 + x} + 0\right) - \frac{1}{x + -1}\right)\right)\right) \cdot \frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [=>]0.1 | \[ \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{\frac{1}{x + 1} - \frac{1}{x + -1}} \cdot \left(\left(\frac{1}{x + 1} - \frac{1}{x + -1}\right) \cdot \left(\color{blue}{\frac{1}{1 + x}} - \frac{1}{x + -1}\right)\right)\right) \cdot \frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.1 | \[ \left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{\frac{1}{x + 1} - \frac{1}{x + -1}} \cdot \left(\left(\frac{1}{x + 1} - \frac{1}{x + -1}\right) \cdot \left(\frac{1}{\color{blue}{x + 1}} - \frac{1}{x + -1}\right)\right)\right) \cdot \frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}\right)
\] |
Applied egg-rr0.1
if 3.8e5 < x Initial program 28.4
Taylor expanded in x around inf 0.8
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13700 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 6920 |
| Alternative 3 | |
|---|---|
| Error | 15.7 |
| Cost | 840 |
| Alternative 4 | |
|---|---|
| Error | 14.6 |
| Cost | 704 |
| Alternative 5 | |
|---|---|
| Error | 57.3 |
| Cost | 64 |
| Alternative 6 | |
|---|---|
| Error | 32.1 |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))