Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.9% → 96.5%
Time: 24.3s
Alternatives: 14
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 14 alternatives:

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

Initial Program: 76.9% accurate, 1.0× speedup?

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

\\
\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\end{array}

Alternative 1: 96.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ {\left(\sqrt[3]{\cos \left(\mathsf{expm1}\left(-0.125 \cdot {\left(K \cdot \left(m + n\right)\right)}^{2}\right) - M\right)}\right)}^{3} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (*
  (pow (cbrt (cos (- (expm1 (* -0.125 (pow (* K (+ m n)) 2.0))) M))) 3.0)
  (exp (- (- (fabs (- m n)) l) (pow (- (/ (+ m n) 2.0) M) 2.0)))))
double code(double K, double m, double n, double M, double l) {
	return pow(cbrt(cos((expm1((-0.125 * pow((K * (m + n)), 2.0))) - M))), 3.0) * exp(((fabs((m - n)) - l) - pow((((m + n) / 2.0) - M), 2.0)));
}
public static double code(double K, double m, double n, double M, double l) {
	return Math.pow(Math.cbrt(Math.cos((Math.expm1((-0.125 * Math.pow((K * (m + n)), 2.0))) - M))), 3.0) * Math.exp(((Math.abs((m - n)) - l) - Math.pow((((m + n) / 2.0) - M), 2.0)));
}
function code(K, m, n, M, l)
	return Float64((cbrt(cos(Float64(expm1(Float64(-0.125 * (Float64(K * Float64(m + n)) ^ 2.0))) - M))) ^ 3.0) * exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))))
end
code[K_, m_, n_, M_, l_] := N[(N[Power[N[Power[N[Cos[N[(N[(Exp[N[(-0.125 * N[Power[N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision] * N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(\sqrt[3]{\cos \left(\mathsf{expm1}\left(-0.125 \cdot {\left(K \cdot \left(m + n\right)\right)}^{2}\right) - M\right)}\right)}^{3} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 73.9%

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

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

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

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

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

    \[\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. Step-by-step derivation
    1. expm1-log1p-u48.4%

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

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

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

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

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{log1p}\left(K \cdot \left(\left(m + n\right) \cdot \color{blue}{0.5}\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
  5. Applied egg-rr48.4%

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

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

      \[\leadsto \cos \left(\mathsf{expm1}\left(\color{blue}{\mathsf{fma}\left(-0.125, {K}^{2} \cdot {\left(m + n\right)}^{2}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)}\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    2. *-commutative76.4%

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

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, \color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot {K}^{2}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    4. unpow276.4%

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

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, \color{blue}{\left(\left(m + n\right) \cdot K\right) \cdot \left(\left(m + n\right) \cdot K\right)}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    6. unpow285.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, \color{blue}{{\left(\left(m + n\right) \cdot K\right)}^{2}}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    7. +-commutative85.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, {\left(\color{blue}{\left(n + m\right)} \cdot K\right)}^{2}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    8. associate-*r*85.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, {\left(\left(n + m\right) \cdot K\right)}^{2}, \color{blue}{\left(0.5 \cdot K\right) \cdot \left(m + n\right)}\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    9. *-commutative85.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, {\left(\left(n + m\right) \cdot K\right)}^{2}, \color{blue}{\left(m + n\right) \cdot \left(0.5 \cdot K\right)}\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    10. +-commutative85.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, {\left(\left(n + m\right) \cdot K\right)}^{2}, \color{blue}{\left(n + m\right)} \cdot \left(0.5 \cdot K\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
  8. Simplified85.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos \left(\mathsf{expm1}\left(\color{blue}{-0.125 \cdot {\left(K \cdot \left(m + n\right)\right)}^{2}}\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
  12. Step-by-step derivation
    1. add-cube-cbrt96.4%

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos \left(\mathsf{expm1}\left(-0.125 \cdot {\left(K \cdot \left(m + n\right)\right)}^{2}\right) - M\right)}\right)}^{3}} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
  13. Applied egg-rr96.4%

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

    \[\leadsto {\left(\sqrt[3]{\cos \left(\mathsf{expm1}\left(-0.125 \cdot {\left(K \cdot \left(m + n\right)\right)}^{2}\right) - M\right)}\right)}^{3} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]

Alternative 2: 96.5% accurate, 0.7× speedup?

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

\\
\cos \left(\mathsf{expm1}\left(-0.125 \cdot {\left(K \cdot \left(m + n\right)\right)}^{2}\right) - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 73.9%

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

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

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

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

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

    \[\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. Step-by-step derivation
    1. expm1-log1p-u48.4%

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

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

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

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

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{log1p}\left(K \cdot \left(\left(m + n\right) \cdot \color{blue}{0.5}\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
  5. Applied egg-rr48.4%

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

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

      \[\leadsto \cos \left(\mathsf{expm1}\left(\color{blue}{\mathsf{fma}\left(-0.125, {K}^{2} \cdot {\left(m + n\right)}^{2}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)}\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    2. *-commutative76.4%

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

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, \color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot {K}^{2}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    4. unpow276.4%

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

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, \color{blue}{\left(\left(m + n\right) \cdot K\right) \cdot \left(\left(m + n\right) \cdot K\right)}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    6. unpow285.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, \color{blue}{{\left(\left(m + n\right) \cdot K\right)}^{2}}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    7. +-commutative85.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, {\left(\color{blue}{\left(n + m\right)} \cdot K\right)}^{2}, 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    8. associate-*r*85.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, {\left(\left(n + m\right) \cdot K\right)}^{2}, \color{blue}{\left(0.5 \cdot K\right) \cdot \left(m + n\right)}\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    9. *-commutative85.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, {\left(\left(n + m\right) \cdot K\right)}^{2}, \color{blue}{\left(m + n\right) \cdot \left(0.5 \cdot K\right)}\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
    10. +-commutative85.8%

      \[\leadsto \cos \left(\mathsf{expm1}\left(\mathsf{fma}\left(-0.125, {\left(\left(n + m\right) \cdot K\right)}^{2}, \color{blue}{\left(n + m\right)} \cdot \left(0.5 \cdot K\right)\right)\right) - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|n - m\right|\right)} \]
  8. Simplified85.8%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 96.5% accurate, 1.0× speedup?

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

\\
\cos \left(-M\right) \cdot e^{\left|m - n\right| - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}
\end{array}
Derivation
  1. Initial program 73.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. Taylor expanded in K around 0 96.0%

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

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

Alternative 4: 63.1% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 76.8%

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

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

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

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

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

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

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

    if 6.4999999999999999e-125 < m

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(-M\right) \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*44.6%

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

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

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

Alternative 5: 85.9% accurate, 1.3× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;t_0 \cdot e^{t_1 - \left(\ell + t_2 \cdot \left(m + t_2\right)\right)}\\


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

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

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

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

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

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

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

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

    if 1e11 < n

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

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

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

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

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

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

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

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

Alternative 6: 62.8% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;m \leq -950000:\\
\;\;\;\;\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{{m}^{2} \cdot -0.25}\\

\mathbf{elif}\;m \leq 6.5 \cdot 10^{-125}:\\
\;\;\;\;t_0 \cdot e^{t_1 + \left(M \cdot \left(n - M\right) - \ell\right)}\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.30000000000000005e115 < m < -9.5e5

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    11. Step-by-step derivation
      1. *-commutative95.9%

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

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

    if -9.5e5 < m < 6.4999999999999999e-125

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

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

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

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

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

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

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

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

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

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

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

    if 6.4999999999999999e-125 < m

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(-M\right) \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*44.6%

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

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

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

Alternative 7: 58.5% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(-M\right)\\
\mathbf{if}\;m \leq -950000:\\
\;\;\;\;\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{{m}^{2} \cdot -0.25}\\

\mathbf{elif}\;m \leq 6.5 \cdot 10^{-125}:\\
\;\;\;\;t_0 \cdot e^{\left|m - n\right| + \left(M \cdot \left(n - M\right) - \ell\right)}\\

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


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

    1. Initial program 72.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    11. Step-by-step derivation
      1. *-commutative74.2%

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Simplified74.2%

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

    if -9.5e5 < m < 6.4999999999999999e-125

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

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

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

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

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

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

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

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

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

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

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

    if 6.4999999999999999e-125 < m

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(-M\right) \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*44.6%

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

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

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

Alternative 8: 54.6% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right)\\
\mathbf{if}\;m \leq -15:\\
\;\;\;\;t_0 \cdot e^{{m}^{2} \cdot -0.25}\\

\mathbf{elif}\;m \leq 4 \cdot 10^{-94}:\\
\;\;\;\;t_0 \cdot e^{-{M}^{2}}\\

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


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

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

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

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

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

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

      \[\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 n around 0 59.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    11. Step-by-step derivation
      1. *-commutative72.9%

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Simplified72.9%

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

    if -15 < m < 3.9999999999999998e-94

    1. Initial program 78.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    11. Step-by-step derivation
      1. mul-1-neg62.4%

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-{M}^{2}}} \]
    12. Simplified62.4%

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

    if 3.9999999999999998e-94 < m

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(-M\right) \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*44.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -15:\\ \;\;\;\;\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;m \leq 4 \cdot 10^{-94}:\\ \;\;\;\;\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \end{array} \]

Alternative 9: 61.7% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 700:\\
\;\;\;\;\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{-{M}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 700

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    11. Step-by-step derivation
      1. mul-1-neg53.3%

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-{M}^{2}}} \]
    12. Simplified53.3%

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

    if 700 < l

    1. Initial program 84.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*84.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. +-commutative84.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-sub84.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. +-commutative84.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. Simplified84.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 n around 0 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    11. Step-by-step derivation
      1. mul-1-neg88.2%

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-\ell}} \]
    12. Simplified88.2%

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

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
    14. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
    15. Simplified100.0%

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

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

Alternative 10: 61.0% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{M \cdot \left(\left(\left(n + m \cdot 0.5\right) - m \cdot -0.5\right) - M\right)}\\ \mathbf{if}\;\ell \leq -3.5 \cdot 10^{-178}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -2.7 \cdot 10^{-240}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq 700:\\ \;\;\;\;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 (- (* K (* m 0.5)) M))
          (exp (* M (- (- (+ n (* m 0.5)) (* m -0.5)) M))))))
   (if (<= l -3.5e-178)
     t_0
     (if (<= l -2.7e-240)
       (* (cos (- M)) (exp (* n (* m -0.5))))
       (if (<= l 700.0) t_0 (* (cos M) (exp (- l))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(((K * (m * 0.5)) - M)) * exp((M * (((n + (m * 0.5)) - (m * -0.5)) - M)));
	double tmp;
	if (l <= -3.5e-178) {
		tmp = t_0;
	} else if (l <= -2.7e-240) {
		tmp = cos(-M) * exp((n * (m * -0.5)));
	} else if (l <= 700.0) {
		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(((k * (m * 0.5d0)) - m_1)) * exp((m_1 * (((n + (m * 0.5d0)) - (m * (-0.5d0))) - m_1)))
    if (l <= (-3.5d-178)) then
        tmp = t_0
    else if (l <= (-2.7d-240)) then
        tmp = cos(-m_1) * exp((n * (m * (-0.5d0))))
    else if (l <= 700.0d0) 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(((K * (m * 0.5)) - M)) * Math.exp((M * (((n + (m * 0.5)) - (m * -0.5)) - M)));
	double tmp;
	if (l <= -3.5e-178) {
		tmp = t_0;
	} else if (l <= -2.7e-240) {
		tmp = Math.cos(-M) * Math.exp((n * (m * -0.5)));
	} else if (l <= 700.0) {
		tmp = t_0;
	} else {
		tmp = Math.cos(M) * Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(((K * (m * 0.5)) - M)) * math.exp((M * (((n + (m * 0.5)) - (m * -0.5)) - M)))
	tmp = 0
	if l <= -3.5e-178:
		tmp = t_0
	elif l <= -2.7e-240:
		tmp = math.cos(-M) * math.exp((n * (m * -0.5)))
	elif l <= 700.0:
		tmp = t_0
	else:
		tmp = math.cos(M) * math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(Float64(Float64(K * Float64(m * 0.5)) - M)) * exp(Float64(M * Float64(Float64(Float64(n + Float64(m * 0.5)) - Float64(m * -0.5)) - M))))
	tmp = 0.0
	if (l <= -3.5e-178)
		tmp = t_0;
	elseif (l <= -2.7e-240)
		tmp = Float64(cos(Float64(-M)) * exp(Float64(n * Float64(m * -0.5))));
	elseif (l <= 700.0)
		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(((K * (m * 0.5)) - M)) * exp((M * (((n + (m * 0.5)) - (m * -0.5)) - M)));
	tmp = 0.0;
	if (l <= -3.5e-178)
		tmp = t_0;
	elseif (l <= -2.7e-240)
		tmp = cos(-M) * exp((n * (m * -0.5)));
	elseif (l <= 700.0)
		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[N[(N[(K * N[(m * 0.5), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(M * N[(N[(N[(n + N[(m * 0.5), $MachinePrecision]), $MachinePrecision] - N[(m * -0.5), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.5e-178], t$95$0, If[LessEqual[l, -2.7e-240], N[(N[Cos[(-M)], $MachinePrecision] * N[Exp[N[(n * N[(m * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 700.0], t$95$0, N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -2.7 \cdot 10^{-240}:\\
\;\;\;\;\cos \left(-M\right) \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\

\mathbf{elif}\;\ell \leq 700:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.49999999999999983e-178 or -2.70000000000000018e-240 < l < 700

    1. Initial program 73.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*73.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. +-commutative73.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-sub73.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. +-commutative73.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. Simplified73.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 n around 0 58.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{-\left(\color{blue}{M \cdot M} + M \cdot \left(-1 \cdot \left(n + 0.5 \cdot m\right) + -0.5 \cdot m\right)\right)} \]
      5. distribute-lft-out52.3%

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

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

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

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

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{-M \cdot \left(M + \left(\color{blue}{m \cdot -0.5} - \left(n + 0.5 \cdot m\right)\right)\right)} \]
      10. *-commutative52.3%

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

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

    if -3.49999999999999983e-178 < l < -2.70000000000000018e-240

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(-M\right) \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*45.5%

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

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

    if 700 < l

    1. Initial program 84.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*84.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. +-commutative84.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-sub84.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. +-commutative84.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. Simplified84.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 n around 0 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    11. Step-by-step derivation
      1. mul-1-neg88.2%

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-\ell}} \]
    12. Simplified88.2%

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

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
    14. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
    15. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.5 \cdot 10^{-178}:\\ \;\;\;\;\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{M \cdot \left(\left(\left(n + m \cdot 0.5\right) - m \cdot -0.5\right) - M\right)}\\ \mathbf{elif}\;\ell \leq -2.7 \cdot 10^{-240}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq 700:\\ \;\;\;\;\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{M \cdot \left(\left(\left(n + m \cdot 0.5\right) - m \cdot -0.5\right) - M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]

Alternative 11: 48.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(-M\right)\\ t_1 := t_0 \cdot e^{n \cdot M}\\ \mathbf{if}\;\ell \leq -1.4 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 1.05 \cdot 10^{-226}:\\ \;\;\;\;t_0 \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq 700:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (cos (- M))) (t_1 (* t_0 (exp (* n M)))))
   (if (<= l -1.4e-63)
     t_1
     (if (<= l 1.05e-226)
       (* t_0 (exp (* n (* m -0.5))))
       (if (<= l 700.0) t_1 (* (cos M) (exp (- l))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(-M);
	double t_1 = t_0 * exp((n * M));
	double tmp;
	if (l <= -1.4e-63) {
		tmp = t_1;
	} else if (l <= 1.05e-226) {
		tmp = t_0 * exp((n * (m * -0.5)));
	} else if (l <= 700.0) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = cos(-m_1)
    t_1 = t_0 * exp((n * m_1))
    if (l <= (-1.4d-63)) then
        tmp = t_1
    else if (l <= 1.05d-226) then
        tmp = t_0 * exp((n * (m * (-0.5d0))))
    else if (l <= 700.0d0) then
        tmp = t_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 t_0 = Math.cos(-M);
	double t_1 = t_0 * Math.exp((n * M));
	double tmp;
	if (l <= -1.4e-63) {
		tmp = t_1;
	} else if (l <= 1.05e-226) {
		tmp = t_0 * Math.exp((n * (m * -0.5)));
	} else if (l <= 700.0) {
		tmp = t_1;
	} else {
		tmp = Math.cos(M) * Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(-M)
	t_1 = t_0 * math.exp((n * M))
	tmp = 0
	if l <= -1.4e-63:
		tmp = t_1
	elif l <= 1.05e-226:
		tmp = t_0 * math.exp((n * (m * -0.5)))
	elif l <= 700.0:
		tmp = t_1
	else:
		tmp = math.cos(M) * math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	t_0 = cos(Float64(-M))
	t_1 = Float64(t_0 * exp(Float64(n * M)))
	tmp = 0.0
	if (l <= -1.4e-63)
		tmp = t_1;
	elseif (l <= 1.05e-226)
		tmp = Float64(t_0 * exp(Float64(n * Float64(m * -0.5))));
	elseif (l <= 700.0)
		tmp = t_1;
	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);
	t_1 = t_0 * exp((n * M));
	tmp = 0.0;
	if (l <= -1.4e-63)
		tmp = t_1;
	elseif (l <= 1.05e-226)
		tmp = t_0 * exp((n * (m * -0.5)));
	elseif (l <= 700.0)
		tmp = t_1;
	else
		tmp = cos(M) * exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Cos[(-M)], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[Exp[N[(n * M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.4e-63], t$95$1, If[LessEqual[l, 1.05e-226], N[(t$95$0 * N[Exp[N[(n * N[(m * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 700.0], t$95$1, N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(-M\right)\\
t_1 := t_0 \cdot e^{n \cdot M}\\
\mathbf{if}\;\ell \leq -1.4 \cdot 10^{-63}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq 1.05 \cdot 10^{-226}:\\
\;\;\;\;t_0 \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\

\mathbf{elif}\;\ell \leq 700:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.4000000000000001e-63 or 1.0500000000000001e-226 < l < 700

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

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

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

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

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

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

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

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

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

    if -1.4000000000000001e-63 < l < 1.0500000000000001e-226

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(-M\right) \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*41.0%

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

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

    if 700 < l

    1. Initial program 84.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*84.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. +-commutative84.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-sub84.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. +-commutative84.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. Simplified84.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 n around 0 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    11. Step-by-step derivation
      1. mul-1-neg88.2%

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-\ell}} \]
    12. Simplified88.2%

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

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
    14. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
    15. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.4 \cdot 10^{-63}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{n \cdot M}\\ \mathbf{elif}\;\ell \leq 1.05 \cdot 10^{-226}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq 700:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{n \cdot M}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]

Alternative 12: 48.7% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 700:\\
\;\;\;\;\cos \left(-M\right) \cdot e^{n \cdot M}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 700

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

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

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

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

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

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

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

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

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

    if 700 < l

    1. Initial program 84.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*84.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. +-commutative84.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-sub84.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. +-commutative84.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. Simplified84.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 n around 0 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    11. Step-by-step derivation
      1. mul-1-neg88.2%

        \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-\ell}} \]
    12. Simplified88.2%

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

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
    14. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
    15. Simplified100.0%

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

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

Alternative 13: 36.4% 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 73.9%

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

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

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

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

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

    \[\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 n around 0 59.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  11. Step-by-step derivation
    1. mul-1-neg28.6%

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-\ell}} \]
  12. Simplified28.6%

    \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-\ell}} \]
  13. Taylor expanded in K around 0 31.1%

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

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

    \[\leadsto \color{blue}{\cos M \cdot e^{-\ell}} \]
  16. Final simplification31.1%

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

Alternative 14: 7.1% accurate, 4.0× speedup?

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

\\
\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right)
\end{array}
Derivation
  1. Initial program 73.9%

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

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

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

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

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

    \[\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 n around 0 59.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  11. Step-by-step derivation
    1. mul-1-neg28.6%

      \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-\ell}} \]
  12. Simplified28.6%

    \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{-\ell}} \]
  13. Taylor expanded in l around 0 8.8%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot m\right) - M\right)} \]
  14. Step-by-step derivation
    1. *-commutative8.8%

      \[\leadsto \cos \left(\color{blue}{\left(K \cdot m\right) \cdot 0.5} - M\right) \]
    2. associate-*r*8.8%

      \[\leadsto \cos \left(\color{blue}{K \cdot \left(m \cdot 0.5\right)} - M\right) \]
  15. Simplified8.8%

    \[\leadsto \color{blue}{\cos \left(K \cdot \left(m \cdot 0.5\right) - M\right)} \]
  16. Final simplification8.8%

    \[\leadsto \cos \left(K \cdot \left(m \cdot 0.5\right) - M\right) \]

Reproduce

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