| Alternative 1 | |
|---|---|
| Error | 1.99% |
| 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+101) (* (cos M) (exp l)) (expm1 (log1p (* (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+101) {
tmp = cos(M) * exp(l);
} else {
tmp = expm1(log1p((cos(M) * exp(((m - n) - (l + (M * M)))))));
}
return tmp;
}
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+101) {
tmp = Math.cos(M) * Math.exp(l);
} else {
tmp = Math.expm1(Math.log1p((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+101: tmp = math.cos(M) * math.exp(l) else: tmp = math.expm1(math.log1p((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+101) tmp = Float64(cos(M) * exp(l)); else tmp = expm1(log1p(Float64(cos(M) * exp(Float64(Float64(m - n) - Float64(l + Float64(M * M))))))); end return 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+101], N[(N[Cos[M], $MachinePrecision] * N[Exp[l], $MachinePrecision]), $MachinePrecision], N[(Exp[N[Log[1 + N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(m - n), $MachinePrecision] - N[(l + N[(M * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $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^{+101}:\\
\;\;\;\;\cos M \cdot e^{\ell}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\cos M \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\right)\right)\\
\end{array}
Results
if l < -9.9999999999999998e100Initial program 28.3
Simplified28.3
[Start]28.3 | \[ \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 [=>]28.3 | \[ \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/ [<=]28.3 | \[ \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- [=>]28.3 | \[ \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 [=>]28.3 | \[ \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 [=>]28.3 | \[ \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 [=>]28.3 | \[ \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 [<=]28.3 | \[ \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 [=>]28.3 | \[ \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- [<=]28.3 | \[ \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 l around inf 100
Simplified100
[Start]100 | \[ \cos M \cdot e^{-1 \cdot \ell}
\] |
|---|---|
mul-1-neg [=>]100 | \[ \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 -9.9999999999999998e100 < l Initial program 22.65
Simplified22.65
[Start]22.65 | \[ \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 [=>]22.65 | \[ \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/ [<=]22.65 | \[ \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- [=>]22.65 | \[ \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 [=>]22.65 | \[ \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 [=>]22.65 | \[ \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 [=>]22.65 | \[ \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 [<=]22.65 | \[ \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 [=>]22.65 | \[ \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- [<=]22.65 | \[ \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 52.83
Simplified52.83
[Start]52.83 | \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {M}^{2}}
\] |
|---|---|
unpow2 [=>]52.83 | \[ \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-rr23.17
Taylor expanded in K around 0 2.85
Simplified2.85
[Start]2.85 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(-M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\right)\right)
\] |
|---|---|
cos-neg [=>]2.85 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\cos M} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\right)\right)
\] |
Final simplification2.5
| Alternative 1 | |
|---|---|
| Error | 1.99% |
| Cost | 26624 |
| Alternative 2 | |
|---|---|
| Error | 3.88% |
| Cost | 20100 |
| Alternative 3 | |
|---|---|
| Error | 5.34% |
| Cost | 13449 |
| Alternative 4 | |
|---|---|
| Error | 9.02% |
| Cost | 13124 |
| Alternative 5 | |
|---|---|
| Error | 17.62% |
| Cost | 6720 |
| Alternative 6 | |
|---|---|
| Error | 67.58% |
| Cost | 6528 |
| Alternative 7 | |
|---|---|
| Error | 92.5% |
| Cost | 6464 |
herbie shell --seed 2023121
(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)))))))