| Alternative 1 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 7172 |
\[\begin{array}{l}
\mathbf{if}\;k \leq 0.1:\\
\;\;\;\;\left(a \cdot {k}^{m}\right) \cdot \left(1 + k \cdot -10\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{k}^{m}}{k} \cdot \frac{a}{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 (let* ((t_0 (* a (pow k m)))) (if (<= m 5.6e-14) (/ t_0 (+ (+ 1.0 (* k 10.0)) (* k k))) t_0)))
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 t_0 = a * pow(k, m);
double tmp;
if (m <= 5.6e-14) {
tmp = t_0 / ((1.0 + (k * 10.0)) + (k * k));
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = a * (k ** m)
if (m <= 5.6d-14) then
tmp = t_0 / ((1.0d0 + (k * 10.0d0)) + (k * k))
else
tmp = t_0
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 t_0 = a * Math.pow(k, m);
double tmp;
if (m <= 5.6e-14) {
tmp = t_0 / ((1.0 + (k * 10.0)) + (k * k));
} else {
tmp = t_0;
}
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): t_0 = a * math.pow(k, m) tmp = 0 if m <= 5.6e-14: tmp = t_0 / ((1.0 + (k * 10.0)) + (k * k)) else: tmp = t_0 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) t_0 = Float64(a * (k ^ m)) tmp = 0.0 if (m <= 5.6e-14) tmp = Float64(t_0 / Float64(Float64(1.0 + Float64(k * 10.0)) + Float64(k * k))); else tmp = t_0; 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) t_0 = a * (k ^ m); tmp = 0.0; if (m <= 5.6e-14) tmp = t_0 / ((1.0 + (k * 10.0)) + (k * k)); else tmp = t_0; 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_] := Block[{t$95$0 = N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[m, 5.6e-14], N[(t$95$0 / N[(N[(1.0 + N[(k * 10.0), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\begin{array}{l}
t_0 := a \cdot {k}^{m}\\
\mathbf{if}\;m \leq 5.6 \cdot 10^{-14}:\\
\;\;\;\;\frac{t_0}{\left(1 + k \cdot 10\right) + k \cdot k}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
if m < 5.6000000000000001e-14Initial program 95.8%
if 5.6000000000000001e-14 < m Initial program 78.1%
Simplified78.1%
[Start]78.1 | \[ \frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\] |
|---|---|
associate-*r/ [<=]78.1 | \[ \color{blue}{a \cdot \frac{{k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}}
\] |
associate-+l+ [=>]78.1 | \[ a \cdot \frac{{k}^{m}}{\color{blue}{1 + \left(10 \cdot k + k \cdot k\right)}}
\] |
+-commutative [=>]78.1 | \[ a \cdot \frac{{k}^{m}}{\color{blue}{\left(10 \cdot k + k \cdot k\right) + 1}}
\] |
distribute-rgt-out [=>]78.1 | \[ a \cdot \frac{{k}^{m}}{\color{blue}{k \cdot \left(10 + k\right)} + 1}
\] |
fma-def [=>]78.1 | \[ a \cdot \frac{{k}^{m}}{\color{blue}{\mathsf{fma}\left(k, 10 + k, 1\right)}}
\] |
+-commutative [=>]78.1 | \[ a \cdot \frac{{k}^{m}}{\mathsf{fma}\left(k, \color{blue}{k + 10}, 1\right)}
\] |
Taylor expanded in k around 0 56.3%
Simplified100.0%
[Start]56.3 | \[ a \cdot e^{\log k \cdot m}
\] |
|---|---|
exp-to-pow [=>]100.0 | \[ a \cdot \color{blue}{{k}^{m}}
\] |
Final simplification97.4%
| Alternative 1 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 7172 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.4% |
| Cost | 7044 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 6921 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.2% |
| Cost | 968 |
| Alternative 5 | |
|---|---|
| Accuracy | 65.6% |
| Cost | 844 |
| Alternative 6 | |
|---|---|
| Accuracy | 77.2% |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Accuracy | 47.1% |
| Cost | 716 |
| Alternative 8 | |
|---|---|
| Accuracy | 54.1% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Accuracy | 57.4% |
| Cost | 712 |
| Alternative 10 | |
|---|---|
| Accuracy | 60.7% |
| Cost | 712 |
| Alternative 11 | |
|---|---|
| Accuracy | 60.8% |
| Cost | 712 |
| Alternative 12 | |
|---|---|
| Accuracy | 44.1% |
| Cost | 584 |
| Alternative 13 | |
|---|---|
| Accuracy | 25.9% |
| Cost | 452 |
herbie shell --seed 2023158
(FPCore (a k m)
:name "Falkner and Boettcher, Appendix A"
:precision binary64
(/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))