| Alternative 1 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 15433 |

(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 (- (* x x) x)))
(if (or (<= t_0 -2e-5) (not (<= t_0 0.0)))
(/ (+ t_1 (* (+ 1.0 x) (+ x (* -2.0 (+ x -1.0))))) (* (+ 1.0 x) t_1))
(+ (/ 2.0 (pow x 5.0)) (/ 2.0 (pow x 3.0))))))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 = (x * x) - x;
double tmp;
if ((t_0 <= -2e-5) || !(t_0 <= 0.0)) {
tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / ((1.0 + x) * t_1);
} else {
tmp = (2.0 / pow(x, 5.0)) + (2.0 / pow(x, 3.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / (x + 1.0d0)) - (2.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) :: tmp
t_0 = ((1.0d0 / (1.0d0 + x)) - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))
t_1 = (x * x) - x
if ((t_0 <= (-2d-5)) .or. (.not. (t_0 <= 0.0d0))) then
tmp = (t_1 + ((1.0d0 + x) * (x + ((-2.0d0) * (x + (-1.0d0)))))) / ((1.0d0 + x) * t_1)
else
tmp = (2.0d0 / (x ** 5.0d0)) + (2.0d0 / (x ** 3.0d0))
end if
code = tmp
end function
public static double code(double x) {
return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
public static double code(double x) {
double t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
double t_1 = (x * x) - x;
double tmp;
if ((t_0 <= -2e-5) || !(t_0 <= 0.0)) {
tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / ((1.0 + x) * t_1);
} else {
tmp = (2.0 / Math.pow(x, 5.0)) + (2.0 / Math.pow(x, 3.0));
}
return tmp;
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x): t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0)) t_1 = (x * x) - x tmp = 0 if (t_0 <= -2e-5) or not (t_0 <= 0.0): tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / ((1.0 + x) * t_1) else: tmp = (2.0 / math.pow(x, 5.0)) + (2.0 / math.pow(x, 3.0)) 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 = Float64(Float64(x * x) - x) tmp = 0.0 if ((t_0 <= -2e-5) || !(t_0 <= 0.0)) tmp = Float64(Float64(t_1 + Float64(Float64(1.0 + x) * Float64(x + Float64(-2.0 * Float64(x + -1.0))))) / Float64(Float64(1.0 + x) * t_1)); else tmp = Float64(Float64(2.0 / (x ^ 5.0)) + Float64(2.0 / (x ^ 3.0))); end return tmp end
function tmp = code(x) tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)); end
function tmp_2 = code(x) t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0)); t_1 = (x * x) - x; tmp = 0.0; if ((t_0 <= -2e-5) || ~((t_0 <= 0.0))) tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / ((1.0 + x) * t_1); else tmp = (2.0 / (x ^ 5.0)) + (2.0 / (x ^ 3.0)); end tmp_2 = 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[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e-5], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], N[(N[(t$95$1 + N[(N[(1.0 + x), $MachinePrecision] * N[(x + N[(-2.0 * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 3.0], $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 := x \cdot x - x\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-5} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;\frac{t_1 + \left(1 + x\right) \cdot \left(x + -2 \cdot \left(x + -1\right)\right)}{\left(1 + x\right) \cdot t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\\
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 85.0% |
|---|---|
| Target | 99.5% |
| Herbie | 99.1% |
if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -2.00000000000000016e-5 or 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) Initial program 99.4%
Simplified99.4%
[Start]99.4% | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]99.4% | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]99.4% | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]99.4% | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]99.4% | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]99.4% | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]99.4% | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]99.4% | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]99.4% | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]99.4% | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Applied egg-rr99.3%
[Start]99.4% | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + -1}\right)
\] |
|---|---|
frac-2neg [=>]99.4% | \[ \frac{1}{1 + x} - \left(\color{blue}{\frac{-2}{-x}} - \frac{1}{x + -1}\right)
\] |
frac-2neg [=>]99.4% | \[ \frac{1}{1 + x} - \left(\frac{-2}{-x} - \color{blue}{\frac{-1}{-\left(x + -1\right)}}\right)
\] |
metadata-eval [=>]99.4% | \[ \frac{1}{1 + x} - \left(\frac{-2}{-x} - \frac{\color{blue}{-1}}{-\left(x + -1\right)}\right)
\] |
frac-sub [=>]99.3% | \[ \frac{1}{1 + x} - \color{blue}{\frac{\left(-2\right) \cdot \left(-\left(x + -1\right)\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(-\left(x + -1\right)\right)}}
\] |
metadata-eval [=>]99.3% | \[ \frac{1}{1 + x} - \frac{\color{blue}{-2} \cdot \left(-\left(x + -1\right)\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(-\left(x + -1\right)\right)}
\] |
+-commutative [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(-\color{blue}{\left(-1 + x\right)}\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(-\left(x + -1\right)\right)}
\] |
distribute-neg-in [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \color{blue}{\left(\left(--1\right) + \left(-x\right)\right)} - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(-\left(x + -1\right)\right)}
\] |
metadata-eval [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(\color{blue}{1} + \left(-x\right)\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(-\left(x + -1\right)\right)}
\] |
sub-neg [<=]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \color{blue}{\left(1 - x\right)} - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(-\left(x + -1\right)\right)}
\] |
+-commutative [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(-\color{blue}{\left(-1 + x\right)}\right)}
\] |
distribute-neg-in [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \color{blue}{\left(\left(--1\right) + \left(-x\right)\right)}}
\] |
metadata-eval [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(\color{blue}{1} + \left(-x\right)\right)}
\] |
sub-neg [<=]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \color{blue}{\left(1 - x\right)}}
\] |
Simplified99.3%
[Start]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(1 - x\right)}
\] |
|---|---|
cancel-sign-sub [=>]99.3% | \[ \frac{1}{1 + x} - \frac{\color{blue}{-2 \cdot \left(1 - x\right) + x \cdot -1}}{\left(-x\right) \cdot \left(1 - x\right)}
\] |
*-commutative [<=]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) + \color{blue}{-1 \cdot x}}{\left(-x\right) \cdot \left(1 - x\right)}
\] |
neg-mul-1 [<=]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) + \color{blue}{\left(-x\right)}}{\left(-x\right) \cdot \left(1 - x\right)}
\] |
unsub-neg [=>]99.3% | \[ \frac{1}{1 + x} - \frac{\color{blue}{-2 \cdot \left(1 - x\right) - x}}{\left(-x\right) \cdot \left(1 - x\right)}
\] |
sub-neg [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\left(-x\right) \cdot \color{blue}{\left(1 + \left(-x\right)\right)}}
\] |
+-commutative [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\left(-x\right) \cdot \color{blue}{\left(\left(-x\right) + 1\right)}}
\] |
distribute-lft-in [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\color{blue}{\left(-x\right) \cdot \left(-x\right) + \left(-x\right) \cdot 1}}
\] |
sqr-neg [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\color{blue}{x \cdot x} + \left(-x\right) \cdot 1}
\] |
unpow2 [<=]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\color{blue}{{x}^{2}} + \left(-x\right) \cdot 1}
\] |
*-rgt-identity [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{{x}^{2} + \color{blue}{\left(-x\right)}}
\] |
sub-neg [<=]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\color{blue}{{x}^{2} - x}}
\] |
unpow2 [=>]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\color{blue}{x \cdot x} - x}
\] |
Applied egg-rr100.0%
[Start]99.3% | \[ \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{x \cdot x - x}
\] |
|---|---|
frac-sub [=>]100.0% | \[ \color{blue}{\frac{1 \cdot \left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(-2 \cdot \left(1 - x\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}}
\] |
*-un-lft-identity [<=]100.0% | \[ \frac{\color{blue}{\left(x \cdot x - x\right)} - \left(1 + x\right) \cdot \left(-2 \cdot \left(1 - x\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
*-commutative [=>]100.0% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\color{blue}{\left(1 - x\right) \cdot -2} - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
if -2.00000000000000016e-5 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0Initial program 65.2%
Simplified65.2%
[Start]65.2% | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]65.2% | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]65.2% | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]65.2% | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]65.2% | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]65.2% | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]65.2% | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]65.2% | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]65.2% | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]65.2% | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Taylor expanded in x around inf 99.1%
Simplified99.1%
[Start]99.1% | \[ 2 \cdot \frac{1}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}
\] |
|---|---|
associate-*r/ [=>]99.1% | \[ \color{blue}{\frac{2 \cdot 1}{{x}^{5}}} + 2 \cdot \frac{1}{{x}^{3}}
\] |
metadata-eval [=>]99.1% | \[ \frac{\color{blue}{2}}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}
\] |
associate-*r/ [=>]99.1% | \[ \frac{2}{{x}^{5}} + \color{blue}{\frac{2 \cdot 1}{{x}^{3}}}
\] |
metadata-eval [=>]99.1% | \[ \frac{2}{{x}^{5}} + \frac{\color{blue}{2}}{{x}^{3}}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 15433 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 8712 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 960 |
| Alternative 4 | |
|---|---|
| Accuracy | 76.6% |
| Cost | 585 |
| Alternative 5 | |
|---|---|
| Accuracy | 83.8% |
| Cost | 448 |
| Alternative 6 | |
|---|---|
| Accuracy | 51.7% |
| Cost | 192 |
| Alternative 7 | |
|---|---|
| Accuracy | 3.3% |
| Cost | 64 |
| Alternative 8 | |
|---|---|
| Accuracy | 3.3% |
| Cost | 64 |
herbie shell --seed 2023271
(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))))