Average Error: 15.1 → 1.6
Time: 16.5s
Precision: binary64
Cost: 13636
\[ \begin{array}{c}[m, n] = \mathsf{sort}([m, n])\\ \end{array} \]
\[\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 2 \cdot 10^{-95}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\\ \end{array} \]
(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 2e-95)
   (* (cos M) (exp (- (- m n) (* M M))))
   (* (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 <= 2e-95) {
		tmp = cos(M) * exp(((m - n) - (M * M)));
	} 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 <= 2d-95) then
        tmp = cos(m_1) * exp(((m - n) - (m_1 * m_1)))
    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 <= 2e-95) {
		tmp = Math.cos(M) * Math.exp(((m - n) - (M * M)));
	} 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 <= 2e-95:
		tmp = math.cos(M) * math.exp(((m - n) - (M * M)))
	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 <= 2e-95)
		tmp = Float64(cos(M) * exp(Float64(Float64(m - n) - Float64(M * M))));
	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 <= 2e-95)
		tmp = cos(M) * exp(((m - n) - (M * M)));
	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, 2e-95], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(m - n), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $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 2 \cdot 10^{-95}:\\
\;\;\;\;\cos M \cdot e^{\left(m - n\right) - M \cdot M}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if l < 1.99999999999999998e-95

    1. Initial program 15.8

      \[\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)} \]
    2. Simplified15.7

      \[\leadsto \color{blue}{\cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}} \]
      Proof

      [Start]15.8

      \[ \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.8

      \[ \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.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- [=>]15.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 [=>]15.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 [=>]15.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 [=>]15.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 [<=]15.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 [=>]15.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- [<=]15.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}}} \]
    3. Applied egg-rr15.9

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\right)} - 1} \]
    4. Simplified15.9

      \[\leadsto \color{blue}{\cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {\left(0.5 \cdot \left(n + m\right) - M\right)}^{2}\right)}} \]
      Proof

      [Start]15.9

      \[ e^{\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\right)} - 1 \]

      expm1-def [=>]15.9

      \[ \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(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\right)\right)} \]

      expm1-log1p [=>]15.9

      \[ \color{blue}{\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}} \]

      +-commutative [=>]15.9

      \[ \cos \left(\color{blue}{\left(n + m\right)} \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [=>]15.9

      \[ \cos \left(\color{blue}{\left(K \cdot 0.5\right) \cdot \left(n + m\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [=>]15.9

      \[ \cos \left(\color{blue}{\left(0.5 \cdot K\right)} \cdot \left(n + m\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      associate-*r* [<=]15.9

      \[ \cos \left(\color{blue}{0.5 \cdot \left(K \cdot \left(n + m\right)\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      fma-neg [=>]15.9

      \[ \cos \color{blue}{\left(\mathsf{fma}\left(0.5, K \cdot \left(n + m\right), -M\right)\right)} \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      distribute-rgt-in [=>]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, \color{blue}{n \cdot K + m \cdot K}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-lft-identity [<=]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, n \cdot K + \color{blue}{\left(1 \cdot m\right)} \cdot K, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      metadata-eval [<=]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, n \cdot K + \left(\color{blue}{\left(--1\right)} \cdot m\right) \cdot K, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      distribute-rgt-in [<=]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, \color{blue}{K \cdot \left(n + \left(--1\right) \cdot m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      cancel-sign-sub-inv [<=]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, K \cdot \color{blue}{\left(n - -1 \cdot m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      fma-neg [<=]15.9

      \[ \cos \color{blue}{\left(0.5 \cdot \left(K \cdot \left(n - -1 \cdot m\right)\right) - M\right)} \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      fma-neg [=>]15.9

      \[ \cos \color{blue}{\left(\mathsf{fma}\left(0.5, K \cdot \left(n - -1 \cdot m\right), -M\right)\right)} \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      cancel-sign-sub-inv [=>]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, K \cdot \color{blue}{\left(n + \left(--1\right) \cdot m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      distribute-lft-in [=>]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, \color{blue}{K \cdot n + K \cdot \left(\left(--1\right) \cdot m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      metadata-eval [=>]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, K \cdot n + K \cdot \left(\color{blue}{1} \cdot m\right), -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-lft-identity [=>]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, K \cdot n + K \cdot \color{blue}{m}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      distribute-lft-in [<=]15.9

      \[ \cos \left(\mathsf{fma}\left(0.5, \color{blue}{K \cdot \left(n + m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      fma-neg [<=]15.9

      \[ \cos \color{blue}{\left(0.5 \cdot \left(K \cdot \left(n + m\right)\right) - M\right)} \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      associate-*r* [=>]15.9

      \[ \cos \left(\color{blue}{\left(0.5 \cdot K\right) \cdot \left(n + m\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [<=]15.9

      \[ \cos \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot \left(n + m\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [<=]15.9

      \[ \cos \left(\color{blue}{\left(n + m\right) \cdot \left(K \cdot 0.5\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      +-commutative [<=]15.9

      \[ \cos \left(\color{blue}{\left(m + n\right)} \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      +-commutative [=>]15.9

      \[ \cos \left(\color{blue}{\left(n + m\right)} \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [=>]15.9

      \[ \cos \left(\left(n + m\right) \cdot \color{blue}{\left(0.5 \cdot K\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      associate--l- [=>]15.9

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\color{blue}{\left(m - n\right) - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}} \]

      +-commutative [=>]15.9

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {\left(\color{blue}{\left(n + m\right)} \cdot 0.5 - M\right)}^{2}\right)} \]

      *-commutative [=>]15.9

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {\left(\color{blue}{0.5 \cdot \left(n + m\right)} - M\right)}^{2}\right)} \]
    5. Taylor expanded in M around inf 18.0

      \[\leadsto \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + \color{blue}{{M}^{2}}\right)} \]
    6. Simplified18.0

      \[\leadsto \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + \color{blue}{M \cdot M}\right)} \]
      Proof

      [Start]18.0

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {M}^{2}\right)} \]

      unpow2 [=>]18.0

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + \color{blue}{M \cdot M}\right)} \]
    7. Taylor expanded in K around 0 4.9

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]
    8. Simplified4.9

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]
      Proof

      [Start]4.9

      \[ \cos \left(-M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]

      cos-neg [=>]4.9

      \[ \color{blue}{\cos M} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]
    9. Taylor expanded in l around 0 1.9

      \[\leadsto \cos M \cdot e^{\left(m - n\right) - \color{blue}{{M}^{2}}} \]
    10. Simplified1.9

      \[\leadsto \cos M \cdot e^{\left(m - n\right) - \color{blue}{M \cdot M}} \]
      Proof

      [Start]1.9

      \[ \cos M \cdot e^{\left(m - n\right) - {M}^{2}} \]

      unpow2 [=>]1.9

      \[ \cos M \cdot e^{\left(m - n\right) - \color{blue}{M \cdot M}} \]

    if 1.99999999999999998e-95 < l

    1. Initial program 13.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)} \]
    2. Simplified13.8

      \[\leadsto \color{blue}{\cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}} \]
      Proof

      [Start]13.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 [=>]13.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/ [<=]13.8

      \[ \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- [=>]13.8

      \[ \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 [=>]13.8

      \[ \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 [=>]13.8

      \[ \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 [=>]13.8

      \[ \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 [<=]13.8

      \[ \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 [=>]13.8

      \[ \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- [<=]13.8

      \[ \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}}} \]
    3. Applied egg-rr14.0

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\right)} - 1} \]
    4. Simplified13.9

      \[\leadsto \color{blue}{\cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {\left(0.5 \cdot \left(n + m\right) - M\right)}^{2}\right)}} \]
      Proof

      [Start]14.0

      \[ e^{\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\right)} - 1 \]

      expm1-def [=>]13.9

      \[ \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(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\right)\right)} \]

      expm1-log1p [=>]13.9

      \[ \color{blue}{\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}} \]

      +-commutative [=>]13.9

      \[ \cos \left(\color{blue}{\left(n + m\right)} \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [=>]13.9

      \[ \cos \left(\color{blue}{\left(K \cdot 0.5\right) \cdot \left(n + m\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [=>]13.9

      \[ \cos \left(\color{blue}{\left(0.5 \cdot K\right)} \cdot \left(n + m\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      associate-*r* [<=]14.0

      \[ \cos \left(\color{blue}{0.5 \cdot \left(K \cdot \left(n + m\right)\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      fma-neg [=>]14.0

      \[ \cos \color{blue}{\left(\mathsf{fma}\left(0.5, K \cdot \left(n + m\right), -M\right)\right)} \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      distribute-rgt-in [=>]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, \color{blue}{n \cdot K + m \cdot K}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-lft-identity [<=]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, n \cdot K + \color{blue}{\left(1 \cdot m\right)} \cdot K, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      metadata-eval [<=]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, n \cdot K + \left(\color{blue}{\left(--1\right)} \cdot m\right) \cdot K, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      distribute-rgt-in [<=]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, \color{blue}{K \cdot \left(n + \left(--1\right) \cdot m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      cancel-sign-sub-inv [<=]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, K \cdot \color{blue}{\left(n - -1 \cdot m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      fma-neg [<=]14.0

      \[ \cos \color{blue}{\left(0.5 \cdot \left(K \cdot \left(n - -1 \cdot m\right)\right) - M\right)} \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      fma-neg [=>]14.0

      \[ \cos \color{blue}{\left(\mathsf{fma}\left(0.5, K \cdot \left(n - -1 \cdot m\right), -M\right)\right)} \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      cancel-sign-sub-inv [=>]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, K \cdot \color{blue}{\left(n + \left(--1\right) \cdot m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      distribute-lft-in [=>]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, \color{blue}{K \cdot n + K \cdot \left(\left(--1\right) \cdot m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      metadata-eval [=>]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, K \cdot n + K \cdot \left(\color{blue}{1} \cdot m\right), -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-lft-identity [=>]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, K \cdot n + K \cdot \color{blue}{m}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      distribute-lft-in [<=]14.0

      \[ \cos \left(\mathsf{fma}\left(0.5, \color{blue}{K \cdot \left(n + m\right)}, -M\right)\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      fma-neg [<=]14.0

      \[ \cos \color{blue}{\left(0.5 \cdot \left(K \cdot \left(n + m\right)\right) - M\right)} \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      associate-*r* [=>]13.9

      \[ \cos \left(\color{blue}{\left(0.5 \cdot K\right) \cdot \left(n + m\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [<=]13.9

      \[ \cos \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot \left(n + m\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [<=]13.9

      \[ \cos \left(\color{blue}{\left(n + m\right) \cdot \left(K \cdot 0.5\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      +-commutative [<=]13.9

      \[ \cos \left(\color{blue}{\left(m + n\right)} \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      +-commutative [=>]13.9

      \[ \cos \left(\color{blue}{\left(n + m\right)} \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      *-commutative [=>]13.9

      \[ \cos \left(\left(n + m\right) \cdot \color{blue}{\left(0.5 \cdot K\right)} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}} \]

      associate--l- [=>]13.9

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\color{blue}{\left(m - n\right) - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}} \]

      +-commutative [=>]13.9

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {\left(\color{blue}{\left(n + m\right)} \cdot 0.5 - M\right)}^{2}\right)} \]

      *-commutative [=>]13.9

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {\left(\color{blue}{0.5 \cdot \left(n + m\right)} - M\right)}^{2}\right)} \]
    5. Taylor expanded in M around inf 14.0

      \[\leadsto \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + \color{blue}{{M}^{2}}\right)} \]
    6. Simplified14.0

      \[\leadsto \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + \color{blue}{M \cdot M}\right)} \]
      Proof

      [Start]14.0

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {M}^{2}\right)} \]

      unpow2 [=>]14.0

      \[ \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + \color{blue}{M \cdot M}\right)} \]
    7. Taylor expanded in K around 0 0.8

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]
    8. Simplified0.8

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]
      Proof

      [Start]0.8

      \[ \cos \left(-M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]

      cos-neg [=>]0.8

      \[ \color{blue}{\cos M} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-95}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error1.4
Cost26624
\[\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
Alternative 2
Error1.6
Cost13508
\[\begin{array}{l} \mathbf{if}\;\ell \leq 2 \cdot 10^{-15}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - \ell}\\ \end{array} \]
Alternative 3
Error19.3
Cost13380
\[\begin{array}{l} \mathbf{if}\;\ell \leq 0.098:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
Alternative 4
Error9.8
Cost13380
\[\begin{array}{l} \mathbf{if}\;\ell \leq -2.1 \cdot 10^{+116}:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - \ell}\\ \end{array} \]
Alternative 5
Error43.7
Cost13056
\[\cos M \cdot e^{-\ell} \]

Error

Reproduce

herbie shell --seed 2022354 
(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)))))))