Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.6% → 96.7%
Time: 22.1s
Alternatives: 9
Speedup: 1.4×

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 9 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: 76.6% 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.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{\left|m - n\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (* (cos M) (exp (- (fabs (- m n)) (+ (pow (- (/ (+ m n) 2.0) M) 2.0) l)))))
double code(double K, double m, double n, double M, double l) {
	return cos(M) * exp((fabs((m - n)) - (pow((((m + n) / 2.0) - M), 2.0) + l)));
}
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)) - (((((m + n) / 2.0d0) - m_1) ** 2.0d0) + l)))
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M) * Math.exp((Math.abs((m - n)) - (Math.pow((((m + n) / 2.0) - M), 2.0) + l)));
}
def code(K, m, n, M, l):
	return math.cos(M) * math.exp((math.fabs((m - n)) - (math.pow((((m + n) / 2.0) - M), 2.0) + l)))
function code(K, m, n, M, l)
	return Float64(cos(M) * exp(Float64(abs(Float64(m - n)) - Float64((Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0) + l))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp((abs((m - n)) - (((((m + n) / 2.0) - M) ^ 2.0) + l)));
end
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos M \cdot e^{\left|m - n\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}
\end{array}
Derivation
  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. associate-/l*71.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. associate--r-71.6%

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

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

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

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

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

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

Alternative 2: 88.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right|\\ \mathbf{if}\;M \leq -1.12 \cdot 10^{+72}:\\ \;\;\;\;\cos M \cdot e^{t_0 - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- m n))))
   (if (<= M -1.12e+72)
     (* (cos M) (exp (- t_0 (* M M))))
     (exp (- t_0 (+ l (* 0.25 (pow (+ m n) 2.0))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n));
	double tmp;
	if (M <= -1.12e+72) {
		tmp = cos(M) * exp((t_0 - (M * M)));
	} else {
		tmp = exp((t_0 - (l + (0.25 * pow((m + n), 2.0)))));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: tmp
    t_0 = abs((m - n))
    if (m_1 <= (-1.12d+72)) then
        tmp = cos(m_1) * exp((t_0 - (m_1 * m_1)))
    else
        tmp = exp((t_0 - (l + (0.25d0 * ((m + n) ** 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.abs((m - n));
	double tmp;
	if (M <= -1.12e+72) {
		tmp = Math.cos(M) * Math.exp((t_0 - (M * M)));
	} else {
		tmp = Math.exp((t_0 - (l + (0.25 * Math.pow((m + n), 2.0)))));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n))
	tmp = 0
	if M <= -1.12e+72:
		tmp = math.cos(M) * math.exp((t_0 - (M * M)))
	else:
		tmp = math.exp((t_0 - (l + (0.25 * math.pow((m + n), 2.0)))))
	return tmp
function code(K, m, n, M, l)
	t_0 = abs(Float64(m - n))
	tmp = 0.0
	if (M <= -1.12e+72)
		tmp = Float64(cos(M) * exp(Float64(t_0 - Float64(M * M))));
	else
		tmp = exp(Float64(t_0 - Float64(l + Float64(0.25 * (Float64(m + n) ^ 2.0)))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((m - n));
	tmp = 0.0;
	if (M <= -1.12e+72)
		tmp = cos(M) * exp((t_0 - (M * M)));
	else
		tmp = exp((t_0 - (l + (0.25 * ((m + n) ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[M, -1.12e+72], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(t$95$0 - N[(M * M), $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}

\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;M \leq -1.12 \cdot 10^{+72}:\\
\;\;\;\;\cos M \cdot e^{t_0 - M \cdot M}\\

\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 M < -1.12000000000000001e72

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

        \[\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. associate--r-74.5%

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot {M}^{2}} + \left|m - n\right|} \]
    8. Step-by-step derivation
      1. mul-1-neg92.3%

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

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - {M}^{2}} \cdot \cos M} \]
    11. Step-by-step derivation
      1. cos-neg92.3%

        \[\leadsto e^{\left|m - n\right| - {M}^{2}} \cdot \color{blue}{\cos \left(-M\right)} \]
      2. *-commutative92.3%

        \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\left|m - n\right| - {M}^{2}}} \]
      3. sub-neg92.3%

        \[\leadsto \cos \left(-M\right) \cdot e^{\color{blue}{\left|m - n\right| + \left(-{M}^{2}\right)}} \]
      4. mul-1-neg92.3%

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left|m - n\right| + -1 \cdot {M}^{2}} \]
      6. mul-1-neg92.3%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left|m - n\right| - {M}^{2}}} \]
      8. unpow292.3%

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \color{blue}{M \cdot M}} \]
    12. Simplified92.3%

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

    if -1.12000000000000001e72 < M

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

        \[\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. associate--r-70.9%

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(n + m\right)}^{2}\right)}} \]
    8. Step-by-step derivation
      1. fabs-sub93.2%

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

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

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

Alternative 3: 73.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -2000:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \left(n \cdot n\right)\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -2000.0)
   (exp (* (* m m) -0.25))
   (exp (- (fabs (- m n)) (+ l (* 0.25 (* n n)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -2000.0) {
		tmp = exp(((m * m) * -0.25));
	} else {
		tmp = exp((fabs((m - n)) - (l + (0.25 * (n * n)))));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: tmp
    if (m <= (-2000.0d0)) then
        tmp = exp(((m * m) * (-0.25d0)))
    else
        tmp = exp((abs((m - n)) - (l + (0.25d0 * (n * n)))))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -2000.0) {
		tmp = Math.exp(((m * m) * -0.25));
	} else {
		tmp = Math.exp((Math.abs((m - n)) - (l + (0.25 * (n * n)))));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -2000.0:
		tmp = math.exp(((m * m) * -0.25))
	else:
		tmp = math.exp((math.fabs((m - n)) - (l + (0.25 * (n * n)))))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -2000.0)
		tmp = exp(Float64(Float64(m * m) * -0.25));
	else
		tmp = exp(Float64(abs(Float64(m - n)) - Float64(l + Float64(0.25 * Float64(n * n)))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -2000.0)
		tmp = exp(((m * m) * -0.25));
	else
		tmp = exp((abs((m - n)) - (l + (0.25 * (n * n)))));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -2000.0], N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision], N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(l + N[(0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -2000:\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

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


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

    1. Initial program 57.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*57.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. associate--r-57.4%

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell\right) + \left|m - n\right|} \]
    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)}} \]
    8. Step-by-step derivation
      1. fabs-sub100.0%

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

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

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

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

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

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

    if -2e3 < m

    1. Initial program 76.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*76.1%

        \[\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. associate--r-76.1%

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(n + m\right)}^{2}\right)}} \]
    8. Step-by-step derivation
      1. fabs-sub87.3%

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

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

      \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\ell + 0.25 \cdot {n}^{2}\right)}} \]
    11. Step-by-step derivation
      1. *-commutative65.1%

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

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

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

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

Alternative 4: 63.0% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;m \leq -8 \cdot 10^{-216}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -54.0)
   (exp (* (* m m) -0.25))
   (if (<= m -8e-216) (/ (cos M) (exp l)) (exp (* -0.25 (* n n))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -54.0) {
		tmp = exp(((m * m) * -0.25));
	} else if (m <= -8e-216) {
		tmp = cos(M) / exp(l);
	} else {
		tmp = exp((-0.25 * (n * n)));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: tmp
    if (m <= (-54.0d0)) then
        tmp = exp(((m * m) * (-0.25d0)))
    else if (m <= (-8d-216)) then
        tmp = cos(m_1) / exp(l)
    else
        tmp = exp(((-0.25d0) * (n * n)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -54.0) {
		tmp = Math.exp(((m * m) * -0.25));
	} else if (m <= -8e-216) {
		tmp = Math.cos(M) / Math.exp(l);
	} else {
		tmp = Math.exp((-0.25 * (n * n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -54.0:
		tmp = math.exp(((m * m) * -0.25))
	elif m <= -8e-216:
		tmp = math.cos(M) / math.exp(l)
	else:
		tmp = math.exp((-0.25 * (n * n)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -54.0)
		tmp = exp(Float64(Float64(m * m) * -0.25));
	elseif (m <= -8e-216)
		tmp = Float64(cos(M) / exp(l));
	else
		tmp = exp(Float64(-0.25 * Float64(n * n)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -54.0)
		tmp = exp(((m * m) * -0.25));
	elseif (m <= -8e-216)
		tmp = cos(M) / exp(l);
	else
		tmp = exp((-0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -54.0], N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -8e-216], N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision], N[Exp[N[(-0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -54:\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

\mathbf{elif}\;m \leq -8 \cdot 10^{-216}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

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


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

    1. Initial program 57.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*57.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. associate--r-57.4%

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell\right) + \left|m - n\right|} \]
    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)}} \]
    8. Step-by-step derivation
      1. fabs-sub100.0%

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

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

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

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

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

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

    if -54 < m < -8.0000000000000003e-216

    1. Initial program 84.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. Simplified84.6%

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

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

      \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
    5. Step-by-step derivation
      1. cos-neg56.8%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    6. Simplified56.8%

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

    if -8.0000000000000003e-216 < m

    1. Initial program 73.6%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*73.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. associate--r-73.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 68.5% accurate, 3.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -54 \lor \neg \left(m \leq 53\right):\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{\ell}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (or (<= m -54.0) (not (<= m 53.0)))
   (exp (* (* m m) -0.25))
   (/ 1.0 (exp l))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((m <= -54.0) || !(m <= 53.0)) {
		tmp = exp(((m * m) * -0.25));
	} else {
		tmp = 1.0 / exp(l);
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: tmp
    if ((m <= (-54.0d0)) .or. (.not. (m <= 53.0d0))) then
        tmp = exp(((m * m) * (-0.25d0)))
    else
        tmp = 1.0d0 / exp(l)
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((m <= -54.0) || !(m <= 53.0)) {
		tmp = Math.exp(((m * m) * -0.25));
	} else {
		tmp = 1.0 / Math.exp(l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if (m <= -54.0) or not (m <= 53.0):
		tmp = math.exp(((m * m) * -0.25))
	else:
		tmp = 1.0 / math.exp(l)
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if ((m <= -54.0) || !(m <= 53.0))
		tmp = exp(Float64(Float64(m * m) * -0.25));
	else
		tmp = Float64(1.0 / exp(l));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if ((m <= -54.0) || ~((m <= 53.0)))
		tmp = exp(((m * m) * -0.25));
	else
		tmp = 1.0 / exp(l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[m, -54.0], N[Not[LessEqual[m, 53.0]], $MachinePrecision]], N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision], N[(1.0 / N[Exp[l], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -54 \lor \neg \left(m \leq 53\right):\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{\ell}}\\


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

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

        \[\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. associate--r-63.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if -54 < m < 53

    1. Initial program 80.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. Simplified80.5%

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

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

      \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
    5. Step-by-step derivation
      1. cos-neg48.5%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    6. Simplified48.5%

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Taylor expanded in M around 0 48.5%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification74.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -54 \lor \neg \left(m \leq 53\right):\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{\ell}}\\ \end{array} \]

Alternative 6: 62.8% accurate, 3.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;m \leq -1.8 \cdot 10^{-215}:\\ \;\;\;\;\frac{1}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -54.0)
   (exp (* (* m m) -0.25))
   (if (<= m -1.8e-215) (/ 1.0 (exp l)) (exp (* -0.25 (* n n))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -54.0) {
		tmp = exp(((m * m) * -0.25));
	} else if (m <= -1.8e-215) {
		tmp = 1.0 / exp(l);
	} else {
		tmp = exp((-0.25 * (n * n)));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: tmp
    if (m <= (-54.0d0)) then
        tmp = exp(((m * m) * (-0.25d0)))
    else if (m <= (-1.8d-215)) then
        tmp = 1.0d0 / exp(l)
    else
        tmp = exp(((-0.25d0) * (n * n)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -54.0) {
		tmp = Math.exp(((m * m) * -0.25));
	} else if (m <= -1.8e-215) {
		tmp = 1.0 / Math.exp(l);
	} else {
		tmp = Math.exp((-0.25 * (n * n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -54.0:
		tmp = math.exp(((m * m) * -0.25))
	elif m <= -1.8e-215:
		tmp = 1.0 / math.exp(l)
	else:
		tmp = math.exp((-0.25 * (n * n)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -54.0)
		tmp = exp(Float64(Float64(m * m) * -0.25));
	elseif (m <= -1.8e-215)
		tmp = Float64(1.0 / exp(l));
	else
		tmp = exp(Float64(-0.25 * Float64(n * n)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -54.0)
		tmp = exp(((m * m) * -0.25));
	elseif (m <= -1.8e-215)
		tmp = 1.0 / exp(l);
	else
		tmp = exp((-0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -54.0], N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -1.8e-215], N[(1.0 / N[Exp[l], $MachinePrecision]), $MachinePrecision], N[Exp[N[(-0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -54:\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

\mathbf{elif}\;m \leq -1.8 \cdot 10^{-215}:\\
\;\;\;\;\frac{1}{e^{\ell}}\\

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


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

    1. Initial program 57.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*57.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. associate--r-57.4%

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell\right) + \left|m - n\right|} \]
    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)}} \]
    8. Step-by-step derivation
      1. fabs-sub100.0%

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

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

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

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

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

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

    if -54 < m < -1.7999999999999999e-215

    1. Initial program 84.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. Simplified84.6%

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

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

      \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
    5. Step-by-step derivation
      1. cos-neg56.8%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    6. Simplified56.8%

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Taylor expanded in M around 0 56.7%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]

    if -1.7999999999999999e-215 < m

    1. Initial program 73.6%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*73.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. associate--r-73.8%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;m \leq -1.8 \cdot 10^{-215}:\\ \;\;\;\;\frac{1}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]

Alternative 7: 35.0% accurate, 4.1× speedup?

\[\begin{array}{l} \\ \frac{1}{e^{\ell}} \end{array} \]
(FPCore (K m n M l) :precision binary64 (/ 1.0 (exp l)))
double code(double K, double m, double n, double M, double l) {
	return 1.0 / exp(l);
}
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 / exp(l)
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0 / Math.exp(l);
}
def code(K, m, n, M, l):
	return 1.0 / math.exp(l)
function code(K, m, n, M, l)
	return Float64(1.0 / exp(l))
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0 / exp(l);
end
code[K_, m_, n_, M_, l_] := N[(1.0 / N[Exp[l], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{e^{\ell}}
\end{array}
Derivation
  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. Simplified71.6%

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

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

    \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
  5. Step-by-step derivation
    1. cos-neg39.1%

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
  6. Simplified39.1%

    \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
  7. Taylor expanded in M around 0 39.1%

    \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
  8. Final simplification39.1%

    \[\leadsto \frac{1}{e^{\ell}} \]

Alternative 8: 35.0% accurate, 4.2× speedup?

\[\begin{array}{l} \\ e^{-\ell} \end{array} \]
(FPCore (K m n M l) :precision binary64 (exp (- l)))
double code(double K, double m, double n, double M, double l) {
	return exp(-l);
}
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
public static double code(double K, double m, double n, double M, double l) {
	return Math.exp(-l);
}
def code(K, m, n, M, l):
	return math.exp(-l)
function code(K, m, n, M, l)
	return exp(Float64(-l))
end
function tmp = code(K, m, n, M, l)
	tmp = exp(-l);
end
code[K_, m_, n_, M_, l_] := N[Exp[(-l)], $MachinePrecision]
\begin{array}{l}

\\
e^{-\ell}
\end{array}
Derivation
  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. associate-/l*71.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. associate--r-71.6%

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

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

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

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

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

    \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(n + m\right)}^{2}\right)}} \]
  8. Step-by-step derivation
    1. fabs-sub90.4%

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

    \[\leadsto \color{blue}{e^{\left|n - m\right| - \left(\ell + 0.25 \cdot {\left(n + m\right)}^{2}\right)}} \]
  10. Taylor expanded in l around inf 39.1%

    \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
  11. Step-by-step derivation
    1. mul-1-neg39.1%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  12. Simplified39.1%

    \[\leadsto e^{\color{blue}{-\ell}} \]
  13. Final simplification39.1%

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

Alternative 9: 6.9% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \cos M \end{array} \]
(FPCore (K m n M l) :precision binary64 (cos M))
double code(double K, double m, double n, double M, double l) {
	return cos(M);
}
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
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M);
}
def code(K, m, n, M, l):
	return math.cos(M)
function code(K, m, n, M, l)
	return cos(M)
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M);
end
code[K_, m_, n_, M_, l_] := N[Cos[M], $MachinePrecision]
\begin{array}{l}

\\
\cos M
\end{array}
Derivation
  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. Simplified71.6%

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

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

    \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
  5. Step-by-step derivation
    1. cos-neg39.1%

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
  6. Simplified39.1%

    \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
  7. Taylor expanded in l around 0 5.6%

    \[\leadsto \color{blue}{\cos M} \]
  8. Final simplification5.6%

    \[\leadsto \cos M \]

Reproduce

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