| Alternative 1 | |
|---|---|
| Error | 1.3 |
| Cost | 26624 |
(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 (if (<= l -1e+144) (* (cos M) (exp l)) (* (cos M) (exp (- (- m n) (+ l (* M M)))))))
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 tmp;
if (l <= -1e+144) {
tmp = cos(M) * exp(l);
} else {
tmp = cos(M) * exp(((m - n) - (l + (M * M))));
}
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) :: tmp
if (l <= (-1d+144)) then
tmp = cos(m_1) * exp(l)
else
tmp = cos(m_1) * exp(((m - n) - (l + (m_1 * m_1))))
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 tmp;
if (l <= -1e+144) {
tmp = Math.cos(M) * Math.exp(l);
} else {
tmp = Math.cos(M) * Math.exp(((m - n) - (l + (M * M))));
}
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): tmp = 0 if l <= -1e+144: tmp = math.cos(M) * math.exp(l) else: tmp = math.cos(M) * math.exp(((m - n) - (l + (M * M)))) 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) tmp = 0.0 if (l <= -1e+144) tmp = Float64(cos(M) * exp(l)); else tmp = Float64(cos(M) * exp(Float64(Float64(m - n) - Float64(l + Float64(M * M))))); 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) tmp = 0.0; if (l <= -1e+144) tmp = cos(M) * exp(l); else tmp = cos(M) * exp(((m - n) - (l + (M * M)))); 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_] := If[LessEqual[l, -1e+144], N[(N[Cos[M], $MachinePrecision] * N[Exp[l], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(m - n), $MachinePrecision] - N[(l + N[(M * M), $MachinePrecision]), $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}
\mathbf{if}\;\ell \leq -1 \cdot 10^{+144}:\\
\;\;\;\;\cos M \cdot e^{\ell}\\
\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\\
\end{array}
Results
if l < -1.00000000000000002e144Initial program 17.9
Simplified17.9
[Start]17.9 | \[ \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)}
\] |
|---|---|
*-commutative [=>]17.9 | \[ \cos \left(\frac{\color{blue}{\left(m + n\right) \cdot K}}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\] |
associate-*r/ [<=]17.9 | \[ \cos \left(\color{blue}{\left(m + n\right) \cdot \frac{K}{2}} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\] |
associate--r- [=>]17.9 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell\right) + \left|m - n\right|}}
\] |
+-commutative [=>]17.9 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left|m - n\right| + \left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell\right)}}
\] |
sub-neg [=>]17.9 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left|m - n\right| + \color{blue}{\left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) + \left(-\ell\right)\right)}}
\] |
distribute-neg-out [=>]17.9 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left|m - n\right| + \color{blue}{\left(-\left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)\right)}}
\] |
sub-neg [<=]17.9 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left|m - n\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}}
\] |
+-commutative [=>]17.9 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\ell + {\left(\frac{m + n}{2} - M\right)}^{2}\right)}}
\] |
associate--l- [<=]17.9 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}}
\] |
Taylor expanded in K around 0 0
Simplified0
[Start]0 | \[ \cos \left(-M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\] |
|---|---|
cos-neg [=>]0 | \[ \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\] |
Taylor expanded in m around inf 35.6
Simplified35.6
[Start]35.6 | \[ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - 0.25 \cdot {m}^{2}}
\] |
|---|---|
*-commutative [=>]35.6 | \[ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{{m}^{2} \cdot 0.25}}
\] |
unpow2 [=>]35.6 | \[ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(m \cdot m\right)} \cdot 0.25}
\] |
Taylor expanded in l around inf 64.0
Simplified64.0
[Start]64.0 | \[ \cos M \cdot e^{-1 \cdot \ell}
\] |
|---|---|
mul-1-neg [=>]64.0 | \[ \cos M \cdot e^{\color{blue}{-\ell}}
\] |
Applied egg-rr0
Simplified0
[Start]0 | \[ \left(1 + \cos M \cdot e^{\ell}\right) - 1
\] |
|---|---|
+-commutative [=>]0 | \[ \color{blue}{\left(\cos M \cdot e^{\ell} + 1\right)} - 1
\] |
associate--l+ [=>]0 | \[ \color{blue}{\cos M \cdot e^{\ell} + \left(1 - 1\right)}
\] |
metadata-eval [=>]0 | \[ \cos M \cdot e^{\ell} + \color{blue}{0}
\] |
+-rgt-identity [=>]0 | \[ \color{blue}{\cos M \cdot e^{\ell}}
\] |
if -1.00000000000000002e144 < l Initial program 15.4
Simplified15.4
[Start]15.4 | \[ \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)}
\] |
|---|---|
*-commutative [=>]15.4 | \[ \cos \left(\frac{\color{blue}{\left(m + n\right) \cdot K}}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\] |
associate-*r/ [<=]15.4 | \[ \cos \left(\color{blue}{\left(m + n\right) \cdot \frac{K}{2}} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\] |
associate--r- [=>]15.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell\right) + \left|m - n\right|}}
\] |
+-commutative [=>]15.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left|m - n\right| + \left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell\right)}}
\] |
sub-neg [=>]15.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left|m - n\right| + \color{blue}{\left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) + \left(-\ell\right)\right)}}
\] |
distribute-neg-out [=>]15.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left|m - n\right| + \color{blue}{\left(-\left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)\right)}}
\] |
sub-neg [<=]15.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left|m - n\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}}
\] |
+-commutative [=>]15.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\ell + {\left(\frac{m + n}{2} - M\right)}^{2}\right)}}
\] |
associate--l- [<=]15.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}}
\] |
Taylor expanded in M around inf 34.4
Simplified34.4
[Start]34.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {M}^{2}}
\] |
|---|---|
unpow2 [=>]34.4 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{M \cdot M}}
\] |
Applied egg-rr15.8
Simplified15.8
[Start]15.8 | \[ e^{\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]15.8 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\right)\right)}
\] |
expm1-log1p [=>]15.8 | \[ \color{blue}{\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}}
\] |
+-commutative [=>]15.8 | \[ \cos \left(\color{blue}{\left(n + m\right)} \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}
\] |
associate-*r* [=>]15.8 | \[ \cos \left(\color{blue}{\left(\left(n + m\right) \cdot K\right) \cdot 0.5} - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}
\] |
*-commutative [<=]15.8 | \[ \cos \left(\color{blue}{\left(K \cdot \left(n + m\right)\right)} \cdot 0.5 - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}
\] |
*-commutative [<=]15.8 | \[ \cos \left(\color{blue}{0.5 \cdot \left(K \cdot \left(n + m\right)\right)} - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}
\] |
Taylor expanded in K around 0 1.9
Simplified1.9
[Start]1.9 | \[ \cos \left(-M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}
\] |
|---|---|
cos-neg [=>]1.9 | \[ \color{blue}{\cos M} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}
\] |
Final simplification1.8
| Alternative 1 | |
|---|---|
| Error | 1.3 |
| Cost | 26624 |
| Alternative 2 | |
|---|---|
| Error | 14.2 |
| Cost | 13512 |
| Alternative 3 | |
|---|---|
| Error | 14.1 |
| Cost | 13512 |
| Alternative 4 | |
|---|---|
| Error | 30.9 |
| Cost | 13188 |
| Alternative 5 | |
|---|---|
| Error | 30.9 |
| Cost | 13124 |
| Alternative 6 | |
|---|---|
| Error | 43.8 |
| Cost | 6528 |
| Alternative 7 | |
|---|---|
| Error | 59.5 |
| Cost | 6464 |
herbie shell --seed 2023187
(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)))))))