| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 16201 |
(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)))))
(if (<= t_0 -0.0005)
(/
(- (* x (+ (+ 1.0 x) (+ x -1.0))) (* 2.0 (fma x x -1.0)))
(* x (fma x x -1.0)))
(if (<= t_0 0.0)
(+ (/ 2.0 (pow x 5.0)) (/ 2.0 (pow x 3.0)))
(/
(- (* (+ x (+ -2.0 (* x -2.0))) (- 1.0 x)) (fma x x x))
(* (- 1.0 x) (fma x x 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 tmp;
if (t_0 <= -0.0005) {
tmp = ((x * ((1.0 + x) + (x + -1.0))) - (2.0 * fma(x, x, -1.0))) / (x * fma(x, x, -1.0));
} else if (t_0 <= 0.0) {
tmp = (2.0 / pow(x, 5.0)) + (2.0 / pow(x, 3.0));
} else {
tmp = (((x + (-2.0 + (x * -2.0))) * (1.0 - x)) - fma(x, x, x)) / ((1.0 - x) * fma(x, x, 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))) tmp = 0.0 if (t_0 <= -0.0005) tmp = Float64(Float64(Float64(x * Float64(Float64(1.0 + x) + Float64(x + -1.0))) - Float64(2.0 * fma(x, x, -1.0))) / Float64(x * fma(x, x, -1.0))); elseif (t_0 <= 0.0) tmp = Float64(Float64(2.0 / (x ^ 5.0)) + Float64(2.0 / (x ^ 3.0))); else tmp = Float64(Float64(Float64(Float64(x + Float64(-2.0 + Float64(x * -2.0))) * Float64(1.0 - x)) - fma(x, x, x)) / Float64(Float64(1.0 - x) * fma(x, x, 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]}, If[LessEqual[t$95$0, -0.0005], N[(N[(N[(x * N[(N[(1.0 + x), $MachinePrecision] + N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(2.0 * N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x + N[(-2.0 + N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] - N[(x * x + x), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(x * x + 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}\\
\mathbf{if}\;t_0 \leq -0.0005:\\
\;\;\;\;\frac{x \cdot \left(\left(1 + x\right) + \left(x + -1\right)\right) - 2 \cdot \mathsf{fma}\left(x, x, -1\right)}{x \cdot \mathsf{fma}\left(x, x, -1\right)}\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x + \left(-2 + x \cdot -2\right)\right) \cdot \left(1 - x\right) - \mathsf{fma}\left(x, x, x\right)}{\left(1 - x\right) \cdot \mathsf{fma}\left(x, x, x\right)}\\
\end{array}
| Original | 84.6% |
|---|---|
| Target | 99.6% |
| Herbie | 99.2% |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -5.0000000000000001e-4Initial program 99.8%
Applied egg-rr99.8%
[Start]99.8 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
+-commutative [=>]99.8 | \[ \color{blue}{\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)}
\] |
associate-+r- [=>]99.8 | \[ \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) - \frac{2}{x}}
\] |
sub-neg [=>]99.8 | \[ \left(\frac{1}{\color{blue}{x + \left(-1\right)}} + \frac{1}{x + 1}\right) - \frac{2}{x}
\] |
metadata-eval [=>]99.8 | \[ \left(\frac{1}{x + \color{blue}{-1}} + \frac{1}{x + 1}\right) - \frac{2}{x}
\] |
+-commutative [=>]99.8 | \[ \left(\frac{1}{x + -1} + \frac{1}{\color{blue}{1 + x}}\right) - \frac{2}{x}
\] |
Applied egg-rr100.0%
[Start]99.8 | \[ \left(\frac{1}{x + -1} + \frac{1}{1 + x}\right) - \frac{2}{x}
\] |
|---|---|
frac-add [=>]99.8 | \[ \color{blue}{\frac{1 \cdot \left(1 + x\right) + \left(x + -1\right) \cdot 1}{\left(x + -1\right) \cdot \left(1 + x\right)}} - \frac{2}{x}
\] |
frac-sub [=>]99.9 | \[ \color{blue}{\frac{\left(1 \cdot \left(1 + x\right) + \left(x + -1\right) \cdot 1\right) \cdot x - \left(\left(x + -1\right) \cdot \left(1 + x\right)\right) \cdot 2}{\left(\left(x + -1\right) \cdot \left(1 + x\right)\right) \cdot x}}
\] |
if -5.0000000000000001e-4 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 69.5%
Taylor expanded in x around inf 99.3%
Simplified99.3%
[Start]99.3 | \[ 2 \cdot \frac{1}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}
\] |
|---|---|
associate-*r/ [=>]99.3 | \[ \color{blue}{\frac{2 \cdot 1}{{x}^{5}}} + 2 \cdot \frac{1}{{x}^{3}}
\] |
metadata-eval [=>]99.3 | \[ \frac{\color{blue}{2}}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}
\] |
associate-*r/ [=>]99.3 | \[ \frac{2}{{x}^{5}} + \color{blue}{\frac{2 \cdot 1}{{x}^{3}}}
\] |
metadata-eval [=>]99.3 | \[ \frac{2}{{x}^{5}} + \frac{\color{blue}{2}}{{x}^{3}}
\] |
if 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 98.9%
Applied egg-rr98.9%
[Start]98.9 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
frac-sub [=>]98.9 | \[ \color{blue}{\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1}
\] |
frac-2neg [=>]98.9 | \[ \frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x} + \color{blue}{\frac{-1}{-\left(x - 1\right)}}
\] |
metadata-eval [=>]98.9 | \[ \frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x} + \frac{\color{blue}{-1}}{-\left(x - 1\right)}
\] |
frac-add [=>]99.9 | \[ \color{blue}{\frac{\left(1 \cdot x - \left(x + 1\right) \cdot 2\right) \cdot \left(-\left(x - 1\right)\right) + \left(\left(x + 1\right) \cdot x\right) \cdot -1}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(-\left(x - 1\right)\right)}}
\] |
Simplified99.9%
[Start]98.9 | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, \mathsf{fma}\left(-1, x, 1\right), \left(x \cdot \left(1 + x\right)\right) \cdot -1\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
|---|---|
*-commutative [=>]98.9 | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, \mathsf{fma}\left(-1, x, 1\right), \color{blue}{-1 \cdot \left(x \cdot \left(1 + x\right)\right)}\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
neg-mul-1 [<=]98.9 | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, \mathsf{fma}\left(-1, x, 1\right), \color{blue}{-x \cdot \left(1 + x\right)}\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
fma-neg [<=]99.9 | \[ \frac{\color{blue}{\left(x - \left(1 + x\right) \cdot 2\right) \cdot \mathsf{fma}\left(-1, x, 1\right) - x \cdot \left(1 + x\right)}}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
*-commutative [=>]99.9 | \[ \frac{\left(x - \color{blue}{2 \cdot \left(1 + x\right)}\right) \cdot \mathsf{fma}\left(-1, x, 1\right) - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
cancel-sign-sub-inv [=>]99.9 | \[ \frac{\color{blue}{\left(x + \left(-2\right) \cdot \left(1 + x\right)\right)} \cdot \mathsf{fma}\left(-1, x, 1\right) - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
metadata-eval [=>]99.9 | \[ \frac{\left(x + \color{blue}{-2} \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right) - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
distribute-lft-in [=>]99.9 | \[ \frac{\left(x + \color{blue}{\left(-2 \cdot 1 + -2 \cdot x\right)}\right) \cdot \mathsf{fma}\left(-1, x, 1\right) - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
metadata-eval [=>]99.9 | \[ \frac{\left(x + \left(\color{blue}{-2} + -2 \cdot x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right) - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
fma-udef [=>]99.9 | \[ \frac{\left(x + \left(-2 + -2 \cdot x\right)\right) \cdot \color{blue}{\left(-1 \cdot x + 1\right)} - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
neg-mul-1 [<=]99.9 | \[ \frac{\left(x + \left(-2 + -2 \cdot x\right)\right) \cdot \left(\color{blue}{\left(-x\right)} + 1\right) - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
+-commutative [<=]99.9 | \[ \frac{\left(x + \left(-2 + -2 \cdot x\right)\right) \cdot \color{blue}{\left(1 + \left(-x\right)\right)} - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
sub-neg [<=]99.9 | \[ \frac{\left(x + \left(-2 + -2 \cdot x\right)\right) \cdot \color{blue}{\left(1 - x\right)} - x \cdot \left(1 + x\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
*-commutative [=>]99.9 | \[ \frac{\left(x + \left(-2 + -2 \cdot x\right)\right) \cdot \left(1 - x\right) - \color{blue}{\left(1 + x\right) \cdot x}}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
+-commutative [=>]99.9 | \[ \frac{\left(x + \left(-2 + -2 \cdot x\right)\right) \cdot \left(1 - x\right) - \color{blue}{\left(x + 1\right)} \cdot x}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
distribute-lft1-in [<=]99.4 | \[ \frac{\left(x + \left(-2 + -2 \cdot x\right)\right) \cdot \left(1 - x\right) - \color{blue}{\left(x \cdot x + x\right)}}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
fma-def [=>]99.9 | \[ \frac{\left(x + \left(-2 + -2 \cdot x\right)\right) \cdot \left(1 - x\right) - \color{blue}{\mathsf{fma}\left(x, x, x\right)}}{\left(x \cdot \left(1 + x\right)\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 16201 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 15432 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 9416 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 9416 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 8712 |
| Alternative 6 | |
|---|---|
| Accuracy | 84.6% |
| Cost | 1216 |
| Alternative 7 | |
|---|---|
| Accuracy | 84.6% |
| Cost | 1216 |
| Alternative 8 | |
|---|---|
| Accuracy | 84.6% |
| Cost | 960 |
| Alternative 9 | |
|---|---|
| Accuracy | 84.6% |
| Cost | 960 |
| Alternative 10 | |
|---|---|
| Accuracy | 75.9% |
| Cost | 585 |
| Alternative 11 | |
|---|---|
| Accuracy | 76.4% |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Accuracy | 83.5% |
| Cost | 448 |
| Alternative 13 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 192 |
herbie shell --seed 2023159
(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))))