| Alternative 1 | |
|---|---|
| Accuracy | 98.0% |
| 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 (or (<= M -0.106) (not (<= M 4.6e-5))) (* (cos M) (exp (* M (- M)))) (exp (+ (fabs (- m n)) (- (* (/ (+ m n) (/ 1.0 (+ m n))) -0.25) l)))))
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 ((M <= -0.106) || !(M <= 4.6e-5)) {
tmp = cos(M) * exp((M * -M));
} else {
tmp = exp((fabs((m - n)) + ((((m + n) / (1.0 / (m + n))) * -0.25) - l)));
}
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 ((m_1 <= (-0.106d0)) .or. (.not. (m_1 <= 4.6d-5))) then
tmp = cos(m_1) * exp((m_1 * -m_1))
else
tmp = exp((abs((m - n)) + ((((m + n) / (1.0d0 / (m + n))) * (-0.25d0)) - l)))
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 ((M <= -0.106) || !(M <= 4.6e-5)) {
tmp = Math.cos(M) * Math.exp((M * -M));
} else {
tmp = Math.exp((Math.abs((m - n)) + ((((m + n) / (1.0 / (m + n))) * -0.25) - l)));
}
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 (M <= -0.106) or not (M <= 4.6e-5): tmp = math.cos(M) * math.exp((M * -M)) else: tmp = math.exp((math.fabs((m - n)) + ((((m + n) / (1.0 / (m + n))) * -0.25) - l))) 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 ((M <= -0.106) || !(M <= 4.6e-5)) tmp = Float64(cos(M) * exp(Float64(M * Float64(-M)))); else tmp = exp(Float64(abs(Float64(m - n)) + Float64(Float64(Float64(Float64(m + n) / Float64(1.0 / Float64(m + n))) * -0.25) - l))); 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 ((M <= -0.106) || ~((M <= 4.6e-5))) tmp = cos(M) * exp((M * -M)); else tmp = exp((abs((m - n)) + ((((m + n) / (1.0 / (m + n))) * -0.25) - l))); 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[Or[LessEqual[M, -0.106], N[Not[LessEqual[M, 4.6e-5]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] + N[(N[(N[(N[(m + n), $MachinePrecision] / N[(1.0 / N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision] - l), $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}\;M \leq -0.106 \lor \neg \left(M \leq 4.6 \cdot 10^{-5}\right):\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{\left|m - n\right| + \left(\frac{m + n}{\frac{1}{m + n}} \cdot -0.25 - \ell\right)}\\
\end{array}
Results
if M < -0.105999999999999997 or 4.6e-5 < M Initial program 77.5%
Simplified77.6%
[Start]77.5 | \[ \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 [=>]77.5 | \[ \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/ [<=]77.6 | \[ \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- [=>]77.6 | \[ \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 [=>]77.6 | \[ \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 [=>]77.6 | \[ \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 [=>]77.6 | \[ \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 [<=]77.6 | \[ \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 [=>]77.6 | \[ \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- [<=]77.6 | \[ \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 99.9%
Simplified99.9%
[Start]99.9 | \[ \cos \left(-M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\] |
|---|---|
cos-neg [=>]99.9 | \[ \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 99.0%
Simplified99.0%
[Start]99.0 | \[ \cos M \cdot e^{-1 \cdot {M}^{2}}
\] |
|---|---|
mul-1-neg [=>]99.0 | \[ \cos M \cdot e^{\color{blue}{-{M}^{2}}}
\] |
unpow2 [=>]99.0 | \[ \cos M \cdot e^{-\color{blue}{M \cdot M}}
\] |
distribute-rgt-neg-in [=>]99.0 | \[ \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)}}
\] |
if -0.105999999999999997 < M < 4.6e-5Initial program 73.6%
Simplified73.7%
[Start]73.6 | \[ \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 [=>]73.6 | \[ \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/ [<=]73.7 | \[ \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- [=>]73.7 | \[ \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 [=>]73.7 | \[ \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 [=>]73.7 | \[ \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 [=>]73.7 | \[ \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 [<=]73.7 | \[ \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 [=>]73.7 | \[ \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- [<=]73.7 | \[ \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 95.9%
Simplified95.9%
[Start]95.9 | \[ \cos \left(-M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\] |
|---|---|
cos-neg [=>]95.9 | \[ \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 0 95.8%
Applied egg-rr95.8%
[Start]95.8 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(n + m\right)}^{2}\right)}
\] |
|---|---|
unpow2 [=>]95.8 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \color{blue}{\left(\left(n + m\right) \cdot \left(n + m\right)\right)}\right)}
\] |
flip-+ [=>]88.6 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \left(\left(n + m\right) \cdot \color{blue}{\frac{n \cdot n - m \cdot m}{n - m}}\right)\right)}
\] |
associate-*r/ [=>]88.6 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \color{blue}{\frac{\left(n + m\right) \cdot \left(n \cdot n - m \cdot m\right)}{n - m}}\right)}
\] |
associate-/l* [=>]88.6 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \color{blue}{\frac{n + m}{\frac{n - m}{n \cdot n - m \cdot m}}}\right)}
\] |
+-commutative [=>]88.6 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \frac{\color{blue}{m + n}}{\frac{n - m}{n \cdot n - m \cdot m}}\right)}
\] |
*-un-lft-identity [=>]88.6 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \frac{m + n}{\frac{\color{blue}{1 \cdot \left(n - m\right)}}{n \cdot n - m \cdot m}}\right)}
\] |
associate-/l* [=>]88.6 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \frac{m + n}{\color{blue}{\frac{1}{\frac{n \cdot n - m \cdot m}{n - m}}}}\right)}
\] |
flip-+ [<=]95.8 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \frac{m + n}{\frac{1}{\color{blue}{n + m}}}\right)}
\] |
+-commutative [=>]95.8 | \[ e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \frac{m + n}{\frac{1}{\color{blue}{m + n}}}\right)}
\] |
Final simplification97.5%
| Alternative 1 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 26624 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.4% |
| Cost | 13449 |
| Alternative 3 | |
|---|---|
| Accuracy | 90.8% |
| Cost | 13124 |
| Alternative 4 | |
|---|---|
| Accuracy | 84.8% |
| Cost | 7620 |
| Alternative 5 | |
|---|---|
| Accuracy | 76.6% |
| Cost | 7108 |
| Alternative 6 | |
|---|---|
| Accuracy | 69.7% |
| Cost | 6852 |
| Alternative 7 | |
|---|---|
| Accuracy | 69.1% |
| Cost | 6852 |
| Alternative 8 | |
|---|---|
| Accuracy | 32.6% |
| Cost | 6528 |
| Alternative 9 | |
|---|---|
| Accuracy | 7.2% |
| Cost | 6464 |
herbie shell --seed 2023138
(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)))))))