| Alternative 1 | |
|---|---|
| Error | 0.35% |
| Cost | 14532 |
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
:precision binary64
(let* ((t_0 (/ (- -1.0 x) (+ x -1.0)))
(t_1 (pow t_0 2.0))
(t_2 (/ x (- -1.0 x)))
(t_3 (pow t_2 2.0)))
(if (<= (+ (/ x (+ x 1.0)) t_0) 5e-8)
(/ (+ 3.0 (/ -2.0 x)) (- 1.0 x))
(/ (- (* t_1 t_1) (* t_3 t_3)) (* (+ t_0 t_2) (+ t_1 t_3))))))double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
double t_0 = (-1.0 - x) / (x + -1.0);
double t_1 = pow(t_0, 2.0);
double t_2 = x / (-1.0 - x);
double t_3 = pow(t_2, 2.0);
double tmp;
if (((x / (x + 1.0)) + t_0) <= 5e-8) {
tmp = (3.0 + (-2.0 / x)) / (1.0 - x);
} else {
tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3));
}
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) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = ((-1.0d0) - x) / (x + (-1.0d0))
t_1 = t_0 ** 2.0d0
t_2 = x / ((-1.0d0) - x)
t_3 = t_2 ** 2.0d0
if (((x / (x + 1.0d0)) + t_0) <= 5d-8) then
tmp = (3.0d0 + ((-2.0d0) / x)) / (1.0d0 - x)
else
tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3))
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 t_0 = (-1.0 - x) / (x + -1.0);
double t_1 = Math.pow(t_0, 2.0);
double t_2 = x / (-1.0 - x);
double t_3 = Math.pow(t_2, 2.0);
double tmp;
if (((x / (x + 1.0)) + t_0) <= 5e-8) {
tmp = (3.0 + (-2.0 / x)) / (1.0 - x);
} else {
tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3));
}
return tmp;
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
def code(x): t_0 = (-1.0 - x) / (x + -1.0) t_1 = math.pow(t_0, 2.0) t_2 = x / (-1.0 - x) t_3 = math.pow(t_2, 2.0) tmp = 0 if ((x / (x + 1.0)) + t_0) <= 5e-8: tmp = (3.0 + (-2.0 / x)) / (1.0 - x) else: tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3)) 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) t_0 = Float64(Float64(-1.0 - x) / Float64(x + -1.0)) t_1 = t_0 ^ 2.0 t_2 = Float64(x / Float64(-1.0 - x)) t_3 = t_2 ^ 2.0 tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) + t_0) <= 5e-8) tmp = Float64(Float64(3.0 + Float64(-2.0 / x)) / Float64(1.0 - x)); else tmp = Float64(Float64(Float64(t_1 * t_1) - Float64(t_3 * t_3)) / Float64(Float64(t_0 + t_2) * Float64(t_1 + t_3))); 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) t_0 = (-1.0 - x) / (x + -1.0); t_1 = t_0 ^ 2.0; t_2 = x / (-1.0 - x); t_3 = t_2 ^ 2.0; tmp = 0.0; if (((x / (x + 1.0)) + t_0) <= 5e-8) tmp = (3.0 + (-2.0 / x)) / (1.0 - x); else tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3)); 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_] := Block[{t$95$0 = N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(x / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[t$95$2, 2.0], $MachinePrecision]}, If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], 5e-8], N[(N[(3.0 + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(t$95$3 * t$95$3), $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$0 + t$95$2), $MachinePrecision] * N[(t$95$1 + t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{-1 - x}{x + -1}\\
t_1 := {t_0}^{2}\\
t_2 := \frac{x}{-1 - x}\\
t_3 := {t_2}^{2}\\
\mathbf{if}\;\frac{x}{x + 1} + t_0 \leq 5 \cdot 10^{-8}:\\
\;\;\;\;\frac{3 + \frac{-2}{x}}{1 - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 \cdot t_1 - t_3 \cdot t_3}{\left(t_0 + t_2\right) \cdot \left(t_1 + t_3\right)}\\
\end{array}
Results
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 4.9999999999999998e-8Initial program 92.48
Simplified92.48
[Start]92.48 | \[ \frac{x}{x + 1} - \frac{x + 1}{x - 1}
\] |
|---|---|
sub-neg [=>]92.48 | \[ \color{blue}{\frac{x}{x + 1} + \left(-\frac{x + 1}{x - 1}\right)}
\] |
+-commutative [=>]92.48 | \[ \color{blue}{\left(-\frac{x + 1}{x - 1}\right) + \frac{x}{x + 1}}
\] |
remove-double-neg [<=]92.48 | \[ \left(-\frac{x + 1}{x - 1}\right) + \color{blue}{\left(-\left(-\frac{x}{x + 1}\right)\right)}
\] |
sub-neg [<=]92.48 | \[ \color{blue}{\left(-\frac{x + 1}{x - 1}\right) - \left(-\frac{x}{x + 1}\right)}
\] |
distribute-neg-frac [=>]92.48 | \[ \color{blue}{\frac{-\left(x + 1\right)}{x - 1}} - \left(-\frac{x}{x + 1}\right)
\] |
neg-sub0 [=>]92.48 | \[ \frac{\color{blue}{0 - \left(x + 1\right)}}{x - 1} - \left(-\frac{x}{x + 1}\right)
\] |
+-commutative [=>]92.48 | \[ \frac{0 - \color{blue}{\left(1 + x\right)}}{x - 1} - \left(-\frac{x}{x + 1}\right)
\] |
associate--r+ [=>]92.48 | \[ \frac{\color{blue}{\left(0 - 1\right) - x}}{x - 1} - \left(-\frac{x}{x + 1}\right)
\] |
metadata-eval [=>]92.48 | \[ \frac{\color{blue}{-1} - x}{x - 1} - \left(-\frac{x}{x + 1}\right)
\] |
sub-neg [=>]92.48 | \[ \frac{-1 - x}{\color{blue}{x + \left(-1\right)}} - \left(-\frac{x}{x + 1}\right)
\] |
metadata-eval [=>]92.48 | \[ \frac{-1 - x}{x + \color{blue}{-1}} - \left(-\frac{x}{x + 1}\right)
\] |
/-rgt-identity [<=]92.48 | \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{-\frac{x}{x + 1}}{1}}
\] |
neg-mul-1 [=>]92.48 | \[ \frac{-1 - x}{x + -1} - \frac{\color{blue}{-1 \cdot \frac{x}{x + 1}}}{1}
\] |
metadata-eval [<=]92.48 | \[ \frac{-1 - x}{x + -1} - \frac{\color{blue}{\left(-1\right)} \cdot \frac{x}{x + 1}}{1}
\] |
*-commutative [=>]92.48 | \[ \frac{-1 - x}{x + -1} - \frac{\color{blue}{\frac{x}{x + 1} \cdot \left(-1\right)}}{1}
\] |
associate-/l* [=>]92.48 | \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{\frac{x}{x + 1}}{\frac{1}{-1}}}
\] |
metadata-eval [=>]92.48 | \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\frac{1}{\color{blue}{-1}}}
\] |
metadata-eval [=>]92.48 | \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\color{blue}{-1}}
\] |
metadata-eval [<=]92.48 | \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\color{blue}{-1}}
\] |
associate-/l/ [=>]92.48 | \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{x}{\left(-1\right) \cdot \left(x + 1\right)}}
\] |
metadata-eval [=>]92.48 | \[ \frac{-1 - x}{x + -1} - \frac{x}{\color{blue}{-1} \cdot \left(x + 1\right)}
\] |
neg-mul-1 [<=]92.48 | \[ \frac{-1 - x}{x + -1} - \frac{x}{\color{blue}{-\left(x + 1\right)}}
\] |
Applied egg-rr91.5
Taylor expanded in x around inf 0.51
Simplified0.51
[Start]0.51 | \[ \frac{3 - 2 \cdot \frac{1}{x}}{\frac{-1 + x}{-1 - x} \cdot \left(x + 1\right)}
\] |
|---|---|
associate-*r/ [=>]0.51 | \[ \frac{3 - \color{blue}{\frac{2 \cdot 1}{x}}}{\frac{-1 + x}{-1 - x} \cdot \left(x + 1\right)}
\] |
metadata-eval [=>]0.51 | \[ \frac{3 - \frac{\color{blue}{2}}{x}}{\frac{-1 + x}{-1 - x} \cdot \left(x + 1\right)}
\] |
Taylor expanded in x around 0 0.51
Simplified0.51
[Start]0.51 | \[ \frac{3 - \frac{2}{x}}{1 + -1 \cdot x}
\] |
|---|---|
mul-1-neg [=>]0.51 | \[ \frac{3 - \frac{2}{x}}{1 + \color{blue}{\left(-x\right)}}
\] |
sub-neg [<=]0.51 | \[ \frac{3 - \frac{2}{x}}{\color{blue}{1 - x}}
\] |
if 4.9999999999999998e-8 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 0.18
Simplified0.18
[Start]0.18 | \[ \frac{x}{x + 1} - \frac{x + 1}{x - 1}
\] |
|---|---|
sub-neg [=>]0.18 | \[ \color{blue}{\frac{x}{x + 1} + \left(-\frac{x + 1}{x - 1}\right)}
\] |
+-commutative [=>]0.18 | \[ \color{blue}{\left(-\frac{x + 1}{x - 1}\right) + \frac{x}{x + 1}}
\] |
remove-double-neg [<=]0.18 | \[ \left(-\frac{x + 1}{x - 1}\right) + \color{blue}{\left(-\left(-\frac{x}{x + 1}\right)\right)}
\] |
sub-neg [<=]0.18 | \[ \color{blue}{\left(-\frac{x + 1}{x - 1}\right) - \left(-\frac{x}{x + 1}\right)}
\] |
distribute-neg-frac [=>]0.18 | \[ \color{blue}{\frac{-\left(x + 1\right)}{x - 1}} - \left(-\frac{x}{x + 1}\right)
\] |
neg-sub0 [=>]0.18 | \[ \frac{\color{blue}{0 - \left(x + 1\right)}}{x - 1} - \left(-\frac{x}{x + 1}\right)
\] |
+-commutative [=>]0.18 | \[ \frac{0 - \color{blue}{\left(1 + x\right)}}{x - 1} - \left(-\frac{x}{x + 1}\right)
\] |
associate--r+ [=>]0.18 | \[ \frac{\color{blue}{\left(0 - 1\right) - x}}{x - 1} - \left(-\frac{x}{x + 1}\right)
\] |
metadata-eval [=>]0.18 | \[ \frac{\color{blue}{-1} - x}{x - 1} - \left(-\frac{x}{x + 1}\right)
\] |
sub-neg [=>]0.18 | \[ \frac{-1 - x}{\color{blue}{x + \left(-1\right)}} - \left(-\frac{x}{x + 1}\right)
\] |
metadata-eval [=>]0.18 | \[ \frac{-1 - x}{x + \color{blue}{-1}} - \left(-\frac{x}{x + 1}\right)
\] |
/-rgt-identity [<=]0.18 | \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{-\frac{x}{x + 1}}{1}}
\] |
neg-mul-1 [=>]0.18 | \[ \frac{-1 - x}{x + -1} - \frac{\color{blue}{-1 \cdot \frac{x}{x + 1}}}{1}
\] |
metadata-eval [<=]0.18 | \[ \frac{-1 - x}{x + -1} - \frac{\color{blue}{\left(-1\right)} \cdot \frac{x}{x + 1}}{1}
\] |
*-commutative [=>]0.18 | \[ \frac{-1 - x}{x + -1} - \frac{\color{blue}{\frac{x}{x + 1} \cdot \left(-1\right)}}{1}
\] |
associate-/l* [=>]0.18 | \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{\frac{x}{x + 1}}{\frac{1}{-1}}}
\] |
metadata-eval [=>]0.18 | \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\frac{1}{\color{blue}{-1}}}
\] |
metadata-eval [=>]0.18 | \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\color{blue}{-1}}
\] |
metadata-eval [<=]0.18 | \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\color{blue}{-1}}
\] |
associate-/l/ [=>]0.18 | \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{x}{\left(-1\right) \cdot \left(x + 1\right)}}
\] |
metadata-eval [=>]0.18 | \[ \frac{-1 - x}{x + -1} - \frac{x}{\color{blue}{-1} \cdot \left(x + 1\right)}
\] |
neg-mul-1 [<=]0.18 | \[ \frac{-1 - x}{x + -1} - \frac{x}{\color{blue}{-\left(x + 1\right)}}
\] |
Applied egg-rr0.18
Final simplification0.35
| Alternative 1 | |
|---|---|
| Error | 0.35% |
| Cost | 14532 |
| Alternative 2 | |
|---|---|
| Error | 0.34% |
| Cost | 1732 |
| Alternative 3 | |
|---|---|
| Error | 0.77% |
| Cost | 841 |
| Alternative 4 | |
|---|---|
| Error | 0.76% |
| Cost | 840 |
| Alternative 5 | |
|---|---|
| Error | 0.77% |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Error | 1.21% |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Error | 1.36% |
| Cost | 584 |
| Alternative 8 | |
|---|---|
| Error | 1.92% |
| Cost | 456 |
| Alternative 9 | |
|---|---|
| Error | 49.91% |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))