Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.9% → 96.0%
Time: 16.2s
Alternatives: 6
Speedup: 1.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 6 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.9% 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: 96.0% accurate, 1.3× speedup?

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

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


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

    1. Initial program 74.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. associate-/l*74.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\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)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out92.7%

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

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

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

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

    if -3.50000000000000023e42 < M

    1. Initial program 74.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. associate-/l*74.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -3.5 \cdot 10^{+42}:\\ \;\;\;\;\cos M \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(\left(M - m \cdot 0.5\right) - n\right) + \left(\left|n - m\right| - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|n - m\right| - \left({\left(0.5 \cdot \left(m + n\right) - M\right)}^{2} + \ell\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 3: 96.3% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto e^{\left|n - m\right| - \left({\left(0.5 \cdot \left(m + n\right) - M\right)}^{2} + \ell\right)} \]
  14. Add Preprocessing

Alternative 4: 93.1% accurate, 1.4× speedup?

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

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


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

    1. Initial program 61.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. associate-/l*61.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.5e18 < 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. associate-/l*78.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 80.1% accurate, 1.4× speedup?

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

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


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

    1. Initial program 77.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. associate-/l*77.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.0000000000000001e130 < M

    1. Initial program 73.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. associate-/l*74.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 78.4% accurate, 1.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto e^{\left|n - m\right| - \left(\ell + \color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(\left(0.5 \cdot n - M\right) + m\right)}\right)} \]
  16. Final simplification76.3%

    \[\leadsto e^{\left|n - m\right| + \left(\left(m + \left(n \cdot 0.5 - M\right)\right) \cdot \left(M - n \cdot 0.5\right) - \ell\right)} \]
  17. Add Preprocessing

Reproduce

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