Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.0% → 96.6%
Time: 22.7s
Alternatives: 11
Speedup: 2.0×

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 11 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.0% accurate, 1.0× speedup?

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

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

Alternative 1: 96.6% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 73.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right|\\ \mathbf{if}\;m \leq -1.75:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.18 \cdot 10^{-203}:\\ \;\;\;\;\cos M \cdot e^{t_0 - \left(\ell + M \cdot M\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{{e}^{\left(\ell + \left(n \cdot \left(n \cdot 0.25\right) - t_0\right)\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- m n))))
   (if (<= m -1.75)
     (* (cos M) (exp (* -0.25 (* m m))))
     (if (<= m -1.18e-203)
       (* (cos M) (exp (- t_0 (+ l (* M M)))))
       (/ (cos M) (pow E (+ l (- (* n (* n 0.25)) t_0))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n));
	double tmp;
	if (m <= -1.75) {
		tmp = cos(M) * exp((-0.25 * (m * m)));
	} else if (m <= -1.18e-203) {
		tmp = cos(M) * exp((t_0 - (l + (M * M))));
	} else {
		tmp = cos(M) / pow(((double) M_E), (l + ((n * (n * 0.25)) - t_0)));
	}
	return tmp;
}
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.abs((m - n));
	double tmp;
	if (m <= -1.75) {
		tmp = Math.cos(M) * Math.exp((-0.25 * (m * m)));
	} else if (m <= -1.18e-203) {
		tmp = Math.cos(M) * Math.exp((t_0 - (l + (M * M))));
	} else {
		tmp = Math.cos(M) / Math.pow(Math.E, (l + ((n * (n * 0.25)) - t_0)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n))
	tmp = 0
	if m <= -1.75:
		tmp = math.cos(M) * math.exp((-0.25 * (m * m)))
	elif m <= -1.18e-203:
		tmp = math.cos(M) * math.exp((t_0 - (l + (M * M))))
	else:
		tmp = math.cos(M) / math.pow(math.e, (l + ((n * (n * 0.25)) - t_0)))
	return tmp
function code(K, m, n, M, l)
	t_0 = abs(Float64(m - n))
	tmp = 0.0
	if (m <= -1.75)
		tmp = Float64(cos(M) * exp(Float64(-0.25 * Float64(m * m))));
	elseif (m <= -1.18e-203)
		tmp = Float64(cos(M) * exp(Float64(t_0 - Float64(l + Float64(M * M)))));
	else
		tmp = Float64(cos(M) / (exp(1) ^ Float64(l + Float64(Float64(n * Float64(n * 0.25)) - t_0))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((m - n));
	tmp = 0.0;
	if (m <= -1.75)
		tmp = cos(M) * exp((-0.25 * (m * m)));
	elseif (m <= -1.18e-203)
		tmp = cos(M) * exp((t_0 - (l + (M * M))));
	else
		tmp = cos(M) / (2.71828182845904523536 ^ (l + ((n * (n * 0.25)) - t_0)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[m, -1.75], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, -1.18e-203], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(t$95$0 - N[(l + N[(M * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] / N[Power[E, N[(l + N[(N[(n * N[(n * 0.25), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;m \leq -1.75:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;m \leq -1.18 \cdot 10^{-203}:\\
\;\;\;\;\cos M \cdot e^{t_0 - \left(\ell + M \cdot M\right)}\\

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


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

    1. Initial program 77.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.75 < m < -1.1800000000000001e-203

    1. Initial program 84.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. *-commutative84.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.1800000000000001e-203 < m

    1. Initial program 71.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. Simplified72.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 73.1% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;m \leq -1.75:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;m \leq -9.5 \cdot 10^{-202}:\\
\;\;\;\;\cos M \cdot e^{t_0 - \left(\ell + M \cdot M\right)}\\

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


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

    1. Initial program 77.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.75 < m < -9.5000000000000001e-202

    1. Initial program 84.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. *-commutative84.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.5000000000000001e-202 < m

    1. Initial program 71.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. Simplified72.4%

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos M}{\color{blue}{\frac{e^{\ell + 0.25 \cdot {n}^{2}}}{e^{\left|n - m\right|}}}} \]
      3. sub-neg18.5%

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

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

        \[\leadsto \frac{\cos M}{\frac{e^{\color{blue}{0.25 \cdot {n}^{2} + \ell}}}{e^{\left|n + -1 \cdot m\right|}}} \]
      6. *-lft-identity18.5%

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

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

        \[\leadsto \frac{\cos M}{\frac{e^{\color{blue}{0.25 \cdot {n}^{2} - -1 \cdot \ell}}}{e^{\left|n + -1 \cdot m\right|}}} \]
      9. mul-1-neg18.5%

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

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

        \[\leadsto \frac{\cos M}{\frac{e^{0.25 \cdot {n}^{2} - -1 \cdot \ell}}{e^{\color{blue}{\left|m - n\right|}}}} \]
      12. exp-diff64.7%

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

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

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

Alternative 4: 69.6% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -3.8 \cdot 10^{-219}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;n \leq 22.5:\\
\;\;\;\;\cos M \cdot e^{\left|m - n\right| - \left(\ell + M \cdot M\right)}\\

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


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

    1. Initial program 75.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. *-commutative75.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.80000000000000025e-219 < n < 22.5

    1. Initial program 78.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. *-commutative78.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 22.5 < n

    1. Initial program 71.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. *-commutative71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 69.5% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.1 \cdot 10^{-219}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\

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

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


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

    1. Initial program 75.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. *-commutative75.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.1e-219 < n < 22.5

    1. Initial program 78.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. *-commutative78.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{e^{\left|m - n\right|}}{e^{\ell + {M}^{2}}}} \]
      2. unpow245.1%

        \[\leadsto \frac{e^{\left|m - n\right|}}{e^{\ell + \color{blue}{M \cdot M}}} \]
      3. cancel-sign-sub45.1%

        \[\leadsto \frac{e^{\left|m - n\right|}}{e^{\color{blue}{\ell - \left(-M\right) \cdot M}}} \]
      4. distribute-lft-neg-in45.1%

        \[\leadsto \frac{e^{\left|m - n\right|}}{e^{\ell - \color{blue}{\left(-M \cdot M\right)}}} \]
      5. exp-diff64.7%

        \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell - \left(-M \cdot M\right)\right)}} \]
      6. fabs-sub64.7%

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell - \left(-M \cdot M\right)\right)} \]
      7. distribute-lft-neg-in64.7%

        \[\leadsto e^{\left|n - m\right| - \left(\ell - \color{blue}{\left(-M\right) \cdot M}\right)} \]
      8. cancel-sign-sub64.7%

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

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

    if 22.5 < n

    1. Initial program 71.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. *-commutative71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 76.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -17 \lor \neg \left(M \leq 8 \cdot 10^{-26}\right):\\
\;\;\;\;\cos M \cdot e^{-M \cdot M}\\

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


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

    1. Initial program 74.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -17 < M < 8.0000000000000003e-26

    1. Initial program 77.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 65.2% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq -2.2 \cdot 10^{-210}:\\
\;\;\;\;\cos M \cdot e^{-M \cdot M}\\

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


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

    1. Initial program 77.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.5e8 < m < -2.19999999999999989e-210

    1. Initial program 84.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.19999999999999989e-210 < m

    1. Initial program 71.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. *-commutative71.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 70.8% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -4.2 \lor \neg \left(M \leq 44000000000\right):\\
\;\;\;\;\cos M \cdot e^{-M \cdot M}\\

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


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

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.20000000000000018 < M < 4.4e10

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 7.4% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \cos M \end{array} \]
(FPCore (K m n M l) :precision binary64 (cos M))
double code(double K, double m, double n, double M, double l) {
	return cos(M);
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = cos(m_1)
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M);
}
def code(K, m, n, M, l):
	return math.cos(M)
function code(K, m, n, M, l)
	return cos(M)
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M);
end
code[K_, m_, n_, M_, l_] := N[Cos[M], $MachinePrecision]
\begin{array}{l}

\\
\cos M
\end{array}
Derivation
  1. Initial program 75.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. *-commutative75.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \]

Alternative 11: 6.8% accurate, 60.7× speedup?

\[\begin{array}{l} \\ 1 + \left(M \cdot M\right) \cdot -1.5 \end{array} \]
(FPCore (K m n M l) :precision binary64 (+ 1.0 (* (* M M) -1.5)))
double code(double K, double m, double n, double M, double l) {
	return 1.0 + ((M * M) * -1.5);
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = 1.0d0 + ((m_1 * m_1) * (-1.5d0))
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0 + ((M * M) * -1.5);
}
def code(K, m, n, M, l):
	return 1.0 + ((M * M) * -1.5)
function code(K, m, n, M, l)
	return Float64(1.0 + Float64(Float64(M * M) * -1.5))
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0 + ((M * M) * -1.5);
end
code[K_, m_, n_, M_, l_] := N[(1.0 + N[(N[(M * M), $MachinePrecision] * -1.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 + \left(M \cdot M\right) \cdot -1.5
\end{array}
Derivation
  1. Initial program 75.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. *-commutative75.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{1 + -1.5 \cdot {M}^{2}} \]
  11. Step-by-step derivation
    1. *-commutative6.8%

      \[\leadsto 1 + \color{blue}{{M}^{2} \cdot -1.5} \]
    2. unpow26.8%

      \[\leadsto 1 + \color{blue}{\left(M \cdot M\right)} \cdot -1.5 \]
  12. Simplified6.8%

    \[\leadsto \color{blue}{1 + \left(M \cdot M\right) \cdot -1.5} \]
  13. Final simplification6.8%

    \[\leadsto 1 + \left(M \cdot M\right) \cdot -1.5 \]

Reproduce

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