| Alternative 1 | |
|---|---|
| Error | 1.4 |
| Cost | 26624 |
\[\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\]
(FPCore (K m n M l) :precision binary64 (* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))
(FPCore (K m n M l)
:precision binary64
(let* ((t_0 (- m (+ n l))))
(if (<= l -5e+165)
(* (cos M) (exp l))
(if (<= l -2e-51)
(* (cos M) (exp (- t_0 (* M M))))
(* (cos M) (exp (- t_0 (pow (- (* m 0.5) M) 2.0))))))))double code(double K, double m, double n, double M, double l) {
return cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - fabs((m - n)))));
}
double code(double K, double m, double n, double M, double l) {
double t_0 = m - (n + l);
double tmp;
if (l <= -5e+165) {
tmp = cos(M) * exp(l);
} else if (l <= -2e-51) {
tmp = cos(M) * exp((t_0 - (M * M)));
} else {
tmp = cos(M) * exp((t_0 - pow(((m * 0.5) - M), 2.0)));
}
return tmp;
}
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = cos((((k * (m + n)) / 2.0d0) - m_1)) * exp((-((((m + n) / 2.0d0) - m_1) ** 2.0d0) - (l - abs((m - n)))))
end function
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
real(8) :: t_0
real(8) :: tmp
t_0 = m - (n + l)
if (l <= (-5d+165)) then
tmp = cos(m_1) * exp(l)
else if (l <= (-2d-51)) then
tmp = cos(m_1) * exp((t_0 - (m_1 * m_1)))
else
tmp = cos(m_1) * exp((t_0 - (((m * 0.5d0) - m_1) ** 2.0d0)))
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.cos((((K * (m + n)) / 2.0) - M)) * Math.exp((-Math.pow((((m + n) / 2.0) - M), 2.0) - (l - Math.abs((m - n)))));
}
public static double code(double K, double m, double n, double M, double l) {
double t_0 = m - (n + l);
double tmp;
if (l <= -5e+165) {
tmp = Math.cos(M) * Math.exp(l);
} else if (l <= -2e-51) {
tmp = Math.cos(M) * Math.exp((t_0 - (M * M)));
} else {
tmp = Math.cos(M) * Math.exp((t_0 - Math.pow(((m * 0.5) - M), 2.0)));
}
return tmp;
}
def code(K, m, n, M, l): return math.cos((((K * (m + n)) / 2.0) - M)) * math.exp((-math.pow((((m + n) / 2.0) - M), 2.0) - (l - math.fabs((m - n)))))
def code(K, m, n, M, l): t_0 = m - (n + l) tmp = 0 if l <= -5e+165: tmp = math.cos(M) * math.exp(l) elif l <= -2e-51: tmp = math.cos(M) * math.exp((t_0 - (M * M))) else: tmp = math.cos(M) * math.exp((t_0 - math.pow(((m * 0.5) - M), 2.0))) return tmp
function code(K, m, n, M, l) return Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * exp(Float64(Float64(-(Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)) - Float64(l - abs(Float64(m - n)))))) end
function code(K, m, n, M, l) t_0 = Float64(m - Float64(n + l)) tmp = 0.0 if (l <= -5e+165) tmp = Float64(cos(M) * exp(l)); elseif (l <= -2e-51) tmp = Float64(cos(M) * exp(Float64(t_0 - Float64(M * M)))); else tmp = Float64(cos(M) * exp(Float64(t_0 - (Float64(Float64(m * 0.5) - M) ^ 2.0)))); end return tmp end
function tmp = code(K, m, n, M, l) tmp = cos((((K * (m + n)) / 2.0) - M)) * exp((-((((m + n) / 2.0) - M) ^ 2.0) - (l - abs((m - n))))); end
function tmp_2 = code(K, m, n, M, l) t_0 = m - (n + l); tmp = 0.0; if (l <= -5e+165) tmp = cos(M) * exp(l); elseif (l <= -2e-51) tmp = cos(M) * exp((t_0 - (M * M))); else tmp = cos(M) * exp((t_0 - (((m * 0.5) - M) ^ 2.0))); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[((-N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]) - N[(l - N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(m - N[(n + l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5e+165], N[(N[Cos[M], $MachinePrecision] * N[Exp[l], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -2e-51], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(t$95$0 - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(t$95$0 - N[Power[N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\begin{array}{l}
t_0 := m - \left(n + \ell\right)\\
\mathbf{if}\;\ell \leq -5 \cdot 10^{+165}:\\
\;\;\;\;\cos M \cdot e^{\ell}\\
\mathbf{elif}\;\ell \leq -2 \cdot 10^{-51}:\\
\;\;\;\;\cos M \cdot e^{t_0 - M \cdot M}\\
\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{t_0 - {\left(m \cdot 0.5 - M\right)}^{2}}\\
\end{array}
Results
if l < -4.9999999999999997e165Initial program 16.8
Simplified16.5
Taylor expanded in l around inf 64.0
Simplified64.0
Applied egg-rr16.5
Taylor expanded in K around 0 0
Simplified0
if -4.9999999999999997e165 < l < -2e-51Initial program 15.7
Simplified15.6
Taylor expanded in K around 0 0.9
Simplified0.9
Taylor expanded in n around 0 14.9
Simplified2.1
Taylor expanded in m around 0 3.4
Simplified3.4
if -2e-51 < l Initial program 15.2
Simplified15.1
Taylor expanded in K around 0 1.7
Simplified1.7
Taylor expanded in n around 0 11.8
Simplified1.9
Final simplification2.0
| Alternative 1 | |
|---|---|
| Error | 1.4 |
| Cost | 26624 |
| Alternative 2 | |
|---|---|
| Error | 2.0 |
| Cost | 13636 |
| Alternative 3 | |
|---|---|
| Error | 13.3 |
| Cost | 13388 |
| Alternative 4 | |
|---|---|
| Error | 9.7 |
| Cost | 13380 |
| Alternative 5 | |
|---|---|
| Error | 9.7 |
| Cost | 13320 |
| Alternative 6 | |
|---|---|
| Error | 11.7 |
| Cost | 6984 |
| Alternative 7 | |
|---|---|
| Error | 27.5 |
| Cost | 6656 |
| Alternative 8 | |
|---|---|
| Error | 59.4 |
| Cost | 6464 |
| Alternative 9 | |
|---|---|
| Error | 59.4 |
| Cost | 64 |

herbie shell --seed 2022318
(FPCore (K m n M l)
:name "Maksimov and Kolovsky, Equation (32)"
:precision binary64
(* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))