| Alternative 1 | |
|---|---|
| Error | 0.0 |
| Cost | 1344 |
\[\frac{-3}{1 - x} \cdot \frac{x}{-1 - x} + \frac{-1}{\left(1 - x\right) \cdot \left(-1 - x\right)}
\]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
:precision binary64
(if (<= x -4000000000.0)
(/ (+ -3.0 (/ -1.0 x)) x)
(if (<= x 2e+14)
(/ (+ -1.0 (* -3.0 x)) (* (- 1.0 x) (- -1.0 x)))
(/ -3.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 <= -4000000000.0) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else if (x <= 2e+14) {
tmp = (-1.0 + (-3.0 * x)) / ((1.0 - x) * (-1.0 - x));
} else {
tmp = -3.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 <= (-4000000000.0d0)) then
tmp = ((-3.0d0) + ((-1.0d0) / x)) / x
else if (x <= 2d+14) then
tmp = ((-1.0d0) + ((-3.0d0) * x)) / ((1.0d0 - x) * ((-1.0d0) - x))
else
tmp = (-3.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 <= -4000000000.0) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else if (x <= 2e+14) {
tmp = (-1.0 + (-3.0 * x)) / ((1.0 - x) * (-1.0 - x));
} else {
tmp = -3.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 <= -4000000000.0: tmp = (-3.0 + (-1.0 / x)) / x elif x <= 2e+14: tmp = (-1.0 + (-3.0 * x)) / ((1.0 - x) * (-1.0 - x)) else: tmp = -3.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 (x <= -4000000000.0) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); elseif (x <= 2e+14) tmp = Float64(Float64(-1.0 + Float64(-3.0 * x)) / Float64(Float64(1.0 - x) * Float64(-1.0 - x))); else tmp = Float64(-3.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 <= -4000000000.0) tmp = (-3.0 + (-1.0 / x)) / x; elseif (x <= 2e+14) tmp = (-1.0 + (-3.0 * x)) / ((1.0 - x) * (-1.0 - x)); else tmp = -3.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[x, -4000000000.0], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 2e+14], N[(N[(-1.0 + N[(-3.0 * x), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-3.0 / x), $MachinePrecision]]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -4000000000:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+14}:\\
\;\;\;\;\frac{-1 + -3 \cdot x}{\left(1 - x\right) \cdot \left(-1 - x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-3}{x}\\
\end{array}
Results
if x < -4e9Initial program 60.1
Simplified60.1
Taylor expanded in x around inf 0.3
Simplified0.0
Applied egg-rr0.0
if -4e9 < x < 2e14Initial program 0.5
Simplified0.5
Applied egg-rr0.5
Taylor expanded in x around 0 0.0
if 2e14 < x Initial program 60.4
Simplified60.4
Taylor expanded in x around inf 0.0
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 0.0 |
| Cost | 1344 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 1097 |
| Alternative 3 | |
|---|---|
| Error | 0.7 |
| Cost | 713 |
| Alternative 4 | |
|---|---|
| Error | 0.6 |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Error | 1.0 |
| Cost | 584 |
| Alternative 6 | |
|---|---|
| Error | 1.4 |
| Cost | 456 |
| Alternative 7 | |
|---|---|
| Error | 31.6 |
| Cost | 64 |
herbie shell --seed 2022340
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))