| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 7300 |
(FPCore (a k m) :precision binary64 (/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))
(FPCore (a k m) :precision binary64 (if (<= k 2.2e+17) (* (/ a (+ -1.0 (* k (- -10.0 k)))) (- (pow k m))) (* (pow k m) (/ (/ a k) k))))
double code(double a, double k, double m) {
return (a * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
}
double code(double a, double k, double m) {
double tmp;
if (k <= 2.2e+17) {
tmp = (a / (-1.0 + (k * (-10.0 - k)))) * -pow(k, m);
} else {
tmp = pow(k, m) * ((a / k) / k);
}
return tmp;
}
real(8) function code(a, k, m)
real(8), intent (in) :: a
real(8), intent (in) :: k
real(8), intent (in) :: m
code = (a * (k ** m)) / ((1.0d0 + (10.0d0 * k)) + (k * k))
end function
real(8) function code(a, k, m)
real(8), intent (in) :: a
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8) :: tmp
if (k <= 2.2d+17) then
tmp = (a / ((-1.0d0) + (k * ((-10.0d0) - k)))) * -(k ** m)
else
tmp = (k ** m) * ((a / k) / k)
end if
code = tmp
end function
public static double code(double a, double k, double m) {
return (a * Math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
}
public static double code(double a, double k, double m) {
double tmp;
if (k <= 2.2e+17) {
tmp = (a / (-1.0 + (k * (-10.0 - k)))) * -Math.pow(k, m);
} else {
tmp = Math.pow(k, m) * ((a / k) / k);
}
return tmp;
}
def code(a, k, m): return (a * math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k))
def code(a, k, m): tmp = 0 if k <= 2.2e+17: tmp = (a / (-1.0 + (k * (-10.0 - k)))) * -math.pow(k, m) else: tmp = math.pow(k, m) * ((a / k) / k) return tmp
function code(a, k, m) return Float64(Float64(a * (k ^ m)) / Float64(Float64(1.0 + Float64(10.0 * k)) + Float64(k * k))) end
function code(a, k, m) tmp = 0.0 if (k <= 2.2e+17) tmp = Float64(Float64(a / Float64(-1.0 + Float64(k * Float64(-10.0 - k)))) * Float64(-(k ^ m))); else tmp = Float64((k ^ m) * Float64(Float64(a / k) / k)); end return tmp end
function tmp = code(a, k, m) tmp = (a * (k ^ m)) / ((1.0 + (10.0 * k)) + (k * k)); end
function tmp_2 = code(a, k, m) tmp = 0.0; if (k <= 2.2e+17) tmp = (a / (-1.0 + (k * (-10.0 - k)))) * -(k ^ m); else tmp = (k ^ m) * ((a / k) / k); end tmp_2 = tmp; end
code[a_, k_, m_] := N[(N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(10.0 * k), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, k_, m_] := If[LessEqual[k, 2.2e+17], N[(N[(a / N[(-1.0 + N[(k * N[(-10.0 - k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Power[k, m], $MachinePrecision])), $MachinePrecision], N[(N[Power[k, m], $MachinePrecision] * N[(N[(a / k), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]]
\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\begin{array}{l}
\mathbf{if}\;k \leq 2.2 \cdot 10^{+17}:\\
\;\;\;\;\frac{a}{-1 + k \cdot \left(-10 - k\right)} \cdot \left(-{k}^{m}\right)\\
\mathbf{else}:\\
\;\;\;\;{k}^{m} \cdot \frac{\frac{a}{k}}{k}\\
\end{array}
Results
if k < 2.2e17Initial program 99.9%
Simplified99.9%
[Start]99.9 | \[ \frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\] |
|---|---|
associate-/l* [=>]99.9 | \[ \color{blue}{\frac{a}{\frac{\left(1 + 10 \cdot k\right) + k \cdot k}{{k}^{m}}}}
\] |
associate-+l+ [=>]99.9 | \[ \frac{a}{\frac{\color{blue}{1 + \left(10 \cdot k + k \cdot k\right)}}{{k}^{m}}}
\] |
*-commutative [=>]99.9 | \[ \frac{a}{\frac{1 + \left(\color{blue}{k \cdot 10} + k \cdot k\right)}{{k}^{m}}}
\] |
Applied egg-rr100.0%
[Start]99.9 | \[ \frac{a}{\frac{1 + \left(k \cdot 10 + k \cdot k\right)}{{k}^{m}}}
\] |
|---|---|
frac-2neg [=>]99.9 | \[ \frac{a}{\color{blue}{\frac{-\left(1 + \left(k \cdot 10 + k \cdot k\right)\right)}{-{k}^{m}}}}
\] |
associate-/r/ [=>]99.9 | \[ \color{blue}{\frac{a}{-\left(1 + \left(k \cdot 10 + k \cdot k\right)\right)} \cdot \left(-{k}^{m}\right)}
\] |
neg-sub0 [=>]99.9 | \[ \frac{a}{\color{blue}{0 - \left(1 + \left(k \cdot 10 + k \cdot k\right)\right)}} \cdot \left(-{k}^{m}\right)
\] |
metadata-eval [<=]99.9 | \[ \frac{a}{\color{blue}{\log 1} - \left(1 + \left(k \cdot 10 + k \cdot k\right)\right)} \cdot \left(-{k}^{m}\right)
\] |
associate--r+ [=>]99.9 | \[ \frac{a}{\color{blue}{\left(\log 1 - 1\right) - \left(k \cdot 10 + k \cdot k\right)}} \cdot \left(-{k}^{m}\right)
\] |
metadata-eval [=>]99.9 | \[ \frac{a}{\left(\color{blue}{0} - 1\right) - \left(k \cdot 10 + k \cdot k\right)} \cdot \left(-{k}^{m}\right)
\] |
metadata-eval [=>]99.9 | \[ \frac{a}{\color{blue}{-1} - \left(k \cdot 10 + k \cdot k\right)} \cdot \left(-{k}^{m}\right)
\] |
distribute-lft-out [=>]100.0 | \[ \frac{a}{-1 - \color{blue}{k \cdot \left(10 + k\right)}} \cdot \left(-{k}^{m}\right)
\] |
+-commutative [=>]100.0 | \[ \frac{a}{-1 - k \cdot \color{blue}{\left(k + 10\right)}} \cdot \left(-{k}^{m}\right)
\] |
if 2.2e17 < k Initial program 90.3%
Simplified90.2%
[Start]90.3 | \[ \frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\] |
|---|---|
associate-/l* [=>]90.2 | \[ \color{blue}{\frac{a}{\frac{\left(1 + 10 \cdot k\right) + k \cdot k}{{k}^{m}}}}
\] |
associate-+l+ [=>]90.2 | \[ \frac{a}{\frac{\color{blue}{1 + \left(10 \cdot k + k \cdot k\right)}}{{k}^{m}}}
\] |
*-commutative [=>]90.2 | \[ \frac{a}{\frac{1 + \left(\color{blue}{k \cdot 10} + k \cdot k\right)}{{k}^{m}}}
\] |
Applied egg-rr90.2%
[Start]90.2 | \[ \frac{a}{\frac{1 + \left(k \cdot 10 + k \cdot k\right)}{{k}^{m}}}
\] |
|---|---|
frac-2neg [=>]90.2 | \[ \frac{a}{\color{blue}{\frac{-\left(1 + \left(k \cdot 10 + k \cdot k\right)\right)}{-{k}^{m}}}}
\] |
associate-/r/ [=>]90.2 | \[ \color{blue}{\frac{a}{-\left(1 + \left(k \cdot 10 + k \cdot k\right)\right)} \cdot \left(-{k}^{m}\right)}
\] |
neg-sub0 [=>]90.2 | \[ \frac{a}{\color{blue}{0 - \left(1 + \left(k \cdot 10 + k \cdot k\right)\right)}} \cdot \left(-{k}^{m}\right)
\] |
metadata-eval [<=]90.2 | \[ \frac{a}{\color{blue}{\log 1} - \left(1 + \left(k \cdot 10 + k \cdot k\right)\right)} \cdot \left(-{k}^{m}\right)
\] |
associate--r+ [=>]90.2 | \[ \frac{a}{\color{blue}{\left(\log 1 - 1\right) - \left(k \cdot 10 + k \cdot k\right)}} \cdot \left(-{k}^{m}\right)
\] |
metadata-eval [=>]90.2 | \[ \frac{a}{\left(\color{blue}{0} - 1\right) - \left(k \cdot 10 + k \cdot k\right)} \cdot \left(-{k}^{m}\right)
\] |
metadata-eval [=>]90.2 | \[ \frac{a}{\color{blue}{-1} - \left(k \cdot 10 + k \cdot k\right)} \cdot \left(-{k}^{m}\right)
\] |
distribute-lft-out [=>]90.2 | \[ \frac{a}{-1 - \color{blue}{k \cdot \left(10 + k\right)}} \cdot \left(-{k}^{m}\right)
\] |
+-commutative [=>]90.2 | \[ \frac{a}{-1 - k \cdot \color{blue}{\left(k + 10\right)}} \cdot \left(-{k}^{m}\right)
\] |
Taylor expanded in k around inf 90.2%
Simplified99.7%
[Start]90.2 | \[ \left(-1 \cdot \frac{a}{{k}^{2}}\right) \cdot \left(-{k}^{m}\right)
\] |
|---|---|
associate-*r/ [=>]90.2 | \[ \color{blue}{\frac{-1 \cdot a}{{k}^{2}}} \cdot \left(-{k}^{m}\right)
\] |
mul-1-neg [=>]90.2 | \[ \frac{\color{blue}{-a}}{{k}^{2}} \cdot \left(-{k}^{m}\right)
\] |
unpow2 [=>]90.2 | \[ \frac{-a}{\color{blue}{k \cdot k}} \cdot \left(-{k}^{m}\right)
\] |
associate-/r* [=>]99.7 | \[ \color{blue}{\frac{\frac{-a}{k}}{k}} \cdot \left(-{k}^{m}\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 7300 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.7% |
| Cost | 7176 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7172 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 7044 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.7% |
| Cost | 6921 |
| Alternative 6 | |
|---|---|
| Accuracy | 67.9% |
| Cost | 841 |
| Alternative 7 | |
|---|---|
| Accuracy | 69.4% |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Accuracy | 61.1% |
| Cost | 713 |
| Alternative 9 | |
|---|---|
| Accuracy | 60.7% |
| Cost | 585 |
| Alternative 10 | |
|---|---|
| Accuracy | 60.7% |
| Cost | 448 |
| Alternative 11 | |
|---|---|
| Accuracy | 26.7% |
| Cost | 64 |
herbie shell --seed 2023133
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))