Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.5% → 95.9%
Time: 16.7s
Alternatives: 16
Speedup: 3.9×

Specification

?
\[\begin{array}{l} \\ \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)} \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)))))))
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)))));
}
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
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)))));
}
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)))))
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 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
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]
\begin{array}{l}

\\
\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)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 16 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 75.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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)} \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)))))))
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)))));
}
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
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)))));
}
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)))))
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 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
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]
\begin{array}{l}

\\
\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)}
\end{array}

Alternative 1: 95.9% accurate, 1.3× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} t_0 := \left|m - n\right|\\ \mathbf{if}\;n \leq 20:\\ \;\;\;\;\cos M \cdot e^{\left(t_0 - \ell\right) + \left(\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot \left(M - m \cdot 0.5\right) - \left(n \cdot n\right) \cdot 0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- m n))))
   (if (<= n 20.0)
     (*
      (cos M)
      (exp
       (+
        (- t_0 l)
        (- (* (+ n (- (* m 0.5) M)) (- M (* m 0.5))) (* (* n n) 0.25)))))
     (exp (- t_0 (+ l (* 0.25 (pow (+ m n) 2.0))))))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n));
	double tmp;
	if (n <= 20.0) {
		tmp = cos(M) * exp(((t_0 - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	} else {
		tmp = exp((t_0 - (l + (0.25 * pow((m + n), 2.0)))));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 = abs((m - n))
    if (n <= 20.0d0) then
        tmp = cos(m_1) * exp(((t_0 - l) + (((n + ((m * 0.5d0) - m_1)) * (m_1 - (m * 0.5d0))) - ((n * n) * 0.25d0))))
    else
        tmp = exp((t_0 - (l + (0.25d0 * ((m + n) ** 2.0d0)))))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.abs((m - n));
	double tmp;
	if (n <= 20.0) {
		tmp = Math.cos(M) * Math.exp(((t_0 - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	} else {
		tmp = Math.exp((t_0 - (l + (0.25 * Math.pow((m + n), 2.0)))));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n))
	tmp = 0
	if n <= 20.0:
		tmp = math.cos(M) * math.exp(((t_0 - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))))
	else:
		tmp = math.exp((t_0 - (l + (0.25 * math.pow((m + n), 2.0)))))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	t_0 = abs(Float64(m - n))
	tmp = 0.0
	if (n <= 20.0)
		tmp = Float64(cos(M) * exp(Float64(Float64(t_0 - l) + Float64(Float64(Float64(n + Float64(Float64(m * 0.5) - M)) * Float64(M - Float64(m * 0.5))) - Float64(Float64(n * n) * 0.25)))));
	else
		tmp = exp(Float64(t_0 - Float64(l + Float64(0.25 * (Float64(m + n) ^ 2.0)))));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((m - n));
	tmp = 0.0;
	if (n <= 20.0)
		tmp = cos(M) * exp(((t_0 - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	else
		tmp = exp((t_0 - (l + (0.25 * ((m + n) ^ 2.0)))));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, 20.0], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(t$95$0 - l), $MachinePrecision] + N[(N[(N[(n + N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision] * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(t$95$0 - N[(l + N[(0.25 * N[Power[N[(m + n), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;n \leq 20:\\
\;\;\;\;\cos M \cdot e^{\left(t_0 - \ell\right) + \left(\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot \left(M - m \cdot 0.5\right) - \left(n \cdot n\right) \cdot 0.25\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 20

    1. Initial program 78.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)} \]
    2. Step-by-step derivation
      1. *-commutative78.3%

        \[\leadsto \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)} \]
      2. associate-*r/78.3%

        \[\leadsto \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)} \]
      3. associate--r-78.3%

        \[\leadsto \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|}} \]
      4. +-commutative78.3%

        \[\leadsto \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)}} \]
      5. associate-+r-78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+78.3%

        \[\leadsto \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)}} \]
      8. +-commutative78.3%

        \[\leadsto \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)}} \]
      9. associate--r+78.3%

        \[\leadsto \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. Simplified78.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 96.3%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg96.3%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified96.3%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 89.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+89.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow289.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out94.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative94.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow294.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified94.7%

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

    if 20 < n

    1. Initial program 63.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)} \]
    2. Step-by-step derivation
      1. *-commutative63.4%

        \[\leadsto \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)} \]
      2. associate-*r/63.4%

        \[\leadsto \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)} \]
      3. associate--r-63.4%

        \[\leadsto \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|}} \]
      4. +-commutative63.4%

        \[\leadsto \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)}} \]
      5. associate-+r-63.4%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg63.4%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+63.4%

        \[\leadsto \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)}} \]
      8. +-commutative63.4%

        \[\leadsto \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)}} \]
      9. associate--r+63.4%

        \[\leadsto \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. Simplified63.4%

      \[\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}}} \]
    4. Taylor expanded in K around 0 74.6%

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(n + m\right)\right)\right)\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg74.6%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(n + m\right)\right)\right)\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
      2. associate-*r*74.6%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(n + m\right)\right)}\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
      3. sin-neg74.6%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(n + m\right)\right)\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified74.6%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(n + m\right)\right)\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in M around 0 100.0%

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(n + m\right)}^{2}\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.1%

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

Alternative 2: 96.6% accurate, 1.0× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (* (cos M) (exp (- (- (fabs (- m n)) l) (pow (- (/ (+ m n) 2.0) M) 2.0)))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	return cos(M) * exp(((fabs((m - n)) - l) - pow((((m + n) / 2.0) - M), 2.0)));
}
NOTE: m and n should be sorted in increasing order before calling this 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
    code = cos(m_1) * exp(((abs((m - n)) - l) - ((((m + n) / 2.0d0) - m_1) ** 2.0d0)))
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M) * Math.exp(((Math.abs((m - n)) - l) - Math.pow((((m + n) / 2.0) - M), 2.0)));
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	return math.cos(M) * math.exp(((math.fabs((m - n)) - l) - math.pow((((m + n) / 2.0) - M), 2.0)))
m, n = sort([m, n])
function code(K, m, n, M, l)
	return Float64(cos(M) * exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))))
end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp(((abs((m - n)) - l) - ((((m + n) / 2.0) - M) ^ 2.0)));
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 74.1%

    \[\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. Step-by-step derivation
    1. *-commutative74.1%

      \[\leadsto \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)} \]
    2. associate-*r/74.1%

      \[\leadsto \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)} \]
    3. associate--r-74.1%

      \[\leadsto \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|}} \]
    4. +-commutative74.1%

      \[\leadsto \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)}} \]
    5. associate-+r-74.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
    6. unsub-neg74.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
    7. associate--r+74.1%

      \[\leadsto \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)}} \]
    8. +-commutative74.1%

      \[\leadsto \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)}} \]
    9. associate--r+74.1%

      \[\leadsto \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. Simplified74.1%

    \[\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}}} \]
  4. Taylor expanded in K around 0 97.3%

    \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  5. Step-by-step derivation
    1. cos-neg97.3%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  6. Simplified97.3%

    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  7. Final simplification97.3%

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

Alternative 3: 95.5% accurate, 1.4× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} t_0 := \left|m - n\right|\\ \mathbf{if}\;n \leq 10000:\\ \;\;\;\;e^{\left(t_0 - \ell\right) + \left(\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot \left(M - m \cdot 0.5\right) - \left(n \cdot n\right) \cdot 0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- m n))))
   (if (<= n 10000.0)
     (exp
      (+
       (- t_0 l)
       (- (* (+ n (- (* m 0.5) M)) (- M (* m 0.5))) (* (* n n) 0.25))))
     (exp (- t_0 (+ l (* 0.25 (pow (+ m n) 2.0))))))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n));
	double tmp;
	if (n <= 10000.0) {
		tmp = exp(((t_0 - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	} else {
		tmp = exp((t_0 - (l + (0.25 * pow((m + n), 2.0)))));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 = abs((m - n))
    if (n <= 10000.0d0) then
        tmp = exp(((t_0 - l) + (((n + ((m * 0.5d0) - m_1)) * (m_1 - (m * 0.5d0))) - ((n * n) * 0.25d0))))
    else
        tmp = exp((t_0 - (l + (0.25d0 * ((m + n) ** 2.0d0)))))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.abs((m - n));
	double tmp;
	if (n <= 10000.0) {
		tmp = Math.exp(((t_0 - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	} else {
		tmp = Math.exp((t_0 - (l + (0.25 * Math.pow((m + n), 2.0)))));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n))
	tmp = 0
	if n <= 10000.0:
		tmp = math.exp(((t_0 - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))))
	else:
		tmp = math.exp((t_0 - (l + (0.25 * math.pow((m + n), 2.0)))))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	t_0 = abs(Float64(m - n))
	tmp = 0.0
	if (n <= 10000.0)
		tmp = exp(Float64(Float64(t_0 - l) + Float64(Float64(Float64(n + Float64(Float64(m * 0.5) - M)) * Float64(M - Float64(m * 0.5))) - Float64(Float64(n * n) * 0.25))));
	else
		tmp = exp(Float64(t_0 - Float64(l + Float64(0.25 * (Float64(m + n) ^ 2.0)))));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((m - n));
	tmp = 0.0;
	if (n <= 10000.0)
		tmp = exp(((t_0 - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	else
		tmp = exp((t_0 - (l + (0.25 * ((m + n) ^ 2.0)))));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, 10000.0], N[Exp[N[(N[(t$95$0 - l), $MachinePrecision] + N[(N[(N[(n + N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision] * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(t$95$0 - N[(l + N[(0.25 * N[Power[N[(m + n), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;n \leq 10000:\\
\;\;\;\;e^{\left(t_0 - \ell\right) + \left(\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot \left(M - m \cdot 0.5\right) - \left(n \cdot n\right) \cdot 0.25\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 1e4

    1. Initial program 78.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)} \]
    2. Step-by-step derivation
      1. *-commutative78.3%

        \[\leadsto \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)} \]
      2. associate-*r/78.3%

        \[\leadsto \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)} \]
      3. associate--r-78.3%

        \[\leadsto \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|}} \]
      4. +-commutative78.3%

        \[\leadsto \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)}} \]
      5. associate-+r-78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+78.3%

        \[\leadsto \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)}} \]
      8. +-commutative78.3%

        \[\leadsto \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)}} \]
      9. associate--r+78.3%

        \[\leadsto \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. Simplified78.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 96.3%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg96.3%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified96.3%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 89.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+89.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow289.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out94.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative94.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow294.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified94.7%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 93.0%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]

    if 1e4 < n

    1. Initial program 63.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)} \]
    2. Step-by-step derivation
      1. *-commutative63.4%

        \[\leadsto \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)} \]
      2. associate-*r/63.4%

        \[\leadsto \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)} \]
      3. associate--r-63.4%

        \[\leadsto \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|}} \]
      4. +-commutative63.4%

        \[\leadsto \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)}} \]
      5. associate-+r-63.4%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg63.4%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+63.4%

        \[\leadsto \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)}} \]
      8. +-commutative63.4%

        \[\leadsto \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)}} \]
      9. associate--r+63.4%

        \[\leadsto \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. Simplified63.4%

      \[\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}}} \]
    4. Taylor expanded in K around 0 74.6%

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(n + m\right)\right)\right)\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg74.6%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(n + m\right)\right)\right)\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
      2. associate-*r*74.6%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(n + m\right)\right)}\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
      3. sin-neg74.6%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(n + m\right)\right)\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified74.6%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(n + m\right)\right)\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in M around 0 100.0%

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(n + m\right)}^{2}\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.0%

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

Alternative 4: 96.2% accurate, 1.9× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} \mathbf{if}\;n \leq 2 \cdot 10^{+106}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) + \left(\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot \left(M - m \cdot 0.5\right) - \left(n \cdot n\right) \cdot 0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 2e+106)
   (exp
    (+
     (- (fabs (- m n)) l)
     (- (* (+ n (- (* m 0.5) M)) (- M (* m 0.5))) (* (* n n) 0.25))))
   (exp (* (* n n) -0.25))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 2e+106) {
		tmp = exp(((fabs((m - n)) - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	} else {
		tmp = exp(((n * n) * -0.25));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 (n <= 2d+106) then
        tmp = exp(((abs((m - n)) - l) + (((n + ((m * 0.5d0) - m_1)) * (m_1 - (m * 0.5d0))) - ((n * n) * 0.25d0))))
    else
        tmp = exp(((n * n) * (-0.25d0)))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 2e+106) {
		tmp = Math.exp(((Math.abs((m - n)) - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	} else {
		tmp = Math.exp(((n * n) * -0.25));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	tmp = 0
	if n <= 2e+106:
		tmp = math.exp(((math.fabs((m - n)) - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))))
	else:
		tmp = math.exp(((n * n) * -0.25))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	tmp = 0.0
	if (n <= 2e+106)
		tmp = exp(Float64(Float64(abs(Float64(m - n)) - l) + Float64(Float64(Float64(n + Float64(Float64(m * 0.5) - M)) * Float64(M - Float64(m * 0.5))) - Float64(Float64(n * n) * 0.25))));
	else
		tmp = exp(Float64(Float64(n * n) * -0.25));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (n <= 2e+106)
		tmp = exp(((abs((m - n)) - l) + (((n + ((m * 0.5) - M)) * (M - (m * 0.5))) - ((n * n) * 0.25))));
	else
		tmp = exp(((n * n) * -0.25));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 2e+106], N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] + N[(N[(N[(n + N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision] * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
\mathbf{if}\;n \leq 2 \cdot 10^{+106}:\\
\;\;\;\;e^{\left(\left|m - n\right| - \ell\right) + \left(\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot \left(M - m \cdot 0.5\right) - \left(n \cdot n\right) \cdot 0.25\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 2.00000000000000018e106

    1. Initial program 79.1%

      \[\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. Step-by-step derivation
      1. *-commutative79.1%

        \[\leadsto \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)} \]
      2. associate-*r/79.1%

        \[\leadsto \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)} \]
      3. associate--r-79.1%

        \[\leadsto \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|}} \]
      4. +-commutative79.1%

        \[\leadsto \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)}} \]
      5. associate-+r-79.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg79.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+79.1%

        \[\leadsto \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)}} \]
      8. +-commutative79.1%

        \[\leadsto \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)}} \]
      9. associate--r+79.1%

        \[\leadsto \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. Simplified79.1%

      \[\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}}} \]
    4. Taylor expanded in K around 0 96.6%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg96.6%

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 89.9%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+89.9%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow289.9%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out95.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative95.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow295.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified95.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 93.8%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]

    if 2.00000000000000018e106 < n

    1. Initial program 53.1%

      \[\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. Step-by-step derivation
      1. *-commutative53.1%

        \[\leadsto \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)} \]
      2. associate-*r/53.1%

        \[\leadsto \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)} \]
      3. associate--r-53.1%

        \[\leadsto \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|}} \]
      4. +-commutative53.1%

        \[\leadsto \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)}} \]
      5. associate-+r-53.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg53.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+53.1%

        \[\leadsto \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)}} \]
      8. +-commutative53.1%

        \[\leadsto \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)}} \]
      9. associate--r+53.1%

        \[\leadsto \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. Simplified53.1%

      \[\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}}} \]
    4. Taylor expanded in K around 0 100.0%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 67.3%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+67.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow267.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out75.5%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative75.5%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow275.5%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified75.5%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 75.5%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in n around inf 100.0%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow2100.0%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    13. Simplified100.0%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right) \cdot -0.25}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.0%

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

Alternative 5: 93.7% accurate, 1.9× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} t_0 := e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -2:\\ \;\;\;\;\cos M \cdot t_0\\ \mathbf{elif}\;M \leq 2.35 \cdot 10^{+21}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right) + \left(n \cdot n\right) \cdot 0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* M (- M)))))
   (if (<= M -2.0)
     (* (cos M) t_0)
     (if (<= M 2.35e+21)
       (exp
        (-
         (- (fabs (- m n)) l)
         (+ (* 0.5 (* m (+ n (* m 0.5)))) (* (* n n) 0.25))))
       t_0))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((M * -M));
	double tmp;
	if (M <= -2.0) {
		tmp = cos(M) * t_0;
	} else if (M <= 2.35e+21) {
		tmp = exp(((fabs((m - n)) - l) - ((0.5 * (m * (n + (m * 0.5)))) + ((n * n) * 0.25))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 = exp((m_1 * -m_1))
    if (m_1 <= (-2.0d0)) then
        tmp = cos(m_1) * t_0
    else if (m_1 <= 2.35d+21) then
        tmp = exp(((abs((m - n)) - l) - ((0.5d0 * (m * (n + (m * 0.5d0)))) + ((n * n) * 0.25d0))))
    else
        tmp = t_0
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((M * -M));
	double tmp;
	if (M <= -2.0) {
		tmp = Math.cos(M) * t_0;
	} else if (M <= 2.35e+21) {
		tmp = Math.exp(((Math.abs((m - n)) - l) - ((0.5 * (m * (n + (m * 0.5)))) + ((n * n) * 0.25))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	t_0 = math.exp((M * -M))
	tmp = 0
	if M <= -2.0:
		tmp = math.cos(M) * t_0
	elif M <= 2.35e+21:
		tmp = math.exp(((math.fabs((m - n)) - l) - ((0.5 * (m * (n + (m * 0.5)))) + ((n * n) * 0.25))))
	else:
		tmp = t_0
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	t_0 = exp(Float64(M * Float64(-M)))
	tmp = 0.0
	if (M <= -2.0)
		tmp = Float64(cos(M) * t_0);
	elseif (M <= 2.35e+21)
		tmp = exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(Float64(0.5 * Float64(m * Float64(n + Float64(m * 0.5)))) + Float64(Float64(n * n) * 0.25))));
	else
		tmp = t_0;
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp((M * -M));
	tmp = 0.0;
	if (M <= -2.0)
		tmp = cos(M) * t_0;
	elseif (M <= 2.35e+21)
		tmp = exp(((abs((m - n)) - l) - ((0.5 * (m * (n + (m * 0.5)))) + ((n * n) * 0.25))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[M, -2.0], N[(N[Cos[M], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[M, 2.35e+21], N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(N[(0.5 * N[(m * N[(n + N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(n * n), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
t_0 := e^{M \cdot \left(-M\right)}\\
\mathbf{if}\;M \leq -2:\\
\;\;\;\;\cos M \cdot t_0\\

\mathbf{elif}\;M \leq 2.35 \cdot 10^{+21}:\\
\;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right) + \left(n \cdot n\right) \cdot 0.25\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -2

    1. Initial program 84.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)} \]
    2. Step-by-step derivation
      1. *-commutative84.5%

        \[\leadsto \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)} \]
      2. associate-*r/84.5%

        \[\leadsto \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)} \]
      3. associate--r-84.5%

        \[\leadsto \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|}} \]
      4. +-commutative84.5%

        \[\leadsto \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)}} \]
      5. associate-+r-84.5%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg84.5%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+84.5%

        \[\leadsto \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)}} \]
      8. +-commutative84.5%

        \[\leadsto \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)}} \]
      9. associate--r+84.5%

        \[\leadsto \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. Simplified84.5%

      \[\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}}} \]
    4. Taylor expanded in K around 0 100.0%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in M around inf 96.6%

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    8. Step-by-step derivation
      1. mul-1-neg96.6%

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
      2. unpow296.6%

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in96.6%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    9. Simplified96.6%

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

    if -2 < M < 2.35e21

    1. Initial program 71.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)} \]
    2. Step-by-step derivation
      1. *-commutative71.6%

        \[\leadsto \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)} \]
      2. associate-*r/71.6%

        \[\leadsto \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)} \]
      3. associate--r-71.6%

        \[\leadsto \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|}} \]
      4. +-commutative71.6%

        \[\leadsto \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)}} \]
      5. associate-+r-71.6%

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+71.6%

        \[\leadsto \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)}} \]
      8. +-commutative71.6%

        \[\leadsto \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)}} \]
      9. associate--r+71.6%

        \[\leadsto \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. Simplified71.6%

      \[\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}}} \]
    4. Taylor expanded in K around 0 95.0%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg95.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified95.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 89.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+89.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow289.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out91.4%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative91.4%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow291.4%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified91.4%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 91.4%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in M around 0 91.4%

      \[\leadsto 1 \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{0.5 \cdot \left(\left(n + 0.5 \cdot m\right) \cdot m\right)} + \left(n \cdot n\right) \cdot 0.25\right)} \]

    if 2.35e21 < M

    1. Initial program 70.0%

      \[\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. Step-by-step derivation
      1. *-commutative70.0%

        \[\leadsto \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)} \]
      2. associate-*r/70.0%

        \[\leadsto \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)} \]
      3. associate--r-70.0%

        \[\leadsto \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|}} \]
      4. +-commutative70.0%

        \[\leadsto \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)}} \]
      5. associate-+r-70.0%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg70.0%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+70.0%

        \[\leadsto \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)}} \]
      8. +-commutative70.0%

        \[\leadsto \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)}} \]
      9. associate--r+70.0%

        \[\leadsto \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. Simplified70.0%

      \[\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}}} \]
    4. Taylor expanded in K around 0 100.0%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 80.0%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+80.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow280.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out86.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative86.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow286.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified86.7%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 85.0%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in M around inf 98.4%

      \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    12. Step-by-step derivation
      1. neg-mul-198.4%

        \[\leadsto 1 \cdot e^{\color{blue}{-{M}^{2}}} \]
      2. unpow298.4%

        \[\leadsto 1 \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in98.4%

        \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    13. Simplified98.4%

      \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification94.2%

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

Alternative 6: 89.2% accurate, 1.9× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -80000000000:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq 3 \cdot 10^{-303}:\\ \;\;\;\;\cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(m - \left(n + \ell\right)\right) - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -80000000000.0)
   (exp (* -0.25 (* m m)))
   (if (<= m 3e-303)
     (* (cos (- (* (+ m n) (/ K 2.0)) M)) (exp (- (- m (+ n l)) (* M M))))
     (exp (- (- (fabs (- m n)) l) (* (* n n) 0.25))))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -80000000000.0) {
		tmp = exp((-0.25 * (m * m)));
	} else if (m <= 3e-303) {
		tmp = cos((((m + n) * (K / 2.0)) - M)) * exp(((m - (n + l)) - (M * M)));
	} else {
		tmp = exp(((fabs((m - n)) - l) - ((n * n) * 0.25)));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 <= (-80000000000.0d0)) then
        tmp = exp(((-0.25d0) * (m * m)))
    else if (m <= 3d-303) then
        tmp = cos((((m + n) * (k / 2.0d0)) - m_1)) * exp(((m - (n + l)) - (m_1 * m_1)))
    else
        tmp = exp(((abs((m - n)) - l) - ((n * n) * 0.25d0)))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -80000000000.0) {
		tmp = Math.exp((-0.25 * (m * m)));
	} else if (m <= 3e-303) {
		tmp = Math.cos((((m + n) * (K / 2.0)) - M)) * Math.exp(((m - (n + l)) - (M * M)));
	} else {
		tmp = Math.exp(((Math.abs((m - n)) - l) - ((n * n) * 0.25)));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	tmp = 0
	if m <= -80000000000.0:
		tmp = math.exp((-0.25 * (m * m)))
	elif m <= 3e-303:
		tmp = math.cos((((m + n) * (K / 2.0)) - M)) * math.exp(((m - (n + l)) - (M * M)))
	else:
		tmp = math.exp(((math.fabs((m - n)) - l) - ((n * n) * 0.25)))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -80000000000.0)
		tmp = exp(Float64(-0.25 * Float64(m * m)));
	elseif (m <= 3e-303)
		tmp = Float64(cos(Float64(Float64(Float64(m + n) * Float64(K / 2.0)) - M)) * exp(Float64(Float64(m - Float64(n + l)) - Float64(M * M))));
	else
		tmp = exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(Float64(n * n) * 0.25)));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -80000000000.0)
		tmp = exp((-0.25 * (m * m)));
	elseif (m <= 3e-303)
		tmp = cos((((m + n) * (K / 2.0)) - M)) * exp(((m - (n + l)) - (M * M)));
	else
		tmp = exp(((abs((m - n)) - l) - ((n * n) * 0.25)));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -80000000000.0], N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, 3e-303], N[(N[Cos[N[(N[(N[(m + n), $MachinePrecision] * N[(K / 2.0), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(m - N[(n + l), $MachinePrecision]), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
\mathbf{if}\;m \leq -80000000000:\\
\;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;m \leq 3 \cdot 10^{-303}:\\
\;\;\;\;\cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(m - \left(n + \ell\right)\right) - M \cdot M}\\

\mathbf{else}:\\
\;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < -8e10

    1. Initial program 62.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)} \]
    2. Step-by-step derivation
      1. *-commutative62.3%

        \[\leadsto \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)} \]
      2. associate-*r/62.3%

        \[\leadsto \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)} \]
      3. associate--r-62.3%

        \[\leadsto \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|}} \]
      4. +-commutative62.3%

        \[\leadsto \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)}} \]
      5. associate-+r-62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+62.3%

        \[\leadsto \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)}} \]
      8. +-commutative62.3%

        \[\leadsto \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)}} \]
      9. associate--r+62.3%

        \[\leadsto \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. Simplified62.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 95.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg95.1%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified95.1%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 73.8%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+73.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow273.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out83.6%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative83.6%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow283.6%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified83.6%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 83.6%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in m around inf 91.9%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative91.9%

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow291.9%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    13. Simplified91.9%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right) \cdot -0.25}} \]

    if -8e10 < m < 3.00000000000000028e-303

    1. Initial program 81.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. Step-by-step derivation
      1. *-commutative81.8%

        \[\leadsto \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)} \]
      2. associate-*r/81.8%

        \[\leadsto \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)} \]
      3. associate--r-81.8%

        \[\leadsto \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|}} \]
      4. +-commutative81.8%

        \[\leadsto \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)}} \]
      5. associate-+r-81.8%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg81.8%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+81.8%

        \[\leadsto \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)}} \]
      8. +-commutative81.8%

        \[\leadsto \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)}} \]
      9. associate--r+81.8%

        \[\leadsto \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. Simplified81.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}}} \]
    4. Step-by-step derivation
      1. exp-diff37.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \color{blue}{\frac{e^{\left|m - n\right| - \ell}}{e^{{\left(\frac{m + n}{2} - M\right)}^{2}}}} \]
      2. add-sqr-sqrt7.9%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \frac{e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell}}{e^{{\left(\frac{m + n}{2} - M\right)}^{2}}} \]
      3. fabs-sqr7.9%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \frac{e^{\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell}}{e^{{\left(\frac{m + n}{2} - M\right)}^{2}}} \]
      4. add-sqr-sqrt55.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \frac{e^{\color{blue}{\left(m - n\right)} - \ell}}{e^{{\left(\frac{m + n}{2} - M\right)}^{2}}} \]
      5. add-sqr-sqrt55.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \frac{e^{\left(m - n\right) - \ell}}{e^{\color{blue}{\sqrt{{\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \sqrt{{\left(\frac{m + n}{2} - M\right)}^{2}}}}} \]
      6. add-sqr-sqrt55.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \frac{e^{\left(m - n\right) - \ell}}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2}}}} \]
      7. div-inv55.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \frac{e^{\left(m - n\right) - \ell}}{e^{{\left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right)}^{2}}} \]
      8. fma-neg55.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \frac{e^{\left(m - n\right) - \ell}}{e^{{\color{blue}{\left(\mathsf{fma}\left(m + n, \frac{1}{2}, -M\right)\right)}}^{2}}} \]
      9. metadata-eval55.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \frac{e^{\left(m - n\right) - \ell}}{e^{{\left(\mathsf{fma}\left(m + n, \color{blue}{0.5}, -M\right)\right)}^{2}}} \]
    5. Applied egg-rr55.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \color{blue}{\frac{e^{\left(m - n\right) - \ell}}{e^{{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}}} \]
    6. Step-by-step derivation
      1. div-exp80.5%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot \color{blue}{e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}} \]
      2. associate--l-80.5%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(m - \left(n + \ell\right)\right)} - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      3. fma-neg80.5%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(m - \left(n + \ell\right)\right) - {\color{blue}{\left(\left(m + n\right) \cdot 0.5 - M\right)}}^{2}} \]
      4. *-commutative80.5%

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(m - \left(n + \ell\right)\right) - {\left(0.5 \cdot \color{blue}{\left(n + m\right)} - M\right)}^{2}} \]
    7. Simplified80.5%

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

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(m - \left(n + \ell\right)\right) - \color{blue}{{M}^{2}}} \]
    9. Step-by-step derivation
      1. unpow269.6%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(m - \left(n + \ell\right)\right) - \color{blue}{M \cdot M}} \]
    10. Simplified69.6%

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

    if 3.00000000000000028e-303 < m

    1. Initial program 76.0%

      \[\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. Step-by-step derivation
      1. *-commutative76.0%

        \[\leadsto \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)} \]
      2. associate-*r/76.0%

        \[\leadsto \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)} \]
      3. associate--r-76.0%

        \[\leadsto \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|}} \]
      4. +-commutative76.0%

        \[\leadsto \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)}} \]
      5. associate-+r-76.0%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg76.0%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+76.0%

        \[\leadsto \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)}} \]
      8. +-commutative76.0%

        \[\leadsto \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)}} \]
      9. associate--r+76.0%

        \[\leadsto \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. Simplified76.0%

      \[\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}}} \]
    4. Taylor expanded in n around inf 50.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{0.25 \cdot {n}^{2}}} \]
    5. Step-by-step derivation
      1. *-commutative50.9%

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(n \cdot n\right)} \cdot 0.25} \]
    6. Simplified50.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(n \cdot n\right) \cdot 0.25}} \]
    7. Taylor expanded in n around inf 50.2%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right)\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25} \]
    8. Taylor expanded in n around 0 69.0%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification74.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -80000000000:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq 3 \cdot 10^{-303}:\\ \;\;\;\;\cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(m - \left(n + \ell\right)\right) - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25}\\ \end{array} \]

Alternative 7: 84.6% accurate, 2.0× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} t_0 := e^{\left(\left|m - n\right| - \ell\right) - M \cdot M}\\ t_1 := e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{if}\;n \leq -2.9 \cdot 10^{-236}:\\ \;\;\;\;\cos M \cdot t_1\\ \mathbf{elif}\;n \leq 1.75 \cdot 10^{-271}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 4.8 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 14.2:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- (- (fabs (- m n)) l) (* M M))))
        (t_1 (exp (* -0.25 (* m m)))))
   (if (<= n -2.9e-236)
     (* (cos M) t_1)
     (if (<= n 1.75e-271)
       t_0
       (if (<= n 4.8e-254)
         t_1
         (if (<= n 14.2) t_0 (exp (* (* n n) -0.25))))))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(((fabs((m - n)) - l) - (M * M)));
	double t_1 = exp((-0.25 * (m * m)));
	double tmp;
	if (n <= -2.9e-236) {
		tmp = cos(M) * t_1;
	} else if (n <= 1.75e-271) {
		tmp = t_0;
	} else if (n <= 4.8e-254) {
		tmp = t_1;
	} else if (n <= 14.2) {
		tmp = t_0;
	} else {
		tmp = exp(((n * n) * -0.25));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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) :: t_1
    real(8) :: tmp
    t_0 = exp(((abs((m - n)) - l) - (m_1 * m_1)))
    t_1 = exp(((-0.25d0) * (m * m)))
    if (n <= (-2.9d-236)) then
        tmp = cos(m_1) * t_1
    else if (n <= 1.75d-271) then
        tmp = t_0
    else if (n <= 4.8d-254) then
        tmp = t_1
    else if (n <= 14.2d0) then
        tmp = t_0
    else
        tmp = exp(((n * n) * (-0.25d0)))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(((Math.abs((m - n)) - l) - (M * M)));
	double t_1 = Math.exp((-0.25 * (m * m)));
	double tmp;
	if (n <= -2.9e-236) {
		tmp = Math.cos(M) * t_1;
	} else if (n <= 1.75e-271) {
		tmp = t_0;
	} else if (n <= 4.8e-254) {
		tmp = t_1;
	} else if (n <= 14.2) {
		tmp = t_0;
	} else {
		tmp = Math.exp(((n * n) * -0.25));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	t_0 = math.exp(((math.fabs((m - n)) - l) - (M * M)))
	t_1 = math.exp((-0.25 * (m * m)))
	tmp = 0
	if n <= -2.9e-236:
		tmp = math.cos(M) * t_1
	elif n <= 1.75e-271:
		tmp = t_0
	elif n <= 4.8e-254:
		tmp = t_1
	elif n <= 14.2:
		tmp = t_0
	else:
		tmp = math.exp(((n * n) * -0.25))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	t_0 = exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(M * M)))
	t_1 = exp(Float64(-0.25 * Float64(m * m)))
	tmp = 0.0
	if (n <= -2.9e-236)
		tmp = Float64(cos(M) * t_1);
	elseif (n <= 1.75e-271)
		tmp = t_0;
	elseif (n <= 4.8e-254)
		tmp = t_1;
	elseif (n <= 14.2)
		tmp = t_0;
	else
		tmp = exp(Float64(Float64(n * n) * -0.25));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((abs((m - n)) - l) - (M * M)));
	t_1 = exp((-0.25 * (m * m)));
	tmp = 0.0;
	if (n <= -2.9e-236)
		tmp = cos(M) * t_1;
	elseif (n <= 1.75e-271)
		tmp = t_0;
	elseif (n <= 4.8e-254)
		tmp = t_1;
	elseif (n <= 14.2)
		tmp = t_0;
	else
		tmp = exp(((n * n) * -0.25));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, -2.9e-236], N[(N[Cos[M], $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[n, 1.75e-271], t$95$0, If[LessEqual[n, 4.8e-254], t$95$1, If[LessEqual[n, 14.2], t$95$0, N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]]]]]]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
t_0 := e^{\left(\left|m - n\right| - \ell\right) - M \cdot M}\\
t_1 := e^{-0.25 \cdot \left(m \cdot m\right)}\\
\mathbf{if}\;n \leq -2.9 \cdot 10^{-236}:\\
\;\;\;\;\cos M \cdot t_1\\

\mathbf{elif}\;n \leq 1.75 \cdot 10^{-271}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 4.8 \cdot 10^{-254}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;n \leq 14.2:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if n < -2.9e-236

    1. Initial program 72.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)} \]
    2. Step-by-step derivation
      1. *-commutative72.6%

        \[\leadsto \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)} \]
      2. associate-*r/72.6%

        \[\leadsto \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)} \]
      3. associate--r-72.6%

        \[\leadsto \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|}} \]
      4. +-commutative72.6%

        \[\leadsto \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)}} \]
      5. associate-+r-72.6%

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+72.6%

        \[\leadsto \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)}} \]
      8. +-commutative72.6%

        \[\leadsto \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)}} \]
      9. associate--r+72.6%

        \[\leadsto \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. Simplified72.6%

      \[\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}}} \]
    4. Taylor expanded in K around 0 99.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg99.1%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified99.1%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in m around inf 50.6%

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    8. Step-by-step derivation
      1. unpow250.6%

        \[\leadsto \cos M \cdot e^{-0.25 \cdot \color{blue}{\left(m \cdot m\right)}} \]
    9. Simplified50.6%

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

    if -2.9e-236 < n < 1.75e-271 or 4.80000000000000003e-254 < n < 14.199999999999999

    1. Initial program 88.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)} \]
    2. Step-by-step derivation
      1. *-commutative88.3%

        \[\leadsto \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)} \]
      2. associate-*r/88.3%

        \[\leadsto \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)} \]
      3. associate--r-88.3%

        \[\leadsto \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|}} \]
      4. +-commutative88.3%

        \[\leadsto \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)}} \]
      5. associate-+r-88.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg88.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+88.3%

        \[\leadsto \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)}} \]
      8. +-commutative88.3%

        \[\leadsto \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)}} \]
      9. associate--r+88.3%

        \[\leadsto \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. Simplified88.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 93.2%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg93.2%

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in M around inf 72.9%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{{M}^{2}}} \]
    8. Step-by-step derivation
      1. unpow272.9%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{M \cdot M}} \]
    9. Simplified72.9%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{M \cdot M}} \]
    10. Taylor expanded in M around 0 71.5%

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

    if 1.75e-271 < n < 4.80000000000000003e-254

    1. Initial program 66.7%

      \[\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. Step-by-step derivation
      1. *-commutative66.7%

        \[\leadsto \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)} \]
      2. associate-*r/66.7%

        \[\leadsto \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)} \]
      3. associate--r-66.7%

        \[\leadsto \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|}} \]
      4. +-commutative66.7%

        \[\leadsto \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)}} \]
      5. associate-+r-66.7%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg66.7%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+66.7%

        \[\leadsto \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)}} \]
      8. +-commutative66.7%

        \[\leadsto \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)}} \]
      9. associate--r+66.7%

        \[\leadsto \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. Simplified66.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}}} \]
    4. Taylor expanded in K around 0 100.0%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 100.0%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+100.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow2100.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out100.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative100.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow2100.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified100.0%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 100.0%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in m around inf 100.0%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow2100.0%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    13. Simplified100.0%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right) \cdot -0.25}} \]

    if 14.199999999999999 < n

    1. Initial program 63.2%

      \[\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. Step-by-step derivation
      1. *-commutative63.2%

        \[\leadsto \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)} \]
      2. associate-*r/63.2%

        \[\leadsto \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)} \]
      3. associate--r-63.2%

        \[\leadsto \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|}} \]
      4. +-commutative63.2%

        \[\leadsto \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)}} \]
      5. associate-+r-63.2%

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+63.2%

        \[\leadsto \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)}} \]
      8. +-commutative63.2%

        \[\leadsto \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)}} \]
      9. associate--r+63.2%

        \[\leadsto \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. Simplified63.2%

      \[\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}}} \]
    4. Taylor expanded in K around 0 98.4%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg98.4%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified98.4%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 75.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+75.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow275.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out82.1%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative82.1%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow282.1%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified82.1%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 82.1%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in n around inf 94.7%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative94.7%

        \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow294.7%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    13. Simplified94.7%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right) \cdot -0.25}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification70.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -2.9 \cdot 10^{-236}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;n \leq 1.75 \cdot 10^{-271}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot M}\\ \mathbf{elif}\;n \leq 4.8 \cdot 10^{-254}:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;n \leq 14.2:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]

Alternative 8: 86.2% accurate, 2.0× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -56:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -56.0)
   (exp (* -0.25 (* m m)))
   (exp (- (- (fabs (- m n)) l) (* (* n n) 0.25)))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -56.0) {
		tmp = exp((-0.25 * (m * m)));
	} else {
		tmp = exp(((fabs((m - n)) - l) - ((n * n) * 0.25)));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 <= (-56.0d0)) then
        tmp = exp(((-0.25d0) * (m * m)))
    else
        tmp = exp(((abs((m - n)) - l) - ((n * n) * 0.25d0)))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -56.0) {
		tmp = Math.exp((-0.25 * (m * m)));
	} else {
		tmp = Math.exp(((Math.abs((m - n)) - l) - ((n * n) * 0.25)));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	tmp = 0
	if m <= -56.0:
		tmp = math.exp((-0.25 * (m * m)))
	else:
		tmp = math.exp(((math.fabs((m - n)) - l) - ((n * n) * 0.25)))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -56.0)
		tmp = exp(Float64(-0.25 * Float64(m * m)));
	else
		tmp = exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(Float64(n * n) * 0.25)));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -56.0)
		tmp = exp((-0.25 * (m * m)));
	else
		tmp = exp(((abs((m - n)) - l) - ((n * n) * 0.25)));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -56.0], N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
\mathbf{if}\;m \leq -56:\\
\;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -56

    1. Initial program 62.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)} \]
    2. Step-by-step derivation
      1. *-commutative62.3%

        \[\leadsto \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)} \]
      2. associate-*r/62.3%

        \[\leadsto \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)} \]
      3. associate--r-62.3%

        \[\leadsto \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|}} \]
      4. +-commutative62.3%

        \[\leadsto \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)}} \]
      5. associate-+r-62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+62.3%

        \[\leadsto \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)}} \]
      8. +-commutative62.3%

        \[\leadsto \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)}} \]
      9. associate--r+62.3%

        \[\leadsto \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. Simplified62.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 95.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg95.1%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified95.1%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 74.8%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+74.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow274.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out84.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative84.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow284.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified84.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 84.2%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in m around inf 90.8%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative90.8%

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow290.8%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    13. Simplified90.8%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right) \cdot -0.25}} \]

    if -56 < m

    1. Initial program 78.1%

      \[\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. Step-by-step derivation
      1. *-commutative78.1%

        \[\leadsto \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)} \]
      2. associate-*r/78.1%

        \[\leadsto \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)} \]
      3. associate--r-78.1%

        \[\leadsto \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|}} \]
      4. +-commutative78.1%

        \[\leadsto \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)}} \]
      5. associate-+r-78.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg78.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+78.1%

        \[\leadsto \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)}} \]
      8. +-commutative78.1%

        \[\leadsto \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)}} \]
      9. associate--r+78.1%

        \[\leadsto \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. Simplified78.1%

      \[\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}}} \]
    4. Taylor expanded in n around inf 55.3%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{0.25 \cdot {n}^{2}}} \]
    5. Step-by-step derivation
      1. *-commutative55.3%

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(n \cdot n\right)} \cdot 0.25} \]
    6. Simplified55.3%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(n \cdot n\right) \cdot 0.25}} \]
    7. Taylor expanded in n around inf 54.1%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right)\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25} \]
    8. Taylor expanded in n around 0 71.1%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -56:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(n \cdot n\right) \cdot 0.25}\\ \end{array} \]

Alternative 9: 77.0% accurate, 2.0× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -53:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -2.85 \cdot 10^{-130}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -53.0)
   (exp (* -0.25 (* m m)))
   (if (<= m -2.85e-130)
     (* (cos M) (exp (- l)))
     (* (cos M) (exp (* n (* n -0.25)))))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -53.0) {
		tmp = exp((-0.25 * (m * m)));
	} else if (m <= -2.85e-130) {
		tmp = cos(M) * exp(-l);
	} else {
		tmp = cos(M) * exp((n * (n * -0.25)));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 <= (-53.0d0)) then
        tmp = exp(((-0.25d0) * (m * m)))
    else if (m <= (-2.85d-130)) then
        tmp = cos(m_1) * exp(-l)
    else
        tmp = cos(m_1) * exp((n * (n * (-0.25d0))))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -53.0) {
		tmp = Math.exp((-0.25 * (m * m)));
	} else if (m <= -2.85e-130) {
		tmp = Math.cos(M) * Math.exp(-l);
	} else {
		tmp = Math.cos(M) * Math.exp((n * (n * -0.25)));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	tmp = 0
	if m <= -53.0:
		tmp = math.exp((-0.25 * (m * m)))
	elif m <= -2.85e-130:
		tmp = math.cos(M) * math.exp(-l)
	else:
		tmp = math.cos(M) * math.exp((n * (n * -0.25)))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -53.0)
		tmp = exp(Float64(-0.25 * Float64(m * m)));
	elseif (m <= -2.85e-130)
		tmp = Float64(cos(M) * exp(Float64(-l)));
	else
		tmp = Float64(cos(M) * exp(Float64(n * Float64(n * -0.25))));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -53.0)
		tmp = exp((-0.25 * (m * m)));
	elseif (m <= -2.85e-130)
		tmp = cos(M) * exp(-l);
	else
		tmp = cos(M) * exp((n * (n * -0.25)));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -53.0], N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -2.85e-130], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(n * N[(n * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
\mathbf{if}\;m \leq -53:\\
\;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;m \leq -2.85 \cdot 10^{-130}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < -53

    1. Initial program 62.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)} \]
    2. Step-by-step derivation
      1. *-commutative62.3%

        \[\leadsto \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)} \]
      2. associate-*r/62.3%

        \[\leadsto \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)} \]
      3. associate--r-62.3%

        \[\leadsto \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|}} \]
      4. +-commutative62.3%

        \[\leadsto \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)}} \]
      5. associate-+r-62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+62.3%

        \[\leadsto \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)}} \]
      8. +-commutative62.3%

        \[\leadsto \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)}} \]
      9. associate--r+62.3%

        \[\leadsto \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. Simplified62.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 95.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg95.1%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified95.1%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 74.8%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+74.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow274.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out84.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative84.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow284.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified84.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 84.2%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in m around inf 90.8%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative90.8%

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow290.8%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    13. Simplified90.8%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right) \cdot -0.25}} \]

    if -53 < m < -2.8499999999999999e-130

    1. Initial program 76.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. Step-by-step derivation
      1. *-commutative76.8%

        \[\leadsto \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)} \]
      2. associate-*r/76.8%

        \[\leadsto \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)} \]
      3. associate--r-76.8%

        \[\leadsto \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|}} \]
      4. +-commutative76.8%

        \[\leadsto \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)}} \]
      5. associate-+r-76.8%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg76.8%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+76.8%

        \[\leadsto \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)}} \]
      8. +-commutative76.8%

        \[\leadsto \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)}} \]
      9. associate--r+76.8%

        \[\leadsto \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. Simplified76.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}}} \]
    4. Taylor expanded in K around 0 92.2%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg92.2%

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in l around inf 54.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    8. Step-by-step derivation
      1. mul-1-neg54.1%

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    9. Simplified54.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]

    if -2.8499999999999999e-130 < m

    1. Initial program 78.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)} \]
    2. Step-by-step derivation
      1. *-commutative78.3%

        \[\leadsto \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)} \]
      2. associate-*r/78.3%

        \[\leadsto \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)} \]
      3. associate--r-78.3%

        \[\leadsto \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|}} \]
      4. +-commutative78.3%

        \[\leadsto \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)}} \]
      5. associate-+r-78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+78.3%

        \[\leadsto \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)}} \]
      8. +-commutative78.3%

        \[\leadsto \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)}} \]
      9. associate--r+78.3%

        \[\leadsto \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. Simplified78.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 98.8%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg98.8%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified98.8%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around inf 58.8%

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    8. Step-by-step derivation
      1. metadata-eval58.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(-0.25\right)} \cdot {n}^{2}} \]
      2. distribute-lft-neg-in58.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
      3. *-commutative58.8%

        \[\leadsto \cos M \cdot e^{-\color{blue}{{n}^{2} \cdot 0.25}} \]
      4. unpow258.8%

        \[\leadsto \cos M \cdot e^{-\color{blue}{\left(n \cdot n\right)} \cdot 0.25} \]
      5. associate-*r*58.8%

        \[\leadsto \cos M \cdot e^{-\color{blue}{n \cdot \left(n \cdot 0.25\right)}} \]
      6. distribute-rgt-neg-in58.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{n \cdot \left(-n \cdot 0.25\right)}} \]
      7. distribute-rgt-neg-in58.8%

        \[\leadsto \cos M \cdot e^{n \cdot \color{blue}{\left(n \cdot \left(-0.25\right)\right)}} \]
      8. metadata-eval58.8%

        \[\leadsto \cos M \cdot e^{n \cdot \left(n \cdot \color{blue}{-0.25}\right)} \]
    9. Simplified58.8%

      \[\leadsto \cos M \cdot e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -53:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -2.85 \cdot 10^{-130}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 10: 77.0% accurate, 2.0× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -53:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.82 \cdot 10^{-127}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -53.0)
   (exp (* -0.25 (* m m)))
   (if (<= m -1.82e-127) (* (cos M) (exp (- l))) (exp (* (* n n) -0.25)))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -53.0) {
		tmp = exp((-0.25 * (m * m)));
	} else if (m <= -1.82e-127) {
		tmp = cos(M) * exp(-l);
	} else {
		tmp = exp(((n * n) * -0.25));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 <= (-53.0d0)) then
        tmp = exp(((-0.25d0) * (m * m)))
    else if (m <= (-1.82d-127)) then
        tmp = cos(m_1) * exp(-l)
    else
        tmp = exp(((n * n) * (-0.25d0)))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -53.0) {
		tmp = Math.exp((-0.25 * (m * m)));
	} else if (m <= -1.82e-127) {
		tmp = Math.cos(M) * Math.exp(-l);
	} else {
		tmp = Math.exp(((n * n) * -0.25));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	tmp = 0
	if m <= -53.0:
		tmp = math.exp((-0.25 * (m * m)))
	elif m <= -1.82e-127:
		tmp = math.cos(M) * math.exp(-l)
	else:
		tmp = math.exp(((n * n) * -0.25))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -53.0)
		tmp = exp(Float64(-0.25 * Float64(m * m)));
	elseif (m <= -1.82e-127)
		tmp = Float64(cos(M) * exp(Float64(-l)));
	else
		tmp = exp(Float64(Float64(n * n) * -0.25));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -53.0)
		tmp = exp((-0.25 * (m * m)));
	elseif (m <= -1.82e-127)
		tmp = cos(M) * exp(-l);
	else
		tmp = exp(((n * n) * -0.25));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -53.0], N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -1.82e-127], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
\mathbf{if}\;m \leq -53:\\
\;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;m \leq -1.82 \cdot 10^{-127}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

\mathbf{else}:\\
\;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < -53

    1. Initial program 62.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)} \]
    2. Step-by-step derivation
      1. *-commutative62.3%

        \[\leadsto \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)} \]
      2. associate-*r/62.3%

        \[\leadsto \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)} \]
      3. associate--r-62.3%

        \[\leadsto \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|}} \]
      4. +-commutative62.3%

        \[\leadsto \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)}} \]
      5. associate-+r-62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+62.3%

        \[\leadsto \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)}} \]
      8. +-commutative62.3%

        \[\leadsto \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)}} \]
      9. associate--r+62.3%

        \[\leadsto \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. Simplified62.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 95.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg95.1%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified95.1%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 74.8%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+74.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow274.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out84.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative84.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow284.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified84.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 84.2%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in m around inf 90.8%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative90.8%

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow290.8%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    13. Simplified90.8%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right) \cdot -0.25}} \]

    if -53 < m < -1.82000000000000002e-127

    1. Initial program 76.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. Step-by-step derivation
      1. *-commutative76.8%

        \[\leadsto \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)} \]
      2. associate-*r/76.8%

        \[\leadsto \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)} \]
      3. associate--r-76.8%

        \[\leadsto \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|}} \]
      4. +-commutative76.8%

        \[\leadsto \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)}} \]
      5. associate-+r-76.8%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg76.8%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+76.8%

        \[\leadsto \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)}} \]
      8. +-commutative76.8%

        \[\leadsto \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)}} \]
      9. associate--r+76.8%

        \[\leadsto \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. Simplified76.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}}} \]
    4. Taylor expanded in K around 0 92.2%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg92.2%

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in l around inf 54.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    8. Step-by-step derivation
      1. mul-1-neg54.1%

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    9. Simplified54.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]

    if -1.82000000000000002e-127 < m

    1. Initial program 78.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)} \]
    2. Step-by-step derivation
      1. *-commutative78.3%

        \[\leadsto \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)} \]
      2. associate-*r/78.3%

        \[\leadsto \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)} \]
      3. associate--r-78.3%

        \[\leadsto \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|}} \]
      4. +-commutative78.3%

        \[\leadsto \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)}} \]
      5. associate-+r-78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+78.3%

        \[\leadsto \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)}} \]
      8. +-commutative78.3%

        \[\leadsto \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)}} \]
      9. associate--r+78.3%

        \[\leadsto \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. Simplified78.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 98.8%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg98.8%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified98.8%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 90.5%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+90.5%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow290.5%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out95.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative95.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow295.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified95.3%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 94.1%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in n around inf 58.8%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative58.8%

        \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow258.8%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    13. Simplified58.8%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right) \cdot -0.25}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -53:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.82 \cdot 10^{-127}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]

Alternative 11: 76.8% accurate, 3.9× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -53 \lor \neg \left(m \leq 4.3 \cdot 10^{-39}\right):\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{M \cdot \left(-M\right)}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (or (<= m -53.0) (not (<= m 4.3e-39)))
   (exp (* -0.25 (* m m)))
   (exp (* M (- M)))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((m <= -53.0) || !(m <= 4.3e-39)) {
		tmp = exp((-0.25 * (m * m)));
	} else {
		tmp = exp((M * -M));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 <= (-53.0d0)) .or. (.not. (m <= 4.3d-39))) then
        tmp = exp(((-0.25d0) * (m * m)))
    else
        tmp = exp((m_1 * -m_1))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((m <= -53.0) || !(m <= 4.3e-39)) {
		tmp = Math.exp((-0.25 * (m * m)));
	} else {
		tmp = Math.exp((M * -M));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	tmp = 0
	if (m <= -53.0) or not (m <= 4.3e-39):
		tmp = math.exp((-0.25 * (m * m)))
	else:
		tmp = math.exp((M * -M))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	tmp = 0.0
	if ((m <= -53.0) || !(m <= 4.3e-39))
		tmp = exp(Float64(-0.25 * Float64(m * m)));
	else
		tmp = exp(Float64(M * Float64(-M)));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if ((m <= -53.0) || ~((m <= 4.3e-39)))
		tmp = exp((-0.25 * (m * m)));
	else
		tmp = exp((M * -M));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[m, -53.0], N[Not[LessEqual[m, 4.3e-39]], $MachinePrecision]], N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
\mathbf{if}\;m \leq -53 \lor \neg \left(m \leq 4.3 \cdot 10^{-39}\right):\\
\;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{M \cdot \left(-M\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -53 or 4.2999999999999999e-39 < m

    1. Initial program 69.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)} \]
    2. Step-by-step derivation
      1. *-commutative69.3%

        \[\leadsto \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)} \]
      2. associate-*r/69.3%

        \[\leadsto \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)} \]
      3. associate--r-69.3%

        \[\leadsto \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|}} \]
      4. +-commutative69.3%

        \[\leadsto \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)}} \]
      5. associate-+r-69.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg69.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+69.3%

        \[\leadsto \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)}} \]
      8. +-commutative69.3%

        \[\leadsto \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)}} \]
      9. associate--r+69.3%

        \[\leadsto \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. Simplified69.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 97.6%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg97.6%

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 82.7%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+82.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow282.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out90.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative90.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow290.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified90.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 89.5%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in m around inf 89.3%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative89.3%

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow289.3%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    13. Simplified89.3%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right) \cdot -0.25}} \]

    if -53 < m < 4.2999999999999999e-39

    1. Initial program 79.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)} \]
    2. Step-by-step derivation
      1. *-commutative79.4%

        \[\leadsto \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)} \]
      2. associate-*r/79.4%

        \[\leadsto \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)} \]
      3. associate--r-79.4%

        \[\leadsto \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|}} \]
      4. +-commutative79.4%

        \[\leadsto \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)}} \]
      5. associate-+r-79.4%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg79.4%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+79.4%

        \[\leadsto \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)}} \]
      8. +-commutative79.4%

        \[\leadsto \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)}} \]
      9. associate--r+79.4%

        \[\leadsto \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. Simplified79.4%

      \[\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}}} \]
    4. Taylor expanded in K around 0 96.9%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg96.9%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified96.9%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 88.7%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+88.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow288.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out92.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative92.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow292.8%

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

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 91.2%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in M around inf 55.6%

      \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    12. Step-by-step derivation
      1. neg-mul-155.6%

        \[\leadsto 1 \cdot e^{\color{blue}{-{M}^{2}}} \]
      2. unpow255.6%

        \[\leadsto 1 \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in55.6%

        \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    13. Simplified55.6%

      \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -53 \lor \neg \left(m \leq 4.3 \cdot 10^{-39}\right):\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{M \cdot \left(-M\right)}\\ \end{array} \]

Alternative 12: 76.8% accurate, 3.9× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -53:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.72 \cdot 10^{-128}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -53.0)
   (exp (* -0.25 (* m m)))
   (if (<= m -1.72e-128) (exp (- l)) (exp (* (* n n) -0.25)))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -53.0) {
		tmp = exp((-0.25 * (m * m)));
	} else if (m <= -1.72e-128) {
		tmp = exp(-l);
	} else {
		tmp = exp(((n * n) * -0.25));
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 <= (-53.0d0)) then
        tmp = exp(((-0.25d0) * (m * m)))
    else if (m <= (-1.72d-128)) then
        tmp = exp(-l)
    else
        tmp = exp(((n * n) * (-0.25d0)))
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -53.0) {
		tmp = Math.exp((-0.25 * (m * m)));
	} else if (m <= -1.72e-128) {
		tmp = Math.exp(-l);
	} else {
		tmp = Math.exp(((n * n) * -0.25));
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	tmp = 0
	if m <= -53.0:
		tmp = math.exp((-0.25 * (m * m)))
	elif m <= -1.72e-128:
		tmp = math.exp(-l)
	else:
		tmp = math.exp(((n * n) * -0.25))
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -53.0)
		tmp = exp(Float64(-0.25 * Float64(m * m)));
	elseif (m <= -1.72e-128)
		tmp = exp(Float64(-l));
	else
		tmp = exp(Float64(Float64(n * n) * -0.25));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -53.0)
		tmp = exp((-0.25 * (m * m)));
	elseif (m <= -1.72e-128)
		tmp = exp(-l);
	else
		tmp = exp(((n * n) * -0.25));
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -53.0], N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -1.72e-128], N[Exp[(-l)], $MachinePrecision], N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
\mathbf{if}\;m \leq -53:\\
\;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;m \leq -1.72 \cdot 10^{-128}:\\
\;\;\;\;e^{-\ell}\\

\mathbf{else}:\\
\;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < -53

    1. Initial program 62.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)} \]
    2. Step-by-step derivation
      1. *-commutative62.3%

        \[\leadsto \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)} \]
      2. associate-*r/62.3%

        \[\leadsto \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)} \]
      3. associate--r-62.3%

        \[\leadsto \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|}} \]
      4. +-commutative62.3%

        \[\leadsto \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)}} \]
      5. associate-+r-62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg62.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+62.3%

        \[\leadsto \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)}} \]
      8. +-commutative62.3%

        \[\leadsto \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)}} \]
      9. associate--r+62.3%

        \[\leadsto \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. Simplified62.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 95.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg95.1%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified95.1%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 74.8%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+74.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow274.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out84.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative84.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow284.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified84.2%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 84.2%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in m around inf 90.8%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative90.8%

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow290.8%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    13. Simplified90.8%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right) \cdot -0.25}} \]

    if -53 < m < -1.71999999999999992e-128

    1. Initial program 76.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. Step-by-step derivation
      1. *-commutative76.8%

        \[\leadsto \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)} \]
      2. associate-*r/76.8%

        \[\leadsto \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)} \]
      3. associate--r-76.8%

        \[\leadsto \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|}} \]
      4. +-commutative76.8%

        \[\leadsto \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)}} \]
      5. associate-+r-76.8%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg76.8%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+76.8%

        \[\leadsto \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)}} \]
      8. +-commutative76.8%

        \[\leadsto \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)}} \]
      9. associate--r+76.8%

        \[\leadsto \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. Simplified76.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}}} \]
    4. Taylor expanded in K around 0 92.2%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg92.2%

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in l around inf 54.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    8. Step-by-step derivation
      1. mul-1-neg54.1%

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    9. Simplified54.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    10. Taylor expanded in M around 0 49.8%

      \[\leadsto \color{blue}{e^{-\ell}} \]

    if -1.71999999999999992e-128 < m

    1. Initial program 78.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)} \]
    2. Step-by-step derivation
      1. *-commutative78.3%

        \[\leadsto \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)} \]
      2. associate-*r/78.3%

        \[\leadsto \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)} \]
      3. associate--r-78.3%

        \[\leadsto \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|}} \]
      4. +-commutative78.3%

        \[\leadsto \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)}} \]
      5. associate-+r-78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg78.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+78.3%

        \[\leadsto \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)}} \]
      8. +-commutative78.3%

        \[\leadsto \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)}} \]
      9. associate--r+78.3%

        \[\leadsto \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. Simplified78.3%

      \[\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}}} \]
    4. Taylor expanded in K around 0 98.8%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg98.8%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified98.8%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 90.5%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+90.5%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow290.5%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out95.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative95.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow295.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified95.3%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 94.1%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in n around inf 58.8%

      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    12. Step-by-step derivation
      1. *-commutative58.8%

        \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow258.8%

        \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    13. Simplified58.8%

      \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right) \cdot -0.25}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -53:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.72 \cdot 10^{-128}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]

Alternative 13: 70.2% accurate, 3.9× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \begin{array}{l} \mathbf{if}\;M \leq -2 \lor \neg \left(M \leq 26\right):\\ \;\;\;\;e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (or (<= M -2.0) (not (<= M 26.0))) (exp (* M (- M))) (exp (- l))))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((M <= -2.0) || !(M <= 26.0)) {
		tmp = exp((M * -M));
	} else {
		tmp = exp(-l);
	}
	return tmp;
}
NOTE: m and n should be sorted in increasing order before calling this 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 <= (-2.0d0)) .or. (.not. (m_1 <= 26.0d0))) then
        tmp = exp((m_1 * -m_1))
    else
        tmp = exp(-l)
    end if
    code = tmp
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((M <= -2.0) || !(M <= 26.0)) {
		tmp = Math.exp((M * -M));
	} else {
		tmp = Math.exp(-l);
	}
	return tmp;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	tmp = 0
	if (M <= -2.0) or not (M <= 26.0):
		tmp = math.exp((M * -M))
	else:
		tmp = math.exp(-l)
	return tmp
m, n = sort([m, n])
function code(K, m, n, M, l)
	tmp = 0.0
	if ((M <= -2.0) || !(M <= 26.0))
		tmp = exp(Float64(M * Float64(-M)));
	else
		tmp = exp(Float64(-l));
	end
	return tmp
end
m, n = num2cell(sort([m, n])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if ((M <= -2.0) || ~((M <= 26.0)))
		tmp = exp((M * -M));
	else
		tmp = exp(-l);
	end
	tmp_2 = tmp;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[M, -2.0], N[Not[LessEqual[M, 26.0]], $MachinePrecision]], N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision], N[Exp[(-l)], $MachinePrecision]]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq -2 \lor \neg \left(M \leq 26\right):\\
\;\;\;\;e^{M \cdot \left(-M\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -2 or 26 < M

    1. Initial program 77.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. Step-by-step derivation
      1. *-commutative77.9%

        \[\leadsto \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)} \]
      2. associate-*r/77.9%

        \[\leadsto \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)} \]
      3. associate--r-77.9%

        \[\leadsto \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|}} \]
      4. +-commutative77.9%

        \[\leadsto \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)}} \]
      5. associate-+r-77.9%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg77.9%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+77.9%

        \[\leadsto \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)}} \]
      8. +-commutative77.9%

        \[\leadsto \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)}} \]
      9. associate--r+77.9%

        \[\leadsto \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. Simplified77.9%

      \[\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}}} \]
    4. Taylor expanded in K around 0 100.0%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in n around 0 81.1%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + \left(n \cdot \left(0.5 \cdot m - M\right) + 0.25 \cdot {n}^{2}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-+r+81.1%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)}} \]
      2. unpow281.1%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right) + 0.25 \cdot {n}^{2}\right)} \]
      3. distribute-rgt-out91.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)} + 0.25 \cdot {n}^{2}\right)} \]
      4. *-commutative91.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{{n}^{2} \cdot 0.25}\right)} \]
      5. unpow291.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \color{blue}{\left(n \cdot n\right)} \cdot 0.25\right)} \]
    9. Simplified91.0%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)}} \]
    10. Taylor expanded in M around 0 88.5%

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right) + \left(n \cdot n\right) \cdot 0.25\right)} \]
    11. Taylor expanded in M around inf 96.8%

      \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    12. Step-by-step derivation
      1. neg-mul-196.8%

        \[\leadsto 1 \cdot e^{\color{blue}{-{M}^{2}}} \]
      2. unpow296.8%

        \[\leadsto 1 \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in96.8%

        \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    13. Simplified96.8%

      \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]

    if -2 < M < 26

    1. Initial program 70.7%

      \[\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. Step-by-step derivation
      1. *-commutative70.7%

        \[\leadsto \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)} \]
      2. associate-*r/70.7%

        \[\leadsto \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)} \]
      3. associate--r-70.7%

        \[\leadsto \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|}} \]
      4. +-commutative70.7%

        \[\leadsto \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)}} \]
      5. associate-+r-70.7%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
      6. unsub-neg70.7%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
      7. associate--r+70.7%

        \[\leadsto \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)}} \]
      8. +-commutative70.7%

        \[\leadsto \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)}} \]
      9. associate--r+70.7%

        \[\leadsto \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. Simplified70.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}}} \]
    4. Taylor expanded in K around 0 94.8%

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    5. Step-by-step derivation
      1. cos-neg94.8%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    6. Simplified94.8%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    7. Taylor expanded in l around inf 44.3%

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    8. Step-by-step derivation
      1. mul-1-neg44.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    9. Simplified44.3%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    10. Taylor expanded in M around 0 44.3%

      \[\leadsto \color{blue}{e^{-\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification69.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -2 \lor \neg \left(M \leq 26\right):\\ \;\;\;\;e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 14: 35.5% accurate, 4.2× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ e^{-\ell} \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l) :precision binary64 (exp (- l)))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	return exp(-l);
}
NOTE: m and n should be sorted in increasing order before calling this 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
    code = exp(-l)
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	return Math.exp(-l);
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	return math.exp(-l)
m, n = sort([m, n])
function code(K, m, n, M, l)
	return exp(Float64(-l))
end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
	tmp = exp(-l);
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := N[Exp[(-l)], $MachinePrecision]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 74.1%

    \[\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. Step-by-step derivation
    1. *-commutative74.1%

      \[\leadsto \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)} \]
    2. associate-*r/74.1%

      \[\leadsto \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)} \]
    3. associate--r-74.1%

      \[\leadsto \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|}} \]
    4. +-commutative74.1%

      \[\leadsto \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)}} \]
    5. associate-+r-74.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
    6. unsub-neg74.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
    7. associate--r+74.1%

      \[\leadsto \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)}} \]
    8. +-commutative74.1%

      \[\leadsto \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)}} \]
    9. associate--r+74.1%

      \[\leadsto \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. Simplified74.1%

    \[\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}}} \]
  4. Taylor expanded in K around 0 97.3%

    \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  5. Step-by-step derivation
    1. cos-neg97.3%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  6. Simplified97.3%

    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  7. Taylor expanded in l around inf 40.1%

    \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  8. Step-by-step derivation
    1. mul-1-neg40.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  9. Simplified40.1%

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  10. Taylor expanded in M around 0 38.9%

    \[\leadsto \color{blue}{e^{-\ell}} \]
  11. Final simplification38.9%

    \[\leadsto e^{-\ell} \]

Alternative 15: 6.9% accurate, 4.2× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ \cos M \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l) :precision binary64 (cos M))
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	return cos(M);
}
NOTE: m and n should be sorted in increasing order before calling this 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
    code = cos(m_1)
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M);
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	return math.cos(M)
m, n = sort([m, n])
function code(K, m, n, M, l)
	return cos(M)
end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
	tmp = cos(M);
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := N[Cos[M], $MachinePrecision]
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
\cos M
\end{array}
Derivation
  1. Initial program 74.1%

    \[\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. Step-by-step derivation
    1. *-commutative74.1%

      \[\leadsto \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)} \]
    2. associate-*r/74.1%

      \[\leadsto \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)} \]
    3. associate--r-74.1%

      \[\leadsto \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|}} \]
    4. +-commutative74.1%

      \[\leadsto \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)}} \]
    5. associate-+r-74.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
    6. unsub-neg74.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
    7. associate--r+74.1%

      \[\leadsto \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)}} \]
    8. +-commutative74.1%

      \[\leadsto \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)}} \]
    9. associate--r+74.1%

      \[\leadsto \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. Simplified74.1%

    \[\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}}} \]
  4. Taylor expanded in K around 0 97.3%

    \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  5. Step-by-step derivation
    1. cos-neg97.3%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  6. Simplified97.3%

    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  7. Taylor expanded in l around inf 40.1%

    \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  8. Step-by-step derivation
    1. mul-1-neg40.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  9. Simplified40.1%

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  10. Taylor expanded in l around 0 6.6%

    \[\leadsto \color{blue}{\cos M} \]
  11. Final simplification6.6%

    \[\leadsto \cos M \]

Alternative 16: 6.9% accurate, 425.0× speedup?

\[\begin{array}{l} [m, n] = \mathsf{sort}([m, n])\\ \\ 1 \end{array} \]
NOTE: m and n should be sorted in increasing order before calling this function.
(FPCore (K m n M l) :precision binary64 1.0)
assert(m < n);
double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
NOTE: m and n should be sorted in increasing order before calling this 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
    code = 1.0d0
end function
assert m < n;
public static double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
[m, n] = sort([m, n])
def code(K, m, n, M, l):
	return 1.0
m, n = sort([m, n])
function code(K, m, n, M, l)
	return 1.0
end
m, n = num2cell(sort([m, n])){:}
function tmp = code(K, m, n, M, l)
	tmp = 1.0;
end
NOTE: m and n should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := 1.0
\begin{array}{l}
[m, n] = \mathsf{sort}([m, n])\\
\\
1
\end{array}
Derivation
  1. Initial program 74.1%

    \[\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. Step-by-step derivation
    1. *-commutative74.1%

      \[\leadsto \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)} \]
    2. associate-*r/74.1%

      \[\leadsto \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)} \]
    3. associate--r-74.1%

      \[\leadsto \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|}} \]
    4. +-commutative74.1%

      \[\leadsto \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)}} \]
    5. associate-+r-74.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| + \left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \ell}} \]
    6. unsub-neg74.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\color{blue}{\left(\left|m - n\right| - {\left(\frac{m + n}{2} - M\right)}^{2}\right)} - \ell} \]
    7. associate--r+74.1%

      \[\leadsto \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)}} \]
    8. +-commutative74.1%

      \[\leadsto \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)}} \]
    9. associate--r+74.1%

      \[\leadsto \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. Simplified74.1%

    \[\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}}} \]
  4. Taylor expanded in K around 0 97.3%

    \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  5. Step-by-step derivation
    1. cos-neg97.3%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  6. Simplified97.3%

    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
  7. Taylor expanded in l around inf 40.1%

    \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  8. Step-by-step derivation
    1. mul-1-neg40.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  9. Simplified40.1%

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  10. Taylor expanded in l around 0 6.6%

    \[\leadsto \color{blue}{\cos M} \]
  11. Taylor expanded in M around 0 6.6%

    \[\leadsto \color{blue}{1} \]
  12. Final simplification6.6%

    \[\leadsto 1 \]

Reproduce

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