Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.8% → 96.6%
Time: 20.7s
Alternatives: 9
Speedup: 1.3×

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

\[\begin{array}{l} \\ \cos M \cdot e^{\left(\left|n - m\right| - \ell\right) - {\left(\left(n + m\right) \cdot 0.5 - M\right)}^{2}} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (* (cos M) (exp (- (- (fabs (- n m)) l) (pow (- (* (+ n m) 0.5) M) 2.0)))))
double code(double K, double m, double n, double M, double l) {
	return cos(M) * exp(((fabs((n - m)) - l) - pow((((n + m) * 0.5) - M), 2.0)));
}
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) - ((((n + m) * 0.5d0) - m_1) ** 2.0d0)))
end function
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((((n + m) * 0.5) - M), 2.0)));
}
def code(K, m, n, M, l):
	return math.cos(M) * math.exp(((math.fabs((n - m)) - l) - math.pow((((n + m) * 0.5) - M), 2.0)))
function code(K, m, n, M, l)
	return Float64(cos(M) * exp(Float64(Float64(abs(Float64(n - m)) - l) - (Float64(Float64(Float64(n + m) * 0.5) - M) ^ 2.0))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp(((abs((n - m)) - l) - ((((n + m) * 0.5) - M) ^ 2.0)));
end
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[(n + m), $MachinePrecision] * 0.5), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos M \cdot e^{\left(\left|n - m\right| - \ell\right) - {\left(\left(n + m\right) \cdot 0.5 - M\right)}^{2}}
\end{array}
Derivation
  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*75.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. +-commutative75.7%

      \[\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-sub75.7%

      \[\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. +-commutative75.7%

      \[\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. Simplified75.7%

    \[\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. Taylor expanded in K around 0 96.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 77.5% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq -1 \cdot 10^{-29}:\\ \;\;\;\;\cos M \cdot e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;n \leq 55:\\ \;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{\left(m - n\right) - \left(\ell + {\left(\left(n + m\right) \cdot 0.5 - M\right)}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n -1e-29)
   (* (cos M) (exp (* (pow m 2.0) -0.25)))
   (if (<= n 55.0)
     (*
      (cos (- (/ (* (+ n m) K) 2.0) M))
      (exp (- (- m n) (+ l (pow (- (* (+ n m) 0.5) M) 2.0)))))
     (* (cos M) (exp (* -0.25 (pow n 2.0)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= -1e-29) {
		tmp = cos(M) * exp((pow(m, 2.0) * -0.25));
	} else if (n <= 55.0) {
		tmp = cos(((((n + m) * K) / 2.0) - M)) * exp(((m - n) - (l + pow((((n + m) * 0.5) - M), 2.0))));
	} else {
		tmp = cos(M) * exp((-0.25 * pow(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) :: tmp
    if (n <= (-1d-29)) then
        tmp = cos(m_1) * exp(((m ** 2.0d0) * (-0.25d0)))
    else if (n <= 55.0d0) then
        tmp = cos(((((n + m) * k) / 2.0d0) - m_1)) * exp(((m - n) - (l + ((((n + m) * 0.5d0) - m_1) ** 2.0d0))))
    else
        tmp = cos(m_1) * exp(((-0.25d0) * (n ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= -1e-29) {
		tmp = Math.cos(M) * Math.exp((Math.pow(m, 2.0) * -0.25));
	} else if (n <= 55.0) {
		tmp = Math.cos(((((n + m) * K) / 2.0) - M)) * Math.exp(((m - n) - (l + Math.pow((((n + m) * 0.5) - M), 2.0))));
	} else {
		tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(n, 2.0)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if n <= -1e-29:
		tmp = math.cos(M) * math.exp((math.pow(m, 2.0) * -0.25))
	elif n <= 55.0:
		tmp = math.cos(((((n + m) * K) / 2.0) - M)) * math.exp(((m - n) - (l + math.pow((((n + m) * 0.5) - M), 2.0))))
	else:
		tmp = math.cos(M) * math.exp((-0.25 * math.pow(n, 2.0)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (n <= -1e-29)
		tmp = Float64(cos(M) * exp(Float64((m ^ 2.0) * -0.25)));
	elseif (n <= 55.0)
		tmp = Float64(cos(Float64(Float64(Float64(Float64(n + m) * K) / 2.0) - M)) * exp(Float64(Float64(m - n) - Float64(l + (Float64(Float64(Float64(n + m) * 0.5) - M) ^ 2.0)))));
	else
		tmp = Float64(cos(M) * exp(Float64(-0.25 * (n ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (n <= -1e-29)
		tmp = cos(M) * exp(((m ^ 2.0) * -0.25));
	elseif (n <= 55.0)
		tmp = cos(((((n + m) * K) / 2.0) - M)) * exp(((m - n) - (l + ((((n + m) * 0.5) - M) ^ 2.0))));
	else
		tmp = cos(M) * exp((-0.25 * (n ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, -1e-29], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 55.0], N[(N[Cos[N[(N[(N[(N[(n + m), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(m - n), $MachinePrecision] - N[(l + N[Power[N[(N[(N[(n + m), $MachinePrecision] * 0.5), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n \leq -1 \cdot 10^{-29}:\\
\;\;\;\;\cos M \cdot e^{{m}^{2} \cdot -0.25}\\

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

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -9.99999999999999943e-30

    1. Initial program 67.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*67.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. +-commutative67.1%

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

        \[\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. +-commutative67.1%

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

      \[\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. Taylor expanded in K around 0 98.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Simplified52.8%

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]

    if -9.99999999999999943e-30 < n < 55

    1. Initial program 84.5%

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

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

        \[\leadsto \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(-\left(\ell - \color{blue}{\left|n - m\right|}\right)\right)} \]
      3. distribute-neg-out84.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 55 < n

    1. Initial program 72.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*72.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. +-commutative72.5%

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

        \[\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. +-commutative72.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    9. Simplified98.6%

      \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification78.9%

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

Alternative 3: 72.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(m - n\right) - \ell\\ t_1 := \cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{M \cdot \left(M - n\right) + t_0}\\ t_2 := \cos M \cdot e^{-{M}^{2}}\\ t_3 := m \cdot 0.5 - M\\ \mathbf{if}\;M \leq -26.5:\\ \;\;\;\;t_2\\ \mathbf{elif}\;M \leq -1.66 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;M \leq -2.45 \cdot 10^{-83}:\\ \;\;\;\;\cos M \cdot e^{t_3 \cdot \left(n + t_3\right) + t_0}\\ \mathbf{elif}\;M \leq 26.5:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (- m n) l))
        (t_1 (* (cos (- (/ (* (+ n m) K) 2.0) M)) (exp (+ (* M (- M n)) t_0))))
        (t_2 (* (cos M) (exp (- (pow M 2.0)))))
        (t_3 (- (* m 0.5) M)))
   (if (<= M -26.5)
     t_2
     (if (<= M -1.66e-43)
       t_1
       (if (<= M -2.45e-83)
         (* (cos M) (exp (+ (* t_3 (+ n t_3)) t_0)))
         (if (<= M 26.5) t_1 t_2))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = (m - n) - l;
	double t_1 = cos(((((n + m) * K) / 2.0) - M)) * exp(((M * (M - n)) + t_0));
	double t_2 = cos(M) * exp(-pow(M, 2.0));
	double t_3 = (m * 0.5) - M;
	double tmp;
	if (M <= -26.5) {
		tmp = t_2;
	} else if (M <= -1.66e-43) {
		tmp = t_1;
	} else if (M <= -2.45e-83) {
		tmp = cos(M) * exp(((t_3 * (n + t_3)) + t_0));
	} else if (M <= 26.5) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = (m - n) - l
    t_1 = cos(((((n + m) * k) / 2.0d0) - m_1)) * exp(((m_1 * (m_1 - n)) + t_0))
    t_2 = cos(m_1) * exp(-(m_1 ** 2.0d0))
    t_3 = (m * 0.5d0) - m_1
    if (m_1 <= (-26.5d0)) then
        tmp = t_2
    else if (m_1 <= (-1.66d-43)) then
        tmp = t_1
    else if (m_1 <= (-2.45d-83)) then
        tmp = cos(m_1) * exp(((t_3 * (n + t_3)) + t_0))
    else if (m_1 <= 26.5d0) then
        tmp = t_1
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = (m - n) - l;
	double t_1 = Math.cos(((((n + m) * K) / 2.0) - M)) * Math.exp(((M * (M - n)) + t_0));
	double t_2 = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
	double t_3 = (m * 0.5) - M;
	double tmp;
	if (M <= -26.5) {
		tmp = t_2;
	} else if (M <= -1.66e-43) {
		tmp = t_1;
	} else if (M <= -2.45e-83) {
		tmp = Math.cos(M) * Math.exp(((t_3 * (n + t_3)) + t_0));
	} else if (M <= 26.5) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = (m - n) - l
	t_1 = math.cos(((((n + m) * K) / 2.0) - M)) * math.exp(((M * (M - n)) + t_0))
	t_2 = math.cos(M) * math.exp(-math.pow(M, 2.0))
	t_3 = (m * 0.5) - M
	tmp = 0
	if M <= -26.5:
		tmp = t_2
	elif M <= -1.66e-43:
		tmp = t_1
	elif M <= -2.45e-83:
		tmp = math.cos(M) * math.exp(((t_3 * (n + t_3)) + t_0))
	elif M <= 26.5:
		tmp = t_1
	else:
		tmp = t_2
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(Float64(m - n) - l)
	t_1 = Float64(cos(Float64(Float64(Float64(Float64(n + m) * K) / 2.0) - M)) * exp(Float64(Float64(M * Float64(M - n)) + t_0)))
	t_2 = Float64(cos(M) * exp(Float64(-(M ^ 2.0))))
	t_3 = Float64(Float64(m * 0.5) - M)
	tmp = 0.0
	if (M <= -26.5)
		tmp = t_2;
	elseif (M <= -1.66e-43)
		tmp = t_1;
	elseif (M <= -2.45e-83)
		tmp = Float64(cos(M) * exp(Float64(Float64(t_3 * Float64(n + t_3)) + t_0)));
	elseif (M <= 26.5)
		tmp = t_1;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = (m - n) - l;
	t_1 = cos(((((n + m) * K) / 2.0) - M)) * exp(((M * (M - n)) + t_0));
	t_2 = cos(M) * exp(-(M ^ 2.0));
	t_3 = (m * 0.5) - M;
	tmp = 0.0;
	if (M <= -26.5)
		tmp = t_2;
	elseif (M <= -1.66e-43)
		tmp = t_1;
	elseif (M <= -2.45e-83)
		tmp = cos(M) * exp(((t_3 * (n + t_3)) + t_0));
	elseif (M <= 26.5)
		tmp = t_1;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(m - n), $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[N[(N[(N[(N[(n + m), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(M * N[(M - n), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision]}, If[LessEqual[M, -26.5], t$95$2, If[LessEqual[M, -1.66e-43], t$95$1, If[LessEqual[M, -2.45e-83], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(t$95$3 * N[(n + t$95$3), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 26.5], t$95$1, t$95$2]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(m - n\right) - \ell\\
t_1 := \cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{M \cdot \left(M - n\right) + t_0}\\
t_2 := \cos M \cdot e^{-{M}^{2}}\\
t_3 := m \cdot 0.5 - M\\
\mathbf{if}\;M \leq -26.5:\\
\;\;\;\;t_2\\

\mathbf{elif}\;M \leq -1.66 \cdot 10^{-43}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;M \leq -2.45 \cdot 10^{-83}:\\
\;\;\;\;\cos M \cdot e^{t_3 \cdot \left(n + t_3\right) + t_0}\\

\mathbf{elif}\;M \leq 26.5:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_2\\


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

    1. Initial program 75.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*75.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. +-commutative75.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-sub75.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. +-commutative75.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. Simplified75.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. Taylor expanded in K around 0 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
    9. Simplified97.5%

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

    if -26.5 < M < -1.66e-43 or -2.45e-83 < M < 26.5

    1. Initial program 80.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. sub-neg80.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.66e-43 < M < -2.45e-83

    1. Initial program 20.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. sub-neg20.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{n \cdot \left(m \cdot 0.5 - \left(M + 1\right)\right)} \]
    11. Simplified60.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -26.5:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq -1.66 \cdot 10^{-43}:\\ \;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{M \cdot \left(M - n\right) + \left(\left(m - n\right) - \ell\right)}\\ \mathbf{elif}\;M \leq -2.45 \cdot 10^{-83}:\\ \;\;\;\;\cos M \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(n + \left(m \cdot 0.5 - M\right)\right) + \left(\left(m - n\right) - \ell\right)}\\ \mathbf{elif}\;M \leq 26.5:\\ \;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{M \cdot \left(M - n\right) + \left(\left(m - n\right) - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \end{array} \]

Alternative 4: 63.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 3.6 \cdot 10^{-302}:\\ \;\;\;\;\cos M \cdot e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;n \leq 55:\\ \;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{n \cdot \left(m \cdot 0.5 - M\right) + \left(\left(m - n\right) - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 3.6e-302)
   (* (cos M) (exp (* (pow m 2.0) -0.25)))
   (if (<= n 55.0)
     (*
      (cos (- (/ (* (+ n m) K) 2.0) M))
      (exp (+ (* n (- (* m 0.5) M)) (- (- m n) l))))
     (* (cos M) (exp (* -0.25 (pow n 2.0)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 3.6e-302) {
		tmp = cos(M) * exp((pow(m, 2.0) * -0.25));
	} else if (n <= 55.0) {
		tmp = cos(((((n + m) * K) / 2.0) - M)) * exp(((n * ((m * 0.5) - M)) + ((m - n) - l)));
	} else {
		tmp = cos(M) * exp((-0.25 * pow(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) :: tmp
    if (n <= 3.6d-302) then
        tmp = cos(m_1) * exp(((m ** 2.0d0) * (-0.25d0)))
    else if (n <= 55.0d0) then
        tmp = cos(((((n + m) * k) / 2.0d0) - m_1)) * exp(((n * ((m * 0.5d0) - m_1)) + ((m - n) - l)))
    else
        tmp = cos(m_1) * exp(((-0.25d0) * (n ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 3.6e-302) {
		tmp = Math.cos(M) * Math.exp((Math.pow(m, 2.0) * -0.25));
	} else if (n <= 55.0) {
		tmp = Math.cos(((((n + m) * K) / 2.0) - M)) * Math.exp(((n * ((m * 0.5) - M)) + ((m - n) - l)));
	} else {
		tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(n, 2.0)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if n <= 3.6e-302:
		tmp = math.cos(M) * math.exp((math.pow(m, 2.0) * -0.25))
	elif n <= 55.0:
		tmp = math.cos(((((n + m) * K) / 2.0) - M)) * math.exp(((n * ((m * 0.5) - M)) + ((m - n) - l)))
	else:
		tmp = math.cos(M) * math.exp((-0.25 * math.pow(n, 2.0)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (n <= 3.6e-302)
		tmp = Float64(cos(M) * exp(Float64((m ^ 2.0) * -0.25)));
	elseif (n <= 55.0)
		tmp = Float64(cos(Float64(Float64(Float64(Float64(n + m) * K) / 2.0) - M)) * exp(Float64(Float64(n * Float64(Float64(m * 0.5) - M)) + Float64(Float64(m - n) - l))));
	else
		tmp = Float64(cos(M) * exp(Float64(-0.25 * (n ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (n <= 3.6e-302)
		tmp = cos(M) * exp(((m ^ 2.0) * -0.25));
	elseif (n <= 55.0)
		tmp = cos(((((n + m) * K) / 2.0) - M)) * exp(((n * ((m * 0.5) - M)) + ((m - n) - l)));
	else
		tmp = cos(M) * exp((-0.25 * (n ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 3.6e-302], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 55.0], N[(N[Cos[N[(N[(N[(N[(n + m), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(n * N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision] + N[(N[(m - n), $MachinePrecision] - l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n \leq 3.6 \cdot 10^{-302}:\\
\;\;\;\;\cos M \cdot e^{{m}^{2} \cdot -0.25}\\

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

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < 3.6000000000000001e-302

    1. Initial program 74.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.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. Taylor expanded in K around 0 97.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Simplified55.7%

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]

    if 3.6000000000000001e-302 < n < 55

    1. Initial program 84.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. sub-neg84.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 55 < n

    1. Initial program 72.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*72.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. +-commutative72.5%

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

        \[\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. +-commutative72.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    9. Simplified98.6%

      \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification68.8%

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

Alternative 5: 48.2% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -9 \cdot 10^{-36}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -9.00000000000000047e-36

    1. Initial program 67.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*67.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. +-commutative67.1%

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

        \[\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. +-commutative67.1%

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

      \[\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. Taylor expanded in K around 0 98.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.00000000000000047e-36 < n < 2.9000000000000003e-17

    1. Initial program 83.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. sub-neg83.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.9000000000000003e-17 < n

    1. Initial program 74.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. sub-neg74.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -9 \cdot 10^{-36}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;n \leq 2.9 \cdot 10^{-17}:\\ \;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{n \cdot \left(m \cdot 0.5 - M\right) + \left(\left(m - n\right) - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot 0.5 + \left(-1 - M\right)\right)}\\ \end{array} \]

Alternative 6: 55.1% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{n \cdot \left(m \cdot 0.5 + \left(-1 - M\right)\right)}\\
\mathbf{if}\;\ell \leq -1.16 \cdot 10^{+44}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 6 \cdot 10^{-10}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.1600000000000001e44 or -3.6999999999999999e-84 < l < 6e-10

    1. Initial program 72.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. sub-neg72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{n \cdot \left(m \cdot 0.5 - \left(M + 1\right)\right)} \]
    13. Step-by-step derivation
      1. cos-neg43.3%

        \[\leadsto \color{blue}{\cos M} \cdot e^{n \cdot \left(m \cdot 0.5 - \left(M + 1\right)\right)} \]
    14. Simplified43.3%

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

    if -1.1600000000000001e44 < l < -3.6999999999999999e-84

    1. Initial program 82.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. sub-neg82.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6e-10 < l

    1. Initial program 80.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*80.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. +-commutative80.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-sub80.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. +-commutative80.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. Simplified80.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. Taylor expanded in K around 0 97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification58.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.16 \cdot 10^{+44}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot 0.5 + \left(-1 - M\right)\right)}\\ \mathbf{elif}\;\ell \leq -3.7 \cdot 10^{-84}:\\ \;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{M \cdot \left(M - n\right) + \left(\left(m - n\right) - \ell\right)}\\ \mathbf{elif}\;\ell \leq 6 \cdot 10^{-10}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot 0.5 + \left(-1 - M\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]

Alternative 7: 56.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 6 \cdot 10^{-10}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot 0.5 + \left(-1 - M\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= l 6e-10)
   (* (cos M) (exp (* n (+ (* m 0.5) (- -1.0 M)))))
   (* (cos M) (exp (- l)))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (l <= 6e-10) {
		tmp = cos(M) * exp((n * ((m * 0.5) + (-1.0 - M))));
	} else {
		tmp = cos(M) * 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 (l <= 6d-10) then
        tmp = cos(m_1) * exp((n * ((m * 0.5d0) + ((-1.0d0) - m_1))))
    else
        tmp = cos(m_1) * 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 (l <= 6e-10) {
		tmp = Math.cos(M) * Math.exp((n * ((m * 0.5) + (-1.0 - M))));
	} else {
		tmp = Math.cos(M) * Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if l <= 6e-10:
		tmp = math.cos(M) * math.exp((n * ((m * 0.5) + (-1.0 - M))))
	else:
		tmp = math.cos(M) * math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (l <= 6e-10)
		tmp = Float64(cos(M) * exp(Float64(n * Float64(Float64(m * 0.5) + Float64(-1.0 - M)))));
	else
		tmp = Float64(cos(M) * exp(Float64(-l)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (l <= 6e-10)
		tmp = cos(M) * exp((n * ((m * 0.5) + (-1.0 - M))));
	else
		tmp = cos(M) * exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[l, 6e-10], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(n * N[(N[(m * 0.5), $MachinePrecision] + N[(-1.0 - M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 6 \cdot 10^{-10}:\\
\;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot 0.5 + \left(-1 - M\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 6e-10

    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. sub-neg74.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{n \cdot \left(m \cdot 0.5 - \left(M + 1\right)\right)} \]
    13. Step-by-step derivation
      1. cos-neg42.7%

        \[\leadsto \color{blue}{\cos M} \cdot e^{n \cdot \left(m \cdot 0.5 - \left(M + 1\right)\right)} \]
    14. Simplified42.7%

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

    if 6e-10 < l

    1. Initial program 80.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*80.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. +-commutative80.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-sub80.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. +-commutative80.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. Simplified80.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. Taylor expanded in K around 0 97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.5%

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

Alternative 8: 36.1% accurate, 2.1× speedup?

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

\\
\cos M \cdot e^{-\ell}
\end{array}
Derivation
  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*75.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. +-commutative75.7%

      \[\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-sub75.7%

      \[\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. +-commutative75.7%

      \[\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. Simplified75.7%

    \[\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. Taylor expanded in K around 0 96.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  10. Final simplification37.7%

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

Alternative 9: 7.1% 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 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*75.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. +-commutative75.7%

      \[\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-sub75.7%

      \[\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. +-commutative75.7%

      \[\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. Simplified75.7%

    \[\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. Taylor expanded in K around 0 96.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  9. Simplified54.7%

    \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  10. Taylor expanded in m around 0 6.3%

    \[\leadsto \cos M \cdot \color{blue}{1} \]
  11. Final simplification6.3%

    \[\leadsto \cos M \]

Reproduce

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