| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 8712 |
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (+ (/ 1.0 (+ 1.0 x)) (/ -2.0 x)) (/ 1.0 (+ x -1.0))))
(t_1 (fma x x (- x))))
(if (<= t_0 -50000000000000.0)
(/ -2.0 x)
(if (<= t_0 4e-25)
(* 2.0 (pow x -3.0))
(/
(- (* (+ 1.0 x) (+ (* x 2.0) (- -2.0 x))) t_1)
(* 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 = ((1.0 / (1.0 + x)) + (-2.0 / x)) + (1.0 / (x + -1.0));
double t_1 = fma(x, x, -x);
double tmp;
if (t_0 <= -50000000000000.0) {
tmp = -2.0 / x;
} else if (t_0 <= 4e-25) {
tmp = 2.0 * pow(x, -3.0);
} else {
tmp = (((1.0 + x) * ((x * 2.0) + (-2.0 - x))) - t_1) / (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(1.0 / Float64(1.0 + x)) + Float64(-2.0 / x)) + Float64(1.0 / Float64(x + -1.0))) t_1 = fma(x, x, Float64(-x)) tmp = 0.0 if (t_0 <= -50000000000000.0) tmp = Float64(-2.0 / x); elseif (t_0 <= 4e-25) tmp = Float64(2.0 * (x ^ -3.0)); else tmp = Float64(Float64(Float64(Float64(1.0 + x) * Float64(Float64(x * 2.0) + Float64(-2.0 - x))) - t_1) / Float64(t_1 * Float64(-1.0 - x))); end return 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[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * x + (-x)), $MachinePrecision]}, If[LessEqual[t$95$0, -50000000000000.0], N[(-2.0 / x), $MachinePrecision], If[LessEqual[t$95$0, 4e-25], N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(1.0 + x), $MachinePrecision] * N[(N[(x * 2.0), $MachinePrecision] + N[(-2.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$1), $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{1}{1 + x} + \frac{-2}{x}\right) + \frac{1}{x + -1}\\
t_1 := \mathsf{fma}\left(x, x, -x\right)\\
\mathbf{if}\;t_0 \leq -50000000000000:\\
\;\;\;\;\frac{-2}{x}\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-25}:\\
\;\;\;\;2 \cdot {x}^{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + x\right) \cdot \left(x \cdot 2 + \left(-2 - x\right)\right) - t_1}{t_1 \cdot \left(-1 - x\right)}\\
\end{array}
| Original | 9.9 |
|---|---|
| Target | 0.3 |
| Herbie | 0.8 |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -5e13Initial program 0.0
Simplified0.0
[Start]0.0 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]0.0 | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]0.0 | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]0.0 | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]0.0 | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]0.0 | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]0.0 | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]0.0 | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]0.0 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]0.0 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Taylor expanded in x around 0 0
if -5e13 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 4.00000000000000015e-25Initial program 19.4
Simplified19.4
[Start]19.4 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]19.4 | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]19.4 | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]19.4 | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]19.4 | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]19.4 | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]19.4 | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]19.4 | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]19.4 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]19.4 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Taylor expanded in x around inf 2.0
Applied egg-rr1.5
if 4.00000000000000015e-25 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 0.8
Simplified0.8
[Start]0.8 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]0.8 | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]0.8 | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]0.8 | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]0.8 | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]0.8 | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]0.8 | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]0.8 | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]0.8 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]0.8 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Applied egg-rr0.1
Simplified0.1
[Start]0.1 | \[ \frac{-1 \cdot \mathsf{fma}\left(x, x, -x\right) - \left(-1 - x\right) \cdot \left(-2 + \left(2 \cdot x - x\right)\right)}{\left(-1 - x\right) \cdot \mathsf{fma}\left(x, x, -x\right)}
\] |
|---|---|
mul-1-neg [=>]0.1 | \[ \frac{\color{blue}{\left(-\mathsf{fma}\left(x, x, -x\right)\right)} - \left(-1 - x\right) \cdot \left(-2 + \left(2 \cdot x - x\right)\right)}{\left(-1 - x\right) \cdot \mathsf{fma}\left(x, x, -x\right)}
\] |
*-commutative [=>]0.1 | \[ \frac{\left(-\mathsf{fma}\left(x, x, -x\right)\right) - \color{blue}{\left(-2 + \left(2 \cdot x - x\right)\right) \cdot \left(-1 - x\right)}}{\left(-1 - x\right) \cdot \mathsf{fma}\left(x, x, -x\right)}
\] |
+-commutative [=>]0.1 | \[ \frac{\left(-\mathsf{fma}\left(x, x, -x\right)\right) - \color{blue}{\left(\left(2 \cdot x - x\right) + -2\right)} \cdot \left(-1 - x\right)}{\left(-1 - x\right) \cdot \mathsf{fma}\left(x, x, -x\right)}
\] |
associate-+l- [=>]0.1 | \[ \frac{\left(-\mathsf{fma}\left(x, x, -x\right)\right) - \color{blue}{\left(2 \cdot x - \left(x - -2\right)\right)} \cdot \left(-1 - x\right)}{\left(-1 - x\right) \cdot \mathsf{fma}\left(x, x, -x\right)}
\] |
*-commutative [=>]0.1 | \[ \frac{\left(-\mathsf{fma}\left(x, x, -x\right)\right) - \left(\color{blue}{x \cdot 2} - \left(x - -2\right)\right) \cdot \left(-1 - x\right)}{\left(-1 - x\right) \cdot \mathsf{fma}\left(x, x, -x\right)}
\] |
*-commutative [=>]0.1 | \[ \frac{\left(-\mathsf{fma}\left(x, x, -x\right)\right) - \left(x \cdot 2 - \left(x - -2\right)\right) \cdot \left(-1 - x\right)}{\color{blue}{\mathsf{fma}\left(x, x, -x\right) \cdot \left(-1 - x\right)}}
\] |
Final simplification0.8
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 8712 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 3528 |
| Alternative 3 | |
|---|---|
| Error | 0.9 |
| Cost | 3144 |
| Alternative 4 | |
|---|---|
| Error | 0.9 |
| Cost | 3016 |
| Alternative 5 | |
|---|---|
| Error | 0.1 |
| Cost | 1737 |
| Alternative 6 | |
|---|---|
| Error | 0.5 |
| Cost | 1225 |
| Alternative 7 | |
|---|---|
| Error | 0.9 |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Error | 10.7 |
| Cost | 448 |
| Alternative 9 | |
|---|---|
| Error | 30.4 |
| Cost | 192 |
| Alternative 10 | |
|---|---|
| Error | 61.9 |
| Cost | 64 |
herbie shell --seed 2022365
(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))))