| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 1732 |
\[\begin{array}{l}
t_0 := \frac{x}{x + 1} - \frac{x + 1}{x + -1}\\
\mathbf{if}\;t_0 \leq 10^{-10}:\\
\;\;\;\;\frac{-3 + \frac{2 + \frac{-2}{x}}{x}}{x + -1}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
:precision binary64
(if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (+ x -1.0))) 1e-10)
(/
(- (+ 3.0 (/ 2.0 (* x x))) (+ (/ 2.0 x) (/ 2.0 (pow x 3.0))))
(/ (+ x -1.0) -1.0))
(/ (- (/ (+ x -1.0) (+ x 1.0)) (/ (+ x 1.0) x)) (+ 1.0 (/ -1.0 x)))))double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x + -1.0))) <= 1e-10) {
tmp = ((3.0 + (2.0 / (x * x))) - ((2.0 / x) + (2.0 / pow(x, 3.0)))) / ((x + -1.0) / -1.0);
} else {
tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x / (x + 1.0d0)) - ((x + 1.0d0) / (x + (-1.0d0)))) <= 1d-10) then
tmp = ((3.0d0 + (2.0d0 / (x * x))) - ((2.0d0 / x) + (2.0d0 / (x ** 3.0d0)))) / ((x + (-1.0d0)) / (-1.0d0))
else
tmp = (((x + (-1.0d0)) / (x + 1.0d0)) - ((x + 1.0d0) / x)) / (1.0d0 + ((-1.0d0) / x))
end if
code = tmp
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
public static double code(double x) {
double tmp;
if (((x / (x + 1.0)) - ((x + 1.0) / (x + -1.0))) <= 1e-10) {
tmp = ((3.0 + (2.0 / (x * x))) - ((2.0 / x) + (2.0 / Math.pow(x, 3.0)))) / ((x + -1.0) / -1.0);
} else {
tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x));
}
return tmp;
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
def code(x): tmp = 0 if ((x / (x + 1.0)) - ((x + 1.0) / (x + -1.0))) <= 1e-10: tmp = ((3.0 + (2.0 / (x * x))) - ((2.0 / x) + (2.0 / math.pow(x, 3.0)))) / ((x + -1.0) / -1.0) else: tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x)) return tmp
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x + -1.0))) <= 1e-10) tmp = Float64(Float64(Float64(3.0 + Float64(2.0 / Float64(x * x))) - Float64(Float64(2.0 / x) + Float64(2.0 / (x ^ 3.0)))) / Float64(Float64(x + -1.0) / -1.0)); else tmp = Float64(Float64(Float64(Float64(x + -1.0) / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / x)) / Float64(1.0 + Float64(-1.0 / x))); end return tmp end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
function tmp_2 = code(x) tmp = 0.0; if (((x / (x + 1.0)) - ((x + 1.0) / (x + -1.0))) <= 1e-10) tmp = ((3.0 + (2.0 / (x * x))) - ((2.0 / x) + (2.0 / (x ^ 3.0)))) / ((x + -1.0) / -1.0); else tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x)); end tmp_2 = tmp; end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-10], N[(N[(N[(3.0 + N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(2.0 / x), $MachinePrecision] + N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x + -1.0), $MachinePrecision] / -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x + -1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x + -1} \leq 10^{-10}:\\
\;\;\;\;\frac{\left(3 + \frac{2}{x \cdot x}\right) - \left(\frac{2}{x} + \frac{2}{{x}^{3}}\right)}{\frac{x + -1}{-1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + -1}{x + 1} - \frac{x + 1}{x}}{1 + \frac{-1}{x}}\\
\end{array}
Results
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1.00000000000000004e-10Initial program 59.4
Applied egg-rr59.3
Simplified58.8
Taylor expanded in x around inf 0.2
Simplified0.2
if 1.00000000000000004e-10 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 0.2
Applied egg-rr0.3
Taylor expanded in x around 0 0.3
Applied egg-rr0.3
Simplified0.3
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 1732 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 1480 |
| Alternative 3 | |
|---|---|
| Error | 0.1 |
| Cost | 1352 |
| Alternative 4 | |
|---|---|
| Error | 0.1 |
| Cost | 1096 |
| Alternative 5 | |
|---|---|
| Error | 0.9 |
| Cost | 840 |
| Alternative 6 | |
|---|---|
| Error | 0.6 |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Error | 0.6 |
| Cost | 840 |
| Alternative 8 | |
|---|---|
| Error | 0.6 |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Error | 0.9 |
| Cost | 584 |
| Alternative 10 | |
|---|---|
| Error | 1.2 |
| Cost | 456 |
| Alternative 11 | |
|---|---|
| Error | 31.8 |
| Cost | 64 |
herbie shell --seed 2022328
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))