Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 96.6%
Time: 17.5s
Alternatives: 13
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 84.2% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 80.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999974e123 < n

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 86.2% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -1.3 \cdot 10^{+73}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\

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


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

    1. Initial program 78.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.3e73 < m

    1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 74.2% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 79.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.32e7 < m

    1. Initial program 78.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 74.9% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ t_1 := \cos M \cdot e^{-{M}^{2}}\\ t_2 := e^{-\ell}\\ \mathbf{if}\;M \leq -27:\\ \;\;\;\;t_1\\ \mathbf{elif}\;M \leq 1.8 \cdot 10^{-272}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq 5.8 \cdot 10^{-133}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;M \leq 4.6 \cdot 10^{-61}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;t_2 \cdot \cos \left(\frac{K}{\frac{2}{n}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos M) (exp (* -0.25 (pow m 2.0)))))
        (t_1 (* (cos M) (exp (- (pow M 2.0)))))
        (t_2 (exp (- l))))
   (if (<= M -27.0)
     t_1
     (if (<= M 1.8e-272)
       t_0
       (if (<= M 5.8e-133)
         t_2
         (if (<= M 4.6e-61)
           t_0
           (if (<= M 27.0) (* t_2 (cos (- (/ K (/ 2.0 n)) M))) t_1)))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp((-0.25 * pow(m, 2.0)));
	double t_1 = cos(M) * exp(-pow(M, 2.0));
	double t_2 = exp(-l);
	double tmp;
	if (M <= -27.0) {
		tmp = t_1;
	} else if (M <= 1.8e-272) {
		tmp = t_0;
	} else if (M <= 5.8e-133) {
		tmp = t_2;
	} else if (M <= 4.6e-61) {
		tmp = t_0;
	} else if (M <= 27.0) {
		tmp = t_2 * cos(((K / (2.0 / n)) - M));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = cos(m_1) * exp(((-0.25d0) * (m ** 2.0d0)))
    t_1 = cos(m_1) * exp(-(m_1 ** 2.0d0))
    t_2 = exp(-l)
    if (m_1 <= (-27.0d0)) then
        tmp = t_1
    else if (m_1 <= 1.8d-272) then
        tmp = t_0
    else if (m_1 <= 5.8d-133) then
        tmp = t_2
    else if (m_1 <= 4.6d-61) then
        tmp = t_0
    else if (m_1 <= 27.0d0) then
        tmp = t_2 * cos(((k / (2.0d0 / n)) - m_1))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.cos(M) * Math.exp((-0.25 * Math.pow(m, 2.0)));
	double t_1 = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
	double t_2 = Math.exp(-l);
	double tmp;
	if (M <= -27.0) {
		tmp = t_1;
	} else if (M <= 1.8e-272) {
		tmp = t_0;
	} else if (M <= 5.8e-133) {
		tmp = t_2;
	} else if (M <= 4.6e-61) {
		tmp = t_0;
	} else if (M <= 27.0) {
		tmp = t_2 * Math.cos(((K / (2.0 / n)) - M));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(M) * math.exp((-0.25 * math.pow(m, 2.0)))
	t_1 = math.cos(M) * math.exp(-math.pow(M, 2.0))
	t_2 = math.exp(-l)
	tmp = 0
	if M <= -27.0:
		tmp = t_1
	elif M <= 1.8e-272:
		tmp = t_0
	elif M <= 5.8e-133:
		tmp = t_2
	elif M <= 4.6e-61:
		tmp = t_0
	elif M <= 27.0:
		tmp = t_2 * math.cos(((K / (2.0 / n)) - M))
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) * exp(Float64(-0.25 * (m ^ 2.0))))
	t_1 = Float64(cos(M) * exp(Float64(-(M ^ 2.0))))
	t_2 = exp(Float64(-l))
	tmp = 0.0
	if (M <= -27.0)
		tmp = t_1;
	elseif (M <= 1.8e-272)
		tmp = t_0;
	elseif (M <= 5.8e-133)
		tmp = t_2;
	elseif (M <= 4.6e-61)
		tmp = t_0;
	elseif (M <= 27.0)
		tmp = Float64(t_2 * cos(Float64(Float64(K / Float64(2.0 / n)) - M)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = cos(M) * exp((-0.25 * (m ^ 2.0)));
	t_1 = cos(M) * exp(-(M ^ 2.0));
	t_2 = exp(-l);
	tmp = 0.0;
	if (M <= -27.0)
		tmp = t_1;
	elseif (M <= 1.8e-272)
		tmp = t_0;
	elseif (M <= 5.8e-133)
		tmp = t_2;
	elseif (M <= 4.6e-61)
		tmp = t_0;
	elseif (M <= 27.0)
		tmp = t_2 * cos(((K / (2.0 / n)) - M));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-l)], $MachinePrecision]}, If[LessEqual[M, -27.0], t$95$1, If[LessEqual[M, 1.8e-272], t$95$0, If[LessEqual[M, 5.8e-133], t$95$2, If[LessEqual[M, 4.6e-61], t$95$0, If[LessEqual[M, 27.0], N[(t$95$2 * N[Cos[N[(N[(K / N[(2.0 / n), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{-0.25 \cdot {m}^{2}}\\
t_1 := \cos M \cdot e^{-{M}^{2}}\\
t_2 := e^{-\ell}\\
\mathbf{if}\;M \leq -27:\\
\;\;\;\;t_1\\

\mathbf{elif}\;M \leq 1.8 \cdot 10^{-272}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;M \leq 5.8 \cdot 10^{-133}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;M \leq 4.6 \cdot 10^{-61}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;M \leq 27:\\
\;\;\;\;t_2 \cdot \cos \left(\frac{K}{\frac{2}{n}} - M\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


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

    1. Initial program 83.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -27 < M < 1.79999999999999984e-272 or 5.7999999999999997e-133 < M < 4.59999999999999984e-61

    1. Initial program 74.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.79999999999999984e-272 < M < 5.7999999999999997e-133

    1. Initial program 76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.59999999999999984e-61 < M < 27

    1. Initial program 75.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{n}} - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    12. Step-by-step derivation
      1. neg-mul-163.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -27:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq 1.8 \cdot 10^{-272}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;M \leq 5.8 \cdot 10^{-133}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{elif}\;M \leq 4.6 \cdot 10^{-61}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(\frac{K}{\frac{2}{n}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \end{array} \]

Alternative 6: 64.6% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;M \leq 1.65 \cdot 10^{+20}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -1.8e-119

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot n - {M}^{2}}} \]
    14. Step-by-step derivation
      1. unpow269.4%

        \[\leadsto \cos M \cdot e^{M \cdot n - \color{blue}{M \cdot M}} \]
      2. distribute-lft-out--71.9%

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

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

    if -1.8e-119 < M < 1.65e20

    1. Initial program 76.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    13. Taylor expanded in l around -inf 53.5%

      \[\leadsto \color{blue}{\cos M \cdot e^{-1 \cdot \ell}} \]
    14. Step-by-step derivation
      1. rem-exp-log53.5%

        \[\leadsto \color{blue}{e^{\log \cos M}} \cdot e^{-1 \cdot \ell} \]
      2. neg-mul-153.5%

        \[\leadsto e^{\log \cos M} \cdot e^{\color{blue}{-\ell}} \]
      3. exp-sum53.5%

        \[\leadsto \color{blue}{e^{\log \cos M + \left(-\ell\right)}} \]
      4. unsub-neg53.5%

        \[\leadsto e^{\color{blue}{\log \cos M - \ell}} \]
      5. exp-diff53.5%

        \[\leadsto \color{blue}{\frac{e^{\log \cos M}}{e^{\ell}}} \]
      6. rem-exp-log53.5%

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

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

    if 1.65e20 < M

    1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -1.8 \cdot 10^{-119}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(n - M\right)}\\ \mathbf{elif}\;M \leq 1.65 \cdot 10^{+20}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \end{array} \]

Alternative 7: 61.4% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;M \leq 8 \cdot 10^{+29}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -7.59999999999999949e-119

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot n - {M}^{2}}} \]
    14. Step-by-step derivation
      1. unpow269.4%

        \[\leadsto \cos M \cdot e^{M \cdot n - \color{blue}{M \cdot M}} \]
      2. distribute-lft-out--71.9%

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

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

    if -7.59999999999999949e-119 < M < 7.99999999999999931e29

    1. Initial program 75.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    13. Taylor expanded in l around -inf 54.7%

      \[\leadsto \color{blue}{\cos M \cdot e^{-1 \cdot \ell}} \]
    14. Step-by-step derivation
      1. rem-exp-log52.9%

        \[\leadsto \color{blue}{e^{\log \cos M}} \cdot e^{-1 \cdot \ell} \]
      2. neg-mul-152.9%

        \[\leadsto e^{\log \cos M} \cdot e^{\color{blue}{-\ell}} \]
      3. exp-sum52.9%

        \[\leadsto \color{blue}{e^{\log \cos M + \left(-\ell\right)}} \]
      4. unsub-neg52.9%

        \[\leadsto e^{\color{blue}{\log \cos M - \ell}} \]
      5. exp-diff52.9%

        \[\leadsto \color{blue}{\frac{e^{\log \cos M}}{e^{\ell}}} \]
      6. rem-exp-log54.7%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    15. Simplified54.7%

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

    if 7.99999999999999931e29 < M

    1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{M \cdot m - \color{blue}{M \cdot M}} \]
      2. distribute-lft-out--84.1%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(m - M\right)}} \]
    15. Simplified84.1%

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

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

Alternative 8: 39.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -4.55 \cdot 10^{-119}:\\
\;\;\;\;\cos M \cdot e^{M \cdot n}\\

\mathbf{elif}\;M \leq 2.1 \cdot 10^{+31}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -4.55e-119

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.55e-119 < M < 2.09999999999999979e31

    1. Initial program 75.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    13. Taylor expanded in l around -inf 54.7%

      \[\leadsto \color{blue}{\cos M \cdot e^{-1 \cdot \ell}} \]
    14. Step-by-step derivation
      1. rem-exp-log52.9%

        \[\leadsto \color{blue}{e^{\log \cos M}} \cdot e^{-1 \cdot \ell} \]
      2. neg-mul-152.9%

        \[\leadsto e^{\log \cos M} \cdot e^{\color{blue}{-\ell}} \]
      3. exp-sum52.9%

        \[\leadsto \color{blue}{e^{\log \cos M + \left(-\ell\right)}} \]
      4. unsub-neg52.9%

        \[\leadsto e^{\color{blue}{\log \cos M - \ell}} \]
      5. exp-diff52.9%

        \[\leadsto \color{blue}{\frac{e^{\log \cos M}}{e^{\ell}}} \]
      6. rem-exp-log54.7%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    15. Simplified54.7%

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

    if 2.09999999999999979e31 < M

    1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -4.55 \cdot 10^{-119}:\\ \;\;\;\;\cos M \cdot e^{M \cdot n}\\ \mathbf{elif}\;M \leq 2.1 \cdot 10^{+31}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot m}\\ \end{array} \]

Alternative 9: 65.4% accurate, 2.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


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

    1. Initial program 77.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot m - {M}^{2}}} \]
    14. Step-by-step derivation
      1. unpow250.3%

        \[\leadsto \cos M \cdot e^{M \cdot m - \color{blue}{M \cdot M}} \]
      2. distribute-lft-out--54.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(m - M\right)}} \]
    15. Simplified54.7%

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

    if 700 < l

    1. Initial program 83.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 48.6% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 700:\\
\;\;\;\;\cos M \cdot e^{M \cdot m}\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


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

    1. Initial program 77.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 700 < l

    1. Initial program 83.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 36.0% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \frac{\cos M}{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(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}

\\
\frac{\cos M}{e^{\ell}}
\end{array}
Derivation
  1. Initial program 79.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. associate-/l*79.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  12. Simplified36.8%

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  13. Taylor expanded in l around -inf 36.8%

    \[\leadsto \color{blue}{\cos M \cdot e^{-1 \cdot \ell}} \]
  14. Step-by-step derivation
    1. rem-exp-log30.1%

      \[\leadsto \color{blue}{e^{\log \cos M}} \cdot e^{-1 \cdot \ell} \]
    2. neg-mul-130.1%

      \[\leadsto e^{\log \cos M} \cdot e^{\color{blue}{-\ell}} \]
    3. exp-sum30.1%

      \[\leadsto \color{blue}{e^{\log \cos M + \left(-\ell\right)}} \]
    4. unsub-neg30.1%

      \[\leadsto e^{\color{blue}{\log \cos M - \ell}} \]
    5. exp-diff30.1%

      \[\leadsto \color{blue}{\frac{e^{\log \cos M}}{e^{\ell}}} \]
    6. rem-exp-log36.8%

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

    \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
  16. Final simplification36.8%

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

Alternative 12: 35.7% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 79.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. associate-/l*79.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  12. Simplified36.8%

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

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

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

Alternative 13: 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 79.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. associate-/l*79.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  12. Simplified36.8%

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  13. Taylor expanded in l around 0 5.4%

    \[\leadsto \color{blue}{\cos M} \]
  14. Final simplification5.4%

    \[\leadsto \cos M \]

Reproduce

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