| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 39232 |
\[\begin{array}{l}
t_0 := \sqrt{{k}^{m}}\\
t_0 \cdot \frac{\frac{a}{\mathsf{hypot}\left(1, k\right)} \cdot t_0}{\mathsf{hypot}\left(1, k\right)}
\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 5e+52) (/ a (/ (+ 1.0 (+ (* k 10.0) (* k k))) (pow k m))) (/ (/ a k) (* k (pow k (- m))))))
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 <= 5e+52) {
tmp = a / ((1.0 + ((k * 10.0) + (k * k))) / pow(k, m));
} else {
tmp = (a / k) / (k * pow(k, -m));
}
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 <= 5d+52) then
tmp = a / ((1.0d0 + ((k * 10.0d0) + (k * k))) / (k ** m))
else
tmp = (a / k) / (k * (k ** -m))
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 <= 5e+52) {
tmp = a / ((1.0 + ((k * 10.0) + (k * k))) / Math.pow(k, m));
} else {
tmp = (a / k) / (k * Math.pow(k, -m));
}
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 <= 5e+52: tmp = a / ((1.0 + ((k * 10.0) + (k * k))) / math.pow(k, m)) else: tmp = (a / k) / (k * math.pow(k, -m)) 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 <= 5e+52) tmp = Float64(a / Float64(Float64(1.0 + Float64(Float64(k * 10.0) + Float64(k * k))) / (k ^ m))); else tmp = Float64(Float64(a / k) / Float64(k * (k ^ Float64(-m)))); 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 <= 5e+52) tmp = a / ((1.0 + ((k * 10.0) + (k * k))) / (k ^ m)); else tmp = (a / k) / (k * (k ^ -m)); 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, 5e+52], N[(a / N[(N[(1.0 + N[(N[(k * 10.0), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[k, m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / k), $MachinePrecision] / N[(k * N[Power[k, (-m)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\begin{array}{l}
\mathbf{if}\;k \leq 5 \cdot 10^{+52}:\\
\;\;\;\;\frac{a}{\frac{1 + \left(k \cdot 10 + k \cdot k\right)}{{k}^{m}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{a}{k}}{k \cdot {k}^{\left(-m\right)}}\\
\end{array}
Results
if k < 5e52Initial program 0.1
Simplified0.1
[Start]0.1 | \[ \frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\] |
|---|---|
associate-/l* [=>]0.1 | \[ \color{blue}{\frac{a}{\frac{\left(1 + 10 \cdot k\right) + k \cdot k}{{k}^{m}}}}
\] |
associate-+l+ [=>]0.1 | \[ \frac{a}{\frac{\color{blue}{1 + \left(10 \cdot k + k \cdot k\right)}}{{k}^{m}}}
\] |
*-commutative [=>]0.1 | \[ \frac{a}{\frac{1 + \left(\color{blue}{k \cdot 10} + k \cdot k\right)}{{k}^{m}}}
\] |
if 5e52 < k Initial program 6.1
Simplified6.2
[Start]6.1 | \[ \frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\] |
|---|---|
associate-/l* [=>]6.2 | \[ \color{blue}{\frac{a}{\frac{\left(1 + 10 \cdot k\right) + k \cdot k}{{k}^{m}}}}
\] |
associate-+l+ [=>]6.2 | \[ \frac{a}{\frac{\color{blue}{1 + \left(10 \cdot k + k \cdot k\right)}}{{k}^{m}}}
\] |
*-commutative [=>]6.2 | \[ \frac{a}{\frac{1 + \left(\color{blue}{k \cdot 10} + k \cdot k\right)}{{k}^{m}}}
\] |
Taylor expanded in k around inf 6.2
Simplified6.2
[Start]6.2 | \[ \frac{a}{\frac{1 + {k}^{2}}{{k}^{m}}}
\] |
|---|---|
unpow2 [=>]6.2 | \[ \frac{a}{\frac{1 + \color{blue}{k \cdot k}}{{k}^{m}}}
\] |
Taylor expanded in k around inf 6.1
Simplified0.1
[Start]6.1 | \[ \frac{a \cdot e^{-1 \cdot \left(\log \left(\frac{1}{k}\right) \cdot m\right)}}{{k}^{2}}
\] |
|---|---|
unpow2 [=>]6.1 | \[ \frac{a \cdot e^{-1 \cdot \left(\log \left(\frac{1}{k}\right) \cdot m\right)}}{\color{blue}{k \cdot k}}
\] |
times-frac [=>]0.1 | \[ \color{blue}{\frac{a}{k} \cdot \frac{e^{-1 \cdot \left(\log \left(\frac{1}{k}\right) \cdot m\right)}}{k}}
\] |
mul-1-neg [=>]0.1 | \[ \frac{a}{k} \cdot \frac{e^{\color{blue}{-\log \left(\frac{1}{k}\right) \cdot m}}}{k}
\] |
exp-neg [=>]0.1 | \[ \frac{a}{k} \cdot \frac{\color{blue}{\frac{1}{e^{\log \left(\frac{1}{k}\right) \cdot m}}}}{k}
\] |
log-rec [=>]0.1 | \[ \frac{a}{k} \cdot \frac{\frac{1}{e^{\color{blue}{\left(-\log k\right)} \cdot m}}}{k}
\] |
distribute-lft-neg-in [<=]0.1 | \[ \frac{a}{k} \cdot \frac{\frac{1}{e^{\color{blue}{-\log k \cdot m}}}}{k}
\] |
exp-neg [=>]0.1 | \[ \frac{a}{k} \cdot \frac{\frac{1}{\color{blue}{\frac{1}{e^{\log k \cdot m}}}}}{k}
\] |
exp-to-pow [=>]0.1 | \[ \frac{a}{k} \cdot \frac{\frac{1}{\frac{1}{\color{blue}{{k}^{m}}}}}{k}
\] |
Applied egg-rr6.2
Simplified0.1
[Start]6.2 | \[ \frac{a}{\left(k \cdot k\right) \cdot {k}^{\left(-m\right)}}
\] |
|---|---|
associate-*l* [=>]6.2 | \[ \frac{a}{\color{blue}{k \cdot \left(k \cdot {k}^{\left(-m\right)}\right)}}
\] |
associate-/r* [=>]0.1 | \[ \color{blue}{\frac{\frac{a}{k}}{k \cdot {k}^{\left(-m\right)}}}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 39232 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 7172 |
| Alternative 3 | |
|---|---|
| Error | 0.8 |
| Cost | 7108 |
| Alternative 4 | |
|---|---|
| Error | 0.8 |
| Cost | 7044 |
| Alternative 5 | |
|---|---|
| Error | 2.5 |
| Cost | 6921 |
| Alternative 6 | |
|---|---|
| Error | 23.4 |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Error | 23.3 |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Error | 21.1 |
| Cost | 708 |
| Alternative 9 | |
|---|---|
| Error | 20.4 |
| Cost | 708 |
| Alternative 10 | |
|---|---|
| Error | 24.5 |
| Cost | 585 |
| Alternative 11 | |
|---|---|
| Error | 23.5 |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Error | 24.5 |
| Cost | 448 |
| Alternative 13 | |
|---|---|
| Error | 46.7 |
| Cost | 64 |
herbie shell --seed 2023083
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))