| Alternative 1 | |
|---|---|
| Error | 99.8% |
| Cost | 7300.00 |
\[\begin{array}{l}
\mathbf{if}\;k \leq 10^{+14}:\\
\;\;\;\;\frac{{k}^{m}}{\frac{1 + k \cdot \left(k + 10\right)}{a}}\\
\mathbf{else}:\\
\;\;\;\;{k}^{m} \cdot \frac{\frac{a}{k}}{k}\\
\end{array}
\]
(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 1e+14) (/ (* a (pow k m)) (+ (+ 1.0 (* k 10.0)) (* k k))) (* (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 <= 1e+14) {
tmp = (a * pow(k, m)) / ((1.0 + (k * 10.0)) + (k * k));
} 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 <= 1d+14) then
tmp = (a * (k ** m)) / ((1.0d0 + (k * 10.0d0)) + (k * k))
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 <= 1e+14) {
tmp = (a * Math.pow(k, m)) / ((1.0 + (k * 10.0)) + (k * k));
} 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 <= 1e+14: tmp = (a * math.pow(k, m)) / ((1.0 + (k * 10.0)) + (k * k)) 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 <= 1e+14) tmp = Float64(Float64(a * (k ^ m)) / Float64(Float64(1.0 + Float64(k * 10.0)) + Float64(k * k))); 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 <= 1e+14) tmp = (a * (k ^ m)) / ((1.0 + (k * 10.0)) + (k * k)); 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, 1e+14], N[(N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(k * 10.0), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $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 10^{+14}:\\
\;\;\;\;\frac{a \cdot {k}^{m}}{\left(1 + k \cdot 10\right) + k \cdot k}\\
\mathbf{else}:\\
\;\;\;\;{k}^{m} \cdot \frac{\frac{a}{k}}{k}\\
\end{array}
Results
if k < 1e14Initial program 99.9
if 1e14 < k Initial program 92.0
Taylor expanded in k around 0 91.9
Taylor expanded in k around inf 91.9
Simplified99.7
[Start]91.9 | \[ \frac{a \cdot e^{-1 \cdot \left(\log \left(\frac{1}{k}\right) \cdot m\right)}}{{k}^{2}}
\] |
|---|---|
associate-/l* [=>]91.9 | \[ \color{blue}{\frac{a}{\frac{{k}^{2}}{e^{-1 \cdot \left(\log \left(\frac{1}{k}\right) \cdot m\right)}}}}
\] |
associate-/r/ [=>]91.9 | \[ \color{blue}{\frac{a}{{k}^{2}} \cdot e^{-1 \cdot \left(\log \left(\frac{1}{k}\right) \cdot m\right)}}
\] |
*-commutative [=>]91.9 | \[ \color{blue}{e^{-1 \cdot \left(\log \left(\frac{1}{k}\right) \cdot m\right)} \cdot \frac{a}{{k}^{2}}}
\] |
mul-1-neg [=>]91.9 | \[ e^{\color{blue}{-\log \left(\frac{1}{k}\right) \cdot m}} \cdot \frac{a}{{k}^{2}}
\] |
log-rec [=>]91.9 | \[ e^{-\color{blue}{\left(-\log k\right)} \cdot m} \cdot \frac{a}{{k}^{2}}
\] |
distribute-lft-neg-out [=>]91.9 | \[ e^{-\color{blue}{\left(-\log k \cdot m\right)}} \cdot \frac{a}{{k}^{2}}
\] |
remove-double-neg [=>]91.9 | \[ e^{\color{blue}{\log k \cdot m}} \cdot \frac{a}{{k}^{2}}
\] |
exp-to-pow [=>]91.9 | \[ \color{blue}{{k}^{m}} \cdot \frac{a}{{k}^{2}}
\] |
unpow2 [=>]91.9 | \[ {k}^{m} \cdot \frac{a}{\color{blue}{k \cdot k}}
\] |
associate-/r* [=>]99.7 | \[ {k}^{m} \cdot \color{blue}{\frac{\frac{a}{k}}{k}}
\] |
Final simplification99.9
| Alternative 1 | |
|---|---|
| Error | 99.8% |
| Cost | 7300.00 |
| Alternative 2 | |
|---|---|
| Error | 98.8% |
| Cost | 7172.00 |
| Alternative 3 | |
|---|---|
| Error | 98.6% |
| Cost | 7044.00 |
| Alternative 4 | |
|---|---|
| Error | 96.1% |
| Cost | 6921.00 |
| Alternative 5 | |
|---|---|
| Error | 69.6% |
| Cost | 841.00 |
| Alternative 6 | |
|---|---|
| Error | 70.7% |
| Cost | 841.00 |
| Alternative 7 | |
|---|---|
| Error | 63.0% |
| Cost | 712.00 |
| Alternative 8 | |
|---|---|
| Error | 63.1% |
| Cost | 712.00 |
| Alternative 9 | |
|---|---|
| Error | 61.8% |
| Cost | 585.00 |
| Alternative 10 | |
|---|---|
| Error | 62.8% |
| Cost | 584.00 |
| Alternative 11 | |
|---|---|
| Error | 62.8% |
| Cost | 580.00 |
| Alternative 12 | |
|---|---|
| Error | 27.4% |
| Cost | 64.00 |
herbie shell --seed 2023121
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))